Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcfilebox.C
index fa2f8b24401483dc332e28db2a8cd5ace6419d20..638081f5166a0c861d0139f88fab3801008e17cc 100644 (file)
 #include <sys/stat.h>
 
 
-
-
-
-
-
 BC_FileBoxRecent::BC_FileBoxRecent(BC_FileBox *filebox, int x, int y)
- : BC_ListBox(x, y, 250,
+ : BC_ListBox(x, y, xS(250),
                filebox->get_text_height(MEDIUMFONT) * FILEBOX_HISTORY_SIZE +
                BC_ScrollBar::get_span(SCROLL_HORIZ) +
                LISTBOX_MARGIN * 2, LISTBOX_TEXT, &filebox->recent_dirs,
                0, 0, 1, 0, 1)
 {
        this->filebox = filebox;
+       set_tooltip(_("Recent paths"));
 }
 
 int BC_FileBoxRecent::handle_event()
@@ -64,15 +60,6 @@ int BC_FileBoxRecent::handle_event()
 }
 
 
-
-
-
-
-
-
-
-
-
 BC_FileBoxListBox::BC_FileBoxListBox(int x, int y, BC_FileBox *filebox)
  : BC_ListBox(x, y, filebox->get_listbox_w(), filebox->get_listbox_h(y),
                filebox->get_display_mode(), filebox->list_column,
@@ -103,14 +90,8 @@ int BC_FileBoxListBox::selection_changed()
                filebox->column_of_type(FILEBOX_NAME), 0);
 
        if(item) {
-               char path[BCTEXTLEN];
-               strcpy(path, item->get_text());
-               filebox->textbox->update(path);
-               filebox->fs->extract_dir(filebox->directory, path);
-               filebox->fs->extract_name(filebox->filename, path);
-               filebox->fs->complete_path(path);
-               strcpy(filebox->current_path, path);
-               strcpy(filebox->submitted_path, path);
+               filebox->textbox->update(item->get_text());
+               filebox->update_paths(item->get_text());
        }
        return 1;
 }
@@ -173,7 +154,7 @@ int BC_FileBoxListBox::evaluate_query(char *string)
 
 
 BC_FileBoxTextBox::BC_FileBoxTextBox(int x, int y, BC_FileBox *filebox)
