4 #include "bcdragwindow.inc"
5 #include "bclistboxitem.inc"
6 #include "bcpixmap.inc"
7 #include "bcpopuplistbox.inc"
8 #include "bcscrollbar.h"
9 #include "bcsubwindow.h"
13 #define BCPOPUPLISTBOX_W 25
14 #define BCPOPUPLISTBOX_H 25
17 #define MIN_COLUMN_WIDTH 10
20 class BC_ListBoxYScroll
: public BC_ScrollBar
23 BC_ListBoxYScroll(BC_ListBox
*listbox
,
33 class BC_ListBoxXScroll
: public BC_ScrollBar
36 BC_ListBoxXScroll(BC_ListBox
*listbox
,
46 class BC_ListBoxToggle
49 BC_ListBoxToggle(BC_ListBox
*listbox
,
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
);
74 // Button pressed then moved out
80 class BC_ListBox
: public BC_SubWindow
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
;
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
114 virtual int sort_order_event() { return 0; };
116 virtual int move_column_event() { return 0; };
119 // Get the column movement
120 int get_from_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
,
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
134 int get_selection_number(int column
, int selection_number
);
135 int get_selection_number_recursive(ArrayList
<BC_ListBoxItem
*> *data
,
137 int selection_number
,
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
,
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
,
151 // Convert flat index and column to desired item.
152 BC_ListBoxItem
* index_to_item(ArrayList
<BC_ListBoxItem
*> *data
,
156 // Get all items with recursion for text mode
157 static int get_total_items(ArrayList
<BC_ListBoxItem
*> *data
,
158 int *result
/* = 0 */,
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();
172 // After popping up a menu call this to interrupt the selection process
173 void deactivate_selection();
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
,
187 int highlighted_number
= -1, // Flat index of item cursor is over
188 int recalc_positions
= 0, // set all autoplace flags to 1
190 void center_selection();
191 void update_format(int display_format
, int redraw
);
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);
208 int set_xposition(int position
);
210 // Return the flat index of the highlighted item
211 int get_highlighted_item();
214 int get_yscroll_height();
217 int get_xscroll_width();
218 int get_column_offset(int column
);
219 int get_column_width(int column
, int clamp_right
= 0);
222 int get_display_mode();
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);
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
,
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
,
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,
260 ArrayList
<BC_ListBoxItem
*> *data
= 0,
262 int *got_second
= 0);
263 int select_next(int skip
,
264 BC_ListBoxItem
*selected_item
= 0,
266 ArrayList
<BC_ListBoxItem
*> *data
= 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
,
276 static void dump(ArrayList
<BC_ListBoxItem
*> *data
,
278 int indent
/* = 0 */,
295 void delete_columns();
296 void set_columns(char **column_titles
,
299 // Draw the button for a popup listbox
301 // Draw the list items
302 int draw_items(int flash
);
304 int draw_border(int flash
);
305 // Draw column titles
306 int draw_titles(int flash
);
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
,
316 int *current_toggle
);
317 // Returns 1 if selection changed
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
,
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
,
344 // Set value of selected in all selected items to new value
345 void promote_selections(ArrayList
<BC_ListBoxItem
*> *data
,
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();
355 int calculate_item_coords();
356 void BC_ListBox::calculate_last_coords_recursive(
357 ArrayList
<BC_ListBoxItem
*> *data
,
363 void calculate_item_coords_recursive(
364 ArrayList
<BC_ListBoxItem
*> *data
,
371 int get_items_width();
372 int get_items_height(ArrayList
<BC_ListBoxItem
*> *data
,
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
,
411 BC_ListBoxItem
**item_return
= 0,
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
,
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
,
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
433 int put_selection(ArrayList
<BC_ListBoxItem
*> *data
,
434 ArrayList
<BC_ListBoxItem
*> *src
,
438 int center_selection(int selection
,
439 ArrayList
<BC_ListBoxItem
*> *data
= 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
454 // pixel of left display relative to first column
456 // dimensions of a row in the list
457 int row_height
, row_ascent
, row_descent
;
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
476 // Size of the popup if there is one
477 char **column_titles
;
479 int default_column_width
[1];
486 // Maximum width of items. Calculated by get_items_width
489 // In BCLISTBOX_SELECT mode determines the value to set items to
491 int need_xscroll
, need_yscroll
;
492 // Move items during drag operation of text items.
495 int allow_drag_scroll
;
496 int allow_drag_column
;
497 // Background color of listbox
503 BC_Pixmap
*button_images
[3];
505 BC_Pixmap
*toggle_images
[5];
506 // Background for drawing on
507 BC_Pixmap
*bg_surface
;
509 // Drag icon for text mode
510 VFrame
*drag_icon_vframe
;
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];
520 BC_Pixmap
*column_sort_up
;
521 BC_Pixmap
*column_sort_dn
;
526 // Number of column to sort
528 // Sort order. -1 means no column is being sorted.
535 // State of the list box and button when the mouse button is pressed.
536 int current_operation
;
541 BUTTON_DOWN_SELECT
, // Pressed button and slid off to select items.
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
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
;
581 // Button release counter for double clicking
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
;