X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbclistbox.C;h=394daac60607dd1bf6e82274408076b8fd0be071;hb=61d95f04b83c2f7f1fa6b44ff64ed9c83a7d8abb;hp=683985feec863488fb4969639fef2f083d1423cb;hpb=99e0a7c70a0185aaa75c751a2126e74dc974ed46;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/guicast/bclistbox.C b/cinelerra-5.1/guicast/bclistbox.C index 683985fe..394daac6 100644 --- a/cinelerra-5.1/guicast/bclistbox.C +++ b/cinelerra-5.1/guicast/bclistbox.C @@ -38,18 +38,10 @@ // ====================================================== scrollbars - -BC_ListBoxYScroll::BC_ListBoxYScroll(BC_ListBox *listbox, - int total_height, - int view_height, - int position) - : BC_ScrollBar(listbox->get_yscroll_x(), - listbox->get_yscroll_y(), - SCROLL_VERT, - listbox->get_yscroll_height(), - total_height, - position, - view_height) +BC_ListBoxYScroll::BC_ListBoxYScroll(BC_ListBox *listbox) + : BC_ScrollBar(listbox->get_yscroll_x(), listbox->get_yscroll_y(), + listbox->yscroll_orientation, listbox->get_yscroll_height(), + listbox->items_h, listbox->yposition, listbox->view_h) { this->listbox = listbox; } @@ -64,23 +56,10 @@ int BC_ListBoxYScroll::handle_event() return 1; } - - - - - - -BC_ListBoxXScroll::BC_ListBoxXScroll(BC_ListBox *listbox, - int total_width, - int view_width, - int position) - : BC_ScrollBar(listbox->get_xscroll_x(), - listbox->get_xscroll_y(), - SCROLL_HORIZ, - listbox->get_xscroll_width(), - total_width, - position, - view_width) +BC_ListBoxXScroll::BC_ListBoxXScroll(BC_ListBox *listbox) + : BC_ScrollBar(listbox->get_xscroll_x(), listbox->get_xscroll_y(), + listbox->xscroll_orientation, listbox->get_xscroll_width(), + listbox->items_w, listbox->xposition, listbox->view_w) { this->listbox = listbox; } @@ -96,12 +75,6 @@ int BC_ListBoxXScroll::handle_event() } - - - - - - BC_ListBoxToggle::BC_ListBoxToggle(BC_ListBox *listbox, BC_ListBoxItem *item, int x, @@ -361,6 +334,8 @@ BC_ListBox::BC_ListBox(int x, new_value = 0; need_xscroll = 0; need_yscroll = 0; + xscroll_orientation = SCROLL_HORIZ; + yscroll_orientation = SCROLL_VERT; bg_tile = 0; bg_draw = 1; drag_popup = 0; @@ -432,6 +407,7 @@ BC_ListBox::BC_ListBox(int x, // reset the search engine //printf("BC_ListBox::BC_ListBox 4\n"); + show_query = 0; reset_query(); //printf("BC_ListBox::BC_ListBox 5\n"); } @@ -732,9 +708,10 @@ void BC_ListBox::calculate_last_coords_recursive( // Lowest right icon coordinate. current_icon_x = item->icon_x; if(current_icon_x > *icon_x) *icon_x = current_icon_x; - if(current_icon_x + get_item_w(item) > *next_icon_x) + if(current_icon_x + get_item_w(item) > *next_icon_x) { *next_icon_x = current_icon_x + get_item_w(item); - + *next_icon_y = 0; + } current_icon_y = item->icon_y + get_item_h(item); if(current_icon_y > *next_icon_y) *next_icon_y = current_icon_y; @@ -1059,7 +1036,7 @@ int BC_ListBox::get_text_w(BC_ListBoxItem *item) int BC_ListBox::get_text_h(BC_ListBoxItem *item) { int h = item->get_text_h(); - if( h < 0 ) item->set_text_h(h = get_text_height(MEDIUMFONT)); + if( h < 0 ) item->set_text_h(h = get_text_height(MEDIUMFONT, item->get_text())); return h; } @@ -1129,8 +1106,8 @@ int BC_ListBox::get_items_height(ArrayList *data, int x, y, w, h; BC_ListBoxItem *item = data[master_column].values[j]; - if(display_format == LISTBOX_ICONS) - { + if( display_format == LISTBOX_ICONS || + display_format == LISTBOX_ICON_LIST ) { get_icon_mask(item, x, y, w, h); if(y + h + yposition > highest) highest = y + h + yposition; @@ -1141,8 +1118,6 @@ int BC_ListBox::get_items_height(ArrayList *data, { get_text_mask(item, x, y, w, h); *result += h; - - // Descend into sublist if(item->get_sublist() && item->get_expand()) @@ -1154,9 +1129,7 @@ int BC_ListBox::get_items_height(ArrayList *data, } } - if((display_format == LISTBOX_TEXT || - display_format == LISTBOX_ICON_LIST) && - top_level) + if( display_format == LISTBOX_TEXT && top_level ) { highest = LISTBOX_MARGIN + *result; } @@ -1236,6 +1209,13 @@ void BC_ListBox::set_autoplacement(ArrayList *data, } +void BC_ListBox::set_scroll_stretch(int xv, int yv) +{ + if( xv >= 0 ) xscroll_orientation = + !xv ? SCROLL_HORIZ : SCROLL_HORIZ + SCROLL_STRETCH; + if( yv >= 0 ) yscroll_orientation = + !yv ? SCROLL_VERT : SCROLL_VERT + SCROLL_STRETCH; +} int BC_ListBox::get_yscroll_x() { @@ -1364,6 +1344,8 @@ int BC_ListBox::get_text_mask(BC_ListBoxItem *item, { w = get_text_width(MEDIUMFONT, item->text) + LISTBOX_MARGIN * 2; h = row_height; + int ih = get_icon_h(item); + if( h < ih ) h = ih; } return 0; } @@ -1809,7 +1791,11 @@ int BC_ListBox::select_next(int skip, void BC_ListBox::clamp_positions() { items_w = get_items_width(); + if( xscroll_orientation & SCROLL_STRETCH ) + items_w += view_w / 4; items_h = get_items_height(data, columns); + if( yscroll_orientation & SCROLL_STRETCH ) + items_h += view_h / 4; if(yposition < 0) yposition = 0; else @@ -1970,11 +1956,8 @@ int BC_ListBox::get_scrollbars() { if(!xscrollbar) { - destination->add_subwindow(xscrollbar = - new BC_ListBoxXScroll(this, - w_needed, - view_w, - xposition)); + xscrollbar = new BC_ListBoxXScroll(this); + destination->add_subwindow(xscrollbar); xscrollbar->show_window(0); xscrollbar->bound_to = this; } @@ -1997,11 +1980,8 @@ int BC_ListBox::get_scrollbars() { if(!yscrollbar) { - destination->add_subwindow(yscrollbar = - new BC_ListBoxYScroll(this, - h_needed, - view_h, - yposition)); + yscrollbar = new BC_ListBoxYScroll(this); + destination->add_subwindow(yscrollbar); yscrollbar->show_window(0); yscrollbar->bound_to = this; } @@ -2254,7 +2234,7 @@ int BC_ListBox::reposition_item(ArrayList *data, void BC_ListBox::move_selection(ArrayList *dst, ArrayList *src) { - for(int i = 0; i < src[master_column].total; i++) + for(int i = 0; i < src[master_column].total; ) { BC_ListBoxItem *item = src[master_column].values[i]; @@ -2266,14 +2246,15 @@ void BC_ListBox::move_selection(ArrayList *dst, dst[j].append(src[j].values[i]); src[j].remove_number(i); } + continue; } - else // Descend into sublist if(item->get_sublist()) { move_selection(dst, item->get_sublist()); } + ++i; } } @@ -2285,7 +2266,7 @@ int BC_ListBox::put_selection(ArrayList *data, int temp = -1; if(!counter) counter = &temp; - if(destination < 0) + if(destination < 0 || destination >= data[master_column].total) { for(int j = 0; j < columns; j++) { @@ -2475,6 +2456,7 @@ int BC_ListBox::repeat_event(int64_t duration) return rectangle_scroll_event(); break; + case DRAG_ITEM: case SELECT: if(duration == get_resources()->scroll_repeat) return select_scroll_event(); @@ -2482,12 +2464,11 @@ int BC_ListBox::repeat_event(int64_t duration) case NO_OPERATION: // Show tooltip - if(button_highlighted && is_popup && !tooltip_done && + if(button_highlighted && is_popup && tooltip_text && tooltip_text[0] != 0 && duration == get_resources()->tooltip_delay) { show_tooltip(); - tooltip_done = 1; return 1; } break; @@ -3733,6 +3714,7 @@ int BC_ListBox::drag_start_event() } current_operation = DRAG_ITEM; + set_repeat(get_resources()->scroll_repeat); return 1; } } @@ -3810,6 +3792,7 @@ int BC_ListBox::drag_stop_event() 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 && @@ -3838,22 +3821,15 @@ int BC_ListBox::drag_stop_event() // Move rows if(process_drag) { -// Get destination - int destination = highlighted_item = item_to_index(data, - highlighted_ptr); -//printf("BC_ListBox::drag_stop_event 1 %p %d\n", highlighted_ptr, destination); - // Move selected items from data to temporary ArrayList *src_items = new ArrayList[columns]; - move_selection(src_items, data); - +// Get destination + int destination = highlighted_item = item_to_index(data, + highlighted_ptr); // Insert items from temporary to data - put_selection(data, - src_items, - destination); - + put_selection(data, src_items, destination); delete [] src_items; set_autoplacement(data, 0, 1); @@ -3925,8 +3901,6 @@ int BC_ListBox::reposition_window(int x, int y, int w, int h, int flush) if(!is_popup) { - if(w != -1) popup_w = w; - if(h != -1) popup_h = h; if(xscrollbar) xscrollbar->reposition_window(get_xscroll_x(), get_xscroll_y(), @@ -3947,6 +3921,7 @@ int BC_ListBox::reposition_window(int x, int y, int w, int h, int flush) int BC_ListBox::deactivate() { + hide_tooltip(); // printf("BC_ListBox::deactivate %d this=%p gui=%p active=%d\n", // __LINE__, // this, @@ -3982,69 +3957,45 @@ int BC_ListBox::deactivate() int BC_ListBox::activate(int take_focus) { -//printf("BC_ListBox::activate %d %p\n", __LINE__, this); - if(!active) - { - if(take_focus) - { - top_level->active_subwindow = this; - active = 1; - } - - button_releases = 0; - -// Test for existence of GUI in case this was previously called without -// take_focus & again with take_focus - if(is_popup && !gui) - { - Window tempwin; - int x, y; - int new_x, new_y; - y = get_y() + get_h(); - if(justify == LISTBOX_RIGHT) - { - x = get_x() - popup_w + get_w(); - } - else - { - x = get_x(); - } - - - XTranslateCoordinates(top_level->display, - parent_window->win, - top_level->rootwin, - x, - y, - &new_x, - &new_y, - &tempwin); - - if(new_x < 0) new_x = 0; - if(new_y + popup_h > top_level->get_root_h(0)) - new_y -= get_h() + popup_h; - - add_subwindow(gui = new BC_Popup(this, - new_x, - new_y, - popup_w, - popup_h, - -1, - 0, - 0)); -// Avoid top going out of screen - if(new_y < 0 ) - new_y = 2; -//printf("BC_ListBox::activate %d this=%p %p\n", __LINE__, this, gui->win); - draw_items(1); - gui->show_window(1); - } -//printf("BC_ListBox::activate %d %p\n", __LINE__, this); -//sleep(1); - } + if( active ) return 0; + active = 1; + if( take_focus ) + set_active_subwindow(this); + button_releases = 0; + if( !is_popup || gui ) return 0; + int wx = get_x(), wy = get_y() + get_h(); + if( justify == LISTBOX_RIGHT ) wx += get_w() - popup_w; + Window xwin; + int abs_x, abs_y; + XTranslateCoordinates(top_level->display, + parent_window->win, top_level->rootwin, + wx, wy, &abs_x, &abs_y, &xwin); + if( x <= 0 ) x = 2; + if( y <= 0 ) y = 2; + return activate(abs_x, abs_y); +} + +int BC_ListBox::activate(int x, int y, int w, int h) +{ + if( !is_popup || gui ) return 0; + active = 1; + if(w != -1) popup_w = w; + if(h != -1) popup_h = h; + reset_query(); + if( y + popup_h > top_level->get_root_h(0) ) + y -= get_h() + popup_h; + add_subwindow(gui = new BC_Popup(this, + x, y, popup_w, popup_h, -1, 0, 0)); + draw_items(1); + gui->show_window(1); return 0; } +int BC_ListBox::is_active() +{ + return active; +} + int BC_ListBox::keypress_event() { if(!active) return 0; @@ -4060,7 +4011,6 @@ int BC_ListBox::keypress_event() { case ESC: case RETURN: - case BACKSPACE: top_level->deactivate(); // If user is manipulating popup with keyboard, don't pass on event. @@ -4161,7 +4111,12 @@ 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(); + } redraw = 1; result = 1; } @@ -4216,6 +4171,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; + xposition = 0; yposition = 0; if( redraw && gui ) draw_items(1, 1); } @@ -4428,9 +4384,14 @@ void BC_ListBox::draw_text_recursive(ArrayList *data, gui->set_color(row_color); gui->draw_box(x, y, column_width, h); gui->set_color(BLACK); - int yy = y, xx = x + column_width-1; - gui->draw_line(x, yy, xx, yy); - yy = y + row_height; + int xx = x + column_width-1; + gui->draw_line(x, y, xx, y); + int hh = row_height; + if( display_format == LISTBOX_ICON_LIST ) { + int ih = get_icon_h(item); + if( ih > hh ) hh = ih; + } + int yy = y + hh-1; gui->draw_line(x, yy, xx, yy); }