- : BC_TextBox(x, y, filebox->get_w() - 20, 1,
+ : BC_TextBox(x, y, filebox->get_w() - x - xS(20), 1,
        filebox->want_directory ?  filebox->directory : filebox->filename)
 {
        this->filebox = filebox;
@@ -185,17 +166,17 @@ BC_FileBoxTextBox::~BC_FileBoxTextBox()
 
 int BC_FileBoxTextBox::handle_event()
 {
-       int result = 0;
-       if(get_keypress() != RETURN)
-       {
+       int key = get_keypress(), result = 1;
+       if( !key || key == RETURN ) // not a text update
+               filebox->update_paths(filebox->textbox->get_text());
+       else
                result = calculate_suggestions(&filebox->list_column[0]);
-       }
        return result;
 }
 
 
-BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, BC_FileBox *filebox)
- : BC_TextBox(x, y, filebox->get_w() - 40, 1, filebox->fs->get_current_dir())
+BC_FileBoxDirectoryText::BC_FileBoxDirectoryText(int x, int y, int w, BC_FileBox *filebox)
+ : BC_TextBox(x, y, w, 1, filebox->fs->get_current_dir())
 {
        this->filebox = filebox;
 }
@@ -223,7 +204,7 @@ int BC_FileBoxDirectoryText::handle_event()
 
 
 BC_FileBoxSearchText::BC_FileBoxSearchText(int x, int y, BC_FileBox *filebox)
- : BC_TextBox(x, y, filebox->get_w() - x - 40, 1, "")
+ : BC_TextBox(x, y, filebox->get_w() - x - xS(40), 1, "")
 {
        this->filebox = filebox;
 }
@@ -236,7 +217,7 @@ int BC_FileBoxSearchText::handle_event()
 
 
 BC_FileBoxFilterText::BC_FileBoxFilterText(int x, int y, BC_FileBox *filebox)
- : BC_TextBox(x, y, filebox->get_w() - x - 50, 1, filebox->get_resources()->filebox_filter)
+ : BC_TextBox(x, y, filebox->get_w() - x - xS(50), 1, filebox->get_resources()->filebox_filter)
 {
        this->filebox = filebox;
 }
@@ -249,7 +230,7 @@ int BC_FileBoxFilterText::handle_event()
 
 
 BC_FileBoxFilterMenu::BC_FileBoxFilterMenu(int x, int y, BC_FileBox *filebox)
- : BC_ListBox(x, y, filebox->get_w() - 30, 120,
+ : BC_ListBox(x, y, filebox->get_w() - xS(30), yS(120),
        LISTBOX_TEXT, &filebox->filter_list, 0, 0, 1, 0, 1)
 {
        this->filebox = filebox;
@@ -461,7 +442,7 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
  : BC_Window(title, x, y,
        BC_WindowBase::get_resources()->filebox_w,
        BC_WindowBase::get_resources()->filebox_h,
-       400, 300, 1, 0, 1)
+       xS(450), yS(350), 1, 0, 1)
 {
        fs = new FileSystem;
 //     if(want_directory)
@@ -539,12 +520,12 @@ BC_FileBox::BC_FileBox(int x, int y, const char *init_path,
 
        if(h_padding == -1)
        {
-               h_padding = BC_WindowBase::get_resources()->ok_images[0]->get_h() -
-                       20;
+               h_padding = BC_WindowBase::get_resources()->ok_images[0]->get_h() - yS(20);
        }
        this->h_padding = h_padding;
        delete_thread = new BC_DeleteThread(this);
        rename_thread = 0;
+       y_margin = 0;
 }
 
 BC_FileBox::~BC_FileBox()
@@ -566,10 +547,12 @@ BC_FileBox::~BC_FileBox()
 
 void BC_FileBox::create_objects()
 {
+       int xs5 = xS(5), xs10 = xS(10), xs20 = xS(20);
+       int ys5 = yS(5), ys10 = yS(10);
        lock_window("BC_FileBox::create_objects");
-       int x = 10, y = 10;
+       int x = xs10, y = ys10;
        BC_Resources *resources = BC_WindowBase::get_resources();
-       int directory_title_margin = MAX(20,
+       int directory_title_margin = MAX(xs20,
                resources->filebox_text_images[0]->get_h());
 
 // Directories aren't filtered in FileSystem so skip this
@@ -595,50 +578,52 @@ void BC_FileBox::create_objects()
 
        add_subwindow(new BC_Title(x, y, caption));
 
-       x = get_w() - resources->filebox_icons_images[0]->get_w() - 10;
+       x = get_w() - resources->filebox_icons_images[0]->get_w() - xs10;
 
        add_subwindow(icon_button = new BC_FileBoxIcons(x, y, this));
-       x -= resources->filebox_text_images[0]->get_w() + 5;
+       x -= resources->filebox_text_images[0]->get_w() + xs5;
 
        add_subwindow(text_button = new BC_FileBoxText(x, y, this));
-       x -= resources->filebox_newfolder_images[0]->get_w() + 5;
+       x -= resources->filebox_newfolder_images[0]->get_w() + xs5;
 
        add_subwindow(folder_button = new BC_FileBoxNewfolder(x, y, this));
-       x -= resources->filebox_delete_images[0]->get_w() + 5;
+       x -= resources->filebox_delete_images[0]->get_w() + xs5;
 
        add_subwindow(rename_button = new BC_FileBoxRename(x, y, this));
-       x -= resources->filebox_delete_images[0]->get_w() + 5;
+       x -= resources->filebox_delete_images[0]->get_w() + xs5;
 
        add_subwindow(delete_button = new BC_FileBoxDelete(x, y, this));
-       x -= resources->filebox_reload_images[0]->get_w() + 5;
+       x -= resources->filebox_reload_images[0]->get_w() + xs5;
 
        add_subwindow(reload_button = new BC_FileBoxReload(x, y, this));
-       x -= resources->filebox_updir_images[0]->get_w() + 5;
+       x -= resources->filebox_updir_images[0]->get_w() + xs5;
 
        add_subwindow(updir_button = new BC_FileBoxUpdir(x, y, this));
-       x -= resources->filebox_szfmt_images[0]->get_w() + 5;
+       x -= resources->filebox_szfmt_images[0]->get_w() + xs5;
 
        add_subwindow(szfmt_button = new BC_FileBoxSizeFormat(x, y, this));
 
-       x = 10;
-       y += directory_title_margin + 3;
+       x = xs10;
+       y += directory_title_margin + yS(3);
 
        add_subwindow(recent_popup = new BC_FileBoxRecent(this, x, y));
-       add_subwindow(directory_title = new BC_FileBoxDirectoryText(x, y, this));
-       directory_title->reposition_window(x, y, get_w() - recent_popup->get_w() -  20, 1);
-       x += directory_title->get_w() + 8;
-       recent_popup->reposition_window(x, y, directory_title->get_w(), 200);
+       BC_Title *dir_title;
+       add_subwindow(dir_title = new BC_Title(x, y, _("Directory:")));
+       int x1 = x + dir_title->get_w() + xs10, w1 = get_w()-x1 - recent_popup->get_w()-xs20;
+       add_subwindow(directory_title = new BC_FileBoxDirectoryText(x1, y, w1, this));
+       x1 += directory_title->get_w() + xS(8);
+       recent_popup->reposition_window(x1, y, directory_title->get_w(), yS(200));
 
-       x = 10;
-       y += directory_title->get_h() + 5;
+       x = xs10;
+       y += directory_title->get_h() + ys5;
 
        BC_Title *search_title;
        add_subwindow(search_title = new BC_Title(x, y, _("Search:")));
-       x += search_title->get_w() + 10;
+       x += search_title->get_w() + xs10;
        add_subwindow(search_text = new BC_FileBoxSearchText(x, y, this));
 
-       x = 10;
-       y += search_text->get_h() + 5;
+       x = xs10;
+       y += search_text->get_h() + ys5;
 
        int newest_id = 0, newest = -1;
        for(int i = 0; i < FILEBOX_HISTORY_SIZE; i++) {
@@ -664,17 +649,21 @@ void BC_FileBox::create_objects()
 
        listbox = 0;
        create_listbox(x, y, get_display_mode());
-       y += listbox->get_h() + 10;
-       add_subwindow(textbox = new BC_FileBoxTextBox(x, y, this));
-       y += textbox->get_h() + 10;
+       y += listbox->get_h() + ys10;
+       add_subwindow(file_title = new BC_Title(x, y, _("File:")));
+       x1 = x + file_title->get_w() + xs10;
+       add_subwindow(textbox = new BC_FileBoxTextBox(x1, y, this));
+       y += textbox->get_h() + ys10;
 
        if(!want_directory) {
                add_subwindow(filter_title = new BC_Title(x, y, _("Specify filter:")));
-               int x1 = x + filter_title->get_w() + 10;
+               int x1 = x + filter_title->get_w() + xs10;
                add_subwindow(filter_text = new BC_FileBoxFilterText(x1, y, this));
                add_subwindow(filter_popup =
                        new BC_FileBoxFilterMenu(x1 + filter_text->get_w(), y, this));
+               y += filter_text->get_h() + ys10;
        }
+       y_margin = y;
 
 // listbox has to be active because refresh might be called from newfolder_thread
        listbox->activate();
@@ -684,17 +673,18 @@ void BC_FileBox::create_objects()
 
        refresh();
        show_window();
+       raise_window();
        unlock_window();
 }
 
 int BC_FileBox::get_listbox_w()
 {
-       return get_w() - 20;
+       return get_w() - xS(20);
 }
 
 int BC_FileBox::get_listbox_h(int y)
 {
-       int result = get_h() - y - h_padding - 10;
+       int result = get_h() - y - h_padding - yS(10);
        if(want_directory)
                result -= BC_WindowBase::get_resources()->dirbox_margin;
        else
@@ -718,64 +708,58 @@ int BC_FileBox::resize_event(int w, int h)
 {
        draw_background(0, 0, w, h);
        flash(0);
+       int dw = w - get_w();
+       int dh = h - get_h();
 
 // OK button handles resize event itself
 //     ok_button->reposition_window(ok_button->get_x(),
-//             h - (get_h() - ok_button->get_y()));
-//     cancel_button->reposition_window(w - (get_w() - cancel_button->get_x()),
-//             h - (get_h() - cancel_button->get_y()));
+//             ok_button->get_y() + dh);
+//     cancel_button->reposition_window(cancel_button->get_x() + dw,
+//             cancel_button->get_y() + dh);
        if(usethis_button)
-               usethis_button->reposition_window(w / 2 - 50,
-                       h - (get_h() - usethis_button->get_y()));
+               usethis_button->reposition_window(w / 2 - xS(50),
+                       usethis_button->get_y() + dh);
 
 
-       if(filter_popup) filter_popup->reposition_window(w - (get_w() - filter_popup->get_x()),
-               h - (get_h() - filter_popup->get_y()),
-               w - 30,
-               0);
+       if(filter_popup)
+               filter_popup->reposition_window(filter_popup->get_x() + dw,
+                       filter_popup->get_y() + dh, w - xS(30), 0);
 
-       if(filter_title) filter_title->reposition_window(filter_title->get_x(),
-               h - (get_h() - filter_title->get_y()));
+       if(filter_title)
+               filter_title->reposition_window(filter_title->get_x(),
+                       filter_title->get_y() + dh);
        if(filter_text) filter_text->reposition_window(filter_text->get_x(),
-               h - (get_h() - filter_text->get_y()),
-               w - (get_w() - filter_text->get_w()),
-               1);
+               filter_text->get_y() + dh, filter_text->get_w() + dw, 1);
        directory_title->reposition_window(
-               directory_title->get_x(),
-               directory_title->get_y(),
-               get_w() - recent_popup->get_w() -  20,
-               1);
+               directory_title->get_x(), directory_title->get_y(),
+               get_w()-directory_title->get_x() - recent_popup->get_w()-xS(20), 1);
        recent_popup->reposition_window(
-               directory_title->get_x() + directory_title->get_w() + 8,
+               directory_title->get_x() + directory_title->get_w() + xS(8),
                directory_title->get_y(),
-               directory_title->get_w() + recent_popup->get_w(),
-               recent_popup->get_h());
+               directory_title->get_w() + recent_popup->get_w(), xS(200));
        search_text->reposition_window(
-               search_text->get_x(),
-               search_text->get_y(),
-               get_w() - search_text->get_x() -  40,
-               1);
+               search_text->get_x(), search_text->get_y(),
+               get_w() - search_text->get_x() -  xS(40), 1);
+       file_title->reposition_window(file_title->get_x(),
+               file_title->get_y() + dh);
        textbox->reposition_window(textbox->get_x(),
-               h - (get_h() - textbox->get_y()),
-               w - (get_w() - textbox->get_w()),
-               1);
-       listbox->reposition_window(listbox->get_x(),
-               listbox->get_y(),
-               w - (get_w() - listbox->get_w()),
-               h - (get_h() - listbox->get_h()),
-               0);
-       int dx = w - get_w();
-       icon_button->reposition_window(icon_button->get_x()+dx, icon_button->get_y());
-       text_button->reposition_window(text_button->get_x()+dx, text_button->get_y());
-       folder_button->reposition_window(folder_button->get_x()+dx, folder_button->get_y());
-       rename_button->reposition_window(rename_button->get_x()+dx, rename_button->get_y());
-       reload_button->reposition_window(reload_button->get_x()+dx, reload_button->get_y());
-       delete_button->reposition_window(delete_button->get_x()+dx, delete_button->get_y());
-       updir_button->reposition_window(updir_button->get_x()+dx, updir_button->get_y());
-       szfmt_button->reposition_window(szfmt_button->get_x()+dx, szfmt_button->get_y());
+               textbox->get_y() + dh, textbox->get_w() + dw, 1);
+       listbox->reposition_window(listbox->get_x(), listbox->get_y(),
+               listbox->get_w() + dw, listbox->get_h() + dh, 0);
+       icon_button->reposition_window(icon_button->get_x()+dw, icon_button->get_y());
+       text_button->reposition_window(text_button->get_x()+dw, text_button->get_y());
+       folder_button->reposition_window(folder_button->get_x()+dw, folder_button->get_y());
+       rename_button->reposition_window(rename_button->get_x()+dw, rename_button->get_y());
+       reload_button->reposition_window(reload_button->get_x()+dw, reload_button->get_y());
+       delete_button->reposition_window(delete_button->get_x()+dw, delete_button->get_y());
+       updir_button->reposition_window(updir_button->get_x()+dw, updir_button->get_y());
+       szfmt_button->reposition_window(szfmt_button->get_x()+dw, szfmt_button->get_y());
        set_w(w);  set_h(h);
        get_resources()->filebox_w = get_w();
        get_resources()->filebox_h = get_h();
+       y_margin = filter_text ?
+               filter_text->get_y() + filter_text->get_h() + yS(10) :
+               textbox->get_y() + textbox->get_h() + yS(10) ;
        flush();
        return 1;
 }
@@ -796,7 +780,7 @@ int BC_FileBox::keypress_event()
                set_done(1);
                return 1;
        }
