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/>.
17 #ifndef _KANJIVIEW_HXX
18 #define _KANJIVIEW_HXX
20 #include <FL/Fl_Table.H>
21 #include <FL/fl_draw.H>
26 #include "gui_settings.hxx"
35 FL_FLAT_BOX causes errors in redrawing
43 class KanjiView
: public Fl_Table
49 bool selected
= false;
52 Cell ( const string
&s
, Fl_Color fg
=-1, Fl_Color bg
=-1 ) : str(s
)
54 fgcolor
= ( fg
== -1 ) ? Fl::get_color( FL_FOREGROUND_COLOR
) : fg
;
55 bgcolor
= ( bg
== -1 ) ? Fl::get_color( FL_BACKGROUND2_COLOR
) : bg
;
60 Fl_Font font_
= FONT_KANJI
;
62 Fl_Color selection_color_
= FL_LIGHT2
;
63 int cell_padding_
= 5;
66 Fl_Callback
*cb_leftclick_
;
67 Fl_Callback
*cb_rightclick_
;
68 Fl_Callback
*cb_select_
;
69 void *cb_leftclick_data_
= nullptr;
70 void *cb_rightclick_data_
= nullptr;
71 void *cb_select_data_
= nullptr;
74 inline void clear_selection () { for ( Cell
&c
: data_
) c
.selected
=false; redraw(); }
75 void draw_single_cell ( int R
, int C
, int X
, int Y
, int W
, int H
);
76 void draw_cell ( TableContext context
, int R
=0, int C
=0, int X
=0, int Y
=0,
80 KanjiView(int x
, int y
, int w
, int h
, const char *l
=0 );
84 void set_data ( const vector
<Cell
> &d
);
86 inline Cell
*cell_at_rc ( int R
, int C
){
88 if ( R
== -1 || C
== -1 || ret
> int(data_
.size())-1 )
93 inline Cell
*cell_at_xy ( int x
, int y
)
100 for ( int r
=0; r
< rows(); r
++ ){
101 int nh
= h
+ row_height(r
);
109 for ( int c
=0; c
< cols(); c
++ ){
110 int nw
= w
+ col_width(c
);
117 int ret
= R
*cols()+C
;
118 if ( R
== -1 || C
== -1 || ret
> int(data_
.size())-1 )
125 inline Cell
*selected () {
126 for ( Cell
&c
: data_
)
131 inline int font_size () const { return font_size_
;};
132 inline Fl_Color
selection_color () const { return selection_color_
; };
133 inline int cell_padding () const { return cell_padding_
; };
134 inline int cell_size () const { return cell_size_
; };
137 void font_size ( int s
);
138 inline void selection_color ( const Fl_Color
&c
) { selection_color_
= c
; };
139 inline void cell_padding ( int x
) { cell_padding_
= x
; };
140 inline void cell_size ( int w
=-1 ) {
147 int handle ( int event
);
150 static void scb_copy ( Fl_Widget
*w
, void *userdata
) {
151 const char *d
= (const char*)userdata
;
153 Fl::copy( d
, len
, 0);
154 Fl::copy( d
, len
, 1);
157 // CALLBACKS - "setters"
158 inline void cb_leftclick ( Fl_Callback
*cb
, void *f
)
159 { cb_leftclick_
= cb
; cb_leftclick_data_
= f
; };
160 inline void cb_rightclick ( Fl_Callback
*cb
, void *f
)
161 { cb_rightclick_
= cb
; cb_rightclick_data_
= f
; };
162 inline void cb_select ( Fl_Callback
*cb
, void *f
)
163 { cb_select_
= cb
; cb_select_data_
= f
; };
165 // CALLBACKS - "getters"
166 // cb_XXXclick_data_ should be pointer to App
167 inline void cb_leftclick ( Fl_Widget
*w
) const
168 { cb_leftclick_(w
,cb_leftclick_data_
); };
169 inline void cb_rightclick ( Fl_Widget
*w
) const
170 { cb_rightclick_(w
, cb_rightclick_data_
); };
171 inline void cb_select ( Fl_Widget
*w
) const
172 { cb_select_(w
,cb_select_data_
); }
175 inline static void scb_general ( Fl_Widget
*w
, void *f
) {};
179 #endif // _KANJIVIEW_HXX