Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

bclistbox.h

Go to the documentation of this file.
00001 #ifndef BCLISTBOX_H
00002 #define BCLISTBOX_H
00003 
00004 #include "bcdragwindow.inc"
00005 #include "bclistboxitem.inc"
00006 #include "bcpixmap.inc"
00007 #include "bcscrollbar.h"
00008 #include "bcsubwindow.h"
00009 #include "bctoggle.h"
00010 #include "colors.h"
00011 
00012 #define BCPOPUPLISTBOX_W 25
00013 #define BCPOPUPLISTBOX_H 25
00014 
00015 
00016 #define MIN_COLUMN_WIDTH 10
00017 
00018 
00019 class BC_ListBoxYScroll : public BC_ScrollBar
00020 {
00021 public:
00022         BC_ListBoxYScroll(BC_ListBox *listbox, 
00023                           int total_height, 
00024                                           int view_height, 
00025                           int position);
00026         ~BC_ListBoxYScroll();
00027         int handle_event();
00028 private:
00029         BC_ListBox *listbox;
00030 };
00031 
00032 class BC_ListBoxXScroll : public BC_ScrollBar
00033 {
00034 public:
00035         BC_ListBoxXScroll(BC_ListBox *listbox, 
00036                           int total_width, 
00037                                           int view_width,
00038                           int position);
00039         ~BC_ListBoxXScroll();
00040         int handle_event();
00041 private:
00042         BC_ListBox *listbox;
00043 };
00044 
00045 class BC_ListBoxToggle
00046 {
00047 public:
00048         BC_ListBoxToggle(BC_ListBox *listbox, 
00049                 BC_ListBoxItem *item, 
00050                 int x, 
00051                 int y);
00052 
00053         int cursor_motion_event(int *redraw_toggles);
00054         int cursor_leave_event(int *redraw_toggles);
00055         int button_press_event();
00056         int button_release_event(int *redraw_toggles);
00057         void update(BC_ListBoxItem *item, int x, int y, int flash);
00058         void draw(int flash);
00059 
00060         BC_ListBox *listbox;
00061         BC_ListBoxItem *item;
00062         int value;
00063         int x;
00064         int y;
00065         int state;
00066         enum
00067         {
00068                 TOGGLE_UP,
00069                 TOGGLE_UPHI,
00070                 TOGGLE_CHECKED,
00071                 TOGGLE_DOWN,
00072                 TOGGLE_CHECKEDHI,
00073 // Button pressed then moved out
00074                 TOGGLE_DOWN_EXIT
00075         };
00076 };
00077 
00078 
00079 class BC_ListBox : public BC_SubWindow
00080 {
00081 public:
00082         BC_ListBox(int x, 
00083                 int y, 
00084                 int w, 
00085                 int h,
00086                 int display_format,                   // Display text list or icons
00087                 ArrayList<BC_ListBoxItem*> *data = 0, // Each column has an ArrayList of BC_ListBoxItems.
00088                 char **column_titles = 0,             // Titles for columns.  Set to 0 for no titles
00089                 int *column_width = 0,                // width of each column
00090                 int columns = 1,                      // Total columns.  Only 1 in icon mode
00091                 int yposition = 0,                    // Pixel of top of window.
00092                 int is_popup = 0,                     // If this listbox is a popup window with a button
00093                 int selection_mode = LISTBOX_SINGLE,  // Select one item or multiple items
00094                 int icon_position = ICON_LEFT,        // Position of icon relative to text of each item
00095                 int allow_drag = 0);                  // Allow user to drag icons around
00096         virtual ~BC_ListBox();
00097 
00098         friend class BC_ListBoxToggle;
00099 
00100         int initialize();
00101 
00102         int enable();
00103         int disable();
00104 
00105 // User event handler for new selections
00106         virtual int selection_changed() { return 0; };
00107 // User event handler for triggering a selection
00108         virtual int handle_event() { return 0; };
00109 // User event handler for a column resize
00110         virtual int column_resize_event() { return 0; };
00111 // Draw background on bg_surface
00112         virtual void draw_background();
00113 // Column sort order.  This must return 1 or BC_ListBox will perform a default
00114 // action.
00115         virtual int sort_order_event() { return 0; };
00116 // Column moved
00117         virtual int move_column_event() { return 0; };
00118 
00119 
00120 // Get the column movement
00121         int get_from_column();
00122         int get_to_column();
00123 
00124 // Get the item in the given column which is the selection_number of the total
00125 // selected rows.  Returns 0 on failure.
00126         BC_ListBoxItem* get_selection(int column, int selection_number);
00127         BC_ListBoxItem* get_selection_recursive(ArrayList<BC_ListBoxItem*> *data,
00128                 int column,
00129                 int selection_number);
00130 
00131 // Get the flat index of the item in the given column which is the selection_number
00132 // of the total selected rows.  Returns -1 on failure.  The column
00133 // argument is really useless because it only checks column 1 and returns the row
00134 // number.
00135         int get_selection_number(int column, int selection_number);
00136         int get_selection_number_recursive(ArrayList<BC_ListBoxItem*> *data,
00137                 int column,
00138                 int selection_number,
00139                 int *counter = 0);
00140 
00141         virtual int evaluate_query(int list_item, char *string);
00142         void expand_item(BC_ListBoxItem *item, int expand);
00143 // Collapse all items
00144         static void collapse_recursive(ArrayList<BC_ListBoxItem*> *data,
00145                 int master_column);
00146 // Convert recursive pointer to flat index.
00147 // The pointer can be any item in the row corresponding to the index.
00148 // Returns -1 if no item was found.
00149         int item_to_index(ArrayList<BC_ListBoxItem*> *data,
00150                 BC_ListBoxItem *item,
00151                 int *counter = 0);
00152 // Convert flat index and column to desired item.
00153         BC_ListBoxItem* index_to_item(ArrayList<BC_ListBoxItem*> *data,
00154                 int number,
00155                 int column,
00156                 int *counter = 0);
00157 // Get all items with recursion for text mode
00158         static int get_total_items(ArrayList<BC_ListBoxItem*> *data, 
00159                 int *result /* = 0 */,
00160                 int master_column);
00161 
00162 
00163         int focus_out_event();
00164         virtual int button_press_event();
00165         int button_release_event();
00166         int cursor_enter_event();
00167         int cursor_leave_event();
00168         int cursor_motion_event();
00169         virtual int drag_start_event();
00170         virtual int drag_motion_event();
00171         virtual int drag_stop_event();
00172         int deactivate();
00173 // After popping up a menu call this to interrupt the selection process
00174         void deactivate_selection();
00175         int activate();
00176         virtual int keypress_event();
00177         int translation_event();
00178         int repeat_event(int64_t duration);
00179         BC_DragWindow* get_drag_popup();
00180 
00181 // change the contents
00182         int update(ArrayList<BC_ListBoxItem*> *data,
00183                                                 char **column_titles,
00184                                                 int *column_widths,
00185                                                 int columns,
00186                                                 int xposition = 0,
00187                                                 int yposition = 0, 
00188                                                 int highlighted_number = -1,  // Flat index of item cursor is over
00189                                                 int recalc_positions = 0,     // set all autoplace flags to 1
00190                                                 int draw = 1);
00191         void center_selection();
00192         void update_format(int display_format, int redraw);
00193         int get_format();
00194 
00195 // Allow scrolling when dragging items
00196         void set_drag_scroll(int value);
00197 // Allow column repositioning
00198         void set_allow_drag_column(int value);
00199 // Allow automatic moving of objects after drag
00200         void set_process_drag(int value);
00201 
00202 // Set the column to use for icons and sublists.
00203         void set_master_column(int value, int redraw);
00204 // Set column to search
00205         void set_search_column(int value);
00206         int set_selection_mode(int mode);
00207         int set_yposition(int position, int draw_items = 1);
00208         int get_yposition();
00209         int set_xposition(int position);
00210         int get_xposition();
00211 // Return the flat index of the highlighted item
00212         int get_highlighted_item();
00213         int get_yscroll_x();
00214         int get_yscroll_y();
00215         int get_yscroll_height();
00216         int get_xscroll_x();
00217         int get_xscroll_y();
00218         int get_xscroll_width();
00219         int get_column_offset(int column);
00220         int get_column_width(int column, int clamp_right = 0);
00221         int get_w();
00222         int get_h();
00223         int get_display_mode();
00224         void set_justify(int value);
00225 
00226 
00227 
00228         enum
00229         {
00230                 SORT_ASCENDING,
00231                 SORT_DESCENDING
00232         };
00233 
00234         int get_sort_column();
00235         void set_sort_column(int value, int redraw = 0);
00236         int get_sort_order();
00237         void set_sort_order(int value, int redraw = 0);
00238 
00239 
00240         void reset_query();
00241         int reposition_window(int x, int y, int w = -1, int h = -1);
00242         BC_Pixmap* get_bg_surface();
00243 // Set all items for autoplacement with recursion into sublists
00244         void set_autoplacement(ArrayList<BC_ListBoxItem*> *data,
00245                 int do_icon, 
00246                 int do_text);
00247 // Set selection status on all items with recursion
00248         void set_all_selected(ArrayList<BC_ListBoxItem*> *data, int value);
00249 // Set selection status of single row with recursion
00250 // item_number - the flat index of the row to select
00251         void set_selected(ArrayList<BC_ListBoxItem*> *data, 
00252                 int item_number, 
00253                 int value,
00254                 int *counter = 0);
00255 
00256 // Called by keypress_event for cursor up.  Selects previous and next visible 
00257 // row, skipping desired number of visible rows.
00258         int select_previous(int skip, 
00259                 BC_ListBoxItem *selected_item = 0,
00260                 int *counter = 0,
00261                 ArrayList<BC_ListBoxItem*> *data = 0,
00262                 int *got_it = 0,
00263                 int *got_second = 0);
00264         int select_next(int skip, 
00265                 BC_ListBoxItem *selected_item = 0,
00266                 int *counter = 0,
00267                 ArrayList<BC_ListBoxItem*> *data = 0,
00268                 int *got_it = 0,
00269                 int *got_second = 0);
00270 
00271 // Called by cursor_motion_event to select different item if selection_number
00272 // changed.  Returns 1 if redraw is required.
00273         int update_selection(ArrayList<BC_ListBoxItem*> *data, 
00274                 int selection_number,
00275                 int *counter = 0);
00276 
00277         static void dump(ArrayList<BC_ListBoxItem*> *data, 
00278                 int columns, 
00279                 int indent /* = 0 */,
00280                 int master_column);
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 private:
00296         void delete_columns();
00297         void set_columns(char **column_titles, 
00298                 int *column_widths, 
00299                 int columns);
00300 // Draw the button for a popup listbox
00301         int draw_button();
00302 // Draw the list items
00303         int draw_items(int flash);
00304 // Draw list border
00305         int draw_border(int flash);
00306 // Draw column titles
00307         int draw_titles(int flash);
00308 // Draw expanders
00309         void draw_toggles(int flash);
00310 // Draw selection rectangle
00311         int draw_rectangle(int flash);
00312 
00313 
00314         void draw_text_recursive(ArrayList<BC_ListBoxItem*> *data, 
00315                 int column,
00316                 int indent,
00317                 int *current_toggle);
00318 // Returns 1 if selection changed
00319         int query_list();
00320         void init_column_width();
00321         void reset_cursor(int new_cursor);
00322 // Fix boundary conditions after resize
00323         void column_width_boundaries();
00324 // Recursive function to get the first item selected in text mode.
00325 // Returns > -1 only if it got it.  Always increments *result
00326         int get_first_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
00327 // Recursive function to get the last item selected in text mode.
00328 // Returns > -1 only if it got it.  Always increments *result
00329         int get_last_selection(ArrayList<BC_ListBoxItem*> *data, int *result = 0);
00330 // Called by button_press_event and cursor_motion_event to expand the selection.
00331 // Returns 1 if redraw is required.
00332         int expand_selection(int button_press, int selection_number);
00333 // Called by button_press_event and cursor_motion_event 
00334 // to select a range in text mode
00335         void select_range(ArrayList<BC_ListBoxItem*> *data,
00336                 int start,
00337                 int end,
00338                 int *current = 0);
00339 // Called by button_press_event to toggle the selection status of a single item.
00340 // Called for both text and icon mode.  In text mode it's recursive and fills
00341 // the entire row with the first item's value.  Returns 1 when the item was toggled.
00342         int toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
00343                 int selection_number,
00344                 int *counter = 0);
00345 // Set value of selected in all selected items to new value
00346         void promote_selections(ArrayList<BC_ListBoxItem*> *data,
00347                 int old_value,
00348                 int new_value);
00349 
00350 
00351         int test_column_divisions(int cursor_x, int cursor_y, int &new_cursor);
00352         int test_column_titles(int cursor_x, int cursor_y);
00353         int test_expanders();
00354 
00355         int get_title_h();
00356         int calculate_item_coords();
00357         void BC_ListBox::calculate_last_coords_recursive(
00358                 ArrayList<BC_ListBoxItem*> *data,
00359                 int *icon_x,
00360                 int *next_icon_x,
00361                 int *next_icon_y,
00362                 int *next_text_y,
00363                 int top_level);
00364         void calculate_item_coords_recursive(
00365                 ArrayList<BC_ListBoxItem*> *data,
00366                 int *icon_x,
00367                 int *next_icon_x,
00368                 int *next_icon_y,
00369                 int *next_text_y,
00370                 int top_level);
00371 
00372         int get_items_width();
00373         int get_items_height(ArrayList<BC_ListBoxItem*> *data, 
00374                 int columns, 
00375                 int *result = 0);
00376         int get_icon_w(BC_ListBoxItem *item);
00377         int get_icon_h(BC_ListBoxItem *item);
00378         int get_item_x(BC_ListBoxItem *item);
00379         int get_item_y(BC_ListBoxItem *item);
00380         int get_item_w(BC_ListBoxItem *item);
00381         int get_item_h(BC_ListBoxItem *item);
00382         int get_item_highlight(ArrayList<BC_ListBoxItem*> *data, int column, int item);
00383         int get_item_color(ArrayList<BC_ListBoxItem*> *data, int column, int item);
00384         int get_icon_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
00385         int get_text_mask(BC_ListBoxItem *item, int &x, int &y, int &w, int &h);
00386 // Copy sections of the bg_surface to the gui
00387         void clear_listbox(int x, int y, int w, int h);
00388 
00389 // Tests for cursor outside boundaries
00390         int test_drag_scroll(int cursor_x, int cursor_y);
00391 // Called by select_scroll_event, rectangle_scroll_event to execute for movement
00392         int drag_scroll_event();
00393         int select_scroll_event();
00394         int rectangle_scroll_event();
00395 
00396 
00397         void move_vertical(int pixels);
00398         void move_horizontal(int pixels);
00399         void clamp_positions();
00400 
00401         int get_scrollbars();
00402         void update_scrollbars();
00403 
00404 // Flat index of the item the cursor is over.  
00405 // Points *item_return to the first item in the row or 0 if no item was found.
00406 // if it's nonzero.  Returns -1 if no item was found.  Clamps the y coordinate
00407 // only if the current operation is not SELECT, so scrolling is possible.
00408 // expanded - 1 if items in this table should be tested for cursor coverage
00409         int get_cursor_item(ArrayList<BC_ListBoxItem*> *data,
00410                 int cursor_x, 
00411                 int cursor_y, 
00412                 BC_ListBoxItem **item_return = 0,
00413                 int *counter = 0,
00414                 int expanded = 1);
00415 // Select the items in the rectangle and deselect the items outside of it.
00416 // Returns 1 if redraw is required.
00417         int select_rectangle(ArrayList<BC_ListBoxItem*> *data,
00418                 int x1, 
00419                 int y1,
00420                 int x2, 
00421                 int y2);
00422 // Convert the row of the item to a pointer.
00423         BC_ListBoxItem* number_to_item(int row);
00424         int reposition_item(ArrayList<BC_ListBoxItem*> *data,
00425                 int selection_number,
00426                 int x,
00427                 int y,
00428                 int *counter = 0);
00429 // Move selected items to src_items
00430         void move_selection(ArrayList<BC_ListBoxItem*> *dst,
00431                 ArrayList<BC_ListBoxItem*> *src);
00432 // Put items from the src table into the data table starting at flat item number
00433 // destination.
00434         int put_selection(ArrayList<BC_ListBoxItem*> *data,
00435                 ArrayList<BC_ListBoxItem*> *src,
00436                 int destination,
00437                 int *counter = 0);
00438 
00439         int center_selection(int selection,
00440                 ArrayList<BC_ListBoxItem*> *data = 0,
00441                 int *counter = 0);
00442 
00443 // Array of one list of pointers for each column
00444         ArrayList<BC_ListBoxItem*> *data;
00445 
00446 
00447 // 1 if a button is used to make the listbox display
00448         int is_popup;      // popup
00449 
00450 
00451 // Dimensions for a popup if there is one
00452         int popup_w, popup_h;
00453 // pixel of top of display relative to top of list
00454         int yposition;
00455 // pixel of left display relative to first column
00456         int xposition;
00457 // dimensions of a row in the list
00458         int row_height, row_ascent, row_descent;
00459 
00460 
00461 
00462 
00463 
00464         int selection_mode;
00465         int display_format;
00466         int icon_position;
00467 // Scrollbars are created as needed
00468         BC_ListBoxXScroll *xscrollbar;
00469         BC_ListBoxYScroll *yscrollbar;
00470         ArrayList<BC_ListBoxToggle*> expanders;
00471         char query[BCTEXTLEN];
00472 
00473 
00474 // Window containing the listbox
00475         BC_WindowBase *gui;
00476 
00477 // Size of the popup if there is one
00478         char **column_titles;
00479         int *column_width;
00480         int default_column_width[1];
00481         int columns;
00482         int master_column;
00483         int search_column;
00484         
00485         int view_h, view_w;
00486         int title_h;
00487 // Maximum width of items.  Calculated by get_items_width
00488         int items_w;
00489         int items_h;
00490 // In BCLISTBOX_SELECT mode determines the value to set items to
00491         int new_value;
00492         int need_xscroll, need_yscroll;
00493 // Move items during drag operation of text items.
00494         int process_drag;
00495         int allow_drag;
00496         int allow_drag_scroll;
00497         int allow_drag_column;
00498 // Background color of listbox
00499         int list_background;
00500 
00501 
00502 
00503 // Popup button
00504         BC_Pixmap *button_images[4];
00505 // Expander
00506         BC_Pixmap *toggle_images[5];
00507 // Background for drawing on
00508         BC_Pixmap *bg_surface;
00509 // Background if 9 segment
00510         BC_Pixmap *bg_tile;
00511 // Drag icon for text mode
00512         VFrame *drag_icon_vframe;
00513 // Drag column icon
00514         VFrame *drag_column_icon_vframe;
00515 // Background picon to be drawn in the upper right
00516         BC_Pixmap *bg_pixmap;
00517 
00518 
00519 // Column title backgrounds
00520         BC_Pixmap *column_bg[3];
00521 // Column sort order
00522         BC_Pixmap *column_sort_up;
00523         BC_Pixmap *column_sort_dn;
00524 
00525 
00526 
00527 
00528 // Number of column to sort
00529         int sort_column;
00530 // Sort order.  -1 means no column is being sorted.
00531         int sort_order;
00532 
00533 
00534 
00535 
00536 
00537 // State of the list box and button when the mouse button is pressed.
00538         int current_operation;
00539 
00540         enum
00541         {
00542                 NO_OPERATION,
00543                 BUTTON_DOWN_SELECT, // Pressed button and slid off to select items.
00544                 BUTTON_DN,
00545                 DRAG_DIVISION,    // Dragging column division
00546                 DRAG_COLUMN,      // Dragging column
00547                 DRAG_ITEM,        // Dragging item
00548                 SELECT,                   // Select item
00549                 SELECT_RECT,      // Selection rectangle
00550                 WHEEL,                    // Wheel mouse
00551                 COLUMN_DN,                // column title down
00552                 COLUMN_DRAG,      // column title is being dragged
00553                 EXPAND_DN         // Expander is down
00554         };
00555 
00556 
00557 // More state variables
00558         int button_highlighted;
00559 
00560         int disabled;
00561 
00562         int list_highlighted;
00563 // item cursor is over.  May not exist in tables.
00564 // Must be an index since this is needed to change the database.
00565         int highlighted_item;
00566         BC_ListBoxItem* highlighted_ptr;
00567 // column title if the cursor is over a column title
00568         int highlighted_title;
00569 // Division the cursor is operating on when resizing
00570         int highlighted_division;
00571 // Column title being dragged
00572         int dragged_title;
00573 
00574 // Selection range being extended
00575         int selection_start, selection_end, selection_center;
00576 // Item being dragged or last item selected in a double click operation
00577         int selection_number;
00578 // Used in button_press_event and button_release_event to detect double clicks
00579         int selection_number1, selection_number2;
00580 
00581 
00582 
00583 
00584         int active;
00585 
00586 // Button release counter for double clicking
00587         int button_releases;
00588         int current_cursor;
00589 // Starting coordinates of rectangle
00590         int rect_x1, rect_y1;
00591         int rect_x2, rect_y2;
00592 
00593 
00594 
00595 // Window for dragging
00596         BC_DragWindow *drag_popup;
00597         int justify;
00598 };
00599 
00600 
00601 
00602 
00603 #endif

Generated on Sun Jan 8 13:26:32 2006 for Guicast-svn by  doxygen 1.4.4