CHANGELOG added. Other trivial changes.
[jben.git] / dialog_addkanjibyfreq.cpp
blob526bad2b828de32646e57e2efdeaf5ce4bea6d0f
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: dialog_addkanjibyfreq.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 "dialog_addkanjibyfreq.h"
26 enum {
27 ID_buttonOK=wxID_OK,
28 ID_buttonCancel=wxID_CANCEL,
29 ID_spinLow=1,
30 ID_spinHigh
33 BEGIN_EVENT_TABLE(DialogAddKanjiByFreq, wxDialog)
34 EVT_BUTTON(ID_buttonOK, DialogAddKanjiByFreq::OnOK)
35 EVT_BUTTON(ID_buttonCancel, DialogAddKanjiByFreq::OnCancel)
36 EVT_KEY_DOWN(DialogAddKanjiByFreq::OnKeyDown)
37 EVT_SPINCTRL(ID_spinLow, DialogAddKanjiByFreq::OnLowValChange)
38 EVT_SPINCTRL(ID_spinHigh, DialogAddKanjiByFreq::OnHighValChange)
39 END_EVENT_TABLE()
41 DialogAddKanjiByFreq::DialogAddKanjiByFreq(wxWindow *parent)
42 : wxDialog(parent, wxID_ANY, wxString(_T("Add Kanji By Grade"))) {
43 spinLowFreq = new wxSpinCtrl(this, ID_spinLow, wxEmptyString,
44 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 2501, 1);
45 spinHighFreq = new wxSpinCtrl(this, ID_spinHigh, wxEmptyString,
46 wxDefaultPosition, wxDefaultSize, wxSP_ARROW_KEYS, 1, 2501, 2501);
48 btnOK = new wxButton(this, ID_buttonOK, _T("OK"));
49 btnCancel = new wxButton(this, ID_buttonCancel, _T("Cancel"));
50 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
51 mainSizer->Add(spinLowFreq, 0, wxALL, 10);
52 mainSizer->Add(spinHighFreq, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10);
53 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
54 buttonSizer->Add(btnOK, 0, wxRIGHT, 10);
55 buttonSizer->Add(btnCancel, 0);
56 mainSizer->Add(buttonSizer, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10);
57 this->SetSizerAndFit(mainSizer);
58 spinLowFreq->SetFocus();
61 int DialogAddKanjiByFreq::GetLowFreq() {
62 return spinLowFreq->GetValue();
65 int DialogAddKanjiByFreq::GetHighFreq() {
66 return spinHighFreq->GetValue();
69 void DialogAddKanjiByFreq::OKProc() {
70 int l = GetLowFreq();
71 int h = GetHighFreq();
72 if(h<l)
73 wxMessageBox(_T("Your high frequency rank cannot be less than your low frequency rank."), _T("Bad frequency range"), wxOK | wxICON_WARNING, this);
74 else
75 EndModal(ID_buttonOK);
78 void DialogAddKanjiByFreq::CancelProc() {
79 EndModal(ID_buttonCancel);
82 void DialogAddKanjiByFreq::OnOK(wxCommandEvent& ev) {OKProc();}
83 void DialogAddKanjiByFreq::OnCancel(wxCommandEvent& ev) {CancelProc();}
85 void DialogAddKanjiByFreq::OnKeyDown(wxKeyEvent& ev) {
86 int i = ev.GetKeyCode();
87 switch(i) {
88 case WXK_ESCAPE:
89 CancelProc();
90 break;
91 case WXK_RETURN:
92 OKProc();
93 break;
94 default:
95 ev.Skip();
99 void DialogAddKanjiByFreq::OnLowValChange(wxSpinEvent& ev) {
100 int low, high;
101 low = spinLowFreq->GetValue();
102 high = spinHighFreq->GetValue();
103 if(low>high)
104 spinHighFreq->SetValue(low);
107 void DialogAddKanjiByFreq::OnHighValChange(wxSpinEvent& ev) {
108 int low, high;
109 low = spinLowFreq->GetValue();
110 high = spinHighFreq->GetValue();
111 if(high<low)
112 spinLowFreq->SetValue(high);