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)
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"
44 BEGIN_EVENT_TABLE(PanelConfig
, wxPanel
)
45 EVT_BUTTON(ID_btnApply
, PanelConfig::OnApply
)
46 EVT_CHECKBOX(ID_chkDictionaries
, PanelConfig::OnDictionaryToggle
)
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
);
95 for(i
=0;i
<dictCount
;i
++) {
96 chkarrayDictionaries
[i
] = new ScrolledCheck(scrlDictionaries
, ID_chkDictBase
+i
, i
, dictionaryList
[i
]);
97 dictSizer
->Add(chkarrayDictionaries
[i
]);
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.) */
106 Here's the Connect call used in the Event sample:
107 Connect(Event_Dynamic, wxID_ANY, wxEVT_COMMAND_MENU_SELECTED,
108 (wxObjectEventFunction)
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
= prefs
->kanjidicOptions
& KDO_DICTIONARIES
;
133 UpdateDictionaryControls(dictionariesEnabled
);
134 this->SetSizerAndFit(panelSizer
);
137 PanelConfig::~PanelConfig() {
138 if(chkarrayDictionaries
) delete[] chkarrayDictionaries
;
141 void PanelConfig::OnApply(wxCommandEvent
& event
) {
145 void PanelConfig::OnCheckboxToggle(wxCommandEvent
& event
) {
146 if(!processingRedraw
) {
147 changeDetected
= true;
151 void PanelConfig::OnDictionaryToggle(wxCommandEvent
& event
) {
152 if(!processingRedraw
) {
153 bool value
= chkDictionaries
->GetValue();
154 if(value
!=dictionariesEnabled
) {
155 dictionariesEnabled
= value
;
156 UpdateDictionaryControls(dictionariesEnabled
);
157 OnCheckboxToggle(event
);
162 void PanelConfig::Commit() {
163 changeDetected
= false;
164 unsigned long options
=0, dictionaries
=0;
165 if(chkReadings
->GetValue()) options
|= KDO_READINGS
;
166 if(chkMeanings
->GetValue()) options
|= KDO_MEANINGS
;
167 if(chkHighImportance
->GetValue()) options
|= KDO_HIGHIMPORTANCE
;
168 if(chkDictionaries
->GetValue()) options
|= KDO_DICTIONARIES
;
169 if(chkVocabCrossRef
->GetValue()) options
|= KDO_VOCABCROSSREF
;
170 if(chkLowImportance
->GetValue()) options
|= KDO_LOWIMPORTANCE
;
171 if(chkUseSODs
->GetValue()) options
|= KDO_SOD_STATIC
;
172 if(chkUseSODAs
->GetValue()) options
|= KDO_SOD_ANIM
;
174 int dictCount
= dictionaryList
.Count();
175 for(int i
=0; i
<dictCount
; i
++) {
176 if(chkarrayDictionaries
[i
]->GetValue()) dictionaries
|= (1ul << i
);
178 prefs
->kanjidicOptions
= options
;
179 prefs
->kanjidicDictionaries
= dictionaries
;
182 void PanelConfig::Revert() {
183 changeDetected
= false;
184 /* We could have a Redraw() call here, but currently Revert is only called when changing away from this panel,
185 and thus it's a pointless call since Redraw will be done when this panel is selected again. */
188 void PanelConfig::Redraw() {
189 processingRedraw
= true;
190 int options
= prefs
->kanjidicOptions
;
191 int dictionaries
= prefs
->kanjidicDictionaries
;
193 /* Set appropriate checkboxes */
194 chkReadings
->SetValue(options
& KDO_READINGS
);
195 chkMeanings
->SetValue(options
& KDO_MEANINGS
);
196 chkHighImportance
->SetValue(options
& KDO_HIGHIMPORTANCE
);
197 chkDictionaries
->SetValue(options
& KDO_DICTIONARIES
);
198 chkVocabCrossRef
->SetValue(options
& KDO_VOCABCROSSREF
);
199 chkLowImportance
->SetValue(options
& KDO_LOWIMPORTANCE
);
200 chkUseSODs
->SetValue(options
& KDO_SOD_STATIC
);
201 chkUseSODAs
->SetValue(options
& KDO_SOD_ANIM
);
203 int dictCount
= dictionaryList
.Count();
204 for(int i
=0;i
<dictCount
;i
++) {
205 chkarrayDictionaries
[i
]->SetValue(dictionaries
& (1ul << i
));
208 scrlDictionaries
->Scroll(0,0);
210 processingRedraw
= false;
211 dictionariesEnabled
= chkDictionaries
->GetValue();
214 bool PanelConfig::ChangeDetected() {return changeDetected
;}
216 void PanelConfig::UpdateDictionaryControls(bool state
) {
218 scrlDictionaries
->Enable();
220 scrlDictionaries
->Disable();