1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
20 #include "support/lstrings.h"
22 #include FORMS_H_LOCATION
24 #include "layout_forms.h"
25 #include "bullet_forms.h"
26 #include "print_form.h"
28 #include "spellchecker.h"
32 #include "insets/insetref.h"
33 #include "insets/insetquotes.h"
35 #include "insets/insetlatex.h"
37 #include "insets/insetlabel.h"
38 #include "insets/insetinfo.h"
39 #include "insets/insetspecialchar.h"
40 #include "insets/figinset.h"
42 #include "latexoptions.h"
44 #include "minibuffer.h"
46 #include "bufferlist.h"
47 #include "support/filetools.h"
48 #include "support/path.h"
50 #include "lyx_gui_misc.h"
51 #include "LyXView.h" // only because of form_main
52 #include "lastfiles.h"
53 #include "support/FileInfo.h"
54 #include "lyxscreen.h"
56 #include "support/syscall.h"
57 #include "support/lyxlib.h"
58 #include "lyxserver.h"
59 #include "FontLoader.h"
65 extern MiniBuffer * minibuffer;
66 extern Combox * combo_language;
67 extern BufferList bufferlist;
68 extern void show_symbols_form();
69 extern FD_form_main * fd_form_main;
70 extern FD_form_title * fd_form_title;
71 extern FD_form_paragraph * fd_form_paragraph;
72 extern FD_form_character * fd_form_character;
73 extern FD_form_document * fd_form_document;
74 extern FD_form_quotes * fd_form_quotes;
75 extern FD_form_preamble * fd_form_preamble;
76 extern FD_form_table * fd_form_table;
77 extern FD_form_print * fd_form_print;
78 extern FD_form_figure * fd_form_figure;
79 extern FD_form_screen * fd_form_screen;
80 extern FD_form_toc * fd_form_toc;
81 extern FD_form_ref * fd_form_ref;
82 extern FD_LaTeXOptions * fd_latex_options;
83 extern FD_form_bullet * fd_form_bullet;
85 extern BufferView * current_view; // called too many times in this file...
87 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
89 extern bool send_fax(string const & fname, string const & sendcmd);
90 extern void MenuSendto();
92 extern LyXServer * lyxserver;
93 extern FontLoader fontloader;
95 // this should be static, but I need it in buffer.C
96 bool quitting; // flag, that we are quitting the program
97 extern bool finished; // all cleanup done just let it run through now.
99 char ascii_type; /* for selection notify callbacks */
101 bool scrolling = false;
103 char updatetimer = 0;
105 /* whether the work area should get callbacks */
106 bool input_prohibited = false;
108 /* the selection possible is needed, that only motion events are
109 * used, where the bottom press event was on the drawing area too */
110 bool selection_possible = false;
112 // This is used to make the dreaded font toggle problem hopefully go
113 // away. Definitely not the best solution, but I think it sorta works.
114 bool toggleall = true;
116 void InsertCorrectQuote();
120 This is the inset locking stuff needed for mathed --------------------
122 an inset can simple call LockInset in it's edit call and *ONLY* in it's
124 Inset::Edit() can only be called by the main lyx module.
126 Then the inset may modify the menu's and/or iconbars.
128 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
130 During the lock, all button and keyboard events will be modified
131 and send to the inset through the following inset-features. Note that
132 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
133 to contain the code for restoring the menus and things like this.
136 virtual void InsetButtonPress(int x, int y, int button);
137 virtual void InsetButtonRelease(int x, int y, int button);
138 virtual void InsetKeyPress(XKeyEvent *ev);
139 virtual void InsetMotionNotify(int x, int y, int state);
140 virtual void InsetUnlock();
142 If a inset wishes any redraw and/or update it just has to call
144 It's is completly irrelevant, where the inset is. UpdateInset will
145 find it in any paragraph in any buffer.
146 Of course the_locking_inset and the insets in the current paragraph/buffer
147 are checked first, so no performance problem should occur.
149 Hope that's ok for the beginning, Alejandro,
150 sorry that I needed so much time,
155 void UpdateInset(Inset * inset, bool mark_dirty = true);
156 /* these functions return 1 if an error occured,
158 // Now they work only for updatable insets. [Alejandro 080596]
159 int LockInset(UpdatableInset * inset);
160 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
161 void FitLockedInsetCursor(long x, long y, int asc, int desc);
162 int UnlockInset(UpdatableInset * inset);
163 void LockedInsetStoreUndo(Undo::undo_kind kind);
165 /* this is for asyncron updating. UpdateInsetUpdateList will be called
166 automatically from LyX. Just insert the Inset into the Updatelist */
167 void UpdateInsetUpdateList();
168 void PutInsetIntoInsetUpdateList(Inset * inset);
170 InsetUpdateStruct * InsetUpdateList = 0;
174 -----------------------------------------------------------------------
177 /* some function prototypes */
184 void HyphenationPoint();
185 void MenuSeparator();
188 void ProtectedBlank();
190 int RunLinuxDoc(int, string const &);
191 int RunDocBook(int, string const &);
192 void MenuWrite(Buffer * buf);
193 void MenuWriteAs(Buffer * buffer);
194 void MenuReload(Buffer * buf);
195 void MenuLayoutSave();
197 unsigned char GetCurrentTextClass()
198 // Who are we asking?
199 // Shouldn't this question be directed to the buffer?
200 // Indeed it should. Asger.
202 return current_view->buffer()->params.textclass;
206 // How should this actually work? Should it prohibit input in all BufferViews,
207 // or just in the current one? If "just the current one", then it should be
208 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
209 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
210 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
211 // current LyxView that should be prohibited (Lgb) (This applies to
212 // "AllowInput" as well.)
215 input_prohibited = true;
216 if (current_view->getScreen())
217 current_view->getScreen()->HideCursor();
219 static Cursor cursor;
220 static bool cursor_undefined = true;
222 if (cursor_undefined){
223 cursor = XCreateFontCursor(fl_display, XC_watch);
225 cursor_undefined = false;
228 /* set the cursor to the watch for all forms and the canvas */
229 XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
230 if (fd_form_paragraph->form_paragraph->visible)
231 XDefineCursor(fl_display,
232 fd_form_paragraph->form_paragraph->window,
234 if (fd_form_character->form_character->visible)
235 XDefineCursor(fl_display,
236 fd_form_character->form_character->window,
240 fl_deactivate_all_forms();
244 // Should find a way to move this into BufferView.C
245 void SetXtermCursor(Window win)
247 static Cursor cursor;
248 static bool cursor_undefined = true;
249 if (cursor_undefined){
250 cursor = XCreateFontCursor(fl_display, XC_xterm);
252 cursor_undefined = false;
254 XDefineCursor(fl_display, win, cursor);
261 input_prohibited = false;
263 /* reset the cursor from the watch for all forms and the canvas */
265 XUndefineCursor(fl_display, fd_form_main->form_main->window);
266 if (fd_form_paragraph->form_paragraph->visible)
267 XUndefineCursor(fl_display,
268 fd_form_paragraph->form_paragraph->window);
269 if (fd_form_character->form_character->visible)
270 XUndefineCursor(fl_display,
271 fd_form_character->form_character->window);
272 if (current_view->getWorkArea()->belowmouse)
273 SetXtermCursor(fd_form_main->form_main->window);
276 fl_activate_all_forms();
280 void FreeUpdateTimer()
282 /* a real free timer would be better but I don't know
283 * how to do this with xforms */
288 void SetUpdateTimer(float time)
290 fl_set_timer(fd_form_main->timer_update, time);
295 // candidate for move to BufferView
298 current_view->getScreen()->ToggleSelection();
299 current_view->text->ClearSelection();
304 // candidate for move to BufferView
305 void SmallUpdate(signed char f)
307 current_view->getScreen()->SmallUpdate();
308 if (current_view->getScreen()->TopCursorVisible()
309 != current_view->getScreen()->first) {
310 current_view->update(f);
314 current_view->fitCursor();
315 current_view->updateScrollbar();
317 if (!current_view->text->selection)
318 current_view->text->sel_cursor =
319 current_view->text->cursor;
321 if (f == 1 || f == -1) {
322 if (current_view->buffer()->isLyxClean()) {
323 current_view->buffer()->markDirty();
324 minibuffer->setTimer(4);
327 current_view->buffer()->markDirty();
341 // should be moved to lyxfunc.C
342 void MenuWrite(Buffer * buf)
345 if (!bufferlist.write(buf)) {
346 string fname = buf->fileName();
347 string s = MakeAbsPath(fname);
348 if (AskQuestion(_("Save failed. Rename and try again?"),
349 MakeDisplayPath(s, 50),
350 _("(If not, document is not saved.)"))) {
354 lastfiles->newFile(buf->fileName());
359 // should be moved to BufferView.C
360 void MenuWriteAs(Buffer * buffer)
362 if (!current_view->text) return;
364 string fname = buffer->fileName();
365 string oldname = fname;
369 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
370 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
372 if (!IsLyXFilename(fname))
375 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
378 OnlyFilename(fname));
382 minibuffer->Set(_("Canceled."));
386 // Make sure the absolute filename ends with appropriate suffix
387 string s = MakeAbsPath(fname);
388 if (!IsLyXFilename(s))
391 // Same name as we have already?
393 if (!AskQuestion(_("Same name as document already has:"),
394 MakeDisplayPath(s, 50),
397 // Falls through to name change and save
399 // No, but do we have another file with this name open?
400 else if (bufferlist.exists(s)) {
401 if (AskQuestion(_("Another document with same name open!"),
402 MakeDisplayPath(s, 50),
403 _("Replace with current document?")))
405 bufferlist.close(bufferlist.getBuffer(s));
407 // Ok, change the name of the buffer, but don't save!
411 minibuffer->Set(_("Document renamed to '"),
413 _("', but not saved..."));
416 } // Check whether the file exists
419 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
420 MakeDisplayPath(s, 50),
425 // Ok, change the name of the buffer
429 // Small bug: If the save fails, we have irreversible changed the name
435 int MenuRunLaTeX(Buffer * buffer)
439 if (buffer->isLinuxDoc())
440 ret = RunLinuxDoc(1, buffer->fileName());
441 else if (buffer->isLiterate())
442 ret = buffer->runLiterate();
443 else if (buffer->isDocBook())
444 ret = RunDocBook(1, buffer->fileName());
446 ret = buffer->runLaTeX();
452 s = _("One error detected");
453 t = _("You should try to fix it.");
456 s += _(" errors detected.");
457 t = _("You should try to fix them.");
459 WriteAlert(_("There were errors during the LaTeX run."), s, t);
465 int MenuBuildProg(Buffer * buffer)
469 if (buffer->isLiterate())
470 ret = buffer->buildProgram();
472 string s = _("Wrong type of document");
473 string t = _("The Build operation is not allowed in this document");
474 WriteAlert(_("There were errors during the Build process."), s, t);
482 s = _("One error detected");
483 t = _("You should try to fix it.");
486 s += _(" errors detected.");
487 t = _("You should try to fix them.");
489 WriteAlert(_("There were errors during the Build process."), s, t);
495 int MenuRunChktex(Buffer * buffer)
499 if (buffer->isSGML()) {
500 WriteAlert(_("Chktex does not work with SGML derived documents."));
503 ret = buffer->runChktex();
509 s = _("No warnings found.");
510 } else if (ret == 1) {
511 s = _("One warning found.");
512 t = _("Use 'Edit->Go to Error' to find it.");
515 s += _(" warnings found.");
516 t = _("Use 'Edit->Go to Error' to find them.");
518 WriteAlert(_("Chktex run successfully"), s, t);
520 WriteAlert(_("Error!"), _("It seems chktex does not work."));
526 int MakeDVIOutput(Buffer * buffer)
528 if (!(current_view->text))
533 string path = OnlyPath(buffer->fileName());
534 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
535 path = buffer->tmppath;
537 if (!buffer->isDviClean()) {
539 ret = MenuRunLaTeX(buffer);
545 /* wait == false means don't wait for termination */
546 /* wait == true means wait for termination */
547 // The bool should be placed last on the argument line. (Lgb)
548 // Returns false if we fail.
549 bool RunScript(Buffer * buffer, bool wait,
550 string const & command,
551 string const & orgname = string(),
552 bool need_shell = true)
556 string name = orgname;
559 if (MakeDVIOutput(buffer) > 0)
561 /* get DVI-Filename */
563 name = ChangeExtension(buffer->getLatexName(),
566 path = OnlyPath(name);
567 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
568 path = buffer->tmppath;
572 cmd = command + ' ' + QuoteName(name);
581 // OS/2 cmd.exe has another use for '&'
583 // This is not NLS safe, but it's OK, I think.
584 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
586 // COMSPEC is set, unless user unsets
587 sh = OnlyFilename(GetEnvPath("COMSPEC"));
592 if (contains(sh, "cmd.exe")
593 || contains(sh, "4os2.exe"))
594 cmd = "start /min/n " + cmd;
599 // It seems that, if wait is false, we never get back
600 // the return code of the command. This means that all
601 // the code I added in PrintApplyCB is currently
604 #warning What should we do here?
606 minibuffer->Set(_("Executing command:"), cmd);
607 result = one.startscript(Systemcalls::System, cmd);
609 minibuffer->Set(_("Executing command:"), cmd);
610 result = one.startscript(wait ? Systemcalls::Wait
611 : Systemcalls::DontWait, cmd);
613 return (result == 0);
617 // Returns false if we fail
618 bool MenuRunDvips(Buffer * buffer, bool wait = false)
620 if (!current_view->text)
626 if (MakeDVIOutput(buffer) > 0) {
630 // Generate postscript file
631 string psname = ChangeExtension (buffer->fileName(),
636 char real_papersize = buffer->params.papersize;
637 if (real_papersize == BufferParams::PAPER_DEFAULT)
638 real_papersize = lyxrc->default_papersize;
640 switch (real_papersize) {
641 case BufferParams::PAPER_USLETTER:
644 case BufferParams::PAPER_A3PAPER:
647 case BufferParams::PAPER_A4PAPER:
650 case BufferParams::PAPER_A5PAPER:
653 case BufferParams::PAPER_B5PAPER:
656 case BufferParams::PAPER_EXECUTIVEPAPER:
659 case BufferParams::PAPER_LEGALPAPER:
662 default: /* If nothing else fits, keep an empty value... */
666 // Make postscript file.
667 string command = "dvips " + lyxrc->print_to_file + ' ';
668 command += QuoteName(psname);
669 if (buffer->params.use_geometry
670 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
671 && !lyxrc->print_paper_dimension_flag.empty()
672 && !buffer->params.paperwidth.empty()
673 && !buffer->params.paperheight.empty()) {
674 // using a custom papersize
676 command += lyxrc->print_paper_dimension_flag + ' ';
677 command += buffer->params.paperwidth + ',';
678 command += buffer->params.paperheight;
679 } else if (!paper.empty()
680 && (real_papersize != BufferParams::PAPER_USLETTER ||
681 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
682 // dvips won't accept -t letter -t landscape. In all other
683 // cases, include the paper size explicitly.
685 command += lyxrc->print_paper_flag + ' ' + paper;
687 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
689 command += lyxrc->print_landscape_flag;
691 // push directorypath, if necessary
692 string path = OnlyPath(buffer->fileName());
693 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
694 path = buffer->tmppath;
697 bool ret = RunScript(buffer, wait, command);
703 // Returns false if we fail
704 bool MenuPreviewPS(Buffer * buffer)
706 if (!current_view->text)
709 // Generate postscript file
710 if (!MenuRunDvips(buffer, true)) {
714 // Start postscript viewer
716 string ps = ChangeExtension (buffer->fileName(),
718 // push directorypath, if necessary
719 string path = OnlyPath(buffer->fileName());
720 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
721 path = buffer->tmppath;
724 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
730 void MenuFax(Buffer * buffer)
732 if (!current_view->text)
735 // Generate postscript file
736 if (!MenuRunDvips(buffer, true)) {
741 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
742 string path = OnlyPath (buffer->fileName());
743 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
744 path = buffer->tmppath;
747 if (!lyxrc->fax_program.empty()) {
748 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
750 Systemcalls one(Systemcalls::System, help2);
752 send_fax(ps, lyxrc->fax_command);
756 // Returns false if we fail
757 bool MenuPreview(Buffer * buffer)
759 if (!current_view->text)
764 char real_papersize = buffer->params.papersize;
765 if (real_papersize == BufferParams::PAPER_DEFAULT)
766 real_papersize = lyxrc->default_papersize;
768 switch (real_papersize) {
769 case BufferParams::PAPER_USLETTER:
772 case BufferParams::PAPER_A3PAPER:
775 case BufferParams::PAPER_A4PAPER:
778 case BufferParams::PAPER_A5PAPER:
781 case BufferParams::PAPER_B5PAPER:
784 case BufferParams::PAPER_EXECUTIVEPAPER:
787 case BufferParams::PAPER_LEGALPAPER:
790 default: /* If nothing else fits, keep the empty value */
795 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
796 // we HAVE to give a size when the page is in
797 // landscape, so use USletter.
798 paper = " -paper usr";
800 paper = " -paper " + paper;
801 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
805 // push directorypath, if necessary
806 string path = OnlyPath(buffer->fileName());
807 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
808 path = buffer->tmppath;
812 string command = lyxrc->view_dvi_command + paper ;
813 bool ret = RunScript(buffer, false, command);
818 void MenuMakeLaTeX(Buffer * buffer)
820 if (!current_view->text)
823 // Get LaTeX-Filename
824 string s = buffer->getLatexName();
828 !AskQuestion(_("File already exists:"),
829 MakeDisplayPath(s, 50),
830 _("Do you want to overwrite the file?"))) {
831 minibuffer->Set(_("Canceled"));
835 if (buffer->isDocBook())
836 minibuffer->Set(_("DocBook does not have a latex backend"));
838 if (buffer->isLinuxDoc())
839 RunLinuxDoc(0, buffer->fileName());
841 buffer->makeLaTeXFile(s, string(), true);
842 minibuffer->Set(_("Nice LaTeX file saved as"),
844 buffer->markDviDirty();
849 void MenuMakeLinuxDoc(Buffer * buffer)
851 if (!current_view->text) return;
853 if (!buffer->isLinuxDoc()) {
854 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
858 // Get LinuxDoc-Filename
859 string s = ChangeExtension (buffer->fileName(),
864 !AskQuestion(_("File already exists:"),
865 MakeDisplayPath(s, 50),
866 _("Do you want to overwrite the file?"))) {
867 minibuffer->Set(_("Canceled"));
871 minibuffer->Set(_("Building LinuxDoc SGML file `"),
872 MakeDisplayPath(s), "'...");
874 buffer->makeLinuxDocFile(s, 65);
876 minibuffer->Set(_("LinuxDoc SGML file save as"),
881 void MenuMakeDocBook(Buffer * buffer)
883 if (!current_view->text) return;
885 if (!buffer->isDocBook()) {
886 WriteAlert(_("Error!"),
887 _("Document class must be docbook."));
891 // Get DocBook-Filename
892 string s = ChangeExtension (buffer->fileName(),
897 !AskQuestion(_("File already exists:"),
898 MakeDisplayPath(s, 50),
899 _("Do you want to overwrite the file?"))) {
900 minibuffer->Set(_("Canceled"));
904 minibuffer->Set(_("Building DocBook SGML file `"),
905 MakeDisplayPath(s), "'...");
907 buffer->makeDocBookFile(s, 65);
909 minibuffer->Set(_("DocBook SGML file save as"),
914 void MenuMakeAscii(Buffer * buffer)
916 if (!current_view->text) return;
918 /* get LaTeX-Filename */
919 string s = ChangeExtension (buffer->fileName(),
924 !AskQuestion(_("File already exists:"),
925 MakeDisplayPath(s, 50),
926 _("Do you want to overwrite the file?"))) {
927 minibuffer->Set(_("Canceled"));
931 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
933 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
937 void MenuPrint(Buffer * buffer)
939 if (!current_view->text)
942 string input_file = ChangeExtension(buffer->fileName(),
943 lyxrc->print_file_extension,
945 fl_set_input(fd_form_print->input_file, input_file.c_str());
947 if (fd_form_print->form_print->visible) {
948 fl_raise_form(fd_form_print->form_print);
951 fl_show_form(fd_form_print->form_print,
952 FL_PLACE_MOUSE, FL_FULLBORDER,
957 void MenuMakeHTML(Buffer * buffer)
959 // First, create LaTeX file
960 MenuMakeLaTeX(buffer);
962 // And now, run the converter
963 string file = buffer->fileName();
964 Path path(OnlyPath(file));
965 // the tex file name has to be correct for
966 // latex, but the html file name can be
968 string result = ChangeExtension(file, ".html", false);
969 string infile = buffer->getLatexName();
970 string tmp = lyxrc->html_command;
971 tmp = subst(tmp, "$$FName", infile);
972 tmp = subst(tmp, "$$OutName", result);
974 int res = one.startscript(Systemcalls::System, tmp);
976 minibuffer->Set(_("Document exported as HTML to file `")
977 + MakeDisplayPath(result) +'\'');
979 minibuffer->Set(_("Unable to convert to HTML the file `")
980 + MakeDisplayPath(infile)
986 void MenuExport(Buffer * buffer, string const & extyp)
989 if (extyp == "latex") {
990 // make sure that this buffer is not linuxdoc
991 MenuMakeLaTeX(buffer);
994 else if (extyp == "linuxdoc") {
995 // make sure that this buffer is not latex
996 MenuMakeLinuxDoc(buffer);
999 else if (extyp == "docbook") {
1000 // make sure that this buffer is not latex or linuxdoc
1001 MenuMakeDocBook(buffer);
1004 else if (extyp == "dvi") {
1005 // Run LaTeX as "Update dvi..." Bernhard.
1006 // We want the dvi in the current directory. This
1007 // is achieved by temporarily disabling use of
1008 // temp directory. As a side-effect, we get
1009 // *.log and *.aux files also. (Asger)
1010 bool flag = lyxrc->use_tempdir;
1011 lyxrc->use_tempdir = false;
1012 MenuRunLaTeX(buffer);
1013 lyxrc->use_tempdir = flag;
1016 else if (extyp == "postscript") {
1017 // Start Print-dialog. Not as good as dvi... Bernhard.
1019 // Since the MenuPrint is a pop-up, we can't use
1020 // the same trick as above. (Asger)
1021 // MISSING: Move of ps-file :-(
1024 else if (extyp == "ascii") {
1025 MenuMakeAscii(buffer);
1027 else if (extyp == "custom") {
1031 else if (extyp == "html") {
1032 MenuMakeHTML(buffer);
1035 minibuffer->Set(_("Unknown export type: ")+ extyp);
1042 lyxerr.debug() << "Running QuitLyX." << endl;
1044 if (!bufferlist.QwriteAll())
1047 lastfiles->writeFile(lyxrc->lastfiles);
1049 // Set a flag that we do quitting from the program,
1050 // so no refreshes are necessary.
1053 // close buffers first
1054 bufferlist.closeAll();
1056 // do any other cleanup procedures now
1057 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1059 DestroyLyXTmpDir(system_tempdir);
1067 // should probably be moved into BufferList (Lgb)
1068 // Perfect target for a thread...
1070 if (!current_view->getScreen() || !current_view->available())
1073 if (current_view->buffer()->isBakClean()
1074 || current_view->buffer()->isReadonly()) {
1075 // We don't save now, but we'll try again later
1076 current_view->owner()->resetAutosaveTimer();
1080 minibuffer->Set(_("Autosaving current document..."));
1082 // create autosave filename
1083 string fname = OnlyPath(current_view->buffer()->fileName());
1085 fname += OnlyFilename(current_view->buffer()->fileName());
1088 // tmp_ret will be located (usually) in /tmp
1089 // will that be a problem?
1090 string tmp_ret = tmpnam(0);
1092 pid_t pid = fork(); // If you want to debug the autosave
1093 // you should set pid to -1, and comment out the
1095 if (pid == 0 || pid == -1) {
1096 // pid = -1 signifies that lyx was unable
1097 // to fork. But we will do the save
1099 bool failed = false;
1100 if (!tmp_ret.empty()) {
1101 current_view->buffer()->writeFile(tmp_ret, 1);
1102 // assume successful write of tmp_ret
1103 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1105 // most likely couldn't move between filesystems
1106 // unless write of tmp_ret failed
1107 // so remove tmp file (if it exists)
1108 remove(tmp_ret.c_str());
1115 // failed to write/rename tmp_ret so try writing direct
1116 if (!current_view->buffer()->writeFile(fname, 1)) {
1117 // It is dangerous to do this in the child,
1118 // but safe in the parent, so...
1120 minibuffer->Set(_("Autosave Failed!"));
1123 if (pid == 0) { // we are the child so...
1128 current_view->buffer()->markBakClean();
1129 current_view->owner()->resetAutosaveTimer();
1134 // (c) CHT Software Service GmbH
1137 // create new file with template
1140 Buffer * NewLyxFile(string const & filename)
1142 // Split argument by :
1144 string tmpname = split(filename, name, ':');
1145 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1146 if (name.length() == 1
1147 && isalpha(static_cast<unsigned char>(name[0]))
1148 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1150 name += token(tmpname, ':', 0);
1151 tmpname = split(tmpname, ':');
1154 lyxerr.debug() << "Arg is " << filename
1155 << "\nName is " << name
1156 << "\nTemplate is " << tmpname << endl;
1158 // find a free buffer
1159 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1161 lastfiles->newFile(tmpbuf->fileName());
1166 // Insert ascii file (if filename is empty, prompt for one)
1167 void InsertAsciiFile(string const & f, bool asParagraph)
1172 if (!current_view->getScreen()) return;
1174 if (fname.empty()) {
1176 fname = fileDlg.Select(_("File to Insert"),
1177 current_view->owner()->buffer()->filepath,
1180 if (fname.empty()) return;
1185 if (!fi.readable()) {
1186 WriteFSAlert(_("Error! Specified file is unreadable: "),
1187 MakeDisplayPath(fname, 50));
1191 FilePtr myfile(fname, FilePtr::read);
1193 WriteFSAlert(_("Error! Cannot open specified file: "),
1194 MakeDisplayPath(fname, 50));
1197 LyXParagraph * tmppar = new LyXParagraph;
1198 tmppar->readSimpleWholeFile(myfile);
1200 // set the end of the string
1201 #ifdef WITH_WARNINGS
1202 #warning why do we do this?
1204 // I don't think this is needed. Actually it might be plain wrong.
1205 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1207 // insert the string
1208 current_view->getScreen()->HideCursor();
1210 // clear the selection
1213 current_view->text->InsertStringA(tmppar->text);
1215 current_view->text->InsertStringB(tmppar->text);
1217 current_view->update(1);
1221 void MenuShowTableOfContents()
1223 static int ow = -1, oh;
1226 if (fd_form_toc->form_toc->visible) {
1227 fl_raise_form(fd_form_toc->form_toc);
1229 fl_show_form(fd_form_toc->form_toc,
1230 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1231 _("Table Of Contents"));
1233 ow = fd_form_toc->form_toc->w;
1234 oh = fd_form_toc->form_toc->h;
1236 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1241 void MenuInsertLabel(char const * arg)
1245 //string label = fl_show_input(_("Enter new label to insert:"), "");
1247 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1248 if (!label.empty()) {
1249 InsetLabel * new_inset = new InsetLabel;
1250 new_inset->setContents(label);
1251 current_view->buffer()->insertInset(new_inset);
1257 void MenuInsertRef()
1259 static int ow = -1, oh;
1262 if (fd_form_ref->form_ref->visible) {
1263 fl_raise_form(fd_form_ref->form_ref);
1265 fl_show_form(fd_form_ref->form_ref,
1266 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1267 _("Insert Reference"));
1269 ow = fd_form_ref->form_ref->w;
1270 oh = fd_form_ref->form_ref->h;
1272 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1277 void MenuPasteSelection(char at)
1279 if (!current_view->getScreen())
1284 Atom data_prop = XInternAtom(fl_display,
1287 if (data_prop == None)
1289 XConvertSelection(fl_display,
1290 XA_PRIMARY, XA_STRING, data_prop,
1291 fd_form_main->form_main->window, 0);
1296 // candidate for move to BufferView
1297 extern "C" void FootCB(FL_OBJECT *, long)
1299 if (!current_view->available())
1302 minibuffer->Set(_("Inserting Footnote..."));
1303 current_view->getScreen()->HideCursor();
1304 current_view->update(-2);
1305 current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1306 current_view->update(1);
1310 // candidate for move to LyXView
1311 void LayoutsCB(int sel, void *)
1313 string tmp = tostr(sel);
1314 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1320 * SGML Linuxdoc support:
1321 * (flag == -1) import SGML file
1322 * (flag == 0) make TeX output
1323 * (flag == 1) make dvi output
1325 int RunLinuxDoc(int flag, string const & filename)
1334 /* generate a path-less extension name */
1335 name = ChangeExtension (filename, ".sgml", true);
1336 path = OnlyPath (filename);
1337 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1338 path = current_view->buffer()->tmppath;
1343 if (!current_view->available())
1345 current_view->buffer()->makeLinuxDocFile(name, 0);
1346 #ifdef WITH_WARNINGS
1347 #warning remove this once we have a proper geometry class
1349 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1351 case BufferParams::PAPER_A4PAPER:
1352 add_flags = "-p a4";
1354 case BufferParams::PAPER_USLETTER:
1355 add_flags = "-p letter";
1357 default: /* nothing to be done yet ;-) */ break;
1365 case -1: /* Import file */
1366 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1367 MakeDisplayPath(filename), "'...");
1368 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1370 if (one.startscript(Systemcalls::System, s2))
1373 case 0: /* TeX output asked */
1374 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1375 s2 = "sgml2latex " + add_flags + " -o tex "
1376 + lyxrc->sgml_extra_options + ' ' + name;
1377 if (one.startscript(Systemcalls::System, s2))
1380 case 1: /* dvi output asked */
1381 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1382 s2 = "sgml2latex " + add_flags + " -o dvi "
1383 + lyxrc->sgml_extra_options + ' ' + name;
1384 if (one.startscript(Systemcalls::System, s2)) {
1387 current_view->buffer()->markDviClean();
1389 default: /* unknown output */
1395 current_view->buffer()->redraw();
1401 * SGML DocBook support:
1402 * (flag == 1) make dvi output
1404 int RunDocBook(int flag, string const & filename)
1406 /* generate a path-less extension name */
1407 string name = ChangeExtension (filename, ".sgml", true);
1408 string path = OnlyPath (filename);
1409 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1410 path = current_view->buffer()->tmppath;
1414 if (!current_view->available())
1417 current_view->buffer()->makeDocBookFile(name, 0);
1419 // Shall this code go or should it stay? (Lgb)
1420 // string add_flags;
1421 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1423 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1424 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1425 // default: /* nothing to be done yet ;-) */ break;
1432 case 1: /* dvi output asked */
1434 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1435 string s2 = "sgmltools --backend dvi " + name;
1436 if (one.startscript(Systemcalls::System, s2)) {
1439 current_view->buffer()->markDviClean();
1442 default: /* unknown output */
1448 current_view->buffer()->redraw();
1453 // candidate for move to BufferView
1454 void AllFloats(char flag, char figmar)
1456 if (!current_view->available())
1459 LyXCursor cursor = current_view->text->cursor;
1461 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1463 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1464 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1466 && cursor.par->footnotekind != LyXParagraph::FIG
1467 && cursor.par->footnotekind != LyXParagraph::TAB
1468 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1469 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1470 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1475 LyXCursor tmpcursor = cursor;
1476 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1477 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1479 LyXParagraph *par = current_view->buffer()->paragraph;
1482 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1484 && par->footnotekind != LyXParagraph::FOOTNOTE
1485 && par->footnotekind != LyXParagraph::MARGIN)
1487 && par->footnotekind != LyXParagraph::FIG
1488 && par->footnotekind != LyXParagraph::TAB
1489 && par->footnotekind != LyXParagraph::WIDE_FIG
1490 && par->footnotekind != LyXParagraph::WIDE_TAB
1491 && par->footnotekind != LyXParagraph::ALGORITHM
1496 && par->previous->footnoteflag !=
1497 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1499 ->SetCursorIntern(par
1502 current_view->text->OpenFootnote();
1507 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1511 par->footnotekind != LyXParagraph::FOOTNOTE
1513 par->footnotekind != LyXParagraph::MARGIN
1518 par->footnotekind != LyXParagraph::FIG
1520 par->footnotekind != LyXParagraph::TAB
1522 par->footnotekind != LyXParagraph::WIDE_FIG
1524 par->footnotekind != LyXParagraph::WIDE_TAB
1526 par->footnotekind != LyXParagraph::ALGORITHM
1530 current_view->text->SetCursorIntern(par, 0);
1531 current_view->text->CloseFootnote();
1537 current_view->text->SetCursorIntern(cursor.par, cursor.pos);
1538 current_view->redraw();
1539 current_view->fitCursor();
1540 current_view->updateScrollbar();
1544 void MenuLayoutCharacter()
1546 static int ow = -1, oh;
1548 if (fd_form_character->form_character->visible) {
1549 fl_raise_form(fd_form_character->form_character);
1551 fl_show_form(fd_form_character->form_character,
1552 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1553 _("Character Style"));
1555 ow = fd_form_character->form_character->w;
1556 oh = fd_form_character->form_character->h;
1558 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1563 inline void DeactivateParagraphButtons ()
1565 fl_deactivate_object (fd_form_paragraph->button_ok);
1566 fl_deactivate_object (fd_form_paragraph->button_apply);
1567 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1568 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1572 inline void ActivateParagraphButtons ()
1574 fl_activate_object (fd_form_paragraph->button_ok);
1575 fl_activate_object (fd_form_paragraph->button_apply);
1576 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1577 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1581 inline void DisableParagraphLayout ()
1583 DeactivateParagraphButtons();
1584 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1585 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1586 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1587 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1588 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1589 fl_deactivate_object (fd_form_paragraph->check_noindent);
1590 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1591 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1592 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1593 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1594 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1595 fl_deactivate_object (fd_form_paragraph->input_space_above);
1596 fl_deactivate_object (fd_form_paragraph->input_space_below);
1597 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1598 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1599 fl_deactivate_object (fd_form_paragraph->check_space_above);
1600 fl_deactivate_object (fd_form_paragraph->check_space_below);
1604 inline void EnableParagraphLayout ()
1606 ActivateParagraphButtons();
1607 fl_activate_object (fd_form_paragraph->input_labelwidth);
1608 fl_activate_object (fd_form_paragraph->check_lines_top);
1609 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1610 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1611 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1612 fl_activate_object (fd_form_paragraph->check_noindent);
1613 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1614 fl_activate_object (fd_form_paragraph->radio_align_right);
1615 fl_activate_object (fd_form_paragraph->radio_align_left);
1616 fl_activate_object (fd_form_paragraph->radio_align_block);
1617 fl_activate_object (fd_form_paragraph->radio_align_center);
1618 fl_activate_object (fd_form_paragraph->input_space_above);
1619 fl_activate_object (fd_form_paragraph->input_space_below);
1620 fl_activate_object (fd_form_paragraph->choice_space_above);
1621 fl_activate_object (fd_form_paragraph->choice_space_below);
1622 fl_activate_object (fd_form_paragraph->check_space_above);
1623 fl_activate_object (fd_form_paragraph->check_space_below);
1627 bool UpdateLayoutParagraph()
1629 if (!current_view->getScreen() || !current_view->available()) {
1630 if (fd_form_paragraph->form_paragraph->visible)
1631 fl_hide_form(fd_form_paragraph->form_paragraph);
1635 Buffer * buf = current_view->buffer();
1637 fl_set_input(fd_form_paragraph->input_labelwidth,
1638 current_view->text->cursor.par->GetLabelWidthString().c_str());
1639 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1640 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1641 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1642 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1644 int align = current_view->text->cursor.par->GetAlign();
1645 if (align == LYX_ALIGN_LAYOUT)
1646 align = textclasslist.Style(buf->params.textclass,
1647 current_view->text->cursor.par->GetLayout()).align;
1650 case LYX_ALIGN_RIGHT:
1651 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1653 case LYX_ALIGN_LEFT:
1654 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1656 case LYX_ALIGN_CENTER:
1657 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1660 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1664 fl_set_button(fd_form_paragraph->check_lines_top,
1665 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1666 fl_set_button(fd_form_paragraph->check_lines_bottom,
1667 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1668 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1669 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1670 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1671 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1672 fl_set_button(fd_form_paragraph->check_noindent,
1673 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1674 fl_set_input (fd_form_paragraph->input_space_above, "");
1676 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1678 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1680 case VSpace::DEFSKIP:
1681 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1683 case VSpace::SMALLSKIP:
1684 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1686 case VSpace::MEDSKIP:
1687 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1689 case VSpace::BIGSKIP:
1690 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1693 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1695 case VSpace::LENGTH:
1696 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1697 fl_set_input (fd_form_paragraph->input_space_above,
1698 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1701 fl_set_button (fd_form_paragraph->check_space_above,
1702 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1703 fl_set_input (fd_form_paragraph->input_space_below, "");
1704 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1706 fl_set_choice (fd_form_paragraph->choice_space_below,
1709 case VSpace::DEFSKIP:
1710 fl_set_choice (fd_form_paragraph->choice_space_below,
1713 case VSpace::SMALLSKIP:
1714 fl_set_choice (fd_form_paragraph->choice_space_below,
1717 case VSpace::MEDSKIP:
1718 fl_set_choice (fd_form_paragraph->choice_space_below,
1721 case VSpace::BIGSKIP:
1722 fl_set_choice (fd_form_paragraph->choice_space_below,
1726 fl_set_choice (fd_form_paragraph->choice_space_below,
1729 case VSpace::LENGTH:
1730 fl_set_choice (fd_form_paragraph->choice_space_below,
1732 fl_set_input (fd_form_paragraph->input_space_below,
1733 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1736 fl_set_button (fd_form_paragraph->check_space_below,
1737 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1739 fl_set_button(fd_form_paragraph->check_noindent,
1740 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1742 if (current_view->buffer()->isReadonly()) {
1743 DisableParagraphLayout();
1745 EnableParagraphLayout();
1751 void MenuLayoutParagraph()
1753 if (UpdateLayoutParagraph()) {
1754 if (fd_form_paragraph->form_paragraph->visible) {
1755 fl_raise_form(fd_form_paragraph->form_paragraph);
1757 fl_show_form(fd_form_paragraph->form_paragraph,
1758 FL_PLACE_MOUSE, FL_FULLBORDER,
1759 _("Paragraph Environment"));
1766 void DeactivateDocumentButtons ()
1768 fl_deactivate_object (fd_form_document->button_ok);
1769 fl_deactivate_object (fd_form_document->button_apply);
1770 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1771 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1776 void ActivateDocumentButtons ()
1778 fl_activate_object (fd_form_document->button_ok);
1779 fl_activate_object (fd_form_document->button_apply);
1780 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1781 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1786 void DisableDocumentLayout ()
1788 DeactivateDocumentButtons ();
1789 fl_deactivate_object (fd_form_document->group_radio_separation);
1790 fl_deactivate_object (fd_form_document->radio_indent);
1791 fl_deactivate_object (fd_form_document->radio_skip);
1792 fl_deactivate_object (fd_form_document->choice_class);
1793 fl_deactivate_object (fd_form_document->choice_pagestyle);
1794 fl_deactivate_object (fd_form_document->choice_fonts);
1795 fl_deactivate_object (fd_form_document->choice_fontsize);
1796 fl_deactivate_object (fd_form_document->input_float_placement);
1797 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1798 fl_deactivate_object (fd_form_document->choice_inputenc);
1799 fl_deactivate_object (fd_form_document->group_radio_sides);
1800 fl_deactivate_object (fd_form_document->radio_sides_one);
1801 fl_deactivate_object (fd_form_document->radio_sides_two);
1802 fl_deactivate_object (fd_form_document->group_radio_columns);
1803 fl_deactivate_object (fd_form_document->radio_columns_one);
1804 fl_deactivate_object (fd_form_document->radio_columns_two);
1805 fl_deactivate_object (fd_form_document->input_extra);
1806 fl_deactivate_object (fd_form_document->choice_language);
1807 combo_language->deactivate();
1808 fl_deactivate_object (fd_form_document->input_default_skip);
1809 fl_deactivate_object (fd_form_document->choice_default_skip);
1810 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1811 fl_deactivate_object (fd_form_document->slider_tocdepth);
1812 fl_deactivate_object (fd_form_document->choice_spacing);
1813 fl_deactivate_object (fd_form_document->input_spacing);
1814 fl_deactivate_object (fd_form_document->check_use_amsmath);
1819 void EnableDocumentLayout ()
1821 ActivateDocumentButtons ();
1822 fl_activate_object (fd_form_document->group_radio_separation);
1823 fl_activate_object (fd_form_document->radio_indent);
1824 fl_activate_object (fd_form_document->radio_skip);
1825 fl_activate_object (fd_form_document->choice_class);
1826 fl_activate_object (fd_form_document->choice_pagestyle);
1827 fl_activate_object (fd_form_document->choice_fonts);
1828 fl_activate_object (fd_form_document->choice_fontsize);
1829 fl_activate_object (fd_form_document->input_float_placement);
1830 fl_activate_object (fd_form_document->choice_postscript_driver);
1831 fl_activate_object (fd_form_document->choice_inputenc);
1832 fl_activate_object (fd_form_document->group_radio_sides);
1833 fl_activate_object (fd_form_document->radio_sides_one);
1834 fl_activate_object (fd_form_document->radio_sides_two);
1835 fl_activate_object (fd_form_document->group_radio_columns);
1836 fl_activate_object (fd_form_document->radio_columns_one);
1837 fl_activate_object (fd_form_document->radio_columns_two);
1838 fl_activate_object (fd_form_document->input_extra);
1839 fl_activate_object (fd_form_document->choice_language);
1840 combo_language->activate();
1841 fl_activate_object (fd_form_document->input_default_skip);
1842 fl_activate_object (fd_form_document->choice_default_skip);
1843 fl_activate_object (fd_form_document->slider_secnumdepth);
1844 fl_activate_object (fd_form_document->slider_tocdepth);
1845 fl_activate_object (fd_form_document->choice_spacing);
1846 fl_activate_object (fd_form_document->input_spacing);
1847 fl_activate_object (fd_form_document->check_use_amsmath);
1851 bool UpdateLayoutDocument(BufferParams * params)
1853 if (!current_view->getScreen() || !current_view->available()) {
1854 if (fd_form_document->form_document->visible)
1855 fl_hide_form(fd_form_document->form_document);
1860 params = ¤t_view->buffer()->params;
1861 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1863 fl_set_choice_text(fd_form_document->choice_class,
1864 textclasslist.DescOfClass(params->textclass).c_str());
1865 combo_language->select_text(params->language.c_str());
1867 fl_set_choice_text(fd_form_document->choice_fonts,
1868 params->fonts.c_str());
1869 fl_set_choice_text(fd_form_document->choice_inputenc,
1870 params->inputenc.c_str());
1871 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1872 params->graphicsDriver.c_str());
1874 // ale970405+lasgoutt970513
1875 fl_clear_choice(fd_form_document->choice_fontsize);
1876 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1877 fl_addto_choice(fd_form_document->choice_fontsize,
1878 tclass.opt_fontsize().c_str());
1879 fl_set_choice(fd_form_document->choice_fontsize,
1880 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1882 // ale970405+lasgoutt970513
1883 fl_clear_choice(fd_form_document->choice_pagestyle);
1884 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1885 fl_addto_choice(fd_form_document->choice_pagestyle,
1886 tclass.opt_pagestyle().c_str());
1888 fl_set_choice(fd_form_document->choice_pagestyle,
1889 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1891 fl_set_button(fd_form_document->radio_indent, 0);
1892 fl_set_button(fd_form_document->radio_skip, 0);
1895 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1897 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1898 fl_set_button(fd_form_document->radio_indent, 1);
1900 fl_set_button(fd_form_document->radio_skip, 1);
1902 switch (params->getDefSkip().kind()) {
1903 case VSpace::SMALLSKIP:
1904 fl_set_choice (fd_form_document->choice_default_skip, 1);
1906 case VSpace::MEDSKIP:
1907 fl_set_choice (fd_form_document->choice_default_skip, 2);
1909 case VSpace::BIGSKIP:
1910 fl_set_choice (fd_form_document->choice_default_skip, 3);
1912 case VSpace::LENGTH:
1913 fl_set_choice (fd_form_document->choice_default_skip, 4);
1914 fl_set_input (fd_form_document->input_default_skip,
1915 params->getDefSkip().asLyXCommand().c_str());
1918 fl_set_choice (fd_form_document->choice_default_skip, 2);
1922 fl_set_button(fd_form_document->radio_sides_one, 0);
1923 fl_set_button(fd_form_document->radio_sides_two, 0);
1925 if (params->sides == 2)
1926 fl_set_button(fd_form_document->radio_sides_two, 1);
1928 fl_set_button(fd_form_document->radio_sides_one, 1);
1930 fl_set_button(fd_form_document->radio_columns_one, 0);
1931 fl_set_button(fd_form_document->radio_columns_two, 0);
1933 if (params->columns == 2)
1934 fl_set_button(fd_form_document->radio_columns_two, 1);
1936 fl_set_button(fd_form_document->radio_columns_one, 1);
1938 fl_set_input(fd_form_document->input_spacing, "");
1939 switch (params->spacing.getSpace()) {
1940 case Spacing::Single:
1943 fl_set_choice(fd_form_document->choice_spacing, 1);
1946 case Spacing::Onehalf:
1949 fl_set_choice(fd_form_document->choice_spacing, 2);
1952 case Spacing::Double:
1955 fl_set_choice(fd_form_document->choice_spacing, 3);
1958 case Spacing::Other:
1960 fl_set_choice(fd_form_document->choice_spacing, 4);
1962 sprintf(sval, "%g", params->spacing.getValue());
1963 fl_set_input(fd_form_document->input_spacing, sval);
1969 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1970 params->secnumdepth);
1971 fl_set_counter_value(fd_form_document->slider_tocdepth,
1973 if (!params->float_placement.empty()) { // buffer local (Lgb)
1974 fl_set_input(fd_form_document->input_float_placement,
1975 params->float_placement.c_str());
1977 fl_set_input(fd_form_document->input_float_placement, "");
1979 if (!params->options.empty())
1980 fl_set_input(fd_form_document->input_extra,
1981 params->options.c_str());
1983 fl_set_input(fd_form_document->input_extra, "");
1985 if (current_view->buffer()->isSGML()) {
1986 // bullets not used in SGML derived documents
1987 fl_deactivate_object(fd_form_document->button_bullets);
1988 fl_set_object_lcol(fd_form_document->button_bullets,
1991 fl_activate_object(fd_form_document->button_bullets);
1992 fl_set_object_lcol(fd_form_document->button_bullets,
1996 if (current_view->buffer()->isReadonly()) {
1997 DisableDocumentLayout();
1999 EnableDocumentLayout();
2006 void MenuLayoutDocument()
2008 if (UpdateLayoutDocument()) {
2009 if (fd_form_document->form_document->visible) {
2010 fl_raise_form(fd_form_document->form_document);
2012 fl_show_form(fd_form_document->form_document,
2013 FL_PLACE_MOUSE, FL_FULLBORDER,
2014 _("Document Layout"));
2020 bool UpdateLayoutQuotes()
2023 if (!current_view->getScreen()
2024 || !current_view->available()
2025 || current_view->buffer()->isReadonly())
2029 fl_set_choice(fd_form_quotes->choice_quotes_language,
2030 current_view->buffer()->params.quotes_language + 1);
2031 fl_set_button(fd_form_quotes->radio_single, 0);
2032 fl_set_button(fd_form_quotes->radio_double, 0);
2034 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
2035 fl_set_button(fd_form_quotes->radio_single, 1);
2037 fl_set_button(fd_form_quotes->radio_double, 1);
2038 } else if (fd_form_quotes->form_quotes->visible) {
2039 fl_hide_form(fd_form_quotes->form_quotes);
2045 void MenuLayoutQuotes()
2047 if (UpdateLayoutQuotes()) {
2048 if (fd_form_quotes->form_quotes->visible) {
2049 fl_raise_form(fd_form_quotes->form_quotes);
2051 fl_show_form(fd_form_quotes->form_quotes,
2052 FL_PLACE_MOUSE, FL_FULLBORDER,
2059 bool UpdateLayoutPreamble()
2062 if (!current_view->getScreen() || ! current_view->available())
2066 fl_set_input(fd_form_preamble->input_preamble,
2067 current_view->buffer()->params.preamble.c_str());
2069 if (current_view->buffer()->isReadonly()) {
2070 fl_deactivate_object(fd_form_preamble->input_preamble);
2071 fl_deactivate_object(fd_form_preamble->button_ok);
2072 fl_deactivate_object(fd_form_preamble->button_apply);
2073 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
2074 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2077 fl_activate_object(fd_form_preamble->input_preamble);
2078 fl_activate_object(fd_form_preamble->button_ok);
2079 fl_activate_object(fd_form_preamble->button_apply);
2080 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2081 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2083 } else if (fd_form_preamble->form_preamble->visible) {
2084 fl_hide_form(fd_form_preamble->form_preamble);
2089 void MenuLayoutPreamble()
2091 static int ow = -1, oh;
2093 if (UpdateLayoutPreamble()) {
2094 if (fd_form_preamble->form_preamble->visible) {
2095 fl_raise_form(fd_form_preamble->form_preamble);
2097 fl_show_form(fd_form_preamble->form_preamble,
2098 FL_PLACE_MOUSE | FL_FREE_SIZE,
2100 _("LaTeX Preamble"));
2102 ow = fd_form_preamble->form_preamble->w;
2103 oh = fd_form_preamble->form_preamble->h;
2105 fl_set_form_minsize(fd_form_preamble->form_preamble,
2112 void MenuLayoutSave()
2114 if (!current_view->getScreen() || ! current_view->available())
2117 if (AskQuestion(_("Do you want to save the current settings"),
2118 _("for Character, Document, Paper and Quotes"),
2119 _("as default for new documents?")))
2120 current_view->buffer()->saveParamsAsDefaults();
2124 // candidate for move to BufferView
2127 InsetInfo * new_inset = new InsetInfo();
2128 current_view->buffer()->insertInset(new_inset);
2129 new_inset->Edit(0, 0);
2133 // candidate for move to BufferView
2136 if (current_view->available()) {
2137 minibuffer->Set(_("Open/Close..."));
2138 current_view->getScreen()->HideCursor();
2140 current_view->update(-2);
2141 current_view->text->OpenStuff();
2142 current_view->update(0);
2147 // candidate for move to BufferView
2150 if (current_view->available()) {
2151 minibuffer->Set(_("Open/Close..."));
2152 current_view->getScreen()->HideCursor();
2154 current_view->update(-2);
2155 current_view->text->ToggleFootnote();
2156 current_view->update(0);
2161 // candidate for move to BufferView
2164 /* if (current_view->buffer()->the_locking_inset) {
2165 minibuffer->Set(_("Undo not yet supported in math mode"));
2169 if (current_view->available()) {
2170 minibuffer->Set(_("Undo"));
2171 current_view->getScreen()->HideCursor();
2173 current_view->update(-2);
2174 if (!current_view->text->TextUndo())
2175 minibuffer->Set(_("No further undo information"));
2177 current_view->update(-1);
2182 // candidate for move to BufferView
2185 if (current_view->buffer()->the_locking_inset) {
2186 minibuffer->Set(_("Redo not yet supported in math mode"));
2190 if (current_view->available()) {
2191 minibuffer->Set(_("Redo"));
2192 current_view->getScreen()->HideCursor();
2194 current_view->update(-2);
2195 if (!current_view->text->TextRedo())
2196 minibuffer->Set(_("No further redo information"));
2198 current_view->update(-1);
2203 // candidate for move to BufferView
2204 void HyphenationPoint()
2206 if (current_view->available()) {
2207 current_view->getScreen()->HideCursor();
2208 current_view->update(-2);
2209 InsetSpecialChar * new_inset =
2210 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2211 current_view->buffer()->insertInset(new_inset);
2216 // candidate for move to BufferView
2219 if (current_view->available()) {
2220 current_view->getScreen()->HideCursor();
2221 current_view->update(-2);
2222 InsetSpecialChar * new_inset =
2223 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2224 current_view->buffer()->insertInset(new_inset);
2229 // candidate for move to BufferView
2230 void EndOfSentenceDot()
2232 if (current_view->available()) {
2233 current_view->getScreen()->HideCursor();
2234 current_view->update(-2);
2235 InsetSpecialChar * new_inset =
2236 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2237 current_view->buffer()->insertInset(new_inset);
2242 // candidate for move to BufferView
2243 void MenuSeparator()
2245 if (current_view->available()) {
2246 current_view->getScreen()->HideCursor();
2247 current_view->update(-2);
2248 InsetSpecialChar * new_inset =
2249 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2250 current_view->buffer()->insertInset(new_inset);
2255 // candidate for move to BufferView
2258 if (current_view->available()) {
2259 current_view->getScreen()->HideCursor();
2260 current_view->update(-2);
2261 current_view->text->InsertChar(LyXParagraph::META_NEWLINE);
2262 current_view->update(-1);
2267 // candidate for move to BufferView
2268 void ProtectedBlank()
2270 if (current_view->available()) {
2271 current_view->getScreen()->HideCursor();
2272 current_view->update(-2);
2273 current_view->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2274 current_view->update(-1);
2279 // candidate for move to BufferView
2282 if (current_view->available()) {
2283 current_view->getScreen()->HideCursor();
2284 current_view->update(-2);
2285 current_view->text->InsertChar(LyXParagraph::META_HFILL);
2286 current_view->update(-1);
2291 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2292 They also show the current font state. */
2295 void ToggleAndShow(LyXFont const &);
2298 void FontSizeCB(string const & size)
2300 LyXFont font(LyXFont::ALL_IGNORE);
2301 font.setGUISize(size);
2302 ToggleAndShow(font);
2308 LyXFont font(LyXFont::ALL_IGNORE);
2309 font.setEmph(LyXFont::TOGGLE);
2310 ToggleAndShow(font);
2316 LyXFont font(LyXFont::ALL_IGNORE);
2317 font.setNoun(LyXFont::TOGGLE);
2318 ToggleAndShow(font);
2324 LyXFont font(LyXFont::ALL_IGNORE);
2325 font.setSeries(LyXFont::BOLD_SERIES);
2326 ToggleAndShow(font);
2332 LyXFont font(LyXFont::ALL_IGNORE);
2333 font.setUnderbar(LyXFont::TOGGLE);
2334 ToggleAndShow(font);
2340 LyXFont font(LyXFont::ALL_IGNORE);
2341 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2342 ToggleAndShow(font);
2348 LyXFont font(LyXFont::ALL_IGNORE);
2349 font.setFamily(LyXFont::SANS_FAMILY);
2350 ToggleAndShow(font);
2356 LyXFont font(LyXFont::ALL_IGNORE);
2357 font.setFamily(LyXFont::ROMAN_FAMILY);
2358 ToggleAndShow(font);
2364 LyXFont font(LyXFont::ALL_IGNORE);
2365 font.setLatex (LyXFont::TOGGLE);
2366 ToggleAndShow(font);
2372 LyXFont font(LyXFont::ALL_INHERIT);
2373 ToggleAndShow(font);
2377 /* -------> Returns the current font and depth by printing a message. In the
2378 * future perhaps we could try to implement a callback to the button-bar.
2379 * That is, `light' the bold button when the font is currently bold, etc.
2381 string CurrentState()
2384 if (current_view->available()) {
2385 // I think we should only show changes from the default
2387 Buffer * buffer = current_view->buffer();
2388 LyXFont font = current_view->text->real_current_font;
2389 LyXFont defaultfont = textclasslist.TextClass(buffer->
2390 params.textclass).defaultfont();
2391 font.reduce(defaultfont);
2392 state = _("Font: ") + font.stateText();
2394 int depth = current_view->text->GetDepth();
2396 state += string(_(", Depth: ")) + tostr(depth);
2402 // candidate for move to BufferView
2403 /* -------> Does the actual toggle job of the XxxCB() calls above.
2404 * Also shows the current font state.
2407 void ToggleAndShow(LyXFont const & font)
2409 if (current_view->available()) {
2410 current_view->getScreen()->HideCursor();
2411 current_view->update(-2);
2412 current_view->text->ToggleFree(font, toggleall);
2413 current_view->update(1);
2415 // removed since it overrides the ToggleFree Message about the style
2416 // Since Styles are more "High Level" than raw fonts I think the user
2417 // prefers it like this Matthias
2418 // FontStateShowCB( 0, 0 );
2422 // candidate for move to BufferView
2423 extern "C" void MarginCB(FL_OBJECT *, long)
2425 if (current_view->available()) {
2426 minibuffer->Set(_("Inserting margin note..."));
2427 current_view->getScreen()->HideCursor();
2428 current_view->update(-2);
2429 current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2430 current_view->update(1);
2435 extern "C" void FigureCB(FL_OBJECT *, long)
2437 if (fd_form_figure->form_figure->visible) {
2438 fl_raise_form(fd_form_figure->form_figure);
2440 fl_show_form(fd_form_figure->form_figure,
2441 FL_PLACE_MOUSE, FL_FULLBORDER,
2442 _("Insert Figure"));
2447 extern "C" void TableCB(FL_OBJECT *, long)
2449 if (fd_form_table->form_table->visible) {
2450 fl_raise_form(fd_form_table->form_table);
2452 fl_show_form(fd_form_table->form_table,
2453 FL_PLACE_MOUSE, FL_FULLBORDER,
2459 // candidate for move to BufferView
2460 void CopyEnvironmentCB()
2462 if (current_view->available()) {
2463 current_view->text->copyEnvironmentType();
2464 /* clear the selection, even if mark_set */
2465 current_view->getScreen()->ToggleSelection();
2466 current_view->text->ClearSelection();
2467 current_view->update(-2);
2468 minibuffer->Set(_("Paragraph environment type copied"));
2473 // candidate for move to BufferView
2474 void PasteEnvironmentCB()
2476 if (current_view->available()) {
2477 current_view->text->pasteEnvironmentType();
2478 minibuffer->Set(_("Paragraph environment type set"));
2479 current_view->update(1);
2484 // candidate for move to BufferView
2487 if (current_view->available()) {
2488 current_view->text->CopySelection();
2489 /* clear the selection, even if mark_set */
2490 current_view->getScreen()->ToggleSelection();
2491 current_view->text->ClearSelection();
2492 current_view->update(-2);
2493 minibuffer->Set(_("Copy"));
2498 // candidate for move to BufferView
2501 if (current_view->available()) {
2502 current_view->getScreen()->HideCursor();
2503 current_view->update(-2);
2504 current_view->text->CutSelection();
2505 current_view->update(1);
2506 minibuffer->Set(_("Cut"));
2511 // candidate for move to BufferView
2514 if (!current_view->available()) return;
2516 minibuffer->Set(_("Paste"));
2517 current_view->getScreen()->HideCursor();
2518 /* clear the selection */
2519 current_view->getScreen()->ToggleSelection();
2520 current_view->text->ClearSelection();
2521 current_view->update(-2);
2524 current_view->text->PasteSelection();
2525 current_view->update(1);
2527 /* clear the selection */
2528 current_view->getScreen()->ToggleSelection();
2529 current_view->text->ClearSelection();
2530 current_view->update(-2);
2534 // candidate for move to BufferView
2535 extern "C" void MeltCB(FL_OBJECT *, long)
2537 if (!current_view->available()) return;
2539 minibuffer->Set(_("Melt"));
2540 current_view->getScreen()->HideCursor();
2542 current_view->update(-2);
2543 current_view->text->MeltFootnoteEnvironment();
2544 current_view->update(1);
2548 // candidate for move to BufferView
2549 // Change environment depth.
2550 // if decInc == 0, depth change taking mouse button number into account
2551 // if decInc == 1, increment depth
2552 // if decInc == -1, decrement depth
2553 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2557 /* When decInc != 0, fake a mouse button. This allows us to
2558 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2559 /* check out wether ob is defined, too (Matthias) */
2562 else if (!decInc && ob) {
2563 button = fl_get_button_numb(ob);
2566 if (current_view->available()) {
2567 current_view->getScreen()->HideCursor();
2568 current_view->update(-2);
2570 current_view->text->IncDepth();
2572 current_view->text->DecDepth();
2573 current_view->update(1);
2574 minibuffer->Set(_("Changed environment depth"
2575 " (in possible range, maybe not)"));
2580 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2581 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2582 LyXFont UserFreeFont()
2584 LyXFont font(LyXFont::ALL_IGNORE);
2586 int pos = fl_get_choice(fd_form_character->choice_family);
2588 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2589 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2590 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2591 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2592 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2595 pos = fl_get_choice(fd_form_character->choice_series);
2597 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2598 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2599 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2600 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2603 pos = fl_get_choice(fd_form_character->choice_shape);
2605 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2606 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2607 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2608 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2609 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2610 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2613 pos = fl_get_choice(fd_form_character->choice_size);
2615 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2616 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2617 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2618 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2619 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2620 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2621 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2622 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2623 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2624 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2625 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2626 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2627 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2628 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2631 pos = fl_get_choice(fd_form_character->choice_bar);
2633 case 1: font.setEmph(LyXFont::IGNORE);
2634 font.setUnderbar(LyXFont::IGNORE);
2635 font.setNoun(LyXFont::IGNORE);
2636 font.setLatex(LyXFont::IGNORE);
2638 case 2: font.setEmph(LyXFont::TOGGLE); break;
2639 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2640 case 4: font.setNoun(LyXFont::TOGGLE); break;
2641 case 5: font.setLatex(LyXFont::TOGGLE); break;
2642 case 6: font.setEmph(LyXFont::INHERIT);
2643 font.setUnderbar(LyXFont::INHERIT);
2644 font.setNoun(LyXFont::INHERIT);
2645 font.setLatex(LyXFont::INHERIT);
2649 pos = fl_get_choice(fd_form_character->choice_color);
2651 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2652 case 2: font.setColor(LyXFont::NONE); break;
2653 case 3: font.setColor(LyXFont::BLACK); break;
2654 case 4: font.setColor(LyXFont::WHITE); break;
2655 case 5: font.setColor(LyXFont::RED); break;
2656 case 6: font.setColor(LyXFont::GREEN); break;
2657 case 7: font.setColor(LyXFont::BLUE); break;
2658 case 8: font.setColor(LyXFont::CYAN); break;
2659 case 9: font.setColor(LyXFont::MAGENTA); break;
2660 case 10: font.setColor(LyXFont::YELLOW); break;
2661 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2670 ToggleAndShow(UserFreeFont());
2674 /* callbacks for form form_title */
2675 extern "C" void TimerCB(FL_OBJECT *, long)
2677 // only if the form still exists
2678 if (fd_form_title->form_title != 0) {
2679 if (fd_form_title->form_title->visible) {
2680 fl_hide_form(fd_form_title->form_title);
2682 fl_free_form(fd_form_title->form_title);
2683 fd_form_title->form_title = 0;
2688 /* callbacks for form form_paragraph */
2690 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2692 // "Synchronize" the choices and input fields, making it
2693 // impossible to commit senseless data.
2695 FD_form_paragraph const * fp = fd_form_paragraph;
2697 if (obj == fp->choice_space_above) {
2698 if (fl_get_choice (fp->choice_space_above) != 7) {
2699 fl_set_input (fp->input_space_above, "");
2700 ActivateParagraphButtons();
2702 } else if (obj == fp->choice_space_below) {
2703 if (fl_get_choice (fp->choice_space_below) != 7) {
2704 fl_set_input (fp->input_space_below, "");
2705 ActivateParagraphButtons();
2707 } else if (obj == fp->input_space_above) {
2708 string input = fl_get_input (fp->input_space_above);
2710 if (input.empty()) {
2711 fl_set_choice (fp->choice_space_above, 1);
2712 ActivateParagraphButtons();
2714 else if (isValidGlueLength (input)) {
2715 fl_set_choice (fp->choice_space_above, 7);
2716 ActivateParagraphButtons();
2719 fl_set_choice (fp->choice_space_above, 7);
2720 DeactivateParagraphButtons();
2722 } else if (obj == fp->input_space_below) {
2723 string input = fl_get_input (fp->input_space_below);
2725 if (input.empty()) {
2726 fl_set_choice (fp->choice_space_below, 1);
2727 ActivateParagraphButtons();
2729 else if (isValidGlueLength (input)) {
2730 fl_set_choice (fp->choice_space_below, 7);
2731 ActivateParagraphButtons();
2734 fl_set_choice (fp->choice_space_below, 7);
2735 DeactivateParagraphButtons();
2741 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2743 if (!current_view->available())
2746 VSpace space_top, space_bottom;
2748 string labelwidthstring;
2751 // If a vspace kind is "Length" but there's no text in
2752 // the input field, reset the kind to "None".
2753 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2754 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2755 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2757 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2758 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2759 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2762 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2763 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2764 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2765 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2766 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2767 case 1: space_top = VSpace(VSpace::NONE); break;
2768 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2769 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2770 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2771 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2772 case 6: space_top = VSpace(VSpace::VFILL); break;
2773 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2775 if (fl_get_button (fd_form_paragraph->check_space_above))
2776 space_top.setKeep (true);
2777 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2778 case 1: space_bottom = VSpace(VSpace::NONE); break;
2779 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2780 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2781 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2782 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2783 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2784 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2786 if (fl_get_button (fd_form_paragraph->check_space_below))
2787 space_bottom.setKeep (true);
2789 if (fl_get_button(fd_form_paragraph->radio_align_left))
2790 align = LYX_ALIGN_LEFT;
2791 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2792 align = LYX_ALIGN_RIGHT;
2793 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2794 align = LYX_ALIGN_CENTER;
2796 align = LYX_ALIGN_BLOCK;
2798 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2799 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2801 current_view->text->SetParagraph(line_top,
2810 current_view->update(1);
2811 minibuffer->Set(_("Paragraph layout set"));
2815 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2817 fl_hide_form(fd_form_paragraph->form_paragraph);
2821 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2823 ParagraphApplyCB(ob, data);
2824 ParagraphCancelCB(ob, data);
2828 /* callbacks for form form_character */
2830 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2832 // we set toggleall locally here, since it should be true for
2833 // all other uses of ToggleAndShow() (JMarc)
2834 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2835 ToggleAndShow( UserFreeFont());
2840 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2842 fl_hide_form(fd_form_character->form_character);
2846 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2848 CharacterApplyCB(ob, data);
2849 CharacterCloseCB(ob, data);
2853 /* callbacks for form form_document */
2855 void UpdateDocumentButtons(BufferParams const & params)
2857 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2859 if (params.sides == 2)
2860 fl_set_button(fd_form_document->radio_sides_two, 1);
2862 fl_set_button(fd_form_document->radio_sides_one, 1);
2864 if (params.columns == 2)
2865 fl_set_button(fd_form_document->radio_columns_two, 1);
2867 fl_set_button(fd_form_document->radio_columns_one, 1);
2869 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2870 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2871 params.secnumdepth);
2872 fl_set_counter_value(fd_form_document->slider_tocdepth,
2877 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2880 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2881 if (AskQuestion(_("Should I set some parameters to"),
2882 fl_get_choice_text(ob),
2883 _("the defaults of this document class?"))) {
2884 BufferParams params = BufferParams();
2885 params.textclass = fl_get_choice(ob)-1;
2886 params.useClassDefaults();
2887 UpdateLayoutDocument(¶ms);
2888 UpdateDocumentButtons(params);
2891 // unable to load new style
2892 WriteAlert(_("Conversion Errors!"),
2893 _("Unable to switch to new document class."),
2894 _("Reverting to original document class."));
2895 fl_set_choice(fd_form_document->choice_class,
2896 GetCurrentTextClass() + 1);
2902 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2904 // "Synchronize" the choice and the input field, so that it
2905 // is impossible to commit senseless data.
2906 FD_form_document const * fd = fd_form_document;
2908 if (obj == fd->choice_default_skip) {
2909 if (fl_get_choice (fd->choice_default_skip) != 4) {
2910 fl_set_input (fd->input_default_skip, "");
2911 ActivateDocumentButtons();
2913 } else if (obj == fd->input_default_skip) {
2915 char const * input = fl_get_input (fd->input_default_skip);
2918 fl_set_choice (fd->choice_default_skip, 2);
2919 ActivateDocumentButtons();
2920 } else if (isValidGlueLength (input)) {
2921 fl_set_choice (fd->choice_default_skip, 4);
2922 ActivateDocumentButtons();
2924 fl_set_choice (fd->choice_default_skip, 4);
2925 DeactivateDocumentButtons();
2931 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2933 // "Synchronize" the choice and the input field, so that it
2934 // is impossible to commit senseless data.
2935 FD_form_document const * fd = fd_form_document;
2937 if (obj == fd->choice_spacing
2938 && fl_get_choice (fd->choice_spacing) != 4) {
2939 fl_set_input(fd->input_spacing, "");
2940 } else if (obj == fd->input_spacing) {
2942 const char* input = fl_get_input (fd->input_spacing);
2945 fl_set_choice (fd->choice_spacing, 1);
2947 fl_set_choice (fd->choice_spacing, 4);
2953 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2956 BufferParams *params = &(current_view->buffer()->params);
2957 current_view->buffer()->params.language =
2958 combo_language->getline();
2960 // If default skip is a "Length" but there's no text in the
2961 // input field, reset the kind to "Medskip", which is the default.
2962 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2963 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2964 fl_set_choice (fd_form_document->choice_default_skip, 2);
2967 /* this shouldn't be done automatically IMO. For example I write german
2968 * documents with an american keyboard very often. Matthias */
2970 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2971 fl_get_choice(fd_form_document->choice_language)); */
2973 fl_get_choice_text(fd_form_document->choice_fonts);
2975 fl_get_choice_text(fd_form_document->choice_inputenc);
2977 fl_get_choice_text(fd_form_document->choice_fontsize);
2979 fl_get_choice_text(fd_form_document->choice_pagestyle);
2980 params->graphicsDriver =
2981 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2982 params->use_amsmath =
2983 fl_get_button(fd_form_document->check_use_amsmath);
2985 if (!current_view->available())
2988 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2989 if (params->textclass != new_class) {
2990 // try to load new_class
2991 if (textclasslist.Load(new_class)) {
2992 // successfully loaded
2994 minibuffer->Set(_("Converting document to new document class..."));
2995 int ret = current_view->text->
2996 SwitchLayoutsBetweenClasses(current_view->buffer()->
2999 current_view->buffer()->
3005 s = _("One paragraph couldn't be converted");
3008 s += _(" paragraphs couldn't be converted");
3010 WriteAlert(_("Conversion Errors!"), s,
3011 _("into chosen document class"));
3014 params->textclass = new_class;
3016 // problem changing class -- warn user and retain old style
3017 WriteAlert(_("Conversion Errors!"),
3018 _("Unable to switch to new document class."),
3019 _("Reverting to original document class."));
3020 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
3024 char tmpsep = params->paragraph_separation;
3025 if (fl_get_button(fd_form_document->radio_indent))
3026 params->paragraph_separation = BufferParams::PARSEP_INDENT;
3028 params->paragraph_separation = BufferParams::PARSEP_SKIP;
3029 if (tmpsep != params->paragraph_separation)
3032 VSpace tmpdefskip = params->getDefSkip();
3033 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
3034 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
3035 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3036 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
3037 case 4: params->setDefSkip(
3038 VSpace (LyXGlueLength (fl_get_input
3039 (fd_form_document->input_default_skip))));
3041 // DocumentDefskipCB assures that this never happens
3042 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3044 if (!(tmpdefskip == params->getDefSkip()))
3047 if (fl_get_button(fd_form_document->radio_columns_two))
3048 params->columns = 2;
3050 params->columns = 1;
3051 if (fl_get_button(fd_form_document->radio_sides_two))
3052 params->sides = LyXTextClass::TwoSides;
3054 params->sides = LyXTextClass::OneSide;
3056 Spacing tmpSpacing = params->spacing;
3057 switch(fl_get_choice(fd_form_document->choice_spacing)) {
3059 lyxerr.debug() << "Spacing: SINGLE" << endl;
3060 params->spacing.set(Spacing::Single);
3063 lyxerr.debug() << "Spacing: ONEHALF" << endl;
3064 params->spacing.set(Spacing::Onehalf);
3067 lyxerr.debug() << "Spacing: DOUBLE" << endl;
3068 params->spacing.set(Spacing::Double);
3071 lyxerr.debug() << "Spacing: OTHER" << endl;
3072 params->spacing.set(Spacing::Other,
3073 fl_get_input(fd_form_document->input_spacing));
3076 if (tmpSpacing != params->spacing)
3079 signed char tmpchar =
3080 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
3081 if (params->secnumdepth != tmpchar)
3083 params->secnumdepth = tmpchar;
3086 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
3088 params->float_placement =
3089 fl_get_input(fd_form_document->input_float_placement);
3091 // More checking should be done to ensure the string doesn't have
3092 // spaces or illegal placement characters in it. (thornley)
3095 current_view->redoCurrentBuffer();
3097 minibuffer->Set(_("Document layout set"));
3098 current_view->buffer()->markDirty();
3101 fl_get_input(fd_form_document->input_extra);
3106 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3108 fl_hide_form(fd_form_document->form_document);
3112 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3114 DocumentCancelCB(ob, data);
3115 DocumentApplyCB(ob, data);
3119 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3122 // bullet callbacks etc. in bullet_panel.C -- ARRae
3126 // candidate for move to BufferView
3129 if (!current_view->getScreen())
3132 current_view->getScreen()->HideCursor();
3134 current_view->update(-2);
3137 if (!current_view->text->GotoNextNote()) {
3138 if (current_view->text->cursor.pos
3139 || current_view->text->cursor.par !=
3140 current_view->text->FirstParagraph())
3142 tmp = current_view->text->cursor;
3143 current_view->text->cursor.par =
3144 current_view->text->FirstParagraph();
3145 current_view->text->cursor.pos = 0;
3146 if (!current_view->text->GotoNextNote()) {
3147 current_view->text->cursor = tmp;
3148 minibuffer->Set(_("No more notes"));
3152 minibuffer->Set(_("No more notes"));
3156 current_view->update(0);
3157 current_view->text->sel_cursor =
3158 current_view->text->cursor;
3162 // candidate for move to BufferView
3163 void InsertCorrectQuote()
3165 Buffer * cbuffer = current_view->buffer();
3168 if (current_view->text->cursor.pos )
3169 c = current_view->text->cursor.par->GetChar(current_view->text->cursor.pos - 1);
3173 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3177 /* callbacks for form form_quotes */
3179 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3181 if (!current_view->available())
3184 minibuffer->Set(_("Quotes type set"));
3185 //current_view->buffer()->params.quotes_language =
3186 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3187 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3188 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3190 lga = InsetQuotes::EnglishQ;
3193 lga = InsetQuotes::SwedishQ;
3196 lga = InsetQuotes::GermanQ;
3199 lga = InsetQuotes::PolishQ;
3202 lga = InsetQuotes::FrenchQ;
3205 lga = InsetQuotes::DanishQ;
3208 current_view->buffer()->params.quotes_language = lga;
3209 if (fl_get_button(fd_form_quotes->radio_single))
3210 current_view->buffer()->
3211 params.quotes_times = InsetQuotes::SingleQ;
3213 current_view->buffer()->
3214 params.quotes_times = InsetQuotes::DoubleQ;
3218 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3220 fl_hide_form(fd_form_quotes->form_quotes);
3224 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3226 QuotesApplyCB(ob, data);
3227 QuotesCancelCB(ob, data);
3232 /* callbacks for form form_preamble */
3234 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3236 fl_hide_form(fd_form_preamble->form_preamble);
3240 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3242 if (!current_view->available())
3245 current_view->buffer()->params.preamble =
3246 fl_get_input(fd_form_preamble->input_preamble);
3247 current_view->buffer()->markDirty();
3248 minibuffer->Set(_("LaTeX preamble set"));
3252 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3254 PreambleApplyCB(ob, data);
3255 PreambleCancelCB(ob, data);
3259 /* callbacks for form form_table */
3261 extern "C" void TableApplyCB(FL_OBJECT *, long)
3263 if (!current_view->getScreen())
3266 // check for tables in tables
3267 if (current_view->text->cursor.par->table){
3268 WriteAlert(_("Impossible Operation!"),
3269 _("Cannot insert table in table."),
3274 minibuffer->Set(_("Inserting table..."));
3276 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3277 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3280 current_view->getScreen()->HideCursor();
3282 current_view->update(-2);
3284 current_view->text->SetCursorParUndo();
3285 current_view->text->FreezeUndo();
3287 current_view->text->BreakParagraph();
3288 current_view->update(-1);
3290 if (current_view->text->cursor.par->Last()) {
3291 current_view->text->CursorLeft();
3293 current_view->text->BreakParagraph();
3294 current_view->update(-1);
3297 current_view->text->current_font.setLatex(LyXFont::OFF);
3298 //if (!fl_get_button(fd_form_table->check_latex)){
3299 // insert the new wysiwy table
3300 current_view->text->SetLayout(0); // standard layout
3301 if (current_view->text->cursor.par->footnoteflag ==
3302 LyXParagraph::NO_FOOTNOTE) {
3304 ->SetParagraph(0, 0,
3306 VSpace (0.3 * current_view->buffer()->
3307 params.spacing.getValue(),
3309 VSpace (0.3 * current_view->buffer()->
3310 params.spacing.getValue(),
3318 ->SetParagraph(0, 0,
3320 VSpace(VSpace::NONE),
3321 VSpace(VSpace::NONE),
3326 current_view->text->cursor.par->table =
3327 new LyXTable(xsize, ysize);
3329 for (int i = 0; i < xsize * ysize - 1; ++i)
3330 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3331 current_view->text->RedoParagraph();
3333 current_view->text->UnFreezeUndo();
3335 current_view->update(1);
3336 minibuffer->Set(_("Table inserted"));
3340 extern "C" void TableCancelCB(FL_OBJECT *, long)
3342 fl_hide_form(fd_form_table->form_table);
3346 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3348 TableApplyCB(ob, data);
3349 TableCancelCB(ob, data);
3353 /* callbacks for form form_print */
3355 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3357 fl_hide_form(fd_form_print->form_print);
3360 static bool stringOnlyContains (string const & LStr, char const * cset)
3362 char const * cstr = LStr.c_str() ;
3364 return strspn(cstr, cset) == strlen(cstr) ;
3367 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3369 if (!current_view->available())
3371 Buffer * buffer = current_view->buffer();
3372 string path = OnlyPath(buffer->fileName());
3375 if (fl_get_button(fd_form_print->radio_even_pages))
3376 pageflag = lyxrc->print_evenpage_flag + ' ';
3377 else if (fl_get_button(fd_form_print->radio_odd_pages))
3378 pageflag = lyxrc->print_oddpage_flag + ' ';
3380 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3381 // User may give a page (range) list
3382 // User may print multiple (unsorted) copies
3383 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3384 pages = subst(pages, '+',',');
3385 pages = frontStrip(strip(pages)) ;
3386 while (!pages.empty()) { // a page range was given
3388 pages = split (pages, piece, ',') ;
3389 piece = strip(piece) ;
3390 piece = frontStrip(piece) ;
3391 if ( !stringOnlyContains (piece, "0123456789-") ) {
3392 WriteAlert(_("ERROR! Unable to print!"),
3393 _("Check 'range of pages'!"));
3396 if (piece.find('-') == string::npos) { // not found
3397 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3398 } else if (suffixIs(piece, "-") ) { // missing last page
3399 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3400 } else if (prefixIs(piece, "-") ) { // missing first page
3401 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3403 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3407 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3408 if (!copies.empty()) { // a number of copies was given
3409 if ( !stringOnlyContains (copies, "0123456789") ) {
3410 WriteAlert(_("ERROR! Unable to print!"),
3411 _("Check 'number of copies'!"));
3414 if (fl_get_button(fd_form_print->do_unsorted))
3415 pageflag += lyxrc->print_copies_flag;
3417 pageflag += lyxrc->print_collcopies_flag;
3418 pageflag += " " + copies + ' ' ;
3422 if (fl_get_button(fd_form_print->radio_order_reverse))
3423 reverseflag = lyxrc->print_reverse_flag + ' ';
3425 string orientationflag;
3426 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3427 orientationflag = lyxrc->print_landscape_flag + ' ';
3429 string ps_file = fl_get_input(fd_form_print->input_file);
3430 string printer = strip(fl_get_input(fd_form_print->input_printer));
3433 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3434 && ! printer.empty()) // a printer name has been given
3435 printerflag = lyxrc->print_to_printer + printer + ' ';
3438 if (!lyxrc->print_extra_options.empty())
3439 extraflags = lyxrc->print_extra_options + ' ';
3441 string command = lyxrc->print_command + ' '
3442 + printerflag + pageflag + reverseflag
3443 + orientationflag + extraflags;
3445 char real_papersize = buffer->params.papersize;
3446 if (real_papersize == BufferParams::PAPER_DEFAULT)
3447 real_papersize = lyxrc->default_papersize;
3450 switch (real_papersize) {
3451 case BufferParams::PAPER_USLETTER:
3454 case BufferParams::PAPER_A3PAPER:
3457 case BufferParams::PAPER_A4PAPER:
3460 case BufferParams::PAPER_A5PAPER:
3463 case BufferParams::PAPER_B5PAPER:
3466 case BufferParams::PAPER_EXECUTIVEPAPER:
3469 case BufferParams::PAPER_LEGALPAPER:
3472 default: /* If nothing else fits, keep an empty value... */
3476 if (buffer->params.use_geometry
3477 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3478 && !lyxrc->print_paper_dimension_flag.empty()
3479 && !buffer->params.paperwidth.empty()
3480 && !buffer->params.paperheight.empty()) {
3481 // using a custom papersize
3483 command += lyxrc->print_paper_dimension_flag + ' ';
3484 command += buffer->params.paperwidth + ',';
3485 command += buffer->params.paperheight + ' ';
3486 } else if (!lyxrc->print_paper_flag.empty()
3488 && (real_papersize != BufferParams::PAPER_USLETTER ||
3489 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3490 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3492 if (fl_get_button(fd_form_print->radio_file))
3493 command += lyxrc->print_to_file
3494 + QuoteName(MakeAbsPath(ps_file, path));
3495 else if (!lyxrc->print_spool_command.empty())
3496 command += lyxrc->print_to_file
3497 + QuoteName(ps_file);
3499 // push directorypath, if necessary
3500 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3501 path = buffer->tmppath;
3506 if (!lyxrc->print_spool_command.empty() &&
3507 !fl_get_button(fd_form_print->radio_file)) {
3508 string command2 = lyxrc->print_spool_command + ' ';
3509 if (!printer.empty())
3510 command2 += lyxrc->print_spool_printerprefix
3512 // First run dvips and, if succesful, then spool command
3513 if ((result = RunScript(buffer, true, command))) {
3514 result = RunScript(buffer, false, command2, ps_file);
3517 result = RunScript(buffer, false, command);
3520 WriteAlert(_("Error:"),
3521 _("Unable to print"),
3522 _("Check that your parameters are correct"));
3526 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3528 PrintCancelCB(ob, data);
3529 PrintApplyCB(ob, data);
3533 /* callbacks for form form_figure */
3534 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3536 if (!current_view->available())
3539 Buffer * buffer = current_view->buffer();
3540 if(buffer->isReadonly()) // paranoia
3543 minibuffer->Set(_("Inserting figure..."));
3544 if (fl_get_button(fd_form_figure->radio_inline)
3545 || current_view->text->cursor.par->table) {
3546 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3547 buffer->insertInset(new_inset);
3548 minibuffer->Set(_("Figure inserted"));
3549 new_inset->Edit(0, 0);
3553 current_view->getScreen()->HideCursor();
3554 current_view->update(-2);
3557 current_view->text->SetCursorParUndo();
3558 current_view->text->FreezeUndo();
3560 current_view->text->BreakParagraph();
3561 current_view->update(-1);
3563 if (current_view->text->cursor.par->Last()) {
3564 current_view->text->CursorLeft();
3566 current_view->text->BreakParagraph();
3567 current_view->update(-1);
3570 // The standard layout should always be numer 0;
3571 current_view->text->SetLayout(0);
3573 if (current_view->text->cursor.par->footnoteflag ==
3574 LyXParagraph::NO_FOOTNOTE) {
3575 current_view->text->
3578 VSpace (0.3 * buffer->params.spacing.getValue(),
3581 buffer->params.spacing.getValue(),
3583 LYX_ALIGN_CENTER, string(), 0);
3585 current_view->text->SetParagraph(0, 0,
3587 VSpace(VSpace::NONE),
3588 VSpace(VSpace::NONE),
3593 current_view->update(-1);
3595 Inset * new_inset = new InsetFig(100, 100, buffer);
3596 buffer->insertInset(new_inset);
3597 new_inset->Edit(0, 0);
3598 current_view->update(0);
3599 minibuffer->Set(_("Figure inserted"));
3600 current_view->text->UnFreezeUndo();
3604 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3606 fl_hide_form(fd_form_figure->form_figure);
3610 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3612 FigureApplyCB(ob, data);
3613 FigureCancelCB(ob, data);
3617 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3619 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3620 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3621 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3622 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3623 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3624 fontloader.update();
3626 // All buffers will need resize
3627 bufferlist.resize();
3629 minibuffer->Set(_("Screen options set"));
3633 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3635 fl_hide_form(fd_form_screen->form_screen);
3639 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3641 ScreenCancelCB(ob, data);
3642 ScreenApplyCB(ob, data);
3648 if (!current_view->available())
3651 fl_set_button(fd_latex_options->accents,
3652 int(current_view->buffer()->params.allowAccents));
3654 if (fd_latex_options->LaTeXOptions->visible) {
3655 fl_raise_form(fd_latex_options->LaTeXOptions);
3657 fl_show_form(fd_latex_options->LaTeXOptions,
3658 FL_PLACE_MOUSE, FL_FULLBORDER,
3659 _("LaTeX Options"));
3664 // This function runs "configure" and then rereads lyx.defaults to
3665 // reconfigure the automatic settings.
3668 minibuffer->Set(_("Running configure..."));
3670 // Run configure in user lyx directory
3671 Path p(user_lyxdir);
3672 Systemcalls one(Systemcalls::System,
3673 AddName(system_lyxdir, "configure"));
3675 minibuffer->Set(_("Reloading configuration..."));
3676 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
3677 WriteAlert(_("The system has been reconfigured."),
3678 _("You need to restart LyX to make use of any"),
3679 _("updated document class specifications."));
3683 // candidate for move to BufferView
3684 /* these functions are for the spellchecker */
3685 char * NextWord(float & value)
3687 if (!current_view->available()){
3692 char * string = current_view->text->SelectNextWord(value);
3698 // candidate for move to BufferView
3699 void SelectLastWord()
3701 if (!current_view->available())
3704 current_view->getScreen()->HideCursor();
3706 current_view->text->SelectSelectedWord();
3707 current_view->getScreen()->ToggleSelection(false);
3708 current_view->update(0);
3712 // candidate for move to BufferView
3713 void EndOfSpellCheck()
3715 if (!current_view->available())
3718 current_view->getScreen()->HideCursor();
3720 current_view->text->SelectSelectedWord();
3721 current_view->text->ClearSelection();
3722 current_view->update(0);
3726 // candidate for move to BufferView
3727 void ReplaceWord(string const & replacestring)
3729 if (!current_view->getScreen())
3732 current_view->getScreen()->HideCursor();
3733 current_view->update(-2);
3735 /* clear the selection (if there is any) */
3736 current_view->getScreen()->ToggleSelection(false);
3737 current_view->update(-2);
3739 /* clear the selection (if there is any) */
3740 current_view->getScreen()->ToggleSelection(false);
3741 current_view->text->
3742 ReplaceSelectionWithString(replacestring.c_str());
3744 current_view->text->SetSelectionOverString(replacestring.c_str());
3746 // Go back so that replacement string is also spellchecked
3747 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3748 current_view->text->CursorLeftIntern();
3750 current_view->update(1);
3752 // End of spellchecker stuff
3757 // Table of Contents
3767 static TocList * toclist = 0;
3770 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3772 if (!current_view->available())
3775 TocList * tmptoclist = toclist;
3776 int i = fl_get_browser(ob);
3777 for (int a = 1; a < i && tmptoclist->next; ++a) {
3778 tmptoclist = tmptoclist->next;
3785 LyXParagraph * par = current_view->buffer()->paragraph;
3786 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3787 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3788 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3789 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3790 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3791 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3792 par->appendix != tmptoclist->appendix)) {
3793 par = par->LastPhysicalPar()->Next();
3798 current_view->text->SetCursor(par, 0);
3799 current_view->text->sel_cursor =
3800 current_view->text->cursor;
3801 current_view->update(0);
3804 WriteAlert(_("Error"),
3805 _("Couldn't find this label"),
3806 _("in current document."));
3812 extern "C" void TocCancelCB(FL_OBJECT *, long)
3814 fl_hide_form(fd_form_toc->form_toc);
3818 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3820 static LyXParagraph * stapar = 0;
3821 TocList * tmptoclist = 0;
3823 /* deleted the toclist */
3826 tmptoclist = toclist->next;
3828 toclist = tmptoclist;
3832 tmptoclist = toclist;
3835 fl_clear_browser(fd_form_toc->browser_toc);
3836 if (!current_view->available()) {
3837 fl_add_browser_line(fd_form_toc->browser_toc,
3838 _("*** No Document ***"));
3841 fl_hide_object(fd_form_toc->browser_toc);
3842 /* get the table of contents */
3843 LyXParagraph * par = current_view->buffer()->paragraph;
3845 char * line = new char[200];
3851 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3855 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3856 par->GetLayout()).labeltype;
3858 if (labeltype >= LABEL_COUNTER_CHAPTER
3859 && labeltype <= LABEL_COUNTER_CHAPTER +
3860 current_view->buffer()->params.tocdepth) {
3861 /* insert this into the table of contents */
3862 /* first indent a little bit */
3866 textclasslist.TextClass(current_view->buffer()->
3867 params.textclass).maxcounter()) * 4 + 2;
3871 // Then the labestring
3872 if (!par->labelstring.empty()) {
3873 string::size_type i = 0;
3874 while (pos < 199 && i < par->labelstring.length()) {
3875 line[pos] = par->labelstring[i];
3884 /* now the contents */
3885 LyXParagraph::size_type i = 0;
3886 while (pos < 199 && i < par->size()) {
3887 c = par->GetChar(i);
3888 if (isprint(c) || c >= 128) {
3895 fl_add_browser_line(fd_form_toc->browser_toc, line);
3897 /* make a toclist entry */
3899 tmptoclist = new TocList;
3900 toclist = tmptoclist;
3902 tmptoclist->next = new TocList;
3903 tmptoclist = tmptoclist->next;
3906 tmptoclist->next = 0;
3908 for (a = 0; a < 6; ++a) {
3909 tmptoclist->counter[a] = par->GetFirstCounter(a);
3911 tmptoclist->appendix = par->appendix;
3913 par = par->LastPhysicalPar()->Next();
3917 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3918 fl_show_object(fd_form_toc->browser_toc);
3922 /* callbacks for form form_ref */
3923 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3925 if (!current_view->available())
3929 fl_get_browser_line(fd_form_ref->browser_ref,
3930 fl_get_browser(fd_form_ref->browser_ref));
3931 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3937 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3947 if(current_view->buffer()->isSGML())
3948 t += "[" + u + "]" + "{" + s + "}";
3953 new InsetRef(t, current_view->buffer());
3954 current_view->buffer()->insertInset(new_inset);
3958 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3960 if (!current_view->available()) {
3961 fl_clear_browser(fd_form_ref->browser_ref);
3965 FL_OBJECT * brow = fd_form_ref->browser_ref;
3967 // Get the current line, in order to restore it later
3968 char const * const btmp = fl_get_browser_line(brow,
3969 fl_get_browser(brow));
3970 string currentstr = btmp ? btmp : "";
3972 fl_clear_browser(brow);
3974 string refs = current_view->buffer()->getReferenceList('\n');
3977 #if FL_REVISION > 85
3978 fl_addto_browser_chars(brow, refs.c_str());
3979 int total_lines = fl_get_browser_maxline(brow);
3980 for (int i = 1; i <= total_lines ; i++) {
3981 if (fl_get_browser_line(brow, i) == currentstr) {
3986 fl_set_browser_topline(brow, topline);
3988 // Keep the old ugly code for xforms 0.81 compatibility
3993 curr_ref = refs.token('\n', ref_num);
3994 if (curr_ref.empty())
3996 fl_add_browser_line(brow, curr_ref.c_str());
4001 if (!fl_get_browser_maxline(brow)) {
4002 fl_add_browser_line(brow,
4003 _("*** No labels found in document ***"));
4004 fl_deactivate_object(brow);
4006 fl_select_browser_line(brow, topline);
4007 fl_activate_object(brow);
4009 if (current_view->buffer()->isReadonly()) {
4010 // would be better to de/activate insert buttons
4011 // but that's more work... besides this works. ARRae
4012 fl_hide_form(fd_form_ref->form_ref);
4014 if (!current_view->buffer()->isSGML()) {
4015 fl_deactivate_object(fd_form_ref->ref_name);
4016 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
4019 fl_activate_object(fd_form_ref->ref_name);
4020 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
4025 extern "C" void RefHideCB(FL_OBJECT *, long)
4027 fl_hide_form(fd_form_ref->form_ref);
4031 // candidate for move to BufferView
4032 void UpdateInset(Inset * inset, bool mark_dirty)
4037 /* very first check for locking insets*/
4038 if (current_view->buffer()->the_locking_inset == inset){
4039 if (current_view->text->UpdateInset(inset)){
4040 current_view->update();
4042 if (current_view->buffer()->isLyxClean())
4043 minibuffer->setTimer(4);
4044 current_view->buffer()->markDirty();
4046 current_view->updateScrollbar();
4051 /* first check the current buffer */
4052 if (current_view->available()){
4053 current_view->getScreen()->HideCursor();
4054 current_view->update(-3);
4055 if (current_view->text->UpdateInset(inset)){
4057 current_view->update(1);
4059 current_view->update(3);
4064 // check all buffers
4065 bufferlist.updateInset(inset, mark_dirty);
4070 // candidate for move to BufferView
4071 /* these functions return 1 if an error occured,
4073 int LockInset(UpdatableInset * inset)
4075 if (!current_view->buffer()->the_locking_inset && inset){
4076 current_view->buffer()->the_locking_inset = inset;
4083 // candidate for move to BufferView
4084 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
4086 if (current_view->buffer()->the_locking_inset &&
4087 current_view->getScreen()){
4088 y += current_view->text->cursor.y;
4089 current_view->getScreen()->ShowManualCursor(x, y,
4095 // candidate for move to BufferView
4096 void HideLockedInsetCursor(long x, long y, int asc, int desc)
4098 if (current_view->buffer()->the_locking_inset &&
4099 current_view->getScreen()){
4100 y += current_view->text->cursor.y;
4101 current_view->getScreen()->HideManualCursor(x, y,
4107 // candidate for move to BufferView
4108 void FitLockedInsetCursor(long x, long y, int asc, int desc)
4110 if (current_view->buffer()->the_locking_inset &&
4111 current_view->getScreen()){
4112 y += current_view->text->cursor.y;
4113 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
4114 current_view->updateScrollbar();
4119 // candidate for move to BufferView
4120 int UnlockInset(UpdatableInset * inset)
4123 current_view->buffer()->the_locking_inset == inset){
4124 inset->InsetUnlock();
4125 current_view->buffer()->the_locking_inset = 0;
4126 current_view->text->FinishUndo();
4129 return bufferlist.unlockInset(inset);
4133 // candidate for move to BufferView
4134 void LockedInsetStoreUndo(Undo::undo_kind kind)
4136 if (!current_view->buffer()->the_locking_inset)
4137 return; // shouldn't happen
4138 if (kind == Undo::EDIT) // in this case insets would not be stored!
4139 kind = Undo::FINISH;
4140 current_view->text->SetUndo(kind,
4141 current_view->text->cursor.par->
4142 ParFromPos(current_view->text->cursor.pos)->previous,
4143 current_view->text->cursor.par->
4144 ParFromPos(current_view->text->cursor.pos)->next);
4148 void PutInsetIntoInsetUpdateList(Inset * inset)
4151 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4153 tmp->next = InsetUpdateList;
4154 InsetUpdateList = tmp;
4159 void UpdateInsetUpdateList()
4161 InsetUpdateStruct * tmp = InsetUpdateList;
4163 UpdateInset(tmp->inset, false); // "false" because no document change
4167 // delete the update list
4168 while (InsetUpdateList) {
4169 tmp = InsetUpdateList;
4170 InsetUpdateList = InsetUpdateList->next;
4173 InsetUpdateList = 0;
4177 #ifdef WITH_WARNINGS
4180 // I know we shouldn't put anything in here but this seems the fastest
4181 // way to do this (and the cleanest for now). This function just inserts
4182 // a newline in the string and the inserts 'depth'-spaces so that the
4183 // code is indented in the right way!!!
4184 void addNewlineAndDepth(string & file, int const depth)
4187 file.append(depth, ' ');