cmake/Source/CursesDialog/cmCursesOptionsWidget.cxx

86 lines
2.2 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2014-08-03 19:52:23 +02:00
#include "cmCursesOptionsWidget.h"
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include "cmCursesWidget.h"
#include "cmState.h"
2014-08-03 19:52:23 +02:00
2016-10-30 18:24:19 +01:00
#define ctrl(z) ((z)&037)
2014-08-03 19:52:23 +02:00
2016-07-09 11:21:54 +02:00
cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left,
int top)
: cmCursesWidget(width, height, left, top)
2014-08-03 19:52:23 +02:00
{
2015-08-17 11:37:30 +02:00
this->Type = cmState::BOOL; // this is a bit of a hack
2014-08-03 19:52:23 +02:00
// 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.
2016-07-09 11:21:54 +02:00
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
field_opts_off(this->Field, O_STATIC);
2014-08-03 19:52:23 +02:00
}
2016-10-30 18:24:19 +01:00
bool cmCursesOptionsWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
WINDOW* w)
2014-08-03 19:52:23 +02:00
{
2016-10-30 18:24:19 +01:00
switch (key) {
case 10: // 10 == enter
case KEY_ENTER:
this->NextOption();
touchwin(w);
wrefresh(w);
return true;
case KEY_LEFT:
case ctrl('b'):
touchwin(w);
wrefresh(w);
this->PreviousOption();
return true;
case KEY_RIGHT:
case ctrl('f'):
this->NextOption();
touchwin(w);
wrefresh(w);
return true;
default:
return false;
2016-07-09 11:21:54 +02:00
}
2014-08-03 19:52:23 +02:00
}
2016-07-09 11:21:54 +02:00
void cmCursesOptionsWidget::AddOption(std::string const& option)
2014-08-03 19:52:23 +02:00
{
this->Options.push_back(option);
}
void cmCursesOptionsWidget::NextOption()
{
this->CurrentOption++;
2016-07-09 11:21:54 +02:00
if (this->CurrentOption > this->Options.size() - 1) {
2014-08-03 19:52:23 +02:00
this->CurrentOption = 0;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
this->SetValue(this->Options[this->CurrentOption]);
2014-08-03 19:52:23 +02:00
}
void cmCursesOptionsWidget::PreviousOption()
{
2016-07-09 11:21:54 +02:00
if (this->CurrentOption == 0) {
this->CurrentOption = this->Options.size() - 1;
} else {
2014-08-03 19:52:23 +02:00
this->CurrentOption--;
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
this->SetValue(this->Options[this->CurrentOption]);
2014-08-03 19:52:23 +02:00
}
2015-04-27 22:25:09 +02:00
void cmCursesOptionsWidget::SetOption(const std::string& value)
2014-08-03 19:52:23 +02:00
{
this->CurrentOption = 0; // default to 0 index
this->SetValue(value);
int index = 0;
2016-07-09 11:21:54 +02:00
for (std::vector<std::string>::iterator i = this->Options.begin();
i != this->Options.end(); ++i) {
if (*i == value) {
2014-08-03 19:52:23 +02:00
this->CurrentOption = index;
}
2016-07-09 11:21:54 +02:00
index++;
}
2014-08-03 19:52:23 +02:00
}