Flv_List.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. // *** TODO ***
  2. // Implement row styles, global styles
  3. // ======================================================================
  4. // File: Flv_List.h - Flv_List implementation
  5. // Program: Flv_List - FLTK Widget
  6. // Version: 0.1.0
  7. // Started: 11/21/99
  8. //
  9. // Copyright (C) 1999 Laurence Charlton
  10. //
  11. // Description:
  12. // Flv_List implements a scrollable list. No data is stored
  13. // in the widget. Supports headers/footers, natively supports a single
  14. // row height per list. Row grids can be turned on and off. Supports
  15. // no scroll bars as well as horizontal/vertical automatic or always
  16. // on scroll bars.
  17. // Uses absolute row references.
  18. //
  19. // row -1 is defined as the row header
  20. // row -2 is defined as the row footer
  21. //
  22. // This library is free software; you can redistribute it and/or
  23. // modify it under the terms of the GNU Library General Public
  24. // License as published by the Free Software Foundation; either
  25. // version 2 of the License, or (at your option) any later version.
  26. //
  27. // This library is distributed in the hope that it will be useful,
  28. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  30. // Library General Public License for more details.
  31. //
  32. // You should have received a copy of the GNU Library General Public
  33. // License along with this library; if not, write to the Free Software
  34. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  35. // USA.
  36. // ======================================================================
  37. #ifndef Flv_List_H
  38. #define Flv_List_H
  39. #include <FL/Fl.H>
  40. #include <FL/Fl_Group.H>
  41. #include <FL/Fl_Scrollbar.H>
  42. #include <FL/Enumerations.H>
  43. #include <FL/Flv_Style.H>
  44. #ifndef FLTK_2
  45. #define text_color() FL_BLACK
  46. #define text_font() FL_HELVETICA
  47. #define text_size() 12
  48. //#define fl_inactive inactive
  49. //#define fl_contrast(x,y) FL_BLACK
  50. #define selection_text_color() FL_WHITE
  51. #define FL_DAMAGE_HIGHLIGHT FL_DAMAGE_CHILD
  52. #define label_font labelfont
  53. #define label_size labelsize
  54. #define label_color labelcolor
  55. #define label_type labeltype
  56. #endif
  57. #define FLV_ROW_HEADER -1
  58. #define FLV_ROW_FOOTER -2
  59. #define FLV_TITLE -3
  60. #define SLIDER_WIDTH 17
  61. typedef unsigned char Flv_ShowScrollbar;
  62. typedef unsigned short Flv_Feature;
  63. // Call back events
  64. #define FLVE_ROW_CHANGED 1
  65. #define FLVE_ROWS_CHANGED 2
  66. #define FLVE_SELECTION_CHANGED 3
  67. #define FLVE_COL_CHANGED 4
  68. #define FLVE_COLS_CHANGED 5
  69. #define FLVE_FEATURE_CHANGED 6
  70. #define FLVE_CLICKED 7
  71. #define FLVE_ENTER_PRESSED 8
  72. #define FLVE_ROW_HEADER_CLICKED 9
  73. #define FLVE_ROW_FOOTER_CLICKED 10
  74. #define FLVE_COL_HEADER_CLICKED 11
  75. #define FLVE_COL_FOOTER_CLICKED 12
  76. #define FLVE_LABEL_CLICKED 13
  77. #define FLVE_TITLE_CLICKED 14
  78. #define FLVE_ALL_CLICKED 15
  79. // Call back when flags
  80. #define FLVEcb_ROW_CHANGED 0x0001
  81. #define FLVEcb_ROWS_CHANGED 0x0002
  82. #define FLVEcb_SELECTION_CHANGED 0x0004
  83. #define FLVEcb_COL_CHANGED 0x0008
  84. #define FLVEcb_COLS_CHANGED 0x0010
  85. #define FLVEcb_FEATURE_CHANGED 0x0020
  86. #define FLVEcb_CLICKED 0x0040
  87. #define FLVEcb_ENTER_PRESSED 0x0080
  88. #define FLVEcb_ROW_HEADER_CLICKED 0x0100
  89. #define FLVEcb_ROW_FOOTER_CLICKED 0x0200
  90. #define FLVEcb_COL_HEADER_CLICKED 0x0400
  91. #define FLVEcb_COL_FOOTER_CLICKED 0x0800
  92. #define FLVEcb_LABEL_CLICKED 0x1000
  93. #define FLVEcb_TITLE_CLICKED 0x2000
  94. #define FLVEcb_ALL_CLICKED 0x4000
  95. // Feature list
  96. #define FLVF_NONE 0
  97. #define FLVF_ROW_HEADER 1
  98. #define FLVF_ROW_FOOTER 2
  99. #define FLVF_ROW_DIVIDER 4
  100. #define FLVF_COL_HEADER 8
  101. #define FLVF_COL_FOOTER 16
  102. #define FLVF_COL_DIVIDER 32
  103. #define FLVF_MULTI_SELECT 64
  104. #define FLVF_ROW_SELECT 128
  105. #define FLVF_PERSIST_SELECT 256
  106. #define FLVF_FULL_RESIZE 512
  107. #define FLVF_DIVIDERS (FLVF_COL_DIVIDER|FLVF_ROW_DIVIDER)
  108. #define FLVF_HEADERS (FLVF_ROW_HEADER|FLVF_COL_HEADER)
  109. #define FLVF_FOOTERS (FLVF_ROW_FOOTER|FLVF_COL_FOOTER)
  110. #define FLVF_ROW_ENDS (FLVF_ROW_HEADER|FLVF_ROW_FOOTER)
  111. #define FLVF_COL_ENDS (FLVF_COL_HEADER|FLVF_COL_FOOTER)
  112. #define FLVF_ALL_ROW (FLVF_ROW_HEADER|FLVF_ROW_FOOTER|FLVF_ROW_DIVIDER)
  113. #define FLVF_ALL_COL (FLVF_COL_HEADER|FLVF_COL_FOOTER|FLVF_COL_DIVIDER)
  114. // Scroll bar visibility
  115. #define FLVS_NONE 0
  116. #define FLVS_HORIZONTAL 1
  117. #define FLVS_VERTICAL 2
  118. #define FLVS_BOTH (FLVS_HORIZONTAL|FLVS_VERTICAL)
  119. #define FLVS_AUTOMATIC 0
  120. #define FLVS_ALWAYS 4
  121. #define FLVS_HORIZONTAL_ALWAYS (FLVS_HORIZONTAL|FLVS_ALWAYS)
  122. #define FLVS_VERTICAL_ALWAYS (FLVS_VERTICAL|FLVS_ALWAYS)
  123. //#define FLVS_BOTH_ALWAYS (FLVS_BOTH|FLVS|FLVS_ALWAYS)
  124. #define FLVS_BOTH_ALWAYS (FLVS_BOTH|FLVS_ALWAYS)
  125. // Edit when constants
  126. #define FLV_EDIT_ALWAYS 1
  127. #define FLV_EDIT_AUTOMATIC 2
  128. #define FLV_EDIT_MANUAL 3
  129. class FL_EXPORT Flv_List : public Fl_Group
  130. {
  131. public:
  132. Fl_Scrollbar scrollbar; // Vertical scrollbar
  133. Fl_Scrollbar hscrollbar; // Horizontal scrollbar
  134. Fl_Scrollbar *get_scrollbar()
  135. {
  136. return &scrollbar;
  137. };
  138. Fl_Scrollbar *get_hscrollbar()
  139. {
  140. return &hscrollbar;
  141. };
  142. Flv_List( int X, int Y, int W, int H, const char *l=0 );
  143. ~Flv_List();
  144. virtual int row_height( int n );
  145. virtual int row_height( int n, int R );
  146. virtual void get_style(Flv_Style &s, int R, int C=0); // get trickle down style
  147. void add_selection_style( Flv_Style &s, int R, int C=0 ); // Add selection style
  148. virtual void save_editor( Fl_Widget *e, int R, int C=0 ); // Save editor contents
  149. virtual void load_editor( Fl_Widget *e, int R, int C=0 ); // Load editor contents
  150. virtual void position_editor( Fl_Widget *e, int x, int y, int w, int h, Flv_Style &s );
  151. int callback_when(void) // Get callback when
  152. {
  153. return vcallback_when;
  154. }
  155. int callback_when(int v) // Set callback when
  156. {
  157. return vcallback_when = v;
  158. }
  159. int add_callback_when(int v) // Add callback conditions
  160. {
  161. return vcallback_when |= v;
  162. }
  163. int clear_callback_when(int v) // Clear callback conditions
  164. {
  165. return vcallback_when &= ~v;
  166. }
  167. bool callback_on(int v) // See if callback should be done
  168. {
  169. return (vcallback_when & v)==v;
  170. }
  171. int edit_when(void) // Get when to edit
  172. {
  173. return vedit_when;
  174. }
  175. int edit_when( int v ); // Set when to edit
  176. void start_edit(void); // Start editing
  177. void end_edit(void); // End editing (w/save)
  178. void cancel_edit(void); // Cancel editing (wo/save)
  179. Fl_Widget *editor(void) // Return current editor
  180. {
  181. return veditor;
  182. }
  183. int bottom_row(void); // Return last partially visible row
  184. unsigned char clicks() // # of clicks 1, 2, 3...
  185. {
  186. return vclicks;
  187. }
  188. void clear_clicks(void) // Reset # of clicks
  189. {
  190. vclicks = 0;
  191. }
  192. unsigned char max_clicks(void) // Get Max # of clicks
  193. {
  194. return vmax_clicks;
  195. }
  196. unsigned char max_clicks(unsigned char n) // Return max # of clicks
  197. {
  198. return vmax_clicks=n;
  199. }
  200. Fl_Color dead_space_color(void) const // Get dead space color
  201. {
  202. return vdead_space_color;
  203. }
  204. Fl_Color dead_space_color(Fl_Color n) // Set dead space color
  205. {
  206. return (vdead_space_color = n);
  207. }
  208. Flv_Feature feature(void) // Get features
  209. {
  210. return vfeature;
  211. }
  212. Flv_Feature feature(Flv_Feature v); // Set features
  213. Flv_Feature feature_add(Flv_Feature v); // Add (set of) feature(s)
  214. Flv_Feature feature_remove(Flv_Feature v); // Remove (set of) feature(s)
  215. bool feature_test(Flv_Feature v) // Test if (set of) feature(s) on
  216. {
  217. return ((vfeature&v)==v);
  218. }
  219. // Convenience funtions to test if a feature is ON.
  220. bool row_footer(void) // Row footer convenience function
  221. {
  222. return feature_test(FLVF_ROW_FOOTER);
  223. }
  224. bool row_header(void) // Row header convenience function
  225. {
  226. return feature_test(FLVF_ROW_HEADER);
  227. }
  228. bool row_divider(void) // Row divider convenience function
  229. {
  230. return feature_test(FLVF_ROW_DIVIDER);
  231. }
  232. bool multi_select(void) // Multi-select convenience function
  233. {
  234. return feature_test(FLVF_MULTI_SELECT);
  235. }
  236. bool persist_select(void) // Persistant selection test
  237. {
  238. return feature_test(FLVF_PERSIST_SELECT);
  239. }
  240. bool full_resize(void) // Full widget resize test
  241. {
  242. return feature_test(FLVF_FULL_RESIZE);
  243. }
  244. bool select_row(void) // Selecting row convenience function
  245. {
  246. return feature_test(FLVF_ROW_SELECT);
  247. }
  248. void get_default_style( Flv_Style &s ); // Fill in s with default style
  249. int get_row( int x, int y ); // Get row from X value
  250. virtual bool get_cell_bounds( int &X, int &Y, int &W, int &H, int R, int C=0 )
  251. {
  252. return false;
  253. };
  254. Flv_ShowScrollbar has_scrollbar(void) // Get/set scrollbar visibility
  255. {
  256. return vhas_scrollbars;
  257. }
  258. Flv_ShowScrollbar has_scrollbar( Flv_ShowScrollbar v );
  259. virtual bool move_row(int amount); // Change row # by amount
  260. int row(void) // Get/set current row
  261. {
  262. return vrow;
  263. };
  264. int row(int n);
  265. bool row_resizable( int r ); // Get/Set row locked status
  266. bool row_resizable( bool n, int r );
  267. int row_offset(void) // Get/Set current row offset
  268. {
  269. return vrow_offset;
  270. }
  271. int row_offset( int n );
  272. int rows(void) // Get/Set total # of rows
  273. {
  274. return vrows;
  275. };
  276. int rows(int n);
  277. int rows_per_page(void) // Get/set # of rows / page
  278. {
  279. return vrows_per_page;
  280. }
  281. int rows_per_page( int n ); // Use 0 to allow calculating
  282. bool row_selected(int n); // Is row selected?
  283. int row_width(void) // Get/set total row width
  284. {
  285. return vrow_width;
  286. };
  287. int row_width( int n );
  288. int scrollbar_width(void) // Get/set scrollbar thickness
  289. {
  290. return vscrollbar_width;
  291. }
  292. int scrollbar_width(int n);
  293. bool select_locked(void) // Allow selecting locked rows/cols?
  294. {
  295. return vselect_locked;
  296. }
  297. bool select_locked(bool n) // Set whether allowing selection of
  298. {
  299. return (vselect_locked=n); // locked rows/cols
  300. }
  301. int select_start_row(void) // Get first selected row
  302. {
  303. return vselect_row;
  304. }
  305. int select_start_row(int n); // Set first selected row
  306. int top_row(void) // Get the current top row
  307. {
  308. return vtop_row;
  309. }
  310. int top_row(int v)
  311. {
  312. return (vtop_row=v);
  313. }; // Set the top row (Hint only)
  314. int why_event() // Why was the event called?
  315. {
  316. return vwhy_event;
  317. }
  318. int why_event( int n ) // Set why the event was called
  319. {
  320. return (vwhy_event=n);
  321. }
  322. // Style routines
  323. Flv_Style global_style; // Global style
  324. Flv_Style_List row_style; // Row styles
  325. int handle(int event);
  326. DECLARE_CLASS_CHEAP_RTTI_2(Flv_List, Fl_Group)
  327. protected:
  328. int vedit_when; // When does editing start
  329. int edit_row;
  330. void switch_editor( int nr );
  331. Fl_Widget *veditor; // Current editor
  332. int vwhy_event; // Why was event called
  333. int vlast_row; // Last row highlighted
  334. void update_top_row(int H);
  335. void start_draw(int &X, int &Y, int &W, int &H, int &rw);
  336. virtual void draw_row( int Offset, int &X, int &Y, int &W, int &H, int R );
  337. void draw_border(Flv_Style &s, int &X, int &Y, int &W, int &H );
  338. void client_area( int &X, int &Y, int &W, int &H );
  339. void draw_scrollbars( int &X, int &Y, int &W, int &H );
  340. void draw();
  341. int page_size(void); // Calculate useable page size
  342. int vrow; // Current selected row
  343. int last_click_timestamp;
  344. unsigned char vmax_clicks; // Max clicks allowed
  345. unsigned char vclicks;
  346. bool vediting; // Are we editing now?
  347. bool is_dragging;
  348. private:
  349. #ifdef FLTK_2
  350. static Fl_Style* default_style;
  351. #endif
  352. void check_cursor(void); // Check if resizing allowed here
  353. bool check_resize(void); // true if resizing
  354. int vcallback_when; // When to call back
  355. Fl_Color vdead_space_color; // Dead space color
  356. Flv_ShowScrollbar vhas_scrollbars; // determine scroll bar visibility
  357. Flv_Feature vfeature; // Features (Headers, footers, dividers)
  358. int vrow_offset; // Current left offset for display
  359. int vrow_width; // Total pixel width
  360. int vrows; // Total # of rows to display
  361. int vrows_per_page; // # of rows to advance/page
  362. int vselect_row; // First selected row
  363. int vscrollbar_width; // "thickness" of scrollbar
  364. int vtop_row; // Current top row
  365. bool vselect_locked; // Selected locked entries or skip?
  366. };
  367. #endif