Updated toolbar.

This commit is contained in:
Berk Geveci 2001-12-13 13:28:41 -05:00
parent 10085174b6
commit 69cb66f7ff
14 changed files with 328 additions and 86 deletions

View File

@ -1,4 +1,5 @@
#include "cmCursesBoolWidget.h" #include "cmCursesBoolWidget.h"
#include "cmCursesMainForm.h"
cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
int left, int top) : int left, int top) :
@ -11,8 +12,10 @@ cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
this->SetValueAsBool(false); 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 // 10 == enter
if (key == 10 || key == KEY_ENTER) if (key == 10 || key == KEY_ENTER)
{ {

View File

@ -2,6 +2,7 @@
#define __cmCursesBoolWidget_h #define __cmCursesBoolWidget_h
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
class cmCursesMainForm;
class cmCursesBoolWidget : public cmCursesWidget class cmCursesBoolWidget : public cmCursesWidget
{ {
@ -12,7 +13,7 @@ public:
// Handle user input. Called by the container of this widget // Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was // when this widget has focus. Returns true if the input was
// handled. // handled.
virtual bool HandleInput(int& key, FORM* form, WINDOW* w); virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
// Description: // Description:
// Set/Get the value (on/off). // Set/Get the value (on/off).

View File

@ -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; return false;
} }

View File

@ -3,6 +3,8 @@
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
class cmCursesMainForm;
class cmCursesDummyWidget : public cmCursesWidget class cmCursesDummyWidget : public cmCursesWidget
{ {
public: public:
@ -12,7 +14,7 @@ public:
// Handle user input. Called by the container of this widget // Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was // when this widget has focus. Returns true if the input was
// handled. // handled.
virtual bool HandleInput(int& key, FORM* form, WINDOW* w); virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
protected: protected:
cmCursesDummyWidget(const cmCursesDummyWidget& from); cmCursesDummyWidget(const cmCursesDummyWidget& from);

View File

@ -39,7 +39,14 @@ public:
// Description: // Description:
// Write a debugging message. // Write a debugging message.
static void LogMessage(const char* msg); 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; static cmCursesForm* CurrentForm;

View File

@ -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. // Static text. No input is handled here.
return false; return false;

View File

@ -4,6 +4,7 @@
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
#include "cmCursesStandardIncludes.h" #include "cmCursesStandardIncludes.h"
class cmCursesMainForm;
class cmCursesLabelWidget : public cmCursesWidget class cmCursesLabelWidget : public cmCursesWidget
{ {
@ -16,7 +17,7 @@ public:
// Handle user input. Called by the container of this widget // Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was // when this widget has focus. Returns true if the input was
// handled // handled
virtual bool HandleInput(int& key, FORM* form, WINDOW* w); virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
protected: protected:
cmCursesLabelWidget(const cmCursesLabelWidget& from); cmCursesLabelWidget(const cmCursesLabelWidget& from);

View File

@ -89,7 +89,7 @@ void cmCursesLongMessageForm::PrintKeys()
return; return;
} }
char firstLine[512]; char firstLine[512];
sprintf(firstLine, "O)k"); sprintf(firstLine, "Press [e] to exit help");
curses_move(y-2,0); curses_move(y-2,0);
printw(firstLine); printw(firstLine);
@ -166,7 +166,7 @@ void cmCursesLongMessageForm::HandleInput()
cmCursesForm::LogMessage(debugMessage); cmCursesForm::LogMessage(debugMessage);
// quit // quit
if ( key == 'o' ) if ( key == 'o' || key == 'e' )
{ {
break; break;
} }

View File

@ -20,8 +20,8 @@ inline int ctrl(int z)
cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args) : cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args) :
m_Args(args) m_Args(args)
{ {
m_NumberOfPages = 0;
m_Fields = 0; m_Fields = 0;
m_Height = 0;
m_Entries = 0; m_Entries = 0;
m_AdvancedMode = false; m_AdvancedMode = false;
m_NumberOfVisibleEntries = 0; m_NumberOfVisibleEntries = 0;
@ -53,6 +53,7 @@ cmCursesMainForm::~cmCursesMainForm()
delete m_Entries; delete m_Entries;
} }
// See if a cache entry is in the list of entries in the ui.
bool cmCursesMainForm::LookForCacheEntry(const char* key) bool cmCursesMainForm::LookForCacheEntry(const char* key)
{ {
if (!key || !m_Entries) if (!key || !m_Entries)
@ -72,6 +73,7 @@ bool cmCursesMainForm::LookForCacheEntry(const char* key)
return false; return false;
} }
// Create new cmCursesCacheEntryComposite entries from the cache
void cmCursesMainForm::InitializeUI() void cmCursesMainForm::InitializeUI()
{ {
@ -79,6 +81,8 @@ void cmCursesMainForm::InitializeUI()
const cmCacheManager::CacheEntryMap &cache = const cmCacheManager::CacheEntryMap &cache =
cmCacheManager::GetInstance()->GetCacheMap(); cmCacheManager::GetInstance()->GetCacheMap();
// Create a vector of cmCursesCacheEntryComposite's
// which contain labels, entries and new entry markers
std::vector<cmCursesCacheEntryComposite*>* newEntries = std::vector<cmCursesCacheEntryComposite*>* newEntries =
new std::vector<cmCursesCacheEntryComposite*>; new std::vector<cmCursesCacheEntryComposite*>;
newEntries->reserve(cache.size()); newEntries->reserve(cache.size());
@ -149,8 +153,10 @@ void cmCursesMainForm::InitializeUI()
} }
} }
// Clean old entries
if (m_Entries) if (m_Entries)
{ {
// Have to call delete on each pointer
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++it) for (it = m_Entries->begin(); it != m_Entries->end(); ++it)
{ {
@ -160,6 +166,7 @@ void cmCursesMainForm::InitializeUI()
delete m_Entries; delete m_Entries;
m_Entries = newEntries; m_Entries = newEntries;
// Compute fields from composites
this->RePost(); this->RePost();
} }
@ -181,6 +188,7 @@ void cmCursesMainForm::RePost()
} }
else else
{ {
// If normal mode, count only non-advanced entries
m_NumberOfVisibleEntries = 0; m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++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]; m_Fields = new FIELD*[3*m_NumberOfVisibleEntries+1];
// Assign fields
int j=0; int j=0;
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++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); FIELD* currentField = current_field(m_Form);
cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*> cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
(field_userptr(currentField)); (field_userptr(currentField));
// If in edit mode, get out of it
if ( cw->GetType() == cmCacheManager::STRING || if ( cw->GetType() == cmCacheManager::STRING ||
cw->GetType() == cmCacheManager::PATH || cw->GetType() == cmCacheManager::PATH ||
cw->GetType() == cmCacheManager::FILEPATH ) 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); cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
sw->SetInEdit(false); sw->SetInEdit(false);
} }
// Delete the previous form
unpost_form(m_Form); unpost_form(m_Form);
free_form(m_Form); free_form(m_Form);
m_Form = 0; m_Form = 0;
} }
// Wrong window size
if ( width < cmCursesMainForm::MIN_WIDTH || if ( width < cmCursesMainForm::MIN_WIDTH ||
height < cmCursesMainForm::MIN_HEIGHT ) height < cmCursesMainForm::MIN_HEIGHT )
{ {
return; return;
} }
height -= 6; // Leave room for toolbar
m_Height = height; height -= 7;
if (m_AdvancedMode) if (m_AdvancedMode)
{ {
@ -249,6 +264,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
} }
else else
{ {
// If normal, display only non-advanced entries
m_NumberOfVisibleEntries = 0; m_NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++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; bool isNewPage;
int i=0; int i=0;
m_NumberOfPages = 1;
std::vector<cmCursesCacheEntryComposite*>::iterator it; std::vector<cmCursesCacheEntryComposite*>::iterator it;
for (it = m_Entries->begin(); it != m_Entries->end(); ++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; int page = (i / height) + 1;
isNewPage = ( page > 1 ) && ( row == 1 ); isNewPage = ( page > 1 ) && ( row == 1 );
if (isNewPage)
{
m_NumberOfPages++;
}
(*it)->m_Label->Move(left, top+row-1, isNewPage); (*it)->m_Label->Move(left, top+row-1, isNewPage);
(*it)->m_IsNewLabel->Move(left+32, top+row-1, false); (*it)->m_IsNewLabel->Move(left+32, top+row-1, false);
(*it)->m_Entry->Move(left+33, top+row-1, false); (*it)->m_Entry->Move(left+33, top+row-1, false);
(*it)->m_Entry->SetPage(m_NumberOfPages);
i++; i++;
} }
// Post the form
m_Form = new_form(m_Fields); m_Form = new_form(m_Fields);
post_form(m_Form); post_form(m_Form);
// Update toolbar
this->UpdateStatusBar(); this->UpdateStatusBar();
this->PrintKeys(); this->PrintKeys()
;
touchwin(stdscr); touchwin(stdscr);
refresh(); refresh();
} }
@ -299,28 +325,58 @@ void cmCursesMainForm::PrintKeys()
{ {
return; return;
} }
char firstLine[512], secondLine[512];
if (m_OkToGenerate) // Give the current widget (if it exists), a chance to print keys
cmCursesWidget* cw = 0;
if (m_Form)
{ {
sprintf(firstLine, "C)onfigure G)enerate and Exit H)elp"); FIELD* currentField = current_field(m_Form);
} cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
else }
{
sprintf(firstLine, "C)onfigure H)elp"); if (cw && cw->PrintKeys())
} {
if (m_AdvancedMode) }
{ else
sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (On)"); {
} char firstLine[512], secondLine[512], thirdLine[512];
else if (m_OkToGenerate)
{ {
sprintf(secondLine, "Q)uit Without Generating T)oggle Advanced Mode (Off)"); 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); pos_form_cursor(m_Form);
} }
@ -331,6 +387,7 @@ void cmCursesMainForm::UpdateStatusBar()
{ {
int x,y; int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
// If window size is too small, display error and return
if ( x < cmCursesMainForm::MIN_WIDTH || if ( x < cmCursesMainForm::MIN_WIDTH ||
y < cmCursesMainForm::MIN_HEIGHT ) y < cmCursesMainForm::MIN_HEIGHT )
{ {
@ -343,12 +400,15 @@ void cmCursesMainForm::UpdateStatusBar()
return; return;
} }
// Get the key of the current entry
FIELD* cur = current_field(m_Form); FIELD* cur = current_field(m_Form);
int index = field_index(cur); int index = field_index(cur);
cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr( cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
m_Fields[index-2])); m_Fields[index-2]));
const char* curField = lbl->GetValue(); const char* curField = lbl->GetValue();
// Get the help string of the current entry
// and add it to the help string
char help[128]; char help[128];
const char* helpString; const char* helpString;
cmCacheManager::CacheEntry *entry = 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]; char bar[cmCursesMainForm::MAX_WIDTH];
int i, curFieldLen = strlen(curField); int i, curFieldLen = strlen(curField);
int helpLen = strlen(help); int helpLen = strlen(help);
@ -405,6 +467,7 @@ void cmCursesMainForm::UpdateStatusBar()
bar[width] = '\0'; bar[width] = '\0';
// Display CMake version info on the next line
// We want to display this on the right // We want to display this on the right
char version[cmCursesMainForm::MAX_WIDTH]; char version[cmCursesMainForm::MAX_WIDTH];
char vertmp[128]; char vertmp[128];
@ -415,11 +478,12 @@ void cmCursesMainForm::UpdateStatusBar()
sprintf(version+sideSpace, "%s", vertmp); sprintf(version+sideSpace, "%s", vertmp);
version[width] = '\0'; version[width] = '\0';
curses_move(y-4,0); // Now print both lines
curses_move(y-5,0);
attron(A_STANDOUT); attron(A_STANDOUT);
printw(bar); printw(bar);
attroff(A_STANDOUT); attroff(A_STANDOUT);
curses_move(y-3,0); curses_move(y-4,0);
printw(version); printw(version);
pos_form_cursor(m_Form); pos_form_cursor(m_Form);
} }
@ -535,6 +599,8 @@ void cmCursesMainForm::FillCacheManagerFromUI()
void cmCursesMainForm::HandleInput() void cmCursesMainForm::HandleInput()
{ {
int x,y;
if (!m_Form) if (!m_Form)
{ {
return; return;
@ -551,12 +617,31 @@ void cmCursesMainForm::HandleInput()
this->PrintKeys(); this->PrintKeys();
int key = getch(); 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); currentField = current_field(m_Form);
currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr( currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
currentField)); 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); sprintf(debugMessage, "Main form handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage); cmCursesForm::LogMessage(debugMessage);
// quit // quit
@ -627,7 +712,6 @@ void cmCursesMainForm::HandleInput()
// display help // display help
else if ( key == 'h' ) else if ( key == 'h' )
{ {
int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
FIELD* cur = current_field(m_Form); FIELD* cur = current_field(m_Form);
@ -666,7 +750,6 @@ void cmCursesMainForm::HandleInput()
// display last errors // display last errors
else if ( key == 'l' ) else if ( key == 'l' )
{ {
int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors, cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(m_Errors,
"Errors which during last pass."); "Errors which during last pass.");
@ -687,7 +770,6 @@ void cmCursesMainForm::HandleInput()
{ {
m_AdvancedMode = true; m_AdvancedMode = true;
} }
int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
this->RePost(); this->RePost();
this->Render(1, 1, x, y); this->Render(1, 1, x, y);
@ -740,7 +822,6 @@ void cmCursesMainForm::HandleInput()
nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue()); nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
} }
int x,y;
getmaxyx(stdscr, y, x); getmaxyx(stdscr, y, x);
this->RemoveEntry(lbl->GetValue()); this->RemoveEntry(lbl->GetValue());
this->RePost(); this->RePost();

View File

@ -7,28 +7,37 @@
class cmCursesCacheEntryComposite; class cmCursesCacheEntryComposite;
/** \class cmCursesMainForm
* \brief The main page of ccmake
*
* cmCursesMainForm is the main page of ccmake.
*/
class cmCursesMainForm : public cmCursesForm class cmCursesMainForm : public cmCursesForm
{ {
public: public:
cmCursesMainForm(std::vector<std::string> const& args); cmCursesMainForm(std::vector<std::string> const& args);
virtual ~cmCursesMainForm(); virtual ~cmCursesMainForm();
// Description: /**
// Set the widgets which represent the cache entries. * Set the widgets which represent the cache entries.
*/
void InitializeUI(); void InitializeUI();
// Description: /**
// Handle user input. * Handle user input.
*/
virtual void HandleInput(); virtual void HandleInput();
// Description: /**
// Display form. Use a window of size width x height, starting * Display form. Use a window of size width x height, starting
// at top, left. * at top, left.
*/
virtual void Render(int left, int top, int width, int height); virtual void Render(int left, int top, int width, int height);
// Description: /**
// Returns true if an entry with the given key is in the * Returns true if an entry with the given key is in the
// list of current composites. * list of current composites.
*/
bool LookForCacheEntry(const char* key); bool LookForCacheEntry(const char* key);
enum { enum {
@ -38,47 +47,71 @@ public:
MAX_WIDTH = 512 MAX_WIDTH = 512
}; };
// Description: /**
// This method should normally called only by the form. * This method should normally called only by the form.
// The only exception is during a resize. * The only exception is during a resize.
*/
virtual void UpdateStatusBar(); virtual void UpdateStatusBar();
// Description: /**
// This method should normally called only by the form. * Display current commands and their keys on the toolbar.
// The only exception is during a resize. * This method should normally called only by the form.
* The only exception is during a resize.
*/
void PrintKeys(); void PrintKeys();
// Description: /**
// During a CMake run, an error handle should add errors * During a CMake run, an error handle should add errors
// to be displayed afterwards. * to be displayed afterwards.
*/
virtual void AddError(const char* message, const char* title); virtual void AddError(const char* message, const char* title);
// Description: /**
// Used to run cmake. * Used to run cmake.
*/
void RunCMake(bool generateMakefiles); void RunCMake(bool generateMakefiles);
protected: protected:
cmCursesMainForm(const cmCursesMainForm& from); cmCursesMainForm(const cmCursesMainForm& from);
void operator=(const cmCursesMainForm&); void operator=(const cmCursesMainForm&);
// Copy the cache values from the user interface to the actual
// cache.
void FillCacheManagerFromUI(); void FillCacheManagerFromUI();
// Re-post the existing fields. Used to toggle between
// normal and advanced modes. Render() should be called
// afterwards.
void RePost(); void RePost();
// Remove an entry from the interface and the cache.
void RemoveEntry(const char* value); void RemoveEntry(const char* value);
// Copies of cache entries stored in the user interface
std::vector<cmCursesCacheEntryComposite*>* m_Entries; std::vector<cmCursesCacheEntryComposite*>* m_Entries;
// Errors produced during last run of cmake
std::vector<std::string> m_Errors; 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; 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; std::vector<std::string> m_HelpMessage;
// Common help
static const char* s_ConstHelpMessage; static const char* s_ConstHelpMessage;
// Fields displayed. Includes labels, new entry markers, entries
FIELD** m_Fields; FIELD** m_Fields;
// Where is source of current project
std::string m_WhereSource; std::string m_WhereSource;
// Where is cmake executable
std::string m_WhereCMake; std::string m_WhereCMake;
int m_Height; // Number of entries shown (depends on mode -normal or advanced-)
int m_NumberOfVisibleEntries; int m_NumberOfVisibleEntries;
bool m_AdvancedMode; bool m_AdvancedMode;
// Did the iteration converge (no new entries) ?
bool m_OkToGenerate; bool m_OkToGenerate;
// Number of pages displayed
int m_NumberOfPages;
}; };

View File

@ -1,5 +1,5 @@
#include "cmCursesStringWidget.h" #include "cmCursesStringWidget.h"
#include "cmCursesForm.h" #include "cmCursesMainForm.h"
inline int ctrl(int z) 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 // 10 == enter
if (!m_InEdit && ( key != 10 ) ) 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); sprintf(debugMessage, "String widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage); 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 resize occured during edit, move out of edit mode
if (!m_InEdit && ( key != 10 && key != KEY_ENTER ) ) 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."); cmCursesForm::LogMessage("String widget leaving edit.");
m_InEdit = false; m_InEdit = false;
fm->PrintKeys();
delete[] originalStr; delete[] originalStr;
// trick to force forms to update the field buffer // trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD); 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."); cmCursesForm::LogMessage("String widget entering edit.");
m_InEdit = true; m_InEdit = true;
fm->PrintKeys();
char* buf = field_buffer(m_Field, 0); char* buf = field_buffer(m_Field, 0);
originalStr = new char[strlen(buf)+1]; originalStr = new char[strlen(buf)+1];
strcpy(originalStr, buf); strcpy(originalStr, buf);
@ -80,6 +106,7 @@ bool cmCursesStringWidget::HandleInput(int& key, FORM* form, WINDOW* w)
if (m_InEdit) if (m_InEdit)
{ {
m_InEdit = false; m_InEdit = false;
fm->PrintKeys();
this->SetString(originalStr); this->SetString(originalStr);
delete[] originalStr; delete[] originalStr;
touchwin(w); touchwin(w);
@ -138,3 +165,41 @@ const char* cmCursesStringWidget::GetValue()
{ {
return field_buffer(m_Field, 0); 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;
}
}

View File

@ -3,31 +3,49 @@
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
class cmCursesMainForm;
/** \class cmCursesStringWidget
* \brief A simple entry widget.
*
* cmCursesStringWdiget is a simple text entry widget.
*/
class cmCursesStringWidget : public cmCursesWidget class cmCursesStringWidget : public cmCursesWidget
{ {
public: public:
cmCursesStringWidget(int width, int height, int left, int top); cmCursesStringWidget(int width, int height, int left, int top);
// Description: /**
// Handle user input. Called by the container of this widget * Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was * when this widget has focus. Returns true if the input was
// handled. * handled.
virtual bool HandleInput(int& key, FORM* form, WINDOW* w); */
virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
// Description: /**
// Set/Get the string. * Set/Get the string.
*/
void SetString(const char* value); void SetString(const char* value);
const char* GetString(); const char* GetString();
virtual const char* GetValue(); virtual const char* GetValue();
// Description: /**
// Set/Get InEdit flag. Can be used to tell the widget to leave * Set/Get InEdit flag. Can be used to tell the widget to leave
// edit mode (in case of a resize for example). * edit mode (in case of a resize for example).
*/
void SetInEdit(bool inedit) void SetInEdit(bool inedit)
{ m_InEdit = inedit; } { m_InEdit = inedit; }
bool GetInEdit() bool GetInEdit()
{ return m_InEdit; } { 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: protected:
cmCursesStringWidget(const cmCursesStringWidget& from); cmCursesStringWidget(const cmCursesStringWidget& from);
void operator=(const cmCursesStringWidget&); void operator=(const cmCursesStringWidget&);

View File

@ -5,6 +5,7 @@ cmCursesWidget::cmCursesWidget(int width, int height, int left, int top)
m_Field = new_field(height, width, top, left, 0, 0); m_Field = new_field(height, width, top, left, 0, 0);
set_field_userptr(m_Field, reinterpret_cast<char*>(this)); set_field_userptr(m_Field, reinterpret_cast<char*>(this));
field_opts_off(m_Field, O_AUTOSKIP); field_opts_off(m_Field, O_AUTOSKIP);
m_Page = 0;
} }
cmCursesWidget::~cmCursesWidget() cmCursesWidget::~cmCursesWidget()

View File

@ -4,34 +4,62 @@
#include "../cmCacheManager.h" #include "../cmCacheManager.h"
#include "cmCursesStandardIncludes.h" #include "cmCursesStandardIncludes.h"
class cmCursesMainForm;
class cmCursesWidget class cmCursesWidget
{ {
public: public:
cmCursesWidget(int width, int height, int left, int top); cmCursesWidget(int width, int height, int left, int top);
virtual ~cmCursesWidget(); virtual ~cmCursesWidget();
// Description: /**
// Handle user input. Called by the container of this widget * Handle user input. Called by the container of this widget
// when this widget has focus. Returns true if the input was * when this widget has focus. Returns true if the input was
// handled * handled
virtual bool HandleInput(int& key, FORM* form, WINDOW* w) = 0; */
virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w) = 0;
// Description: /**
// Change the position of the widget. Set isNewPage to true * Change the position of the widget. Set isNewPage to true
// if this widget marks the beginning of a new page. * if this widget marks the beginning of a new page.
*/
virtual void Move(int x, int y, bool isNewPage); virtual void Move(int x, int y, bool isNewPage);
// Description: /**
// Set/Get the value (setting the value also changes the contents * Set/Get the value (setting the value also changes the contents
// of the field buffer). * of the field buffer).
*/
virtual void SetValue(const char* value); virtual void SetValue(const char* value);
virtual const char* GetValue(); 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() cmCacheManager::CacheEntryType GetType()
{ return m_Type; } { 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; friend class cmCursesMainForm;
protected: protected:
@ -41,6 +69,8 @@ protected:
cmCacheManager::CacheEntryType m_Type; cmCacheManager::CacheEntryType m_Type;
std::string m_Value; std::string m_Value;
FIELD* m_Field; FIELD* m_Field;
// The page in the main form this widget is in
int m_Page;
}; };
#endif // __cmCursesWidget_h #endif // __cmCursesWidget_h