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 Combox * combo_language;
66 extern BufferList bufferlist;
67 extern void show_symbols_form();
68 extern FD_form_title * fd_form_title;
69 extern FD_form_paragraph * fd_form_paragraph;
70 extern FD_form_character * fd_form_character;
71 extern FD_form_document * fd_form_document;
72 extern FD_form_quotes * fd_form_quotes;
73 extern FD_form_preamble * fd_form_preamble;
74 extern FD_form_table * fd_form_table;
75 extern FD_form_print * fd_form_print;
76 extern FD_form_figure * fd_form_figure;
77 extern FD_form_screen * fd_form_screen;
78 extern FD_form_toc * fd_form_toc;
79 extern FD_form_ref * fd_form_ref;
80 extern FD_LaTeXOptions * fd_latex_options;
81 extern FD_form_bullet * fd_form_bullet;
83 extern BufferView * current_view; // called too many times in this file...
85 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
87 extern bool send_fax(string const & fname, string const & sendcmd);
88 extern void MenuSendto();
90 extern LyXServer * lyxserver;
91 extern FontLoader fontloader;
93 // this should be static, but I need it in buffer.C
94 bool quitting; // flag, that we are quitting the program
95 extern bool finished; // all cleanup done just let it run through now.
97 char ascii_type; /* for selection notify callbacks */
99 bool scrolling = false;
101 char updatetimer = 0;
103 /* whether the work area should get callbacks */
104 bool input_prohibited = false;
106 /* the selection possible is needed, that only motion events are
107 * used, where the bottom press event was on the drawing area too */
108 bool selection_possible = false;
110 // This is used to make the dreaded font toggle problem hopefully go
111 // away. Definitely not the best solution, but I think it sorta works.
112 bool toggleall = true;
114 void InsertCorrectQuote();
118 This is the inset locking stuff needed for mathed --------------------
120 an inset can simple call LockInset in it's edit call and *ONLY* in it's
122 Inset::Edit() can only be called by the main lyx module.
124 Then the inset may modify the menu's and/or iconbars.
126 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
128 During the lock, all button and keyboard events will be modified
129 and send to the inset through the following inset-features. Note that
130 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
131 to contain the code for restoring the menus and things like this.
134 virtual void InsetButtonPress(int x, int y, int button);
135 virtual void InsetButtonRelease(int x, int y, int button);
136 virtual void InsetKeyPress(XKeyEvent *ev);
137 virtual void InsetMotionNotify(int x, int y, int state);
138 virtual void InsetUnlock();
140 If a inset wishes any redraw and/or update it just has to call
142 It's is completly irrelevant, where the inset is. UpdateInset will
143 find it in any paragraph in any buffer.
144 Of course the_locking_inset and the insets in the current paragraph/buffer
145 are checked first, so no performance problem should occur.
147 Hope that's ok for the beginning, Alejandro,
148 sorry that I needed so much time,
153 void UpdateInset(Inset * inset, bool mark_dirty = true);
154 /* these functions return 1 if an error occured,
156 // Now they work only for updatable insets. [Alejandro 080596]
157 int LockInset(UpdatableInset * inset);
158 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
159 void FitLockedInsetCursor(long x, long y, int asc, int desc);
160 int UnlockInset(UpdatableInset * inset);
161 void LockedInsetStoreUndo(Undo::undo_kind kind);
163 /* this is for asyncron updating. UpdateInsetUpdateList will be called
164 automatically from LyX. Just insert the Inset into the Updatelist */
165 void UpdateInsetUpdateList();
166 void PutInsetIntoInsetUpdateList(Inset * inset);
168 InsetUpdateStruct * InsetUpdateList = 0;
172 -----------------------------------------------------------------------
175 /* some function prototypes */
182 void HyphenationPoint();
183 void MenuSeparator();
186 void ProtectedBlank();
188 int RunLinuxDoc(int, string const &);
189 int RunDocBook(int, string const &);
190 void MenuWrite(Buffer * buf);
191 void MenuWriteAs(Buffer * buffer);
192 void MenuReload(Buffer * buf);
193 void MenuLayoutSave();
195 unsigned char GetCurrentTextClass()
196 // Who are we asking?
197 // Shouldn't this question be directed to the buffer?
198 // Indeed it should. Asger.
200 return current_view->buffer()->params.textclass;
204 // How should this actually work? Should it prohibit input in all BufferViews,
205 // or just in the current one? If "just the current one", then it should be
206 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
207 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
208 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
209 // current LyxView that should be prohibited (Lgb) (This applies to
210 // "AllowInput" as well.)
213 input_prohibited = true;
214 if (current_view->getScreen())
215 current_view->getScreen()->HideCursor();
217 static Cursor cursor;
218 static bool cursor_undefined = true;
220 if (cursor_undefined){
221 cursor = XCreateFontCursor(fl_display, XC_watch);
223 cursor_undefined = false;
226 /* set the cursor to the watch for all forms and the canvas */
227 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
229 if (fd_form_paragraph->form_paragraph->visible)
230 XDefineCursor(fl_display,
231 fd_form_paragraph->form_paragraph->window,
233 if (fd_form_character->form_character->visible)
234 XDefineCursor(fl_display,
235 fd_form_character->form_character->window,
239 fl_deactivate_all_forms();
243 // Should find a way to move this into BufferView.C
244 void SetXtermCursor(Window win)
246 static Cursor cursor;
247 static bool cursor_undefined = true;
248 if (cursor_undefined){
249 cursor = XCreateFontCursor(fl_display, XC_xterm);
251 cursor_undefined = false;
253 XDefineCursor(fl_display, win, cursor);
260 input_prohibited = false;
262 /* reset the cursor from the watch for all forms and the canvas */
264 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
265 if (fd_form_paragraph->form_paragraph->visible)
266 XUndefineCursor(fl_display,
267 fd_form_paragraph->form_paragraph->window);
268 if (fd_form_character->form_character->visible)
269 XUndefineCursor(fl_display,
270 fd_form_character->form_character->window);
271 if (current_view->getWorkArea()->belowmouse)
272 SetXtermCursor(current_view->owner()->getForm()->window);
275 fl_activate_all_forms();
279 void FreeUpdateTimer()
281 /* a real free timer would be better but I don't know
282 * how to do this with xforms */
287 void SetUpdateTimer(float time)
289 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
294 // candidate for move to BufferView
297 current_view->getScreen()->ToggleSelection();
298 current_view->text->ClearSelection();
303 // candidate for move to BufferView
304 void SmallUpdate(signed char f)
306 current_view->getScreen()->SmallUpdate();
307 if (current_view->getScreen()->TopCursorVisible()
308 != current_view->getScreen()->first) {
309 current_view->update(f);
313 current_view->fitCursor();
314 current_view->updateScrollbar();
316 if (!current_view->text->selection)
317 current_view->text->sel_cursor =
318 current_view->text->cursor;
320 if (f == 1 || f == -1) {
321 if (current_view->buffer()->isLyxClean()) {
322 current_view->buffer()->markDirty();
323 current_view->owner()->getMiniBuffer()->setTimer(4);
326 current_view->buffer()->markDirty();
340 // should be moved to lyxfunc.C
341 void MenuWrite(Buffer * buf)
344 if (!bufferlist.write(buf)) {
345 string fname = buf->fileName();
346 string s = MakeAbsPath(fname);
347 if (AskQuestion(_("Save failed. Rename and try again?"),
348 MakeDisplayPath(s, 50),
349 _("(If not, document is not saved.)"))) {
353 lastfiles->newFile(buf->fileName());
358 // should be moved to BufferView.C
359 void MenuWriteAs(Buffer * buffer)
361 if (!current_view->text) return;
363 string fname = buffer->fileName();
364 string oldname = fname;
368 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
369 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
371 if (!IsLyXFilename(fname))
374 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
377 OnlyFilename(fname));
381 current_view->owner()->getMiniBuffer()->Set(_("Canceled."));
385 // Make sure the absolute filename ends with appropriate suffix
386 string s = MakeAbsPath(fname);
387 if (!IsLyXFilename(s))
390 // Same name as we have already?
392 if (!AskQuestion(_("Same name as document already has:"),
393 MakeDisplayPath(s, 50),
396 // Falls through to name change and save
398 // No, but do we have another file with this name open?
399 else if (bufferlist.exists(s)) {
400 if (AskQuestion(_("Another document with same name open!"),
401 MakeDisplayPath(s, 50),
402 _("Replace with current document?")))
404 bufferlist.close(bufferlist.getBuffer(s));
406 // Ok, change the name of the buffer, but don't save!
410 current_view->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
412 _("', but not saved..."));
415 } // Check whether the file exists
418 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
419 MakeDisplayPath(s, 50),
424 // Ok, change the name of the buffer
428 // Small bug: If the save fails, we have irreversible changed the name
434 int MenuRunLaTeX(Buffer * buffer)
438 if (buffer->isLinuxDoc())
439 ret = RunLinuxDoc(1, buffer->fileName());
440 else if (buffer->isLiterate())
441 ret = buffer->runLiterate();
442 else if (buffer->isDocBook())
443 ret = RunDocBook(1, buffer->fileName());
445 ret = buffer->runLaTeX();
451 s = _("One error detected");
452 t = _("You should try to fix it.");
455 s += _(" errors detected.");
456 t = _("You should try to fix them.");
458 WriteAlert(_("There were errors during the LaTeX run."), s, t);
464 int MenuBuildProg(Buffer * buffer)
468 if (buffer->isLiterate())
469 ret = buffer->buildProgram();
471 string s = _("Wrong type of document");
472 string t = _("The Build operation is not allowed in this document");
473 WriteAlert(_("There were errors during the Build process."), s, t);
481 s = _("One error detected");
482 t = _("You should try to fix it.");
485 s += _(" errors detected.");
486 t = _("You should try to fix them.");
488 WriteAlert(_("There were errors during the Build process."), s, t);
494 int MenuRunChktex(Buffer * buffer)
498 if (buffer->isSGML()) {
499 WriteAlert(_("Chktex does not work with SGML derived documents."));
502 ret = buffer->runChktex();
508 s = _("No warnings found.");
509 } else if (ret == 1) {
510 s = _("One warning found.");
511 t = _("Use 'Edit->Go to Error' to find it.");
514 s += _(" warnings found.");
515 t = _("Use 'Edit->Go to Error' to find them.");
517 WriteAlert(_("Chktex run successfully"), s, t);
519 WriteAlert(_("Error!"), _("It seems chktex does not work."));
525 int MakeDVIOutput(Buffer * buffer)
527 if (!(current_view->text))
532 string path = OnlyPath(buffer->fileName());
533 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
534 path = buffer->tmppath;
536 if (!buffer->isDviClean()) {
538 ret = MenuRunLaTeX(buffer);
544 /* wait == false means don't wait for termination */
545 /* wait == true means wait for termination */
546 // The bool should be placed last on the argument line. (Lgb)
547 // Returns false if we fail.
548 bool RunScript(Buffer * buffer, bool wait,
549 string const & command,
550 string const & orgname = string(),
551 bool need_shell = true)
555 string name = orgname;
558 if (MakeDVIOutput(buffer) > 0)
560 /* get DVI-Filename */
562 name = ChangeExtension(buffer->getLatexName(),
565 path = OnlyPath(name);
566 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
567 path = buffer->tmppath;
571 cmd = command + ' ' + QuoteName(name);
580 // OS/2 cmd.exe has another use for '&'
582 // This is not NLS safe, but it's OK, I think.
583 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
585 // COMSPEC is set, unless user unsets
586 sh = OnlyFilename(GetEnvPath("COMSPEC"));
591 if (contains(sh, "cmd.exe")
592 || contains(sh, "4os2.exe"))
593 cmd = "start /min/n " + cmd;
598 // It seems that, if wait is false, we never get back
599 // the return code of the command. This means that all
600 // the code I added in PrintApplyCB is currently
603 #warning What should we do here?
605 current_view->owner()->getMiniBuffer()->Set(
606 _("Executing command:"), cmd);
607 result = one.startscript(Systemcalls::System, cmd);
609 current_view->owner()->getMiniBuffer()->Set(
610 _("Executing command:"), cmd);
611 result = one.startscript(wait ? Systemcalls::Wait
612 : Systemcalls::DontWait, cmd);
614 return (result == 0);
618 // Returns false if we fail
619 bool MenuRunDvips(Buffer * buffer, bool wait = false)
621 if (!current_view->text)
627 if (MakeDVIOutput(buffer) > 0) {
631 // Generate postscript file
632 string psname = ChangeExtension (buffer->fileName(),
637 char real_papersize = buffer->params.papersize;
638 if (real_papersize == BufferParams::PAPER_DEFAULT)
639 real_papersize = lyxrc->default_papersize;
641 switch (real_papersize) {
642 case BufferParams::PAPER_USLETTER:
645 case BufferParams::PAPER_A3PAPER:
648 case BufferParams::PAPER_A4PAPER:
651 case BufferParams::PAPER_A5PAPER:
654 case BufferParams::PAPER_B5PAPER:
657 case BufferParams::PAPER_EXECUTIVEPAPER:
660 case BufferParams::PAPER_LEGALPAPER:
663 default: /* If nothing else fits, keep an empty value... */
667 // Make postscript file.
668 string command = "dvips " + lyxrc->print_to_file + ' ';
669 command += QuoteName(psname);
670 if (buffer->params.use_geometry
671 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
672 && !lyxrc->print_paper_dimension_flag.empty()
673 && !buffer->params.paperwidth.empty()
674 && !buffer->params.paperheight.empty()) {
675 // using a custom papersize
677 command += lyxrc->print_paper_dimension_flag + ' ';
678 command += buffer->params.paperwidth + ',';
679 command += buffer->params.paperheight;
680 } else if (!paper.empty()
681 && (real_papersize != BufferParams::PAPER_USLETTER ||
682 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
683 // dvips won't accept -t letter -t landscape. In all other
684 // cases, include the paper size explicitly.
686 command += lyxrc->print_paper_flag + ' ' + paper;
688 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
690 command += lyxrc->print_landscape_flag;
692 // push directorypath, if necessary
693 string path = OnlyPath(buffer->fileName());
694 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
695 path = buffer->tmppath;
698 bool ret = RunScript(buffer, wait, command);
704 // Returns false if we fail
705 bool MenuPreviewPS(Buffer * buffer)
707 if (!current_view->text)
710 // Generate postscript file
711 if (!MenuRunDvips(buffer, true)) {
715 // Start postscript viewer
717 string ps = ChangeExtension (buffer->fileName(),
719 // push directorypath, if necessary
720 string path = OnlyPath(buffer->fileName());
721 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
722 path = buffer->tmppath;
725 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
731 void MenuFax(Buffer * buffer)
733 if (!current_view->text)
736 // Generate postscript file
737 if (!MenuRunDvips(buffer, true)) {
742 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
743 string path = OnlyPath (buffer->fileName());
744 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
745 path = buffer->tmppath;
748 if (!lyxrc->fax_program.empty()) {
749 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
751 Systemcalls one(Systemcalls::System, help2);
753 send_fax(ps, lyxrc->fax_command);
757 // Returns false if we fail
758 bool MenuPreview(Buffer * buffer)
760 if (!current_view->text)
765 char real_papersize = buffer->params.papersize;
766 if (real_papersize == BufferParams::PAPER_DEFAULT)
767 real_papersize = lyxrc->default_papersize;
769 switch (real_papersize) {
770 case BufferParams::PAPER_USLETTER:
773 case BufferParams::PAPER_A3PAPER:
776 case BufferParams::PAPER_A4PAPER:
779 case BufferParams::PAPER_A5PAPER:
782 case BufferParams::PAPER_B5PAPER:
785 case BufferParams::PAPER_EXECUTIVEPAPER:
788 case BufferParams::PAPER_LEGALPAPER:
791 default: /* If nothing else fits, keep the empty value */
796 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
797 // we HAVE to give a size when the page is in
798 // landscape, so use USletter.
799 paper = " -paper usr";
801 paper = " -paper " + paper;
802 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
806 // push directorypath, if necessary
807 string path = OnlyPath(buffer->fileName());
808 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
809 path = buffer->tmppath;
813 string command = lyxrc->view_dvi_command + paper ;
814 bool ret = RunScript(buffer, false, command);
819 void MenuMakeLaTeX(Buffer * buffer)
821 if (!current_view->text)
824 // Get LaTeX-Filename
825 string s = buffer->getLatexName(false);
829 !AskQuestion(_("File already exists:"),
830 MakeDisplayPath(s, 50),
831 _("Do you want to overwrite the file?"))) {
832 current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
836 if (buffer->isDocBook())
837 current_view->owner()->getMiniBuffer()->Set(
838 _("DocBook does not have a latex backend"));
840 if (buffer->isLinuxDoc())
841 RunLinuxDoc(0, buffer->fileName());
843 buffer->makeLaTeXFile(s, string(), true);
844 current_view->owner()->getMiniBuffer()->Set(
845 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
846 buffer->markDviDirty();
851 void MenuMakeLinuxDoc(Buffer * buffer)
853 if (!current_view->text) return;
855 if (!buffer->isLinuxDoc()) {
856 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
860 // Get LinuxDoc-Filename
861 string s = ChangeExtension (buffer->fileName(),
866 !AskQuestion(_("File already exists:"),
867 MakeDisplayPath(s, 50),
868 _("Do you want to overwrite the file?"))) {
869 current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
873 current_view->owner()->getMiniBuffer()->Set(
874 _("Building LinuxDoc SGML file `"), MakeDisplayPath(s),"'...");
876 buffer->makeLinuxDocFile(s, 65);
878 current_view->owner()->getMiniBuffer()->Set(
879 _("LinuxDoc SGML file save as"), MakeDisplayPath(s));
883 void MenuMakeDocBook(Buffer * buffer)
885 if (!current_view->text) return;
887 if (!buffer->isDocBook()) {
888 WriteAlert(_("Error!"),
889 _("Document class must be docbook."));
893 // Get DocBook-Filename
894 string s = ChangeExtension (buffer->fileName(),
899 !AskQuestion(_("File already exists:"),
900 MakeDisplayPath(s, 50),
901 _("Do you want to overwrite the file?"))) {
902 current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
906 current_view->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
907 MakeDisplayPath(s), "'...");
909 buffer->makeDocBookFile(s, 65);
911 current_view->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
916 void MenuMakeAscii(Buffer * buffer)
918 if (!current_view->text) return;
920 /* get LaTeX-Filename */
921 string s = ChangeExtension (buffer->fileName(),
926 !AskQuestion(_("File already exists:"),
927 MakeDisplayPath(s, 50),
928 _("Do you want to overwrite the file?"))) {
929 current_view->owner()->getMiniBuffer()->Set(_("Canceled"));
933 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
935 current_view->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
939 void MenuPrint(Buffer * buffer)
941 if (!current_view->text)
944 string input_file = ChangeExtension(buffer->fileName(),
945 lyxrc->print_file_extension,
947 fl_set_input(fd_form_print->input_file, input_file.c_str());
949 if (fd_form_print->form_print->visible) {
950 fl_raise_form(fd_form_print->form_print);
953 fl_show_form(fd_form_print->form_print,
954 FL_PLACE_MOUSE, FL_FULLBORDER,
959 void MenuMakeHTML(Buffer * buffer)
961 // First, create LaTeX file
962 MenuMakeLaTeX(buffer);
964 // And now, run the converter
965 string file = buffer->fileName();
966 Path path(OnlyPath(file));
967 // the tex file name has to be correct for
968 // latex, but the html file name can be
970 string result = ChangeExtension(file, ".html", false);
971 string infile = buffer->getLatexName(false);
972 string tmp = lyxrc->html_command;
973 tmp = subst(tmp, "$$FName", infile);
974 tmp = subst(tmp, "$$OutName", result);
976 int res = one.startscript(Systemcalls::System, tmp);
978 current_view->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
979 + MakeDisplayPath(result) +'\'');
981 current_view->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
982 + MakeDisplayPath(infile)
988 void MenuExport(Buffer * buffer, string const & extyp)
991 if (extyp == "latex") {
992 // make sure that this buffer is not linuxdoc
993 MenuMakeLaTeX(buffer);
996 else if (extyp == "linuxdoc") {
997 // make sure that this buffer is not latex
998 MenuMakeLinuxDoc(buffer);
1001 else if (extyp == "docbook") {
1002 // make sure that this buffer is not latex or linuxdoc
1003 MenuMakeDocBook(buffer);
1006 else if (extyp == "dvi") {
1007 // Run LaTeX as "Update dvi..." Bernhard.
1008 // We want the dvi in the current directory. This
1009 // is achieved by temporarily disabling use of
1010 // temp directory. As a side-effect, we get
1011 // *.log and *.aux files also. (Asger)
1012 bool flag = lyxrc->use_tempdir;
1013 lyxrc->use_tempdir = false;
1014 MenuRunLaTeX(buffer);
1015 lyxrc->use_tempdir = flag;
1018 else if (extyp == "postscript") {
1019 // Start Print-dialog. Not as good as dvi... Bernhard.
1021 // Since the MenuPrint is a pop-up, we can't use
1022 // the same trick as above. (Asger)
1023 // MISSING: Move of ps-file :-(
1026 else if (extyp == "ascii") {
1027 MenuMakeAscii(buffer);
1029 else if (extyp == "custom") {
1033 else if (extyp == "html") {
1034 MenuMakeHTML(buffer);
1037 current_view->owner()->getMiniBuffer()->Set(_("Unknown export type: ")+ extyp);
1044 lyxerr.debug() << "Running QuitLyX." << endl;
1046 if (!bufferlist.QwriteAll())
1049 lastfiles->writeFile(lyxrc->lastfiles);
1051 // Set a flag that we do quitting from the program,
1052 // so no refreshes are necessary.
1055 // close buffers first
1056 bufferlist.closeAll();
1058 // do any other cleanup procedures now
1059 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1061 DestroyLyXTmpDir(system_tempdir);
1069 // should probably be moved into BufferList (Lgb)
1070 // Perfect target for a thread...
1072 if (!current_view->getScreen() || !current_view->available())
1075 if (current_view->buffer()->isBakClean()
1076 || current_view->buffer()->isReadonly()) {
1077 // We don't save now, but we'll try again later
1078 current_view->owner()->resetAutosaveTimer();
1082 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1084 // create autosave filename
1085 string fname = OnlyPath(current_view->buffer()->fileName());
1087 fname += OnlyFilename(current_view->buffer()->fileName());
1090 // tmp_ret will be located (usually) in /tmp
1091 // will that be a problem?
1092 string tmp_ret = tmpnam(0);
1094 pid_t pid = fork(); // If you want to debug the autosave
1095 // you should set pid to -1, and comment out the
1097 if (pid == 0 || pid == -1) {
1098 // pid = -1 signifies that lyx was unable
1099 // to fork. But we will do the save
1101 bool failed = false;
1102 if (!tmp_ret.empty()) {
1103 current_view->buffer()->writeFile(tmp_ret, 1);
1104 // assume successful write of tmp_ret
1105 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1107 // most likely couldn't move between filesystems
1108 // unless write of tmp_ret failed
1109 // so remove tmp file (if it exists)
1110 remove(tmp_ret.c_str());
1117 // failed to write/rename tmp_ret so try writing direct
1118 if (!current_view->buffer()->writeFile(fname, 1)) {
1119 // It is dangerous to do this in the child,
1120 // but safe in the parent, so...
1122 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1125 if (pid == 0) { // we are the child so...
1130 current_view->buffer()->markBakClean();
1131 current_view->owner()->resetAutosaveTimer();
1136 // (c) CHT Software Service GmbH
1139 // create new file with template
1142 Buffer * NewLyxFile(string const & filename)
1144 // Split argument by :
1146 string tmpname = split(filename, name, ':');
1147 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1148 if (name.length() == 1
1149 && isalpha(static_cast<unsigned char>(name[0]))
1150 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1152 name += token(tmpname, ':', 0);
1153 tmpname = split(tmpname, ':');
1156 lyxerr.debug() << "Arg is " << filename
1157 << "\nName is " << name
1158 << "\nTemplate is " << tmpname << endl;
1160 // find a free buffer
1161 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1163 lastfiles->newFile(tmpbuf->fileName());
1168 // Insert ascii file (if filename is empty, prompt for one)
1169 void InsertAsciiFile(string const & f, bool asParagraph)
1174 if (!current_view->getScreen()) return;
1176 if (fname.empty()) {
1178 fname = fileDlg.Select(_("File to Insert"),
1179 current_view->owner()->buffer()->filepath,
1182 if (fname.empty()) return;
1187 if (!fi.readable()) {
1188 WriteFSAlert(_("Error! Specified file is unreadable: "),
1189 MakeDisplayPath(fname, 50));
1193 FilePtr myfile(fname, FilePtr::read);
1195 WriteFSAlert(_("Error! Cannot open specified file: "),
1196 MakeDisplayPath(fname, 50));
1199 LyXParagraph * tmppar = new LyXParagraph;
1200 tmppar->readSimpleWholeFile(myfile);
1202 // set the end of the string
1203 #ifdef WITH_WARNINGS
1204 #warning why do we do this?
1206 // I don't think this is needed. Actually it might be plain wrong.
1207 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1209 // insert the string
1210 current_view->getScreen()->HideCursor();
1212 // clear the selection
1215 current_view->text->InsertStringA(tmppar->text);
1217 current_view->text->InsertStringB(tmppar->text);
1219 current_view->update(1);
1223 void MenuShowTableOfContents()
1225 static int ow = -1, oh;
1228 if (fd_form_toc->form_toc->visible) {
1229 fl_raise_form(fd_form_toc->form_toc);
1231 fl_show_form(fd_form_toc->form_toc,
1232 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1233 _("Table Of Contents"));
1235 ow = fd_form_toc->form_toc->w;
1236 oh = fd_form_toc->form_toc->h;
1238 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1243 void MenuInsertLabel(char const * arg)
1247 //string label = fl_show_input(_("Enter new label to insert:"), "");
1249 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1250 if (!label.empty()) {
1251 InsetLabel * new_inset = new InsetLabel;
1252 new_inset->setContents(label);
1253 current_view->buffer()->insertInset(new_inset);
1259 void MenuInsertRef()
1261 static int ow = -1, oh;
1264 if (fd_form_ref->form_ref->visible) {
1265 fl_raise_form(fd_form_ref->form_ref);
1267 fl_show_form(fd_form_ref->form_ref,
1268 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1269 _("Insert Reference"));
1271 ow = fd_form_ref->form_ref->w;
1272 oh = fd_form_ref->form_ref->h;
1274 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1279 void MenuPasteSelection(char at)
1281 if (!current_view->getScreen())
1286 Atom data_prop = XInternAtom(fl_display,
1289 if (data_prop == None)
1291 XConvertSelection(fl_display,
1292 XA_PRIMARY, XA_STRING, data_prop,
1293 current_view->owner()->getForm()->window, 0);
1298 // candidate for move to BufferView
1299 extern "C" void FootCB(FL_OBJECT *, long)
1301 if (!current_view->available())
1304 current_view->owner()->getMiniBuffer()->Set(_("Inserting Footnote..."));
1305 current_view->getScreen()->HideCursor();
1306 current_view->update(-2);
1307 current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1308 current_view->update(1);
1312 // candidate for move to LyXView
1313 void LayoutsCB(int sel, void *)
1315 string tmp = tostr(sel);
1316 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1322 * SGML Linuxdoc support:
1323 * (flag == -1) import SGML file
1324 * (flag == 0) make TeX output
1325 * (flag == 1) make dvi output
1327 int RunLinuxDoc(int flag, string const & filename)
1336 /* generate a path-less extension name */
1337 name = ChangeExtension (filename, ".sgml", true);
1338 path = OnlyPath (filename);
1339 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1340 path = current_view->buffer()->tmppath;
1345 if (!current_view->available())
1347 current_view->buffer()->makeLinuxDocFile(name, 0);
1348 #ifdef WITH_WARNINGS
1349 #warning remove this once we have a proper geometry class
1351 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1353 case BufferParams::PAPER_A4PAPER:
1354 add_flags = "-p a4";
1356 case BufferParams::PAPER_USLETTER:
1357 add_flags = "-p letter";
1359 default: /* nothing to be done yet ;-) */ break;
1367 case -1: /* Import file */
1368 current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"),
1369 MakeDisplayPath(filename), "'...");
1370 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1372 if (one.startscript(Systemcalls::System, s2))
1375 case 0: /* TeX output asked */
1376 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1377 s2 = "sgml2latex " + add_flags + " -o tex "
1378 + lyxrc->sgml_extra_options + ' ' + name;
1379 if (one.startscript(Systemcalls::System, s2))
1382 case 1: /* dvi output asked */
1383 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1384 s2 = "sgml2latex " + add_flags + " -o dvi "
1385 + lyxrc->sgml_extra_options + ' ' + name;
1386 if (one.startscript(Systemcalls::System, s2)) {
1389 current_view->buffer()->markDviClean();
1391 default: /* unknown output */
1397 current_view->buffer()->redraw();
1403 * SGML DocBook support:
1404 * (flag == 1) make dvi output
1406 int RunDocBook(int flag, string const & filename)
1408 /* generate a path-less extension name */
1409 string name = ChangeExtension (filename, ".sgml", true);
1410 string path = OnlyPath (filename);
1411 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1412 path = current_view->buffer()->tmppath;
1416 if (!current_view->available())
1419 current_view->buffer()->makeDocBookFile(name, 0);
1421 // Shall this code go or should it stay? (Lgb)
1422 // string add_flags;
1423 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1425 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1426 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1427 // default: /* nothing to be done yet ;-) */ break;
1434 case 1: /* dvi output asked */
1436 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1437 string s2 = "sgmltools --backend dvi " + name;
1438 if (one.startscript(Systemcalls::System, s2)) {
1441 current_view->buffer()->markDviClean();
1444 default: /* unknown output */
1450 current_view->buffer()->redraw();
1455 // candidate for move to BufferView
1456 void AllFloats(char flag, char figmar)
1458 if (!current_view->available())
1461 LyXCursor cursor = current_view->text->cursor;
1463 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1465 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1466 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1468 && cursor.par->footnotekind != LyXParagraph::FIG
1469 && cursor.par->footnotekind != LyXParagraph::TAB
1470 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1471 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1472 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1477 LyXCursor tmpcursor = cursor;
1478 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1479 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1481 LyXParagraph *par = current_view->buffer()->paragraph;
1484 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1486 && par->footnotekind != LyXParagraph::FOOTNOTE
1487 && par->footnotekind != LyXParagraph::MARGIN)
1489 && par->footnotekind != LyXParagraph::FIG
1490 && par->footnotekind != LyXParagraph::TAB
1491 && par->footnotekind != LyXParagraph::WIDE_FIG
1492 && par->footnotekind != LyXParagraph::WIDE_TAB
1493 && par->footnotekind != LyXParagraph::ALGORITHM
1498 && par->previous->footnoteflag !=
1499 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1501 ->SetCursorIntern(par
1504 current_view->text->OpenFootnote();
1509 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1513 par->footnotekind != LyXParagraph::FOOTNOTE
1515 par->footnotekind != LyXParagraph::MARGIN
1520 par->footnotekind != LyXParagraph::FIG
1522 par->footnotekind != LyXParagraph::TAB
1524 par->footnotekind != LyXParagraph::WIDE_FIG
1526 par->footnotekind != LyXParagraph::WIDE_TAB
1528 par->footnotekind != LyXParagraph::ALGORITHM
1532 current_view->text->SetCursorIntern(par, 0);
1533 current_view->text->CloseFootnote();
1539 current_view->text->SetCursorIntern(cursor.par, cursor.pos);
1540 current_view->redraw();
1541 current_view->fitCursor();
1542 current_view->updateScrollbar();
1546 void MenuLayoutCharacter()
1548 static int ow = -1, oh;
1550 if (fd_form_character->form_character->visible) {
1551 fl_raise_form(fd_form_character->form_character);
1553 fl_show_form(fd_form_character->form_character,
1554 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1555 _("Character Style"));
1557 ow = fd_form_character->form_character->w;
1558 oh = fd_form_character->form_character->h;
1560 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1565 inline void DeactivateParagraphButtons ()
1567 fl_deactivate_object (fd_form_paragraph->button_ok);
1568 fl_deactivate_object (fd_form_paragraph->button_apply);
1569 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1570 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1574 inline void ActivateParagraphButtons ()
1576 fl_activate_object (fd_form_paragraph->button_ok);
1577 fl_activate_object (fd_form_paragraph->button_apply);
1578 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1579 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1583 inline void DisableParagraphLayout ()
1585 DeactivateParagraphButtons();
1586 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1587 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1588 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1589 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1590 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1591 fl_deactivate_object (fd_form_paragraph->check_noindent);
1592 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1593 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1594 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1595 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1596 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1597 fl_deactivate_object (fd_form_paragraph->input_space_above);
1598 fl_deactivate_object (fd_form_paragraph->input_space_below);
1599 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1600 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1601 fl_deactivate_object (fd_form_paragraph->check_space_above);
1602 fl_deactivate_object (fd_form_paragraph->check_space_below);
1606 inline void EnableParagraphLayout ()
1608 ActivateParagraphButtons();
1609 fl_activate_object (fd_form_paragraph->input_labelwidth);
1610 fl_activate_object (fd_form_paragraph->check_lines_top);
1611 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1612 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1613 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1614 fl_activate_object (fd_form_paragraph->check_noindent);
1615 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1616 fl_activate_object (fd_form_paragraph->radio_align_right);
1617 fl_activate_object (fd_form_paragraph->radio_align_left);
1618 fl_activate_object (fd_form_paragraph->radio_align_block);
1619 fl_activate_object (fd_form_paragraph->radio_align_center);
1620 fl_activate_object (fd_form_paragraph->input_space_above);
1621 fl_activate_object (fd_form_paragraph->input_space_below);
1622 fl_activate_object (fd_form_paragraph->choice_space_above);
1623 fl_activate_object (fd_form_paragraph->choice_space_below);
1624 fl_activate_object (fd_form_paragraph->check_space_above);
1625 fl_activate_object (fd_form_paragraph->check_space_below);
1629 bool UpdateLayoutParagraph()
1631 if (!current_view->getScreen() || !current_view->available()) {
1632 if (fd_form_paragraph->form_paragraph->visible)
1633 fl_hide_form(fd_form_paragraph->form_paragraph);
1637 Buffer * buf = current_view->buffer();
1639 fl_set_input(fd_form_paragraph->input_labelwidth,
1640 current_view->text->cursor.par->GetLabelWidthString().c_str());
1641 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1642 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1643 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1644 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1646 int align = current_view->text->cursor.par->GetAlign();
1647 if (align == LYX_ALIGN_LAYOUT)
1648 align = textclasslist.Style(buf->params.textclass,
1649 current_view->text->cursor.par->GetLayout()).align;
1652 case LYX_ALIGN_RIGHT:
1653 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1655 case LYX_ALIGN_LEFT:
1656 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1658 case LYX_ALIGN_CENTER:
1659 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1662 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1666 fl_set_button(fd_form_paragraph->check_lines_top,
1667 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1668 fl_set_button(fd_form_paragraph->check_lines_bottom,
1669 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1670 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1671 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1672 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1673 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1674 fl_set_button(fd_form_paragraph->check_noindent,
1675 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1676 fl_set_input (fd_form_paragraph->input_space_above, "");
1678 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1680 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1682 case VSpace::DEFSKIP:
1683 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1685 case VSpace::SMALLSKIP:
1686 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1688 case VSpace::MEDSKIP:
1689 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1691 case VSpace::BIGSKIP:
1692 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1695 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1697 case VSpace::LENGTH:
1698 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1699 fl_set_input (fd_form_paragraph->input_space_above,
1700 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1703 fl_set_button (fd_form_paragraph->check_space_above,
1704 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1705 fl_set_input (fd_form_paragraph->input_space_below, "");
1706 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1708 fl_set_choice (fd_form_paragraph->choice_space_below,
1711 case VSpace::DEFSKIP:
1712 fl_set_choice (fd_form_paragraph->choice_space_below,
1715 case VSpace::SMALLSKIP:
1716 fl_set_choice (fd_form_paragraph->choice_space_below,
1719 case VSpace::MEDSKIP:
1720 fl_set_choice (fd_form_paragraph->choice_space_below,
1723 case VSpace::BIGSKIP:
1724 fl_set_choice (fd_form_paragraph->choice_space_below,
1728 fl_set_choice (fd_form_paragraph->choice_space_below,
1731 case VSpace::LENGTH:
1732 fl_set_choice (fd_form_paragraph->choice_space_below,
1734 fl_set_input (fd_form_paragraph->input_space_below,
1735 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1738 fl_set_button (fd_form_paragraph->check_space_below,
1739 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1741 fl_set_button(fd_form_paragraph->check_noindent,
1742 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1744 if (current_view->buffer()->isReadonly()) {
1745 DisableParagraphLayout();
1747 EnableParagraphLayout();
1753 void MenuLayoutParagraph()
1755 if (UpdateLayoutParagraph()) {
1756 if (fd_form_paragraph->form_paragraph->visible) {
1757 fl_raise_form(fd_form_paragraph->form_paragraph);
1759 fl_show_form(fd_form_paragraph->form_paragraph,
1760 FL_PLACE_MOUSE, FL_FULLBORDER,
1761 _("Paragraph Environment"));
1768 void DeactivateDocumentButtons ()
1770 fl_deactivate_object (fd_form_document->button_ok);
1771 fl_deactivate_object (fd_form_document->button_apply);
1772 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1773 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1778 void ActivateDocumentButtons ()
1780 fl_activate_object (fd_form_document->button_ok);
1781 fl_activate_object (fd_form_document->button_apply);
1782 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1783 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1788 void DisableDocumentLayout ()
1790 DeactivateDocumentButtons ();
1791 fl_deactivate_object (fd_form_document->group_radio_separation);
1792 fl_deactivate_object (fd_form_document->radio_indent);
1793 fl_deactivate_object (fd_form_document->radio_skip);
1794 fl_deactivate_object (fd_form_document->choice_class);
1795 fl_deactivate_object (fd_form_document->choice_pagestyle);
1796 fl_deactivate_object (fd_form_document->choice_fonts);
1797 fl_deactivate_object (fd_form_document->choice_fontsize);
1798 fl_deactivate_object (fd_form_document->input_float_placement);
1799 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1800 fl_deactivate_object (fd_form_document->choice_inputenc);
1801 fl_deactivate_object (fd_form_document->group_radio_sides);
1802 fl_deactivate_object (fd_form_document->radio_sides_one);
1803 fl_deactivate_object (fd_form_document->radio_sides_two);
1804 fl_deactivate_object (fd_form_document->group_radio_columns);
1805 fl_deactivate_object (fd_form_document->radio_columns_one);
1806 fl_deactivate_object (fd_form_document->radio_columns_two);
1807 fl_deactivate_object (fd_form_document->input_extra);
1808 fl_deactivate_object (fd_form_document->choice_language);
1809 combo_language->deactivate();
1810 fl_deactivate_object (fd_form_document->input_default_skip);
1811 fl_deactivate_object (fd_form_document->choice_default_skip);
1812 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1813 fl_deactivate_object (fd_form_document->slider_tocdepth);
1814 fl_deactivate_object (fd_form_document->choice_spacing);
1815 fl_deactivate_object (fd_form_document->input_spacing);
1816 fl_deactivate_object (fd_form_document->check_use_amsmath);
1821 void EnableDocumentLayout ()
1823 ActivateDocumentButtons ();
1824 fl_activate_object (fd_form_document->group_radio_separation);
1825 fl_activate_object (fd_form_document->radio_indent);
1826 fl_activate_object (fd_form_document->radio_skip);
1827 fl_activate_object (fd_form_document->choice_class);
1828 fl_activate_object (fd_form_document->choice_pagestyle);
1829 fl_activate_object (fd_form_document->choice_fonts);
1830 fl_activate_object (fd_form_document->choice_fontsize);
1831 fl_activate_object (fd_form_document->input_float_placement);
1832 fl_activate_object (fd_form_document->choice_postscript_driver);
1833 fl_activate_object (fd_form_document->choice_inputenc);
1834 fl_activate_object (fd_form_document->group_radio_sides);
1835 fl_activate_object (fd_form_document->radio_sides_one);
1836 fl_activate_object (fd_form_document->radio_sides_two);
1837 fl_activate_object (fd_form_document->group_radio_columns);
1838 fl_activate_object (fd_form_document->radio_columns_one);
1839 fl_activate_object (fd_form_document->radio_columns_two);
1840 fl_activate_object (fd_form_document->input_extra);
1841 fl_activate_object (fd_form_document->choice_language);
1842 combo_language->activate();
1843 fl_activate_object (fd_form_document->input_default_skip);
1844 fl_activate_object (fd_form_document->choice_default_skip);
1845 fl_activate_object (fd_form_document->slider_secnumdepth);
1846 fl_activate_object (fd_form_document->slider_tocdepth);
1847 fl_activate_object (fd_form_document->choice_spacing);
1848 fl_activate_object (fd_form_document->input_spacing);
1849 fl_activate_object (fd_form_document->check_use_amsmath);
1853 bool UpdateLayoutDocument(BufferParams * params)
1855 if (!current_view->getScreen() || !current_view->available()) {
1856 if (fd_form_document->form_document->visible)
1857 fl_hide_form(fd_form_document->form_document);
1862 params = ¤t_view->buffer()->params;
1863 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1865 fl_set_choice_text(fd_form_document->choice_class,
1866 textclasslist.DescOfClass(params->textclass).c_str());
1867 combo_language->select_text(params->language.c_str());
1869 fl_set_choice_text(fd_form_document->choice_fonts,
1870 params->fonts.c_str());
1871 fl_set_choice_text(fd_form_document->choice_inputenc,
1872 params->inputenc.c_str());
1873 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1874 params->graphicsDriver.c_str());
1876 // ale970405+lasgoutt970513
1877 fl_clear_choice(fd_form_document->choice_fontsize);
1878 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1879 fl_addto_choice(fd_form_document->choice_fontsize,
1880 tclass.opt_fontsize().c_str());
1881 fl_set_choice(fd_form_document->choice_fontsize,
1882 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1884 // ale970405+lasgoutt970513
1885 fl_clear_choice(fd_form_document->choice_pagestyle);
1886 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1887 fl_addto_choice(fd_form_document->choice_pagestyle,
1888 tclass.opt_pagestyle().c_str());
1890 fl_set_choice(fd_form_document->choice_pagestyle,
1891 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1893 fl_set_button(fd_form_document->radio_indent, 0);
1894 fl_set_button(fd_form_document->radio_skip, 0);
1897 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1899 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1900 fl_set_button(fd_form_document->radio_indent, 1);
1902 fl_set_button(fd_form_document->radio_skip, 1);
1904 switch (params->getDefSkip().kind()) {
1905 case VSpace::SMALLSKIP:
1906 fl_set_choice (fd_form_document->choice_default_skip, 1);
1908 case VSpace::MEDSKIP:
1909 fl_set_choice (fd_form_document->choice_default_skip, 2);
1911 case VSpace::BIGSKIP:
1912 fl_set_choice (fd_form_document->choice_default_skip, 3);
1914 case VSpace::LENGTH:
1915 fl_set_choice (fd_form_document->choice_default_skip, 4);
1916 fl_set_input (fd_form_document->input_default_skip,
1917 params->getDefSkip().asLyXCommand().c_str());
1920 fl_set_choice (fd_form_document->choice_default_skip, 2);
1924 fl_set_button(fd_form_document->radio_sides_one, 0);
1925 fl_set_button(fd_form_document->radio_sides_two, 0);
1927 if (params->sides == 2)
1928 fl_set_button(fd_form_document->radio_sides_two, 1);
1930 fl_set_button(fd_form_document->radio_sides_one, 1);
1932 fl_set_button(fd_form_document->radio_columns_one, 0);
1933 fl_set_button(fd_form_document->radio_columns_two, 0);
1935 if (params->columns == 2)
1936 fl_set_button(fd_form_document->radio_columns_two, 1);
1938 fl_set_button(fd_form_document->radio_columns_one, 1);
1940 fl_set_input(fd_form_document->input_spacing, "");
1941 switch (params->spacing.getSpace()) {
1942 case Spacing::Single:
1945 fl_set_choice(fd_form_document->choice_spacing, 1);
1948 case Spacing::Onehalf:
1951 fl_set_choice(fd_form_document->choice_spacing, 2);
1954 case Spacing::Double:
1957 fl_set_choice(fd_form_document->choice_spacing, 3);
1960 case Spacing::Other:
1962 fl_set_choice(fd_form_document->choice_spacing, 4);
1964 sprintf(sval, "%g", params->spacing.getValue());
1965 fl_set_input(fd_form_document->input_spacing, sval);
1971 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1972 params->secnumdepth);
1973 fl_set_counter_value(fd_form_document->slider_tocdepth,
1975 if (!params->float_placement.empty()) { // buffer local (Lgb)
1976 fl_set_input(fd_form_document->input_float_placement,
1977 params->float_placement.c_str());
1979 fl_set_input(fd_form_document->input_float_placement, "");
1981 if (!params->options.empty())
1982 fl_set_input(fd_form_document->input_extra,
1983 params->options.c_str());
1985 fl_set_input(fd_form_document->input_extra, "");
1987 if (current_view->buffer()->isSGML()) {
1988 // bullets not used in SGML derived documents
1989 fl_deactivate_object(fd_form_document->button_bullets);
1990 fl_set_object_lcol(fd_form_document->button_bullets,
1993 fl_activate_object(fd_form_document->button_bullets);
1994 fl_set_object_lcol(fd_form_document->button_bullets,
1998 if (current_view->buffer()->isReadonly()) {
1999 DisableDocumentLayout();
2001 EnableDocumentLayout();
2008 void MenuLayoutDocument()
2010 if (UpdateLayoutDocument()) {
2011 if (fd_form_document->form_document->visible) {
2012 fl_raise_form(fd_form_document->form_document);
2014 fl_show_form(fd_form_document->form_document,
2015 FL_PLACE_MOUSE, FL_FULLBORDER,
2016 _("Document Layout"));
2022 bool UpdateLayoutQuotes()
2025 if (!current_view->getScreen()
2026 || !current_view->available()
2027 || current_view->buffer()->isReadonly())
2031 fl_set_choice(fd_form_quotes->choice_quotes_language,
2032 current_view->buffer()->params.quotes_language + 1);
2033 fl_set_button(fd_form_quotes->radio_single, 0);
2034 fl_set_button(fd_form_quotes->radio_double, 0);
2036 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
2037 fl_set_button(fd_form_quotes->radio_single, 1);
2039 fl_set_button(fd_form_quotes->radio_double, 1);
2040 } else if (fd_form_quotes->form_quotes->visible) {
2041 fl_hide_form(fd_form_quotes->form_quotes);
2047 void MenuLayoutQuotes()
2049 if (UpdateLayoutQuotes()) {
2050 if (fd_form_quotes->form_quotes->visible) {
2051 fl_raise_form(fd_form_quotes->form_quotes);
2053 fl_show_form(fd_form_quotes->form_quotes,
2054 FL_PLACE_MOUSE, FL_FULLBORDER,
2061 bool UpdateLayoutPreamble()
2064 if (!current_view->getScreen() || ! current_view->available())
2068 fl_set_input(fd_form_preamble->input_preamble,
2069 current_view->buffer()->params.preamble.c_str());
2071 if (current_view->buffer()->isReadonly()) {
2072 fl_deactivate_object(fd_form_preamble->input_preamble);
2073 fl_deactivate_object(fd_form_preamble->button_ok);
2074 fl_deactivate_object(fd_form_preamble->button_apply);
2075 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
2076 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2079 fl_activate_object(fd_form_preamble->input_preamble);
2080 fl_activate_object(fd_form_preamble->button_ok);
2081 fl_activate_object(fd_form_preamble->button_apply);
2082 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2083 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2085 } else if (fd_form_preamble->form_preamble->visible) {
2086 fl_hide_form(fd_form_preamble->form_preamble);
2091 void MenuLayoutPreamble()
2093 static int ow = -1, oh;
2095 if (UpdateLayoutPreamble()) {
2096 if (fd_form_preamble->form_preamble->visible) {
2097 fl_raise_form(fd_form_preamble->form_preamble);
2099 fl_show_form(fd_form_preamble->form_preamble,
2100 FL_PLACE_MOUSE | FL_FREE_SIZE,
2102 _("LaTeX Preamble"));
2104 ow = fd_form_preamble->form_preamble->w;
2105 oh = fd_form_preamble->form_preamble->h;
2107 fl_set_form_minsize(fd_form_preamble->form_preamble,
2114 void MenuLayoutSave()
2116 if (!current_view->getScreen() || ! current_view->available())
2119 if (AskQuestion(_("Do you want to save the current settings"),
2120 _("for Character, Document, Paper and Quotes"),
2121 _("as default for new documents?")))
2122 current_view->buffer()->saveParamsAsDefaults();
2126 // candidate for move to BufferView
2129 InsetInfo * new_inset = new InsetInfo();
2130 current_view->buffer()->insertInset(new_inset);
2131 new_inset->Edit(0, 0);
2135 // candidate for move to BufferView
2138 if (current_view->available()) {
2139 current_view->owner()->getMiniBuffer()->Set(_("Open/Close..."));
2140 current_view->getScreen()->HideCursor();
2142 current_view->update(-2);
2143 current_view->text->OpenStuff();
2144 current_view->update(0);
2149 // candidate for move to BufferView
2152 if (current_view->available()) {
2153 current_view->owner()->getMiniBuffer()->Set(_("Open/Close..."));
2154 current_view->getScreen()->HideCursor();
2156 current_view->update(-2);
2157 current_view->text->ToggleFootnote();
2158 current_view->update(0);
2163 // candidate for move to BufferView
2166 /* if (current_view->buffer()->the_locking_inset) {
2167 current_view->owner()->getMiniBuffer()->Set(_("Undo not yet supported in math mode"));
2171 if (current_view->available()) {
2172 current_view->owner()->getMiniBuffer()->Set(_("Undo"));
2173 current_view->getScreen()->HideCursor();
2175 current_view->update(-2);
2176 if (!current_view->text->TextUndo())
2177 current_view->owner()->getMiniBuffer()->Set(_("No further undo information"));
2179 current_view->update(-1);
2184 // candidate for move to BufferView
2187 if (current_view->buffer()->the_locking_inset) {
2188 current_view->owner()->getMiniBuffer()->Set(_("Redo not yet supported in math mode"));
2192 if (current_view->available()) {
2193 current_view->owner()->getMiniBuffer()->Set(_("Redo"));
2194 current_view->getScreen()->HideCursor();
2196 current_view->update(-2);
2197 if (!current_view->text->TextRedo())
2198 current_view->owner()->getMiniBuffer()->Set(_("No further redo information"));
2200 current_view->update(-1);
2205 // candidate for move to BufferView
2206 void HyphenationPoint()
2208 if (current_view->available()) {
2209 current_view->getScreen()->HideCursor();
2210 current_view->update(-2);
2211 InsetSpecialChar * new_inset =
2212 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2213 current_view->buffer()->insertInset(new_inset);
2218 // candidate for move to BufferView
2221 if (current_view->available()) {
2222 current_view->getScreen()->HideCursor();
2223 current_view->update(-2);
2224 InsetSpecialChar * new_inset =
2225 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2226 current_view->buffer()->insertInset(new_inset);
2231 // candidate for move to BufferView
2232 void EndOfSentenceDot()
2234 if (current_view->available()) {
2235 current_view->getScreen()->HideCursor();
2236 current_view->update(-2);
2237 InsetSpecialChar * new_inset =
2238 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2239 current_view->buffer()->insertInset(new_inset);
2244 // candidate for move to BufferView
2245 void MenuSeparator()
2247 if (current_view->available()) {
2248 current_view->getScreen()->HideCursor();
2249 current_view->update(-2);
2250 InsetSpecialChar * new_inset =
2251 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2252 current_view->buffer()->insertInset(new_inset);
2257 // candidate for move to BufferView
2260 if (current_view->available()) {
2261 current_view->getScreen()->HideCursor();
2262 current_view->update(-2);
2263 current_view->text->InsertChar(LyXParagraph::META_NEWLINE);
2264 current_view->update(-1);
2269 // candidate for move to BufferView
2270 void ProtectedBlank()
2272 if (current_view->available()) {
2273 current_view->getScreen()->HideCursor();
2274 current_view->update(-2);
2275 current_view->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2276 current_view->update(-1);
2281 // candidate for move to BufferView
2284 if (current_view->available()) {
2285 current_view->getScreen()->HideCursor();
2286 current_view->update(-2);
2287 current_view->text->InsertChar(LyXParagraph::META_HFILL);
2288 current_view->update(-1);
2293 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2294 They also show the current font state. */
2297 void ToggleAndShow(LyXFont const &);
2300 void FontSizeCB(string const & size)
2302 LyXFont font(LyXFont::ALL_IGNORE);
2303 font.setGUISize(size);
2304 ToggleAndShow(font);
2310 LyXFont font(LyXFont::ALL_IGNORE);
2311 font.setEmph(LyXFont::TOGGLE);
2312 ToggleAndShow(font);
2318 LyXFont font(LyXFont::ALL_IGNORE);
2319 font.setNoun(LyXFont::TOGGLE);
2320 ToggleAndShow(font);
2326 LyXFont font(LyXFont::ALL_IGNORE);
2327 font.setSeries(LyXFont::BOLD_SERIES);
2328 ToggleAndShow(font);
2334 LyXFont font(LyXFont::ALL_IGNORE);
2335 font.setUnderbar(LyXFont::TOGGLE);
2336 ToggleAndShow(font);
2342 LyXFont font(LyXFont::ALL_IGNORE);
2343 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2344 ToggleAndShow(font);
2350 LyXFont font(LyXFont::ALL_IGNORE);
2351 font.setFamily(LyXFont::SANS_FAMILY);
2352 ToggleAndShow(font);
2358 LyXFont font(LyXFont::ALL_IGNORE);
2359 font.setFamily(LyXFont::ROMAN_FAMILY);
2360 ToggleAndShow(font);
2366 LyXFont font(LyXFont::ALL_IGNORE);
2367 font.setLatex (LyXFont::TOGGLE);
2368 ToggleAndShow(font);
2374 LyXFont font(LyXFont::ALL_INHERIT);
2375 ToggleAndShow(font);
2379 /* -------> Returns the current font and depth by printing a message. In the
2380 * future perhaps we could try to implement a callback to the button-bar.
2381 * That is, `light' the bold button when the font is currently bold, etc.
2383 string CurrentState()
2386 if (current_view->available()) {
2387 // I think we should only show changes from the default
2389 Buffer * buffer = current_view->buffer();
2390 LyXFont font = current_view->text->real_current_font;
2391 LyXFont defaultfont = textclasslist.TextClass(buffer->
2392 params.textclass).defaultfont();
2393 font.reduce(defaultfont);
2394 state = _("Font: ") + font.stateText();
2396 int depth = current_view->text->GetDepth();
2398 state += string(_(", Depth: ")) + tostr(depth);
2404 // candidate for move to BufferView
2405 /* -------> Does the actual toggle job of the XxxCB() calls above.
2406 * Also shows the current font state.
2409 void ToggleAndShow(LyXFont const & font)
2411 if (current_view->available()) {
2412 current_view->getScreen()->HideCursor();
2413 current_view->update(-2);
2414 current_view->text->ToggleFree(font, toggleall);
2415 current_view->update(1);
2417 // removed since it overrides the ToggleFree Message about the style
2418 // Since Styles are more "High Level" than raw fonts I think the user
2419 // prefers it like this Matthias
2420 // FontStateShowCB( 0, 0 );
2424 // candidate for move to BufferView
2425 extern "C" void MarginCB(FL_OBJECT *, long)
2427 if (current_view->available()) {
2428 current_view->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2429 current_view->getScreen()->HideCursor();
2430 current_view->update(-2);
2431 current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2432 current_view->update(1);
2437 extern "C" void FigureCB(FL_OBJECT *, long)
2439 if (fd_form_figure->form_figure->visible) {
2440 fl_raise_form(fd_form_figure->form_figure);
2442 fl_show_form(fd_form_figure->form_figure,
2443 FL_PLACE_MOUSE, FL_FULLBORDER,
2444 _("Insert Figure"));
2449 extern "C" void TableCB(FL_OBJECT *, long)
2451 if (fd_form_table->form_table->visible) {
2452 fl_raise_form(fd_form_table->form_table);
2454 fl_show_form(fd_form_table->form_table,
2455 FL_PLACE_MOUSE, FL_FULLBORDER,
2461 // candidate for move to BufferView
2462 void CopyEnvironmentCB()
2464 if (current_view->available()) {
2465 current_view->text->copyEnvironmentType();
2466 /* clear the selection, even if mark_set */
2467 current_view->getScreen()->ToggleSelection();
2468 current_view->text->ClearSelection();
2469 current_view->update(-2);
2470 current_view->owner()->getMiniBuffer()->Set(_("Paragraph environment type copied"));
2475 // candidate for move to BufferView
2476 void PasteEnvironmentCB()
2478 if (current_view->available()) {
2479 current_view->text->pasteEnvironmentType();
2480 current_view->owner()->getMiniBuffer()->Set(_("Paragraph environment type set"));
2481 current_view->update(1);
2486 // candidate for move to BufferView
2489 if (current_view->available()) {
2490 current_view->text->CopySelection();
2491 /* clear the selection, even if mark_set */
2492 current_view->getScreen()->ToggleSelection();
2493 current_view->text->ClearSelection();
2494 current_view->update(-2);
2495 current_view->owner()->getMiniBuffer()->Set(_("Copy"));
2500 // candidate for move to BufferView
2503 if (current_view->available()) {
2504 current_view->getScreen()->HideCursor();
2505 current_view->update(-2);
2506 current_view->text->CutSelection();
2507 current_view->update(1);
2508 current_view->owner()->getMiniBuffer()->Set(_("Cut"));
2513 // candidate for move to BufferView
2516 if (!current_view->available()) return;
2518 current_view->owner()->getMiniBuffer()->Set(_("Paste"));
2519 current_view->getScreen()->HideCursor();
2520 /* clear the selection */
2521 current_view->getScreen()->ToggleSelection();
2522 current_view->text->ClearSelection();
2523 current_view->update(-2);
2526 current_view->text->PasteSelection();
2527 current_view->update(1);
2529 /* clear the selection */
2530 current_view->getScreen()->ToggleSelection();
2531 current_view->text->ClearSelection();
2532 current_view->update(-2);
2536 // candidate for move to BufferView
2537 extern "C" void MeltCB(FL_OBJECT *, long)
2539 if (!current_view->available()) return;
2541 current_view->owner()->getMiniBuffer()->Set(_("Melt"));
2542 current_view->getScreen()->HideCursor();
2544 current_view->update(-2);
2545 current_view->text->MeltFootnoteEnvironment();
2546 current_view->update(1);
2550 // candidate for move to BufferView
2551 // Change environment depth.
2552 // if decInc == 0, depth change taking mouse button number into account
2553 // if decInc == 1, increment depth
2554 // if decInc == -1, decrement depth
2555 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2559 /* When decInc != 0, fake a mouse button. This allows us to
2560 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2561 /* check out wether ob is defined, too (Matthias) */
2564 else if (!decInc && ob) {
2565 button = fl_get_button_numb(ob);
2568 if (current_view->available()) {
2569 current_view->getScreen()->HideCursor();
2570 current_view->update(-2);
2572 current_view->text->IncDepth();
2574 current_view->text->DecDepth();
2575 current_view->update(1);
2576 current_view->owner()->getMiniBuffer()->Set(_("Changed environment depth"
2577 " (in possible range, maybe not)"));
2582 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2583 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2584 LyXFont UserFreeFont()
2586 LyXFont font(LyXFont::ALL_IGNORE);
2588 int pos = fl_get_choice(fd_form_character->choice_family);
2590 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2591 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2592 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2593 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2594 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2597 pos = fl_get_choice(fd_form_character->choice_series);
2599 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2600 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2601 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2602 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2605 pos = fl_get_choice(fd_form_character->choice_shape);
2607 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2608 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2609 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2610 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2611 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2612 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2615 pos = fl_get_choice(fd_form_character->choice_size);
2617 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2618 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2619 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2620 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2621 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2622 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2623 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2624 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2625 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2626 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2627 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2628 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2629 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2630 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2633 pos = fl_get_choice(fd_form_character->choice_bar);
2635 case 1: font.setEmph(LyXFont::IGNORE);
2636 font.setUnderbar(LyXFont::IGNORE);
2637 font.setNoun(LyXFont::IGNORE);
2638 font.setLatex(LyXFont::IGNORE);
2640 case 2: font.setEmph(LyXFont::TOGGLE); break;
2641 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2642 case 4: font.setNoun(LyXFont::TOGGLE); break;
2643 case 5: font.setLatex(LyXFont::TOGGLE); break;
2644 case 6: font.setEmph(LyXFont::INHERIT);
2645 font.setUnderbar(LyXFont::INHERIT);
2646 font.setNoun(LyXFont::INHERIT);
2647 font.setLatex(LyXFont::INHERIT);
2651 pos = fl_get_choice(fd_form_character->choice_color);
2653 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2654 case 2: font.setColor(LyXFont::NONE); break;
2655 case 3: font.setColor(LyXFont::BLACK); break;
2656 case 4: font.setColor(LyXFont::WHITE); break;
2657 case 5: font.setColor(LyXFont::RED); break;
2658 case 6: font.setColor(LyXFont::GREEN); break;
2659 case 7: font.setColor(LyXFont::BLUE); break;
2660 case 8: font.setColor(LyXFont::CYAN); break;
2661 case 9: font.setColor(LyXFont::MAGENTA); break;
2662 case 10: font.setColor(LyXFont::YELLOW); break;
2663 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2672 ToggleAndShow(UserFreeFont());
2676 /* callbacks for form form_title */
2677 extern "C" void TimerCB(FL_OBJECT *, long)
2679 // only if the form still exists
2680 if (fd_form_title->form_title != 0) {
2681 if (fd_form_title->form_title->visible) {
2682 fl_hide_form(fd_form_title->form_title);
2684 fl_free_form(fd_form_title->form_title);
2685 fd_form_title->form_title = 0;
2690 /* callbacks for form form_paragraph */
2692 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2694 // "Synchronize" the choices and input fields, making it
2695 // impossible to commit senseless data.
2697 FD_form_paragraph const * fp = fd_form_paragraph;
2699 if (obj == fp->choice_space_above) {
2700 if (fl_get_choice (fp->choice_space_above) != 7) {
2701 fl_set_input (fp->input_space_above, "");
2702 ActivateParagraphButtons();
2704 } else if (obj == fp->choice_space_below) {
2705 if (fl_get_choice (fp->choice_space_below) != 7) {
2706 fl_set_input (fp->input_space_below, "");
2707 ActivateParagraphButtons();
2709 } else if (obj == fp->input_space_above) {
2710 string input = fl_get_input (fp->input_space_above);
2712 if (input.empty()) {
2713 fl_set_choice (fp->choice_space_above, 1);
2714 ActivateParagraphButtons();
2716 else if (isValidGlueLength (input)) {
2717 fl_set_choice (fp->choice_space_above, 7);
2718 ActivateParagraphButtons();
2721 fl_set_choice (fp->choice_space_above, 7);
2722 DeactivateParagraphButtons();
2724 } else if (obj == fp->input_space_below) {
2725 string input = fl_get_input (fp->input_space_below);
2727 if (input.empty()) {
2728 fl_set_choice (fp->choice_space_below, 1);
2729 ActivateParagraphButtons();
2731 else if (isValidGlueLength (input)) {
2732 fl_set_choice (fp->choice_space_below, 7);
2733 ActivateParagraphButtons();
2736 fl_set_choice (fp->choice_space_below, 7);
2737 DeactivateParagraphButtons();
2743 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2745 if (!current_view->available())
2748 VSpace space_top, space_bottom;
2750 string labelwidthstring;
2753 // If a vspace kind is "Length" but there's no text in
2754 // the input field, reset the kind to "None".
2755 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2756 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2757 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2759 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2760 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2761 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2764 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2765 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2766 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2767 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2768 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2769 case 1: space_top = VSpace(VSpace::NONE); break;
2770 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2771 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2772 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2773 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2774 case 6: space_top = VSpace(VSpace::VFILL); break;
2775 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2777 if (fl_get_button (fd_form_paragraph->check_space_above))
2778 space_top.setKeep (true);
2779 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2780 case 1: space_bottom = VSpace(VSpace::NONE); break;
2781 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2782 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2783 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2784 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2785 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2786 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2788 if (fl_get_button (fd_form_paragraph->check_space_below))
2789 space_bottom.setKeep (true);
2791 if (fl_get_button(fd_form_paragraph->radio_align_left))
2792 align = LYX_ALIGN_LEFT;
2793 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2794 align = LYX_ALIGN_RIGHT;
2795 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2796 align = LYX_ALIGN_CENTER;
2798 align = LYX_ALIGN_BLOCK;
2800 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2801 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2803 current_view->text->SetParagraph(line_top,
2812 current_view->update(1);
2813 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2817 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2819 fl_hide_form(fd_form_paragraph->form_paragraph);
2823 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2825 ParagraphApplyCB(ob, data);
2826 ParagraphCancelCB(ob, data);
2830 /* callbacks for form form_character */
2832 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2834 // we set toggleall locally here, since it should be true for
2835 // all other uses of ToggleAndShow() (JMarc)
2836 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2837 ToggleAndShow( UserFreeFont());
2842 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2844 fl_hide_form(fd_form_character->form_character);
2848 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2850 CharacterApplyCB(ob, data);
2851 CharacterCloseCB(ob, data);
2855 /* callbacks for form form_document */
2857 void UpdateDocumentButtons(BufferParams const & params)
2859 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2861 if (params.sides == 2)
2862 fl_set_button(fd_form_document->radio_sides_two, 1);
2864 fl_set_button(fd_form_document->radio_sides_one, 1);
2866 if (params.columns == 2)
2867 fl_set_button(fd_form_document->radio_columns_two, 1);
2869 fl_set_button(fd_form_document->radio_columns_one, 1);
2871 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2872 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2873 params.secnumdepth);
2874 fl_set_counter_value(fd_form_document->slider_tocdepth,
2879 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2882 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2883 if (AskQuestion(_("Should I set some parameters to"),
2884 fl_get_choice_text(ob),
2885 _("the defaults of this document class?"))) {
2886 BufferParams params = BufferParams();
2887 params.textclass = fl_get_choice(ob)-1;
2888 params.useClassDefaults();
2889 UpdateLayoutDocument(¶ms);
2890 UpdateDocumentButtons(params);
2893 // unable to load new style
2894 WriteAlert(_("Conversion Errors!"),
2895 _("Unable to switch to new document class."),
2896 _("Reverting to original document class."));
2897 fl_set_choice(fd_form_document->choice_class,
2898 GetCurrentTextClass() + 1);
2904 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2906 // "Synchronize" the choice and the input field, so that it
2907 // is impossible to commit senseless data.
2908 FD_form_document const * fd = fd_form_document;
2910 if (obj == fd->choice_default_skip) {
2911 if (fl_get_choice (fd->choice_default_skip) != 4) {
2912 fl_set_input (fd->input_default_skip, "");
2913 ActivateDocumentButtons();
2915 } else if (obj == fd->input_default_skip) {
2917 char const * input = fl_get_input (fd->input_default_skip);
2920 fl_set_choice (fd->choice_default_skip, 2);
2921 ActivateDocumentButtons();
2922 } else if (isValidGlueLength (input)) {
2923 fl_set_choice (fd->choice_default_skip, 4);
2924 ActivateDocumentButtons();
2926 fl_set_choice (fd->choice_default_skip, 4);
2927 DeactivateDocumentButtons();
2933 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2935 // "Synchronize" the choice and the input field, so that it
2936 // is impossible to commit senseless data.
2937 FD_form_document const * fd = fd_form_document;
2939 if (obj == fd->choice_spacing
2940 && fl_get_choice (fd->choice_spacing) != 4) {
2941 fl_set_input(fd->input_spacing, "");
2942 } else if (obj == fd->input_spacing) {
2944 const char* input = fl_get_input (fd->input_spacing);
2947 fl_set_choice (fd->choice_spacing, 1);
2949 fl_set_choice (fd->choice_spacing, 4);
2955 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2958 BufferParams *params = &(current_view->buffer()->params);
2959 current_view->buffer()->params.language =
2960 combo_language->getline();
2962 // If default skip is a "Length" but there's no text in the
2963 // input field, reset the kind to "Medskip", which is the default.
2964 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2965 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2966 fl_set_choice (fd_form_document->choice_default_skip, 2);
2969 /* this shouldn't be done automatically IMO. For example I write german
2970 * documents with an american keyboard very often. Matthias */
2972 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2973 fl_get_choice(fd_form_document->choice_language)); */
2975 fl_get_choice_text(fd_form_document->choice_fonts);
2977 fl_get_choice_text(fd_form_document->choice_inputenc);
2979 fl_get_choice_text(fd_form_document->choice_fontsize);
2981 fl_get_choice_text(fd_form_document->choice_pagestyle);
2982 params->graphicsDriver =
2983 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2984 params->use_amsmath =
2985 fl_get_button(fd_form_document->check_use_amsmath);
2987 if (!current_view->available())
2990 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2991 if (params->textclass != new_class) {
2992 // try to load new_class
2993 if (textclasslist.Load(new_class)) {
2994 // successfully loaded
2996 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2997 int ret = current_view->text->
2998 SwitchLayoutsBetweenClasses(current_view->buffer()->
3001 current_view->buffer()->
3007 s = _("One paragraph couldn't be converted");
3010 s += _(" paragraphs couldn't be converted");
3012 WriteAlert(_("Conversion Errors!"), s,
3013 _("into chosen document class"));
3016 params->textclass = new_class;
3018 // problem changing class -- warn user and retain old style
3019 WriteAlert(_("Conversion Errors!"),
3020 _("Unable to switch to new document class."),
3021 _("Reverting to original document class."));
3022 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
3026 char tmpsep = params->paragraph_separation;
3027 if (fl_get_button(fd_form_document->radio_indent))
3028 params->paragraph_separation = BufferParams::PARSEP_INDENT;
3030 params->paragraph_separation = BufferParams::PARSEP_SKIP;
3031 if (tmpsep != params->paragraph_separation)
3034 VSpace tmpdefskip = params->getDefSkip();
3035 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
3036 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
3037 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3038 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
3039 case 4: params->setDefSkip(
3040 VSpace (LyXGlueLength (fl_get_input
3041 (fd_form_document->input_default_skip))));
3043 // DocumentDefskipCB assures that this never happens
3044 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3046 if (!(tmpdefskip == params->getDefSkip()))
3049 if (fl_get_button(fd_form_document->radio_columns_two))
3050 params->columns = 2;
3052 params->columns = 1;
3053 if (fl_get_button(fd_form_document->radio_sides_two))
3054 params->sides = LyXTextClass::TwoSides;
3056 params->sides = LyXTextClass::OneSide;
3058 Spacing tmpSpacing = params->spacing;
3059 switch(fl_get_choice(fd_form_document->choice_spacing)) {
3061 lyxerr.debug() << "Spacing: SINGLE" << endl;
3062 params->spacing.set(Spacing::Single);
3065 lyxerr.debug() << "Spacing: ONEHALF" << endl;
3066 params->spacing.set(Spacing::Onehalf);
3069 lyxerr.debug() << "Spacing: DOUBLE" << endl;
3070 params->spacing.set(Spacing::Double);
3073 lyxerr.debug() << "Spacing: OTHER" << endl;
3074 params->spacing.set(Spacing::Other,
3075 fl_get_input(fd_form_document->input_spacing));
3078 if (tmpSpacing != params->spacing)
3081 signed char tmpchar =
3082 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
3083 if (params->secnumdepth != tmpchar)
3085 params->secnumdepth = tmpchar;
3088 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
3090 params->float_placement =
3091 fl_get_input(fd_form_document->input_float_placement);
3093 // More checking should be done to ensure the string doesn't have
3094 // spaces or illegal placement characters in it. (thornley)
3097 current_view->redoCurrentBuffer();
3099 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
3100 current_view->buffer()->markDirty();
3103 fl_get_input(fd_form_document->input_extra);
3108 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3110 fl_hide_form(fd_form_document->form_document);
3114 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3116 DocumentCancelCB(ob, data);
3117 DocumentApplyCB(ob, data);
3121 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3124 // bullet callbacks etc. in bullet_panel.C -- ARRae
3128 // candidate for move to BufferView
3131 if (!current_view->getScreen())
3134 current_view->getScreen()->HideCursor();
3136 current_view->update(-2);
3139 if (!current_view->text->GotoNextNote()) {
3140 if (current_view->text->cursor.pos
3141 || current_view->text->cursor.par !=
3142 current_view->text->FirstParagraph())
3144 tmp = current_view->text->cursor;
3145 current_view->text->cursor.par =
3146 current_view->text->FirstParagraph();
3147 current_view->text->cursor.pos = 0;
3148 if (!current_view->text->GotoNextNote()) {
3149 current_view->text->cursor = tmp;
3150 current_view->owner()->getMiniBuffer()->Set(_("No more notes"));
3154 current_view->owner()->getMiniBuffer()->Set(_("No more notes"));
3158 current_view->update(0);
3159 current_view->text->sel_cursor =
3160 current_view->text->cursor;
3164 // candidate for move to BufferView
3165 void InsertCorrectQuote()
3167 Buffer * cbuffer = current_view->buffer();
3170 if (current_view->text->cursor.pos )
3171 c = current_view->text->cursor.par->GetChar(current_view->text->cursor.pos - 1);
3175 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3179 /* callbacks for form form_quotes */
3181 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3183 if (!current_view->available())
3186 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
3187 //current_view->buffer()->params.quotes_language =
3188 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3189 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3190 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3192 lga = InsetQuotes::EnglishQ;
3195 lga = InsetQuotes::SwedishQ;
3198 lga = InsetQuotes::GermanQ;
3201 lga = InsetQuotes::PolishQ;
3204 lga = InsetQuotes::FrenchQ;
3207 lga = InsetQuotes::DanishQ;
3210 current_view->buffer()->params.quotes_language = lga;
3211 if (fl_get_button(fd_form_quotes->radio_single))
3212 current_view->buffer()->
3213 params.quotes_times = InsetQuotes::SingleQ;
3215 current_view->buffer()->
3216 params.quotes_times = InsetQuotes::DoubleQ;
3220 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3222 fl_hide_form(fd_form_quotes->form_quotes);
3226 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3228 QuotesApplyCB(ob, data);
3229 QuotesCancelCB(ob, data);
3234 /* callbacks for form form_preamble */
3236 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3238 fl_hide_form(fd_form_preamble->form_preamble);
3242 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3244 if (!current_view->available())
3247 current_view->buffer()->params.preamble =
3248 fl_get_input(fd_form_preamble->input_preamble);
3249 current_view->buffer()->markDirty();
3250 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
3254 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3256 PreambleApplyCB(ob, data);
3257 PreambleCancelCB(ob, data);
3261 /* callbacks for form form_table */
3263 extern "C" void TableApplyCB(FL_OBJECT *, long)
3265 if (!current_view->getScreen())
3268 // check for tables in tables
3269 if (current_view->text->cursor.par->table){
3270 WriteAlert(_("Impossible Operation!"),
3271 _("Cannot insert table in table."),
3276 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
3278 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3279 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3282 current_view->getScreen()->HideCursor();
3284 current_view->update(-2);
3286 current_view->text->SetCursorParUndo();
3287 current_view->text->FreezeUndo();
3289 current_view->text->BreakParagraph();
3290 current_view->update(-1);
3292 if (current_view->text->cursor.par->Last()) {
3293 current_view->text->CursorLeft();
3295 current_view->text->BreakParagraph();
3296 current_view->update(-1);
3299 current_view->text->current_font.setLatex(LyXFont::OFF);
3300 //if (!fl_get_button(fd_form_table->check_latex)){
3301 // insert the new wysiwy table
3302 current_view->text->SetLayout(0); // standard layout
3303 if (current_view->text->cursor.par->footnoteflag ==
3304 LyXParagraph::NO_FOOTNOTE) {
3306 ->SetParagraph(0, 0,
3308 VSpace (0.3 * current_view->buffer()->
3309 params.spacing.getValue(),
3311 VSpace (0.3 * current_view->buffer()->
3312 params.spacing.getValue(),
3320 ->SetParagraph(0, 0,
3322 VSpace(VSpace::NONE),
3323 VSpace(VSpace::NONE),
3328 current_view->text->cursor.par->table =
3329 new LyXTable(xsize, ysize);
3331 for (int i = 0; i < xsize * ysize - 1; ++i)
3332 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3333 current_view->text->RedoParagraph();
3335 current_view->text->UnFreezeUndo();
3337 current_view->update(1);
3338 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
3342 extern "C" void TableCancelCB(FL_OBJECT *, long)
3344 fl_hide_form(fd_form_table->form_table);
3348 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3350 TableApplyCB(ob, data);
3351 TableCancelCB(ob, data);
3355 /* callbacks for form form_print */
3357 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3359 fl_hide_form(fd_form_print->form_print);
3362 static bool stringOnlyContains (string const & LStr, char const * cset)
3364 char const * cstr = LStr.c_str() ;
3366 return strspn(cstr, cset) == strlen(cstr) ;
3369 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3371 if (!current_view->available())
3373 Buffer * buffer = current_view->buffer();
3374 string path = OnlyPath(buffer->fileName());
3377 if (fl_get_button(fd_form_print->radio_even_pages))
3378 pageflag = lyxrc->print_evenpage_flag + ' ';
3379 else if (fl_get_button(fd_form_print->radio_odd_pages))
3380 pageflag = lyxrc->print_oddpage_flag + ' ';
3382 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3383 // User may give a page (range) list
3384 // User may print multiple (unsorted) copies
3385 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3386 pages = subst(pages, '+',',');
3387 pages = frontStrip(strip(pages)) ;
3388 while (!pages.empty()) { // a page range was given
3390 pages = split (pages, piece, ',') ;
3391 piece = strip(piece) ;
3392 piece = frontStrip(piece) ;
3393 if ( !stringOnlyContains (piece, "0123456789-") ) {
3394 WriteAlert(_("ERROR! Unable to print!"),
3395 _("Check 'range of pages'!"));
3398 if (piece.find('-') == string::npos) { // not found
3399 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3400 } else if (suffixIs(piece, "-") ) { // missing last page
3401 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3402 } else if (prefixIs(piece, "-") ) { // missing first page
3403 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3405 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3409 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3410 if (!copies.empty()) { // a number of copies was given
3411 if ( !stringOnlyContains (copies, "0123456789") ) {
3412 WriteAlert(_("ERROR! Unable to print!"),
3413 _("Check 'number of copies'!"));
3416 if (fl_get_button(fd_form_print->do_unsorted))
3417 pageflag += lyxrc->print_copies_flag;
3419 pageflag += lyxrc->print_collcopies_flag;
3420 pageflag += " " + copies + ' ' ;
3424 if (fl_get_button(fd_form_print->radio_order_reverse))
3425 reverseflag = lyxrc->print_reverse_flag + ' ';
3427 string orientationflag;
3428 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3429 orientationflag = lyxrc->print_landscape_flag + ' ';
3431 string ps_file = fl_get_input(fd_form_print->input_file);
3432 string printer = strip(fl_get_input(fd_form_print->input_printer));
3435 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3436 && ! printer.empty()) // a printer name has been given
3437 printerflag = lyxrc->print_to_printer + printer + ' ';
3440 if (!lyxrc->print_extra_options.empty())
3441 extraflags = lyxrc->print_extra_options + ' ';
3443 string command = lyxrc->print_command + ' '
3444 + printerflag + pageflag + reverseflag
3445 + orientationflag + extraflags;
3447 char real_papersize = buffer->params.papersize;
3448 if (real_papersize == BufferParams::PAPER_DEFAULT)
3449 real_papersize = lyxrc->default_papersize;
3452 switch (real_papersize) {
3453 case BufferParams::PAPER_USLETTER:
3456 case BufferParams::PAPER_A3PAPER:
3459 case BufferParams::PAPER_A4PAPER:
3462 case BufferParams::PAPER_A5PAPER:
3465 case BufferParams::PAPER_B5PAPER:
3468 case BufferParams::PAPER_EXECUTIVEPAPER:
3471 case BufferParams::PAPER_LEGALPAPER:
3474 default: /* If nothing else fits, keep an empty value... */
3478 if (buffer->params.use_geometry
3479 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3480 && !lyxrc->print_paper_dimension_flag.empty()
3481 && !buffer->params.paperwidth.empty()
3482 && !buffer->params.paperheight.empty()) {
3483 // using a custom papersize
3485 command += lyxrc->print_paper_dimension_flag + ' ';
3486 command += buffer->params.paperwidth + ',';
3487 command += buffer->params.paperheight + ' ';
3488 } else if (!lyxrc->print_paper_flag.empty()
3490 && (real_papersize != BufferParams::PAPER_USLETTER ||
3491 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3492 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3494 if (fl_get_button(fd_form_print->radio_file))
3495 command += lyxrc->print_to_file
3496 + QuoteName(MakeAbsPath(ps_file, path));
3497 else if (!lyxrc->print_spool_command.empty())
3498 command += lyxrc->print_to_file
3499 + QuoteName(ps_file);
3501 // push directorypath, if necessary
3502 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3503 path = buffer->tmppath;
3508 if (!lyxrc->print_spool_command.empty() &&
3509 !fl_get_button(fd_form_print->radio_file)) {
3510 string command2 = lyxrc->print_spool_command + ' ';
3511 if (!printer.empty())
3512 command2 += lyxrc->print_spool_printerprefix
3514 // First run dvips and, if succesful, then spool command
3515 if ((result = RunScript(buffer, true, command))) {
3516 result = RunScript(buffer, false, command2, ps_file);
3519 result = RunScript(buffer, false, command);
3522 WriteAlert(_("Error:"),
3523 _("Unable to print"),
3524 _("Check that your parameters are correct"));
3528 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3530 PrintCancelCB(ob, data);
3531 PrintApplyCB(ob, data);
3535 /* callbacks for form form_figure */
3536 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3538 if (!current_view->available())
3541 Buffer * buffer = current_view->buffer();
3542 if(buffer->isReadonly()) // paranoia
3545 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3546 if (fl_get_button(fd_form_figure->radio_inline)
3547 || current_view->text->cursor.par->table) {
3548 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3549 buffer->insertInset(new_inset);
3550 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3551 new_inset->Edit(0, 0);
3555 current_view->getScreen()->HideCursor();
3556 current_view->update(-2);
3559 current_view->text->SetCursorParUndo();
3560 current_view->text->FreezeUndo();
3562 current_view->text->BreakParagraph();
3563 current_view->update(-1);
3565 if (current_view->text->cursor.par->Last()) {
3566 current_view->text->CursorLeft();
3568 current_view->text->BreakParagraph();
3569 current_view->update(-1);
3572 // The standard layout should always be numer 0;
3573 current_view->text->SetLayout(0);
3575 if (current_view->text->cursor.par->footnoteflag ==
3576 LyXParagraph::NO_FOOTNOTE) {
3577 current_view->text->
3580 VSpace (0.3 * buffer->params.spacing.getValue(),
3583 buffer->params.spacing.getValue(),
3585 LYX_ALIGN_CENTER, string(), 0);
3587 current_view->text->SetParagraph(0, 0,
3589 VSpace(VSpace::NONE),
3590 VSpace(VSpace::NONE),
3595 current_view->update(-1);
3597 Inset * new_inset = new InsetFig(100, 100, buffer);
3598 buffer->insertInset(new_inset);
3599 new_inset->Edit(0, 0);
3600 current_view->update(0);
3601 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3602 current_view->text->UnFreezeUndo();
3606 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3608 fl_hide_form(fd_form_figure->form_figure);
3612 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3614 FigureApplyCB(ob, data);
3615 FigureCancelCB(ob, data);
3619 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3621 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3622 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3623 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3624 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3625 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3626 fontloader.update();
3628 // All buffers will need resize
3629 bufferlist.resize();
3631 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3635 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3637 fl_hide_form(fd_form_screen->form_screen);
3641 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3643 ScreenCancelCB(ob, data);
3644 ScreenApplyCB(ob, data);
3650 if (!current_view->available())
3653 fl_set_button(fd_latex_options->accents,
3654 int(current_view->buffer()->params.allowAccents));
3656 if (fd_latex_options->LaTeXOptions->visible) {
3657 fl_raise_form(fd_latex_options->LaTeXOptions);
3659 fl_show_form(fd_latex_options->LaTeXOptions,
3660 FL_PLACE_MOUSE, FL_FULLBORDER,
3661 _("LaTeX Options"));
3666 // This function runs "configure" and then rereads lyx.defaults to
3667 // reconfigure the automatic settings.
3670 current_view->owner()->getMiniBuffer()->Set(_("Running configure..."));
3672 // Run configure in user lyx directory
3673 Path p(user_lyxdir);
3674 Systemcalls one(Systemcalls::System,
3675 AddName(system_lyxdir, "configure"));
3677 current_view->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3678 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
3679 WriteAlert(_("The system has been reconfigured."),
3680 _("You need to restart LyX to make use of any"),
3681 _("updated document class specifications."));
3685 // candidate for move to BufferView
3686 /* these functions are for the spellchecker */
3687 char * NextWord(float & value)
3689 if (!current_view->available()){
3694 char * string = current_view->text->SelectNextWord(value);
3700 // candidate for move to BufferView
3701 void SelectLastWord()
3703 if (!current_view->available())
3706 current_view->getScreen()->HideCursor();
3708 current_view->text->SelectSelectedWord();
3709 current_view->getScreen()->ToggleSelection(false);
3710 current_view->update(0);
3714 // candidate for move to BufferView
3715 void EndOfSpellCheck()
3717 if (!current_view->available())
3720 current_view->getScreen()->HideCursor();
3722 current_view->text->SelectSelectedWord();
3723 current_view->text->ClearSelection();
3724 current_view->update(0);
3728 // candidate for move to BufferView
3729 void ReplaceWord(string const & replacestring)
3731 if (!current_view->getScreen())
3734 current_view->getScreen()->HideCursor();
3735 current_view->update(-2);
3737 /* clear the selection (if there is any) */
3738 current_view->getScreen()->ToggleSelection(false);
3739 current_view->update(-2);
3741 /* clear the selection (if there is any) */
3742 current_view->getScreen()->ToggleSelection(false);
3743 current_view->text->
3744 ReplaceSelectionWithString(replacestring.c_str());
3746 current_view->text->SetSelectionOverString(replacestring.c_str());
3748 // Go back so that replacement string is also spellchecked
3749 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3750 current_view->text->CursorLeftIntern();
3752 current_view->update(1);
3754 // End of spellchecker stuff
3759 // Table of Contents
3769 static TocList * toclist = 0;
3772 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3774 if (!current_view->available())
3777 TocList * tmptoclist = toclist;
3778 int i = fl_get_browser(ob);
3779 for (int a = 1; a < i && tmptoclist->next; ++a) {
3780 tmptoclist = tmptoclist->next;
3787 LyXParagraph * par = current_view->buffer()->paragraph;
3788 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3789 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3790 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3791 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3792 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3793 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3794 par->appendix != tmptoclist->appendix)) {
3795 par = par->LastPhysicalPar()->Next();
3800 current_view->text->SetCursor(par, 0);
3801 current_view->text->sel_cursor =
3802 current_view->text->cursor;
3803 current_view->update(0);
3806 WriteAlert(_("Error"),
3807 _("Couldn't find this label"),
3808 _("in current document."));
3814 extern "C" void TocCancelCB(FL_OBJECT *, long)
3816 fl_hide_form(fd_form_toc->form_toc);
3820 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3822 static LyXParagraph * stapar = 0;
3823 TocList * tmptoclist = 0;
3825 /* deleted the toclist */
3828 tmptoclist = toclist->next;
3830 toclist = tmptoclist;
3834 tmptoclist = toclist;
3837 fl_clear_browser(fd_form_toc->browser_toc);
3838 if (!current_view->available()) {
3839 fl_add_browser_line(fd_form_toc->browser_toc,
3840 _("*** No Document ***"));
3843 fl_hide_object(fd_form_toc->browser_toc);
3844 /* get the table of contents */
3845 LyXParagraph * par = current_view->buffer()->paragraph;
3847 char * line = new char[200];
3853 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3857 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3858 par->GetLayout()).labeltype;
3860 if (labeltype >= LABEL_COUNTER_CHAPTER
3861 && labeltype <= LABEL_COUNTER_CHAPTER +
3862 current_view->buffer()->params.tocdepth) {
3863 /* insert this into the table of contents */
3864 /* first indent a little bit */
3868 textclasslist.TextClass(current_view->buffer()->
3869 params.textclass).maxcounter()) * 4 + 2;
3873 // Then the labestring
3874 if (!par->labelstring.empty()) {
3875 string::size_type i = 0;
3876 while (pos < 199 && i < par->labelstring.length()) {
3877 line[pos] = par->labelstring[i];
3886 /* now the contents */
3887 LyXParagraph::size_type i = 0;
3888 while (pos < 199 && i < par->size()) {
3889 c = par->GetChar(i);
3890 if (isprint(c) || c >= 128) {
3897 fl_add_browser_line(fd_form_toc->browser_toc, line);
3899 /* make a toclist entry */
3901 tmptoclist = new TocList;
3902 toclist = tmptoclist;
3904 tmptoclist->next = new TocList;
3905 tmptoclist = tmptoclist->next;
3908 tmptoclist->next = 0;
3910 for (a = 0; a < 6; ++a) {
3911 tmptoclist->counter[a] = par->GetFirstCounter(a);
3913 tmptoclist->appendix = par->appendix;
3915 par = par->LastPhysicalPar()->Next();
3919 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3920 fl_show_object(fd_form_toc->browser_toc);
3924 /* callbacks for form form_ref */
3925 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3927 if (!current_view->available())
3931 fl_get_browser_line(fd_form_ref->browser_ref,
3932 fl_get_browser(fd_form_ref->browser_ref));
3933 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3939 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3949 if(current_view->buffer()->isSGML())
3950 t += "[" + u + "]" + "{" + s + "}";
3955 new InsetRef(t, current_view->buffer());
3956 current_view->buffer()->insertInset(new_inset);
3960 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3962 if (!current_view->available()) {
3963 fl_clear_browser(fd_form_ref->browser_ref);
3967 FL_OBJECT * brow = fd_form_ref->browser_ref;
3969 // Get the current line, in order to restore it later
3970 char const * const btmp = fl_get_browser_line(brow,
3971 fl_get_browser(brow));
3972 string currentstr = btmp ? btmp : "";
3974 fl_clear_browser(brow);
3976 string refs = current_view->buffer()->getReferenceList('\n');
3979 #if FL_REVISION > 85
3980 fl_addto_browser_chars(brow, refs.c_str());
3981 int total_lines = fl_get_browser_maxline(brow);
3982 for (int i = 1; i <= total_lines ; i++) {
3983 if (fl_get_browser_line(brow, i) == currentstr) {
3988 fl_set_browser_topline(brow, topline);
3990 // Keep the old ugly code for xforms 0.81 compatibility
3995 curr_ref = refs.token('\n', ref_num);
3996 if (curr_ref.empty())
3998 fl_add_browser_line(brow, curr_ref.c_str());
4003 if (!fl_get_browser_maxline(brow)) {
4004 fl_add_browser_line(brow,
4005 _("*** No labels found in document ***"));
4006 fl_deactivate_object(brow);
4008 fl_select_browser_line(brow, topline);
4009 fl_activate_object(brow);
4011 if (current_view->buffer()->isReadonly()) {
4012 // would be better to de/activate insert buttons
4013 // but that's more work... besides this works. ARRae
4014 fl_hide_form(fd_form_ref->form_ref);
4016 if (!current_view->buffer()->isSGML()) {
4017 fl_deactivate_object(fd_form_ref->ref_name);
4018 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
4021 fl_activate_object(fd_form_ref->ref_name);
4022 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
4027 extern "C" void RefHideCB(FL_OBJECT *, long)
4029 fl_hide_form(fd_form_ref->form_ref);
4033 // candidate for move to BufferView
4034 void UpdateInset(Inset * inset, bool mark_dirty)
4039 /* very first check for locking insets*/
4040 if (current_view->buffer()->the_locking_inset == inset){
4041 if (current_view->text->UpdateInset(inset)){
4042 current_view->update();
4044 if (current_view->buffer()->isLyxClean())
4045 current_view->owner()->getMiniBuffer()->setTimer(4);
4046 current_view->buffer()->markDirty();
4048 current_view->updateScrollbar();
4053 /* first check the current buffer */
4054 if (current_view->available()){
4055 current_view->getScreen()->HideCursor();
4056 current_view->update(-3);
4057 if (current_view->text->UpdateInset(inset)){
4059 current_view->update(1);
4061 current_view->update(3);
4066 // check all buffers
4067 bufferlist.updateInset(inset, mark_dirty);
4072 // candidate for move to BufferView
4073 /* these functions return 1 if an error occured,
4075 int LockInset(UpdatableInset * inset)
4077 if (!current_view->buffer()->the_locking_inset && inset){
4078 current_view->buffer()->the_locking_inset = inset;
4085 // candidate for move to BufferView
4086 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
4088 if (current_view->buffer()->the_locking_inset &&
4089 current_view->getScreen()){
4090 y += current_view->text->cursor.y;
4091 current_view->getScreen()->ShowManualCursor(x, y,
4097 // candidate for move to BufferView
4098 void HideLockedInsetCursor(long x, long y, int asc, int desc)
4100 if (current_view->buffer()->the_locking_inset &&
4101 current_view->getScreen()){
4102 y += current_view->text->cursor.y;
4103 current_view->getScreen()->HideManualCursor(x, y,
4109 // candidate for move to BufferView
4110 void FitLockedInsetCursor(long x, long y, int asc, int desc)
4112 if (current_view->buffer()->the_locking_inset &&
4113 current_view->getScreen()){
4114 y += current_view->text->cursor.y;
4115 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
4116 current_view->updateScrollbar();
4121 // candidate for move to BufferView
4122 int UnlockInset(UpdatableInset * inset)
4125 current_view->buffer()->the_locking_inset == inset){
4126 inset->InsetUnlock();
4127 current_view->buffer()->the_locking_inset = 0;
4128 current_view->text->FinishUndo();
4131 return bufferlist.unlockInset(inset);
4135 // candidate for move to BufferView
4136 void LockedInsetStoreUndo(Undo::undo_kind kind)
4138 if (!current_view->buffer()->the_locking_inset)
4139 return; // shouldn't happen
4140 if (kind == Undo::EDIT) // in this case insets would not be stored!
4141 kind = Undo::FINISH;
4142 current_view->text->SetUndo(kind,
4143 current_view->text->cursor.par->
4144 ParFromPos(current_view->text->cursor.pos)->previous,
4145 current_view->text->cursor.par->
4146 ParFromPos(current_view->text->cursor.pos)->next);
4150 void PutInsetIntoInsetUpdateList(Inset * inset)
4153 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4155 tmp->next = InsetUpdateList;
4156 InsetUpdateList = tmp;
4161 void UpdateInsetUpdateList()
4163 InsetUpdateStruct * tmp = InsetUpdateList;
4165 UpdateInset(tmp->inset, false); // "false" because no document change
4169 // delete the update list
4170 while (InsetUpdateList) {
4171 tmp = InsetUpdateList;
4172 InsetUpdateList = InsetUpdateList->next;
4175 InsetUpdateList = 0;
4179 #ifdef WITH_WARNINGS
4182 // I know we shouldn't put anything in here but this seems the fastest
4183 // way to do this (and the cleanest for now). This function just inserts
4184 // a newline in the string and the inserts 'depth'-spaces so that the
4185 // code is indented in the right way!!!
4186 void addNewlineAndDepth(string & file, int const depth)
4189 file.append(depth, ' ');