titler rework, some code cleanup and fixes
[goodguy/history.git] / cinelerra-5.1 / guicast / bclistbox.C
index b48847ba14971e5315479764a856a48573531008..76f8fde1eee13f042d592db2f3f2793977d4bda1 100644 (file)
@@ -389,13 +389,9 @@ BC_ListBox::BC_ListBox(int x,
        popup_w = w;
        popup_h = h;
 
-       for(int i = 0; i < 3; i++)
-       {
-               button_images[i] = 0;
-               column_bg[i] = 0;
-       }
-       for(int i = 0; i < 5; i++)
-               toggle_images[i] = 0;
+       for(int i = 0; i < 3; i++) column_bg[i] = 0;
+       for(int i = 0; i < 4; i++) button_images[i] = 0;
+       for(int i = 0; i < 5; i++) toggle_images[i] = 0;
 
        column_sort_up = 0;
        column_sort_dn = 0;
@@ -447,13 +443,9 @@ BC_ListBox::~BC_ListBox()
        if(bg_pixmap) delete bg_pixmap;
        if(xscrollbar) delete xscrollbar;
        if(yscrollbar) delete yscrollbar;
-       for(int i = 0; i < 3; i++)
-       {
-               if(button_images[i]) delete button_images[i];
-               if(column_bg[i]) delete column_bg[i];
-       }
-       for(int i = 0; i < 5; i++)
-               if(toggle_images[i]) delete toggle_images[i];
+       for(int i = 0; i < 3; i++) delete column_bg[i];
+       for(int i = 0; i < 4; i++) delete button_images[i];
+       for(int i = 0; i < 5; i++) delete toggle_images[i];
        if(column_sort_up) delete column_sort_up;
        if(column_sort_dn) delete column_sort_dn;
 
@@ -550,7 +542,7 @@ int BC_ListBox::initialize()
        {
                if(use_button)
                {
-                       for( volatile int i = 0; i < 4; ++i ) // volatile due to cplr bug
+                       for( int i = 0; i < 4; ++i )
                        {
                                button_images[i] = new BC_Pixmap(parent_window,
                                        BC_WindowBase::get_resources()->listbox_button[i],
@@ -740,9 +732,10 @@ void BC_ListBox::calculate_last_coords_recursive(
 // Lowest right icon coordinate.
                                current_icon_x = item->icon_x;
                                if(current_icon_x > *icon_x) *icon_x = current_icon_x;
-                               if(current_icon_x + get_item_w(item) > *next_icon_x)
+                               if(current_icon_x + get_item_w(item) > *next_icon_x) {
                                        *next_icon_x = current_icon_x + get_item_w(item);
-
+                                       *next_icon_y = 0;
+                               }
                                current_icon_y = item->icon_y + get_item_h(item);
                                if(current_icon_y > *next_icon_y)
                                        *next_icon_y = current_icon_y;
@@ -1137,8 +1130,8 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data,
                int x, y, w, h;
                BC_ListBoxItem *item = data[master_column].values[j];
 
-               if(display_format == LISTBOX_ICONS)
-               {
+               if( display_format == LISTBOX_ICONS ||
+                   display_format == LISTBOX_ICON_LIST ) {
                        get_icon_mask(item, x, y, w, h);
                        if(y + h + yposition > highest) highest = y + h + yposition;
 
@@ -1149,8 +1142,6 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data,
                {
                        get_text_mask(item, x, y, w, h);
                        *result += h;
-
-
 // Descend into sublist
                        if(item->get_sublist() &&
                                item->get_expand())
@@ -1162,9 +1153,7 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data,
                }
        }
 
-       if((display_format == LISTBOX_TEXT ||
-               display_format == LISTBOX_ICON_LIST) &&
-               top_level)
+       if( display_format == LISTBOX_TEXT && top_level )
        {
                highest = LISTBOX_MARGIN + *result;
        }
@@ -2427,9 +2416,8 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data,
                        }
                }
        }
-       else
+       else if( gui ) {
 // Text is treed
-       {
 // Cursor is inside items rectangle
                if(cursor_x >= 0 &&
                        cursor_x < (yscrollbar ?
@@ -3134,17 +3122,14 @@ int BC_ListBox::button_release_event()
 //printf("BC_ListBox::button_release_event 10\n");
                        unset_repeat(get_resources()->scroll_repeat);
                        current_operation = NO_OPERATION;
-                       translate_coordinates(top_level->event_win,
-                               gui->win,
-                               gui->get_cursor_x(),
-                               gui->get_cursor_y(),
-                               &cursor_x,
-                               &cursor_y);
-
-                       selection_number1 =
-                               selection_number =
-                               get_cursor_item(data, cursor_x, cursor_y);
+                       if( gui ) {
+                               translate_coordinates(top_level->event_win, gui->win,
+                                       gui->get_cursor_x(), gui->get_cursor_y(),
+                                       &cursor_x, &cursor_y);
+                               selection_number1 = selection_number =
+                                       get_cursor_item(data, cursor_x, cursor_y);
 //printf("BC_ListBox::button_release_event %d %d\n", selection_number2, selection_number1);
+                       }
 
                        if(is_popup)
                        {