Flv_Style.H 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. // ======================================================================
  2. // File: Flv_Style.H - Flv_Style definition
  3. // Program: Flv_Style - FLTK Virtual List/Table Styles Widget
  4. // Version: 0.1.0
  5. // Started: 11/21/99
  6. //
  7. // Copyright (C) 1999 Laurence Charlton
  8. //
  9. // Description:
  10. // This has nothing to do with styles and themes being implemented
  11. // in FLTK 2.0 the name is just coincidental. We will however try to use
  12. // true 2.0 style information as much as possible.
  13. //
  14. // The virtual style classes are designed to handle style informaton for
  15. // the Flv_List class and derivatives. (Although anyone could use
  16. // them) The concept of virtual styles is to create a trickle down style
  17. // protocol that allows only defined attributes to be created. The trickle
  18. // down is as follows:
  19. // Global style
  20. // Row style
  21. // Column style
  22. // Cell style
  23. //
  24. // Note: Global Style will be a Flv_Cell_Style since that will
  25. // maximally define attributes for the table.
  26. // The global style will inherit whatever the current style information
  27. // dictates, so it will be completely defined. (Whether it used in 1.x or 2.x
  28. // FLTK. From there we will only require definition of styles where you
  29. // need them. For instance:
  30. // If you want to override the header and footer styles and redefine
  31. // 5 column layouts, you will have a total of 8 styles defined:
  32. // 1 global style (always defined)
  33. // 2 row styles
  34. // 5 column styles
  35. //
  36. // Hopefully only requiring the styles you really want to define will help
  37. // offset the fact that it just takes memory to do this... :)
  38. // Of course you could choose not to define any styles and then you'll just
  39. // have the global style defined. But you know the table is pretty bare...
  40. // ======================================================================
  41. #ifndef Flv_Style_H
  42. #define Flv_Style_H
  43. #include <FL/Fl.H>
  44. #ifdef FLTK_2
  45. #include <FL/Fl_Font.H>
  46. #endif
  47. // Border constants
  48. #define FLVB_NONE 0
  49. #define FLVB_LEFT 1
  50. #define FLVB_TOP 2
  51. #define FLVB_RIGHT 4
  52. #define FLVB_BOTTOM 8
  53. #define FLVB_INNER_LEFT 16
  54. #define FLVB_INNER_TOP 32
  55. #define FLVB_INNER_RIGHT 64
  56. #define FLVB_INNER_BOTTOM 128
  57. #define FLVB_OUTER_VERTICALS (FLVB_LEFT|FLVB_RIGHT)
  58. #define FLVB_OUTER_HORIZONTALS (FLVB_TOP|FLVB_BOTTOM)
  59. #define FLVB_OUTER_ALL (FLVB_VERTICALS|FLVB_HORIZONTALS)
  60. #define FLVB_INNER_VERTICALS (FLVB_INNER_LEFT|FLVB_INNER_RIGHT)
  61. #define FLVB_INNER_HORIZONTALS (FLVB_INNER_TOP|FLVB_INNER_BOTTOM)
  62. #define FLVB_INNER_ALL (FLVB_INNER_VERTICALS|FLVB_INNER_HORIZONTALS)
  63. #define FLVB_VERTICALS (FLVB_OUTER_VERTICALS|FLVB_INNER_VERTICALS)
  64. #define FLVB_HORIZONTALS (FLVB_OUTER_HORIZONTALS|FLVB_INNER_HORIZONTALS)
  65. #define FLVB_ALL (FLVB_OUTER_ALL|FLVB_INNER_ALL)
  66. #define FLVB_LEFTS (FLVB_LEFT|FLVB_INNER_LEFT)
  67. #define FLVB_TOPS (FLVB_TOP|FLVB_INNER_TOP)
  68. #define FLVB_RIGHTS (FLVB_RIGHT|FLVB_INNER_RIGHT)
  69. #define FLVB_BOTTOMS (FLVB_BOTTOM|FLVB_INNER_BOTTOM)
  70. class Flv_Style;
  71. // Note: it is undefined behavior to insert a non-dynamically allocated
  72. // styles into this list!
  73. class FL_EXPORT Flv_Style_List
  74. {
  75. public:
  76. Flv_Style_List();
  77. void clear(void); // Undefine all styles in list
  78. void compact(void); // Release any unused style memory
  79. void release(void); // Free memory for all (including cell
  80. Flv_Style *current(void); // Current node
  81. Flv_Style *find( int n ); // Find value n (Random access method)
  82. Flv_Style *first(void); // Get first style
  83. bool insert( Flv_Style *n ); // Add style (if doesn't exist)
  84. Flv_Style *next(void); // Next style
  85. Flv_Style *skip_to(int v ); // Find value n (Sequential processing)
  86. Flv_Style *prior(void); // Previous style
  87. bool clear_current(void); // Undefine optionally release
  88. bool release_current(void); // Remove current style
  89. int count(void) // # of styles
  90. {
  91. return vcount;
  92. }
  93. Flv_Style& get(int value); // Gt/Create style
  94. Flv_Style &operator[](int value)
  95. {
  96. return get(value);
  97. }; // Note: this could be a little
  98. // weird. It's actually going
  99. // to return a style with value
  100. // not index value.
  101. private:
  102. int vcount; // # of style pointers defined
  103. int vallocated; // # of style pointers allocated
  104. int vcurrent; // Current position
  105. Flv_Style **list; // Array of style pointers
  106. };
  107. class FL_EXPORT Flv_Style
  108. {
  109. public:
  110. friend class Flv_Style_List; // Hack for value
  111. Flv_Style();
  112. Flv_Style( int value );
  113. bool all_clear(void) // Is all style info cleared?
  114. {
  115. return (vdefined==0);
  116. }
  117. void clear_all(void) // Clear all style info
  118. {
  119. vdefined=0;
  120. }
  121. bool all_defined(void) // Everything defined?
  122. {
  123. return (vdefined&1023)==1023;
  124. }
  125. const Fl_Align &align(void) const // Get drawing alignment
  126. {
  127. return valign;
  128. };
  129. const Fl_Align &align(const Fl_Align &n); // Set drawing alignment
  130. void clear_align(void); // Undefine drawing alignment
  131. bool align_defined(void) const; // Is drawing alignment defined?
  132. Fl_Color background(void) const // Get background color
  133. {
  134. return vbackground;
  135. };
  136. Fl_Color background(Fl_Color n); // Set background color
  137. void clear_background(void); // Undefine background color
  138. bool background_defined(void) const; // Is background defined?
  139. int border(void) const // Get borders
  140. {
  141. return vborder;
  142. }
  143. int border(int n); // Set borders
  144. void clear_border(void); // Undefine border
  145. bool border_defined(void) const; // Is border defined?
  146. bool left_border(void) const // Left border?
  147. {
  148. return (vborder&FLVB_LEFT)==FLVB_LEFT;
  149. }
  150. bool top_border(void) const // Top border?
  151. {
  152. return (vborder&FLVB_TOP)==FLVB_TOP;
  153. }
  154. bool right_border(void) const // Right border?
  155. {
  156. return (vborder&FLVB_RIGHT)==FLVB_RIGHT;
  157. }
  158. bool bottom_border(void) const // Bottom border?
  159. {
  160. return (vborder&FLVB_BOTTOM)==FLVB_BOTTOM;
  161. }
  162. bool inner_left_border(void) const // Inner left border?
  163. {
  164. return (vborder&FLVB_INNER_LEFT)==FLVB_INNER_LEFT;
  165. }
  166. bool inner_top_border(void) const // Inner top border?
  167. {
  168. return (vborder&FLVB_INNER_TOP)==FLVB_INNER_TOP;
  169. }
  170. bool inner_right_border(void) const // Inner right border?
  171. {
  172. return (vborder&FLVB_INNER_RIGHT)==FLVB_INNER_RIGHT;
  173. }
  174. bool inner_bottom_border(void) const // Inner bottom border?
  175. {
  176. return (vborder&FLVB_INNER_BOTTOM)==FLVB_INNER_BOTTOM;
  177. }
  178. Fl_Color border_color(void) const // Get border colors
  179. {
  180. return vborder_color;
  181. }
  182. Fl_Color border_color(Fl_Color n); // Set border colors
  183. void clear_border_color(void); // Undefine border color
  184. bool border_color_defined(void) const; // Is border color defined?
  185. int border_spacing(void) const // Get border spacings
  186. {
  187. return vborder_spacing;
  188. }
  189. int border_spacing(int n); // Set border spacings
  190. void clear_border_spacing(void); // Undefine border spacing
  191. bool border_spacing_defined(void) const; // Is border spacing defined?
  192. Fl_Widget *editor(void) const // Get content editor
  193. {
  194. return veditor;
  195. };
  196. Fl_Widget *editor(Fl_Widget *v);
  197. void clear_editor(void); // Undefine content editor
  198. bool editor_defined(void) const; // Is content editor defined?
  199. const Fl_Font &font(void) const // Get current font
  200. {
  201. return vfont;
  202. };
  203. const Fl_Font &font(const Fl_Font &n); // Set current font
  204. void clear_font(void); // Undefine font
  205. bool font_defined(void) const; // Is font defined
  206. int font_size(void) const // Get font size
  207. {
  208. return vfont_size;
  209. };
  210. int font_size(int n); // Set font size
  211. void clear_font_size(void); // Undefine font size
  212. bool font_size_defined(void) const; // Is font size defined?
  213. Fl_Color foreground(void) const // Get foreground color
  214. {
  215. return vforeground;
  216. };
  217. Fl_Color foreground(Fl_Color n); // Set foreground color
  218. void clear_foreground(void); // Undefine foreground color
  219. bool foreground_defined(void) const; // Is foreground defined?
  220. const Fl_Boxtype &frame(void) const // Get frame type
  221. {
  222. return vframe;
  223. };
  224. const Fl_Boxtype &frame(const Fl_Boxtype &n) ; // Set frame type
  225. void clear_frame(void); // Undefine frame type
  226. bool frame_defined(void) const; // Is frame type defined?
  227. int height(void) const // Get height
  228. {
  229. return vheight;
  230. };
  231. int height(int n ); // Set height
  232. void clear_height(void); // Undefine row height
  233. bool height_defined(void) const; // Is row height defined
  234. bool locked(void) const // Get locked
  235. {
  236. return vlocked;
  237. }
  238. bool locked(bool n); // Set locked
  239. void clear_locked(void); // Undefine locked
  240. bool locked_defined(void) const; // Is locked defined?
  241. bool resizable(void) const // Get resizable (Not for Cell)
  242. {
  243. return vresizable;
  244. };
  245. bool resizable(bool n); // Set resizable
  246. void clear_resizable(void); // Undefine resizable
  247. bool resizable_defined(void) const; // Is resizable defined?
  248. int width(void) const // Get column width
  249. {
  250. return vwidth;
  251. }
  252. int width(int n); // Set column width
  253. void clear_width(void); // Undefine column width
  254. bool width_defined(void) const; // Is column width defined?
  255. int x_margin(void) const // Get x margin
  256. {
  257. return vx_margin;
  258. }
  259. int x_margin(int x); // Set x margin
  260. void clear_x_margin(void); // Undefine x margin
  261. bool x_margin_defined(void) const; // Is x margin defined?
  262. int y_margin(void) const // Get y margin
  263. {
  264. return vy_margin;
  265. }
  266. int y_margin(int y); // Set y margin
  267. void clear_y_margin(void); // Undefine y margin
  268. bool y_margin_defined(void) const; // Is y margin defined?
  269. // Cumulative assignment operator
  270. // This will only assign portions that are defined.
  271. const Flv_Style &add(const Flv_Style &n);
  272. const Flv_Style &operator=(const Flv_Style &n)
  273. {
  274. return add(n);
  275. };
  276. Flv_Style_List cell_style;
  277. protected:
  278. int value(void) const // Get row/column #
  279. {
  280. return vvalue;
  281. };
  282. int value(int n) // Set row/column #
  283. {
  284. return (vvalue=n);
  285. }
  286. private:
  287. unsigned int vdefined; // Which parts are defined?
  288. Fl_Align valign; // Drawing alignment
  289. Fl_Color vbackground; // Background color
  290. Fl_Color vborder_color; // Outer border color
  291. Fl_Widget *veditor; // Content editor
  292. unsigned char vborder; // Borders around cell
  293. unsigned char vborder_spacing; // Spacing between inner/outer border
  294. unsigned char vx_margin; // X margin (Left/Right)
  295. unsigned char vy_margin; // Y margin (Top/Bottom)
  296. Flv_Style_List vcell; // Cell list
  297. Fl_Font vfont; // Font to draw with
  298. int vfont_size; // Size of font
  299. Fl_Color vforeground; // Foreground color
  300. Fl_Boxtype vframe; // Frame around cell
  301. int vheight; // Row height
  302. int vvalue; // Row or Column #
  303. int vwidth; // Column height
  304. bool vlocked; // Group locked?
  305. bool vresizable; // Allow resizing?
  306. };
  307. #endif