add 2 asset list fmts, user title rework, added show edit, bt tweak
[goodguy/history.git] / cinelerra-5.1 / guicast / bclistbox.C
index 23c4e185accd27c9477060d7581c14bfd8e7048e..a6946530ffb1638f2cfe0690589d7653dcd44462 100644 (file)
@@ -369,6 +369,7 @@ BC_ListBox::BC_ListBox(int x, int y, int w, int h,
        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;
 
@@ -708,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(),
@@ -851,25 +852,38 @@ int BC_ListBox::get_highlighted_item()
 
 int BC_ListBox::get_item_x(BC_ListBoxItem *item)
 {
-       if( display_format == LISTBOX_TEXT )
+       switch( display_format ) {
+       case LISTBOX_TEXT:
+       case LISTBOX_ICON_LIST:
                return item->text_x - xposition + 2;
-       if( display_format == 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;
@@ -878,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;
@@ -892,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;
 }
 
 
@@ -931,9 +951,12 @@ int BC_ListBox::get_baseline(BC_ListBoxItem *item)
 
 int BC_ListBox::get_items_width()
 {
-       int widest = 0;
-
-       if( display_format == LISTBOX_ICONS ) {
+       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;
@@ -943,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 get_column_offset(columns);
-       }
-       else {
+               return widest; }
+       case LISTBOX_ICON_LIST:
                return get_column_offset(columns);
        }
-       return widest;
+       return 0;
 }
 
 int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
@@ -976,15 +995,8 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
                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
@@ -993,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;
                }
        }
 
@@ -1147,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;
 }
 
@@ -1164,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);
@@ -1173,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;
 }
@@ -1581,9 +1613,9 @@ int BC_ListBox::center_selection(int selection,
                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 ) {
@@ -1594,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;
@@ -1849,7 +1880,9 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
        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);
@@ -1870,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() :
@@ -1889,6 +1923,7 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
                                                result = 1;
                                        }
                                }
+                               break; }
                        }
                }
 
@@ -2039,8 +2074,10 @@ 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_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];
@@ -2055,8 +2092,10 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                                return j;
                        }
                }
-       }
-       else if( gui ) {
+               if( display_format == LISTBOX_ICONS ) return -1;
+               } // fall through
+       case LISTBOX_TEXT:
+               if( !gui ) break;
 // Text is treed
 // Cursor is inside items rectangle
                if( cursor_x >= 0 &&
@@ -2090,6 +2129,7 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                                }
                        }
                }
+               break;
        }
 
        return -1;
@@ -3246,7 +3286,8 @@ 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_w() / 2 -
@@ -3575,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);
 }
@@ -3604,7 +3646,8 @@ 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);
@@ -3651,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);
@@ -3734,7 +3781,7 @@ void BC_ListBox::draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
                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 ) {