cmake/Source/CursesDialog/cmCursesBoolWidget.cxx

65 lines
1.7 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. */
#include "cmCursesBoolWidget.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include <string>
2020-08-30 11:54:41 +02:00
#include "cmCursesColor.h"
2016-10-30 18:24:19 +01:00
#include "cmCursesWidget.h"
2017-04-14 19:02:05 +02:00
#include "cmStateTypes.h"
2016-10-30 18:24:19 +01:00
2016-07-09 11:21:54 +02:00
cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
int top)
: cmCursesWidget(width, height, left, top)
{
2017-04-14 19:02:05 +02:00
this->Type = cmStateEnums::BOOL;
2020-08-30 11:54:41 +02:00
if (!cmCursesColor::HasColors()) {
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
}
2016-07-09 11:21:54 +02:00
field_opts_off(this->Field, O_STATIC);
this->SetValueAsBool(false);
}
2016-10-30 18:24:19 +01:00
bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
WINDOW* w)
{
2016-10-30 18:24:19 +01:00
// toggle boolean values with enter or space
// 10 == enter
2016-10-30 18:24:19 +01:00
if (key == 10 || key == KEY_ENTER || key == ' ') {
2016-07-09 11:21:54 +02:00
if (this->GetValueAsBool()) {
this->SetValueAsBool(false);
2016-07-09 11:21:54 +02:00
} else {
this->SetValueAsBool(true);
2016-07-09 11:21:54 +02:00
}
2013-03-16 19:13:01 +02:00
touchwin(w);
wrefresh(w);
return true;
2016-07-09 11:21:54 +02:00
}
2016-10-30 18:24:19 +01:00
return false;
}
void cmCursesBoolWidget::SetValueAsBool(bool value)
{
2016-07-09 11:21:54 +02:00
if (value) {
this->SetValue("ON");
2020-08-30 11:54:41 +02:00
if (cmCursesColor::HasColors()) {
set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::BoolOn));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::BoolOn));
}
2016-07-09 11:21:54 +02:00
} else {
this->SetValue("OFF");
2020-08-30 11:54:41 +02:00
if (cmCursesColor::HasColors()) {
set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::BoolOff));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::BoolOff));
}
2016-07-09 11:21:54 +02:00
}
}
bool cmCursesBoolWidget::GetValueAsBool()
{
2016-10-30 18:24:19 +01:00
return this->Value == "ON";
}