Various changes to preferences object, file loading, and error logging.
[jben.git] / coveredtextbox.cpp
blob4a710d3261ab83d5cae6df1eb185cdd9e45e6512
1 /*
2 Project: J-Ben
3 Author: Paul Goins
4 Website: http://www.vultaire.net/software/jben/
5 License: GNU General Public License (GPL) version 2
6 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
8 File: coveredtextbox.cpp
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>
24 #include "coveredtextbox.h"
26 BEGIN_EVENT_TABLE(CoveredTextBox, wxTextCtrl)
27 /* */
28 EVT_KEY_UP(CoveredTextBox::OnKeyUp)
29 EVT_LEFT_UP(CoveredTextBox::OnMouseLeftUp)
30 END_EVENT_TABLE()
32 CoveredTextBox::CoveredTextBox(wxWindow *parent, int id, const wxString& coverString, const wxString& hiddenString, bool isCovered)
33 : wxTextCtrl(parent, id, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY) {
34 normalbg = this->GetBackgroundColour();
35 hidden = hiddenString;
36 cover = coverString;
37 Cover(isCovered);
40 void CoveredTextBox::UpdateValue() {
41 if(covered) {
42 this->SetValue(cover);
43 } else {
44 this->SetValue(hidden);
46 this->SetSelection(0,0);
49 void CoveredTextBox::Uncover() {
50 covered=false;
51 this->SetBackgroundColour(normalbg);
52 UpdateValue();
55 void CoveredTextBox::Cover() {
56 covered=true;
57 this->SetBackgroundColour(*wxLIGHT_GREY);
58 UpdateValue();
61 void CoveredTextBox::Cover(bool state) {
62 if(state) Cover();
63 else Uncover();
66 void CoveredTextBox::OnKeyUp(wxKeyEvent& event) {
67 if(covered && event.GetKeyCode()==WXK_SPACE) Uncover();
69 void CoveredTextBox::OnMouseLeftUp(wxMouseEvent& event) {
70 if(covered) Uncover();
71 event.Skip();
74 void CoveredTextBox::SetHiddenStr(const wxString& s) {hidden=s;}
75 void CoveredTextBox::SetCoverStr(const wxString& s) {cover=s;}