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/>.
20 #include <FL/Fl_Table_Row.H>
21 #include <FL/fl_draw.H>
34 FL_FLAT_BOX causes errors in redrawing
62 TextStyle( Fl_Font fnt
=FL_TIMES
, float sz
=1.0, Fl_Color clr
=FL_BLACK
, int offy
=0,
63 Separator sep
=SEPARATOR_NONE
, NewlineStyle nl
=NEWLINE_NONE
)
64 :font(fnt
),relsize(sz
),color(clr
), offset_y(offy
), separator(sep
),newline(nl
){};
66 TextStyle( Separator sep
): TextStyle() { separator
=sep
; };
67 TextStyle( NewlineStyle nl
): TextStyle() { newline
=nl
; };
71 class DicView
: public Fl_Table_Row
75 int cell_padding_x_
= 5;
76 int cell_padding_y_
= 5;
77 map
<string
,TextStyle
> tag_table_
; // tag_name:style
78 vector
<string
> headers_
;
80 void redraw_row ( int R
, int H
);
83 Fl_Callback
*cb_leftclick_
;
84 Fl_Callback
*cb_rightclick_
;
85 Fl_Callback
*cb_doubleclick_
;
86 Fl_Callback
*cb_select_
;
87 void *cb_leftclick_data_
= nullptr;
88 void *cb_rightclick_data_
= nullptr;
89 void *cb_doubleclick_data_
= nullptr;
90 void *cb_select_data_
= nullptr;
91 vector
<int> cell_heights_
;
95 // returns cell height
96 int draw_single_cell ( int R
, int C
, int X
, int Y
, int W
, int H
);
97 void draw_cell ( TableContext context
, int R
=0, int C
=0, int X
=0, int Y
=0,
101 DicView(int x
, int y
, int w
, int h
, const char *l
=0 );
104 void set_data ( const vector
<string
> &d
, const vector
<int> &cell_ids
={} );
106 inline void register_tag ( const string
&name
, const TextStyle
&style
)
107 { tag_table_
[name
] = style
; };
109 inline TextStyle
*get_style ( const string
&tag
= "default" ) const
111 auto mi
= tag_table_
.find(tag
);
112 if ( mi
!= tag_table_
.end() )
113 return const_cast<TextStyle
*>(&mi
->second
);
114 return const_cast<TextStyle
*>(&tag_table_
.at("default"));
118 static void scb_copy ( Fl_Widget
*w
, void *userdata
) {
119 const char *d
= (const char*)userdata
;
121 Fl::copy( d
, len
, 0);
122 Fl::copy( d
, len
, 1);
126 inline int cell_id ( int R
, int C
)
133 catch ( std::out_of_range
) {
139 inline int selected_row_id () { return cell_id( selected_row(), 0 );};
140 inline int row_id ( int R
) { return cell_id(R
,0); };
142 inline int cell_at_xy ( int x
, int y
)
149 for ( int r
=0; r
< rows(); r
++ ){
150 int nh
= h
+ row_height(r
);
158 for ( int c
=0; c
< cols(); c
++ ){
159 int nw
= w
+ col_width(c
);
166 int ret
= R
*cols()+C
;
167 if ( R
== -1 || C
== -1 || ret
> int(data_
.size())-1 )
173 inline int row_at_y ( int y
){
177 cursor2rowcol( R
, C
, flag
);
182 int handle ( int event
);
185 inline int font_size () const { return font_size_
;};
186 inline int cell_padding_x () const { return cell_padding_x_
; };
187 inline int cell_padding_y () const { return cell_padding_y_
; };
188 inline int selected_row () {
189 for ( int r
=0; r
<rows(); r
++ )
190 if ( row_selected(r
) )
196 inline void font_size ( int s
) { font_size_
= s
; }
197 inline void cell_padding ( int x
) { cell_padding_x_
= x
; cell_padding_y_
=x
;}
198 inline void cell_padding_x ( int x
) { cell_padding_x_
= x
; };
199 inline void cell_padding_y ( int y
) { cell_padding_y_
= y
; };
200 inline void headers ( const vector
<string
> &v
) { headers_
=v
; };
202 // CALLBACKS - "setters"
203 inline void cb_leftclick ( Fl_Callback
*cb
, void *f
)
204 { cb_leftclick_
= cb
; cb_leftclick_data_
= f
; };
205 inline void cb_rightclick ( Fl_Callback
*cb
, void *f
)
206 { cb_rightclick_
= cb
; cb_rightclick_data_
= f
; };
207 inline void cb_doubleclick( Fl_Callback
*cb
, void *f
)
208 { cb_doubleclick_
= cb
; cb_doubleclick_data_
= f
; };
209 inline void cb_select ( Fl_Callback
*cb
, void *f
)
210 { cb_select_
= cb
; cb_select_data_
= f
; };
212 // CALLBACKS - "getters"
213 inline void cb_leftclick ( Fl_Widget
*w
) const
214 { cb_leftclick_(w
,cb_leftclick_data_
); };
215 inline void cb_rightclick ( Fl_Widget
*w
) const
216 { cb_rightclick_(w
, cb_rightclick_data_
); };
217 inline void cb_doubleclick( Fl_Widget
*w
) const
218 { cb_doubleclick_(w
, cb_doubleclick_data_
); };
219 inline void cb_select ( Fl_Widget
*w
) const
220 { cb_select_(w
,cb_select_data_
); }
223 inline static void scb_general ( Fl_Widget
*w
, void *f
) {};
227 #endif // _DICVIEW_HXX