add binfolder path relative filters, fix gbrp color model, vwdw timebar tweaks, title...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / swindow.C
index e88a9e1cb8c88f8165467d906586e376f55dc0aa..1604d8dbf371804fb36e6d1f938a256abc940e49 100644 (file)
@@ -76,27 +76,15 @@ SWindowLoadPath::SWindowLoadPath(SWindowGUI *gui, int x, int y, char *path)
  : BC_TextBox(x, y, 200, 1, path)
 {
        this->sw_gui = gui;
-
-       file_entries = new ArrayList<BC_ListBoxItem*>;
-       FileSystem fs;  char string[BCTEXTLEN];
-// Load current directory
-       fs.update(getcwd(string, BCTEXTLEN));
-       int total_files = fs.total_files();
-       for(int i = 0; i < total_files; i++) {
-               const char *name = fs.get_entry(i)->get_name();
-               file_entries->append(new BC_ListBoxItem(name));
-       }
 }
 
 SWindowLoadPath::~SWindowLoadPath()
 {
-       file_entries->remove_all_objects();
-       delete file_entries;
 }
 
 int SWindowLoadPath::handle_event()
 {
-       calculate_suggestions(file_entries);
+       calculate_suggestions();
        strcpy(sw_gui->script_path, get_text());
        return 1;
 }
@@ -114,9 +102,14 @@ SWindowLoadFile::~SWindowLoadFile()
 
 int SWindowLoadFile::handle_event()
 {
-       sw_gui->load_path->set_suggestions(0,0);
-       sw_gui->load_script();
-       sw_gui->set_script_pos(0);
+       if( sw_gui->script_path[0] ) {
+               sw_gui->load_path->set_suggestions(0,0);
+               sw_gui->load_script();
+               sw_gui->set_script_pos(0);
+       }
+       else {
+               eprintf(_("script text file path required"));
+       }
        return 1;
 }
 
@@ -132,7 +125,12 @@ SWindowSaveFile::~SWindowSaveFile()
 
 int SWindowSaveFile::handle_event()
 {
-       sw_gui->save_spumux_data();
+       if( sw_gui->script_path[0] ) {
+               sw_gui->save_spumux_data();
+       }
+       else {
+               eprintf(_("script microdvd file path required"));
+       }
        return 1;
 }
 
@@ -141,6 +139,7 @@ int SWindowSaveFile::handle_event()
 
 void SWindowGUI::create_objects()
 {
+       lock_window("SWindowGUI::create_objects");
        int x = 10, y = 10;
        BC_Title *title = new BC_Title(x, y, _("Path:"));
        add_subwindow(title);
@@ -183,17 +182,23 @@ void SWindowGUI::create_objects()
        x1 = x + pad;
        blank_line = new char[2];
        blank_line[0] = ' ';  blank_line[1] = 0;
-       int rows = (ok_y - y - 4*pad) / text_rowsz - 3;
-       int w1 = get_w()-x1-pad;
+       add_subwindow(script_title = new BC_Title(x1, y, _("Script Text:")));
+       y += script_title->get_h() + pad;
+       int rows = (ok_y - y - BC_Title::calculate_h(this,_("Line Text:")) -
+               4*pad) / text_rowsz - 4;
+       int w1 = get_w() - x1 - pad;
        script_entry = new ScriptEntry(this, x1, y, w1, rows, blank_line);
        script_entry->create_objects();
        y += script_entry->get_h() + pad;
-       line_entry = new ScriptEntry(this, x1, y, w1, 3);
+       add_subwindow(line_title = new BC_Title(x1, y, _("Line Text:")));
+       y += line_title->get_h() + pad;
+       line_entry = new ScriptEntry(this, x1, y, w1, 4);
        line_entry->create_objects();
        ok = new SWindowOK(this, ok_x, ok_y);
        add_subwindow(ok);
        cancel = new SWindowCancel(this, cancel_x, cancel_y);
        add_subwindow(cancel);
+       unlock_window();
 }
 
 void SWindowGUI::load()
@@ -315,11 +320,15 @@ int SWindowGUI::resize_event(int w, int h)
        int w1 = w - x1 - pad;
        script_scroll->reposition_window(x1, y, w1);
        y += hh + 2*pad;
+       script_title->reposition_window(x, y);
+       y += script_title->get_h() + pad;
        w1 = w - x - pad;
-       int rows = (ok_y - y - 4*pad) / text_rowsz - 3;
+       int rows = (ok_y - y - line_title->get_h() - 4*pad) / text_rowsz - 4;
        script_entry->reposition_window(x, y, w1, rows);
