1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
18 #include "support/lstrings.h"
20 #include FORMS_H_LOCATION
22 #include "layout_forms.h"
23 #include "bullet_forms.h"
24 #include "print_form.h"
26 #include "spellchecker.h"
30 #include "insets/insetref.h"
31 #include "insets/insetquotes.h"
32 #include "insets/insetlabel.h"
33 #include "insets/figinset.h"
35 #include "latexoptions.h"
37 #include "minibuffer.h"
39 #include "bufferlist.h"
40 #include "support/filetools.h"
41 #include "support/path.h"
43 #include "lyx_gui_misc.h"
45 #include "lastfiles.h"
46 #include "support/FileInfo.h"
48 #include "support/syscall.h"
49 #include "support/lyxlib.h"
50 #include "lyxserver.h"
51 #include "FontLoader.h"
58 extern Combox * combo_language;
59 extern BufferList bufferlist;
60 extern void show_symbols_form();
61 extern FD_form_title * fd_form_title;
62 extern FD_form_paragraph * fd_form_paragraph;
63 extern FD_form_character * fd_form_character;
64 extern FD_form_document * fd_form_document;
65 extern FD_form_quotes * fd_form_quotes;
66 extern FD_form_preamble * fd_form_preamble;
67 extern FD_form_table * fd_form_table;
68 extern FD_form_print * fd_form_print;
69 extern FD_form_figure * fd_form_figure;
70 extern FD_form_screen * fd_form_screen;
71 extern FD_form_toc * fd_form_toc;
72 extern FD_form_ref * fd_form_ref;
73 extern FD_LaTeXOptions * fd_latex_options;
74 extern FD_form_bullet * fd_form_bullet;
76 extern BufferView * current_view; // called too many times in this file...
78 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
80 extern bool send_fax(string const & fname, string const & sendcmd);
81 extern void MenuSendto();
83 extern LyXServer * lyxserver;
84 extern FontLoader fontloader;
86 // this should be static, but I need it in buffer.C
87 bool quitting; // flag, that we are quitting the program
88 extern bool finished; // all cleanup done just let it run through now.
90 char ascii_type; /* for selection notify callbacks */
92 bool scrolling = false;
96 /* whether the work area should get callbacks */
97 bool input_prohibited = false;
99 /* the selection possible is needed, that only motion events are
100 * used, where the bottom press event was on the drawing area too */
101 bool selection_possible = false;
103 // This is used to make the dreaded font toggle problem hopefully go
104 // away. Definitely not the best solution, but I think it sorta works.
105 bool toggleall = true;
108 This is the inset locking stuff needed for mathed --------------------
110 an inset can simple call LockInset in it's edit call and *ONLY* in it's
112 Inset::Edit() can only be called by the main lyx module.
114 Then the inset may modify the menu's and/or iconbars.
116 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
118 During the lock, all button and keyboard events will be modified
119 and send to the inset through the following inset-features. Note that
120 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
121 to contain the code for restoring the menus and things like this.
124 virtual void InsetButtonPress(int x, int y, int button);
125 virtual void InsetButtonRelease(int x, int y, int button);
126 virtual void InsetKeyPress(XKeyEvent *ev);
127 virtual void InsetMotionNotify(int x, int y, int state);
128 virtual void InsetUnlock();
130 If a inset wishes any redraw and/or update it just has to call
132 It's is completly irrelevant, where the inset is. UpdateInset will
133 find it in any paragraph in any buffer.
134 Of course the_locking_inset and the insets in the current paragraph/buffer
135 are checked first, so no performance problem should occur.
137 Hope that's ok for the beginning, Alejandro,
138 sorry that I needed so much time,
143 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
145 /* these functions return 1 if an error occured,
147 // Now they work only for updatable insets. [Alejandro 080596]
148 //int LockInset(UpdatableInset * inset);
149 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
150 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
151 //int UnlockInset(UpdatableInset * inset);
152 //void LockedInsetStoreUndo(Undo::undo_kind kind);
154 /* this is for asyncron updating. UpdateInsetUpdateList will be called
155 automatically from LyX. Just insert the Inset into the Updatelist */
156 //void UpdateInsetUpdateList();
157 //void PutInsetIntoInsetUpdateList(Inset * inset);
159 //InsetUpdateStruct * InsetUpdateList = 0;
163 -----------------------------------------------------------------------
166 /* some function prototypes */
168 int RunLinuxDoc(BufferView *, int, string const &);
169 int RunDocBook(int, string const &);
170 void MenuWrite(Buffer * buf);
171 void MenuWriteAs(Buffer * buffer);
172 void MenuReload(Buffer * buf);
173 void MenuLayoutSave();
176 // How should this actually work? Should it prohibit input in all BufferViews,
177 // or just in the current one? If "just the current one", then it should be
178 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
179 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
180 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
181 // current LyxView that should be prohibited (Lgb) (This applies to
182 // "AllowInput" as well.)
185 input_prohibited = true;
186 current_view->hideCursor();
188 static Cursor cursor;
189 static bool cursor_undefined = true;
191 if (cursor_undefined){
192 cursor = XCreateFontCursor(fl_display, XC_watch);
194 cursor_undefined = false;
197 /* set the cursor to the watch for all forms and the canvas */
198 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
200 if (fd_form_paragraph->form_paragraph->visible)
201 XDefineCursor(fl_display,
202 fd_form_paragraph->form_paragraph->window,
204 if (fd_form_character->form_character->visible)
205 XDefineCursor(fl_display,
206 fd_form_character->form_character->window,
210 fl_deactivate_all_forms();
214 // Should find a way to move this into BufferView.C
215 void SetXtermCursor(Window win)
217 static Cursor cursor;
218 static bool cursor_undefined = true;
219 if (cursor_undefined){
220 cursor = XCreateFontCursor(fl_display, XC_xterm);
222 cursor_undefined = false;
224 XDefineCursor(fl_display, win, cursor);
231 input_prohibited = false;
233 /* reset the cursor from the watch for all forms and the canvas */
235 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
236 if (fd_form_paragraph->form_paragraph->visible)
237 XUndefineCursor(fl_display,
238 fd_form_paragraph->form_paragraph->window);
239 if (fd_form_character->form_character->visible)
240 XUndefineCursor(fl_display,
241 fd_form_character->form_character->window);
243 // What to do about this? (Lgb)
244 if (current_view->belowMouse())
245 SetXtermCursor(current_view->owner()->getForm()->window);
248 fl_activate_all_forms();
252 void FreeUpdateTimer()
254 /* a real free timer would be better but I don't know
255 * how to do this with xforms */
260 void SetUpdateTimer(float time)
262 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
275 // should be moved to lyxfunc.C
276 void MenuWrite(Buffer * buffer)
279 if (!buffer->save(lyxrc.make_backup)) {
280 string fname = buffer->fileName();
281 string s = MakeAbsPath(fname);
282 if (AskQuestion(_("Save failed. Rename and try again?"),
283 MakeDisplayPath(s, 50),
284 _("(If not, document is not saved.)"))) {
288 lastfiles->newFile(buffer->fileName());
293 // should be moved to BufferView.C
294 // Half of this func should be in LyXView, the rest in BufferView.
295 void MenuWriteAs(Buffer * buffer)
297 // Why do we require BufferView::text to be able to write a
298 // document? I see no point in that. (Lgb)
299 //if (!bv->text) return;
301 string fname = buffer->fileName();
302 string oldname = fname;
306 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
307 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
309 if (!IsLyXFilename(fname))
312 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
315 OnlyFilename(fname));
321 // Make sure the absolute filename ends with appropriate suffix
322 string s = MakeAbsPath(fname);
323 if (!IsLyXFilename(s))
326 // Same name as we have already?
328 if (!AskQuestion(_("Same name as document already has:"),
329 MakeDisplayPath(s, 50),
332 // Falls through to name change and save
334 // No, but do we have another file with this name open?
335 else if (bufferlist.exists(s)) {
336 if (AskQuestion(_("Another document with same name open!"),
337 MakeDisplayPath(s, 50),
338 _("Replace with current document?")))
340 bufferlist.close(bufferlist.getBuffer(s));
342 // Ok, change the name of the buffer, but don't save!
346 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
348 _("', but not saved..."));
351 } // Check whether the file exists
354 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
355 MakeDisplayPath(s, 50),
360 // Ok, change the name of the buffer
364 // Small bug: If the save fails, we have irreversible changed the name
370 int MenuRunLaTeX(Buffer * buffer)
374 if (buffer->isLinuxDoc())
375 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
376 else if (buffer->isLiterate())
377 ret = buffer->runLiterate();
378 else if (buffer->isDocBook())
379 ret = RunDocBook(1, buffer->fileName());
381 ret = buffer->runLaTeX();
387 s = _("One error detected");
388 t = _("You should try to fix it.");
391 s += _(" errors detected.");
392 t = _("You should try to fix them.");
394 WriteAlert(_("There were errors during the LaTeX run."), s, t);
400 int MenuBuildProg(Buffer * buffer)
404 if (buffer->isLiterate())
405 ret = buffer->buildProgram();
407 string s = _("Wrong type of document");
408 string t = _("The Build operation is not allowed in this document");
409 WriteAlert(_("There were errors during the Build process."), s, t);
417 s = _("One error detected");
418 t = _("You should try to fix it.");
421 s += _(" errors detected.");
422 t = _("You should try to fix them.");
424 WriteAlert(_("There were errors during the Build process."), s, t);
430 int MenuRunChktex(Buffer * buffer)
434 if (buffer->isSGML()) {
435 WriteAlert(_("Chktex does not work with SGML derived documents."));
438 ret = buffer->runChktex();
444 s = _("No warnings found.");
445 } else if (ret == 1) {
446 s = _("One warning found.");
447 t = _("Use 'Edit->Go to Error' to find it.");
450 s += _(" warnings found.");
451 t = _("Use 'Edit->Go to Error' to find them.");
453 WriteAlert(_("Chktex run successfully"), s, t);
455 WriteAlert(_("Error!"), _("It seems chktex does not work."));
461 int MakeLaTeXOutput(Buffer * buffer)
467 string path = OnlyPath(buffer->fileName());
468 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
469 path = buffer->tmppath;
471 if (!buffer->isDviClean()) {
473 ret = MenuRunLaTeX(buffer);
479 /* wait == false means don't wait for termination */
480 /* wait == true means wait for termination */
481 // The bool should be placed last on the argument line. (Lgb)
482 // Returns false if we fail.
483 bool RunScript(Buffer * buffer, bool wait,
484 string const & command,
485 string const & orgname = string(),
486 bool need_shell = true)
490 string name = orgname;
493 if (MakeLaTeXOutput(buffer) > 0)
495 /* get DVI-Filename */
497 name = ChangeExtension(buffer->getLatexName(),
500 path = OnlyPath(name);
501 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
502 path = buffer->tmppath;
505 // At this point we check whether the command contains the
506 // filename parameter $$FName and if that's the case we
507 // substitute the real file name otherwise the filename is
508 // simply appended. rokrau 1/12/00
510 std::string::size_type i;
511 if ( (i=command.find("$$FName")) != std::string::npos)
513 cmd.replace(i,7,QuoteName(name));
516 cmd = command + ' ' + QuoteName(name);
525 // OS/2 cmd.exe has another use for '&'
527 // This is not NLS safe, but it's OK, I think.
528 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
530 // COMSPEC is set, unless user unsets
531 sh = OnlyFilename(GetEnvPath("COMSPEC"));
536 if (contains(sh, "cmd.exe")
537 || contains(sh, "4os2.exe"))
538 cmd = "start /min/n " + cmd;
543 // It seems that, if wait is false, we never get back
544 // the return code of the command. This means that all
545 // the code I added in PrintApplyCB is currently
548 #warning What should we do here?
550 buffer->getUser()->owner()->getMiniBuffer()->Set(
551 _("Executing command:"), cmd);
552 result = one.startscript(Systemcalls::System, cmd);
554 buffer->getUser()->owner()->getMiniBuffer()->Set(
555 _("Executing command:"), cmd);
556 result = one.startscript(wait ? Systemcalls::Wait
557 : Systemcalls::DontWait, cmd);
563 // Returns false if we fail
564 bool CreatePostscript(Buffer * buffer, bool wait = false)
573 if (MakeLaTeXOutput(buffer) > 0) {
577 // Generate postscript file
578 string psname = ChangeExtension (buffer->fileName(),
584 char real_papersize = buffer->params.papersize;
585 if (real_papersize == BufferParams::PAPER_DEFAULT)
586 real_papersize = lyxrc.default_papersize;
588 switch (real_papersize) {
589 case BufferParams::PAPER_USLETTER:
592 case BufferParams::PAPER_A3PAPER:
595 case BufferParams::PAPER_A4PAPER:
598 case BufferParams::PAPER_A5PAPER:
601 case BufferParams::PAPER_B5PAPER:
604 case BufferParams::PAPER_EXECUTIVEPAPER:
607 case BufferParams::PAPER_LEGALPAPER:
610 default: /* If nothing else fits, keep an empty value... */
614 // Make postscript file.
615 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
616 command += QuoteName(psname);
617 if (buffer->params.use_geometry
618 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
619 && !lyxrc.print_paper_dimension_flag.empty()
620 && !buffer->params.paperwidth.empty()
621 && !buffer->params.paperheight.empty()) {
622 // using a custom papersize
624 command += lyxrc.print_paper_dimension_flag + ' ';
625 command += buffer->params.paperwidth + ',';
626 command += buffer->params.paperheight;
627 } else if (!paper.empty()
628 && (real_papersize != BufferParams::PAPER_USLETTER ||
629 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
630 // dvips won't accept -t letter -t landscape. In all other
631 // cases, include the paper size explicitly.
633 command += lyxrc.print_paper_flag + ' ' + paper;
635 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
637 command += lyxrc.print_landscape_flag;
639 // push directorypath, if necessary
640 string path = OnlyPath(buffer->fileName());
641 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
642 path = buffer->tmppath;
645 bool ret = RunScript(buffer, wait, command);
651 // Returns false if we fail
652 //bool MenuPreviewPS(Buffer * buffer)
653 bool PreviewPostscript(Buffer * buffer)
659 // Generate postscript file
660 if (!CreatePostscript(buffer, true)) {
664 // Start postscript viewer
666 string ps = ChangeExtension (buffer->fileName(),
668 // push directorypath, if necessary
669 string path = OnlyPath(buffer->fileName());
670 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
671 path = buffer->tmppath;
674 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
680 void MenuFax(Buffer * buffer)
686 // Generate postscript file
687 if (!CreatePostscript(buffer, true)) {
692 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
693 string path = OnlyPath (buffer->fileName());
694 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
695 path = buffer->tmppath;
698 if (!lyxrc.fax_program.empty()) {
699 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
701 Systemcalls one(Systemcalls::System, help2);
703 send_fax(ps, lyxrc.fax_command);
707 // Returns false if we fail
708 bool PreviewDVI(Buffer * buffer)
714 string paper = lyxrc.view_dvi_paper_option;
715 if (!paper.empty()) {
717 char real_papersize = buffer->params.papersize;
718 if (real_papersize == BufferParams::PAPER_DEFAULT)
719 real_papersize = lyxrc.default_papersize;
721 switch (real_papersize) {
722 case BufferParams::PAPER_USLETTER:
725 case BufferParams::PAPER_A3PAPER:
728 case BufferParams::PAPER_A4PAPER:
731 case BufferParams::PAPER_A5PAPER:
734 case BufferParams::PAPER_B5PAPER:
737 case BufferParams::PAPER_EXECUTIVEPAPER:
738 paper += " foolscap";
740 case BufferParams::PAPER_LEGALPAPER:
743 default: /* If nothing else fits, keep the empty value */
746 if (real_papersize==' ') {
747 // if (paper.empty()) {
748 if (buffer->params.orientation
749 == BufferParams::ORIENTATION_LANDSCAPE)
750 // we HAVE to give a size when the page is in
751 // landscape, so use USletter.
752 paper = " -paper usr";
754 // paper = " -paper " + paper;
755 if (buffer->params.orientation
756 == BufferParams::ORIENTATION_LANDSCAPE)
760 // push directorypath, if necessary
761 string path = OnlyPath(buffer->fileName());
762 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
763 path = buffer->tmppath;
767 string command = lyxrc.view_dvi_command + " " + paper;
768 bool ret = RunScript(buffer, false, command);
773 void MenuMakeLaTeX(Buffer * buffer)
775 // Why care about this?
779 // Get LaTeX-Filename
780 string s = buffer->getLatexName(false);
784 !AskQuestion(_("File already exists:"),
785 MakeDisplayPath(s, 50),
786 _("Do you want to overwrite the file?"))) {
787 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
791 if (buffer->isDocBook())
792 buffer->getUser()->owner()->getMiniBuffer()->Set(
793 _("DocBook does not have a latex backend"));
795 if (buffer->isLinuxDoc())
796 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
798 buffer->makeLaTeXFile(s, string(), true);
799 buffer->getUser()->owner()->getMiniBuffer()->Set(
800 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
801 buffer->markDviDirty();
806 void MenuMakeLinuxDoc(Buffer * buffer)
809 //if (!bv->text) return;
811 if (!buffer->isLinuxDoc()) {
812 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
816 // Get LinuxDoc-Filename
817 string s = ChangeExtension(buffer->fileName(),
822 !AskQuestion(_("File already exists:"),
823 MakeDisplayPath(s, 50),
824 _("Do you want to overwrite the file?"))) {
825 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
829 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
830 MakeDisplayPath(s),"'...");
832 buffer->makeLinuxDocFile(s, 65);
834 buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
839 void MenuMakeDocBook(Buffer * buffer)
842 //if (!bv->text) return;
844 if (!buffer->isDocBook()) {
845 WriteAlert(_("Error!"),
846 _("Document class must be docbook."));
850 // Get DocBook-Filename
851 string s = ChangeExtension(buffer->fileName(),
856 !AskQuestion(_("File already exists:"),
857 MakeDisplayPath(s, 50),
858 _("Do you want to overwrite the file?"))) {
859 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
863 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
864 MakeDisplayPath(s), "'...");
866 buffer->makeDocBookFile(s, 65);
868 buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
873 void MenuMakeAscii(Buffer * buffer)
876 //if (!bv->text) return;
878 /* get LaTeX-Filename */
879 string s = ChangeExtension (buffer->fileName(),
884 !AskQuestion(_("File already exists:"),
885 MakeDisplayPath(s, 50),
886 _("Do you want to overwrite the file?"))) {
887 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
891 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
893 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
897 void MenuPrint(Buffer * buffer)
903 string input_file = ChangeExtension(buffer->fileName(),
904 lyxrc.print_file_extension,
906 fl_set_input(fd_form_print->input_file, input_file.c_str());
908 if (fd_form_print->form_print->visible) {
909 fl_raise_form(fd_form_print->form_print);
912 fl_show_form(fd_form_print->form_print,
913 FL_PLACE_MOUSE, FL_FULLBORDER,
918 void MenuMakeHTML(Buffer * buffer)
920 // First, create LaTeX file
921 MenuMakeLaTeX(buffer);
923 // And now, run the converter
924 string file = buffer->fileName();
925 Path path(OnlyPath(file));
926 // the tex file name has to be correct for
927 // latex, but the html file name can be
929 string result = ChangeExtension(file, ".html", false);
930 string infile = buffer->getLatexName(false);
931 string tmp = lyxrc.html_command;
932 tmp = subst(tmp, "$$FName", infile);
933 tmp = subst(tmp, "$$OutName", result);
935 int res = one.startscript(Systemcalls::System, tmp);
937 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
938 + MakeDisplayPath(result) +'\'');
940 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
941 + MakeDisplayPath(infile)
947 void MenuExport(Buffer * buffer, string const & extyp)
950 if (extyp == "latex") {
951 // make sure that this buffer is not linuxdoc
952 MenuMakeLaTeX(buffer);
955 else if (extyp == "linuxdoc") {
956 // make sure that this buffer is not latex
957 MenuMakeLinuxDoc(buffer);
960 else if (extyp == "docbook") {
961 // make sure that this buffer is not latex or linuxdoc
962 MenuMakeDocBook(buffer);
965 else if (extyp == "dvi") {
966 // Run LaTeX as "Update dvi..." Bernhard.
967 // We want the dvi in the current directory. This
968 // is achieved by temporarily disabling use of
969 // temp directory. As a side-effect, we get
970 // *.log and *.aux files also. (Asger)
971 bool flag = lyxrc.use_tempdir;
972 lyxrc.use_tempdir = false;
973 MenuRunLaTeX(buffer);
974 lyxrc.use_tempdir = flag;
977 else if (extyp == "postscript") {
978 // Start Print-dialog. Not as good as dvi... Bernhard.
980 // Since the MenuPrint is a pop-up, we can't use
981 // the same trick as above. (Asger)
982 // MISSING: Move of ps-file :-(
983 // And MenuPrint should not be used for this at all...
986 else if (extyp == "ascii") {
987 MenuMakeAscii(buffer);
989 else if (extyp == "custom") {
993 else if (extyp == "html") {
994 MenuMakeHTML(buffer);
997 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
1004 lyxerr.debug() << "Running QuitLyX." << endl;
1006 if (!bufferlist.QwriteAll())
1009 lastfiles->writeFile(lyxrc.lastfiles);
1011 // Set a flag that we do quitting from the program,
1012 // so no refreshes are necessary.
1015 // close buffers first
1016 bufferlist.closeAll();
1018 // do any other cleanup procedures now
1019 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1021 DestroyLyXTmpDir(system_tempdir);
1029 // should probably be moved into BufferList (Lgb)
1030 // Perfect target for a thread...
1032 if (!current_view->available())
1035 if (current_view->buffer()->isBakClean()
1036 || current_view->buffer()->isReadonly()) {
1037 // We don't save now, but we'll try again later
1038 current_view->owner()->resetAutosaveTimer();
1042 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1044 // create autosave filename
1045 string fname = OnlyPath(current_view->buffer()->fileName());
1047 fname += OnlyFilename(current_view->buffer()->fileName());
1050 // tmp_ret will be located (usually) in /tmp
1051 // will that be a problem?
1052 string tmp_ret = tmpnam(0);
1054 pid_t pid = fork(); // If you want to debug the autosave
1055 // you should set pid to -1, and comment out the
1057 if (pid == 0 || pid == -1) {
1058 // pid = -1 signifies that lyx was unable
1059 // to fork. But we will do the save
1061 bool failed = false;
1062 if (!tmp_ret.empty()) {
1063 current_view->buffer()->writeFile(tmp_ret, 1);
1064 // assume successful write of tmp_ret
1065 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1067 // most likely couldn't move between filesystems
1068 // unless write of tmp_ret failed
1069 // so remove tmp file (if it exists)
1070 remove(tmp_ret.c_str());
1077 // failed to write/rename tmp_ret so try writing direct
1078 if (!current_view->buffer()->writeFile(fname, 1)) {
1079 // It is dangerous to do this in the child,
1080 // but safe in the parent, so...
1082 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1085 if (pid == 0) { // we are the child so...
1090 current_view->buffer()->markBakClean();
1091 current_view->owner()->resetAutosaveTimer();
1096 // Copyright CHT Software Service GmbH
1099 // create new file with template
1102 Buffer * NewLyxFile(string const & filename)
1104 // Split argument by :
1106 string tmpname = split(filename, name, ':');
1107 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1108 if (name.length() == 1
1109 && isalpha(static_cast<unsigned char>(name[0]))
1110 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1112 name += token(tmpname, ':', 0);
1113 tmpname = split(tmpname, ':');
1116 lyxerr.debug() << "Arg is " << filename
1117 << "\nName is " << name
1118 << "\nTemplate is " << tmpname << endl;
1120 // find a free buffer
1121 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1123 lastfiles->newFile(tmpbuf->fileName());
1128 // Insert ascii file (if filename is empty, prompt for one)
1129 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1134 if (!bv->available()) return;
1136 if (fname.empty()) {
1138 fname = fileDlg.Select(_("File to Insert"),
1139 bv->owner()->buffer()->filepath,
1142 if (fname.empty()) return;
1147 if (!fi.readable()) {
1148 WriteFSAlert(_("Error! Specified file is unreadable: "),
1149 MakeDisplayPath(fname, 50));
1153 ifstream ifs(fname.c_str());
1155 WriteFSAlert(_("Error! Cannot open specified file: "),
1156 MakeDisplayPath(fname, 50));
1160 ifs.unsetf(std::ios::skipws);
1161 std::istream_iterator<char> ii(ifs);
1162 std::istream_iterator<char> end;
1163 //string tmpstr(ii, end); // yet a reason for using std::string
1164 // alternate approach to get the file into a string:
1166 copy(ii, end, back_inserter(tmpstr));
1167 // insert the string
1168 current_view->hideCursor();
1170 // clear the selection
1173 bv->text->InsertStringA(tmpstr);
1175 bv->text->InsertStringB(tmpstr);
1180 void MenuShowTableOfContents()
1182 static int ow = -1, oh;
1185 if (fd_form_toc->form_toc->visible) {
1186 fl_raise_form(fd_form_toc->form_toc);
1188 fl_show_form(fd_form_toc->form_toc,
1189 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1190 _("Table Of Contents"));
1192 ow = fd_form_toc->form_toc->w;
1193 oh = fd_form_toc->form_toc->h;
1195 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1200 void MenuInsertLabel(char const * arg)
1204 if (label.empty()) {
1206 result = askForText(_("Enter new label to insert:"));
1208 label = frontStrip(strip(result.second));
1211 if (!label.empty()) {
1212 InsetLabel * new_inset = new InsetLabel;
1213 new_inset->setContents(label);
1214 current_view->insertInset(new_inset);
1220 void MenuInsertRef()
1222 static int ow = -1, oh;
1225 if (fd_form_ref->form_ref->visible) {
1226 fl_raise_form(fd_form_ref->form_ref);
1228 fl_show_form(fd_form_ref->form_ref,
1229 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1230 _("Insert Reference"));
1232 ow = fd_form_ref->form_ref->w;
1233 oh = fd_form_ref->form_ref->h;
1235 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1240 void MenuPasteSelection(char at)
1242 if (!current_view->available())
1247 Atom data_prop = XInternAtom(fl_display,
1250 if (data_prop == None)
1252 XConvertSelection(fl_display,
1253 XA_PRIMARY, XA_STRING, data_prop,
1254 current_view->owner()->getForm()->window, 0);
1259 // candidate for move to BufferView
1260 void Foot(BufferView * bv)
1262 if (!bv->available())
1265 bv->owner()->getMiniBuffer()
1266 ->Set(_("Inserting Footnote..."));
1269 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1274 // candidate for move to LyXView
1275 // This is only used in toolbar.C
1276 void LayoutsCB(int sel, void *)
1278 string tmp = tostr(sel);
1279 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1285 * SGML Linuxdoc support:
1286 * (flag == 0) make TeX output
1287 * (flag == 1) make dvi output
1289 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1296 /* generate a path-less extension name */
1297 string name = ChangeExtension (filename, ".sgml", true);
1298 string path = OnlyPath (filename);
1299 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1300 path = bv->buffer()->tmppath;
1304 if (!bv->available())
1306 bv->buffer()->makeLinuxDocFile(name, 0);
1307 #ifdef WITH_WARNINGS
1308 #warning remove this once we have a proper geometry class
1310 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1312 case BufferParams::PAPER_A4PAPER:
1313 add_flags = "-p a4";
1315 case BufferParams::PAPER_USLETTER:
1316 add_flags = "-p letter";
1318 default: /* nothing to be done yet ;-) */ break;
1325 case 0: /* TeX output asked */
1326 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1327 s2 = "sgml2latex " + add_flags + " -o tex "
1328 + lyxrc.sgml_extra_options + ' ' + name;
1329 if (one.startscript(Systemcalls::System, s2))
1332 case 1: /* dvi output asked */
1333 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1334 s2 = "sgml2latex " + add_flags + " -o dvi "
1335 + lyxrc.sgml_extra_options + ' ' + name;
1336 if (one.startscript(Systemcalls::System, s2)) {
1339 bv->buffer()->markDviClean();
1341 default: /* unknown output */
1347 bv->buffer()->redraw();
1353 * SGML DocBook support:
1354 * (flag == 1) make dvi output
1356 int RunDocBook(int flag, string const & filename)
1358 /* generate a path-less extension name */
1359 string name = ChangeExtension (filename, ".sgml", true);
1360 string path = OnlyPath (filename);
1361 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1362 path = current_view->buffer()->tmppath;
1366 if (!current_view->available())
1369 current_view->buffer()->makeDocBookFile(name, 0);
1371 // Shall this code go or should it stay? (Lgb)
1372 // string add_flags;
1373 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1375 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1376 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1377 // default: /* nothing to be done yet ;-) */ break;
1384 case 1: /* dvi output asked */
1386 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1387 string s2 = "sgmltools --backend dvi " + name;
1388 if (one.startscript(Systemcalls::System, s2)) {
1391 current_view->buffer()->markDviClean();
1394 default: /* unknown output */
1400 current_view->buffer()->redraw();
1405 void MenuLayoutCharacter()
1407 static int ow = -1, oh;
1409 if (fd_form_character->form_character->visible) {
1410 fl_raise_form(fd_form_character->form_character);
1412 fl_show_form(fd_form_character->form_character,
1413 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1414 _("Character Style"));
1416 ow = fd_form_character->form_character->w;
1417 oh = fd_form_character->form_character->h;
1419 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1425 void DeactivateParagraphButtons ()
1427 fl_deactivate_object (fd_form_paragraph->button_ok);
1428 fl_deactivate_object (fd_form_paragraph->button_apply);
1429 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1430 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1435 void ActivateParagraphButtons ()
1437 fl_activate_object (fd_form_paragraph->button_ok);
1438 fl_activate_object (fd_form_paragraph->button_apply);
1439 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1440 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1445 void DisableParagraphLayout ()
1447 DeactivateParagraphButtons();
1448 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1449 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1450 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1451 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1452 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1453 fl_deactivate_object (fd_form_paragraph->check_noindent);
1454 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1455 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1456 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1457 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1458 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1459 fl_deactivate_object (fd_form_paragraph->input_space_above);
1460 fl_deactivate_object (fd_form_paragraph->input_space_below);
1461 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1462 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1463 fl_deactivate_object (fd_form_paragraph->check_space_above);
1464 fl_deactivate_object (fd_form_paragraph->check_space_below);
1469 void EnableParagraphLayout ()
1471 ActivateParagraphButtons();
1472 fl_activate_object (fd_form_paragraph->input_labelwidth);
1473 fl_activate_object (fd_form_paragraph->check_lines_top);
1474 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1475 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1476 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1477 fl_activate_object (fd_form_paragraph->check_noindent);
1478 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1479 fl_activate_object (fd_form_paragraph->radio_align_right);
1480 fl_activate_object (fd_form_paragraph->radio_align_left);
1481 fl_activate_object (fd_form_paragraph->radio_align_block);
1482 fl_activate_object (fd_form_paragraph->radio_align_center);
1483 fl_activate_object (fd_form_paragraph->input_space_above);
1484 fl_activate_object (fd_form_paragraph->input_space_below);
1485 fl_activate_object (fd_form_paragraph->choice_space_above);
1486 fl_activate_object (fd_form_paragraph->choice_space_below);
1487 fl_activate_object (fd_form_paragraph->check_space_above);
1488 fl_activate_object (fd_form_paragraph->check_space_below);
1492 bool UpdateLayoutParagraph()
1494 if (!current_view->available()) {
1495 if (fd_form_paragraph->form_paragraph->visible)
1496 fl_hide_form(fd_form_paragraph->form_paragraph);
1500 Buffer * buf = current_view->buffer();
1502 fl_set_input(fd_form_paragraph->input_labelwidth,
1503 current_view->text->cursor.par->GetLabelWidthString().c_str());
1504 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1505 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1506 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1507 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1509 int align = current_view->text->cursor.par->GetAlign();
1510 if (align == LYX_ALIGN_LAYOUT)
1511 align = textclasslist.Style(buf->params.textclass,
1512 current_view->text->cursor.par->GetLayout()).align;
1515 case LYX_ALIGN_RIGHT:
1516 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1518 case LYX_ALIGN_LEFT:
1519 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1521 case LYX_ALIGN_CENTER:
1522 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1525 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1529 fl_set_button(fd_form_paragraph->check_lines_top,
1530 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1531 fl_set_button(fd_form_paragraph->check_lines_bottom,
1532 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1533 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1534 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1535 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1536 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1537 fl_set_button(fd_form_paragraph->check_noindent,
1538 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1539 fl_set_input (fd_form_paragraph->input_space_above, "");
1541 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1543 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1545 case VSpace::DEFSKIP:
1546 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1548 case VSpace::SMALLSKIP:
1549 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1551 case VSpace::MEDSKIP:
1552 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1554 case VSpace::BIGSKIP:
1555 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1558 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1560 case VSpace::LENGTH:
1561 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1562 fl_set_input (fd_form_paragraph->input_space_above,
1563 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1566 fl_set_button (fd_form_paragraph->check_space_above,
1567 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1568 fl_set_input (fd_form_paragraph->input_space_below, "");
1569 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1571 fl_set_choice (fd_form_paragraph->choice_space_below,
1574 case VSpace::DEFSKIP:
1575 fl_set_choice (fd_form_paragraph->choice_space_below,
1578 case VSpace::SMALLSKIP:
1579 fl_set_choice (fd_form_paragraph->choice_space_below,
1582 case VSpace::MEDSKIP:
1583 fl_set_choice (fd_form_paragraph->choice_space_below,
1586 case VSpace::BIGSKIP:
1587 fl_set_choice (fd_form_paragraph->choice_space_below,
1591 fl_set_choice (fd_form_paragraph->choice_space_below,
1594 case VSpace::LENGTH:
1595 fl_set_choice (fd_form_paragraph->choice_space_below,
1597 fl_set_input (fd_form_paragraph->input_space_below,
1598 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1601 fl_set_button (fd_form_paragraph->check_space_below,
1602 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1604 fl_set_button(fd_form_paragraph->check_noindent,
1605 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1607 if (current_view->buffer()->isReadonly()) {
1608 DisableParagraphLayout();
1610 EnableParagraphLayout();
1616 void MenuLayoutParagraph()
1618 if (UpdateLayoutParagraph()) {
1619 if (fd_form_paragraph->form_paragraph->visible) {
1620 fl_raise_form(fd_form_paragraph->form_paragraph);
1622 fl_show_form(fd_form_paragraph->form_paragraph,
1623 FL_PLACE_MOUSE, FL_FULLBORDER,
1624 _("Paragraph Environment"));
1631 void DeactivateDocumentButtons ()
1633 fl_deactivate_object (fd_form_document->button_ok);
1634 fl_deactivate_object (fd_form_document->button_apply);
1635 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1636 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1641 void ActivateDocumentButtons ()
1643 fl_activate_object (fd_form_document->button_ok);
1644 fl_activate_object (fd_form_document->button_apply);
1645 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1646 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1651 void DisableDocumentLayout ()
1653 DeactivateDocumentButtons ();
1654 fl_deactivate_object (fd_form_document->group_radio_separation);
1655 fl_deactivate_object (fd_form_document->radio_indent);
1656 fl_deactivate_object (fd_form_document->radio_skip);
1657 fl_deactivate_object (fd_form_document->choice_class);
1658 fl_deactivate_object (fd_form_document->choice_pagestyle);
1659 fl_deactivate_object (fd_form_document->choice_fonts);
1660 fl_deactivate_object (fd_form_document->choice_fontsize);
1661 fl_deactivate_object (fd_form_document->input_float_placement);
1662 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1663 fl_deactivate_object (fd_form_document->choice_inputenc);
1664 fl_deactivate_object (fd_form_document->group_radio_sides);
1665 fl_deactivate_object (fd_form_document->radio_sides_one);
1666 fl_deactivate_object (fd_form_document->radio_sides_two);
1667 fl_deactivate_object (fd_form_document->group_radio_columns);
1668 fl_deactivate_object (fd_form_document->radio_columns_one);
1669 fl_deactivate_object (fd_form_document->radio_columns_two);
1670 fl_deactivate_object (fd_form_document->input_extra);
1671 fl_deactivate_object (fd_form_document->choice_language);
1672 combo_language->deactivate();
1673 fl_deactivate_object (fd_form_document->input_default_skip);
1674 fl_deactivate_object (fd_form_document->choice_default_skip);
1675 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1676 fl_deactivate_object (fd_form_document->slider_tocdepth);
1677 fl_deactivate_object (fd_form_document->choice_spacing);
1678 fl_deactivate_object (fd_form_document->input_spacing);
1679 fl_deactivate_object (fd_form_document->check_use_amsmath);
1684 void EnableDocumentLayout ()
1686 ActivateDocumentButtons ();
1687 fl_activate_object (fd_form_document->group_radio_separation);
1688 fl_activate_object (fd_form_document->radio_indent);
1689 fl_activate_object (fd_form_document->radio_skip);
1690 fl_activate_object (fd_form_document->choice_class);
1691 fl_activate_object (fd_form_document->choice_pagestyle);
1692 fl_activate_object (fd_form_document->choice_fonts);
1693 fl_activate_object (fd_form_document->choice_fontsize);
1694 fl_activate_object (fd_form_document->input_float_placement);
1695 fl_activate_object (fd_form_document->choice_postscript_driver);
1696 fl_activate_object (fd_form_document->choice_inputenc);
1697 fl_activate_object (fd_form_document->group_radio_sides);
1698 fl_activate_object (fd_form_document->radio_sides_one);
1699 fl_activate_object (fd_form_document->radio_sides_two);
1700 fl_activate_object (fd_form_document->group_radio_columns);
1701 fl_activate_object (fd_form_document->radio_columns_one);
1702 fl_activate_object (fd_form_document->radio_columns_two);
1703 fl_activate_object (fd_form_document->input_extra);
1704 fl_activate_object (fd_form_document->choice_language);
1705 combo_language->activate();
1706 fl_activate_object (fd_form_document->input_default_skip);
1707 fl_activate_object (fd_form_document->choice_default_skip);
1708 fl_activate_object (fd_form_document->slider_secnumdepth);
1709 fl_activate_object (fd_form_document->slider_tocdepth);
1710 fl_activate_object (fd_form_document->choice_spacing);
1711 fl_activate_object (fd_form_document->input_spacing);
1712 fl_activate_object (fd_form_document->check_use_amsmath);
1716 bool UpdateLayoutDocument(BufferParams * params)
1718 if (!current_view->available()) {
1719 if (fd_form_document->form_document->visible)
1720 fl_hide_form(fd_form_document->form_document);
1725 params = ¤t_view->buffer()->params;
1726 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1728 fl_set_choice_text(fd_form_document->choice_class,
1729 textclasslist.DescOfClass(params->textclass).c_str());
1730 combo_language->select_text(params->language.c_str());
1732 fl_set_choice_text(fd_form_document->choice_fonts,
1733 params->fonts.c_str());
1734 fl_set_choice_text(fd_form_document->choice_inputenc,
1735 params->inputenc.c_str());
1736 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1737 params->graphicsDriver.c_str());
1739 // ale970405+lasgoutt970513
1740 fl_clear_choice(fd_form_document->choice_fontsize);
1741 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1742 fl_addto_choice(fd_form_document->choice_fontsize,
1743 tclass.opt_fontsize().c_str());
1744 fl_set_choice(fd_form_document->choice_fontsize,
1745 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1747 // ale970405+lasgoutt970513
1748 fl_clear_choice(fd_form_document->choice_pagestyle);
1749 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1750 fl_addto_choice(fd_form_document->choice_pagestyle,
1751 tclass.opt_pagestyle().c_str());
1753 fl_set_choice(fd_form_document->choice_pagestyle,
1754 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1756 fl_set_button(fd_form_document->radio_indent, 0);
1757 fl_set_button(fd_form_document->radio_skip, 0);
1760 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1762 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1763 fl_set_button(fd_form_document->radio_indent, 1);
1765 fl_set_button(fd_form_document->radio_skip, 1);
1767 switch (params->getDefSkip().kind()) {
1768 case VSpace::SMALLSKIP:
1769 fl_set_choice (fd_form_document->choice_default_skip, 1);
1771 case VSpace::MEDSKIP:
1772 fl_set_choice (fd_form_document->choice_default_skip, 2);
1774 case VSpace::BIGSKIP:
1775 fl_set_choice (fd_form_document->choice_default_skip, 3);
1777 case VSpace::LENGTH:
1778 fl_set_choice (fd_form_document->choice_default_skip, 4);
1779 fl_set_input (fd_form_document->input_default_skip,
1780 params->getDefSkip().asLyXCommand().c_str());
1783 fl_set_choice (fd_form_document->choice_default_skip, 2);
1787 fl_set_button(fd_form_document->radio_sides_one, 0);
1788 fl_set_button(fd_form_document->radio_sides_two, 0);
1790 switch (params->sides) {
1791 case LyXTextClass::OneSide:
1792 fl_set_button(fd_form_document->radio_sides_one, 1);
1794 case LyXTextClass::TwoSides:
1795 fl_set_button(fd_form_document->radio_sides_two, 1);
1799 fl_set_button(fd_form_document->radio_columns_one, 0);
1800 fl_set_button(fd_form_document->radio_columns_two, 0);
1802 if (params->columns == 2)
1803 fl_set_button(fd_form_document->radio_columns_two, 1);
1805 fl_set_button(fd_form_document->radio_columns_one, 1);
1807 fl_set_input(fd_form_document->input_spacing, "");
1808 switch (params->spacing.getSpace()) {
1809 case Spacing::Single:
1812 fl_set_choice(fd_form_document->choice_spacing, 1);
1815 case Spacing::Onehalf:
1818 fl_set_choice(fd_form_document->choice_spacing, 2);
1821 case Spacing::Double:
1824 fl_set_choice(fd_form_document->choice_spacing, 3);
1827 case Spacing::Other:
1829 fl_set_choice(fd_form_document->choice_spacing, 4);
1831 //sprintf(sval, "%g", params->spacing.getValue());
1834 sval << params->spacing.getValue(); // setw?
1835 fl_set_input(fd_form_document->input_spacing,
1836 sval.str().c_str());
1839 ostrstream sval(tval, 20);
1840 sval << params->spacing.getValue() << '\0'; // setw?
1841 fl_set_input(fd_form_document->input_spacing, sval.str());
1848 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1849 params->secnumdepth);
1850 fl_set_counter_value(fd_form_document->slider_tocdepth,
1852 if (!params->float_placement.empty()) { // buffer local (Lgb)
1853 fl_set_input(fd_form_document->input_float_placement,
1854 params->float_placement.c_str());
1856 fl_set_input(fd_form_document->input_float_placement, "");
1858 if (!params->options.empty())
1859 fl_set_input(fd_form_document->input_extra,
1860 params->options.c_str());
1862 fl_set_input(fd_form_document->input_extra, "");
1864 if (current_view->buffer()->isSGML()) {
1865 // bullets not used in SGML derived documents
1866 fl_deactivate_object(fd_form_document->button_bullets);
1867 fl_set_object_lcol(fd_form_document->button_bullets,
1870 fl_activate_object(fd_form_document->button_bullets);
1871 fl_set_object_lcol(fd_form_document->button_bullets,
1875 if (current_view->buffer()->isReadonly()) {
1876 DisableDocumentLayout();
1878 EnableDocumentLayout();
1885 void MenuLayoutDocument()
1887 if (UpdateLayoutDocument()) {
1888 if (fd_form_document->form_document->visible) {
1889 fl_raise_form(fd_form_document->form_document);
1891 fl_show_form(fd_form_document->form_document,
1892 FL_PLACE_MOUSE, FL_FULLBORDER,
1893 _("Document Layout"));
1899 bool UpdateLayoutQuotes()
1902 if (!current_view->available()
1903 || current_view->buffer()->isReadonly())
1907 fl_set_choice(fd_form_quotes->choice_quotes_language,
1908 current_view->buffer()->params.quotes_language + 1);
1909 fl_set_button(fd_form_quotes->radio_single, 0);
1910 fl_set_button(fd_form_quotes->radio_double, 0);
1912 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1913 fl_set_button(fd_form_quotes->radio_single, 1);
1915 fl_set_button(fd_form_quotes->radio_double, 1);
1916 } else if (fd_form_quotes->form_quotes->visible) {
1917 fl_hide_form(fd_form_quotes->form_quotes);
1923 void MenuLayoutQuotes()
1925 if (UpdateLayoutQuotes()) {
1926 if (fd_form_quotes->form_quotes->visible) {
1927 fl_raise_form(fd_form_quotes->form_quotes);
1929 fl_show_form(fd_form_quotes->form_quotes,
1930 FL_PLACE_MOUSE, FL_FULLBORDER,
1937 bool UpdateLayoutPreamble()
1940 if (!current_view->available())
1944 fl_set_input(fd_form_preamble->input_preamble,
1945 current_view->buffer()->params.preamble.c_str());
1947 if (current_view->buffer()->isReadonly()) {
1948 fl_deactivate_object(fd_form_preamble->input_preamble);
1949 fl_deactivate_object(fd_form_preamble->button_ok);
1950 fl_deactivate_object(fd_form_preamble->button_apply);
1951 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1952 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1955 fl_activate_object(fd_form_preamble->input_preamble);
1956 fl_activate_object(fd_form_preamble->button_ok);
1957 fl_activate_object(fd_form_preamble->button_apply);
1958 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1959 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1961 } else if (fd_form_preamble->form_preamble->visible) {
1962 fl_hide_form(fd_form_preamble->form_preamble);
1968 void MenuLayoutPreamble()
1970 static int ow = -1, oh;
1972 if (UpdateLayoutPreamble()) {
1973 if (fd_form_preamble->form_preamble->visible) {
1974 fl_raise_form(fd_form_preamble->form_preamble);
1976 fl_show_form(fd_form_preamble->form_preamble,
1977 FL_PLACE_MOUSE | FL_FREE_SIZE,
1979 _("LaTeX Preamble"));
1981 ow = fd_form_preamble->form_preamble->w;
1982 oh = fd_form_preamble->form_preamble->h;
1984 fl_set_form_minsize(fd_form_preamble->form_preamble,
1991 void MenuLayoutSave()
1993 if (!current_view->available())
1996 if (AskQuestion(_("Do you want to save the current settings"),
1997 _("for Character, Document, Paper and Quotes"),
1998 _("as default for new documents?")))
1999 current_view->buffer()->saveParamsAsDefaults();
2003 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2004 They also show the current font state. */
2007 void ToggleAndShow(BufferView *, LyXFont const &);
2010 void FontSize(string const & size)
2012 LyXFont font(LyXFont::ALL_IGNORE);
2013 font.setGUISize(size);
2014 ToggleAndShow(current_view, font);
2020 LyXFont font(LyXFont::ALL_IGNORE);
2021 font.setEmph(LyXFont::TOGGLE);
2022 ToggleAndShow(current_view, font);
2028 LyXFont font(LyXFont::ALL_IGNORE);
2029 font.setNoun(LyXFont::TOGGLE);
2030 ToggleAndShow(current_view, font);
2036 LyXFont font(LyXFont::ALL_IGNORE);
2037 font.setSeries(LyXFont::BOLD_SERIES);
2038 ToggleAndShow(current_view, font);
2044 LyXFont font(LyXFont::ALL_IGNORE);
2045 font.setUnderbar(LyXFont::TOGGLE);
2046 ToggleAndShow(current_view, font);
2052 LyXFont font(LyXFont::ALL_IGNORE);
2053 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2054 ToggleAndShow(current_view, font);
2060 LyXFont font(LyXFont::ALL_IGNORE);
2061 font.setFamily(LyXFont::SANS_FAMILY);
2062 ToggleAndShow(current_view, font);
2068 LyXFont font(LyXFont::ALL_IGNORE);
2069 font.setFamily(LyXFont::ROMAN_FAMILY);
2070 ToggleAndShow(current_view, font);
2076 LyXFont font(LyXFont::ALL_IGNORE);
2077 font.setLatex (LyXFont::TOGGLE);
2078 ToggleAndShow(current_view, font);
2081 void LangCB(string const & l)
2083 LyXFont font(LyXFont::ALL_IGNORE);
2084 Languages::iterator lit = languages.find(l);
2085 if (lit != languages.end()) {
2086 font.setLanguage(&(*lit).second);
2087 ToggleAndShow(current_view, font);
2089 WriteAlert(_("Error! unknown language"),l);
2095 LyXFont font(LyXFont::ALL_INHERIT);
2096 ToggleAndShow(current_view, font);
2100 /* -------> Returns the current font and depth by printing a message. In the
2101 * future perhaps we could try to implement a callback to the button-bar.
2102 * That is, `light' the bold button when the font is currently bold, etc.
2104 string CurrentState()
2107 if (current_view->available()) {
2108 // I think we should only show changes from the default
2110 Buffer * buffer = current_view->buffer();
2111 LyXFont font = current_view->text->real_current_font;
2112 LyXFont defaultfont = textclasslist.TextClass(buffer->
2113 params.textclass).defaultfont();
2114 font.reduce(defaultfont);
2115 state = _("Font: ") + font.stateText();
2117 int depth = current_view->text->GetDepth();
2119 state += string(_(", Depth: ")) + tostr(depth);
2125 // candidate for move to BufferView
2126 /* -------> Does the actual toggle job of the XxxCB() calls above.
2127 * Also shows the current font state.
2130 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2132 if (bv->available()) {
2135 if (bv->the_locking_inset)
2136 bv->the_locking_inset->SetFont(bv, font, toggleall);
2138 bv->text->ToggleFree(font, toggleall);
2144 // candidate for move to BufferView
2145 void Margin(BufferView * bv)
2147 if (bv->available()) {
2148 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2151 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2159 if (fd_form_figure->form_figure->visible) {
2160 fl_raise_form(fd_form_figure->form_figure);
2162 fl_show_form(fd_form_figure->form_figure,
2163 FL_PLACE_MOUSE, FL_FULLBORDER,
2164 _("Insert Figure"));
2171 if (fd_form_table->form_table->visible) {
2172 fl_raise_form(fd_form_table->form_table);
2174 fl_show_form(fd_form_table->form_table,
2175 FL_PLACE_MOUSE, FL_FULLBORDER,
2181 // candidate for move to BufferView
2182 void Melt(BufferView * bv)
2184 if (!bv->available()) return;
2186 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2190 bv->text->MeltFootnoteEnvironment();
2195 // candidate for move to BufferView
2196 // Change environment depth.
2197 // if decInc >= 0, increment depth
2198 // if decInc < 0, decrement depth
2199 void changeDepth(BufferView * bv, int decInc)
2201 if (!bv->available()) return;
2206 bv->text->IncDepth();
2208 bv->text->DecDepth();
2210 bv->owner()->getMiniBuffer()
2211 ->Set(_("Changed environment depth"
2212 " (in possible range, maybe not)"));
2216 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2217 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2218 LyXFont UserFreeFont()
2220 LyXFont font(LyXFont::ALL_IGNORE);
2222 int pos = fl_get_choice(fd_form_character->choice_family);
2224 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2225 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2226 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2227 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2228 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2231 pos = fl_get_choice(fd_form_character->choice_series);
2233 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2234 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2235 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2236 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2239 pos = fl_get_choice(fd_form_character->choice_shape);
2241 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2242 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2243 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2244 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2245 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2246 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2249 pos = fl_get_choice(fd_form_character->choice_size);
2251 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2252 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2253 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2254 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2255 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2256 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2257 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2258 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2259 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2260 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2261 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2262 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2263 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2264 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2267 pos = fl_get_choice(fd_form_character->choice_bar);
2269 case 1: font.setEmph(LyXFont::IGNORE);
2270 font.setUnderbar(LyXFont::IGNORE);
2271 font.setNoun(LyXFont::IGNORE);
2272 font.setLatex(LyXFont::IGNORE);
2274 case 2: font.setEmph(LyXFont::TOGGLE); break;
2275 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2276 case 4: font.setNoun(LyXFont::TOGGLE); break;
2277 case 5: font.setLatex(LyXFont::TOGGLE); break;
2278 case 6: font.setEmph(LyXFont::INHERIT);
2279 font.setUnderbar(LyXFont::INHERIT);
2280 font.setNoun(LyXFont::INHERIT);
2281 font.setLatex(LyXFont::INHERIT);
2285 pos = fl_get_choice(fd_form_character->choice_color);
2287 case 1: font.setColor(LColor::ignore); break;
2288 case 2: font.setColor(LColor::none); break;
2289 case 3: font.setColor(LColor::black); break;
2290 case 4: font.setColor(LColor::white); break;
2291 case 5: font.setColor(LColor::red); break;
2292 case 6: font.setColor(LColor::green); break;
2293 case 7: font.setColor(LColor::blue); break;
2294 case 8: font.setColor(LColor::cyan); break;
2295 case 9: font.setColor(LColor::magenta); break;
2296 case 10: font.setColor(LColor::yellow); break;
2297 case 11: font.setColor(LColor::inherit); break;
2306 ToggleAndShow(current_view, UserFreeFont());
2310 /* callbacks for form form_title */
2311 extern "C" void TimerCB(FL_OBJECT *, long)
2313 // only if the form still exists
2314 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2315 if (fd_form_title->form_title->visible) {
2316 fl_hide_form(fd_form_title->form_title);
2318 fl_free_form(fd_form_title->form_title);
2319 fd_form_title->form_title = 0;
2324 /* callbacks for form form_paragraph */
2326 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2328 // "Synchronize" the choices and input fields, making it
2329 // impossible to commit senseless data.
2331 FD_form_paragraph const * fp = fd_form_paragraph;
2333 if (obj == fp->choice_space_above) {
2334 if (fl_get_choice (fp->choice_space_above) != 7) {
2335 fl_set_input (fp->input_space_above, "");
2336 ActivateParagraphButtons();
2338 } else if (obj == fp->choice_space_below) {
2339 if (fl_get_choice (fp->choice_space_below) != 7) {
2340 fl_set_input (fp->input_space_below, "");
2341 ActivateParagraphButtons();
2343 } else if (obj == fp->input_space_above) {
2344 string input = fl_get_input (fp->input_space_above);
2346 if (input.empty()) {
2347 fl_set_choice (fp->choice_space_above, 1);
2348 ActivateParagraphButtons();
2350 else if (isValidGlueLength (input)) {
2351 fl_set_choice (fp->choice_space_above, 7);
2352 ActivateParagraphButtons();
2355 fl_set_choice (fp->choice_space_above, 7);
2356 DeactivateParagraphButtons();
2358 } else if (obj == fp->input_space_below) {
2359 string input = fl_get_input (fp->input_space_below);
2361 if (input.empty()) {
2362 fl_set_choice (fp->choice_space_below, 1);
2363 ActivateParagraphButtons();
2365 else if (isValidGlueLength (input)) {
2366 fl_set_choice (fp->choice_space_below, 7);
2367 ActivateParagraphButtons();
2370 fl_set_choice (fp->choice_space_below, 7);
2371 DeactivateParagraphButtons();
2377 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2379 if (!current_view->available())
2382 VSpace space_top, space_bottom;
2384 string labelwidthstring;
2387 // If a vspace kind is "Length" but there's no text in
2388 // the input field, reset the kind to "None".
2389 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2390 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2391 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2393 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2394 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2395 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2398 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2399 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2400 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2401 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2402 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2403 case 1: space_top = VSpace(VSpace::NONE); break;
2404 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2405 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2406 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2407 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2408 case 6: space_top = VSpace(VSpace::VFILL); break;
2409 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2411 if (fl_get_button (fd_form_paragraph->check_space_above))
2412 space_top.setKeep (true);
2413 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2414 case 1: space_bottom = VSpace(VSpace::NONE); break;
2415 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2416 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2417 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2418 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2419 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2420 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2422 if (fl_get_button (fd_form_paragraph->check_space_below))
2423 space_bottom.setKeep (true);
2425 if (fl_get_button(fd_form_paragraph->radio_align_left))
2426 align = LYX_ALIGN_LEFT;
2427 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2428 align = LYX_ALIGN_RIGHT;
2429 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2430 align = LYX_ALIGN_CENTER;
2432 align = LYX_ALIGN_BLOCK;
2434 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2435 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2437 current_view->text->SetParagraph(line_top,
2446 current_view->update(1);
2447 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2451 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2453 fl_hide_form(fd_form_paragraph->form_paragraph);
2457 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2459 ParagraphApplyCB(ob, data);
2460 ParagraphCancelCB(ob, data);
2464 /* callbacks for form form_character */
2466 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2468 // we set toggleall locally here, since it should be true for
2469 // all other uses of ToggleAndShow() (JMarc)
2470 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2471 ToggleAndShow(current_view, UserFreeFont());
2476 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2478 fl_hide_form(fd_form_character->form_character);
2482 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2484 CharacterApplyCB(ob, data);
2485 CharacterCloseCB(ob, data);
2489 /* callbacks for form form_document */
2491 void UpdateDocumentButtons(BufferParams const & params)
2493 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2495 switch (params.sides) {
2496 case LyXTextClass::OneSide:
2497 fl_set_button(fd_form_document->radio_sides_one, 1);
2499 case LyXTextClass::TwoSides:
2500 fl_set_button(fd_form_document->radio_sides_two, 1);
2504 if (params.columns == 2)
2505 fl_set_button(fd_form_document->radio_columns_two, 1);
2507 fl_set_button(fd_form_document->radio_columns_one, 1);
2509 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2510 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2511 params.secnumdepth);
2512 fl_set_counter_value(fd_form_document->slider_tocdepth,
2517 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2520 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2521 if (AskQuestion(_("Should I set some parameters to"),
2522 fl_get_choice_text(ob),
2523 _("the defaults of this document class?"))) {
2524 BufferParams params = BufferParams();
2525 params.textclass = fl_get_choice(ob)-1;
2526 params.useClassDefaults();
2527 UpdateLayoutDocument(¶ms);
2528 UpdateDocumentButtons(params);
2531 // unable to load new style
2532 WriteAlert(_("Conversion Errors!"),
2533 _("Unable to switch to new document class."),
2534 _("Reverting to original document class."));
2535 fl_set_choice(fd_form_document->choice_class,
2536 current_view->buffer()->params.textclass + 1);
2542 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2544 // "Synchronize" the choice and the input field, so that it
2545 // is impossible to commit senseless data.
2546 FD_form_document const * fd = fd_form_document;
2548 if (obj == fd->choice_default_skip) {
2549 if (fl_get_choice (fd->choice_default_skip) != 4) {
2550 fl_set_input (fd->input_default_skip, "");
2551 ActivateDocumentButtons();
2553 } else if (obj == fd->input_default_skip) {
2555 char const * input = fl_get_input (fd->input_default_skip);
2558 fl_set_choice (fd->choice_default_skip, 2);
2559 ActivateDocumentButtons();
2560 } else if (isValidGlueLength (input)) {
2561 fl_set_choice (fd->choice_default_skip, 4);
2562 ActivateDocumentButtons();
2564 fl_set_choice (fd->choice_default_skip, 4);
2565 DeactivateDocumentButtons();
2571 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2573 // "Synchronize" the choice and the input field, so that it
2574 // is impossible to commit senseless data.
2575 FD_form_document const * fd = fd_form_document;
2577 if (obj == fd->choice_spacing
2578 && fl_get_choice (fd->choice_spacing) != 4) {
2579 fl_set_input(fd->input_spacing, "");
2580 } else if (obj == fd->input_spacing) {
2582 const char* input = fl_get_input (fd->input_spacing);
2585 fl_set_choice (fd->choice_spacing, 1);
2587 fl_set_choice (fd->choice_spacing, 4);
2593 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2596 BufferParams * params = &(current_view->buffer()->params);
2598 params->language = combo_language->getline();
2599 Languages::iterator lit = languages.find(params->language);
2600 if (lit != languages.end())
2601 params->language_info = &(*lit).second;
2603 params->language_info = default_language;
2605 // If default skip is a "Length" but there's no text in the
2606 // input field, reset the kind to "Medskip", which is the default.
2607 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2608 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2609 fl_set_choice (fd_form_document->choice_default_skip, 2);
2612 /* this shouldn't be done automatically IMO. For example I write german
2613 * documents with an american keyboard very often. Matthias */
2615 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2616 fl_get_choice(fd_form_document->choice_language)); */
2618 fl_get_choice_text(fd_form_document->choice_fonts);
2620 fl_get_choice_text(fd_form_document->choice_inputenc);
2622 fl_get_choice_text(fd_form_document->choice_fontsize);
2624 fl_get_choice_text(fd_form_document->choice_pagestyle);
2625 params->graphicsDriver =
2626 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2627 params->use_amsmath =
2628 fl_get_button(fd_form_document->check_use_amsmath);
2630 if (!current_view->available())
2632 if (lyxrc.rtl_support) {
2633 current_view->text->SetCursor(current_view->text->cursor.par,
2634 current_view->text->cursor.pos);
2635 current_view->setState();
2638 LyXTextClassList::ClassList::size_type new_class =
2639 fl_get_choice(fd_form_document->choice_class) - 1;
2641 if (params->textclass != new_class) {
2642 // try to load new_class
2643 if (textclasslist.Load(new_class)) {
2644 // successfully loaded
2646 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2647 int ret = current_view->text->
2648 SwitchLayoutsBetweenClasses(current_view->buffer()->
2651 current_view->buffer()->
2657 s = _("One paragraph couldn't be converted");
2660 s += _(" paragraphs couldn't be converted");
2662 WriteAlert(_("Conversion Errors!"), s,
2663 _("into chosen document class"));
2666 params->textclass = new_class;
2668 // problem changing class -- warn user and retain old style
2669 WriteAlert(_("Conversion Errors!"),
2670 _("Unable to switch to new document class."),
2671 _("Reverting to original document class."));
2672 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2676 char tmpsep = params->paragraph_separation;
2677 if (fl_get_button(fd_form_document->radio_indent))
2678 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2680 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2681 if (tmpsep != params->paragraph_separation)
2684 VSpace tmpdefskip = params->getDefSkip();
2685 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2686 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2687 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2688 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2689 case 4: params->setDefSkip(
2690 VSpace (LyXGlueLength (fl_get_input
2691 (fd_form_document->input_default_skip))));
2693 // DocumentDefskipCB assures that this never happens
2694 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2696 if (!(tmpdefskip == params->getDefSkip()))
2699 if (fl_get_button(fd_form_document->radio_columns_two))
2700 params->columns = 2;
2702 params->columns = 1;
2703 if (fl_get_button(fd_form_document->radio_sides_two))
2704 params->sides = LyXTextClass::TwoSides;
2706 params->sides = LyXTextClass::OneSide;
2708 Spacing tmpSpacing = params->spacing;
2709 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2711 lyxerr.debug() << "Spacing: SINGLE" << endl;
2712 params->spacing.set(Spacing::Single);
2715 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2716 params->spacing.set(Spacing::Onehalf);
2719 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2720 params->spacing.set(Spacing::Double);
2723 lyxerr.debug() << "Spacing: OTHER" << endl;
2724 params->spacing.set(Spacing::Other,
2725 fl_get_input(fd_form_document->input_spacing));
2728 if (tmpSpacing != params->spacing)
2731 signed char tmpchar =
2732 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2733 if (params->secnumdepth != tmpchar)
2735 params->secnumdepth = tmpchar;
2738 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2740 params->float_placement =
2741 fl_get_input(fd_form_document->input_float_placement);
2743 // More checking should be done to ensure the string doesn't have
2744 // spaces or illegal placement characters in it. (thornley)
2747 current_view->redoCurrentBuffer();
2749 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2750 current_view->buffer()->markDirty();
2753 fl_get_input(fd_form_document->input_extra);
2758 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2760 fl_hide_form(fd_form_document->form_document);
2764 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2766 DocumentCancelCB(ob, data);
2767 DocumentApplyCB(ob, data);
2771 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2774 // bullet callbacks etc. in bullet_panel.C -- ARRae
2778 /* callbacks for form form_quotes */
2780 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2782 if (!current_view->available())
2785 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2786 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2787 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2789 lga = InsetQuotes::EnglishQ;
2792 lga = InsetQuotes::SwedishQ;
2795 lga = InsetQuotes::GermanQ;
2798 lga = InsetQuotes::PolishQ;
2801 lga = InsetQuotes::FrenchQ;
2804 lga = InsetQuotes::DanishQ;
2807 current_view->buffer()->params.quotes_language = lga;
2808 if (fl_get_button(fd_form_quotes->radio_single))
2809 current_view->buffer()->
2810 params.quotes_times = InsetQuotes::SingleQ;
2812 current_view->buffer()->
2813 params.quotes_times = InsetQuotes::DoubleQ;
2817 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2819 fl_hide_form(fd_form_quotes->form_quotes);
2823 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2825 QuotesApplyCB(ob, data);
2826 QuotesCancelCB(ob, data);
2831 /* callbacks for form form_preamble */
2833 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2835 fl_hide_form(fd_form_preamble->form_preamble);
2839 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2841 if (!current_view->available())
2844 current_view->buffer()->params.preamble =
2845 fl_get_input(fd_form_preamble->input_preamble);
2846 current_view->buffer()->markDirty();
2847 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2851 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2853 PreambleApplyCB(ob, data);
2854 PreambleCancelCB(ob, data);
2858 /* callbacks for form form_table */
2860 extern "C" void TableApplyCB(FL_OBJECT *, long)
2862 if (!current_view->available())
2865 // check for tables in tables
2866 if (current_view->text->cursor.par->table){
2867 WriteAlert(_("Impossible Operation!"),
2868 _("Cannot insert table in table."),
2873 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2875 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2876 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2879 current_view->hideCursor();
2880 current_view->beforeChange();
2881 current_view->update(-2);
2883 current_view->text->SetCursorParUndo();
2884 current_view->text->FreezeUndo();
2886 current_view->text->BreakParagraph();
2887 current_view->update(-1);
2889 if (current_view->text->cursor.par->Last()) {
2890 current_view->text->CursorLeft();
2892 current_view->text->BreakParagraph();
2893 current_view->update(-1);
2896 current_view->text->current_font.setLatex(LyXFont::OFF);
2897 //if (!fl_get_button(fd_form_table->check_latex)){
2898 // insert the new wysiwy table
2899 current_view->text->SetLayout(0); // standard layout
2900 if (current_view->text->cursor.par->footnoteflag ==
2901 LyXParagraph::NO_FOOTNOTE) {
2903 ->SetParagraph(0, 0,
2905 VSpace (0.3 * current_view->buffer()->
2906 params.spacing.getValue(),
2908 VSpace (0.3 * current_view->buffer()->
2909 params.spacing.getValue(),
2916 ->SetParagraph(0, 0,
2918 VSpace(VSpace::NONE),
2919 VSpace(VSpace::NONE),
2925 current_view->text->cursor.par->table =
2926 new LyXTable(xsize, ysize);
2928 Language const * lang =
2929 current_view->text->cursor.par->getParLanguage();
2930 LyXFont font(LyXFont::ALL_INHERIT,lang);
2931 for (int i = 0; i < xsize * ysize - 1; ++i) {
2932 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2933 current_view->text->cursor.par->SetFont(0, font);
2935 current_view->text->RedoParagraph();
2937 current_view->text->UnFreezeUndo();
2939 current_view->update(1);
2940 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2941 current_view->setState();
2945 extern "C" void TableCancelCB(FL_OBJECT *, long)
2947 fl_hide_form(fd_form_table->form_table);
2951 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2953 TableApplyCB(ob, data);
2954 TableCancelCB(ob, data);
2958 /* callbacks for form form_print */
2960 extern "C" void PrintCancelCB(FL_OBJECT *, long)
2962 fl_hide_form(fd_form_print->form_print);
2967 bool stringOnlyContains (string const & LStr, char const * cset)
2969 char const * cstr = LStr.c_str() ;
2971 return strspn(cstr, cset) == strlen(cstr) ;
2975 extern "C" void PrintApplyCB(FL_OBJECT *, long)
2977 if (!current_view->available())
2979 Buffer * buffer = current_view->buffer();
2980 string path = OnlyPath(buffer->fileName());
2983 if (fl_get_button(fd_form_print->radio_even_pages))
2984 pageflag = lyxrc.print_evenpage_flag + ' ';
2985 else if (fl_get_button(fd_form_print->radio_odd_pages))
2986 pageflag = lyxrc.print_oddpage_flag + ' ';
2988 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
2989 // User may give a page (range) list
2990 // User may print multiple (unsorted) copies
2991 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
2992 pages = subst(pages, '+',',');
2993 pages = frontStrip(strip(pages)) ;
2994 while (!pages.empty()) { // a page range was given
2996 pages = split (pages, piece, ',') ;
2997 piece = strip(piece) ;
2998 piece = frontStrip(piece) ;
2999 if ( !stringOnlyContains (piece, "0123456789-") ) {
3000 WriteAlert(_("ERROR! Unable to print!"),
3001 _("Check 'range of pages'!"));
3004 if (piece.find('-') == string::npos) { // not found
3005 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
3006 } else if (suffixIs(piece, "-") ) { // missing last page
3007 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
3008 } else if (prefixIs(piece, "-") ) { // missing first page
3009 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
3011 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
3015 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3016 if (!copies.empty()) { // a number of copies was given
3017 if ( !stringOnlyContains (copies, "0123456789") ) {
3018 WriteAlert(_("ERROR! Unable to print!"),
3019 _("Check 'number of copies'!"));
3022 if (fl_get_button(fd_form_print->do_unsorted))
3023 pageflag += lyxrc.print_copies_flag;
3025 pageflag += lyxrc.print_collcopies_flag;
3026 pageflag += " " + copies + ' ' ;
3030 if (fl_get_button(fd_form_print->radio_order_reverse))
3031 reverseflag = lyxrc.print_reverse_flag + ' ';
3033 string orientationflag;
3034 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3035 orientationflag = lyxrc.print_landscape_flag + ' ';
3037 string ps_file = fl_get_input(fd_form_print->input_file);
3038 string printer = strip(fl_get_input(fd_form_print->input_printer));
3041 if (lyxrc.print_adapt_output // printer name should be passed to dvips
3042 && ! printer.empty()) // a printer name has been given
3043 printerflag = lyxrc.print_to_printer + printer + ' ';
3046 if (!lyxrc.print_extra_options.empty())
3047 extraflags = lyxrc.print_extra_options + ' ';
3049 string command = lyxrc.print_command + ' '
3050 + printerflag + pageflag + reverseflag
3051 + orientationflag + extraflags;
3053 char real_papersize = buffer->params.papersize;
3054 if (real_papersize == BufferParams::PAPER_DEFAULT)
3055 real_papersize = lyxrc.default_papersize;
3058 switch (real_papersize) {
3059 case BufferParams::PAPER_USLETTER:
3062 case BufferParams::PAPER_A3PAPER:
3065 case BufferParams::PAPER_A4PAPER:
3068 case BufferParams::PAPER_A5PAPER:
3071 case BufferParams::PAPER_B5PAPER:
3074 case BufferParams::PAPER_EXECUTIVEPAPER:
3077 case BufferParams::PAPER_LEGALPAPER:
3080 default: /* If nothing else fits, keep an empty value... */
3084 if (buffer->params.use_geometry
3085 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3086 && !lyxrc.print_paper_dimension_flag.empty()
3087 && !buffer->params.paperwidth.empty()
3088 && !buffer->params.paperheight.empty()) {
3089 // using a custom papersize
3091 command += lyxrc.print_paper_dimension_flag + ' ';
3092 command += buffer->params.paperwidth + ',';
3093 command += buffer->params.paperheight + ' ';
3094 } else if (!lyxrc.print_paper_flag.empty()
3096 && (real_papersize != BufferParams::PAPER_USLETTER ||
3097 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3098 command += " " + lyxrc.print_paper_flag + " " + paper + " ";
3100 if (fl_get_button(fd_form_print->radio_file))
3101 command += lyxrc.print_to_file
3102 + QuoteName(MakeAbsPath(ps_file, path));
3103 else if (!lyxrc.print_spool_command.empty())
3104 command += lyxrc.print_to_file
3105 + QuoteName(ps_file);
3107 // push directorypath, if necessary
3108 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
3109 path = buffer->tmppath;
3114 if (!lyxrc.print_spool_command.empty() &&
3115 !fl_get_button(fd_form_print->radio_file)) {
3116 string command2 = lyxrc.print_spool_command + ' ';
3117 if (!printer.empty())
3118 command2 += lyxrc.print_spool_printerprefix
3120 // First run dvips and, if succesful, then spool command
3121 if ((result = RunScript(buffer, true, command))) {
3122 result = RunScript(buffer, false, command2, ps_file);
3125 result = RunScript(buffer, false, command);
3128 WriteAlert(_("Error:"),
3129 _("Unable to print"),
3130 _("Check that your parameters are correct"));
3134 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3136 PrintCancelCB(ob, data);
3137 PrintApplyCB(ob, data);
3141 /* callbacks for form form_figure */
3142 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3144 if (!current_view->available())
3147 Buffer * buffer = current_view->buffer();
3148 if(buffer->isReadonly()) // paranoia
3151 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3152 if (fl_get_button(fd_form_figure->radio_inline)
3153 || current_view->text->cursor.par->table) {
3154 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3155 current_view->insertInset(new_inset);
3156 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3157 new_inset->Edit(current_view, 0, 0, 0);
3161 current_view->hideCursor();
3162 current_view->update(-2);
3163 current_view->beforeChange();
3165 current_view->text->SetCursorParUndo();
3166 current_view->text->FreezeUndo();
3168 current_view->text->BreakParagraph();
3169 current_view->update(-1);
3171 if (current_view->text->cursor.par->Last()) {
3172 current_view->text->CursorLeft();
3174 current_view->text->BreakParagraph();
3175 current_view->update(-1);
3178 // The standard layout should always be numer 0;
3179 current_view->text->SetLayout(0);
3181 if (current_view->text->cursor.par->footnoteflag ==
3182 LyXParagraph::NO_FOOTNOTE) {
3183 current_view->text->
3186 VSpace (0.3 * buffer->params.spacing.getValue(),
3189 buffer->params.spacing.getValue(),
3191 LYX_ALIGN_CENTER, string(), 0);
3193 current_view->text->SetParagraph(0, 0,
3195 VSpace(VSpace::NONE),
3196 VSpace(VSpace::NONE),
3202 current_view->update(-1);
3204 Inset * new_inset = new InsetFig(100, 100, buffer);
3205 current_view->insertInset(new_inset);
3206 new_inset->Edit(current_view, 0, 0, 0);
3207 current_view->update(0);
3208 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3209 current_view->text->UnFreezeUndo();
3210 current_view->setState();
3214 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3216 fl_hide_form(fd_form_figure->form_figure);
3220 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3222 FigureApplyCB(ob, data);
3223 FigureCancelCB(ob, data);
3227 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3229 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
3230 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
3231 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3232 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
3233 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3234 fontloader.update();
3236 // All buffers will need resize
3237 bufferlist.resize();
3239 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3243 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3245 fl_hide_form(fd_form_screen->form_screen);
3249 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3251 ScreenCancelCB(ob, data);
3252 ScreenApplyCB(ob, data);
3256 void LaTeXOptions(BufferView * bv)
3258 if (!bv->available())
3261 fl_set_button(fd_latex_options->accents,
3262 int(bv->buffer()->params.allowAccents));
3264 if (fd_latex_options->LaTeXOptions->visible) {
3265 fl_raise_form(fd_latex_options->LaTeXOptions);
3267 fl_show_form(fd_latex_options->LaTeXOptions,
3268 FL_PLACE_MOUSE, FL_FULLBORDER,
3269 _("LaTeX Options"));
3274 // This function runs "configure" and then rereads lyx.defaults to
3275 // reconfigure the automatic settings.
3276 void Reconfigure(BufferView * bv)
3278 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3280 // Run configure in user lyx directory
3281 Path p(user_lyxdir);
3282 Systemcalls one(Systemcalls::System,
3283 AddName(system_lyxdir, "configure"));
3285 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3286 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
3287 WriteAlert(_("The system has been reconfigured."),
3288 _("You need to restart LyX to make use of any"),
3289 _("updated document class specifications."));
3294 // Table of Contents
3304 static TocList * toclist = 0;
3307 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3309 if (!current_view->available())
3312 TocList * tmptoclist = toclist;
3313 int i = fl_get_browser(ob);
3314 for (int a = 1; a < i && tmptoclist->next; ++a) {
3315 tmptoclist = tmptoclist->next;
3322 LyXParagraph * par = current_view->buffer()->paragraph;
3323 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3324 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3325 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3326 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3327 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3328 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3329 par->appendix != tmptoclist->appendix)) {
3330 par = par->LastPhysicalPar()->Next();
3334 current_view->beforeChange();
3335 current_view->text->SetCursor(par, 0);
3336 current_view->text->sel_cursor =
3337 current_view->text->cursor;
3338 current_view->update(0);
3341 WriteAlert(_("Error"),
3342 _("Couldn't find this label"),
3343 _("in current document."));
3349 extern "C" void TocCancelCB(FL_OBJECT *, long)
3351 fl_hide_form(fd_form_toc->form_toc);
3355 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3357 static LyXParagraph * stapar = 0;
3358 TocList * tmptoclist = 0;
3360 /* deleted the toclist */
3363 tmptoclist = toclist->next;
3365 toclist = tmptoclist;
3369 tmptoclist = toclist;
3372 fl_clear_browser(fd_form_toc->browser_toc);
3373 if (!current_view->available()) {
3374 fl_add_browser_line(fd_form_toc->browser_toc,
3375 _("*** No Document ***"));
3378 fl_hide_object(fd_form_toc->browser_toc);
3379 /* get the table of contents */
3380 LyXParagraph * par = current_view->buffer()->paragraph;
3382 char * line = new char[200];
3388 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3392 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3393 par->GetLayout()).labeltype;
3395 if (labeltype >= LABEL_COUNTER_CHAPTER
3396 && labeltype <= LABEL_COUNTER_CHAPTER +
3397 current_view->buffer()->params.tocdepth) {
3398 /* insert this into the table of contents */
3399 /* first indent a little bit */
3403 textclasslist.TextClass(current_view->buffer()->
3404 params.textclass).maxcounter()) * 4 + 2;
3408 // Then the labestring
3409 if (!par->labelstring.empty()) {
3410 string::size_type i = 0;
3411 while (pos < 199 && i < par->labelstring.length()) {
3412 line[pos] = par->labelstring[i];
3421 /* now the contents */
3422 LyXParagraph::size_type i = 0;
3423 while (pos < 199 && i < par->size()) {
3424 c = par->GetChar(i);
3425 if (isprint(c) || c >= 128) {
3432 fl_add_browser_line(fd_form_toc->browser_toc, line);
3434 /* make a toclist entry */
3436 tmptoclist = new TocList;
3437 toclist = tmptoclist;
3439 tmptoclist->next = new TocList;
3440 tmptoclist = tmptoclist->next;
3443 tmptoclist->next = 0;
3445 for (a = 0; a < 6; ++a) {
3446 tmptoclist->counter[a] = par->GetFirstCounter(a);
3448 tmptoclist->appendix = par->appendix;
3450 par = par->LastPhysicalPar()->Next();
3454 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3455 fl_show_object(fd_form_toc->browser_toc);
3459 /* callbacks for form form_ref */
3460 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3462 if (!current_view->available())
3466 fl_get_browser_line(fd_form_ref->browser_ref,
3467 fl_get_browser(fd_form_ref->browser_ref));
3468 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3474 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3484 if(current_view->buffer()->isSGML())
3485 t += "[" + u + "]" + "{" + s + "}";
3490 new InsetRef(t, current_view->buffer());
3491 current_view->insertInset(new_inset);
3495 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3497 if (!current_view->available()) {
3498 fl_clear_browser(fd_form_ref->browser_ref);
3502 FL_OBJECT * brow = fd_form_ref->browser_ref;
3504 // Get the current line, in order to restore it later
3505 char const * const btmp = fl_get_browser_line(brow,
3506 fl_get_browser(brow));
3507 string currentstr = btmp ? btmp : "";
3509 fl_clear_browser(brow);
3511 string refs = current_view->buffer()->getReferenceList('\n');
3514 fl_addto_browser_chars(brow, refs.c_str());
3515 int total_lines = fl_get_browser_maxline(brow);
3516 for (int i = 1; i <= total_lines ; ++i) {
3517 if (fl_get_browser_line(brow, i) == currentstr) {
3522 fl_set_browser_topline(brow, topline);
3524 if (!fl_get_browser_maxline(brow)) {
3525 fl_add_browser_line(brow,
3526 _("*** No labels found in document ***"));
3527 fl_deactivate_object(brow);
3529 fl_select_browser_line(brow, topline);
3530 fl_activate_object(brow);
3532 if (current_view->buffer()->isReadonly()) {
3533 // would be better to de/activate insert buttons
3534 // but that's more work... besides this works. ARRae
3535 fl_hide_form(fd_form_ref->form_ref);
3537 if (!current_view->buffer()->isSGML()) {
3538 fl_deactivate_object(fd_form_ref->ref_name);
3539 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3542 fl_activate_object(fd_form_ref->ref_name);
3543 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3548 extern "C" void RefHideCB(FL_OBJECT *, long)
3550 fl_hide_form(fd_form_ref->form_ref);