summaryrefslogtreecommitdiffstats
path: root/Source/CursesDialog
diff options
context:
space:
mode:
Diffstat (limited to 'Source/CursesDialog')
-rw-r--r--Source/CursesDialog/ccmake.cxx147
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.cxx49
-rw-r--r--Source/CursesDialog/cmCursesBoolWidget.h1
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.cxx77
-rw-r--r--Source/CursesDialog/cmCursesCacheEntryComposite.h5
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.cxx10
-rw-r--r--Source/CursesDialog/cmCursesDummyWidget.h1
-rw-r--r--Source/CursesDialog/cmCursesFilePathWidget.cxx7
-rw-r--r--Source/CursesDialog/cmCursesFilePathWidget.h1
-rw-r--r--Source/CursesDialog/cmCursesForm.cxx15
-rw-r--r--Source/CursesDialog/cmCursesForm.h7
-rw-r--r--Source/CursesDialog/cmCursesLabelWidget.cxx15
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.cxx133
-rw-r--r--Source/CursesDialog/cmCursesLongMessageForm.h1
-rw-r--r--Source/CursesDialog/cmCursesMainForm.cxx1136
-rw-r--r--Source/CursesDialog/cmCursesMainForm.h17
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.cxx61
-rw-r--r--Source/CursesDialog/cmCursesOptionsWidget.h3
-rw-r--r--Source/CursesDialog/cmCursesPathWidget.cxx54
-rw-r--r--Source/CursesDialog/cmCursesStandardIncludes.h9
-rw-r--r--Source/CursesDialog/cmCursesStringWidget.cxx166
-rw-r--r--Source/CursesDialog/cmCursesWidget.cxx23
-rw-r--r--Source/CursesDialog/cmCursesWidget.h18
23 files changed, 803 insertions, 1153 deletions
diff --git a/Source/CursesDialog/ccmake.cxx b/Source/CursesDialog/ccmake.cxx
index 6eccf54..be8751c 100644
--- a/Source/CursesDialog/ccmake.cxx
+++ b/Source/CursesDialog/ccmake.cxx
@@ -23,68 +23,56 @@
#include <form.h>
-static const char * cmDocumentationName[][2] =
-{
- {0,
- " ccmake - Curses Interface for CMake."},
- {0,0}
+static const char* cmDocumentationName[][2] = {
+ { 0, " ccmake - Curses Interface for CMake." },
+ { 0, 0 }
};
-static const char * cmDocumentationUsage[][2] =
-{
- {0,
- " ccmake <path-to-source>\n"
- " ccmake <path-to-existing-build>"},
- {0,
- "Specify a source directory to (re-)generate a build system for "
- "it in the current working directory. Specify an existing build "
- "directory to re-generate its build system."},
- {0,0}
+static const char* cmDocumentationUsage[][2] = {
+ { 0, " ccmake <path-to-source>\n"
+ " ccmake <path-to-existing-build>" },
+ { 0, "Specify a source directory to (re-)generate a build system for "
+ "it in the current working directory. Specify an existing build "
+ "directory to re-generate its build system." },
+ { 0, 0 }
};
-static const char * cmDocumentationUsageNote[][2] =
-{
- {0,
- "Run 'ccmake --help' for more information."},
- {0,0}
+static const char* cmDocumentationUsageNote[][2] = {
+ { 0, "Run 'ccmake --help' for more information." },
+ { 0, 0 }
};
-static const char * cmDocumentationOptions[][2] =
-{
- CMAKE_STANDARD_OPTIONS_TABLE,
- {0,0}
-};
+static const char* cmDocumentationOptions[]
+ [2] = { CMAKE_STANDARD_OPTIONS_TABLE,
+ { 0, 0 } };
-cmCursesForm* cmCursesForm::CurrentForm=0;
+cmCursesForm* cmCursesForm::CurrentForm = 0;
-extern "C"
-{
+extern "C" {
void onsig(int)
{
- if (cmCursesForm::CurrentForm)
- {
+ if (cmCursesForm::CurrentForm) {
endwin();
- initscr(); /* Initialization */
- noecho(); /* Echo off */
- cbreak(); /* nl- or cr not needed */
- keypad(stdscr,TRUE); /* Use key symbols as
- KEY_DOWN*/
+ initscr(); /* Initialization */
+ noecho(); /* Echo off */
+ cbreak(); /* nl- or cr not needed */
+ keypad(stdscr, TRUE); /* Use key symbols as
+ KEY_DOWN*/
refresh();
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- cmCursesForm::CurrentForm->Render(1,1,x,y);
+ cmCursesForm::CurrentForm->Render(1, 1, x, y);
cmCursesForm::CurrentForm->UpdateStatusBar();
- }
+ }
signal(SIGWINCH, onsig);
}
-
}
void CMakeMessageHandler(const char* message, const char* title, bool&,
void* clientData)
{
- cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
+ cmCursesForm* self = static_cast<cmCursesForm*>(clientData);
self->AddError(message, title);
}
@@ -98,8 +86,7 @@ int main(int argc, char const* const* argv)
cmSystemTools::FindCMakeResources(argv[0]);
cmDocumentation doc;
doc.addCMakeStandardDocSections();
- if(doc.CheckOptions(argc, argv))
- {
+ if (doc.CheckOptions(argc, argv)) {
cmake hcm;
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
@@ -107,95 +94,82 @@ int main(int argc, char const* const* argv)
std::vector<cmDocumentationEntry> generators;
hcm.GetGeneratorDocumentation(generators);
doc.SetName("ccmake");
- doc.SetSection("Name",cmDocumentationName);
- doc.SetSection("Usage",cmDocumentationUsage);
- if ( argc == 1 )
- {
- doc.AppendSection("Usage",cmDocumentationUsageNote);
- }
- doc.SetSection("Generators",generators);
- doc.PrependSection("Options",cmDocumentationOptions);
- return doc.PrintRequestedDocumentation(std::cout)? 0:1;
+ doc.SetSection("Name", cmDocumentationName);
+ doc.SetSection("Usage", cmDocumentationUsage);
+ if (argc == 1) {
+ doc.AppendSection("Usage", cmDocumentationUsageNote);
}
+ doc.SetSection("Generators", generators);
+ doc.PrependSection("Options", cmDocumentationOptions);
+ return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1;
+ }
bool debug = false;
unsigned int i;
int j;
std::vector<std::string> args;
- for(j =0; j < argc; ++j)
- {
- if(strcmp(argv[j], "-debug") == 0)
- {
+ for (j = 0; j < argc; ++j) {
+ if (strcmp(argv[j], "-debug") == 0) {
debug = true;
- }
- else
- {
+ } else {
args.push_back(argv[j]);
- }
}
+ }
std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
- for(i=1; i < args.size(); ++i)
- {
+ for (i = 1; i < args.size(); ++i) {
std::string arg = args[i];
- if(arg.find("-B",0) == 0)
- {
+ if (arg.find("-B", 0) == 0) {
cacheDir = arg.substr(2);
- }
}
+ }
cmSystemTools::DisableRunCommandOutput();
- if (debug)
- {
+ if (debug) {
cmCursesForm::DebugStart();
- }
+ }
- initscr(); /* Initialization */
- noecho(); /* Echo off */
- cbreak(); /* nl- or cr not needed */
- keypad(stdscr,TRUE); /* Use key symbols as
- KEY_DOWN*/
+ initscr(); /* Initialization */
+ noecho(); /* Echo off */
+ cbreak(); /* nl- or cr not needed */
+ keypad(stdscr, TRUE); /* Use key symbols as
+ KEY_DOWN*/
signal(SIGWINCH, onsig);
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
endwin();
std::cerr << "Window is too small. A size of at least "
<< cmCursesMainForm::MIN_WIDTH << " x "
- << cmCursesMainForm::MIN_HEIGHT
- << " is required to run ccmake." << std::endl;
+ << cmCursesMainForm::MIN_HEIGHT << " is required to run ccmake."
+ << std::endl;
return 1;
- }
-
+ }
cmCursesMainForm* myform;
myform = new cmCursesMainForm(args, x);
- if(myform->LoadCache(cacheDir.c_str()))
- {
+ if (myform->LoadCache(cacheDir.c_str())) {
curses_clear();
touchwin(stdscr);
endwin();
delete myform;
std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
return 1;
- }
+ }
cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
cmCursesForm::CurrentForm = myform;
myform->InitializeUI();
- if ( myform->Configure(1) == 0 )
- {
+ if (myform->Configure(1) == 0) {
myform->Render(1, 1, x, y);
myform->HandleInput();
- }
+ }
// Need to clean-up better
curses_clear();
@@ -207,5 +181,4 @@ int main(int argc, char const* const* argv)
std::cout << std::endl << std::endl;
return 0;
-
}
diff --git a/Source/CursesDialog/cmCursesBoolWidget.cxx b/Source/CursesDialog/cmCursesBoolWidget.cxx
index 0529b78..0055e88 100644
--- a/Source/CursesDialog/cmCursesBoolWidget.cxx
+++ b/Source/CursesDialog/cmCursesBoolWidget.cxx
@@ -13,14 +13,14 @@
#include "cmCursesMainForm.h"
-cmCursesBoolWidget::cmCursesBoolWidget(int width, int height,
- int left, int top) :
- cmCursesWidget(width, height, left, top)
+cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
+ int top)
+ : cmCursesWidget(width, height, left, top)
{
this->Type = cmState::BOOL;
- set_field_fore(this->Field, A_NORMAL);
- set_field_back(this->Field, A_STANDOUT);
- field_opts_off(this->Field, O_STATIC);
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
this->SetValueAsBool(false);
}
@@ -28,48 +28,35 @@ bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
{
// 10 == enter
- if (key == 10 || key == KEY_ENTER)
- {
- if (this->GetValueAsBool())
- {
+ if (key == 10 || key == KEY_ENTER) {
+ if (this->GetValueAsBool()) {
this->SetValueAsBool(false);
- }
- else
- {
+ } else {
this->SetValueAsBool(true);
- }
+ }
touchwin(w);
wrefresh(w);
return true;
- }
- else
- {
+ } else {
return false;
- }
-
+ }
}
void cmCursesBoolWidget::SetValueAsBool(bool value)
{
- if (value)
- {
+ if (value) {
this->SetValue("ON");
- }
- else
- {
+ } else {
this->SetValue("OFF");
- }
+ }
}
bool cmCursesBoolWidget::GetValueAsBool()
{
- if (this->Value == "ON")
- {
+ if (this->Value == "ON") {
return true;
- }
- else
- {
+ } else {
return false;
- }
+ }
}
diff --git a/Source/CursesDialog/cmCursesBoolWidget.h b/Source/CursesDialog/cmCursesBoolWidget.h
index 65a8ddb..49be45a 100644
--- a/Source/CursesDialog/cmCursesBoolWidget.h
+++ b/Source/CursesDialog/cmCursesBoolWidget.h
@@ -35,7 +35,6 @@ public:
protected:
cmCursesBoolWidget(const cmCursesBoolWidget& from);
void operator=(const cmCursesBoolWidget&);
-
};
#endif // cmCursesBoolWidget_h
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
index 40c0eb6..bdfc8e9 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx
@@ -25,10 +25,10 @@
#include <assert.h>
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
- const std::string& key,
- int labelwidth,
- int entrywidth) :
- Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
+ const std::string& key, int labelwidth, int entrywidth)
+ : Key(key)
+ , LabelWidth(labelwidth)
+ , EntryWidth(entrywidth)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
@@ -37,35 +37,30 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
}
cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
- const std::string& key, cmake *cm, bool isNew,
- int labelwidth, int entrywidth)
- : Key(key), LabelWidth(labelwidth), EntryWidth(entrywidth)
+ const std::string& key, cmake* cm, bool isNew, int labelwidth,
+ int entrywidth)
+ : Key(key)
+ , LabelWidth(labelwidth)
+ , EntryWidth(entrywidth)
{
this->Label = new cmCursesLabelWidget(this->LabelWidth, 1, 1, 1, key);
- if (isNew)
- {
+ if (isNew) {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, "*");
- }
- else
- {
+ } else {
this->IsNewLabel = new cmCursesLabelWidget(1, 1, 1, 1, " ");
- }
+ }
this->Entry = 0;
const char* value = cm->GetState()->GetCacheEntryValue(key);
assert(value);
- switch (cm->GetState()->GetCacheEntryType(key))
- {
+ switch (cm->GetState()->GetCacheEntryType(key)) {
case cmState::BOOL:
this->Entry = new cmCursesBoolWidget(this->EntryWidth, 1, 1, 1);
- if (cmSystemTools::IsOn(value))
- {
+ if (cmSystemTools::IsOn(value)) {
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(true);
- }
- else
- {
+ } else {
static_cast<cmCursesBoolWidget*>(this->Entry)->SetValueAsBool(false);
- }
+ }
break;
case cmState::PATH:
this->Entry = new cmCursesPathWidget(this->EntryWidth, 1, 1, 1);
@@ -75,40 +70,33 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
this->Entry = new cmCursesFilePathWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesFilePathWidget*>(this->Entry)->SetString(value);
break;
- case cmState::STRING:
- {
- const char* stringsProp = cm->GetState()
- ->GetCacheEntryProperty(key, "STRINGS");
- if(stringsProp)
- {
+ case cmState::STRING: {
+ const char* stringsProp =
+ cm->GetState()->GetCacheEntryProperty(key, "STRINGS");
+ if (stringsProp) {
cmCursesOptionsWidget* ow =
new cmCursesOptionsWidget(this->EntryWidth, 1, 1, 1);
this->Entry = ow;
std::vector<std::string> options;
cmSystemTools::ExpandListArgument(stringsProp, options);
- for(std::vector<std::string>::iterator
- si = options.begin(); si != options.end(); ++si)
- {
+ for (std::vector<std::string>::iterator si = options.begin();
+ si != options.end(); ++si) {
ow->AddOption(*si);
- }
- ow->SetOption(value);
}
- else
- {
+ ow->SetOption(value);
+ } else {
this->Entry = new cmCursesStringWidget(this->EntryWidth, 1, 1, 1);
static_cast<cmCursesStringWidget*>(this->Entry)->SetString(value);
- }
- break;
}
+ break;
+ }
case cmState::UNINITIALIZED:
- cmSystemTools::Error("Found an undefined variable: ",
- key.c_str());
+ cmSystemTools::Error("Found an undefined variable: ", key.c_str());
break;
default:
// TODO : put warning message here
break;
- }
-
+ }
}
cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
@@ -120,12 +108,9 @@ cmCursesCacheEntryComposite::~cmCursesCacheEntryComposite()
const char* cmCursesCacheEntryComposite::GetValue()
{
- if (this->Label)
- {
+ if (this->Label) {
return this->Label->GetValue();
- }
- else
- {
+ } else {
return 0;
- }
+ }
}
diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.h b/Source/CursesDialog/cmCursesCacheEntryComposite.h
index f280897..8ed3902 100644
--- a/Source/CursesDialog/cmCursesCacheEntryComposite.h
+++ b/Source/CursesDialog/cmCursesCacheEntryComposite.h
@@ -19,9 +19,8 @@ class cmCursesCacheEntryComposite
public:
cmCursesCacheEntryComposite(const std::string& key, int labelwidth,
int entrywidth);
- cmCursesCacheEntryComposite(const std::string& key,
- cmake *cm,
- bool isNew, int labelwidth, int entrywidth);
+ cmCursesCacheEntryComposite(const std::string& key, cmake* cm, bool isNew,
+ int labelwidth, int entrywidth);
~cmCursesCacheEntryComposite();
const char* GetValue();
diff --git a/Source/CursesDialog/cmCursesDummyWidget.cxx b/Source/CursesDialog/cmCursesDummyWidget.cxx
index 9801e4d..3cd36af 100644
--- a/Source/CursesDialog/cmCursesDummyWidget.cxx
+++ b/Source/CursesDialog/cmCursesDummyWidget.cxx
@@ -11,16 +11,14 @@
============================================================================*/
#include "cmCursesDummyWidget.h"
-cmCursesDummyWidget::cmCursesDummyWidget(int width, int height,
- int left, int top) :
- cmCursesWidget(width, height, left, top)
+cmCursesDummyWidget::cmCursesDummyWidget(int width, int height, int left,
+ int top)
+ : cmCursesWidget(width, height, left, top)
{
this->Type = cmState::INTERNAL;
}
-
-bool cmCursesDummyWidget::HandleInput(int&, cmCursesMainForm*, WINDOW* )
+bool cmCursesDummyWidget::HandleInput(int&, cmCursesMainForm*, WINDOW*)
{
return false;
}
-
diff --git a/Source/CursesDialog/cmCursesDummyWidget.h b/Source/CursesDialog/cmCursesDummyWidget.h
index 2b3b9b5..9a3df29 100644
--- a/Source/CursesDialog/cmCursesDummyWidget.h
+++ b/Source/CursesDialog/cmCursesDummyWidget.h
@@ -30,7 +30,6 @@ public:
protected:
cmCursesDummyWidget(const cmCursesDummyWidget& from);
void operator=(const cmCursesDummyWidget&);
-
};
#endif // cmCursesDummyWidget_h
diff --git a/Source/CursesDialog/cmCursesFilePathWidget.cxx b/Source/CursesDialog/cmCursesFilePathWidget.cxx
index 51ed670..28a74a9 100644
--- a/Source/CursesDialog/cmCursesFilePathWidget.cxx
+++ b/Source/CursesDialog/cmCursesFilePathWidget.cxx
@@ -11,10 +11,9 @@
============================================================================*/
#include "cmCursesFilePathWidget.h"
-cmCursesFilePathWidget::cmCursesFilePathWidget(int width, int height,
- int left, int top) :
- cmCursesPathWidget(width, height, left, top)
+cmCursesFilePathWidget::cmCursesFilePathWidget(int width, int height, int left,
+ int top)
+ : cmCursesPathWidget(width, height, left, top)
{
this->Type = cmState::FILEPATH;
}
-
diff --git a/Source/CursesDialog/cmCursesFilePathWidget.h b/Source/CursesDialog/cmCursesFilePathWidget.h
index 6c50dd4..72adc77 100644
--- a/Source/CursesDialog/cmCursesFilePathWidget.h
+++ b/Source/CursesDialog/cmCursesFilePathWidget.h
@@ -22,7 +22,6 @@ public:
protected:
cmCursesFilePathWidget(const cmCursesFilePathWidget& from);
void operator=(const cmCursesFilePathWidget&);
-
};
#endif // cmCursesFilePathWidget_h
diff --git a/Source/CursesDialog/cmCursesForm.cxx b/Source/CursesDialog/cmCursesForm.cxx
index d1b470c..aa4710f 100644
--- a/Source/CursesDialog/cmCursesForm.cxx
+++ b/Source/CursesDialog/cmCursesForm.cxx
@@ -21,12 +21,11 @@ cmCursesForm::cmCursesForm()
cmCursesForm::~cmCursesForm()
{
- if (this->Form)
- {
+ if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
this->Form = 0;
- }
+ }
}
void cmCursesForm::DebugStart()
@@ -37,10 +36,9 @@ void cmCursesForm::DebugStart()
void cmCursesForm::DebugEnd()
{
- if (!cmCursesForm::Debug)
- {
+ if (!cmCursesForm::Debug) {
return;
- }
+ }
cmCursesForm::Debug = false;
cmCursesForm::DebugFile.close();
@@ -48,10 +46,9 @@ void cmCursesForm::DebugEnd()
void cmCursesForm::LogMessage(const char* msg)
{
- if (!cmCursesForm::Debug)
- {
+ if (!cmCursesForm::Debug) {
return;
- }
+ }
cmCursesForm::DebugFile << msg << std::endl;
}
diff --git a/Source/CursesDialog/cmCursesForm.h b/Source/CursesDialog/cmCursesForm.h
index 2c45494..c0192fc 100644
--- a/Source/CursesDialog/cmCursesForm.h
+++ b/Source/CursesDialog/cmCursesForm.h
@@ -54,16 +54,11 @@ public:
// Description:
// Return the FORM. Should be only used by low-level methods.
- FORM* GetForm()
- {
- return this->Form;
- }
+ FORM* GetForm() { return this->Form; }
static cmCursesForm* CurrentForm;
-
protected:
-
static cmsys::ofstream DebugFile;
static bool Debug;
diff --git a/Source/CursesDialog/cmCursesLabelWidget.cxx b/Source/CursesDialog/cmCursesLabelWidget.cxx
index b50eb64..e9da71e 100644
--- a/Source/CursesDialog/cmCursesLabelWidget.cxx
+++ b/Source/CursesDialog/cmCursesLabelWidget.cxx
@@ -11,14 +11,13 @@
============================================================================*/
#include "cmCursesLabelWidget.h"
-cmCursesLabelWidget::cmCursesLabelWidget(int width, int height,
- int left, int top,
- const std::string& name) :
- cmCursesWidget(width, height, left, top)
+cmCursesLabelWidget::cmCursesLabelWidget(int width, int height, int left,
+ int top, const std::string& name)
+ : cmCursesWidget(width, height, left, top)
{
- field_opts_off(this->Field, O_EDIT);
- field_opts_off(this->Field, O_ACTIVE);
- field_opts_off(this->Field, O_STATIC);
+ field_opts_off(this->Field, O_EDIT);
+ field_opts_off(this->Field, O_ACTIVE);
+ field_opts_off(this->Field, O_STATIC);
this->SetValue(name);
}
@@ -26,7 +25,7 @@ cmCursesLabelWidget::~cmCursesLabelWidget()
{
}
-bool cmCursesLabelWidget::HandleInput(int&, cmCursesMainForm*, WINDOW* )
+bool cmCursesLabelWidget::HandleInput(int&, cmCursesMainForm*, WINDOW*)
{
// Static text. No input is handled here.
return false;
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.cxx b/Source/CursesDialog/cmCursesLongMessageForm.cxx
index 776d828..84672ae 100644
--- a/Source/CursesDialog/cmCursesLongMessageForm.cxx
+++ b/Source/CursesDialog/cmCursesLongMessageForm.cxx
@@ -18,21 +18,19 @@
inline int ctrl(int z)
{
- return (z&037);
+ return (z & 037);
}
-cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string>
- const& messages, const char*
- title)
+cmCursesLongMessageForm::cmCursesLongMessageForm(
+ std::vector<std::string> const& messages, const char* title)
{
// Append all messages into on big string
std::vector<std::string>::const_iterator it;
- for(it=messages.begin(); it != messages.end(); it++)
- {
+ for (it = messages.begin(); it != messages.end(); it++) {
this->Messages += (*it);
// Add one blank line after each message
this->Messages += "\n\n";
- }
+ }
this->Title = title;
this->Fields[0] = 0;
this->Fields[1] = 0;
@@ -40,170 +38,145 @@ cmCursesLongMessageForm::cmCursesLongMessageForm(std::vector<std::string>
cmCursesLongMessageForm::~cmCursesLongMessageForm()
{
- if (this->Fields[0])
- {
+ if (this->Fields[0]) {
free_field(this->Fields[0]);
- }
+ }
}
-
void cmCursesLongMessageForm::UpdateStatusBar()
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
char bar[cmCursesMainForm::MAX_WIDTH];
size_t size = strlen(this->Title.c_str());
- if ( size >= cmCursesMainForm::MAX_WIDTH )
- {
- size = cmCursesMainForm::MAX_WIDTH-1;
- }
+ if (size >= cmCursesMainForm::MAX_WIDTH) {
+ size = cmCursesMainForm::MAX_WIDTH - 1;
+ }
strncpy(bar, this->Title.c_str(), size);
- for(size_t i=size-1; i<cmCursesMainForm::MAX_WIDTH; i++) bar[i] = ' ';
+ for (size_t i = size - 1; i < cmCursesMainForm::MAX_WIDTH; i++)
+ bar[i] = ' ';
int width;
- if (x < cmCursesMainForm::MAX_WIDTH )
- {
+ if (x < cmCursesMainForm::MAX_WIDTH) {
width = x;
- }
- else
- {
- width = cmCursesMainForm::MAX_WIDTH-1;
- }
+ } else {
+ width = cmCursesMainForm::MAX_WIDTH - 1;
+ }
bar[width] = '\0';
char version[cmCursesMainForm::MAX_WIDTH];
char vertmp[128];
- sprintf(vertmp,"CMake Version %s", cmVersion::GetCMakeVersion());
- size_t sideSpace = (width-strlen(vertmp));
- for(size_t i=0; i<sideSpace; i++) { version[i] = ' '; }
- sprintf(version+sideSpace, "%s", vertmp);
+ sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion());
+ size_t sideSpace = (width - strlen(vertmp));
+ for (size_t i = 0; i < sideSpace; i++) {
+ version[i] = ' ';
+ }
+ sprintf(version + sideSpace, "%s", vertmp);
version[width] = '\0';
char fmt_s[] = "%s";
- curses_move(y-4,0);
+ curses_move(y - 4, 0);
attron(A_STANDOUT);
printw(fmt_s, bar);
attroff(A_STANDOUT);
- curses_move(y-3,0);
+ curses_move(y - 3, 0);
printw(fmt_s, version);
pos_form_cursor(this->Form);
}
void cmCursesLongMessageForm::PrintKeys()
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
return;
- }
+ }
char firstLine[512];
- sprintf(firstLine, "Press [e] to exit help");
+ sprintf(firstLine, "Press [e] to exit help");
char fmt_s[] = "%s";
- curses_move(y-2,0);
+ curses_move(y - 2, 0);
printw(fmt_s, firstLine);
pos_form_cursor(this->Form);
-
}
void cmCursesLongMessageForm::Render(int, int, int, int)
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- if (this->Form)
- {
+ if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
this->Form = 0;
- }
+ }
const char* msg = this->Messages.c_str();
curses_clear();
- if (this->Fields[0])
- {
+ if (this->Fields[0]) {
free_field(this->Fields[0]);
this->Fields[0] = 0;
- }
+ }
- this->Fields[0] = new_field(y-6, x-2, 1, 1, 0, 0);
+ this->Fields[0] = new_field(y - 6, x - 2, 1, 1, 0, 0);
- field_opts_off(this->Fields[0], O_STATIC);
+ field_opts_off(this->Fields[0], O_STATIC);
this->Form = new_form(this->Fields);
post_form(this->Form);
- int i=0;
+ int i = 0;
form_driver(this->Form, REQ_BEG_FIELD);
- while(msg[i] != '\0' && i < 60000)
- {
- if (msg[i] == '\n' && msg[i+1] != '\0')
- {
+ while (msg[i] != '\0' && i < 60000) {
+ if (msg[i] == '\n' && msg[i + 1] != '\0') {
form_driver(this->Form, REQ_NEW_LINE);
- }
- else
- {
+ } else {
form_driver(this->Form, msg[i]);
- }
- i++;
}
+ i++;
+ }
form_driver(this->Form, REQ_BEG_FIELD);
this->UpdateStatusBar();
this->PrintKeys();
touchwin(stdscr);
refresh();
-
}
void cmCursesLongMessageForm::HandleInput()
{
- if (!this->Form)
- {
+ if (!this->Form) {
return;
- }
+ }
char debugMessage[128];
- for(;;)
- {
+ for (;;) {
int key = getch();
sprintf(debugMessage, "Message widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
// quit
- if ( key == 'o' || key == 'e' )
- {
+ if (key == 'o' || key == 'e') {
break;
- }
- else if ( key == KEY_DOWN || key == ctrl('n') )
- {
+ } else if (key == KEY_DOWN || key == ctrl('n')) {
form_driver(this->Form, REQ_SCR_FLINE);
- }
- else if ( key == KEY_UP || key == ctrl('p') )
- {
+ } else if (key == KEY_UP || key == ctrl('p')) {
form_driver(this->Form, REQ_SCR_BLINE);
- }
- else if ( key == KEY_NPAGE || key == ctrl('d') )
- {
+ } else if (key == KEY_NPAGE || key == ctrl('d')) {
form_driver(this->Form, REQ_SCR_FPAGE);
- }
- else if ( key == KEY_PPAGE || key == ctrl('u') )
- {
+ } else if (key == KEY_PPAGE || key == ctrl('u')) {
form_driver(this->Form, REQ_SCR_BPAGE);
- }
+ }
this->UpdateStatusBar();
this->PrintKeys();
touchwin(stdscr);
wrefresh(stdscr);
- }
-
+ }
}
diff --git a/Source/CursesDialog/cmCursesLongMessageForm.h b/Source/CursesDialog/cmCursesLongMessageForm.h
index e9bd542..73ccfc4 100644
--- a/Source/CursesDialog/cmCursesLongMessageForm.h
+++ b/Source/CursesDialog/cmCursesLongMessageForm.h
@@ -52,7 +52,6 @@ protected:
std::string Title;
FIELD* Fields[2];
-
};
#endif // cmCursesLongMessageForm_h
diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx
index 2aafc8b..7368560 100644
--- a/Source/CursesDialog/cmCursesMainForm.cxx
+++ b/Source/CursesDialog/cmCursesMainForm.cxx
@@ -25,15 +25,15 @@
#include "cmCursesStringWidget.h"
#include "cmState.h"
-
inline int ctrl(int z)
{
- return (z&037);
+ return (z & 037);
}
cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
- int initWidth) :
- Args(args), InitialWidth(initWidth)
+ int initWidth)
+ : Args(args)
+ , InitialWidth(initWidth)
{
this->NumberOfPages = 0;
this->Fields = 0;
@@ -41,7 +41,8 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
this->AdvancedMode = false;
this->NumberOfVisibleEntries = 0;
this->OkToGenerate = false;
- this->HelpMessage.push_back("Welcome to ccmake, curses based user interface for CMake.");
+ this->HelpMessage.push_back(
+ "Welcome to ccmake, curses based user interface for CMake.");
this->HelpMessage.push_back("");
this->HelpMessage.push_back(s_ConstHelpMessage);
this->CMakeInstance = new cmake;
@@ -60,43 +61,37 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> const& args,
cmCursesMainForm::~cmCursesMainForm()
{
- if (this->Form)
- {
+ if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
this->Form = 0;
- }
+ }
delete[] this->Fields;
// Clean-up composites
- if (this->Entries)
- {
+ if (this->Entries) {
cmDeleteAll(*this->Entries);
- }
+ }
delete this->Entries;
- if (this->CMakeInstance)
- {
+ if (this->CMakeInstance) {
delete this->CMakeInstance;
this->CMakeInstance = 0;
- }
+ }
}
// See if a cache entry is in the list of entries in the ui.
bool cmCursesMainForm::LookForCacheEntry(const std::string& key)
{
- if (!this->Entries)
- {
+ if (!this->Entries) {
return false;
- }
+ }
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
- if (key == (*it)->Key)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
+ if (key == (*it)->Key) {
return true;
- }
}
+ }
return false;
}
@@ -109,93 +104,74 @@ void cmCursesMainForm::InitializeUI()
std::vector<cmCursesCacheEntryComposite*>* newEntries =
new std::vector<cmCursesCacheEntryComposite*>;
std::vector<std::string> cacheKeys =
- this->CMakeInstance->GetState()->GetCacheEntryKeys();
+ this->CMakeInstance->GetState()->GetCacheEntryKeys();
newEntries->reserve(cacheKeys.size());
// Count non-internal and non-static entries
- int count=0;
-
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
- {
- cmState::CacheEntryType t = this->CMakeInstance->GetState()
- ->GetCacheEntryType(*it);
- if (t != cmState::INTERNAL &&
- t != cmState::STATIC &&
- t != cmState::UNINITIALIZED)
- {
+ int count = 0;
+
+ for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
+ it != cacheKeys.end(); ++it) {
+ cmState::CacheEntryType t =
+ this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ if (t != cmState::INTERNAL && t != cmState::STATIC &&
+ t != cmState::UNINITIALIZED) {
++count;
- }
}
+ }
int entrywidth = this->InitialWidth - 35;
cmCursesCacheEntryComposite* comp;
- if ( count == 0 )
- {
+ if (count == 0) {
// If cache is empty, display a label saying so and a
// dummy entry widget (does not respond to input)
comp = new cmCursesCacheEntryComposite("EMPTY CACHE", 30, 30);
comp->Entry = new cmCursesDummyWidget(1, 1, 1, 1);
newEntries->push_back(comp);
- }
- else
- {
+ } else {
// Create the composites.
// First add entries which are new
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
- {
+ for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
+ it != cacheKeys.end(); ++it) {
std::string key = *it;
- cmState::CacheEntryType t = this->CMakeInstance->GetState()
- ->GetCacheEntryType(*it);
- if (t == cmState::INTERNAL ||
- t == cmState::STATIC ||
- t == cmState::UNINITIALIZED )
- {
+ cmState::CacheEntryType t =
+ this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ if (t == cmState::INTERNAL || t == cmState::STATIC ||
+ t == cmState::UNINITIALIZED) {
continue;
- }
+ }
- if (!this->LookForCacheEntry(key))
- {
- newEntries->push_back(new cmCursesCacheEntryComposite(key,
- this->CMakeInstance,
- true, 30,
- entrywidth));
+ if (!this->LookForCacheEntry(key)) {
+ newEntries->push_back(new cmCursesCacheEntryComposite(
+ key, this->CMakeInstance, true, 30, entrywidth));
this->OkToGenerate = false;
- }
}
+ }
// then add entries which are old
- for(std::vector<std::string>::const_iterator it = cacheKeys.begin();
- it != cacheKeys.end(); ++it)
- {
+ for (std::vector<std::string>::const_iterator it = cacheKeys.begin();
+ it != cacheKeys.end(); ++it) {
std::string key = *it;
- cmState::CacheEntryType t = this->CMakeInstance->GetState()
- ->GetCacheEntryType(*it);
- if (t == cmState::INTERNAL ||
- t == cmState::STATIC ||
- t == cmState::UNINITIALIZED )
- {
+ cmState::CacheEntryType t =
+ this->CMakeInstance->GetState()->GetCacheEntryType(*it);
+ if (t == cmState::INTERNAL || t == cmState::STATIC ||
+ t == cmState::UNINITIALIZED) {
continue;
- }
+ }
- if (this->LookForCacheEntry(key))
- {
- newEntries->push_back(new cmCursesCacheEntryComposite(key,
- this->CMakeInstance,
- false, 30,
- entrywidth));
- }
+ if (this->LookForCacheEntry(key)) {
+ newEntries->push_back(new cmCursesCacheEntryComposite(
+ key, this->CMakeInstance, false, 30, entrywidth));
}
}
+ }
// Clean old entries
- if (this->Entries)
- {
+ if (this->Entries) {
cmDeleteAll(*this->Entries);
- }
+ }
delete this->Entries;
this->Entries = newEntries;
@@ -203,180 +179,150 @@ void cmCursesMainForm::InitializeUI()
this->RePost();
}
-
void cmCursesMainForm::RePost()
{
// Create the fields to be passed to the form.
- if (this->Form)
- {
+ if (this->Form) {
unpost_form(this->Form);
free_form(this->Form);
this->Form = 0;
- }
+ }
delete[] this->Fields;
- if (this->AdvancedMode)
- {
+ if (this->AdvancedMode) {
this->NumberOfVisibleEntries = this->Entries->size();
- }
- else
- {
+ } else {
// If normal mode, count only non-advanced entries
this->NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
const char* existingValue =
- this->CMakeInstance->GetState()
- ->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
bool advanced =
- this->CMakeInstance->GetState()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
- {
+ this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
+ (*it)->GetValue(), "ADVANCED");
+ if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
- }
- this->NumberOfVisibleEntries++;
}
+ this->NumberOfVisibleEntries++;
}
+ }
// there is always one even if it is the dummy one
- if(this->NumberOfVisibleEntries == 0)
- {
+ if (this->NumberOfVisibleEntries == 0) {
this->NumberOfVisibleEntries = 1;
- }
+ }
// Assign the fields: 3 for each entry: label, new entry marker
// ('*' or ' ') and entry widget
- this->Fields = new FIELD*[3*this->NumberOfVisibleEntries+1];
+ this->Fields = new FIELD*[3 * this->NumberOfVisibleEntries + 1];
size_t cc;
- for ( cc = 0; cc < 3 * this->NumberOfVisibleEntries+1; cc ++ )
- {
+ for (cc = 0; cc < 3 * this->NumberOfVisibleEntries + 1; cc++) {
this->Fields[cc] = 0;
- }
+ }
// Assign fields
- int j=0;
+ int j = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
const char* existingValue =
- this->CMakeInstance->GetState()
- ->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
bool advanced =
- this->CMakeInstance->GetState()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
- {
+ this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
+ (*it)->GetValue(), "ADVANCED");
+ if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
- }
- this->Fields[3*j] = (*it)->Label->Field;
- this->Fields[3*j+1] = (*it)->IsNewLabel->Field;
- this->Fields[3*j+2] = (*it)->Entry->Field;
- j++;
}
+ this->Fields[3 * j] = (*it)->Label->Field;
+ this->Fields[3 * j + 1] = (*it)->IsNewLabel->Field;
+ this->Fields[3 * j + 2] = (*it)->Entry->Field;
+ j++;
+ }
// if no cache entries there should still be one dummy field
- if(j == 0)
- {
+ if (j == 0) {
it = this->Entries->begin();
- this->Fields[0] = (*it)->Label->Field;
- this->Fields[1] = (*it)->IsNewLabel->Field;
- this->Fields[2] = (*it)->Entry->Field;
+ this->Fields[0] = (*it)->Label->Field;
+ this->Fields[1] = (*it)->IsNewLabel->Field;
+ this->Fields[2] = (*it)->Entry->Field;
this->NumberOfVisibleEntries = 1;
- }
+ }
// Has to be null terminated.
- this->Fields[3*this->NumberOfVisibleEntries] = 0;
+ this->Fields[3 * this->NumberOfVisibleEntries] = 0;
}
void cmCursesMainForm::Render(int left, int top, int width, int height)
{
- if (this->Form)
- {
+ if (this->Form) {
FIELD* currentField = current_field(this->Form);
- cmCursesWidget* cw = reinterpret_cast<cmCursesWidget*>
- (field_userptr(currentField));
+ cmCursesWidget* cw =
+ reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
// If in edit mode, get out of it
- if ( cw->GetType() == cmState::STRING ||
- cw->GetType() == cmState::PATH ||
- cw->GetType() == cmState::FILEPATH )
- {
+ if (cw->GetType() == cmState::STRING || cw->GetType() == cmState::PATH ||
+ cw->GetType() == cmState::FILEPATH) {
cmCursesStringWidget* sw = static_cast<cmCursesStringWidget*>(cw);
sw->SetInEdit(false);
- }
+ }
// Delete the previous form
unpost_form(this->Form);
free_form(this->Form);
this->Form = 0;
- }
+ }
// Wrong window size
- if ( width < cmCursesMainForm::MIN_WIDTH ||
- width < this->InitialWidth ||
- height < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (width < cmCursesMainForm::MIN_WIDTH || width < this->InitialWidth ||
+ height < cmCursesMainForm::MIN_HEIGHT) {
return;
- }
+ }
// Leave room for toolbar
height -= 7;
- if (this->AdvancedMode)
- {
+ if (this->AdvancedMode) {
this->NumberOfVisibleEntries = this->Entries->size();
- }
- else
- {
+ } else {
// If normal, display only non-advanced entries
this->NumberOfVisibleEntries = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
const char* existingValue =
- this->CMakeInstance->GetState()
- ->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
bool advanced =
- this->CMakeInstance->GetState()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
- {
+ this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
+ (*it)->GetValue(), "ADVANCED");
+ if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
- }
- this->NumberOfVisibleEntries++;
}
+ this->NumberOfVisibleEntries++;
}
+ }
// Re-adjust the fields according to their place
this->NumberOfPages = 1;
- if (height > 0)
- {
+ if (height > 0) {
bool isNewPage;
- int i=0;
+ int i = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
const char* existingValue =
- this->CMakeInstance->GetState()
- ->GetCacheEntryValue((*it)->GetValue());
+ this->CMakeInstance->GetState()->GetCacheEntryValue((*it)->GetValue());
bool advanced =
- this->CMakeInstance->GetState()
- ->GetCacheEntryPropertyAsBool((*it)->GetValue(), "ADVANCED");
- if (!existingValue || (!this->AdvancedMode && advanced))
- {
+ this->CMakeInstance->GetState()->GetCacheEntryPropertyAsBool(
+ (*it)->GetValue(), "ADVANCED");
+ if (!existingValue || (!this->AdvancedMode && advanced)) {
continue;
- }
+ }
int row = (i % height) + 1;
int page = (i / height) + 1;
- isNewPage = ( page > 1 ) && ( row == 1 );
+ isNewPage = (page > 1) && (row == 1);
- if (isNewPage)
- {
+ if (isNewPage) {
this->NumberOfPages++;
- }
- (*it)->Label->Move(left, top+row-1, isNewPage);
- (*it)->IsNewLabel->Move(left+32, top+row-1, false);
- (*it)->Entry->Move(left+33, top+row-1, false);
+ }
+ (*it)->Label->Move(left, top + row - 1, isNewPage);
+ (*it)->IsNewLabel->Move(left + 32, top + row - 1, false);
+ (*it)->Entry->Move(left + 33, top + row - 1, false);
(*it)->Entry->SetPage(this->NumberOfPages);
i++;
- }
}
+ }
// Post the form
this->Form = new_form(this->Fields);
@@ -391,153 +337,130 @@ void cmCursesMainForm::Render(int left, int top, int width, int height)
void cmCursesMainForm::PrintKeys(int process /* = 0 */)
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- x < this->InitialWidth ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || x < this->InitialWidth ||
+ y < cmCursesMainForm::MIN_HEIGHT) {
return;
- }
+ }
// Give the current widget (if it exists), a chance to print keys
cmCursesWidget* cw = 0;
- if (this->Form)
- {
+ if (this->Form) {
FIELD* currentField = current_field(this->Form);
cw = reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
- }
+ }
- if (cw)
- {
+ if (cw) {
cw->PrintKeys();
- }
-
-// {
-// }
-// else
-// {
- char firstLine[512]="";
- char secondLine[512]="";
- char thirdLine[512]="";
- if (process)
- {
+ }
+
+ // {
+ // }
+ // else
+ // {
+ char firstLine[512] = "";
+ char secondLine[512] = "";
+ char thirdLine[512] = "";
+ if (process) {
const char* clearLine =
" ";
strcpy(firstLine, clearLine);
strcpy(secondLine, clearLine);
strcpy(thirdLine, clearLine);
- }
- else
- {
- if (this->OkToGenerate)
- {
+ } else {
+ if (this->OkToGenerate) {
sprintf(firstLine,
"Press [c] to configure Press [g] to generate and exit");
- }
- else
- {
- sprintf(firstLine, "Press [c] to configure ");
- }
+ } else {
+ sprintf(firstLine,
+ "Press [c] to configure ");
+ }
{
const char* toggleKeyInstruction =
"Press [t] to toggle advanced mode (Currently %s)";
- sprintf(thirdLine,
- toggleKeyInstruction,
+ sprintf(thirdLine, toggleKeyInstruction,
this->AdvancedMode ? "On" : "Off");
}
- sprintf(secondLine,
- "Press [h] for help "
- "Press [q] to quit without generating");
- }
+ sprintf(secondLine, "Press [h] for help "
+ "Press [q] to quit without generating");
+ }
- curses_move(y-4,0);
+ curses_move(y - 4, 0);
char fmt_s[] = "%s";
char fmt[512] = "Press [enter] to edit option";
- if ( process )
- {
+ if (process) {
strcpy(fmt, " ");
- }
+ }
printw(fmt_s, fmt);
- curses_move(y-3,0);
+ curses_move(y - 3, 0);
printw(fmt_s, firstLine);
- curses_move(y-2,0);
+ curses_move(y - 2, 0);
printw(fmt_s, secondLine);
- curses_move(y-1,0);
+ curses_move(y - 1, 0);
printw(fmt_s, thirdLine);
- if (cw)
- {
+ if (cw) {
sprintf(firstLine, "Page %d of %d", cw->GetPage(), this->NumberOfPages);
- curses_move(0,65-static_cast<unsigned int>(strlen(firstLine))-1);
+ curses_move(0, 65 - static_cast<unsigned int>(strlen(firstLine)) - 1);
printw(fmt_s, firstLine);
- }
-// }
+ }
+ // }
pos_form_cursor(this->Form);
-
}
// Print the key of the current entry and the CMake version
// on the status bar. Designed for a width of 80 chars.
void cmCursesMainForm::UpdateStatusBar(const char* message)
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
// If window size is too small, display error and return
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- x < this->InitialWidth ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || x < this->InitialWidth ||
+ y < cmCursesMainForm::MIN_HEIGHT) {
curses_clear();
- curses_move(0,0);
+ curses_move(0, 0);
char fmt[] = "Window is too small. A size of at least %dx%d is required.";
- printw(fmt,
- (cmCursesMainForm::MIN_WIDTH < this->InitialWidth ?
- this->InitialWidth : cmCursesMainForm::MIN_WIDTH),
+ printw(fmt, (cmCursesMainForm::MIN_WIDTH < this->InitialWidth
+ ? this->InitialWidth
+ : cmCursesMainForm::MIN_WIDTH),
cmCursesMainForm::MIN_HEIGHT);
touchwin(stdscr);
wrefresh(stdscr);
return;
- }
+ }
// Get the key of the current entry
FIELD* cur = current_field(this->Form);
int findex = field_index(cur);
cmCursesWidget* lbl = 0;
- if ( findex >= 0 )
- {
- lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(this->Fields[findex-2]));
- }
+ if (findex >= 0) {
+ lbl = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[findex - 2]));
+ }
char help[128] = "";
const char* curField = "";
- if ( lbl )
- {
+ if (lbl) {
curField = lbl->GetValue();
// Get the help string of the current entry
// and add it to the help string
const char* existingValue =
- this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
- if (existingValue)
- {
- const char* hs = this->CMakeInstance->GetState()
- ->GetCacheEntryProperty(curField, "HELPSTRING");
- if ( hs )
- {
+ this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
+ if (existingValue) {
+ const char* hs = this->CMakeInstance->GetState()->GetCacheEntryProperty(
+ curField, "HELPSTRING");
+ if (hs) {
strncpy(help, hs, 127);
help[127] = '\0';
- }
- else
- {
+ } else {
help[0] = 0;
- }
- }
- else
- {
- sprintf(help," ");
}
+ } else {
+ sprintf(help, " ");
}
+ }
// Join the key, help string and pad with spaces
// (or truncate) as necessary
@@ -546,119 +469,98 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
size_t helpLen = strlen(help);
size_t width;
- if (x < cmCursesMainForm::MAX_WIDTH )
- {
+ if (x < cmCursesMainForm::MAX_WIDTH) {
width = x;
- }
- else
- {
+ } else {
width = cmCursesMainForm::MAX_WIDTH;
- }
+ }
- if ( message )
- {
+ if (message) {
curField = message;
curFieldLen = strlen(message);
- if ( curFieldLen < width )
- {
+ if (curFieldLen < width) {
strcpy(bar, curField);
- for(i=curFieldLen; i < width; ++i)
- {
+ for (i = curFieldLen; i < width; ++i) {
bar[i] = ' ';
- }
}
- else
- {
+ } else {
strncpy(bar, curField, width);
- }
- }
- else
- {
- if (curFieldLen >= width)
- {
+ }
+ } else {
+ if (curFieldLen >= width) {
strncpy(bar, curField, width);
- }
- else
- {
+ } else {
strcpy(bar, curField);
bar[curFieldLen] = ':';
- bar[curFieldLen+1] = ' ';
- if (curFieldLen + helpLen + 2 >= width)
- {
- strncpy(bar+curFieldLen+2, help, width
- - curFieldLen - 2);
- }
- else
- {
- strcpy(bar+curFieldLen+2, help);
- for(i=curFieldLen+helpLen+2; i < width; ++i)
- {
+ bar[curFieldLen + 1] = ' ';
+ if (curFieldLen + helpLen + 2 >= width) {
+ strncpy(bar + curFieldLen + 2, help, width - curFieldLen - 2);
+ } else {
+ strcpy(bar + curFieldLen + 2, help);
+ for (i = curFieldLen + helpLen + 2; i < width; ++i) {
bar[i] = ' ';
- }
}
}
}
-
+ }
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];
- sprintf(vertmp,"CMake Version %s", cmVersion::GetCMakeVersion());
- size_t sideSpace = (width-strlen(vertmp));
- for(i=0; i<sideSpace; i++) { version[i] = ' '; }
- sprintf(version+sideSpace, "%s", vertmp);
+ sprintf(vertmp, "CMake Version %s", cmVersion::GetCMakeVersion());
+ size_t sideSpace = (width - strlen(vertmp));
+ for (i = 0; i < sideSpace; i++) {
+ version[i] = ' ';
+ }
+ sprintf(version + sideSpace, "%s", vertmp);
version[width] = '\0';
// Now print both lines
char fmt_s[] = "%s";
- curses_move(y-5,0);
+ curses_move(y - 5, 0);
attron(A_STANDOUT);
printw(fmt_s, bar);
attroff(A_STANDOUT);
- curses_move(y-4,0);
+ curses_move(y - 4, 0);
printw(fmt_s, version);
pos_form_cursor(this->Form);
}
-void cmCursesMainForm::UpdateProgress(const char *msg, float prog, void* vp)
+void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp)
{
cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp);
- if ( !cm )
- {
+ if (!cm) {
return;
- }
+ }
char tmp[1024];
- const char *cmsg = tmp;
- if ( prog >= 0 )
- {
- sprintf(tmp, "%s %i%%",msg,(int)(100*prog));
- }
- else
- {
+ const char* cmsg = tmp;
+ if (prog >= 0) {
+ sprintf(tmp, "%s %i%%", msg, (int)(100 * prog));
+ } else {
cmsg = msg;
- }
+ }
cm->UpdateStatusBar(cmsg);
cm->PrintKeys(1);
- curses_move(1,1);
+ curses_move(1, 1);
touchwin(stdscr);
refresh();
}
int cmCursesMainForm::Configure(int noconfigure)
{
- int xi,yi;
+ int xi, yi;
getmaxyx(stdscr, yi, xi);
- curses_move(1,1);
+ curses_move(1, 1);
this->UpdateStatusBar("Configuring, please wait...");
this->PrintKeys(1);
touchwin(stdscr);
refresh();
- this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
+ this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
+ this);
// always save the current gui values to disk
this->FillCacheManagerFromUI();
@@ -672,52 +574,44 @@ int cmCursesMainForm::Configure(int noconfigure)
// run the generate process
this->OkToGenerate = true;
int retVal;
- if ( noconfigure )
- {
+ if (noconfigure) {
retVal = this->CMakeInstance->DoPreConfigureChecks();
this->OkToGenerate = false;
- if ( retVal > 0 )
- {
+ if (retVal > 0) {
retVal = 0;
- }
}
- else
- {
+ } else {
retVal = this->CMakeInstance->Configure();
- }
+ }
this->CMakeInstance->SetProgressCallback(0, 0);
- keypad(stdscr,TRUE); /* Use key symbols as
- KEY_DOWN*/
+ keypad(stdscr, TRUE); /* Use key symbols as
+ KEY_DOWN*/
- if( retVal != 0 || !this->Errors.empty())
- {
+ if (retVal != 0 || !this->Errors.empty()) {
// see if there was an error
- if(cmSystemTools::GetErrorOccuredFlag())
- {
+ if (cmSystemTools::GetErrorOccuredFlag()) {
this->OkToGenerate = false;
- }
- int xx,yy;
+ }
+ int xx, yy;
getmaxyx(stdscr, yy, xx);
cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
- this->Errors,
- cmSystemTools::GetErrorOccuredFlag()
- ? "Errors occurred during the last pass." :
- "CMake produced the following output.");
+ this->Errors, cmSystemTools::GetErrorOccuredFlag()
+ ? "Errors occurred during the last pass."
+ : "CMake produced the following output.");
// reset error condition
cmSystemTools::ResetErrorOccuredFlag();
CurrentForm = msgs;
- msgs->Render(1,1,xx,yy);
+ msgs->Render(1, 1, xx, yy);
msgs->HandleInput();
// If they typed the wrong source directory, we report
// an error and exit
- if ( retVal == -2 )
- {
+ if (retVal == -2) {
return retVal;
- }
- CurrentForm = this;
- this->Render(1,1,xx,yy);
}
+ CurrentForm = this;
+ this->Render(1, 1, xx, yy);
+ }
this->InitializeUI();
this->Render(1, 1, xi, yi);
@@ -727,15 +621,16 @@ int cmCursesMainForm::Configure(int noconfigure)
int cmCursesMainForm::Generate()
{
- int xi,yi;
+ int xi, yi;
getmaxyx(stdscr, yi, xi);
- curses_move(1,1);
+ curses_move(1, 1);
this->UpdateStatusBar("Generating, please wait...");
this->PrintKeys(1);
touchwin(stdscr);
refresh();
- this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress, this);
+ this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
+ this);
// Get rid of previous errors
this->Errors = std::vector<std::string>();
@@ -744,39 +639,35 @@ int cmCursesMainForm::Generate()
int retVal = this->CMakeInstance->Generate();
this->CMakeInstance->SetProgressCallback(0, 0);
- keypad(stdscr,TRUE); /* Use key symbols as
- KEY_DOWN*/
+ keypad(stdscr, TRUE); /* Use key symbols as
+ KEY_DOWN*/
- if( retVal != 0 || !this->Errors.empty())
- {
+ if (retVal != 0 || !this->Errors.empty()) {
// see if there was an error
- if(cmSystemTools::GetErrorOccuredFlag())
- {
+ if (cmSystemTools::GetErrorOccuredFlag()) {
this->OkToGenerate = false;
- }
+ }
// reset error condition
cmSystemTools::ResetErrorOccuredFlag();
- int xx,yy;
+ int xx, yy;
getmaxyx(stdscr, yy, xx);
const char* title = "Messages during last pass.";
- if(cmSystemTools::GetErrorOccuredFlag())
- {
+ if (cmSystemTools::GetErrorOccuredFlag()) {
title = "Errors occurred during the last pass.";
- }
- cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->Errors,
- title);
+ }
+ cmCursesLongMessageForm* msgs =
+ new cmCursesLongMessageForm(this->Errors, title);
CurrentForm = msgs;
- msgs->Render(1,1,xx,yy);
+ msgs->Render(1, 1, xx, yy);
msgs->HandleInput();
// If they typed the wrong source directory, we report
// an error and exit
- if ( retVal == -2 )
- {
+ if (retVal == -2) {
return retVal;
- }
- CurrentForm = this;
- this->Render(1,1,xx,yy);
}
+ CurrentForm = this;
+ this->Render(1, 1, xx, yy);
+ }
this->InitializeUI();
this->Render(1, 1, xi, yi);
@@ -791,346 +682,286 @@ void cmCursesMainForm::AddError(const char* message, const char*)
void cmCursesMainForm::RemoveEntry(const char* value)
{
- if (!value)
- {
+ if (!value) {
return;
- }
+ }
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end(); ++it) {
const char* val = (*it)->GetValue();
- if ( val && !strcmp(value, val) )
- {
+ if (val && !strcmp(value, val)) {
this->CMakeInstance->UnwatchUnusedCli(value);
this->Entries->erase(it);
break;
- }
}
+ }
}
// copy from the list box to the cache manager
void cmCursesMainForm::FillCacheManagerFromUI()
{
size_t size = this->Entries->size();
- for(size_t i=0; i < size; i++)
- {
+ for (size_t i = 0; i < size; i++) {
std::string cacheKey = (*this->Entries)[i]->Key;
- const char* existingValue = this->CMakeInstance->GetState()
- ->GetCacheEntryValue(cacheKey);
- if (existingValue)
- {
+ const char* existingValue =
+ this->CMakeInstance->GetState()->GetCacheEntryValue(cacheKey);
+ if (existingValue) {
std::string oldValue = existingValue;
std::string newValue = (*this->Entries)[i]->Entry->GetValue();
std::string fixedOldValue;
std::string fixedNewValue;
cmState::CacheEntryType t =
- this->CMakeInstance->GetState()
- ->GetCacheEntryType(cacheKey);
+ this->CMakeInstance->GetState()->GetCacheEntryType(cacheKey);
this->FixValue(t, oldValue, fixedOldValue);
this->FixValue(t, newValue, fixedNewValue);
- if(!(fixedOldValue == fixedNewValue))
- {
+ if (!(fixedOldValue == fixedNewValue)) {
// The user has changed the value. Mark it as modified.
- this->CMakeInstance->GetState()
- ->SetCacheEntryBoolProperty(cacheKey, "MODIFIED", true);
- this->CMakeInstance->GetState()
- ->SetCacheEntryValue(cacheKey, fixedNewValue);
- }
+ this->CMakeInstance->GetState()->SetCacheEntryBoolProperty(
+ cacheKey, "MODIFIED", true);
+ this->CMakeInstance->GetState()->SetCacheEntryValue(cacheKey,
+ fixedNewValue);
}
}
+ }
}
void cmCursesMainForm::FixValue(cmState::CacheEntryType type,
const std::string& in, std::string& out) const
{
- out = in.substr(0,in.find_last_not_of(" ")+1);
- if(type == cmState::PATH || type == cmState::FILEPATH)
- {
+ out = in.substr(0, in.find_last_not_of(" ") + 1);
+ if (type == cmState::PATH || type == cmState::FILEPATH) {
cmSystemTools::ConvertToUnixSlashes(out);
- }
- if(type == cmState::BOOL)
- {
- if(cmSystemTools::IsOff(out.c_str()))
- {
+ }
+ if (type == cmState::BOOL) {
+ if (cmSystemTools::IsOff(out.c_str())) {
out = "OFF";
- }
- else
- {
+ } else {
out = "ON";
- }
}
+ }
}
#include <unistd.h>
void cmCursesMainForm::HandleInput()
{
- int x=0,y=0;
+ int x = 0, y = 0;
- if (!this->Form)
- {
+ if (!this->Form) {
return;
- }
+ }
FIELD* currentField;
cmCursesWidget* currentWidget;
char debugMessage[128];
- for(;;)
- {
+ for (;;) {
this->UpdateStatusBar();
this->PrintKeys();
- if ( this->SearchMode )
- {
+ if (this->SearchMode) {
std::string searchstr = "Search: " + this->SearchString;
- this->UpdateStatusBar( searchstr.c_str() );
+ this->UpdateStatusBar(searchstr.c_str());
this->PrintKeys(1);
- curses_move(y-5,static_cast<unsigned int>(searchstr.size()));
- //curses_move(1,1);
+ curses_move(y - 5, static_cast<unsigned int>(searchstr.size()));
+ // curses_move(1,1);
touchwin(stdscr);
refresh();
- }
+ }
int key = getch();
getmaxyx(stdscr, y, x);
// If window too small, handle 'q' only
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
// quit
- if ( key == 'q' )
- {
+ if (key == 'q') {
break;
- }
- else
- {
+ } else {
continue;
- }
}
+ }
currentField = current_field(this->Form);
- currentWidget = reinterpret_cast<cmCursesWidget*>(field_userptr(
- currentField));
+ currentWidget =
+ reinterpret_cast<cmCursesWidget*>(field_userptr(currentField));
- bool widgetHandled=false;
+ bool widgetHandled = false;
- if ( this->SearchMode )
- {
- if ( key == 10 || key == KEY_ENTER )
- {
+ if (this->SearchMode) {
+ if (key == 10 || key == KEY_ENTER) {
this->SearchMode = false;
- if (!this->SearchString.empty())
- {
+ if (!this->SearchString.empty()) {
this->JumpToCacheEntry(this->SearchString.c_str());
this->OldSearchString = this->SearchString;
- }
- this->SearchString = "";
}
+ this->SearchString = "";
+ }
/*
else if ( key == KEY_ESCAPE )
{
this->SearchMode = false;
}
*/
- else if ((key >= 'a' && key <= 'z') ||
- (key >= 'A' && key <= 'Z') ||
- (key >= '0' && key <= '9') ||
- (key == '_' ))
- {
- if ( this->SearchString.size() < static_cast<std::string::size_type>(x-10) )
- {
+ else if ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z') ||
+ (key >= '0' && key <= '9') || (key == '_')) {
+ if (this->SearchString.size() <
+ static_cast<std::string::size_type>(x - 10)) {
this->SearchString += static_cast<char>(key);
- }
}
- else if ( key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC )
- {
- if (!this->SearchString.empty())
- {
- this->SearchString.resize(this->SearchString.size()-1);
- }
+ } else if (key == ctrl('h') || key == KEY_BACKSPACE || key == KEY_DC) {
+ if (!this->SearchString.empty()) {
+ this->SearchString.resize(this->SearchString.size() - 1);
}
}
- else if (currentWidget && !this->SearchMode)
- {
+ } else if (currentWidget && !this->SearchMode) {
// Ask the current widget if it wants to handle input
widgetHandled = currentWidget->HandleInput(key, this, stdscr);
- if (widgetHandled)
- {
+ if (widgetHandled) {
this->OkToGenerate = false;
this->UpdateStatusBar();
this->PrintKeys();
- }
}
- if ((!currentWidget || !widgetHandled) && !this->SearchMode)
- {
+ }
+ if ((!currentWidget || !widgetHandled) && !this->SearchMode) {
// 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
- if ( key == 'q' )
- {
+ if (key == 'q') {
break;
- }
+ }
// if not end of page, next field otherwise next page
// each entry consists of fields: label, isnew, value
// therefore, the label field for the prev. entry is index-5
// and the label field for the next entry is index+1
// (index always corresponds to the value field)
- else if ( key == KEY_DOWN || key == ctrl('n') )
- {
+ else if (key == KEY_DOWN || key == ctrl('n')) {
FIELD* cur = current_field(this->Form);
size_t findex = field_index(cur);
- if ( findex == 3*this->NumberOfVisibleEntries-1 )
- {
+ if (findex == 3 * this->NumberOfVisibleEntries - 1) {
continue;
- }
- if (new_page(this->Fields[findex+1]))
- {
+ }
+ if (new_page(this->Fields[findex + 1])) {
form_driver(this->Form, REQ_NEXT_PAGE);
- }
- else
- {
+ } else {
form_driver(this->Form, REQ_NEXT_FIELD);
- }
}
+ }
// if not beginning of page, previous field, otherwise previous page
// each entry consists of fields: label, isnew, value
// therefore, the label field for the prev. entry is index-5
// and the label field for the next entry is index+1
// (index always corresponds to the value field)
- else if ( key == KEY_UP || key == ctrl('p') )
- {
+ else if (key == KEY_UP || key == ctrl('p')) {
FIELD* cur = current_field(this->Form);
int findex = field_index(cur);
- if ( findex == 2 )
- {
+ if (findex == 2) {
continue;
- }
- if ( new_page(this->Fields[findex-2]) )
- {
+ }
+ if (new_page(this->Fields[findex - 2])) {
form_driver(this->Form, REQ_PREV_PAGE);
- set_current_field(this->Form, this->Fields[findex-3]);
- }
- else
- {
+ set_current_field(this->Form, this->Fields[findex - 3]);
+ } else {
form_driver(this->Form, REQ_PREV_FIELD);
- }
}
+ }
// pg down
- else if ( key == KEY_NPAGE || key == ctrl('d') )
- {
+ else if (key == KEY_NPAGE || key == ctrl('d')) {
form_driver(this->Form, REQ_NEXT_PAGE);
- }
+ }
// pg up
- else if ( key == KEY_PPAGE || key == ctrl('u') )
- {
+ else if (key == KEY_PPAGE || key == ctrl('u')) {
form_driver(this->Form, REQ_PREV_PAGE);
- }
+ }
// configure
- else if ( key == 'c' )
- {
+ else if (key == 'c') {
this->Configure();
- }
+ }
// display help
- else if ( key == 'h' )
- {
+ else if (key == 'h') {
getmaxyx(stdscr, y, x);
FIELD* cur = current_field(this->Form);
int findex = field_index(cur);
- cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(
- this->Fields[findex-2]));
+ cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[findex - 2]));
const char* curField = lbl->GetValue();
const char* helpString = 0;
const char* existingValue =
- this->CMakeInstance->GetState()
- ->GetCacheEntryValue(curField);
- if (existingValue)
- {
- helpString = this->CMakeInstance->GetState()
- ->GetCacheEntryProperty(curField, "HELPSTRING");
- }
- if (helpString)
- {
- char* message = new char[strlen(curField)+strlen(helpString)
- +strlen("Current option is: \n Help string for this option is: \n")+10];
- sprintf(message,"Current option is: %s\nHelp string for this option is: %s\n", curField, helpString);
+ this->CMakeInstance->GetState()->GetCacheEntryValue(curField);
+ if (existingValue) {
+ helpString = this->CMakeInstance->GetState()->GetCacheEntryProperty(
+ curField, "HELPSTRING");
+ }
+ if (helpString) {
+ char* message = new char
+ [strlen(curField) + strlen(helpString) +
+ strlen(
+ "Current option is: \n Help string for this option is: \n") +
+ 10];
+ sprintf(
+ message,
+ "Current option is: %s\nHelp string for this option is: %s\n",
+ curField, helpString);
this->HelpMessage[1] = message;
delete[] message;
- }
- else
- {
+ } else {
this->HelpMessage[1] = "";
- }
+ }
- cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->HelpMessage,
- "Help.");
+ cmCursesLongMessageForm* msgs =
+ new cmCursesLongMessageForm(this->HelpMessage, "Help.");
CurrentForm = msgs;
- msgs->Render(1,1,x,y);
+ msgs->Render(1, 1, x, y);
msgs->HandleInput();
CurrentForm = this;
- this->Render(1,1,x,y);
+ this->Render(1, 1, x, y);
set_current_field(this->Form, cur);
- }
+ }
// display last errors
- else if ( key == 'l' )
- {
+ else if (key == 'l') {
getmaxyx(stdscr, y, x);
- cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(this->Errors,
- "Errors occurred during the last pass.");
+ cmCursesLongMessageForm* msgs = new cmCursesLongMessageForm(
+ this->Errors, "Errors occurred during the last pass.");
CurrentForm = msgs;
- msgs->Render(1,1,x,y);
+ msgs->Render(1, 1, x, y);
msgs->HandleInput();
CurrentForm = this;
- this->Render(1,1,x,y);
- }
- else if ( key == '/' )
- {
+ this->Render(1, 1, x, y);
+ } else if (key == '/') {
this->SearchMode = true;
this->UpdateStatusBar("Search");
this->PrintKeys(1);
touchwin(stdscr);
refresh();
- }
- else if ( key == 'n' )
- {
- if (!this->OldSearchString.empty())
- {
+ } else if (key == 'n') {
+ if (!this->OldSearchString.empty()) {
this->JumpToCacheEntry(this->OldSearchString.c_str());
- }
}
+ }
// switch advanced on/off
- else if ( key == 't' )
- {
- if (this->AdvancedMode)
- {
+ else if (key == 't') {
+ if (this->AdvancedMode) {
this->AdvancedMode = false;
- }
- else
- {
+ } else {
this->AdvancedMode = true;
- }
+ }
getmaxyx(stdscr, y, x);
this->RePost();
this->Render(1, 1, x, y);
- }
+ }
// generate and exit
- else if ( key == 'g' )
- {
- if ( this->OkToGenerate )
- {
+ else if (key == 'g') {
+ if (this->OkToGenerate) {
this->Generate();
break;
- }
}
+ }
// delete cache entry
- else if ( key == 'd' && this->NumberOfVisibleEntries )
- {
+ else if (key == 'd' && this->NumberOfVisibleEntries) {
this->OkToGenerate = false;
FIELD* cur = current_field(this->Form);
size_t findex = field_index(cur);
@@ -1141,76 +972,66 @@ void cmCursesMainForm::HandleInput()
// and the label field for the next entry is findex+1
// (findex always corresponds to the value field)
FIELD* nextCur;
- if ( findex == 2 )
- {
- nextCur=0;
- }
- else if ( findex == 3*this->NumberOfVisibleEntries-1 )
- {
- nextCur = this->Fields[findex-5];
- }
- else
- {
- nextCur = this->Fields[findex+1];
- }
+ if (findex == 2) {
+ nextCur = 0;
+ } else if (findex == 3 * this->NumberOfVisibleEntries - 1) {
+ nextCur = this->Fields[findex - 5];
+ } else {
+ nextCur = this->Fields[findex + 1];
+ }
// Get the label widget
// each entry consists of fields: label, isnew, value
// therefore, the label field for the is findex-2
// (findex always corresponds to the value field)
- cmCursesWidget* lbl
- = reinterpret_cast<cmCursesWidget*>(
- field_userptr(this->Fields[findex-2]));
- if ( lbl )
- {
+ cmCursesWidget* lbl = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[findex - 2]));
+ if (lbl) {
this->CMakeInstance->GetState()->RemoveCacheEntry(lbl->GetValue());
std::string nextVal;
- if (nextCur)
- {
- nextVal = (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))->GetValue());
- }
+ if (nextCur) {
+ nextVal =
+ (reinterpret_cast<cmCursesWidget*>(field_userptr(nextCur))
+ ->GetValue());
+ }
getmaxyx(stdscr, y, x);
this->RemoveEntry(lbl->GetValue());
this->RePost();
this->Render(1, 1, x, y);
- if (nextCur)
- {
+ if (nextCur) {
// make the next or prev. current field after deletion
nextCur = 0;
std::vector<cmCursesCacheEntryComposite*>::iterator it;
- for (it = this->Entries->begin(); it != this->Entries->end(); ++it)
- {
- if (nextVal == (*it)->Key)
- {
+ for (it = this->Entries->begin(); it != this->Entries->end();
+ ++it) {
+ if (nextVal == (*it)->Key) {
nextCur = (*it)->Entry->Field;
- }
}
+ }
- if (nextCur)
- {
+ if (nextCur) {
set_current_field(this->Form, nextCur);
- }
}
}
}
}
+ }
touchwin(stdscr);
wrefresh(stdscr);
- }
+ }
}
-int cmCursesMainForm::LoadCache(const char *)
+int cmCursesMainForm::LoadCache(const char*)
{
int r = this->CMakeInstance->LoadCache();
- if(r < 0)
- {
+ if (r < 0) {
return r;
- }
+ }
this->CMakeInstance->SetCacheArgs(this->Args);
this->CMakeInstance->PreLoadCMakeFiles();
return r;
@@ -1219,55 +1040,44 @@ int cmCursesMainForm::LoadCache(const char *)
void cmCursesMainForm::JumpToCacheEntry(const char* astr)
{
std::string str;
- if ( astr )
- {
+ if (astr) {
str = cmSystemTools::LowerCase(astr);
- }
+ }
- if(str.empty())
- {
+ if (str.empty()) {
return;
- }
+ }
FIELD* cur = current_field(this->Form);
int start_index = field_index(cur);
int findex = start_index;
- for(;;)
- {
- if (!str.empty())
- {
+ for (;;) {
+ if (!str.empty()) {
cmCursesWidget* lbl = 0;
- if ( findex >= 0 )
- {
- lbl = reinterpret_cast<cmCursesWidget*>(field_userptr(this->Fields[findex-2]));
- }
- if ( lbl )
- {
+ if (findex >= 0) {
+ lbl = reinterpret_cast<cmCursesWidget*>(
+ field_userptr(this->Fields[findex - 2]));
+ }
+ if (lbl) {
const char* curField = lbl->GetValue();
- if ( curField )
- {
+ if (curField) {
std::string cfld = cmSystemTools::LowerCase(curField);
- if ( cfld.find(str) != cfld.npos && findex != start_index )
- {
+ if (cfld.find(str) != cfld.npos && findex != start_index) {
break;
- }
}
}
}
- if ( size_t(findex) >= 3* this->NumberOfVisibleEntries-1 )
- {
+ }
+ if (size_t(findex) >= 3 * this->NumberOfVisibleEntries - 1) {
set_current_field(this->Form, this->Fields[2]);
- }
- else if (new_page(this->Fields[findex+1]))
- {
+ } else if (new_page(this->Fields[findex + 1])) {
form_driver(this->Form, REQ_NEXT_PAGE);
- }
- else
- {
+ } else {
form_driver(this->Form, REQ_NEXT_FIELD);
- }
+ }
/*
char buffer[1024];
- sprintf(buffer, "Line: %d != %d / %d\n", findex, idx, this->NumberOfVisibleEntries);
+ sprintf(buffer, "Line: %d != %d / %d\n", findex, idx,
+ this->NumberOfVisibleEntries);
touchwin(stdscr);
refresh();
this->UpdateStatusBar( buffer );
@@ -1275,52 +1085,70 @@ void cmCursesMainForm::JumpToCacheEntry(const char* astr)
*/
cur = current_field(this->Form);
findex = field_index(cur);
- if ( findex == start_index )
- {
+ if (findex == start_index) {
break;
- }
}
+ }
}
-
const char* cmCursesMainForm::s_ConstHelpMessage =
-"CMake is used to configure and generate build files for software projects. "
-"The basic steps for configuring a project with ccmake are as follows:\n\n"
-"1. Run ccmake in the directory where you want the object and executable files to be placed (build directory). If the source directory is not the same as this build directory, you have to specify it as an argument on the command line.\n\n"
-"2. When ccmake is run, it will read the configuration files and display the current build options. "
-"If you have run CMake before and have updated the configuration files since then, any new entries will be displayed on top and will be marked with a *. "
-"On the other hand, the first time you run ccmake, all build options will be new and will be marked as such. "
-"At this point, you can modify any options (see keys below) you want to change. "
-"When you are satisfied with your changes, press 'c' to have CMake process the configuration files. "
-"Please note that changing some options may cause new ones to appear. These will be shown on top and will be marked with *. "
-"Repeat this procedure until you are satisfied with all the options and there are no new entries. "
-"At this point, a new command will appear: G)enerate and Exit. You can now hit 'g' to have CMake generate all the build files (i.e. makefiles or project files) and exit. "
-"At any point during the process, you can exit ccmake with 'q'. However, this will not generate/change any build files.\n\n"
-"ccmake KEYS:\n\n"
-"Navigation: "
-"You can use the arrow keys and page up, down to navigate the options. Alternatively, you can use the following keys: \n"
-" C-n : next option\n"
-" C-p : previous options\n"
-" C-d : down one page\n"
-" C-u : up one page\n\n"
-"Editing options: "
-"To change an option press enter or return. If the current options is a boolean, this will toggle it's value. "
-"Otherwise, ccmake will enter edit mode. In this mode you can edit an option using arrow keys and backspace. Alternatively, you can use the following keys:\n"
-" C-b : back one character\n"
-" C-f : forward one character\n"
-" C-a : go to the beginning of the field\n"
-" C-e : go to the end of the field\n"
-" C-d : delete previous character\n"
-" C-k : kill the rest of the field\n"
-" Esc : Restore field (discard last changes)\n"
-" Enter : Leave edit mode\n"
-"You can also delete an option by pressing 'd'\n\n"
-"Commands:\n"
-" q : quit ccmake without generating build files\n"
-" h : help, shows this screen\n"
-" c : process the configuration files with the current options\n"
-" g : generate build files and exit, only available when there are no "
-"new options and no errors have been detected during last configuration.\n"
-" l : shows last errors\n"
-" t : toggles advanced mode. In normal mode, only the most important options are shown. In advanced mode, all options are shown. We recommend using normal mode unless you are an expert.\n"
-" / : search for a variable name.\n";
+ "CMake is used to configure and generate build files for software projects. "
+ "The basic steps for configuring a project with ccmake are as follows:\n\n"
+ "1. Run ccmake in the directory where you want the object and executable "
+ "files to be placed (build directory). If the source directory is not the "
+ "same as this build directory, you have to specify it as an argument on the "
+ "command line.\n\n"
+ "2. When ccmake is run, it will read the configuration files and display "
+ "the current build options. "
+ "If you have run CMake before and have updated the configuration files "
+ "since then, any new entries will be displayed on top and will be marked "
+ "with a *. "
+ "On the other hand, the first time you run ccmake, all build options will "
+ "be new and will be marked as such. "
+ "At this point, you can modify any options (see keys below) you want to "
+ "change. "
+ "When you are satisfied with your changes, press 'c' to have CMake process "
+ "the configuration files. "
+ "Please note that changing some options may cause new ones to appear. These "
+ "will be shown on top and will be marked with *. "
+ "Repeat this procedure until you are satisfied with all the options and "
+ "there are no new entries. "
+ "At this point, a new command will appear: G)enerate and Exit. You can now "
+ "hit 'g' to have CMake generate all the build files (i.e. makefiles or "
+ "project files) and exit. "
+ "At any point during the process, you can exit ccmake with 'q'. However, "
+ "this will not generate/change any build files.\n\n"
+ "ccmake KEYS:\n\n"
+ "Navigation: "
+ "You can use the arrow keys and page up, down to navigate the options. "
+ "Alternatively, you can use the following keys: \n"
+ " C-n : next option\n"
+ " C-p : previous options\n"
+ " C-d : down one page\n"
+ " C-u : up one page\n\n"
+ "Editing options: "
+ "To change an option press enter or return. If the current options is a "
+ "boolean, this will toggle it's value. "
+ "Otherwise, ccmake will enter edit mode. In this mode you can edit an "
+ "option using arrow keys and backspace. Alternatively, you can use the "
+ "following keys:\n"
+ " C-b : back one character\n"
+ " C-f : forward one character\n"
+ " C-a : go to the beginning of the field\n"
+ " C-e : go to the end of the field\n"
+ " C-d : delete previous character\n"
+ " C-k : kill the rest of the field\n"
+ " Esc : Restore field (discard last changes)\n"
+ " Enter : Leave edit mode\n"
+ "You can also delete an option by pressing 'd'\n\n"
+ "Commands:\n"
+ " q : quit ccmake without generating build files\n"
+ " h : help, shows this screen\n"
+ " c : process the configuration files with the current options\n"
+ " g : generate build files and exit, only available when there are no "
+ "new options and no errors have been detected during last configuration.\n"
+ " l : shows last errors\n"
+ " t : toggles advanced mode. In normal mode, only the most important "
+ "options are shown. In advanced mode, all options are shown. We recommend "
+ "using normal mode unless you are an expert.\n"
+ " / : search for a variable name.\n";
diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h
index 9a80ba2..9aa0f67 100644
--- a/Source/CursesDialog/cmCursesMainForm.h
+++ b/Source/CursesDialog/cmCursesMainForm.h
@@ -54,7 +54,8 @@ public:
*/
bool LookForCacheEntry(const std::string& key);
- enum {
+ enum
+ {
MIN_WIDTH = 65,
MIN_HEIGHT = 6,
IDEAL_WIDTH = 80,
@@ -88,7 +89,7 @@ public:
* Used to do a configure. If argument is specified, it does only the check
* and not configure.
*/
- int Configure(int noconfigure=0);
+ int Configure(int noconfigure = 0);
/**
* Used to generate
@@ -98,13 +99,13 @@ public:
/**
* Used by main program
*/
- int LoadCache(const char *dir);
+ int LoadCache(const char* dir);
/**
* Progress callback
*/
- static void UpdateProgressOld(const char *msg, float prog, void*);
- static void UpdateProgress(const char *msg, float prog, void*);
+ static void UpdateProgressOld(const char* msg, float prog, void*);
+ static void UpdateProgress(const char* msg, float prog, void*);
protected:
cmCursesMainForm(const cmCursesMainForm& from);
@@ -114,8 +115,8 @@ protected:
// cache.
void FillCacheManagerFromUI();
// Fix formatting of values to a consistent form.
- void FixValue(cmState::CacheEntryType type,
- const std::string& in, std::string& out) const;
+ void FixValue(cmState::CacheEntryType type, const std::string& in,
+ std::string& out) const;
// Re-post the existing fields. Used to toggle between
// normal and advanced modes. Render() should be called
// afterwards.
@@ -155,7 +156,7 @@ protected:
int NumberOfPages;
int InitialWidth;
- cmake *CMakeInstance;
+ cmake* CMakeInstance;
std::string SearchString;
std::string OldSearchString;
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.cxx b/Source/CursesDialog/cmCursesOptionsWidget.cxx
index 05aeab1..1a3a8c2 100644
--- a/Source/CursesDialog/cmCursesOptionsWidget.cxx
+++ b/Source/CursesDialog/cmCursesOptionsWidget.cxx
@@ -15,54 +15,47 @@
inline int ctrl(int z)
{
- return (z&037);
+ return (z & 037);
}
-cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height,
- int left, int top) :
- cmCursesWidget(width, height, left, top)
+cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left,
+ int top)
+ : cmCursesWidget(width, height, left, top)
{
this->Type = cmState::BOOL; // this is a bit of a hack
// there is no option type, and string type causes ccmake to cast
// the widget into a string widget at some point. BOOL is safe for
// now.
- set_field_fore(this->Field, A_NORMAL);
- set_field_back(this->Field, A_STANDOUT);
- field_opts_off(this->Field, O_STATIC);
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
}
bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
{
// 10 == enter
- if (key == 10 || key == KEY_ENTER)
- {
+ if (key == 10 || key == KEY_ENTER) {
this->NextOption();
touchwin(w);
wrefresh(w);
return true;
- }
- else if (key == KEY_LEFT || key == ctrl('b'))
- {
+ } else if (key == KEY_LEFT || key == ctrl('b')) {
touchwin(w);
wrefresh(w);
this->PreviousOption();
return true;
- }
- else if (key == KEY_RIGHT || key == ctrl('f'))
- {
+ } else if (key == KEY_RIGHT || key == ctrl('f')) {
this->NextOption();
touchwin(w);
wrefresh(w);
return true;
- }
- else
- {
+ } else {
return false;
- }
+ }
}
-void cmCursesOptionsWidget::AddOption(std::string const & option )
+void cmCursesOptionsWidget::AddOption(std::string const& option)
{
this->Options.push_back(option);
}
@@ -70,22 +63,18 @@ void cmCursesOptionsWidget::AddOption(std::string const & option )
void cmCursesOptionsWidget::NextOption()
{
this->CurrentOption++;
- if(this->CurrentOption > this->Options.size()-1)
- {
+ if (this->CurrentOption > this->Options.size() - 1) {
this->CurrentOption = 0;
- }
+ }
this->SetValue(this->Options[this->CurrentOption]);
}
void cmCursesOptionsWidget::PreviousOption()
{
- if(this->CurrentOption == 0)
- {
- this->CurrentOption = this->Options.size()-1;
- }
- else
- {
+ if (this->CurrentOption == 0) {
+ this->CurrentOption = this->Options.size() - 1;
+ } else {
this->CurrentOption--;
- }
+ }
this->SetValue(this->Options[this->CurrentOption]);
}
@@ -94,13 +83,11 @@ void cmCursesOptionsWidget::SetOption(const std::string& value)
this->CurrentOption = 0; // default to 0 index
this->SetValue(value);
int index = 0;
- for(std::vector<std::string>::iterator i = this->Options.begin();
- i != this->Options.end(); ++i)
- {
- if(*i == value)
- {
+ for (std::vector<std::string>::iterator i = this->Options.begin();
+ i != this->Options.end(); ++i) {
+ if (*i == value) {
this->CurrentOption = index;
- }
- index++;
}
+ index++;
+ }
}
diff --git a/Source/CursesDialog/cmCursesOptionsWidget.h b/Source/CursesDialog/cmCursesOptionsWidget.h
index ba359d3..a17f2d5 100644
--- a/Source/CursesDialog/cmCursesOptionsWidget.h
+++ b/Source/CursesDialog/cmCursesOptionsWidget.h
@@ -27,9 +27,10 @@ public:
// handled.
virtual bool HandleInput(int& key, cmCursesMainForm* fm, WINDOW* w);
void SetOption(const std::string&);
- void AddOption(std::string const &);
+ void AddOption(std::string const&);
void NextOption();
void PreviousOption();
+
protected:
cmCursesOptionsWidget(const cmCursesOptionsWidget& from);
void operator=(const cmCursesOptionsWidget&);
diff --git a/Source/CursesDialog/cmCursesPathWidget.cxx b/Source/CursesDialog/cmCursesPathWidget.cxx
index 6116823..33fffd1 100644
--- a/Source/CursesDialog/cmCursesPathWidget.cxx
+++ b/Source/CursesDialog/cmCursesPathWidget.cxx
@@ -14,9 +14,9 @@
#include "cmCursesMainForm.h"
#include "cmSystemTools.h"
-cmCursesPathWidget::cmCursesPathWidget(int width, int height,
- int left, int top) :
- cmCursesStringWidget(width, height, left, top)
+cmCursesPathWidget::cmCursesPathWidget(int width, int height, int left,
+ int top)
+ : cmCursesStringWidget(width, height, left, top)
{
this->Type = cmState::PATH;
this->Cycle = false;
@@ -33,46 +33,39 @@ void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
{
- if ( !this->GetString() )
- {
+ if (!this->GetString()) {
return;
- }
+ }
FORM* form = fm->GetForm();
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
std::string cstr = this->GetString();
- cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
- if ( this->LastString != cstr )
- {
+ cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r") + 1);
+ if (this->LastString != cstr) {
this->Cycle = false;
this->CurrentIndex = 0;
this->LastGlob = "";
- }
+ }
std::string glob;
- if ( this->Cycle )
- {
+ if (this->Cycle) {
glob = this->LastGlob;
- }
- else
- {
+ } else {
glob = cstr + "*";
- }
+ }
std::vector<std::string> dirs;
- cmSystemTools::SimpleGlob(glob, dirs, (this->Type == cmState::PATH?-1:0));
- if ( this->CurrentIndex < dirs.size() )
- {
+ cmSystemTools::SimpleGlob(glob, dirs,
+ (this->Type == cmState::PATH ? -1 : 0));
+ if (this->CurrentIndex < dirs.size()) {
cstr = dirs[this->CurrentIndex];
- }
- if ( cstr[cstr.size()-1] == '*' )
- {
- cstr = cstr.substr(0, cstr.size()-1);
- }
+ }
+ if (cstr[cstr.size() - 1] == '*') {
+ cstr = cstr.substr(0, cstr.size() - 1);
+ }
- if ( cmSystemTools::FileIsDirectory(cstr) )
- {
+ if (cmSystemTools::FileIsDirectory(cstr)) {
cstr += "/";
- }
+ }
this->SetString(cstr);
touchwin(w);
@@ -81,11 +74,10 @@ void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
this->LastGlob = glob;
this->LastString = cstr;
this->Cycle = true;
- this->CurrentIndex ++;
- if ( this->CurrentIndex >= dirs.size() )
- {
+ this->CurrentIndex++;
+ if (this->CurrentIndex >= dirs.size()) {
this->CurrentIndex = 0;
- }
+ }
}
void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
diff --git a/Source/CursesDialog/cmCursesStandardIncludes.h b/Source/CursesDialog/cmCursesStandardIncludes.h
index 69a05b2..7b44df9 100644
--- a/Source/CursesDialog/cmCursesStandardIncludes.h
+++ b/Source/CursesDialog/cmCursesStandardIncludes.h
@@ -15,12 +15,12 @@
#include "../cmStandardIncludes.h"
#if defined(__sun__) && defined(__GNUC__)
- #define _MSE_INT_H
+#define _MSE_INT_H
#endif
#if defined(__hpux)
-# define _BOOL_DEFINED
-# include <sys/time.h>
+#define _BOOL_DEFINED
+#include <sys/time.h>
#endif
#include <form.h>
@@ -29,7 +29,7 @@
// so remove them from the namespace
inline void curses_move(unsigned int x, unsigned int y)
{
- move(x,y);
+ move(x, y);
}
inline void curses_clear()
@@ -42,5 +42,4 @@ inline void curses_clear()
#undef erase
#undef clear
-
#endif // cmCursesStandardIncludes_h
diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx
index 6bd7b45..3707d0d 100644
--- a/Source/CursesDialog/cmCursesStringWidget.cxx
+++ b/Source/CursesDialog/cmCursesStringWidget.cxx
@@ -15,30 +15,29 @@
inline int ctrl(int z)
{
- return (z&037);
+ return (z & 037);
}
-cmCursesStringWidget::cmCursesStringWidget(int width, int height,
- int left, int top) :
- cmCursesWidget(width, height, left, top)
+cmCursesStringWidget::cmCursesStringWidget(int width, int height, int left,
+ int top)
+ : cmCursesWidget(width, height, left, top)
{
this->InEdit = false;
this->Type = cmState::STRING;
- set_field_fore(this->Field, A_NORMAL);
- set_field_back(this->Field, A_STANDOUT);
- field_opts_off(this->Field, O_STATIC);
+ set_field_fore(this->Field, A_NORMAL);
+ set_field_back(this->Field, A_STANDOUT);
+ field_opts_off(this->Field, O_STATIC);
}
void cmCursesStringWidget::OnTab(cmCursesMainForm*, WINDOW*)
{
- //FORM* form = fm->GetForm();
+ // FORM* form = fm->GetForm();
}
void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*)
{
FORM* form = fm->GetForm();
- if (this->InEdit)
- {
+ if (this->InEdit) {
cmCursesForm::LogMessage("String widget leaving edit.");
this->InEdit = false;
fm->PrintKeys();
@@ -47,16 +46,14 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW*)
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
this->Done = true;
- }
- else
- {
+ } else {
cmCursesForm::LogMessage("String widget entering edit.");
this->InEdit = true;
fm->PrintKeys();
char* buf = field_buffer(this->Field, 0);
- this->OriginalString = new char[strlen(buf)+1];
+ this->OriginalString = new char[strlen(buf) + 1];
strcpy(this->OriginalString, buf);
- }
+ }
}
void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*)
@@ -67,23 +64,21 @@ void cmCursesStringWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW*)
bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
WINDOW* w)
{
- int x,y;
+ int x, y;
FORM* form = fm->GetForm();
// 10 == enter
- if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) )
- {
+ if (!this->InEdit && (key != 10 && key != KEY_ENTER)) {
return false;
- }
+ }
- this->OriginalString=0;
+ this->OriginalString = 0;
this->Done = false;
char debugMessage[128];
// <Enter> is used to change edit mode (like <Esc> in vi).
- while(!this->Done)
- {
+ while (!this->Done) {
sprintf(debugMessage, "String widget handling input, key: %d", key);
cmCursesForm::LogMessage(debugMessage);
@@ -91,48 +86,36 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
getmaxyx(stdscr, y, x);
// If window too small, handle 'q' only
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
// quit
- if ( key == 'q' )
- {
+ if (key == 'q') {
return false;
- }
- else
- {
- key=getch();
+ } else {
+ key = getch();
continue;
- }
}
+ }
// If resize occurred during edit, move out of edit mode
- if (!this->InEdit && ( key != 10 && key != KEY_ENTER ) )
- {
+ if (!this->InEdit && (key != 10 && key != KEY_ENTER)) {
return false;
- }
+ }
// 10 == enter
- if (key == 10 || key == KEY_ENTER)
- {
+ if (key == 10 || key == KEY_ENTER) {
this->OnReturn(fm, w);
- }
- else if ( key == KEY_DOWN || key == ctrl('n') ||
- key == KEY_UP || key == ctrl('p') ||
- key == KEY_NPAGE || key == ctrl('d') ||
- key == KEY_PPAGE || key == ctrl('u'))
- {
+ } else if (key == KEY_DOWN || key == ctrl('n') || key == KEY_UP ||
+ key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') ||
+ key == KEY_PPAGE || key == ctrl('u')) {
this->InEdit = false;
delete[] this->OriginalString;
// trick to force forms to update the field buffer
form_driver(form, REQ_NEXT_FIELD);
form_driver(form, REQ_PREV_FIELD);
return false;
- }
+ }
// esc
- else if (key == 27)
- {
- if (this->InEdit)
- {
+ else if (key == 27) {
+ if (this->InEdit) {
this->InEdit = false;
fm->PrintKeys();
this->SetString(this->OriginalString);
@@ -140,58 +123,37 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm,
touchwin(w);
wrefresh(w);
return true;
- }
}
- else if ( key == 9 )
- {
+ } else if (key == 9) {
this->OnTab(fm, w);
- }
- else if ( key == KEY_LEFT || key == ctrl('b') )
- {
+ } else if (key == KEY_LEFT || key == ctrl('b')) {
form_driver(form, REQ_PREV_CHAR);
- }
- else if ( key == KEY_RIGHT || key == ctrl('f') )
- {
+ } else if (key == KEY_RIGHT || key == ctrl('f')) {
form_driver(form, REQ_NEXT_CHAR);
- }
- else if ( key == ctrl('k') )
- {
+ } else if (key == ctrl('k')) {
form_driver(form, REQ_CLR_EOL);
- }
- else if ( key == ctrl('a') || key == KEY_HOME )
- {
+ } else if (key == ctrl('a') || key == KEY_HOME) {
form_driver(form, REQ_BEG_FIELD);
- }
- else if ( key == ctrl('e') || key == KEY_END )
- {
+ } else if (key == ctrl('e') || key == KEY_END) {
form_driver(form, REQ_END_FIELD);
+ } else if (key == 127 || key == KEY_BACKSPACE) {
+ FIELD* cur = current_field(form);
+ form_driver(form, REQ_DEL_PREV);
+ if (current_field(form) != cur) {
+ set_current_field(form, cur);
}
- else if ( key == 127 ||
- key == KEY_BACKSPACE )
- {
- FIELD *cur = current_field(form);
- form_driver(form, REQ_DEL_PREV);
- if (current_field(form) != cur)
- {
- set_current_field(form, cur);
- }
- }
- else if ( key == ctrl('d') ||key == KEY_DC )
- {
+ } else if (key == ctrl('d') || key == KEY_DC) {
form_driver(form, REQ_DEL_CHAR);
- }
- else
- {
+ } else {
this->OnType(key, fm, w);
- }
- if ( !this->Done )
- {
+ }
+ if (!this->Done) {
touchwin(w);
wrefresh(w);
- key=getch();
- }
+ key = getch();
}
+ }
return true;
}
@@ -212,38 +174,32 @@ const char* cmCursesStringWidget::GetValue()
bool cmCursesStringWidget::PrintKeys()
{
- int x,y;
+ int x, y;
getmaxyx(stdscr, y, x);
- if ( x < cmCursesMainForm::MIN_WIDTH ||
- y < cmCursesMainForm::MIN_HEIGHT )
- {
+ if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
return false;
- }
- if (this->InEdit)
- {
+ }
+ if (this->InEdit) {
char fmt_s[] = "%s";
char firstLine[512];
// Clean the toolbar
- for(int i=0; i<512; i++)
- {
+ for (int i = 0; i < 512; i++) {
firstLine[i] = ' ';
- }
+ }
firstLine[511] = '\0';
- curses_move(y-4,0);
+ curses_move(y - 4, 0);
printw(fmt_s, firstLine);
- curses_move(y-3,0);
+ curses_move(y - 3, 0);
printw(fmt_s, firstLine);
- curses_move(y-2,0);
+ curses_move(y - 2, 0);
printw(fmt_s, firstLine);
- curses_move(y-1,0);
+ curses_move(y - 1, 0);
printw(fmt_s, firstLine);
- curses_move(y-3,0);
+ curses_move(y - 3, 0);
printw(fmt_s, "Editing option, press [enter] to leave edit.");
return true;
- }
- else
- {
+ } else {
return false;
- }
+ }
}
diff --git a/Source/CursesDialog/cmCursesWidget.cxx b/Source/CursesDialog/cmCursesWidget.cxx
index a12e4c2..100ed1d 100644
--- a/Source/CursesDialog/cmCursesWidget.cxx
+++ b/Source/CursesDialog/cmCursesWidget.cxx
@@ -15,41 +15,36 @@ cmCursesWidget::cmCursesWidget(int width, int height, int left, int top)
{
this->Field = new_field(height, width, top, left, 0, 0);
set_field_userptr(this->Field, reinterpret_cast<char*>(this));
- field_opts_off(this->Field, O_AUTOSKIP);
+ field_opts_off(this->Field, O_AUTOSKIP);
this->Page = 0;
}
cmCursesWidget::~cmCursesWidget()
{
- if (this->Field)
- {
+ if (this->Field) {
free_field(this->Field);
this->Field = 0;
- }
+ }
}
void cmCursesWidget::Move(int x, int y, bool isNewPage)
{
- if (!this->Field)
- {
+ if (!this->Field) {
return;
- }
+ }
move_field(this->Field, y, x);
- if (isNewPage)
- {
+ if (isNewPage) {
set_new_page(this->Field, TRUE);
- }
- else
- {
+ } else {
set_new_page(this->Field, FALSE);
- }
+ }
}
void cmCursesWidget::SetValue(const std::string& value)
{
this->Value = value;
- set_field_buffer(this->Field, 0, const_cast<char *>(value.c_str()));
+ set_field_buffer(this->Field, 0, const_cast<char*>(value.c_str()));
}
const char* cmCursesWidget::GetValue()
diff --git a/Source/CursesDialog/cmCursesWidget.h b/Source/CursesDialog/cmCursesWidget.h
index 1f53786..2ac5bb8 100644
--- a/Source/CursesDialog/cmCursesWidget.h
+++ b/Source/CursesDialog/cmCursesWidget.h
@@ -47,30 +47,20 @@ public:
/**
* Get the type of the widget (STRING, PATH etc...)
*/
- cmState::CacheEntryType GetType()
- { return this->Type; }
+ cmState::CacheEntryType GetType() { return this->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;
- }
+ virtual bool PrintKeys() { return false; }
/**
* Set/Get the page this widget is in.
*/
- void SetPage(int page)
- {
- this->Page = page;
- }
- int GetPage()
- {
- return this->Page;
- }
+ void SetPage(int page) { this->Page = page; }
+ int GetPage() { return this->Page; }
friend class cmCursesMainForm;