Flv_Table.H 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // ======================================================================
  2. // File: Flv_Table.h - Flv_Table implementation
  3. // Program: Flv_Table - FLTK Widget
  4. // Version: 0.1.0
  5. // Started: 11/21/99
  6. //
  7. // Copyright (C) 1999 Laurence Charlton
  8. //
  9. // Description:
  10. // Flv_Table implements a table/grid. No data is stored
  11. // in the widget. Supports headers/footers for rows and columns,
  12. // natively supports a single row height and column width per table.
  13. // Row and column grids can be turned on and off. Supports no scroll
  14. // bars as well as horizontal/vertical automatic or always on scroll bars.
  15. // Also support cell selection and row selection modes. In row selection
  16. // mode it acts like a pumped-up list widget.
  17. //
  18. // row -1 is defined as the row header
  19. // row -2 is defined as the row footer
  20. // column -1 is defined as the column header
  21. // column -2 is defined as the column footer
  22. //
  23. // This library is free software; you can redistribute it and/or
  24. // modify it under the terms of the GNU Library General Public
  25. // License as published by the Free Software Foundation; either
  26. // version 2 of the License, or (at your option) any later version.
  27. //
  28. // This library is distributed in the hope that it will be useful,
  29. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  31. // Library General Public License for more details.
  32. //
  33. // You should have received a copy of the GNU Library General Public
  34. // License along with this library; if not, write to the Free Software
  35. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  36. // USA.
  37. // ======================================================================
  38. #ifndef Flv_Table_H
  39. #define Flv_Table_H
  40. #include <FL/Flv_List.H>
  41. #define FLV_COL_HEADER -1
  42. #define FLV_COL_FOOTER -2
  43. #define FLV_MOVE_ON_ENTER_ROW_COL 1
  44. #define FLV_MOVE_ON_ENTER_COL_ROW 2
  45. #define FLV_MOVE_ON_ENTER_NEVER 3
  46. #define FLV_BUTTON1 1
  47. #define FLV_BUTTON2 2
  48. #define FLV_BUTTON3 4
  49. class FL_EXPORT Flv_Table : public Flv_List
  50. {
  51. public:
  52. Flv_Table( int X, int Y, int W, int H, const char *l=0 );
  53. ~Flv_Table();
  54. virtual int col_width(int c); // Get column width
  55. virtual int col_width(int n, int c); // Set column width
  56. // Add selection info if applicable
  57. void add_selection_style( Flv_Style &s, int R, int C=0 );
  58. int buttons(void)
  59. {
  60. return vbuttons;
  61. }
  62. int buttons(int v)
  63. {
  64. return (vbuttons=v);
  65. }
  66. void cell_area( int &X, int &Y, int &W, int &H);
  67. bool cell_selected(int R, int C); // Is cell selected?
  68. // Convenience functions to tell if a feature is ON.
  69. bool col_footer(void) // Column footer convenience function
  70. {
  71. return (Flv_Feature)(feature() & FLVF_COL_FOOTER)!=0;
  72. }
  73. bool col_header(void) // Column header convenience function
  74. {
  75. return (Flv_Feature)(feature() & FLVF_COL_HEADER)!=0;
  76. }
  77. bool col_divider(void) // Column divider convenience function
  78. {
  79. return (Flv_Feature)(feature() & FLVF_COL_DIVIDER)!=0;
  80. }
  81. // These are guaranteed style retrieval functions and get
  82. // the trickle down style information. Any style elements
  83. // not defined are set to default values.
  84. virtual void get_style( Flv_Style &s, int R, int C=0 );
  85. int edit_when(void) // Get when to edit
  86. {
  87. return vedit_when;
  88. }
  89. int edit_when( int v ); // When to edit
  90. bool move_row(int amount); // # of rows to move
  91. bool move_col(int amount); // # of cols to move
  92. int col(void) // Get current column #
  93. {
  94. return vcol;
  95. }
  96. int col( int n ); // Set current column #
  97. int row(void) // Get current row #
  98. {
  99. return vrow;
  100. }
  101. int row(int n); // Set current row #
  102. bool col_resizable(int c); // Get/set column locked status
  103. bool col_resizable( bool n, int c);
  104. int cols(void) // Get number of columns
  105. {
  106. return vcols;
  107. }
  108. int cols( int n ); // Set number of columns
  109. bool col_selected(int n); // Is column selected
  110. bool get_cell_bounds( int &X, int &Y, int &W, int &H, int R, int C );
  111. int get_col( int x, int y ); // Get column from x,y
  112. int move_on_enter(void) const // How do we move when enter pressed?
  113. {
  114. return vmove_on_enter;
  115. }
  116. int move_on_enter(int v) // Set how we move on enter
  117. {
  118. return (vmove_on_enter=v);
  119. }
  120. int select_start_col(void) // Get column selection starts in
  121. {
  122. return vselect_col;
  123. }
  124. int select_start_col(int n); // Set column selection starts in
  125. void start_edit(void); // Start editing
  126. void end_edit(void); // End editing (with save)
  127. void cancel_edit(void); // Cancel editing (no save)
  128. Flv_Style_List col_style; // Column styles
  129. int handle(int event);
  130. DECLARE_CLASS_CHEAP_RTTI_2(Flv_Table, Flv_List)
  131. protected:
  132. int edit_col;
  133. void switch_editor( int nr, int nc );
  134. void draw(void);
  135. int internal_handle(int event);
  136. virtual void draw_row( int Offset, int &X, int &Y, int &W, int &H, int R );
  137. virtual void draw_cell( int Offset, int &X, int &Y, int &W, int &H, int R, int C );
  138. private:
  139. void check_cursor(void); // Check if resizing allowed here
  140. bool check_resize(void); // true if resizing
  141. void update_width(); // Update scroll width
  142. void adjust_for_cell(); // Guarantee cell is as visible as possible
  143. int vbuttons; // Click buttons
  144. int vcol; // Current column
  145. int vcol_width; // Default width
  146. int vcols; // Total # of columns
  147. int vmove_on_enter; // How to move when enter pressed.
  148. int vselect_col; // First column selected
  149. };
  150. #endif