1with agar.core.event;
2with agar.core.event_types;
3with agar.core.tail_queue;
4with agar.core.timeout;
5with agar.core.types;
6with agar.gui.surface;
7with agar.gui.widget.label;
8with agar.gui.widget.menu;
9with agar.gui.widget.scrollbar;
10with agar.gui.window;
11
12package agar.gui.widget.tlist is
13
14  use type c.unsigned;
15
16  type popup_t is limited private;
17  type popup_access_t is access all popup_t;
18  pragma convention (c, popup_access_t);
19
20  type item_t is limited private;
21  type item_access_t is access all item_t;
22  pragma convention (c, item_access_t);
23
24  type tlist_t is limited private;
25  type tlist_access_t is access all tlist_t;
26  pragma convention (c, tlist_access_t);
27
28  package popup_tail_queue is new agar.core.tail_queue
29    (entry_type => popup_access_t);
30  package item_tail_queue is new agar.core.tail_queue
31    (entry_type => item_access_t);
32  package tlist_tail_queue is new agar.core.tail_queue
33    (entry_type => tlist_access_t);
34
35  type flags_t is new c.unsigned;
36  TLIST_MULTI       : constant flags_t := 16#001#;
37  TLIST_MULTITOGGLE : constant flags_t := 16#002#;
38  TLIST_POLL        : constant flags_t := 16#004#;
39  TLIST_TREE        : constant flags_t := 16#010#;
40  TLIST_HFILL       : constant flags_t := 16#020#;
41  TLIST_VFILL       : constant flags_t := 16#040#;
42  TLIST_NOSELSTATE  : constant flags_t := 16#100#;
43  TLIST_EXPAND      : constant flags_t := TLIST_HFILL or TLIST_VFILL;
44
45  -- API
46
47  function allocate
48    (parent : widget_access_t;
49     flags  : flags_t) return tlist_access_t;
50  pragma import (c, allocate, "AG_TlistNew");
51
52  function allocate_polled
53    (parent   : widget_access_t;
54     flags    : flags_t;
55     callback : agar.core.event.callback_t) return tlist_access_t;
56  pragma import (c, allocate_polled, "AG_TlistNewPolled");
57
58  procedure set_item_height
59    (tlist  : tlist_access_t;
60     height : natural);
61  pragma inline (set_item_height);
62
63  procedure set_icon
64    (tlist : tlist_access_t;
65     item  : item_access_t;
66     icon  : agar.gui.surface.surface_access_t);
67  pragma import (c, set_icon, "AG_TlistSetIcon");
68
69  procedure size_hint
70    (tlist     : tlist_access_t;
71     text      : string;
72     num_items : natural);
73  pragma inline (size_hint);
74
75  procedure size_hint_pixels
76    (tlist     : tlist_access_t;
77     width     : natural;
78     num_items : natural);
79  pragma inline (size_hint_pixels);
80
81  procedure size_hint_largest
82    (tlist     : tlist_access_t;
83     num_items : natural);
84  pragma inline (size_hint_largest);
85
86  procedure set_double_click_callback
87    (tlist     : tlist_access_t;
88     callback  : agar.core.event.callback_t);
89  pragma inline (set_double_click_callback);
90
91  procedure set_changed_callback
92    (tlist     : tlist_access_t;
93     callback  : agar.core.event.callback_t);
94  pragma inline (set_changed_callback);
95
96  -- manipulating items
97
98  procedure delete
99    (tlist : tlist_access_t;
100     item  : item_access_t);
101  pragma import (c, delete, "AG_TlistDel");
102
103  procedure list_begin (tlist : tlist_access_t);
104  pragma import (c, list_begin, "AG_TlistClear");
105
106  procedure list_end (tlist : tlist_access_t);
107  pragma import (c, list_end, "AG_TlistRestore");
108
109  procedure list_select
110    (tlist : tlist_access_t;
111     item  : item_access_t);
112  pragma import (c, list_select, "AG_TlistSelect");
113
114  procedure list_select_all (tlist : tlist_access_t);
115  pragma import (c, list_select_all, "AG_TlistSelectAll");
116
117  procedure list_deselect
118    (tlist : tlist_access_t;
119     item  : item_access_t);
120  pragma import (c, list_deselect, "AG_TlistDeselect");
121
122  procedure list_deselect_all (tlist : tlist_access_t);
123  pragma import (c, list_deselect_all, "AG_TlistDeselectAll");
124
125  function list_select_pointer
126    (tlist   : tlist_access_t;
127     pointer : agar.core.types.void_ptr_t) return item_access_t;
128  pragma import (c, list_select_pointer, "AG_TlistSelectPtr");
129
130  function list_select_text
131    (tlist : tlist_access_t;
132     text  : string) return item_access_t;
133  pragma inline (list_select_text);
134
135  function list_find_by_index
136    (tlist : tlist_access_t;
137     index : integer) return item_access_t;
138  pragma inline (list_find_by_index);
139
140  function list_selected_item (tlist : tlist_access_t) return item_access_t;
141  pragma import (c, list_selected_item, "AG_TlistSelectedItem");
142
143  function list_selected_item_pointer (tlist : tlist_access_t) return agar.core.types.void_ptr_t;
144  pragma import (c, list_selected_item_pointer, "AG_TlistSelectedItemPtr");
145
146  function list_first (tlist : tlist_access_t) return item_access_t;
147  pragma import (c, list_first, "AG_TlistFirstItem");
148
149  function list_last (tlist : tlist_access_t) return item_access_t;
150  pragma import (c, list_last, "AG_TlistLastItem");
151
152  -- popup menus
153
154  function set_popup_callback
155    (tlist    : tlist_access_t;
156     callback : agar.core.event.callback_t) return agar.gui.widget.menu.item_access_t;
157  pragma inline (set_popup_callback);
158
159  function set_popup
160    (tlist    : tlist_access_t;
161     category : string) return agar.gui.widget.menu.item_access_t;
162  pragma inline (set_popup);
163
164  --
165
166  function widget (tlist : tlist_access_t) return widget_access_t;
167  pragma inline (widget);
168
169private
170
171  type popup_t is record
172    class  : cs.chars_ptr;
173    menu   : agar.gui.widget.menu.menu_access_t;
174    item   : agar.gui.widget.menu.item_access_t;
175    panel  : agar.gui.window.window_access_t;
176    popups : popup_tail_queue.entry_t;
177  end record;
178  pragma convention (c, popup_t);
179
180  type item_label_t is array (1 .. agar.gui.widget.label.max) of aliased c.char;
181  pragma convention (c, item_label_t);
182
183  type item_argv_t is array (1 .. 8) of aliased agar.core.event_types.arg_t;
184  pragma convention (c, item_argv_t);
185
186  type item_t is record
187    selected    : c.int;
188    icon_source : agar.gui.surface.surface_access_t;
189    icon        : c.int;
190    ptr         : agar.core.types.void_ptr_t;
191    category    : cs.chars_ptr;
192    text        : item_label_t;
193    label       : c.int;
194    argv        : item_argv_t;
195    argc        : c.int;
196    depth       : agar.core.types.uint8_t;
197    flags       : agar.core.types.uint8_t;
198    items       : item_tail_queue.entry_t;
199    selitems    : item_tail_queue.entry_t;
200  end record;
201  pragma convention (c, item_t);
202
203  type tlist_t is record
204    widget          : aliased widget_t;
205    flags           : flags_t;
206
207    selected        : agar.core.types.void_ptr_t;
208    hint_width      : c.int;
209    hint_height     : c.int;
210    space           : c.int;
211
212    item_height     : c.int;
213    icon_width      : c.int;
214    double_clicked  : agar.core.types.void_ptr_t;
215    items           : item_tail_queue.head_t;
216    selitems        : item_tail_queue.head_t;
217    num_items       : c.int;
218    visible_items   : c.int;
219    sbar            : agar.gui.widget.scrollbar.scrollbar_access_t;
220    popups          : item_tail_queue.head_t;
221    compare_func    : access function (a, b : item_access_t) return c.int;
222    popup_ev        : access agar.core.event.event_t;
223    changed_ev      : access agar.core.event.event_t;
224    double_click_ev : access agar.core.event.event_t;
225    inc_to          : agar.core.timeout.timeout_t;
226    dec_to          : agar.core.timeout.timeout_t;
227    wheel_ticks     : agar.core.types.uint32_t;
228    row_width       : c.int;
229    r               : agar.gui.rect.rect_t;
230  end record;
231  pragma convention (c, tlist_t);
232
233end agar.gui.widget.tlist;
234