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 LISTBOX_HIGH 1
20 #define MIN_COLUMN_WIDTH 10
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
35 BC_ListBoxYScroll(BC_ListBox
*listbox
,
45 class BC_ListBoxXScroll
: public BC_ScrollBar
48 BC_ListBoxXScroll(BC_ListBox
*listbox
,
58 class BC_ListBoxToggle
: public BC_Toggle
61 BC_ListBoxToggle(BC_ListBox
*listbox
, BC_ListBoxItem
*item
, int x
, int y
);
63 void update(BC_ListBoxItem
*item
, int x
, int y
);
69 class BC_ListBox
: public BC_SubWindow
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
;
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
,
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
113 int get_selection_number(int column
, int selection_number
);
114 int get_selection_number_recursive(ArrayList
<BC_ListBoxItem
*> *data
,
116 int selection_number
,
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
,
129 // Convert flat index and column to desired item.
130 BC_ListBoxItem
* index_to_item(ArrayList
<BC_ListBoxItem
*> *data
,
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();
147 // After popping up a menu call this to interrupt the selection process
148 void deactivate_selection();
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
,
162 int highlighted_number
= -1, // Flat index of item cursor is over
163 int recalc_positions
= 0, // set all autoplace flags to 1
165 void center_selection();
166 void update_format(int display_format
, int redraw
);
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);
174 int set_xposition(int position
);
176 // Return the flat index of the highlighted item
177 int get_highlighted_item();
180 int get_yscroll_height();
183 int get_xscroll_width();
184 int get_column_offset(int column
);
185 int get_column_width(int column
, int clamp_right
= 0);
188 int get_display_mode();
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
,
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
,
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,
210 ArrayList
<BC_ListBoxItem
*> *data
= 0,
212 int *got_second
= 0);
213 int select_next(int skip
,
214 BC_ListBoxItem
*selected_item
= 0,
216 ArrayList
<BC_ListBoxItem
*> *data
= 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
,
226 static void dump(ArrayList
<BC_ListBoxItem
*> *data
,
232 void delete_columns();
233 void set_columns(char **column_titles
,
236 // Draw the button for a popup listbox
240 int draw_rectangle();
241 void draw_text_recursive(ArrayList
<BC_ListBoxItem
*> *data
,
244 int *current_toggle
);
245 // Returns 1 if selection changed
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
,
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
,
272 // Set value of selected in all selected items to new value
273 void promote_selections(ArrayList
<BC_ListBoxItem
*> *data
,
278 int test_divisions(int cursor_x
, int cursor_y
, int &new_cursor
);
281 int calculate_item_coords();
282 void BC_ListBox::calculate_last_coords_recursive(
283 ArrayList
<BC_ListBoxItem
*> *data
,
289 void calculate_item_coords_recursive(
290 ArrayList
<BC_ListBoxItem
*> *data
,
297 int get_items_width();
298 int get_items_height(ArrayList
<BC_ListBoxItem
*> *data
,
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
,
328 BC_ListBoxItem
**item_return
= 0,
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
,
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
,
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
350 int put_selection(ArrayList
<BC_ListBoxItem
*> *data
,
351 ArrayList
<BC_ListBoxItem
*> *src
,
355 int center_selection(int selection
,
356 ArrayList
<BC_ListBoxItem
*> *data
= 0,
359 // Array of one list of pointers for each column
360 ArrayList
<BC_ListBoxItem
*> *data
;
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
367 // pixel of left display relative to first column
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.
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
391 // Size of the popup if there is one
392 char **column_titles
;
394 int default_column_width
[1];
396 int items_per_column
;
400 // In BCLISTBOX_SELECT mode determines the value to set items to
402 int need_xscroll
, need_yscroll
;
404 int allow_drag_scroll
;
405 // Selection range being extended
406 int selection_start
, selection_end
, selection_center
;
407 // Background color of listbox
410 // Drag icon for text mode
411 BC_Pixmap
*drag_icon
;
413 BC_Pixmap
*images
[3];
414 // Background for drawing on
415 BC_Pixmap
*bg_surface
;
416 // Default background picon
417 BC_Pixmap
*bg_pixmap
;
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
;