]> git.lyx.org Git - lyx.git/blobdiff - src/lyx_cb.C
Three patches from Dekel. Read ChangeLog
[lyx.git] / src / lyx_cb.C
index 95718cf7167557f8931d1704db8919ab68a5ae44..f93db63ab5b4820201290c8b340f2205e44cfc99 100644 (file)
@@ -55,6 +55,9 @@ using std::cout;
 using std::ios;
 using std::istream_iterator;
 using std::pair;
+using std::vector;
+using std::sort;
+using std::equal;
 
 extern Combox * combo_language;
 extern Combox * combo_language2;
@@ -75,6 +78,8 @@ extern FD_form_ref * fd_form_ref;
 extern FD_LaTeXOptions * fd_latex_options;
 extern FD_form_bullet * fd_form_bullet;
 
+#define XFORMS_CLIPBOARD 1
+
 extern BufferView * current_view; // called too many times in this file...
 
 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
@@ -404,10 +409,10 @@ int MakeLaTeXOutput(Buffer * buffer)
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
        }
-       if (!buffer->isDviClean()) {
+       //if (!buffer->isDviClean()) {
                Path p(path);
                ret = MenuRunLaTeX(buffer);
-       }
+               //}
        return ret;
 }
 
@@ -430,8 +435,7 @@ bool RunScript(Buffer * buffer, bool wait,
                return false;
        /* get DVI-Filename */
        if (name.empty())
-               name = ChangeExtension(buffer->getLatexName(),
-                                      ".dvi", true);
+               name = ChangeExtension(buffer->getLatexName(), ".dvi");
 
        path = OnlyPath(name);
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
@@ -507,8 +511,8 @@ bool CreatePostscript(Buffer * buffer, bool wait = false)
                return false;
         }
        // Generate postscript file
-       string psname = ChangeExtension (buffer->fileName(),
-                                        ".ps_tmp", true);
+       string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
+                                        ".ps_tmp"));
 
        string paper;
 
@@ -595,8 +599,8 @@ bool PreviewPostscript(Buffer * buffer)
 
        // Start postscript viewer
        ProhibitInput(current_view);
-       string ps = ChangeExtension (buffer->fileName(),
-                                    ".ps_tmp", true);
+       string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
+                                    ".ps_tmp"));
        // push directorypath, if necessary 
         string path = OnlyPath(buffer->fileName());
         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
@@ -621,7 +625,8 @@ void MenuFax(Buffer * buffer)
        }
 
        // Send fax
-       string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
+       string ps = OnlyFilename(ChangeExtension (buffer->fileName(), 
+                                                 ".ps_tmp"));
        string path = OnlyPath (buffer->fileName());
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = buffer->tmppath;
@@ -756,8 +761,7 @@ void MenuMakeLinuxDoc(Buffer * buffer)
        }
        
        // Get LinuxDoc-Filename
-       string s = ChangeExtension(buffer->fileName(), 
-                                  ".sgml", false);
+       string s = ChangeExtension(buffer->fileName(), ".sgml");
 
        if (!AskOverwrite(buffer, s))
                return;
@@ -784,8 +788,7 @@ void MenuMakeDocBook(Buffer * buffer)
        }
        
        // Get DocBook-Filename
-       string s = ChangeExtension(buffer->fileName(), 
-                                  ".sgml", false);
+       string s = ChangeExtension(buffer->fileName(), ".sgml");
 
        if (!AskOverwrite(buffer, s))
                return;
@@ -806,8 +809,7 @@ void MenuMakeAscii(Buffer * buffer)
        //if (!bv->text) return;
        
        /* get LaTeX-Filename */
-       string s = ChangeExtension (buffer->fileName(),
-                                   ".txt", false);
+       string s = ChangeExtension (buffer->fileName(), ".txt");
        
 
        if (!AskOverwrite(buffer, s))
@@ -825,9 +827,8 @@ void MenuPrint(Buffer * buffer)
        //if (!bv->text)
        //      return;
 
