X-Git-Url: http://git.cinelerra-gg.org/git/?p=goodguy%2Fhistory.git;a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbclistbox.C;h=16a477bbe309d0de365f9029675516f61a3f2487;hp=88afc836f39d9317b1856cfea66aaa02446918e6;hb=a95193c3fd88733d184f2d460eca1fe6ddf8af28;hpb=22a5ea2ff7a04c02465dc9b2256f04c38433142e diff --git a/cinelerra-5.1/guicast/bclistbox.C b/cinelerra-5.1/guicast/bclistbox.C index 88afc836..16a477bb 100644 --- a/cinelerra-5.1/guicast/bclistbox.C +++ b/cinelerra-5.1/guicast/bclistbox.C @@ -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; @@ -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"); @@ -645,8 +656,8 @@ void BC_ListBox::calculate_item_coords_recursive( if( temp_display_format == LISTBOX_ICON_LIST ) { for( int i=0; iicon ) { - 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; } } } @@ -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,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 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 *data, int columns, @@ -953,15 +995,8 @@ int BC_ListBox::get_items_height(ArrayList *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 @@ -970,6 +1005,16 @@ int BC_ListBox::get_items_height(ArrayList *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; } } @@ -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 ) { - 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 + switch( display_format ) { + case LISTBOX_ICONS: + case LISTBOX_ICONS_PACKED: + case LISTBOX_ICON_LIST: { + x = get_item_x(item) + ICON_MARGIN; + y = get_item_y(item) + ICON_MARGIN; + w = get_icon_w(item) + ICON_MARGIN; + h = get_icon_h(item) + ICON_MARGIN; + 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; } @@ -1558,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 ) { @@ -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; @@ -1826,7 +1880,9 @@ int BC_ListBox::select_rectangle(ArrayList *data, for( int i=0; i *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 *data, result = 1; } } + break; } } } @@ -2016,8 +2074,11 @@ int BC_ListBox::get_cursor_item(ArrayList *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 *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 && @@ -2067,11 +2129,20 @@ int BC_ListBox::get_cursor_item(ArrayList *data, int cursor_x, } } } + break; } return -1; } +// short version +int BC_ListBox::get_cursor_item() +{ + int rx, ry; + gui->get_relative_cursor(rx, ry); + return get_cursor_item(data, rx, ry, 0, 0); +} + int BC_ListBox::repeat_event(int64_t duration) { switch( current_operation ) { @@ -2443,6 +2514,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 ) { @@ -2624,9 +2703,9 @@ 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(); //printf("BC_ListBox::button_release_event 1 %d\n", current_operation); switch( current_operation ) { @@ -2644,14 +2723,9 @@ 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, - 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(); //printf("BC_ListBox::button_release_event %d %d\n", selection_number2, selection_number1); } @@ -2679,7 +2753,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); @@ -2877,9 +2950,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 +3002,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); @@ -3141,7 +3210,7 @@ int BC_ListBox::drag_start_event() 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; } } @@ -3208,9 +3277,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 && @@ -3219,7 +3289,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 - @@ -3248,13 +3319,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 ) { @@ -3264,13 +3330,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() @@ -3478,7 +3549,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 && @@ -3492,12 +3563,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; } @@ -3550,6 +3619,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); } @@ -3579,7 +3649,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); @@ -3626,9 +3697,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); @@ -3709,7 +3784,7 @@ void BC_ListBox::draw_text_recursive(ArrayList *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