Import of widgets from wxKanjiPad, plus the files needed to compile kpengine. Also...
[jben.git] / maingui.cpp
blob311a78f4b0fb8987d698099fb76abe0c8e54e021
1 /*
2 Project: J-Ben
3 Author: Paul Goins
4 License: GNU General Public License (GPL) version 2
5 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
7 File: maingui.cpp
9 This file is part of J-Ben.
11 J-Ben is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License version 2
13 as published by the Free Software Foundation.
15 J-Ben 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 /* DEVNOTE: This code just got redone with a multi-level wxNotebook layout.
25 The code needs to be updated to raise events on the child notebooks and have those events properly handled.
26 Currently we just have code for handling the parent booklet (tabsMain). */
28 #include "global.h"
29 #include "version.h"
30 #include "maingui.h"
31 #include "wx/msgdlg.h"
32 #include "file_utils.h"
33 #include "wx/ffile.h"
35 #ifndef __WXMSW__
36 #include "jben.xpm"
37 #endif
39 enum {
40 ID_menuFileQuit=wxID_EXIT,
41 ID_menuHelpAbout=wxID_ABOUT,
43 ID_menuKanjiAddFromFile=1,
44 ID_menuKanjiAddByGrade,
45 ID_menuKanjiAddByFreq,
46 ID_menuKanjiSaveToFile,
47 ID_menuKanjiClearList,
48 #ifdef DEBUG
49 ID_menuKanjiDumpList,
50 #endif
51 ID_menuKanjiSortByGrade,
52 ID_menuKanjiSortByFreq,
53 ID_menuHelpLicense,
54 ID_tabsMain,
55 ID_tabsKanji,
56 ID_tabsWords,
57 ID_tabsConfig
60 BEGIN_EVENT_TABLE(MainGUI, wxFrame)
61 EVT_CLOSE(MainGUI::OnClose)
63 EVT_MENU(ID_menuFileQuit, MainGUI::OnFileQuit)
65 EVT_MENU(ID_menuKanjiAddFromFile, MainGUI::OnKanjiAddFromFile)
66 EVT_MENU(ID_menuKanjiAddByGrade, MainGUI::OnKanjiAddByGrade)
67 EVT_MENU(ID_menuKanjiAddByFreq, MainGUI::OnKanjiAddByFreq)
68 EVT_MENU(ID_menuKanjiSaveToFile, MainGUI::OnKanjiSaveToFile)
69 EVT_MENU(ID_menuKanjiClearList, MainGUI::OnKanjiClearList)
70 #ifdef DEBUG
71 EVT_MENU(ID_menuKanjiDumpList, MainGUI::OnKanjiDumpList)
72 #endif
73 EVT_MENU(ID_menuKanjiSortByGrade, MainGUI::OnKanjiSortByGrade)
74 EVT_MENU(ID_menuKanjiSortByFreq, MainGUI::OnKanjiSortByFreq)
76 EVT_MENU(ID_menuHelpAbout, MainGUI::OnHelpAbout)
77 EVT_MENU(ID_menuHelpLicense, MainGUI::OnHelpLicense)
79 EVT_NOTEBOOK_PAGE_CHANGING(ID_tabsMain, MainGUI::OnTabChanging)
80 EVT_NOTEBOOK_PAGE_CHANGED (ID_tabsMain, MainGUI::OnMajorTabChanged)
81 EVT_NOTEBOOK_PAGE_CHANGING(ID_tabsKanji, MainGUI::OnTabChanging)
82 EVT_NOTEBOOK_PAGE_CHANGED (ID_tabsKanji, MainGUI::OnMinorTabChanged)
83 EVT_NOTEBOOK_PAGE_CHANGING(ID_tabsWords, MainGUI::OnTabChanging)
84 EVT_NOTEBOOK_PAGE_CHANGED (ID_tabsWords, MainGUI::OnMinorTabChanged)
85 EVT_NOTEBOOK_PAGE_CHANGING(ID_tabsConfig, MainGUI::OnTabChanging)
86 EVT_NOTEBOOK_PAGE_CHANGED (ID_tabsConfig, MainGUI::OnMinorTabChanged)
88 END_EVENT_TABLE()
90 MainGUI::MainGUI() : wxFrame((wxFrame *)NULL, -1,
91 _T(PROGRAM_NAME " v" VERSION_STR " by " AUTHOR_NAME),
92 wxDefaultPosition, wxSize(600,400)) {
93 /* wxDefaultPosition, wxDefaultSize) { */
94 this->SetIcon(wxICON(iconJben));
95 wxInitAllImageHandlers(); /* This is needed for PNG support - GIFs seem to load fine without it. */
97 dialogAddKanjiByGrade = new DialogAddKanjiByGrade(this);
98 dialogAddKanjiByFreq = new DialogAddKanjiByFreq(this);
100 wxMenuBar *menuBar;
101 wxMenu *menu, *subMenu;
102 tabMinor = NULL;
104 menuBar = new wxMenuBar;
106 menu = new wxMenu;
107 menu->Append(ID_menuFileQuit, _T("E&xit..."));
108 menuBar->Append(menu, _T("&File"));
110 kanjiMenu = new wxMenu;
111 subMenu = new wxMenu;
112 subMenu->Append(ID_menuKanjiAddFromFile, _T("&From File..."));
113 subMenu->Append(ID_menuKanjiAddByGrade, _T("By Jouyou &Grade Level..."));
114 subMenu->Append(ID_menuKanjiAddByFreq, _T("By Newspaper F&requency Ranking..."));
115 kanjiMenu->AppendSubMenu(subMenu, _T("&Add Kanji"));
116 subMenu = new wxMenu;
117 subMenu->Append(ID_menuKanjiSortByGrade, _T("By Jouyou &Grade Level"));
118 subMenu->Append(ID_menuKanjiSortByFreq, _T("By Newspaper F&requency Ranking"));
119 kanjiMenu->AppendSubMenu(subMenu, _T("S&ort Kanji"));
120 kanjiMenu->Append(ID_menuKanjiSaveToFile, _T("&Save Kanji List to File..."));
121 if(jben->kanjiList->Size()==0)
122 kanjiMenu->Enable(ID_menuKanjiSaveToFile, false);
123 kanjiMenu->AppendSeparator();
124 kanjiMenu->Append(ID_menuKanjiClearList, _T("&Clear Kanji List"));
125 if(jben->kanjiList->Size()==0)
126 kanjiMenu->Enable(ID_menuKanjiClearList, false);
127 #ifdef DEBUG
128 kanjiMenu->Append(ID_menuKanjiDumpList, _T("&Dump Kanji List to Console"));
129 #endif
130 menuBar->Append(kanjiMenu, _T("&Kanji"));
132 menu = new wxMenu;
133 menu->Append(ID_menuHelpAbout, _T("&About..."));
134 menu->Append(ID_menuHelpLicense, _T("&License Information..."));
135 menuBar->Append(menu, _T("&Help"));
137 SetMenuBar(menuBar);
139 tabsMain = new wxNotebook(this,
140 ID_tabsMain,wxDefaultPosition,
141 wxDefaultSize,wxCLIP_CHILDREN | wxNB_TOP);
142 #ifdef __WXMSW__
143 tabsKanji = new wxNotebook(tabsMain,
144 ID_tabsKanji,wxDefaultPosition,
145 wxDefaultSize,wxCLIP_CHILDREN | wxNB_TOP);
146 tabsWords = new wxNotebook(tabsMain,
147 ID_tabsWords,wxDefaultPosition,
148 wxDefaultSize,wxCLIP_CHILDREN | wxNB_TOP);
149 tabsConfig = new wxNotebook(tabsMain,
150 ID_tabsConfig,wxDefaultPosition,
151 wxDefaultSize,wxCLIP_CHILDREN | wxNB_TOP);
152 #else
153 tabsKanji = new wxNotebook(tabsMain,
154 ID_tabsKanji,wxDefaultPosition,
155 wxDefaultSize,wxCLIP_CHILDREN | wxNB_LEFT);
156 tabsWords = new wxNotebook(tabsMain,
157 ID_tabsWords,wxDefaultPosition,
158 wxDefaultSize,wxCLIP_CHILDREN | wxNB_LEFT);
159 tabsConfig = new wxNotebook(tabsMain,
160 ID_tabsConfig,wxDefaultPosition,
161 wxDefaultSize,wxCLIP_CHILDREN | wxNB_LEFT);
162 #endif
163 tabsMain->AddPage(tabsKanji,_T("Kanji"),true);
164 tabsMain->AddPage(tabsWords,_T("Words"),false);
165 tabsMain->AddPage(tabsConfig,_T("Configuration"),false);
166 tabMajor = (wxNotebookPage *) tabsKanji;
168 panelKanjiDict = new PanelKanjiDict(tabsKanji);
169 panelKanjiDrill = new PanelKanjiDrill(tabsKanji);
170 panelKanjiListEditor = new PanelKanjiListEditor(tabsKanji);
171 tabsKanji->AddPage(panelKanjiDict,_T("Dictionary"),true);
172 tabsKanji->AddPage(panelKanjiDrill,_T("Practice"),false);
173 tabsKanji->AddPage(panelKanjiListEditor,_T("Study List"),false);
174 tabMinor = (wxNotebookPage *) panelKanjiDict;
176 panelWordDict = new PanelWordDict(tabsWords);
177 /* ADVANCED IDEA: Use radical database to create a multi-choice test option for vocab and kanji.
178 That is, like on the JLPT for reading/writing Kanji, use kanji which share one or more radicals
179 or readings as alternate options when possible. (Without this, panelVocabTest seems somewhat
180 pointless at this time. */
181 panelVocabListEditor = new PanelVocabListEditor(tabsWords);
182 tabsWords->AddPage(panelWordDict,_T("Dictionary"),true);
183 tabsWords->AddPage(panelVocabListEditor,_T("Study List"),false);
185 panelConfig = new PanelConfig(tabsConfig);
186 tabsConfig->AddPage(panelConfig,_T("Main Options"),true);
188 #if 0
189 /* An attempted workaround, which did not work. */
190 int w, h, x, y;
191 this->GetSize(&w, &h);
192 this->GetPosition(&x, &y);
193 this->SetSize(x, y, w, h, wxSIZE_FORCE);
194 #endif
197 void MainGUI::OnFileQuit(wxCommandEvent& event) {
198 Close();
201 void MainGUI::OnKanjiAddFromFile(wxCommandEvent& event) {
202 /* NOTE: We may add the flag wxFD_CHANGE_DIR later, if we add in code
203 to save the full path for the jben.cfg file. */
204 wxFileDialog *fd = new wxFileDialog(
205 this, _T("Open File"), wxEmptyString, wxEmptyString, _T("*"),
206 wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
207 if(fd->ShowModal()==wxID_OK) {
208 wxArrayString filenames;
209 wxString file, allFiles;
210 fd->GetPaths(filenames);
211 for(unsigned int i=0;i<filenames.Count();i++) {
212 if(ReadFile(filenames[i], file)==REF_SUCCESS)
213 allFiles.append(file);
215 int result = jben->kanjiList->AddFromString(allFiles);
216 this->Redraw();
217 wxMessageBox(wxString::Format(
218 _T("Added %d kanji to the list."), result),
219 _T("Add Kanji From File"), wxOK | wxICON_INFORMATION, this);
221 fd->Destroy();
224 void MainGUI::OnKanjiAddByGrade(wxCommandEvent& event) {
225 int result = dialogAddKanjiByGrade->ShowModal();
226 if(result==wxID_OK) {
227 /*printf("Selected grades: %d to %d\n",
228 dialogAddKanjiByGrade->GetLowGrade(),
229 dialogAddKanjiByGrade->GetHighGrade()
230 );*/
231 result = jben->kanjiList->AddByGrade(
232 dialogAddKanjiByGrade->GetLowGrade(),
233 dialogAddKanjiByGrade->GetHighGrade());
234 this->Redraw();
235 wxMessageBox(wxString::Format(
236 _T("Added %d kanji to the list."), result),
237 _T("Add Kanji by Jouyou Grade"), wxOK | wxICON_INFORMATION, this);
238 } else if(result==wxID_CANCEL) {
239 /*printf("Cancel event occurred within dialog!\n");*/
241 #ifdef DEBUG
242 else printf("Unknown key (%08X) pressed within dialog!\n", result);
243 #endif
246 void MainGUI::OnKanjiAddByFreq(wxCommandEvent& event) {
247 int result = dialogAddKanjiByFreq->ShowModal();
248 if(result==wxID_OK) {
249 /*printf("Selected frequencies: %d to %d\n",
250 dialogAddKanjiByFreq->GetLowFreq(),
251 dialogAddKanjiByFreq->GetHighFreq()
252 );*/
253 result = jben->kanjiList->AddByFrequency(
254 dialogAddKanjiByFreq->GetLowFreq(),
255 dialogAddKanjiByFreq->GetHighFreq());
256 this->Redraw();
257 wxMessageBox(wxString::Format(
258 _T("Added %d kanji to the list."), result),
259 _T("Add Kanji by Frequency"), wxOK | wxICON_INFORMATION, this);
260 } else if(result==wxID_CANCEL) {
261 /* Do nothing */
263 #ifdef DEBUG
264 else printf("Unknown key (%08X) pressed within dialog!\n", result);
265 #endif
268 void MainGUI::OnKanjiSaveToFile(wxCommandEvent& event) {
269 /* NOTE: We may add the flag wxFD_CHANGE_DIR later, if we add in code
270 to save the full path for the jben.cfg file. */
271 wxFileDialog *fd = new wxFileDialog(
272 this, _T("Save Kanji List to File"), wxEmptyString, wxEmptyString, _T("*"),
273 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
274 if(fd->ShowModal()==wxID_OK) {
275 wxString kanjiList = jben->kanjiList->ToString(20);
276 wxString filename = fd->GetPath();
277 /* Open file/write to file/close file */ /* TO DO */
278 wxFFile f(filename, _T("w"));
279 if(f.IsOpened()) {
280 f.Write(kanjiList, *wxConvCurrent);
281 f.Close();
284 fd->Destroy();
287 void MainGUI::OnKanjiClearList(wxCommandEvent& event) {
288 jben->kanjiList->Clear();
289 this->Redraw();
292 #ifdef DEBUG
293 void MainGUI::OnKanjiDumpList(wxCommandEvent& event) {
294 printf("Current kanji list: %ls\n", jben->kanjiList->ToString().c_str());
296 #endif
298 void MainGUI::OnHelpAbout(wxCommandEvent& event) {
299 /* wxMessageBox(_T(PROGRAM_NAME " " VERSION_STR "\n"
300 "Copyright " COPYRIGHT_DATE " by " AUTHOR_NAME "\n\n"
301 "Powered by wxWidgets:\n"
302 "http://www.wxwidgets.org/\n"
303 AUTHOR_NAME " is not affiliated with the wxWidgets team in any way."),
304 _T("About " PROGRAM_NAME), wxOK | wxICON_INFORMATION);*/
305 wxMessageBox(_T(
306 PROGRAM_NAME " v" VERSION_STR
307 "\nBy " AUTHOR_NAME
308 "\nCopyright " COPYRIGHT_DATE "\n\n"
310 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
311 "http://www.physics.ucla.edu/~grosenth/\n\n"
313 "Powered by Monash University's EDICT2 and KANJIDIC:\n"
314 "http://www.csse.monash.edu.au/~jwb/edict_doc.html\n"
315 "http://www.csse.monash.edu.au/~jwb/kanjidic.html\n\n"
317 "Built using wxWidgets: http://www.wxwidgets.org/\n\n"
319 "See \"Help->License Information...\" for important license details."),
320 _T("About " PROGRAM_NAME), wxOK | wxICON_INFORMATION, this);
323 void MainGUI::OnHelpLicense(wxCommandEvent& event) {
324 wxMessageBox(_T(
325 "Program distributed under the GNU General Public License (GPL) version 2:\n"
326 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
327 "EDICT2 and KANJIDIC distributed under a separate license specified at\n"
328 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
330 #ifdef USE_SKIP
331 "Regarding SKIP index data from KANJIDIC:\n"
332 "SKIP (System of Kanji Indexing by Patterns) numbers are derived from "
333 "the New Japanese-English Character Dictionary (Kenkyusha 1990, NTC 1993) "
334 "and The Kodansha Kanji Learner's Dictionary (Kodansha International, 1999). "
335 "SKIP is protected by copyright, copyleft and patent laws. The commercial "
336 "or non-commercial utilization of SKIP in any form is strictly forbidden "
337 "without the written permission of Jack Halpern, the copyright holder. Such "
338 "permission is normally granted. Please contact jack@kanji.org and/or see"
339 "http://www.kanji.org.\n\n"
340 #endif
342 "Copies of the GNU General Public License, Monash University's license for "
343 "the dictionary files and documentation for the dictionary files are "
344 "contained in this program's \"license\" directory."),
345 _T("License Information"), wxOK | wxICON_INFORMATION, this);
348 void MainGUI::OnMajorTabChanged(wxNotebookEvent& event) {
349 #ifdef DEBUG
350 printf("DEBUG: OnMAJORTabChanged called.\n");
351 #endif
352 tabMajor = (wxNotebookPage *) tabsMain->GetPage(event.GetSelection());
353 tabMinor = ((wxNotebook *)tabMajor)->GetCurrentPage();
354 #ifdef DEBUG
355 printf("tabMajor = %p, tabMinor = %p\n", tabMajor, tabMinor);
356 #endif
357 this->Redraw();
360 void MainGUI::OnMinorTabChanged(wxNotebookEvent& event) {
361 #ifdef DEBUG
362 printf("DEBUG: OnMinorTabChanged called.\n");
363 #endif
364 wxNotebook *nb = (wxNotebook *) tabsMain->GetCurrentPage();
365 if(nb) {
366 tabMinor = (wxNotebookPage *) nb->GetPage(event.GetSelection());
367 } else tabMinor = NULL;
368 #ifdef DEBUG
369 printf("tabMajor = %p, tabMinor = %p\n", tabMajor, tabMinor);
370 #endif
371 this->Redraw();
374 /* This is the handler code for our tab changes.
375 It's called by both OnTabChanging functions.
376 Returns true if the tab change should take place, and false if it
377 should be vetoed. */
378 bool MainGUI::TabChangeHandler(wxNotebookPage *page) {
379 int result;
380 if(page == panelConfig) {
381 if(panelConfig->ChangeDetected()) {
382 result = wxMessageBox(
383 _T("You have made changes to your configuration. Do you want to save them?" /*"\n\n"
384 "Yes: Save Changes\n"
385 "No: Abandon Changes\n"
386 "Cancel: Continue making changes"*/),
387 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
388 if(result==wxYES) {
389 panelConfig->Commit();
390 } else if(result==wxNO) {
391 panelConfig->Revert();
392 } else if(result==wxCANCEL) {
393 return false;
397 else if(page == panelKanjiListEditor) {
398 if(panelKanjiListEditor->ChangeDetected()) {
399 result = wxMessageBox(
400 _T("You have made changes to the kanji list. Do you want to save them?" /*"\n\n"
401 "Yes: Save Changes\n"
402 "No: Abandon Changes\n"
403 "Cancel: Continue making changes"*/),
404 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
405 if(result==wxYES) {
406 panelKanjiListEditor->Commit();
407 } else if(result==wxNO) {
408 panelKanjiListEditor->Revert();
409 } else if(result==wxCANCEL) {
410 return false;
414 else if(page == panelVocabListEditor) {
415 if(panelVocabListEditor->ChangeDetected()) {
416 result = wxMessageBox(
417 _T("You have made changes to the vocab list. Do you want to save them?" /*"\n\n"
418 "Yes: Save Changes\n"
419 "No: Abandon Changes\n"
420 "Cancel: Continue making changes"*/),
421 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
422 if(result==wxYES) {
423 panelVocabListEditor->Commit();
424 } else if(result==wxNO) {
425 panelVocabListEditor->Revert();
426 } else if(result==wxCANCEL) {
427 return false;
431 else if(page == panelKanjiDrill) {
432 if(panelKanjiDrill->TestInProgress()) {
433 result =
434 wxMessageBox(_T("A test is in progress. Switching tabs will abort the test. Are you sure you want to do this?"),
435 _T("Test in progress!"), wxYES_NO | wxICON_EXCLAMATION, this);
436 if(result==wxYES) {
437 panelKanjiDrill->Stop();
438 } else {
439 return false;
443 return true;
446 void MainGUI::OnTabChanging(wxNotebookEvent& event) {
447 int index = event.GetOldSelection();
448 if(index==-1) return;
449 /* Original code */
450 /*wxNotebookPage *page = tabsMain->GetPage(index);*/
451 /* First revision for multi-level tabs */
452 /*wxNotebook *tabs = (wxNotebook *) tabsMain->GetPage(index);
453 wxNotebookPage *page = tabs->GetPage(index);*/
455 /* New code, using tab tracking vars in MainGUI class */
456 if(!TabChangeHandler(tabMinor)) event.Veto();
459 /* OLD CODE! */
460 #if 0
461 void MainGUI::OnMajorTabChanging(wxNotebookEvent& event) {
462 int index = event.GetOldSelection();
463 if(index==-1) return;
464 /*wxNotebookPage *page = tabsMain->GetPage(index);*/
465 wxNotebook *tabs = (wxNotebook *) tabsMain->GetPage(index);
466 wxNotebookPage *page = tabs->GetPage(index);
467 int result;
468 if(page == panelConfig) {
469 if(panelConfig->ChangeDetected()) {
470 result = wxMessageBox(
471 _T("You have made changes to your configuration. Do you want to save them?" /*"\n\n"
472 "Yes: Save Changes\n"
473 "No: Abandon Changes\n"
474 "Cancel: Continue making changes"*/),
475 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
476 if(result==wxYES) {
477 panelConfig->Commit();
478 } else if(result==wxNO) {
479 panelConfig->Revert();
480 } else if(result==wxCANCEL) {
481 event.Veto();
485 else if(page == panelKanjiListEditor) {
486 if(panelKanjiListEditor->ChangeDetected()) {
487 result = wxMessageBox(
488 _T("You have made changes to the kanji list. Do you want to save them?" /*"\n\n"
489 "Yes: Save Changes\n"
490 "No: Abandon Changes\n"
491 "Cancel: Continue making changes"*/),
492 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
493 if(result==wxYES) {
494 panelKanjiListEditor->Commit();
495 } else if(result==wxNO) {
496 panelKanjiListEditor->Revert();
497 } else if(result==wxCANCEL) {
498 event.Veto();
502 else if(page == panelVocabListEditor) {
503 if(panelVocabListEditor->ChangeDetected()) {
504 result = wxMessageBox(
505 _T("You have made changes to the vocab list. Do you want to save them?" /*"\n\n"
506 "Yes: Save Changes\n"
507 "No: Abandon Changes\n"
508 "Cancel: Continue making changes"*/),
509 _T("Unsaved Changes Detected!"), wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
510 if(result==wxYES) {
511 panelVocabListEditor->Commit();
512 } else if(result==wxNO) {
513 panelVocabListEditor->Revert();
514 } else if(result==wxCANCEL) {
515 event.Veto();
519 else if(page == panelKanjiDrill) {
520 if(panelKanjiDrill->TestInProgress()) {
521 result =
522 wxMessageBox(_T("A test is in progress. Switching tabs will abort the test. Are you sure you want to do this?"),
523 _T("Test in progress!"), wxYES_NO | wxICON_EXCLAMATION, this);
524 if(result==wxYES) {
525 panelKanjiDrill->Stop();
526 } else {
527 event.Veto();
532 #endif
534 void MainGUI::OnKanjiSortByGrade(wxCommandEvent& ev) {
535 jben->kanjiList->Sort(ST_GRADE);
536 this->Redraw();
539 void MainGUI::OnKanjiSortByFreq(wxCommandEvent& ev) {
540 jben->kanjiList->Sort(ST_FREQUENCY);
541 this->Redraw();
544 void MainGUI::Redraw() {
545 bool state = (jben->kanjiList->Size()>0);
546 kanjiMenu->Enable(ID_menuKanjiSaveToFile, state);
547 kanjiMenu->Enable(ID_menuKanjiClearList, state);
549 if(tabMinor) {
550 ((RedrawablePanel *)tabMinor)->Redraw();
553 /* This is no longer valid; tabsMain only contains other wxNotebooks now. */
554 /*( (RedrawablePanel *) tabsMain->GetCurrentPage() )->Redraw();*/
556 /* OLD CODE */
558 if(tabs->GetCurrentPage()==panelKanjiDict) {
559 panelKanjiDict->Redraw();
560 } else if(tabs->GetCurrentPage()==panelKanjiDrill) {
561 panelKanjiDrill->Redraw();
562 } else if(tabs->GetCurrentPage()==panelKanjiListEditor) {
563 panelKanjiListEditor->Redraw();
564 } else if(tabs->GetCurrentPage()==panelVocabListEditor) {
565 panelVocabListEditor->Redraw();
566 } else if(tabs->GetCurrentPage()==panelConfig) {
567 panelConfig->Redraw();
572 void MainGUI::OnClose(wxCloseEvent& event) {
573 if(!event.CanVeto()) {
574 #ifdef DEBUG
575 fprintf(stderr, "event.CanVeto() returned false!\n");
576 #endif
577 this->Destroy();
579 /* Check for active kanji drill */
580 if(tabsMain->GetCurrentPage()==panelKanjiDrill &&
581 panelKanjiDrill->TestInProgress()) {
582 int result =
583 wxMessageBox(_T("A test is in progress. Are you sure you want to quit?"),
584 _T("Test in progress!"), wxYES_NO | wxICON_EXCLAMATION, this);
585 if(result==wxYES) {
586 panelKanjiDrill->Stop();
587 } else {
588 event.Veto();
589 return;
593 /* Everything is okay - close the program. */
594 this->Destroy();