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. */
|
2008-10-12 18:41:06 +02:00
|
|
|
#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)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
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);
|
2008-10-12 18:41:06 +02:00
|
|
|
this->SetValueAsBool(false);
|
|
|
|
}
|
|
|
|
|
2016-10-30 18:24:19 +01:00
|
|
|
bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
|
|
|
|
WINDOW* w)
|
2008-10-12 18:41:06 +02:00
|
|
|
{
|
|
|
|
|
2016-10-30 18:24:19 +01:00
|
|
|
// toggle boolean values with enter or space
|
2008-10-12 18:41:06 +02:00
|
|
|
// 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()) {
|
2008-10-12 18:41:06 +02:00
|
|
|
this->SetValueAsBool(false);
|
2016-07-09 11:21:54 +02:00
|
|
|
} else {
|
2008-10-12 18:41:06 +02:00
|
|
|
this->SetValueAsBool(true);
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
|
2013-03-16 19:13:01 +02:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
2008-10-12 18:41:06 +02:00
|
|
|
return true;
|
2016-07-09 11:21:54 +02:00
|
|
|
}
|
2016-10-30 18:24:19 +01:00
|
|
|
return false;
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesBoolWidget::SetValueAsBool(bool value)
|
|
|
|
{
|
2016-07-09 11:21:54 +02:00
|
|
|
if (value) {
|
2008-10-12 18:41:06 +02:00
|
|
|
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 {
|
2008-10-12 18:41:06 +02:00
|
|
|
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
|
|
|
}
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCursesBoolWidget::GetValueAsBool()
|
|
|
|
{
|
2016-10-30 18:24:19 +01:00
|
|
|
return this->Value == "ON";
|
2008-10-12 18:41:06 +02:00
|
|
|
}
|