-       return 0;
+       return context_help_check_and_show();
 }
 
 int BC_FileBox::close_event()
@@ -1019,6 +1003,17 @@ int BC_FileBox::update_filter(const char *filter)
 }
 
 
+void BC_FileBox::update_paths(const char *text)
+{
+       char path[BCTEXTLEN];
+       strncpy(path, text, sizeof(path)-1);
+       fs->extract_dir(directory, path);
+       fs->extract_name(filename, path);
+       fs->complete_path(path);
+       strcpy(current_path, path);
+       strcpy(submitted_path, path);
+}
+
 void BC_FileBox::move_column(int src, int dst)
 {
        if(src != dst)
@@ -1319,27 +1314,27 @@ void BC_FileBox::create_listbox(int x, int y, int mode)
                add_subwindow(listbox = new BC_FileBoxListBox(x, y, this));
 }
 
+int BC_FileBox::get_y_margin()
+{
+       return y_margin;
+}
+
 char* BC_FileBox::get_path(int selection)
 {
        if(selection == 0)
-       {
                return get_submitted_path();
-       }
-       else
-       {
-               BC_ListBoxItem *item = listbox->get_selection(
-                       column_of_type(FILEBOX_NAME), selection - 1);
-               if(item)
-               {
-                       fs->join_names(string, directory, item->get_text());
-                       return string;
-               }
+       BC_ListBoxItem *item = listbox->get_selection(
+               column_of_type(FILEBOX_NAME), selection - 1);
+       if( item ) {
+               fs->join_names(string, directory, item->get_text());
+               return string;
        }
        return 0;
 }
 
 char* BC_FileBox::get_submitted_path()
 {
+       update_paths(textbox->get_text());
        return submitted_path;
 }