summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.cxx5
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.h3
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.cxx2
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.h4
-rw-r--r--Source/CursesDialog/cmCursesForm.h9
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.cxx2
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.h3
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.cxx4
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx131
-rw-r--r--Source/CursesDialog/cmCursesMainForm.h77
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx69
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.h40
-rw-r--r--Source/CursesDialog/cmCursesWidget.cxx1
-rw-r--r--Source/CursesDialog/cmCursesWidget.h58
14 files changed, 325 insertions, 83 deletions
diff --git a/Source/CursesDialog/cmCursesBoolWidget.cxx b/Source/CursesDialog/cmCursesBoolWidget.cxx
index 9d54b54..f19dba5 100644
--- a/Source/CursesDialog/cmCursesBoolWidget.cxx
+++ b/Source/CursesDialog/cmCursesBoolWidget.cxx
@@ -1,4 +1,5 @@
#include "cmCursesBoolWidget.h"
+#include "cmCursesMainForm.h"
cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
int left, int top) :
@@ -11,8 +12,10 @@ cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
this->SetValueAsBool(false);
}
-bool cmCursesBoolWidget::HandleInput(int& key, FORM* form, WINDOW* w)
+bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w)
{
+ FORM* form = fm->GetForm();
+
// 10 == enter
if (key == 10 || key == KEY_ENTER)
{
diff --git a/Source/CursesDialog/cmCursesBoolWidget.h b/Source/CursesDialog/cmCursesBoolWidget.h
index a4dff63..ba05c43 100644
--- a/Source/CursesDialog/cmCursesBoolWidget.h
+++ b/Source/CursesDialog/cmCursesBoolWidget.h
@@ -2,6 +2,7 @@
#define __cmCursesBoolWidget_h
#include "cmCursesWidget.h"
+class cmCursesMainForm;
class cmCursesBoolWidget : public cmCursesWidget
{
@@ -12,7 +13,7 @@ public:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled.
- virtual bool HandleInput(int& key, FORM* form, WINDOW* w);
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
// Description:
// Set/Get the value (on/off).
diff --git a/Source/CursesDialog/cmCursesDummyWidget.cxx b/Source/CursesDialog/cmCursesDummyWidget.cxx
index 432b3e1..8eca5be 100644
--- a/Source/CursesDialog/cmCursesDummyWidget.cxx
+++ b/Source/CursesDialog/cmCursesDummyWidget.cxx
@@ -8,7 +8,7 @@ cmCursesDummyWidget::cmCursesDummyWidget(int width, int height,
}
-bool cmCursesDummyWidget::HandleInput(int& key, FORM* form, WINDOW* w)
+bool cmCursesDummyWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* )
{
return false;
}
diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h
index ead9699..aa7d72a 100644
--- a/Source/CursesDialog/cmCursesDummyWidget.h
+++ b/Source/CursesDialog/cmCursesDummyWidget.h
@@ -3,6 +3,8 @@
#include "cmCursesWidget.h"
+class cmCursesMainForm;
+
class cmCursesDummyWidget : public cmCursesWidget
{
public:
@@ -12,7 +14,7 @@ public:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled.
- virtual bool HandleInput(int& key, FORM* form, WINDOW* w);
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
protected:
cmCursesDummyWidget(const cmCursesDummyWidget& from);
diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h
index 35a3f13..23996a3 100644
--- a/Source/CursesDialog/cmCursesForm.h
+++ b/Source/CursesDialog/cmCursesForm.h
@@ -39,7 +39,14 @@ public:
// Description:
// Write a debugging message.
static void LogMessage(const char* msg);
-
+
+ // Description:
+ // Return the FORM. Should be only used by low-level methods.
+ FORM* GetForm()
+ {
+ return m_Form;
+ }
+
static cmCursesForm* CurrentForm;
diff --git a/Source/CursesDialog/cmCursesLabelWidget.cxx b/Source/CursesDialog/cmCursesLabelWidget.cxx
index b260eac..d51dd67 100644
--- a/Source/CursesDialog/cmCursesLabelWidget.cxx
+++ b/Source/CursesDialog/cmCursesLabelWidget.cxx
@@ -15,7 +15,7 @@ cmCursesLabelWidget::~cmCursesLabelWidget()
{
}
-bool cmCursesLabelWidget::HandleInput(int& key, FORM* form, WINDOW* w)
+bool cmCursesLabelWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* )
{
// Static text. No input is handled here.
return false;
diff --git a/Source/CursesDialog/cmCursesLabelWidget.h b/Source/CursesDialog/cmCursesLabelWidget.h
index 93442d2..2ae37b1 100644
--- a/Source/CursesDialog/cmCursesLabelWidget.h
+++ b/Source/CursesDialog/cmCursesLabelWidget.h
@@ -4,6 +4,7 @@
#include "cmCursesWidget.h"
#include "cmCursesStandardIncludes.h"
+class cmCursesMainForm;
class cmCursesLabelWidget : public cmCursesWidget
{
@@ -16,7 +17,7 @@ public:
// Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was
// handled
- virtual bool HandleInput(int& key, FORM* form, WINDOW* w);
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
protected:
cmCursesLabelWidget(const cmCursesLabelWidget& from);
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx
index 83c01f1..ab988ff 100644
--- a/Source/CursesDialog/cmCursesLongMessageForm.cxx
+++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx
@@ -89,7 +89,7 @@ void cmCursesLongMessageForm::PrintKeys()
return;
}
char firstLine[512];
- sprintf(firstLine, "O)k");
+ sprintf(firstLine, "Press [e] to exit help");
curses_move(y-2,0);
printw(firstLine);
@@ -166,7 +166,7 @@ void cmCursesLongMessageForm::HandleInput()
cmCursesForm::LogMessage(debugMessage);
// quit
- if ( key == 'o' )
+ if ( key == 'o' || key == 'e' )
{
break;
}
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 38ab65e..b40753c 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -20,8 +20,8 @@ inline int ctrl(int z)
cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args) :
m_Args(args)
{
+ m_NumberOfPages = 0;
m_Fields = 0;
- m_Height = 0;
m_Entries = 0;
m_AdvancedMode = false;
m_NumberOfVisibleEntries = 0;
@@ -53,6 +53,7 @@ cmCursesMainForm::~cmCursesMainForm()
delete m_Entries;
}
+// See if a cache entry is in the list of entries in the ui.
bool cmCursesMainForm::LookForCacheEntry(const char* key)
{
if (!key || !m_Entries)
@@ -72,6 +73,7 @@ bool cmCursesMainForm::LookForCacheEntry(const char* key)
return false;
}
+// Create new cmCursesCacheEntryComposite entries from the cache
void cmCursesMainForm::InitializeUI()
{
@@ -79,6 +81,8 @@ void cmCursesMainForm::InitializeUI()
const cmCacheManager::CacheEntryMap &cache =
cmCacheManager::GetInstance()->GetCacheMap();
+ // Create a vector of cmCursesCacheEntryComposite's
+ // which contain labels, entries and new entry markers
std::vector<cmCursesCacheEntryComposite*>* newEntries =
new std::vector<cmCursesCacheEntryComposite*>;
newEntries->reserve(cache.size());
@@ -149,8 +153,10 @@ void cmCursesMainForm::InitializeUI()
}
}
+ // Clean old entries
if (m_Entries)
{
+ // Have to call delete on each pointer
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
@@ -160,6 +166,7 @@ void cmCursesMainForm::InitializeUI()
delete m_Entries;
m_Entries = newEntries;
+ // Compute fields from composites
this->RePost();
}
@@ -181,6 +188,7 @@ void cmCursesMainForm::RePost()
}
else
{
+ // If normal mode, count only non-advanced entries
m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
@@ -194,8 +202,11 @@ void cmCursesMainForm::RePost()
}
}
+ // Assign the fields: 3 for each entry: label, new entry marker
+ // ('*' or ' ') and entry widget
m_Fields = new FIELD*[3*m_NumberOfVisibleEntries+1];
+ // Assign fields
int j=0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
@@ -223,6 +234,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
FIELD* currentField = current_field(m_Form);
cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
(field_userptr(currentField));
+ // If in edit mode, get out of it
if ( cw->GetType() == cmCacheManager::STRING ||
cw->GetType() == cmCacheManager::PATH ||
cw->GetType() == cmCacheManager::FILEPATH )
@@ -230,18 +242,21 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
sw->SetInEdit(false);
}
+ // Delete the previous form
unpost_form(m_Form);
free_form(m_Form);
m_Form = 0;
}
+
+ // Wrong window size
if ( width < cmCursesMainForm::MIN_WIDTH ||
height < cmCursesMainForm::MIN_HEIGHT )
{
return;
}
- height -= 6;
- m_Height = height;
+ // Leave room for toolbar
+ height -= 7;
if (m_AdvancedMode)
{
@@ -249,6 +264,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
}
else
{
+ // If normal, display only non-advanced entries
m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
@@ -262,8 +278,10 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
}
}
+ // Re-adjust the fields according to their place
bool isNewPage;
int i=0;
+ m_NumberOfPages = 1;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{
@@ -276,16 +294,24 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
int page = (i / height) + 1;
isNewPage = ( page > 1 ) && ( row == 1 );
+ if (isNewPage)
+ {
+ m_NumberOfPages++;
+ }
(*it)->m_Label->Move(left, top+row-1, isNewPage);
(*it)->m_IsNewLabel->Move(left+32, top+row-1, false);
(*it)->m_Entry->Move(left+33, top+row-1, false);
+ (*it)->m_Entry->SetPage(m_NumberOfPages);
i++;
}
+ // Post the form
m_Form = new_form(m_Fields);
post_form(m_Form);
+ // Update toolbar
this->UpdateStatusBar();
- this->PrintKeys();
+ this->PrintKeys()
+;
touchwin(stdscr);
refresh();
}
@@ -299,28 +325,58 @@ void cmCursesMainForm::PrintKeys()
{
return;
}
- char firstLine[512], secondLine[512];
- if (m_OkToGenerate)
- {
- sprintf(firstLine, "C)onfigure G)enerate and Exit H)elp");
- }
- else
+
+ // Give the current widget (if it exists), a chance to print keys
+ cmCursesWidget* cw = 0;
+ if (m_Form)
{
- sprintf(firstLine, "C)onfigure H)elp");
+ FIELD* currentField = current_field(m_Form);
+ cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
}
- if (m_AdvancedMode)
+
+ if (cw && cw->PrintKeys())
{
- sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (On)");
}
else
{
- sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (Off)");
+ char firstLine[512], secondLine[512], thirdLine[512];
+ if (m_OkToGenerate)
+ {
+ sprintf(firstLine, "Press [c] to configure Press [g] to generate and exit");
+ }
+ else
+ {
+ sprintf(firstLine, "Press [c] to configure");
+ }
+ if (m_AdvancedMode)
+ {
+ sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently On)");
+ }
+ else
+ {
+ sprintf(thirdLine, "Press [t] to toggle advanced mode (Currently Off)");
+ }
+
+ sprintf(secondLine, "Press [h] for help Press [q] to quit without generating");
+
+
+ curses_move(y-4,0);
+ printw("Press [enter] to edit option");
+ curses_move(y-3,0);
+ printw(firstLine);
+ curses_move(y-2,0);
+ printw(secondLine);
+ curses_move(y-1,0);
+ printw(thirdLine);
+
+ if (cw)
+ {
+ sprintf(firstLine, "Page %d of %d", cw->GetPage(), m_NumberOfPages);
+ curses_move(0,65-strlen(firstLine)-1);
+ printw(firstLine);
+ }
}
- curses_move(y-2,0);
- printw(firstLine);
- curses_move(y-1,0);
- printw(secondLine);
pos_form_cursor(m_Form);
}
@@ -331,6 +387,7 @@ void cmCursesMainForm::UpdateStatusBar()
{
int x,y;
getmaxyx(stdscr, y, x);
+ // If window size is too small, display error and return
if ( x < cmCursesMainForm::MIN_WIDTH ||
y < cmCursesMainForm::MIN_HEIGHT )
{
@@ -343,12 +400,15 @@ void cmCursesMainForm::UpdateStatusBar()
return;
}
+ // Get the key of the current entry
FIELD* cur = current_field(m_Form);
int index = field_index(cur);
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
m_Fields[index-2]));
const char* curField = lbl->GetValue();
+ // Get the help string of the current entry
+ // and add it to the help string
char help[128];
const char* helpString;
cmCacheManager::CacheEntry *entry =
@@ -365,6 +425,8 @@ void cmCursesMainForm::UpdateStatusBar()
}
+ // Join the key, help string and pad with spaces
+ // (or truncate) as necessary
char bar[cmCursesMainForm::MAX_WIDTH];
int i, curFieldLen = strlen(curField);
int helpLen = strlen(help);
@@ -405,6 +467,7 @@ void cmCursesMainForm::UpdateStatusBar()
bar[width] = '\0';
+ // Display CMake version info on the next line
// We want to display this on the right
char version[cmCursesMainForm::MAX_WIDTH];
char vertmp[128];
@@ -415,11 +478,12 @@ void cmCursesMainForm::UpdateStatusBar()
sprintf(version+sideSpace, "%s", vertmp);
version[width] = '\0';
- curses_move(y-4,0);
+ // Now print both lines
+ curses_move(y-5,0);
attron(A_STANDOUT);
printw(bar);
attroff(A_STANDOUT);
- curses_move(y-3,0);
+ curses_move(y-4,0);
printw(version);
pos_form_cursor(m_Form);
}
@@ -535,6 +599,8 @@ void cmCursesMainForm::FillCacheManagerFromUI()
void cmCursesMainForm::HandleInput()
{
+ int x,y;
+
if (!m_Form)
{
return;
@@ -551,12 +617,31 @@ void cmCursesMainForm::HandleInput()
this->PrintKeys();
int key = getch();
+ getmaxyx(stdscr, y, x);
+ // If window too small, handle 'q' only
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ // quit
+ if ( key == 'q' )
+ {
+ break;
+ }
+ else
+ {
+ continue;
+ }
+ }
+
currentField = current_field(m_Form);
currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
currentField));
- if (!currentWidget || !currentWidget->HandleInput(key, m_Form, stdscr))
+ // Ask the current widget if it wants to handle input
+ if (!currentWidget || !currentWidget->HandleInput(key, this, stdscr))
{
+ // If the current widget does not want to handle input,
+ // we handle it.
sprintf(debugMessage, "Main form handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
// quit
@@ -627,7 +712,6 @@ void cmCursesMainForm::HandleInput()
// display help
else if ( key == 'h' )
{
- int x,y;
getmaxyx(stdscr, y, x);
FIELD* cur = current_field(m_Form);
@@ -666,7 +750,6 @@ void cmCursesMainForm::HandleInput()
// display last errors
else if ( key == 'l' )
{
- int x,y;
getmaxyx(stdscr, y, x);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
"Errors which during last pass.");
@@ -687,7 +770,6 @@ void cmCursesMainForm::HandleInput()
{
m_AdvancedMode = true;
}
- int x,y;
getmaxyx(stdscr, y, x);
this->RePost();
this->Render(1, 1, x, y);
@@ -740,7 +822,6 @@ void cmCursesMainForm::HandleInput()
nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
}
- int x,y;
getmaxyx(stdscr, y, x);
this->RemoveEntry(lbl->GetValue());
this->RePost();
diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h
index aa6c0ed..d6a616d 100644
--- a/Source/CursesDialog/cmCursesMainForm.h
+++ b/Source/CursesDialog/cmCursesMainForm.h
@@ -7,28 +7,37 @@
class cmCursesCacheEntryComposite;
+/** \class cmCursesMainForm
+ * \brief The main page of ccmake
+ *
+ * cmCursesMainForm is the main page of ccmake.
+ */
class cmCursesMainForm : public cmCursesForm
{
public:
cmCursesMainForm(std::vector<std::string> const& args);
virtual ~cmCursesMainForm();
- // Description:
- // Set the widgets which represent the cache entries.
+ /**
+ * Set the widgets which represent the cache entries.
+ */
void InitializeUI();
- // Description:
- // Handle user input.
+ /**
+ * Handle user input.
+ */
virtual void HandleInput();
- // Description:
- // Display form. Use a window of size width x height, starting
- // at top, left.
+ /**
+ * Display form. Use a window of size width x height, starting
+ * at top, left.
+ */
virtual void Render(int left, int top, int width, int height);
- // Description:
- // Returns true if an entry with the given key is in the
- // list of current composites.
+ /**
+ * Returns true if an entry with the given key is in the
+ * list of current composites.
+ */
bool LookForCacheEntry(const char* key);
enum {
@@ -38,47 +47,71 @@ public:
MAX_WIDTH = 512
};
- // Description:
- // This method should normally called only by the form.
- // The only exception is during a resize.
+ /**
+ * This method should normally called only by the form.
+ * The only exception is during a resize.
+ */
virtual void UpdateStatusBar();
- // Description:
- // This method should normally called only by the form.
- // The only exception is during a resize.
+ /**
+ * Display current commands and their keys on the toolbar.
+ * This method should normally called only by the form.
+ * The only exception is during a resize.
+ */
void PrintKeys();
- // Description:
- // During a CMake run, an error handle should add errors
- // to be displayed afterwards.
+ /**
+ * During a CMake run, an error handle should add errors
+ * to be displayed afterwards.
+ */
virtual void AddError(const char* message, const char* title);
- // Description:
- // Used to run cmake.
+ /**
+ * Used to run cmake.
+ */
void RunCMake(bool generateMakefiles);
protected:
cmCursesMainForm(const cmCursesMainForm& from);
void operator=(const cmCursesMainForm&);
+ // Copy the cache values from the user interface to the actual
+ // cache.
void FillCacheManagerFromUI();
+ // Re-post the existing fields. Used to toggle between
+ // normal and advanced modes. Render() should be called
+ // afterwards.
void RePost();
+ // Remove an entry from the interface and the cache.
void RemoveEntry(const char* value);
+ // Copies of cache entries stored in the user interface
std::vector<cmCursesCacheEntryComposite*>* m_Entries;
+ // Errors produced during last run of cmake
std::vector<std::string> m_Errors;
+ // Command line argumens to be passed to cmake each time
+ // it is run
std::vector<std::string> m_Args;
+ // Message displayed when user presses 'h'
+ // It is: Welcome + info about current entry + common help
std::vector<std::string> m_HelpMessage;
+ // Common help
static const char* s_ConstHelpMessage;
+ // Fields displayed. Includes labels, new entry markers, entries
FIELD** m_Fields;
+ // Where is source of current project
std::string m_WhereSource;
+ // Where is cmake executable
std::string m_WhereCMake;
- int m_Height;
+ // Number of entries shown (depends on mode -normal or advanced-)
int m_NumberOfVisibleEntries;
bool m_AdvancedMode;
+ // Did the iteration converge (no new entries) ?
bool m_OkToGenerate;
+ // Number of pages displayed
+ int m_NumberOfPages;
};
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx
index 8273fdf..b32984b 100644
--- a/Source/CursesDialog/cmCursesStringWidget.cxx
+++ b/Source/CursesDialog/cmCursesStringWidget.cxx
@@ -1,5 +1,5 @@
#include "cmCursesStringWidget.h"
-#include "cmCursesForm.h"
+#include "cmCursesMainForm.h"
inline int ctrl(int z)
{
@@ -18,8 +18,12 @@ cmCursesStringWidget::cmCursesStringWidget(int width, int height,
}
-bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
+bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
+ WINDOW* w)
{
+ int x,y;
+
+ FORM* form = fm->GetForm();
// 10 == enter
if (!m_InEdit && ( key != 10 ) )
{
@@ -35,6 +39,26 @@ bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
{
sprintf(debugMessage, "String widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
+
+ fm->PrintKeys();
+
+ getmaxyx(stdscr, y, x);
+ // If window too small, handle 'q' only
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ // quit
+ if ( key == 'q' )
+ {
+ return false;
+ }
+ else
+ {
+ key=getch();
+ continue;
+ }
+ }
+
// If resize occured during edit, move out of edit mode
if (!m_InEdit && ( key != 10 && key != KEY_ENTER ) )
{
@@ -47,6 +71,7 @@ bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
{
cmCursesForm::LogMessage("String widget leaving edit.");
m_InEdit = false;
+ fm->PrintKeys();
delete[] originalStr;
// trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD);
@@ -57,6 +82,7 @@ bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
{
cmCursesForm::LogMessage("String widget entering edit.");
m_InEdit = true;
+ fm->PrintKeys();
char* buf = field_buffer(m_Field, 0);
originalStr = new char[strlen(buf)+1];
strcpy(originalStr, buf);
@@ -80,6 +106,7 @@ bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
if (m_InEdit)
{
m_InEdit = false;
+ fm->PrintKeys();
this->SetString(originalStr);
delete[] originalStr;
touchwin(w);
@@ -138,3 +165,41 @@ const char* cmCursesStringWidget::GetValue()
{
return field_buffer(m_Field, 0);
}
+
+bool cmCursesStringWidget::PrintKeys()
+{
+ int x,y;
+ getmaxyx(stdscr, y, x);
+ if ( x < cmCursesMainForm::MIN_WIDTH ||
+ y < cmCursesMainForm::MIN_HEIGHT )
+ {
+ return false;
+ }
+ if (m_InEdit)
+ {
+ char firstLine[512];
+ // Clean the toolbar
+ for(int i=0; i<512; i++)
+ {
+ firstLine[i] = ' ';
+ }
+ firstLine[511] = '\0';
+ curses_move(y-4,0);
+ printw(firstLine);
+ curses_move(y-3,0);
+ printw(firstLine);
+ curses_move(y-2,0);
+ printw(firstLine);
+ curses_move(y-1,0);
+ printw(firstLine);
+
+ sprintf(firstLine, "Editing option, press [enter] to leave edit.");
+ curses_move(y-3,0);
+ printw(firstLine);
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h
index 29fb281..0153843 100644
--- a/Source/CursesDialog/cmCursesStringWidget.h
+++ b/Source/CursesDialog/cmCursesStringWidget.h
@@ -3,31 +3,49 @@
#include "cmCursesWidget.h"
+class cmCursesMainForm;
+
+/** \class cmCursesStringWidget
+ * \brief A simple entry widget.
+ *
+ * cmCursesStringWdiget is a simple text entry widget.
+ */
+
class cmCursesStringWidget : public cmCursesWidget
{
public:
cmCursesStringWidget(int width, int height, int left, int top);
- // Description:
- // Handle user input. Called by the container of this widget
- // when this widget has focus. Returns true if the input was
- // handled.
- virtual bool HandleInput(int& key, FORM* form, WINDOW* w);
-
- // Description:
- // Set/Get the string.
+ /**
+ * Handle user input. Called by the container of this widget
+ * when this widget has focus. Returns true if the input was
+ * handled.
+ */
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
+
+ /**
+ * Set/Get the string.
+ */
void SetString(const char* value);
const char* GetString();
virtual const char* GetValue();
- // Description:
- // Set/Get InEdit flag. Can be used to tell the widget to leave
- // edit mode (in case of a resize for example).
+ /**
+ * Set/Get InEdit flag. Can be used to tell the widget to leave
+ * edit mode (in case of a resize for example).
+ */
void SetInEdit(bool inedit)
{ m_InEdit = inedit; }
bool GetInEdit()
{ return m_InEdit; }
+ /**
+ * If there are any, print the widget specific commands
+ * in the toolbar and return true. Otherwise, return false
+ * and the parent widget will print.
+ */
+ virtual bool PrintKeys();
+
protected:
cmCursesStringWidget(const cmCursesStringWidget& from);
void operator=(const cmCursesStringWidget&);
diff --git a/Source/CursesDialog/cmCursesWidget.cxx b/Source/CursesDialog/cmCursesWidget.cxx
index 55c9e76..6852814 100644
--- a/Source/CursesDialog/cmCursesWidget.cxx
+++ b/Source/CursesDialog/cmCursesWidget.cxx
@@ -5,6 +5,7 @@ cmCursesWidget::cmCursesWidget(int width, int height, int left, int top)
m_Field = new_field(height, width, top, left, 0, 0);
set_field_userptr(m_Field, reinterpret_cast<char*>(this));
field_opts_off(m_Field, O_AUTOSKIP);
+ m_Page = 0;
}
cmCursesWidget::~cmCursesWidget()
diff --git a/Source/CursesDialog/cmCursesWidget.h b/Source/CursesDialog/cmCursesWidget.h
index a516bca..f4822a5 100644
--- a/Source/CursesDialog/cmCursesWidget.h
+++ b/Source/CursesDialog/cmCursesWidget.h
@@ -4,34 +4,62 @@
#include "../cmCacheManager.h"
#include "cmCursesStandardIncludes.h"
+class cmCursesMainForm;
+
class cmCursesWidget
{
public:
cmCursesWidget(int width, int height, int left, int top);
virtual ~cmCursesWidget();
- // Description:
- // Handle user input. Called by the container of this widget
- // when this widget has focus. Returns true if the input was
- // handled
- virtual bool HandleInput(int& key, FORM* form, WINDOW* w) = 0;
-
- // Description:
- // Change the position of the widget. Set isNewPage to true
- // if this widget marks the beginning of a new page.
+ /**
+ * Handle user input. Called by the container of this widget
+ * when this widget has focus. Returns true if the input was
+ * handled
+ */
+ virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) = 0;
+
+ /**
+ * Change the position of the widget. Set isNewPage to true
+ * if this widget marks the beginning of a new page.
+ */
virtual void Move(int x, int y, bool isNewPage);
- // Description:
- // Set/Get the value (setting the value also changes the contents
- // of the field buffer).
+ /**
+ * Set/Get the value (setting the value also changes the contents
+ * of the field buffer).
+ */
virtual void SetValue(const char* value);
virtual const char* GetValue();
- // Description:
- // Get the type of the widget (STRING, PATH etc...)
+ /**
+ * Get the type of the widget (STRING, PATH etc...)
+ */
cmCacheManager::CacheEntryType GetType()
{ return m_Type; }
+ /**
+ * If there are any, print the widget specific commands
+ * in the toolbar and return true. Otherwise, return false
+ * and the parent widget will print.
+ */
+ virtual bool PrintKeys()
+ {
+ return false;
+ }
+
+ /**
+ * Set/Get the page this widget is in.
+ */
+ void SetPage(int page)
+ {
+ m_Page = page;
+ }
+ int GetPage()
+ {
+ return m_Page;
+ }
+
friend class cmCursesMainForm;
protected:
@@ -41,6 +69,8 @@ protected:
cmCacheManager::CacheEntryType m_Type;
std::string m_Value;
FIELD* m_Field;
+ // The page in the main form this widget is in
+ int m_Page;
};
#endif // __cmCursesWidget_h