2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2001-11-05 02:05:21 +03:00
|
|
|
#include "cmCursesBoolWidget.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-09-01 22:55:09 +03:00
|
|
|
#include "cmCursesWidget.h"
|
|
|
|
#include "cmState.h"
|
|
|
|
|
|
|
|
#include <string>
|
2001-11-05 02:05:21 +03:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
|
|
|
|
int top)
|
|
|
|
: cmCursesWidget(width, height, left, top)
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2015-04-07 23:45:54 +03:00
|
|
|
this->Type = cmState::BOOL;
|
2016-05-16 17:34:04 +03:00
|
|
|
set_field_fore(this->Field, A_NORMAL);
|
|
|
|
set_field_back(this->Field, A_STANDOUT);
|
|
|
|
field_opts_off(this->Field, O_STATIC);
|
2001-11-05 02:05:21 +03:00
|
|
|
this->SetValueAsBool(false);
|
|
|
|
}
|
|
|
|
|
2016-08-17 02:49:57 +03:00
|
|
|
bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm* /*fm*/,
|
|
|
|
WINDOW* w)
|
2001-11-05 02:05:21 +03:00
|
|
|
{
|
2001-12-13 21:28:41 +03:00
|
|
|
|
2016-07-21 22:30:50 +03:00
|
|
|
// toggle boolean values with enter or space
|
2001-11-05 02:05:21 +03:00
|
|
|
// 10 == enter
|
2016-07-21 22:30:50 +03:00
|
|
|
if (key == 10 || key == KEY_ENTER || key == ' ') {
|
2016-05-16 17:34:04 +03:00
|
|
|
if (this->GetValueAsBool()) {
|
2001-11-05 02:05:21 +03:00
|
|
|
this->SetValueAsBool(false);
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2001-11-05 02:05:21 +03:00
|
|
|
this->SetValueAsBool(true);
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
|
2012-08-13 21:42:58 +04:00
|
|
|
touchwin(w);
|
|
|
|
wrefresh(w);
|
2001-11-05 02:05:21 +03:00
|
|
|
return true;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2016-08-18 20:39:54 +03:00
|
|
|
return false;
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmCursesBoolWidget::SetValueAsBool(bool value)
|
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (value) {
|
2001-11-05 02:05:21 +03:00
|
|
|
this->SetValue("ON");
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2001-11-05 02:05:21 +03:00
|
|
|
this->SetValue("OFF");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cmCursesBoolWidget::GetValueAsBool()
|
|
|
|
{
|
2016-06-02 00:29:53 +03:00
|
|
|
return this->Value == "ON";
|
2001-11-05 02:05:21 +03:00
|
|
|
}
|