libzmpeg3 layer3 tweak, listbox selection fix, vicon emtpy video fixes
[goodguy/history.git] / cinelerra-5.1 / guicast / bclistbox.C
index 0285fd39247d6b59c12564a701927322b021fe41..320e98bc4d701269e2fa636f02556a2bc4c419c6 100644 (file)
@@ -287,8 +287,8 @@ BC_ListBox::BC_ListBox(int x, int y, int w, int h,
        yscrollbar = 0;
        current_cursor = ARROW_CURSOR;
        gui = 0;
-       view_h = 0;
-       view_w = 0;
+       view_w = items_w = 0;
+       view_h = items_h = 0;
        title_h = 0;
        active = 0;
        is_suggestions = 0;
@@ -300,19 +300,26 @@ BC_ListBox::BC_ListBox(int x, int y, int w, int h,
        bg_tile = 0;
        bg_draw = 1;
        drag_popup = 0;
+       dragged_title = 0;
        selection_number1 = -1;
        selection_number2 = -1;
        bg_surface = 0;
        bg_pixmap = 0;
        row_height = row_ascent = row_descent = 0;
-
+       selection_start = 0;
+       selection_center = 0;
+       selection_end = -1;
+       selection_number = -1;
        current_operation = NO_OPERATION;
        button_highlighted = 0;
+       button_releases = 0;
        list_highlighted = 0;
        disabled = 0;
 
+       scroll_repeat = 0;
        allow_drag_scroll = 1;
        process_drag = 1;
+       for( int i=0; i<32; ++i ) default_column_width[i] = 0;
 
        sort_column = -1;
        sort_order = 0;
@@ -324,9 +331,9 @@ BC_ListBox::BC_ListBox(int x, int y, int w, int h,
        popup_w = w;
        popup_h = h;
 
-       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;
+       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;
@@ -359,8 +366,12 @@ BC_ListBox::BC_ListBox(int x, int y, int w, int h,
 
        drag_icon_vframe = 0;
        drag_column_icon_vframe = 0;
-
-
+       drag_cursor_x = 0;
+       drag_column_w = 0;
+       temp_display_format = display_format;
+       packed_icons = display_format == LISTBOX_ICONS_PACKED ? 1 : 0;
+       rect_x1 = rect_x2 = 0;
+       rect_y1 = rect_y2 = 0;
 
 // reset the search engine
 //printf("BC_ListBox::BC_ListBox 4\n");
@@ -376,9 +387,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++ ) 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];
+       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;
 
@@ -407,7 +418,7 @@ void BC_ListBox::reset_query()
 
 int BC_ListBox::evaluate_query(char *string)
 {
-       for( int i = 0; i < data[search_column].size(); i++ ) {
+       for( int i=0; i<data[search_column].size(); ++i ) {
                if( strcmp(string, data[search_column].get(i)->text) <= 0 &&
                    data[search_column].get(i)->searchable ) {
                        return i;
@@ -430,8 +441,8 @@ int BC_ListBox::query_list()
 
        if( done ) {
 // Deselect all
-               for( int i = 0; i < data[0].total; i++ ) {
-                       for( int j = 0; j < columns; j++ ) {
+               for( int i=0; i<data[0].total; ++i ) {
+                       for( int j=0; j<columns; ++j ) {
                                if( data[j].values[i]->selected ) prev_selection = i;
                                data[j].values[i]->selected = 0;
                        }
@@ -440,7 +451,7 @@ int BC_ListBox::query_list()
 // Select one
                if( prev_selection != result )
                        selection_changed = 1;
-               for( int j = 0; j < columns; j++ ) {
+               for( int j=0; j<columns; ++j ) {
                        data[j].values[result]->selected = 1;
                }
                center_selection(result);
@@ -453,7 +464,7 @@ void BC_ListBox::init_column_width()
 {
        if( !column_width && data ) {
                int widest = 5, wd;
-               for( int i = 0; i < data[0].total; i++ ) {
+               for( int i=0; i<data[0].total; ++i ) {
                        wd = get_text_w(data[0].values[i]);
                        if( wd > widest ) widest = wd;
                }
@@ -465,7 +476,7 @@ int BC_ListBox::initialize()
 {
        if( is_popup ) {
                if( use_button ) {
-                       for( int i = 0; i < 4; ++i ) {
+                       for( int i=0; i<4; ++i ) {
                                button_images[i] = new BC_Pixmap(parent_window,
                                        BC_WindowBase::get_resources()->listbox_button[i],
                                        PIXMAP_ALPHA);
@@ -483,12 +494,12 @@ int BC_ListBox::initialize()
                current_operation = NO_OPERATION;
        }
 
-       for( int i = 0; i < 3; i++ ) {
+       for( int i=0; i<3; ++i ) {
                column_bg[i] = new BC_Pixmap(parent_window,
                        get_resources()->listbox_column[i],
                        PIXMAP_ALPHA);
        }
-       for( int i = 0; i < 5; i++ ) {
+       for( int i=0; i<5; ++i ) {
                toggle_images[i] = new BC_Pixmap(parent_window,
                        get_resources()->listbox_expand[i],
                        PIXMAP_ALPHA);
@@ -592,7 +603,7 @@ void BC_ListBox::calculate_last_coords_recursive(
        int *next_text_y,
        int top_level)
 {
-       for( int i = 0; i < data[0].size(); i++ ) {
+       for( int i=0; i<data[0].size(); ++i ) {
                int current_text_y = 0;
                int current_icon_x = 0;
                int current_icon_y = 0;
@@ -643,7 +654,7 @@ void BC_ListBox::calculate_item_coords_recursive(
 // get maximum height of an icon
        row_height = get_text_height(MEDIUMFONT);
        if( temp_display_format == LISTBOX_ICON_LIST ) {
-               for( int i = 0; i < data[0].size(); i++ ) {
+               for( int i=0; i<data[0].size(); ++i ) {
                        if( data[0].get(i)->icon ) {
                                if( data[0].get(i)->icon->get_h() > row_height )
                                        row_height = data[0].get(i)->icon->get_h();
@@ -654,7 +665,7 @@ void BC_ListBox::calculate_item_coords_recursive(
 
 // Set up items which need autoplacement.
 // Should fill icons down and then across
-       for( int i = 0; i < data[0].size(); i++ ) {
+       for( int i=0; i<data[0].size(); ++i ) {
 // Don't increase y unless the row requires autoplacing.
                int total_autoplaced_columns = 0;
 
@@ -687,7 +698,7 @@ void BC_ListBox::calculate_item_coords_recursive(
                int next_text_x = 0;
                row_ascent = row_descent = 0;
 // row_height still holds icon max height
-               for( int j = 0; j < columns; j++ ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *item = data[j].get(i);
                        if( item->autoplace_text ) {
                                display_format = LISTBOX_TEXT;
@@ -698,7 +709,7 @@ void BC_ListBox::calculate_item_coords_recursive(
                                int bl = get_baseline(item);
                                if( bl > row_ascent ) row_ascent = bl;
                                int dt = ht - bl;
-                               if( dt > row_descent ) row_ascent = bl;
+                               if( dt > row_descent ) row_descent = dt;
 
 // printf("BC_ListBox::calculate_item_coords_recursive %p %d %d %d %d %s \n",
 // item->get_sublist(), item->get_columns(), item->get_expand(),
@@ -744,6 +755,19 @@ void BC_ListBox::set_is_suggestions(int value)
 {
        this->is_suggestions = value;
 }
+void BC_ListBox::set_scroll_repeat()
+{
+       if( scroll_repeat ) return;
+       scroll_repeat = 1;
+       set_repeat(get_resources()->scroll_repeat);
+}
+
+void BC_ListBox::unset_scroll_repeat()
+{
+       if( !scroll_repeat ) return;
+       scroll_repeat = 0;
+       unset_repeat(get_resources()->scroll_repeat);
+}
 
 void BC_ListBox::set_use_button(int value)
 {
@@ -828,25 +852,38 @@ int BC_ListBox::get_highlighted_item()
 
 int BC_ListBox::get_item_x(BC_ListBoxItem *item)
 {
-       if( display_format == LISTBOX_TEXT )
-               return item->text_x - xposition + 2;
-       if( display_format == LISTBOX_ICON_LIST )
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+       case LISTBOX_ICON_LIST:
                return item->text_x - xposition + 2;
-       return item->icon_x - xposition + 2;
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED:
+               return item->icon_x - xposition + 2;
+       }
+       return 0;
 }
 
 int BC_ListBox::get_item_y(BC_ListBoxItem *item)
 {
-       if( display_format == LISTBOX_TEXT )
-               return item->text_y - yposition + title_h + 2;
-       if( display_format == LISTBOX_ICON_LIST )
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+       case LISTBOX_ICON_LIST:
                return item->text_y - yposition + title_h + 2;
-       return item->icon_y - yposition + title_h + 2;
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED:
+               return item->icon_y - yposition + 2;
+       }
+       return 0;
 }
 
 int BC_ListBox::get_item_w(BC_ListBoxItem *item)
 {
-       if( display_format == LISTBOX_ICONS ) {
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+       case LISTBOX_ICON_LIST: {
+               return get_text_w(item) + 2 * LISTBOX_MARGIN; }
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED: {
                int x, y, w, h;
                get_icon_mask(item, x, y, w, h);
                int icon_w = w;
@@ -855,13 +892,19 @@ int BC_ListBox::get_item_w(BC_ListBoxItem *item)
 
                return icon_position == ICON_LEFT ? icon_w + text_w :
                        icon_w > text_w ? icon_w : text_w;
+               }
        }
-       return get_text_w(item) + 2 * LISTBOX_MARGIN;
+       return 0;
 }
 
 int BC_ListBox::get_item_h(BC_ListBoxItem *item)
 {
-       if( display_format == LISTBOX_ICONS ) {
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+       case LISTBOX_ICON_LIST:
+               return get_text_h(item);
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED: {
                int x, y, w, h;
                get_icon_mask(item, x, y, w, h);
                int icon_h = h;
@@ -869,9 +912,9 @@ int BC_ListBox::get_item_h(BC_ListBoxItem *item)
                int text_h = h;
 
                return icon_position != ICON_LEFT ? icon_h + text_h :
-                       icon_h > text_h ? icon_h : text_h;
+                       icon_h > text_h ? icon_h : text_h; }
        }
-       return get_text_h(item);
+       return 0;
 }
 
 
@@ -908,11 +951,14 @@ int BC_ListBox::get_baseline(BC_ListBoxItem *item)
 
 int BC_ListBox::get_items_width()
 {
-       int widest = 0;
-
-       if( display_format == LISTBOX_ICONS ) {
-               for( int i = 0; i < columns; i++ ) {
-                       for( int j = 0; j < data[i].total; j++ ) {
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+               return get_column_offset(columns);
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED: {
+               int widest = 0;
+               for( int i=0; i<columns; ++i ) {
+                       for( int j=0; j<data[i].total; ++j ) {
                                int x1, x, y, w, h;
                                BC_ListBoxItem *item = data[i].values[j];
                                x1 = item->icon_x;
@@ -920,22 +966,18 @@ int BC_ListBox::get_items_width()
                                get_icon_mask(item, x, y, w, h);
                                if( x1 + w > widest ) widest = x1 + w;
 
-                               if( display_format == LISTBOX_ICONS && icon_position == ICON_LEFT )
+                               if( icon_position == ICON_LEFT )
                                        x1 += w;
 
                                get_text_mask(item, x, y, w, h);
                                if( x1 + w > widest ) widest = x1 + w;
                        }
                }
-       }
-       else
-       if( display_format == LISTBOX_TEXT ) {
+               return widest; }
+       case LISTBOX_ICON_LIST:
                return get_column_offset(columns);
        }
-       else {
-               return get_column_offset(columns);
-       }
-       return widest;
+       return 0;
 }
 
 int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
@@ -949,19 +991,12 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
                top_level = 1;
        }
 
-       for( int j = 0; j < (data ? data[master_column].total : 0); j++ ) {
+       for( int j=0; j<(data?data[master_column].total:0); ++j ) {
                int x, y, w, h;
                BC_ListBoxItem *item = data[master_column].values[j];
 
-               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;
-
-                       get_text_mask(item, x, y, w, h);
-                       if( y + h + yposition > highest ) highest = y + h + yposition;
-               }
-               else {
+               switch( display_format ) {
+               case LISTBOX_TEXT:
                        get_text_mask(item, x, y, w, h);
                        *result += h;
 // Descend into sublist
@@ -970,6 +1005,16 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
                                        item->get_columns(),
                                        result);
                        }
+                       break;
+               case LISTBOX_ICONS:
+               case LISTBOX_ICONS_PACKED:
+               case LISTBOX_ICON_LIST:
+                       get_icon_mask(item, x, y, w, h);
+                       if( y + h + yposition > highest ) highest = y + h + yposition;
+
+                       get_text_mask(item, x, y, w, h);
+                       if( y + h + yposition > highest ) highest = y + h + yposition;
+                       break;
                }
        }
 
@@ -1014,7 +1059,7 @@ void BC_ListBox::expand_item(BC_ListBoxItem *item, int expand)
 void BC_ListBox::collapse_recursive(ArrayList<BC_ListBoxItem*> *data,
                int master_column)
 {
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                if( item->get_sublist() && item->expand ) {
                        item->expand = 0;
@@ -1027,8 +1072,8 @@ void BC_ListBox::set_autoplacement(ArrayList<BC_ListBoxItem*> *data,
        int do_icons,
        int do_text)
 {
-       for( int i = 0; i < data[0].total; i++ ) {
-               for( int j = 0; j < columns; j++ ) {
+       for( int i=0; i<data[0].total; ++i ) {
+               for( int j=0; j<columns; ++j ) {
                        if( do_icons ) data[j].values[i]->autoplace_icon = 1;
                        if( do_text ) data[j].values[i]->autoplace_text = 1;
                }
@@ -1101,13 +1146,13 @@ int BC_ListBox::get_column_offset(int column)
 void BC_ListBox::column_width_boundaries()
 {
        if( column_width ) {
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        if( column_width[i] < MIN_COLUMN_WIDTH )
                                 column_width[i] = MIN_COLUMN_WIDTH;
                }
        }
        else {
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        if( default_column_width[i] < MIN_COLUMN_WIDTH )
                                 default_column_width[i] = MIN_COLUMN_WIDTH;
                }
@@ -1124,14 +1169,20 @@ int BC_ListBox::get_column_width(int column, int clamp_right)
 int BC_ListBox::get_icon_mask(BC_ListBoxItem *item,
        int &x, int &y, int &w, int &h)
 {
-       if( display_format == LISTBOX_ICONS ) {
+       switch( display_format ) {
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED:
+       case LISTBOX_ICON_LIST: {
                x = get_item_x(item);
                y = get_item_y(item);
                w = get_icon_w(item) + ICON_MARGIN * 2;
                h = get_icon_h(item) + ICON_MARGIN * 2;
-       }
-       else
+               break; }
+       case LISTBOX_TEXT:
+       default: {
                x = y = w = h = 0;
+               break; }
+       }
        return 0;
 }
 
@@ -1141,7 +1192,13 @@ int BC_ListBox::get_text_mask(BC_ListBoxItem *item,
        x = get_item_x(item);
        y = get_item_y(item);
 
-       if( display_format == LISTBOX_ICONS ) {
+       switch( display_format ) {
+       case LISTBOX_TEXT: {
+               w = get_text_w(item) + LISTBOX_MARGIN * 2;
+               h = get_text_h(item);
+               break; }
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED: {
                if( icon_position == ICON_LEFT ) {
                        x += get_icon_w(item) + ICON_MARGIN * 2;
                        y += get_icon_h(item) - get_text_h(item);
@@ -1150,19 +1207,17 @@ int BC_ListBox::get_text_mask(BC_ListBoxItem *item,
                        y += get_icon_h(item) + ICON_MARGIN;
                }
 
-               w = get_text_w(item) + ICON_MARGIN * 2;
+               w = packed_icons ?
+                       get_icon_w(item) + ICON_MARGIN * 4 :
+                       get_text_w(item) + ICON_MARGIN * 2 ;
                h = get_text_h(item) + ICON_MARGIN * 2;
-       }
-       else
-       if( display_format == LISTBOX_TEXT ) {
-               w = get_text_w(item) + LISTBOX_MARGIN * 2;
-               h = get_text_h(item);
-       }
-       else {
+               break; }
+       case LISTBOX_ICON_LIST: {
                w = get_text_width(MEDIUMFONT, item->text) + LISTBOX_MARGIN * 2;
                h = row_height;
-               int ih = get_icon_h(item);
-               if( h < ih ) h = ih;
+               break; }
+       default:
+               w = h = 0;
        }
        return 0;
 }
@@ -1212,7 +1267,7 @@ BC_ListBoxItem* BC_ListBox::get_selection_recursive(ArrayList<BC_ListBoxItem*> *
 {
        if( !data ) return 0;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                if( item->selected ) {
 //printf("BC_ListBox::get_selection_recursive %d\n", __LINE__);
@@ -1247,7 +1302,7 @@ int BC_ListBox::get_selection_number_recursive(ArrayList<BC_ListBoxItem*> *data,
        if( !data ) return 0;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*counter)++;
                BC_ListBoxItem *item = data[master_column].values[i];
                if( item->selected ) {
@@ -1275,7 +1330,7 @@ int BC_ListBox::set_selection_mode(int mode)
 void BC_ListBox::delete_columns()
 {
        if( column_titles ) {
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        delete [] column_titles[i];
                }
                delete [] column_titles;
@@ -1299,14 +1354,14 @@ void BC_ListBox::set_columns(const char **column_titles, int *column_width, int
        delete_columns();
        if( column_titles ) {
                this->column_titles = new char*[columns];
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        this->column_titles[i] = new char[strlen(column_titles[i]) + 1];
                        strcpy(this->column_titles[i], column_titles[i]);
                }
        }
        if( column_width ) {
                this->column_width = new int[columns];
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        this->column_width[i] = column_width[i];
                }
        }
@@ -1385,7 +1440,7 @@ int BC_ListBox::select_previous(int skip, BC_ListBoxItem *selected_item, int *co
 // Scan backwards to item pointer.  Then count visible items to get
 // destination.  No wraparound.
        do {
-               for( int i = data[master_column].total - 1; i >= 0; i-- ) {
+               for( int i=data[master_column].total-1; i>=0; --i ) {
                        BC_ListBoxItem *current_item = data[master_column].values[i];
                        if( current_item->get_sublist() &&
                            current_item->get_expand() ) {
@@ -1398,7 +1453,7 @@ int BC_ListBox::select_previous(int skip, BC_ListBoxItem *selected_item, int *co
                        if( *got_first ) {
                                (*counter)++;
                                if( (*counter) >= skip ) {
-                                       for( int j = 0; j < columns; j++ )
+                                       for( int j=0; j<columns; ++j )
                                                data[j].values[i]->selected = 1;
                                        (*got_second) = 1;
                                        return item_to_index(this->data, current_item);
@@ -1406,7 +1461,7 @@ int BC_ListBox::select_previous(int skip, BC_ListBoxItem *selected_item, int *co
                        }
                        else {
                                if( current_item->selected ) {
-                                       for( int j = 0; j < columns; j++ )
+                                       for( int j=0; j<columns; ++j )
                                                data[j].values[i]->selected = 0;
                                        (*got_first) = 1;
                                        (*counter)++;
@@ -1421,7 +1476,7 @@ int BC_ListBox::select_previous(int skip, BC_ListBoxItem *selected_item, int *co
                        (*got_first) = 1;
                        current_item = data[master_column].values[0];
 
-                       for( int j = 0; j < columns; j++ )
+                       for( int j=0; j<columns; ++j )
                                data[j].values[0]->selected = 1;
                        (*got_second) = 1;
                        return item_to_index(this->data, current_item);
@@ -1454,7 +1509,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
 // Scan forwards to currently selected item pointer.
 // Then count visible items to get destination.  No wraparound.
        do {
-               for( int i = 0; i < data[master_column].total; i++ ) {
+               for( int i=0; i<data[master_column].total; ++i ) {
                        BC_ListBoxItem *current_item = data[master_column].values[i];
 
 // Select next item once the number items after the currently selected item
@@ -1462,7 +1517,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
                        if( *got_first ) {
                                (*counter)++;
                                if( (*counter) >= skip ) {
-                                       for( int j = 0; j < columns; j++ )
+                                       for( int j=0; j<columns; ++j )
                                                data[j].values[i]->selected = 1;
                                        (*got_second) = 1;
                                        return item_to_index(this->data, current_item);
@@ -1471,7 +1526,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
                        else {
 // Got currently selected item.  Deselect it.
                                if( current_item->selected ) {
-                                       for( int j = 0; j < columns; j++ )
+                                       for( int j=0; j<columns; ++j )
                                                data[j].values[i]->selected = 0;
                                        (*got_first) = 1;
                                        (*counter)++;
@@ -1497,7 +1552,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
                                (*got_first) = 1;
                                current_item = data[master_column].values[0];
 
-                               for( int j = 0; j < columns; j++ )
+                               for( int j=0; j<columns; ++j )
                                        data[j].values[0]->selected = 1;
                                (*got_second) = 1;
                        }
@@ -1507,7 +1562,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
                                int current_row = data[master_column].total - 1;
                                current_item = data[master_column].values[current_row];
 
-                               for( int j = 0; j < columns; j++ )
+                               for( int j=0; j<columns; ++j )
                                        data[j].values[current_row]->selected = 1;
                                (*got_second) = 1;
                        }
@@ -1551,16 +1606,16 @@ int BC_ListBox::center_selection(int selection,
        if( !data ) data = this->data;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*counter)++;
 
 // Got it
                BC_ListBoxItem *item = data[master_column].values[i];
                if( (*counter) == selection ) {
                        BC_ListBoxItem *top_item = this->data[master_column].values[0];
-
-
-                       if( display_format == LISTBOX_ICONS ) {
+                       switch( display_format ) {
+                       case LISTBOX_ICONS:
+                       case LISTBOX_ICONS_PACKED: {
 // Icon is out of window
                                if( item->icon_y-yposition  > view_h-get_text_h(item) ||
                                    item->icon_y-yposition < 0 ) {
@@ -1571,14 +1626,13 @@ int BC_ListBox::center_selection(int selection,
                                    data[master_column].values[selection]->icon_x - xposition < 0 ) {
                                        xposition = item->icon_x - view_w / 2;
                                }
-                       }
-                       else {
+                               break; }
+                       case LISTBOX_TEXT:
+                       case LISTBOX_ICON_LIST:
 // Text coordinate is out of window
                                if( item->text_y-yposition  > view_h-get_text_h(item) ||
                                    item->text_y-yposition < 0 ) {
-                                       yposition = item->text_y -
-                                               top_item->text_y -
-                                               view_h / 2;
+                                       yposition = item->text_y - top_item->text_y - view_h / 2;
                                }
                        }
                        return 1;
@@ -1634,7 +1688,7 @@ int BC_ListBox::get_scrollbars()
        view_w = popup_w - 4;
 
 // Create scrollbars as needed
-       for( int i = 0; i < 2; i++ ) {
+       for( int i=0; i<2; ++i ) {
                if( w_needed > view_w ) {
                        need_xscroll = 1;
                        view_h = popup_h -
@@ -1823,10 +1877,12 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
                int x1, int y1, int x2, int y2)
 {
        int result = 0;
-       for( int i = 0; i < data[master_column].total; i++ ) {
-               for( int j = 0; j < columns; j++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *item = data[j].values[i];
-                       if( display_format == LISTBOX_ICONS ) {
+                       switch( display_format ) {
+                       case LISTBOX_ICONS:
+                       case LISTBOX_ICONS_PACKED: {
                                int icon_x, icon_y, icon_w, icon_h;
                                int text_x, text_y, text_w, text_h;
                                get_icon_mask(item, icon_x, icon_y, icon_w, icon_h);
@@ -1847,8 +1903,9 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
                                                result = 1;
                                        }
                                }
-                       }
-                       else {
+                               break; }
+                       case LISTBOX_TEXT:
+                       case LISTBOX_ICON_LIST: {
                                if( x2 >= 0 &&
                                    x1 < (yscrollbar ?
                                        gui->get_w() - get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w() :
@@ -1866,6 +1923,7 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
                                                result = 1;
                                        }
                                }
+                               break; }
                        }
                }
 
@@ -1884,7 +1942,7 @@ int BC_ListBox::reposition_item(ArrayList<BC_ListBoxItem*> *data,
        int temp = -1;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                (*counter)++;
                if( (*counter) == selection_number ) {
@@ -1900,12 +1958,12 @@ int BC_ListBox::reposition_item(ArrayList<BC_ListBoxItem*> *data,
 void BC_ListBox::move_selection(ArrayList<BC_ListBoxItem*> *dst,
        ArrayList<BC_ListBoxItem*> *src)
 {
-       for( int i = 0; i < src[master_column].total;  ) {
+       for( int i=0; i<src[master_column].total;  ) {
                BC_ListBoxItem *item = src[master_column].values[i];
 
 // Move item to dst
                if( item->selected ) {
-                       for( int j = 0; j < columns; j++ ) {
+                       for( int j=0; j<columns; ++j ) {
                                dst[j].append(src[j].values[i]);
                                src[j].remove_number(i);
                        }
@@ -1927,19 +1985,19 @@ int BC_ListBox::put_selection(ArrayList<BC_ListBoxItem*> *data,
        if( !counter ) counter = &temp;
 
        if( destination < 0 || destination >= data[master_column].total ) {
-               for( int j = 0; j < columns; j++ ) {
-                       for( int i = 0; i < src[j].total; i++ ) {
+               for( int j=0; j<columns; ++j ) {
+                       for( int i=0; i<src[j].total; ++i ) {
                                data[j].append(src[j].values[i]);
                        }
                }
                return 1;
        }
        else
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*counter)++;
                if( (*counter) == destination ) {
-                       for( int j = 0; j < columns; j++ ) {
-                               for( int k = 0; k < src[j].total; k++ ) {
+                       for( int j=0; j<columns; ++j ) {
+                               for( int k=0; k<src[j].total; ++k ) {
                                        data[j].insert(src[j].values[k], destination + k);
                                }
                        }
@@ -1966,9 +2024,9 @@ int BC_ListBox::item_to_index(ArrayList<BC_ListBoxItem*> *data,
        int temp = -1;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*counter)++;
-               for( int j = 0; j < columns; j++ ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *new_item = data[j].values[i];
 //printf("BC_ListBox::item_to_index 1 %d %d %p\n", j, i, new_item);
                        if( new_item == item ) {
@@ -1993,7 +2051,7 @@ BC_ListBoxItem* BC_ListBox::index_to_item(ArrayList<BC_ListBoxItem*> *data,
 {
        int temp = -1;
        if( !counter ) counter = &temp;
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*counter)++;
                if( (*counter) == number ) {
                        return data[column].values[i];
@@ -2016,8 +2074,11 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
        if( !counter ) counter = &temp;
 
 // Icons are not treed
-       if( display_format == LISTBOX_ICONS ) {
-               for( int j = data[master_column].total - 1; j >= 0; j-- ) {
+       switch( display_format ) {
+       case LISTBOX_ICONS:
+       case LISTBOX_ICONS_PACKED:
+       case LISTBOX_ICON_LIST: {
+               for( int j=data[master_column].total; --j>=0; ) {
                        int icon_x, icon_y, icon_w, icon_h;
                        int text_x, text_y, text_w, text_h;
                        BC_ListBoxItem *item = data[master_column].values[j];
@@ -2032,8 +2093,9 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                                return j;
                        }
                }
-       }
-       else if( gui ) {
+               return -1; }
+       case LISTBOX_TEXT:
+               if( !gui ) break;
 // Text is treed
 // Cursor is inside items rectangle
                if( cursor_x >= 0 &&
@@ -2045,7 +2107,7 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                        (cursor_y > get_title_h() + LISTBOX_BORDER &&
                         cursor_y < gui->get_h())) ) {
 // Search table for cursor obstruction
-                       for( int i = 0; i < data[master_column].total; i++ ) {
+                       for( int i=0; i<data[master_column].total; ++i ) {
                                BC_ListBoxItem *item = data[master_column].values[i];
                                (*counter)++;
 
@@ -2067,6 +2129,7 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                                }
                        }
                }
+               break;
        }
 
        return -1;
@@ -2156,7 +2219,7 @@ int BC_ListBox::cursor_leave_event()
                highlighted_ptr = 0;
                highlighted_title = -1;
                int redraw_toggles = 0;
-               for( int i = 0; i < expanders.total; i++ )
+               for( int i=0; i<expanders.total; ++i )
                        expanders.values[i]->cursor_leave_event(&redraw_toggles);
 
                draw_items(1);
@@ -2170,7 +2233,7 @@ int BC_ListBox::get_first_selection(ArrayList<BC_ListBoxItem*> *data, int *resul
        int temp = -1;
        if( !result ) result = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                (*result)++;
                if( item->selected ) return (*result);
@@ -2189,7 +2252,7 @@ int BC_ListBox::get_total_items(ArrayList<BC_ListBoxItem*> *data,
        int temp = 0;
        if( !result ) result = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*result)++;
                if( data[master_column].values[i]->get_sublist() )
                        get_total_items(data[master_column].values[i]->get_sublist(),
@@ -2211,7 +2274,7 @@ int BC_ListBox::get_last_selection(ArrayList<BC_ListBoxItem*> *data,
                top_level = 1;
        }
 
-       for( int i = data[master_column].total - 1; i >= 0; i-- ) {
+       for( int i=data[master_column].total-1; i>=0; --i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                (*result)++;
                if( item->selected ) {
@@ -2239,10 +2302,10 @@ void BC_ListBox::select_range(ArrayList<BC_ListBoxItem*> *data,
        int temp = -1;
        if( !current ) current = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                (*current)++;
                if( (*current) >= start && (*current) < end ) {
-                       for( int j = 0; j < columns; j++ )
+                       for( int j=0; j<columns; ++j )
                                data[j].values[i]->selected = 1;
                }
                BC_ListBoxItem *item = data[master_column].values[i];
@@ -2285,14 +2348,14 @@ int BC_ListBox::toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
        int temp = -1;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                (*counter)++;
                if( (*counter) == selection_number ) {
 // Get new value for selection
                        int selected = !item->selected;
 // Set row
-                       for( int j = 0; j < columns; j++ )
+                       for( int j=0; j<columns; ++j )
                                data[j].values[i]->selected = selected;
                        return 1;
                }
@@ -2311,8 +2374,8 @@ int BC_ListBox::toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
 
 void BC_ListBox::set_all_selected(ArrayList<BC_ListBoxItem*> *data, int value)
 {
-       for( int i = 0; i < data[master_column].total; i++ ) {
-               for( int j = 0; j < columns; j++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *item = data[j].values[i];
                        item->selected = value;
                }
@@ -2328,10 +2391,10 @@ void BC_ListBox::set_selected(ArrayList<BC_ListBoxItem*> *data,
 {
        int temp = -1;
        if( !counter ) counter = &temp;
-       for( int i = 0; i < data[master_column].total && (*counter) != item_number; i++ ) {
+       for( int i=0; i<data[master_column].total&&(*counter)!=item_number; ++i ) {
                (*counter)++;
                if( (*counter) == item_number ) {
-                       for( int j = 0; j < columns; j++ ) {
+                       for( int j=0; j<columns; ++j ) {
                                BC_ListBoxItem *item = data[j].values[i];
                                item->selected = value;
                        }
@@ -2352,18 +2415,18 @@ int BC_ListBox::update_selection(ArrayList<BC_ListBoxItem*> *data,
        int result = 0;
        if( !counter ) counter = &temp;
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
                (*counter)++;
                if( (*counter) == selection_number && !item->selected ) {
                        result = 1;
-                       for( int j = 0; j < columns; j++ )
+                       for( int j=0; j<columns; ++j )
                                data[j].values[i]->selected = 1;
                }
                else
                if( (*counter) != selection_number && item->selected ) {
                        result = 1;
-                       for( int j = 0; j < columns; j++ )
+                       for( int j=0; j<columns; ++j )
                                data[j].values[i]->selected = 0;
                }
                if( item->get_sublist() )
@@ -2377,8 +2440,8 @@ int BC_ListBox::update_selection(ArrayList<BC_ListBoxItem*> *data,
 void BC_ListBox::promote_selections(ArrayList<BC_ListBoxItem*> *data,
                int old_value, int new_value)
 {
-       for( int i = 0; i < data[master_column].total; i++ ) {
-               for( int j = 0; j < columns; j++ ) {
+       for( int i=0; i<data[master_column].total; ++i ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *item = data[j].values[i];
                        if( item->selected == old_value ) item->selected = new_value;
                }
@@ -2443,6 +2506,14 @@ int BC_ListBox::button_press_event()
                        if( debug ) printf("BC_ListBox::button_press_event %d\n", __LINE__);
                }
 
+               if( current_operation != NO_OPERATION ) {
+                       switch( current_operation ) {
+                       case DRAG_ITEM:
+                       case COLUMN_DRAG:
+                               return drag_stop_event();
+                       }
+               }
+
 // Wheel mouse pressed
                if( get_buttonpress() == 4 ) {
                        if( current_operation == NO_OPERATION ) {
@@ -2627,6 +2698,7 @@ int BC_ListBox::button_release_event()
        int cursor_x, cursor_y;
        int do_event = 0;
        new_value = 0;
+       unset_scroll_repeat();
 
 //printf("BC_ListBox::button_release_event 1 %d\n", current_operation);
        switch( current_operation ) {
@@ -2644,7 +2716,6 @@ int BC_ListBox::button_release_event()
        case BUTTON_DOWN_SELECT:
        case SELECT:
 //printf("BC_ListBox::button_release_event 10\n");
-               unset_repeat(get_resources()->scroll_repeat);
                current_operation = NO_OPERATION;
                if( gui ) {
                        translate_coordinates(top_level->event_win, gui->win,
@@ -2679,7 +2750,6 @@ int BC_ListBox::button_release_event()
 
 
        case SELECT_RECT:
-               unset_repeat(get_resources()->scroll_repeat);
                if( data ) {
 // Demote selections from rectangle selection
                        promote_selections(data, 2, 1);
@@ -2730,7 +2800,7 @@ int BC_ListBox::button_release_event()
 
        case EXPAND_DN: {
                int redraw_toggles = 0;
-               for( int i = 0; i < expanders.total && !result; i++ ) {
+               for( int i=0; i<expanders.total&&!result; ++i ) {
                        if( expanders.values[i]->button_release_event(&redraw_toggles) ) {
                                result = 1;
                        }
@@ -2778,7 +2848,7 @@ int BC_ListBox::test_column_divisions(int cursor_x, int cursor_y, int &new_curso
        if( gui && column_titles &&
            cursor_y >= 0 && cursor_y < get_title_h() &&
            cursor_x >= 0 && cursor_x < gui->get_w() ) {
-               for( int i = 1; i < columns; i++ ) {
+               for( int i=1; i<columns; ++i ) {
                        if( cursor_x >= -xposition + get_column_offset(i) - 5 &&
                            cursor_x <  -xposition + get_column_offset(i) +
                                        get_resources()->listbox_title_hotspot ) {
@@ -2801,7 +2871,7 @@ int BC_ListBox::test_column_titles(int cursor_x, int cursor_y)
        if( gui && column_titles &&
            cursor_y >= 0 && cursor_y < get_title_h() &&
            cursor_x >= 0 && cursor_x < gui->get_w() ) {
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        if( cursor_x >= -xposition + get_column_offset(i) &&
                                (cursor_x < -xposition + get_column_offset(i + 1) ||
                                        i == columns - 1) ) {
@@ -2820,7 +2890,7 @@ int BC_ListBox::test_column_titles(int cursor_x, int cursor_y)
 
 int BC_ListBox::test_expanders()
 {
-       for( int i = 0; i < expanders.total; i++ ) {
+       for( int i=0; i<expanders.total; ++i ) {
                if( expanders.values[i]->button_press_event() ) {
                        current_operation = EXPAND_DN;
                        draw_toggles(1);
@@ -2877,9 +2947,8 @@ int BC_ListBox::cursor_motion_event()
                break; }
 
        case SELECT_RECT: {
-               if( test_drag_scroll(get_cursor_x(), get_cursor_y()) ) {
-                       set_repeat(get_resources()->scroll_repeat);
-               }
+               if( test_drag_scroll(get_cursor_x(), get_cursor_y()) )
+                       set_scroll_repeat();
 
                int old_x1 = MIN(rect_x1, rect_x2);
                int old_x2 = MAX(rect_x1, rect_x2);
@@ -2930,11 +2999,8 @@ int BC_ListBox::cursor_motion_event()
        case SELECT: {
                int old_highlighted_item = highlighted_item;
 
-               if( test_drag_scroll(get_cursor_x(),
-                       get_cursor_y()) ) {
-                       set_repeat(get_resources()->scroll_repeat);
-               }
-
+               if( test_drag_scroll(get_cursor_x(), get_cursor_y()) )
+                       set_scroll_repeat();
 
                highlighted_item = selection_number = get_cursor_item(data,
                        get_cursor_x(), get_cursor_y(), &highlighted_ptr);
@@ -3006,7 +3072,7 @@ int BC_ListBox::cursor_motion_event()
 
        case EXPAND_DN: {
                int redraw_toggles = 0;
-               for( int i = 0; i < expanders.total && !result; i++ ) {
+               for( int i=0; i<expanders.total&&!result; ++i ) {
                        result = expanders.values[i]->cursor_motion_event(
                                &redraw_toggles);
                }
@@ -3040,7 +3106,7 @@ int BC_ListBox::cursor_motion_event()
                        if( highlighted_division < 0 && highlighted_title < 0 &&
                            (display_format == LISTBOX_TEXT ||
                             display_format == LISTBOX_ICON_LIST) ) {
-                               for( int i = 0; i < expanders.total; i++ ) {
+                               for( int i=0; i<expanders.total; ++i ) {
                                        expanders.values[i]->cursor_motion_event(
                                                &redraw_toggles);
                                }
@@ -3126,29 +3192,22 @@ int BC_ListBox::drag_start_event()
                                int cx, cy;
                                get_abs_cursor(cx, cy);
                                if( item_return->icon_vframe ) {
-                                       cx -= item_return->icon_vframe->get_w() / 2,
-                                       cy -= item_return->icon_vframe->get_h() / 2;
                                        drag_popup = new BC_DragWindow(this,
                                                item_return->icon_vframe, cx, cy);
                                }
                                else
-// this probably works not!
                                if( item_return->icon ) {
-                                       cx -= item_return->icon->get_w() / 2,
-                                       cy -= item_return->icon->get_h() / 2;
                                        drag_popup = new BC_DragWindow(this,
                                                item_return->icon, cx, cy);
                                }
                                else {
-                                       cx -= drag_icon_vframe->get_w() / 2,
-                                       cy -= drag_icon_vframe->get_h() / 2;
                                        drag_popup = new BC_DragWindow(this,
                                                drag_icon_vframe, cx, cy);
                                }
                                current_operation = DRAG_ITEM;
 // require shift down for scrolling
                                if( allow_drag < 0 && shift_down() )
-                                       set_repeat(get_resources()->scroll_repeat);
+                                       set_scroll_repeat();
                                return 1;
                        }
                }
@@ -3215,9 +3274,10 @@ int BC_ListBox::drag_motion_event()
 
 int BC_ListBox::drag_stop_event()
 {
+       int result = 0;
+       unset_scroll_repeat();
        switch( current_operation ) {
        case DRAG_ITEM:
-               unset_repeat(get_resources()->scroll_repeat);
 // Inside window boundary
                if( top_level->cursor_x > 0 &&
                    top_level->cursor_x < gui->get_w() - drag_popup->get_w() / 2 &&
@@ -3226,12 +3286,13 @@ int BC_ListBox::drag_stop_event()
 // Move icon
 
 
-                       if( display_format == LISTBOX_ICONS ) {
+                       if( display_format == LISTBOX_ICONS ||
+                           display_format == LISTBOX_ICONS_PACKED ) {
                                reposition_item(data,
                                        selection_number,
-                                       top_level->cursor_x + drag_popup->get_offset_x() -
+                                       top_level->cursor_x - drag_popup->get_w() / 2 -
                                                LISTBOX_MARGIN - 2 + xposition,
-                                       top_level->cursor_y + drag_popup->get_offset_y() -
+                                       top_level->cursor_y - drag_popup->get_h() / 2 -
                                                LISTBOX_MARGIN - 2 + yposition);
                        }
                        else
@@ -3255,13 +3316,8 @@ int BC_ListBox::drag_stop_event()
                }
                else
                        drag_popup->drag_failure_event();
-
-               delete drag_popup;
-               flush();
-               drag_popup = 0;
-               current_operation = NO_OPERATION;
-               new_value = 0;
-               return 1;
+               result = 1;
+               break;
 
        case COLUMN_DRAG:
                if( dragged_title != highlighted_title ) {
@@ -3271,13 +3327,18 @@ int BC_ListBox::drag_stop_event()
                        else
                                drag_popup->drag_failure_event();
                }
+               result = 1;
+       }
+
+       if( result ) {
                current_operation = NO_OPERATION;
                delete drag_popup;
                flush();
                drag_popup = 0;
-               return 1;
+               new_value = 0;
        }
-       return 0;
+
+       return result;
 }
 
 BC_DragWindow* BC_ListBox::get_drag_popup()
@@ -3485,7 +3546,7 @@ int BC_ListBox::keypress_event()
                break;
 
        default:
-               if( !ctrl_down() ) {
+               if( show_query && !ctrl_down() ) {
                        int query_len = strlen(query);
                        if( query_len < (int)sizeof(query)-1 &&
                            top_level->get_keypress() > 30 &&
@@ -3499,12 +3560,10 @@ int BC_ListBox::keypress_event()
                                if( query_len > 0 ) query[--query_len] = 0;
                                new_selection = query_list();
                        }
-                       if( show_query ) {
-                               if( query_len > 0 )
-                                       show_tooltip(query);
-                               else
-                                       hide_tooltip();
-                       }
+                       if( query_len > 0 )
+                               show_tooltip(query);
+                       else
+                               hide_tooltip();
                        redraw = 1;
                        result = 1;
                }
@@ -3557,6 +3616,7 @@ void BC_ListBox::clear_listbox(int x, int y, int w, int h)
 void BC_ListBox::update_format(int display_format, int redraw)
 {
        this->display_format = display_format;
+       packed_icons = display_format == LISTBOX_ICONS_PACKED ? 1 : 0;
        xposition = 0;  yposition = 0;
        if( redraw && gui ) draw_items(1, 1);
 }
@@ -3586,11 +3646,12 @@ int BC_ListBox::draw_items(int flush, int draw_bg)
                first_in_view = -1;
                last_in_view = 0;
 // Icon display
-               if( display_format == LISTBOX_ICONS ) {
+               if( display_format == LISTBOX_ICONS ||
+                   display_format == LISTBOX_ICONS_PACKED ) {
                        clear_listbox(2, 2 + title_h, view_w, view_h);
 
                        set_font(MEDIUMFONT);
-                       for( int i = 0; i < data[master_column].size(); i++ ) {
+                       for( int i=0; i<data[master_column].size(); ++i ) {
                                BC_ListBoxItem *item = data[master_column].get(i);
                                if( get_item_x(item) >= -get_item_w(item) &&
                                    get_item_x(item) < view_w &&
@@ -3633,9 +3694,13 @@ int BC_ListBox::draw_items(int flush, int draw_bg)
                                        if( item->icon )
                                                gui->pixmap->draw_pixmap(item->icon,
                                                        icon_x + ICON_MARGIN, icon_y + ICON_MARGIN);
-
+                                       char item_text[BCTEXTLEN];
+                                       if( display_format == LISTBOX_ICONS_PACKED )
+                                               gui->truncate_text(item_text, item->text, text_w);
+                                       else
+                                               strcpy(item_text, item->text);
                                        gui->draw_text(text_x + ICON_MARGIN,
-                                               text_y + ICON_MARGIN + get_baseline(item), item->text);
+                                               text_y + ICON_MARGIN + get_baseline(item), item_text);
                                }
                                else
                                        item->set_in_view(0);
@@ -3646,7 +3711,7 @@ int BC_ListBox::draw_items(int flush, int draw_bg)
 // Draw one column at a time so text overruns don't go into the next column
 // clear column backgrounds
                        int current_toggle = 0;
-                       for( int j = 0; j < columns; j++ ) {
+                       for( int j=0; j<columns; ++j ) {
                                clear_listbox(LISTBOX_BORDER + get_column_offset(j) - xposition,
                                        LISTBOX_BORDER + title_h,
                                        get_column_width(j, 1),
@@ -3700,7 +3765,7 @@ void BC_ListBox::draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
 
 // Search for a branch and make room for toggle if there is one
        if( column == 0 ) {
-               for( int i = 0; i < data[column].size(); i++ ) {
+               for( int i=0; i<data[column].size(); ++i ) {
                        if( data[column].get(i)->get_sublist() ) {
                                subindent = BC_WindowBase::get_resources()->listbox_expand[0]->get_w();
                                break;
@@ -3709,17 +3774,17 @@ void BC_ListBox::draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
        }
 
        row_height = row_ascent = row_descent = 0;
-       for( int i = 0; i < data[column].total; i++ ) {
+       for( int i=0; i<data[column].total; ++i ) {
                BC_ListBoxItem *item = data[column].values[i];
                int ht = get_text_h(item);
                if( ht > row_height ) row_height = ht;
                int bl = get_baseline(item);
                if( bl > row_ascent ) row_ascent = bl;
                int dt = ht - bl;
-               if( dt > row_descent ) row_ascent = bl;
+               if( dt > row_descent ) row_descent = dt;
        }
 
-       for( int i = 0; i < data[column].size(); i++ ) {
+       for( int i=0; i<data[column].size(); ++i ) {
 // Draw a row
                BC_ListBoxItem *item = data[column].values[i];
                BC_ListBoxItem *first_item = data[master_column].values[i];
@@ -3877,7 +3942,7 @@ int BC_ListBox::draw_titles(int flash)
            (display_format == LISTBOX_TEXT ||
             display_format == LISTBOX_ICON_LIST) ) {
 //printf("BC_ListBox::draw_titles 1 %d\n", highlighted_title);
-               for( int i = 0; i < columns; i++ ) {
+               for( int i=0; i<columns; ++i ) {
                        if( i != highlighted_title )
                                draw_title(i);
                }
@@ -3894,7 +3959,7 @@ int BC_ListBox::draw_titles(int flash)
 
 void BC_ListBox::draw_toggles(int flash)
 {
-       for( int i = 0; i < expanders.total; i++ )
+       for( int i=0; i<expanders.total; ++i )
                expanders.values[i]->draw(0);
 
 //printf("BC_ListBox::draw_toggles 1 %d\n", flash);
@@ -3931,10 +3996,10 @@ void BC_ListBox::dump(ArrayList<BC_ListBoxItem*> *data, int columns,
                printf("BC_ListBox::dump 1\n");
        }
 
-       for( int i = 0; i < data[master_column].total; i++ ) {
-               for( int k = 0; k < indent; k++ )
+       for( int i=0; i<data[master_column].total; ++i ) {
+               for( int k=0; k<indent; ++k )
                        printf(" ");
-               for( int j = 0; j < columns; j++ ) {
+               for( int j=0; j<columns; ++j ) {
                        BC_ListBoxItem *item = data[j].values[i];
                        printf("%d,%d,%d=%s ",
                                item->get_text_x(), item->get_text_y(),