4 #include "bcdragwindow.inc"
5 #include "bclistboxitem.inc"
6 #include "bcpixmap.inc"
7 #include "bcscrollbar.h"
8 #include "bcsubwindow.h"
12 #define BCPOPUPLISTBOX_W 25
13 #define BCPOPUPLISTBOX_H 25
16 #define MIN_COLUMN_WIDTH 10
19 class BC_ListBoxYScroll
: public BC_ScrollBar
22 BC_ListBoxYScroll(BC_ListBox
*listbox
,
32 class BC_ListBoxXScroll
: public BC_ScrollBar
35 BC_ListBoxXScroll(BC_ListBox
*listbox
,
45 class BC_ListBoxToggle
48 BC_ListBoxToggle(BC_ListBox
*listbox
,
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
);
73 // Button pressed then moved out
79 class BC_ListBox
: public BC_SubWindow
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
;
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
115 virtual int sort_order_event() { return 0; };
117 virtual int move_column_event() { return 0; };
120 // Get the column movement
121 int get_from_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
,
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
135 int get_selection_number(int column
, int selection_number
);
136 int get_selection_number_recursive(ArrayList
<BC_ListBoxItem
*> *data
,
138 int selection_number
,
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
,
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
,
152 // Convert flat index and column to desired item.
153 BC_ListBoxItem
* index_to_item(ArrayList
<BC_ListBoxItem
*> *data
,
157 // Get all items with recursion for text mode
158 static int get_total_items(ArrayList
<BC_ListBoxItem
*> *data
,
159 int *result
/* = 0 */,
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();
173 // After popping up a menu call this to interrupt the selection process
174 void deactivate_selection();
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
,
188 int highlighted_number
= -1, // Flat index of item cursor is over
189 int recalc_positions
= 0, // set all autoplace flags to 1
191 void center_selection();
192 void update_format(int display_format
, int redraw
);
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);
209 int set_xposition(int position
);
211 // Return the flat index of the highlighted item
212 int get_highlighted_item();
215 int get_yscroll_height();
218 int get_xscroll_width();
219 int get_column_offset(int column
);
220 int get_column_width(int column
, int clamp_right
= 0);
223 int get_display_mode();
224 void set_justify(int value
);
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);
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
,
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
,
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,
261 ArrayList
<BC_ListBoxItem
*> *data
= 0,
263 int *got_second
= 0);
264 int select_next(int skip
,
265 BC_ListBoxItem
*selected_item
= 0,
267 ArrayList
<BC_ListBoxItem
*> *data
= 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
,
277 static void dump(ArrayList
<BC_ListBoxItem
*> *data
,
279 int indent
/* = 0 */,
286 // Draw the list items
287 int draw_items(int flash
);
298 void delete_columns();
299 void set_columns(char **column_titles
,
302 // Draw the button for a popup listbox
305 int draw_border(int flash
);
306 // Draw column titles
307 int draw_titles(int flash
);
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
,
317 int *current_toggle
);
318 // Returns 1 if selection changed
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
,
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
,
345 // Set value of selected in all selected items to new value
346 void promote_selections(ArrayList
<BC_ListBoxItem
*> *data
,
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();
356 int calculate_item_coords();
357 void calculate_last_coords_recursive(
358 ArrayList
<BC_ListBoxItem
*> *data
,
364 void calculate_item_coords_recursive(
365 ArrayList
<BC_ListBoxItem
*> *data
,
372 int get_items_width();
373 int get_items_height(ArrayList
<BC_ListBoxItem
*> *data
,
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
,
412 BC_ListBoxItem
**item_return
= 0,
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
,
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
,
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
434 int put_selection(ArrayList
<BC_ListBoxItem
*> *data
,
435 ArrayList
<BC_ListBoxItem
*> *src
,
439 int center_selection(int selection
,
440 ArrayList
<BC_ListBoxItem
*> *data
= 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
455 // pixel of left display relative to first column
457 // dimensions of a row in the list
458 int row_height
, row_ascent
, row_descent
;
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
477 // Size of the popup if there is one
478 char **column_titles
;
480 int default_column_width
[1];
487 // Maximum width of items. Calculated by get_items_width
490 // In BCLISTBOX_SELECT mode determines the value to set items to
492 int need_xscroll
, need_yscroll
;
493 // Move items during drag operation of text items.
496 int allow_drag_scroll
;
497 int allow_drag_column
;
498 // Background color of listbox
504 BC_Pixmap
*button_images
[4];
506 BC_Pixmap
*toggle_images
[5];
507 // Background for drawing on
508 BC_Pixmap
*bg_surface
;
509 // Background if 9 segment
511 // Drag icon for text mode
512 VFrame
*drag_icon_vframe
;
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];
522 BC_Pixmap
*column_sort_up
;
523 BC_Pixmap
*column_sort_dn
;
528 // Number of column to sort
530 // Sort order. -1 means no column is being sorted.
537 // State of the list box and button when the mouse button is pressed.
538 int current_operation
;
543 BUTTON_DOWN_SELECT
, // Pressed button and slid off to select items.
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
;
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
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
;
586 // Button release counter for double clicking
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
;