clip folder bug on reload, expander user folder drag/drop segv, remove libfdk src...
[goodguy/history.git] / cinelerra-5.1 / guicast / bclistbox.C
index 320e98bc4d701269e2fa636f02556a2bc4c419c6..2dd4283c990fc325d4caf6edc68068c882a4b035 100644 (file)
@@ -618,8 +618,7 @@ void BC_ListBox::calculate_last_coords_recursive(
                                *next_text_y = current_text_y;
 
 // Add sublist depth if it is expanded
-                       if( item->get_sublist() && item->get_columns() &&
-                           item->get_expand() ) {
+                       if( item->sublist_active() && item->get_columns() ) {
                                calculate_last_coords_recursive(item->get_sublist(),
                                        icon_x, next_icon_x, next_icon_y, next_text_y, 0);
                        }
@@ -656,8 +655,8 @@ void BC_ListBox::calculate_item_coords_recursive(
        if( temp_display_format == LISTBOX_ICON_LIST ) {
                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();
+                               int icon_h = data[0].get(i)->icon->get_h() + 2*ICON_MARGIN;
+                               if( row_height < icon_h ) row_height = icon_h;
                        }
                }
        }
@@ -712,7 +711,7 @@ void BC_ListBox::calculate_item_coords_recursive(
                                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(),
+// item->sublist, item->get_columns(), item->get_expand(),
 // next_text_x, *next_text_y, item->get_text());
 // Increment position of next column
                                if( j < columns - 1 ) {
@@ -743,8 +742,7 @@ void BC_ListBox::calculate_item_coords_recursive(
 
 // Set up a sublist
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() && item->get_columns() &&
-                   item->get_expand() ) {
+               if( item->sublist_active() && item->get_columns() ) {
                        calculate_item_coords_recursive( item->get_sublist(),
                                icon_x, next_icon_x, next_icon_y, next_text_y, 0);
                }
@@ -918,14 +916,24 @@ int BC_ListBox::get_item_h(BC_ListBoxItem *item)
 }
 
 
+int BC_ListBox::get_icon_x(BC_ListBoxItem *item)
+{
+       return get_item_x(item) + ICON_MARGIN;
+}
+
+int BC_ListBox::get_icon_y(BC_ListBoxItem *item)
+{
+       return get_item_y(item) + ICON_MARGIN;
+}
+
 int BC_ListBox::get_icon_w(BC_ListBoxItem *item)
 {
-       return item->get_icon_w();
+       return item->get_icon_w() + 2*ICON_MARGIN;
 }
 
 int BC_ListBox::get_icon_h(BC_ListBoxItem *item)
 {
-       return item->get_icon_h();
+       return item->get_icon_h() + 2*ICON_MARGIN;
 }
 
 int BC_ListBox::get_text_w(BC_ListBoxItem *item)
@@ -1000,11 +1008,8 @@ int BC_ListBox::get_items_height(ArrayList<BC_ListBoxItem*> *data, int columns,
                        get_text_mask(item, x, y, w, h);
                        *result += h;
 // Descend into sublist
-                       if( item->get_sublist() && item->get_expand() ) {
-                               get_items_height(item->get_sublist(),
-                                       item->get_columns(),
-                                       result);
-                       }
+                       if( item->sublist_active() )
+                               get_items_height(item->get_sublist(), item->get_columns(), result);
                        break;
                case LISTBOX_ICONS:
                case LISTBOX_ICONS_PACKED:
@@ -1041,6 +1046,11 @@ int BC_ListBox::set_xposition(int position)
        return 0;
 }
 
+int BC_ListBox::is_highlighted()
+{
+       return list_highlighted;
+}
+
 void BC_ListBox::expand_item(BC_ListBoxItem *item, int expand)
 {
        if( item ) {
@@ -1061,7 +1071,7 @@ void BC_ListBox::collapse_recursive(ArrayList<BC_ListBoxItem*> *data,
 {
        for( int i=0; i<data[master_column].total; ++i ) {
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() && item->expand ) {
+               if( item->sublist_active() ) {
                        item->expand = 0;
                        collapse_recursive(item->get_sublist(), master_column);
                }
@@ -1079,7 +1089,7 @@ void BC_ListBox::set_autoplacement(ArrayList<BC_ListBoxItem*> *data,
                }
 
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        set_autoplacement(item->get_sublist(), do_icons, do_text);
                }
        }
@@ -1173,10 +1183,10 @@ int BC_ListBox::get_icon_mask(BC_ListBoxItem *item,
        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;
+               x = get_icon_x(item);
+               y = get_icon_y(item);
+               w = get_icon_w(item);
+               h = get_icon_h(item);
                break; }
        case LISTBOX_TEXT:
        default: {
@@ -1200,15 +1210,15 @@ int BC_ListBox::get_text_mask(BC_ListBoxItem *item,
        case LISTBOX_ICONS:
        case LISTBOX_ICONS_PACKED: {
                if( icon_position == ICON_LEFT ) {
-                       x += get_icon_w(item) + ICON_MARGIN * 2;
+                       x += get_icon_w(item);
                        y += get_icon_h(item) - get_text_h(item);
                }
                else {
-                       y += get_icon_h(item) + ICON_MARGIN;
+                       y += get_icon_h(item);
                }
 
                w = packed_icons ?
-                       get_icon_w(item) + ICON_MARGIN * 4 :
+                       get_icon_w(item) + ICON_MARGIN * 2 :
                        get_text_w(item) + ICON_MARGIN * 2 ;
                h = get_text_h(item) + ICON_MARGIN * 2;
                break; }
@@ -1278,7 +1288,7 @@ BC_ListBoxItem* BC_ListBox::get_selection_recursive(ArrayList<BC_ListBoxItem*> *
                        }
                }
 
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        BC_ListBoxItem *result = get_selection_recursive(item->get_sublist(),
                                column,
                                selection_number);
@@ -1311,7 +1321,7 @@ int BC_ListBox::get_selection_number_recursive(ArrayList<BC_ListBoxItem*> *data,
                                return (*counter);
                        }
                }
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        int result = get_selection_number_recursive(item->get_sublist(),
                                column, selection_number, counter);
                        if( result >= 0 ) return result;
@@ -1442,8 +1452,7 @@ int BC_ListBox::select_previous(int skip, BC_ListBoxItem *selected_item, int *co
        do {
                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() ) {
+                       if( current_item->sublist_active() ) {
                                int result = select_previous(skip, selected_item, counter,
                                        current_item->get_sublist(), got_first, got_second);
                                if( *got_second )
@@ -1534,8 +1543,7 @@ int BC_ListBox::select_next(int skip, BC_ListBoxItem *selected_item, int *counte
                        }
 
 // Descend into expanded level
-                       if( current_item->get_sublist() &&
-                           current_item->get_expand() ) {
+                       if( current_item->sublist_active() ) {
                                int result = select_next(skip, selected_item, counter,
                                        current_item->get_sublist(), got_first, got_second);
                                if( *got_second ) {
@@ -1639,10 +1647,8 @@ int BC_ListBox::center_selection(int selection,
                }
 
 // Descend
-               if( item->get_sublist() ) {
-                       int result = center_selection(selection,
-                               item->get_sublist(),
-                               counter);
+               if( item->sublist_active() ) {
+                       int result = center_selection(selection, item->get_sublist(), counter);
                        if( result ) return result;
                }
        }
@@ -1928,10 +1934,10 @@ int BC_ListBox::select_rectangle(ArrayList<BC_ListBoxItem*> *data,
                }
 
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() &&
-                   item->get_expand() )
+               if( item->sublist_active() ) {
                        result |= select_rectangle(item->get_sublist(),
                                x1, y1, x2, y2);
+               }
        }
        return result;
 }
@@ -1970,9 +1976,8 @@ void BC_ListBox::move_selection(ArrayList<BC_ListBoxItem*> *dst,
                        continue;
                }
 // Descend into sublist
-               if( item->get_sublist() ) {
-                       move_selection(dst,
-                               item->get_sublist());
+               if( item->sublist_active() ) {
+                       move_selection(dst, item->get_sublist());
                }
                ++i;
        }
@@ -2005,11 +2010,8 @@ int BC_ListBox::put_selection(ArrayList<BC_ListBoxItem*> *data,
                }
 
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() ) {
-                       if( put_selection(item->get_sublist(),
-                               src,
-                               destination,
-                               counter) )
+               if( item->sublist_active() ) {
+                       if( put_selection(item->get_sublist(), src, destination, counter) )
                                return 1;
                }
        }
@@ -2035,10 +2037,8 @@ int BC_ListBox::item_to_index(ArrayList<BC_ListBoxItem*> *data,
                }
 
                BC_ListBoxItem *new_item = data[master_column].values[i];
-               if( new_item->get_sublist() ) {
-                       if( item_to_index(new_item->get_sublist(),
-                               item,
-                               counter) >= 0 )
+               if( new_item->sublist_active() ) {
+                       if( item_to_index(new_item->get_sublist(), item, counter) >= 0 )
                                return (*counter);
                }
        }
@@ -2057,7 +2057,7 @@ BC_ListBoxItem* BC_ListBox::index_to_item(ArrayList<BC_ListBoxItem*> *data,
                        return data[column].values[i];
                }
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        BC_ListBoxItem *result = index_to_item(item->get_sublist(),
                                number, column, counter);
                        if( result ) return result;
@@ -2117,15 +2117,18 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
                                    cursor_y < get_item_y(item) + get_item_h(item) ) {
 //printf("BC_ListBox::get_cursor_item %d %d %p\n", master_column, i, item);
                                        if( item_return ) (*item_return) = item;
+                                       if( expanded < 0 ) (*counter) = i;
                                        return (*counter);
                                }
 
 // Descend into sublist
-                               if( item->get_sublist() ) {
+                               if( item->sublist_active() ) {
                                        if( get_cursor_item(item->get_sublist(),
                                              cursor_x, cursor_y, item_return, counter,
-                                             item->get_expand()) >= 0 )
+                                             item->get_expand()) >= 0 ) {
+                                               if( expanded < 0 ) (*counter) = i;
                                                return (*counter);
+                                       }
                                }
                        }
                }
@@ -2135,6 +2138,21 @@ int BC_ListBox::get_cursor_item(ArrayList<BC_ListBoxItem*> *data, int cursor_x,
        return -1;
 }
 
+// short version
+int BC_ListBox::get_cursor_item_no()
+{
+       int rx, ry;
+       gui->get_relative_cursor(rx, ry);
+       return get_cursor_item(data, rx, ry, 0, 0);
+}
+
+int BC_ListBox::get_cursor_data_item_no(BC_ListBoxItem **item_return)
+{
+       int rx, ry;
+       gui->get_relative_cursor(rx, ry);
+       return get_cursor_item(data, rx, ry, item_return, 0, -1);
+}
+
 int BC_ListBox::repeat_event(int64_t duration)
 {
        switch( current_operation ) {
@@ -2237,7 +2255,7 @@ int BC_ListBox::get_first_selection(ArrayList<BC_ListBoxItem*> *data, int *resul
                BC_ListBoxItem *item = data[master_column].values[i];
                (*result)++;
                if( item->selected ) return (*result);
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        if( get_first_selection(item->get_sublist(), result) >= 0 )
                                return (*result);
                }
@@ -2254,7 +2272,7 @@ int BC_ListBox::get_total_items(ArrayList<BC_ListBoxItem*> *data,
 
        for( int i=0; i<data[master_column].total; ++i ) {
                (*result)++;
-               if( data[master_column].values[i]->get_sublist() )
+               if( data[master_column].values[i]->sublist_active() )
                        get_total_items(data[master_column].values[i]->get_sublist(),
                                result,
                                master_column);
@@ -2284,7 +2302,7 @@ int BC_ListBox::get_last_selection(ArrayList<BC_ListBoxItem*> *data,
                                return (*result);
                }
 
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        if( get_last_selection(item->get_sublist(), result) >= 0 ) {
                                if( top_level )
                                        return get_total_items(data, 0, master_column) - (*result) /* - 1 */;
@@ -2309,7 +2327,7 @@ void BC_ListBox::select_range(ArrayList<BC_ListBoxItem*> *data,
                                data[j].values[i]->selected = 1;
                }
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() )
+               if( item->sublist_active() )
                        select_range(item->get_sublist(), start, end, current);
        }
 }
@@ -2361,7 +2379,7 @@ int BC_ListBox::toggle_item_selection(ArrayList<BC_ListBoxItem*> *data,
                }
 
 // Descend into sublist
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        if( toggle_item_selection(item->get_sublist(),
                              selection_number, counter) )
                                return 1;
@@ -2402,7 +2420,7 @@ void BC_ListBox::set_selected(ArrayList<BC_ListBoxItem*> *data,
                }
 
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() ) {
+               if( item->sublist_active() ) {
                        set_selected(item->get_sublist(), item_number, value, counter);
                }
        }
@@ -2429,7 +2447,7 @@ int BC_ListBox::update_selection(ArrayList<BC_ListBoxItem*> *data,
                        for( int j=0; j<columns; ++j )
                                data[j].values[i]->selected = 0;
                }
-               if( item->get_sublist() )
+               if( item->sublist_active() )
                        result |= update_selection(item->get_sublist(),
                                selection_number,
                                counter);
@@ -2446,7 +2464,7 @@ void BC_ListBox::promote_selections(ArrayList<BC_ListBoxItem*> *data,
                        if( item->selected == old_value ) item->selected = new_value;
                }
                BC_ListBoxItem *item = data[master_column].values[i];
-               if( item->get_sublist() )
+               if( item->sublist_active() )
                        promote_selections(item->get_sublist(), old_value, new_value);
        }
 }
@@ -2695,7 +2713,6 @@ int BC_ListBox::button_press_event()
 int BC_ListBox::button_release_event()
 {
        int result = 0;
-       int cursor_x, cursor_y;
        int do_event = 0;
        new_value = 0;
        unset_scroll_repeat();
@@ -2718,11 +2735,7 @@ int BC_ListBox::button_release_event()
 //printf("BC_ListBox::button_release_event 10\n");
                current_operation = NO_OPERATION;
                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);
+                       selection_number1 = selection_number = get_cursor_item_no();
 //printf("BC_ListBox::button_release_event %d %d\n", selection_number2, selection_number1);
                }
 
@@ -3134,7 +3147,8 @@ int BC_ListBox::cursor_motion_event()
 
 // Moved out of item area
                        if( old_highlighted_item != highlighted_item ) {
-                               redraw_items = 1;
+                               if( !mouse_over_event(highlighted_item) )
+                                       redraw_items = 1;
                        }
 
 //printf("BC_ListBox::cursor_motion_event 1 %d\n", highlighted_item);
@@ -3181,6 +3195,7 @@ int BC_ListBox::drag_start_event()
 {
        switch( current_operation ) {
        case SELECT:
+               if( expander_active() ) break;
                if( gui && gui->is_event_win() && allow_drag ) {
                        BC_ListBoxItem *item_return = 0;
                        selection_number = get_cursor_item(data,
@@ -3454,6 +3469,14 @@ int BC_ListBox::is_active()
        return active;
 }
 
+int BC_ListBox::expander_active()
+{
+       for( int i=0; i<expanders.total; ++i ) {
+               if( expanders.values[i]->value ) return 1;
+       }
+       return 0 ;
+}
+
 int BC_ListBox::keypress_event()
 {
        if( !active ) return 0;
@@ -3691,16 +3714,17 @@ int BC_ListBox::draw_items(int flush, int draw_bg)
                                        }
 // Draw icons
                                        gui->set_color(get_item_color(data, 0, i));
-                                       if( item->icon )
-                                               gui->pixmap->draw_pixmap(item->icon,
-                                                       icon_x + ICON_MARGIN, icon_y + ICON_MARGIN);
+                                       VFrame *vicon = item->get_vicon_frame();
+                                       if( vicon )
+                                               gui->pixmap->draw_vframe(vicon, icon_x, icon_y);
+                                       else if( item->icon )
+                                               gui->pixmap->draw_pixmap(item->icon, icon_x, icon_y);
                                        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);
+                                       gui->draw_text(text_x, text_y + get_baseline(item), item_text);
                                }
                                else
                                        item->set_in_view(0);
@@ -3818,8 +3842,14 @@ void BC_ListBox::draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
 
 
                        if( column == 0 && display_format == LISTBOX_ICON_LIST ) {
-                               if( item->icon ) {
-                                       gui->pixmap->draw_pixmap(item->icon, x, y);
+                               int ix = get_icon_x(item), iy = get_icon_y(item);
+                               VFrame *vicon = item->get_vicon_frame();
+                               if( vicon ) {
+                                       gui->pixmap->draw_vframe(vicon, ix, iy);
+                                       x += vicon->get_w() + ICON_MARGIN;
+                               }
+                               else if( item->icon ) {
+                                       gui->pixmap->draw_pixmap(item->icon, ix, iy);
                                        x += item->icon->get_w() + ICON_MARGIN;
                                }
                        }
@@ -3863,7 +3893,7 @@ void BC_ListBox::draw_text_recursive(ArrayList<BC_ListBoxItem*> *data,
                        item->set_in_view(0);
 
 // Descend into sublist
-               if( first_item->get_expand() ) {
+               if( first_item->sublist_active() ) {
                        draw_text_recursive(first_item->get_sublist(),
                                column,
                                indent + LISTBOX_INDENT,