Const conversions for edict and kanjidic objects. Removal of obsolete dictionary...
[jben.git] / dialog_addkanjibygrade.cpp
blobf0a327ca45f701b2a69108388a943553c4767385
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_addkanjibygrade.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_addkanjibygrade.h"
26 enum {
27 ID_buttonOK=wxID_OK,
28 ID_buttonCancel=wxID_CANCEL,
29 ID_comboLow=1,
30 ID_comboHigh
33 BEGIN_EVENT_TABLE(DialogAddKanjiByGrade, wxDialog)
34 EVT_BUTTON(ID_buttonOK, DialogAddKanjiByGrade::OnOK)
35 EVT_BUTTON(ID_buttonCancel, DialogAddKanjiByGrade::OnCancel)
36 EVT_KEY_DOWN(DialogAddKanjiByGrade::OnKeyDown)
37 EVT_COMBOBOX(ID_comboLow, DialogAddKanjiByGrade::OnLowValChange)
38 EVT_COMBOBOX(ID_comboHigh, DialogAddKanjiByGrade::OnHighValChange)
39 END_EVENT_TABLE()
41 wxString comboStrings[] = {
42 _T("Jouyou Kanji Grade 1"),
43 _T("Jouyou Kanji Grade 2"),
44 _T("Jouyou Kanji Grade 3"),
45 _T("Jouyou Kanji Grade 4"),
46 _T("Jouyou Kanji Grade 5"),
47 _T("Jouyou Kanji Grade 6"),
48 _T("Jouyou Kanji, General Usage"),
49 _T("Jinmeiyou Kanji (for names)"),
50 _T("Non-Jouyou/Non-Jinmeiyou Kanji")
52 int comboStringCount = 9;
54 DialogAddKanjiByGrade::DialogAddKanjiByGrade(wxWindow *parent)
55 : wxDialog(parent, wxID_ANY, wxString(_T("Add Kanji By Grade"))) {
56 comboLowGrade = new wxComboBox(this, ID_comboLow, comboStrings[0], wxDefaultPosition, wxDefaultSize, 9, comboStrings, wxCB_DROPDOWN | wxCB_READONLY);
57 comboHighGrade = new wxComboBox(this, ID_comboHigh, comboStrings[0], wxDefaultPosition, wxDefaultSize, 9, comboStrings, wxCB_DROPDOWN | wxCB_READONLY);
59 btnOK = new wxButton(this, ID_buttonOK, _T("OK"));
60 btnCancel = new wxButton(this, ID_buttonCancel, _T("Cancel"));
61 wxBoxSizer *mainSizer = new wxBoxSizer(wxVERTICAL);
62 mainSizer->Add(comboLowGrade, 0, wxALL, 10);
63 mainSizer->Add(comboHighGrade, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10);
64 wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
65 buttonSizer->Add(btnOK, 0, wxRIGHT, 10);
66 buttonSizer->Add(btnCancel, 0);
67 mainSizer->Add(buttonSizer, 0, wxLEFT | wxRIGHT | wxBOTTOM, 10);
68 this->SetSizerAndFit(mainSizer);
69 comboLowGrade->SetFocus();
72 int ComboBoxToKanjidicGrade(wxComboBox *c) {
73 int i;
74 for(i=0;i<comboStringCount;i++)
75 if(c->GetValue()==comboStrings[i]) break;
76 if(i<6) return i+1; /* G1-G6 in KANJIDIC */
77 if(i==6) return 8; /* G8 (Jouyou Jr. High) in KANJIDIC */
78 if(i==7) return 9; /* G9 (Jinmeiyou) in KANJIDIC */
79 return 0; /* No grade listed in KANJIDIC */
82 int DialogAddKanjiByGrade::GetLowGrade() {
83 return ComboBoxToKanjidicGrade(comboLowGrade);
86 int DialogAddKanjiByGrade::GetHighGrade() {
87 return ComboBoxToKanjidicGrade(comboHighGrade);
90 #if 0
91 void DialogAddKanjiByGrade::OnClose(wxCloseEvent& ev) {
92 printf("OnClose event entered...\n");
93 if(ev.CanVeto()) {
94 printf("Event CAN be vetoed...\n");
95 int l = GetLowGrade();
96 int h = GetHighGrade();
97 if(h<l && h!=0) { /* 0 is a special code for non-graded kanji and is treated as the highest grade level here. */
98 wxMessageBox(_T("Your high grade level cannot be less than your low grade level."), _T("Bad grade range"), wxOK | wxICON_WARNING, this);
99 ev.Veto(true);
103 #endif
105 void DialogAddKanjiByGrade::OKProc() {
106 int l = GetLowGrade();
107 int h = GetHighGrade();
108 /* 0 is a special code for non-graded kanji and is treated
109 as the highest grade level here. */
110 if((h<l && h!=0) || (l==0 && h!=0))
111 wxMessageBox(_T("Your high grade level cannot be less than your low grade level."), _T("Bad grade range"), wxOK | wxICON_WARNING, this);
112 else
113 EndModal(ID_buttonOK);
116 void DialogAddKanjiByGrade::CancelProc() {
117 EndModal(ID_buttonCancel);
120 void DialogAddKanjiByGrade::OnOK(wxCommandEvent& ev) {OKProc();}
121 void DialogAddKanjiByGrade::OnCancel(wxCommandEvent& ev) {CancelProc();}
123 void DialogAddKanjiByGrade::OnKeyDown(wxKeyEvent& ev) {
124 int i = ev.GetKeyCode();
125 switch(i) {
126 case WXK_ESCAPE:
127 CancelProc();
128 break;
129 case WXK_RETURN:
130 OKProc();
131 break;
132 default:
133 ev.Skip();
137 void DialogAddKanjiByGrade::OnLowValChange(wxCommandEvent& ev) {
138 int low, high;
139 low = GetLowGrade();
140 high = GetHighGrade();
141 if(high!=0 && (low>high || low==0))
142 comboHighGrade->SetValue(comboLowGrade->GetValue());
145 void DialogAddKanjiByGrade::OnHighValChange(wxCommandEvent& ev) {
146 int low, high;
147 low = GetLowGrade();
148 high = GetHighGrade();
149 if(high!=0 && (high<low || low==0))
150 comboLowGrade->SetValue(comboHighGrade->GetValue());