2 Copyright 2013 Karel Matas
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // http://fltk.org/articles.php?L415+I0+T+M1000+P1
26 const char *LABEL_DICTIONARY
= "D";
27 const char *LABEL_KANJI
= "K";
29 //////////////////////////////////////////////////////////////////////////
30 // DialogRomanizationTest
32 DialogRomanizationTest::DialogRomanizationTest( int w
, int h
)
33 : Fl_Double_Window(w
,h
){
34 choice_
= new Fl_Choice( 5, 5, w
-10, 25 );
35 choice_
->add("Hiragana");
36 choice_
->add("Katakana");
38 choice_
->callback( scb_input
, (void*)this );
39 input_
= new Fl_Input( 5, 35, w
-10, 30 );
40 input_
->callback( scb_input
, (void*)this );
41 input_
->when(FL_WHEN_CHANGED
);
43 output_
= new Fl_Input( 5, 75, w
-10, h
-105 );
44 output_
->align( FL_ALIGN_INSIDE
|FL_ALIGN_WRAP
);
45 output_
->textfont( FONT_KANJI
);
46 output_
->textsize( 2*input_
->labelsize() );
47 output_
->box(FL_BORDER_BOX
);
48 label("Romanization test");
49 b_close_
= new Fl_Button( w
-65, h
-25, 60, 20, "Close");
50 b_close_
->callback( scb_close
, (void*)this );
56 void DialogRomanizationTest::cb_input (){
57 const char *s
= input_
->value();
58 if ( choice_
->value() == 0 )
59 buff_
= App::get()->rmn()->romaji_to_hiragana(s
).c_str();
61 buff_
= App::get()->rmn()->romaji_to_katakana(s
).c_str();
62 output_
->value( buff_
.c_str() );
67 MainWindow::MainWindow ( GUI
*parent
, int w
, int h
): Fl_Double_Window(w
,h
)
72 grp_dictionary_
= new Fl_Group(0,0,w
,h
);
74 Fl_Group
*grp
= new Fl_Group(60,5,200,30);
75 dic_input_
= new Entry( 60, 5, 200, 30, "Insert romaji/kanji" );
80 dic_view_
= new DicView( 5, 40, 700, 555 );
81 dic_view_
->col_width(0,200);
82 dic_view_
->col_width(1,200);
83 // width of the last column is determined dynamically
85 cb_noun_
= new Fl_Check_Button(710, 40, 50, 20, "noun");
86 cb_verb_
= new Fl_Check_Button(710, 65, 50, 20, "verb");
87 cb_adj_
= new Fl_Check_Button(710, 90, 50, 20, "adj");
88 cb_expr_
= new Fl_Check_Button(710, 115, 50, 20, "expr");
90 grp_dictionary_
->end();
93 grp_kanjidic_
= new Fl_Group( 0, 0, WIN_WIDTH
, WIN_HEIGHT
);
95 Fl_Group
*grp
= new Fl_Group(60,5,WIN_WIDTH
-60-60-2*5,30);
96 e_skip
= new Entry( 60, 5, 120, 30, "SKIP" );
97 e_strokes
= new Entry( 185, 5, 70, 30, "#" );
98 e_jlpt
= new Entry( 260, 5, 40, 30, "JLPT");
99 e_grade
= new Entry( 305, 5, 40, 30, "Grd.");
100 knj_orderby_
= new Fl_Choice( 350, 5, 150, 30 );
101 cb_knj_jis208
= new Fl_Check_Button( 505, 5, 100, 30, "JIS 208 only" );
102 b_knj_search_
= new Fl_Button( 615, 5, 60, 30, "Search");
103 b_knj_clear_
= new Fl_Button( 680, 5, 60, 30, "Clear");
104 l_knj_results
= new Label( 555, 565, 240, 30 );
109 knj_view_
= new KanjiView( 5, 40, 545, 555 );
110 cb_knj_components
= new Fl_Check_Button( 555, 40, 250, 25, "Sort by strokes");
111 compo_view_
= new ComponentView( 555, 70, 240, 300);
113 grp_kanjidic_
->end();
114 grp_kanjidic_
->hide();
116 // ALWAYS VISIBLE BUTTONS
118 int b_width
= 10+fl_width( LABEL_DICTIONARY
);
121 b_toggle_view_
= new Fl_Button( w
-b_width
-5, 5, b_width
, 30, LABEL_DICTIONARY
);
122 Fl_Group
*g
= new Fl_Group( 5, 5, 50, 30 );
123 b_menu_
= new Fl_Menu_Button( 5, 5, 50, 30, "M");
128 resizable( dic_view_
);
129 resizable( knj_view_
);
134 int MainWindow::handle ( int event
)
136 unsigned int mods
= Fl::event_state() & (FL_META
|FL_CTRL
|FL_ALT
);
137 if ( event
== FL_KEYDOWN
&& mods
==FL_CTRL
){
138 switch ( Fl::event_key() ){
141 if ( grp_dictionary_
->visible() )
142 dic_input_
->take_focus();
144 e_skip
->take_focus();
148 parent_
->cb_toggle_group();
152 if ( grp_dictionary_
->visible() )
153 dic_input_
->callback()(dic_input_
,(void*)App::get());
155 b_knj_search_
->callback()(dic_input_
,(void*)App::get());
165 return Fl_Double_Window::handle(event
);
170 GUI::GUI ( aoi::App
*parent
):parent_(parent
)
172 Fl::visual(FL_DOUBLE
|FL_INDEX
);
175 dlg_fonts_
= new DialogFontTest();
176 dlg_progress_
= new DialogProgress(300,50);
177 dlg_help_
= new Fl_Help_Dialog();
178 dlg_edit_word_
= new DialogEditWord();
179 dlg_manage_db_
= new ManageDBDialog();
180 dlg_download_
= new DialogDownload(400,125);
182 main_window_
= new MainWindow( this, WIN_WIDTH
, WIN_HEIGHT
);
183 main_window_
->label( WIN_TITLE
);
184 main_window_
->callback(scb_main_window_
);
187 // should be in same order as aoi::KANJI_SORT_MODE
188 main_window_
->knj_orderby_
->add("Freq (ASC)");
189 main_window_
->knj_orderby_
->add("Freq (DESC)");
190 main_window_
->knj_orderby_
->add("Strokes (ASC)");
191 main_window_
->knj_orderby_
->add("Strokes (DESC)");
192 main_window_
->knj_orderby_
->value(0);
194 main_window_
->cb_knj_jis208
->value( parent_
->get_config
<bool>("knj/jis208_only") );
197 main_window_
->b_menu_
->add("Manage database", 0, App::scb_manage_db
, (void*)parent_
);
198 main_window_
->b_menu_
->add("Settings", 0, scb_show_settings
, (void*)this);
199 main_window_
->b_menu_
->add("Tools/Test romanization", 0,
200 scb_test_romanization
, (void*)this);
201 main_window_
->b_menu_
->add("Tools/Test fonts", 0,
202 scb_test_fonts
, (void*)this);
203 main_window_
->b_menu_
->add("Help && About", 0, scb_show_help
, (void*)this);
204 main_window_
->b_menu_
->add("Quit", 0, quit_fltk
, (void*)main_window_
);
207 main_window_
->dic_input_
->callback( App::scb_dic_input
, (void*)parent_
);
208 main_window_
->dic_view_
->cb_doubleclick( App::scb_dicview_doubleclick
, (void*)parent_
);
209 main_window_
->dic_view_
->cb_rightclick( App::scb_dicview_rightclick
, (void*)parent_
);
210 main_window_
->cb_noun_
->callback( App::scb_filter_listview
, (void*)parent_
);
211 main_window_
->cb_verb_
->callback( App::scb_filter_listview
, (void*)parent_
);
212 main_window_
->cb_adj_
->callback( App::scb_filter_listview
, (void*)parent_
);
213 main_window_
->cb_expr_
->callback( App::scb_filter_listview
, (void*)parent_
);
214 main_window_
->e_skip
->callback( App::scb_kanji_search
, (void*)parent_
);
215 main_window_
->knj_orderby_
->callback( App::scb_kanji_search
, (void*)parent_
);
216 main_window_
->b_knj_search_
->callback( App::scb_kanji_search
, (void*)parent_
);
217 main_window_
->b_knj_clear_
->callback( scb_knj_clear
, (void*)this);
218 main_window_
->knj_view_
->cb_leftclick( App::scb_kanjiview_select
, (void*)parent_
);
219 main_window_
->knj_view_
->cb_select( App::scb_kanjiview_select
, (void*)parent_
);
220 main_window_
->compo_view_
->callback( App::scb_kanji_search
, (void*)parent_
);
221 main_window_
->b_toggle_view_
->callback( scb_toggle_group
, (void*)this );
222 main_window_
->e_strokes
->callback( App::scb_kanji_search
, (void*)parent_
);
223 main_window_
->e_jlpt
->callback( App::scb_kanji_search
, (void*)parent_
);
224 main_window_
->e_grade
->callback( App::scb_kanji_search
, (void*)parent_
);
225 main_window_
->cb_knj_jis208
->callback( scb_jis208_toggle
, (void*)this);
226 main_window_
->cb_knj_components
->callback( App::scb_set_components
, (void*)parent_
);
229 main_window_
->dic_input_
->when(FL_WHEN_ENTER_KEY_ALWAYS
);
230 main_window_
->b_menu_
->labeltype(FL_NORMAL_LABEL
);
233 main_window_
->dic_input_
->take_focus();
237 void GUI::init_colors ()
239 parent_
->log("Initializing colors.");
241 Fl_Color col
= parent_
->get_color("foreground");
242 Fl::foreground(col
>>24&0xFF, col
>>16&0xFF, col
>>8&0xFF);
244 col
= parent_
->get_color("background");
245 Fl::background(col
>>24&0xFF, col
>>16&0xFF, col
>>8&0xFF);
247 col
= parent_
->get_color("background2");
248 Fl::background2(col
>>24&0xFF, col
>>16&0xFF, col
>>8&0xFF);
250 col
= parent_
->get_color("selection");
251 Fl::free_color(FL_SELECTION_COLOR
);
252 Fl::set_color(FL_SELECTION_COLOR
, col
>>24&0xFF, col
>>16&0xFF, col
>>8&0xFF);
258 for ( int i
=0; i
< main_window_
->children(); i
++ )
259 main_window_
->child(i
)->redraw();
264 void GUI::init_fonts ()
266 Fl::set_font(FL_SYMBOL
,fontname_kanji_
.c_str()); // for Fl_Help_Dialog
267 Fl::set_font(FONT_KANJI
, fontname_kanji_
.c_str());
269 dlg_help_
->textsize( font_base_size_
);
270 if ( main_window_
->dic_view_
){
271 main_window_
->dic_view_
->font_size( font_base_size_
);
272 main_window_
->dic_view_
->redraw();
274 if ( main_window_
->knj_view_
) {
275 main_window_
->knj_view_
->font_size( 3*font_base_size_
);
276 main_window_
->knj_view_
->redraw();
278 if ( main_window_
->compo_view_
) {
279 main_window_
->compo_view_
->font_cell( FONT_KANJI
, font_base_size_
*1.2 );
280 main_window_
->compo_view_
->font_label( FL_HELVETICA_BOLD
, font_base_size_
*1.2 );
282 if ( main_window_
->dic_input_
){
283 main_window_
->dic_input_
->textfont( FONT_KANJI
);
284 main_window_
->dic_input_
->textsize( font_base_size_
*1.2 );
289 int GUI::run ( int argc
, char **argv
)
291 main_window_
->show(argc
,argv
);
296 void GUI::dicview_menu ( int did
, const vector
<string
> &v
, bool notes
, bool examples
)
298 Fl_Menu_Button
menu(Fl::event_x(), Fl::event_y(), 80, 1);
299 menu
.textfont(FONT_KANJI
);
300 menu
.textsize( 1.5*font_base_size_
);
302 menu
.add( (s
+"/Copy").c_str(), 0, scb_copy
, (void*)s
.c_str());
303 menu
.add( (s
+"/Show").c_str() );
305 menu
.add("Notes",0,0,0, notes
? 0:FL_MENU_INACTIVE
);
306 menu
.add("Examples",0, App::scb_examples
,(void*)parent_
,
307 examples
? 0:FL_MENU_INACTIVE
);
308 menu
.add("Show", 0, App::scb_edit_word
, (void*)parent_
);
312 void GUI::edit_word ( const aoi::DicWord
&w
)
314 dlg_edit_word_
->set(w
);
315 dlg_edit_word_
->show();
320 void GUI::cb_jis208_toggle ()
322 parent_
->set_config("knj/jis208_only", std::to_string(main_window_
->cb_knj_jis208
->value()));
323 parent_
->scb_kanji_search( nullptr, (void*)parent_
);
326 void GUI::cb_toggle_group ()
328 if ( main_window_
->grp_dictionary_
->visible() ){
329 main_window_
->grp_dictionary_
->hide();
330 main_window_
->grp_kanjidic_
->show();
331 main_window_
->b_toggle_view_
->label(LABEL_KANJI
);
334 main_window_
->grp_dictionary_
->show();
335 main_window_
->grp_kanjidic_
->hide();
336 main_window_
->b_toggle_view_
->label(LABEL_DICTIONARY
);
341 void GUI::popup_kanji ( const Kanji
&k
)
345 popup_
= new KanjiPopupWindow(100,100);
346 popup_
->font_a(FL_HELVETICA_BOLD
, font_base_size_
);
347 popup_
->font_b(FL_HELVETICA
, font_base_size_
);
353 void GUI::cb_knj_clear ()
355 main_window_
->e_strokes
->value("");
356 main_window_
->e_skip
->value("");
357 main_window_
->e_jlpt
->value("");
358 main_window_
->e_grade
->value("");
359 main_window_
->compo_view_
->set_data();
363 void GUI::reset_filters ()
365 main_window_
->cb_noun_
->value(0);
366 main_window_
->cb_verb_
->value(0);
367 main_window_
->cb_adj_
->value(0);
368 main_window_
->cb_expr_
->value(0);
372 vector
<string
> GUI::listview_filters ()
375 if ( main_window_
->cb_noun_
->value() )
376 out
.push_back("noun");
377 if ( main_window_
->cb_verb_
->value() )
378 out
.push_back("verb");
379 if ( main_window_
->cb_adj_
->value() )
380 out
.push_back("adj");
381 if ( main_window_
->cb_expr_
->value() )
382 out
.push_back("expr");
387 void GUI::show_settings ()
390 d
.set( parent_
->get_config_map(), parent_
->get_config_map_default() );
391 parent_
->save_config( d
.run() );
394 void GUI::change_cursor ( Fl_Cursor c
)
396 if ( main_window_
&& main_window_
->visible() )
397 main_window_
->cursor(c
);
398 if ( dlg_manage_db_
&& dlg_manage_db_
->visible() )
399 dlg_manage_db_
->cursor(c
);