-       string input_file = ChangeExtension(buffer->fileName(),
-                                           lyxrc.print_file_extension,
-                                           true);
+       string input_file = OnlyFilename(ChangeExtension(buffer->fileName(),
+                                           lyxrc.print_file_extension));
        fl_set_input(fd_form_print->input_file, input_file.c_str());
        
        if (fd_form_print->form_print->visible) {
@@ -852,7 +853,7 @@ void MenuMakeHTML(Buffer * buffer)
        // the tex file name has to be correct for
        // latex, but the html file name can be
        // anything.
-       string result = ChangeExtension(file, ".html", false);
+       string result = ChangeExtension(file, ".html");
        string infile = buffer->getLatexName(false);
        string tmp = lyxrc.html_command;
        tmp = subst(tmp, "$$FName", infile);
@@ -879,8 +880,8 @@ void MenuMakeHTML_LinuxDoc(Buffer * buffer)
        // And now, run the converter
        string file = buffer->fileName();
 
-       string result = ChangeExtension(file, ".html", false);
-       string infile = ChangeExtension(file, ".sgml", false);
+       string result = ChangeExtension(file, ".html");
+       string infile = ChangeExtension(file, ".sgml");
        string tmp = lyxrc.linuxdoc_to_html_command;
        tmp = subst(tmp, "$$FName", infile);
        tmp = subst(tmp, "$$OutName", result);
@@ -904,8 +905,8 @@ void MenuMakeHTML_DocBook(Buffer * buffer)
 
        // And now, run the converter
        string file = buffer->fileName();
-       string result = ChangeExtension(file, ".html", false);
-       string infile = ChangeExtension(file, ".sgml", false);
+       string result = ChangeExtension(file, ".html");
+       string infile = ChangeExtension(file, ".sgml");
        string tmp = lyxrc.docbook_to_html_command;
        tmp = subst(tmp, "$$FName", infile);
        tmp = subst(tmp, "$$OutName", result);
@@ -1224,11 +1225,11 @@ void MenuInsertRef()
 }
 
 
+#ifndef XFORMS_CLIPBOARD
 void MenuPasteSelection(char at)
 {
        if (!current_view->available())
                return;
-
        ascii_type = at;
   
        Atom data_prop = XInternAtom(fl_display, 
@@ -1240,8 +1241,9 @@ void MenuPasteSelection(char at)
                          XA_PRIMARY, XA_STRING, data_prop, 
                          current_view->owner()->getForm()->window, 0);
        XFlush(fl_display);
-}
 
+}
+#endif
 
 
 
@@ -1268,7 +1270,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
        int errorcode = 0;
 
        /* generate a path-less extension name */
-       string name = ChangeExtension (filename, ".sgml", true);
+       string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
        string path = OnlyPath (filename);
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = bv->buffer()->tmppath;
@@ -1329,7 +1331,7 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
 int RunDocBook(int flag, string const & filename)
 {
        /* generate a path-less extension name */
-       string name = ChangeExtension (filename, ".sgml", true);
+       string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
        string path = OnlyPath (filename);
        if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
                path = current_view->buffer()->tmppath;
@@ -2375,10 +2377,12 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long)
        if (current_view->available()) {
                if (old_language != new_language &&
                    old_language->RightToLeft == new_language->RightToLeft && 
-                   ! current_view->buffer()->isMultiLingual() ) {
+                   ! current_view->buffer()->isMultiLingual() )
                        current_view->buffer()->ChangeLanguage(old_language,
                                                               new_language);
-                       current_view->buffer()->redraw();
+               if (old_language != new_language) {
+                       //current_view->buffer()->redraw();
+                       redo = true;
                }
        }
        params->language_info = new_language;
@@ -3103,14 +3107,7 @@ void Reconfigure(BufferView * bv)
 // Table of Contents
 //
 
-struct TocList {
-       int counter[6];
-       bool appendix;
-       TocList * next;
-};
-
-
-static TocList * toclist = 0;
+static vector<Buffer::TocItem> toclist;
 
 
 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
@@ -3118,40 +3115,19 @@ extern "C" void TocSelectCB(FL_OBJECT * ob, long)
        if (!current_view->available())
                return;
    
-       TocList * tmptoclist = toclist;
-       int i = fl_get_browser(ob);
-       for (int a = 1; a < i && tmptoclist->next; ++a) {
-               tmptoclist = tmptoclist->next;
-       }
-
-       if (!tmptoclist)
-               return;
-     
-
-       LyXParagraph * par = current_view->buffer()->paragraph;
-       while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
-                      par->GetFirstCounter(1) != tmptoclist->counter[1] ||
-                      par->GetFirstCounter(2) != tmptoclist->counter[2] ||
-                      par->GetFirstCounter(3) != tmptoclist->counter[3] ||
-                      par->GetFirstCounter(4) != tmptoclist->counter[4] ||
-                      par->GetFirstCounter(5) != tmptoclist->counter[5] ||
-                      par->appendix != tmptoclist->appendix)) {
-               par = par->LastPhysicalPar()->Next();
-       }
-   
-       if (par) {
-               current_view->beforeChange();
-               current_view->text->SetCursor(par, 0);
+       TocUpdateCB(0, 0);
+       unsigned int choice = fl_get_browser(ob);
+       if (0 < choice && choice - 1 < toclist.size()) {
+               current_view->beforeChange();
+               current_view->text->SetCursor(toclist[choice-1].par, 0);
                current_view->text->sel_cursor = 
                        current_view->text->cursor;
                current_view->update(0);
-       }
-       else {
+       } else {
                WriteAlert(_("Error"), 
                           _("Couldn't find this label"), 
                           _("in current document."));
        }
-         
 }
 
 
