cmake/Source/CursesDialog/cmCursesBoolWidget.cxx

63 lines
1.6 KiB
C++
Raw Normal View History

2009-10-04 10:30:41 +03:00
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2009-10-04 10:30:41 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2009-10-04 10:30:41 +03:00
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#include "cmCursesBoolWidget.h"
2016-07-09 11:21:54 +02:00
#include "cmCursesMainForm.h"
2016-07-09 11:21:54 +02:00
cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
int top)
: cmCursesWidget(width, height, left, top)
{
2015-08-17 11:37:30 +02:00
this->Type = cmState::BOOL;
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);
this->SetValueAsBool(false);
}
bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
{
// 10 == enter
2016-07-09 11:21:54 +02:00
if (key == 10 || key == KEY_ENTER) {
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
} else {
return false;
2016-07-09 11:21:54 +02:00
}
}
void cmCursesBoolWidget::SetValueAsBool(bool value)
{
2016-07-09 11:21:54 +02:00
if (value) {
this->SetValue("ON");
2016-07-09 11:21:54 +02:00
} else {
this->SetValue("OFF");
2016-07-09 11:21:54 +02:00
}
}
bool cmCursesBoolWidget::GetValueAsBool()
{
2016-07-09 11:21:54 +02:00
if (this->Value == "ON") {
return true;
2016-07-09 11:21:54 +02:00
} else {
return false;
2016-07-09 11:21:54 +02:00
}
}