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