-       y += script_entry->get_h() + pad;
-       line_entry->reposition_window(x, y, w1, 3);
+       y += script_entry->get_h() + 2*pad;
+       line_title->reposition_window(x, y);
+       y += line_title->get_h() + pad;
+       line_entry->reposition_window(x, y, w1, 4);
        return 0;
 }
 
@@ -349,6 +358,7 @@ void SWindowGUI::set_script_pos(int64_t entry_no, int text_no)
 
 int SWindowGUI::load_selection(int pos, int row)
 {
+       if( pos < 0 || pos >= script.size() ) return 1;
        ScriptLines *texts = script[pos];
        char *rp = texts->get_text_row(row);
        if( !rp || *rp == '=' || *rp == '*' || *rp=='\n' ) return 1;
@@ -670,7 +680,7 @@ char *ScriptLines::get_text_row(int n)
 }
 
 ScriptScroll::ScriptScroll(SWindowGUI *gui, int x, int y, int w)
- : BC_ScrollBar(x, y, SCROLL_HORIZ, w, 0, 0, 0)
+ : BC_ScrollBar(x, y, SCROLL_HORIZ + SCROLL_STRETCH, w, 0, 0, 0)
 {
        this->sw_gui = gui;
 }
@@ -728,11 +738,26 @@ ScriptEntry::~ScriptEntry()
 void ScriptEntry::set_text(char *text, int isz)
 {
        if( !text || !*text ) return;
-       if( isz < 0 ) isz = strlen(text);
+       if( isz < 0 ) isz = strlen(text)+1;
        BC_ScrollTextBox::set_text(text, isz);
        ttext = text;
 }
 
+int ScriptEntry::handle_event()
+{
+       if( ttext && sw_gui->get_button_down() &&
+           sw_gui->get_buttonpress() == 1 &&
+           sw_gui->get_triple_click() ) {
+               int ibeam = get_ibeam_letter(), row = 0;
+               const char *tp = ttext;
+               while( *tp && tp-ttext < ibeam ) {
+                       if( *tp++ == '\n' ) ++row;
+               }
+               int pos = sw_gui->script_entry_no;
+               sw_gui->load_selection(pos, row);
+       }
+       return 1;
+}
 
 int SWindowGUI::load_script_line(FILE *fp)
 {
@@ -772,6 +797,8 @@ void SWindowGUI::load_script()
                return;
        }
        load_script(fp);
+       script_text_no = -1;
+       load_selection(script_entry_no=0, 0);
 }
 
 void SWindowGUI::load_script(FILE *fp)
@@ -783,17 +810,16 @@ void SWindowGUI::load_script(FILE *fp)
        char value[64];
        sprintf(value,"%ld",ftell(fp));
        script_filesz->update(value);
-       sprintf(value,"%ld",script_line_no);
+       sprintf(value,"%jd",script_line_no);
        script_lines->update(value);
        sprintf(value,"%d",script.size());
        script_entries->update(value);
-       sprintf(value,"%ld",script_text_lines);
+       sprintf(value,"%jd",script_text_lines);
        script_texts->update(value);
-       int hw = 2*script_scroll->get_h();
+       int hw = script_scroll->get_h();
        script_scroll->update_length(script.size(), script_entry_no, hw, 0);
        script_position->update(script_entry_no);
        script_position->set_boundaries((int64_t)0, (int64_t)script.size()-1);
-
        fclose(fp);
 }
 
@@ -812,12 +838,18 @@ void SWindowGUI::save_spumux_data()
        for( Track *track=tracks->first; track; track=track->next ) {
                if( track->data_type != TRACK_SUBTITLE ) continue;
                if( !track->record ) continue;
-               char *cp = track_title;
-               for( char *bp=track->title; *bp; ++bp,++cp )
-                       *cp = !isalnum(*bp) ? '_' : *bp;
+               char *cp = track_title, *ep = cp+sizeof(track_title)-6;
+               for( const char *bp=track->title; cp<ep && *bp!=0; ) {
+                       int b = butf8(bp), c = !iswalnum(b) ? '_' : b;
+                       butf8(c, cp);
+               }
                *cp = 0;
                snprintf(ext,len,"-%s.udvd",track_title);
                FILE *fp = fopen(filename, "w");
+               if( !fp ) {
+                       eprintf(_("Unable to open %s:\n%m"), filename);
+                       continue;
+               }
                int64_t start = 0;
                for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
                        SEdit *sedit = (SEdit *)edit;
@@ -825,7 +857,7 @@ void SWindowGUI::save_spumux_data()
                                int64_t end = start + sedit->length;
                                char *text = sedit->get_text();
                                if( *text ) {
-                                       fprintf(fp, "{%ld}{%ld}%s\n", start, end-1, text);
+                                       fprintf(fp, "{%jd}{%jd}%s\n", start, end-1, text);
                                }
                                start = end;
                        }