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 * ====================================================== */
23 #include "support/lstrings.h"
25 #include FORMS_H_LOCATION
27 #include "layout_forms.h"
28 #include "bullet_forms.h"
29 #include "print_form.h"
31 #include "spellchecker.h"
35 #include "insets/insetref.h"
36 #include "insets/insetquotes.h"
37 #include "insets/insetlabel.h"
38 #include "insets/figinset.h"
40 #include "latexoptions.h"
42 #include "minibuffer.h"
44 #include "bufferlist.h"
45 #include "support/filetools.h"
46 #include "support/path.h"
48 #include "lyx_gui_misc.h"
50 #include "lastfiles.h"
51 #include "support/FileInfo.h"
53 #include "support/syscall.h"
54 #include "support/lyxlib.h"
55 #include "lyxserver.h"
56 #include "FontLoader.h"
62 extern Combox * combo_language;
63 extern BufferList bufferlist;
64 extern void show_symbols_form();
65 extern FD_form_title * fd_form_title;
66 extern FD_form_paragraph * fd_form_paragraph;
67 extern FD_form_character * fd_form_character;
68 extern FD_form_document * fd_form_document;
69 extern FD_form_quotes * fd_form_quotes;
70 extern FD_form_preamble * fd_form_preamble;
71 extern FD_form_table * fd_form_table;
72 extern FD_form_print * fd_form_print;
73 extern FD_form_figure * fd_form_figure;
74 extern FD_form_screen * fd_form_screen;
75 extern FD_form_toc * fd_form_toc;
76 extern FD_form_ref * fd_form_ref;
77 extern FD_LaTeXOptions * fd_latex_options;
78 extern FD_form_bullet * fd_form_bullet;
80 extern BufferView * current_view; // called too many times in this file...
82 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
84 extern bool send_fax(string const & fname, string const & sendcmd);
85 extern void MenuSendto();
87 extern LyXServer * lyxserver;
88 extern FontLoader fontloader;
90 // this should be static, but I need it in buffer.C
91 bool quitting; // flag, that we are quitting the program
92 extern bool finished; // all cleanup done just let it run through now.
94 char ascii_type; /* for selection notify callbacks */
96 bool scrolling = false;
100 /* whether the work area should get callbacks */
101 bool input_prohibited = false;
103 /* the selection possible is needed, that only motion events are
104 * used, where the bottom press event was on the drawing area too */
105 bool selection_possible = false;
107 // This is used to make the dreaded font toggle problem hopefully go
108 // away. Definitely not the best solution, but I think it sorta works.
109 bool toggleall = true;
112 This is the inset locking stuff needed for mathed --------------------
114 an inset can simple call LockInset in it's edit call and *ONLY* in it's
116 Inset::Edit() can only be called by the main lyx module.
118 Then the inset may modify the menu's and/or iconbars.
120 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
122 During the lock, all button and keyboard events will be modified
123 and send to the inset through the following inset-features. Note that
124 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
125 to contain the code for restoring the menus and things like this.
128 virtual void InsetButtonPress(int x, int y, int button);
129 virtual void InsetButtonRelease(int x, int y, int button);
130 virtual void InsetKeyPress(XKeyEvent *ev);
131 virtual void InsetMotionNotify(int x, int y, int state);
132 virtual void InsetUnlock();
134 If a inset wishes any redraw and/or update it just has to call
136 It's is completly irrelevant, where the inset is. UpdateInset will
137 find it in any paragraph in any buffer.
138 Of course the_locking_inset and the insets in the current paragraph/buffer
139 are checked first, so no performance problem should occur.
141 Hope that's ok for the beginning, Alejandro,
142 sorry that I needed so much time,
147 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
149 /* these functions return 1 if an error occured,
151 // Now they work only for updatable insets. [Alejandro 080596]
152 //int LockInset(UpdatableInset * inset);
153 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
154 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
155 //int UnlockInset(UpdatableInset * inset);
156 //void LockedInsetStoreUndo(Undo::undo_kind kind);
158 /* this is for asyncron updating. UpdateInsetUpdateList will be called
159 automatically from LyX. Just insert the Inset into the Updatelist */
160 //void UpdateInsetUpdateList();
161 //void PutInsetIntoInsetUpdateList(Inset * inset);
163 //InsetUpdateStruct * InsetUpdateList = 0;
167 -----------------------------------------------------------------------
170 /* some function prototypes */
172 int RunLinuxDoc(int, string const &);
173 int RunDocBook(int, string const &);
174 void MenuWrite(Buffer * buf);
175 void MenuWriteAs(Buffer * buffer);
176 void MenuReload(Buffer * buf);
177 void MenuLayoutSave();
180 // How should this actually work? Should it prohibit input in all BufferViews,
181 // or just in the current one? If "just the current one", then it should be
182 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
183 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
184 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
185 // current LyxView that should be prohibited (Lgb) (This applies to
186 // "AllowInput" as well.)
189 input_prohibited = true;
190 current_view->hideCursor();
192 static Cursor cursor;
193 static bool cursor_undefined = true;
195 if (cursor_undefined){
196 cursor = XCreateFontCursor(fl_display, XC_watch);
198 cursor_undefined = false;
201 /* set the cursor to the watch for all forms and the canvas */
202 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
204 if (fd_form_paragraph->form_paragraph->visible)
205 XDefineCursor(fl_display,
206 fd_form_paragraph->form_paragraph->window,
208 if (fd_form_character->form_character->visible)
209 XDefineCursor(fl_display,
210 fd_form_character->form_character->window,
214 fl_deactivate_all_forms();
218 // Should find a way to move this into BufferView.C
219 void SetXtermCursor(Window win)
221 static Cursor cursor;
222 static bool cursor_undefined = true;
223 if (cursor_undefined){
224 cursor = XCreateFontCursor(fl_display, XC_xterm);
226 cursor_undefined = false;
228 XDefineCursor(fl_display, win, cursor);
235 input_prohibited = false;
237 /* reset the cursor from the watch for all forms and the canvas */
239 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
240 if (fd_form_paragraph->form_paragraph->visible)
241 XUndefineCursor(fl_display,
242 fd_form_paragraph->form_paragraph->window);
243 if (fd_form_character->form_character->visible)
244 XUndefineCursor(fl_display,
245 fd_form_character->form_character->window);
247 // What to do about this? (Lgb)
248 if (current_view->belowMouse())
249 SetXtermCursor(current_view->owner()->getForm()->window);
252 fl_activate_all_forms();
256 void FreeUpdateTimer()
258 /* a real free timer would be better but I don't know
259 * how to do this with xforms */
264 void SetUpdateTimer(float time)
266 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
279 // should be moved to lyxfunc.C
280 void MenuWrite(Buffer * buffer)
283 if (!buffer->save(lyxrc->make_backup)) {
284 string fname = buffer->fileName();
285 string s = MakeAbsPath(fname);
286 if (AskQuestion(_("Save failed. Rename and try again?"),
287 MakeDisplayPath(s, 50),
288 _("(If not, document is not saved.)"))) {
292 lastfiles->newFile(buffer->fileName());
297 // should be moved to BufferView.C
298 // Half of this func should be in LyXView, the rest in BufferView.
299 void MenuWriteAs(Buffer * buffer)
301 // Why do we require BufferView::text to be able to write a
302 // document? I see no point in that. (Lgb)
303 //if (!bv->text) return;
305 string fname = buffer->fileName();
306 string oldname = fname;
310 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
311 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
313 if (!IsLyXFilename(fname))
316 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
319 OnlyFilename(fname));
325 // Make sure the absolute filename ends with appropriate suffix
326 string s = MakeAbsPath(fname);
327 if (!IsLyXFilename(s))
330 // Same name as we have already?
332 if (!AskQuestion(_("Same name as document already has:"),
333 MakeDisplayPath(s, 50),
336 // Falls through to name change and save
338 // No, but do we have another file with this name open?
339 else if (bufferlist.exists(s)) {
340 if (AskQuestion(_("Another document with same name open!"),
341 MakeDisplayPath(s, 50),
342 _("Replace with current document?")))
344 bufferlist.close(bufferlist.getBuffer(s));
346 // Ok, change the name of the buffer, but don't save!
350 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
352 _("', but not saved..."));
355 } // Check whether the file exists
358 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
359 MakeDisplayPath(s, 50),
364 // Ok, change the name of the buffer
368 // Small bug: If the save fails, we have irreversible changed the name
374 int MenuRunLaTeX(Buffer * buffer)
378 if (buffer->isLinuxDoc())
379 ret = RunLinuxDoc(1, buffer->fileName());
380 else if (buffer->isLiterate())
381 ret = buffer->runLiterate();
382 else if (buffer->isDocBook())
383 ret = RunDocBook(1, buffer->fileName());
385 ret = buffer->runLaTeX();
391 s = _("One error detected");
392 t = _("You should try to fix it.");
395 s += _(" errors detected.");
396 t = _("You should try to fix them.");
398 WriteAlert(_("There were errors during the LaTeX run."), s, t);
404 int MenuBuildProg(Buffer * buffer)
408 if (buffer->isLiterate())
409 ret = buffer->buildProgram();
411 string s = _("Wrong type of document");
412 string t = _("The Build operation is not allowed in this document");
413 WriteAlert(_("There were errors during the Build process."), s, t);
421 s = _("One error detected");
422 t = _("You should try to fix it.");
425 s += _(" errors detected.");
426 t = _("You should try to fix them.");
428 WriteAlert(_("There were errors during the Build process."), s, t);
434 int MenuRunChktex(Buffer * buffer)
438 if (buffer->isSGML()) {
439 WriteAlert(_("Chktex does not work with SGML derived documents."));
442 ret = buffer->runChktex();
448 s = _("No warnings found.");
449 } else if (ret == 1) {
450 s = _("One warning found.");
451 t = _("Use 'Edit->Go to Error' to find it.");
454 s += _(" warnings found.");
455 t = _("Use 'Edit->Go to Error' to find them.");
457 WriteAlert(_("Chktex run successfully"), s, t);
459 WriteAlert(_("Error!"), _("It seems chktex does not work."));
465 int MakeLaTeXOutput(Buffer * buffer)
471 string path = OnlyPath(buffer->fileName());
472 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
473 path = buffer->tmppath;
475 if (!buffer->isDviClean()) {
477 ret = MenuRunLaTeX(buffer);
483 /* wait == false means don't wait for termination */
484 /* wait == true means wait for termination */
485 // The bool should be placed last on the argument line. (Lgb)
486 // Returns false if we fail.
487 bool RunScript(Buffer * buffer, bool wait,
488 string const & command,
489 string const & orgname = string(),
490 bool need_shell = true)
494 string name = orgname;
497 if (MakeLaTeXOutput(buffer) > 0)
499 /* get DVI-Filename */
501 name = ChangeExtension(buffer->getLatexName(),
504 path = OnlyPath(name);
505 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
506 path = buffer->tmppath;
509 // At this point we check whether the command contains the
510 // filename parameter $$FName and if that's the case we
511 // substitute the real file name otherwise the filename is
512 // simply appended. rokrau 1/12/00
514 std::string::size_type i;
515 if ( (i=command.find("$$FName")) != std::string::npos)
517 cmd.replace(i,7,QuoteName(name));
520 cmd = command + ' ' + QuoteName(name);
529 // OS/2 cmd.exe has another use for '&'
531 // This is not NLS safe, but it's OK, I think.
532 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
534 // COMSPEC is set, unless user unsets
535 sh = OnlyFilename(GetEnvPath("COMSPEC"));
540 if (contains(sh, "cmd.exe")
541 || contains(sh, "4os2.exe"))
542 cmd = "start /min/n " + cmd;
547 // It seems that, if wait is false, we never get back
548 // the return code of the command. This means that all
549 // the code I added in PrintApplyCB is currently
552 #warning What should we do here?
554 buffer->getUser()->owner()->getMiniBuffer()->Set(
555 _("Executing command:"), cmd);
556 result = one.startscript(Systemcalls::System, cmd);
558 buffer->getUser()->owner()->getMiniBuffer()->Set(
559 _("Executing command:"), cmd);
560 result = one.startscript(wait ? Systemcalls::Wait
561 : Systemcalls::DontWait, cmd);
567 // Returns false if we fail
568 bool CreatePostscript(Buffer * buffer, bool wait = false)
577 if (MakeLaTeXOutput(buffer) > 0) {
581 // Generate postscript file
582 string psname = ChangeExtension (buffer->fileName(),
588 char real_papersize = buffer->params.papersize;
589 if (real_papersize == BufferParams::PAPER_DEFAULT)
590 real_papersize = lyxrc->default_papersize;
592 switch (real_papersize) {
593 case BufferParams::PAPER_USLETTER:
596 case BufferParams::PAPER_A3PAPER:
599 case BufferParams::PAPER_A4PAPER:
602 case BufferParams::PAPER_A5PAPER:
605 case BufferParams::PAPER_B5PAPER:
608 case BufferParams::PAPER_EXECUTIVEPAPER:
611 case BufferParams::PAPER_LEGALPAPER:
614 default: /* If nothing else fits, keep an empty value... */
618 // Make postscript file.
619 string command = lyxrc->dvi_to_ps_command + ' ' + lyxrc->print_to_file + ' ';
620 command += QuoteName(psname);
621 if (buffer->params.use_geometry
622 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
623 && !lyxrc->print_paper_dimension_flag.empty()
624 && !buffer->params.paperwidth.empty()
625 && !buffer->params.paperheight.empty()) {
626 // using a custom papersize
628 command += lyxrc->print_paper_dimension_flag + ' ';
629 command += buffer->params.paperwidth + ',';
630 command += buffer->params.paperheight;
631 } else if (!paper.empty()
632 && (real_papersize != BufferParams::PAPER_USLETTER ||
633 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
634 // dvips won't accept -t letter -t landscape. In all other
635 // cases, include the paper size explicitly.
637 command += lyxrc->print_paper_flag + ' ' + paper;
639 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
641 command += lyxrc->print_landscape_flag;
643 // push directorypath, if necessary
644 string path = OnlyPath(buffer->fileName());
645 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
646 path = buffer->tmppath;
649 bool ret = RunScript(buffer, wait, command);
655 // Returns false if we fail
656 //bool MenuPreviewPS(Buffer * buffer)
657 bool PreviewPostscript(Buffer * buffer)
663 // Generate postscript file
664 if (!CreatePostscript(buffer, true)) {
668 // Start postscript viewer
670 string ps = ChangeExtension (buffer->fileName(),
672 // push directorypath, if necessary
673 string path = OnlyPath(buffer->fileName());
674 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
675 path = buffer->tmppath;
678 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
684 void MenuFax(Buffer * buffer)
690 // Generate postscript file
691 if (!CreatePostscript(buffer, true)) {
696 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
697 string path = OnlyPath (buffer->fileName());
698 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
699 path = buffer->tmppath;
702 if (!lyxrc->fax_program.empty()) {
703 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
705 Systemcalls one(Systemcalls::System, help2);
707 send_fax(ps, lyxrc->fax_command);
711 // Returns false if we fail
712 bool PreviewDVI(Buffer * buffer)
718 string paper = lyxrc->view_dvi_paper_option;
719 if (!paper.empty()) {
721 char real_papersize = buffer->params.papersize;
722 if (real_papersize == BufferParams::PAPER_DEFAULT)
723 real_papersize = lyxrc->default_papersize;
725 switch (real_papersize) {
726 case BufferParams::PAPER_USLETTER:
729 case BufferParams::PAPER_A3PAPER:
732 case BufferParams::PAPER_A4PAPER:
735 case BufferParams::PAPER_A5PAPER:
738 case BufferParams::PAPER_B5PAPER:
741 case BufferParams::PAPER_EXECUTIVEPAPER:
742 paper += " foolscap";
744 case BufferParams::PAPER_LEGALPAPER:
747 default: /* If nothing else fits, keep the empty value */
750 if (real_papersize==' ') {
751 // if (paper.empty()) {
752 if (buffer->params.orientation
753 == BufferParams::ORIENTATION_LANDSCAPE)
754 // we HAVE to give a size when the page is in
755 // landscape, so use USletter.
756 paper = " -paper usr";
758 // paper = " -paper " + paper;
759 if (buffer->params.orientation
760 == BufferParams::ORIENTATION_LANDSCAPE)
764 // push directorypath, if necessary
765 string path = OnlyPath(buffer->fileName());
766 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
767 path = buffer->tmppath;
771 string command = lyxrc->view_dvi_command + " " + paper;
772 bool ret = RunScript(buffer, false, command);
777 void MenuMakeLaTeX(Buffer * buffer)
779 // Why care about this?
783 // Get LaTeX-Filename
784 string s = buffer->getLatexName(false);
788 !AskQuestion(_("File already exists:"),
789 MakeDisplayPath(s, 50),
790 _("Do you want to overwrite the file?"))) {
791 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
795 if (buffer->isDocBook())
796 buffer->getUser()->owner()->getMiniBuffer()->Set(
797 _("DocBook does not have a latex backend"));
799 if (buffer->isLinuxDoc())
800 RunLinuxDoc(0, buffer->fileName());
802 buffer->makeLaTeXFile(s, string(), true);
803 buffer->getUser()->owner()->getMiniBuffer()->Set(
804 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
805 buffer->markDviDirty();
810 void MenuMakeLinuxDoc(Buffer * buffer)
813 //if (!bv->text) return;
815 if (!buffer->isLinuxDoc()) {
816 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
820 // Get LinuxDoc-Filename
821 string s = ChangeExtension(buffer->fileName(),
826 !AskQuestion(_("File already exists:"),
827 MakeDisplayPath(s, 50),
828 _("Do you want to overwrite the file?"))) {
829 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
833 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
834 MakeDisplayPath(s),"'...");
836 buffer->makeLinuxDocFile(s, 65);
838 buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
843 void MenuMakeDocBook(Buffer * buffer)
846 //if (!bv->text) return;
848 if (!buffer->isDocBook()) {
849 WriteAlert(_("Error!"),
850 _("Document class must be docbook."));
854 // Get DocBook-Filename
855 string s = ChangeExtension(buffer->fileName(),
860 !AskQuestion(_("File already exists:"),
861 MakeDisplayPath(s, 50),
862 _("Do you want to overwrite the file?"))) {
863 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
867 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
868 MakeDisplayPath(s), "'...");
870 buffer->makeDocBookFile(s, 65);
872 buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
877 void MenuMakeAscii(Buffer * buffer)
880 //if (!bv->text) return;
882 /* get LaTeX-Filename */
883 string s = ChangeExtension (buffer->fileName(),
888 !AskQuestion(_("File already exists:"),
889 MakeDisplayPath(s, 50),
890 _("Do you want to overwrite the file?"))) {
891 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
895 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
897 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
901 void MenuPrint(Buffer * buffer)
907 string input_file = ChangeExtension(buffer->fileName(),
908 lyxrc->print_file_extension,
910 fl_set_input(fd_form_print->input_file, input_file.c_str());
912 if (fd_form_print->form_print->visible) {
913 fl_raise_form(fd_form_print->form_print);
916 fl_show_form(fd_form_print->form_print,
917 FL_PLACE_MOUSE, FL_FULLBORDER,
922 void MenuMakeHTML(Buffer * buffer)
924 // First, create LaTeX file
925 MenuMakeLaTeX(buffer);
927 // And now, run the converter
928 string file = buffer->fileName();
929 Path path(OnlyPath(file));
930 // the tex file name has to be correct for
931 // latex, but the html file name can be
933 string result = ChangeExtension(file, ".html", false);
934 string infile = buffer->getLatexName(false);
935 string tmp = lyxrc->html_command;
936 tmp = subst(tmp, "$$FName", infile);
937 tmp = subst(tmp, "$$OutName", result);
939 int res = one.startscript(Systemcalls::System, tmp);
941 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
942 + MakeDisplayPath(result) +'\'');
944 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
945 + MakeDisplayPath(infile)
951 void MenuExport(Buffer * buffer, string const & extyp)
954 if (extyp == "latex") {
955 // make sure that this buffer is not linuxdoc
956 MenuMakeLaTeX(buffer);
959 else if (extyp == "linuxdoc") {
960 // make sure that this buffer is not latex
961 MenuMakeLinuxDoc(buffer);
964 else if (extyp == "docbook") {
965 // make sure that this buffer is not latex or linuxdoc
966 MenuMakeDocBook(buffer);
969 else if (extyp == "dvi") {
970 // Run LaTeX as "Update dvi..." Bernhard.
971 // We want the dvi in the current directory. This
972 // is achieved by temporarily disabling use of
973 // temp directory. As a side-effect, we get
974 // *.log and *.aux files also. (Asger)
975 bool flag = lyxrc->use_tempdir;
976 lyxrc->use_tempdir = false;
977 MenuRunLaTeX(buffer);
978 lyxrc->use_tempdir = flag;
981 else if (extyp == "postscript") {
982 // Start Print-dialog. Not as good as dvi... Bernhard.
984 // Since the MenuPrint is a pop-up, we can't use
985 // the same trick as above. (Asger)
986 // MISSING: Move of ps-file :-(
987 // And MenuPrint should not be used for this at all...
990 else if (extyp == "ascii") {
991 MenuMakeAscii(buffer);
993 else if (extyp == "custom") {
997 else if (extyp == "html") {
998 MenuMakeHTML(buffer);
1001 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
1008 lyxerr.debug() << "Running QuitLyX." << endl;
1010 if (!bufferlist.QwriteAll())
1013 lastfiles->writeFile(lyxrc->lastfiles);
1015 // Set a flag that we do quitting from the program,
1016 // so no refreshes are necessary.
1019 // close buffers first
1020 bufferlist.closeAll();
1022 // do any other cleanup procedures now
1023 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1025 DestroyLyXTmpDir(system_tempdir);
1033 // should probably be moved into BufferList (Lgb)
1034 // Perfect target for a thread...
1036 if (!current_view->available())
1039 if (current_view->buffer()->isBakClean()
1040 || current_view->buffer()->isReadonly()) {
1041 // We don't save now, but we'll try again later
1042 current_view->owner()->resetAutosaveTimer();
1046 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1048 // create autosave filename
1049 string fname = OnlyPath(current_view->buffer()->fileName());
1051 fname += OnlyFilename(current_view->buffer()->fileName());
1054 // tmp_ret will be located (usually) in /tmp
1055 // will that be a problem?
1056 string tmp_ret = tmpnam(0);
1058 pid_t pid = fork(); // If you want to debug the autosave
1059 // you should set pid to -1, and comment out the
1061 if (pid == 0 || pid == -1) {
1062 // pid = -1 signifies that lyx was unable
1063 // to fork. But we will do the save
1065 bool failed = false;
1066 if (!tmp_ret.empty()) {
1067 current_view->buffer()->writeFile(tmp_ret, 1);
1068 // assume successful write of tmp_ret
1069 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1071 // most likely couldn't move between filesystems
1072 // unless write of tmp_ret failed
1073 // so remove tmp file (if it exists)
1074 remove(tmp_ret.c_str());
1081 // failed to write/rename tmp_ret so try writing direct
1082 if (!current_view->buffer()->writeFile(fname, 1)) {
1083 // It is dangerous to do this in the child,
1084 // but safe in the parent, so...
1086 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1089 if (pid == 0) { // we are the child so...
1094 current_view->buffer()->markBakClean();
1095 current_view->owner()->resetAutosaveTimer();
1100 // (c) CHT Software Service GmbH
1103 // create new file with template
1106 Buffer * NewLyxFile(string const & filename)
1108 // Split argument by :
1110 string tmpname = split(filename, name, ':');
1111 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1112 if (name.length() == 1
1113 && isalpha(static_cast<unsigned char>(name[0]))
1114 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1116 name += token(tmpname, ':', 0);
1117 tmpname = split(tmpname, ':');
1120 lyxerr.debug() << "Arg is " << filename
1121 << "\nName is " << name
1122 << "\nTemplate is " << tmpname << endl;
1124 // find a free buffer
1125 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1127 lastfiles->newFile(tmpbuf->fileName());
1132 // Insert ascii file (if filename is empty, prompt for one)
1133 void InsertAsciiFile(string const & f, bool asParagraph)
1138 if (!current_view->available()) return;
1140 if (fname.empty()) {
1142 fname = fileDlg.Select(_("File to Insert"),
1143 current_view->owner()->buffer()->filepath,
1146 if (fname.empty()) return;
1151 if (!fi.readable()) {
1152 WriteFSAlert(_("Error! Specified file is unreadable: "),
1153 MakeDisplayPath(fname, 50));
1157 ifstream ifs(fname.c_str());
1159 WriteFSAlert(_("Error! Cannot open specified file: "),
1160 MakeDisplayPath(fname, 50));
1163 LyXParagraph * tmppar = new LyXParagraph;
1164 tmppar->readSimpleWholeFile(ifs);
1166 // set the end of the string
1167 #ifdef WITH_WARNINGS
1168 #warning why do we do this?
1170 // I don't think this is needed. Actually it might be plain wrong.
1171 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1173 // insert the string
1174 current_view->hideCursor();
1176 // clear the selection
1177 current_view->beforeChange();
1179 current_view->text->InsertStringA(tmppar->text);
1181 current_view->text->InsertStringB(tmppar->text);
1183 current_view->update(1);
1187 void MenuShowTableOfContents()
1189 static int ow = -1, oh;
1192 if (fd_form_toc->form_toc->visible) {
1193 fl_raise_form(fd_form_toc->form_toc);
1195 fl_show_form(fd_form_toc->form_toc,
1196 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1197 _("Table Of Contents"));
1199 ow = fd_form_toc->form_toc->w;
1200 oh = fd_form_toc->form_toc->h;
1202 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1207 void MenuInsertLabel(char const * arg)
1211 if (label.empty()) {
1213 result = askForText(_("Enter new label to insert:"));
1215 label = frontStrip(strip(result.second));
1218 if (!label.empty()) {
1219 InsetLabel * new_inset = new InsetLabel;
1220 new_inset->setContents(label);
1221 current_view->insertInset(new_inset);
1227 void MenuInsertRef()
1229 static int ow = -1, oh;
1232 if (fd_form_ref->form_ref->visible) {
1233 fl_raise_form(fd_form_ref->form_ref);
1235 fl_show_form(fd_form_ref->form_ref,
1236 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1237 _("Insert Reference"));
1239 ow = fd_form_ref->form_ref->w;
1240 oh = fd_form_ref->form_ref->h;
1242 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1247 void MenuPasteSelection(char at)
1249 if (!current_view->available())
1254 Atom data_prop = XInternAtom(fl_display,
1257 if (data_prop == None)
1259 XConvertSelection(fl_display,
1260 XA_PRIMARY, XA_STRING, data_prop,
1261 current_view->owner()->getForm()->window, 0);
1266 // candidate for move to BufferView
1267 void Foot(BufferView * bv)
1269 if (!bv->available())
1272 bv->owner()->getMiniBuffer()
1273 ->Set(_("Inserting Footnote..."));
1276 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1281 // candidate for move to LyXView
1282 // This is only used in toolbar.C
1283 void LayoutsCB(int sel, void *)
1285 string tmp = tostr(sel);
1286 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1292 * SGML Linuxdoc support:
1293 * (flag == -1) import SGML file
1294 * (flag == 0) make TeX output
1295 * (flag == 1) make dvi output
1297 int RunLinuxDoc(int flag, string const & filename)
1306 /* generate a path-less extension name */
1307 name = ChangeExtension (filename, ".sgml", true);
1308 path = OnlyPath (filename);
1309 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1310 path = current_view->buffer()->tmppath;
1315 if (!current_view->available())
1317 current_view->buffer()->makeLinuxDocFile(name, 0);
1318 #ifdef WITH_WARNINGS
1319 #warning remove this once we have a proper geometry class
1321 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1323 case BufferParams::PAPER_A4PAPER:
1324 add_flags = "-p a4";
1326 case BufferParams::PAPER_USLETTER:
1327 add_flags = "-p letter";
1329 default: /* nothing to be done yet ;-) */ break;
1337 case -1: /* Import file */
1338 current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"),
1339 MakeDisplayPath(filename), "'...");
1340 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1342 if (one.startscript(Systemcalls::System, s2))
1345 case 0: /* TeX output asked */
1346 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1347 s2 = "sgml2latex " + add_flags + " -o tex "
1348 + lyxrc->sgml_extra_options + ' ' + name;
1349 if (one.startscript(Systemcalls::System, s2))
1352 case 1: /* dvi output asked */
1353 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1354 s2 = "sgml2latex " + add_flags + " -o dvi "
1355 + lyxrc->sgml_extra_options + ' ' + name;
1356 if (one.startscript(Systemcalls::System, s2)) {
1359 current_view->buffer()->markDviClean();
1361 default: /* unknown output */
1367 current_view->buffer()->redraw();
1373 * SGML DocBook support:
1374 * (flag == 1) make dvi output
1376 int RunDocBook(int flag, string const & filename)
1378 /* generate a path-less extension name */
1379 string name = ChangeExtension (filename, ".sgml", true);
1380 string path = OnlyPath (filename);
1381 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1382 path = current_view->buffer()->tmppath;
1386 if (!current_view->available())
1389 current_view->buffer()->makeDocBookFile(name, 0);
1391 // Shall this code go or should it stay? (Lgb)
1392 // string add_flags;
1393 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1395 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1396 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1397 // default: /* nothing to be done yet ;-) */ break;
1404 case 1: /* dvi output asked */
1406 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1407 string s2 = "sgmltools --backend dvi " + name;
1408 if (one.startscript(Systemcalls::System, s2)) {
1411 current_view->buffer()->markDviClean();
1414 default: /* unknown output */
1420 current_view->buffer()->redraw();
1425 void MenuLayoutCharacter()
1427 static int ow = -1, oh;
1429 if (fd_form_character->form_character->visible) {
1430 fl_raise_form(fd_form_character->form_character);
1432 fl_show_form(fd_form_character->form_character,
1433 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1434 _("Character Style"));
1436 ow = fd_form_character->form_character->w;
1437 oh = fd_form_character->form_character->h;
1439 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1445 void DeactivateParagraphButtons ()
1447 fl_deactivate_object (fd_form_paragraph->button_ok);
1448 fl_deactivate_object (fd_form_paragraph->button_apply);
1449 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1450 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1455 void ActivateParagraphButtons ()
1457 fl_activate_object (fd_form_paragraph->button_ok);
1458 fl_activate_object (fd_form_paragraph->button_apply);
1459 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1460 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1465 void DisableParagraphLayout ()
1467 DeactivateParagraphButtons();
1468 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1469 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1470 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1471 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1472 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1473 fl_deactivate_object (fd_form_paragraph->check_noindent);
1474 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1475 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1476 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1477 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1478 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1479 fl_deactivate_object (fd_form_paragraph->input_space_above);
1480 fl_deactivate_object (fd_form_paragraph->input_space_below);
1481 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1482 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1483 fl_deactivate_object (fd_form_paragraph->check_space_above);
1484 fl_deactivate_object (fd_form_paragraph->check_space_below);
1489 void EnableParagraphLayout ()
1491 ActivateParagraphButtons();
1492 fl_activate_object (fd_form_paragraph->input_labelwidth);
1493 fl_activate_object (fd_form_paragraph->check_lines_top);
1494 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1495 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1496 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1497 fl_activate_object (fd_form_paragraph->check_noindent);
1498 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1499 fl_activate_object (fd_form_paragraph->radio_align_right);
1500 fl_activate_object (fd_form_paragraph->radio_align_left);
1501 fl_activate_object (fd_form_paragraph->radio_align_block);
1502 fl_activate_object (fd_form_paragraph->radio_align_center);
1503 fl_activate_object (fd_form_paragraph->input_space_above);
1504 fl_activate_object (fd_form_paragraph->input_space_below);
1505 fl_activate_object (fd_form_paragraph->choice_space_above);
1506 fl_activate_object (fd_form_paragraph->choice_space_below);
1507 fl_activate_object (fd_form_paragraph->check_space_above);
1508 fl_activate_object (fd_form_paragraph->check_space_below);
1512 bool UpdateLayoutParagraph()
1514 if (!current_view->available()) {
1515 if (fd_form_paragraph->form_paragraph->visible)
1516 fl_hide_form(fd_form_paragraph->form_paragraph);
1520 Buffer * buf = current_view->buffer();
1522 fl_set_input(fd_form_paragraph->input_labelwidth,
1523 current_view->text->cursor.par->GetLabelWidthString().c_str());
1524 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1525 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1526 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1527 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1529 int align = current_view->text->cursor.par->GetAlign();
1530 if (align == LYX_ALIGN_LAYOUT)
1531 align = textclasslist.Style(buf->params.textclass,
1532 current_view->text->cursor.par->GetLayout()).align;
1535 case LYX_ALIGN_RIGHT:
1536 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1538 case LYX_ALIGN_LEFT:
1539 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1541 case LYX_ALIGN_CENTER:
1542 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1545 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1549 fl_set_button(fd_form_paragraph->check_lines_top,
1550 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1551 fl_set_button(fd_form_paragraph->check_lines_bottom,
1552 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1553 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1554 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1555 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1556 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1557 fl_set_button(fd_form_paragraph->check_noindent,
1558 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1559 fl_set_input (fd_form_paragraph->input_space_above, "");
1561 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1563 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1565 case VSpace::DEFSKIP:
1566 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1568 case VSpace::SMALLSKIP:
1569 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1571 case VSpace::MEDSKIP:
1572 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1574 case VSpace::BIGSKIP:
1575 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1578 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1580 case VSpace::LENGTH:
1581 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1582 fl_set_input (fd_form_paragraph->input_space_above,
1583 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1586 fl_set_button (fd_form_paragraph->check_space_above,
1587 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1588 fl_set_input (fd_form_paragraph->input_space_below, "");
1589 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1591 fl_set_choice (fd_form_paragraph->choice_space_below,
1594 case VSpace::DEFSKIP:
1595 fl_set_choice (fd_form_paragraph->choice_space_below,
1598 case VSpace::SMALLSKIP:
1599 fl_set_choice (fd_form_paragraph->choice_space_below,
1602 case VSpace::MEDSKIP:
1603 fl_set_choice (fd_form_paragraph->choice_space_below,
1606 case VSpace::BIGSKIP:
1607 fl_set_choice (fd_form_paragraph->choice_space_below,
1611 fl_set_choice (fd_form_paragraph->choice_space_below,
1614 case VSpace::LENGTH:
1615 fl_set_choice (fd_form_paragraph->choice_space_below,
1617 fl_set_input (fd_form_paragraph->input_space_below,
1618 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1621 fl_set_button (fd_form_paragraph->check_space_below,
1622 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1624 fl_set_button(fd_form_paragraph->check_noindent,
1625 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1627 if (current_view->buffer()->isReadonly()) {
1628 DisableParagraphLayout();
1630 EnableParagraphLayout();
1636 void MenuLayoutParagraph()
1638 if (UpdateLayoutParagraph()) {
1639 if (fd_form_paragraph->form_paragraph->visible) {
1640 fl_raise_form(fd_form_paragraph->form_paragraph);
1642 fl_show_form(fd_form_paragraph->form_paragraph,
1643 FL_PLACE_MOUSE, FL_FULLBORDER,
1644 _("Paragraph Environment"));
1651 void DeactivateDocumentButtons ()
1653 fl_deactivate_object (fd_form_document->button_ok);
1654 fl_deactivate_object (fd_form_document->button_apply);
1655 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1656 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1661 void ActivateDocumentButtons ()
1663 fl_activate_object (fd_form_document->button_ok);
1664 fl_activate_object (fd_form_document->button_apply);
1665 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1666 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1671 void DisableDocumentLayout ()
1673 DeactivateDocumentButtons ();
1674 fl_deactivate_object (fd_form_document->group_radio_separation);
1675 fl_deactivate_object (fd_form_document->radio_indent);
1676 fl_deactivate_object (fd_form_document->radio_skip);
1677 fl_deactivate_object (fd_form_document->choice_class);
1678 fl_deactivate_object (fd_form_document->choice_pagestyle);
1679 fl_deactivate_object (fd_form_document->choice_fonts);
1680 fl_deactivate_object (fd_form_document->choice_fontsize);
1681 fl_deactivate_object (fd_form_document->input_float_placement);
1682 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1683 fl_deactivate_object (fd_form_document->choice_inputenc);
1684 fl_deactivate_object (fd_form_document->group_radio_sides);
1685 fl_deactivate_object (fd_form_document->radio_sides_one);
1686 fl_deactivate_object (fd_form_document->radio_sides_two);
1687 fl_deactivate_object (fd_form_document->group_radio_columns);
1688 fl_deactivate_object (fd_form_document->radio_columns_one);
1689 fl_deactivate_object (fd_form_document->radio_columns_two);
1690 fl_deactivate_object (fd_form_document->input_extra);
1691 fl_deactivate_object (fd_form_document->choice_language);
1692 combo_language->deactivate();
1693 fl_deactivate_object (fd_form_document->input_default_skip);
1694 fl_deactivate_object (fd_form_document->choice_default_skip);
1695 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1696 fl_deactivate_object (fd_form_document->slider_tocdepth);
1697 fl_deactivate_object (fd_form_document->choice_spacing);
1698 fl_deactivate_object (fd_form_document->input_spacing);
1699 fl_deactivate_object (fd_form_document->check_use_amsmath);
1704 void EnableDocumentLayout ()
1706 ActivateDocumentButtons ();
1707 fl_activate_object (fd_form_document->group_radio_separation);
1708 fl_activate_object (fd_form_document->radio_indent);
1709 fl_activate_object (fd_form_document->radio_skip);
1710 fl_activate_object (fd_form_document->choice_class);
1711 fl_activate_object (fd_form_document->choice_pagestyle);
1712 fl_activate_object (fd_form_document->choice_fonts);
1713 fl_activate_object (fd_form_document->choice_fontsize);
1714 fl_activate_object (fd_form_document->input_float_placement);
1715 fl_activate_object (fd_form_document->choice_postscript_driver);
1716 fl_activate_object (fd_form_document->choice_inputenc);
1717 fl_activate_object (fd_form_document->group_radio_sides);
1718 fl_activate_object (fd_form_document->radio_sides_one);
1719 fl_activate_object (fd_form_document->radio_sides_two);
1720 fl_activate_object (fd_form_document->group_radio_columns);
1721 fl_activate_object (fd_form_document->radio_columns_one);
1722 fl_activate_object (fd_form_document->radio_columns_two);
1723 fl_activate_object (fd_form_document->input_extra);
1724 fl_activate_object (fd_form_document->choice_language);
1725 combo_language->activate();
1726 fl_activate_object (fd_form_document->input_default_skip);
1727 fl_activate_object (fd_form_document->choice_default_skip);
1728 fl_activate_object (fd_form_document->slider_secnumdepth);
1729 fl_activate_object (fd_form_document->slider_tocdepth);
1730 fl_activate_object (fd_form_document->choice_spacing);
1731 fl_activate_object (fd_form_document->input_spacing);
1732 fl_activate_object (fd_form_document->check_use_amsmath);
1736 bool UpdateLayoutDocument(BufferParams * params)
1738 if (!current_view->available()) {
1739 if (fd_form_document->form_document->visible)
1740 fl_hide_form(fd_form_document->form_document);
1745 params = ¤t_view->buffer()->params;
1746 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1748 fl_set_choice_text(fd_form_document->choice_class,
1749 textclasslist.DescOfClass(params->textclass).c_str());
1750 combo_language->select_text(params->language.c_str());
1752 fl_set_choice_text(fd_form_document->choice_fonts,
1753 params->fonts.c_str());
1754 fl_set_choice_text(fd_form_document->choice_inputenc,
1755 params->inputenc.c_str());
1756 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1757 params->graphicsDriver.c_str());
1759 // ale970405+lasgoutt970513
1760 fl_clear_choice(fd_form_document->choice_fontsize);
1761 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1762 fl_addto_choice(fd_form_document->choice_fontsize,
1763 tclass.opt_fontsize().c_str());
1764 fl_set_choice(fd_form_document->choice_fontsize,
1765 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1767 // ale970405+lasgoutt970513
1768 fl_clear_choice(fd_form_document->choice_pagestyle);
1769 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1770 fl_addto_choice(fd_form_document->choice_pagestyle,
1771 tclass.opt_pagestyle().c_str());
1773 fl_set_choice(fd_form_document->choice_pagestyle,
1774 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1776 fl_set_button(fd_form_document->radio_indent, 0);
1777 fl_set_button(fd_form_document->radio_skip, 0);
1780 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1782 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1783 fl_set_button(fd_form_document->radio_indent, 1);
1785 fl_set_button(fd_form_document->radio_skip, 1);
1787 switch (params->getDefSkip().kind()) {
1788 case VSpace::SMALLSKIP:
1789 fl_set_choice (fd_form_document->choice_default_skip, 1);
1791 case VSpace::MEDSKIP:
1792 fl_set_choice (fd_form_document->choice_default_skip, 2);
1794 case VSpace::BIGSKIP:
1795 fl_set_choice (fd_form_document->choice_default_skip, 3);
1797 case VSpace::LENGTH:
1798 fl_set_choice (fd_form_document->choice_default_skip, 4);
1799 fl_set_input (fd_form_document->input_default_skip,
1800 params->getDefSkip().asLyXCommand().c_str());
1803 fl_set_choice (fd_form_document->choice_default_skip, 2);
1807 fl_set_button(fd_form_document->radio_sides_one, 0);
1808 fl_set_button(fd_form_document->radio_sides_two, 0);
1810 switch (params->sides) {
1811 case LyXTextClass::OneSide:
1812 fl_set_button(fd_form_document->radio_sides_one, 1);
1814 case LyXTextClass::TwoSides:
1815 fl_set_button(fd_form_document->radio_sides_two, 1);
1819 fl_set_button(fd_form_document->radio_columns_one, 0);
1820 fl_set_button(fd_form_document->radio_columns_two, 0);
1822 if (params->columns == 2)
1823 fl_set_button(fd_form_document->radio_columns_two, 1);
1825 fl_set_button(fd_form_document->radio_columns_one, 1);
1827 fl_set_input(fd_form_document->input_spacing, "");
1828 switch (params->spacing.getSpace()) {
1829 case Spacing::Single:
1832 fl_set_choice(fd_form_document->choice_spacing, 1);
1835 case Spacing::Onehalf:
1838 fl_set_choice(fd_form_document->choice_spacing, 2);
1841 case Spacing::Double:
1844 fl_set_choice(fd_form_document->choice_spacing, 3);
1847 case Spacing::Other:
1849 fl_set_choice(fd_form_document->choice_spacing, 4);
1851 sprintf(sval, "%g", params->spacing.getValue());
1852 fl_set_input(fd_form_document->input_spacing, sval);
1858 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1859 params->secnumdepth);
1860 fl_set_counter_value(fd_form_document->slider_tocdepth,
1862 if (!params->float_placement.empty()) { // buffer local (Lgb)
1863 fl_set_input(fd_form_document->input_float_placement,
1864 params->float_placement.c_str());
1866 fl_set_input(fd_form_document->input_float_placement, "");
1868 if (!params->options.empty())
1869 fl_set_input(fd_form_document->input_extra,
1870 params->options.c_str());
1872 fl_set_input(fd_form_document->input_extra, "");
1874 if (current_view->buffer()->isSGML()) {
1875 // bullets not used in SGML derived documents
1876 fl_deactivate_object(fd_form_document->button_bullets);
1877 fl_set_object_lcol(fd_form_document->button_bullets,
1880 fl_activate_object(fd_form_document->button_bullets);
1881 fl_set_object_lcol(fd_form_document->button_bullets,
1885 if (current_view->buffer()->isReadonly()) {
1886 DisableDocumentLayout();
1888 EnableDocumentLayout();
1895 void MenuLayoutDocument()
1897 if (UpdateLayoutDocument()) {
1898 if (fd_form_document->form_document->visible) {
1899 fl_raise_form(fd_form_document->form_document);
1901 fl_show_form(fd_form_document->form_document,
1902 FL_PLACE_MOUSE, FL_FULLBORDER,
1903 _("Document Layout"));
1909 bool UpdateLayoutQuotes()
1912 if (!current_view->available()
1913 || current_view->buffer()->isReadonly())
1917 fl_set_choice(fd_form_quotes->choice_quotes_language,
1918 current_view->buffer()->params.quotes_language + 1);
1919 fl_set_button(fd_form_quotes->radio_single, 0);
1920 fl_set_button(fd_form_quotes->radio_double, 0);
1922 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1923 fl_set_button(fd_form_quotes->radio_single, 1);
1925 fl_set_button(fd_form_quotes->radio_double, 1);
1926 } else if (fd_form_quotes->form_quotes->visible) {
1927 fl_hide_form(fd_form_quotes->form_quotes);
1933 void MenuLayoutQuotes()
1935 if (UpdateLayoutQuotes()) {
1936 if (fd_form_quotes->form_quotes->visible) {
1937 fl_raise_form(fd_form_quotes->form_quotes);
1939 fl_show_form(fd_form_quotes->form_quotes,
1940 FL_PLACE_MOUSE, FL_FULLBORDER,
1947 bool UpdateLayoutPreamble()
1950 if (!current_view->available())
1954 fl_set_input(fd_form_preamble->input_preamble,
1955 current_view->buffer()->params.preamble.c_str());
1957 if (current_view->buffer()->isReadonly()) {
1958 fl_deactivate_object(fd_form_preamble->input_preamble);
1959 fl_deactivate_object(fd_form_preamble->button_ok);
1960 fl_deactivate_object(fd_form_preamble->button_apply);
1961 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1962 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1965 fl_activate_object(fd_form_preamble->input_preamble);
1966 fl_activate_object(fd_form_preamble->button_ok);
1967 fl_activate_object(fd_form_preamble->button_apply);
1968 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1969 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1971 } else if (fd_form_preamble->form_preamble->visible) {
1972 fl_hide_form(fd_form_preamble->form_preamble);
1978 void MenuLayoutPreamble()
1980 static int ow = -1, oh;
1982 if (UpdateLayoutPreamble()) {
1983 if (fd_form_preamble->form_preamble->visible) {
1984 fl_raise_form(fd_form_preamble->form_preamble);
1986 fl_show_form(fd_form_preamble->form_preamble,
1987 FL_PLACE_MOUSE | FL_FREE_SIZE,
1989 _("LaTeX Preamble"));
1991 ow = fd_form_preamble->form_preamble->w;
1992 oh = fd_form_preamble->form_preamble->h;
1994 fl_set_form_minsize(fd_form_preamble->form_preamble,
2001 void MenuLayoutSave()
2003 if (!current_view->available())
2006 if (AskQuestion(_("Do you want to save the current settings"),
2007 _("for Character, Document, Paper and Quotes"),
2008 _("as default for new documents?")))
2009 current_view->buffer()->saveParamsAsDefaults();
2013 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2014 They also show the current font state. */
2017 void ToggleAndShow(BufferView *, LyXFont const &);
2020 void FontSize(string const & size)
2022 LyXFont font(LyXFont::ALL_IGNORE);
2023 font.setGUISize(size);
2024 ToggleAndShow(current_view, font);
2030 LyXFont font(LyXFont::ALL_IGNORE);
2031 font.setEmph(LyXFont::TOGGLE);
2032 ToggleAndShow(current_view, font);
2038 LyXFont font(LyXFont::ALL_IGNORE);
2039 font.setNoun(LyXFont::TOGGLE);
2040 ToggleAndShow(current_view, font);
2046 LyXFont font(LyXFont::ALL_IGNORE);
2047 font.setSeries(LyXFont::BOLD_SERIES);
2048 ToggleAndShow(current_view, font);
2054 LyXFont font(LyXFont::ALL_IGNORE);
2055 font.setUnderbar(LyXFont::TOGGLE);
2056 ToggleAndShow(current_view, font);
2062 LyXFont font(LyXFont::ALL_IGNORE);
2063 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2064 ToggleAndShow(current_view, font);
2070 LyXFont font(LyXFont::ALL_IGNORE);
2071 font.setFamily(LyXFont::SANS_FAMILY);
2072 ToggleAndShow(current_view, font);
2078 LyXFont font(LyXFont::ALL_IGNORE);
2079 font.setFamily(LyXFont::ROMAN_FAMILY);
2080 ToggleAndShow(current_view, font);
2086 LyXFont font(LyXFont::ALL_IGNORE);
2087 font.setLatex (LyXFont::TOGGLE);
2088 ToggleAndShow(current_view, font);
2093 LyXFont font(LyXFont::ALL_IGNORE);
2094 font.setDirection (LyXFont::TOGGLE_DIR);
2095 ToggleAndShow(current_view, font);
2101 LyXFont font(LyXFont::ALL_INHERIT);
2102 ToggleAndShow(current_view, font);
2106 /* -------> Returns the current font and depth by printing a message. In the
2107 * future perhaps we could try to implement a callback to the button-bar.
2108 * That is, `light' the bold button when the font is currently bold, etc.
2110 string CurrentState()
2113 if (current_view->available()) {
2114 // I think we should only show changes from the default
2116 Buffer * buffer = current_view->buffer();
2117 LyXFont font = current_view->text->real_current_font;
2118 LyXFont defaultfont = textclasslist.TextClass(buffer->
2119 params.textclass).defaultfont();
2120 font.reduce(defaultfont);
2121 state = _("Font: ") + font.stateText();
2123 int depth = current_view->text->GetDepth();
2125 state += string(_(", Depth: ")) + tostr(depth);
2131 // candidate for move to BufferView
2132 /* -------> Does the actual toggle job of the XxxCB() calls above.
2133 * Also shows the current font state.
2136 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2138 if (bv->available()) {
2141 if (bv->the_locking_inset)
2142 bv->the_locking_inset->SetFont(bv, font, toggleall);
2144 bv->text->ToggleFree(font, toggleall);
2150 // candidate for move to BufferView
2151 void Margin(BufferView * bv)
2153 if (bv->available()) {
2154 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2157 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2165 if (fd_form_figure->form_figure->visible) {
2166 fl_raise_form(fd_form_figure->form_figure);
2168 fl_show_form(fd_form_figure->form_figure,
2169 FL_PLACE_MOUSE, FL_FULLBORDER,
2170 _("Insert Figure"));
2177 if (fd_form_table->form_table->visible) {
2178 fl_raise_form(fd_form_table->form_table);
2180 fl_show_form(fd_form_table->form_table,
2181 FL_PLACE_MOUSE, FL_FULLBORDER,
2187 // candidate for move to BufferView
2188 void Melt(BufferView * bv)
2190 if (!bv->available()) return;
2192 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2196 bv->text->MeltFootnoteEnvironment();
2201 // candidate for move to BufferView
2202 // Change environment depth.
2203 // if decInc >= 0, increment depth
2204 // if decInc < 0, decrement depth
2205 void changeDepth(BufferView * bv, int decInc)
2207 if (!bv->available()) return;
2212 bv->text->IncDepth();
2214 bv->text->DecDepth();
2216 bv->owner()->getMiniBuffer()
2217 ->Set(_("Changed environment depth"
2218 " (in possible range, maybe not)"));
2222 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2223 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2224 LyXFont UserFreeFont()
2226 LyXFont font(LyXFont::ALL_IGNORE);
2228 int pos = fl_get_choice(fd_form_character->choice_family);
2230 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2231 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2232 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2233 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2234 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2237 pos = fl_get_choice(fd_form_character->choice_series);
2239 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2240 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2241 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2242 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2245 pos = fl_get_choice(fd_form_character->choice_shape);
2247 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2248 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2249 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2250 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2251 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2252 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2255 pos = fl_get_choice(fd_form_character->choice_size);
2257 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2258 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2259 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2260 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2261 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2262 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2263 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2264 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2265 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2266 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2267 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2268 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2269 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2270 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2273 pos = fl_get_choice(fd_form_character->choice_bar);
2275 case 1: font.setEmph(LyXFont::IGNORE);
2276 font.setUnderbar(LyXFont::IGNORE);
2277 font.setNoun(LyXFont::IGNORE);
2278 font.setLatex(LyXFont::IGNORE);
2280 case 2: font.setEmph(LyXFont::TOGGLE); break;
2281 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2282 case 4: font.setNoun(LyXFont::TOGGLE); break;
2283 case 5: font.setLatex(LyXFont::TOGGLE); break;
2284 case 6: font.setEmph(LyXFont::INHERIT);
2285 font.setUnderbar(LyXFont::INHERIT);
2286 font.setNoun(LyXFont::INHERIT);
2287 font.setLatex(LyXFont::INHERIT);
2291 pos = fl_get_choice(fd_form_character->choice_color);
2293 case 1: font.setColor(LColor::ignore); break;
2294 case 2: font.setColor(LColor::none); break;
2295 case 3: font.setColor(LColor::black); break;
2296 case 4: font.setColor(LColor::white); break;
2297 case 5: font.setColor(LColor::red); break;
2298 case 6: font.setColor(LColor::green); break;
2299 case 7: font.setColor(LColor::blue); break;
2300 case 8: font.setColor(LColor::cyan); break;
2301 case 9: font.setColor(LColor::magenta); break;
2302 case 10: font.setColor(LColor::yellow); break;
2303 case 11: font.setColor(LColor::inherit); break;
2312 ToggleAndShow(current_view, UserFreeFont());
2316 /* callbacks for form form_title */
2317 extern "C" void TimerCB(FL_OBJECT *, long)
2319 // only if the form still exists
2320 if (lyxrc->show_banner && fd_form_title->form_title != 0) {
2321 if (fd_form_title->form_title->visible) {
2322 fl_hide_form(fd_form_title->form_title);
2324 fl_free_form(fd_form_title->form_title);
2325 fd_form_title->form_title = 0;
2330 /* callbacks for form form_paragraph */
2332 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2334 // "Synchronize" the choices and input fields, making it
2335 // impossible to commit senseless data.
2337 FD_form_paragraph const * fp = fd_form_paragraph;
2339 if (obj == fp->choice_space_above) {
2340 if (fl_get_choice (fp->choice_space_above) != 7) {
2341 fl_set_input (fp->input_space_above, "");
2342 ActivateParagraphButtons();
2344 } else if (obj == fp->choice_space_below) {
2345 if (fl_get_choice (fp->choice_space_below) != 7) {
2346 fl_set_input (fp->input_space_below, "");
2347 ActivateParagraphButtons();
2349 } else if (obj == fp->input_space_above) {
2350 string input = fl_get_input (fp->input_space_above);
2352 if (input.empty()) {
2353 fl_set_choice (fp->choice_space_above, 1);
2354 ActivateParagraphButtons();
2356 else if (isValidGlueLength (input)) {
2357 fl_set_choice (fp->choice_space_above, 7);
2358 ActivateParagraphButtons();
2361 fl_set_choice (fp->choice_space_above, 7);
2362 DeactivateParagraphButtons();
2364 } else if (obj == fp->input_space_below) {
2365 string input = fl_get_input (fp->input_space_below);
2367 if (input.empty()) {
2368 fl_set_choice (fp->choice_space_below, 1);
2369 ActivateParagraphButtons();
2371 else if (isValidGlueLength (input)) {
2372 fl_set_choice (fp->choice_space_below, 7);
2373 ActivateParagraphButtons();
2376 fl_set_choice (fp->choice_space_below, 7);
2377 DeactivateParagraphButtons();
2383 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2385 if (!current_view->available())
2388 VSpace space_top, space_bottom;
2390 string labelwidthstring;
2393 // If a vspace kind is "Length" but there's no text in
2394 // the input field, reset the kind to "None".
2395 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2396 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2397 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2399 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2400 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2401 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2404 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2405 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2406 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2407 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2408 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2409 case 1: space_top = VSpace(VSpace::NONE); break;
2410 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2411 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2412 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2413 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2414 case 6: space_top = VSpace(VSpace::VFILL); break;
2415 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2417 if (fl_get_button (fd_form_paragraph->check_space_above))
2418 space_top.setKeep (true);
2419 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2420 case 1: space_bottom = VSpace(VSpace::NONE); break;
2421 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2422 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2423 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2424 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2425 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2426 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2428 if (fl_get_button (fd_form_paragraph->check_space_below))
2429 space_bottom.setKeep (true);
2431 if (fl_get_button(fd_form_paragraph->radio_align_left))
2432 align = LYX_ALIGN_LEFT;
2433 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2434 align = LYX_ALIGN_RIGHT;
2435 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2436 align = LYX_ALIGN_CENTER;
2438 align = LYX_ALIGN_BLOCK;
2440 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2441 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2443 current_view->text->SetParagraph(line_top,
2452 current_view->update(1);
2453 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2457 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2459 fl_hide_form(fd_form_paragraph->form_paragraph);
2463 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2465 ParagraphApplyCB(ob, data);
2466 ParagraphCancelCB(ob, data);
2470 /* callbacks for form form_character */
2472 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2474 // we set toggleall locally here, since it should be true for
2475 // all other uses of ToggleAndShow() (JMarc)
2476 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2477 ToggleAndShow(current_view, UserFreeFont());
2482 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2484 fl_hide_form(fd_form_character->form_character);
2488 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2490 CharacterApplyCB(ob, data);
2491 CharacterCloseCB(ob, data);
2495 /* callbacks for form form_document */
2497 void UpdateDocumentButtons(BufferParams const & params)
2499 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2501 switch (params.sides) {
2502 case LyXTextClass::OneSide:
2503 fl_set_button(fd_form_document->radio_sides_one, 1);
2505 case LyXTextClass::TwoSides:
2506 fl_set_button(fd_form_document->radio_sides_two, 1);
2510 if (params.columns == 2)
2511 fl_set_button(fd_form_document->radio_columns_two, 1);
2513 fl_set_button(fd_form_document->radio_columns_one, 1);
2515 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2516 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2517 params.secnumdepth);
2518 fl_set_counter_value(fd_form_document->slider_tocdepth,
2523 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2526 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2527 if (AskQuestion(_("Should I set some parameters to"),
2528 fl_get_choice_text(ob),
2529 _("the defaults of this document class?"))) {
2530 BufferParams params = BufferParams();
2531 params.textclass = fl_get_choice(ob)-1;
2532 params.useClassDefaults();
2533 UpdateLayoutDocument(¶ms);
2534 UpdateDocumentButtons(params);
2537 // unable to load new style
2538 WriteAlert(_("Conversion Errors!"),
2539 _("Unable to switch to new document class."),
2540 _("Reverting to original document class."));
2541 fl_set_choice(fd_form_document->choice_class,
2542 current_view->buffer()->params.textclass + 1);
2548 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2550 // "Synchronize" the choice and the input field, so that it
2551 // is impossible to commit senseless data.
2552 FD_form_document const * fd = fd_form_document;
2554 if (obj == fd->choice_default_skip) {
2555 if (fl_get_choice (fd->choice_default_skip) != 4) {
2556 fl_set_input (fd->input_default_skip, "");
2557 ActivateDocumentButtons();
2559 } else if (obj == fd->input_default_skip) {
2561 char const * input = fl_get_input (fd->input_default_skip);
2564 fl_set_choice (fd->choice_default_skip, 2);
2565 ActivateDocumentButtons();
2566 } else if (isValidGlueLength (input)) {
2567 fl_set_choice (fd->choice_default_skip, 4);
2568 ActivateDocumentButtons();
2570 fl_set_choice (fd->choice_default_skip, 4);
2571 DeactivateDocumentButtons();
2577 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2579 // "Synchronize" the choice and the input field, so that it
2580 // is impossible to commit senseless data.
2581 FD_form_document const * fd = fd_form_document;
2583 if (obj == fd->choice_spacing
2584 && fl_get_choice (fd->choice_spacing) != 4) {
2585 fl_set_input(fd->input_spacing, "");
2586 } else if (obj == fd->input_spacing) {
2588 const char* input = fl_get_input (fd->input_spacing);
2591 fl_set_choice (fd->choice_spacing, 1);
2593 fl_set_choice (fd->choice_spacing, 4);
2599 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2602 BufferParams * params = &(current_view->buffer()->params);
2603 current_view->buffer()->params.language =
2604 combo_language->getline();
2606 // If default skip is a "Length" but there's no text in the
2607 // input field, reset the kind to "Medskip", which is the default.
2608 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2609 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2610 fl_set_choice (fd_form_document->choice_default_skip, 2);
2613 /* this shouldn't be done automatically IMO. For example I write german
2614 * documents with an american keyboard very often. Matthias */
2616 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2617 fl_get_choice(fd_form_document->choice_language)); */
2619 fl_get_choice_text(fd_form_document->choice_fonts);
2621 fl_get_choice_text(fd_form_document->choice_inputenc);
2623 fl_get_choice_text(fd_form_document->choice_fontsize);
2625 fl_get_choice_text(fd_form_document->choice_pagestyle);
2626 params->graphicsDriver =
2627 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2628 params->use_amsmath =
2629 fl_get_button(fd_form_document->check_use_amsmath);
2631 if (!current_view->available())
2633 if (lyxrc->rtl_support) {
2634 current_view->text->SetCursor(current_view->text->cursor.par,
2635 current_view->text->cursor.pos);
2636 current_view->setState();
2639 LyXTextClassList::ClassList::size_type new_class =
2640 fl_get_choice(fd_form_document->choice_class) - 1;
2642 if (params->textclass != new_class) {
2643 // try to load new_class
2644 if (textclasslist.Load(new_class)) {
2645 // successfully loaded
2647 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2648 int ret = current_view->text->
2649 SwitchLayoutsBetweenClasses(current_view->buffer()->
2652 current_view->buffer()->
2658 s = _("One paragraph couldn't be converted");
2661 s += _(" paragraphs couldn't be converted");
2663 WriteAlert(_("Conversion Errors!"), s,
2664 _("into chosen document class"));
2667 params->textclass = new_class;
2669 // problem changing class -- warn user and retain old style
2670 WriteAlert(_("Conversion Errors!"),
2671 _("Unable to switch to new document class."),
2672 _("Reverting to original document class."));
2673 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2677 char tmpsep = params->paragraph_separation;
2678 if (fl_get_button(fd_form_document->radio_indent))
2679 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2681 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2682 if (tmpsep != params->paragraph_separation)
2685 VSpace tmpdefskip = params->getDefSkip();
2686 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2687 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2688 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2689 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2690 case 4: params->setDefSkip(
2691 VSpace (LyXGlueLength (fl_get_input
2692 (fd_form_document->input_default_skip))));
2694 // DocumentDefskipCB assures that this never happens
2695 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2697 if (!(tmpdefskip == params->getDefSkip()))
2700 if (fl_get_button(fd_form_document->radio_columns_two))
2701 params->columns = 2;
2703 params->columns = 1;
2704 if (fl_get_button(fd_form_document->radio_sides_two))
2705 params->sides = LyXTextClass::TwoSides;
2707 params->sides = LyXTextClass::OneSide;
2709 Spacing tmpSpacing = params->spacing;
2710 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2712 lyxerr.debug() << "Spacing: SINGLE" << endl;
2713 params->spacing.set(Spacing::Single);
2716 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2717 params->spacing.set(Spacing::Onehalf);
2720 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2721 params->spacing.set(Spacing::Double);
2724 lyxerr.debug() << "Spacing: OTHER" << endl;
2725 params->spacing.set(Spacing::Other,
2726 fl_get_input(fd_form_document->input_spacing));
2729 if (tmpSpacing != params->spacing)
2732 signed char tmpchar =
2733 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2734 if (params->secnumdepth != tmpchar)
2736 params->secnumdepth = tmpchar;
2739 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2741 params->float_placement =
2742 fl_get_input(fd_form_document->input_float_placement);
2744 // More checking should be done to ensure the string doesn't have
2745 // spaces or illegal placement characters in it. (thornley)
2748 current_view->redoCurrentBuffer();
2750 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2751 current_view->buffer()->markDirty();
2754 fl_get_input(fd_form_document->input_extra);
2759 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2761 fl_hide_form(fd_form_document->form_document);
2765 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2767 DocumentCancelCB(ob, data);
2768 DocumentApplyCB(ob, data);
2772 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2775 // bullet callbacks etc. in bullet_panel.C -- ARRae
2779 /* callbacks for form form_quotes */
2781 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2783 if (!current_view->available())
2786 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2787 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2788 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2790 lga = InsetQuotes::EnglishQ;
2793 lga = InsetQuotes::SwedishQ;
2796 lga = InsetQuotes::GermanQ;
2799 lga = InsetQuotes::PolishQ;
2802 lga = InsetQuotes::FrenchQ;
2805 lga = InsetQuotes::DanishQ;
2808 current_view->buffer()->params.quotes_language = lga;
2809 if (fl_get_button(fd_form_quotes->radio_single))
2810 current_view->buffer()->
2811 params.quotes_times = InsetQuotes::SingleQ;
2813 current_view->buffer()->
2814 params.quotes_times = InsetQuotes::DoubleQ;
2818 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2820 fl_hide_form(fd_form_quotes->form_quotes);
2824 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2826 QuotesApplyCB(ob, data);
2827 QuotesCancelCB(ob, data);
2832 /* callbacks for form form_preamble */
2834 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2836 fl_hide_form(fd_form_preamble->form_preamble);
2840 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2842 if (!current_view->available())
2845 current_view->buffer()->params.preamble =
2846 fl_get_input(fd_form_preamble->input_preamble);
2847 current_view->buffer()->markDirty();
2848 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2852 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2854 PreambleApplyCB(ob, data);
2855 PreambleCancelCB(ob, data);
2859 /* callbacks for form form_table */
2861 extern "C" void TableApplyCB(FL_OBJECT *, long)
2863 if (!current_view->available())
2866 // check for tables in tables
2867 if (current_view->text->cursor.par->table){
2868 WriteAlert(_("Impossible Operation!"),
2869 _("Cannot insert table in table."),
2874 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2876 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2877 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2880 current_view->hideCursor();
2881 current_view->beforeChange();
2882 current_view->update(-2);
2884 current_view->text->SetCursorParUndo();
2885 current_view->text->FreezeUndo();
2887 current_view->text->BreakParagraph();
2888 current_view->update(-1);
2890 if (current_view->text->cursor.par->Last()) {
2891 current_view->text->CursorLeft();
2893 current_view->text->BreakParagraph();
2894 current_view->update(-1);
2897 current_view->text->current_font.setLatex(LyXFont::OFF);
2898 //if (!fl_get_button(fd_form_table->check_latex)){
2899 // insert the new wysiwy table
2900 current_view->text->SetLayout(0); // standard layout
2901 if (current_view->text->cursor.par->footnoteflag ==
2902 LyXParagraph::NO_FOOTNOTE) {
2904 ->SetParagraph(0, 0,
2906 VSpace (0.3 * current_view->buffer()->
2907 params.spacing.getValue(),
2909 VSpace (0.3 * current_view->buffer()->
2910 params.spacing.getValue(),
2917 ->SetParagraph(0, 0,
2919 VSpace(VSpace::NONE),
2920 VSpace(VSpace::NONE),
2926 current_view->text->cursor.par->table =
2927 new LyXTable(xsize, ysize);
2929 for (int i = 0; i < xsize * ysize - 1; ++i)
2930 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2931 current_view->text->RedoParagraph();
2933 current_view->text->UnFreezeUndo();
2935 current_view->update(1);
2936 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2937 current_view->setState();
2941 extern "C" void TableCancelCB(FL_OBJECT *, long)
2943 fl_hide_form(fd_form_table->form_table);
2947 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2949 TableApplyCB(ob, data);
2950 TableCancelCB(ob, data);
2954 /* callbacks for form form_print */
2956 extern "C" void PrintCancelCB(FL_OBJECT *, long)
2958 fl_hide_form(fd_form_print->form_print);
2963 bool stringOnlyContains (string const & LStr, char const * cset)
2965 char const * cstr = LStr.c_str() ;
2967 return strspn(cstr, cset) == strlen(cstr) ;
2971 extern "C" void PrintApplyCB(FL_OBJECT *, long)
2973 if (!current_view->available())
2975 Buffer * buffer = current_view->buffer();
2976 string path = OnlyPath(buffer->fileName());
2979 if (fl_get_button(fd_form_print->radio_even_pages))
2980 pageflag = lyxrc->print_evenpage_flag + ' ';
2981 else if (fl_get_button(fd_form_print->radio_odd_pages))
2982 pageflag = lyxrc->print_oddpage_flag + ' ';
2984 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
2985 // User may give a page (range) list
2986 // User may print multiple (unsorted) copies
2987 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
2988 pages = subst(pages, '+',',');
2989 pages = frontStrip(strip(pages)) ;
2990 while (!pages.empty()) { // a page range was given
2992 pages = split (pages, piece, ',') ;
2993 piece = strip(piece) ;
2994 piece = frontStrip(piece) ;
2995 if ( !stringOnlyContains (piece, "0123456789-") ) {
2996 WriteAlert(_("ERROR! Unable to print!"),
2997 _("Check 'range of pages'!"));
3000 if (piece.find('-') == string::npos) { // not found
3001 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3002 } else if (suffixIs(piece, "-") ) { // missing last page
3003 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3004 } else if (prefixIs(piece, "-") ) { // missing first page
3005 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3007 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3011 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3012 if (!copies.empty()) { // a number of copies was given
3013 if ( !stringOnlyContains (copies, "0123456789") ) {
3014 WriteAlert(_("ERROR! Unable to print!"),
3015 _("Check 'number of copies'!"));
3018 if (fl_get_button(fd_form_print->do_unsorted))
3019 pageflag += lyxrc->print_copies_flag;
3021 pageflag += lyxrc->print_collcopies_flag;
3022 pageflag += " " + copies + ' ' ;
3026 if (fl_get_button(fd_form_print->radio_order_reverse))
3027 reverseflag = lyxrc->print_reverse_flag + ' ';
3029 string orientationflag;
3030 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3031 orientationflag = lyxrc->print_landscape_flag + ' ';
3033 string ps_file = fl_get_input(fd_form_print->input_file);
3034 string printer = strip(fl_get_input(fd_form_print->input_printer));
3037 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3038 && ! printer.empty()) // a printer name has been given
3039 printerflag = lyxrc->print_to_printer + printer + ' ';
3042 if (!lyxrc->print_extra_options.empty())
3043 extraflags = lyxrc->print_extra_options + ' ';
3045 string command = lyxrc->print_command + ' '
3046 + printerflag + pageflag + reverseflag
3047 + orientationflag + extraflags;
3049 char real_papersize = buffer->params.papersize;
3050 if (real_papersize == BufferParams::PAPER_DEFAULT)
3051 real_papersize = lyxrc->default_papersize;
3054 switch (real_papersize) {
3055 case BufferParams::PAPER_USLETTER:
3058 case BufferParams::PAPER_A3PAPER:
3061 case BufferParams::PAPER_A4PAPER:
3064 case BufferParams::PAPER_A5PAPER:
3067 case BufferParams::PAPER_B5PAPER:
3070 case BufferParams::PAPER_EXECUTIVEPAPER:
3073 case BufferParams::PAPER_LEGALPAPER:
3076 default: /* If nothing else fits, keep an empty value... */
3080 if (buffer->params.use_geometry
3081 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3082 && !lyxrc->print_paper_dimension_flag.empty()
3083 && !buffer->params.paperwidth.empty()
3084 && !buffer->params.paperheight.empty()) {
3085 // using a custom papersize
3087 command += lyxrc->print_paper_dimension_flag + ' ';
3088 command += buffer->params.paperwidth + ',';
3089 command += buffer->params.paperheight + ' ';
3090 } else if (!lyxrc->print_paper_flag.empty()
3092 && (real_papersize != BufferParams::PAPER_USLETTER ||
3093 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3094 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3096 if (fl_get_button(fd_form_print->radio_file))
3097 command += lyxrc->print_to_file
3098 + QuoteName(MakeAbsPath(ps_file, path));
3099 else if (!lyxrc->print_spool_command.empty())
3100 command += lyxrc->print_to_file
3101 + QuoteName(ps_file);
3103 // push directorypath, if necessary
3104 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3105 path = buffer->tmppath;
3110 if (!lyxrc->print_spool_command.empty() &&
3111 !fl_get_button(fd_form_print->radio_file)) {
3112 string command2 = lyxrc->print_spool_command + ' ';
3113 if (!printer.empty())
3114 command2 += lyxrc->print_spool_printerprefix
3116 // First run dvips and, if succesful, then spool command
3117 if ((result = RunScript(buffer, true, command))) {
3118 result = RunScript(buffer, false, command2, ps_file);
3121 result = RunScript(buffer, false, command);
3124 WriteAlert(_("Error:"),
3125 _("Unable to print"),
3126 _("Check that your parameters are correct"));
3130 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3132 PrintCancelCB(ob, data);
3133 PrintApplyCB(ob, data);
3137 /* callbacks for form form_figure */
3138 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3140 if (!current_view->available())
3143 Buffer * buffer = current_view->buffer();
3144 if(buffer->isReadonly()) // paranoia
3147 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3148 if (fl_get_button(fd_form_figure->radio_inline)
3149 || current_view->text->cursor.par->table) {
3150 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3151 current_view->insertInset(new_inset);
3152 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3153 new_inset->Edit(current_view, 0, 0, 0);
3157 current_view->hideCursor();
3158 current_view->update(-2);
3159 current_view->beforeChange();
3161 current_view->text->SetCursorParUndo();
3162 current_view->text->FreezeUndo();
3164 current_view->text->BreakParagraph();
3165 current_view->update(-1);
3167 if (current_view->text->cursor.par->Last()) {
3168 current_view->text->CursorLeft();
3170 current_view->text->BreakParagraph();
3171 current_view->update(-1);
3174 // The standard layout should always be numer 0;
3175 current_view->text->SetLayout(0);
3177 if (current_view->text->cursor.par->footnoteflag ==
3178 LyXParagraph::NO_FOOTNOTE) {
3179 current_view->text->
3182 VSpace (0.3 * buffer->params.spacing.getValue(),
3185 buffer->params.spacing.getValue(),
3187 LYX_ALIGN_CENTER, string(), 0);
3189 current_view->text->SetParagraph(0, 0,
3191 VSpace(VSpace::NONE),
3192 VSpace(VSpace::NONE),
3198 current_view->update(-1);
3200 Inset * new_inset = new InsetFig(100, 100, buffer);
3201 current_view->insertInset(new_inset);
3202 new_inset->Edit(current_view, 0, 0, 0);
3203 current_view->update(0);
3204 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3205 current_view->text->UnFreezeUndo();
3206 current_view->setState();
3210 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3212 fl_hide_form(fd_form_figure->form_figure);
3216 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3218 FigureApplyCB(ob, data);
3219 FigureCancelCB(ob, data);
3223 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3225 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3226 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3227 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3228 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3229 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3230 fontloader.update();
3232 // All buffers will need resize
3233 bufferlist.resize();
3235 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3239 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3241 fl_hide_form(fd_form_screen->form_screen);
3245 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3247 ScreenCancelCB(ob, data);
3248 ScreenApplyCB(ob, data);
3252 void LaTeXOptions(BufferView * bv)
3254 if (!bv->available())
3257 fl_set_button(fd_latex_options->accents,
3258 int(bv->buffer()->params.allowAccents));
3260 if (fd_latex_options->LaTeXOptions->visible) {
3261 fl_raise_form(fd_latex_options->LaTeXOptions);
3263 fl_show_form(fd_latex_options->LaTeXOptions,
3264 FL_PLACE_MOUSE, FL_FULLBORDER,
3265 _("LaTeX Options"));
3270 // This function runs "configure" and then rereads lyx.defaults to
3271 // reconfigure the automatic settings.
3272 void Reconfigure(BufferView * bv)
3274 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3276 // Run configure in user lyx directory
3277 Path p(user_lyxdir);
3278 Systemcalls one(Systemcalls::System,
3279 AddName(system_lyxdir, "configure"));
3281 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3282 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
3283 WriteAlert(_("The system has been reconfigured."),
3284 _("You need to restart LyX to make use of any"),
3285 _("updated document class specifications."));
3290 // Table of Contents
3300 static TocList * toclist = 0;
3303 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3305 if (!current_view->available())
3308 TocList * tmptoclist = toclist;
3309 int i = fl_get_browser(ob);
3310 for (int a = 1; a < i && tmptoclist->next; ++a) {
3311 tmptoclist = tmptoclist->next;
3318 LyXParagraph * par = current_view->buffer()->paragraph;
3319 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3320 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3321 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3322 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3323 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3324 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3325 par->appendix != tmptoclist->appendix)) {
3326 par = par->LastPhysicalPar()->Next();
3330 current_view->beforeChange();
3331 current_view->text->SetCursor(par, 0);
3332 current_view->text->sel_cursor =
3333 current_view->text->cursor;
3334 current_view->update(0);
3337 WriteAlert(_("Error"),
3338 _("Couldn't find this label"),
3339 _("in current document."));
3345 extern "C" void TocCancelCB(FL_OBJECT *, long)
3347 fl_hide_form(fd_form_toc->form_toc);
3351 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3353 static LyXParagraph * stapar = 0;
3354 TocList * tmptoclist = 0;
3356 /* deleted the toclist */
3359 tmptoclist = toclist->next;
3361 toclist = tmptoclist;
3365 tmptoclist = toclist;
3368 fl_clear_browser(fd_form_toc->browser_toc);
3369 if (!current_view->available()) {
3370 fl_add_browser_line(fd_form_toc->browser_toc,
3371 _("*** No Document ***"));
3374 fl_hide_object(fd_form_toc->browser_toc);
3375 /* get the table of contents */
3376 LyXParagraph * par = current_view->buffer()->paragraph;
3378 char * line = new char[200];
3384 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3388 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3389 par->GetLayout()).labeltype;
3391 if (labeltype >= LABEL_COUNTER_CHAPTER
3392 && labeltype <= LABEL_COUNTER_CHAPTER +
3393 current_view->buffer()->params.tocdepth) {
3394 /* insert this into the table of contents */
3395 /* first indent a little bit */
3399 textclasslist.TextClass(current_view->buffer()->
3400 params.textclass).maxcounter()) * 4 + 2;
3404 // Then the labestring
3405 if (!par->labelstring.empty()) {
3406 string::size_type i = 0;
3407 while (pos < 199 && i < par->labelstring.length()) {
3408 line[pos] = par->labelstring[i];
3417 /* now the contents */
3418 LyXParagraph::size_type i = 0;
3419 while (pos < 199 && i < par->size()) {
3420 c = par->GetChar(i);
3421 if (isprint(c) || c >= 128) {
3428 fl_add_browser_line(fd_form_toc->browser_toc, line);
3430 /* make a toclist entry */
3432 tmptoclist = new TocList;
3433 toclist = tmptoclist;
3435 tmptoclist->next = new TocList;
3436 tmptoclist = tmptoclist->next;
3439 tmptoclist->next = 0;
3441 for (a = 0; a < 6; ++a) {
3442 tmptoclist->counter[a] = par->GetFirstCounter(a);
3444 tmptoclist->appendix = par->appendix;
3446 par = par->LastPhysicalPar()->Next();
3450 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3451 fl_show_object(fd_form_toc->browser_toc);
3455 /* callbacks for form form_ref */
3456 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3458 if (!current_view->available())
3462 fl_get_browser_line(fd_form_ref->browser_ref,
3463 fl_get_browser(fd_form_ref->browser_ref));
3464 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3470 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3480 if(current_view->buffer()->isSGML())
3481 t += "[" + u + "]" + "{" + s + "}";
3486 new InsetRef(t, current_view->buffer());
3487 current_view->insertInset(new_inset);
3491 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3493 if (!current_view->available()) {
3494 fl_clear_browser(fd_form_ref->browser_ref);
3498 FL_OBJECT * brow = fd_form_ref->browser_ref;
3500 // Get the current line, in order to restore it later
3501 char const * const btmp = fl_get_browser_line(brow,
3502 fl_get_browser(brow));
3503 string currentstr = btmp ? btmp : "";
3505 fl_clear_browser(brow);
3507 string refs = current_view->buffer()->getReferenceList('\n');
3510 fl_addto_browser_chars(brow, refs.c_str());
3511 int total_lines = fl_get_browser_maxline(brow);
3512 for (int i = 1; i <= total_lines ; ++i) {
3513 if (fl_get_browser_line(brow, i) == currentstr) {
3518 fl_set_browser_topline(brow, topline);
3520 if (!fl_get_browser_maxline(brow)) {
3521 fl_add_browser_line(brow,
3522 _("*** No labels found in document ***"));
3523 fl_deactivate_object(brow);
3525 fl_select_browser_line(brow, topline);
3526 fl_activate_object(brow);
3528 if (current_view->buffer()->isReadonly()) {
3529 // would be better to de/activate insert buttons
3530 // but that's more work... besides this works. ARRae
3531 fl_hide_form(fd_form_ref->form_ref);
3533 if (!current_view->buffer()->isSGML()) {
3534 fl_deactivate_object(fd_form_ref->ref_name);
3535 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3538 fl_activate_object(fd_form_ref->ref_name);
3539 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3544 extern "C" void RefHideCB(FL_OBJECT *, long)
3546 fl_hide_form(fd_form_ref->form_ref);
3549 #ifndef USE_OSTREAM_ONLY
3550 #ifdef WITH_WARNINGS
3553 // I know we shouldn't put anything in here but this seems the fastest
3554 // way to do this (and the cleanest for now). This function just inserts
3555 // a newline in the string and the inserts 'depth'-spaces so that the
3556 // code is indented in the right way!!!
3557 void addNewlineAndDepth(string & file, int depth)
3560 file.append(depth, ' ');