Fl_Table_Row.H 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $"
  3. //
  4. #ifndef _FL_TABLE_ROW_H
  5. #define _FL_TABLE_ROW_H
  6. //
  7. // Fl_Table_Row -- A row oriented table widget
  8. //
  9. // A class specializing in a table of rows.
  10. // Handles row-specific selection behavior.
  11. //
  12. // Copyright 2002 by Greg Ercolano.
  13. //
  14. // This library is free software. Distribution and use rights are outlined in
  15. // the file "COPYING" which should have been included with this file. If this
  16. // file is missing or damaged, see the license at:
  17. //
  18. // http://www.fltk.org/COPYING.php
  19. //
  20. // Please report all bugs and problems to "erco at seriss dot com".
  21. //
  22. #include "Fl_Table.H"
  23. /**
  24. A table with row selection capabilities.
  25. This class implements a simple table with the ability to select
  26. rows. This widget is similar to an Fl_Browser with columns. Most
  27. methods of importance will be found in the Fl_Table widget, such
  28. as Fl_Table::rows() and Fl_Table::cols().
  29. To be useful it must be subclassed and at minimum the draw_cell()
  30. method must be overridden to provide the content of the cells. This widget
  31. does \em not manage the cell's data content; it is up to the parent
  32. class's draw_cell() method override to provide this.
  33. Events on the cells and/or headings generate callbacks when they are
  34. clicked by the user. You control when events are generated based on
  35. the values you supply for Fl_Table::when().
  36. */
  37. class FL_EXPORT Fl_Table_Row : public Fl_Table {
  38. public:
  39. enum TableRowSelectMode {
  40. SELECT_NONE, // no selection allowed
  41. SELECT_SINGLE, // single row selection
  42. SELECT_MULTI // multiple row selection (default)
  43. };
  44. private:
  45. Fl_Char_Vector _rowselect; // selection flag for each row
  46. // handle() state variables.
  47. // Put here instead of local statics in handle(), so more
  48. // than one instance can exist without crosstalk between.
  49. //
  50. int _dragging_select; // dragging out a selection?
  51. int _last_row;
  52. int _last_y; // last event's Y position
  53. int _last_push_x; // last PUSH event's X position
  54. int _last_push_y; // last PUSH event's Y position
  55. TableRowSelectMode _selectmode;
  56. protected:
  57. int handle(int event);
  58. int find_cell(TableContext context, // find cell's x/y/w/h given r/c
  59. int R, int C, int &X, int &Y, int &W, int &H) {
  60. return(Fl_Table::find_cell(context, R, C, X, Y, W, H));
  61. }
  62. public:
  63. /**
  64. The constructor for the Fl_Table_Row.
  65. This creates an empty table with no rows or columns,
  66. with headers and row/column resize behavior disabled.
  67. */
  68. Fl_Table_Row(int X, int Y, int W, int H, const char *l=0) : Fl_Table(X,Y,W,H,l) {
  69. _dragging_select = 0;
  70. _last_row = -1;
  71. _last_y = -1;
  72. _last_push_x = -1;
  73. _last_push_y = -1;
  74. _selectmode = SELECT_MULTI;
  75. }
  76. /**
  77. The destructor for the Fl_Table_Row.
  78. Destroys the table and its associated widgets.
  79. */
  80. ~Fl_Table_Row() { }
  81. void rows(int val); // set number of rows
  82. int rows() { // get number of rows
  83. return(Fl_Table::rows());
  84. }
  85. /**
  86. Sets the table selection mode.
  87. - \p Fl_Table_Row::SELECT_NONE - No selection allowed
  88. - \p Fl_Table_Row::SELECT_SINGLE - Only single rows can be selected
  89. - \p Fl_Table_Row::SELECT_MULTI - Multiple rows can be selected
  90. */
  91. void type(TableRowSelectMode val); // set selection mode
  92. TableRowSelectMode type() const { // get selection mode
  93. return(_selectmode);
  94. }
  95. /**
  96. Checks to see if 'row' is selected. Returns 1 if selected, 0 if not. You can
  97. change the selection of a row by clicking on it, or by using
  98. select_row(row, flag)
  99. */
  100. int row_selected(int row); // is row selected? (0=no, 1=yes, -1=range err)
  101. /**
  102. Changes the selection state for 'row', depending on the value
  103. of 'flag'. 0=deselected, 1=select, 2=toggle existing state.
  104. */
  105. int select_row(int row, int flag=1); // select state for row: flag:0=off, 1=on, 2=toggle
  106. // returns: 0=no change, 1=changed, -1=range err
  107. /**
  108. This convenience function changes the selection state
  109. for \em all rows based on 'flag'. 0=deselect, 1=select, 2=toggle existing state.
  110. */
  111. void select_all_rows(int flag=1); // all rows to a known state
  112. void clear() {
  113. rows(0); // implies clearing selection
  114. cols(0);
  115. Fl_Table::clear(); // clear the table
  116. }
  117. DECLARE_CLASS_CHEAP_RTTI_2(Fl_Table_Row, Fl_Table)
  118. };
  119. #endif /*_FL_TABLE_ROW_H*/
  120. //
  121. // End of "$Id: Fl_Table_Row.H 8864 2011-07-19 04:49:30Z greg.ercolano $".
  122. //