additional Andrew provided Termux mods +
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bclistbox.C
index e99d7316f3d0a126e1f817c58976e00ee7cf8016..df5b6f0f32c2de420208d8dc4f323aba575a3e10 100644 (file)
@@ -551,9 +551,6 @@ int BC_ListBox::draw_button(int flush)
 // Draw the button for a popup listbox
        if( use_button && is_popup ) {
                int image_number = 0;
-
-               draw_top_background(parent_window, 0, 0, w, h);
-
                if( button_highlighted )
                        image_number = 1;
                if( current_operation == BUTTON_DN )
@@ -561,8 +558,9 @@ int BC_ListBox::draw_button(int flush)
                if( disabled )
                        image_number = 3;
 
-               pixmap->draw_pixmap(button_images[image_number],
-                       0, 0, w, h, 0, 0);
+               int iw = button_images[image_number]->get_w();
+               int ih = button_images[image_number]->get_h();
+               pixmap->draw_pixmap(button_images[image_number],0,0,iw,ih);
                flash(flush);
        }
        return 0;
@@ -1223,7 +1221,7 @@ int BC_ListBox::get_text_mask(BC_ListBoxItem *item,
                h = get_text_h(item) + ICON_MARGIN * 2;
                break; }
        case LISTBOX_ICON_LIST: {
-               w = get_text_width(MEDIUMFONT, item->text) + LISTBOX_MARGIN * 2;
+               w = column_width ? column_width[0] : default_column_width[0];
                h = row_height;
                break; }
        default:
@@ -1691,17 +1689,16 @@ int BC_ListBox::get_scrollbars()
        int flush = 0;
 
        title_h = get_title_h();
-       view_h = popup_h - title_h - 4;
-       view_w = popup_w - 4;
+       view_h = popup_h - title_h - yS(4);
+       view_w = popup_w - xS(4);
 
 // Create scrollbars as needed
        for( int i=0; i<2; ++i ) {
                if( w_needed > view_w ) {
                        need_xscroll = 1;
-                       view_h = popup_h -
-                               title_h -
+                       view_h = popup_h - title_h -
                                get_resources()->hscroll_data[SCROLL_HANDLE_UP]->get_h() -
-                               4;
+                               yS(4);
                }
                else {
                        need_xscroll = 0;
@@ -1711,7 +1708,7 @@ int BC_ListBox::get_scrollbars()
                        need_yscroll = 1;
                        view_w = popup_w -
                                get_resources()->vscroll_data[SCROLL_HANDLE_UP]->get_w() -
-                               4;
+                               xS(4);
                }
                else {
                        need_yscroll = 0;
@@ -1770,10 +1767,10 @@ int BC_ListBox::get_scrollbars()
        }
 
        if( !bg_surface ||
-           view_w + 4 != bg_surface->get_w() ||
-           view_h + 4 != bg_surface->get_h() ) {
+           view_w + xS(4) != bg_surface->get_w() ||
+           view_h + yS(4) != bg_surface->get_h() ) {
                if( bg_surface ) delete bg_surface;
-               bg_surface = new BC_Pixmap(gui, view_w + 4, view_h + 4);
+               bg_surface = new BC_Pixmap(gui, view_w + xS(4), view_h + yS(4));
                bg_draw = 1;
        }
 
@@ -1781,6 +1778,19 @@ int BC_ListBox::get_scrollbars()
        return 0;
 }
 
+int BC_ListBox::get_w()
+{
+       return is_popup ? BCPOPUPLISTBOX_W : popup_w;
+}
+int BC_ListBox::get_h()
+{
+       return is_popup ? BCPOPUPLISTBOX_H : popup_h;
+}
+
+int BC_ListBox::gui_tooltip(const char *text)
+{
+       return is_popup && gui ? gui->show_tooltip(text, gui->get_w(),0, -1,-1) : -1;
+}
 
 void BC_ListBox::set_drag_scroll(int value)
 {
@@ -1817,18 +1827,18 @@ int BC_ListBox::drag_scroll_event()
                result = 1;
        }
        else