@@ -3161,106 +3137,54 @@ extern "C" void TocCancelCB(FL_OBJECT *, long)
 }
 
 
-extern "C" void TocUpdateCB(FL_OBJECT *, long)
+extern "C"
+void TocUpdateCB(FL_OBJECT *, long)
 {
-       static LyXParagraph * stapar = 0;
-       TocList * tmptoclist = 0;
-   
-       /* deleted the toclist */ 
-       if (toclist){
-               while (toclist){
-                       tmptoclist = toclist->next;
-                       delete toclist;
-                       toclist = tmptoclist;
-               }
-       }
-       toclist = 0;
-       tmptoclist = toclist;
-
-
-       fl_clear_browser(fd_form_toc->browser_toc);
        if (!current_view->available()) {
+               toclist.clear();
+               fl_clear_browser(fd_form_toc->browser_toc);
                fl_add_browser_line(fd_form_toc->browser_toc,
                                    _("*** No Document ***"));
                return;
        }
-       fl_hide_object(fd_form_toc->browser_toc);
-       /* get the table of contents */ 
-       LyXParagraph * par = current_view->buffer()->paragraph;
-       char labeltype;
-       char * line = new char[200];
-       int pos = 0;
-       unsigned char c;
-       int topline = 0;
-   
-       if (stapar == par)
-               topline = fl_get_browser_topline(fd_form_toc->browser_toc);
-       stapar = par;
-   
-       while (par) {
-               labeltype = textclasslist.Style(current_view->buffer()->params.textclass, 
-                                               par->GetLayout()).labeltype;
-      
-               if (labeltype >= LABEL_COUNTER_CHAPTER
-                   && labeltype <= LABEL_COUNTER_CHAPTER +
-                   current_view->buffer()->params.tocdepth) {
-                       /* insert this into the table of contents */ 
-                       /* first indent a little bit */ 
-                       
-                       for (pos = 0; 
-                            pos < (labeltype - 
-                                   textclasslist.TextClass(current_view->buffer()->
-                                                           params.textclass).maxcounter()) * 4 + 2;
-                            ++pos)
-                               line[pos] = ' ';
-                       
-                       // Then the labestring
-                       if (!par->labelstring.empty()) {
-                               string::size_type i = 0;
-                               while (pos < 199 && i < par->labelstring.length()) {
-                                       line[pos] = par->labelstring[i];
-                                       ++i;
-                                       ++pos;
-                               }
-                       }
-        
-                       line[pos] = ' ';
-                       ++pos;
-                       
-                       /* now the contents */
-                       LyXParagraph::size_type i = 0;
-                       while (pos < 199 && i < par->size()) {
-                               c = par->GetChar(i);
-                               if (isprint(c) || c >= 128) {
-                                       line[pos] = c;
-                                       ++pos;
-                               }
-                               ++i;
-                       }
-                       line[pos] = '\0';
-                       fl_add_browser_line(fd_form_toc->browser_toc, line);
-                       
-                       /* make a toclist entry */
-                       if (!tmptoclist){
-                               tmptoclist = new TocList;
-                               toclist = tmptoclist;
-                       } else {
-                               tmptoclist->next = new TocList;
-                               tmptoclist = tmptoclist->next;
-                       }
-                       
-                       tmptoclist->next = 0;
-                       int a = 0;
-                       for (a = 0; a < 6; ++a) {
-                               tmptoclist->counter[a] = par->GetFirstCounter(a);
-                       }
-                       tmptoclist->appendix = par->appendix;
+
+       vector<vector<Buffer::TocItem> > tmp =
+               current_view->buffer()->getTocList();
+       int type = fl_get_choice(fd_form_toc->toctype)-1;
+       //if (toclist == tmp[type])
+       //      return;
+       if (toclist.size() == tmp[type].size()) {
+               // Check if all elements are the same.
+               unsigned int i = 0;
+               for (; i < toclist.size(); ++i) {
+                       if (toclist[i] !=  tmp[type][i])
+                               break;
                }
-               par = par->LastPhysicalPar()->Next();
-               
+               if (i >= toclist.size()) return;
        }
-       delete[] line;
+
+       toclist = tmp[type];
+
+       static Buffer * buffer = 0;
+       int topline = 0;
+       int line = 0;
+       if (buffer == current_view->buffer()) {
+               topline = fl_get_browser_topline(fd_form_toc->browser_toc);
+               line = fl_get_browser(fd_form_toc->browser_toc);
+       } else
+               buffer = current_view->buffer();
+
+       fl_clear_browser(fd_form_toc->browser_toc);
+       fl_hide_object(fd_form_toc->browser_toc);
+
+       for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
+            it != toclist.end(); ++it)
+               fl_add_browser_line(fd_form_toc->browser_toc,
+                                   (string(4*(*it).depth,' ')+
+                                    (*it).str).c_str());
+
        fl_set_browser_topline(fd_form_toc->browser_toc, topline);
+       fl_select_browser_line(fd_form_toc->browser_toc, line);
        fl_show_object(fd_form_toc->browser_toc);
 }
 
@@ -3279,18 +3203,28 @@ extern "C" void RefSelectCB(FL_OBJECT *, long data)
        if (s.empty())
                return;
 
-        if (data == 2) {
+        if (data == 5) {
                 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
+               if (!current_view->NoSavedPositions()) {
+                       fl_activate_object(fd_form_ref->back);
+                       fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
+               }
                return;
-       }
-           
-       string t;
-       if (data == 0)
-               t += "\\ref";
-       else
-               t += "\\pageref";
+       } else if (data >= 6) {
+               current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK);
+               if (current_view->NoSavedPositions()) {
+                       fl_deactivate_object(fd_form_ref->back);
+                       fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
+               }
+               return;
+       }       
+
+       static string const commands[5]
+               = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
+                   "\\prettyref"};
+       string t = commands[data];
 
