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 DialogRomanizationTest::DialogRomanizationTest( int w
, int h
)
30 : Fl_Double_Window(w
,h
){
31 choice_
= new Fl_Choice( 5, 5, w
-10, 25 );
32 choice_
->add("Hiragana");
33 choice_
->add("Katakana");
35 choice_
->callback( scb_input
, (void*)this );
36 input_
= new Fl_Input( 5, 35, w
-10, 30 );
37 input_
->callback( scb_input
, (void*)this );
38 input_
->when(FL_WHEN_CHANGED
);
40 output_
= new Fl_Box( 5, 75, w
-10, h
-85 );
41 output_
->align( FL_ALIGN_INSIDE
|FL_ALIGN_WRAP
);
42 output_
->labelfont( FONT_KANJI
);
43 output_
->labelsize( 2*input_
->labelsize() );
44 output_
->box(FL_BORDER_BOX
);
45 label("Romanization test");
51 void DialogRomanizationTest::cb_input (){
52 const char *s
= input_
->value();
53 if ( choice_
->value() == 0 )
54 buff_
= App::get()->rmn()->romaji_to_hiragana(s
).c_str();
56 buff_
= App::get()->rmn()->romaji_to_katakana(s
).c_str();
57 output_
->label( buff_
.c_str() );
61 MainWindow::MainWindow ( GUI
*parent
, int w
, int h
): Fl_Double_Window(w
,h
)
66 grp_dictionary_
= new Fl_Group(0,0,w
,h
);
68 Fl_Group
*grp
= new Fl_Group(60,5,200,30);
69 dic_input_
= new Entry( 60, 5, 200, 30, "Insert romaji/kanji" );
74 dic_view_
= new DicView( 5, 40, 700, 555 );
75 dic_view_
->col_width(0,200);
76 dic_view_
->col_width(1,200);
77 // width of the last column is determined dynamically
79 cb_noun_
= new Fl_Check_Button(710, 40, 50, 20, "noun");
80 cb_verb_
= new Fl_Check_Button(710, 65, 50, 20, "verb");
81 cb_adj_
= new Fl_Check_Button(710, 90, 50, 20, "adj");
82 cb_expr_
= new Fl_Check_Button(710, 115, 50, 20, "expr");
84 grp_dictionary_
->end();
87 grp_kanjidic_
= new Fl_Group( 0, 0, WIN_WIDTH
, WIN_HEIGHT
);
89 Fl_Group
*grp
= new Fl_Group(60,5,WIN_WIDTH
-60-60-2*5,30);
90 e_skip
= new Entry( 60, 5, 120, 30, "SKIP" );
91 e_strokes
= new Entry( 185, 5, 70, 30, "#" );
92 e_jlpt
= new Entry( 260, 5, 40, 30, "JLPT");
93 e_grade
= new Entry( 305, 5, 40, 30, "Grd.");
94 knj_orderby_
= new Fl_Choice( 350, 5, 150, 30 );
95 cb_knj_jis208
= new Fl_Check_Button( 505, 5, 100, 30, "JIS 208 only" );
96 b_knj_search_
= new Fl_Button( 615, 5, 60, 30, "Search");
97 b_knj_clear_
= new Fl_Button( 680, 5, 60, 30, "Clear");
98 l_knj_results
= new Fl_Box( 555, 565, 240, 30 );
103 knj_view_
= new KanjiView( 5, 40, 545, 555 );
104 cb_knj_components
= new Fl_Check_Button( 555, 40, 250, 25, "Sort by strokes");
105 compo_view_
= new ComponentView( 555, 70, 240, 300);
107 grp_kanjidic_
->end();
108 grp_kanjidic_
->hide();
110 // ALWAYS VISIBLE BUTTONS
112 int b_width
= 10+fl_width( LABEL_DICTIONARY
);
115 b_toggle_view_
= new Fl_Button( w
-b_width
-5, 5, b_width
, 30, LABEL_DICTIONARY
);
116 Fl_Group
*g
= new Fl_Group( 5, 5, 50, 30 );
117 b_menu_
= new Fl_Menu_Button( 5, 5, 50, 30, "M");
122 resizable( dic_view_
);
123 resizable( knj_view_
);
128 int MainWindow::handle ( int event
)
130 unsigned int mods
= Fl::event_state() & (FL_META
|FL_CTRL
|FL_ALT
);
131 if ( event
== FL_KEYDOWN
&& mods
==FL_CTRL
){
132 switch ( Fl::event_key() ){
135 if ( grp_dictionary_
->visible() ){
136 dic_input_
->take_focus();
140 e_skip
->take_focus();
145 parent_
->cb_toggle_group();
155 return Fl_Double_Window::handle(event
);
160 GUI::GUI ( aoi::App
*parent
):parent_(parent
)
162 dlg_fonts_
= new DialogFontTest();
163 dlg_progress_
= new DialogProgress(300,50);
164 dlg_alert_
= new DialogAlert();
165 dlg_help_
= new Fl_Help_Dialog();
166 dlg_edit_word_
= new EditWordDialog(0,0,400,550);
167 dlg_edit_word_
->end();
168 dlg_manage_db_
= new ManageDBDialog(500,300);
169 dlg_download_
= new DialogDownload(400,125);
171 main_window_
= new MainWindow( this, WIN_WIDTH
, WIN_HEIGHT
);
172 main_window_
->label( WIN_TITLE
);
173 main_window_
->callback(scb_main_window_
);
176 // should be in same order as aoi::KANJI_SORT_MODE
177 main_window_
->knj_orderby_
->add("Freq (ASC)");
178 main_window_
->knj_orderby_
->add("Freq (DESC)");
179 main_window_
->knj_orderby_
->add("Strokes (ASC)");
180 main_window_
->knj_orderby_
->add("Strokes (DESC)");
181 main_window_
->knj_orderby_
->value(0);
183 main_window_
->cb_knj_jis208
->value( parent_
->get_config
<bool>("knj/jis208_only") );
186 main_window_
->b_menu_
->add("Manage database", 0, App::scb_manage_db
, (void*)parent_
);
187 main_window_
->b_menu_
->add("Settings", 0, scb_show_settings
, (void*)this);
188 main_window_
->b_menu_
->add("Tools/Test romanization", 0,
189 scb_test_romanization
, (void*)this);
190 main_window_
->b_menu_
->add("Tools/Test fonts", 0,
191 scb_test_fonts
, (void*)this);
192 main_window_
->b_menu_
->add("Help && About", 0, scb_show_help
, (void*)this);
193 main_window_
->b_menu_
->add("Quit", 0, quit_fltk
, (void*)main_window_
);
196 main_window_
->dic_input_
->callback( App::scb_dic_input
, (void*)parent_
);
197 main_window_
->dic_view_
->cb_doubleclick( App::scb_dicview_doubleclick
, (void*)parent_
);
198 main_window_
->dic_view_
->cb_rightclick( App::scb_dicview_rightclick
, (void*)parent_
);
199 main_window_
->cb_noun_
->callback( App::scb_filter_listview
, (void*)parent_
);
200 main_window_
->cb_verb_
->callback( App::scb_filter_listview
, (void*)parent_
);
201 main_window_
->cb_adj_
->callback( App::scb_filter_listview
, (void*)parent_
);
202 main_window_
->cb_expr_
->callback( App::scb_filter_listview
, (void*)parent_
);
203 main_window_
->e_skip
->callback( App::scb_kanji_search
, (void*)parent_
);
204 main_window_
->knj_orderby_
->callback( App::scb_kanji_search
, (void*)parent_
);
205 main_window_
->b_knj_search_
->callback( App::scb_kanji_search
, (void*)parent_
);
206 main_window_
->b_knj_clear_
->callback( scb_knj_clear
, (void*)this);
207 main_window_
->knj_view_
->cb_leftclick( App::scb_kanjiview_leftclick
, (void*)parent_
);
208 main_window_
->compo_view_
->callback( App::scb_kanji_search
, (void*)parent_
);
209 main_window_
->b_toggle_view_
->callback( scb_toggle_group
, (void*)this );
210 main_window_
->e_strokes
->callback( App::scb_kanji_search
, (void*)parent_
);
211 main_window_
->e_jlpt
->callback( App::scb_kanji_search
, (void*)parent_
);
212 main_window_
->e_grade
->callback( App::scb_kanji_search
, (void*)parent_
);
213 main_window_
->cb_knj_jis208
->callback( scb_jis208_toggle
, (void*)this);
214 main_window_
->cb_knj_components
->callback( App::scb_set_components
, (void*)parent_
);
217 main_window_
->dic_input_
->when(FL_WHEN_ENTER_KEY_ALWAYS
);
218 main_window_
->b_menu_
->labeltype(FL_NORMAL_LABEL
);
221 dlg_progress_
->show();
223 // XXX: z nejakeho duvodu musi byt DialogTextDisplay ukazate ?!
224 // alert2("Titulek poplachu", "Popis udalost jez zpusobila poplach");
233 void GUI::init_fonts ()
235 Fl::set_font(FL_SYMBOL
,fontname_kanji_
.c_str()); // for Fl_Help_Dialog
236 Fl::set_font(FONT_KANJI
, fontname_kanji_
.c_str());
238 dlg_help_
->textsize( font_base_size_
);
239 if ( main_window_
->dic_view_
){
240 main_window_
->dic_view_
->font_size( font_base_size_
);
241 main_window_
->dic_view_
->redraw();
243 if ( main_window_
->knj_view_
) {
244 main_window_
->knj_view_
->font_size( 3*font_base_size_
);
245 main_window_
->knj_view_
->redraw();
247 if ( main_window_
->compo_view_
) {
248 main_window_
->compo_view_
->font_cell( FONT_KANJI
, font_base_size_
*1.2 );
249 main_window_
->compo_view_
->font_label( FL_HELVETICA_BOLD
, font_base_size_
*1.2 );
251 if ( main_window_
->dic_input_
){
252 main_window_
->dic_input_
->textfont( FONT_KANJI
);
253 main_window_
->dic_input_
->textsize( font_base_size_
*1.2 );
257 int GUI::run ( int argc
, char **argv
)
259 main_window_
->show(argc
,argv
);
264 void GUI::menu_copy ( const vector
<string
> &v
)
266 Fl_Menu_Button
menu(Fl::event_x(), Fl::event_y(), 80, 1);
267 menu
.textfont(FONT_KANJI
);
268 menu
.textsize( 1.5*font_base_size_
);
269 // XXX: copy all will be in edit
270 // menu.add("Copy all",0,0,0,FL_MENU_DIVIDER);
272 menu
.add( (s
+"/Copy").c_str(), 0, scb_copy
, (void*)s
.c_str());
273 menu
.add( (s
+"/Show").c_str() );
279 void GUI::edit_word ()
282 dlg_edit_word_
->resize( main_window_
->x()*1.5, main_window_
->y(),
283 dlg_edit_word_
->w(), dlg_edit_word_
->h() );
284 dlg_edit_word_
->show();
289 void GUI::cb_jis208_toggle ()
291 parent_
->set_config("knj/jis208_only", std::to_string(main_window_
->cb_knj_jis208
->value()));
292 parent_
->scb_kanji_search( nullptr, (void*)parent_
);
295 void GUI::cb_toggle_group ()
297 if ( main_window_
->grp_dictionary_
->visible() ){
298 main_window_
->grp_dictionary_
->hide();
299 main_window_
->grp_kanjidic_
->show();
300 main_window_
->b_toggle_view_
->label(LABEL_KANJI
);
303 main_window_
->grp_dictionary_
->show();
304 main_window_
->grp_kanjidic_
->hide();
305 main_window_
->b_toggle_view_
->label(LABEL_DICTIONARY
);
309 void GUI::popup_kanji ( const Kanji
&k
)
313 popup_
= new KanjiPopupWindow(100,100);
314 popup_
->font_a(FL_HELVETICA_BOLD
, font_base_size_
);
315 popup_
->font_b(FL_HELVETICA
, font_base_size_
);
320 void GUI::cb_knj_clear ()
322 main_window_
->e_strokes
->value("");
323 main_window_
->e_skip
->value("");
324 main_window_
->compo_view_
->set_data();
327 void GUI::reset_filters ()
329 main_window_
->cb_noun_
->value(0);
330 main_window_
->cb_verb_
->value(0);
331 main_window_
->cb_adj_
->value(0);
332 main_window_
->cb_expr_
->value(0);
335 vector
<string
> GUI::listview_filters ()
338 if ( main_window_
->cb_noun_
->value() )
339 out
.push_back("noun");
340 if ( main_window_
->cb_verb_
->value() )
341 out
.push_back("verb");
342 if ( main_window_
->cb_adj_
->value() )
343 out
.push_back("adj");
344 if ( main_window_
->cb_expr_
->value() )
345 out
.push_back("expr");
350 void GUI::show_settings ()
353 d
.set( parent_
->get_config_map() );
354 parent_
->save_config( d
.run() );