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 char cursor_undefined = 1;
248 if (cursor_undefined){
249 cursor = XCreateFontCursor(fl_display, XC_xterm);
251 cursor_undefined = 0;
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();
471 s = _("Wrong type of document");
472 t = _("The Build operation is not allowed in this document");
473 WriteAlert(_("There were errors during the Build process."), s, t);
481 s = _("One error detected");
482 t = _("You should try to fix it.");
485 s += _(" errors detected.");
486 t = _("You should try to fix them.");
488 WriteAlert(_("There were errors during the Build process."), s, t);
494 int MenuRunChktex(Buffer *buffer)
498 if (buffer->isSGML()) {
499 WriteAlert(_("Chktex does not work with SGML derived documents."));
502 ret = buffer->runChktex();
508 s = _("No warnings found.");
509 } else if (ret == 1) {
510 s = _("One warning found.");
511 t = _("Use 'Edit->Go to Error' to find it.");
514 s += _(" warnings found.");
515 t = _("Use 'Edit->Go to Error' to find them.");
517 WriteAlert(_("Chktex run successfully"), s, t);
519 WriteAlert(_("Error!"), _("It seems chktex does not work."));
525 int MakeDVIOutput(Buffer *buffer)
532 string path = OnlyPath(buffer->getFileName());
533 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
534 path = buffer->tmppath;
536 if (!buffer->isDviClean()) {
538 ret = MenuRunLaTeX(buffer);
544 /* wait == false means don't wait for termination */
545 /* wait == true means wait for termination */
546 // The bool should be placed last on the argument line. (Lgb)
547 // Returns false if we fail.
548 bool RunScript(Buffer * buffer, bool wait,
549 string const & command, string const & orgname = string(),
550 bool need_shell = true)
554 string name = orgname;
557 if (MakeDVIOutput(buffer) > 0)
559 /* get DVI-Filename */
561 name = ChangeExtension(buffer->getFileName(),
564 path = OnlyPath(name);
565 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
566 path = buffer->tmppath;
570 cmd = command + ' ' + SpaceLess(name);
578 // OS/2 cmd.exe has another use for '&'
580 // This is not NLS safe, but it's OK, I think.
581 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
583 // COMSPEC is set, unless user unsets
584 sh = OnlyFilename(GetEnvPath("COMSPEC"));
589 if (contains(sh, "cmd.exe")
590 || contains(sh, "4os2.exe"))
591 cmd = "start /min/n " + cmd;
596 // It seems that, if wait is false, we never get back
597 // the return code of the command. This means that all
598 // the code I added in PrintApplyCB is currently
601 #warning What should we do here?
603 minibuffer->Set(_("Executing command:"), cmd);
604 result = one.startscript(Systemcalls::System, cmd);
606 minibuffer->Set(_("Executing command:"), cmd);
607 result = one.startscript(wait ? Systemcalls::Wait
608 : Systemcalls::DontWait, cmd);
610 return (result == 0);
614 // Returns false if we fail
615 bool MenuRunDvips(Buffer *buffer, bool wait = false)
623 if (MakeDVIOutput(buffer) > 0) {
627 // Generate postscript file
628 string ps = ChangeExtension (buffer->getFileName(),
633 char real_papersize = buffer->params.papersize;
634 if (real_papersize == BufferParams::PAPER_DEFAULT)
635 real_papersize = lyxrc->default_papersize;
637 switch (real_papersize) {
638 case BufferParams::PAPER_USLETTER:
641 case BufferParams::PAPER_A3PAPER:
644 case BufferParams::PAPER_A4PAPER:
647 case BufferParams::PAPER_A5PAPER:
650 case BufferParams::PAPER_B5PAPER:
653 case BufferParams::PAPER_EXECUTIVEPAPER:
656 case BufferParams::PAPER_LEGALPAPER:
659 default: /* If nothing else fits, keep an empty value... */
663 // Make postscript file.
664 string command = "dvips " + lyxrc->print_to_file + ' ';
665 command += SpaceLess(ps);
666 if (buffer->params.use_geometry
667 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
668 && !lyxrc->print_paper_dimension_flag.empty()
669 && !buffer->params.paperwidth.empty()
670 && !buffer->params.paperheight.empty()) {
671 // using a custom papersize
673 command += lyxrc->print_paper_dimension_flag + ' ';
674 command += buffer->params.paperwidth + ',';
675 command += buffer->params.paperheight;
676 } else if (!paper.empty()
677 && (real_papersize != BufferParams::PAPER_USLETTER ||
678 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
679 // dvips won't accept -t letter -t landscape. In all other
680 // cases, include the paper size explicitly.
682 command += lyxrc->print_paper_flag + ' ' + paper;
684 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
686 command += lyxrc->print_landscape_flag;
688 // push directorypath, if necessary
689 string path = OnlyPath(buffer->getFileName());
690 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
691 path = buffer->tmppath;
694 bool ret = RunScript(buffer, wait, command);
700 // Returns false if we fail
701 bool MenuPreviewPS(Buffer *buffer)
706 // Generate postscript file
707 if (!MenuRunDvips(buffer, true)) {
711 // Start postscript viewer
713 string ps = ChangeExtension (buffer->getFileName(),
715 // push directorypath, if necessary
716 string path = OnlyPath(buffer->getFileName());
717 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
718 path = buffer->tmppath;
721 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
727 void MenuFax(Buffer *buffer)
732 // Generate postscript file
733 if (!MenuRunDvips(buffer, true)) {
738 string ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true);
739 string path = OnlyPath (buffer->getFileName());
740 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
741 path = buffer->tmppath;
744 if (!lyxrc->fax_program.empty()) {
745 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
747 Systemcalls one(Systemcalls::System, help2);
749 send_fax(ps, lyxrc->fax_command);
753 // Returns false if we fail
754 bool MenuPreview(Buffer *buffer)
761 char real_papersize = buffer->params.papersize;
762 if (real_papersize == BufferParams::PAPER_DEFAULT)
763 real_papersize = lyxrc->default_papersize;
765 switch (real_papersize) {
766 case BufferParams::PAPER_USLETTER:
769 case BufferParams::PAPER_A3PAPER:
772 case BufferParams::PAPER_A4PAPER:
775 case BufferParams::PAPER_A5PAPER:
778 case BufferParams::PAPER_B5PAPER:
781 case BufferParams::PAPER_EXECUTIVEPAPER:
784 case BufferParams::PAPER_LEGALPAPER:
787 default: /* If nothing else fits, keep the empty value */
792 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
793 // we HAVE to give a size when the page is in
794 // landscape, so use USletter.
795 paper = " -paper usr";
797 paper = " -paper " + paper;
798 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
802 // push directorypath, if necessary
803 string path = OnlyPath(buffer->getFileName());
804 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
805 path = buffer->tmppath;
809 string command = lyxrc->view_dvi_command + paper ;
810 bool ret = RunScript(buffer, false, command);
815 void MenuMakeLaTeX(Buffer * buffer)
818 // Get LaTeX-Filename
819 string s = SpaceLess(ChangeExtension(
820 buffer->getFileName(),
823 FilePtr myfile(s, FilePtr::read);
825 !AskQuestion(_("File already exists:"),
826 MakeDisplayPath(s, 50),
827 _("Do you want to overwrite the file?"))) {
828 minibuffer->Set(_("Canceled"));
832 if (buffer->isDocBook())
833 minibuffer->Set(_("DocBook does not have a latex backend"));
835 if (buffer->isLinuxDoc())
836 RunLinuxDoc(0, buffer->getFileName());
838 buffer->makeLaTeXFile(s, string(), true);
839 minibuffer->Set(_("Nice LaTeX file saved as"),
841 buffer->markDviDirty();
847 void MenuMakeLinuxDoc(Buffer *buffer)
851 if (!buffer->isLinuxDoc()) {
852 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
856 // Get LinuxDoc-Filename
857 string s = ChangeExtension (buffer->getFileName(),
860 FilePtr myfile(s, FilePtr::read);
862 !AskQuestion(_("File already exists:"),
863 MakeDisplayPath(s, 50),
864 _("Do you want to overwrite the file?"))) {
865 minibuffer->Set(_("Canceled"));
869 minibuffer->Set(_("Building LinuxDoc SGML file `"),
870 MakeDisplayPath(s), "'...");
872 buffer->makeLinuxDocFile(s, 65);
874 minibuffer->Set(_("LinuxDoc SGML file save as"),
880 void MenuMakeDocBook(Buffer *buffer)
884 if (!buffer->isDocBook()) {
885 WriteAlert(_("Error!"), _("Document class must be docbook."));
889 // Get DocBook-Filename
890 string s = ChangeExtension (buffer->getFileName(),
893 FilePtr myfile(s, FilePtr::read);
895 !AskQuestion(_("File already exists:"),
896 MakeDisplayPath(s, 50),
897 _("Do you want to overwrite the file?"))) {
898 minibuffer->Set(_("Canceled"));
902 minibuffer->Set(_("Building DocBook SGML file `"),
903 MakeDisplayPath(s), "'...");
905 buffer->makeDocBookFile(s, 65);
907 minibuffer->Set(_("DocBook SGML file save as"),
913 void MenuMakeAscii(Buffer *buffer)
916 /* get LaTeX-Filename */
917 string s = ChangeExtension (buffer->getFileName(),
920 FilePtr myfile(s, FilePtr::read);
922 !AskQuestion(_("File already exists:"),
923 MakeDisplayPath(s, 50),
924 _("Do you want to overwrite the file?"))) {
925 minibuffer->Set(_("Canceled"));
929 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
931 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
936 void MenuPrint(Buffer *buffer)
943 input_file = ChangeExtension(buffer->getFileName(),
944 lyxrc->print_file_extension,
946 fl_set_input(fd_form_print->input_file, input_file.c_str());
948 if (fd_form_print->form_print->visible) {
949 fl_raise_form(fd_form_print->form_print);
952 fl_show_form(fd_form_print->form_print,
953 FL_PLACE_MOUSE, FL_FULLBORDER,
961 lyxerr.debug() << "Running QuitLyX." << endl;
963 if (!bufferlist.QwriteAll())
966 lastfiles->writeFile(lyxrc->lastfiles);
968 // Set a flag that we do quitting from the program,
969 // so no refreshes are necessary.
972 // close buffers first
973 bufferlist.closeAll();
975 // do any other cleanup procedures now
976 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
978 DestroyLyXTmpDir(system_tempdir);
986 // should probably be moved into BufferList (Lgb)
987 // Perfect target for a thread...
989 if (!current_view->getScreen() || !current_view->available())
992 if (current_view->buffer()->isBakClean()
993 || current_view->buffer()->isReadonly()) {
994 // We don't save now, but we'll try again later
995 current_view->owner()->resetAutosaveTimer();
999 minibuffer->Set(_("Autosaving current document..."));
1001 // create autosave filename
1002 string fname = OnlyPath(current_view->buffer()->getFileName());
1004 fname += OnlyFilename(current_view->buffer()->getFileName());
1007 // tmp_ret will be located (usually) in /tmp
1008 // will that be a problem?
1009 string tmp_ret = tmpnam(0);
1011 pid_t pid = fork(); // If you want to debug the autosave
1012 // you should set pid to -1, and comment out the
1014 if (pid == 0 || pid == -1) {
1015 // pid = -1 signifies that lyx was unable
1016 // to fork. But we will do the save
1018 bool failed = false;
1019 if (!tmp_ret.empty()) {
1020 current_view->buffer()->writeFile(tmp_ret, 1);
1021 // assume successful write of tmp_ret
1022 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1024 // most likely couldn't move between filesystems
1025 // unless write of tmp_ret failed
1026 // so remove tmp file (if it exists)
1027 remove(tmp_ret.c_str());
1034 // failed to write/rename tmp_ret so try writing direct
1035 if (!current_view->buffer()->writeFile(fname, 1)) {
1036 // It is dangerous to do this in the child,
1037 // but safe in the parent, so...
1039 minibuffer->Set(_("Autosave Failed!"));
1042 if (pid == 0) { // we are the child so...
1047 current_view->buffer()->markBakClean();
1048 current_view->owner()->resetAutosaveTimer();
1053 // (c) CHT Software Service GmbH
1056 // create new file with template
1059 Buffer * NewLyxFile(string const & filename)
1061 // Split argument by :
1063 string tmpname = split(filename, name, ':');
1064 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1065 if (name.length() == 1
1066 && isalpha(static_cast<unsigned char>(name[0]))
1067 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1069 name += token(tmpname, ':', 0);
1070 tmpname = split(tmpname, ':');
1073 lyxerr.debug() << "Arg is " << filename
1074 << "\nName is " << name
1075 << "\nTemplate is " << tmpname << endl;
1077 // find a free buffer
1078 Buffer *tmpbuf = bufferlist.newFile(name, tmpname);
1080 lastfiles->newFile(tmpbuf->getFileName());
1085 // Insert ascii file (if filename is empty, prompt for one)
1086 void InsertAsciiFile(string const & f, bool asParagraph)
1089 LyXParagraph *tmppar;
1092 if (!current_view->getScreen()) return;
1094 if (fname.empty()) {
1096 fname = fileDlg.Select(_("File to Insert"),
1097 current_view->owner()->buffer()->filepath,
1100 if (fname.empty()) return;
1104 FilePtr myfile(fname, FilePtr::read);
1106 if (!fi.exist() || !fi.readable() || !myfile()) {
1107 WriteFSAlert(_("Error! Cannot open specified file:"),
1108 MakeDisplayPath(fname, 50));
1112 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 BufferParams::PAPER_SIZE ps = current_view->buffer()->params.papersize;
1259 case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1260 case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1261 default: /* nothing to be done yet ;-) */ break;
1269 case -1: /* Import file */
1270 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1271 MakeDisplayPath(filename), "'...");
1272 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1274 if (one.startscript(Systemcalls::System, s2))
1277 case 0: /* TeX output asked */
1278 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1279 s2 = "sgml2latex " + add_flags + " -o tex "
1280 + lyxrc->sgml_extra_options + ' ' + name;
1281 if (one.startscript(Systemcalls::System, s2))
1284 case 1: /* dvi output asked */
1285 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1286 s2 = "sgml2latex " + add_flags + " -o dvi "
1287 + lyxrc->sgml_extra_options + ' ' + name;
1288 if (one.startscript(Systemcalls::System, s2)) {
1291 current_view->buffer()->markDviClean();
1293 default: /* unknown output */
1299 current_view->buffer()->redraw();
1305 * SGML DocBook support:
1306 * (flag == 1) make dvi output
1308 int RunDocBook(int flag, string const & filename)
1316 /* generate a path-less extension name */
1317 name = ChangeExtension (filename, ".sgml", true);
1318 path = OnlyPath (filename);
1319 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1320 path = current_view->buffer()->tmppath;
1324 if (!current_view->available())
1327 current_view->buffer()->makeDocBookFile(name, 0);
1329 // Shall this code go or should it stay? (Lgb)
1330 // string add_flags;
1331 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1333 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1334 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1335 // default: /* nothing to be done yet ;-) */ break;
1341 case 1: /* dvi output asked */
1342 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1343 s2 = "sgmltools --backend dvi " + name;
1344 if (one.startscript(Systemcalls::System, s2)) {
1347 current_view->buffer()->markDviClean();
1349 default: /* unknown output */
1355 current_view->buffer()->redraw();
1360 void AllFloats(char flag, char figmar)
1362 if (!current_view->available())
1365 LyXCursor cursor = current_view->buffer()->text->cursor;
1367 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1369 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1370 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1372 && cursor.par->footnotekind != LyXParagraph::FIG
1373 && cursor.par->footnotekind != LyXParagraph::TAB
1374 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1375 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1376 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1381 LyXCursor tmpcursor = cursor;
1382 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1383 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1385 LyXParagraph *par = current_view->buffer()->paragraph;
1388 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1392 par->footnotekind != LyXParagraph::FOOTNOTE
1394 par->footnotekind != LyXParagraph::MARGIN
1399 par->footnotekind != LyXParagraph::FIG
1401 par->footnotekind != LyXParagraph::TAB
1403 par->footnotekind != LyXParagraph::WIDE_FIG
1405 par->footnotekind != LyXParagraph::WIDE_TAB
1407 par->footnotekind != LyXParagraph::ALGORITHM
1412 && par->previous->footnoteflag !=
1413 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1414 current_view->buffer()->text->SetCursorIntern(par->previous,
1416 current_view->buffer()->text->OpenFootnote();
1421 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1425 par->footnotekind != LyXParagraph::FOOTNOTE
1427 par->footnotekind != LyXParagraph::MARGIN
1432 par->footnotekind != LyXParagraph::FIG
1434 par->footnotekind != LyXParagraph::TAB
1436 par->footnotekind != LyXParagraph::WIDE_FIG
1438 par->footnotekind != LyXParagraph::WIDE_TAB
1440 par->footnotekind != LyXParagraph::ALGORITHM
1444 current_view->buffer()->text->SetCursorIntern(par, 0);
1445 current_view->buffer()->text->CloseFootnote();
1451 current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1452 current_view->redraw();
1453 current_view->fitCursor();
1454 current_view->updateScrollbar();
1458 void MenuLayoutCharacter()
1460 static int ow = -1, oh;
1462 if (fd_form_character->form_character->visible) {
1463 fl_raise_form(fd_form_character->form_character);
1465 fl_show_form(fd_form_character->form_character,
1466 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1467 _("Character Style"));
1469 ow = fd_form_character->form_character->w;
1470 oh = fd_form_character->form_character->h;
1472 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1477 inline void DeactivateParagraphButtons ()
1479 fl_deactivate_object (fd_form_paragraph->button_ok);
1480 fl_deactivate_object (fd_form_paragraph->button_apply);
1481 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1482 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1485 inline void ActivateParagraphButtons ()
1487 fl_activate_object (fd_form_paragraph->button_ok);
1488 fl_activate_object (fd_form_paragraph->button_apply);
1489 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1490 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1493 inline void DisableParagraphLayout ()
1495 DeactivateParagraphButtons();
1496 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1497 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1498 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1499 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1500 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1501 fl_deactivate_object (fd_form_paragraph->check_noindent);
1502 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1503 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1504 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1505 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1506 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1507 fl_deactivate_object (fd_form_paragraph->input_space_above);
1508 fl_deactivate_object (fd_form_paragraph->input_space_below);
1509 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1510 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1511 fl_deactivate_object (fd_form_paragraph->check_space_above);
1512 fl_deactivate_object (fd_form_paragraph->check_space_below);
1515 inline void EnableParagraphLayout ()
1517 ActivateParagraphButtons();
1518 fl_activate_object (fd_form_paragraph->input_labelwidth);
1519 fl_activate_object (fd_form_paragraph->check_lines_top);
1520 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1521 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1522 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1523 fl_activate_object (fd_form_paragraph->check_noindent);
1524 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1525 fl_activate_object (fd_form_paragraph->radio_align_right);
1526 fl_activate_object (fd_form_paragraph->radio_align_left);
1527 fl_activate_object (fd_form_paragraph->radio_align_block);
1528 fl_activate_object (fd_form_paragraph->radio_align_center);
1529 fl_activate_object (fd_form_paragraph->input_space_above);
1530 fl_activate_object (fd_form_paragraph->input_space_below);
1531 fl_activate_object (fd_form_paragraph->choice_space_above);
1532 fl_activate_object (fd_form_paragraph->choice_space_below);
1533 fl_activate_object (fd_form_paragraph->check_space_above);
1534 fl_activate_object (fd_form_paragraph->check_space_below);
1537 bool UpdateLayoutParagraph()
1539 if (!current_view->getScreen() || !current_view->available()) {
1540 if (fd_form_paragraph->form_paragraph->visible)
1541 fl_hide_form(fd_form_paragraph->form_paragraph);
1545 Buffer * buf = current_view->buffer();
1547 fl_set_input(fd_form_paragraph->input_labelwidth,
1548 buf->text->cursor.par->GetLabelWidthString().c_str());
1549 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1550 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1551 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1552 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1554 int align = buf->text->cursor.par->GetAlign();
1555 if (align == LYX_ALIGN_LAYOUT)
1556 align = textclasslist.Style(buf->params.textclass,
1557 buf->text->cursor.par->GetLayout()).align;
1560 case LYX_ALIGN_RIGHT:
1561 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1563 case LYX_ALIGN_LEFT:
1564 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1566 case LYX_ALIGN_CENTER:
1567 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1570 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1574 fl_set_button(fd_form_paragraph->check_lines_top,
1575 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1576 fl_set_button(fd_form_paragraph->check_lines_bottom,
1577 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1578 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1579 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1580 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1581 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1582 fl_set_button(fd_form_paragraph->check_noindent,
1583 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1584 fl_set_input (fd_form_paragraph->input_space_above, "");
1586 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1588 fl_set_choice (fd_form_paragraph->choice_space_above,
1591 case VSpace::DEFSKIP:
1592 fl_set_choice (fd_form_paragraph->choice_space_above,
1595 case VSpace::SMALLSKIP:
1596 fl_set_choice (fd_form_paragraph->choice_space_above,
1599 case VSpace::MEDSKIP:
1600 fl_set_choice (fd_form_paragraph->choice_space_above,
1603 case VSpace::BIGSKIP:
1604 fl_set_choice (fd_form_paragraph->choice_space_above,
1608 fl_set_choice (fd_form_paragraph->choice_space_above,
1611 case VSpace::LENGTH:
1612 fl_set_choice (fd_form_paragraph->choice_space_above,
1614 fl_set_input (fd_form_paragraph->input_space_above,
1615 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1618 fl_set_button (fd_form_paragraph->check_space_above,
1619 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1620 fl_set_input (fd_form_paragraph->input_space_below, "");
1621 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1623 fl_set_choice (fd_form_paragraph->choice_space_below,
1626 case VSpace::DEFSKIP:
1627 fl_set_choice (fd_form_paragraph->choice_space_below,
1630 case VSpace::SMALLSKIP:
1631 fl_set_choice (fd_form_paragraph->choice_space_below,
1634 case VSpace::MEDSKIP:
1635 fl_set_choice (fd_form_paragraph->choice_space_below,
1638 case VSpace::BIGSKIP:
1639 fl_set_choice (fd_form_paragraph->choice_space_below,
1643 fl_set_choice (fd_form_paragraph->choice_space_below,
1646 case VSpace::LENGTH:
1647 fl_set_choice (fd_form_paragraph->choice_space_below,
1649 fl_set_input (fd_form_paragraph->input_space_below,
1650 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1653 fl_set_button (fd_form_paragraph->check_space_below,
1654 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1656 fl_set_button(fd_form_paragraph->check_noindent,
1657 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1659 if (current_view->buffer()->isReadonly()) {
1660 DisableParagraphLayout();
1662 EnableParagraphLayout();
1667 void MenuLayoutParagraph()
1669 if (UpdateLayoutParagraph()) {
1670 if (fd_form_paragraph->form_paragraph->visible) {
1671 fl_raise_form(fd_form_paragraph->form_paragraph);
1673 fl_show_form(fd_form_paragraph->form_paragraph,
1674 FL_PLACE_MOUSE, FL_FULLBORDER,
1675 _("Paragraph Environment"));
1682 void DeactivateDocumentButtons ()
1684 fl_deactivate_object (fd_form_document->button_ok);
1685 fl_deactivate_object (fd_form_document->button_apply);
1686 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1687 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1692 void ActivateDocumentButtons ()
1694 fl_activate_object (fd_form_document->button_ok);
1695 fl_activate_object (fd_form_document->button_apply);
1696 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1697 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1701 void DisableDocumentLayout ()
1703 DeactivateDocumentButtons ();
1704 fl_deactivate_object (fd_form_document->group_radio_separation);
1705 fl_deactivate_object (fd_form_document->radio_indent);
1706 fl_deactivate_object (fd_form_document->radio_skip);
1707 fl_deactivate_object (fd_form_document->choice_class);
1708 fl_deactivate_object (fd_form_document->choice_pagestyle);
1709 fl_deactivate_object (fd_form_document->choice_fonts);
1710 fl_deactivate_object (fd_form_document->choice_fontsize);
1711 fl_deactivate_object (fd_form_document->input_float_placement);
1712 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1713 fl_deactivate_object (fd_form_document->choice_inputenc);
1714 fl_deactivate_object (fd_form_document->group_radio_sides);
1715 fl_deactivate_object (fd_form_document->radio_sides_one);
1716 fl_deactivate_object (fd_form_document->radio_sides_two);
1717 fl_deactivate_object (fd_form_document->group_radio_columns);
1718 fl_deactivate_object (fd_form_document->radio_columns_one);
1719 fl_deactivate_object (fd_form_document->radio_columns_two);
1720 fl_deactivate_object (fd_form_document->input_extra);
1721 fl_deactivate_object (fd_form_document->choice_language);
1722 combo_language->deactivate();
1723 fl_deactivate_object (fd_form_document->input_default_skip);
1724 fl_deactivate_object (fd_form_document->choice_default_skip);
1725 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1726 fl_deactivate_object (fd_form_document->slider_tocdepth);
1727 fl_deactivate_object (fd_form_document->choice_spacing);
1728 fl_deactivate_object (fd_form_document->input_spacing);
1729 fl_deactivate_object (fd_form_document->check_use_amsmath);
1733 void EnableDocumentLayout ()
1735 ActivateDocumentButtons ();
1736 fl_activate_object (fd_form_document->group_radio_separation);
1737 fl_activate_object (fd_form_document->radio_indent);
1738 fl_activate_object (fd_form_document->radio_skip);
1739 fl_activate_object (fd_form_document->choice_class);
1740 fl_activate_object (fd_form_document->choice_pagestyle);
1741 fl_activate_object (fd_form_document->choice_fonts);
1742 fl_activate_object (fd_form_document->choice_fontsize);
1743 fl_activate_object (fd_form_document->input_float_placement);
1744 fl_activate_object (fd_form_document->choice_postscript_driver);
1745 fl_activate_object (fd_form_document->choice_inputenc);
1746 fl_activate_object (fd_form_document->group_radio_sides);
1747 fl_activate_object (fd_form_document->radio_sides_one);
1748 fl_activate_object (fd_form_document->radio_sides_two);
1749 fl_activate_object (fd_form_document->group_radio_columns);
1750 fl_activate_object (fd_form_document->radio_columns_one);
1751 fl_activate_object (fd_form_document->radio_columns_two);
1752 fl_activate_object (fd_form_document->input_extra);
1753 fl_activate_object (fd_form_document->choice_language);
1754 combo_language->activate();
1755 fl_activate_object (fd_form_document->input_default_skip);
1756 fl_activate_object (fd_form_document->choice_default_skip);
1757 fl_activate_object (fd_form_document->slider_secnumdepth);
1758 fl_activate_object (fd_form_document->slider_tocdepth);
1759 fl_activate_object (fd_form_document->choice_spacing);
1760 fl_activate_object (fd_form_document->input_spacing);
1761 fl_activate_object (fd_form_document->check_use_amsmath);
1764 bool UpdateLayoutDocument(BufferParams *params)
1766 if (!current_view->getScreen() || !current_view->available()) {
1767 if (fd_form_document->form_document->visible)
1768 fl_hide_form(fd_form_document->form_document);
1773 params = ¤t_view->buffer()->params;
1774 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1776 fl_set_choice_text(fd_form_document->choice_class,
1777 textclasslist.DescOfClass(params->textclass).c_str());
1778 combo_language->select_text(params->language.c_str());
1780 fl_set_choice_text(fd_form_document->choice_fonts,
1781 params->fonts.c_str());
1782 fl_set_choice_text(fd_form_document->choice_inputenc,
1783 params->inputenc.c_str());
1784 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1785 params->graphicsDriver.c_str());
1787 // ale970405+lasgoutt970513
1788 fl_clear_choice(fd_form_document->choice_fontsize);
1789 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1790 fl_addto_choice(fd_form_document->choice_fontsize,
1791 tclass.opt_fontsize().c_str());
1792 fl_set_choice(fd_form_document->choice_fontsize,
1793 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1795 // ale970405+lasgoutt970513
1796 fl_clear_choice(fd_form_document->choice_pagestyle);
1797 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1798 fl_addto_choice(fd_form_document->choice_pagestyle,
1799 tclass.opt_pagestyle().c_str());
1801 fl_set_choice(fd_form_document->choice_pagestyle,
1802 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1804 fl_set_button(fd_form_document->radio_indent, 0);
1805 fl_set_button(fd_form_document->radio_skip, 0);
1808 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1810 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1811 fl_set_button(fd_form_document->radio_indent, 1);
1813 fl_set_button(fd_form_document->radio_skip, 1);
1815 switch (params->getDefSkip().kind()) {
1816 case VSpace::SMALLSKIP:
1817 fl_set_choice (fd_form_document->choice_default_skip, 1);
1819 case VSpace::MEDSKIP:
1820 fl_set_choice (fd_form_document->choice_default_skip, 2);
1822 case VSpace::BIGSKIP:
1823 fl_set_choice (fd_form_document->choice_default_skip, 3);
1825 case VSpace::LENGTH:
1826 fl_set_choice (fd_form_document->choice_default_skip, 4);
1827 fl_set_input (fd_form_document->input_default_skip,
1828 params->getDefSkip().asLyXCommand().c_str());
1831 fl_set_choice (fd_form_document->choice_default_skip, 2);
1835 fl_set_button(fd_form_document->radio_sides_one, 0);
1836 fl_set_button(fd_form_document->radio_sides_two, 0);
1838 if (params->sides == 2)
1839 fl_set_button(fd_form_document->radio_sides_two, 1);
1841 fl_set_button(fd_form_document->radio_sides_one, 1);
1843 fl_set_button(fd_form_document->radio_columns_one, 0);
1844 fl_set_button(fd_form_document->radio_columns_two, 0);
1846 if (params->columns == 2)
1847 fl_set_button(fd_form_document->radio_columns_two, 1);
1849 fl_set_button(fd_form_document->radio_columns_one, 1);
1851 fl_set_input(fd_form_document->input_spacing, "");
1852 switch (params->spacing.getSpace()) {
1853 case Spacing::Single:
1856 fl_set_choice(fd_form_document->choice_spacing, 1);
1859 case Spacing::Onehalf:
1862 fl_set_choice(fd_form_document->choice_spacing, 2);
1865 case Spacing::Double:
1868 fl_set_choice(fd_form_document->choice_spacing, 3);
1871 case Spacing::Other:
1873 fl_set_choice(fd_form_document->choice_spacing, 4);
1875 sprintf(sval, "%g", params->spacing.getValue());
1876 fl_set_input(fd_form_document->input_spacing, sval);
1882 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1883 params->secnumdepth);
1884 fl_set_counter_value(fd_form_document->slider_tocdepth,
1886 if (!params->float_placement.empty()) { // buffer local (Lgb)
1887 fl_set_input(fd_form_document->input_float_placement,
1888 params->float_placement.c_str());
1890 fl_set_input(fd_form_document->input_float_placement, "");
1892 if (!params->options.empty())
1893 fl_set_input(fd_form_document->input_extra,
1894 params->options.c_str());
1896 fl_set_input(fd_form_document->input_extra, "");
1898 if (current_view->buffer()->isSGML()) {
1899 // bullets not used in SGML derived documents
1900 fl_deactivate_object(fd_form_document->button_bullets);
1901 fl_set_object_lcol(fd_form_document->button_bullets,
1904 fl_activate_object(fd_form_document->button_bullets);
1905 fl_set_object_lcol(fd_form_document->button_bullets,
1909 if (current_view->buffer()->isReadonly()) {
1910 DisableDocumentLayout();
1912 EnableDocumentLayout();
1918 void MenuLayoutDocument()
1920 if (UpdateLayoutDocument()) {
1921 if (fd_form_document->form_document->visible) {
1922 fl_raise_form(fd_form_document->form_document);
1924 fl_show_form(fd_form_document->form_document,
1925 FL_PLACE_MOUSE, FL_FULLBORDER,
1926 _("Document Layout"));
1932 bool UpdateLayoutQuotes()
1935 if (!current_view->getScreen()
1936 || !current_view->available()
1937 || current_view->buffer()->isReadonly())
1941 fl_set_choice(fd_form_quotes->choice_quotes_language,
1942 current_view->buffer()->params.quotes_language + 1);
1943 fl_set_button(fd_form_quotes->radio_single, 0);
1944 fl_set_button(fd_form_quotes->radio_double, 0);
1946 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1947 fl_set_button(fd_form_quotes->radio_single, 1);
1949 fl_set_button(fd_form_quotes->radio_double, 1);
1950 } else if (fd_form_quotes->form_quotes->visible) {
1951 fl_hide_form(fd_form_quotes->form_quotes);
1956 void MenuLayoutQuotes()
1958 if (UpdateLayoutQuotes()) {
1959 if (fd_form_quotes->form_quotes->visible) {
1960 fl_raise_form(fd_form_quotes->form_quotes);
1962 fl_show_form(fd_form_quotes->form_quotes,
1963 FL_PLACE_MOUSE, FL_FULLBORDER,
1970 bool UpdateLayoutPreamble()
1973 if (!current_view->getScreen() || ! current_view->available())
1977 fl_set_input(fd_form_preamble->input_preamble,
1978 current_view->buffer()->params.preamble.c_str());
1980 if (current_view->buffer()->isReadonly()) {
1981 fl_deactivate_object(fd_form_preamble->input_preamble);
1982 fl_deactivate_object(fd_form_preamble->button_ok);
1983 fl_deactivate_object(fd_form_preamble->button_apply);
1984 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1985 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1988 fl_activate_object(fd_form_preamble->input_preamble);
1989 fl_activate_object(fd_form_preamble->button_ok);
1990 fl_activate_object(fd_form_preamble->button_apply);
1991 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1992 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1994 } else if (fd_form_preamble->form_preamble->visible) {
1995 fl_hide_form(fd_form_preamble->form_preamble);
2000 void MenuLayoutPreamble()
2002 static int ow = -1, oh;
2004 if (UpdateLayoutPreamble()) {
2005 if (fd_form_preamble->form_preamble->visible) {
2006 fl_raise_form(fd_form_preamble->form_preamble);
2008 fl_show_form(fd_form_preamble->form_preamble,
2009 FL_PLACE_MOUSE | FL_FREE_SIZE,
2011 _("LaTeX Preamble"));
2013 ow = fd_form_preamble->form_preamble->w;
2014 oh = fd_form_preamble->form_preamble->h;
2016 fl_set_form_minsize(fd_form_preamble->form_preamble,
2022 void MenuLayoutSave()
2024 if (!current_view->getScreen() || ! current_view->available())
2027 if (AskQuestion(_("Do you want to save the current settings"),
2028 _("for Character, Document, Paper and Quotes"),
2029 _("as default for new documents?")))
2030 current_view->buffer()->saveParamsAsDefaults();
2036 InsetInfo *new_inset = new InsetInfo();
2037 current_view->buffer()->insertInset(new_inset);
2038 new_inset->Edit(0, 0);
2039 //current_view->buffer()->update(-1);
2045 if (current_view->available()) {
2046 minibuffer->Set(_("Open/Close..."));
2047 current_view->getScreen()->HideCursor();
2049 current_view->buffer()->update(-2);
2050 current_view->buffer()->text->OpenStuff();
2051 current_view->buffer()->update(0);
2057 if (current_view->available()) {
2058 minibuffer->Set(_("Open/Close..."));
2059 current_view->getScreen()->HideCursor();
2061 current_view->buffer()->update(-2);
2062 current_view->buffer()->text->ToggleFootnote();
2063 current_view->buffer()->update(0);
2070 /* if (current_view->buffer()->the_locking_inset) {
2071 minibuffer->Set(_("Undo not yet supported in math mode"));
2075 if (current_view->available()) {
2076 minibuffer->Set(_("Undo"));
2077 current_view->getScreen()->HideCursor();
2079 current_view->buffer()->update(-2);
2080 if (!current_view->buffer()->text->TextUndo())
2081 minibuffer->Set(_("No further undo information"));
2083 current_view->buffer()->update(-1);
2090 if (current_view->buffer()->the_locking_inset) {
2091 minibuffer->Set(_("Redo not yet supported in math mode"));
2095 if (current_view->available()) {
2096 minibuffer->Set(_("Redo"));
2097 current_view->getScreen()->HideCursor();
2099 current_view->buffer()->update(-2);
2100 if (!current_view->buffer()->text->TextRedo())
2101 minibuffer->Set(_("No further redo information"));
2103 current_view->buffer()->update(-1);
2108 void HyphenationPoint()
2110 if (current_view->available()) {
2111 current_view->getScreen()->HideCursor();
2112 current_view->buffer()->update(-2);
2113 InsetSpecialChar *new_inset =
2114 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2115 current_view->buffer()->insertInset(new_inset);
2116 //current_view->buffer()->update(-1);
2123 if (current_view->available()) {
2124 current_view->getScreen()->HideCursor();
2125 current_view->buffer()->update(-2);
2126 InsetSpecialChar *new_inset =
2127 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2128 current_view->buffer()->insertInset(new_inset);
2133 void EndOfSentenceDot()
2135 if (current_view->available()) {
2136 current_view->getScreen()->HideCursor();
2137 current_view->buffer()->update(-2);
2138 InsetSpecialChar *new_inset =
2139 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2140 current_view->buffer()->insertInset(new_inset);
2145 void MenuSeparator()
2147 if (current_view->available()) {
2148 current_view->getScreen()->HideCursor();
2149 current_view->buffer()->update(-2);
2150 InsetSpecialChar *new_inset =
2151 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2152 current_view->buffer()->insertInset(new_inset);
2153 //current_view->buffer()->update(-1);
2160 if (current_view->available()) {
2161 current_view->getScreen()->HideCursor();
2162 current_view->buffer()->update(-2);
2163 current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
2164 current_view->buffer()->update(-1);
2169 void ProtectedBlank()
2171 if (current_view->available()) {
2172 current_view->getScreen()->HideCursor();
2173 current_view->buffer()->update(-2);
2174 current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2175 current_view->buffer()->update(-1);
2182 if (current_view->available()) {
2183 current_view->getScreen()->HideCursor();
2184 current_view->buffer()->update(-2);
2185 current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL);
2186 current_view->buffer()->update(-1);
2191 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2192 They also show the current font state. */
2195 void ToggleAndShow(LyXFont const &);
2198 void FontSizeCB(string const & size)
2200 LyXFont font(LyXFont::ALL_IGNORE);
2201 font.setGUISize(size);
2202 ToggleAndShow(font);
2208 LyXFont font(LyXFont::ALL_IGNORE);
2209 font.setEmph(LyXFont::TOGGLE);
2210 ToggleAndShow(font);
2216 LyXFont font(LyXFont::ALL_IGNORE);
2217 font.setNoun(LyXFont::TOGGLE);
2218 ToggleAndShow(font);
2224 LyXFont font(LyXFont::ALL_IGNORE);
2225 font.setSeries(LyXFont::BOLD_SERIES);
2226 ToggleAndShow(font);
2232 LyXFont font(LyXFont::ALL_IGNORE);
2233 font.setUnderbar(LyXFont::TOGGLE);
2234 ToggleAndShow(font);
2240 LyXFont font(LyXFont::ALL_IGNORE);
2241 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2242 ToggleAndShow(font);
2248 LyXFont font(LyXFont::ALL_IGNORE);
2249 font.setFamily(LyXFont::SANS_FAMILY);
2250 ToggleAndShow(font);
2256 LyXFont font(LyXFont::ALL_IGNORE);
2257 font.setFamily(LyXFont::ROMAN_FAMILY);
2258 ToggleAndShow(font);
2264 LyXFont font(LyXFont::ALL_IGNORE);
2265 font.setLatex (LyXFont::TOGGLE);
2266 ToggleAndShow(font);
2272 LyXFont font(LyXFont::ALL_INHERIT);
2273 ToggleAndShow(font);
2277 /* -------> Returns the current font and depth by printing a message. In the
2278 * future perhaps we could try to implement a callback to the button-bar.
2279 * That is, `light' the bold button when the font is currently bold, etc.
2281 string CurrentState()
2284 if (current_view->available()) {
2285 // I think we should only show changes from the default
2287 Buffer * buffer = current_view->buffer();
2288 LyXFont font = buffer->text->real_current_font;
2289 LyXFont defaultfont = textclasslist.TextClass(buffer->
2290 params.textclass).defaultfont();
2291 font.reduce(defaultfont);
2292 state = _("Font: ") + font.stateText();
2294 int depth = buffer->text->GetDepth();
2296 state += string(_(", Depth: ")) + tostr(depth);
2302 /* -------> Does the actual toggle job of the XxxCB() calls above.
2303 * Also shows the current font state.
2306 void ToggleAndShow(LyXFont const & font)
2308 if (current_view->available()) {
2309 current_view->getScreen()->HideCursor();
2310 current_view->buffer()->update(-2);
2311 current_view->buffer()->text->ToggleFree(font, toggleall);
2312 current_view->buffer()->update(1);
2314 // removed since it overrides the ToggleFree Message about the style
2315 // Since Styles are more "High Level" than raw fonts I think the user
2316 // prefers it like this Matthias
2317 // FontStateShowCB( 0, 0 );
2321 extern "C" void MarginCB(FL_OBJECT *, long)
2323 if (current_view->available()) {
2324 minibuffer->Set(_("Inserting margin note..."));
2325 current_view->getScreen()->HideCursor();
2326 current_view->buffer()->update(-2);
2327 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2328 current_view->buffer()->update(1);
2333 extern "C" void FigureCB(FL_OBJECT *, long)
2335 if (fd_form_figure->form_figure->visible) {
2336 fl_raise_form(fd_form_figure->form_figure);
2338 fl_show_form(fd_form_figure->form_figure,
2339 FL_PLACE_MOUSE, FL_FULLBORDER,
2340 _("Insert Figure"));
2345 extern "C" void TableCB(FL_OBJECT *, long)
2347 if (fd_form_table->form_table->visible) {
2348 fl_raise_form(fd_form_table->form_table);
2350 fl_show_form(fd_form_table->form_table,
2351 FL_PLACE_MOUSE, FL_FULLBORDER,
2357 void CopyEnvironmentCB()
2359 if (current_view->available()) {
2360 current_view->buffer()->text->copyEnvironmentType();
2361 /* clear the selection, even if mark_set */
2362 current_view->getScreen()->ToggleSelection();
2363 current_view->buffer()->text->ClearSelection();
2364 current_view->buffer()->update(-2);
2365 minibuffer->Set(_("Paragraph environment type copied"));
2370 void PasteEnvironmentCB()
2372 if (current_view->available()) {
2373 current_view->buffer()->text->pasteEnvironmentType();
2374 minibuffer->Set(_("Paragraph environment type set"));
2375 current_view->buffer()->update(1);
2382 if (current_view->available()) {
2383 current_view->buffer()->text->CopySelection();
2384 /* clear the selection, even if mark_set */
2385 current_view->getScreen()->ToggleSelection();
2386 current_view->buffer()->text->ClearSelection();
2387 current_view->buffer()->update(-2);
2388 minibuffer->Set(_("Copy"));
2395 if (current_view->available()) {
2396 current_view->getScreen()->HideCursor();
2397 current_view->buffer()->update(-2);
2398 current_view->buffer()->text->CutSelection();
2399 current_view->buffer()->update(1);
2400 minibuffer->Set(_("Cut"));
2407 if (!current_view->available()) return;
2409 minibuffer->Set(_("Paste"));
2410 current_view->getScreen()->HideCursor();
2411 /* clear the selection */
2412 current_view->getScreen()->ToggleSelection();
2413 current_view->buffer()->text->ClearSelection();
2414 current_view->buffer()->update(-2);
2417 current_view->buffer()->text->PasteSelection();
2418 current_view->buffer()->update(1);
2420 /* clear the selection */
2421 current_view->getScreen()->ToggleSelection();
2422 current_view->buffer()->text->ClearSelection();
2423 current_view->buffer()->update(-2);
2427 extern "C" void MeltCB(FL_OBJECT *, long)
2429 if (!current_view->available()) return;
2431 minibuffer->Set(_("Melt"));
2432 current_view->getScreen()->HideCursor();
2434 current_view->buffer()->update(-2);
2435 current_view->buffer()->text->MeltFootnoteEnvironment();
2436 current_view->buffer()->update(1);
2440 // Change environment depth.
2441 // if decInc == 0, depth change taking mouse button number into account
2442 // if decInc == 1, increment depth
2443 // if decInc == -1, decrement depth
2444 extern "C" void DepthCB(FL_OBJECT *ob, long decInc)
2448 /* When decInc != 0, fake a mouse button. This allows us to
2449 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2450 /* check out wether ob is defined, too (Matthias) */
2453 else if (!decInc && ob) {
2454 button = fl_get_button_numb(ob);
2457 if (current_view->available()) {
2458 current_view->getScreen()->HideCursor();
2459 current_view->buffer()->update(-2);
2461 current_view->buffer()->text->IncDepth();
2463 current_view->buffer()->text->DecDepth();
2464 current_view->buffer()->update(1);
2465 minibuffer->Set(_("Changed environment depth"
2466 " (in possible range, maybe not)"));
2471 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2472 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2473 LyXFont UserFreeFont()
2475 LyXFont font(LyXFont::ALL_IGNORE);
2478 pos = fl_get_choice(fd_form_character->choice_family);
2480 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2481 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2482 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2483 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2484 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2487 pos = fl_get_choice(fd_form_character->choice_series);
2489 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2490 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2491 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2492 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2495 pos = fl_get_choice(fd_form_character->choice_shape);
2497 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2498 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2499 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2500 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2501 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2502 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2505 pos = fl_get_choice(fd_form_character->choice_size);
2507 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2508 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2509 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2510 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2511 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2512 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2513 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2514 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2515 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2516 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2517 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2518 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2519 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2520 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2523 pos = fl_get_choice(fd_form_character->choice_bar);
2525 case 1: font.setEmph(LyXFont::IGNORE);
2526 font.setUnderbar(LyXFont::IGNORE);
2527 font.setNoun(LyXFont::IGNORE);
2528 font.setLatex(LyXFont::IGNORE);
2530 case 2: font.setEmph(LyXFont::TOGGLE); break;
2531 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2532 case 4: font.setNoun(LyXFont::TOGGLE); break;
2533 case 5: font.setLatex(LyXFont::TOGGLE); break;
2534 case 6: font.setEmph(LyXFont::INHERIT);
2535 font.setUnderbar(LyXFont::INHERIT);
2536 font.setNoun(LyXFont::INHERIT);
2537 font.setLatex(LyXFont::INHERIT);
2541 pos = fl_get_choice(fd_form_character->choice_color);
2543 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2544 case 2: font.setColor(LyXFont::NONE); break;
2545 case 3: font.setColor(LyXFont::BLACK); break;
2546 case 4: font.setColor(LyXFont::WHITE); break;
2547 case 5: font.setColor(LyXFont::RED); break;
2548 case 6: font.setColor(LyXFont::GREEN); break;
2549 case 7: font.setColor(LyXFont::BLUE); break;
2550 case 8: font.setColor(LyXFont::CYAN); break;
2551 case 9: font.setColor(LyXFont::MAGENTA); break;
2552 case 10: font.setColor(LyXFont::YELLOW); break;
2553 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2562 ToggleAndShow(UserFreeFont());
2566 /* callbacks for form form_title */
2567 extern "C" void TimerCB(FL_OBJECT *, long)
2569 // only if the form still exists
2570 if (fd_form_title->form_title != 0) {
2571 if (fd_form_title->form_title->visible) {
2572 fl_hide_form(fd_form_title->form_title);
2574 fl_free_form(fd_form_title->form_title);
2575 fd_form_title->form_title = 0;
2580 /* callbacks for form form_paragraph */
2582 extern "C" void ParagraphVSpaceCB(FL_OBJECT* obj, long )
2584 // "Synchronize" the choices and input fields, making it
2585 // impossible to commit senseless data.
2587 const FD_form_paragraph* fp = fd_form_paragraph;
2589 if (obj == fp->choice_space_above) {
2590 if (fl_get_choice (fp->choice_space_above) != 7) {
2591 fl_set_input (fp->input_space_above, "");
2592 ActivateParagraphButtons();
2594 } else if (obj == fp->choice_space_below) {
2595 if (fl_get_choice (fp->choice_space_below) != 7) {
2596 fl_set_input (fp->input_space_below, "");
2597 ActivateParagraphButtons();
2599 } else if (obj == fp->input_space_above) {
2600 string input = fl_get_input (fp->input_space_above);
2602 if (input.empty()) {
2603 fl_set_choice (fp->choice_space_above, 1);
2604 ActivateParagraphButtons();
2606 else if (isValidGlueLength (input)) {
2607 fl_set_choice (fp->choice_space_above, 7);
2608 ActivateParagraphButtons();
2611 fl_set_choice (fp->choice_space_above, 7);
2612 DeactivateParagraphButtons();
2614 } else if (obj == fp->input_space_below) {
2615 string input = fl_get_input (fp->input_space_below);
2617 if (input.empty()) {
2618 fl_set_choice (fp->choice_space_below, 1);
2619 ActivateParagraphButtons();
2621 else if (isValidGlueLength (input)) {
2622 fl_set_choice (fp->choice_space_below, 7);
2623 ActivateParagraphButtons();
2626 fl_set_choice (fp->choice_space_below, 7);
2627 DeactivateParagraphButtons();
2633 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2635 if (!current_view->available())
2638 VSpace space_top, space_bottom;
2640 string labelwidthstring;
2643 // If a vspace kind is "Length" but there's no text in
2644 // the input field, reset the kind to "None".
2645 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2646 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2647 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2649 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2650 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2651 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2654 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2655 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2656 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2657 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2658 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2659 case 1: space_top = VSpace(VSpace::NONE); break;
2660 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2661 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2662 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2663 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2664 case 6: space_top = VSpace(VSpace::VFILL); break;
2665 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2667 if (fl_get_button (fd_form_paragraph->check_space_above))
2668 space_top.setKeep (true);
2669 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2670 case 1: space_bottom = VSpace(VSpace::NONE); break;
2671 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2672 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2673 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2674 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2675 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2676 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2678 if (fl_get_button (fd_form_paragraph->check_space_below))
2679 space_bottom.setKeep (true);
2681 if (fl_get_button(fd_form_paragraph->radio_align_left))
2682 align = LYX_ALIGN_LEFT;
2683 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2684 align = LYX_ALIGN_RIGHT;
2685 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2686 align = LYX_ALIGN_CENTER;
2688 align = LYX_ALIGN_BLOCK;
2690 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2691 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2693 current_view->buffer()->text->SetParagraph(line_top,
2702 current_view->buffer()->update(1);
2703 minibuffer->Set(_("Paragraph layout set"));
2707 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2709 fl_hide_form(fd_form_paragraph->form_paragraph);
2713 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2715 ParagraphApplyCB(ob, data);
2716 ParagraphCancelCB(ob, data);
2720 /* callbacks for form form_character */
2722 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2724 // we set toggleall locally here, since it should be true for
2725 // all other uses of ToggleAndShow() (JMarc)
2726 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2727 ToggleAndShow( UserFreeFont());
2732 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2734 fl_hide_form(fd_form_character->form_character);
2738 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2740 CharacterApplyCB(ob, data);
2741 CharacterCloseCB(ob, data);
2745 /* callbacks for form form_document */
2747 void UpdateDocumentButtons(BufferParams const ¶ms)
2749 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2751 if (params.sides == 2)
2752 fl_set_button(fd_form_document->radio_sides_two, 1);
2754 fl_set_button(fd_form_document->radio_sides_one, 1);
2756 if (params.columns == 2)
2757 fl_set_button(fd_form_document->radio_columns_two, 1);
2759 fl_set_button(fd_form_document->radio_columns_one, 1);
2761 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2762 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2763 params.secnumdepth);
2764 fl_set_counter_value(fd_form_document->slider_tocdepth,
2769 extern "C" void ChoiceClassCB(FL_OBJECT *ob, long)
2772 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2773 if (AskQuestion(_("Should I set some parameters to"),
2774 fl_get_choice_text(ob),
2775 _("the defaults of this document class?"))) {
2776 BufferParams params = BufferParams();
2777 params.textclass = fl_get_choice(ob)-1;
2778 params.useClassDefaults();
2779 UpdateLayoutDocument(¶ms);
2780 UpdateDocumentButtons(params);
2783 // unable to load new style
2784 WriteAlert(_("Conversion Errors!"),
2785 _("Unable to switch to new document class."),
2786 _("Reverting to original document class."));
2787 fl_set_choice(fd_form_document->choice_class,
2788 GetCurrentTextClass() + 1);
2794 extern "C" void DocumentDefskipCB(FL_OBJECT *obj, long)
2796 // "Synchronize" the choice and the input field, so that it
2797 // is impossible to commit senseless data.
2798 const FD_form_document* fd = fd_form_document;
2800 if (obj == fd->choice_default_skip) {
2801 if (fl_get_choice (fd->choice_default_skip) != 4) {
2802 fl_set_input (fd->input_default_skip, "");
2803 ActivateDocumentButtons();
2805 } else if (obj == fd->input_default_skip) {
2807 const char* input = fl_get_input (fd->input_default_skip);
2810 fl_set_choice (fd->choice_default_skip, 2);
2811 ActivateDocumentButtons();
2812 } else if (isValidGlueLength (input)) {
2813 fl_set_choice (fd->choice_default_skip, 4);
2814 ActivateDocumentButtons();
2816 fl_set_choice (fd->choice_default_skip, 4);
2817 DeactivateDocumentButtons();
2823 extern "C" void DocumentSpacingCB(FL_OBJECT *obj, long)
2825 // "Synchronize" the choice and the input field, so that it
2826 // is impossible to commit senseless data.
2827 const FD_form_document* fd = fd_form_document;
2829 if (obj == fd->choice_spacing
2830 && fl_get_choice (fd->choice_spacing) != 4) {
2831 fl_set_input(fd->input_spacing, "");
2832 } else if (obj == fd->input_spacing) {
2834 const char* input = fl_get_input (fd->input_spacing);
2837 fl_set_choice (fd->choice_spacing, 1);
2839 fl_set_choice (fd->choice_spacing, 4);
2845 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2848 BufferParams *params = &(current_view->buffer()->params);
2849 current_view->buffer()->params.language =
2850 combo_language->getline();
2852 // If default skip is a "Length" but there's no text in the
2853 // input field, reset the kind to "Medskip", which is the default.
2854 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2855 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2856 fl_set_choice (fd_form_document->choice_default_skip, 2);
2859 /* this shouldn't be done automatically IMO. For example I write german
2860 * documents with an american keyboard very often. Matthias */
2862 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2863 fl_get_choice(fd_form_document->choice_language)); */
2865 fl_get_choice_text(fd_form_document->choice_fonts);
2867 fl_get_choice_text(fd_form_document->choice_inputenc);
2869 fl_get_choice_text(fd_form_document->choice_fontsize);
2871 fl_get_choice_text(fd_form_document->choice_pagestyle);
2872 params->graphicsDriver =
2873 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2874 params->use_amsmath =
2875 fl_get_button(fd_form_document->check_use_amsmath);
2877 if (!current_view->available())
2880 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2881 if (params->textclass != new_class) {
2882 // try to load new_class
2883 if (textclasslist.Load(new_class)) {
2884 // successfully loaded
2886 minibuffer->Set(_("Converting document to new document class..."));
2887 int ret = current_view->buffer()->
2889 SwitchLayoutsBetweenClasses(current_view->buffer()->
2892 current_view->buffer()->
2898 s = _("One paragraph couldn't be converted");
2901 s += _(" paragraphs couldn't be converted");
2903 WriteAlert(_("Conversion Errors!"), s,
2904 _("into chosen document class"));
2907 params->textclass = new_class;
2909 // problem changing class -- warn user and retain old style
2910 WriteAlert(_("Conversion Errors!"),
2911 _("Unable to switch to new document class."),
2912 _("Reverting to original document class."));
2913 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2917 char tmpsep = params->paragraph_separation;
2918 if (fl_get_button(fd_form_document->radio_indent))
2919 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2921 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2922 if (tmpsep != params->paragraph_separation)
2925 VSpace tmpdefskip = params->getDefSkip();
2926 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2927 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2928 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2929 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2930 case 4: params->setDefSkip(
2931 VSpace (LyXGlueLength (fl_get_input
2932 (fd_form_document->input_default_skip))));
2934 // DocumentDefskipCB assures that this never happens
2935 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2937 if (!(tmpdefskip == params->getDefSkip()))
2940 if (fl_get_button(fd_form_document->radio_columns_two))
2941 params->columns = 2;
2943 params->columns = 1;
2944 if (fl_get_button(fd_form_document->radio_sides_two))
2945 params->sides = LyXTextClass::TwoSides;
2947 params->sides = LyXTextClass::OneSide;
2949 Spacing tmpSpacing = params->spacing;
2950 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2952 lyxerr.debug() << "Spacing: SINGLE" << endl;
2953 params->spacing.set(Spacing::Single);
2956 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2957 params->spacing.set(Spacing::Onehalf);
2960 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2961 params->spacing.set(Spacing::Double);
2964 lyxerr.debug() << "Spacing: OTHER" << endl;
2965 params->spacing.set(Spacing::Other,
2966 fl_get_input(fd_form_document->input_spacing));
2969 if (tmpSpacing != params->spacing)
2972 signed char tmpchar =
2973 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2974 if (params->secnumdepth != tmpchar)
2976 params->secnumdepth = tmpchar;
2979 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2981 params->float_placement =
2982 fl_get_input(fd_form_document->input_float_placement);
2984 // More checking should be done to ensure the string doesn't have
2985 // spaces or illegal placement characters in it. (thornley)
2988 current_view->redoCurrentBuffer();
2990 minibuffer->Set(_("Document layout set"));
2991 current_view->buffer()->markDirty();
2994 fl_get_input(fd_form_document->input_extra);
2999 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3001 fl_hide_form(fd_form_document->form_document);
3005 extern "C" void DocumentOKCB(FL_OBJECT *ob, long data)
3007 DocumentCancelCB(ob, data);
3008 DocumentApplyCB(ob, data);
3012 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3015 // bullet callbacks etc. in bullet_panel.C -- ARRae
3021 if (!current_view->getScreen())
3024 current_view->getScreen()->HideCursor();
3026 current_view->buffer()->update(-2);
3029 if (!current_view->buffer()->text->GotoNextNote()) {
3030 if (current_view->buffer()->text->cursor.pos
3031 || current_view->buffer()->text->cursor.par !=
3032 current_view->buffer()->text->FirstParagraph())
3034 tmp = current_view->buffer()->text->cursor;
3035 current_view->buffer()->text->cursor.par =
3036 current_view->buffer()->text->FirstParagraph();
3037 current_view->buffer()->text->cursor.pos = 0;
3038 if (!current_view->buffer()->text->GotoNextNote()) {
3039 current_view->buffer()->text->cursor = tmp;
3040 minibuffer->Set(_("No more notes"));
3044 minibuffer->Set(_("No more notes"));
3048 current_view->buffer()->update(0);
3049 current_view->buffer()->text->sel_cursor =
3050 current_view->buffer()->text->cursor;
3054 void InsertCorrectQuote()
3056 Buffer *cbuffer = current_view->buffer();
3059 if (cbuffer->text->cursor.pos )
3060 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3064 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3068 /* callbacks for form form_quotes */
3070 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3072 if (!current_view->available())
3075 minibuffer->Set(_("Quotes type set"));
3076 //current_view->buffer()->params.quotes_language =
3077 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3078 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3079 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3081 lga = InsetQuotes::EnglishQ;
3084 lga = InsetQuotes::SwedishQ;
3087 lga = InsetQuotes::GermanQ;
3090 lga = InsetQuotes::PolishQ;
3093 lga = InsetQuotes::FrenchQ;
3096 lga = InsetQuotes::DanishQ;
3099 current_view->buffer()->params.quotes_language = lga;
3100 if (fl_get_button(fd_form_quotes->radio_single))
3101 current_view->buffer()->
3102 params.quotes_times = InsetQuotes::SingleQ;
3104 current_view->buffer()->
3105 params.quotes_times = InsetQuotes::DoubleQ;
3109 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3111 fl_hide_form(fd_form_quotes->form_quotes);
3115 extern "C" void QuotesOKCB(FL_OBJECT *ob, long data)
3117 QuotesApplyCB(ob, data);
3118 QuotesCancelCB(ob, data);
3123 /* callbacks for form form_preamble */
3125 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3127 fl_hide_form(fd_form_preamble->form_preamble);
3131 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3133 if (!current_view->available())
3136 current_view->buffer()->params.preamble =
3137 fl_get_input(fd_form_preamble->input_preamble);
3138 current_view->buffer()->markDirty();
3139 minibuffer->Set(_("LaTeX preamble set"));
3143 extern "C" void PreambleOKCB(FL_OBJECT *ob, long data)
3145 PreambleApplyCB(ob, data);
3146 PreambleCancelCB(ob, data);
3150 /* callbacks for form form_table */
3152 extern "C" void TableApplyCB(FL_OBJECT *, long)
3155 if (!current_view->getScreen())
3158 // check for tables in tables
3159 if (current_view->buffer()->text->cursor.par->table){
3160 WriteAlert(_("Impossible Operation!"),
3161 _("Cannot insert table in table."),
3166 minibuffer->Set(_("Inserting table..."));
3168 ysize = (int)(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3169 xsize = (int)(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3172 current_view->getScreen()->HideCursor();
3174 current_view->buffer()->update(-2);
3176 current_view->buffer()->text->SetCursorParUndo();
3177 current_view->buffer()->text->FreezeUndo();
3179 current_view->buffer()->text->BreakParagraph();
3180 current_view->buffer()->update(-1);
3182 if (current_view->buffer()->text->cursor.par->Last()) {
3183 current_view->buffer()->text->CursorLeft();
3185 current_view->buffer()->text->BreakParagraph();
3186 current_view->buffer()->update(-1);
3189 current_view->buffer()->text->current_font.setLatex(LyXFont::OFF);
3190 //if (!fl_get_button(fd_form_table->check_latex)){
3191 // insert the new wysiwy table
3192 current_view->buffer()->text->SetLayout(0); // standard layout
3193 if (current_view->buffer()->text->cursor.par->footnoteflag ==
3194 LyXParagraph::NO_FOOTNOTE) {
3195 current_view->buffer()->
3196 text->SetParagraph(0, 0,
3198 VSpace (0.3 * current_view->buffer()->
3199 params.spacing.getValue(),
3201 VSpace (0.3 * current_view->buffer()->
3202 params.spacing.getValue(),
3209 current_view->buffer()->text->SetParagraph(0, 0,
3211 VSpace(VSpace::NONE),
3212 VSpace(VSpace::NONE),
3217 current_view->buffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
3219 for (i = 0; i<xsize * ysize - 1; i++)
3220 current_view->buffer()->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3221 current_view->buffer()->text->RedoParagraph();
3223 current_view->buffer()->text->UnFreezeUndo();
3225 current_view->buffer()->update(1);
3226 minibuffer->Set(_("Table inserted"));
3230 extern "C" void TableCancelCB(FL_OBJECT *, long)
3232 fl_hide_form(fd_form_table->form_table);
3236 extern "C" void TableOKCB(FL_OBJECT *ob, long data)
3238 TableApplyCB(ob, data);
3239 TableCancelCB(ob, data);
3243 /* callbacks for form form_print */
3245 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3247 fl_hide_form(fd_form_print->form_print);
3250 static bool stringOnlyContains (string const & LStr, char const * cset)
3252 char const * cstr = LStr.c_str() ;
3254 return strspn(cstr, cset) == strlen(cstr) ;
3257 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3259 if (!current_view->available())
3261 Buffer *buffer = current_view->buffer();
3262 string path = OnlyPath(buffer->getFileName());
3265 if (fl_get_button(fd_form_print->radio_even_pages))
3266 pageflag = lyxrc->print_evenpage_flag + ' ';
3267 else if (fl_get_button(fd_form_print->radio_odd_pages))
3268 pageflag = lyxrc->print_oddpage_flag + ' ';
3270 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3271 // User may give a page (range) list
3272 // User may print multiple (unsorted) copies
3273 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3274 pages = subst(pages, '+',',');
3275 pages = frontStrip(strip(pages)) ;
3276 while (!pages.empty()) { // a page range was given
3278 pages = split (pages, piece, ',') ;
3279 piece = strip(piece) ;
3280 piece = frontStrip(piece) ;
3281 if ( !stringOnlyContains (piece, "0123456789-") ) {
3282 WriteAlert(_("ERROR! Unable to print!"),
3283 _("Check 'range of pages'!"));
3286 if (piece.find('-') == string::npos) { // not found
3287 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3288 } else if (suffixIs(piece, "-") ) { // missing last page
3289 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3290 } else if (prefixIs(piece, "-") ) { // missing first page
3291 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3293 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3297 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3298 if (!copies.empty()) { // a number of copies was given
3299 if ( !stringOnlyContains (copies, "0123456789") ) {
3300 WriteAlert(_("ERROR! Unable to print!"),
3301 _("Check 'number of copies'!"));
3304 if (fl_get_button(fd_form_print->do_unsorted))
3305 pageflag += lyxrc->print_copies_flag;
3307 pageflag += lyxrc->print_collcopies_flag;
3308 pageflag += " " + copies + ' ' ;
3312 if (fl_get_button(fd_form_print->radio_order_reverse))
3313 reverseflag = lyxrc->print_reverse_flag + ' ';
3315 string orientationflag;
3316 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3317 orientationflag = lyxrc->print_landscape_flag + ' ';
3319 string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
3320 string printer = strip(fl_get_input(fd_form_print->input_printer));
3323 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3324 && ! printer.empty()) // a printer name has been given
3325 printerflag = lyxrc->print_to_printer + printer + ' ';
3328 if (!lyxrc->print_extra_options.empty())
3329 extraflags = lyxrc->print_extra_options + ' ';
3331 string command = lyxrc->print_command + ' '
3332 + printerflag + pageflag + reverseflag
3333 + orientationflag + extraflags;
3335 char real_papersize = buffer->params.papersize;
3336 if (real_papersize == BufferParams::PAPER_DEFAULT)
3337 real_papersize = lyxrc->default_papersize;
3341 switch (real_papersize) {
3342 case BufferParams::PAPER_USLETTER:
3345 case BufferParams::PAPER_A3PAPER:
3348 case BufferParams::PAPER_A4PAPER:
3351 case BufferParams::PAPER_A5PAPER:
3354 case BufferParams::PAPER_B5PAPER:
3357 case BufferParams::PAPER_EXECUTIVEPAPER:
3360 case BufferParams::PAPER_LEGALPAPER:
3363 default: /* If nothing else fits, keep an empty value... */
3367 if (buffer->params.use_geometry
3368 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3369 && !lyxrc->print_paper_dimension_flag.empty()
3370 && !buffer->params.paperwidth.empty()
3371 && !buffer->params.paperheight.empty()) {
3372 // using a custom papersize
3374 command += lyxrc->print_paper_dimension_flag + ' ';
3375 command += buffer->params.paperwidth + ',';
3376 command += buffer->params.paperheight + ' ';
3377 } else if (!lyxrc->print_paper_flag.empty()
3379 && (real_papersize != BufferParams::PAPER_USLETTER ||
3380 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3381 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3383 if (fl_get_button(fd_form_print->radio_file))
3384 command += lyxrc->print_to_file + '\"'
3385 + MakeAbsPath(ps_file, path)
3387 else if (!lyxrc->print_spool_command.empty())
3388 command += lyxrc->print_to_file
3389 + '\"' + ps_file + '\"';
3391 // push directorypath, if necessary
3392 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3393 path = buffer->tmppath;
3398 if (!lyxrc->print_spool_command.empty() &&
3399 !fl_get_button(fd_form_print->radio_file)) {
3400 string command2 = lyxrc->print_spool_command + ' ';
3401 if (!printer.empty())
3402 command2 += lyxrc->print_spool_printerprefix
3404 // First run dvips and, if succesful, then spool command
3405 if ((result = RunScript(buffer, true, command))) {
3406 result = RunScript(buffer, false, command2, ps_file);
3409 result = RunScript(buffer, false, command);
3412 WriteAlert(_("Error:"),
3413 _("Unable to print"),
3414 _("Check that your parameters are correct"));
3418 extern "C" void PrintOKCB(FL_OBJECT *ob, long data)
3420 PrintCancelCB(ob, data);
3421 PrintApplyCB(ob, data);
3425 /* callbacks for form form_figure */
3427 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3429 if (!current_view->available())
3432 Buffer * buffer = current_view->buffer();
3433 if(buffer->isReadonly()) // paranoia
3436 minibuffer->Set(_("Inserting figure..."));
3437 if (fl_get_button(fd_form_figure->radio_inline)
3438 || buffer->text->cursor.par->table) {
3439 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3440 buffer->insertInset(new_inset);
3441 minibuffer->Set(_("Figure inserted"));
3442 new_inset->Edit(0, 0);
3446 current_view->getScreen()->HideCursor();
3450 buffer->text->SetCursorParUndo();
3451 buffer->text->FreezeUndo();
3453 buffer->text->BreakParagraph();
3456 if (buffer->text->cursor.par->Last()) {
3457 buffer->text->CursorLeft();
3459 buffer->text->BreakParagraph();
3463 // The standard layout should always be numer 0;
3464 buffer->text->SetLayout(0);
3466 if (buffer->text->cursor.par->footnoteflag ==
3467 LyXParagraph::NO_FOOTNOTE) {
3468 buffer->text->SetParagraph(0, 0,
3470 VSpace (0.3 * buffer->params.spacing.getValue(),
3473 buffer->params.spacing.getValue(),
3475 LYX_ALIGN_CENTER, string(), 0);
3477 buffer->text->SetParagraph(0, 0,
3479 VSpace(VSpace::NONE),
3480 VSpace(VSpace::NONE),
3487 Inset *new_inset = 0;
3489 new_inset = new InsetFig(100, 100, buffer);
3490 buffer->insertInset(new_inset);
3491 new_inset->Edit(0, 0);
3493 minibuffer->Set(_("Figure inserted"));
3494 buffer->text->UnFreezeUndo();
3498 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3500 fl_hide_form(fd_form_figure->form_figure);
3504 extern "C" void FigureOKCB(FL_OBJECT *ob, long data)
3506 FigureApplyCB(ob, data);
3507 FigureCancelCB(ob, data);
3510 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3512 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3513 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3514 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3515 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3516 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3517 fontloader.update();
3519 // All buffers will need resize
3520 bufferlist.resize();
3522 minibuffer->Set(_("Screen options set"));
3526 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3528 fl_hide_form(fd_form_screen->form_screen);
3532 extern "C" void ScreenOKCB(FL_OBJECT *ob, long data)
3534 ScreenCancelCB(ob, data);
3535 ScreenApplyCB(ob, data);
3541 if (!current_view->available())
3544 fl_set_button(fd_latex_options->accents,
3545 (int)current_view->buffer()->params.allowAccents);
3547 if (fd_latex_options->LaTeXOptions->visible) {
3548 fl_raise_form(fd_latex_options->LaTeXOptions);
3550 fl_show_form(fd_latex_options->LaTeXOptions,
3551 FL_PLACE_MOUSE, FL_FULLBORDER,
3552 _("LaTeX Options"));
3557 // This function runs "configure" and then rereads lyx.defaults to
3558 // reconfigure the automatic settings.
3561 minibuffer->Set(_("Running configure..."));
3563 // Run configure in user lyx directory
3564 Path p(user_lyxdir);
3565 Systemcalls one(Systemcalls::System,
3566 AddName(system_lyxdir, "configure"));
3568 minibuffer->Set(_("Reloading configuration..."));
3569 lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults"));
3570 WriteAlert(_("The system has been reconfigured."),
3571 _("You need to restart LyX to make use of any"),
3572 _("updated document class specifications."));
3576 /* these functions are for the spellchecker */
3577 char* NextWord(float &value)
3579 if (!current_view->available()){
3584 char* string = current_view->buffer()->text->SelectNextWord(value);
3590 void SelectLastWord()
3592 if (!current_view->available())
3595 current_view->getScreen()->HideCursor();
3597 current_view->buffer()->text->SelectSelectedWord();
3598 current_view->getScreen()->ToggleSelection(false);
3599 current_view->buffer()->update(0);
3603 void EndOfSpellCheck()
3605 if (!current_view->available())
3608 current_view->getScreen()->HideCursor();
3610 current_view->buffer()->text->SelectSelectedWord();
3611 current_view->buffer()->text->ClearSelection();
3612 current_view->buffer()->update(0);
3616 void ReplaceWord(string const & replacestring)
3618 if (!current_view->getScreen())
3621 current_view->getScreen()->HideCursor();
3622 current_view->buffer()->update(-2);
3624 /* clear the selection (if there is any) */
3625 current_view->getScreen()->ToggleSelection(false);
3626 current_view->buffer()->text->
3627 ReplaceSelectionWithString(replacestring.c_str());
3629 current_view->buffer()->text->SetSelectionOverString(replacestring.c_str());
3631 // Go back so that replacement string is also spellchecked
3632 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3633 current_view->buffer()->text->CursorLeftIntern();
3635 current_view->buffer()->update(1);
3637 // End of spellchecker stuff
3642 // Table of Contents
3652 static TocList* toclist = 0;
3655 extern "C" void TocSelectCB(FL_OBJECT *ob, long)
3657 if (!current_view->available())
3660 TocList* tmptoclist = toclist;
3661 int i = fl_get_browser(ob);
3664 for (a = 1; a<i && tmptoclist->next; a++){
3665 tmptoclist = tmptoclist->next;
3672 LyXParagraph *par = current_view->buffer()->paragraph;
3673 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3674 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3675 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3676 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3677 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3678 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3679 par->appendix != tmptoclist->appendix)) {
3680 par = par->LastPhysicalPar()->Next();
3685 current_view->buffer()->text->SetCursor(par, 0);
3686 current_view->buffer()->text->sel_cursor =
3687 current_view->buffer()->text->cursor;
3688 current_view->buffer()->update(0);
3691 WriteAlert(_("Error"),
3692 _("Couldn't find this label"),
3693 _("in current document."));
3699 extern "C" void TocCancelCB(FL_OBJECT *, long)
3701 fl_hide_form(fd_form_toc->form_toc);
3705 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3707 static LyXParagraph * stapar = 0;
3708 TocList * tmptoclist = 0;
3710 /* deleted the toclist */
3713 tmptoclist = toclist->next;
3715 toclist = tmptoclist;
3719 tmptoclist = toclist;
3722 fl_clear_browser(fd_form_toc->browser_toc);
3723 if (!current_view->available()) {
3724 fl_add_browser_line(fd_form_toc->browser_toc, _("*** No Document ***"));
3727 fl_hide_object(fd_form_toc->browser_toc);
3728 /* get the table of contents */
3729 LyXParagraph * par = current_view->buffer()->paragraph;
3731 char * line = new char[200];
3737 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3741 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3742 par->GetLayout()).labeltype;
3744 if (labeltype >= LABEL_COUNTER_CHAPTER
3745 && labeltype <= LABEL_COUNTER_CHAPTER +
3746 current_view->buffer()->params.tocdepth) {
3747 /* insert this into the table of contents */
3748 /* first indent a little bit */
3752 textclasslist.TextClass(current_view->buffer()->
3753 params.textclass).maxcounter()) * 4 + 2;
3757 // Then the labestring
3758 if (!par->labelstring.empty()) {
3759 string::size_type i = 0;
3760 while (pos < 199 && i < par->labelstring.length()) {
3761 line[pos] = par->labelstring[i];
3770 /* now the contents */
3771 LyXParagraph::size_type i = 0;
3772 while (pos < 199 && i < par->size()) {
3773 c = par->GetChar(i);
3774 if (isprint(c) || c >= 128) {
3781 fl_add_browser_line(fd_form_toc->browser_toc, line);
3783 /* make a toclist entry */
3785 tmptoclist = new TocList;
3786 toclist = tmptoclist;
3788 tmptoclist->next = new TocList;
3789 tmptoclist = tmptoclist->next;
3792 tmptoclist->next = 0;
3794 for (a = 0; a<6; a++){
3795 tmptoclist->counter[a] = par->GetFirstCounter(a);
3797 tmptoclist->appendix = par->appendix;
3799 par = par->LastPhysicalPar()->Next();
3803 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3804 fl_show_object(fd_form_toc->browser_toc);
3808 /* callbacks for form form_ref */
3809 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3811 if (!current_view->available())
3815 fl_get_browser_line(fd_form_ref->browser_ref,
3816 fl_get_browser(fd_form_ref->browser_ref));
3817 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3823 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3833 if(current_view->buffer()->isSGML())
3834 t += "[" + u + "]" + "{" + s + "}";
3839 new InsetRef(t, current_view->buffer());
3840 current_view->buffer()->insertInset(new_inset);
3844 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3846 if (!current_view->available()) {
3847 fl_clear_browser(fd_form_ref->browser_ref);
3851 FL_OBJECT * brow = fd_form_ref->browser_ref;
3853 // Get the current line, in order to restore it later
3854 char const * const btmp = fl_get_browser_line(brow,
3855 fl_get_browser(brow));
3856 string currentstr = btmp ? btmp : "";
3857 //string currentstr = fl_get_browser_line(brow,
3858 // fl_get_browser(brow));
3860 fl_clear_browser(brow);
3862 string refs = current_view->buffer()->getReferenceList('\n');
3865 #if FL_REVISION > 85
3866 fl_addto_browser_chars(brow, refs.c_str());
3867 int total_lines = fl_get_browser_maxline(brow);
3868 for (int i = 1; i <= total_lines ; i++) {
3869 if (fl_get_browser_line(brow, i) == currentstr) {
3874 fl_set_browser_topline(brow, topline);
3876 // Keep the old ugly code for xforms 0.81 compatibility
3881 curr_ref = refs.token('\n', ref_num);
3882 if (curr_ref.empty())
3884 fl_add_browser_line(brow, curr_ref.c_str());
3889 if (!fl_get_browser_maxline(brow)) {
3890 fl_add_browser_line(brow,
3891 _("*** No labels found in document ***"));
3892 fl_deactivate_object(brow);
3894 fl_select_browser_line(brow, topline);
3895 fl_activate_object(brow);
3897 if (current_view->buffer()->isReadonly()) {
3898 // would be better to de/activate insert buttons
3899 // but that's more work... besides this works. ARRae
3900 fl_hide_form(fd_form_ref->form_ref);
3902 if (!current_view->buffer()->isSGML()) {
3903 fl_deactivate_object(fd_form_ref->ref_name);
3904 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3907 fl_activate_object(fd_form_ref->ref_name);
3908 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3913 extern "C" void RefHideCB(FL_OBJECT *, long)
3915 fl_hide_form(fd_form_ref->form_ref);
3919 void UpdateInset(Inset* inset, bool mark_dirty)
3924 /* very first check for locking insets*/
3925 if (current_view->buffer()->the_locking_inset == inset){
3926 if (current_view->buffer()->text->UpdateInset(inset)){
3927 current_view->update();
3929 if (current_view->buffer()->isLyxClean())
3930 minibuffer->setTimer(4);
3931 current_view->buffer()->markDirty();
3933 current_view->updateScrollbar();
3938 /* first check the current buffer */
3939 if (current_view->available()){
3940 current_view->getScreen()->HideCursor();
3941 current_view->buffer()->update(-3);
3942 if (current_view->buffer()->text->UpdateInset(inset)){
3944 current_view->buffer()->update(1);
3946 current_view->buffer()->update(3);
3951 // check all buffers
3952 bufferlist.updateInset(inset, mark_dirty);
3957 /* these functions return 1 if an error occured,
3959 int LockInset(UpdatableInset* inset)
3961 if (!current_view->buffer()->the_locking_inset && inset){
3962 current_view->buffer()->the_locking_inset = inset;
3969 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
3971 if (current_view->buffer()->the_locking_inset &&
3972 current_view->getScreen()){
3973 y += current_view->buffer()->text->cursor.y;
3974 current_view->getScreen()->ShowManualCursor(x, y,
3980 void HideLockedInsetCursor(long x, long y, int asc, int desc)
3982 if (current_view->buffer()->the_locking_inset &&
3983 current_view->getScreen()){
3984 y += current_view->buffer()->text->cursor.y;
3985 current_view->getScreen()->HideManualCursor(x, y,
3991 void FitLockedInsetCursor(long x, long y, int asc, int desc)
3993 if (current_view->buffer()->the_locking_inset &&
3994 current_view->getScreen()){
3995 y += current_view->buffer()->text->cursor.y;
3996 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
3997 current_view->updateScrollbar();
4002 int UnlockInset(UpdatableInset* inset)
4005 current_view->buffer()->the_locking_inset == inset){
4006 inset->InsetUnlock();
4007 current_view->buffer()->the_locking_inset = 0;
4008 current_view->buffer()->text->FinishUndo();
4011 return bufferlist.unlockInset(inset);
4015 void LockedInsetStoreUndo(Undo::undo_kind kind)
4017 if (!current_view->buffer()->the_locking_inset)
4018 return; // shouldn't happen
4019 if (kind == Undo::EDIT) // in this case insets would not be stored!
4020 kind = Undo::FINISH;
4021 current_view->buffer()->text->SetUndo(kind,
4022 current_view->buffer()->text->cursor.par->
4023 ParFromPos(current_view->buffer()->text->cursor.pos)->previous,
4024 current_view->buffer()->text->cursor.par->
4025 ParFromPos(current_view->buffer()->text->cursor.pos)->next);
4029 void PutInsetIntoInsetUpdateList(Inset* inset)
4032 InsetUpdateStruct* tmp = new InsetUpdateStruct();
4034 tmp->next = InsetUpdateList;
4035 InsetUpdateList = tmp;
4040 void UpdateInsetUpdateList()
4042 InsetUpdateStruct *tmp = InsetUpdateList;
4044 UpdateInset(tmp->inset, false); // "false" because no document change
4048 // delete the update list
4049 while (InsetUpdateList) {
4050 tmp = InsetUpdateList;
4051 InsetUpdateList = InsetUpdateList->next;
4054 InsetUpdateList = 0;
4057 #ifdef WITH_WARNINGS
4060 // I know we shouldn't put anything in here but this seems the fastest
4061 // way to do this (and the cleanest for now). This function just inserts
4062 // a newline in the string and the inserts 'depth'-spaces so that the
4063 // code is indented in the right way!!!
4064 void addNewlineAndDepth(string & file, int const depth)
4067 file.append(depth, ' ');