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 * ====================================================== */
23 #include "support/lstrings.h"
25 #include FORMS_H_LOCATION
27 #include "layout_forms.h"
28 #include "bullet_forms.h"
29 #include "print_form.h"
31 #include "spellchecker.h"
35 #include "insets/insetref.h"
36 #include "insets/insetquotes.h"
38 #include "insets/insetlatex.h"
40 #include "insets/insetlabel.h"
41 #include "insets/insetinfo.h"
42 #include "insets/insetspecialchar.h"
43 #include "insets/figinset.h"
45 #include "latexoptions.h"
47 #include "minibuffer.h"
49 #include "bufferlist.h"
50 #include "support/filetools.h"
51 #include "support/path.h"
53 #include "lyx_gui_misc.h"
54 #include "LyXView.h" // only because of form_main
55 #include "lastfiles.h"
56 #include "support/FileInfo.h"
57 #include "lyxscreen.h"
59 #include "support/syscall.h"
60 #include "support/lyxlib.h"
61 #include "lyxserver.h"
62 #include "FontLoader.h"
68 extern Combox * combo_language;
69 extern BufferList bufferlist;
70 extern void show_symbols_form();
71 extern FD_form_title * fd_form_title;
72 extern FD_form_paragraph * fd_form_paragraph;
73 extern FD_form_character * fd_form_character;
74 extern FD_form_document * fd_form_document;
75 extern FD_form_quotes * fd_form_quotes;
76 extern FD_form_preamble * fd_form_preamble;
77 extern FD_form_table * fd_form_table;
78 extern FD_form_print * fd_form_print;
79 extern FD_form_figure * fd_form_figure;
80 extern FD_form_screen * fd_form_screen;
81 extern FD_form_toc * fd_form_toc;
82 extern FD_form_ref * fd_form_ref;
83 extern FD_LaTeXOptions * fd_latex_options;
84 extern FD_form_bullet * fd_form_bullet;
86 extern BufferView * current_view; // called too many times in this file...
88 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
90 extern bool send_fax(string const & fname, string const & sendcmd);
91 extern void MenuSendto();
93 extern LyXServer * lyxserver;
94 extern FontLoader fontloader;
96 // this should be static, but I need it in buffer.C
97 bool quitting; // flag, that we are quitting the program
98 extern bool finished; // all cleanup done just let it run through now.
100 char ascii_type; /* for selection notify callbacks */
102 bool scrolling = false;
104 char updatetimer = 0;
106 /* whether the work area should get callbacks */
107 bool input_prohibited = false;
109 /* the selection possible is needed, that only motion events are
110 * used, where the bottom press event was on the drawing area too */
111 bool selection_possible = false;
113 // This is used to make the dreaded font toggle problem hopefully go
114 // away. Definitely not the best solution, but I think it sorta works.
115 bool toggleall = true;
118 This is the inset locking stuff needed for mathed --------------------
120 an inset can simple call LockInset in it's edit call and *ONLY* in it's
122 Inset::Edit() can only be called by the main lyx module.
124 Then the inset may modify the menu's and/or iconbars.
126 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
128 During the lock, all button and keyboard events will be modified
129 and send to the inset through the following inset-features. Note that
130 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
131 to contain the code for restoring the menus and things like this.
134 virtual void InsetButtonPress(int x, int y, int button);
135 virtual void InsetButtonRelease(int x, int y, int button);
136 virtual void InsetKeyPress(XKeyEvent *ev);
137 virtual void InsetMotionNotify(int x, int y, int state);
138 virtual void InsetUnlock();
140 If a inset wishes any redraw and/or update it just has to call
142 It's is completly irrelevant, where the inset is. UpdateInset will
143 find it in any paragraph in any buffer.
144 Of course the_locking_inset and the insets in the current paragraph/buffer
145 are checked first, so no performance problem should occur.
147 Hope that's ok for the beginning, Alejandro,
148 sorry that I needed so much time,
153 void UpdateInset(Inset * inset, bool mark_dirty = true);
154 /* these functions return 1 if an error occured,
156 // Now they work only for updatable insets. [Alejandro 080596]
157 //int LockInset(UpdatableInset * inset);
158 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
159 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
160 //int UnlockInset(UpdatableInset * inset);
161 //void LockedInsetStoreUndo(Undo::undo_kind kind);
163 /* this is for asyncron updating. UpdateInsetUpdateList will be called
164 automatically from LyX. Just insert the Inset into the Updatelist */
165 void UpdateInsetUpdateList();
166 void PutInsetIntoInsetUpdateList(Inset * inset);
168 InsetUpdateStruct * InsetUpdateList = 0;
172 -----------------------------------------------------------------------
175 /* some function prototypes */
177 int RunLinuxDoc(int, string const &);
178 int RunDocBook(int, string const &);
179 void MenuWrite(Buffer * buf);
180 void MenuWriteAs(Buffer * buffer);
181 void MenuReload(Buffer * buf);
182 void MenuLayoutSave();
185 // How should this actually work? Should it prohibit input in all BufferViews,
186 // or just in the current one? If "just the current one", then it should be
187 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
188 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
189 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
190 // current LyxView that should be prohibited (Lgb) (This applies to
191 // "AllowInput" as well.)
194 input_prohibited = true;
195 if (current_view->getScreen())
196 current_view->getScreen()->HideCursor();
198 static Cursor cursor;
199 static bool cursor_undefined = true;
201 if (cursor_undefined){
202 cursor = XCreateFontCursor(fl_display, XC_watch);
204 cursor_undefined = false;
207 /* set the cursor to the watch for all forms and the canvas */
208 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
210 if (fd_form_paragraph->form_paragraph->visible)
211 XDefineCursor(fl_display,
212 fd_form_paragraph->form_paragraph->window,
214 if (fd_form_character->form_character->visible)
215 XDefineCursor(fl_display,
216 fd_form_character->form_character->window,
220 fl_deactivate_all_forms();
224 // Should find a way to move this into BufferView.C
225 void SetXtermCursor(Window win)
227 static Cursor cursor;
228 static bool cursor_undefined = true;
229 if (cursor_undefined){
230 cursor = XCreateFontCursor(fl_display, XC_xterm);
232 cursor_undefined = false;
234 XDefineCursor(fl_display, win, cursor);
241 input_prohibited = false;
243 /* reset the cursor from the watch for all forms and the canvas */
245 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
246 if (fd_form_paragraph->form_paragraph->visible)
247 XUndefineCursor(fl_display,
248 fd_form_paragraph->form_paragraph->window);
249 if (fd_form_character->form_character->visible)
250 XUndefineCursor(fl_display,
251 fd_form_character->form_character->window);
252 if (current_view->getWorkArea()->belowmouse)
253 SetXtermCursor(current_view->owner()->getForm()->window);
256 fl_activate_all_forms();
260 void FreeUpdateTimer()
262 /* a real free timer would be better but I don't know
263 * how to do this with xforms */
268 void SetUpdateTimer(float time)
270 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
283 // should be moved to lyxfunc.C
284 void MenuWrite(Buffer * buffer)
287 if (!bufferlist.write(buffer)) {
288 string fname = buffer->fileName();
289 string s = MakeAbsPath(fname);
290 if (AskQuestion(_("Save failed. Rename and try again?"),
291 MakeDisplayPath(s, 50),
292 _("(If not, document is not saved.)"))) {
296 lastfiles->newFile(buffer->fileName());
301 // should be moved to BufferView.C
302 // Half of this func should be in LyXView, the rest in BufferView.
303 void MenuWriteAs(Buffer * buffer)
305 // Why do we require BufferView::text to be able to write a
306 // document? I see no point in that. (Lgb)
307 //if (!bv->text) return;
309 string fname = buffer->fileName();
310 string oldname = fname;
314 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
315 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
317 if (!IsLyXFilename(fname))
320 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
323 OnlyFilename(fname));
327 // Can we do without this one?
329 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled."));
333 // Make sure the absolute filename ends with appropriate suffix
334 string s = MakeAbsPath(fname);
335 if (!IsLyXFilename(s))
338 // Same name as we have already?
340 if (!AskQuestion(_("Same name as document already has:"),
341 MakeDisplayPath(s, 50),
344 // Falls through to name change and save
346 // No, but do we have another file with this name open?
347 else if (bufferlist.exists(s)) {
348 if (AskQuestion(_("Another document with same name open!"),
349 MakeDisplayPath(s, 50),
350 _("Replace with current document?")))
352 bufferlist.close(bufferlist.getBuffer(s));
354 // Ok, change the name of the buffer, but don't save!
358 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
360 _("', but not saved..."));
363 } // Check whether the file exists
366 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
367 MakeDisplayPath(s, 50),
372 // Ok, change the name of the buffer
376 // Small bug: If the save fails, we have irreversible changed the name
382 int MenuRunLaTeX(Buffer * buffer)
386 if (buffer->isLinuxDoc())
387 ret = RunLinuxDoc(1, buffer->fileName());
388 else if (buffer->isLiterate())
389 ret = buffer->runLiterate();
390 else if (buffer->isDocBook())
391 ret = RunDocBook(1, buffer->fileName());
393 ret = buffer->runLaTeX();
399 s = _("One error detected");
400 t = _("You should try to fix it.");
403 s += _(" errors detected.");
404 t = _("You should try to fix them.");
406 WriteAlert(_("There were errors during the LaTeX run."), s, t);
412 int MenuBuildProg(Buffer * buffer)
416 if (buffer->isLiterate())
417 ret = buffer->buildProgram();
419 string s = _("Wrong type of document");
420 string t = _("The Build operation is not allowed in this document");
421 WriteAlert(_("There were errors during the Build process."), s, t);
429 s = _("One error detected");
430 t = _("You should try to fix it.");
433 s += _(" errors detected.");
434 t = _("You should try to fix them.");
436 WriteAlert(_("There were errors during the Build process."), s, t);
442 int MenuRunChktex(Buffer * buffer)
446 if (buffer->isSGML()) {
447 WriteAlert(_("Chktex does not work with SGML derived documents."));
450 ret = buffer->runChktex();
456 s = _("No warnings found.");
457 } else if (ret == 1) {
458 s = _("One warning found.");
459 t = _("Use 'Edit->Go to Error' to find it.");
462 s += _(" warnings found.");
463 t = _("Use 'Edit->Go to Error' to find them.");
465 WriteAlert(_("Chktex run successfully"), s, t);
467 WriteAlert(_("Error!"), _("It seems chktex does not work."));
473 int MakeDVIOutput(Buffer * buffer)
481 string path = OnlyPath(buffer->fileName());
482 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
483 path = buffer->tmppath;
485 if (!buffer->isDviClean()) {
487 ret = MenuRunLaTeX(buffer);
493 /* wait == false means don't wait for termination */
494 /* wait == true means wait for termination */
495 // The bool should be placed last on the argument line. (Lgb)
496 // Returns false if we fail.
497 bool RunScript(Buffer * buffer, bool wait,
498 string const & command,
499 string const & orgname = string(),
500 bool need_shell = true)
504 string name = orgname;
507 if (MakeDVIOutput(buffer) > 0)
509 /* get DVI-Filename */
511 name = ChangeExtension(buffer->getLatexName(),
514 path = OnlyPath(name);
515 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
516 path = buffer->tmppath;
520 cmd = command + ' ' + QuoteName(name);
529 // OS/2 cmd.exe has another use for '&'
531 // This is not NLS safe, but it's OK, I think.
532 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
534 // COMSPEC is set, unless user unsets
535 sh = OnlyFilename(GetEnvPath("COMSPEC"));
540 if (contains(sh, "cmd.exe")
541 || contains(sh, "4os2.exe"))
542 cmd = "start /min/n " + cmd;
547 // It seems that, if wait is false, we never get back
548 // the return code of the command. This means that all
549 // the code I added in PrintApplyCB is currently
552 #warning What should we do here?
554 buffer->getUser()->owner()->getMiniBuffer()->Set(
555 _("Executing command:"), cmd);
556 result = one.startscript(Systemcalls::System, cmd);
558 buffer->getUser()->owner()->getMiniBuffer()->Set(
559 _("Executing command:"), cmd);
560 result = one.startscript(wait ? Systemcalls::Wait
561 : Systemcalls::DontWait, cmd);
567 // Returns false if we fail
568 bool MenuRunDvips(Buffer * buffer, bool wait = false)
577 if (MakeDVIOutput(buffer) > 0) {
581 // Generate postscript file
582 string psname = ChangeExtension (buffer->fileName(),
588 char real_papersize = buffer->params.papersize;
589 if (real_papersize == BufferParams::PAPER_DEFAULT)
590 real_papersize = lyxrc->default_papersize;
592 switch (real_papersize) {
593 case BufferParams::PAPER_USLETTER:
596 case BufferParams::PAPER_A3PAPER:
599 case BufferParams::PAPER_A4PAPER:
602 case BufferParams::PAPER_A5PAPER:
605 case BufferParams::PAPER_B5PAPER:
608 case BufferParams::PAPER_EXECUTIVEPAPER:
611 case BufferParams::PAPER_LEGALPAPER:
614 default: /* If nothing else fits, keep an empty value... */
618 // Make postscript file.
619 string command = "dvips " + lyxrc->print_to_file + ' ';
620 command += QuoteName(psname);
621 if (buffer->params.use_geometry
622 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
623 && !lyxrc->print_paper_dimension_flag.empty()
624 && !buffer->params.paperwidth.empty()
625 && !buffer->params.paperheight.empty()) {
626 // using a custom papersize
628 command += lyxrc->print_paper_dimension_flag + ' ';
629 command += buffer->params.paperwidth + ',';
630 command += buffer->params.paperheight;
631 } else if (!paper.empty()
632 && (real_papersize != BufferParams::PAPER_USLETTER ||
633 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
634 // dvips won't accept -t letter -t landscape. In all other
635 // cases, include the paper size explicitly.
637 command += lyxrc->print_paper_flag + ' ' + paper;
639 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
641 command += lyxrc->print_landscape_flag;
643 // push directorypath, if necessary
644 string path = OnlyPath(buffer->fileName());
645 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
646 path = buffer->tmppath;
649 bool ret = RunScript(buffer, wait, command);
655 // Returns false if we fail
656 bool MenuPreviewPS(Buffer * buffer)
662 // Generate postscript file
663 if (!MenuRunDvips(buffer, true)) {
667 // Start postscript viewer
669 string ps = ChangeExtension (buffer->fileName(),
671 // push directorypath, if necessary
672 string path = OnlyPath(buffer->fileName());
673 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
674 path = buffer->tmppath;
677 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
683 void MenuFax(Buffer * buffer)
689 // Generate postscript file
690 if (!MenuRunDvips(buffer, true)) {
695 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
696 string path = OnlyPath (buffer->fileName());
697 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
698 path = buffer->tmppath;
701 if (!lyxrc->fax_program.empty()) {
702 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
704 Systemcalls one(Systemcalls::System, help2);
706 send_fax(ps, lyxrc->fax_command);
710 // Returns false if we fail
711 bool MenuPreview(Buffer * buffer)
720 char real_papersize = buffer->params.papersize;
721 if (real_papersize == BufferParams::PAPER_DEFAULT)
722 real_papersize = lyxrc->default_papersize;
724 switch (real_papersize) {
725 case BufferParams::PAPER_USLETTER:
728 case BufferParams::PAPER_A3PAPER:
731 case BufferParams::PAPER_A4PAPER:
734 case BufferParams::PAPER_A5PAPER:
737 case BufferParams::PAPER_B5PAPER:
740 case BufferParams::PAPER_EXECUTIVEPAPER:
743 case BufferParams::PAPER_LEGALPAPER:
746 default: /* If nothing else fits, keep the empty value */
751 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
752 // we HAVE to give a size when the page is in
753 // landscape, so use USletter.
754 paper = " -paper usr";
756 paper = " -paper " + paper;
757 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
761 // push directorypath, if necessary
762 string path = OnlyPath(buffer->fileName());
763 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
764 path = buffer->tmppath;
768 string command = lyxrc->view_dvi_command + paper ;
769 bool ret = RunScript(buffer, false, command);
774 void MenuMakeLaTeX(Buffer * buffer)
776 // Why care about this?
780 // Get LaTeX-Filename
781 string s = buffer->getLatexName(false);
785 !AskQuestion(_("File already exists:"),
786 MakeDisplayPath(s, 50),
787 _("Do you want to overwrite the file?"))) {
788 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
792 if (buffer->isDocBook())
793 buffer->getUser()->owner()->getMiniBuffer()->Set(
794 _("DocBook does not have a latex backend"));
796 if (buffer->isLinuxDoc())
797 RunLinuxDoc(0, buffer->fileName());
799 buffer->makeLaTeXFile(s, string(), true);
800 buffer->getUser()->owner()->getMiniBuffer()->Set(
801 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
802 buffer->markDviDirty();
807 void MenuMakeLinuxDoc(Buffer * buffer)
810 //if (!bv->text) return;
812 if (!buffer->isLinuxDoc()) {
813 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
817 // Get LinuxDoc-Filename
818 string s = ChangeExtension(buffer->fileName(),
823 !AskQuestion(_("File already exists:"),
824 MakeDisplayPath(s, 50),
825 _("Do you want to overwrite the file?"))) {
826 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
830 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
831 MakeDisplayPath(s),"'...");
833 buffer->makeLinuxDocFile(s, 65);
835 buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
840 void MenuMakeDocBook(Buffer * buffer)
843 //if (!bv->text) return;
845 if (!buffer->isDocBook()) {
846 WriteAlert(_("Error!"),
847 _("Document class must be docbook."));
851 // Get DocBook-Filename
852 string s = ChangeExtension(buffer->fileName(),
857 !AskQuestion(_("File already exists:"),
858 MakeDisplayPath(s, 50),
859 _("Do you want to overwrite the file?"))) {
860 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
864 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
865 MakeDisplayPath(s), "'...");
867 buffer->makeDocBookFile(s, 65);
869 buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
874 void MenuMakeAscii(Buffer * buffer)
877 //if (!bv->text) return;
879 /* get LaTeX-Filename */
880 string s = ChangeExtension (buffer->fileName(),
885 !AskQuestion(_("File already exists:"),
886 MakeDisplayPath(s, 50),
887 _("Do you want to overwrite the file?"))) {
888 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
892 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
894 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
898 void MenuPrint(Buffer * buffer)
904 string input_file = ChangeExtension(buffer->fileName(),
905 lyxrc->print_file_extension,
907 fl_set_input(fd_form_print->input_file, input_file.c_str());
909 if (fd_form_print->form_print->visible) {
910 fl_raise_form(fd_form_print->form_print);
913 fl_show_form(fd_form_print->form_print,
914 FL_PLACE_MOUSE, FL_FULLBORDER,
919 void MenuMakeHTML(Buffer * buffer)
921 // First, create LaTeX file
922 MenuMakeLaTeX(buffer);
924 // And now, run the converter
925 string file = buffer->fileName();
926 Path path(OnlyPath(file));
927 // the tex file name has to be correct for
928 // latex, but the html file name can be
930 string result = ChangeExtension(file, ".html", false);
931 string infile = buffer->getLatexName(false);
932 string tmp = lyxrc->html_command;
933 tmp = subst(tmp, "$$FName", infile);
934 tmp = subst(tmp, "$$OutName", result);
936 int res = one.startscript(Systemcalls::System, tmp);
938 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
939 + MakeDisplayPath(result) +'\'');
941 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
942 + MakeDisplayPath(infile)
948 void MenuExport(Buffer * buffer, string const & extyp)
951 if (extyp == "latex") {
952 // make sure that this buffer is not linuxdoc
953 MenuMakeLaTeX(buffer);
956 else if (extyp == "linuxdoc") {
957 // make sure that this buffer is not latex
958 MenuMakeLinuxDoc(buffer);
961 else if (extyp == "docbook") {
962 // make sure that this buffer is not latex or linuxdoc
963 MenuMakeDocBook(buffer);
966 else if (extyp == "dvi") {
967 // Run LaTeX as "Update dvi..." Bernhard.
968 // We want the dvi in the current directory. This
969 // is achieved by temporarily disabling use of
970 // temp directory. As a side-effect, we get
971 // *.log and *.aux files also. (Asger)
972 bool flag = lyxrc->use_tempdir;
973 lyxrc->use_tempdir = false;
974 MenuRunLaTeX(buffer);
975 lyxrc->use_tempdir = flag;
978 else if (extyp == "postscript") {
979 // Start Print-dialog. Not as good as dvi... Bernhard.
981 // Since the MenuPrint is a pop-up, we can't use
982 // the same trick as above. (Asger)
983 // MISSING: Move of ps-file :-(
984 // And MenuPrint should not be used for this at all...
987 else if (extyp == "ascii") {
988 MenuMakeAscii(buffer);
990 else if (extyp == "custom") {
994 else if (extyp == "html") {
995 MenuMakeHTML(buffer);
998 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
1005 lyxerr.debug() << "Running QuitLyX." << endl;
1007 if (!bufferlist.QwriteAll())
1010 lastfiles->writeFile(lyxrc->lastfiles);
1012 // Set a flag that we do quitting from the program,
1013 // so no refreshes are necessary.
1016 // close buffers first
1017 bufferlist.closeAll();
1019 // do any other cleanup procedures now
1020 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1022 DestroyLyXTmpDir(system_tempdir);
1030 // should probably be moved into BufferList (Lgb)
1031 // Perfect target for a thread...
1033 if (!current_view->getScreen() || !current_view->available())
1036 if (current_view->buffer()->isBakClean()
1037 || current_view->buffer()->isReadonly()) {
1038 // We don't save now, but we'll try again later
1039 current_view->owner()->resetAutosaveTimer();
1043 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1045 // create autosave filename
1046 string fname = OnlyPath(current_view->buffer()->fileName());
1048 fname += OnlyFilename(current_view->buffer()->fileName());
1051 // tmp_ret will be located (usually) in /tmp
1052 // will that be a problem?
1053 string tmp_ret = tmpnam(0);
1055 pid_t pid = fork(); // If you want to debug the autosave
1056 // you should set pid to -1, and comment out the
1058 if (pid == 0 || pid == -1) {
1059 // pid = -1 signifies that lyx was unable
1060 // to fork. But we will do the save
1062 bool failed = false;
1063 if (!tmp_ret.empty()) {
1064 current_view->buffer()->writeFile(tmp_ret, 1);
1065 // assume successful write of tmp_ret
1066 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1068 // most likely couldn't move between filesystems
1069 // unless write of tmp_ret failed
1070 // so remove tmp file (if it exists)
1071 remove(tmp_ret.c_str());
1078 // failed to write/rename tmp_ret so try writing direct
1079 if (!current_view->buffer()->writeFile(fname, 1)) {
1080 // It is dangerous to do this in the child,
1081 // but safe in the parent, so...
1083 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1086 if (pid == 0) { // we are the child so...
1091 current_view->buffer()->markBakClean();
1092 current_view->owner()->resetAutosaveTimer();
1097 // (c) CHT Software Service GmbH
1100 // create new file with template
1103 Buffer * NewLyxFile(string const & filename)
1105 // Split argument by :
1107 string tmpname = split(filename, name, ':');
1108 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1109 if (name.length() == 1
1110 && isalpha(static_cast<unsigned char>(name[0]))
1111 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1113 name += token(tmpname, ':', 0);
1114 tmpname = split(tmpname, ':');
1117 lyxerr.debug() << "Arg is " << filename
1118 << "\nName is " << name
1119 << "\nTemplate is " << tmpname << endl;
1121 // find a free buffer
1122 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1124 lastfiles->newFile(tmpbuf->fileName());
1129 // Insert ascii file (if filename is empty, prompt for one)
1130 void InsertAsciiFile(string const & f, bool asParagraph)
1135 if (!current_view->getScreen()) return;
1137 if (fname.empty()) {
1139 fname = fileDlg.Select(_("File to Insert"),
1140 current_view->owner()->buffer()->filepath,
1143 if (fname.empty()) return;
1148 if (!fi.readable()) {
1149 WriteFSAlert(_("Error! Specified file is unreadable: "),
1150 MakeDisplayPath(fname, 50));
1154 ifstream ifs(fname.c_str());
1156 WriteFSAlert(_("Error! Cannot open specified file: "),
1157 MakeDisplayPath(fname, 50));
1160 LyXParagraph * tmppar = new LyXParagraph;
1161 tmppar->readSimpleWholeFile(ifs);
1163 // set the end of the string
1164 #ifdef WITH_WARNINGS
1165 #warning why do we do this?
1167 // I don't think this is needed. Actually it might be plain wrong.
1168 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1170 // insert the string
1171 current_view->getScreen()->HideCursor();
1173 // clear the selection
1174 current_view->beforeChange();
1176 current_view->text->InsertStringA(tmppar->text);
1178 current_view->text->InsertStringB(tmppar->text);
1180 current_view->update(1);
1184 void MenuShowTableOfContents()
1186 static int ow = -1, oh;
1189 if (fd_form_toc->form_toc->visible) {
1190 fl_raise_form(fd_form_toc->form_toc);
1192 fl_show_form(fd_form_toc->form_toc,
1193 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1194 _("Table Of Contents"));
1196 ow = fd_form_toc->form_toc->w;
1197 oh = fd_form_toc->form_toc->h;
1199 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1204 void MenuInsertLabel(char const * arg)
1208 if (label.empty()) {
1210 result = askForText(_("Enter new label to insert:"));
1212 label = frontStrip(strip(result.second));
1215 if (!label.empty()) {
1216 InsetLabel * new_inset = new InsetLabel;
1217 new_inset->setContents(label);
1218 current_view->insertInset(new_inset);
1224 void MenuInsertRef()
1226 static int ow = -1, oh;
1229 if (fd_form_ref->form_ref->visible) {
1230 fl_raise_form(fd_form_ref->form_ref);
1232 fl_show_form(fd_form_ref->form_ref,
1233 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1234 _("Insert Reference"));
1236 ow = fd_form_ref->form_ref->w;
1237 oh = fd_form_ref->form_ref->h;
1239 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1244 void MenuPasteSelection(char at)
1246 if (!current_view->getScreen())
1251 Atom data_prop = XInternAtom(fl_display,
1254 if (data_prop == None)
1256 XConvertSelection(fl_display,
1257 XA_PRIMARY, XA_STRING, data_prop,
1258 current_view->owner()->getForm()->window, 0);
1263 // candidate for move to BufferView
1264 extern "C" void FootCB(FL_OBJECT *, long)
1266 if (!current_view->available())
1269 current_view->owner()->getMiniBuffer()->Set(_("Inserting Footnote..."));
1270 current_view->getScreen()->HideCursor();
1271 current_view->update(-2);
1272 current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1273 current_view->update(1);
1277 // candidate for move to LyXView
1278 void LayoutsCB(int sel, void *)
1280 string tmp = tostr(sel);
1281 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1287 * SGML Linuxdoc support:
1288 * (flag == -1) import SGML file
1289 * (flag == 0) make TeX output
1290 * (flag == 1) make dvi output
1292 int RunLinuxDoc(int flag, string const & filename)
1301 /* generate a path-less extension name */
1302 name = ChangeExtension (filename, ".sgml", true);
1303 path = OnlyPath (filename);
1304 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1305 path = current_view->buffer()->tmppath;
1310 if (!current_view->available())
1312 current_view->buffer()->makeLinuxDocFile(name, 0);
1313 #ifdef WITH_WARNINGS
1314 #warning remove this once we have a proper geometry class
1316 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1318 case BufferParams::PAPER_A4PAPER:
1319 add_flags = "-p a4";
1321 case BufferParams::PAPER_USLETTER:
1322 add_flags = "-p letter";
1324 default: /* nothing to be done yet ;-) */ break;
1332 case -1: /* Import file */
1333 current_view->owner()->getMiniBuffer()->Set(_("Importing LinuxDoc SGML file `"),
1334 MakeDisplayPath(filename), "'...");
1335 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1337 if (one.startscript(Systemcalls::System, s2))
1340 case 0: /* TeX output asked */
1341 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1342 s2 = "sgml2latex " + add_flags + " -o tex "
1343 + lyxrc->sgml_extra_options + ' ' + name;
1344 if (one.startscript(Systemcalls::System, s2))
1347 case 1: /* dvi output asked */
1348 current_view->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1349 s2 = "sgml2latex " + add_flags + " -o dvi "
1350 + lyxrc->sgml_extra_options + ' ' + name;
1351 if (one.startscript(Systemcalls::System, s2)) {
1354 current_view->buffer()->markDviClean();
1356 default: /* unknown output */
1362 current_view->buffer()->redraw();
1368 * SGML DocBook support:
1369 * (flag == 1) make dvi output
1371 int RunDocBook(int flag, string const & filename)
1373 /* generate a path-less extension name */
1374 string name = ChangeExtension (filename, ".sgml", true);
1375 string path = OnlyPath (filename);
1376 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1377 path = current_view->buffer()->tmppath;
1381 if (!current_view->available())
1384 current_view->buffer()->makeDocBookFile(name, 0);
1386 // Shall this code go or should it stay? (Lgb)
1387 // string add_flags;
1388 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1390 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1391 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1392 // default: /* nothing to be done yet ;-) */ break;
1399 case 1: /* dvi output asked */
1401 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1402 string s2 = "sgmltools --backend dvi " + name;
1403 if (one.startscript(Systemcalls::System, s2)) {
1406 current_view->buffer()->markDviClean();
1409 default: /* unknown output */
1415 current_view->buffer()->redraw();
1420 void BufferView::allFloats(char flag, char figmar)
1422 if (!available()) return;
1424 LyXCursor cursor = text->cursor;
1426 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1428 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1429 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1431 && cursor.par->footnotekind != LyXParagraph::FIG
1432 && cursor.par->footnotekind != LyXParagraph::TAB
1433 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1434 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1435 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1440 LyXCursor tmpcursor = cursor;
1441 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1442 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1444 LyXParagraph *par = buffer()->paragraph;
1447 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1449 && par->footnotekind != LyXParagraph::FOOTNOTE
1450 && par->footnotekind != LyXParagraph::MARGIN)
1452 && par->footnotekind != LyXParagraph::FIG
1453 && par->footnotekind != LyXParagraph::TAB
1454 && par->footnotekind != LyXParagraph::WIDE_FIG
1455 && par->footnotekind != LyXParagraph::WIDE_TAB
1456 && par->footnotekind != LyXParagraph::ALGORITHM
1461 && par->previous->footnoteflag !=
1462 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1463 text->SetCursorIntern(par->previous,
1465 text->OpenFootnote();
1470 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1474 par->footnotekind != LyXParagraph::FOOTNOTE
1476 par->footnotekind != LyXParagraph::MARGIN
1481 par->footnotekind != LyXParagraph::FIG
1483 par->footnotekind != LyXParagraph::TAB
1485 par->footnotekind != LyXParagraph::WIDE_FIG
1487 par->footnotekind != LyXParagraph::WIDE_TAB
1489 par->footnotekind != LyXParagraph::ALGORITHM
1493 text->SetCursorIntern(par, 0);
1494 text->CloseFootnote();
1500 text->SetCursorIntern(cursor.par, cursor.pos);
1507 void MenuLayoutCharacter()
1509 static int ow = -1, oh;
1511 if (fd_form_character->form_character->visible) {
1512 fl_raise_form(fd_form_character->form_character);
1514 fl_show_form(fd_form_character->form_character,
1515 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1516 _("Character Style"));
1518 ow = fd_form_character->form_character->w;
1519 oh = fd_form_character->form_character->h;
1521 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1526 inline void DeactivateParagraphButtons ()
1528 fl_deactivate_object (fd_form_paragraph->button_ok);
1529 fl_deactivate_object (fd_form_paragraph->button_apply);
1530 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1531 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1535 inline void ActivateParagraphButtons ()
1537 fl_activate_object (fd_form_paragraph->button_ok);
1538 fl_activate_object (fd_form_paragraph->button_apply);
1539 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1540 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1544 inline void DisableParagraphLayout ()
1546 DeactivateParagraphButtons();
1547 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1548 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1549 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1550 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1551 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1552 fl_deactivate_object (fd_form_paragraph->check_noindent);
1553 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1554 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1555 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1556 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1557 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1558 fl_deactivate_object (fd_form_paragraph->input_space_above);
1559 fl_deactivate_object (fd_form_paragraph->input_space_below);
1560 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1561 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1562 fl_deactivate_object (fd_form_paragraph->check_space_above);
1563 fl_deactivate_object (fd_form_paragraph->check_space_below);
1567 inline void EnableParagraphLayout ()
1569 ActivateParagraphButtons();
1570 fl_activate_object (fd_form_paragraph->input_labelwidth);
1571 fl_activate_object (fd_form_paragraph->check_lines_top);
1572 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1573 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1574 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1575 fl_activate_object (fd_form_paragraph->check_noindent);
1576 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1577 fl_activate_object (fd_form_paragraph->radio_align_right);
1578 fl_activate_object (fd_form_paragraph->radio_align_left);
1579 fl_activate_object (fd_form_paragraph->radio_align_block);
1580 fl_activate_object (fd_form_paragraph->radio_align_center);
1581 fl_activate_object (fd_form_paragraph->input_space_above);
1582 fl_activate_object (fd_form_paragraph->input_space_below);
1583 fl_activate_object (fd_form_paragraph->choice_space_above);
1584 fl_activate_object (fd_form_paragraph->choice_space_below);
1585 fl_activate_object (fd_form_paragraph->check_space_above);
1586 fl_activate_object (fd_form_paragraph->check_space_below);
1590 bool UpdateLayoutParagraph()
1592 if (!current_view->getScreen() || !current_view->available()) {
1593 if (fd_form_paragraph->form_paragraph->visible)
1594 fl_hide_form(fd_form_paragraph->form_paragraph);
1598 Buffer * buf = current_view->buffer();
1600 fl_set_input(fd_form_paragraph->input_labelwidth,
1601 current_view->text->cursor.par->GetLabelWidthString().c_str());
1602 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1603 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1604 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1605 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1607 int align = current_view->text->cursor.par->GetAlign();
1608 if (align == LYX_ALIGN_LAYOUT)
1609 align = textclasslist.Style(buf->params.textclass,
1610 current_view->text->cursor.par->GetLayout()).align;
1613 case LYX_ALIGN_RIGHT:
1614 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1616 case LYX_ALIGN_LEFT:
1617 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1619 case LYX_ALIGN_CENTER:
1620 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1623 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1627 fl_set_button(fd_form_paragraph->check_lines_top,
1628 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1629 fl_set_button(fd_form_paragraph->check_lines_bottom,
1630 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1631 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1632 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1633 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1634 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1635 fl_set_button(fd_form_paragraph->check_noindent,
1636 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1637 fl_set_input (fd_form_paragraph->input_space_above, "");
1639 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1641 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1643 case VSpace::DEFSKIP:
1644 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1646 case VSpace::SMALLSKIP:
1647 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1649 case VSpace::MEDSKIP:
1650 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1652 case VSpace::BIGSKIP:
1653 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1656 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1658 case VSpace::LENGTH:
1659 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1660 fl_set_input (fd_form_paragraph->input_space_above,
1661 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1664 fl_set_button (fd_form_paragraph->check_space_above,
1665 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1666 fl_set_input (fd_form_paragraph->input_space_below, "");
1667 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1669 fl_set_choice (fd_form_paragraph->choice_space_below,
1672 case VSpace::DEFSKIP:
1673 fl_set_choice (fd_form_paragraph->choice_space_below,
1676 case VSpace::SMALLSKIP:
1677 fl_set_choice (fd_form_paragraph->choice_space_below,
1680 case VSpace::MEDSKIP:
1681 fl_set_choice (fd_form_paragraph->choice_space_below,
1684 case VSpace::BIGSKIP:
1685 fl_set_choice (fd_form_paragraph->choice_space_below,
1689 fl_set_choice (fd_form_paragraph->choice_space_below,
1692 case VSpace::LENGTH:
1693 fl_set_choice (fd_form_paragraph->choice_space_below,
1695 fl_set_input (fd_form_paragraph->input_space_below,
1696 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1699 fl_set_button (fd_form_paragraph->check_space_below,
1700 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1702 fl_set_button(fd_form_paragraph->check_noindent,
1703 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1705 if (current_view->buffer()->isReadonly()) {
1706 DisableParagraphLayout();
1708 EnableParagraphLayout();
1714 void MenuLayoutParagraph()
1716 if (UpdateLayoutParagraph()) {
1717 if (fd_form_paragraph->form_paragraph->visible) {
1718 fl_raise_form(fd_form_paragraph->form_paragraph);
1720 fl_show_form(fd_form_paragraph->form_paragraph,
1721 FL_PLACE_MOUSE, FL_FULLBORDER,
1722 _("Paragraph Environment"));
1729 void DeactivateDocumentButtons ()
1731 fl_deactivate_object (fd_form_document->button_ok);
1732 fl_deactivate_object (fd_form_document->button_apply);
1733 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1734 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1739 void ActivateDocumentButtons ()
1741 fl_activate_object (fd_form_document->button_ok);
1742 fl_activate_object (fd_form_document->button_apply);
1743 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1744 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1749 void DisableDocumentLayout ()
1751 DeactivateDocumentButtons ();
1752 fl_deactivate_object (fd_form_document->group_radio_separation);
1753 fl_deactivate_object (fd_form_document->radio_indent);
1754 fl_deactivate_object (fd_form_document->radio_skip);
1755 fl_deactivate_object (fd_form_document->choice_class);
1756 fl_deactivate_object (fd_form_document->choice_pagestyle);
1757 fl_deactivate_object (fd_form_document->choice_fonts);
1758 fl_deactivate_object (fd_form_document->choice_fontsize);
1759 fl_deactivate_object (fd_form_document->input_float_placement);
1760 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1761 fl_deactivate_object (fd_form_document->choice_inputenc);
1762 fl_deactivate_object (fd_form_document->group_radio_sides);
1763 fl_deactivate_object (fd_form_document->radio_sides_one);
1764 fl_deactivate_object (fd_form_document->radio_sides_two);
1765 fl_deactivate_object (fd_form_document->group_radio_columns);
1766 fl_deactivate_object (fd_form_document->radio_columns_one);
1767 fl_deactivate_object (fd_form_document->radio_columns_two);
1768 fl_deactivate_object (fd_form_document->input_extra);
1769 fl_deactivate_object (fd_form_document->choice_language);
1770 combo_language->deactivate();
1771 fl_deactivate_object (fd_form_document->input_default_skip);
1772 fl_deactivate_object (fd_form_document->choice_default_skip);
1773 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1774 fl_deactivate_object (fd_form_document->slider_tocdepth);
1775 fl_deactivate_object (fd_form_document->choice_spacing);
1776 fl_deactivate_object (fd_form_document->input_spacing);
1777 fl_deactivate_object (fd_form_document->check_use_amsmath);
1782 void EnableDocumentLayout ()
1784 ActivateDocumentButtons ();
1785 fl_activate_object (fd_form_document->group_radio_separation);
1786 fl_activate_object (fd_form_document->radio_indent);
1787 fl_activate_object (fd_form_document->radio_skip);
1788 fl_activate_object (fd_form_document->choice_class);
1789 fl_activate_object (fd_form_document->choice_pagestyle);
1790 fl_activate_object (fd_form_document->choice_fonts);
1791 fl_activate_object (fd_form_document->choice_fontsize);
1792 fl_activate_object (fd_form_document->input_float_placement);
1793 fl_activate_object (fd_form_document->choice_postscript_driver);
1794 fl_activate_object (fd_form_document->choice_inputenc);
1795 fl_activate_object (fd_form_document->group_radio_sides);
1796 fl_activate_object (fd_form_document->radio_sides_one);
1797 fl_activate_object (fd_form_document->radio_sides_two);
1798 fl_activate_object (fd_form_document->group_radio_columns);
1799 fl_activate_object (fd_form_document->radio_columns_one);
1800 fl_activate_object (fd_form_document->radio_columns_two);
1801 fl_activate_object (fd_form_document->input_extra);
1802 fl_activate_object (fd_form_document->choice_language);
1803 combo_language->activate();
1804 fl_activate_object (fd_form_document->input_default_skip);
1805 fl_activate_object (fd_form_document->choice_default_skip);
1806 fl_activate_object (fd_form_document->slider_secnumdepth);
1807 fl_activate_object (fd_form_document->slider_tocdepth);
1808 fl_activate_object (fd_form_document->choice_spacing);
1809 fl_activate_object (fd_form_document->input_spacing);
1810 fl_activate_object (fd_form_document->check_use_amsmath);
1814 bool UpdateLayoutDocument(BufferParams * params)
1816 if (!current_view->getScreen() || !current_view->available()) {
1817 if (fd_form_document->form_document->visible)
1818 fl_hide_form(fd_form_document->form_document);
1823 params = ¤t_view->buffer()->params;
1824 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1826 fl_set_choice_text(fd_form_document->choice_class,
1827 textclasslist.DescOfClass(params->textclass).c_str());
1828 combo_language->select_text(params->language.c_str());
1830 fl_set_choice_text(fd_form_document->choice_fonts,
1831 params->fonts.c_str());
1832 fl_set_choice_text(fd_form_document->choice_inputenc,
1833 params->inputenc.c_str());
1834 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1835 params->graphicsDriver.c_str());
1837 // ale970405+lasgoutt970513
1838 fl_clear_choice(fd_form_document->choice_fontsize);
1839 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1840 fl_addto_choice(fd_form_document->choice_fontsize,
1841 tclass.opt_fontsize().c_str());
1842 fl_set_choice(fd_form_document->choice_fontsize,
1843 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1845 // ale970405+lasgoutt970513
1846 fl_clear_choice(fd_form_document->choice_pagestyle);
1847 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1848 fl_addto_choice(fd_form_document->choice_pagestyle,
1849 tclass.opt_pagestyle().c_str());
1851 fl_set_choice(fd_form_document->choice_pagestyle,
1852 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1854 fl_set_button(fd_form_document->radio_indent, 0);
1855 fl_set_button(fd_form_document->radio_skip, 0);
1858 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1860 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1861 fl_set_button(fd_form_document->radio_indent, 1);
1863 fl_set_button(fd_form_document->radio_skip, 1);
1865 switch (params->getDefSkip().kind()) {
1866 case VSpace::SMALLSKIP:
1867 fl_set_choice (fd_form_document->choice_default_skip, 1);
1869 case VSpace::MEDSKIP:
1870 fl_set_choice (fd_form_document->choice_default_skip, 2);
1872 case VSpace::BIGSKIP:
1873 fl_set_choice (fd_form_document->choice_default_skip, 3);
1875 case VSpace::LENGTH:
1876 fl_set_choice (fd_form_document->choice_default_skip, 4);
1877 fl_set_input (fd_form_document->input_default_skip,
1878 params->getDefSkip().asLyXCommand().c_str());
1881 fl_set_choice (fd_form_document->choice_default_skip, 2);
1885 fl_set_button(fd_form_document->radio_sides_one, 0);
1886 fl_set_button(fd_form_document->radio_sides_two, 0);
1888 if (params->sides == 2)
1889 fl_set_button(fd_form_document->radio_sides_two, 1);
1891 fl_set_button(fd_form_document->radio_sides_one, 1);
1893 fl_set_button(fd_form_document->radio_columns_one, 0);
1894 fl_set_button(fd_form_document->radio_columns_two, 0);
1896 if (params->columns == 2)
1897 fl_set_button(fd_form_document->radio_columns_two, 1);
1899 fl_set_button(fd_form_document->radio_columns_one, 1);
1901 fl_set_input(fd_form_document->input_spacing, "");
1902 switch (params->spacing.getSpace()) {
1903 case Spacing::Single:
1906 fl_set_choice(fd_form_document->choice_spacing, 1);
1909 case Spacing::Onehalf:
1912 fl_set_choice(fd_form_document->choice_spacing, 2);
1915 case Spacing::Double:
1918 fl_set_choice(fd_form_document->choice_spacing, 3);
1921 case Spacing::Other:
1923 fl_set_choice(fd_form_document->choice_spacing, 4);
1925 sprintf(sval, "%g", params->spacing.getValue());
1926 fl_set_input(fd_form_document->input_spacing, sval);
1932 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1933 params->secnumdepth);
1934 fl_set_counter_value(fd_form_document->slider_tocdepth,
1936 if (!params->float_placement.empty()) { // buffer local (Lgb)
1937 fl_set_input(fd_form_document->input_float_placement,
1938 params->float_placement.c_str());
1940 fl_set_input(fd_form_document->input_float_placement, "");
1942 if (!params->options.empty())
1943 fl_set_input(fd_form_document->input_extra,
1944 params->options.c_str());
1946 fl_set_input(fd_form_document->input_extra, "");
1948 if (current_view->buffer()->isSGML()) {
1949 // bullets not used in SGML derived documents
1950 fl_deactivate_object(fd_form_document->button_bullets);
1951 fl_set_object_lcol(fd_form_document->button_bullets,
1954 fl_activate_object(fd_form_document->button_bullets);
1955 fl_set_object_lcol(fd_form_document->button_bullets,
1959 if (current_view->buffer()->isReadonly()) {
1960 DisableDocumentLayout();
1962 EnableDocumentLayout();
1969 void MenuLayoutDocument()
1971 if (UpdateLayoutDocument()) {
1972 if (fd_form_document->form_document->visible) {
1973 fl_raise_form(fd_form_document->form_document);
1975 fl_show_form(fd_form_document->form_document,
1976 FL_PLACE_MOUSE, FL_FULLBORDER,
1977 _("Document Layout"));
1983 bool UpdateLayoutQuotes()
1986 if (!current_view->getScreen()
1987 || !current_view->available()
1988 || current_view->buffer()->isReadonly())
1992 fl_set_choice(fd_form_quotes->choice_quotes_language,
1993 current_view->buffer()->params.quotes_language + 1);
1994 fl_set_button(fd_form_quotes->radio_single, 0);
1995 fl_set_button(fd_form_quotes->radio_double, 0);
1997 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1998 fl_set_button(fd_form_quotes->radio_single, 1);
2000 fl_set_button(fd_form_quotes->radio_double, 1);
2001 } else if (fd_form_quotes->form_quotes->visible) {
2002 fl_hide_form(fd_form_quotes->form_quotes);
2008 void MenuLayoutQuotes()
2010 if (UpdateLayoutQuotes()) {
2011 if (fd_form_quotes->form_quotes->visible) {
2012 fl_raise_form(fd_form_quotes->form_quotes);
2014 fl_show_form(fd_form_quotes->form_quotes,
2015 FL_PLACE_MOUSE, FL_FULLBORDER,
2022 bool UpdateLayoutPreamble()
2025 if (!current_view->getScreen() || ! current_view->available())
2029 fl_set_input(fd_form_preamble->input_preamble,
2030 current_view->buffer()->params.preamble.c_str());
2032 if (current_view->buffer()->isReadonly()) {
2033 fl_deactivate_object(fd_form_preamble->input_preamble);
2034 fl_deactivate_object(fd_form_preamble->button_ok);
2035 fl_deactivate_object(fd_form_preamble->button_apply);
2036 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
2037 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2040 fl_activate_object(fd_form_preamble->input_preamble);
2041 fl_activate_object(fd_form_preamble->button_ok);
2042 fl_activate_object(fd_form_preamble->button_apply);
2043 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2044 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2046 } else if (fd_form_preamble->form_preamble->visible) {
2047 fl_hide_form(fd_form_preamble->form_preamble);
2052 void MenuLayoutPreamble()
2054 static int ow = -1, oh;
2056 if (UpdateLayoutPreamble()) {
2057 if (fd_form_preamble->form_preamble->visible) {
2058 fl_raise_form(fd_form_preamble->form_preamble);
2060 fl_show_form(fd_form_preamble->form_preamble,
2061 FL_PLACE_MOUSE | FL_FREE_SIZE,
2063 _("LaTeX Preamble"));
2065 ow = fd_form_preamble->form_preamble->w;
2066 oh = fd_form_preamble->form_preamble->h;
2068 fl_set_form_minsize(fd_form_preamble->form_preamble,
2075 void MenuLayoutSave()
2077 if (!current_view->getScreen() || ! current_view->available())
2080 if (AskQuestion(_("Do you want to save the current settings"),
2081 _("for Character, Document, Paper and Quotes"),
2082 _("as default for new documents?")))
2083 current_view->buffer()->saveParamsAsDefaults();
2087 void BufferView::insertNote()
2089 InsetInfo * new_inset = new InsetInfo();
2090 insertInset(new_inset);
2091 new_inset->Edit(0, 0);
2095 void BufferView::openStuff()
2098 owner()->getMiniBuffer()->Set(_("Open/Close..."));
2099 getScreen()->HideCursor();
2108 void BufferView::toggleFloat()
2111 owner()->getMiniBuffer()->Set(_("Open/Close..."));
2112 getScreen()->HideCursor();
2115 text->ToggleFootnote();
2121 void BufferView::menuUndo()
2124 owner()->getMiniBuffer()->Set(_("Undo"));
2125 getScreen()->HideCursor();
2128 if (!text->TextUndo())
2129 owner()->getMiniBuffer()->Set(_("No further undo information"));
2136 void BufferView::menuRedo()
2138 if (the_locking_inset) {
2139 owner()->getMiniBuffer()->Set(_("Redo not yet supported in math mode"));
2144 owner()->getMiniBuffer()->Set(_("Redo"));
2145 getScreen()->HideCursor();
2148 if (!text->TextRedo())
2149 owner()->getMiniBuffer()->Set(_("No further redo information"));
2156 void BufferView::hyphenationPoint()
2159 getScreen()->HideCursor();
2161 InsetSpecialChar * new_inset =
2162 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2163 insertInset(new_inset);
2168 void BufferView::ldots()
2171 getScreen()->HideCursor();
2173 InsetSpecialChar * new_inset =
2174 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2175 insertInset(new_inset);
2180 void BufferView::endOfSentenceDot()
2183 getScreen()->HideCursor();
2185 InsetSpecialChar * new_inset =
2186 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2187 insertInset(new_inset);
2192 void BufferView::menuSeparator()
2195 getScreen()->HideCursor();
2197 InsetSpecialChar * new_inset =
2198 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2199 insertInset(new_inset);
2204 void BufferView::newline()
2207 getScreen()->HideCursor();
2209 text->InsertChar(LyXParagraph::META_NEWLINE);
2215 void BufferView::protectedBlank()
2218 getScreen()->HideCursor();
2220 text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2226 void BufferView::hfill()
2229 getScreen()->HideCursor();
2231 text->InsertChar(LyXParagraph::META_HFILL);
2237 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2238 They also show the current font state. */
2241 void ToggleAndShow(LyXFont const &);
2244 void FontSizeCB(string const & size)
2246 LyXFont font(LyXFont::ALL_IGNORE);
2247 font.setGUISize(size);
2248 ToggleAndShow(font);
2254 LyXFont font(LyXFont::ALL_IGNORE);
2255 font.setEmph(LyXFont::TOGGLE);
2256 ToggleAndShow(font);
2262 LyXFont font(LyXFont::ALL_IGNORE);
2263 font.setNoun(LyXFont::TOGGLE);
2264 ToggleAndShow(font);
2270 LyXFont font(LyXFont::ALL_IGNORE);
2271 font.setSeries(LyXFont::BOLD_SERIES);
2272 ToggleAndShow(font);
2278 LyXFont font(LyXFont::ALL_IGNORE);
2279 font.setUnderbar(LyXFont::TOGGLE);
2280 ToggleAndShow(font);
2286 LyXFont font(LyXFont::ALL_IGNORE);
2287 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2288 ToggleAndShow(font);
2294 LyXFont font(LyXFont::ALL_IGNORE);
2295 font.setFamily(LyXFont::SANS_FAMILY);
2296 ToggleAndShow(font);
2302 LyXFont font(LyXFont::ALL_IGNORE);
2303 font.setFamily(LyXFont::ROMAN_FAMILY);
2304 ToggleAndShow(font);
2310 LyXFont font(LyXFont::ALL_IGNORE);
2311 font.setLatex (LyXFont::TOGGLE);
2312 ToggleAndShow(font);
2318 LyXFont font(LyXFont::ALL_INHERIT);
2319 ToggleAndShow(font);
2323 /* -------> Returns the current font and depth by printing a message. In the
2324 * future perhaps we could try to implement a callback to the button-bar.
2325 * That is, `light' the bold button when the font is currently bold, etc.
2327 string CurrentState()
2330 if (current_view->available()) {
2331 // I think we should only show changes from the default
2333 Buffer * buffer = current_view->buffer();
2334 LyXFont font = current_view->text->real_current_font;
2335 LyXFont defaultfont = textclasslist.TextClass(buffer->
2336 params.textclass).defaultfont();
2337 font.reduce(defaultfont);
2338 state = _("Font: ") + font.stateText();
2340 int depth = current_view->text->GetDepth();
2342 state += string(_(", Depth: ")) + tostr(depth);
2348 // candidate for move to BufferView
2349 /* -------> Does the actual toggle job of the XxxCB() calls above.
2350 * Also shows the current font state.
2353 void ToggleAndShow(LyXFont const & font)
2355 if (current_view->available()) {
2356 current_view->getScreen()->HideCursor();
2357 current_view->update(-2);
2358 current_view->text->ToggleFree(font, toggleall);
2359 current_view->update(1);
2364 // candidate for move to BufferView
2365 extern "C" void MarginCB(FL_OBJECT *, long)
2367 if (current_view->available()) {
2368 current_view->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2369 current_view->getScreen()->HideCursor();
2370 current_view->update(-2);
2371 current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2372 current_view->update(1);
2377 extern "C" void FigureCB(FL_OBJECT *, long)
2379 if (fd_form_figure->form_figure->visible) {
2380 fl_raise_form(fd_form_figure->form_figure);
2382 fl_show_form(fd_form_figure->form_figure,
2383 FL_PLACE_MOUSE, FL_FULLBORDER,
2384 _("Insert Figure"));
2389 extern "C" void TableCB(FL_OBJECT *, long)
2391 if (fd_form_table->form_table->visible) {
2392 fl_raise_form(fd_form_table->form_table);
2394 fl_show_form(fd_form_table->form_table,
2395 FL_PLACE_MOUSE, FL_FULLBORDER,
2401 void BufferView::copyEnvironment()
2404 text->copyEnvironmentType();
2405 // clear the selection, even if mark_set
2406 getScreen()->ToggleSelection();
2407 text->ClearSelection();
2409 owner()->getMiniBuffer()->Set(_("Paragraph environment type copied"));
2414 void BufferView::pasteEnvironment()
2417 text->pasteEnvironmentType();
2418 owner()->getMiniBuffer()->Set(_("Paragraph environment type set"));
2424 void BufferView::copy()
2427 text->CopySelection();
2428 // clear the selection, even if mark_set
2429 getScreen()->ToggleSelection();
2430 text->ClearSelection();
2432 owner()->getMiniBuffer()->Set(_("Copy"));
2437 void BufferView::cut()
2440 getScreen()->HideCursor();
2442 text->CutSelection();
2444 owner()->getMiniBuffer()->Set(_("Cut"));
2449 void BufferView::paste()
2451 if (!available()) return;
2453 owner()->getMiniBuffer()->Set(_("Paste"));
2454 getScreen()->HideCursor();
2455 // clear the selection
2456 getScreen()->ToggleSelection();
2457 text->ClearSelection();
2461 text->PasteSelection();
2464 // clear the selection
2465 getScreen()->ToggleSelection();
2466 text->ClearSelection();
2471 // candidate for move to BufferView
2472 extern "C" void MeltCB(FL_OBJECT *, long)
2474 if (!current_view->available()) return;
2476 current_view->owner()->getMiniBuffer()->Set(_("Melt"));
2477 current_view->getScreen()->HideCursor();
2478 current_view->beforeChange();
2479 current_view->update(-2);
2480 current_view->text->MeltFootnoteEnvironment();
2481 current_view->update(1);
2485 // candidate for move to BufferView
2486 // Change environment depth.
2487 // if decInc == 0, depth change taking mouse button number into account
2488 // if decInc == 1, increment depth
2489 // if decInc == -1, decrement depth
2490 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2494 /* When decInc != 0, fake a mouse button. This allows us to
2495 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2496 /* check out wether ob is defined, too (Matthias) */
2499 else if (!decInc && ob) {
2500 button = fl_get_button_numb(ob);
2503 if (current_view->available()) {
2504 current_view->getScreen()->HideCursor();
2505 current_view->update(-2);
2507 current_view->text->IncDepth();
2509 current_view->text->DecDepth();
2510 current_view->update(1);
2511 current_view->owner()->getMiniBuffer()->Set(_("Changed environment depth"
2512 " (in possible range, maybe not)"));
2517 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2518 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2519 LyXFont UserFreeFont()
2521 LyXFont font(LyXFont::ALL_IGNORE);
2523 int pos = fl_get_choice(fd_form_character->choice_family);
2525 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2526 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2527 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2528 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2529 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2532 pos = fl_get_choice(fd_form_character->choice_series);
2534 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2535 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2536 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2537 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2540 pos = fl_get_choice(fd_form_character->choice_shape);
2542 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2543 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2544 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2545 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2546 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2547 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2550 pos = fl_get_choice(fd_form_character->choice_size);
2552 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2553 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2554 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2555 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2556 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2557 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2558 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2559 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2560 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2561 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2562 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2563 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2564 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2565 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2568 pos = fl_get_choice(fd_form_character->choice_bar);
2570 case 1: font.setEmph(LyXFont::IGNORE);
2571 font.setUnderbar(LyXFont::IGNORE);
2572 font.setNoun(LyXFont::IGNORE);
2573 font.setLatex(LyXFont::IGNORE);
2575 case 2: font.setEmph(LyXFont::TOGGLE); break;
2576 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2577 case 4: font.setNoun(LyXFont::TOGGLE); break;
2578 case 5: font.setLatex(LyXFont::TOGGLE); break;
2579 case 6: font.setEmph(LyXFont::INHERIT);
2580 font.setUnderbar(LyXFont::INHERIT);
2581 font.setNoun(LyXFont::INHERIT);
2582 font.setLatex(LyXFont::INHERIT);
2586 pos = fl_get_choice(fd_form_character->choice_color);
2588 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2589 case 2: font.setColor(LyXFont::NONE); break;
2590 case 3: font.setColor(LyXFont::BLACK); break;
2591 case 4: font.setColor(LyXFont::WHITE); break;
2592 case 5: font.setColor(LyXFont::RED); break;
2593 case 6: font.setColor(LyXFont::GREEN); break;
2594 case 7: font.setColor(LyXFont::BLUE); break;
2595 case 8: font.setColor(LyXFont::CYAN); break;
2596 case 9: font.setColor(LyXFont::MAGENTA); break;
2597 case 10: font.setColor(LyXFont::YELLOW); break;
2598 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2607 ToggleAndShow(UserFreeFont());
2611 /* callbacks for form form_title */
2612 extern "C" void TimerCB(FL_OBJECT *, long)
2614 // only if the form still exists
2615 if (fd_form_title->form_title != 0) {
2616 if (fd_form_title->form_title->visible) {
2617 fl_hide_form(fd_form_title->form_title);
2619 fl_free_form(fd_form_title->form_title);
2620 fd_form_title->form_title = 0;
2625 /* callbacks for form form_paragraph */
2627 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2629 // "Synchronize" the choices and input fields, making it
2630 // impossible to commit senseless data.
2632 FD_form_paragraph const * fp = fd_form_paragraph;
2634 if (obj == fp->choice_space_above) {
2635 if (fl_get_choice (fp->choice_space_above) != 7) {
2636 fl_set_input (fp->input_space_above, "");
2637 ActivateParagraphButtons();
2639 } else if (obj == fp->choice_space_below) {
2640 if (fl_get_choice (fp->choice_space_below) != 7) {
2641 fl_set_input (fp->input_space_below, "");
2642 ActivateParagraphButtons();
2644 } else if (obj == fp->input_space_above) {
2645 string input = fl_get_input (fp->input_space_above);
2647 if (input.empty()) {
2648 fl_set_choice (fp->choice_space_above, 1);
2649 ActivateParagraphButtons();
2651 else if (isValidGlueLength (input)) {
2652 fl_set_choice (fp->choice_space_above, 7);
2653 ActivateParagraphButtons();
2656 fl_set_choice (fp->choice_space_above, 7);
2657 DeactivateParagraphButtons();
2659 } else if (obj == fp->input_space_below) {
2660 string input = fl_get_input (fp->input_space_below);
2662 if (input.empty()) {
2663 fl_set_choice (fp->choice_space_below, 1);
2664 ActivateParagraphButtons();
2666 else if (isValidGlueLength (input)) {
2667 fl_set_choice (fp->choice_space_below, 7);
2668 ActivateParagraphButtons();
2671 fl_set_choice (fp->choice_space_below, 7);
2672 DeactivateParagraphButtons();
2678 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2680 if (!current_view->available())
2683 VSpace space_top, space_bottom;
2685 string labelwidthstring;
2688 // If a vspace kind is "Length" but there's no text in
2689 // the input field, reset the kind to "None".
2690 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2691 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2692 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2694 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2695 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2696 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2699 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2700 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2701 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2702 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2703 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2704 case 1: space_top = VSpace(VSpace::NONE); break;
2705 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2706 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2707 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2708 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2709 case 6: space_top = VSpace(VSpace::VFILL); break;
2710 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2712 if (fl_get_button (fd_form_paragraph->check_space_above))
2713 space_top.setKeep (true);
2714 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2715 case 1: space_bottom = VSpace(VSpace::NONE); break;
2716 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2717 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2718 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2719 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2720 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2721 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2723 if (fl_get_button (fd_form_paragraph->check_space_below))
2724 space_bottom.setKeep (true);
2726 if (fl_get_button(fd_form_paragraph->radio_align_left))
2727 align = LYX_ALIGN_LEFT;
2728 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2729 align = LYX_ALIGN_RIGHT;
2730 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2731 align = LYX_ALIGN_CENTER;
2733 align = LYX_ALIGN_BLOCK;
2735 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2736 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2738 current_view->text->SetParagraph(line_top,
2747 current_view->update(1);
2748 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2752 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2754 fl_hide_form(fd_form_paragraph->form_paragraph);
2758 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2760 ParagraphApplyCB(ob, data);
2761 ParagraphCancelCB(ob, data);
2765 /* callbacks for form form_character */
2767 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2769 // we set toggleall locally here, since it should be true for
2770 // all other uses of ToggleAndShow() (JMarc)
2771 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2772 ToggleAndShow( UserFreeFont());
2777 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2779 fl_hide_form(fd_form_character->form_character);
2783 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2785 CharacterApplyCB(ob, data);
2786 CharacterCloseCB(ob, data);
2790 /* callbacks for form form_document */
2792 void UpdateDocumentButtons(BufferParams const & params)
2794 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2796 if (params.sides == 2)
2797 fl_set_button(fd_form_document->radio_sides_two, 1);
2799 fl_set_button(fd_form_document->radio_sides_one, 1);
2801 if (params.columns == 2)
2802 fl_set_button(fd_form_document->radio_columns_two, 1);
2804 fl_set_button(fd_form_document->radio_columns_one, 1);
2806 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2807 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2808 params.secnumdepth);
2809 fl_set_counter_value(fd_form_document->slider_tocdepth,
2814 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2817 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2818 if (AskQuestion(_("Should I set some parameters to"),
2819 fl_get_choice_text(ob),
2820 _("the defaults of this document class?"))) {
2821 BufferParams params = BufferParams();
2822 params.textclass = fl_get_choice(ob)-1;
2823 params.useClassDefaults();
2824 UpdateLayoutDocument(¶ms);
2825 UpdateDocumentButtons(params);
2828 // unable to load new style
2829 WriteAlert(_("Conversion Errors!"),
2830 _("Unable to switch to new document class."),
2831 _("Reverting to original document class."));
2832 fl_set_choice(fd_form_document->choice_class,
2833 current_view->buffer()->params.textclass + 1);
2839 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2841 // "Synchronize" the choice and the input field, so that it
2842 // is impossible to commit senseless data.
2843 FD_form_document const * fd = fd_form_document;
2845 if (obj == fd->choice_default_skip) {
2846 if (fl_get_choice (fd->choice_default_skip) != 4) {
2847 fl_set_input (fd->input_default_skip, "");
2848 ActivateDocumentButtons();
2850 } else if (obj == fd->input_default_skip) {
2852 char const * input = fl_get_input (fd->input_default_skip);
2855 fl_set_choice (fd->choice_default_skip, 2);
2856 ActivateDocumentButtons();
2857 } else if (isValidGlueLength (input)) {
2858 fl_set_choice (fd->choice_default_skip, 4);
2859 ActivateDocumentButtons();
2861 fl_set_choice (fd->choice_default_skip, 4);
2862 DeactivateDocumentButtons();
2868 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2870 // "Synchronize" the choice and the input field, so that it
2871 // is impossible to commit senseless data.
2872 FD_form_document const * fd = fd_form_document;
2874 if (obj == fd->choice_spacing
2875 && fl_get_choice (fd->choice_spacing) != 4) {
2876 fl_set_input(fd->input_spacing, "");
2877 } else if (obj == fd->input_spacing) {
2879 const char* input = fl_get_input (fd->input_spacing);
2882 fl_set_choice (fd->choice_spacing, 1);
2884 fl_set_choice (fd->choice_spacing, 4);
2890 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2893 BufferParams *params = &(current_view->buffer()->params);
2894 current_view->buffer()->params.language =
2895 combo_language->getline();
2897 // If default skip is a "Length" but there's no text in the
2898 // input field, reset the kind to "Medskip", which is the default.
2899 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2900 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2901 fl_set_choice (fd_form_document->choice_default_skip, 2);
2904 /* this shouldn't be done automatically IMO. For example I write german
2905 * documents with an american keyboard very often. Matthias */
2907 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2908 fl_get_choice(fd_form_document->choice_language)); */
2910 fl_get_choice_text(fd_form_document->choice_fonts);
2912 fl_get_choice_text(fd_form_document->choice_inputenc);
2914 fl_get_choice_text(fd_form_document->choice_fontsize);
2916 fl_get_choice_text(fd_form_document->choice_pagestyle);
2917 params->graphicsDriver =
2918 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2919 params->use_amsmath =
2920 fl_get_button(fd_form_document->check_use_amsmath);
2922 if (!current_view->available())
2925 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2926 if (params->textclass != new_class) {
2927 // try to load new_class
2928 if (textclasslist.Load(new_class)) {
2929 // successfully loaded
2931 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2932 int ret = current_view->text->
2933 SwitchLayoutsBetweenClasses(current_view->buffer()->
2936 current_view->buffer()->
2942 s = _("One paragraph couldn't be converted");
2945 s += _(" paragraphs couldn't be converted");
2947 WriteAlert(_("Conversion Errors!"), s,
2948 _("into chosen document class"));
2951 params->textclass = new_class;
2953 // problem changing class -- warn user and retain old style
2954 WriteAlert(_("Conversion Errors!"),
2955 _("Unable to switch to new document class."),
2956 _("Reverting to original document class."));
2957 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2961 char tmpsep = params->paragraph_separation;
2962 if (fl_get_button(fd_form_document->radio_indent))
2963 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2965 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2966 if (tmpsep != params->paragraph_separation)
2969 VSpace tmpdefskip = params->getDefSkip();
2970 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2971 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2972 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2973 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2974 case 4: params->setDefSkip(
2975 VSpace (LyXGlueLength (fl_get_input
2976 (fd_form_document->input_default_skip))));
2978 // DocumentDefskipCB assures that this never happens
2979 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2981 if (!(tmpdefskip == params->getDefSkip()))
2984 if (fl_get_button(fd_form_document->radio_columns_two))
2985 params->columns = 2;
2987 params->columns = 1;
2988 if (fl_get_button(fd_form_document->radio_sides_two))
2989 params->sides = LyXTextClass::TwoSides;
2991 params->sides = LyXTextClass::OneSide;
2993 Spacing tmpSpacing = params->spacing;
2994 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2996 lyxerr.debug() << "Spacing: SINGLE" << endl;
2997 params->spacing.set(Spacing::Single);
3000 lyxerr.debug() << "Spacing: ONEHALF" << endl;
3001 params->spacing.set(Spacing::Onehalf);
3004 lyxerr.debug() << "Spacing: DOUBLE" << endl;
3005 params->spacing.set(Spacing::Double);
3008 lyxerr.debug() << "Spacing: OTHER" << endl;
3009 params->spacing.set(Spacing::Other,
3010 fl_get_input(fd_form_document->input_spacing));
3013 if (tmpSpacing != params->spacing)
3016 signed char tmpchar =
3017 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
3018 if (params->secnumdepth != tmpchar)
3020 params->secnumdepth = tmpchar;
3023 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
3025 params->float_placement =
3026 fl_get_input(fd_form_document->input_float_placement);
3028 // More checking should be done to ensure the string doesn't have
3029 // spaces or illegal placement characters in it. (thornley)
3032 current_view->redoCurrentBuffer();
3034 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
3035 current_view->buffer()->markDirty();
3038 fl_get_input(fd_form_document->input_extra);
3043 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3045 fl_hide_form(fd_form_document->form_document);
3049 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3051 DocumentCancelCB(ob, data);
3052 DocumentApplyCB(ob, data);
3056 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3059 // bullet callbacks etc. in bullet_panel.C -- ARRae
3063 void BufferView::gotoNote()
3065 if (!getScreen()) return;
3067 getScreen()->HideCursor();
3072 if (!text->GotoNextNote()) {
3073 if (text->cursor.pos
3074 || text->cursor.par != text->FirstParagraph()) {
3076 text->cursor.par = text->FirstParagraph();
3077 text->cursor.pos = 0;
3078 if (!text->GotoNextNote()) {
3080 owner()->getMiniBuffer()->Set(_("No more notes"));
3084 owner()->getMiniBuffer()->Set(_("No more notes"));
3089 text->sel_cursor = text->cursor;
3093 void BufferView::insertCorrectQuote()
3097 if (text->cursor.pos)
3098 c = text->cursor.par->GetChar(text->cursor.pos - 1);
3102 insertInset(new InsetQuotes(c, buffer()->params));
3106 /* callbacks for form form_quotes */
3108 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3110 if (!current_view->available())
3113 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
3114 //current_view->buffer()->params.quotes_language =
3115 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3116 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3117 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3119 lga = InsetQuotes::EnglishQ;
3122 lga = InsetQuotes::SwedishQ;
3125 lga = InsetQuotes::GermanQ;
3128 lga = InsetQuotes::PolishQ;
3131 lga = InsetQuotes::FrenchQ;
3134 lga = InsetQuotes::DanishQ;
3137 current_view->buffer()->params.quotes_language = lga;
3138 if (fl_get_button(fd_form_quotes->radio_single))
3139 current_view->buffer()->
3140 params.quotes_times = InsetQuotes::SingleQ;
3142 current_view->buffer()->
3143 params.quotes_times = InsetQuotes::DoubleQ;
3147 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3149 fl_hide_form(fd_form_quotes->form_quotes);
3153 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3155 QuotesApplyCB(ob, data);
3156 QuotesCancelCB(ob, data);
3161 /* callbacks for form form_preamble */
3163 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3165 fl_hide_form(fd_form_preamble->form_preamble);
3169 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3171 if (!current_view->available())
3174 current_view->buffer()->params.preamble =
3175 fl_get_input(fd_form_preamble->input_preamble);
3176 current_view->buffer()->markDirty();
3177 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
3181 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3183 PreambleApplyCB(ob, data);
3184 PreambleCancelCB(ob, data);
3188 /* callbacks for form form_table */
3190 extern "C" void TableApplyCB(FL_OBJECT *, long)
3192 if (!current_view->getScreen())
3195 // check for tables in tables
3196 if (current_view->text->cursor.par->table){
3197 WriteAlert(_("Impossible Operation!"),
3198 _("Cannot insert table in table."),
3203 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
3205 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3206 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3209 current_view->getScreen()->HideCursor();
3210 current_view->beforeChange();
3211 current_view->update(-2);
3213 current_view->text->SetCursorParUndo();
3214 current_view->text->FreezeUndo();
3216 current_view->text->BreakParagraph();
3217 current_view->update(-1);
3219 if (current_view->text->cursor.par->Last()) {
3220 current_view->text->CursorLeft();
3222 current_view->text->BreakParagraph();
3223 current_view->update(-1);
3226 current_view->text->current_font.setLatex(LyXFont::OFF);
3227 //if (!fl_get_button(fd_form_table->check_latex)){
3228 // insert the new wysiwy table
3229 current_view->text->SetLayout(0); // standard layout
3230 if (current_view->text->cursor.par->footnoteflag ==
3231 LyXParagraph::NO_FOOTNOTE) {
3233 ->SetParagraph(0, 0,
3235 VSpace (0.3 * current_view->buffer()->
3236 params.spacing.getValue(),
3238 VSpace (0.3 * current_view->buffer()->
3239 params.spacing.getValue(),
3247 ->SetParagraph(0, 0,
3249 VSpace(VSpace::NONE),
3250 VSpace(VSpace::NONE),
3255 current_view->text->cursor.par->table =
3256 new LyXTable(xsize, ysize);
3258 for (int i = 0; i < xsize * ysize - 1; ++i)
3259 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3260 current_view->text->RedoParagraph();
3262 current_view->text->UnFreezeUndo();
3264 current_view->update(1);
3265 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
3269 extern "C" void TableCancelCB(FL_OBJECT *, long)
3271 fl_hide_form(fd_form_table->form_table);
3275 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3277 TableApplyCB(ob, data);
3278 TableCancelCB(ob, data);
3282 /* callbacks for form form_print */
3284 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3286 fl_hide_form(fd_form_print->form_print);
3289 static bool stringOnlyContains (string const & LStr, char const * cset)
3291 char const * cstr = LStr.c_str() ;
3293 return strspn(cstr, cset) == strlen(cstr) ;
3296 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3298 if (!current_view->available())
3300 Buffer * buffer = current_view->buffer();
3301 string path = OnlyPath(buffer->fileName());
3304 if (fl_get_button(fd_form_print->radio_even_pages))
3305 pageflag = lyxrc->print_evenpage_flag + ' ';
3306 else if (fl_get_button(fd_form_print->radio_odd_pages))
3307 pageflag = lyxrc->print_oddpage_flag + ' ';
3309 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3310 // User may give a page (range) list
3311 // User may print multiple (unsorted) copies
3312 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3313 pages = subst(pages, '+',',');
3314 pages = frontStrip(strip(pages)) ;
3315 while (!pages.empty()) { // a page range was given
3317 pages = split (pages, piece, ',') ;
3318 piece = strip(piece) ;
3319 piece = frontStrip(piece) ;
3320 if ( !stringOnlyContains (piece, "0123456789-") ) {
3321 WriteAlert(_("ERROR! Unable to print!"),
3322 _("Check 'range of pages'!"));
3325 if (piece.find('-') == string::npos) { // not found
3326 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3327 } else if (suffixIs(piece, "-") ) { // missing last page
3328 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3329 } else if (prefixIs(piece, "-") ) { // missing first page
3330 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3332 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3336 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3337 if (!copies.empty()) { // a number of copies was given
3338 if ( !stringOnlyContains (copies, "0123456789") ) {
3339 WriteAlert(_("ERROR! Unable to print!"),
3340 _("Check 'number of copies'!"));
3343 if (fl_get_button(fd_form_print->do_unsorted))
3344 pageflag += lyxrc->print_copies_flag;
3346 pageflag += lyxrc->print_collcopies_flag;
3347 pageflag += " " + copies + ' ' ;
3351 if (fl_get_button(fd_form_print->radio_order_reverse))
3352 reverseflag = lyxrc->print_reverse_flag + ' ';
3354 string orientationflag;
3355 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3356 orientationflag = lyxrc->print_landscape_flag + ' ';
3358 string ps_file = fl_get_input(fd_form_print->input_file);
3359 string printer = strip(fl_get_input(fd_form_print->input_printer));
3362 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3363 && ! printer.empty()) // a printer name has been given
3364 printerflag = lyxrc->print_to_printer + printer + ' ';
3367 if (!lyxrc->print_extra_options.empty())
3368 extraflags = lyxrc->print_extra_options + ' ';
3370 string command = lyxrc->print_command + ' '
3371 + printerflag + pageflag + reverseflag
3372 + orientationflag + extraflags;
3374 char real_papersize = buffer->params.papersize;
3375 if (real_papersize == BufferParams::PAPER_DEFAULT)
3376 real_papersize = lyxrc->default_papersize;
3379 switch (real_papersize) {
3380 case BufferParams::PAPER_USLETTER:
3383 case BufferParams::PAPER_A3PAPER:
3386 case BufferParams::PAPER_A4PAPER:
3389 case BufferParams::PAPER_A5PAPER:
3392 case BufferParams::PAPER_B5PAPER:
3395 case BufferParams::PAPER_EXECUTIVEPAPER:
3398 case BufferParams::PAPER_LEGALPAPER:
3401 default: /* If nothing else fits, keep an empty value... */
3405 if (buffer->params.use_geometry
3406 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3407 && !lyxrc->print_paper_dimension_flag.empty()
3408 && !buffer->params.paperwidth.empty()
3409 && !buffer->params.paperheight.empty()) {
3410 // using a custom papersize
3412 command += lyxrc->print_paper_dimension_flag + ' ';
3413 command += buffer->params.paperwidth + ',';
3414 command += buffer->params.paperheight + ' ';
3415 } else if (!lyxrc->print_paper_flag.empty()
3417 && (real_papersize != BufferParams::PAPER_USLETTER ||
3418 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3419 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3421 if (fl_get_button(fd_form_print->radio_file))
3422 command += lyxrc->print_to_file
3423 + QuoteName(MakeAbsPath(ps_file, path));
3424 else if (!lyxrc->print_spool_command.empty())
3425 command += lyxrc->print_to_file
3426 + QuoteName(ps_file);
3428 // push directorypath, if necessary
3429 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3430 path = buffer->tmppath;
3435 if (!lyxrc->print_spool_command.empty() &&
3436 !fl_get_button(fd_form_print->radio_file)) {
3437 string command2 = lyxrc->print_spool_command + ' ';
3438 if (!printer.empty())
3439 command2 += lyxrc->print_spool_printerprefix
3441 // First run dvips and, if succesful, then spool command
3442 if ((result = RunScript(buffer, true, command))) {
3443 result = RunScript(buffer, false, command2, ps_file);
3446 result = RunScript(buffer, false, command);
3449 WriteAlert(_("Error:"),
3450 _("Unable to print"),
3451 _("Check that your parameters are correct"));
3455 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3457 PrintCancelCB(ob, data);
3458 PrintApplyCB(ob, data);
3462 /* callbacks for form form_figure */
3463 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3465 if (!current_view->available())
3468 Buffer * buffer = current_view->buffer();
3469 if(buffer->isReadonly()) // paranoia
3472 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3473 if (fl_get_button(fd_form_figure->radio_inline)
3474 || current_view->text->cursor.par->table) {
3475 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3476 current_view->insertInset(new_inset);
3477 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3478 new_inset->Edit(0, 0);
3482 current_view->getScreen()->HideCursor();
3483 current_view->update(-2);
3484 current_view->beforeChange();
3486 current_view->text->SetCursorParUndo();
3487 current_view->text->FreezeUndo();
3489 current_view->text->BreakParagraph();
3490 current_view->update(-1);
3492 if (current_view->text->cursor.par->Last()) {
3493 current_view->text->CursorLeft();
3495 current_view->text->BreakParagraph();
3496 current_view->update(-1);
3499 // The standard layout should always be numer 0;
3500 current_view->text->SetLayout(0);
3502 if (current_view->text->cursor.par->footnoteflag ==
3503 LyXParagraph::NO_FOOTNOTE) {
3504 current_view->text->
3507 VSpace (0.3 * buffer->params.spacing.getValue(),
3510 buffer->params.spacing.getValue(),
3512 LYX_ALIGN_CENTER, string(), 0);
3514 current_view->text->SetParagraph(0, 0,
3516 VSpace(VSpace::NONE),
3517 VSpace(VSpace::NONE),
3522 current_view->update(-1);
3524 Inset * new_inset = new InsetFig(100, 100, buffer);
3525 current_view->insertInset(new_inset);
3526 new_inset->Edit(0, 0);
3527 current_view->update(0);
3528 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3529 current_view->text->UnFreezeUndo();
3533 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3535 fl_hide_form(fd_form_figure->form_figure);
3539 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3541 FigureApplyCB(ob, data);
3542 FigureCancelCB(ob, data);
3546 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3548 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3549 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3550 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3551 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3552 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3553 fontloader.update();
3555 // All buffers will need resize
3556 bufferlist.resize();
3558 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3562 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3564 fl_hide_form(fd_form_screen->form_screen);
3568 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3570 ScreenCancelCB(ob, data);
3571 ScreenApplyCB(ob, data);
3577 if (!current_view->available())
3580 fl_set_button(fd_latex_options->accents,
3581 int(current_view->buffer()->params.allowAccents));
3583 if (fd_latex_options->LaTeXOptions->visible) {
3584 fl_raise_form(fd_latex_options->LaTeXOptions);
3586 fl_show_form(fd_latex_options->LaTeXOptions,
3587 FL_PLACE_MOUSE, FL_FULLBORDER,
3588 _("LaTeX Options"));
3593 // This function runs "configure" and then rereads lyx.defaults to
3594 // reconfigure the automatic settings.
3597 current_view->owner()->getMiniBuffer()->Set(_("Running configure..."));
3599 // Run configure in user lyx directory
3600 Path p(user_lyxdir);
3601 Systemcalls one(Systemcalls::System,
3602 AddName(system_lyxdir, "configure"));
3604 current_view->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3605 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
3606 WriteAlert(_("The system has been reconfigured."),
3607 _("You need to restart LyX to make use of any"),
3608 _("updated document class specifications."));
3612 /* these functions are for the spellchecker */
3613 char * BufferView::nextWord(float & value)
3620 char * string = text->SelectNextWord(value);
3626 void BufferView::selectLastWord()
3628 if (!available()) return;
3630 getScreen()->HideCursor();
3632 text->SelectSelectedWord();
3633 getScreen()->ToggleSelection(false);
3638 void BufferView::endOfSpellCheck()
3640 if (!available()) return;
3642 getScreen()->HideCursor();
3644 text->SelectSelectedWord();
3645 text->ClearSelection();
3650 void BufferView::replaceWord(string const & replacestring)
3652 if (!getScreen()) return;
3654 getScreen()->HideCursor();
3657 /* clear the selection (if there is any) */
3658 getScreen()->ToggleSelection(false);
3661 /* clear the selection (if there is any) */
3662 getScreen()->ToggleSelection(false);
3663 text->ReplaceSelectionWithString(replacestring.c_str());
3665 text->SetSelectionOverString(replacestring.c_str());
3667 // Go back so that replacement string is also spellchecked
3668 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3669 text->CursorLeftIntern();
3673 // End of spellchecker stuff
3678 // Table of Contents
3688 static TocList * toclist = 0;
3691 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3693 if (!current_view->available())
3696 TocList * tmptoclist = toclist;
3697 int i = fl_get_browser(ob);
3698 for (int a = 1; a < i && tmptoclist->next; ++a) {
3699 tmptoclist = tmptoclist->next;
3706 LyXParagraph * par = current_view->buffer()->paragraph;
3707 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3708 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3709 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3710 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3711 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3712 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3713 par->appendix != tmptoclist->appendix)) {
3714 par = par->LastPhysicalPar()->Next();
3718 current_view->beforeChange();
3719 current_view->text->SetCursor(par, 0);
3720 current_view->text->sel_cursor =
3721 current_view->text->cursor;
3722 current_view->update(0);
3725 WriteAlert(_("Error"),
3726 _("Couldn't find this label"),
3727 _("in current document."));
3733 extern "C" void TocCancelCB(FL_OBJECT *, long)
3735 fl_hide_form(fd_form_toc->form_toc);
3739 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3741 static LyXParagraph * stapar = 0;
3742 TocList * tmptoclist = 0;
3744 /* deleted the toclist */
3747 tmptoclist = toclist->next;
3749 toclist = tmptoclist;
3753 tmptoclist = toclist;
3756 fl_clear_browser(fd_form_toc->browser_toc);
3757 if (!current_view->available()) {
3758 fl_add_browser_line(fd_form_toc->browser_toc,
3759 _("*** No Document ***"));
3762 fl_hide_object(fd_form_toc->browser_toc);
3763 /* get the table of contents */
3764 LyXParagraph * par = current_view->buffer()->paragraph;
3766 char * line = new char[200];
3772 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3776 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3777 par->GetLayout()).labeltype;
3779 if (labeltype >= LABEL_COUNTER_CHAPTER
3780 && labeltype <= LABEL_COUNTER_CHAPTER +
3781 current_view->buffer()->params.tocdepth) {
3782 /* insert this into the table of contents */
3783 /* first indent a little bit */
3787 textclasslist.TextClass(current_view->buffer()->
3788 params.textclass).maxcounter()) * 4 + 2;
3792 // Then the labestring
3793 if (!par->labelstring.empty()) {
3794 string::size_type i = 0;
3795 while (pos < 199 && i < par->labelstring.length()) {
3796 line[pos] = par->labelstring[i];
3805 /* now the contents */
3806 LyXParagraph::size_type i = 0;
3807 while (pos < 199 && i < par->size()) {
3808 c = par->GetChar(i);
3809 if (isprint(c) || c >= 128) {
3816 fl_add_browser_line(fd_form_toc->browser_toc, line);
3818 /* make a toclist entry */
3820 tmptoclist = new TocList;
3821 toclist = tmptoclist;
3823 tmptoclist->next = new TocList;
3824 tmptoclist = tmptoclist->next;
3827 tmptoclist->next = 0;
3829 for (a = 0; a < 6; ++a) {
3830 tmptoclist->counter[a] = par->GetFirstCounter(a);
3832 tmptoclist->appendix = par->appendix;
3834 par = par->LastPhysicalPar()->Next();
3838 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3839 fl_show_object(fd_form_toc->browser_toc);
3843 /* callbacks for form form_ref */
3844 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3846 if (!current_view->available())
3850 fl_get_browser_line(fd_form_ref->browser_ref,
3851 fl_get_browser(fd_form_ref->browser_ref));
3852 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3858 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3868 if(current_view->buffer()->isSGML())
3869 t += "[" + u + "]" + "{" + s + "}";
3874 new InsetRef(t, current_view->buffer());
3875 current_view->insertInset(new_inset);
3879 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3881 if (!current_view->available()) {
3882 fl_clear_browser(fd_form_ref->browser_ref);
3886 FL_OBJECT * brow = fd_form_ref->browser_ref;
3888 // Get the current line, in order to restore it later
3889 char const * const btmp = fl_get_browser_line(brow,
3890 fl_get_browser(brow));
3891 string currentstr = btmp ? btmp : "";
3893 fl_clear_browser(brow);
3895 string refs = current_view->buffer()->getReferenceList('\n');
3898 #if FL_REVISION > 85
3899 fl_addto_browser_chars(brow, refs.c_str());
3900 int total_lines = fl_get_browser_maxline(brow);
3901 for (int i = 1; i <= total_lines ; i++) {
3902 if (fl_get_browser_line(brow, i) == currentstr) {
3907 fl_set_browser_topline(brow, topline);
3909 // Keep the old ugly code for xforms 0.81 compatibility
3914 curr_ref = refs.token('\n', ref_num);
3915 if (curr_ref.empty())
3917 fl_add_browser_line(brow, curr_ref.c_str());
3922 if (!fl_get_browser_maxline(brow)) {
3923 fl_add_browser_line(brow,
3924 _("*** No labels found in document ***"));
3925 fl_deactivate_object(brow);
3927 fl_select_browser_line(brow, topline);
3928 fl_activate_object(brow);
3930 if (current_view->buffer()->isReadonly()) {
3931 // would be better to de/activate insert buttons
3932 // but that's more work... besides this works. ARRae
3933 fl_hide_form(fd_form_ref->form_ref);
3935 if (!current_view->buffer()->isSGML()) {
3936 fl_deactivate_object(fd_form_ref->ref_name);
3937 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3940 fl_activate_object(fd_form_ref->ref_name);
3941 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3946 extern "C" void RefHideCB(FL_OBJECT *, long)
3948 fl_hide_form(fd_form_ref->form_ref);
3952 // candidate for move to BufferView
3953 void UpdateInset(Inset * inset, bool mark_dirty)
3958 /* very first check for locking insets*/
3959 if (current_view->the_locking_inset == inset) {
3960 if (current_view->text->UpdateInset(inset)){
3961 current_view->update();
3963 if (current_view->buffer()->isLyxClean())
3964 current_view->owner()->getMiniBuffer()->setTimer(4);
3965 current_view->buffer()->markDirty();
3967 current_view->updateScrollbar();
3972 /* first check the current buffer */
3973 if (current_view->available()){
3974 current_view->getScreen()->HideCursor();
3975 current_view->update(-3);
3976 if (current_view->text->UpdateInset(inset)){
3978 current_view->update(1);
3980 current_view->update(3);
3985 // check all buffers
3986 bufferlist.updateInset(inset, mark_dirty);
3991 /* these functions return 1 if an error occured,
3993 int BufferView::lockInset(UpdatableInset * inset)
3995 if (!the_locking_inset && inset){
3996 the_locking_inset = inset;
4003 void BufferView::showLockedInsetCursor(long x, long y, int asc, int desc)
4005 if (the_locking_inset && getScreen()) {
4006 y += text->cursor.y;
4007 getScreen()->ShowManualCursor(x, y,
4013 void BufferView::hideLockedInsetCursor(long x, long y, int asc, int desc)
4015 if (the_locking_inset && getScreen()) {
4016 y += text->cursor.y;
4017 getScreen()->HideManualCursor(x, y,
4023 void BufferView::fitLockedInsetCursor(long x, long y, int asc, int desc)
4025 if (the_locking_inset && getScreen()){
4026 y += text->cursor.y;
4027 if (getScreen()->FitManualCursor(x, y, asc, desc))
4033 int BufferView::unlockInset(UpdatableInset * inset)
4035 if (inset && the_locking_inset == inset) {
4036 inset->InsetUnlock();
4037 the_locking_inset = 0;
4041 return bufferlist.unlockInset(inset);
4045 void BufferView::lockedInsetStoreUndo(Undo::undo_kind kind)
4047 if (!the_locking_inset)
4048 return; // shouldn't happen
4049 if (kind == Undo::EDIT) // in this case insets would not be stored!
4050 kind = Undo::FINISH;
4053 ParFromPos(text->cursor.pos)->previous,
4055 ParFromPos(text->cursor.pos)->next);
4059 void PutInsetIntoInsetUpdateList(Inset * inset)
4062 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4064 tmp->next = InsetUpdateList;
4065 InsetUpdateList = tmp;
4069 void UpdateInsetUpdateList()
4071 InsetUpdateStruct * tmp = InsetUpdateList;
4073 UpdateInset(tmp->inset, false); // "false" because no document change
4077 // delete the update list
4078 while (InsetUpdateList) {
4079 tmp = InsetUpdateList;
4080 InsetUpdateList = InsetUpdateList->next;
4083 InsetUpdateList = 0;
4087 #ifdef WITH_WARNINGS
4090 // I know we shouldn't put anything in here but this seems the fastest
4091 // way to do this (and the cleanest for now). This function just inserts
4092 // a newline in the string and the inserts 'depth'-spaces so that the
4093 // code is indented in the right way!!!
4094 void addNewlineAndDepth(string & file, int const depth)
4097 file.append(depth, ' ');