1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
20 #include "support/lstrings.h"
22 #include FORMS_H_LOCATION
24 #include "layout_forms.h"
25 #include "bullet_forms.h"
26 #include "print_form.h"
28 #include "spellchecker.h"
32 #include "insets/insetref.h"
33 #include "insets/insetquotes.h"
35 #include "insets/insetlatex.h"
37 #include "insets/insetlabel.h"
38 #include "insets/insetinfo.h"
39 #include "insets/insetspecialchar.h"
40 #include "insets/figinset.h"
42 #include "latexoptions.h"
44 #include "minibuffer.h"
46 #include "bufferlist.h"
47 #include "support/filetools.h"
48 #include "support/path.h"
50 #include "lyx_gui_misc.h"
51 #include "LyXView.h" // only because of form_main
52 #include "lastfiles.h"
53 #include "support/FileInfo.h"
54 #include "lyxscreen.h"
56 #include "support/syscall.h"
57 #include "support/lyxlib.h"
58 #include "lyxserver.h"
59 #include "FontLoader.h"
65 extern MiniBuffer * minibuffer;
66 extern Combox * combo_language;
67 extern BufferList bufferlist;
68 extern void show_symbols_form();
69 extern FD_form_main * fd_form_main;
70 extern FD_form_title * fd_form_title;
71 extern FD_form_paragraph * fd_form_paragraph;
72 extern FD_form_character * fd_form_character;
73 extern FD_form_document * fd_form_document;
74 extern FD_form_quotes * fd_form_quotes;
75 extern FD_form_preamble * fd_form_preamble;
76 extern FD_form_table * fd_form_table;
77 extern FD_form_print * fd_form_print;
78 extern FD_form_figure * fd_form_figure;
79 extern FD_form_screen * fd_form_screen;
80 extern FD_form_toc * fd_form_toc;
81 extern FD_form_ref * fd_form_ref;
82 extern FD_LaTeXOptions * fd_latex_options;
83 extern FD_form_bullet * fd_form_bullet;
85 extern BufferView * current_view; // called too many times in this file...
87 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
89 extern bool send_fax(string const & fname, string const & sendcmd);
91 extern LyXServer * lyxserver;
92 extern FontLoader fontloader;
94 // this should be static, but I need it in buffer.C
95 bool quitting; // flag, that we are quitting the program
96 extern bool finished; // all cleanup done just let it run through now.
98 char ascii_type; /* for selection notify callbacks */
100 bool scrolling = false;
102 char updatetimer = 0;
104 /* whether the work area should get callbacks */
105 bool input_prohibited = false;
107 /* the selection possible is needed, that only motion events are
108 * used, where the bottom press event was on the drawing area too */
109 bool selection_possible = false;
111 // This is used to make the dreaded font toggle problem hopefully go
112 // away. Definitely not the best solution, but I think it sorta works.
113 bool toggleall = true;
115 void InsertCorrectQuote();
119 This is the inset locking stuff needed for mathed --------------------
121 an inset can simple call LockInset in it's edit call and *ONLY* in it's
123 Inset::Edit() can only be called by the main lyx module.
125 Then the inset may modify the menu's and/or iconbars.
127 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
129 During the lock, all button and keyboard events will be modified
130 and send to the inset through the following inset-features. Note that
131 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
132 to contain the code for restoring the menus and things like this.
135 virtual void InsetButtonPress(int x, int y, int button);
136 virtual void InsetButtonRelease(int x, int y, int button);
137 virtual void InsetKeyPress(XKeyEvent *ev);
138 virtual void InsetMotionNotify(int x, int y, int state);
139 virtual void InsetUnlock();
141 If a inset wishes any redraw and/or update it just has to call
143 It's is completly irrelevant, where the inset is. UpdateInset will
144 find it in any paragraph in any buffer.
145 Of course the_locking_inset and the insets in the current paragraph/buffer
146 are checked first, so no performance problem should occur.
148 Hope that's ok for the beginning, Alejandro,
149 sorry that I needed so much time,
154 void UpdateInset(Inset * inset, bool mark_dirty = true);
155 /* these functions return 1 if an error occured,
157 // Now they work only for updatable insets. [Alejandro 080596]
158 int LockInset(UpdatableInset * inset);
159 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
160 void FitLockedInsetCursor(long x, long y, int asc, int desc);
161 int UnlockInset(UpdatableInset * inset);
162 void LockedInsetStoreUndo(Undo::undo_kind kind);
164 /* this is for asyncron updating. UpdateInsetUpdateList will be called
165 automatically from LyX. Just insert the Inset into the Updatelist */
166 void UpdateInsetUpdateList();
167 void PutInsetIntoInsetUpdateList(Inset * inset);
169 InsetUpdateStruct * InsetUpdateList = 0;
173 -----------------------------------------------------------------------
176 /* some function prototypes */
183 void HyphenationPoint();
184 void MenuSeparator();
187 void ProtectedBlank();
189 int RunLinuxDoc(int, string const &);
190 int RunDocBook(int, string const &);
191 void MenuWrite(Buffer * buf);
192 void MenuWriteAs(Buffer * buffer);
193 void MenuReload(Buffer * buf);
194 void MenuLayoutSave();
196 unsigned char GetCurrentTextClass()
197 // Who are we asking?
198 // Shouldn't this question be directed to the buffer?
199 // Indeed it should. Asger.
201 return current_view->buffer()->params.textclass;
205 // How should this actually work? Should it prohibit input in all BufferViews,
206 // or just in the current one? If "just the current one", then it should be
207 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
208 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
209 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
210 // current LyxView that should be prohibited (Lgb) (This applies to
211 // "AllowInput" as well.)
214 input_prohibited = true;
215 if (current_view->getScreen())
216 current_view->getScreen()->HideCursor();
218 static Cursor cursor;
219 static bool cursor_undefined = true;
221 if (cursor_undefined){
222 cursor = XCreateFontCursor(fl_display, XC_watch);
224 cursor_undefined = false;
227 /* set the cursor to the watch for all forms and the canvas */
228 XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
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, fd_form_main->form_main->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(fd_form_main->form_main->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(fd_form_main->timer_update, time);
296 current_view->getScreen()->ToggleSelection();
297 current_view->buffer()->text->ClearSelection();
302 void SmallUpdate(signed char f)
304 current_view->getScreen()->SmallUpdate();
305 if (current_view->getScreen()->TopCursorVisible()
306 != current_view->getScreen()->first){
307 current_view->buffer()->update(f);
311 current_view->fitCursor();
312 current_view->updateScrollbar();
314 if (!current_view->buffer()->text->selection)
315 current_view->buffer()->text->sel_cursor =
316 current_view->buffer()->text->cursor;
318 if (f == 1 || f == -1) {
319 if (current_view->buffer()->isLyxClean()) {
320 current_view->buffer()->markDirty();
321 minibuffer->setTimer(4);
324 current_view->buffer()->markDirty();
338 // should be moved to lyxfunc.C
339 void MenuWrite(Buffer * buf)
342 if (!bufferlist.write(buf)) {
343 string fname = buf->getFileName();
344 string s = MakeAbsPath(fname);
345 if (AskQuestion(_("Save failed. Rename and try again?"),
346 MakeDisplayPath(s, 50),
347 _("(If not, document is not saved.)"))) {
351 lastfiles->newFile(buf->getFileName());
356 // should be moved to BufferView.C
357 void MenuWriteAs(Buffer * buffer)
359 if (!buffer->text) return;
361 string fname = buffer->getFileName();
362 string oldname = fname;
366 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
367 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
369 if (!IsLyXFilename(fname))
372 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
375 OnlyFilename(fname));
379 minibuffer->Set(_("Canceled."));
383 // Make sure the absolute filename ends with appropriate suffix
384 string s = MakeAbsPath(fname);
385 if (!IsLyXFilename(s))
388 // Same name as we have already?
390 if (!AskQuestion(_("Same name as document already has:"),
391 MakeDisplayPath(s, 50),
394 // Falls through to name change and save
396 // No, but do we have another file with this name open?
397 else if (bufferlist.exists(s)) {
398 if (AskQuestion(_("Another document with same name open!"),
399 MakeDisplayPath(s, 50),
400 _("Replace with current document?")))
402 bufferlist.close(bufferlist.getBuffer(s));
404 // Ok, change the name of the buffer, but don't save!
405 buffer->setFileName(s);
408 minibuffer->Set(_("Document renamed to '"),
410 _("', but not saved..."));
413 } // Check whether the file exists
416 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
417 MakeDisplayPath(s, 50),
422 // Ok, change the name of the buffer
423 buffer->setFileName(s);
426 // Small bug: If the save fails, we have irreversible changed the name
432 int MenuRunLaTeX(Buffer * buffer)
436 if (buffer->isLinuxDoc())
437 ret = RunLinuxDoc(1, buffer->getFileName());
438 else if (buffer->isLiterate())
439 ret = buffer->runLiterate();
440 else if (buffer->isDocBook())
441 ret = RunDocBook(1, buffer->getFileName());
443 ret = buffer->runLaTeX();
449 s = _("One error detected");
450 t = _("You should try to fix it.");
453 s += _(" errors detected.");
454 t = _("You should try to fix them.");
456 WriteAlert(_("There were errors during the LaTeX run."), s, t);
462 int MenuBuildProg(Buffer * buffer)
466 if (buffer->isLiterate())
467 ret = buffer->buildProgram();
469 string s = _("Wrong type of document");
470 string t = _("The Build operation is not allowed in this document");
471 WriteAlert(_("There were errors during the Build process."), s, t);
479 s = _("One error detected");
480 t = _("You should try to fix it.");
483 s += _(" errors detected.");
484 t = _("You should try to fix them.");
486 WriteAlert(_("There were errors during the Build process."), s, t);
492 int MenuRunChktex(Buffer * buffer)
496 if (buffer->isSGML()) {
497 WriteAlert(_("Chktex does not work with SGML derived documents."));
500 ret = buffer->runChktex();
506 s = _("No warnings found.");
507 } else if (ret == 1) {
508 s = _("One warning found.");
509 t = _("Use 'Edit->Go to Error' to find it.");
512 s += _(" warnings found.");
513 t = _("Use 'Edit->Go to Error' to find them.");
515 WriteAlert(_("Chktex run successfully"), s, t);
517 WriteAlert(_("Error!"), _("It seems chktex does not work."));
523 int MakeDVIOutput(Buffer * buffer)
530 string path = OnlyPath(buffer->getFileName());
531 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
532 path = buffer->tmppath;
534 if (!buffer->isDviClean()) {
536 ret = MenuRunLaTeX(buffer);
542 /* wait == false means don't wait for termination */
543 /* wait == true means wait for termination */
544 // The bool should be placed last on the argument line. (Lgb)
545 // Returns false if we fail.
546 bool RunScript(Buffer * buffer, bool wait,
547 string const & command,
548 string const & orgname = string(),
549 bool need_shell = true)
553 string name = orgname;
556 if (MakeDVIOutput(buffer) > 0)
558 /* get DVI-Filename */
560 name = ChangeExtension(buffer->getFileName(),
563 path = OnlyPath(name);
564 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
565 path = buffer->tmppath;
569 cmd = command + ' ' + SpaceLess(name);
577 // OS/2 cmd.exe has another use for '&'
579 // This is not NLS safe, but it's OK, I think.
580 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
582 // COMSPEC is set, unless user unsets
583 sh = OnlyFilename(GetEnvPath("COMSPEC"));
588 if (contains(sh, "cmd.exe")
589 || contains(sh, "4os2.exe"))
590 cmd = "start /min/n " + cmd;
595 // It seems that, if wait is false, we never get back
596 // the return code of the command. This means that all
597 // the code I added in PrintApplyCB is currently
600 #warning What should we do here?
602 minibuffer->Set(_("Executing command:"), cmd);
603 result = one.startscript(Systemcalls::System, cmd);
605 minibuffer->Set(_("Executing command:"), cmd);
606 result = one.startscript(wait ? Systemcalls::Wait
607 : Systemcalls::DontWait, cmd);
609 return (result == 0);
613 // Returns false if we fail
614 bool MenuRunDvips(Buffer * buffer, bool wait = false)
622 if (MakeDVIOutput(buffer) > 0) {
626 // Generate postscript file
627 string ps = ChangeExtension (buffer->getFileName(),
632 char real_papersize = buffer->params.papersize;
633 if (real_papersize == BufferParams::PAPER_DEFAULT)
634 real_papersize = lyxrc->default_papersize;
636 switch (real_papersize) {
637 case BufferParams::PAPER_USLETTER:
640 case BufferParams::PAPER_A3PAPER:
643 case BufferParams::PAPER_A4PAPER:
646 case BufferParams::PAPER_A5PAPER:
649 case BufferParams::PAPER_B5PAPER:
652 case BufferParams::PAPER_EXECUTIVEPAPER:
655 case BufferParams::PAPER_LEGALPAPER:
658 default: /* If nothing else fits, keep an empty value... */
662 // Make postscript file.
663 string command = "dvips " + lyxrc->print_to_file + ' ';
664 command += SpaceLess(ps);
665 if (buffer->params.use_geometry
666 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
667 && !lyxrc->print_paper_dimension_flag.empty()
668 && !buffer->params.paperwidth.empty()
669 && !buffer->params.paperheight.empty()) {
670 // using a custom papersize
672 command += lyxrc->print_paper_dimension_flag + ' ';
673 command += buffer->params.paperwidth + ',';
674 command += buffer->params.paperheight;
675 } else if (!paper.empty()
676 && (real_papersize != BufferParams::PAPER_USLETTER ||
677 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
678 // dvips won't accept -t letter -t landscape. In all other
679 // cases, include the paper size explicitly.
681 command += lyxrc->print_paper_flag + ' ' + paper;
683 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
685 command += lyxrc->print_landscape_flag;
687 // push directorypath, if necessary
688 string path = OnlyPath(buffer->getFileName());
689 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
690 path = buffer->tmppath;
693 bool ret = RunScript(buffer, wait, command);
699 // Returns false if we fail
700 bool MenuPreviewPS(Buffer * buffer)
705 // Generate postscript file
706 if (!MenuRunDvips(buffer, true)) {
710 // Start postscript viewer
712 string ps = ChangeExtension (buffer->getFileName(),
714 // push directorypath, if necessary
715 string path = OnlyPath(buffer->getFileName());
716 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
717 path = buffer->tmppath;
720 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
726 void MenuFax(Buffer * buffer)
731 // Generate postscript file
732 if (!MenuRunDvips(buffer, true)) {
737 string ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true);
738 string path = OnlyPath (buffer->getFileName());
739 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
740 path = buffer->tmppath;
743 if (!lyxrc->fax_program.empty()) {
744 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
746 Systemcalls one(Systemcalls::System, help2);
748 send_fax(ps, lyxrc->fax_command);
752 // Returns false if we fail
753 bool MenuPreview(Buffer * buffer)
760 char real_papersize = buffer->params.papersize;
761 if (real_papersize == BufferParams::PAPER_DEFAULT)
762 real_papersize = lyxrc->default_papersize;
764 switch (real_papersize) {
765 case BufferParams::PAPER_USLETTER:
768 case BufferParams::PAPER_A3PAPER:
771 case BufferParams::PAPER_A4PAPER:
774 case BufferParams::PAPER_A5PAPER:
777 case BufferParams::PAPER_B5PAPER:
780 case BufferParams::PAPER_EXECUTIVEPAPER:
783 case BufferParams::PAPER_LEGALPAPER:
786 default: /* If nothing else fits, keep the empty value */
791 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
792 // we HAVE to give a size when the page is in
793 // landscape, so use USletter.
794 paper = " -paper usr";
796 paper = " -paper " + paper;
797 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
801 // push directorypath, if necessary
802 string path = OnlyPath(buffer->getFileName());
803 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
804 path = buffer->tmppath;
808 string command = lyxrc->view_dvi_command + paper ;
809 bool ret = RunScript(buffer, false, command);
814 void MenuMakeLaTeX(Buffer * buffer)
817 // Get LaTeX-Filename
818 string s = SpaceLess(ChangeExtension(
819 buffer->getFileName(),
824 !AskQuestion(_("File already exists:"),
825 MakeDisplayPath(s, 50),
826 _("Do you want to overwrite the file?"))) {
827 minibuffer->Set(_("Canceled"));
831 if (buffer->isDocBook())
832 minibuffer->Set(_("DocBook does not have a latex backend"));
834 if (buffer->isLinuxDoc())
835 RunLinuxDoc(0, buffer->getFileName());
837 buffer->makeLaTeXFile(s, string(), true);
838 minibuffer->Set(_("Nice LaTeX file saved as"),
840 buffer->markDviDirty();
846 void MenuMakeLinuxDoc(Buffer * buffer)
849 if (!buffer->isLinuxDoc()) {
850 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
854 // Get LinuxDoc-Filename
855 string s = ChangeExtension (buffer->getFileName(),
860 !AskQuestion(_("File already exists:"),
861 MakeDisplayPath(s, 50),
862 _("Do you want to overwrite the file?"))) {
863 minibuffer->Set(_("Canceled"));
867 minibuffer->Set(_("Building LinuxDoc SGML file `"),
868 MakeDisplayPath(s), "'...");
870 buffer->makeLinuxDocFile(s, 65);
872 minibuffer->Set(_("LinuxDoc SGML file save as"),
878 void MenuMakeDocBook(Buffer * buffer)
881 if (!buffer->isDocBook()) {
882 WriteAlert(_("Error!"),
883 _("Document class must be docbook."));
887 // Get DocBook-Filename
888 string s = ChangeExtension (buffer->getFileName(),
893 !AskQuestion(_("File already exists:"),
894 MakeDisplayPath(s, 50),
895 _("Do you want to overwrite the file?"))) {
896 minibuffer->Set(_("Canceled"));
900 minibuffer->Set(_("Building DocBook SGML file `"),
901 MakeDisplayPath(s), "'...");
903 buffer->makeDocBookFile(s, 65);
905 minibuffer->Set(_("DocBook SGML file save as"),
911 void MenuMakeAscii(Buffer * buffer)
914 /* get LaTeX-Filename */
915 string s = ChangeExtension (buffer->getFileName(),
920 !AskQuestion(_("File already exists:"),
921 MakeDisplayPath(s, 50),
922 _("Do you want to overwrite the file?"))) {
923 minibuffer->Set(_("Canceled"));
927 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
929 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
934 void MenuPrint(Buffer * buffer)
939 string input_file = ChangeExtension(buffer->getFileName(),
940 lyxrc->print_file_extension,
942 fl_set_input(fd_form_print->input_file, input_file.c_str());
944 if (fd_form_print->form_print->visible) {
945 fl_raise_form(fd_form_print->form_print);
948 fl_show_form(fd_form_print->form_print,
949 FL_PLACE_MOUSE, FL_FULLBORDER,
957 lyxerr.debug() << "Running QuitLyX." << endl;
959 if (!bufferlist.QwriteAll())
962 lastfiles->writeFile(lyxrc->lastfiles);
964 // Set a flag that we do quitting from the program,
965 // so no refreshes are necessary.
968 // close buffers first
969 bufferlist.closeAll();
971 // do any other cleanup procedures now
972 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
974 DestroyLyXTmpDir(system_tempdir);
982 // should probably be moved into BufferList (Lgb)
983 // Perfect target for a thread...
985 if (!current_view->getScreen() || !current_view->available())
988 if (current_view->buffer()->isBakClean()
989 || current_view->buffer()->isReadonly()) {
990 // We don't save now, but we'll try again later
991 current_view->owner()->resetAutosaveTimer();
995 minibuffer->Set(_("Autosaving current document..."));
997 // create autosave filename
998 string fname = OnlyPath(current_view->buffer()->getFileName());
1000 fname += OnlyFilename(current_view->buffer()->getFileName());
1003 // tmp_ret will be located (usually) in /tmp
1004 // will that be a problem?
1005 string tmp_ret = tmpnam(0);
1007 pid_t pid = fork(); // If you want to debug the autosave
1008 // you should set pid to -1, and comment out the
1010 if (pid == 0 || pid == -1) {
1011 // pid = -1 signifies that lyx was unable
1012 // to fork. But we will do the save
1014 bool failed = false;
1015 if (!tmp_ret.empty()) {
1016 current_view->buffer()->writeFile(tmp_ret, 1);
1017 // assume successful write of tmp_ret
1018 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1020 // most likely couldn't move between filesystems
1021 // unless write of tmp_ret failed
1022 // so remove tmp file (if it exists)
1023 remove(tmp_ret.c_str());
1030 // failed to write/rename tmp_ret so try writing direct
1031 if (!current_view->buffer()->writeFile(fname, 1)) {
1032 // It is dangerous to do this in the child,
1033 // but safe in the parent, so...
1035 minibuffer->Set(_("Autosave Failed!"));
1038 if (pid == 0) { // we are the child so...
1043 current_view->buffer()->markBakClean();
1044 current_view->owner()->resetAutosaveTimer();
1049 // (c) CHT Software Service GmbH
1052 // create new file with template
1055 Buffer * NewLyxFile(string const & filename)
1057 // Split argument by :
1059 string tmpname = split(filename, name, ':');
1060 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1061 if (name.length() == 1
1062 && isalpha(static_cast<unsigned char>(name[0]))
1063 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1065 name += token(tmpname, ':', 0);
1066 tmpname = split(tmpname, ':');
1069 lyxerr.debug() << "Arg is " << filename
1070 << "\nName is " << name
1071 << "\nTemplate is " << tmpname << endl;
1073 // find a free buffer
1074 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1076 lastfiles->newFile(tmpbuf->getFileName());
1081 // Insert ascii file (if filename is empty, prompt for one)
1082 void InsertAsciiFile(string const & f, bool asParagraph)
1087 if (!current_view->getScreen()) return;
1089 if (fname.empty()) {
1091 fname = fileDlg.Select(_("File to Insert"),
1092 current_view->owner()->buffer()->filepath,
1095 if (fname.empty()) return;
1100 if (!fi.readable()) {
1101 WriteFSAlert(_("Error! Specified file is unreadable: "),
1102 MakeDisplayPath(fname, 50));
1106 FilePtr myfile(fname, FilePtr::read);
1108 WriteFSAlert(_("Error! Cannot open specified file: "),
1109 MakeDisplayPath(fname, 50));
1112 LyXParagraph * tmppar = new LyXParagraph;
1113 tmppar->readSimpleWholeFile(myfile);
1115 // set the end of the string
1116 #ifdef WITH_WARNINGS
1117 #warning why do we do this?
1119 // I don't think this is needed. Actually it might be plain wrong.
1120 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1122 // insert the string
1123 current_view->getScreen()->HideCursor();
1125 // clear the selection
1128 current_view->buffer()->text->InsertStringA(tmppar->text);
1130 current_view->buffer()->text->InsertStringB(tmppar->text);
1132 current_view->buffer()->update(1);
1136 void MenuShowTableOfContents()
1138 static int ow = -1, oh;
1141 if (fd_form_toc->form_toc->visible) {
1142 fl_raise_form(fd_form_toc->form_toc);
1144 fl_show_form(fd_form_toc->form_toc,
1145 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1146 _("Table Of Contents"));
1148 ow = fd_form_toc->form_toc->w;
1149 oh = fd_form_toc->form_toc->h;
1151 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1156 void MenuInsertLabel(char const * arg)
1160 //string label = fl_show_input(_("Enter new label to insert:"), "");
1162 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1163 if (!label.empty()) {
1164 InsetLabel * new_inset = new InsetLabel;
1165 new_inset->setContents(label);
1166 current_view->buffer()->insertInset(new_inset);
1172 void MenuInsertRef()
1174 static int ow = -1, oh;
1177 if (fd_form_ref->form_ref->visible) {
1178 fl_raise_form(fd_form_ref->form_ref);
1180 fl_show_form(fd_form_ref->form_ref,
1181 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1182 _("Insert Reference"));
1184 ow = fd_form_ref->form_ref->w;
1185 oh = fd_form_ref->form_ref->h;
1187 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1192 void MenuPasteSelection(char at)
1194 if (!current_view->getScreen())
1199 Atom data_prop = XInternAtom(fl_display,
1202 if (data_prop == None)
1204 XConvertSelection(fl_display,
1205 XA_PRIMARY, XA_STRING, data_prop,
1206 fd_form_main->form_main->window, 0);
1211 extern "C" void FootCB(FL_OBJECT *, long)
1213 if (!current_view->available())
1216 minibuffer->Set(_("Inserting Footnote..."));
1217 current_view->getScreen()->HideCursor();
1218 current_view->buffer()->update(-2);
1219 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1220 current_view->buffer()->update(1);
1224 void LayoutsCB(int sel, void *)
1226 string tmp = tostr(sel);
1227 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1233 * SGML Linuxdoc support:
1234 * (flag == -1) import SGML file
1235 * (flag == 0) make TeX output
1236 * (flag == 1) make dvi output
1238 int RunLinuxDoc(int flag, string const & filename)
1247 /* generate a path-less extension name */
1248 name = ChangeExtension (filename, ".sgml", true);
1249 path = OnlyPath (filename);
1250 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1251 path = current_view->buffer()->tmppath;
1256 if (!current_view->available())
1258 current_view->buffer()->makeLinuxDocFile(name, 0);
1259 #ifdef WITH_WARNINGS
1260 #warning remove this once we have a proper geometry class
1262 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1264 case BufferParams::PAPER_A4PAPER:
1265 add_flags = "-p a4";
1267 case BufferParams::PAPER_USLETTER:
1268 add_flags = "-p letter";
1270 default: /* nothing to be done yet ;-) */ break;
1278 case -1: /* Import file */
1279 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1280 MakeDisplayPath(filename), "'...");
1281 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1283 if (one.startscript(Systemcalls::System, s2))
1286 case 0: /* TeX output asked */
1287 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1288 s2 = "sgml2latex " + add_flags + " -o tex "
1289 + lyxrc->sgml_extra_options + ' ' + name;
1290 if (one.startscript(Systemcalls::System, s2))
1293 case 1: /* dvi output asked */
1294 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1295 s2 = "sgml2latex " + add_flags + " -o dvi "
1296 + lyxrc->sgml_extra_options + ' ' + name;
1297 if (one.startscript(Systemcalls::System, s2)) {
1300 current_view->buffer()->markDviClean();
1302 default: /* unknown output */
1308 current_view->buffer()->redraw();
1314 * SGML DocBook support:
1315 * (flag == 1) make dvi output
1317 int RunDocBook(int flag, string const & filename)
1319 /* generate a path-less extension name */
1320 string name = ChangeExtension (filename, ".sgml", true);
1321 string path = OnlyPath (filename);
1322 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1323 path = current_view->buffer()->tmppath;
1327 if (!current_view->available())
1330 current_view->buffer()->makeDocBookFile(name, 0);
1332 // Shall this code go or should it stay? (Lgb)
1333 // string add_flags;
1334 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1336 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1337 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1338 // default: /* nothing to be done yet ;-) */ break;
1345 case 1: /* dvi output asked */
1347 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1348 string s2 = "sgmltools --backend dvi " + name;
1349 if (one.startscript(Systemcalls::System, s2)) {
1352 current_view->buffer()->markDviClean();
1355 default: /* unknown output */
1361 current_view->buffer()->redraw();
1366 void AllFloats(char flag, char figmar)
1368 if (!current_view->available())
1371 LyXCursor cursor = current_view->buffer()->text->cursor;
1373 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1375 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1376 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1378 && cursor.par->footnotekind != LyXParagraph::FIG
1379 && cursor.par->footnotekind != LyXParagraph::TAB
1380 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1381 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1382 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1387 LyXCursor tmpcursor = cursor;
1388 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1389 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1391 LyXParagraph *par = current_view->buffer()->paragraph;
1394 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1396 && par->footnotekind != LyXParagraph::FOOTNOTE
1397 && par->footnotekind != LyXParagraph::MARGIN)
1399 && par->footnotekind != LyXParagraph::FIG
1400 && par->footnotekind != LyXParagraph::TAB
1401 && par->footnotekind != LyXParagraph::WIDE_FIG
1402 && par->footnotekind != LyXParagraph::WIDE_TAB
1403 && par->footnotekind != LyXParagraph::ALGORITHM
1408 && par->previous->footnoteflag !=
1409 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1410 current_view->buffer()->text->SetCursorIntern(par->previous,
1412 current_view->buffer()->text->OpenFootnote();
1417 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1421 par->footnotekind != LyXParagraph::FOOTNOTE
1423 par->footnotekind != LyXParagraph::MARGIN
1428 par->footnotekind != LyXParagraph::FIG
1430 par->footnotekind != LyXParagraph::TAB
1432 par->footnotekind != LyXParagraph::WIDE_FIG
1434 par->footnotekind != LyXParagraph::WIDE_TAB
1436 par->footnotekind != LyXParagraph::ALGORITHM
1440 current_view->buffer()->text->SetCursorIntern(par, 0);
1441 current_view->buffer()->text->CloseFootnote();
1447 current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1448 current_view->redraw();
1449 current_view->fitCursor();
1450 current_view->updateScrollbar();
1454 void MenuLayoutCharacter()
1456 static int ow = -1, oh;
1458 if (fd_form_character->form_character->visible) {
1459 fl_raise_form(fd_form_character->form_character);
1461 fl_show_form(fd_form_character->form_character,
1462 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1463 _("Character Style"));
1465 ow = fd_form_character->form_character->w;
1466 oh = fd_form_character->form_character->h;
1468 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1473 inline void DeactivateParagraphButtons ()
1475 fl_deactivate_object (fd_form_paragraph->button_ok);
1476 fl_deactivate_object (fd_form_paragraph->button_apply);
1477 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1478 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1482 inline void ActivateParagraphButtons ()
1484 fl_activate_object (fd_form_paragraph->button_ok);
1485 fl_activate_object (fd_form_paragraph->button_apply);
1486 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1487 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1491 inline void DisableParagraphLayout ()
1493 DeactivateParagraphButtons();
1494 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1495 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1496 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1497 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1498 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1499 fl_deactivate_object (fd_form_paragraph->check_noindent);
1500 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1501 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1502 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1503 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1504 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1505 fl_deactivate_object (fd_form_paragraph->input_space_above);
1506 fl_deactivate_object (fd_form_paragraph->input_space_below);
1507 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1508 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1509 fl_deactivate_object (fd_form_paragraph->check_space_above);
1510 fl_deactivate_object (fd_form_paragraph->check_space_below);
1514 inline void EnableParagraphLayout ()
1516 ActivateParagraphButtons();
1517 fl_activate_object (fd_form_paragraph->input_labelwidth);
1518 fl_activate_object (fd_form_paragraph->check_lines_top);
1519 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1520 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1521 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1522 fl_activate_object (fd_form_paragraph->check_noindent);
1523 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1524 fl_activate_object (fd_form_paragraph->radio_align_right);
1525 fl_activate_object (fd_form_paragraph->radio_align_left);
1526 fl_activate_object (fd_form_paragraph->radio_align_block);
1527 fl_activate_object (fd_form_paragraph->radio_align_center);
1528 fl_activate_object (fd_form_paragraph->input_space_above);
1529 fl_activate_object (fd_form_paragraph->input_space_below);
1530 fl_activate_object (fd_form_paragraph->choice_space_above);
1531 fl_activate_object (fd_form_paragraph->choice_space_below);
1532 fl_activate_object (fd_form_paragraph->check_space_above);
1533 fl_activate_object (fd_form_paragraph->check_space_below);
1537 bool UpdateLayoutParagraph()
1539 if (!current_view->getScreen() || !current_view->available()) {
1540 if (fd_form_paragraph->form_paragraph->visible)
1541 fl_hide_form(fd_form_paragraph->form_paragraph);
1545 Buffer * buf = current_view->buffer();
1547 fl_set_input(fd_form_paragraph->input_labelwidth,
1548 buf->text->cursor.par->GetLabelWidthString().c_str());
1549 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1550 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1551 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1552 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1554 int align = buf->text->cursor.par->GetAlign();
1555 if (align == LYX_ALIGN_LAYOUT)
1556 align = textclasslist.Style(buf->params.textclass,
1557 buf->text->cursor.par->GetLayout()).align;
1560 case LYX_ALIGN_RIGHT:
1561 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1563 case LYX_ALIGN_LEFT:
1564 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1566 case LYX_ALIGN_CENTER:
1567 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1570 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1574 fl_set_button(fd_form_paragraph->check_lines_top,
1575 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1576 fl_set_button(fd_form_paragraph->check_lines_bottom,
1577 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1578 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1579 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1580 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1581 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1582 fl_set_button(fd_form_paragraph->check_noindent,
1583 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1584 fl_set_input (fd_form_paragraph->input_space_above, "");
1586 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1588 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1590 case VSpace::DEFSKIP:
1591 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1593 case VSpace::SMALLSKIP:
1594 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1596 case VSpace::MEDSKIP:
1597 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1599 case VSpace::BIGSKIP:
1600 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1603 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1605 case VSpace::LENGTH:
1606 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1607 fl_set_input (fd_form_paragraph->input_space_above,
1608 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1611 fl_set_button (fd_form_paragraph->check_space_above,
1612 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1613 fl_set_input (fd_form_paragraph->input_space_below, "");
1614 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1616 fl_set_choice (fd_form_paragraph->choice_space_below,
1619 case VSpace::DEFSKIP:
1620 fl_set_choice (fd_form_paragraph->choice_space_below,
1623 case VSpace::SMALLSKIP:
1624 fl_set_choice (fd_form_paragraph->choice_space_below,
1627 case VSpace::MEDSKIP:
1628 fl_set_choice (fd_form_paragraph->choice_space_below,
1631 case VSpace::BIGSKIP:
1632 fl_set_choice (fd_form_paragraph->choice_space_below,
1636 fl_set_choice (fd_form_paragraph->choice_space_below,
1639 case VSpace::LENGTH:
1640 fl_set_choice (fd_form_paragraph->choice_space_below,
1642 fl_set_input (fd_form_paragraph->input_space_below,
1643 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1646 fl_set_button (fd_form_paragraph->check_space_below,
1647 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1649 fl_set_button(fd_form_paragraph->check_noindent,
1650 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1652 if (current_view->buffer()->isReadonly()) {
1653 DisableParagraphLayout();
1655 EnableParagraphLayout();
1661 void MenuLayoutParagraph()
1663 if (UpdateLayoutParagraph()) {
1664 if (fd_form_paragraph->form_paragraph->visible) {
1665 fl_raise_form(fd_form_paragraph->form_paragraph);
1667 fl_show_form(fd_form_paragraph->form_paragraph,
1668 FL_PLACE_MOUSE, FL_FULLBORDER,
1669 _("Paragraph Environment"));
1676 void DeactivateDocumentButtons ()
1678 fl_deactivate_object (fd_form_document->button_ok);
1679 fl_deactivate_object (fd_form_document->button_apply);
1680 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1681 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1686 void ActivateDocumentButtons ()
1688 fl_activate_object (fd_form_document->button_ok);
1689 fl_activate_object (fd_form_document->button_apply);
1690 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1691 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1696 void DisableDocumentLayout ()
1698 DeactivateDocumentButtons ();
1699 fl_deactivate_object (fd_form_document->group_radio_separation);
1700 fl_deactivate_object (fd_form_document->radio_indent);
1701 fl_deactivate_object (fd_form_document->radio_skip);
1702 fl_deactivate_object (fd_form_document->choice_class);
1703 fl_deactivate_object (fd_form_document->choice_pagestyle);
1704 fl_deactivate_object (fd_form_document->choice_fonts);
1705 fl_deactivate_object (fd_form_document->choice_fontsize);
1706 fl_deactivate_object (fd_form_document->input_float_placement);
1707 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1708 fl_deactivate_object (fd_form_document->choice_inputenc);
1709 fl_deactivate_object (fd_form_document->group_radio_sides);
1710 fl_deactivate_object (fd_form_document->radio_sides_one);
1711 fl_deactivate_object (fd_form_document->radio_sides_two);
1712 fl_deactivate_object (fd_form_document->group_radio_columns);
1713 fl_deactivate_object (fd_form_document->radio_columns_one);
1714 fl_deactivate_object (fd_form_document->radio_columns_two);
1715 fl_deactivate_object (fd_form_document->input_extra);
1716 fl_deactivate_object (fd_form_document->choice_language);
1717 combo_language->deactivate();
1718 fl_deactivate_object (fd_form_document->input_default_skip);
1719 fl_deactivate_object (fd_form_document->choice_default_skip);
1720 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1721 fl_deactivate_object (fd_form_document->slider_tocdepth);
1722 fl_deactivate_object (fd_form_document->choice_spacing);
1723 fl_deactivate_object (fd_form_document->input_spacing);
1724 fl_deactivate_object (fd_form_document->check_use_amsmath);
1729 void EnableDocumentLayout ()
1731 ActivateDocumentButtons ();
1732 fl_activate_object (fd_form_document->group_radio_separation);
1733 fl_activate_object (fd_form_document->radio_indent);
1734 fl_activate_object (fd_form_document->radio_skip);
1735 fl_activate_object (fd_form_document->choice_class);
1736 fl_activate_object (fd_form_document->choice_pagestyle);
1737 fl_activate_object (fd_form_document->choice_fonts);
1738 fl_activate_object (fd_form_document->choice_fontsize);
1739 fl_activate_object (fd_form_document->input_float_placement);
1740 fl_activate_object (fd_form_document->choice_postscript_driver);
1741 fl_activate_object (fd_form_document->choice_inputenc);
1742 fl_activate_object (fd_form_document->group_radio_sides);
1743 fl_activate_object (fd_form_document->radio_sides_one);
1744 fl_activate_object (fd_form_document->radio_sides_two);
1745 fl_activate_object (fd_form_document->group_radio_columns);
1746 fl_activate_object (fd_form_document->radio_columns_one);
1747 fl_activate_object (fd_form_document->radio_columns_two);
1748 fl_activate_object (fd_form_document->input_extra);
1749 fl_activate_object (fd_form_document->choice_language);
1750 combo_language->activate();
1751 fl_activate_object (fd_form_document->input_default_skip);
1752 fl_activate_object (fd_form_document->choice_default_skip);
1753 fl_activate_object (fd_form_document->slider_secnumdepth);
1754 fl_activate_object (fd_form_document->slider_tocdepth);
1755 fl_activate_object (fd_form_document->choice_spacing);
1756 fl_activate_object (fd_form_document->input_spacing);
1757 fl_activate_object (fd_form_document->check_use_amsmath);
1761 bool UpdateLayoutDocument(BufferParams * params)
1763 if (!current_view->getScreen() || !current_view->available()) {
1764 if (fd_form_document->form_document->visible)
1765 fl_hide_form(fd_form_document->form_document);
1770 params = ¤t_view->buffer()->params;
1771 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1773 fl_set_choice_text(fd_form_document->choice_class,
1774 textclasslist.DescOfClass(params->textclass).c_str());
1775 combo_language->select_text(params->language.c_str());
1777 fl_set_choice_text(fd_form_document->choice_fonts,
1778 params->fonts.c_str());
1779 fl_set_choice_text(fd_form_document->choice_inputenc,
1780 params->inputenc.c_str());
1781 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1782 params->graphicsDriver.c_str());
1784 // ale970405+lasgoutt970513
1785 fl_clear_choice(fd_form_document->choice_fontsize);
1786 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1787 fl_addto_choice(fd_form_document->choice_fontsize,
1788 tclass.opt_fontsize().c_str());
1789 fl_set_choice(fd_form_document->choice_fontsize,
1790 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1792 // ale970405+lasgoutt970513
1793 fl_clear_choice(fd_form_document->choice_pagestyle);
1794 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1795 fl_addto_choice(fd_form_document->choice_pagestyle,
1796 tclass.opt_pagestyle().c_str());
1798 fl_set_choice(fd_form_document->choice_pagestyle,
1799 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1801 fl_set_button(fd_form_document->radio_indent, 0);
1802 fl_set_button(fd_form_document->radio_skip, 0);
1805 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1807 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1808 fl_set_button(fd_form_document->radio_indent, 1);
1810 fl_set_button(fd_form_document->radio_skip, 1);
1812 switch (params->getDefSkip().kind()) {
1813 case VSpace::SMALLSKIP:
1814 fl_set_choice (fd_form_document->choice_default_skip, 1);
1816 case VSpace::MEDSKIP:
1817 fl_set_choice (fd_form_document->choice_default_skip, 2);
1819 case VSpace::BIGSKIP:
1820 fl_set_choice (fd_form_document->choice_default_skip, 3);
1822 case VSpace::LENGTH:
1823 fl_set_choice (fd_form_document->choice_default_skip, 4);
1824 fl_set_input (fd_form_document->input_default_skip,
1825 params->getDefSkip().asLyXCommand().c_str());
1828 fl_set_choice (fd_form_document->choice_default_skip, 2);
1832 fl_set_button(fd_form_document->radio_sides_one, 0);
1833 fl_set_button(fd_form_document->radio_sides_two, 0);
1835 if (params->sides == 2)
1836 fl_set_button(fd_form_document->radio_sides_two, 1);
1838 fl_set_button(fd_form_document->radio_sides_one, 1);
1840 fl_set_button(fd_form_document->radio_columns_one, 0);
1841 fl_set_button(fd_form_document->radio_columns_two, 0);
1843 if (params->columns == 2)
1844 fl_set_button(fd_form_document->radio_columns_two, 1);
1846 fl_set_button(fd_form_document->radio_columns_one, 1);
1848 fl_set_input(fd_form_document->input_spacing, "");
1849 switch (params->spacing.getSpace()) {
1850 case Spacing::Single:
1853 fl_set_choice(fd_form_document->choice_spacing, 1);
1856 case Spacing::Onehalf:
1859 fl_set_choice(fd_form_document->choice_spacing, 2);
1862 case Spacing::Double:
1865 fl_set_choice(fd_form_document->choice_spacing, 3);
1868 case Spacing::Other:
1870 fl_set_choice(fd_form_document->choice_spacing, 4);
1872 sprintf(sval, "%g", params->spacing.getValue());
1873 fl_set_input(fd_form_document->input_spacing, sval);
1879 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1880 params->secnumdepth);
1881 fl_set_counter_value(fd_form_document->slider_tocdepth,
1883 if (!params->float_placement.empty()) { // buffer local (Lgb)
1884 fl_set_input(fd_form_document->input_float_placement,
1885 params->float_placement.c_str());
1887 fl_set_input(fd_form_document->input_float_placement, "");
1889 if (!params->options.empty())
1890 fl_set_input(fd_form_document->input_extra,
1891 params->options.c_str());
1893 fl_set_input(fd_form_document->input_extra, "");
1895 if (current_view->buffer()->isSGML()) {
1896 // bullets not used in SGML derived documents
1897 fl_deactivate_object(fd_form_document->button_bullets);
1898 fl_set_object_lcol(fd_form_document->button_bullets,
1901 fl_activate_object(fd_form_document->button_bullets);
1902 fl_set_object_lcol(fd_form_document->button_bullets,
1906 if (current_view->buffer()->isReadonly()) {
1907 DisableDocumentLayout();
1909 EnableDocumentLayout();
1916 void MenuLayoutDocument()
1918 if (UpdateLayoutDocument()) {
1919 if (fd_form_document->form_document->visible) {
1920 fl_raise_form(fd_form_document->form_document);
1922 fl_show_form(fd_form_document->form_document,
1923 FL_PLACE_MOUSE, FL_FULLBORDER,
1924 _("Document Layout"));
1930 bool UpdateLayoutQuotes()
1933 if (!current_view->getScreen()
1934 || !current_view->available()
1935 || current_view->buffer()->isReadonly())
1939 fl_set_choice(fd_form_quotes->choice_quotes_language,
1940 current_view->buffer()->params.quotes_language + 1);
1941 fl_set_button(fd_form_quotes->radio_single, 0);
1942 fl_set_button(fd_form_quotes->radio_double, 0);
1944 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1945 fl_set_button(fd_form_quotes->radio_single, 1);
1947 fl_set_button(fd_form_quotes->radio_double, 1);
1948 } else if (fd_form_quotes->form_quotes->visible) {
1949 fl_hide_form(fd_form_quotes->form_quotes);
1955 void MenuLayoutQuotes()
1957 if (UpdateLayoutQuotes()) {
1958 if (fd_form_quotes->form_quotes->visible) {
1959 fl_raise_form(fd_form_quotes->form_quotes);
1961 fl_show_form(fd_form_quotes->form_quotes,
1962 FL_PLACE_MOUSE, FL_FULLBORDER,
1969 bool UpdateLayoutPreamble()
1972 if (!current_view->getScreen() || ! current_view->available())
1976 fl_set_input(fd_form_preamble->input_preamble,
1977 current_view->buffer()->params.preamble.c_str());
1979 if (current_view->buffer()->isReadonly()) {
1980 fl_deactivate_object(fd_form_preamble->input_preamble);
1981 fl_deactivate_object(fd_form_preamble->button_ok);
1982 fl_deactivate_object(fd_form_preamble->button_apply);
1983 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1984 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1987 fl_activate_object(fd_form_preamble->input_preamble);
1988 fl_activate_object(fd_form_preamble->button_ok);
1989 fl_activate_object(fd_form_preamble->button_apply);
1990 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1991 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1993 } else if (fd_form_preamble->form_preamble->visible) {
1994 fl_hide_form(fd_form_preamble->form_preamble);
1999 void MenuLayoutPreamble()
2001 static int ow = -1, oh;
2003 if (UpdateLayoutPreamble()) {
2004 if (fd_form_preamble->form_preamble->visible) {
2005 fl_raise_form(fd_form_preamble->form_preamble);
2007 fl_show_form(fd_form_preamble->form_preamble,
2008 FL_PLACE_MOUSE | FL_FREE_SIZE,
2010 _("LaTeX Preamble"));
2012 ow = fd_form_preamble->form_preamble->w;
2013 oh = fd_form_preamble->form_preamble->h;
2015 fl_set_form_minsize(fd_form_preamble->form_preamble,
2022 void MenuLayoutSave()
2024 if (!current_view->getScreen() || ! current_view->available())
2027 if (AskQuestion(_("Do you want to save the current settings"),
2028 _("for Character, Document, Paper and Quotes"),
2029 _("as default for new documents?")))
2030 current_view->buffer()->saveParamsAsDefaults();
2036 InsetInfo * new_inset = new InsetInfo();
2037 current_view->buffer()->insertInset(new_inset);
2038 new_inset->Edit(0, 0);
2044 if (current_view->available()) {
2045 minibuffer->Set(_("Open/Close..."));
2046 current_view->getScreen()->HideCursor();
2048 current_view->buffer()->update(-2);
2049 current_view->buffer()->text->OpenStuff();
2050 current_view->buffer()->update(0);
2057 if (current_view->available()) {
2058 minibuffer->Set(_("Open/Close..."));
2059 current_view->getScreen()->HideCursor();
2061 current_view->buffer()->update(-2);
2062 current_view->buffer()->text->ToggleFootnote();
2063 current_view->buffer()->update(0);
2070 /* if (current_view->buffer()->the_locking_inset) {
2071 minibuffer->Set(_("Undo not yet supported in math mode"));
2075 if (current_view->available()) {
2076 minibuffer->Set(_("Undo"));
2077 current_view->getScreen()->HideCursor();
2079 current_view->buffer()->update(-2);
2080 if (!current_view->buffer()->text->TextUndo())
2081 minibuffer->Set(_("No further undo information"));
2083 current_view->buffer()->update(-1);
2090 if (current_view->buffer()->the_locking_inset) {
2091 minibuffer->Set(_("Redo not yet supported in math mode"));
2095 if (current_view->available()) {
2096 minibuffer->Set(_("Redo"));
2097 current_view->getScreen()->HideCursor();
2099 current_view->buffer()->update(-2);
2100 if (!current_view->buffer()->text->TextRedo())
2101 minibuffer->Set(_("No further redo information"));
2103 current_view->buffer()->update(-1);
2108 void HyphenationPoint()
2110 if (current_view->available()) {
2111 current_view->getScreen()->HideCursor();
2112 current_view->buffer()->update(-2);
2113 InsetSpecialChar * new_inset =
2114 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2115 current_view->buffer()->insertInset(new_inset);
2122 if (current_view->available()) {
2123 current_view->getScreen()->HideCursor();
2124 current_view->buffer()->update(-2);
2125 InsetSpecialChar * new_inset =
2126 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2127 current_view->buffer()->insertInset(new_inset);
2132 void EndOfSentenceDot()
2134 if (current_view->available()) {
2135 current_view->getScreen()->HideCursor();
2136 current_view->buffer()->update(-2);
2137 InsetSpecialChar * new_inset =
2138 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2139 current_view->buffer()->insertInset(new_inset);
2144 void MenuSeparator()
2146 if (current_view->available()) {
2147 current_view->getScreen()->HideCursor();
2148 current_view->buffer()->update(-2);
2149 InsetSpecialChar * new_inset =
2150 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2151 current_view->buffer()->insertInset(new_inset);
2158 if (current_view->available()) {
2159 current_view->getScreen()->HideCursor();
2160 current_view->buffer()->update(-2);
2161 current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
2162 current_view->buffer()->update(-1);
2167 void ProtectedBlank()
2169 if (current_view->available()) {
2170 current_view->getScreen()->HideCursor();
2171 current_view->buffer()->update(-2);
2172 current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2173 current_view->buffer()->update(-1);
2180 if (current_view->available()) {
2181 current_view->getScreen()->HideCursor();
2182 current_view->buffer()->update(-2);
2183 current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL);
2184 current_view->buffer()->update(-1);
2189 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2190 They also show the current font state. */
2193 void ToggleAndShow(LyXFont const &);
2196 void FontSizeCB(string const & size)
2198 LyXFont font(LyXFont::ALL_IGNORE);
2199 font.setGUISize(size);
2200 ToggleAndShow(font);
2206 LyXFont font(LyXFont::ALL_IGNORE);
2207 font.setEmph(LyXFont::TOGGLE);
2208 ToggleAndShow(font);
2214 LyXFont font(LyXFont::ALL_IGNORE);
2215 font.setNoun(LyXFont::TOGGLE);
2216 ToggleAndShow(font);
2222 LyXFont font(LyXFont::ALL_IGNORE);
2223 font.setSeries(LyXFont::BOLD_SERIES);
2224 ToggleAndShow(font);
2230 LyXFont font(LyXFont::ALL_IGNORE);
2231 font.setUnderbar(LyXFont::TOGGLE);
2232 ToggleAndShow(font);
2238 LyXFont font(LyXFont::ALL_IGNORE);
2239 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2240 ToggleAndShow(font);
2246 LyXFont font(LyXFont::ALL_IGNORE);
2247 font.setFamily(LyXFont::SANS_FAMILY);
2248 ToggleAndShow(font);
2254 LyXFont font(LyXFont::ALL_IGNORE);
2255 font.setFamily(LyXFont::ROMAN_FAMILY);
2256 ToggleAndShow(font);
2262 LyXFont font(LyXFont::ALL_IGNORE);
2263 font.setLatex (LyXFont::TOGGLE);
2264 ToggleAndShow(font);
2270 LyXFont font(LyXFont::ALL_INHERIT);
2271 ToggleAndShow(font);
2275 /* -------> Returns the current font and depth by printing a message. In the
2276 * future perhaps we could try to implement a callback to the button-bar.
2277 * That is, `light' the bold button when the font is currently bold, etc.
2279 string CurrentState()
2282 if (current_view->available()) {
2283 // I think we should only show changes from the default
2285 Buffer * buffer = current_view->buffer();
2286 LyXFont font = buffer->text->real_current_font;
2287 LyXFont defaultfont = textclasslist.TextClass(buffer->
2288 params.textclass).defaultfont();
2289 font.reduce(defaultfont);
2290 state = _("Font: ") + font.stateText();
2292 int depth = buffer->text->GetDepth();
2294 state += string(_(", Depth: ")) + tostr(depth);
2300 /* -------> Does the actual toggle job of the XxxCB() calls above.
2301 * Also shows the current font state.
2304 void ToggleAndShow(LyXFont const & font)
2306 if (current_view->available()) {
2307 current_view->getScreen()->HideCursor();
2308 current_view->buffer()->update(-2);
2309 current_view->buffer()->text->ToggleFree(font, toggleall);
2310 current_view->buffer()->update(1);
2312 // removed since it overrides the ToggleFree Message about the style
2313 // Since Styles are more "High Level" than raw fonts I think the user
2314 // prefers it like this Matthias
2315 // FontStateShowCB( 0, 0 );
2319 extern "C" void MarginCB(FL_OBJECT *, long)
2321 if (current_view->available()) {
2322 minibuffer->Set(_("Inserting margin note..."));
2323 current_view->getScreen()->HideCursor();
2324 current_view->buffer()->update(-2);
2325 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2326 current_view->buffer()->update(1);
2331 extern "C" void FigureCB(FL_OBJECT *, long)
2333 if (fd_form_figure->form_figure->visible) {
2334 fl_raise_form(fd_form_figure->form_figure);
2336 fl_show_form(fd_form_figure->form_figure,
2337 FL_PLACE_MOUSE, FL_FULLBORDER,
2338 _("Insert Figure"));
2343 extern "C" void TableCB(FL_OBJECT *, long)
2345 if (fd_form_table->form_table->visible) {
2346 fl_raise_form(fd_form_table->form_table);
2348 fl_show_form(fd_form_table->form_table,
2349 FL_PLACE_MOUSE, FL_FULLBORDER,
2355 void CopyEnvironmentCB()
2357 if (current_view->available()) {
2358 current_view->buffer()->text->copyEnvironmentType();
2359 /* clear the selection, even if mark_set */
2360 current_view->getScreen()->ToggleSelection();
2361 current_view->buffer()->text->ClearSelection();
2362 current_view->buffer()->update(-2);
2363 minibuffer->Set(_("Paragraph environment type copied"));
2368 void PasteEnvironmentCB()
2370 if (current_view->available()) {
2371 current_view->buffer()->text->pasteEnvironmentType();
2372 minibuffer->Set(_("Paragraph environment type set"));
2373 current_view->buffer()->update(1);
2380 if (current_view->available()) {
2381 current_view->buffer()->text->CopySelection();
2382 /* clear the selection, even if mark_set */
2383 current_view->getScreen()->ToggleSelection();
2384 current_view->buffer()->text->ClearSelection();
2385 current_view->buffer()->update(-2);
2386 minibuffer->Set(_("Copy"));
2393 if (current_view->available()) {
2394 current_view->getScreen()->HideCursor();
2395 current_view->buffer()->update(-2);
2396 current_view->buffer()->text->CutSelection();
2397 current_view->buffer()->update(1);
2398 minibuffer->Set(_("Cut"));
2405 if (!current_view->available()) return;
2407 minibuffer->Set(_("Paste"));
2408 current_view->getScreen()->HideCursor();
2409 /* clear the selection */
2410 current_view->getScreen()->ToggleSelection();
2411 current_view->buffer()->text->ClearSelection();
2412 current_view->buffer()->update(-2);
2415 current_view->buffer()->text->PasteSelection();
2416 current_view->buffer()->update(1);
2418 /* clear the selection */
2419 current_view->getScreen()->ToggleSelection();
2420 current_view->buffer()->text->ClearSelection();
2421 current_view->buffer()->update(-2);
2425 extern "C" void MeltCB(FL_OBJECT *, long)
2427 if (!current_view->available()) return;
2429 minibuffer->Set(_("Melt"));
2430 current_view->getScreen()->HideCursor();
2432 current_view->buffer()->update(-2);
2433 current_view->buffer()->text->MeltFootnoteEnvironment();
2434 current_view->buffer()->update(1);
2438 // Change environment depth.
2439 // if decInc == 0, depth change taking mouse button number into account
2440 // if decInc == 1, increment depth
2441 // if decInc == -1, decrement depth
2442 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2446 /* When decInc != 0, fake a mouse button. This allows us to
2447 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2448 /* check out wether ob is defined, too (Matthias) */
2451 else if (!decInc && ob) {
2452 button = fl_get_button_numb(ob);
2455 if (current_view->available()) {
2456 current_view->getScreen()->HideCursor();
2457 current_view->buffer()->update(-2);
2459 current_view->buffer()->text->IncDepth();
2461 current_view->buffer()->text->DecDepth();
2462 current_view->buffer()->update(1);
2463 minibuffer->Set(_("Changed environment depth"
2464 " (in possible range, maybe not)"));
2469 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2470 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2471 LyXFont UserFreeFont()
2473 LyXFont font(LyXFont::ALL_IGNORE);
2475 int pos = fl_get_choice(fd_form_character->choice_family);
2477 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2478 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2479 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2480 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2481 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2484 pos = fl_get_choice(fd_form_character->choice_series);
2486 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2487 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2488 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2489 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2492 pos = fl_get_choice(fd_form_character->choice_shape);
2494 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2495 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2496 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2497 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2498 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2499 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2502 pos = fl_get_choice(fd_form_character->choice_size);
2504 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2505 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2506 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2507 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2508 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2509 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2510 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2511 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2512 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2513 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2514 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2515 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2516 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2517 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2520 pos = fl_get_choice(fd_form_character->choice_bar);
2522 case 1: font.setEmph(LyXFont::IGNORE);
2523 font.setUnderbar(LyXFont::IGNORE);
2524 font.setNoun(LyXFont::IGNORE);
2525 font.setLatex(LyXFont::IGNORE);
2527 case 2: font.setEmph(LyXFont::TOGGLE); break;
2528 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2529 case 4: font.setNoun(LyXFont::TOGGLE); break;
2530 case 5: font.setLatex(LyXFont::TOGGLE); break;
2531 case 6: font.setEmph(LyXFont::INHERIT);
2532 font.setUnderbar(LyXFont::INHERIT);
2533 font.setNoun(LyXFont::INHERIT);
2534 font.setLatex(LyXFont::INHERIT);
2538 pos = fl_get_choice(fd_form_character->choice_color);
2540 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2541 case 2: font.setColor(LyXFont::NONE); break;
2542 case 3: font.setColor(LyXFont::BLACK); break;
2543 case 4: font.setColor(LyXFont::WHITE); break;
2544 case 5: font.setColor(LyXFont::RED); break;
2545 case 6: font.setColor(LyXFont::GREEN); break;
2546 case 7: font.setColor(LyXFont::BLUE); break;
2547 case 8: font.setColor(LyXFont::CYAN); break;
2548 case 9: font.setColor(LyXFont::MAGENTA); break;
2549 case 10: font.setColor(LyXFont::YELLOW); break;
2550 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2559 ToggleAndShow(UserFreeFont());
2563 /* callbacks for form form_title */
2564 extern "C" void TimerCB(FL_OBJECT *, long)
2566 // only if the form still exists
2567 if (fd_form_title->form_title != 0) {
2568 if (fd_form_title->form_title->visible) {
2569 fl_hide_form(fd_form_title->form_title);
2571 fl_free_form(fd_form_title->form_title);
2572 fd_form_title->form_title = 0;
2577 /* callbacks for form form_paragraph */
2579 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2581 // "Synchronize" the choices and input fields, making it
2582 // impossible to commit senseless data.
2584 FD_form_paragraph const * fp = fd_form_paragraph;
2586 if (obj == fp->choice_space_above) {
2587 if (fl_get_choice (fp->choice_space_above) != 7) {
2588 fl_set_input (fp->input_space_above, "");
2589 ActivateParagraphButtons();
2591 } else if (obj == fp->choice_space_below) {
2592 if (fl_get_choice (fp->choice_space_below) != 7) {
2593 fl_set_input (fp->input_space_below, "");
2594 ActivateParagraphButtons();
2596 } else if (obj == fp->input_space_above) {
2597 string input = fl_get_input (fp->input_space_above);
2599 if (input.empty()) {
2600 fl_set_choice (fp->choice_space_above, 1);
2601 ActivateParagraphButtons();
2603 else if (isValidGlueLength (input)) {
2604 fl_set_choice (fp->choice_space_above, 7);
2605 ActivateParagraphButtons();
2608 fl_set_choice (fp->choice_space_above, 7);
2609 DeactivateParagraphButtons();
2611 } else if (obj == fp->input_space_below) {
2612 string input = fl_get_input (fp->input_space_below);
2614 if (input.empty()) {
2615 fl_set_choice (fp->choice_space_below, 1);
2616 ActivateParagraphButtons();
2618 else if (isValidGlueLength (input)) {
2619 fl_set_choice (fp->choice_space_below, 7);
2620 ActivateParagraphButtons();
2623 fl_set_choice (fp->choice_space_below, 7);
2624 DeactivateParagraphButtons();
2630 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2632 if (!current_view->available())
2635 VSpace space_top, space_bottom;
2637 string labelwidthstring;
2640 // If a vspace kind is "Length" but there's no text in
2641 // the input field, reset the kind to "None".
2642 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2643 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2644 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2646 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2647 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2648 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2651 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2652 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2653 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2654 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2655 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2656 case 1: space_top = VSpace(VSpace::NONE); break;
2657 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2658 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2659 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2660 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2661 case 6: space_top = VSpace(VSpace::VFILL); break;
2662 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2664 if (fl_get_button (fd_form_paragraph->check_space_above))
2665 space_top.setKeep (true);
2666 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2667 case 1: space_bottom = VSpace(VSpace::NONE); break;
2668 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2669 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2670 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2671 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2672 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2673 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2675 if (fl_get_button (fd_form_paragraph->check_space_below))
2676 space_bottom.setKeep (true);
2678 if (fl_get_button(fd_form_paragraph->radio_align_left))
2679 align = LYX_ALIGN_LEFT;
2680 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2681 align = LYX_ALIGN_RIGHT;
2682 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2683 align = LYX_ALIGN_CENTER;
2685 align = LYX_ALIGN_BLOCK;
2687 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2688 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2690 current_view->buffer()->text->SetParagraph(line_top,
2699 current_view->buffer()->update(1);
2700 minibuffer->Set(_("Paragraph layout set"));
2704 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2706 fl_hide_form(fd_form_paragraph->form_paragraph);
2710 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2712 ParagraphApplyCB(ob, data);
2713 ParagraphCancelCB(ob, data);
2717 /* callbacks for form form_character */
2719 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2721 // we set toggleall locally here, since it should be true for
2722 // all other uses of ToggleAndShow() (JMarc)
2723 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2724 ToggleAndShow( UserFreeFont());
2729 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2731 fl_hide_form(fd_form_character->form_character);
2735 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2737 CharacterApplyCB(ob, data);
2738 CharacterCloseCB(ob, data);
2742 /* callbacks for form form_document */
2744 void UpdateDocumentButtons(BufferParams const & params)
2746 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2748 if (params.sides == 2)
2749 fl_set_button(fd_form_document->radio_sides_two, 1);
2751 fl_set_button(fd_form_document->radio_sides_one, 1);
2753 if (params.columns == 2)
2754 fl_set_button(fd_form_document->radio_columns_two, 1);
2756 fl_set_button(fd_form_document->radio_columns_one, 1);
2758 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2759 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2760 params.secnumdepth);
2761 fl_set_counter_value(fd_form_document->slider_tocdepth,
2766 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2769 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2770 if (AskQuestion(_("Should I set some parameters to"),
2771 fl_get_choice_text(ob),
2772 _("the defaults of this document class?"))) {
2773 BufferParams params = BufferParams();
2774 params.textclass = fl_get_choice(ob)-1;
2775 params.useClassDefaults();
2776 UpdateLayoutDocument(¶ms);
2777 UpdateDocumentButtons(params);
2780 // unable to load new style
2781 WriteAlert(_("Conversion Errors!"),
2782 _("Unable to switch to new document class."),
2783 _("Reverting to original document class."));
2784 fl_set_choice(fd_form_document->choice_class,
2785 GetCurrentTextClass() + 1);
2791 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2793 // "Synchronize" the choice and the input field, so that it
2794 // is impossible to commit senseless data.
2795 FD_form_document const * fd = fd_form_document;
2797 if (obj == fd->choice_default_skip) {
2798 if (fl_get_choice (fd->choice_default_skip) != 4) {
2799 fl_set_input (fd->input_default_skip, "");
2800 ActivateDocumentButtons();
2802 } else if (obj == fd->input_default_skip) {
2804 char const * input = fl_get_input (fd->input_default_skip);
2807 fl_set_choice (fd->choice_default_skip, 2);
2808 ActivateDocumentButtons();
2809 } else if (isValidGlueLength (input)) {
2810 fl_set_choice (fd->choice_default_skip, 4);
2811 ActivateDocumentButtons();
2813 fl_set_choice (fd->choice_default_skip, 4);
2814 DeactivateDocumentButtons();
2820 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2822 // "Synchronize" the choice and the input field, so that it
2823 // is impossible to commit senseless data.
2824 FD_form_document const * fd = fd_form_document;
2826 if (obj == fd->choice_spacing
2827 && fl_get_choice (fd->choice_spacing) != 4) {
2828 fl_set_input(fd->input_spacing, "");
2829 } else if (obj == fd->input_spacing) {
2831 const char* input = fl_get_input (fd->input_spacing);
2834 fl_set_choice (fd->choice_spacing, 1);
2836 fl_set_choice (fd->choice_spacing, 4);
2842 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2845 BufferParams *params = &(current_view->buffer()->params);
2846 current_view->buffer()->params.language =
2847 combo_language->getline();
2849 // If default skip is a "Length" but there's no text in the
2850 // input field, reset the kind to "Medskip", which is the default.
2851 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2852 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2853 fl_set_choice (fd_form_document->choice_default_skip, 2);
2856 /* this shouldn't be done automatically IMO. For example I write german
2857 * documents with an american keyboard very often. Matthias */
2859 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2860 fl_get_choice(fd_form_document->choice_language)); */
2862 fl_get_choice_text(fd_form_document->choice_fonts);
2864 fl_get_choice_text(fd_form_document->choice_inputenc);
2866 fl_get_choice_text(fd_form_document->choice_fontsize);
2868 fl_get_choice_text(fd_form_document->choice_pagestyle);
2869 params->graphicsDriver =
2870 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2871 params->use_amsmath =
2872 fl_get_button(fd_form_document->check_use_amsmath);
2874 if (!current_view->available())
2877 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2878 if (params->textclass != new_class) {
2879 // try to load new_class
2880 if (textclasslist.Load(new_class)) {
2881 // successfully loaded
2883 minibuffer->Set(_("Converting document to new document class..."));
2884 int ret = current_view->buffer()->
2886 SwitchLayoutsBetweenClasses(current_view->buffer()->
2889 current_view->buffer()->
2895 s = _("One paragraph couldn't be converted");
2898 s += _(" paragraphs couldn't be converted");
2900 WriteAlert(_("Conversion Errors!"), s,
2901 _("into chosen document class"));
2904 params->textclass = new_class;
2906 // problem changing class -- warn user and retain old style
2907 WriteAlert(_("Conversion Errors!"),
2908 _("Unable to switch to new document class."),
2909 _("Reverting to original document class."));
2910 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2914 char tmpsep = params->paragraph_separation;
2915 if (fl_get_button(fd_form_document->radio_indent))
2916 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2918 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2919 if (tmpsep != params->paragraph_separation)
2922 VSpace tmpdefskip = params->getDefSkip();
2923 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2924 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2925 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2926 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2927 case 4: params->setDefSkip(
2928 VSpace (LyXGlueLength (fl_get_input
2929 (fd_form_document->input_default_skip))));
2931 // DocumentDefskipCB assures that this never happens
2932 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2934 if (!(tmpdefskip == params->getDefSkip()))
2937 if (fl_get_button(fd_form_document->radio_columns_two))
2938 params->columns = 2;
2940 params->columns = 1;
2941 if (fl_get_button(fd_form_document->radio_sides_two))
2942 params->sides = LyXTextClass::TwoSides;
2944 params->sides = LyXTextClass::OneSide;
2946 Spacing tmpSpacing = params->spacing;
2947 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2949 lyxerr.debug() << "Spacing: SINGLE" << endl;
2950 params->spacing.set(Spacing::Single);
2953 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2954 params->spacing.set(Spacing::Onehalf);
2957 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2958 params->spacing.set(Spacing::Double);
2961 lyxerr.debug() << "Spacing: OTHER" << endl;
2962 params->spacing.set(Spacing::Other,
2963 fl_get_input(fd_form_document->input_spacing));
2966 if (tmpSpacing != params->spacing)
2969 signed char tmpchar =
2970 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2971 if (params->secnumdepth != tmpchar)
2973 params->secnumdepth = tmpchar;
2976 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2978 params->float_placement =
2979 fl_get_input(fd_form_document->input_float_placement);
2981 // More checking should be done to ensure the string doesn't have
2982 // spaces or illegal placement characters in it. (thornley)
2985 current_view->redoCurrentBuffer();
2987 minibuffer->Set(_("Document layout set"));
2988 current_view->buffer()->markDirty();
2991 fl_get_input(fd_form_document->input_extra);
2996 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2998 fl_hide_form(fd_form_document->form_document);
3002 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3004 DocumentCancelCB(ob, data);
3005 DocumentApplyCB(ob, data);
3009 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3012 // bullet callbacks etc. in bullet_panel.C -- ARRae
3018 if (!current_view->getScreen())
3021 current_view->getScreen()->HideCursor();
3023 current_view->buffer()->update(-2);
3026 if (!current_view->buffer()->text->GotoNextNote()) {
3027 if (current_view->buffer()->text->cursor.pos
3028 || current_view->buffer()->text->cursor.par !=
3029 current_view->buffer()->text->FirstParagraph())
3031 tmp = current_view->buffer()->text->cursor;
3032 current_view->buffer()->text->cursor.par =
3033 current_view->buffer()->text->FirstParagraph();
3034 current_view->buffer()->text->cursor.pos = 0;
3035 if (!current_view->buffer()->text->GotoNextNote()) {
3036 current_view->buffer()->text->cursor = tmp;
3037 minibuffer->Set(_("No more notes"));
3041 minibuffer->Set(_("No more notes"));
3045 current_view->buffer()->update(0);
3046 current_view->buffer()->text->sel_cursor =
3047 current_view->buffer()->text->cursor;
3051 void InsertCorrectQuote()
3053 Buffer * cbuffer = current_view->buffer();
3056 if (cbuffer->text->cursor.pos )
3057 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3061 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3065 /* callbacks for form form_quotes */
3067 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3069 if (!current_view->available())
3072 minibuffer->Set(_("Quotes type set"));
3073 //current_view->buffer()->params.quotes_language =
3074 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3075 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3076 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3078 lga = InsetQuotes::EnglishQ;
3081 lga = InsetQuotes::SwedishQ;
3084 lga = InsetQuotes::GermanQ;
3087 lga = InsetQuotes::PolishQ;
3090 lga = InsetQuotes::FrenchQ;
3093 lga = InsetQuotes::DanishQ;
3096 current_view->buffer()->params.quotes_language = lga;
3097 if (fl_get_button(fd_form_quotes->radio_single))
3098 current_view->buffer()->
3099 params.quotes_times = InsetQuotes::SingleQ;
3101 current_view->buffer()->
3102 params.quotes_times = InsetQuotes::DoubleQ;
3106 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3108 fl_hide_form(fd_form_quotes->form_quotes);
3112 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3114 QuotesApplyCB(ob, data);
3115 QuotesCancelCB(ob, data);
3120 /* callbacks for form form_preamble */
3122 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3124 fl_hide_form(fd_form_preamble->form_preamble);
3128 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3130 if (!current_view->available())
3133 current_view->buffer()->params.preamble =
3134 fl_get_input(fd_form_preamble->input_preamble);
3135 current_view->buffer()->markDirty();
3136 minibuffer->Set(_("LaTeX preamble set"));
3140 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3142 PreambleApplyCB(ob, data);
3143 PreambleCancelCB(ob, data);
3147 /* callbacks for form form_table */
3149 extern "C" void TableApplyCB(FL_OBJECT *, long)
3151 if (!current_view->getScreen())
3154 // check for tables in tables
3155 if (current_view->buffer()->text->cursor.par->table){
3156 WriteAlert(_("Impossible Operation!"),
3157 _("Cannot insert table in table."),
3162 minibuffer->Set(_("Inserting table..."));
3164 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3165 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3168 current_view->getScreen()->HideCursor();
3170 current_view->buffer()->update(-2);
3172 current_view->buffer()->text->SetCursorParUndo();
3173 current_view->buffer()->text->FreezeUndo();
3175 current_view->buffer()->text->BreakParagraph();
3176 current_view->buffer()->update(-1);
3178 if (current_view->buffer()->text->cursor.par->Last()) {
3179 current_view->buffer()->text->CursorLeft();
3181 current_view->buffer()->text->BreakParagraph();
3182 current_view->buffer()->update(-1);
3185 current_view->buffer()->text->current_font.setLatex(LyXFont::OFF);
3186 //if (!fl_get_button(fd_form_table->check_latex)){
3187 // insert the new wysiwy table
3188 current_view->buffer()->text->SetLayout(0); // standard layout
3189 if (current_view->buffer()->text->cursor.par->footnoteflag ==
3190 LyXParagraph::NO_FOOTNOTE) {
3191 current_view->buffer()->
3192 text->SetParagraph(0, 0,
3194 VSpace (0.3 * current_view->buffer()->
3195 params.spacing.getValue(),
3197 VSpace (0.3 * current_view->buffer()->
3198 params.spacing.getValue(),
3205 current_view->buffer()->
3206 text->SetParagraph(0, 0,
3208 VSpace(VSpace::NONE),
3209 VSpace(VSpace::NONE),
3214 current_view->buffer()->text->cursor.par->table =
3215 new LyXTable(xsize, ysize);
3217 for (int i = 0; i < xsize * ysize - 1; ++i)
3218 current_view->buffer()->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3219 current_view->buffer()->text->RedoParagraph();
3221 current_view->buffer()->text->UnFreezeUndo();
3223 current_view->buffer()->update(1);
3224 minibuffer->Set(_("Table inserted"));
3228 extern "C" void TableCancelCB(FL_OBJECT *, long)
3230 fl_hide_form(fd_form_table->form_table);
3234 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3236 TableApplyCB(ob, data);
3237 TableCancelCB(ob, data);
3241 /* callbacks for form form_print */
3243 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3245 fl_hide_form(fd_form_print->form_print);
3248 static bool stringOnlyContains (string const & LStr, char const * cset)
3250 char const * cstr = LStr.c_str() ;
3252 return strspn(cstr, cset) == strlen(cstr) ;
3255 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3257 if (!current_view->available())
3259 Buffer * buffer = current_view->buffer();
3260 string path = OnlyPath(buffer->getFileName());
3263 if (fl_get_button(fd_form_print->radio_even_pages))
3264 pageflag = lyxrc->print_evenpage_flag + ' ';
3265 else if (fl_get_button(fd_form_print->radio_odd_pages))
3266 pageflag = lyxrc->print_oddpage_flag + ' ';
3268 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3269 // User may give a page (range) list
3270 // User may print multiple (unsorted) copies
3271 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3272 pages = subst(pages, '+',',');
3273 pages = frontStrip(strip(pages)) ;
3274 while (!pages.empty()) { // a page range was given
3276 pages = split (pages, piece, ',') ;
3277 piece = strip(piece) ;
3278 piece = frontStrip(piece) ;
3279 if ( !stringOnlyContains (piece, "0123456789-") ) {
3280 WriteAlert(_("ERROR! Unable to print!"),
3281 _("Check 'range of pages'!"));
3284 if (piece.find('-') == string::npos) { // not found
3285 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3286 } else if (suffixIs(piece, "-") ) { // missing last page
3287 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3288 } else if (prefixIs(piece, "-") ) { // missing first page
3289 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3291 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3295 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3296 if (!copies.empty()) { // a number of copies was given
3297 if ( !stringOnlyContains (copies, "0123456789") ) {
3298 WriteAlert(_("ERROR! Unable to print!"),
3299 _("Check 'number of copies'!"));
3302 if (fl_get_button(fd_form_print->do_unsorted))
3303 pageflag += lyxrc->print_copies_flag;
3305 pageflag += lyxrc->print_collcopies_flag;
3306 pageflag += " " + copies + ' ' ;
3310 if (fl_get_button(fd_form_print->radio_order_reverse))
3311 reverseflag = lyxrc->print_reverse_flag + ' ';
3313 string orientationflag;
3314 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3315 orientationflag = lyxrc->print_landscape_flag + ' ';
3317 string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
3318 string printer = strip(fl_get_input(fd_form_print->input_printer));
3321 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3322 && ! printer.empty()) // a printer name has been given
3323 printerflag = lyxrc->print_to_printer + printer + ' ';
3326 if (!lyxrc->print_extra_options.empty())
3327 extraflags = lyxrc->print_extra_options + ' ';
3329 string command = lyxrc->print_command + ' '
3330 + printerflag + pageflag + reverseflag
3331 + orientationflag + extraflags;
3333 char real_papersize = buffer->params.papersize;
3334 if (real_papersize == BufferParams::PAPER_DEFAULT)
3335 real_papersize = lyxrc->default_papersize;
3338 switch (real_papersize) {
3339 case BufferParams::PAPER_USLETTER:
3342 case BufferParams::PAPER_A3PAPER:
3345 case BufferParams::PAPER_A4PAPER:
3348 case BufferParams::PAPER_A5PAPER:
3351 case BufferParams::PAPER_B5PAPER:
3354 case BufferParams::PAPER_EXECUTIVEPAPER:
3357 case BufferParams::PAPER_LEGALPAPER:
3360 default: /* If nothing else fits, keep an empty value... */
3364 if (buffer->params.use_geometry
3365 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3366 && !lyxrc->print_paper_dimension_flag.empty()
3367 && !buffer->params.paperwidth.empty()
3368 && !buffer->params.paperheight.empty()) {
3369 // using a custom papersize
3371 command += lyxrc->print_paper_dimension_flag + ' ';
3372 command += buffer->params.paperwidth + ',';
3373 command += buffer->params.paperheight + ' ';
3374 } else if (!lyxrc->print_paper_flag.empty()
3376 && (real_papersize != BufferParams::PAPER_USLETTER ||
3377 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3378 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3380 if (fl_get_button(fd_form_print->radio_file))
3381 command += lyxrc->print_to_file + '\"'
3382 + MakeAbsPath(ps_file, path)
3384 else if (!lyxrc->print_spool_command.empty())
3385 command += lyxrc->print_to_file
3386 + '\"' + ps_file + '\"';
3388 // push directorypath, if necessary
3389 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3390 path = buffer->tmppath;
3395 if (!lyxrc->print_spool_command.empty() &&
3396 !fl_get_button(fd_form_print->radio_file)) {
3397 string command2 = lyxrc->print_spool_command + ' ';
3398 if (!printer.empty())
3399 command2 += lyxrc->print_spool_printerprefix
3401 // First run dvips and, if succesful, then spool command
3402 if ((result = RunScript(buffer, true, command))) {
3403 result = RunScript(buffer, false, command2, ps_file);
3406 result = RunScript(buffer, false, command);
3409 WriteAlert(_("Error:"),
3410 _("Unable to print"),
3411 _("Check that your parameters are correct"));
3415 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3417 PrintCancelCB(ob, data);
3418 PrintApplyCB(ob, data);
3422 /* callbacks for form form_figure */
3424 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3426 if (!current_view->available())
3429 Buffer * buffer = current_view->buffer();
3430 if(buffer->isReadonly()) // paranoia
3433 minibuffer->Set(_("Inserting figure..."));
3434 if (fl_get_button(fd_form_figure->radio_inline)
3435 || buffer->text->cursor.par->table) {
3436 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3437 buffer->insertInset(new_inset);
3438 minibuffer->Set(_("Figure inserted"));
3439 new_inset->Edit(0, 0);
3443 current_view->getScreen()->HideCursor();
3447 buffer->text->SetCursorParUndo();
3448 buffer->text->FreezeUndo();
3450 buffer->text->BreakParagraph();
3453 if (buffer->text->cursor.par->Last()) {
3454 buffer->text->CursorLeft();
3456 buffer->text->BreakParagraph();
3460 // The standard layout should always be numer 0;
3461 buffer->text->SetLayout(0);
3463 if (buffer->text->cursor.par->footnoteflag ==
3464 LyXParagraph::NO_FOOTNOTE) {
3468 VSpace (0.3 * buffer->params.spacing.getValue(),
3471 buffer->params.spacing.getValue(),
3473 LYX_ALIGN_CENTER, string(), 0);
3475 buffer->text->SetParagraph(0, 0,
3477 VSpace(VSpace::NONE),
3478 VSpace(VSpace::NONE),
3485 Inset * new_inset = new InsetFig(100, 100, buffer);
3486 buffer->insertInset(new_inset);
3487 new_inset->Edit(0, 0);
3489 minibuffer->Set(_("Figure inserted"));
3490 buffer->text->UnFreezeUndo();
3494 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3496 fl_hide_form(fd_form_figure->form_figure);
3500 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3502 FigureApplyCB(ob, data);
3503 FigureCancelCB(ob, data);
3507 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3509 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3510 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3511 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3512 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3513 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3514 fontloader.update();
3516 // All buffers will need resize
3517 bufferlist.resize();
3519 minibuffer->Set(_("Screen options set"));
3523 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3525 fl_hide_form(fd_form_screen->form_screen);
3529 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3531 ScreenCancelCB(ob, data);
3532 ScreenApplyCB(ob, data);
3538 if (!current_view->available())
3541 fl_set_button(fd_latex_options->accents,
3542 (int)current_view->buffer()->params.allowAccents);
3544 if (fd_latex_options->LaTeXOptions->visible) {
3545 fl_raise_form(fd_latex_options->LaTeXOptions);
3547 fl_show_form(fd_latex_options->LaTeXOptions,
3548 FL_PLACE_MOUSE, FL_FULLBORDER,
3549 _("LaTeX Options"));
3554 // This function runs "configure" and then rereads lyx.defaults to
3555 // reconfigure the automatic settings.
3558 minibuffer->Set(_("Running configure..."));
3560 // Run configure in user lyx directory
3561 Path p(user_lyxdir);
3562 Systemcalls one(Systemcalls::System,
3563 AddName(system_lyxdir, "configure"));
3565 minibuffer->Set(_("Reloading configuration..."));
3566 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
3567 WriteAlert(_("The system has been reconfigured."),
3568 _("You need to restart LyX to make use of any"),
3569 _("updated document class specifications."));
3573 /* these functions are for the spellchecker */
3574 char * NextWord(float & value)
3576 if (!current_view->available()){
3581 char * string = current_view->buffer()->text->SelectNextWord(value);
3587 void SelectLastWord()
3589 if (!current_view->available())
3592 current_view->getScreen()->HideCursor();
3594 current_view->buffer()->text->SelectSelectedWord();
3595 current_view->getScreen()->ToggleSelection(false);
3596 current_view->buffer()->update(0);
3600 void EndOfSpellCheck()
3602 if (!current_view->available())
3605 current_view->getScreen()->HideCursor();
3607 current_view->buffer()->text->SelectSelectedWord();
3608 current_view->buffer()->text->ClearSelection();
3609 current_view->buffer()->update(0);
3613 void ReplaceWord(string const & replacestring)
3615 if (!current_view->getScreen())
3618 current_view->getScreen()->HideCursor();
3619 current_view->buffer()->update(-2);
3621 /* clear the selection (if there is any) */
3622 current_view->getScreen()->ToggleSelection(false);
3623 current_view->buffer()->text->
3624 ReplaceSelectionWithString(replacestring.c_str());
3626 current_view->buffer()->text->SetSelectionOverString(replacestring.c_str());
3628 // Go back so that replacement string is also spellchecked
3629 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3630 current_view->buffer()->text->CursorLeftIntern();
3632 current_view->buffer()->update(1);
3634 // End of spellchecker stuff
3639 // Table of Contents
3649 static TocList * toclist = 0;
3652 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3654 if (!current_view->available())
3657 TocList * tmptoclist = toclist;
3658 int i = fl_get_browser(ob);
3659 for (int a = 1; a < i && tmptoclist->next; ++a) {
3660 tmptoclist = tmptoclist->next;
3667 LyXParagraph * par = current_view->buffer()->paragraph;
3668 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3669 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3670 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3671 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3672 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3673 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3674 par->appendix != tmptoclist->appendix)) {
3675 par = par->LastPhysicalPar()->Next();
3680 current_view->buffer()->text->SetCursor(par, 0);
3681 current_view->buffer()->text->sel_cursor =
3682 current_view->buffer()->text->cursor;
3683 current_view->buffer()->update(0);
3686 WriteAlert(_("Error"),
3687 _("Couldn't find this label"),
3688 _("in current document."));
3694 extern "C" void TocCancelCB(FL_OBJECT *, long)
3696 fl_hide_form(fd_form_toc->form_toc);
3700 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3702 static LyXParagraph * stapar = 0;
3703 TocList * tmptoclist = 0;
3705 /* deleted the toclist */
3708 tmptoclist = toclist->next;
3710 toclist = tmptoclist;
3714 tmptoclist = toclist;
3717 fl_clear_browser(fd_form_toc->browser_toc);
3718 if (!current_view->available()) {
3719 fl_add_browser_line(fd_form_toc->browser_toc,
3720 _("*** No Document ***"));
3723 fl_hide_object(fd_form_toc->browser_toc);
3724 /* get the table of contents */
3725 LyXParagraph * par = current_view->buffer()->paragraph;
3727 char * line = new char[200];
3733 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3737 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3738 par->GetLayout()).labeltype;
3740 if (labeltype >= LABEL_COUNTER_CHAPTER
3741 && labeltype <= LABEL_COUNTER_CHAPTER +
3742 current_view->buffer()->params.tocdepth) {
3743 /* insert this into the table of contents */
3744 /* first indent a little bit */
3748 textclasslist.TextClass(current_view->buffer()->
3749 params.textclass).maxcounter()) * 4 + 2;
3753 // Then the labestring
3754 if (!par->labelstring.empty()) {
3755 string::size_type i = 0;
3756 while (pos < 199 && i < par->labelstring.length()) {
3757 line[pos] = par->labelstring[i];
3766 /* now the contents */
3767 LyXParagraph::size_type i = 0;
3768 while (pos < 199 && i < par->size()) {
3769 c = par->GetChar(i);
3770 if (isprint(c) || c >= 128) {
3777 fl_add_browser_line(fd_form_toc->browser_toc, line);
3779 /* make a toclist entry */
3781 tmptoclist = new TocList;
3782 toclist = tmptoclist;
3784 tmptoclist->next = new TocList;
3785 tmptoclist = tmptoclist->next;
3788 tmptoclist->next = 0;
3790 for (a = 0; a<6; a++){
3791 tmptoclist->counter[a] = par->GetFirstCounter(a);
3793 tmptoclist->appendix = par->appendix;
3795 par = par->LastPhysicalPar()->Next();
3799 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3800 fl_show_object(fd_form_toc->browser_toc);
3804 /* callbacks for form form_ref */
3805 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3807 if (!current_view->available())
3811 fl_get_browser_line(fd_form_ref->browser_ref,
3812 fl_get_browser(fd_form_ref->browser_ref));
3813 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3819 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3829 if(current_view->buffer()->isSGML())
3830 t += "[" + u + "]" + "{" + s + "}";
3835 new InsetRef(t, current_view->buffer());
3836 current_view->buffer()->insertInset(new_inset);
3840 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3842 if (!current_view->available()) {
3843 fl_clear_browser(fd_form_ref->browser_ref);
3847 FL_OBJECT * brow = fd_form_ref->browser_ref;
3849 // Get the current line, in order to restore it later
3850 char const * const btmp = fl_get_browser_line(brow,
3851 fl_get_browser(brow));
3852 string currentstr = btmp ? btmp : "";
3853 //string currentstr = fl_get_browser_line(brow,
3854 // fl_get_browser(brow));
3856 fl_clear_browser(brow);
3858 string refs = current_view->buffer()->getReferenceList('\n');
3861 #if FL_REVISION > 85
3862 fl_addto_browser_chars(brow, refs.c_str());
3863 int total_lines = fl_get_browser_maxline(brow);
3864 for (int i = 1; i <= total_lines ; i++) {
3865 if (fl_get_browser_line(brow, i) == currentstr) {
3870 fl_set_browser_topline(brow, topline);
3872 // Keep the old ugly code for xforms 0.81 compatibility
3877 curr_ref = refs.token('\n', ref_num);
3878 if (curr_ref.empty())
3880 fl_add_browser_line(brow, curr_ref.c_str());
3885 if (!fl_get_browser_maxline(brow)) {
3886 fl_add_browser_line(brow,
3887 _("*** No labels found in document ***"));
3888 fl_deactivate_object(brow);
3890 fl_select_browser_line(brow, topline);
3891 fl_activate_object(brow);
3893 if (current_view->buffer()->isReadonly()) {
3894 // would be better to de/activate insert buttons
3895 // but that's more work... besides this works. ARRae
3896 fl_hide_form(fd_form_ref->form_ref);
3898 if (!current_view->buffer()->isSGML()) {
3899 fl_deactivate_object(fd_form_ref->ref_name);
3900 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3903 fl_activate_object(fd_form_ref->ref_name);
3904 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3909 extern "C" void RefHideCB(FL_OBJECT *, long)
3911 fl_hide_form(fd_form_ref->form_ref);
3915 void UpdateInset(Inset * inset, bool mark_dirty)
3920 /* very first check for locking insets*/
3921 if (current_view->buffer()->the_locking_inset == inset){
3922 if (current_view->buffer()->text->UpdateInset(inset)){
3923 current_view->update();
3925 if (current_view->buffer()->isLyxClean())
3926 minibuffer->setTimer(4);
3927 current_view->buffer()->markDirty();
3929 current_view->updateScrollbar();
3934 /* first check the current buffer */
3935 if (current_view->available()){
3936 current_view->getScreen()->HideCursor();
3937 current_view->buffer()->update(-3);
3938 if (current_view->buffer()->text->UpdateInset(inset)){
3940 current_view->buffer()->update(1);
3942 current_view->buffer()->update(3);
3947 // check all buffers
3948 bufferlist.updateInset(inset, mark_dirty);
3953 /* these functions return 1 if an error occured,
3955 int LockInset(UpdatableInset * inset)
3957 if (!current_view->buffer()->the_locking_inset && inset){
3958 current_view->buffer()->the_locking_inset = inset;
3965 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
3967 if (current_view->buffer()->the_locking_inset &&
3968 current_view->getScreen()){
3969 y += current_view->buffer()->text->cursor.y;
3970 current_view->getScreen()->ShowManualCursor(x, y,
3976 void HideLockedInsetCursor(long x, long y, int asc, int desc)
3978 if (current_view->buffer()->the_locking_inset &&
3979 current_view->getScreen()){
3980 y += current_view->buffer()->text->cursor.y;
3981 current_view->getScreen()->HideManualCursor(x, y,
3987 void FitLockedInsetCursor(long x, long y, int asc, int desc)
3989 if (current_view->buffer()->the_locking_inset &&
3990 current_view->getScreen()){
3991 y += current_view->buffer()->text->cursor.y;
3992 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
3993 current_view->updateScrollbar();
3998 int UnlockInset(UpdatableInset * inset)
4001 current_view->buffer()->the_locking_inset == inset){
4002 inset->InsetUnlock();
4003 current_view->buffer()->the_locking_inset = 0;
4004 current_view->buffer()->text->FinishUndo();
4007 return bufferlist.unlockInset(inset);
4011 void LockedInsetStoreUndo(Undo::undo_kind kind)
4013 if (!current_view->buffer()->the_locking_inset)
4014 return; // shouldn't happen
4015 if (kind == Undo::EDIT) // in this case insets would not be stored!
4016 kind = Undo::FINISH;
4017 current_view->buffer()->text->SetUndo(kind,
4018 current_view->buffer()->text->cursor.par->
4019 ParFromPos(current_view->buffer()->text->cursor.pos)->previous,
4020 current_view->buffer()->text->cursor.par->
4021 ParFromPos(current_view->buffer()->text->cursor.pos)->next);
4025 void PutInsetIntoInsetUpdateList(Inset * inset)
4028 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4030 tmp->next = InsetUpdateList;
4031 InsetUpdateList = tmp;
4036 void UpdateInsetUpdateList()
4038 InsetUpdateStruct * tmp = InsetUpdateList;
4040 UpdateInset(tmp->inset, false); // "false" because no document change
4044 // delete the update list
4045 while (InsetUpdateList) {
4046 tmp = InsetUpdateList;
4047 InsetUpdateList = InsetUpdateList->next;
4050 InsetUpdateList = 0;
4054 #ifdef WITH_WARNINGS
4057 // I know we shouldn't put anything in here but this seems the fastest
4058 // way to do this (and the cleanest for now). This function just inserts
4059 // a newline in the string and the inserts 'depth'-spaces so that the
4060 // code is indented in the right way!!!
4061 void addNewlineAndDepth(string & file, int const depth)
4064 file.append(depth, ' ');