Temporary prototypes of a document management program and gui toolkit I'm working on.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

224 lines
6.6KB

  1. #include <cairo/cairo.h>
  2. #include "btk-text.h"
  3. #define NEW_PP(type, pp) (pp = (type*)malloc(sizeof(type)))
  4. #define PP_BUTTON(c) ((btk_pp_button_t*)c->pp)
  5. #define PP_EDITOR(c) ((btk_pp_editor_t*)c->pp)
  6. #define PP_INPUT(c) ((btk_pp_input_t*)c->pp)
  7. #define PP_LIST(c) ((btk_pp_list_t*)c->pp)
  8. #define PP_MARK(c) ((btk_pp_mark_t*)c->pp)
  9. #define PP_SWITCH(c) ((btk_pp_switch_t*)c->pp)
  10. #define PP_TABLE(c) ((btk_pp_table_t*)c->pp)
  11. enum btk_cell_states {
  12. BTK_CELL_STATE_INITIAL = 0,
  13. BTK_CELL_STATE_HIDDEN = 1U << 0,
  14. BTK_CELL_STATE_DISABLED = 1U << 1,
  15. BTK_CELL_STATE_FOCUSED = 1U << 2,
  16. BTK_CELL_STATE_PRESSED = 1U << 3,
  17. BTK_CELL_STATE_ON = 1U << 4,
  18. BTK_CELL_STATE_BELL = 1U << 5,
  19. BTK_CELL_STATE_IN = 1U << 6
  20. };
  21. enum btk_cell_group {
  22. BTK_CELL_GROUP_PASSIVE,
  23. BTK_CELL_GROUP_DYNAMIC,
  24. BTK_CELL_GROUP_FIELD
  25. };
  26. enum btk_cell_type {
  27. BTK_CELL_TYPE_EMPTY,
  28. BTK_CELL_TYPE_MARK,
  29. BTK_CELL_TYPE_GAUGE,
  30. BTK_CELL_TYPE_BUTTON,
  31. BTK_CELL_TYPE_SWITCH,
  32. BTK_CELL_TYPE_WHEEL,
  33. BTK_CELL_TYPE_LIST,
  34. BTK_CELL_TYPE_TABLE,
  35. BTK_CELL_TYPE_INPUT,
  36. BTK_CELL_TYPE_PROMPT,
  37. BTK_CELL_TYPE_EDITOR
  38. };
  39. enum btk_cell_table_col_state {
  40. BTK_CELL_TABLE_COL_HIDDEN,
  41. BTK_CELL_TABLE_COL_VISIBLE
  42. };
  43. typedef struct {
  44. /* global properties */
  45. unsigned int group;
  46. unsigned int type;
  47. unsigned int state;
  48. btk_area_t ca; /* geometry in cell coordinates */
  49. btk_area_t pa; /* geometry in pixel coordinates */
  50. void *pp; /* type specific properties to cast */
  51. btk_field_t *fd; /* for field group types only */
  52. int lh; /* lock pixel height from stretching */
  53. char *label;
  54. } btk_cell_t;
  55. typedef struct {
  56. void (*func)(void);
  57. } btk_pp_button_t;
  58. typedef struct {
  59. char *text;
  60. unsigned int text_w;
  61. btk_pos_t caret_2d;
  62. int caret;
  63. int scroll;
  64. btk_par_t *par;
  65. } btk_pp_editor_t;
  66. typedef struct {
  67. char *text;
  68. unsigned int text_w; /* max text size */
  69. int caret;
  70. int scroll;
  71. } btk_pp_input_t;
  72. typedef struct {
  73. char **items;
  74. unsigned int *items_n;
  75. unsigned int items_w;
  76. int item_sel;
  77. int **filter; // TODO
  78. int **order; // TODO
  79. int **spot;
  80. int scroll;
  81. void (*func_trigger)(int);
  82. void (*func_sel)(int);
  83. } btk_pp_list_t;
  84. typedef struct {
  85. int justify;
  86. } btk_pp_mark_t;
  87. typedef struct {
  88. void (*func)(int, btk_arg_t);
  89. btk_arg_t func_args;
  90. } btk_pp_switch_t;
  91. typedef struct {
  92. char *header;
  93. char **items;
  94. unsigned int items_w;
  95. unsigned int cols_n;
  96. unsigned int *rows_n;
  97. int row_sel;
  98. int *cols_ena; /* hidden cols */
  99. unsigned int *cols_cw; /* width in cell units of each col */
  100. unsigned int *cols_pw; /* width in picels of each col */
  101. unsigned int *cols_px; /* position of each col in pixels */
  102. unsigned int sc; /* stretch col */
  103. unsigned int tw; /* columns total pixel width */
  104. int **filter; // TODO
  105. int **order; // TODO
  106. int **spot;
  107. btk_pos_t scroll;
  108. void (*func_trigger)(int);
  109. void (*func_sel)(int);
  110. } btk_pp_table_t;
  111. void btk_cell_set_button (btk_cell_t *,
  112. unsigned int,
  113. unsigned int,
  114. unsigned int,
  115. char *,
  116. void (*)(void));
  117. void btk_cell_set_editor (btk_cell_t *,
  118. unsigned int,
  119. unsigned int,
  120. unsigned int,
  121. unsigned int,
  122. char *,
  123. unsigned int);
  124. void btk_cell_set_empty (btk_cell_t *,
  125. unsigned int,
  126. unsigned int,
  127. unsigned int,
  128. unsigned int);
  129. void btk_cell_set_input (btk_cell_t *,
  130. unsigned int,
  131. unsigned int,
  132. unsigned int,
  133. char *,
  134. unsigned int);
  135. void btk_cell_set_list (btk_cell_t *,
  136. unsigned int,
  137. unsigned int,
  138. unsigned int,
  139. unsigned int,
  140. char **,
  141. unsigned int *,
  142. unsigned int,
  143. int **,
  144. int **,
  145. int **,
  146. void (*)(int),
  147. void (*)(int));
  148. void btk_cell_set_mark (btk_cell_t *,
  149. unsigned int,
  150. unsigned int,
  151. unsigned int,
  152. int,
  153. char *);
  154. void btk_cell_set_switch (btk_cell_t *,
  155. unsigned int,
  156. unsigned int,
  157. unsigned int,
  158. char *,
  159. void (*)(int, btk_arg_t),
  160. btk_arg_t);
  161. void btk_cell_set_table (btk_cell_t *,
  162. unsigned int,
  163. unsigned int,
  164. unsigned int,
  165. unsigned int,
  166. char *,
  167. char **,
  168. unsigned int,
  169. unsigned int,
  170. unsigned int *,
  171. int *,
  172. unsigned int *,
  173. unsigned int,
  174. int **,
  175. int **,
  176. int **,
  177. void (*)(int),
  178. void (*)(int));
  179. void btk_cell_button_trigger (btk_cell_t *, int);
  180. void btk_cell_destroy (btk_cell_t *);
  181. void btk_cell_draw (btk_cell_t *, cairo_t *);
  182. void btk_cell_editor_input_button (btk_cell_t *, int, int, btk_pos_t);
  183. void btk_cell_editor_input_key (btk_cell_t *, uint32_t);
  184. void btk_cell_editor_reset_caret (btk_cell_t*);
  185. void btk_cell_editor_update_text (btk_cell_t *);
  186. btk_field_t* btk_cell_field_create (cairo_surface_t *, btk_area_t);
  187. void btk_cell_input_button (btk_cell_t *, int, int, btk_pos_t);
  188. void btk_cell_input_input_key (btk_cell_t *, uint32_t);
  189. void btk_cell_input_reset_caret (btk_cell_t *);
  190. void btk_cell_field_destroy (btk_field_t *);
  191. void btk_cell_list_deselect (btk_cell_t*);
  192. void btk_cell_list_input_button (btk_cell_t *, int, int, btk_pos_t);
  193. int btk_cell_list_get_sel (btk_cell_t *);
  194. void btk_cell_setup_font (cairo_t *c_ctx);
  195. void btk_cell_switch_toggle (btk_cell_t *, int);
  196. void btk_cell_table_deselect (btk_cell_t*);
  197. char* btk_cell_table_get_item (btk_cell_t *, int, int);
  198. void btk_cell_table_input_button (btk_cell_t *, int, int, btk_pos_t);
  199. void btk_cell_table_update_geometry (btk_cell_t *);