Renamed kpengine to jben_kpengine and made its data dir relocatable.
[jben.git] / panel_config.cpp
blobac4d84f5259adfbe2f67711fb7cb1315c383f44a
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: panel_config.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 "panel_config.h"
25 #include "jben.h"
26 #include "kdict.h"
28 enum {
29 ID_chkReadings=1,
30 ID_chkMeanings,
31 ID_chkHighImportance,
32 ID_chkVocabCrossRef,
33 ID_chkLowImportance,
34 ID_chkUseSODs,
35 ID_chkUseSODAs,
37 ID_scrlDictionaries,
38 ID_btnApply,
40 ID_chkDictionaries,
41 ID_chkDictBase
44 BEGIN_EVENT_TABLE(PanelConfig, wxPanel)
45 EVT_BUTTON(ID_btnApply, PanelConfig::OnApply)
46 EVT_CHECKBOX(ID_chkDictionaries, PanelConfig::OnDictionaryToggle)
47 END_EVENT_TABLE()
49 PanelConfig::PanelConfig(wxWindow *owner) : RedrawablePanel(owner) {
50 /* Make main controls */
51 chkReadings = new wxCheckBox(this, ID_chkReadings, _T("Include on-yomi, kun-yomi, and nanori (name) readings"));
52 chkMeanings = new wxCheckBox(this, ID_chkMeanings, _T("Include English meanings"));
53 chkHighImportance = new wxCheckBox(this, ID_chkHighImportance, _T("Include stroke count, Jouyou grade and newspaper frequency rank"));
54 chkDictionaries = new wxCheckBox(this, ID_chkDictionaries, _T("Include dictionary reference codes"));
55 scrlDictionaries = new wxScrolledWindow(this, ID_scrlDictionaries, wxDefaultPosition, wxDefaultSize, wxVSCROLL | wxHSCROLL | wxSUNKEN_BORDER | wxTAB_TRAVERSAL);
56 scrlDictionaries->SetBackgroundColour(*wxWHITE);
57 chkVocabCrossRef = new wxCheckBox(this, ID_chkVocabCrossRef, _T("Show vocab from your study list which use this kanji"));
58 chkLowImportance = new wxCheckBox(this, ID_chkLowImportance, _T("Other information (Radical #'s, Korean and Pinyin romanization)"));
59 chkUseSODs = new wxCheckBox(this, ID_chkUseSODs, _T("Use KanjiCafe.com stroke order diagrams"));
60 chkUseSODAs = new wxCheckBox(this, ID_chkUseSODAs, _T("Use KanjiCafe.com animated stroke order diagrams"));
61 wxButton *btnApply = new wxButton(this, ID_btnApply, _T("Apply Changes"));
63 /* Create our list of dictionaries */
64 dictionaryList.Add(_T("\"New Japanese-English Character Dictionary\" by Jack Halpern."));
65 dictionaryList.Add(_T("\"Modern Reader's Japanese-English Character Dictionary\" by Andrew Nelson"));
66 dictionaryList.Add(_T("\"The New Nelson Japanese-English Character Dictionary\" by John Haig"));
67 dictionaryList.Add(_T("\"Japanese for Busy People\" by AJLT"));
68 dictionaryList.Add(_T("\"The Kanji Way to Japanese Language Power\" by Dale Crowley"));
69 dictionaryList.Add(_T("\"Kodansha Compact Kanji Guide\""));
70 dictionaryList.Add(_T("\"A Guide To Reading and Writing Japanese\" by Ken Hensall et al."));
71 dictionaryList.Add(_T("\"Kanji in Context\" by Nishiguchi and Kono"));
72 dictionaryList.Add(_T("\"Kanji Learner's Dictionary\" by Jack Halpern"));
73 dictionaryList.Add(_T("\"Essential Kanji\" by P.G. O'Neill"));
74 dictionaryList.Add(_T("\"2001 Kanji\" by Father Joseph De Roo"));
75 dictionaryList.Add(_T("\"A Guide To Reading and Writing Japanese\" by Florence Sakade"));
76 dictionaryList.Add(_T("\"Tuttle Kanji Cards\" by Alexander Kask"));
77 dictionaryList.Add(_T("\"Japanese Kanji Flashcards\" by White Rabbit Press"));
78 dictionaryList.Add(_T("(Not yet supported) SKIP codes used by Halpern dictionaries"));
79 dictionaryList.Add(_T("\"Kanji Dictionary\" by Spahn && Hadamitzky"));
80 dictionaryList.Add(_T("\"Kanji && Kana\" by Spahn && Hadamitzky"));
81 dictionaryList.Add(_T("Four Corner code (various dictionaries)"));
82 dictionaryList.Add(_T("\"Morohashi Daikanwajiten\" (index number)"));
83 dictionaryList.Add(_T("\"Morohashi Daikanwajiten\" (volume.page number)"));
84 dictionaryList.Add(_T("\"A Guide to Remembering Japanese Characters\" by Kenneth G. Henshal"));
85 dictionaryList.Add(_T("Gakken Kanji Dictionary (\"A New Dictionary of Kanji Usage\")"));
86 dictionaryList.Add(_T("\"Remembering The Kanji\" by James Heisig"));
87 dictionaryList.Add(_T("\"Japanese Names\" by P.G. O'Neill"));
89 /* Make controls for dictionary stuff */
90 int dictCount = dictionaryList.Count();
91 if(dictCount>0) chkarrayDictionaries = new ScrolledCheck*[dictCount];
92 else chkarrayDictionaries = NULL;
93 wxBoxSizer *dictSizer = new wxBoxSizer(wxVERTICAL);
94 int i;
95 for(i=0;i<dictCount;i++) {
96 chkarrayDictionaries[i] = new ScrolledCheck(scrlDictionaries, ID_chkDictBase+i, i, dictionaryList[i]);
97 dictSizer->Add(chkarrayDictionaries[i]);
99 if(dictCount>0)
100 scrlDictionaries->SetScrollRate(25, chkarrayDictionaries[0]->GetSize().GetHeight());
101 scrlDictionaries->SetSizer(dictSizer);
103 /* Connect event handlers for all checkboxes (except the parent dictionary checkbox,
104 since it already has a special handler configured.) */
105 /* NOTE:
106 Here's the Connect call used in the Event sample:
107 Connect(Event_Dynamic, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
108 (wxObjectEventFunction)
109 (wxEventFunction)
110 (wxCommandEventFunction)&MyFrame::OnDynamic);
111 In practice, only the (wxObjectEventFunction) cast appears to be necessary (under GNU gcc). */
112 this->Connect(ID_chkReadings, ID_chkUseSODAs,
113 wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&PanelConfig::OnCheckboxToggle);
114 this->Connect(ID_chkDictBase, ID_chkDictBase+dictCount-1,
115 wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction)&PanelConfig::OnCheckboxToggle);
117 /* Add everything to the main panel */
118 wxBoxSizer *panelSizer = new wxBoxSizer(wxVERTICAL);
119 panelSizer->Add(chkReadings, 0, wxTOP | wxLEFT | wxRIGHT, 10);
120 panelSizer->Add(chkMeanings, 0, wxLEFT | wxRIGHT, 10);
121 panelSizer->Add(chkHighImportance, 0, wxLEFT | wxRIGHT, 10);
122 panelSizer->Add(chkDictionaries, 0, wxTOP | wxLEFT | wxRIGHT, 10);
123 panelSizer->Add(scrlDictionaries, 1, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
124 panelSizer->Add(chkVocabCrossRef, 0, wxLEFT | wxRIGHT, 10);
125 panelSizer->Add(chkLowImportance, 0, wxLEFT | wxRIGHT, 10);
126 panelSizer->Add(chkUseSODs, 0, wxLEFT | wxRIGHT, 10);
127 panelSizer->Add(chkUseSODAs, 0, wxLEFT | wxRIGHT, 10);
128 panelSizer->Add(btnApply, 0, wxALIGN_CENTER | wxALL, 10);
130 changeDetected = false;
131 processingRedraw = false;
132 dictionariesEnabled =
133 Preferences::Get()->kanjidicOptions & KDO_DICTIONARIES;
134 UpdateDictionaryControls(dictionariesEnabled);
135 this->SetSizerAndFit(panelSizer);
138 PanelConfig::~PanelConfig() {
139 if(chkarrayDictionaries) delete[] chkarrayDictionaries;
142 void PanelConfig::OnApply(wxCommandEvent& event) {
143 Commit();
146 void PanelConfig::OnCheckboxToggle(wxCommandEvent& event) {
147 if(!processingRedraw) {
148 changeDetected = true;
152 void PanelConfig::OnDictionaryToggle(wxCommandEvent& event) {
153 if(!processingRedraw) {
154 bool value = chkDictionaries->GetValue();
155 if(value!=dictionariesEnabled) {
156 dictionariesEnabled = value;
157 UpdateDictionaryControls(dictionariesEnabled);
158 OnCheckboxToggle(event);
163 void PanelConfig::Commit() {
164 changeDetected = false;
165 unsigned long options=0, dictionaries=0;
166 if(chkReadings->GetValue()) options |= KDO_READINGS;
167 if(chkMeanings->GetValue()) options |= KDO_MEANINGS;
168 if(chkHighImportance->GetValue()) options |= KDO_HIGHIMPORTANCE;
169 if(chkDictionaries->GetValue()) options |= KDO_DICTIONARIES;
170 if(chkVocabCrossRef->GetValue()) options |= KDO_VOCABCROSSREF;
171 if(chkLowImportance->GetValue()) options |= KDO_LOWIMPORTANCE;
172 if(chkUseSODs->GetValue()) options |= KDO_SOD_STATIC;
173 if(chkUseSODAs->GetValue()) options |= KDO_SOD_ANIM;
175 int dictCount = dictionaryList.Count();
176 for(int i=0; i<dictCount; i++) {
177 if(chkarrayDictionaries[i]->GetValue()) dictionaries |= (1ul << i);
179 Preferences *prefs = Preferences::Get();
180 prefs->kanjidicOptions = options;
181 prefs->kanjidicDictionaries = dictionaries;
184 void PanelConfig::Revert() {
185 changeDetected = false;
186 /* We could have a Redraw() call here, but currently Revert is only called when changing away from this panel,
187 and thus it's a pointless call since Redraw will be done when this panel is selected again. */
190 void PanelConfig::Redraw() {
191 processingRedraw = true;
192 Preferences *prefs = Preferences::Get();
193 int options = prefs->kanjidicOptions;
194 int dictionaries = prefs->kanjidicDictionaries;
196 /* Set appropriate checkboxes */
197 chkReadings->SetValue(options & KDO_READINGS);
198 chkMeanings->SetValue(options & KDO_MEANINGS);
199 chkHighImportance->SetValue(options & KDO_HIGHIMPORTANCE);
200 chkDictionaries->SetValue(options & KDO_DICTIONARIES);
201 chkVocabCrossRef->SetValue(options & KDO_VOCABCROSSREF);
202 chkLowImportance->SetValue(options & KDO_LOWIMPORTANCE);
203 chkUseSODs->SetValue(options & KDO_SOD_STATIC);
204 chkUseSODAs->SetValue(options & KDO_SOD_ANIM);
206 int dictCount = dictionaryList.Count();
207 for(int i=0;i<dictCount;i++) {
208 chkarrayDictionaries[i]->SetValue(dictionaries & (1ul << i));
211 scrlDictionaries->Scroll(0,0);
213 processingRedraw = false;
214 dictionariesEnabled = chkDictionaries->GetValue();
217 bool PanelConfig::ChangeDetected() {return changeDetected;}
219 void PanelConfig::UpdateDictionaryControls(bool state) {
220 if(state) {
221 scrlDictionaries->Enable();
222 } else {
223 scrlDictionaries->Disable();