CMake/Source/CursesDialog/cmCursesBoolWidget.cxx

60 lines
1.6 KiB
C++
Raw Normal View History

/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
2002-01-21 23:30:43 +03:00
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
2002-01-21 23:30:43 +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.
============================================================================*/
2001-11-05 02:05:21 +03:00
#include "cmCursesBoolWidget.h"
2001-12-13 21:28:41 +03:00
#include "cmCursesMainForm.h"
2001-11-05 02:05:21 +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
{
this->Type = cmState::BOOL;
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);
}
bool cmCursesBoolWidget::HandleInput(int& key, cmCursesMainForm*, WINDOW* w)
2001-11-05 02:05:21 +03:00
{
2001-12-13 21:28:41 +03:00
// toggle boolean values with enter or space
2001-11-05 02:05:21 +03:00
// 10 == enter
if (key == 10 || key == KEY_ENTER || key == ' ') {
if (this->GetValueAsBool()) {
2001-11-05 02:05:21 +03:00
this->SetValueAsBool(false);
} else {
2001-11-05 02:05:21 +03:00
this->SetValueAsBool(true);
}
2001-11-05 02:05:21 +03:00
touchwin(w);
wrefresh(w);
2001-11-05 02:05:21 +03:00
return true;
} else {
2001-11-05 02:05:21 +03:00
return false;
}
2001-11-05 02:05:21 +03:00
}
void cmCursesBoolWidget::SetValueAsBool(bool value)
{
if (value) {
2001-11-05 02:05:21 +03:00
this->SetValue("ON");
} else {
2001-11-05 02:05:21 +03:00
this->SetValue("OFF");
}
2001-11-05 02:05:21 +03:00
}
bool cmCursesBoolWidget::GetValueAsBool()
{
return this->Value == "ON";
2001-11-05 02:05:21 +03:00
}