1with agar.core.event;
2with agar.core.slist;
3with agar.core.timeout;
4with agar.gui.surface;
5with agar.gui.widget.menu;
6with agar.gui.widget.scrollbar;
7with agar.gui.window;
8
9package agar.gui.widget.table is
10
11  use type c.unsigned;
12
13  type popup_t is limited private;
14  type popup_access_t is access all popup_t;
15  pragma convention (c, popup_access_t);
16
17  txt_max      : constant := 128;
18  fmt_max      : constant := 16;
19  col_name_max : constant := 48;
20
21  type select_mode_t is (SEL_ROWS, SEL_CELLS, SEL_COLS);
22   for select_mode_t use (SEL_ROWS => 0, SEL_CELLS => 1, SEL_COLS => 2);
23   for select_mode_t'size use c.unsigned'size;
24  pragma convention (c, select_mode_t);
25
26  package popup_slist is new agar.core.slist
27    (entry_type => popup_access_t);
28
29  type cell_type_t is (
30    CELL_NULL,
31    CELL_STRING,
32    CELL_INT,
33    CELL_UINT,
34    CELL_LONG,
35    CELL_ULONG,
36    CELL_FLOAT,
37    CELL_DOUBLE,
38    CELL_PSTRING,
39    CELL_PINT,
40    CELL_PUINT,
41    CELL_PLONG,
42    CELL_PULONG,
43    CELL_PUINT8,
44    CELL_PSINT8,
45    CELL_PUINT16,
46    CELL_PSINT16,
47    CELL_PUINT32,
48    CELL_PSINT32,
49    CELL_PFLOAT,
50    CELL_PDOUBLE,
51    CELL_INT64,
52    CELL_UINT64,
53    CELL_PINT64,
54    CELL_PUINT64,
55    CELL_POINTER,
56    CELL_FN_SU,
57    CELL_FN_TXT,
58    CELL_WIDGET
59  );
60  for cell_type_t use (
61    CELL_NULL    => 0,
62    CELL_STRING  => 1,
63    CELL_INT     => 2,
64    CELL_UINT    => 3,
65    CELL_LONG    => 4,
66    CELL_ULONG   => 5,
67    CELL_FLOAT   => 6,
68    CELL_DOUBLE  => 7,
69    CELL_PSTRING => 8,
70    CELL_PINT    => 9,
71    CELL_PUINT   => 10,
72    CELL_PLONG   => 11,
73    CELL_PULONG  => 12,
74    CELL_PUINT8  => 13,
75    CELL_PSINT8  => 14,
76    CELL_PUINT16 => 15,
77    CELL_PSINT16 => 16,
78    CELL_PUINT32 => 17,
79    CELL_PSINT32 => 18,
80    CELL_PFLOAT  => 19,
81    CELL_PDOUBLE => 20,
82    CELL_INT64   => 21,
83    CELL_UINT64  => 22,
84    CELL_PINT64  => 23,
85    CELL_PUINT64 => 24,
86    CELL_POINTER => 25,
87    CELL_FN_SU   => 26,
88    CELL_FN_TXT  => 27,
89    CELL_WIDGET  => 28
90  );
91  for cell_type_t'size use c.unsigned'size;
92  pragma convention (c, cell_type_t);
93
94  type cell_data_text_t is array (1 .. txt_max) of aliased c.char;
95  pragma convention (c, cell_data_text_t);
96
97  type cell_data_selector_t is (sel_s, sel_i, sel_f, sel_p, sel_l, sel_u64);
98  type cell_data_t (member : cell_data_selector_t := sel_s) is record
99    case member is
100      when sel_s   => s   : cell_data_text_t;
101      when sel_i   => i   : c.int;
102      when sel_f   => f   : c.double;
103      when sel_p   => p   : agar.core.types.void_ptr_t;
104      when sel_l   => l   : c.long;
105      when sel_u64 => u64 : agar.core.types.uint64_t;
106    end case;
107  end record;
108  pragma convention (c, cell_data_t);
109  pragma unchecked_union (cell_data_t);
110
111  type cell_format_t is array (1 .. fmt_max) of aliased c.char;
112  pragma convention (c, cell_format_t);
113
114  type cell_t is limited private;
115  type cell_access_t is access all cell_t;
116  pragma convention (c, cell_access_t);
117
118  type column_name_t is array (1 .. col_name_max) of aliased c.char;
119  pragma convention (c, column_name_t);
120
121  type column_flags_t is new c.unsigned;
122  TABLE_COL_FILL        : constant column_flags_t := 16#01#;
123  TABLE_SORT_ASCENDING  : constant column_flags_t := 16#02#;
124  TABLE_SORT_DESCENDING : constant column_flags_t := 16#04#;
125  TABLE_HFILL           : constant column_flags_t := 16#08#;
126  TABLE_VFILL           : constant column_flags_t := 16#10#;
127  TABLE_EXPAND          : constant column_flags_t := TABLE_HFILL or TABLE_VFILL;
128
129  type column_t is limited private;
130  type column_access_t is access all column_t;
131  pragma convention (c, column_access_t);
132
133  type table_flags_t is new c.unsigned;
134  TABLE_MULTI          : constant table_flags_t := 16#01#;
135  TABLE_MULTITOGGLE    : constant table_flags_t := 16#02#;
136  TABLE_REDRAW_CELLS   : constant table_flags_t := 16#04#;
137  TABLE_POLL           : constant table_flags_t := 16#08#;
138  TABLE_HIGHLIGHT_COLS : constant table_flags_t := 16#40#;
139  TABLE_MULTIMODE      : constant table_flags_t := TABLE_MULTI or TABLE_MULTITOGGLE;
140
141  type table_t is limited private;
142  type table_access_t is access all table_t;
143  pragma convention (c, table_access_t);
144
145  type sort_callback_t is access function
146    (elem1 : agar.core.types.void_ptr_t;
147     elem2 : agar.core.types.void_ptr_t) return c.int;
148  pragma convention (c, sort_callback_t);
149
150  -- API
151
152  function allocate
153    (parent : widget_access_t;
154     flags  : table_flags_t) return table_access_t;
155  pragma import (c, allocate, "AG_TableNew");
156
157  function allocate_polled
158    (parent   : widget_access_t;
159     flags    : table_flags_t;
160     callback : agar.core.event.callback_t) return table_access_t;
161  pragma inline (allocate_polled);
162
163  procedure size_hint
164    (table    : table_access_t;
165     width    : positive;
166     num_rows : positive);
167  pragma inline (size_hint);
168
169  procedure set_separator
170    (table     : table_access_t;
171     separator : string);
172  pragma inline (set_separator);
173
174  function set_popup
175    (table  : table_access_t;
176     row    : integer;
177     column : integer) return agar.gui.widget.menu.item_access_t;
178  pragma inline (set_popup);
179
180  procedure set_row_double_click_func
181    (table    : table_access_t;
182     callback : agar.core.event.callback_t);
183  pragma inline (set_row_double_click_func);
184
185  procedure set_column_double_click_func
186    (table    : table_access_t;
187     callback : agar.core.event.callback_t);
188  pragma inline (set_column_double_click_func);
189
190  -- table functions
191
192  procedure table_begin (table : table_access_t);
193  pragma import (c, table_begin, "AG_TableBegin");
194
195  procedure table_end (table : table_access_t);
196  pragma import (c, table_end, "AG_TableEnd");
197
198  -- column functions
199
200  function add_column
201    (table         : table_access_t;
202     name          : string;
203     size_spec     : string;
204     sort_callback : sort_callback_t) return boolean;
205  pragma inline (add_column);
206
207  procedure select_column
208    (table  : table_access_t;
209     column : integer);
210  pragma inline (select_column);
211
212  procedure deselect_column
213    (table  : table_access_t;
214     column : integer);
215  pragma inline (deselect_column);
216
217  procedure select_all_columns (table : table_access_t);
218  pragma import (c, select_all_columns, "AG_TableSelectAllCols");
219
220  procedure deselect_all_columns (table : table_access_t);
221  pragma import (c, deselect_all_columns, "AG_TableDeselectAllCols");
222
223  function column_selected
224    (table  : table_access_t;
225     column : integer) return boolean;
226  pragma inline (column_selected);
227
228  -- row functions
229
230-- TODO: how to get arguments to this function (format string)?
231--  function add_row
232--    (table         : table_access_t
233--     ...
234--  pragma inline (add_row);
235
236  procedure select_row
237    (table : table_access_t;
238     row   : natural);
239  pragma inline (select_row);
240
241  procedure deselect_row
242    (table : table_access_t;
243     row   : natural);
244  pragma inline (deselect_row);
245
246  procedure select_all_rows (table : table_access_t);
247  pragma import (c, select_all_rows, "AG_TableSelectAllCols");
248
249  procedure deselect_all_rows (table : table_access_t);
250  pragma import (c, deselect_all_rows, "AG_TableDeselectAllCols");
251
252  function row_selected
253    (table : table_access_t;
254     row   : natural) return boolean;
255  pragma inline (row_selected);
256
257  -- cell functions
258
259  procedure select_cell
260    (table  : table_access_t;
261     row    : natural;
262     column : natural);
263  pragma inline (select_cell);
264
265  procedure deselect_cell
266    (table  : table_access_t;
267     row    : natural;
268     column : natural);
269  pragma inline (deselect_cell);
270
271  function cell_selected
272    (table  : table_access_t;
273     row    : natural;
274     column : natural) return boolean;
275  pragma inline (cell_selected);
276
277  function compare_cells
278    (cell1 : cell_access_t;
279     cell2 : cell_access_t) return integer;
280  pragma inline (compare_cells);
281
282  --
283
284  function rows (table : table_access_t) return natural;
285  pragma inline (rows);
286
287  function columns (table : table_access_t) return natural;
288  pragma inline (columns);
289
290  --
291
292  function widget (table : table_access_t) return widget_access_t;
293  pragma inline (widget);
294
295private
296
297  type table_t is record
298    widget            : aliased widget_t;
299    flags             : table_flags_t;
300    selmode           : select_mode_t;
301    w_hint            : c.int;
302    h_hint            : c.int;
303
304    sep               : cs.chars_ptr;
305    h_row             : c.int;
306    h_col             : c.int;
307    w_col_min         : c.int;
308    w_col_default     : c.int;
309
310    x_offset          : c.int;
311    m_offset          : c.int;
312
313    cols              : column_access_t;
314    cells             : access cell_access_t;
315
316    n                 : c.unsigned;
317    m                 : c.unsigned;
318    m_vis             : c.unsigned;
319    n_resizing        : c.int;
320    v_bar             : agar.gui.widget.scrollbar.scrollbar_access_t;
321    h_bar             : agar.gui.widget.scrollbar.scrollbar_access_t;
322    poll_ev           : agar.core.event.event_access_t;
323    dbl_click_row_ev  : agar.core.event.event_access_t;
324    dbl_click_col_ev  : agar.core.event.event_access_t;
325    dbl_click_cell_ev : agar.core.event.event_access_t;
326    dbl_clicked_row   : c.int;
327    dbl_clicked_col   : c.int;
328    dbl_clicked_cell  : c.int;
329    wheel_ticks       : agar.core.types.uint32_t;
330    inc_to            : agar.core.timeout.timeout_t;
331    dec_to            : agar.core.timeout.timeout_t;
332    r                 : agar.gui.rect.rect_t;
333    w_total           : c.int;
334
335    popups            : popup_slist.head_t;
336  end record;
337  pragma convention (c, table_t);
338
339  type column_t is record
340    name     : column_name_t;
341    sort_fn  : access function (a, b : agar.core.types.void_ptr_t) return c.int;
342    flags    : column_flags_t;
343    selected : c.int;
344    w        : c.int;
345    w_pct    : c.int;
346    x        : c.int;
347    surface  : c.int;
348    pool     : cell_access_t;
349    mpool    : c.unsigned;
350  end record;
351  pragma convention (c, column_t);
352
353  type cell_t is record
354    cell_type : cell_type_t;
355    data      : cell_data_t;
356    fmt       : cell_format_t;
357    fn_su     : access function
358      (v : agar.core.types.void_ptr_t;
359       n : c.int;
360       m : c.int) return agar.gui.surface.surface_access_t;
361    fn_txt    : access procedure
362      (v : agar.core.types.void_ptr_t;
363       s : cs.chars_ptr;
364       n : c.size_t);
365    widget    : widget_access_t;
366    selected  : c.int;
367    surface   : c.int;
368  end record;
369  pragma convention (c, cell_t);
370
371  type popup_t is record
372    m      : c.int;
373    n      : c.int;
374    menu   : agar.gui.widget.menu.menu_access_t;
375    item   : agar.gui.widget.menu.item_access_t;
376    panel  : agar.gui.window.window_access_t;
377    popups : popup_slist.entry_t;
378  end record;
379  pragma convention (c, popup_t);
380
381end agar.gui.widget.table;
382