-       if( get_cursor_y() >= view_h + title_h + 4 ) {
-               yposition += get_cursor_y() - (view_h + title_h + 4);
+       if( get_cursor_y() >= view_h + title_h + yS(4) ) {
+               yposition += get_cursor_y() - (view_h + title_h + yS(4));
                result = 1;
        }
 
-       if( get_cursor_x() < 2 ) {
-               xposition -= 2 - get_cursor_x();
+       if( get_cursor_x() < xS(2) ) {
+               xposition -= xS(2) - get_cursor_x();
                result = 1;
        }
        else
-       if( get_cursor_x() >= view_w + 2 ) {
-               xposition += get_cursor_x() - (view_w + 2);
+       if( get_cursor_x() >= view_w + xS(2) ) {
+               xposition += get_cursor_x() - (view_w + xS(2));
                result = 1;
        }
 
@@ -2615,7 +2625,7 @@ int BC_ListBox::button_press_event()
 
 // Multiple item selection is possible
                        if( selection_mode == LISTBOX_MULTIPLE &&
-                           (ctrl_down() || shift_down()) ) {
+                           (ctrl_down() || shift_down() || current_item->selected) ) {
 // Expand text selection.
 // Fill items between selected region and current item.
                                if( shift_down() &&
@@ -2639,7 +2649,7 @@ int BC_ListBox::button_press_event()
                                        new_value = 1;
                                }
 // Toggle a single item on or off
-                               else {
+                               else if( ctrl_down() ) {
                                        toggle_item_selection(data, selection_number);
                                        new_value = current_item->selected;
                                }
@@ -3302,9 +3312,9 @@ int BC_ListBox::drag_stop_event()
                                reposition_item(data,
                                        selection_number,
                                        top_level->cursor_x - drag_popup->get_w() / 2 -
-                                               LISTBOX_MARGIN - 2 + xposition,
+                                               LISTBOX_MARGIN - xS(2) + xposition,
                                        top_level->cursor_y - drag_popup->get_h() / 2 -
-                                               LISTBOX_MARGIN - 2 + yposition);
+                                               LISTBOX_MARGIN - yS(2) + yposition);
                        }
                        else
 // Move rows
@@ -3439,8 +3449,8 @@ int BC_ListBox::activate(int take_focus)
        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;
+       if( x <= 0 ) x = xS(2);
+       if( y <= 0 ) y = yS(2);
        return activate(abs_x, abs_y);
 }
 
@@ -3475,7 +3485,7 @@ int BC_ListBox::expander_active()
 
 int BC_ListBox::keypress_event()
 {
-       if( !active ) return 0;
+       if( !active ) return context_help_check_and_show();
 
 //printf("BC_ListBox::keypress_event %d\n", __LINE__);
 
@@ -3547,13 +3557,13 @@ int BC_ListBox::keypress_event()
                break;
 
        case LEFT:
-               xposition -= 10;
+               xposition -= xS(10);
                redraw = 1;
                result = 1;
                break;
 
        case RIGHT:
-               xposition += 10;
+               xposition += xS(10);
                redraw = 1;
                result = 1;
                break;
@@ -3602,6 +3612,9 @@ int BC_ListBox::keypress_event()
 //printf("BC_ListBox::keypress_event %d\n", __LINE__);
        }
 
+       if( !result )
+               result = context_help_check_and_show();
+
        return result;
 }
 
@@ -3715,12 +3728,11 @@ int BC_ListBox::draw_items(int flush, int draw_bg)
                                                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);
+                                       char *item_text = display_format == LISTBOX_ICONS_PACKED ?
+                                               get_truncated_text(MEDIUMFONT, item->text, text_w) :
+                                               cstrdup(item->text);
                                        gui->draw_text(text_x, text_y + get_baseline(item), item_text);
+                                       delete [] item_text;
                                }
                                else
                                        item->set_in_view(0);