Fl_TableBox.H 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef FL_TABLEBOX_H
  2. #define FL_TABLEBOX_H
  3. #ifdef WIN32
  4. #define uint unsigned int
  5. #endif
  6. #include <cstdlib>
  7. #include <cstring>
  8. #include <FL/Fl_Group.H>
  9. #define ATTACH_WIDGET(tbl, wid, label, row, col) (wid*) tbl->Attach((Fl_Widget *) new wid (0, 0, 0, 0, label), row, col)
  10. class Fl_TableBox : public Fl_Group {
  11. public:
  12. enum Expand_Type {NONE, EXPAND=2, FILL=4};
  13. enum TableBox_Type {TABLEBOX=1, VBOX, HBOX};
  14. struct TABLE_CELL {
  15. Fl_Widget * o;
  16. uint w, h;
  17. uint x_span, y_span;
  18. float x_align, y_align;
  19. bool x_expand, y_expand;
  20. bool x_fill, y_fill;
  21. void reset()
  22. {
  23. o = 0;
  24. w = 100;
  25. h = 25;
  26. x_expand = false;
  27. y_expand = false;
  28. x_fill = false;
  29. y_fill = false;
  30. x_span = 1;
  31. y_span = 1;
  32. x_align = 0.0f;
  33. y_align = 0.0f;
  34. }
  35. };
  36. struct CELL_GAP {
  37. uint w, h;
  38. };
  39. Fl_Vector_Based_On_Malloc(TABLE_CELL, TABLE_CELL, 2);
  40. Fl_Vector_Based_On_Malloc(TABLE_CELL_Vector, Fl_TABLE_CELL_Vector, 2);
  41. struct TABLE {
  42. uint cols, rows;
  43. Fl_TABLE_CELL_Vector_Vector cell;
  44. CELL_GAP * gap;
  45. };
  46. private:
  47. TableBox_Type __type;
  48. uint cur_row, cur_col;
  49. TABLE * t;
  50. public:
  51. Fl_TableBox (int _x, int _y, int _w, int _h);
  52. ~Fl_TableBox ();
  53. void resize(int _x, int _y, int _w, int _h);
  54. void draw();
  55. // get
  56. TableBox_Type Type ();
  57. void Size (uint * _rows, uint * _cols);
  58. uint Size ();
  59. uint Rows ();
  60. uint Cols ();
  61. CELL_GAP * Gap ();
  62. void Gap (uint * _w, uint * _h);
  63. Fl_Widget * Widget (uint _row, uint _col);
  64. TABLE_CELL * Cell (uint _row, uint _col);
  65. uint fixed_width();
  66. uint fixed_height();
  67. // set
  68. void Type (TableBox_Type _type);
  69. void Size (uint _rows, uint _cols);
  70. bool Size (uint _len);
  71. void Rows (uint _len);
  72. void Cols (uint _len);
  73. void AddCell (uint _len);
  74. void Gap (CELL_GAP * _gap);
  75. void Gap (uint _w, uint _h);
  76. void Widget (Fl_Widget * _widget, uint row, uint col);
  77. void Cell (TABLE_CELL * _cell, uint _row, uint _col);
  78. void Attach (const TABLE_CELL & _cell, uint _row, uint _col);
  79. Fl_Widget * Attach (
  80. Fl_Widget * _widget,
  81. uint _row, uint _col,
  82. uint _w = 100, uint _h = 25,
  83. Expand_Type _x_prop = FILL,
  84. Expand_Type _y_prop = NONE,
  85. uint _x_span = 1, uint _y_span = 1,
  86. float _x_align = 0.0f, float _y_align = 0.0f
  87. );
  88. Fl_Widget * Add (
  89. Fl_Widget * _widget,
  90. uint _w = 100, uint _h = 25,
  91. Expand_Type _x_prop = FILL,
  92. Expand_Type _y_prop = NONE,
  93. uint _x_span = 1, uint _y_span = 1,
  94. float _x_align = 0.0f, float _y_align = 0.0f
  95. );
  96. DECLARE_CLASS_CHEAP_RTTI_2(Fl_TableBox, Fl_Group)
  97. };
  98. #endif //FL_TABLEBOX_H