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 * ====================================================== */
17 #include "support/lstrings.h"
19 #include FORMS_H_LOCATION
21 #include "layout_forms.h"
22 #include "bullet_forms.h"
23 #include "print_form.h"
25 #include "spellchecker.h"
29 #include "insets/insetref.h"
30 #include "insets/insetquotes.h"
31 #include "insets/insetlabel.h"
32 #include "insets/figinset.h"
34 #include "latexoptions.h"
36 #include "minibuffer.h"
38 #include "bufferlist.h"
39 #include "support/filetools.h"
40 #include "support/path.h"
42 #include "lyx_gui_misc.h"
44 #include "lastfiles.h"
45 #include "support/FileInfo.h"
47 #include "support/syscall.h"
48 #include "support/lyxlib.h"
49 #include "lyxserver.h"
50 #include "FontLoader.h"
56 extern Combox * combo_language;
57 extern BufferList bufferlist;
58 extern void show_symbols_form();
59 extern FD_form_title * fd_form_title;
60 extern FD_form_paragraph * fd_form_paragraph;
61 extern FD_form_character * fd_form_character;
62 extern FD_form_document * fd_form_document;
63 extern FD_form_quotes * fd_form_quotes;
64 extern FD_form_preamble * fd_form_preamble;
65 extern FD_form_table * fd_form_table;
66 extern FD_form_print * fd_form_print;
67 extern FD_form_figure * fd_form_figure;
68 extern FD_form_screen * fd_form_screen;
69 extern FD_form_toc * fd_form_toc;
70 extern FD_form_ref * fd_form_ref;
71 extern FD_LaTeXOptions * fd_latex_options;
72 extern FD_form_bullet * fd_form_bullet;
74 extern BufferView * current_view; // called too many times in this file...
76 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
78 extern bool send_fax(string const & fname, string const & sendcmd);
79 extern void MenuSendto();
81 extern LyXServer * lyxserver;
82 extern FontLoader fontloader;
84 // this should be static, but I need it in buffer.C
85 bool quitting; // flag, that we are quitting the program
86 extern bool finished; // all cleanup done just let it run through now.
88 char ascii_type; /* for selection notify callbacks */
90 bool scrolling = false;
94 /* whether the work area should get callbacks */
95 bool input_prohibited = false;
97 /* the selection possible is needed, that only motion events are
98 * used, where the bottom press event was on the drawing area too */
99 bool selection_possible = false;
101 // This is used to make the dreaded font toggle problem hopefully go
102 // away. Definitely not the best solution, but I think it sorta works.
103 bool toggleall = true;
106 This is the inset locking stuff needed for mathed --------------------
108 an inset can simple call LockInset in it's edit call and *ONLY* in it's
110 Inset::Edit() can only be called by the main lyx module.
112 Then the inset may modify the menu's and/or iconbars.
114 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
116 During the lock, all button and keyboard events will be modified
117 and send to the inset through the following inset-features. Note that
118 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
119 to contain the code for restoring the menus and things like this.
122 virtual void InsetButtonPress(int x, int y, int button);
123 virtual void InsetButtonRelease(int x, int y, int button);
124 virtual void InsetKeyPress(XKeyEvent *ev);
125 virtual void InsetMotionNotify(int x, int y, int state);
126 virtual void InsetUnlock();
128 If a inset wishes any redraw and/or update it just has to call
130 It's is completly irrelevant, where the inset is. UpdateInset will
131 find it in any paragraph in any buffer.
132 Of course the_locking_inset and the insets in the current paragraph/buffer
133 are checked first, so no performance problem should occur.
135 Hope that's ok for the beginning, Alejandro,
136 sorry that I needed so much time,
141 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
143 /* these functions return 1 if an error occured,
145 // Now they work only for updatable insets. [Alejandro 080596]
146 //int LockInset(UpdatableInset * inset);
147 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
148 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
149 //int UnlockInset(UpdatableInset * inset);
150 //void LockedInsetStoreUndo(Undo::undo_kind kind);
152 /* this is for asyncron updating. UpdateInsetUpdateList will be called
153 automatically from LyX. Just insert the Inset into the Updatelist */
154 //void UpdateInsetUpdateList();
155 //void PutInsetIntoInsetUpdateList(Inset * inset);
157 //InsetUpdateStruct * InsetUpdateList = 0;
161 -----------------------------------------------------------------------
164 /* some function prototypes */
166 int RunLinuxDoc(int, string const &);
167 int RunDocBook(int, string const &);
168 void MenuWrite(Buffer * buf);
169 void MenuWriteAs(Buffer * buffer);
170 void MenuReload(Buffer * buf);
171 void MenuLayoutSave();
174 // How should this actually work? Should it prohibit input in all BufferViews,
175 // or just in the current one? If "just the current one", then it should be
176 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
177 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
178 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
179 // current LyxView that should be prohibited (Lgb) (This applies to
180 // "AllowInput" as well.)
183 input_prohibited = true;
184 current_view->hideCursor();
186 static Cursor cursor;
187 static bool cursor_undefined = true;
189 if (cursor_undefined){
190 cursor = XCreateFontCursor(fl_display, XC_watch);
192 cursor_undefined = false;
195 /* set the cursor to the watch for all forms and the canvas */
196 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
198 if (fd_form_paragraph->form_paragraph->visible)
199 XDefineCursor(fl_display,
200 fd_form_paragraph->form_paragraph->window,
202 if (fd_form_character->form_character->visible)
203 XDefineCursor(fl_display,
204 fd_form_character->form_character->window,
208 fl_deactivate_all_forms();
212 // Should find a way to move this into BufferView.C
213 void SetXtermCursor(Window win)
215 static Cursor cursor;
216 static bool cursor_undefined = true;
217 if (cursor_undefined){
218 cursor = XCreateFontCursor(fl_display, XC_xterm);
220 cursor_undefined = false;
222 XDefineCursor(fl_display, win, cursor);
229 input_prohibited = false;
231 /* reset the cursor from the watch for all forms and the canvas */
233 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
234 if (fd_form_paragraph->form_paragraph->visible)
235 XUndefineCursor(fl_display,
236 fd_form_paragraph->form_paragraph->window);
237 if (fd_form_character->form_character->visible)
238 XUndefineCursor(fl_display,
239 fd_form_character->form_character->window);
241 // What to do about this? (Lgb)
242 if (current_view->belowMouse())
243 SetXtermCursor(current_view->owner()->getForm()->window);
246 fl_activate_all_forms();
250 void FreeUpdateTimer()
252 /* a real free timer would be better but I don't know
253 * how to do this with xforms */
258 void SetUpdateTimer(float time)
260 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
273 // should be moved to lyxfunc.C
274 void MenuWrite(Buffer * buffer)
277 if (!buffer->save(lyxrc.make_backup)) {
278 string fname = buffer->fileName();
279 string s = MakeAbsPath(fname);
280 if (AskQuestion(_("Save failed. Rename and try again?"),
281 MakeDisplayPath(s, 50),
282 _("(If not, document is not saved.)"))) {
286 lastfiles->newFile(buffer->fileName());
291 // should be moved to BufferView.C
292 // Half of this func should be in LyXView, the rest in BufferView.
293 void MenuWriteAs(Buffer * buffer)
295 // Why do we require BufferView::text to be able to write a
296 // document? I see no point in that. (Lgb)
297 //if (!bv->text) return;
299 string fname = buffer->fileName();
300 string oldname = fname;
304 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
305 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
307 if (!IsLyXFilename(fname))
310 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
313 OnlyFilename(fname));
319 // Make sure the absolute filename ends with appropriate suffix
320 string s = MakeAbsPath(fname);
321 if (!IsLyXFilename(s))
324 // Same name as we have already?
326 if (!AskQuestion(_("Same name as document already has:"),
327 MakeDisplayPath(s, 50),
330 // Falls through to name change and save
332 // No, but do we have another file with this name open?
333 else if (bufferlist.exists(s)) {
334 if (AskQuestion(_("Another document with same name open!"),
335 MakeDisplayPath(s, 50),
336 _("Replace with current document?")))
338 bufferlist.close(bufferlist.getBuffer(s));
340 // Ok, change the name of the buffer, but don't save!
344 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
346 _("', but not saved..."));
349 } // Check whether the file exists
352 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
353 MakeDisplayPath(s, 50),
358 // Ok, change the name of the buffer
362 // Small bug: If the save fails, we have irreversible changed the name
368 int MenuRunLaTeX(Buffer * buffer)
372 if (buffer->isLinuxDoc())
373 ret = RunLinuxDoc(1, buffer->fileName());
374 else if (buffer->isLiterate())
375 ret = buffer->runLiterate();
376 else if (buffer->isDocBook())
377 ret = RunDocBook(1, buffer->fileName());
379 ret = buffer->runLaTeX();
385 s = _("One error detected");
386 t = _("You should try to fix it.");
389 s += _(" errors detected.");
390 t = _("You should try to fix them.");
392 WriteAlert(_("There were errors during the LaTeX run."), s, t);
398 int MenuBuildProg(Buffer * buffer)
402 if (buffer->isLiterate())
403 ret = buffer->buildProgram();
405 string s = _("Wrong type of document");
406 string t = _("The Build operation is not allowed in this document");
407 WriteAlert(_("There were errors during the Build process."), s, t);
415 s = _("One error detected");
416 t = _("You should try to fix it.");
419 s += _(" errors detected.");
420 t = _("You should try to fix them.");
422 WriteAlert(_("There were errors during the Build process."), s, t);
428 int MenuRunChktex(Buffer * buffer)
432 if (buffer->isSGML()) {
433 WriteAlert(_("Chktex does not work with SGML derived documents."));
436 ret = buffer->runChktex();
442 s = _("No warnings found.");
443 } else if (ret == 1) {
444 s = _("One warning found.");
445 t = _("Use 'Edit->Go to Error' to find it.");
448 s += _(" warnings found.");
449 t = _("Use 'Edit->Go to Error' to find them.");
451 WriteAlert(_("Chktex run successfully"), s, t);
453 WriteAlert(_("Error!"), _("It seems chktex does not work."));
459 int MakeLaTeXOutput(Buffer * buffer)
465 string path = OnlyPath(buffer->fileName());
466 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
467 path = buffer->tmppath;
469 if (!buffer->isDviClean()) {
471 ret = MenuRunLaTeX(buffer);
477 /* wait == false means don't wait for termination */
478 /* wait == true means wait for termination */
479 // The bool should be placed last on the argument line. (Lgb)
480 // Returns false if we fail.
481 bool RunScript(Buffer * buffer, bool wait,
482 string const & command,
483 string const & orgname = string(),
484 bool need_shell = true)
488 string name = orgname;
491 if (MakeLaTeXOutput(buffer) > 0)
493 /* get DVI-Filename */
495 name = ChangeExtension(buffer->getLatexName(),
498 path = OnlyPath(name);
499 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
500 path = buffer->tmppath;
503 // At this point we check whether the command contains the
504 // filename parameter $$FName and if that's the case we
505 // substitute the real file name otherwise the filename is
506 // simply appended. rokrau 1/12/00
508 std::string::size_type i;
509 if ( (i=command.find("$$FName")) != std::string::npos)
511 cmd.replace(i,7,QuoteName(name));
514 cmd = command + ' ' + QuoteName(name);
523 // OS/2 cmd.exe has another use for '&'
525 // This is not NLS safe, but it's OK, I think.
526 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
528 // COMSPEC is set, unless user unsets
529 sh = OnlyFilename(GetEnvPath("COMSPEC"));
534 if (contains(sh, "cmd.exe")
535 || contains(sh, "4os2.exe"))
536 cmd = "start /min/n " + cmd;
541 // It seems that, if wait is false, we never get back
542 // the return code of the command. This means that all
543 // the code I added in PrintApplyCB is currently
546 #warning What should we do here?
548 buffer->getUser()->owner()->getMiniBuffer()->Set(
549 _("Executing command:"), cmd);
550 result = one.startscript(Systemcalls::System, cmd);
552 buffer->getUser()->owner()->getMiniBuffer()->Set(
553 _("Executing command:"), cmd);
554 result = one.startscript(wait ? Systemcalls::Wait
555 : Systemcalls::DontWait, cmd);
561 // Returns false if we fail
562 bool CreatePostscript(Buffer * buffer, bool wait = false)
571 if (MakeLaTeXOutput(buffer) > 0) {
575 // Generate postscript file
576 string psname = ChangeExtension (buffer->fileName(),
582 char real_papersize = buffer->params.papersize;
583 if (real_papersize == BufferParams::PAPER_DEFAULT)
584 real_papersize = lyxrc.default_papersize;
586 switch (real_papersize) {
587 case BufferParams::PAPER_USLETTER:
590 case BufferParams::PAPER_A3PAPER:
593 case BufferParams::PAPER_A4PAPER:
596 case BufferParams::PAPER_A5PAPER:
599 case BufferParams::PAPER_B5PAPER:
602 case BufferParams::PAPER_EXECUTIVEPAPER:
605 case BufferParams::PAPER_LEGALPAPER:
608 default: /* If nothing else fits, keep an empty value... */
612 // Make postscript file.
613 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
614 command += QuoteName(psname);
615 if (buffer->params.use_geometry
616 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
617 && !lyxrc.print_paper_dimension_flag.empty()
618 && !buffer->params.paperwidth.empty()
619 && !buffer->params.paperheight.empty()) {
620 // using a custom papersize
622 command += lyxrc.print_paper_dimension_flag + ' ';
623 command += buffer->params.paperwidth + ',';
624 command += buffer->params.paperheight;
625 } else if (!paper.empty()
626 && (real_papersize != BufferParams::PAPER_USLETTER ||
627 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
628 // dvips won't accept -t letter -t landscape. In all other
629 // cases, include the paper size explicitly.
631 command += lyxrc.print_paper_flag + ' ' + paper;
633 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
635 command += lyxrc.print_landscape_flag;
637 // push directorypath, if necessary
638 string path = OnlyPath(buffer->fileName());
639 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
640 path = buffer->tmppath;
643 bool ret = RunScript(buffer, wait, command);
649 // Returns false if we fail
650 //bool MenuPreviewPS(Buffer * buffer)
651 bool PreviewPostscript(Buffer * buffer)
657 // Generate postscript file
658 if (!CreatePostscript(buffer, true)) {
662 // Start postscript viewer
664 string ps = ChangeExtension (buffer->fileName(),
666 // push directorypath, if necessary
667 string path = OnlyPath(buffer->fileName());
668 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
669 path = buffer->tmppath;
672 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
678 void MenuFax(Buffer * buffer)
684 // Generate postscript file
685 if (!CreatePostscript(buffer, true)) {
690 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
691 string path = OnlyPath (buffer->fileName());
692 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
693 path = buffer->tmppath;
696 if (!lyxrc.fax_program.empty()) {
697 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
699 Systemcalls one(Systemcalls::System, help2);
701 send_fax(ps, lyxrc.fax_command);
705 // Returns false if we fail
706 bool PreviewDVI(Buffer * buffer)
712 string paper = lyxrc.view_dvi_paper_option;
713 if (!paper.empty()) {
715 char real_papersize = buffer->params.papersize;
716 if (real_papersize == BufferParams::PAPER_DEFAULT)
717 real_papersize = lyxrc.default_papersize;
719 switch (real_papersize) {
720 case BufferParams::PAPER_USLETTER:
723 case BufferParams::PAPER_A3PAPER:
726 case BufferParams::PAPER_A4PAPER:
729 case BufferParams::PAPER_A5PAPER:
732 case BufferParams::PAPER_B5PAPER:
735 case BufferParams::PAPER_EXECUTIVEPAPER:
736 paper += " foolscap";
738 case BufferParams::PAPER_LEGALPAPER:
741 default: /* If nothing else fits, keep the empty value */
744 if (real_papersize==' ') {
745 // if (paper.empty()) {
746 if (buffer->params.orientation
747 == BufferParams::ORIENTATION_LANDSCAPE)
748 // we HAVE to give a size when the page is in
749 // landscape, so use USletter.
750 paper = " -paper usr";
752 // paper = " -paper " + paper;
753 if (buffer->params.orientation
754 == BufferParams::ORIENTATION_LANDSCAPE)
758 // push directorypath, if necessary
759 string path = OnlyPath(buffer->fileName());
760 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
761 path = buffer->tmppath;
765 string command = lyxrc.view_dvi_command + " " + paper;
766 bool ret = RunScript(buffer, false, command);
771 void MenuMakeLaTeX(Buffer * buffer)
773 // Why care about this?
777 // Get LaTeX-Filename
778 string s = buffer->getLatexName(false);
782 !AskQuestion(_("File already exists:"),
783 MakeDisplayPath(s, 50),
784 _("Do you want to overwrite the file?"))) {
785 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
789 if (buffer->isDocBook())
790 buffer->getUser()->owner()->getMiniBuffer()->Set(
791 _("DocBook does not have a latex backend"));
793 if (buffer->isLinuxDoc())
794 RunLinuxDoc(0, buffer->fileName());
796 buffer->makeLaTeXFile(s, string(), true);
797 buffer->getUser()->owner()->getMiniBuffer()->Set(
798 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
799 buffer->markDviDirty();
804 void MenuMakeLinuxDoc(Buffer * buffer)
807 //if (!bv->text) return;
809 if (!buffer->isLinuxDoc()) {
810 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
814 // Get LinuxDoc-Filename
815 string s = ChangeExtension(buffer->fileName(),
820 !AskQuestion(_("File already exists:"),
821 MakeDisplayPath(s, 50),
822 _("Do you want to overwrite the file?"))) {
823 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
827 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
828 MakeDisplayPath(s),"'...");
830 buffer->makeLinuxDocFile(s, 65);
832 buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
837 void MenuMakeDocBook(Buffer * buffer)
840 //if (!bv->text) return;
842 if (!buffer->isDocBook()) {
843 WriteAlert(_("Error!"),
844 _("Document class must be docbook."));
848 // Get DocBook-Filename
849 string s = ChangeExtension(buffer->fileName(),
854 !AskQuestion(_("File already exists:"),
855 MakeDisplayPath(s, 50),
856 _("Do you want to overwrite the file?"))) {
857 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
861 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
862 MakeDisplayPath(s), "'...");
864 buffer->makeDocBookFile(s, 65);
866 buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
871 void MenuMakeAscii(Buffer * buffer)
874 //if (!bv->text) return;
876 /* get LaTeX-Filename */
877 string s = ChangeExtension (buffer->fileName(),
882 !AskQuestion(_("File already exists:"),
883 MakeDisplayPath(s, 50),
884 _("Do you want to overwrite the file?"))) {
885 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
889 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
891 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
895 void MenuPrint(Buffer * buffer)
901 string input_file = ChangeExtension(buffer->fileName(),
902 lyxrc.print_file_extension,
904 fl_set_input(fd_form_print->input_file, input_file.c_str());
906 if (fd_form_print->form_print->visible) {
907 fl_raise_form(fd_form_print->form_print);
910 fl_show_form(fd_form_print->form_print,
911 FL_PLACE_MOUSE, FL_FULLBORDER,
916 void MenuMakeHTML(Buffer * buffer)
918 // First, create LaTeX file
919 MenuMakeLaTeX(buffer);
921 // And now, run the converter
922 string file = buffer->fileName();
923 Path path(OnlyPath(file));
924 // the tex file name has to be correct for
925 // latex, but the html file name can be
927 string result = ChangeExtension(file, ".html", false);
928 string infile = buffer->getLatexName(false);
929 string tmp = lyxrc.html_command;
930 tmp = subst(tmp, "$$FName", infile);
931 tmp = subst(tmp, "$$OutName", result);
933 int res = one.startscript(Systemcalls::System, tmp);
935 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
936 + MakeDisplayPath(result) +'\'');
938 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
939 + MakeDisplayPath(infile)
945 void MenuExport(Buffer * buffer, string const & extyp)
948 if (extyp == "latex") {
949 // make sure that this buffer is not linuxdoc
950 MenuMakeLaTeX(buffer);
953 else if (extyp == "linuxdoc") {
954 // make sure that this buffer is not latex
955 MenuMakeLinuxDoc(buffer);
958 else if (extyp == "docbook") {
959 // make sure that this buffer is not latex or linuxdoc
960 MenuMakeDocBook(buffer);
963 else if (extyp == "dvi") {
964 // Run LaTeX as "Update dvi..." Bernhard.
965 // We want the dvi in the current directory. This
966 // is achieved by temporarily disabling use of
967 // temp directory. As a side-effect, we get
968 // *.log and *.aux files also. (Asger)
969 bool flag = lyxrc.use_tempdir;
970 lyxrc.use_tempdir = false;
971 MenuRunLaTeX(buffer);
972 lyxrc.use_tempdir = flag;
975 else if (extyp == "postscript") {
976 // Start Print-dialog. Not as good as dvi... Bernhard.
978 // Since the MenuPrint is a pop-up, we can't use
979 // the same trick as above. (Asger)
980 // MISSING: Move of ps-file :-(
981 // And MenuPrint should not be used for this at all...
984 else if (extyp == "ascii") {
985 MenuMakeAscii(buffer);
987 else if (extyp == "custom") {
991 else if (extyp == "html") {
992 MenuMakeHTML(buffer);
995 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
1002 lyxerr.debug() << "Running QuitLyX." << endl;
1004 if (!bufferlist.QwriteAll())
1007 lastfiles->writeFile(lyxrc.lastfiles);
1009 // Set a flag that we do quitting from the program,
1010 // so no refreshes are necessary.
1013 // close buffers first
1014 bufferlist.closeAll();
1016 // do any other cleanup procedures now
1017 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1019 DestroyLyXTmpDir(system_tempdir);
1027 // should probably be moved into BufferList (Lgb)
1028 // Perfect target for a thread...
1030 if (!current_view->available())
1033 if (current_view->buffer()->isBakClean()
1034 || current_view->buffer()->isReadonly()) {
1035 // We don't save now, but we'll try again later
1036 current_view->owner()->resetAutosaveTimer();
1040 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1042 // create autosave filename
1043 string fname = OnlyPath(current_view->buffer()->fileName());
1045 fname += OnlyFilename(current_view->buffer()->fileName());
1048 // tmp_ret will be located (usually) in /tmp
1049 // will that be a problem?
1050 string tmp_ret = tmpnam(0);
1052 pid_t pid = fork(); // If you want to debug the autosave
1053 // you should set pid to -1, and comment out the
1055 if (pid == 0 || pid == -1) {
1056 // pid = -1 signifies that lyx was unable
1057 // to fork. But we will do the save
1059 bool failed = false;
1060 if (!tmp_ret.empty()) {
1061 current_view->buffer()->writeFile(tmp_ret, 1);
1062 // assume successful write of tmp_ret
1063 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1065 // most likely couldn't move between filesystems
1066 // unless write of tmp_ret failed
1067 // so remove tmp file (if it exists)
1068 remove(tmp_ret.c_str());
1075 // failed to write/rename tmp_ret so try writing direct
1076 if (!current_view->buffer()->writeFile(fname, 1)) {
1077 // It is dangerous to do this in the child,
1078 // but safe in the parent, so...
1080 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1083 if (pid == 0) { // we are the child so...
1088 current_view->buffer()->markBakClean();
1089 current_view->owner()->resetAutosaveTimer();
1094 // Copyright CHT Software Service GmbH
1097 // create new file with template
1100 Buffer * NewLyxFile(string const & filename)
1102 // Split argument by :
1104 string tmpname = split(filename, name, ':');
1105 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1106 if (name.length() == 1
1107 && isalpha(static_cast<unsigned char>(name[0]))
1108 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1110 name += token(tmpname, ':', 0);
1111 tmpname = split(tmpname, ':');
1114 lyxerr.debug() << "Arg is " << filename
1115 << "\nName is " << name
1116 << "\nTemplate is " << tmpname << endl;
1118 // find a free buffer
1119 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1121 lastfiles->newFile(tmpbuf->fileName());
1126 // Insert ascii file (if filename is empty, prompt for one)
1127 void InsertAsciiFile(string const & f, bool asParagraph)
1132 if (!current_view->available()) return;
1134 if (fname.empty()) {
1136 fname = fileDlg.Select(_("File to Insert"),
1137 current_view->owner()->buffer()->filepath,
1140 if (fname.empty()) return;
1145 if (!fi.readable()) {
1146 WriteFSAlert(_("Error! Specified file is unreadable: "),
1147 MakeDisplayPath(fname, 50));
1151 ifstream ifs(fname.c_str());
1153 WriteFSAlert(_("Error! Cannot open specified file: "),
1154 MakeDisplayPath(fname, 50));
1157 LyXParagraph * tmppar = new LyXParagraph;
1158 tmppar->readSimpleWholeFile(ifs);
1160 // set the end of the string
1161 #ifdef WITH_WARNINGS
1162 #warning why do we do this?
1164 // I don't think this is needed. Actually it might be plain wrong.
1165 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1167 // insert the string
1168 current_view->hideCursor();
1170 // clear the selection
1171 current_view->beforeChange();
1173 current_view->text->InsertStringA(tmppar->text);
1175 current_view->text->InsertStringB(tmppar->text);
1177 current_view->update(1);
1181 void MenuShowTableOfContents()
1183 static int ow = -1, oh;
1186 if (fd_form_toc->form_toc->visible) {
1187 fl_raise_form(fd_form_toc->form_toc);
1189 fl_show_form(fd_form_toc->form_toc,
1190 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1191 _("Table Of Contents"));
1193 ow = fd_form_toc->form_toc->w;
1194 oh = fd_form_toc->form_toc->h;
1196 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1201 void MenuInsertLabel(char const * arg)
1205 if (label.empty()) {
1207 result = askForText(_("Enter new label to insert:"));
1209 label = frontStrip(strip(result.second));
1212 if (!label.empty()) {
1213 InsetLabel * new_inset = new InsetLabel;
1214 new_inset->setContents(label);
1215 current_view->insertInset(new_inset);
1221 void MenuInsertRef()
1223 static int ow = -1, oh;
1226 if (fd_form_ref->form_ref->visible) {
1227 fl_raise_form(fd_form_ref->form_ref);
1229 fl_show_form(fd_form_ref->form_ref,
1230 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1231 _("Insert Reference"));
1233 ow = fd_form_ref->form_ref->w;
1234 oh = fd_form_ref->form_ref->h;
1236 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1241 void MenuPasteSelection(char at)
1243 if (!current_view->available())
1248 Atom data_prop = XInternAtom(fl_display,
1251 if (data_prop == None)
1253 XConvertSelection(fl_display,
1254 XA_PRIMARY, XA_STRING, data_prop,
1255 current_view->owner()->getForm()->window, 0);
1260 // candidate for move to BufferView
1261 void Foot(BufferView * bv)
1263 if (!bv->available())
1266 bv->owner()->getMiniBuffer()
1267 ->Set(_("Inserting Footnote..."));
1270 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1275 // candidate for move to LyXView
1276 // This is only used in toolbar.C
1277 void LayoutsCB(int sel, void *)
1279 string tmp = tostr(sel);
1280 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1286 * SGML Linuxdoc support:
1287 * (flag == -1) import SGML file
1288 * (flag == 0) make TeX output
1289 * (flag == 1) make dvi output
1291 int RunLinuxDoc(int flag, string const & filename)
1300 /* generate a path-less extension name */
1301 name = ChangeExtension (filename, ".sgml", true);
1302 path = OnlyPath (filename);
1303 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1304 path = current_view->buffer()->tmppath;
1309 if (!current_view->available())
1311 current_view->buffer()->makeLinuxDocFile(name, 0);
1312 #ifdef WITH_WARNINGS
1313 #warning remove this once we have a proper geometry class
1315 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1317 case BufferParams::PAPER_A4PAPER:
1318 add_flags = "-p a4";
1320 case BufferParams::PAPER_USLETTER:
1321 add_flags = "-p letter";
1323 default: /* nothing to be done yet ;-) */ break;
1331 case -1: /* Import file */
1332 current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"),
1333 MakeDisplayPath(filename), "'...");
1334 s2 = "sgml2lyx " + lyxrc.sgml_extra_options + ' '
1336 if (one.startscript(Systemcalls::System, s2))
1339 case 0: /* TeX output asked */
1340 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1341 s2 = "sgml2latex " + add_flags + " -o tex "
1342 + lyxrc.sgml_extra_options + ' ' + name;
1343 if (one.startscript(Systemcalls::System, s2))
1346 case 1: /* dvi output asked */
1347 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1348 s2 = "sgml2latex " + add_flags + " -o dvi "
1349 + lyxrc.sgml_extra_options + ' ' + name;
1350 if (one.startscript(Systemcalls::System, s2)) {
1353 current_view->buffer()->markDviClean();
1355 default: /* unknown output */
1361 current_view->buffer()->redraw();
1367 * SGML DocBook support:
1368 * (flag == 1) make dvi output
1370 int RunDocBook(int flag, string const & filename)
1372 /* generate a path-less extension name */
1373 string name = ChangeExtension (filename, ".sgml", true);
1374 string path = OnlyPath (filename);
1375 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1376 path = current_view->buffer()->tmppath;
1380 if (!current_view->available())
1383 current_view->buffer()->makeDocBookFile(name, 0);
1385 // Shall this code go or should it stay? (Lgb)
1386 // string add_flags;
1387 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1389 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1390 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1391 // default: /* nothing to be done yet ;-) */ break;
1398 case 1: /* dvi output asked */
1400 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1401 string s2 = "sgmltools --backend dvi " + name;
1402 if (one.startscript(Systemcalls::System, s2)) {
1405 current_view->buffer()->markDviClean();
1408 default: /* unknown output */
1414 current_view->buffer()->redraw();
1419 void MenuLayoutCharacter()
1421 static int ow = -1, oh;
1423 if (fd_form_character->form_character->visible) {
1424 fl_raise_form(fd_form_character->form_character);
1426 fl_show_form(fd_form_character->form_character,
1427 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1428 _("Character Style"));
1430 ow = fd_form_character->form_character->w;
1431 oh = fd_form_character->form_character->h;
1433 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1439 void DeactivateParagraphButtons ()
1441 fl_deactivate_object (fd_form_paragraph->button_ok);
1442 fl_deactivate_object (fd_form_paragraph->button_apply);
1443 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1444 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1449 void ActivateParagraphButtons ()
1451 fl_activate_object (fd_form_paragraph->button_ok);
1452 fl_activate_object (fd_form_paragraph->button_apply);
1453 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1454 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1459 void DisableParagraphLayout ()
1461 DeactivateParagraphButtons();
1462 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1463 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1464 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1465 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1466 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1467 fl_deactivate_object (fd_form_paragraph->check_noindent);
1468 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1469 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1470 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1471 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1472 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1473 fl_deactivate_object (fd_form_paragraph->input_space_above);
1474 fl_deactivate_object (fd_form_paragraph->input_space_below);
1475 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1476 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1477 fl_deactivate_object (fd_form_paragraph->check_space_above);
1478 fl_deactivate_object (fd_form_paragraph->check_space_below);
1483 void EnableParagraphLayout ()
1485 ActivateParagraphButtons();
1486 fl_activate_object (fd_form_paragraph->input_labelwidth);
1487 fl_activate_object (fd_form_paragraph->check_lines_top);
1488 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1489 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1490 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1491 fl_activate_object (fd_form_paragraph->check_noindent);
1492 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1493 fl_activate_object (fd_form_paragraph->radio_align_right);
1494 fl_activate_object (fd_form_paragraph->radio_align_left);
1495 fl_activate_object (fd_form_paragraph->radio_align_block);
1496 fl_activate_object (fd_form_paragraph->radio_align_center);
1497 fl_activate_object (fd_form_paragraph->input_space_above);
1498 fl_activate_object (fd_form_paragraph->input_space_below);
1499 fl_activate_object (fd_form_paragraph->choice_space_above);
1500 fl_activate_object (fd_form_paragraph->choice_space_below);
1501 fl_activate_object (fd_form_paragraph->check_space_above);
1502 fl_activate_object (fd_form_paragraph->check_space_below);
1506 bool UpdateLayoutParagraph()
1508 if (!current_view->available()) {
1509 if (fd_form_paragraph->form_paragraph->visible)
1510 fl_hide_form(fd_form_paragraph->form_paragraph);
1514 Buffer * buf = current_view->buffer();
1516 fl_set_input(fd_form_paragraph->input_labelwidth,
1517 current_view->text->cursor.par->GetLabelWidthString().c_str());
1518 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1519 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1520 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1521 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1523 int align = current_view->text->cursor.par->GetAlign();
1524 if (align == LYX_ALIGN_LAYOUT)
1525 align = textclasslist.Style(buf->params.textclass,
1526 current_view->text->cursor.par->GetLayout()).align;
1529 case LYX_ALIGN_RIGHT:
1530 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1532 case LYX_ALIGN_LEFT:
1533 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1535 case LYX_ALIGN_CENTER:
1536 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1539 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1543 fl_set_button(fd_form_paragraph->check_lines_top,
1544 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1545 fl_set_button(fd_form_paragraph->check_lines_bottom,
1546 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1547 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1548 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1549 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1550 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1551 fl_set_button(fd_form_paragraph->check_noindent,
1552 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1553 fl_set_input (fd_form_paragraph->input_space_above, "");
1555 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1557 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1559 case VSpace::DEFSKIP:
1560 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1562 case VSpace::SMALLSKIP:
1563 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1565 case VSpace::MEDSKIP:
1566 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1568 case VSpace::BIGSKIP:
1569 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1572 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1574 case VSpace::LENGTH:
1575 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1576 fl_set_input (fd_form_paragraph->input_space_above,
1577 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1580 fl_set_button (fd_form_paragraph->check_space_above,
1581 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1582 fl_set_input (fd_form_paragraph->input_space_below, "");
1583 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1585 fl_set_choice (fd_form_paragraph->choice_space_below,
1588 case VSpace::DEFSKIP:
1589 fl_set_choice (fd_form_paragraph->choice_space_below,
1592 case VSpace::SMALLSKIP:
1593 fl_set_choice (fd_form_paragraph->choice_space_below,
1596 case VSpace::MEDSKIP:
1597 fl_set_choice (fd_form_paragraph->choice_space_below,
1600 case VSpace::BIGSKIP:
1601 fl_set_choice (fd_form_paragraph->choice_space_below,
1605 fl_set_choice (fd_form_paragraph->choice_space_below,
1608 case VSpace::LENGTH:
1609 fl_set_choice (fd_form_paragraph->choice_space_below,
1611 fl_set_input (fd_form_paragraph->input_space_below,
1612 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1615 fl_set_button (fd_form_paragraph->check_space_below,
1616 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1618 fl_set_button(fd_form_paragraph->check_noindent,
1619 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1621 if (current_view->buffer()->isReadonly()) {
1622 DisableParagraphLayout();
1624 EnableParagraphLayout();
1630 void MenuLayoutParagraph()
1632 if (UpdateLayoutParagraph()) {
1633 if (fd_form_paragraph->form_paragraph->visible) {
1634 fl_raise_form(fd_form_paragraph->form_paragraph);
1636 fl_show_form(fd_form_paragraph->form_paragraph,
1637 FL_PLACE_MOUSE, FL_FULLBORDER,
1638 _("Paragraph Environment"));
1645 void DeactivateDocumentButtons ()
1647 fl_deactivate_object (fd_form_document->button_ok);
1648 fl_deactivate_object (fd_form_document->button_apply);
1649 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1650 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1655 void ActivateDocumentButtons ()
1657 fl_activate_object (fd_form_document->button_ok);
1658 fl_activate_object (fd_form_document->button_apply);
1659 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1660 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1665 void DisableDocumentLayout ()
1667 DeactivateDocumentButtons ();
1668 fl_deactivate_object (fd_form_document->group_radio_separation);
1669 fl_deactivate_object (fd_form_document->radio_indent);
1670 fl_deactivate_object (fd_form_document->radio_skip);
1671 fl_deactivate_object (fd_form_document->choice_class);
1672 fl_deactivate_object (fd_form_document->choice_pagestyle);
1673 fl_deactivate_object (fd_form_document->choice_fonts);
1674 fl_deactivate_object (fd_form_document->choice_fontsize);
1675 fl_deactivate_object (fd_form_document->input_float_placement);
1676 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1677 fl_deactivate_object (fd_form_document->choice_inputenc);
1678 fl_deactivate_object (fd_form_document->group_radio_sides);
1679 fl_deactivate_object (fd_form_document->radio_sides_one);
1680 fl_deactivate_object (fd_form_document->radio_sides_two);
1681 fl_deactivate_object (fd_form_document->group_radio_columns);
1682 fl_deactivate_object (fd_form_document->radio_columns_one);
1683 fl_deactivate_object (fd_form_document->radio_columns_two);
1684 fl_deactivate_object (fd_form_document->input_extra);
1685 fl_deactivate_object (fd_form_document->choice_language);
1686 combo_language->deactivate();
1687 fl_deactivate_object (fd_form_document->input_default_skip);
1688 fl_deactivate_object (fd_form_document->choice_default_skip);
1689 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1690 fl_deactivate_object (fd_form_document->slider_tocdepth);
1691 fl_deactivate_object (fd_form_document->choice_spacing);
1692 fl_deactivate_object (fd_form_document->input_spacing);
1693 fl_deactivate_object (fd_form_document->check_use_amsmath);
1698 void EnableDocumentLayout ()
1700 ActivateDocumentButtons ();
1701 fl_activate_object (fd_form_document->group_radio_separation);
1702 fl_activate_object (fd_form_document->radio_indent);
1703 fl_activate_object (fd_form_document->radio_skip);
1704 fl_activate_object (fd_form_document->choice_class);
1705 fl_activate_object (fd_form_document->choice_pagestyle);
1706 fl_activate_object (fd_form_document->choice_fonts);
1707 fl_activate_object (fd_form_document->choice_fontsize);
1708 fl_activate_object (fd_form_document->input_float_placement);
1709 fl_activate_object (fd_form_document->choice_postscript_driver);
1710 fl_activate_object (fd_form_document->choice_inputenc);
1711 fl_activate_object (fd_form_document->group_radio_sides);
1712 fl_activate_object (fd_form_document->radio_sides_one);
1713 fl_activate_object (fd_form_document->radio_sides_two);
1714 fl_activate_object (fd_form_document->group_radio_columns);
1715 fl_activate_object (fd_form_document->radio_columns_one);
1716 fl_activate_object (fd_form_document->radio_columns_two);
1717 fl_activate_object (fd_form_document->input_extra);
1718 fl_activate_object (fd_form_document->choice_language);
1719 combo_language->activate();
1720 fl_activate_object (fd_form_document->input_default_skip);
1721 fl_activate_object (fd_form_document->choice_default_skip);
1722 fl_activate_object (fd_form_document->slider_secnumdepth);
1723 fl_activate_object (fd_form_document->slider_tocdepth);
1724 fl_activate_object (fd_form_document->choice_spacing);
1725 fl_activate_object (fd_form_document->input_spacing);
1726 fl_activate_object (fd_form_document->check_use_amsmath);
1730 bool UpdateLayoutDocument(BufferParams * params)
1732 if (!current_view->available()) {
1733 if (fd_form_document->form_document->visible)
1734 fl_hide_form(fd_form_document->form_document);
1739 params = ¤t_view->buffer()->params;
1740 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1742 fl_set_choice_text(fd_form_document->choice_class,
1743 textclasslist.DescOfClass(params->textclass).c_str());
1744 combo_language->select_text(params->language.c_str());
1746 fl_set_choice_text(fd_form_document->choice_fonts,
1747 params->fonts.c_str());
1748 fl_set_choice_text(fd_form_document->choice_inputenc,
1749 params->inputenc.c_str());
1750 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1751 params->graphicsDriver.c_str());
1753 // ale970405+lasgoutt970513
1754 fl_clear_choice(fd_form_document->choice_fontsize);
1755 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1756 fl_addto_choice(fd_form_document->choice_fontsize,
1757 tclass.opt_fontsize().c_str());
1758 fl_set_choice(fd_form_document->choice_fontsize,
1759 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1761 // ale970405+lasgoutt970513
1762 fl_clear_choice(fd_form_document->choice_pagestyle);
1763 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1764 fl_addto_choice(fd_form_document->choice_pagestyle,
1765 tclass.opt_pagestyle().c_str());
1767 fl_set_choice(fd_form_document->choice_pagestyle,
1768 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1770 fl_set_button(fd_form_document->radio_indent, 0);
1771 fl_set_button(fd_form_document->radio_skip, 0);
1774 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1776 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1777 fl_set_button(fd_form_document->radio_indent, 1);
1779 fl_set_button(fd_form_document->radio_skip, 1);
1781 switch (params->getDefSkip().kind()) {
1782 case VSpace::SMALLSKIP:
1783 fl_set_choice (fd_form_document->choice_default_skip, 1);
1785 case VSpace::MEDSKIP:
1786 fl_set_choice (fd_form_document->choice_default_skip, 2);
1788 case VSpace::BIGSKIP:
1789 fl_set_choice (fd_form_document->choice_default_skip, 3);
1791 case VSpace::LENGTH:
1792 fl_set_choice (fd_form_document->choice_default_skip, 4);
1793 fl_set_input (fd_form_document->input_default_skip,
1794 params->getDefSkip().asLyXCommand().c_str());
1797 fl_set_choice (fd_form_document->choice_default_skip, 2);
1801 fl_set_button(fd_form_document->radio_sides_one, 0);
1802 fl_set_button(fd_form_document->radio_sides_two, 0);
1804 switch (params->sides) {
1805 case LyXTextClass::OneSide:
1806 fl_set_button(fd_form_document->radio_sides_one, 1);
1808 case LyXTextClass::TwoSides:
1809 fl_set_button(fd_form_document->radio_sides_two, 1);
1813 fl_set_button(fd_form_document->radio_columns_one, 0);
1814 fl_set_button(fd_form_document->radio_columns_two, 0);
1816 if (params->columns == 2)
1817 fl_set_button(fd_form_document->radio_columns_two, 1);
1819 fl_set_button(fd_form_document->radio_columns_one, 1);
1821 fl_set_input(fd_form_document->input_spacing, "");
1822 switch (params->spacing.getSpace()) {
1823 case Spacing::Single:
1826 fl_set_choice(fd_form_document->choice_spacing, 1);
1829 case Spacing::Onehalf:
1832 fl_set_choice(fd_form_document->choice_spacing, 2);
1835 case Spacing::Double:
1838 fl_set_choice(fd_form_document->choice_spacing, 3);
1841 case Spacing::Other:
1843 fl_set_choice(fd_form_document->choice_spacing, 4);
1845 //sprintf(sval, "%g", params->spacing.getValue());
1848 sval << params->spacing.getValue(); // setw?
1849 fl_set_input(fd_form_document->input_spacing,
1850 sval.str().c_str());
1853 ostrstream sval(tval, 20);
1854 sval << params->spacing.getValue() << '\0'; // setw?
1855 fl_set_input(fd_form_document->input_spacing, sval.str());
1862 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1863 params->secnumdepth);
1864 fl_set_counter_value(fd_form_document->slider_tocdepth,
1866 if (!params->float_placement.empty()) { // buffer local (Lgb)
1867 fl_set_input(fd_form_document->input_float_placement,
1868 params->float_placement.c_str());
1870 fl_set_input(fd_form_document->input_float_placement, "");
1872 if (!params->options.empty())
1873 fl_set_input(fd_form_document->input_extra,
1874 params->options.c_str());
1876 fl_set_input(fd_form_document->input_extra, "");
1878 if (current_view->buffer()->isSGML()) {
1879 // bullets not used in SGML derived documents
1880 fl_deactivate_object(fd_form_document->button_bullets);
1881 fl_set_object_lcol(fd_form_document->button_bullets,
1884 fl_activate_object(fd_form_document->button_bullets);
1885 fl_set_object_lcol(fd_form_document->button_bullets,
1889 if (current_view->buffer()->isReadonly()) {
1890 DisableDocumentLayout();
1892 EnableDocumentLayout();
1899 void MenuLayoutDocument()
1901 if (UpdateLayoutDocument()) {
1902 if (fd_form_document->form_document->visible) {
1903 fl_raise_form(fd_form_document->form_document);
1905 fl_show_form(fd_form_document->form_document,
1906 FL_PLACE_MOUSE, FL_FULLBORDER,
1907 _("Document Layout"));
1913 bool UpdateLayoutQuotes()
1916 if (!current_view->available()
1917 || current_view->buffer()->isReadonly())
1921 fl_set_choice(fd_form_quotes->choice_quotes_language,
1922 current_view->buffer()->params.quotes_language + 1);
1923 fl_set_button(fd_form_quotes->radio_single, 0);
1924 fl_set_button(fd_form_quotes->radio_double, 0);
1926 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1927 fl_set_button(fd_form_quotes->radio_single, 1);
1929 fl_set_button(fd_form_quotes->radio_double, 1);
1930 } else if (fd_form_quotes->form_quotes->visible) {
1931 fl_hide_form(fd_form_quotes->form_quotes);
1937 void MenuLayoutQuotes()
1939 if (UpdateLayoutQuotes()) {
1940 if (fd_form_quotes->form_quotes->visible) {
1941 fl_raise_form(fd_form_quotes->form_quotes);
1943 fl_show_form(fd_form_quotes->form_quotes,
1944 FL_PLACE_MOUSE, FL_FULLBORDER,
1951 bool UpdateLayoutPreamble()
1954 if (!current_view->available())
1958 fl_set_input(fd_form_preamble->input_preamble,
1959 current_view->buffer()->params.preamble.c_str());
1961 if (current_view->buffer()->isReadonly()) {
1962 fl_deactivate_object(fd_form_preamble->input_preamble);
1963 fl_deactivate_object(fd_form_preamble->button_ok);
1964 fl_deactivate_object(fd_form_preamble->button_apply);
1965 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1966 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1969 fl_activate_object(fd_form_preamble->input_preamble);
1970 fl_activate_object(fd_form_preamble->button_ok);
1971 fl_activate_object(fd_form_preamble->button_apply);
1972 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1973 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1975 } else if (fd_form_preamble->form_preamble->visible) {
1976 fl_hide_form(fd_form_preamble->form_preamble);
1982 void MenuLayoutPreamble()
1984 static int ow = -1, oh;
1986 if (UpdateLayoutPreamble()) {
1987 if (fd_form_preamble->form_preamble->visible) {
1988 fl_raise_form(fd_form_preamble->form_preamble);
1990 fl_show_form(fd_form_preamble->form_preamble,
1991 FL_PLACE_MOUSE | FL_FREE_SIZE,
1993 _("LaTeX Preamble"));
1995 ow = fd_form_preamble->form_preamble->w;
1996 oh = fd_form_preamble->form_preamble->h;
1998 fl_set_form_minsize(fd_form_preamble->form_preamble,
2005 void MenuLayoutSave()
2007 if (!current_view->available())
2010 if (AskQuestion(_("Do you want to save the current settings"),
2011 _("for Character, Document, Paper and Quotes"),
2012 _("as default for new documents?")))
2013 current_view->buffer()->saveParamsAsDefaults();
2017 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2018 They also show the current font state. */
2021 void ToggleAndShow(BufferView *, LyXFont const &);
2024 void FontSize(string const & size)
2026 LyXFont font(LyXFont::ALL_IGNORE);
2027 font.setGUISize(size);
2028 ToggleAndShow(current_view, font);
2034 LyXFont font(LyXFont::ALL_IGNORE);
2035 font.setEmph(LyXFont::TOGGLE);
2036 ToggleAndShow(current_view, font);
2042 LyXFont font(LyXFont::ALL_IGNORE);
2043 font.setNoun(LyXFont::TOGGLE);
2044 ToggleAndShow(current_view, font);
2050 LyXFont font(LyXFont::ALL_IGNORE);
2051 font.setSeries(LyXFont::BOLD_SERIES);
2052 ToggleAndShow(current_view, font);
2058 LyXFont font(LyXFont::ALL_IGNORE);
2059 font.setUnderbar(LyXFont::TOGGLE);
2060 ToggleAndShow(current_view, font);
2066 LyXFont font(LyXFont::ALL_IGNORE);
2067 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2068 ToggleAndShow(current_view, font);
2074 LyXFont font(LyXFont::ALL_IGNORE);
2075 font.setFamily(LyXFont::SANS_FAMILY);
2076 ToggleAndShow(current_view, font);
2082 LyXFont font(LyXFont::ALL_IGNORE);
2083 font.setFamily(LyXFont::ROMAN_FAMILY);
2084 ToggleAndShow(current_view, font);
2090 LyXFont font(LyXFont::ALL_IGNORE);
2091 font.setLatex (LyXFont::TOGGLE);
2092 ToggleAndShow(current_view, font);
2097 LyXFont font(LyXFont::ALL_IGNORE);
2098 font.setDirection (LyXFont::TOGGLE_DIR);
2099 ToggleAndShow(current_view, font);
2105 LyXFont font(LyXFont::ALL_INHERIT);
2106 ToggleAndShow(current_view, font);
2110 /* -------> Returns the current font and depth by printing a message. In the
2111 * future perhaps we could try to implement a callback to the button-bar.
2112 * That is, `light' the bold button when the font is currently bold, etc.
2114 string CurrentState()
2117 if (current_view->available()) {
2118 // I think we should only show changes from the default
2120 Buffer * buffer = current_view->buffer();
2121 LyXFont font = current_view->text->real_current_font;
2122 LyXFont defaultfont = textclasslist.TextClass(buffer->
2123 params.textclass).defaultfont();
2124 font.reduce(defaultfont);
2125 state = _("Font: ") + font.stateText();
2127 int depth = current_view->text->GetDepth();
2129 state += string(_(", Depth: ")) + tostr(depth);
2135 // candidate for move to BufferView
2136 /* -------> Does the actual toggle job of the XxxCB() calls above.
2137 * Also shows the current font state.
2140 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2142 if (bv->available()) {
2145 if (bv->the_locking_inset)
2146 bv->the_locking_inset->SetFont(bv, font, toggleall);
2148 bv->text->ToggleFree(font, toggleall);
2154 // candidate for move to BufferView
2155 void Margin(BufferView * bv)
2157 if (bv->available()) {
2158 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2161 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2169 if (fd_form_figure->form_figure->visible) {
2170 fl_raise_form(fd_form_figure->form_figure);
2172 fl_show_form(fd_form_figure->form_figure,
2173 FL_PLACE_MOUSE, FL_FULLBORDER,
2174 _("Insert Figure"));
2181 if (fd_form_table->form_table->visible) {
2182 fl_raise_form(fd_form_table->form_table);
2184 fl_show_form(fd_form_table->form_table,
2185 FL_PLACE_MOUSE, FL_FULLBORDER,
2191 // candidate for move to BufferView
2192 void Melt(BufferView * bv)
2194 if (!bv->available()) return;
2196 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2200 bv->text->MeltFootnoteEnvironment();
2205 // candidate for move to BufferView
2206 // Change environment depth.
2207 // if decInc >= 0, increment depth
2208 // if decInc < 0, decrement depth
2209 void changeDepth(BufferView * bv, int decInc)
2211 if (!bv->available()) return;
2216 bv->text->IncDepth();
2218 bv->text->DecDepth();
2220 bv->owner()->getMiniBuffer()
2221 ->Set(_("Changed environment depth"
2222 " (in possible range, maybe not)"));
2226 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2227 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2228 LyXFont UserFreeFont()
2230 LyXFont font(LyXFont::ALL_IGNORE);
2232 int pos = fl_get_choice(fd_form_character->choice_family);
2234 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2235 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2236 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2237 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2238 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2241 pos = fl_get_choice(fd_form_character->choice_series);
2243 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2244 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2245 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2246 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2249 pos = fl_get_choice(fd_form_character->choice_shape);
2251 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2252 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2253 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2254 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2255 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2256 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2259 pos = fl_get_choice(fd_form_character->choice_size);
2261 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2262 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2263 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2264 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2265 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2266 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2267 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2268 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2269 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2270 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2271 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2272 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2273 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2274 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2277 pos = fl_get_choice(fd_form_character->choice_bar);
2279 case 1: font.setEmph(LyXFont::IGNORE);
2280 font.setUnderbar(LyXFont::IGNORE);
2281 font.setNoun(LyXFont::IGNORE);
2282 font.setLatex(LyXFont::IGNORE);
2284 case 2: font.setEmph(LyXFont::TOGGLE); break;
2285 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2286 case 4: font.setNoun(LyXFont::TOGGLE); break;
2287 case 5: font.setLatex(LyXFont::TOGGLE); break;
2288 case 6: font.setEmph(LyXFont::INHERIT);
2289 font.setUnderbar(LyXFont::INHERIT);
2290 font.setNoun(LyXFont::INHERIT);
2291 font.setLatex(LyXFont::INHERIT);
2295 pos = fl_get_choice(fd_form_character->choice_color);
2297 case 1: font.setColor(LColor::ignore); break;
2298 case 2: font.setColor(LColor::none); break;
2299 case 3: font.setColor(LColor::black); break;
2300 case 4: font.setColor(LColor::white); break;
2301 case 5: font.setColor(LColor::red); break;
2302 case 6: font.setColor(LColor::green); break;
2303 case 7: font.setColor(LColor::blue); break;
2304 case 8: font.setColor(LColor::cyan); break;
2305 case 9: font.setColor(LColor::magenta); break;
2306 case 10: font.setColor(LColor::yellow); break;
2307 case 11: font.setColor(LColor::inherit); break;
2316 ToggleAndShow(current_view, UserFreeFont());
2320 /* callbacks for form form_title */
2321 extern "C" void TimerCB(FL_OBJECT *, long)
2323 // only if the form still exists
2324 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2325 if (fd_form_title->form_title->visible) {
2326 fl_hide_form(fd_form_title->form_title);
2328 fl_free_form(fd_form_title->form_title);
2329 fd_form_title->form_title = 0;
2334 /* callbacks for form form_paragraph */
2336 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2338 // "Synchronize" the choices and input fields, making it
2339 // impossible to commit senseless data.
2341 FD_form_paragraph const * fp = fd_form_paragraph;
2343 if (obj == fp->choice_space_above) {
2344 if (fl_get_choice (fp->choice_space_above) != 7) {
2345 fl_set_input (fp->input_space_above, "");
2346 ActivateParagraphButtons();
2348 } else if (obj == fp->choice_space_below) {
2349 if (fl_get_choice (fp->choice_space_below) != 7) {
2350 fl_set_input (fp->input_space_below, "");
2351 ActivateParagraphButtons();
2353 } else if (obj == fp->input_space_above) {
2354 string input = fl_get_input (fp->input_space_above);
2356 if (input.empty()) {
2357 fl_set_choice (fp->choice_space_above, 1);
2358 ActivateParagraphButtons();
2360 else if (isValidGlueLength (input)) {
2361 fl_set_choice (fp->choice_space_above, 7);
2362 ActivateParagraphButtons();
2365 fl_set_choice (fp->choice_space_above, 7);
2366 DeactivateParagraphButtons();
2368 } else if (obj == fp->input_space_below) {
2369 string input = fl_get_input (fp->input_space_below);
2371 if (input.empty()) {
2372 fl_set_choice (fp->choice_space_below, 1);
2373 ActivateParagraphButtons();
2375 else if (isValidGlueLength (input)) {
2376 fl_set_choice (fp->choice_space_below, 7);
2377 ActivateParagraphButtons();
2380 fl_set_choice (fp->choice_space_below, 7);
2381 DeactivateParagraphButtons();
2387 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2389 if (!current_view->available())
2392 VSpace space_top, space_bottom;
2394 string labelwidthstring;
2397 // If a vspace kind is "Length" but there's no text in
2398 // the input field, reset the kind to "None".
2399 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2400 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2401 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2403 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2404 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2405 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2408 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2409 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2410 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2411 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2412 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2413 case 1: space_top = VSpace(VSpace::NONE); break;
2414 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2415 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2416 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2417 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2418 case 6: space_top = VSpace(VSpace::VFILL); break;
2419 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2421 if (fl_get_button (fd_form_paragraph->check_space_above))
2422 space_top.setKeep (true);
2423 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2424 case 1: space_bottom = VSpace(VSpace::NONE); break;
2425 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2426 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2427 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2428 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2429 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2430 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2432 if (fl_get_button (fd_form_paragraph->check_space_below))
2433 space_bottom.setKeep (true);
2435 if (fl_get_button(fd_form_paragraph->radio_align_left))
2436 align = LYX_ALIGN_LEFT;
2437 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2438 align = LYX_ALIGN_RIGHT;
2439 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2440 align = LYX_ALIGN_CENTER;
2442 align = LYX_ALIGN_BLOCK;
2444 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2445 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2447 current_view->text->SetParagraph(line_top,
2456 current_view->update(1);
2457 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2461 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2463 fl_hide_form(fd_form_paragraph->form_paragraph);
2467 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2469 ParagraphApplyCB(ob, data);
2470 ParagraphCancelCB(ob, data);
2474 /* callbacks for form form_character */
2476 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2478 // we set toggleall locally here, since it should be true for
2479 // all other uses of ToggleAndShow() (JMarc)
2480 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2481 ToggleAndShow(current_view, UserFreeFont());
2486 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2488 fl_hide_form(fd_form_character->form_character);
2492 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2494 CharacterApplyCB(ob, data);
2495 CharacterCloseCB(ob, data);
2499 /* callbacks for form form_document */
2501 void UpdateDocumentButtons(BufferParams const & params)
2503 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2505 switch (params.sides) {
2506 case LyXTextClass::OneSide:
2507 fl_set_button(fd_form_document->radio_sides_one, 1);
2509 case LyXTextClass::TwoSides:
2510 fl_set_button(fd_form_document->radio_sides_two, 1);
2514 if (params.columns == 2)
2515 fl_set_button(fd_form_document->radio_columns_two, 1);
2517 fl_set_button(fd_form_document->radio_columns_one, 1);
2519 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2520 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2521 params.secnumdepth);
2522 fl_set_counter_value(fd_form_document->slider_tocdepth,
2527 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2530 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2531 if (AskQuestion(_("Should I set some parameters to"),
2532 fl_get_choice_text(ob),
2533 _("the defaults of this document class?"))) {
2534 BufferParams params = BufferParams();
2535 params.textclass = fl_get_choice(ob)-1;
2536 params.useClassDefaults();
2537 UpdateLayoutDocument(¶ms);
2538 UpdateDocumentButtons(params);
2541 // unable to load new style
2542 WriteAlert(_("Conversion Errors!"),
2543 _("Unable to switch to new document class."),
2544 _("Reverting to original document class."));
2545 fl_set_choice(fd_form_document->choice_class,
2546 current_view->buffer()->params.textclass + 1);
2552 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2554 // "Synchronize" the choice and the input field, so that it
2555 // is impossible to commit senseless data.
2556 FD_form_document const * fd = fd_form_document;
2558 if (obj == fd->choice_default_skip) {
2559 if (fl_get_choice (fd->choice_default_skip) != 4) {
2560 fl_set_input (fd->input_default_skip, "");
2561 ActivateDocumentButtons();
2563 } else if (obj == fd->input_default_skip) {
2565 char const * input = fl_get_input (fd->input_default_skip);
2568 fl_set_choice (fd->choice_default_skip, 2);
2569 ActivateDocumentButtons();
2570 } else if (isValidGlueLength (input)) {
2571 fl_set_choice (fd->choice_default_skip, 4);
2572 ActivateDocumentButtons();
2574 fl_set_choice (fd->choice_default_skip, 4);
2575 DeactivateDocumentButtons();
2581 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2583 // "Synchronize" the choice and the input field, so that it
2584 // is impossible to commit senseless data.
2585 FD_form_document const * fd = fd_form_document;
2587 if (obj == fd->choice_spacing
2588 && fl_get_choice (fd->choice_spacing) != 4) {
2589 fl_set_input(fd->input_spacing, "");
2590 } else if (obj == fd->input_spacing) {
2592 const char* input = fl_get_input (fd->input_spacing);
2595 fl_set_choice (fd->choice_spacing, 1);
2597 fl_set_choice (fd->choice_spacing, 4);
2603 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2606 BufferParams * params = &(current_view->buffer()->params);
2607 current_view->buffer()->params.language =
2608 combo_language->getline();
2610 // If default skip is a "Length" but there's no text in the
2611 // input field, reset the kind to "Medskip", which is the default.
2612 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2613 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2614 fl_set_choice (fd_form_document->choice_default_skip, 2);
2617 /* this shouldn't be done automatically IMO. For example I write german
2618 * documents with an american keyboard very often. Matthias */
2620 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2621 fl_get_choice(fd_form_document->choice_language)); */
2623 fl_get_choice_text(fd_form_document->choice_fonts);
2625 fl_get_choice_text(fd_form_document->choice_inputenc);
2627 fl_get_choice_text(fd_form_document->choice_fontsize);
2629 fl_get_choice_text(fd_form_document->choice_pagestyle);
2630 params->graphicsDriver =
2631 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2632 params->use_amsmath =
2633 fl_get_button(fd_form_document->check_use_amsmath);
2635 if (!current_view->available())
2637 if (lyxrc.rtl_support) {
2638 current_view->text->SetCursor(current_view->text->cursor.par,
2639 current_view->text->cursor.pos);
2640 current_view->setState();
2643 LyXTextClassList::ClassList::size_type new_class =
2644 fl_get_choice(fd_form_document->choice_class) - 1;
2646 if (params->textclass != new_class) {
2647 // try to load new_class
2648 if (textclasslist.Load(new_class)) {
2649 // successfully loaded
2651 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2652 int ret = current_view->text->
2653 SwitchLayoutsBetweenClasses(current_view->buffer()->
2656 current_view->buffer()->
2662 s = _("One paragraph couldn't be converted");
2665 s += _(" paragraphs couldn't be converted");
2667 WriteAlert(_("Conversion Errors!"), s,
2668 _("into chosen document class"));
2671 params->textclass = new_class;
2673 // problem changing class -- warn user and retain old style
2674 WriteAlert(_("Conversion Errors!"),
2675 _("Unable to switch to new document class."),
2676 _("Reverting to original document class."));
2677 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2681 char tmpsep = params->paragraph_separation;
2682 if (fl_get_button(fd_form_document->radio_indent))
2683 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2685 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2686 if (tmpsep != params->paragraph_separation)
2689 VSpace tmpdefskip = params->getDefSkip();
2690 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2691 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2692 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2693 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2694 case 4: params->setDefSkip(
2695 VSpace (LyXGlueLength (fl_get_input
2696 (fd_form_document->input_default_skip))));
2698 // DocumentDefskipCB assures that this never happens
2699 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2701 if (!(tmpdefskip == params->getDefSkip()))
2704 if (fl_get_button(fd_form_document->radio_columns_two))
2705 params->columns = 2;
2707 params->columns = 1;
2708 if (fl_get_button(fd_form_document->radio_sides_two))
2709 params->sides = LyXTextClass::TwoSides;
2711 params->sides = LyXTextClass::OneSide;
2713 Spacing tmpSpacing = params->spacing;
2714 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2716 lyxerr.debug() << "Spacing: SINGLE" << endl;
2717 params->spacing.set(Spacing::Single);
2720 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2721 params->spacing.set(Spacing::Onehalf);
2724 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2725 params->spacing.set(Spacing::Double);
2728 lyxerr.debug() << "Spacing: OTHER" << endl;
2729 params->spacing.set(Spacing::Other,
2730 fl_get_input(fd_form_document->input_spacing));
2733 if (tmpSpacing != params->spacing)
2736 signed char tmpchar =
2737 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2738 if (params->secnumdepth != tmpchar)
2740 params->secnumdepth = tmpchar;
2743 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2745 params->float_placement =
2746 fl_get_input(fd_form_document->input_float_placement);
2748 // More checking should be done to ensure the string doesn't have
2749 // spaces or illegal placement characters in it. (thornley)
2752 current_view->redoCurrentBuffer();
2754 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2755 current_view->buffer()->markDirty();
2758 fl_get_input(fd_form_document->input_extra);
2763 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2765 fl_hide_form(fd_form_document->form_document);
2769 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2771 DocumentCancelCB(ob, data);
2772 DocumentApplyCB(ob, data);
2776 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2779 // bullet callbacks etc. in bullet_panel.C -- ARRae
2783 /* callbacks for form form_quotes */
2785 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2787 if (!current_view->available())
2790 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2791 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2792 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2794 lga = InsetQuotes::EnglishQ;
2797 lga = InsetQuotes::SwedishQ;
2800 lga = InsetQuotes::GermanQ;
2803 lga = InsetQuotes::PolishQ;
2806 lga = InsetQuotes::FrenchQ;
2809 lga = InsetQuotes::DanishQ;
2812 current_view->buffer()->params.quotes_language = lga;
2813 if (fl_get_button(fd_form_quotes->radio_single))
2814 current_view->buffer()->
2815 params.quotes_times = InsetQuotes::SingleQ;
2817 current_view->buffer()->
2818 params.quotes_times = InsetQuotes::DoubleQ;
2822 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2824 fl_hide_form(fd_form_quotes->form_quotes);
2828 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2830 QuotesApplyCB(ob, data);
2831 QuotesCancelCB(ob, data);
2836 /* callbacks for form form_preamble */
2838 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2840 fl_hide_form(fd_form_preamble->form_preamble);
2844 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2846 if (!current_view->available())
2849 current_view->buffer()->params.preamble =
2850 fl_get_input(fd_form_preamble->input_preamble);
2851 current_view->buffer()->markDirty();
2852 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2856 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2858 PreambleApplyCB(ob, data);
2859 PreambleCancelCB(ob, data);
2863 /* callbacks for form form_table */
2865 extern "C" void TableApplyCB(FL_OBJECT *, long)
2867 if (!current_view->available())
2870 // check for tables in tables
2871 if (current_view->text->cursor.par->table){
2872 WriteAlert(_("Impossible Operation!"),
2873 _("Cannot insert table in table."),
2878 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2880 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2881 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2884 current_view->hideCursor();
2885 current_view->beforeChange();
2886 current_view->update(-2);
2888 current_view->text->SetCursorParUndo();
2889 current_view->text->FreezeUndo();
2891 current_view->text->BreakParagraph();
2892 current_view->update(-1);
2894 if (current_view->text->cursor.par->Last()) {
2895 current_view->text->CursorLeft();
2897 current_view->text->BreakParagraph();
2898 current_view->update(-1);
2901 current_view->text->current_font.setLatex(LyXFont::OFF);
2902 //if (!fl_get_button(fd_form_table->check_latex)){
2903 // insert the new wysiwy table
2904 current_view->text->SetLayout(0); // standard layout
2905 if (current_view->text->cursor.par->footnoteflag ==
2906 LyXParagraph::NO_FOOTNOTE) {
2908 ->SetParagraph(0, 0,
2910 VSpace (0.3 * current_view->buffer()->
2911 params.spacing.getValue(),
2913 VSpace (0.3 * current_view->buffer()->
2914 params.spacing.getValue(),
2921 ->SetParagraph(0, 0,
2923 VSpace(VSpace::NONE),
2924 VSpace(VSpace::NONE),
2930 current_view->text->cursor.par->table =
2931 new LyXTable(xsize, ysize);
2933 for (int i = 0; i < xsize * ysize - 1; ++i)
2934 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
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);