-       if(current_view->buffer()->isSGML())
+       if (current_view->buffer()->isSGML())
                t += "[" + u + "]" + "{" + s + "}";
        else
                t += "{" + s + "}";
@@ -3316,11 +3250,16 @@ extern "C" void RefUpdateCB(FL_OBJECT *, long)
        string currentstr = btmp ? btmp : "";
 
        fl_clear_browser(brow);
+       fl_hide_object(brow);
 
-       string refs = current_view->buffer()->getReferenceList('\n');
-       int topline = 1;
+       vector<string> refs = current_view->buffer()->getLabelList();
+       if (fl_get_button(fd_form_ref->sort))
+               sort(refs.begin(),refs.end());
+       for (vector<string>::const_iterator it = refs.begin();
+            it != refs.end(); ++it)
+               fl_add_browser_line(brow, (*it).c_str());
 
-       fl_addto_browser_chars(brow, refs.c_str());
+       int topline = 1;
        int total_lines = fl_get_browser_maxline(brow);
        for (int i = 1; i <= total_lines ; ++i) {
                if (fl_get_browser_line(brow, i) == currentstr) {
@@ -3330,27 +3269,68 @@ extern "C" void RefUpdateCB(FL_OBJECT *, long)
        }
        fl_set_browser_topline(brow, topline);
 
-       if (!fl_get_browser_maxline(brow)) {
+       bool empty = refs.empty();
+       bool sgml = current_view->buffer()->isSGML();
+       bool readonly = current_view->buffer()->isReadonly();
+
+       if (current_view->NoSavedPositions()) {
+               fl_deactivate_object(fd_form_ref->back);
+               fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
+       } else {
+               fl_activate_object(fd_form_ref->back);
+               fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
+       }
+
+       if (empty) {
                fl_add_browser_line(brow, 
                                    _("*** No labels found in document ***"));
                fl_deactivate_object(brow);
+               fl_deactivate_object(fd_form_ref->gotoref);
+               fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE);
        } else {
                fl_select_browser_line(brow, topline);
                fl_activate_object(brow);
+               fl_activate_object(fd_form_ref->gotoref);
+               fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK);
        }
-       if (current_view->buffer()->isReadonly()) {
-               // would be better to de/activate insert buttons
-               // but that's more work... besides this works. ARRae
-               fl_hide_form(fd_form_ref->form_ref);
+
+       if (empty || readonly) {
+               fl_deactivate_object(fd_form_ref->ref);
+               fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE);
+               fl_deactivate_object(fd_form_ref->pageref);
+               fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE);
+       } else {
+               fl_activate_object(fd_form_ref->ref);
+               fl_set_object_lcol(fd_form_ref->ref, FL_BLACK);
+               fl_activate_object(fd_form_ref->pageref);
+               fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK);
        }
-       if (!current_view->buffer()->isSGML()) {
-               fl_deactivate_object(fd_form_ref->ref_name);
-               fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
+       
+       if (empty || readonly || sgml) {
+               fl_deactivate_object(fd_form_ref->vref);
+               fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
+               fl_deactivate_object(fd_form_ref->vpageref);
+               fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
+               fl_deactivate_object(fd_form_ref->prettyref);
+               fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
+       } else {
+               fl_activate_object(fd_form_ref->vref);
+               fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
+               fl_activate_object(fd_form_ref->vpageref);
+               fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
+               fl_activate_object(fd_form_ref->prettyref);
+               fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
        }
-       else {
+
+       if (sgml) {
                fl_activate_object(fd_form_ref->ref_name);
                fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
+       } else {
+               fl_deactivate_object(fd_form_ref->ref_name);
+               fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
        }
+
+       fl_show_object(brow);
 }