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 #warning why do we do this?
1117 // I don't think this is needed. Actually it might be plain wrong.
1118 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1120 // insert the string
1121 current_view->getScreen()->HideCursor();
1123 // clear the selection
1126 current_view->buffer()->text->InsertStringA(tmppar->text);
1128 current_view->buffer()->text->InsertStringB(tmppar->text);
1130 current_view->buffer()->update(1);
1134 void MenuShowTableOfContents()
1136 static int ow = -1, oh;
1139 if (fd_form_toc->form_toc->visible) {
1140 fl_raise_form(fd_form_toc->form_toc);
1142 fl_show_form(fd_form_toc->form_toc,
1143 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1144 _("Table Of Contents"));
1146 ow = fd_form_toc->form_toc->w;
1147 oh = fd_form_toc->form_toc->h;
1149 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1154 void MenuInsertLabel(char const * arg)
1158 //string label = fl_show_input(_("Enter new label to insert:"), "");
1160 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1161 if (!label.empty()) {
1162 InsetLabel * new_inset = new InsetLabel;
1163 new_inset->setContents(label);
1164 current_view->buffer()->insertInset(new_inset);
1170 void MenuInsertRef()
1172 static int ow = -1, oh;
1175 if (fd_form_ref->form_ref->visible) {
1176 fl_raise_form(fd_form_ref->form_ref);
1178 fl_show_form(fd_form_ref->form_ref,
1179 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1180 _("Insert Reference"));
1182 ow = fd_form_ref->form_ref->w;
1183 oh = fd_form_ref->form_ref->h;
1185 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1190 void MenuPasteSelection(char at)
1192 if (!current_view->getScreen())
1197 Atom data_prop = XInternAtom(fl_display,
1200 if (data_prop == None)
1202 XConvertSelection(fl_display,
1203 XA_PRIMARY, XA_STRING, data_prop,
1204 fd_form_main->form_main->window, 0);
1209 extern "C" void FootCB(FL_OBJECT *, long)
1211 if (!current_view->available())
1214 minibuffer->Set(_("Inserting Footnote..."));
1215 current_view->getScreen()->HideCursor();
1216 current_view->buffer()->update(-2);
1217 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1218 current_view->buffer()->update(1);
1222 void LayoutsCB(int sel, void *)
1224 string tmp = tostr(sel);
1225 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1231 * SGML Linuxdoc support:
1232 * (flag == -1) import SGML file
1233 * (flag == 0) make TeX output
1234 * (flag == 1) make dvi output
1236 int RunLinuxDoc(int flag, string const & filename)
1245 /* generate a path-less extension name */
1246 name = ChangeExtension (filename, ".sgml", true);
1247 path = OnlyPath (filename);
1248 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1249 path = current_view->buffer()->tmppath;
1254 if (!current_view->available())
1256 current_view->buffer()->makeLinuxDocFile(name, 0);
1257 #ifdef WITH_WARNINGS
1258 #warning remove this once we have a proper geometry class
1260 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1262 case BufferParams::PAPER_A4PAPER:
1263 add_flags = "-p a4";
1265 case BufferParams::PAPER_USLETTER:
1266 add_flags = "-p letter";
1268 default: /* nothing to be done yet ;-) */ break;
1276 case -1: /* Import file */
1277 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1278 MakeDisplayPath(filename), "'...");
1279 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1281 if (one.startscript(Systemcalls::System, s2))
1284 case 0: /* TeX output asked */
1285 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1286 s2 = "sgml2latex " + add_flags + " -o tex "
1287 + lyxrc->sgml_extra_options + ' ' + name;
1288 if (one.startscript(Systemcalls::System, s2))
1291 case 1: /* dvi output asked */
1292 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1293 s2 = "sgml2latex " + add_flags + " -o dvi "
1294 + lyxrc->sgml_extra_options + ' ' + name;
1295 if (one.startscript(Systemcalls::System, s2)) {
1298 current_view->buffer()->markDviClean();
1300 default: /* unknown output */
1306 current_view->buffer()->redraw();
1312 * SGML DocBook support:
1313 * (flag == 1) make dvi output
1315 int RunDocBook(int flag, string const & filename)
1317 /* generate a path-less extension name */
1318 string name = ChangeExtension (filename, ".sgml", true);
1319 string path = OnlyPath (filename);
1320 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1321 path = current_view->buffer()->tmppath;
1325 if (!current_view->available())
1328 current_view->buffer()->makeDocBookFile(name, 0);
1330 // Shall this code go or should it stay? (Lgb)
1331 // string add_flags;
1332 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1334 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1335 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1336 // default: /* nothing to be done yet ;-) */ break;
1343 case 1: /* dvi output asked */
1345 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1346 string s2 = "sgmltools --backend dvi " + name;
1347 if (one.startscript(Systemcalls::System, s2)) {
1350 current_view->buffer()->markDviClean();
1353 default: /* unknown output */
1359 current_view->buffer()->redraw();
1364 void AllFloats(char flag, char figmar)
1366 if (!current_view->available())
1369 LyXCursor cursor = current_view->buffer()->text->cursor;
1371 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1373 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1374 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1376 && cursor.par->footnotekind != LyXParagraph::FIG
1377 && cursor.par->footnotekind != LyXParagraph::TAB
1378 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1379 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1380 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1385 LyXCursor tmpcursor = cursor;
1386 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1387 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1389 LyXParagraph *par = current_view->buffer()->paragraph;
1392 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1394 && par->footnotekind != LyXParagraph::FOOTNOTE
1395 && par->footnotekind != LyXParagraph::MARGIN)
1397 && par->footnotekind != LyXParagraph::FIG
1398 && par->footnotekind != LyXParagraph::TAB
1399 && par->footnotekind != LyXParagraph::WIDE_FIG
1400 && par->footnotekind != LyXParagraph::WIDE_TAB
1401 && par->footnotekind != LyXParagraph::ALGORITHM
1406 && par->previous->footnoteflag !=
1407 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1408 current_view->buffer()->text->SetCursorIntern(par->previous,
1410 current_view->buffer()->text->OpenFootnote();
1415 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1419 par->footnotekind != LyXParagraph::FOOTNOTE
1421 par->footnotekind != LyXParagraph::MARGIN
1426 par->footnotekind != LyXParagraph::FIG
1428 par->footnotekind != LyXParagraph::TAB
1430 par->footnotekind != LyXParagraph::WIDE_FIG
1432 par->footnotekind != LyXParagraph::WIDE_TAB
1434 par->footnotekind != LyXParagraph::ALGORITHM
1438 current_view->buffer()->text->SetCursorIntern(par, 0);
1439 current_view->buffer()->text->CloseFootnote();
1445 current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1446 current_view->redraw();
1447 current_view->fitCursor();
1448 current_view->updateScrollbar();
1452 void MenuLayoutCharacter()
1454 static int ow = -1, oh;
1456 if (fd_form_character->form_character->visible) {
1457 fl_raise_form(fd_form_character->form_character);
1459 fl_show_form(fd_form_character->form_character,
1460 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1461 _("Character Style"));
1463 ow = fd_form_character->form_character->w;
1464 oh = fd_form_character->form_character->h;
1466 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1471 inline void DeactivateParagraphButtons ()
1473 fl_deactivate_object (fd_form_paragraph->button_ok);
1474 fl_deactivate_object (fd_form_paragraph->button_apply);
1475 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1476 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1480 inline void ActivateParagraphButtons ()
1482 fl_activate_object (fd_form_paragraph->button_ok);
1483 fl_activate_object (fd_form_paragraph->button_apply);
1484 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1485 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1489 inline void DisableParagraphLayout ()
1491 DeactivateParagraphButtons();
1492 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1493 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1494 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1495 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1496 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1497 fl_deactivate_object (fd_form_paragraph->check_noindent);
1498 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1499 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1500 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1501 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1502 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1503 fl_deactivate_object (fd_form_paragraph->input_space_above);
1504 fl_deactivate_object (fd_form_paragraph->input_space_below);
1505 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1506 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1507 fl_deactivate_object (fd_form_paragraph->check_space_above);
1508 fl_deactivate_object (fd_form_paragraph->check_space_below);
1512 inline void EnableParagraphLayout ()
1514 ActivateParagraphButtons();
1515 fl_activate_object (fd_form_paragraph->input_labelwidth);
1516 fl_activate_object (fd_form_paragraph->check_lines_top);
1517 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1518 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1519 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1520 fl_activate_object (fd_form_paragraph->check_noindent);
1521 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1522 fl_activate_object (fd_form_paragraph->radio_align_right);
1523 fl_activate_object (fd_form_paragraph->radio_align_left);
1524 fl_activate_object (fd_form_paragraph->radio_align_block);
1525 fl_activate_object (fd_form_paragraph->radio_align_center);
1526 fl_activate_object (fd_form_paragraph->input_space_above);
1527 fl_activate_object (fd_form_paragraph->input_space_below);
1528 fl_activate_object (fd_form_paragraph->choice_space_above);
1529 fl_activate_object (fd_form_paragraph->choice_space_below);
1530 fl_activate_object (fd_form_paragraph->check_space_above);
1531 fl_activate_object (fd_form_paragraph->check_space_below);
1535 bool UpdateLayoutParagraph()
1537 if (!current_view->getScreen() || !current_view->available()) {
1538 if (fd_form_paragraph->form_paragraph->visible)
1539 fl_hide_form(fd_form_paragraph->form_paragraph);
1543 Buffer * buf = current_view->buffer();
1545 fl_set_input(fd_form_paragraph->input_labelwidth,
1546 buf->text->cursor.par->GetLabelWidthString().c_str());
1547 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1548 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1549 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1550 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1552 int align = buf->text->cursor.par->GetAlign();
1553 if (align == LYX_ALIGN_LAYOUT)
1554 align = textclasslist.Style(buf->params.textclass,
1555 buf->text->cursor.par->GetLayout()).align;
1558 case LYX_ALIGN_RIGHT:
1559 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1561 case LYX_ALIGN_LEFT:
1562 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1564 case LYX_ALIGN_CENTER:
1565 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1568 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1572 fl_set_button(fd_form_paragraph->check_lines_top,
1573 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1574 fl_set_button(fd_form_paragraph->check_lines_bottom,
1575 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1576 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1577 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1578 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1579 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1580 fl_set_button(fd_form_paragraph->check_noindent,
1581 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1582 fl_set_input (fd_form_paragraph->input_space_above, "");
1584 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1586 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1588 case VSpace::DEFSKIP:
1589 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1591 case VSpace::SMALLSKIP:
1592 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1594 case VSpace::MEDSKIP:
1595 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1597 case VSpace::BIGSKIP:
1598 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1601 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1603 case VSpace::LENGTH:
1604 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1605 fl_set_input (fd_form_paragraph->input_space_above,
1606 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1609 fl_set_button (fd_form_paragraph->check_space_above,
1610 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1611 fl_set_input (fd_form_paragraph->input_space_below, "");
1612 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1614 fl_set_choice (fd_form_paragraph->choice_space_below,
1617 case VSpace::DEFSKIP:
1618 fl_set_choice (fd_form_paragraph->choice_space_below,
1621 case VSpace::SMALLSKIP:
1622 fl_set_choice (fd_form_paragraph->choice_space_below,
1625 case VSpace::MEDSKIP:
1626 fl_set_choice (fd_form_paragraph->choice_space_below,
1629 case VSpace::BIGSKIP:
1630 fl_set_choice (fd_form_paragraph->choice_space_below,
1634 fl_set_choice (fd_form_paragraph->choice_space_below,
1637 case VSpace::LENGTH:
1638 fl_set_choice (fd_form_paragraph->choice_space_below,
1640 fl_set_input (fd_form_paragraph->input_space_below,
1641 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1644 fl_set_button (fd_form_paragraph->check_space_below,
1645 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1647 fl_set_button(fd_form_paragraph->check_noindent,
1648 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1650 if (current_view->buffer()->isReadonly()) {
1651 DisableParagraphLayout();
1653 EnableParagraphLayout();
1659 void MenuLayoutParagraph()
1661 if (UpdateLayoutParagraph()) {
1662 if (fd_form_paragraph->form_paragraph->visible) {
1663 fl_raise_form(fd_form_paragraph->form_paragraph);
1665 fl_show_form(fd_form_paragraph->form_paragraph,
1666 FL_PLACE_MOUSE, FL_FULLBORDER,
1667 _("Paragraph Environment"));
1674 void DeactivateDocumentButtons ()
1676 fl_deactivate_object (fd_form_document->button_ok);
1677 fl_deactivate_object (fd_form_document->button_apply);
1678 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1679 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1684 void ActivateDocumentButtons ()
1686 fl_activate_object (fd_form_document->button_ok);
1687 fl_activate_object (fd_form_document->button_apply);
1688 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1689 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1694 void DisableDocumentLayout ()
1696 DeactivateDocumentButtons ();
1697 fl_deactivate_object (fd_form_document->group_radio_separation);
1698 fl_deactivate_object (fd_form_document->radio_indent);
1699 fl_deactivate_object (fd_form_document->radio_skip);
1700 fl_deactivate_object (fd_form_document->choice_class);
1701 fl_deactivate_object (fd_form_document->choice_pagestyle);
1702 fl_deactivate_object (fd_form_document->choice_fonts);
1703 fl_deactivate_object (fd_form_document->choice_fontsize);
1704 fl_deactivate_object (fd_form_document->input_float_placement);
1705 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1706 fl_deactivate_object (fd_form_document->choice_inputenc);
1707 fl_deactivate_object (fd_form_document->group_radio_sides);
1708 fl_deactivate_object (fd_form_document->radio_sides_one);
1709 fl_deactivate_object (fd_form_document->radio_sides_two);
1710 fl_deactivate_object (fd_form_document->group_radio_columns);
1711 fl_deactivate_object (fd_form_document->radio_columns_one);
1712 fl_deactivate_object (fd_form_document->radio_columns_two);
1713 fl_deactivate_object (fd_form_document->input_extra);
1714 fl_deactivate_object (fd_form_document->choice_language);
1715 combo_language->deactivate();
1716 fl_deactivate_object (fd_form_document->input_default_skip);
1717 fl_deactivate_object (fd_form_document->choice_default_skip);
1718 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1719 fl_deactivate_object (fd_form_document->slider_tocdepth);
1720 fl_deactivate_object (fd_form_document->choice_spacing);
1721 fl_deactivate_object (fd_form_document->input_spacing);
1722 fl_deactivate_object (fd_form_document->check_use_amsmath);
1727 void EnableDocumentLayout ()
1729 ActivateDocumentButtons ();
1730 fl_activate_object (fd_form_document->group_radio_separation);
1731 fl_activate_object (fd_form_document->radio_indent);
1732 fl_activate_object (fd_form_document->radio_skip);
1733 fl_activate_object (fd_form_document->choice_class);
1734 fl_activate_object (fd_form_document->choice_pagestyle);
1735 fl_activate_object (fd_form_document->choice_fonts);
1736 fl_activate_object (fd_form_document->choice_fontsize);
1737 fl_activate_object (fd_form_document->input_float_placement);
1738 fl_activate_object (fd_form_document->choice_postscript_driver);
1739 fl_activate_object (fd_form_document->choice_inputenc);
1740 fl_activate_object (fd_form_document->group_radio_sides);
1741 fl_activate_object (fd_form_document->radio_sides_one);
1742 fl_activate_object (fd_form_document->radio_sides_two);
1743 fl_activate_object (fd_form_document->group_radio_columns);
1744 fl_activate_object (fd_form_document->radio_columns_one);
1745 fl_activate_object (fd_form_document->radio_columns_two);
1746 fl_activate_object (fd_form_document->input_extra);
1747 fl_activate_object (fd_form_document->choice_language);
1748 combo_language->activate();
1749 fl_activate_object (fd_form_document->input_default_skip);
1750 fl_activate_object (fd_form_document->choice_default_skip);
1751 fl_activate_object (fd_form_document->slider_secnumdepth);
1752 fl_activate_object (fd_form_document->slider_tocdepth);
1753 fl_activate_object (fd_form_document->choice_spacing);
1754 fl_activate_object (fd_form_document->input_spacing);
1755 fl_activate_object (fd_form_document->check_use_amsmath);
1759 bool UpdateLayoutDocument(BufferParams * params)
1761 if (!current_view->getScreen() || !current_view->available()) {
1762 if (fd_form_document->form_document->visible)
1763 fl_hide_form(fd_form_document->form_document);
1768 params = ¤t_view->buffer()->params;
1769 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1771 fl_set_choice_text(fd_form_document->choice_class,
1772 textclasslist.DescOfClass(params->textclass).c_str());
1773 combo_language->select_text(params->language.c_str());
1775 fl_set_choice_text(fd_form_document->choice_fonts,
1776 params->fonts.c_str());
1777 fl_set_choice_text(fd_form_document->choice_inputenc,
1778 params->inputenc.c_str());
1779 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1780 params->graphicsDriver.c_str());
1782 // ale970405+lasgoutt970513
1783 fl_clear_choice(fd_form_document->choice_fontsize);
1784 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1785 fl_addto_choice(fd_form_document->choice_fontsize,
1786 tclass.opt_fontsize().c_str());
1787 fl_set_choice(fd_form_document->choice_fontsize,
1788 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1790 // ale970405+lasgoutt970513
1791 fl_clear_choice(fd_form_document->choice_pagestyle);
1792 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1793 fl_addto_choice(fd_form_document->choice_pagestyle,
1794 tclass.opt_pagestyle().c_str());
1796 fl_set_choice(fd_form_document->choice_pagestyle,
1797 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1799 fl_set_button(fd_form_document->radio_indent, 0);
1800 fl_set_button(fd_form_document->radio_skip, 0);
1803 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1805 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1806 fl_set_button(fd_form_document->radio_indent, 1);
1808 fl_set_button(fd_form_document->radio_skip, 1);
1810 switch (params->getDefSkip().kind()) {
1811 case VSpace::SMALLSKIP:
1812 fl_set_choice (fd_form_document->choice_default_skip, 1);
1814 case VSpace::MEDSKIP:
1815 fl_set_choice (fd_form_document->choice_default_skip, 2);
1817 case VSpace::BIGSKIP:
1818 fl_set_choice (fd_form_document->choice_default_skip, 3);
1820 case VSpace::LENGTH:
1821 fl_set_choice (fd_form_document->choice_default_skip, 4);
1822 fl_set_input (fd_form_document->input_default_skip,
1823 params->getDefSkip().asLyXCommand().c_str());
1826 fl_set_choice (fd_form_document->choice_default_skip, 2);
1830 fl_set_button(fd_form_document->radio_sides_one, 0);
1831 fl_set_button(fd_form_document->radio_sides_two, 0);
1833 if (params->sides == 2)
1834 fl_set_button(fd_form_document->radio_sides_two, 1);
1836 fl_set_button(fd_form_document->radio_sides_one, 1);
1838 fl_set_button(fd_form_document->radio_columns_one, 0);
1839 fl_set_button(fd_form_document->radio_columns_two, 0);
1841 if (params->columns == 2)
1842 fl_set_button(fd_form_document->radio_columns_two, 1);
1844 fl_set_button(fd_form_document->radio_columns_one, 1);
1846 fl_set_input(fd_form_document->input_spacing, "");
1847 switch (params->spacing.getSpace()) {
1848 case Spacing::Single:
1851 fl_set_choice(fd_form_document->choice_spacing, 1);
1854 case Spacing::Onehalf:
1857 fl_set_choice(fd_form_document->choice_spacing, 2);
1860 case Spacing::Double:
1863 fl_set_choice(fd_form_document->choice_spacing, 3);
1866 case Spacing::Other:
1868 fl_set_choice(fd_form_document->choice_spacing, 4);
1870 sprintf(sval, "%g", params->spacing.getValue());
1871 fl_set_input(fd_form_document->input_spacing, sval);
1877 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1878 params->secnumdepth);
1879 fl_set_counter_value(fd_form_document->slider_tocdepth,
1881 if (!params->float_placement.empty()) { // buffer local (Lgb)
1882 fl_set_input(fd_form_document->input_float_placement,
1883 params->float_placement.c_str());
1885 fl_set_input(fd_form_document->input_float_placement, "");
1887 if (!params->options.empty())
1888 fl_set_input(fd_form_document->input_extra,
1889 params->options.c_str());
1891 fl_set_input(fd_form_document->input_extra, "");
1893 if (current_view->buffer()->isSGML()) {
1894 // bullets not used in SGML derived documents
1895 fl_deactivate_object(fd_form_document->button_bullets);
1896 fl_set_object_lcol(fd_form_document->button_bullets,
1899 fl_activate_object(fd_form_document->button_bullets);
1900 fl_set_object_lcol(fd_form_document->button_bullets,
1904 if (current_view->buffer()->isReadonly()) {
1905 DisableDocumentLayout();
1907 EnableDocumentLayout();
1914 void MenuLayoutDocument()
1916 if (UpdateLayoutDocument()) {
1917 if (fd_form_document->form_document->visible) {
1918 fl_raise_form(fd_form_document->form_document);
1920 fl_show_form(fd_form_document->form_document,
1921 FL_PLACE_MOUSE, FL_FULLBORDER,
1922 _("Document Layout"));
1928 bool UpdateLayoutQuotes()
1931 if (!current_view->getScreen()
1932 || !current_view->available()
1933 || current_view->buffer()->isReadonly())
1937 fl_set_choice(fd_form_quotes->choice_quotes_language,
1938 current_view->buffer()->params.quotes_language + 1);
1939 fl_set_button(fd_form_quotes->radio_single, 0);
1940 fl_set_button(fd_form_quotes->radio_double, 0);
1942 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1943 fl_set_button(fd_form_quotes->radio_single, 1);
1945 fl_set_button(fd_form_quotes->radio_double, 1);
1946 } else if (fd_form_quotes->form_quotes->visible) {
1947 fl_hide_form(fd_form_quotes->form_quotes);
1953 void MenuLayoutQuotes()
1955 if (UpdateLayoutQuotes()) {
1956 if (fd_form_quotes->form_quotes->visible) {
1957 fl_raise_form(fd_form_quotes->form_quotes);
1959 fl_show_form(fd_form_quotes->form_quotes,
1960 FL_PLACE_MOUSE, FL_FULLBORDER,
1967 bool UpdateLayoutPreamble()
1970 if (!current_view->getScreen() || ! current_view->available())
1974 fl_set_input(fd_form_preamble->input_preamble,
1975 current_view->buffer()->params.preamble.c_str());
1977 if (current_view->buffer()->isReadonly()) {
1978 fl_deactivate_object(fd_form_preamble->input_preamble);
1979 fl_deactivate_object(fd_form_preamble->button_ok);
1980 fl_deactivate_object(fd_form_preamble->button_apply);
1981 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1982 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1985 fl_activate_object(fd_form_preamble->input_preamble);
1986 fl_activate_object(fd_form_preamble->button_ok);
1987 fl_activate_object(fd_form_preamble->button_apply);
1988 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1989 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1991 } else if (fd_form_preamble->form_preamble->visible) {
1992 fl_hide_form(fd_form_preamble->form_preamble);
1997 void MenuLayoutPreamble()
1999 static int ow = -1, oh;
2001 if (UpdateLayoutPreamble()) {
2002 if (fd_form_preamble->form_preamble->visible) {
2003 fl_raise_form(fd_form_preamble->form_preamble);
2005 fl_show_form(fd_form_preamble->form_preamble,
2006 FL_PLACE_MOUSE | FL_FREE_SIZE,
2008 _("LaTeX Preamble"));
2010 ow = fd_form_preamble->form_preamble->w;
2011 oh = fd_form_preamble->form_preamble->h;
2013 fl_set_form_minsize(fd_form_preamble->form_preamble,
2020 void MenuLayoutSave()
2022 if (!current_view->getScreen() || ! current_view->available())
2025 if (AskQuestion(_("Do you want to save the current settings"),
2026 _("for Character, Document, Paper and Quotes"),
2027 _("as default for new documents?")))
2028 current_view->buffer()->saveParamsAsDefaults();
2034 InsetInfo * new_inset = new InsetInfo();
2035 current_view->buffer()->insertInset(new_inset);
2036 new_inset->Edit(0, 0);
2042 if (current_view->available()) {
2043 minibuffer->Set(_("Open/Close..."));
2044 current_view->getScreen()->HideCursor();
2046 current_view->buffer()->update(-2);
2047 current_view->buffer()->text->OpenStuff();
2048 current_view->buffer()->update(0);
2055 if (current_view->available()) {
2056 minibuffer->Set(_("Open/Close..."));
2057 current_view->getScreen()->HideCursor();
2059 current_view->buffer()->update(-2);
2060 current_view->buffer()->text->ToggleFootnote();
2061 current_view->buffer()->update(0);
2068 /* if (current_view->buffer()->the_locking_inset) {
2069 minibuffer->Set(_("Undo not yet supported in math mode"));
2073 if (current_view->available()) {
2074 minibuffer->Set(_("Undo"));
2075 current_view->getScreen()->HideCursor();
2077 current_view->buffer()->update(-2);
2078 if (!current_view->buffer()->text->TextUndo())
2079 minibuffer->Set(_("No further undo information"));
2081 current_view->buffer()->update(-1);
2088 if (current_view->buffer()->the_locking_inset) {
2089 minibuffer->Set(_("Redo not yet supported in math mode"));
2093 if (current_view->available()) {
2094 minibuffer->Set(_("Redo"));
2095 current_view->getScreen()->HideCursor();
2097 current_view->buffer()->update(-2);
2098 if (!current_view->buffer()->text->TextRedo())
2099 minibuffer->Set(_("No further redo information"));
2101 current_view->buffer()->update(-1);
2106 void HyphenationPoint()
2108 if (current_view->available()) {
2109 current_view->getScreen()->HideCursor();
2110 current_view->buffer()->update(-2);
2111 InsetSpecialChar * new_inset =
2112 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2113 current_view->buffer()->insertInset(new_inset);
2120 if (current_view->available()) {
2121 current_view->getScreen()->HideCursor();
2122 current_view->buffer()->update(-2);
2123 InsetSpecialChar * new_inset =
2124 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2125 current_view->buffer()->insertInset(new_inset);
2130 void EndOfSentenceDot()
2132 if (current_view->available()) {
2133 current_view->getScreen()->HideCursor();
2134 current_view->buffer()->update(-2);
2135 InsetSpecialChar * new_inset =
2136 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2137 current_view->buffer()->insertInset(new_inset);
2142 void MenuSeparator()
2144 if (current_view->available()) {
2145 current_view->getScreen()->HideCursor();
2146 current_view->buffer()->update(-2);
2147 InsetSpecialChar * new_inset =
2148 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2149 current_view->buffer()->insertInset(new_inset);
2156 if (current_view->available()) {
2157 current_view->getScreen()->HideCursor();
2158 current_view->buffer()->update(-2);
2159 current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
2160 current_view->buffer()->update(-1);
2165 void ProtectedBlank()
2167 if (current_view->available()) {
2168 current_view->getScreen()->HideCursor();
2169 current_view->buffer()->update(-2);
2170 current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2171 current_view->buffer()->update(-1);
2178 if (current_view->available()) {
2179 current_view->getScreen()->HideCursor();
2180 current_view->buffer()->update(-2);
2181 current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL);
2182 current_view->buffer()->update(-1);
2187 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2188 They also show the current font state. */
2191 void ToggleAndShow(LyXFont const &);
2194 void FontSizeCB(string const & size)
2196 LyXFont font(LyXFont::ALL_IGNORE);
2197 font.setGUISize(size);
2198 ToggleAndShow(font);
2204 LyXFont font(LyXFont::ALL_IGNORE);
2205 font.setEmph(LyXFont::TOGGLE);
2206 ToggleAndShow(font);
2212 LyXFont font(LyXFont::ALL_IGNORE);
2213 font.setNoun(LyXFont::TOGGLE);
2214 ToggleAndShow(font);
2220 LyXFont font(LyXFont::ALL_IGNORE);
2221 font.setSeries(LyXFont::BOLD_SERIES);
2222 ToggleAndShow(font);
2228 LyXFont font(LyXFont::ALL_IGNORE);
2229 font.setUnderbar(LyXFont::TOGGLE);
2230 ToggleAndShow(font);
2236 LyXFont font(LyXFont::ALL_IGNORE);
2237 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2238 ToggleAndShow(font);
2244 LyXFont font(LyXFont::ALL_IGNORE);
2245 font.setFamily(LyXFont::SANS_FAMILY);
2246 ToggleAndShow(font);
2252 LyXFont font(LyXFont::ALL_IGNORE);
2253 font.setFamily(LyXFont::ROMAN_FAMILY);
2254 ToggleAndShow(font);
2260 LyXFont font(LyXFont::ALL_IGNORE);
2261 font.setLatex (LyXFont::TOGGLE);
2262 ToggleAndShow(font);
2268 LyXFont font(LyXFont::ALL_INHERIT);
2269 ToggleAndShow(font);
2273 /* -------> Returns the current font and depth by printing a message. In the
2274 * future perhaps we could try to implement a callback to the button-bar.
2275 * That is, `light' the bold button when the font is currently bold, etc.
2277 string CurrentState()
2280 if (current_view->available()) {
2281 // I think we should only show changes from the default
2283 Buffer * buffer = current_view->buffer();
2284 LyXFont font = buffer->text->real_current_font;
2285 LyXFont defaultfont = textclasslist.TextClass(buffer->
2286 params.textclass).defaultfont();
2287 font.reduce(defaultfont);
2288 state = _("Font: ") + font.stateText();
2290 int depth = buffer->text->GetDepth();
2292 state += string(_(", Depth: ")) + tostr(depth);
2298 /* -------> Does the actual toggle job of the XxxCB() calls above.
2299 * Also shows the current font state.
2302 void ToggleAndShow(LyXFont const & font)
2304 if (current_view->available()) {
2305 current_view->getScreen()->HideCursor();
2306 current_view->buffer()->update(-2);
2307 current_view->buffer()->text->ToggleFree(font, toggleall);
2308 current_view->buffer()->update(1);
2310 // removed since it overrides the ToggleFree Message about the style
2311 // Since Styles are more "High Level" than raw fonts I think the user
2312 // prefers it like this Matthias
2313 // FontStateShowCB( 0, 0 );
2317 extern "C" void MarginCB(FL_OBJECT *, long)
2319 if (current_view->available()) {
2320 minibuffer->Set(_("Inserting margin note..."));
2321 current_view->getScreen()->HideCursor();
2322 current_view->buffer()->update(-2);
2323 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2324 current_view->buffer()->update(1);
2329 extern "C" void FigureCB(FL_OBJECT *, long)
2331 if (fd_form_figure->form_figure->visible) {
2332 fl_raise_form(fd_form_figure->form_figure);
2334 fl_show_form(fd_form_figure->form_figure,
2335 FL_PLACE_MOUSE, FL_FULLBORDER,
2336 _("Insert Figure"));
2341 extern "C" void TableCB(FL_OBJECT *, long)
2343 if (fd_form_table->form_table->visible) {
2344 fl_raise_form(fd_form_table->form_table);
2346 fl_show_form(fd_form_table->form_table,
2347 FL_PLACE_MOUSE, FL_FULLBORDER,
2353 void CopyEnvironmentCB()
2355 if (current_view->available()) {
2356 current_view->buffer()->text->copyEnvironmentType();
2357 /* clear the selection, even if mark_set */
2358 current_view->getScreen()->ToggleSelection();
2359 current_view->buffer()->text->ClearSelection();
2360 current_view->buffer()->update(-2);
2361 minibuffer->Set(_("Paragraph environment type copied"));
2366 void PasteEnvironmentCB()
2368 if (current_view->available()) {
2369 current_view->buffer()->text->pasteEnvironmentType();
2370 minibuffer->Set(_("Paragraph environment type set"));
2371 current_view->buffer()->update(1);
2378 if (current_view->available()) {
2379 current_view->buffer()->text->CopySelection();
2380 /* clear the selection, even if mark_set */
2381 current_view->getScreen()->ToggleSelection();
2382 current_view->buffer()->text->ClearSelection();
2383 current_view->buffer()->update(-2);
2384 minibuffer->Set(_("Copy"));
2391 if (current_view->available()) {
2392 current_view->getScreen()->HideCursor();
2393 current_view->buffer()->update(-2);
2394 current_view->buffer()->text->CutSelection();
2395 current_view->buffer()->update(1);
2396 minibuffer->Set(_("Cut"));
2403 if (!current_view->available()) return;
2405 minibuffer->Set(_("Paste"));
2406 current_view->getScreen()->HideCursor();
2407 /* clear the selection */
2408 current_view->getScreen()->ToggleSelection();
2409 current_view->buffer()->text->ClearSelection();
2410 current_view->buffer()->update(-2);
2413 current_view->buffer()->text->PasteSelection();
2414 current_view->buffer()->update(1);
2416 /* clear the selection */
2417 current_view->getScreen()->ToggleSelection();
2418 current_view->buffer()->text->ClearSelection();
2419 current_view->buffer()->update(-2);
2423 extern "C" void MeltCB(FL_OBJECT *, long)
2425 if (!current_view->available()) return;
2427 minibuffer->Set(_("Melt"));
2428 current_view->getScreen()->HideCursor();
2430 current_view->buffer()->update(-2);
2431 current_view->buffer()->text->MeltFootnoteEnvironment();
2432 current_view->buffer()->update(1);
2436 // Change environment depth.
2437 // if decInc == 0, depth change taking mouse button number into account
2438 // if decInc == 1, increment depth
2439 // if decInc == -1, decrement depth
2440 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2444 /* When decInc != 0, fake a mouse button. This allows us to
2445 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2446 /* check out wether ob is defined, too (Matthias) */
2449 else if (!decInc && ob) {
2450 button = fl_get_button_numb(ob);
2453 if (current_view->available()) {
2454 current_view->getScreen()->HideCursor();
2455 current_view->buffer()->update(-2);
2457 current_view->buffer()->text->IncDepth();
2459 current_view->buffer()->text->DecDepth();
2460 current_view->buffer()->update(1);
2461 minibuffer->Set(_("Changed environment depth"
2462 " (in possible range, maybe not)"));
2467 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2468 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2469 LyXFont UserFreeFont()
2471 LyXFont font(LyXFont::ALL_IGNORE);
2473 int pos = fl_get_choice(fd_form_character->choice_family);
2475 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2476 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2477 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2478 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2479 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2482 pos = fl_get_choice(fd_form_character->choice_series);
2484 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2485 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2486 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2487 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2490 pos = fl_get_choice(fd_form_character->choice_shape);
2492 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2493 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2494 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2495 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2496 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2497 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2500 pos = fl_get_choice(fd_form_character->choice_size);
2502 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2503 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2504 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2505 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2506 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2507 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2508 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2509 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2510 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2511 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2512 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2513 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2514 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2515 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2518 pos = fl_get_choice(fd_form_character->choice_bar);
2520 case 1: font.setEmph(LyXFont::IGNORE);
2521 font.setUnderbar(LyXFont::IGNORE);
2522 font.setNoun(LyXFont::IGNORE);
2523 font.setLatex(LyXFont::IGNORE);
2525 case 2: font.setEmph(LyXFont::TOGGLE); break;
2526 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2527 case 4: font.setNoun(LyXFont::TOGGLE); break;
2528 case 5: font.setLatex(LyXFont::TOGGLE); break;
2529 case 6: font.setEmph(LyXFont::INHERIT);
2530 font.setUnderbar(LyXFont::INHERIT);
2531 font.setNoun(LyXFont::INHERIT);
2532 font.setLatex(LyXFont::INHERIT);
2536 pos = fl_get_choice(fd_form_character->choice_color);
2538 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2539 case 2: font.setColor(LyXFont::NONE); break;
2540 case 3: font.setColor(LyXFont::BLACK); break;
2541 case 4: font.setColor(LyXFont::WHITE); break;
2542 case 5: font.setColor(LyXFont::RED); break;
2543 case 6: font.setColor(LyXFont::GREEN); break;
2544 case 7: font.setColor(LyXFont::BLUE); break;
2545 case 8: font.setColor(LyXFont::CYAN); break;
2546 case 9: font.setColor(LyXFont::MAGENTA); break;
2547 case 10: font.setColor(LyXFont::YELLOW); break;
2548 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2557 ToggleAndShow(UserFreeFont());
2561 /* callbacks for form form_title */
2562 extern "C" void TimerCB(FL_OBJECT *, long)
2564 // only if the form still exists
2565 if (fd_form_title->form_title != 0) {
2566 if (fd_form_title->form_title->visible) {
2567 fl_hide_form(fd_form_title->form_title);
2569 fl_free_form(fd_form_title->form_title);
2570 fd_form_title->form_title = 0;
2575 /* callbacks for form form_paragraph */
2577 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2579 // "Synchronize" the choices and input fields, making it
2580 // impossible to commit senseless data.
2582 FD_form_paragraph const * fp = fd_form_paragraph;
2584 if (obj == fp->choice_space_above) {
2585 if (fl_get_choice (fp->choice_space_above) != 7) {
2586 fl_set_input (fp->input_space_above, "");
2587 ActivateParagraphButtons();
2589 } else if (obj == fp->choice_space_below) {
2590 if (fl_get_choice (fp->choice_space_below) != 7) {
2591 fl_set_input (fp->input_space_below, "");
2592 ActivateParagraphButtons();
2594 } else if (obj == fp->input_space_above) {
2595 string input = fl_get_input (fp->input_space_above);
2597 if (input.empty()) {
2598 fl_set_choice (fp->choice_space_above, 1);
2599 ActivateParagraphButtons();
2601 else if (isValidGlueLength (input)) {
2602 fl_set_choice (fp->choice_space_above, 7);
2603 ActivateParagraphButtons();
2606 fl_set_choice (fp->choice_space_above, 7);
2607 DeactivateParagraphButtons();
2609 } else if (obj == fp->input_space_below) {
2610 string input = fl_get_input (fp->input_space_below);
2612 if (input.empty()) {
2613 fl_set_choice (fp->choice_space_below, 1);
2614 ActivateParagraphButtons();
2616 else if (isValidGlueLength (input)) {
2617 fl_set_choice (fp->choice_space_below, 7);
2618 ActivateParagraphButtons();
2621 fl_set_choice (fp->choice_space_below, 7);
2622 DeactivateParagraphButtons();
2628 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2630 if (!current_view->available())
2633 VSpace space_top, space_bottom;
2635 string labelwidthstring;
2638 // If a vspace kind is "Length" but there's no text in
2639 // the input field, reset the kind to "None".
2640 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2641 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2642 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2644 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2645 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2646 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2649 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2650 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2651 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2652 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2653 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2654 case 1: space_top = VSpace(VSpace::NONE); break;
2655 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2656 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2657 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2658 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2659 case 6: space_top = VSpace(VSpace::VFILL); break;
2660 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2662 if (fl_get_button (fd_form_paragraph->check_space_above))
2663 space_top.setKeep (true);
2664 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2665 case 1: space_bottom = VSpace(VSpace::NONE); break;
2666 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2667 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2668 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2669 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2670 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2671 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2673 if (fl_get_button (fd_form_paragraph->check_space_below))
2674 space_bottom.setKeep (true);
2676 if (fl_get_button(fd_form_paragraph->radio_align_left))
2677 align = LYX_ALIGN_LEFT;
2678 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2679 align = LYX_ALIGN_RIGHT;
2680 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2681 align = LYX_ALIGN_CENTER;
2683 align = LYX_ALIGN_BLOCK;
2685 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2686 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2688 current_view->buffer()->text->SetParagraph(line_top,
2697 current_view->buffer()->update(1);
2698 minibuffer->Set(_("Paragraph layout set"));
2702 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2704 fl_hide_form(fd_form_paragraph->form_paragraph);
2708 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2710 ParagraphApplyCB(ob, data);
2711 ParagraphCancelCB(ob, data);
2715 /* callbacks for form form_character */
2717 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2719 // we set toggleall locally here, since it should be true for
2720 // all other uses of ToggleAndShow() (JMarc)
2721 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2722 ToggleAndShow( UserFreeFont());
2727 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2729 fl_hide_form(fd_form_character->form_character);
2733 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2735 CharacterApplyCB(ob, data);
2736 CharacterCloseCB(ob, data);
2740 /* callbacks for form form_document */
2742 void UpdateDocumentButtons(BufferParams const & params)
2744 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2746 if (params.sides == 2)
2747 fl_set_button(fd_form_document->radio_sides_two, 1);
2749 fl_set_button(fd_form_document->radio_sides_one, 1);
2751 if (params.columns == 2)
2752 fl_set_button(fd_form_document->radio_columns_two, 1);
2754 fl_set_button(fd_form_document->radio_columns_one, 1);
2756 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2757 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2758 params.secnumdepth);
2759 fl_set_counter_value(fd_form_document->slider_tocdepth,
2764 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2767 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2768 if (AskQuestion(_("Should I set some parameters to"),
2769 fl_get_choice_text(ob),
2770 _("the defaults of this document class?"))) {
2771 BufferParams params = BufferParams();
2772 params.textclass = fl_get_choice(ob)-1;
2773 params.useClassDefaults();
2774 UpdateLayoutDocument(¶ms);
2775 UpdateDocumentButtons(params);
2778 // unable to load new style
2779 WriteAlert(_("Conversion Errors!"),
2780 _("Unable to switch to new document class."),
2781 _("Reverting to original document class."));
2782 fl_set_choice(fd_form_document->choice_class,
2783 GetCurrentTextClass() + 1);
2789 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2791 // "Synchronize" the choice and the input field, so that it
2792 // is impossible to commit senseless data.
2793 FD_form_document const * fd = fd_form_document;
2795 if (obj == fd->choice_default_skip) {
2796 if (fl_get_choice (fd->choice_default_skip) != 4) {
2797 fl_set_input (fd->input_default_skip, "");
2798 ActivateDocumentButtons();
2800 } else if (obj == fd->input_default_skip) {
2802 char const * input = fl_get_input (fd->input_default_skip);
2805 fl_set_choice (fd->choice_default_skip, 2);
2806 ActivateDocumentButtons();
2807 } else if (isValidGlueLength (input)) {
2808 fl_set_choice (fd->choice_default_skip, 4);
2809 ActivateDocumentButtons();
2811 fl_set_choice (fd->choice_default_skip, 4);
2812 DeactivateDocumentButtons();
2818 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2820 // "Synchronize" the choice and the input field, so that it
2821 // is impossible to commit senseless data.
2822 FD_form_document const * fd = fd_form_document;
2824 if (obj == fd->choice_spacing
2825 && fl_get_choice (fd->choice_spacing) != 4) {
2826 fl_set_input(fd->input_spacing, "");
2827 } else if (obj == fd->input_spacing) {
2829 const char* input = fl_get_input (fd->input_spacing);
2832 fl_set_choice (fd->choice_spacing, 1);
2834 fl_set_choice (fd->choice_spacing, 4);
2840 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2843 BufferParams *params = &(current_view->buffer()->params);
2844 current_view->buffer()->params.language =
2845 combo_language->getline();
2847 // If default skip is a "Length" but there's no text in the
2848 // input field, reset the kind to "Medskip", which is the default.
2849 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2850 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2851 fl_set_choice (fd_form_document->choice_default_skip, 2);
2854 /* this shouldn't be done automatically IMO. For example I write german
2855 * documents with an american keyboard very often. Matthias */
2857 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2858 fl_get_choice(fd_form_document->choice_language)); */
2860 fl_get_choice_text(fd_form_document->choice_fonts);
2862 fl_get_choice_text(fd_form_document->choice_inputenc);
2864 fl_get_choice_text(fd_form_document->choice_fontsize);
2866 fl_get_choice_text(fd_form_document->choice_pagestyle);
2867 params->graphicsDriver =
2868 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2869 params->use_amsmath =
2870 fl_get_button(fd_form_document->check_use_amsmath);
2872 if (!current_view->available())
2875 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2876 if (params->textclass != new_class) {
2877 // try to load new_class
2878 if (textclasslist.Load(new_class)) {
2879 // successfully loaded
2881 minibuffer->Set(_("Converting document to new document class..."));
2882 int ret = current_view->buffer()->
2884 SwitchLayoutsBetweenClasses(current_view->buffer()->
2887 current_view->buffer()->
2893 s = _("One paragraph couldn't be converted");
2896 s += _(" paragraphs couldn't be converted");
2898 WriteAlert(_("Conversion Errors!"), s,
2899 _("into chosen document class"));
2902 params->textclass = new_class;
2904 // problem changing class -- warn user and retain old style
2905 WriteAlert(_("Conversion Errors!"),
2906 _("Unable to switch to new document class."),
2907 _("Reverting to original document class."));
2908 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2912 char tmpsep = params->paragraph_separation;
2913 if (fl_get_button(fd_form_document->radio_indent))
2914 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2916 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2917 if (tmpsep != params->paragraph_separation)
2920 VSpace tmpdefskip = params->getDefSkip();
2921 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2922 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2923 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2924 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2925 case 4: params->setDefSkip(
2926 VSpace (LyXGlueLength (fl_get_input
2927 (fd_form_document->input_default_skip))));
2929 // DocumentDefskipCB assures that this never happens
2930 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2932 if (!(tmpdefskip == params->getDefSkip()))
2935 if (fl_get_button(fd_form_document->radio_columns_two))
2936 params->columns = 2;
2938 params->columns = 1;
2939 if (fl_get_button(fd_form_document->radio_sides_two))
2940 params->sides = LyXTextClass::TwoSides;
2942 params->sides = LyXTextClass::OneSide;
2944 Spacing tmpSpacing = params->spacing;
2945 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2947 lyxerr.debug() << "Spacing: SINGLE" << endl;
2948 params->spacing.set(Spacing::Single);
2951 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2952 params->spacing.set(Spacing::Onehalf);
2955 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2956 params->spacing.set(Spacing::Double);
2959 lyxerr.debug() << "Spacing: OTHER" << endl;
2960 params->spacing.set(Spacing::Other,
2961 fl_get_input(fd_form_document->input_spacing));
2964 if (tmpSpacing != params->spacing)
2967 signed char tmpchar =
2968 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2969 if (params->secnumdepth != tmpchar)
2971 params->secnumdepth = tmpchar;
2974 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2976 params->float_placement =
2977 fl_get_input(fd_form_document->input_float_placement);
2979 // More checking should be done to ensure the string doesn't have
2980 // spaces or illegal placement characters in it. (thornley)
2983 current_view->redoCurrentBuffer();
2985 minibuffer->Set(_("Document layout set"));
2986 current_view->buffer()->markDirty();
2989 fl_get_input(fd_form_document->input_extra);
2994 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2996 fl_hide_form(fd_form_document->form_document);
3000 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3002 DocumentCancelCB(ob, data);
3003 DocumentApplyCB(ob, data);
3007 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3010 // bullet callbacks etc. in bullet_panel.C -- ARRae
3016 if (!current_view->getScreen())
3019 current_view->getScreen()->HideCursor();
3021 current_view->buffer()->update(-2);
3024 if (!current_view->buffer()->text->GotoNextNote()) {
3025 if (current_view->buffer()->text->cursor.pos
3026 || current_view->buffer()->text->cursor.par !=
3027 current_view->buffer()->text->FirstParagraph())
3029 tmp = current_view->buffer()->text->cursor;
3030 current_view->buffer()->text->cursor.par =
3031 current_view->buffer()->text->FirstParagraph();
3032 current_view->buffer()->text->cursor.pos = 0;
3033 if (!current_view->buffer()->text->GotoNextNote()) {
3034 current_view->buffer()->text->cursor = tmp;
3035 minibuffer->Set(_("No more notes"));
3039 minibuffer->Set(_("No more notes"));
3043 current_view->buffer()->update(0);
3044 current_view->buffer()->text->sel_cursor =
3045 current_view->buffer()->text->cursor;
3049 void InsertCorrectQuote()
3051 Buffer * cbuffer = current_view->buffer();
3054 if (cbuffer->text->cursor.pos )
3055 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3059 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3063 /* callbacks for form form_quotes */
3065 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3067 if (!current_view->available())
3070 minibuffer->Set(_("Quotes type set"));
3071 //current_view->buffer()->params.quotes_language =
3072 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3073 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3074 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3076 lga = InsetQuotes::EnglishQ;
3079 lga = InsetQuotes::SwedishQ;
3082 lga = InsetQuotes::GermanQ;
3085 lga = InsetQuotes::PolishQ;
3088 lga = InsetQuotes::FrenchQ;
3091 lga = InsetQuotes::DanishQ;
3094 current_view->buffer()->params.quotes_language = lga;
3095 if (fl_get_button(fd_form_quotes->radio_single))
3096 current_view->buffer()->
3097 params.quotes_times = InsetQuotes::SingleQ;
3099 current_view->buffer()->
3100 params.quotes_times = InsetQuotes::DoubleQ;
3104 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3106 fl_hide_form(fd_form_quotes->form_quotes);
3110 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3112 QuotesApplyCB(ob, data);
3113 QuotesCancelCB(ob, data);
3118 /* callbacks for form form_preamble */
3120 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3122 fl_hide_form(fd_form_preamble->form_preamble);
3126 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3128 if (!current_view->available())
3131 current_view->buffer()->params.preamble =
3132 fl_get_input(fd_form_preamble->input_preamble);
3133 current_view->buffer()->markDirty();
3134 minibuffer->Set(_("LaTeX preamble set"));
3138 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3140 PreambleApplyCB(ob, data);
3141 PreambleCancelCB(ob, data);
3145 /* callbacks for form form_table */
3147 extern "C" void TableApplyCB(FL_OBJECT *, long)
3149 if (!current_view->getScreen())
3152 // check for tables in tables
3153 if (current_view->buffer()->text->cursor.par->table){
3154 WriteAlert(_("Impossible Operation!"),
3155 _("Cannot insert table in table."),
3160 minibuffer->Set(_("Inserting table..."));
3162 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3163 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3166 current_view->getScreen()->HideCursor();
3168 current_view->buffer()->update(-2);
3170 current_view->buffer()->text->SetCursorParUndo();
3171 current_view->buffer()->text->FreezeUndo();
3173 current_view->buffer()->text->BreakParagraph();
3174 current_view->buffer()->update(-1);
3176 if (current_view->buffer()->text->cursor.par->Last()) {
3177 current_view->buffer()->text->CursorLeft();
3179 current_view->buffer()->text->BreakParagraph();
3180 current_view->buffer()->update(-1);
3183 current_view->buffer()->text->current_font.setLatex(LyXFont::OFF);
3184 //if (!fl_get_button(fd_form_table->check_latex)){
3185 // insert the new wysiwy table
3186 current_view->buffer()->text->SetLayout(0); // standard layout
3187 if (current_view->buffer()->text->cursor.par->footnoteflag ==
3188 LyXParagraph::NO_FOOTNOTE) {
3189 current_view->buffer()->
3190 text->SetParagraph(0, 0,
3192 VSpace (0.3 * current_view->buffer()->
3193 params.spacing.getValue(),
3195 VSpace (0.3 * current_view->buffer()->
3196 params.spacing.getValue(),
3203 current_view->buffer()->
3204 text->SetParagraph(0, 0,
3206 VSpace(VSpace::NONE),
3207 VSpace(VSpace::NONE),
3212 current_view->buffer()->text->cursor.par->table =
3213 new LyXTable(xsize, ysize);
3215 for (int i = 0; i < xsize * ysize - 1; ++i)
3216 current_view->buffer()->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3217 current_view->buffer()->text->RedoParagraph();
3219 current_view->buffer()->text->UnFreezeUndo();
3221 current_view->buffer()->update(1);
3222 minibuffer->Set(_("Table inserted"));
3226 extern "C" void TableCancelCB(FL_OBJECT *, long)
3228 fl_hide_form(fd_form_table->form_table);
3232 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3234 TableApplyCB(ob, data);
3235 TableCancelCB(ob, data);
3239 /* callbacks for form form_print */
3241 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3243 fl_hide_form(fd_form_print->form_print);
3246 static bool stringOnlyContains (string const & LStr, char const * cset)
3248 char const * cstr = LStr.c_str() ;
3250 return strspn(cstr, cset) == strlen(cstr) ;
3253 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3255 if (!current_view->available())
3257 Buffer * buffer = current_view->buffer();
3258 string path = OnlyPath(buffer->getFileName());
3261 if (fl_get_button(fd_form_print->radio_even_pages))
3262 pageflag = lyxrc->print_evenpage_flag + ' ';
3263 else if (fl_get_button(fd_form_print->radio_odd_pages))
3264 pageflag = lyxrc->print_oddpage_flag + ' ';
3266 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3267 // User may give a page (range) list
3268 // User may print multiple (unsorted) copies
3269 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3270 pages = subst(pages, '+',',');
3271 pages = frontStrip(strip(pages)) ;
3272 while (!pages.empty()) { // a page range was given
3274 pages = split (pages, piece, ',') ;
3275 piece = strip(piece) ;
3276 piece = frontStrip(piece) ;
3277 if ( !stringOnlyContains (piece, "0123456789-") ) {
3278 WriteAlert(_("ERROR! Unable to print!"),
3279 _("Check 'range of pages'!"));
3282 if (piece.find('-') == string::npos) { // not found
3283 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3284 } else if (suffixIs(piece, "-") ) { // missing last page
3285 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3286 } else if (prefixIs(piece, "-") ) { // missing first page
3287 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3289 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3293 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3294 if (!copies.empty()) { // a number of copies was given
3295 if ( !stringOnlyContains (copies, "0123456789") ) {
3296 WriteAlert(_("ERROR! Unable to print!"),
3297 _("Check 'number of copies'!"));
3300 if (fl_get_button(fd_form_print->do_unsorted))
3301 pageflag += lyxrc->print_copies_flag;
3303 pageflag += lyxrc->print_collcopies_flag;
3304 pageflag += " " + copies + ' ' ;
3308 if (fl_get_button(fd_form_print->radio_order_reverse))
3309 reverseflag = lyxrc->print_reverse_flag + ' ';
3311 string orientationflag;
3312 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3313 orientationflag = lyxrc->print_landscape_flag + ' ';
3315 string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
3316 string printer = strip(fl_get_input(fd_form_print->input_printer));
3319 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3320 && ! printer.empty()) // a printer name has been given
3321 printerflag = lyxrc->print_to_printer + printer + ' ';
3324 if (!lyxrc->print_extra_options.empty())
3325 extraflags = lyxrc->print_extra_options + ' ';
3327 string command = lyxrc->print_command + ' '
3328 + printerflag + pageflag + reverseflag
3329 + orientationflag + extraflags;
3331 char real_papersize = buffer->params.papersize;
3332 if (real_papersize == BufferParams::PAPER_DEFAULT)
3333 real_papersize = lyxrc->default_papersize;
3336 switch (real_papersize) {
3337 case BufferParams::PAPER_USLETTER:
3340 case BufferParams::PAPER_A3PAPER:
3343 case BufferParams::PAPER_A4PAPER:
3346 case BufferParams::PAPER_A5PAPER:
3349 case BufferParams::PAPER_B5PAPER:
3352 case BufferParams::PAPER_EXECUTIVEPAPER:
3355 case BufferParams::PAPER_LEGALPAPER:
3358 default: /* If nothing else fits, keep an empty value... */
3362 if (buffer->params.use_geometry
3363 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3364 && !lyxrc->print_paper_dimension_flag.empty()
3365 && !buffer->params.paperwidth.empty()
3366 && !buffer->params.paperheight.empty()) {
3367 // using a custom papersize
3369 command += lyxrc->print_paper_dimension_flag + ' ';
3370 command += buffer->params.paperwidth + ',';
3371 command += buffer->params.paperheight + ' ';
3372 } else if (!lyxrc->print_paper_flag.empty()
3374 && (real_papersize != BufferParams::PAPER_USLETTER ||
3375 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3376 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3378 if (fl_get_button(fd_form_print->radio_file))
3379 command += lyxrc->print_to_file + '\"'
3380 + MakeAbsPath(ps_file, path)
3382 else if (!lyxrc->print_spool_command.empty())
3383 command += lyxrc->print_to_file
3384 + '\"' + ps_file + '\"';
3386 // push directorypath, if necessary
3387 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3388 path = buffer->tmppath;
3393 if (!lyxrc->print_spool_command.empty() &&
3394 !fl_get_button(fd_form_print->radio_file)) {
3395 string command2 = lyxrc->print_spool_command + ' ';
3396 if (!printer.empty())
3397 command2 += lyxrc->print_spool_printerprefix
3399 // First run dvips and, if succesful, then spool command
3400 if ((result = RunScript(buffer, true, command))) {
3401 result = RunScript(buffer, false, command2, ps_file);
3404 result = RunScript(buffer, false, command);
3407 WriteAlert(_("Error:"),
3408 _("Unable to print"),
3409 _("Check that your parameters are correct"));
3413 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3415 PrintCancelCB(ob, data);
3416 PrintApplyCB(ob, data);
3420 /* callbacks for form form_figure */
3422 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3424 if (!current_view->available())
3427 Buffer * buffer = current_view->buffer();
3428 if(buffer->isReadonly()) // paranoia
3431 minibuffer->Set(_("Inserting figure..."));
3432 if (fl_get_button(fd_form_figure->radio_inline)
3433 || buffer->text->cursor.par->table) {
3434 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3435 buffer->insertInset(new_inset);
3436 minibuffer->Set(_("Figure inserted"));
3437 new_inset->Edit(0, 0);
3441 current_view->getScreen()->HideCursor();
3445 buffer->text->SetCursorParUndo();
3446 buffer->text->FreezeUndo();
3448 buffer->text->BreakParagraph();
3451 if (buffer->text->cursor.par->Last()) {
3452 buffer->text->CursorLeft();
3454 buffer->text->BreakParagraph();
3458 // The standard layout should always be numer 0;
3459 buffer->text->SetLayout(0);
3461 if (buffer->text->cursor.par->footnoteflag ==
3462 LyXParagraph::NO_FOOTNOTE) {
3466 VSpace (0.3 * buffer->params.spacing.getValue(),
3469 buffer->params.spacing.getValue(),
3471 LYX_ALIGN_CENTER, string(), 0);
3473 buffer->text->SetParagraph(0, 0,
3475 VSpace(VSpace::NONE),
3476 VSpace(VSpace::NONE),
3483 Inset * new_inset = new InsetFig(100, 100, buffer);
3484 buffer->insertInset(new_inset);
3485 new_inset->Edit(0, 0);
3487 minibuffer->Set(_("Figure inserted"));
3488 buffer->text->UnFreezeUndo();
3492 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3494 fl_hide_form(fd_form_figure->form_figure);
3498 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3500 FigureApplyCB(ob, data);
3501 FigureCancelCB(ob, data);
3505 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3507 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3508 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3509 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3510 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3511 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3512 fontloader.update();
3514 // All buffers will need resize
3515 bufferlist.resize();
3517 minibuffer->Set(_("Screen options set"));
3521 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3523 fl_hide_form(fd_form_screen->form_screen);
3527 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3529 ScreenCancelCB(ob, data);
3530 ScreenApplyCB(ob, data);
3536 if (!current_view->available())
3539 fl_set_button(fd_latex_options->accents,
3540 (int)current_view->buffer()->params.allowAccents);
3542 if (fd_latex_options->LaTeXOptions->visible) {
3543 fl_raise_form(fd_latex_options->LaTeXOptions);
3545 fl_show_form(fd_latex_options->LaTeXOptions,
3546 FL_PLACE_MOUSE, FL_FULLBORDER,
3547 _("LaTeX Options"));
3552 // This function runs "configure" and then rereads lyx.defaults to
3553 // reconfigure the automatic settings.
3556 minibuffer->Set(_("Running configure..."));
3558 // Run configure in user lyx directory
3559 Path p(user_lyxdir);
3560 Systemcalls one(Systemcalls::System,
3561 AddName(system_lyxdir, "configure"));
3563 minibuffer->Set(_("Reloading configuration..."));
3564 lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults"));
3565 WriteAlert(_("The system has been reconfigured."),
3566 _("You need to restart LyX to make use of any"),
3567 _("updated document class specifications."));
3571 /* these functions are for the spellchecker */
3572 char * NextWord(float & value)
3574 if (!current_view->available()){
3579 char * string = current_view->buffer()->text->SelectNextWord(value);
3585 void SelectLastWord()
3587 if (!current_view->available())
3590 current_view->getScreen()->HideCursor();
3592 current_view->buffer()->text->SelectSelectedWord();
3593 current_view->getScreen()->ToggleSelection(false);
3594 current_view->buffer()->update(0);
3598 void EndOfSpellCheck()
3600 if (!current_view->available())
3603 current_view->getScreen()->HideCursor();
3605 current_view->buffer()->text->SelectSelectedWord();
3606 current_view->buffer()->text->ClearSelection();
3607 current_view->buffer()->update(0);
3611 void ReplaceWord(string const & replacestring)
3613 if (!current_view->getScreen())
3616 current_view->getScreen()->HideCursor();
3617 current_view->buffer()->update(-2);
3619 /* clear the selection (if there is any) */
3620 current_view->getScreen()->ToggleSelection(false);
3621 current_view->buffer()->text->
3622 ReplaceSelectionWithString(replacestring.c_str());
3624 current_view->buffer()->text->SetSelectionOverString(replacestring.c_str());
3626 // Go back so that replacement string is also spellchecked
3627 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3628 current_view->buffer()->text->CursorLeftIntern();
3630 current_view->buffer()->update(1);
3632 // End of spellchecker stuff
3637 // Table of Contents
3647 static TocList * toclist = 0;
3650 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3652 if (!current_view->available())
3655 TocList * tmptoclist = toclist;
3656 int i = fl_get_browser(ob);
3657 for (int a = 1; a < i && tmptoclist->next; ++a) {
3658 tmptoclist = tmptoclist->next;
3665 LyXParagraph * par = current_view->buffer()->paragraph;
3666 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3667 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3668 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3669 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3670 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3671 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3672 par->appendix != tmptoclist->appendix)) {
3673 par = par->LastPhysicalPar()->Next();
3678 current_view->buffer()->text->SetCursor(par, 0);
3679 current_view->buffer()->text->sel_cursor =
3680 current_view->buffer()->text->cursor;
3681 current_view->buffer()->update(0);
3684 WriteAlert(_("Error"),
3685 _("Couldn't find this label"),
3686 _("in current document."));
3692 extern "C" void TocCancelCB(FL_OBJECT *, long)
3694 fl_hide_form(fd_form_toc->form_toc);
3698 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3700 static LyXParagraph * stapar = 0;
3701 TocList * tmptoclist = 0;
3703 /* deleted the toclist */
3706 tmptoclist = toclist->next;
3708 toclist = tmptoclist;
3712 tmptoclist = toclist;
3715 fl_clear_browser(fd_form_toc->browser_toc);
3716 if (!current_view->available()) {
3717 fl_add_browser_line(fd_form_toc->browser_toc,
3718 _("*** No Document ***"));
3721 fl_hide_object(fd_form_toc->browser_toc);
3722 /* get the table of contents */
3723 LyXParagraph * par = current_view->buffer()->paragraph;
3725 char * line = new char[200];
3731 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3735 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3736 par->GetLayout()).labeltype;
3738 if (labeltype >= LABEL_COUNTER_CHAPTER
3739 && labeltype <= LABEL_COUNTER_CHAPTER +
3740 current_view->buffer()->params.tocdepth) {
3741 /* insert this into the table of contents */
3742 /* first indent a little bit */
3746 textclasslist.TextClass(current_view->buffer()->
3747 params.textclass).maxcounter()) * 4 + 2;
3751 // Then the labestring
3752 if (!par->labelstring.empty()) {
3753 string::size_type i = 0;
3754 while (pos < 199 && i < par->labelstring.length()) {
3755 line[pos] = par->labelstring[i];
3764 /* now the contents */
3765 LyXParagraph::size_type i = 0;
3766 while (pos < 199 && i < par->size()) {
3767 c = par->GetChar(i);
3768 if (isprint(c) || c >= 128) {
3775 fl_add_browser_line(fd_form_toc->browser_toc, line);
3777 /* make a toclist entry */
3779 tmptoclist = new TocList;
3780 toclist = tmptoclist;
3782 tmptoclist->next = new TocList;
3783 tmptoclist = tmptoclist->next;
3786 tmptoclist->next = 0;
3788 for (a = 0; a<6; a++){
3789 tmptoclist->counter[a] = par->GetFirstCounter(a);
3791 tmptoclist->appendix = par->appendix;
3793 par = par->LastPhysicalPar()->Next();
3797 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3798 fl_show_object(fd_form_toc->browser_toc);
3802 /* callbacks for form form_ref */
3803 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3805 if (!current_view->available())
3809 fl_get_browser_line(fd_form_ref->browser_ref,
3810 fl_get_browser(fd_form_ref->browser_ref));
3811 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3817 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3827 if(current_view->buffer()->isSGML())
3828 t += "[" + u + "]" + "{" + s + "}";
3833 new InsetRef(t, current_view->buffer());
3834 current_view->buffer()->insertInset(new_inset);
3838 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3840 if (!current_view->available()) {
3841 fl_clear_browser(fd_form_ref->browser_ref);
3845 FL_OBJECT * brow = fd_form_ref->browser_ref;
3847 // Get the current line, in order to restore it later
3848 char const * const btmp = fl_get_browser_line(brow,
3849 fl_get_browser(brow));
3850 string currentstr = btmp ? btmp : "";
3851 //string currentstr = fl_get_browser_line(brow,
3852 // fl_get_browser(brow));
3854 fl_clear_browser(brow);
3856 string refs = current_view->buffer()->getReferenceList('\n');
3859 #if FL_REVISION > 85
3860 fl_addto_browser_chars(brow, refs.c_str());
3861 int total_lines = fl_get_browser_maxline(brow);
3862 for (int i = 1; i <= total_lines ; i++) {
3863 if (fl_get_browser_line(brow, i) == currentstr) {
3868 fl_set_browser_topline(brow, topline);
3870 // Keep the old ugly code for xforms 0.81 compatibility
3875 curr_ref = refs.token('\n', ref_num);
3876 if (curr_ref.empty())
3878 fl_add_browser_line(brow, curr_ref.c_str());
3883 if (!fl_get_browser_maxline(brow)) {
3884 fl_add_browser_line(brow,
3885 _("*** No labels found in document ***"));
3886 fl_deactivate_object(brow);
3888 fl_select_browser_line(brow, topline);
3889 fl_activate_object(brow);
3891 if (current_view->buffer()->isReadonly()) {
3892 // would be better to de/activate insert buttons
3893 // but that's more work... besides this works. ARRae
3894 fl_hide_form(fd_form_ref->form_ref);
3896 if (!current_view->buffer()->isSGML()) {
3897 fl_deactivate_object(fd_form_ref->ref_name);
3898 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3901 fl_activate_object(fd_form_ref->ref_name);
3902 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3907 extern "C" void RefHideCB(FL_OBJECT *, long)
3909 fl_hide_form(fd_form_ref->form_ref);
3913 void UpdateInset(Inset * inset, bool mark_dirty)
3918 /* very first check for locking insets*/
3919 if (current_view->buffer()->the_locking_inset == inset){
3920 if (current_view->buffer()->text->UpdateInset(inset)){
3921 current_view->update();
3923 if (current_view->buffer()->isLyxClean())
3924 minibuffer->setTimer(4);
3925 current_view->buffer()->markDirty();
3927 current_view->updateScrollbar();
3932 /* first check the current buffer */
3933 if (current_view->available()){
3934 current_view->getScreen()->HideCursor();
3935 current_view->buffer()->update(-3);
3936 if (current_view->buffer()->text->UpdateInset(inset)){
3938 current_view->buffer()->update(1);
3940 current_view->buffer()->update(3);
3945 // check all buffers
3946 bufferlist.updateInset(inset, mark_dirty);
3951 /* these functions return 1 if an error occured,
3953 int LockInset(UpdatableInset * inset)
3955 if (!current_view->buffer()->the_locking_inset && inset){
3956 current_view->buffer()->the_locking_inset = inset;
3963 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
3965 if (current_view->buffer()->the_locking_inset &&
3966 current_view->getScreen()){
3967 y += current_view->buffer()->text->cursor.y;
3968 current_view->getScreen()->ShowManualCursor(x, y,
3974 void HideLockedInsetCursor(long x, long y, int asc, int desc)
3976 if (current_view->buffer()->the_locking_inset &&
3977 current_view->getScreen()){
3978 y += current_view->buffer()->text->cursor.y;
3979 current_view->getScreen()->HideManualCursor(x, y,
3985 void FitLockedInsetCursor(long x, long y, int asc, int desc)
3987 if (current_view->buffer()->the_locking_inset &&
3988 current_view->getScreen()){
3989 y += current_view->buffer()->text->cursor.y;
3990 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
3991 current_view->updateScrollbar();
3996 int UnlockInset(UpdatableInset * inset)
3999 current_view->buffer()->the_locking_inset == inset){
4000 inset->InsetUnlock();
4001 current_view->buffer()->the_locking_inset = 0;
4002 current_view->buffer()->text->FinishUndo();
4005 return bufferlist.unlockInset(inset);
4009 void LockedInsetStoreUndo(Undo::undo_kind kind)
4011 if (!current_view->buffer()->the_locking_inset)
4012 return; // shouldn't happen
4013 if (kind == Undo::EDIT) // in this case insets would not be stored!
4014 kind = Undo::FINISH;
4015 current_view->buffer()->text->SetUndo(kind,
4016 current_view->buffer()->text->cursor.par->
4017 ParFromPos(current_view->buffer()->text->cursor.pos)->previous,
4018 current_view->buffer()->text->cursor.par->
4019 ParFromPos(current_view->buffer()->text->cursor.pos)->next);
4023 void PutInsetIntoInsetUpdateList(Inset * inset)
4026 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4028 tmp->next = InsetUpdateList;
4029 InsetUpdateList = tmp;
4034 void UpdateInsetUpdateList()
4036 InsetUpdateStruct * tmp = InsetUpdateList;
4038 UpdateInset(tmp->inset, false); // "false" because no document change
4042 // delete the update list
4043 while (InsetUpdateList) {
4044 tmp = InsetUpdateList;
4045 InsetUpdateList = InsetUpdateList->next;
4048 InsetUpdateList = 0;
4052 #ifdef WITH_WARNINGS
4055 // I know we shouldn't put anything in here but this seems the fastest
4056 // way to do this (and the cleanest for now). This function just inserts
4057 // a newline in the string and the inserts 'depth'-spaces so that the
4058 // code is indented in the right way!!!
4059 void addNewlineAndDepth(string & file, int const depth)
4062 file.append(depth, ' ');