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) ?fg
:FL_FOREGROUND_COLOR
;
55 bgcolor
= (bg
!=-1) ?bg
:FL_BACKGROUND2_COLOR
;
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 () {
75 for ( Cell
&c
: data_
)
79 void draw_single_cell ( int R
, int C
, int X
, int Y
, int W
, int H
);
80 void draw_cell ( TableContext context
, int R
=0, int C
=0, int X
=0, int Y
=0,
84 KanjiView(int x
, int y
, int w
, int h
, const char *l
=0 );
88 void set_data ( const vector
<Cell
> &d
);
90 inline void select_cell ( int id
){
92 data_
.at(id
).selected
= true;
96 inline void select_cell ( Cell
*c
){
102 inline Cell
*cell_at_rc ( int R
, int C
){
103 int ret
= R
*cols()+C
;
104 if ( R
== -1 || C
== -1 || ret
> int(data_
.size())-1 )
109 inline Cell
*cell_at_xy ( int x
, int y
)
116 for ( int r
=0; r
< rows(); r
++ ){
117 int nh
= h
+ row_height(r
);
125 for ( int c
=0; c
< cols(); c
++ ){
126 int nw
= w
+ col_width(c
);
133 int ret
= R
*cols()+C
;
134 if ( R
== -1 || C
== -1 || ret
> int(data_
.size())-1 )
141 inline Cell
*selected () {
142 for ( Cell
&c
: data_
)
147 inline int font_size () const { return font_size_
;};
148 inline Fl_Color
selection_color () const { return selection_color_
; };
149 inline int cell_padding () const { return cell_padding_
; };
150 inline int cell_size () const { return cell_size_
; };
151 inline int selected_id () const {
152 for ( size_t i
=0; i
<data_
.size(); i
++)
153 if ( data_
.at(i
).selected
)
159 void font_size ( int s
);
160 inline void selection_color ( const Fl_Color
&c
) { selection_color_
= c
; };
161 inline void cell_padding ( int x
) { cell_padding_
= x
; };
162 inline void cell_size ( int w
=-1 ) {
169 int handle ( int event
);
172 static void scb_copy ( Fl_Widget
*w
, void *userdata
) {
173 const char *d
= (const char*)userdata
;
175 Fl::copy( d
, len
, 0);
176 Fl::copy( d
, len
, 1);
179 // CALLBACKS - "setters"
180 inline void cb_leftclick ( Fl_Callback
*cb
, void *f
)
181 { cb_leftclick_
= cb
; cb_leftclick_data_
= f
; };
182 inline void cb_rightclick ( Fl_Callback
*cb
, void *f
)
183 { cb_rightclick_
= cb
; cb_rightclick_data_
= f
; };
184 inline void cb_select ( Fl_Callback
*cb
, void *f
)
185 { cb_select_
= cb
; cb_select_data_
= f
; };
187 // CALLBACKS - "getters"
188 // cb_XXXclick_data_ should be pointer to App
189 inline void cb_leftclick ( Fl_Widget
*w
) const
190 { cb_leftclick_(w
,cb_leftclick_data_
); };
191 inline void cb_rightclick ( Fl_Widget
*w
) const
192 { cb_rightclick_(w
, cb_rightclick_data_
); };
193 inline void cb_select ( Fl_Widget
*w
) const
194 { cb_select_(w
,cb_select_data_
); }
197 inline static void scb_general ( Fl_Widget
*w
, void *f
) {};
201 #endif // _KANJIVIEW_HXX