r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bclistbox.h
blob2cabbd2aa5d5db4d77186cc3d7bb806f567d16ce
1 #ifndef BCLISTBOX_H
2 #define BCLISTBOX_H
4 #include "bcdragwindow.inc"
5 #include "bclistboxitem.inc"
6 #include "bcpixmap.inc"
7 #include "bcpopuplistbox.inc"
8 #include "bcscrollbar.h"
9 #include "bcsubwindow.h"
10 #include "bctoggle.h"
11 #include "colors.h"
13 #define BCPOPUPLISTBOX_W 25
14 #define BCPOPUPLISTBOX_H 25
16 #define LISTBOX_UP 0
17 #define LISTBOX_HIGH 1
18 #define LISTBOX_DN 2
20 #define MIN_COLUMN_WIDTH 10
22 enum
24 BCLISTBOX_NO_OPERATION,
25 BCLISTBOX_DRAG_DIVISION, // Dragging column division
26 BCLISTBOX_SELECT, // Select item
27 BCLISTBOX_SELECT_RECT, // Selection rectangle
28 BCLISTBOX_WHEEL // Wheel mouse
32 class BC_ListBoxYScroll : public BC_ScrollBar
34 public:
35 BC_ListBoxYScroll(BC_ListBox *listbox,
36 int total_height,
37 int view_height,
38 int position);
39 ~BC_ListBoxYScroll();
40 int handle_event();
41 private:
42 BC_ListBox *listbox;
45 class BC_ListBoxXScroll : public BC_ScrollBar
47 public:
48 BC_ListBoxXScroll(BC_ListBox *listbox,
49 int total_width,
50 int view_width,
51 int position);
52 ~BC_ListBoxXScroll();
53 int handle_event();
54 private:
55 BC_ListBox *listbox;
58 class BC_ListBoxToggle : public BC_Toggle
60 public:
61 BC_ListBoxToggle(BC_ListBox *listbox, BC_ListBoxItem *item, int x, int y);
62 int handle_event();
63 void update(BC_ListBoxItem *item, int x, int y);
64 BC_ListBox *listbox;
65 BC_ListBoxItem *item;
69 class BC_ListBox : public BC_SubWindow
71 public:
72 BC_ListBox(int x,
73 int y,
74 int w,
75 int h,
76 int display_format, // Display text list or icons
77 ArrayList<BC_ListBoxItem*> *data = 0, // Each column has an ArrayList of BC_ListBoxItems.
78 char **column_titles = 0, // Titles for columns. Set to 0 for no titles
79 int *column_width = 0, // width of each column
80 int columns = 1, // Total columns. Only 1 in icon mode
81 int yposition = 0, // Pixel of top of window.
82 int popup = 0, // If this listbox is a popup window
83 int selection_mode = LISTBOX_SINGLE, // Select one item or multiple items
84 int icon_position = ICON_LEFT, // Position of icon relative to text of each item
85 int allow_drag = 0); // Allow user to drag icons around
86 virtual ~BC_ListBox();
88 friend class BC_PopupListBox;
90 int initialize();
92 // User event handler for new selections
93 virtual int selection_changed() { return 0; };
94 // User event handler for triggering a selection
95 virtual int handle_event() { return 0; };
96 // User event handler for a column resize
97 virtual int column_resize_event() { return 0; };
98 // Draw background on bg_surface
99 virtual void draw_background();
102 // Get the item in the given column which is the selection_number of the total
103 // selected rows. Returns 0 on failure.
104 BC_ListBoxItem* get_selection(int column, int selection_number);
105 BC_ListBoxItem* get_selection_recursive(ArrayList<BC_ListBoxItem*> *data,
106 int column,
107 int selection_number);
109 // Get the flat index of the item in the given column which is the selection_number
110 // of the total selected rows. Returns -1 on failure. The column
111 // argument is really useless because it only checks column 1 and returns the row
112 // number.
113 int get_selection_number(int column, int selection_number);
114 int get_selection_number_recursive(ArrayList<BC_ListBoxItem*> *data,
115 int column,
116 int selection_number,
117 int *counter = 0);
119 virtual int evaluate_query(int list_item, char *string);
120 void expand_item(BC_ListBoxItem *item, int expand);
121 // Collapse all items
122 static void collapse_recursive(ArrayList<BC_ListBoxItem*> *data);
123 // Convert recursive pointer to flat index.
124 // The pointer can be any item in the row corresponding to the index.
125 // Returns -1 if no item was found.
126 int item_to_index(ArrayList<BC_ListBoxItem*> *data,
127 BC_ListBoxItem *item,
128 int *counter = 0);
129 // Convert flat index and column to desired item.
130 BC_ListBoxItem* index_to_item(ArrayList<BC_ListBoxItem*> *data,
131 int number,
132 int column,
133 int *counter = 0);
134 // Get all items with recursion for text mode
135 static int get_total_items(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
138 virtual int button_press_event();
139 int button_release_event();
140 int cursor_enter_event();
141 int cursor_leave_event();
142 int cursor_motion_event();
143 virtual int drag_start_event();
144 virtual int drag_motion_event();
145 virtual int drag_stop_event();
146 int deactivate();
147 // After popping up a menu call this to interrupt the selection process
148 void deactivate_selection();
149 int activate();
150 virtual int keypress_event();
151 int translation_event();
152 int repeat_event(int64_t repeat_id);
153 BC_DragWindow* get_drag_popup();
155 // change the contents
156 int update(ArrayList<BC_ListBoxItem*> *data,
157 char **column_titles,
158 int *column_widths,
159 int columns,
160 int xposition = 0,
161 int yposition = 0,
162 int highlighted_number = -1, // Flat index of item cursor is over
163 int recalc_positions = 0, // set all autoplace flags to 1
164 int draw = 1);
165 void center_selection();
166 void update_format(int display_format, int redraw);
167 int get_format();
169 // Allow scrolling when dragging items
170 void set_drag_scroll(int value);
171 int set_selection_mode(int mode);
172 int set_yposition(int position, int draw_items = 1);
173 int get_yposition();
174 int set_xposition(int position);
175 int get_xposition();
176 // Return the flat index of the highlighted item
177 int get_highlighted_item();
178 int get_yscroll_x();
179 int get_yscroll_y();
180 int get_yscroll_height();
181 int get_xscroll_x();
182 int get_xscroll_y();
183 int get_xscroll_width();
184 int get_column_offset(int column);
185 int get_column_width(int column, int clamp_right = 0);
186 int get_w();
187 int get_h();
188 int get_display_mode();
189 void reset_query();
190 int reposition_window(int x, int y, int w = -1, int h = -1);
191 BC_Pixmap* get_bg_surface();
192 // Set all items for autoplacement with recursion into sublists
193 void set_autoplacement(ArrayList<BC_ListBoxItem*> *data,
194 int do_icon,
195 int do_text);
196 // Set selection status on all items with recursion
197 void set_all_selected(ArrayList<BC_ListBoxItem*> *data, int value);
198 // Set selection status of single row with recursion
199 // item_number - the flat index of the row to select
200 void set_selected(ArrayList<BC_ListBoxItem*> *data,
201 int item_number,
202 int value,
203 int *counter = 0);
205 // Called by keypress_event for cursor up. Selects previous and next visible
206 // row, skipping desired number of visible rows.
207 int select_previous(int skip,
208 BC_ListBoxItem *selected_item = 0,
209 int *counter = 0,
210 ArrayList<BC_ListBoxItem*> *data = 0,
211 int *got_it = 0,
212 int *got_second = 0);
213 int select_next(int skip,
214 BC_ListBoxItem *selected_item = 0,
215 int *counter = 0,
216 ArrayList<BC_ListBoxItem*> *data = 0,
217 int *got_it = 0,
218 int *got_second = 0);
220 // Called by cursor_motion_event to select different item if selection_number
221 // changed. Returns 1 if redraw is required.
222 int update_selection(ArrayList<BC_ListBoxItem*> *data,
223 int selection_number,
224 int *counter = 0);
226 static void dump(ArrayList<BC_ListBoxItem*> *data,
227 int columns,
228 int indent = 0);
231 private:
232 void delete_columns();
233 void set_columns(char **column_titles,
234 int *column_widths,
235 int columns);
236 // Draw the button for a popup listbox
237 int draw_face();
238 int draw_items();
239 int draw_border();
240 int draw_rectangle();
241 void draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
242 int column,
243 int indent,
244 int *current_toggle);
245 // Returns 1 if selection changed
246 int query_list();
247 void init_column_width();
248 void reset_cursor(int new_cursor);
249 // Fix boundary conditions after resize
250 void column_width_boundaries();
251 // Recursive function to get the first item selected in text mode.
252 // Returns > -1 only if it got it. Always increments *result
253 int get_first_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
254 // Recursive function to get the last item selected in text mode.
255 // Returns > -1 only if it got it. Always increments *result
256 int get_last_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
257 // Called by button_press_event and cursor_motion_event to expand the selection.
258 // Returns 1 if redraw is required.
259 int expand_selection(int button_press, int selection_number);
260 // Called by button_press_event and cursor_motion_event
261 // to select a range in text mode
262 void select_range(ArrayList<BC_ListBoxItem*> *data,
263 int start,
264 int end,
265 int *current = 0);
266 // Called by button_press_event to toggle the selection status of a single item.
267 // Called for both text and icon mode. In text mode it's recursive and fills
268 // the entire row with the first item's value. Returns 1 when the item was toggled.
269 int toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
270 int selection_number,
271 int *counter = 0);
272 // Set value of selected in all selected items to new value
273 void promote_selections(ArrayList<BC_ListBoxItem*> *data,
274 int old_value,
275 int new_value);
278 int test_divisions(int cursor_x, int cursor_y, int &new_cursor);
280 int get_title_h();
281 int calculate_item_coords();
282 void BC_ListBox::calculate_last_coords_recursive(
283 ArrayList<BC_ListBoxItem*> *data,
284 int *icon_x,
285 int *next_icon_x,
286 int *next_icon_y,
287 int *next_text_y,
288 int top_level);
289 void calculate_item_coords_recursive(
290 ArrayList<BC_ListBoxItem*> *data,
291 int *icon_x,
292 int *next_icon_x,
293 int *next_icon_y,
294 int *next_text_y,
295 int top_level);
297 int get_items_width();
298 int get_items_height(ArrayList<BC_ListBoxItem*> *data,
299 int columns,
300 int *result = 0);
301 int get_icon_w(BC_ListBoxItem *item);
302 int get_icon_h(BC_ListBoxItem *item);
303 int get_item_x(BC_ListBoxItem *item);
304 int get_item_y(BC_ListBoxItem *item);
305 int get_item_w(BC_ListBoxItem *item);
306 int get_item_h(BC_ListBoxItem *item);
307 int get_item_highlight(ArrayList<BC_ListBoxItem*> *data, int column, int item);
308 int get_item_color(ArrayList<BC_ListBoxItem*> *data, int column, int item);
309 int get_icon_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
310 int get_text_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
311 // Copy sections of the bg_surface to the gui
312 void clear_listbox(int x, int y, int w, int h);
313 void test_drag_scroll(int &redraw, int cursor_x, int cursor_y);
314 void move_vertical(int pixels);
315 void move_horizontal(int pixels);
316 void fix_positions();
318 int get_scrollbars();
319 void update_scrollbars();
321 // Flat index of the item the cursor is over.
322 // Points *item_return to the first item in the row
323 // if it's nonzero. Returns -1 if no item was found.
324 // expanded - 1 if items in this table should be tested for cursor coverage
325 int cursor_item(ArrayList<BC_ListBoxItem*> *data,
326 int cursor_x,
327 int cursor_y,
328 BC_ListBoxItem **item_return = 0,
329 int *counter = 0,
330 int expanded = 1);
331 // Select the items in the rectangle and deselect the items outside of it.
332 // Returns 1 if redraw is required.
333 int select_rectangle(ArrayList<BC_ListBoxItem*> *data,
334 int x1,
335 int y1,
336 int x2,
337 int y2);
338 // Convert the row of the item to a pointer.
339 BC_ListBoxItem* number_to_item(int row);
340 int reposition_item(ArrayList<BC_ListBoxItem*> *data,
341 int selection_number,
342 int x,
343 int y,
344 int *counter = 0);
345 // Move selected items to src_items
346 void move_selection(ArrayList<BC_ListBoxItem*> *dst,
347 ArrayList<BC_ListBoxItem*> *src);
348 // Put items from the src table into the data table starting at flat item number
349 // destination.
350 int put_selection(ArrayList<BC_ListBoxItem*> *data,
351 ArrayList<BC_ListBoxItem*> *src,
352 int destination,
353 int *counter = 0);
355 int center_selection(int selection,
356 ArrayList<BC_ListBoxItem*> *data = 0,
357 int *counter = 0);
359 // Array of one list of pointers for each column
360 ArrayList<BC_ListBoxItem*> *data;
361 // Mode
362 int popup;
363 // Dimensions for a popup if there is one
364 int popup_w, popup_h;
365 // pixel of top of display relative to top of list
366 int yposition;
367 // pixel of left display relative to first column
368 int xposition;
369 // dimensions of a row in the list
370 int row_height, row_ascent, row_descent;
371 // item cursor is over. May not exist in tables.
372 // Must be an index since this is needed to change the database.
373 int highlighted_item;
374 BC_ListBoxItem* highlighted_ptr;
375 // Item being dragged or last item selected in a double click operation
376 int selection_number;
377 // Used in button_press_event and button_release_event to detect double clicks
378 int selection_number1, selection_number2;
379 // When cursor is over the listbox or button.
380 int highlighted;
381 int selection_mode;
382 int display_format;
383 int icon_position;
384 // Scrollbars are created as needed
385 BC_ListBoxXScroll *xscrollbar;
386 BC_ListBoxYScroll *yscrollbar;
387 ArrayList<BC_ListBoxToggle*> expanders;
388 char query[BCTEXTLEN];
389 // Window containing the listbox
390 BC_WindowBase *gui;
391 // Size of the popup if there is one
392 char **column_titles;
393 int *column_width;
394 int default_column_width[1];
395 int columns;
396 int items_per_column;
397 int view_h, view_w;
398 int title_h;
399 int active;
400 // In BCLISTBOX_SELECT mode determines the value to set items to
401 int new_value;
402 int need_xscroll, need_yscroll;
403 int allow_drag;
404 int allow_drag_scroll;
405 // Selection range being extended
406 int selection_start, selection_end, selection_center;
407 // Background color of listbox
408 int list_background;
409 BC_Pixmap *bg_tile;
410 // Drag icon for text mode
411 BC_Pixmap *drag_icon;
412 // Popup button
413 BC_Pixmap *images[3];
414 // Background for drawing on
415 BC_Pixmap *bg_surface;
416 // Default background picon
417 BC_Pixmap *bg_pixmap;
418 int status;
419 int button_releases;
420 int current_cursor;
421 // Starting coordinates of rectangle
422 int rect_x1, rect_y1;
423 int rect_x2, rect_y2;
424 // Gradually being expanded into the state of the list box.
425 int current_operation;
428 // Division the cursor is operating on when resizing
429 int highlighted_division;
430 // Window for dragging
431 BC_DragWindow *drag_popup;
437 #endif