r419: various fixes, memory allocations, etc.
[cinelerra_cv/mob.git] / guicast / bclistbox.h
blob5f31376a57998ef04a9fb1246e50584c8a4cf031
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
17 #define MIN_COLUMN_WIDTH 10
20 class BC_ListBoxYScroll : public BC_ScrollBar
22 public:
23 BC_ListBoxYScroll(BC_ListBox *listbox,
24 int total_height,
25 int view_height,
26 int position);
27 ~BC_ListBoxYScroll();
28 int handle_event();
29 private:
30 BC_ListBox *listbox;
33 class BC_ListBoxXScroll : public BC_ScrollBar
35 public:
36 BC_ListBoxXScroll(BC_ListBox *listbox,
37 int total_width,
38 int view_width,
39 int position);
40 ~BC_ListBoxXScroll();
41 int handle_event();
42 private:
43 BC_ListBox *listbox;
46 class BC_ListBoxToggle
48 public:
49 BC_ListBoxToggle(BC_ListBox *listbox,
50 BC_ListBoxItem *item,
51 int x,
52 int y);
54 int cursor_motion_event(int *redraw_toggles);
55 int cursor_leave_event(int *redraw_toggles);
56 int button_press_event();
57 int button_release_event(int *redraw_toggles);
58 void update(BC_ListBoxItem *item, int x, int y, int flash);
59 void draw(int flash);
61 BC_ListBox *listbox;
62 BC_ListBoxItem *item;
63 int value;
64 int x;
65 int y;
66 int state;
67 enum
69 TOGGLE_UP,
70 TOGGLE_UPHI,
71 TOGGLE_CHECKED,
72 TOGGLE_DOWN,
73 TOGGLE_CHECKEDHI,
74 // Button pressed then moved out
75 TOGGLE_DOWN_EXIT
80 class BC_ListBox : public BC_SubWindow
82 public:
83 BC_ListBox(int x,
84 int y,
85 int w,
86 int h,
87 int display_format, // Display text list or icons
88 ArrayList<BC_ListBoxItem*> *data = 0, // Each column has an ArrayList of BC_ListBoxItems.
89 char **column_titles = 0, // Titles for columns. Set to 0 for no titles
90 int *column_width = 0, // width of each column
91 int columns = 1, // Total columns. Only 1 in icon mode
92 int yposition = 0, // Pixel of top of window.
93 int is_popup = 0, // If this listbox is a popup window with a button
94 int selection_mode = LISTBOX_SINGLE, // Select one item or multiple items
95 int icon_position = ICON_LEFT, // Position of icon relative to text of each item
96 int allow_drag = 0); // Allow user to drag icons around
97 virtual ~BC_ListBox();
99 friend class BC_PopupListBox;
100 friend class BC_ListBoxToggle;
102 int initialize();
104 // User event handler for new selections
105 virtual int selection_changed() { return 0; };
106 // User event handler for triggering a selection
107 virtual int handle_event() { return 0; };
108 // User event handler for a column resize
109 virtual int column_resize_event() { return 0; };
110 // Draw background on bg_surface
111 virtual void draw_background();
112 // Column sort order. This must return 1 or BC_ListBox will perform a default
113 // action.
114 virtual int sort_order_event() { return 0; };
115 // Column moved
116 virtual int move_column_event() { return 0; };
119 // Get the column movement
120 int get_from_column();
121 int get_to_column();
123 // Get the item in the given column which is the selection_number of the total
124 // selected rows. Returns 0 on failure.
125 BC_ListBoxItem* get_selection(int column, int selection_number);
126 BC_ListBoxItem* get_selection_recursive(ArrayList<BC_ListBoxItem*> *data,
127 int column,
128 int selection_number);
130 // Get the flat index of the item in the given column which is the selection_number
131 // of the total selected rows. Returns -1 on failure. The column
132 // argument is really useless because it only checks column 1 and returns the row
133 // number.
134 int get_selection_number(int column, int selection_number);
135 int get_selection_number_recursive(ArrayList<BC_ListBoxItem*> *data,
136 int column,
137 int selection_number,
138 int *counter = 0);
140 virtual int evaluate_query(int list_item, char *string);
141 void expand_item(BC_ListBoxItem *item, int expand);
142 // Collapse all items
143 static void collapse_recursive(ArrayList<BC_ListBoxItem*> *data,
144 int master_column);
145 // Convert recursive pointer to flat index.
146 // The pointer can be any item in the row corresponding to the index.
147 // Returns -1 if no item was found.
148 int item_to_index(ArrayList<BC_ListBoxItem*> *data,
149 BC_ListBoxItem *item,
150 int *counter = 0);
151 // Convert flat index and column to desired item.
152 BC_ListBoxItem* index_to_item(ArrayList<BC_ListBoxItem*> *data,
153 int number,
154 int column,
155 int *counter = 0);
156 // Get all items with recursion for text mode
157 static int get_total_items(ArrayList<BC_ListBoxItem*> *data,
158 int *result /* = 0 */,
159 int master_column);
162 int focus_out_event();
163 virtual int button_press_event();
164 int button_release_event();
165 int cursor_enter_event();
166 int cursor_leave_event();
167 int cursor_motion_event();
168 virtual int drag_start_event();
169 virtual int drag_motion_event();
170 virtual int drag_stop_event();
171 int deactivate();
172 // After popping up a menu call this to interrupt the selection process
173 void deactivate_selection();
174 int activate();
175 virtual int keypress_event();
176 int translation_event();
177 int repeat_event(int64_t duration);
178 BC_DragWindow* get_drag_popup();
180 // change the contents
181 int update(ArrayList<BC_ListBoxItem*> *data,
182 char **column_titles,
183 int *column_widths,
184 int columns,
185 int xposition = 0,
186 int yposition = 0,
187 int highlighted_number = -1, // Flat index of item cursor is over
188 int recalc_positions = 0, // set all autoplace flags to 1
189 int draw = 1);
190 void center_selection();
191 void update_format(int display_format, int redraw);
192 int get_format();
194 // Allow scrolling when dragging items
195 void set_drag_scroll(int value);
196 // Allow column repositioning
197 void set_allow_drag_column(int value);
198 // Allow automatic moving of objects after drag
199 void set_process_drag(int value);
201 // Set the column to use for icons and sublists.
202 void set_master_column(int value, int redraw);
203 // Set column to search
204 void set_search_column(int value);
205 int set_selection_mode(int mode);
206 int set_yposition(int position, int draw_items = 1);
207 int get_yposition();
208 int set_xposition(int position);
209 int get_xposition();
210 // Return the flat index of the highlighted item
211 int get_highlighted_item();
212 int get_yscroll_x();
213 int get_yscroll_y();
214 int get_yscroll_height();
215 int get_xscroll_x();
216 int get_xscroll_y();
217 int get_xscroll_width();
218 int get_column_offset(int column);
219 int get_column_width(int column, int clamp_right = 0);
220 int get_w();
221 int get_h();
222 int get_display_mode();
227 enum
229 SORT_ASCENDING,
230 SORT_DESCENDING
233 int get_sort_column();
234 void set_sort_column(int value, int redraw = 0);
235 int get_sort_order();
236 void set_sort_order(int value, int redraw = 0);
239 void reset_query();
240 int reposition_window(int x, int y, int w = -1, int h = -1);
241 BC_Pixmap* get_bg_surface();
242 // Set all items for autoplacement with recursion into sublists
243 void set_autoplacement(ArrayList<BC_ListBoxItem*> *data,
244 int do_icon,
245 int do_text);
246 // Set selection status on all items with recursion
247 void set_all_selected(ArrayList<BC_ListBoxItem*> *data, int value);
248 // Set selection status of single row with recursion
249 // item_number - the flat index of the row to select
250 void set_selected(ArrayList<BC_ListBoxItem*> *data,
251 int item_number,
252 int value,
253 int *counter = 0);
255 // Called by keypress_event for cursor up. Selects previous and next visible
256 // row, skipping desired number of visible rows.
257 int select_previous(int skip,
258 BC_ListBoxItem *selected_item = 0,
259 int *counter = 0,
260 ArrayList<BC_ListBoxItem*> *data = 0,
261 int *got_it = 0,
262 int *got_second = 0);
263 int select_next(int skip,
264 BC_ListBoxItem *selected_item = 0,
265 int *counter = 0,
266 ArrayList<BC_ListBoxItem*> *data = 0,
267 int *got_it = 0,
268 int *got_second = 0);
270 // Called by cursor_motion_event to select different item if selection_number
271 // changed. Returns 1 if redraw is required.
272 int update_selection(ArrayList<BC_ListBoxItem*> *data,
273 int selection_number,
274 int *counter = 0);
276 static void dump(ArrayList<BC_ListBoxItem*> *data,
277 int columns,
278 int indent /* = 0 */,
279 int master_column);
294 private:
295 void delete_columns();
296 void set_columns(char **column_titles,
297 int *column_widths,
298 int columns);
299 // Draw the button for a popup listbox
300 int draw_button();
301 // Draw the list items
302 int draw_items(int flash);
303 // Draw list border
304 int draw_border(int flash);
305 // Draw column titles
306 int draw_titles(int flash);
307 // Draw expanders
308 void draw_toggles(int flash);
309 // Draw selection rectangle
310 int draw_rectangle(int flash);
313 void draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
314 int column,
315 int indent,
316 int *current_toggle);
317 // Returns 1 if selection changed
318 int query_list();
319 void init_column_width();
320 void reset_cursor(int new_cursor);
321 // Fix boundary conditions after resize
322 void column_width_boundaries();
323 // Recursive function to get the first item selected in text mode.
324 // Returns > -1 only if it got it. Always increments *result
325 int get_first_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
326 // Recursive function to get the last item selected in text mode.
327 // Returns > -1 only if it got it. Always increments *result
328 int get_last_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
329 // Called by button_press_event and cursor_motion_event to expand the selection.
330 // Returns 1 if redraw is required.
331 int expand_selection(int button_press, int selection_number);
332 // Called by button_press_event and cursor_motion_event
333 // to select a range in text mode
334 void select_range(ArrayList<BC_ListBoxItem*> *data,
335 int start,
336 int end,
337 int *current = 0);
338 // Called by button_press_event to toggle the selection status of a single item.
339 // Called for both text and icon mode. In text mode it's recursive and fills
340 // the entire row with the first item's value. Returns 1 when the item was toggled.
341 int toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
342 int selection_number,
343 int *counter = 0);
344 // Set value of selected in all selected items to new value
345 void promote_selections(ArrayList<BC_ListBoxItem*> *data,
346 int old_value,
347 int new_value);
350 int test_column_divisions(int cursor_x, int cursor_y, int &new_cursor);
351 int test_column_titles(int cursor_x, int cursor_y);
352 int test_expanders();
354 int get_title_h();
355 int calculate_item_coords();
356 void BC_ListBox::calculate_last_coords_recursive(
357 ArrayList<BC_ListBoxItem*> *data,
358 int *icon_x,
359 int *next_icon_x,
360 int *next_icon_y,
361 int *next_text_y,
362 int top_level);
363 void calculate_item_coords_recursive(
364 ArrayList<BC_ListBoxItem*> *data,
365 int *icon_x,
366 int *next_icon_x,
367 int *next_icon_y,
368 int *next_text_y,
369 int top_level);
371 int get_items_width();
372 int get_items_height(ArrayList<BC_ListBoxItem*> *data,
373 int columns,
374 int *result = 0);
375 int get_icon_w(BC_ListBoxItem *item);
376 int get_icon_h(BC_ListBoxItem *item);
377 int get_item_x(BC_ListBoxItem *item);
378 int get_item_y(BC_ListBoxItem *item);
379 int get_item_w(BC_ListBoxItem *item);
380 int get_item_h(BC_ListBoxItem *item);
381 int get_item_highlight(ArrayList<BC_ListBoxItem*> *data, int column, int item);
382 int get_item_color(ArrayList<BC_ListBoxItem*> *data, int column, int item);
383 int get_icon_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
384 int get_text_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
385 // Copy sections of the bg_surface to the gui
386 void clear_listbox(int x, int y, int w, int h);
388 // Tests for cursor outside boundaries
389 int test_drag_scroll(int cursor_x, int cursor_y);
390 // Called by select_scroll_event, rectangle_scroll_event to execute for movement
391 int drag_scroll_event();
392 int select_scroll_event();
393 int rectangle_scroll_event();
396 void move_vertical(int pixels);
397 void move_horizontal(int pixels);
398 void clamp_positions();
400 int get_scrollbars();
401 void update_scrollbars();
403 // Flat index of the item the cursor is over.
404 // Points *item_return to the first item in the row or 0 if no item was found.
405 // if it's nonzero. Returns -1 if no item was found. Clamps the y coordinate
406 // only if the current operation is not SELECT, so scrolling is possible.
407 // expanded - 1 if items in this table should be tested for cursor coverage
408 int get_cursor_item(ArrayList<BC_ListBoxItem*> *data,
409 int cursor_x,
410 int cursor_y,
411 BC_ListBoxItem **item_return = 0,
412 int *counter = 0,
413 int expanded = 1);
414 // Select the items in the rectangle and deselect the items outside of it.
415 // Returns 1 if redraw is required.
416 int select_rectangle(ArrayList<BC_ListBoxItem*> *data,
417 int x1,
418 int y1,
419 int x2,
420 int y2);
421 // Convert the row of the item to a pointer.
422 BC_ListBoxItem* number_to_item(int row);
423 int reposition_item(ArrayList<BC_ListBoxItem*> *data,
424 int selection_number,
425 int x,
426 int y,
427 int *counter = 0);
428 // Move selected items to src_items
429 void move_selection(ArrayList<BC_ListBoxItem*> *dst,
430 ArrayList<BC_ListBoxItem*> *src);
431 // Put items from the src table into the data table starting at flat item number
432 // destination.
433 int put_selection(ArrayList<BC_ListBoxItem*> *data,
434 ArrayList<BC_ListBoxItem*> *src,
435 int destination,
436 int *counter = 0);
438 int center_selection(int selection,
439 ArrayList<BC_ListBoxItem*> *data = 0,
440 int *counter = 0);
442 // Array of one list of pointers for each column
443 ArrayList<BC_ListBoxItem*> *data;
446 // 1 if a button is used to make the listbox display
447 int is_popup; // popup
450 // Dimensions for a popup if there is one
451 int popup_w, popup_h;
452 // pixel of top of display relative to top of list
453 int yposition;
454 // pixel of left display relative to first column
455 int xposition;
456 // dimensions of a row in the list
457 int row_height, row_ascent, row_descent;
463 int selection_mode;
464 int display_format;
465 int icon_position;
466 // Scrollbars are created as needed
467 BC_ListBoxXScroll *xscrollbar;
468 BC_ListBoxYScroll *yscrollbar;
469 ArrayList<BC_ListBoxToggle*> expanders;
470 char query[BCTEXTLEN];
473 // Window containing the listbox
474 BC_WindowBase *gui;
476 // Size of the popup if there is one
477 char **column_titles;
478 int *column_width;
479 int default_column_width[1];
480 int columns;
481 int master_column;
482 int search_column;
484 int view_h, view_w;
485 int title_h;
486 // Maximum width of items. Calculated by get_items_width
487 int items_w;
488 int items_h;
489 // In BCLISTBOX_SELECT mode determines the value to set items to
490 int new_value;
491 int need_xscroll, need_yscroll;
492 // Move items during drag operation of text items.
493 int process_drag;
494 int allow_drag;
495 int allow_drag_scroll;
496 int allow_drag_column;
497 // Background color of listbox
498 int list_background;
502 // Popup button
503 BC_Pixmap *button_images[3];
504 // Expander
505 BC_Pixmap *toggle_images[5];
506 // Background for drawing on
507 BC_Pixmap *bg_surface;
508 BC_Pixmap *bg_tile;
509 // Drag icon for text mode
510 VFrame *drag_icon_vframe;
511 // Drag column icon
512 VFrame *drag_column_icon_vframe;
513 // Default background picon
514 BC_Pixmap *bg_pixmap;
517 // Column title backgrounds
518 BC_Pixmap *column_bg[3];
519 // Column sort order
520 BC_Pixmap *column_sort_up;
521 BC_Pixmap *column_sort_dn;
526 // Number of column to sort
527 int sort_column;
528 // Sort order. -1 means no column is being sorted.
529 int sort_order;
535 // State of the list box and button when the mouse button is pressed.
536 int current_operation;
538 enum
540 NO_OPERATION,
541 BUTTON_DOWN_SELECT, // Pressed button and slid off to select items.
542 BUTTON_DN,
543 DRAG_DIVISION, // Dragging column division
544 DRAG_COLUMN, // Dragging column
545 DRAG_ITEM, // Dragging item
546 SELECT, // Select item
547 SELECT_RECT, // Selection rectangle
548 WHEEL, // Wheel mouse
549 COLUMN_DN, // column title down
550 COLUMN_DRAG, // column title is being dragged
551 EXPAND_DN // Expander is down
555 // More state variables
556 int button_highlighted;
557 int list_highlighted;
558 // item cursor is over. May not exist in tables.
559 // Must be an index since this is needed to change the database.
560 int highlighted_item;
561 BC_ListBoxItem* highlighted_ptr;
562 // column title if the cursor is over a column title
563 int highlighted_title;
564 // Division the cursor is operating on when resizing
565 int highlighted_division;
566 // Column title being dragged
567 int dragged_title;
569 // Selection range being extended
570 int selection_start, selection_end, selection_center;
571 // Item being dragged or last item selected in a double click operation
572 int selection_number;
573 // Used in button_press_event and button_release_event to detect double clicks
574 int selection_number1, selection_number2;
579 int active;
581 // Button release counter for double clicking
582 int button_releases;
583 int current_cursor;
584 // Starting coordinates of rectangle
585 int rect_x1, rect_y1;
586 int rect_x2, rect_y2;
590 // Window for dragging
591 BC_DragWindow *drag_popup;
597 #endif