1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-1999 The LyX Team.
9 * ====================================================== */
20 #include "support/lstrings.h"
22 #include FORMS_H_LOCATION
24 #include "layout_forms.h"
25 #include "bullet_forms.h"
26 #include "print_form.h"
28 #include "spellchecker.h"
32 #include "insets/insetref.h"
33 #include "insets/insetquotes.h"
35 #include "insets/insetlatex.h"
37 #include "insets/insetlabel.h"
38 #include "insets/insetinfo.h"
39 #include "insets/insetspecialchar.h"
40 #include "insets/figinset.h"
42 #include "latexoptions.h"
44 #include "minibuffer.h"
46 #include "bufferlist.h"
47 #include "support/filetools.h"
48 #include "support/path.h"
50 #include "lyx_gui_misc.h"
51 #include "LyXView.h" // only because of form_main
52 #include "lastfiles.h"
53 #include "support/FileInfo.h"
54 #include "lyxscreen.h"
56 #include "support/syscall.h"
57 #include "support/lyxlib.h"
58 #include "lyxserver.h"
59 #include "FontLoader.h"
65 extern MiniBuffer * minibuffer;
66 extern Combox * combo_language;
67 extern BufferList bufferlist;
68 extern void show_symbols_form();
69 extern FD_form_main * fd_form_main;
70 extern FD_form_title * fd_form_title;
71 extern FD_form_paragraph * fd_form_paragraph;
72 extern FD_form_character * fd_form_character;
73 extern FD_form_document * fd_form_document;
74 extern FD_form_quotes * fd_form_quotes;
75 extern FD_form_preamble * fd_form_preamble;
76 extern FD_form_table * fd_form_table;
77 extern FD_form_print * fd_form_print;
78 extern FD_form_figure * fd_form_figure;
79 extern FD_form_screen * fd_form_screen;
80 extern FD_form_toc * fd_form_toc;
81 extern FD_form_ref * fd_form_ref;
82 extern FD_LaTeXOptions * fd_latex_options;
83 extern FD_form_bullet * fd_form_bullet;
85 extern BufferView * current_view; // called too many times in this file...
87 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
89 extern bool send_fax(string const & fname, string const & sendcmd);
90 extern void MenuSendto();
92 extern LyXServer * lyxserver;
93 extern FontLoader fontloader;
95 // this should be static, but I need it in buffer.C
96 bool quitting; // flag, that we are quitting the program
97 extern bool finished; // all cleanup done just let it run through now.
99 char ascii_type; /* for selection notify callbacks */
101 bool scrolling = false;
103 char updatetimer = 0;
105 /* whether the work area should get callbacks */
106 bool input_prohibited = false;
108 /* the selection possible is needed, that only motion events are
109 * used, where the bottom press event was on the drawing area too */
110 bool selection_possible = false;
112 // This is used to make the dreaded font toggle problem hopefully go
113 // away. Definitely not the best solution, but I think it sorta works.
114 bool toggleall = true;
116 void InsertCorrectQuote();
120 This is the inset locking stuff needed for mathed --------------------
122 an inset can simple call LockInset in it's edit call and *ONLY* in it's
124 Inset::Edit() can only be called by the main lyx module.
126 Then the inset may modify the menu's and/or iconbars.
128 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
130 During the lock, all button and keyboard events will be modified
131 and send to the inset through the following inset-features. Note that
132 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
133 to contain the code for restoring the menus and things like this.
136 virtual void InsetButtonPress(int x, int y, int button);
137 virtual void InsetButtonRelease(int x, int y, int button);
138 virtual void InsetKeyPress(XKeyEvent *ev);
139 virtual void InsetMotionNotify(int x, int y, int state);
140 virtual void InsetUnlock();
142 If a inset wishes any redraw and/or update it just has to call
144 It's is completly irrelevant, where the inset is. UpdateInset will
145 find it in any paragraph in any buffer.
146 Of course the_locking_inset and the insets in the current paragraph/buffer
147 are checked first, so no performance problem should occur.
149 Hope that's ok for the beginning, Alejandro,
150 sorry that I needed so much time,
155 void UpdateInset(Inset * inset, bool mark_dirty = true);
156 /* these functions return 1 if an error occured,
158 // Now they work only for updatable insets. [Alejandro 080596]
159 int LockInset(UpdatableInset * inset);
160 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
161 void FitLockedInsetCursor(long x, long y, int asc, int desc);
162 int UnlockInset(UpdatableInset * inset);
163 void LockedInsetStoreUndo(Undo::undo_kind kind);
165 /* this is for asyncron updating. UpdateInsetUpdateList will be called
166 automatically from LyX. Just insert the Inset into the Updatelist */
167 void UpdateInsetUpdateList();
168 void PutInsetIntoInsetUpdateList(Inset * inset);
170 InsetUpdateStruct * InsetUpdateList = 0;
174 -----------------------------------------------------------------------
177 /* some function prototypes */
184 void HyphenationPoint();
185 void MenuSeparator();
188 void ProtectedBlank();
190 int RunLinuxDoc(int, string const &);
191 int RunDocBook(int, string const &);
192 void MenuWrite(Buffer * buf);
193 void MenuWriteAs(Buffer * buffer);
194 void MenuReload(Buffer * buf);
195 void MenuLayoutSave();
197 unsigned char GetCurrentTextClass()
198 // Who are we asking?
199 // Shouldn't this question be directed to the buffer?
200 // Indeed it should. Asger.
202 return current_view->buffer()->params.textclass;
206 // How should this actually work? Should it prohibit input in all BufferViews,
207 // or just in the current one? If "just the current one", then it should be
208 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
209 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
210 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
211 // current LyxView that should be prohibited (Lgb) (This applies to
212 // "AllowInput" as well.)
215 input_prohibited = true;
216 if (current_view->getScreen())
217 current_view->getScreen()->HideCursor();
219 static Cursor cursor;
220 static bool cursor_undefined = true;
222 if (cursor_undefined){
223 cursor = XCreateFontCursor(fl_display, XC_watch);
225 cursor_undefined = false;
228 /* set the cursor to the watch for all forms and the canvas */
229 XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
230 if (fd_form_paragraph->form_paragraph->visible)
231 XDefineCursor(fl_display,
232 fd_form_paragraph->form_paragraph->window,
234 if (fd_form_character->form_character->visible)
235 XDefineCursor(fl_display,
236 fd_form_character->form_character->window,
240 fl_deactivate_all_forms();
244 // Should find a way to move this into BufferView.C
245 void SetXtermCursor(Window win)
247 static Cursor cursor;
248 static bool cursor_undefined = true;
249 if (cursor_undefined){
250 cursor = XCreateFontCursor(fl_display, XC_xterm);
252 cursor_undefined = false;
254 XDefineCursor(fl_display, win, cursor);
261 input_prohibited = false;
263 /* reset the cursor from the watch for all forms and the canvas */
265 XUndefineCursor(fl_display, fd_form_main->form_main->window);
266 if (fd_form_paragraph->form_paragraph->visible)
267 XUndefineCursor(fl_display,
268 fd_form_paragraph->form_paragraph->window);
269 if (fd_form_character->form_character->visible)
270 XUndefineCursor(fl_display,
271 fd_form_character->form_character->window);
272 if (current_view->getWorkArea()->belowmouse)
273 SetXtermCursor(fd_form_main->form_main->window);
276 fl_activate_all_forms();
280 void FreeUpdateTimer()
282 /* a real free timer would be better but I don't know
283 * how to do this with xforms */
288 void SetUpdateTimer(float time)
290 fl_set_timer(fd_form_main->timer_update, time);
295 // candidate for move to BufferView
298 current_view->getScreen()->ToggleSelection();
300 current_view->text->ClearSelection();
302 current_view->buffer()->text->ClearSelection();
308 // candidate for move to BufferView
309 void SmallUpdate(signed char f)
311 current_view->getScreen()->SmallUpdate();
312 if (current_view->getScreen()->TopCursorVisible()
313 != current_view->getScreen()->first){
315 current_view->update(f);
317 current_view->buffer()->update(f);
322 current_view->fitCursor();
323 current_view->updateScrollbar();
326 if (!current_view->text->selection)
327 current_view->text->sel_cursor =
328 current_view->text->cursor;
330 if (!current_view->buffer()->text->selection)
331 current_view->buffer()->text->sel_cursor =
332 current_view->buffer()->text->cursor;
335 if (f == 1 || f == -1) {
336 if (current_view->buffer()->isLyxClean()) {
337 current_view->buffer()->markDirty();
338 minibuffer->setTimer(4);
341 current_view->buffer()->markDirty();
355 // should be moved to lyxfunc.C
356 void MenuWrite(Buffer * buf)
359 if (!bufferlist.write(buf)) {
360 string fname = buf->fileName();
361 string s = MakeAbsPath(fname);
362 if (AskQuestion(_("Save failed. Rename and try again?"),
363 MakeDisplayPath(s, 50),
364 _("(If not, document is not saved.)"))) {
368 lastfiles->newFile(buf->fileName());
373 // should be moved to BufferView.C
374 void MenuWriteAs(Buffer * buffer)
377 if (!current_view->text) return;
379 if (!buffer->text) return;
382 string fname = buffer->fileName();
383 string oldname = fname;
387 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
388 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
390 if (!IsLyXFilename(fname))
393 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
396 OnlyFilename(fname));
400 minibuffer->Set(_("Canceled."));
404 // Make sure the absolute filename ends with appropriate suffix
405 string s = MakeAbsPath(fname);
406 if (!IsLyXFilename(s))
409 // Same name as we have already?
411 if (!AskQuestion(_("Same name as document already has:"),
412 MakeDisplayPath(s, 50),
415 // Falls through to name change and save
417 // No, but do we have another file with this name open?
418 else if (bufferlist.exists(s)) {
419 if (AskQuestion(_("Another document with same name open!"),
420 MakeDisplayPath(s, 50),
421 _("Replace with current document?")))
423 bufferlist.close(bufferlist.getBuffer(s));
425 // Ok, change the name of the buffer, but don't save!
429 minibuffer->Set(_("Document renamed to '"),
431 _("', but not saved..."));
434 } // Check whether the file exists
437 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
438 MakeDisplayPath(s, 50),
443 // Ok, change the name of the buffer
447 // Small bug: If the save fails, we have irreversible changed the name
453 int MenuRunLaTeX(Buffer * buffer)
457 if (buffer->isLinuxDoc())
458 ret = RunLinuxDoc(1, buffer->fileName());
459 else if (buffer->isLiterate())
460 ret = buffer->runLiterate();
461 else if (buffer->isDocBook())
462 ret = RunDocBook(1, buffer->fileName());
464 ret = buffer->runLaTeX();
470 s = _("One error detected");
471 t = _("You should try to fix it.");
474 s += _(" errors detected.");
475 t = _("You should try to fix them.");
477 WriteAlert(_("There were errors during the LaTeX run."), s, t);
483 int MenuBuildProg(Buffer * buffer)
487 if (buffer->isLiterate())
488 ret = buffer->buildProgram();
490 string s = _("Wrong type of document");
491 string t = _("The Build operation is not allowed in this document");
492 WriteAlert(_("There were errors during the Build process."), s, t);
500 s = _("One error detected");
501 t = _("You should try to fix it.");
504 s += _(" errors detected.");
505 t = _("You should try to fix them.");
507 WriteAlert(_("There were errors during the Build process."), s, t);
513 int MenuRunChktex(Buffer * buffer)
517 if (buffer->isSGML()) {
518 WriteAlert(_("Chktex does not work with SGML derived documents."));
521 ret = buffer->runChktex();
527 s = _("No warnings found.");
528 } else if (ret == 1) {
529 s = _("One warning found.");
530 t = _("Use 'Edit->Go to Error' to find it.");
533 s += _(" warnings found.");
534 t = _("Use 'Edit->Go to Error' to find them.");
536 WriteAlert(_("Chktex run successfully"), s, t);
538 WriteAlert(_("Error!"), _("It seems chktex does not work."));
544 int MakeDVIOutput(Buffer * buffer)
547 if (!(current_view->text))
556 string path = OnlyPath(buffer->fileName());
557 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
558 path = buffer->tmppath;
560 if (!buffer->isDviClean()) {
562 ret = MenuRunLaTeX(buffer);
568 /* wait == false means don't wait for termination */
569 /* wait == true means wait for termination */
570 // The bool should be placed last on the argument line. (Lgb)
571 // Returns false if we fail.
572 bool RunScript(Buffer * buffer, bool wait,
573 string const & command,
574 string const & orgname = string(),
575 bool need_shell = true)
579 string name = orgname;
582 if (MakeDVIOutput(buffer) > 0)
584 /* get DVI-Filename */
586 name = ChangeExtension(buffer->getLatexName(),
589 path = OnlyPath(name);
590 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
591 path = buffer->tmppath;
595 cmd = command + ' ' + QuoteName(name);
604 // OS/2 cmd.exe has another use for '&'
606 // This is not NLS safe, but it's OK, I think.
607 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
609 // COMSPEC is set, unless user unsets
610 sh = OnlyFilename(GetEnvPath("COMSPEC"));
615 if (contains(sh, "cmd.exe")
616 || contains(sh, "4os2.exe"))
617 cmd = "start /min/n " + cmd;
622 // It seems that, if wait is false, we never get back
623 // the return code of the command. This means that all
624 // the code I added in PrintApplyCB is currently
627 #warning What should we do here?
629 minibuffer->Set(_("Executing command:"), cmd);
630 result = one.startscript(Systemcalls::System, cmd);
632 minibuffer->Set(_("Executing command:"), cmd);
633 result = one.startscript(wait ? Systemcalls::Wait
634 : Systemcalls::DontWait, cmd);
636 return (result == 0);
640 // Returns false if we fail
641 bool MenuRunDvips(Buffer * buffer, bool wait = false)
644 if (!current_view->text)
654 if (MakeDVIOutput(buffer) > 0) {
658 // Generate postscript file
659 string psname = ChangeExtension (buffer->fileName(),
664 char real_papersize = buffer->params.papersize;
665 if (real_papersize == BufferParams::PAPER_DEFAULT)
666 real_papersize = lyxrc->default_papersize;
668 switch (real_papersize) {
669 case BufferParams::PAPER_USLETTER:
672 case BufferParams::PAPER_A3PAPER:
675 case BufferParams::PAPER_A4PAPER:
678 case BufferParams::PAPER_A5PAPER:
681 case BufferParams::PAPER_B5PAPER:
684 case BufferParams::PAPER_EXECUTIVEPAPER:
687 case BufferParams::PAPER_LEGALPAPER:
690 default: /* If nothing else fits, keep an empty value... */
694 // Make postscript file.
695 string command = "dvips " + lyxrc->print_to_file + ' ';
696 command += QuoteName(psname);
697 if (buffer->params.use_geometry
698 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
699 && !lyxrc->print_paper_dimension_flag.empty()
700 && !buffer->params.paperwidth.empty()
701 && !buffer->params.paperheight.empty()) {
702 // using a custom papersize
704 command += lyxrc->print_paper_dimension_flag + ' ';
705 command += buffer->params.paperwidth + ',';
706 command += buffer->params.paperheight;
707 } else if (!paper.empty()
708 && (real_papersize != BufferParams::PAPER_USLETTER ||
709 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
710 // dvips won't accept -t letter -t landscape. In all other
711 // cases, include the paper size explicitly.
713 command += lyxrc->print_paper_flag + ' ' + paper;
715 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
717 command += lyxrc->print_landscape_flag;
719 // push directorypath, if necessary
720 string path = OnlyPath(buffer->fileName());
721 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
722 path = buffer->tmppath;
725 bool ret = RunScript(buffer, wait, command);
731 // Returns false if we fail
732 bool MenuPreviewPS(Buffer * buffer)
735 if (!current_view->text)
742 // Generate postscript file
743 if (!MenuRunDvips(buffer, true)) {
747 // Start postscript viewer
749 string ps = ChangeExtension (buffer->fileName(),
751 // push directorypath, if necessary
752 string path = OnlyPath(buffer->fileName());
753 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
754 path = buffer->tmppath;
757 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
763 void MenuFax(Buffer * buffer)
766 if (!current_view->text)
773 // Generate postscript file
774 if (!MenuRunDvips(buffer, true)) {
779 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
780 string path = OnlyPath (buffer->fileName());
781 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
782 path = buffer->tmppath;
785 if (!lyxrc->fax_program.empty()) {
786 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
788 Systemcalls one(Systemcalls::System, help2);
790 send_fax(ps, lyxrc->fax_command);
794 // Returns false if we fail
795 bool MenuPreview(Buffer * buffer)
798 if (!current_view->text)
806 char real_papersize = buffer->params.papersize;
807 if (real_papersize == BufferParams::PAPER_DEFAULT)
808 real_papersize = lyxrc->default_papersize;
810 switch (real_papersize) {
811 case BufferParams::PAPER_USLETTER:
814 case BufferParams::PAPER_A3PAPER:
817 case BufferParams::PAPER_A4PAPER:
820 case BufferParams::PAPER_A5PAPER:
823 case BufferParams::PAPER_B5PAPER:
826 case BufferParams::PAPER_EXECUTIVEPAPER:
829 case BufferParams::PAPER_LEGALPAPER:
832 default: /* If nothing else fits, keep the empty value */
837 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
838 // we HAVE to give a size when the page is in
839 // landscape, so use USletter.
840 paper = " -paper usr";
842 paper = " -paper " + paper;
843 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
847 // push directorypath, if necessary
848 string path = OnlyPath(buffer->fileName());
849 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
850 path = buffer->tmppath;
854 string command = lyxrc->view_dvi_command + paper ;
855 bool ret = RunScript(buffer, false, command);
860 void MenuMakeLaTeX(Buffer * buffer)
863 if (!current_view->text)
870 // Get LaTeX-Filename
871 string s = buffer->getLatexName();
875 !AskQuestion(_("File already exists:"),
876 MakeDisplayPath(s, 50),
877 _("Do you want to overwrite the file?"))) {
878 minibuffer->Set(_("Canceled"));
882 if (buffer->isDocBook())
883 minibuffer->Set(_("DocBook does not have a latex backend"));
885 if (buffer->isLinuxDoc())
886 RunLinuxDoc(0, buffer->fileName());
888 buffer->makeLaTeXFile(s, string(), true);
889 minibuffer->Set(_("Nice LaTeX file saved as"),
891 buffer->markDviDirty();
896 void MenuMakeLinuxDoc(Buffer * buffer)
899 if (!current_view->text) return;
901 if (!buffer->text) return;
904 if (!buffer->isLinuxDoc()) {
905 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
909 // Get LinuxDoc-Filename
910 string s = ChangeExtension (buffer->fileName(),
915 !AskQuestion(_("File already exists:"),
916 MakeDisplayPath(s, 50),
917 _("Do you want to overwrite the file?"))) {
918 minibuffer->Set(_("Canceled"));
922 minibuffer->Set(_("Building LinuxDoc SGML file `"),
923 MakeDisplayPath(s), "'...");
925 buffer->makeLinuxDocFile(s, 65);
927 minibuffer->Set(_("LinuxDoc SGML file save as"),
932 void MenuMakeDocBook(Buffer * buffer)
935 if (!current_view->text) return;
937 if (!buffer->text) return;
940 if (!buffer->isDocBook()) {
941 WriteAlert(_("Error!"),
942 _("Document class must be docbook."));
946 // Get DocBook-Filename
947 string s = ChangeExtension (buffer->fileName(),
952 !AskQuestion(_("File already exists:"),
953 MakeDisplayPath(s, 50),
954 _("Do you want to overwrite the file?"))) {
955 minibuffer->Set(_("Canceled"));
959 minibuffer->Set(_("Building DocBook SGML file `"),
960 MakeDisplayPath(s), "'...");
962 buffer->makeDocBookFile(s, 65);
964 minibuffer->Set(_("DocBook SGML file save as"),
969 void MenuMakeAscii(Buffer * buffer)
972 if (!current_view->text) return;
974 if (!buffer->text) return;
977 /* get LaTeX-Filename */
978 string s = ChangeExtension (buffer->fileName(),
983 !AskQuestion(_("File already exists:"),
984 MakeDisplayPath(s, 50),
985 _("Do you want to overwrite the file?"))) {
986 minibuffer->Set(_("Canceled"));
990 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
992 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
996 void MenuPrint(Buffer * buffer)
999 if (!current_view->text)
1005 string input_file = ChangeExtension(buffer->fileName(),
1006 lyxrc->print_file_extension,
1008 fl_set_input(fd_form_print->input_file, input_file.c_str());
1010 if (fd_form_print->form_print->visible) {
1011 fl_raise_form(fd_form_print->form_print);
1014 fl_show_form(fd_form_print->form_print,
1015 FL_PLACE_MOUSE, FL_FULLBORDER,
1020 void MenuMakeHTML(Buffer * buffer)
1022 // First, create LaTeX file
1023 MenuMakeLaTeX(buffer);
1025 // And now, run the converter
1026 string file = buffer->fileName();
1027 Path path(OnlyPath(file));
1028 // the tex file name has to be correct for
1029 // latex, but the html file name can be
1031 string result = ChangeExtension(file, ".html", false);
1032 string infile = buffer->getLatexName();
1033 string tmp = lyxrc->html_command;
1034 tmp = subst(tmp, "$$FName", infile);
1035 tmp = subst(tmp, "$$OutName", result);
1037 int res = one.startscript(Systemcalls::System, tmp);
1039 minibuffer->Set(_("Document exported as HTML to file `")
1040 + MakeDisplayPath(result) +'\'');
1042 minibuffer->Set(_("Unable to convert to HTML the file `")
1043 + MakeDisplayPath(infile)
1049 void MenuExport(Buffer * buffer, string const & extyp)
1052 if (extyp == "latex") {
1053 // make sure that this buffer is not linuxdoc
1054 MenuMakeLaTeX(buffer);
1057 else if (extyp == "linuxdoc") {
1058 // make sure that this buffer is not latex
1059 MenuMakeLinuxDoc(buffer);
1062 else if (extyp == "docbook") {
1063 // make sure that this buffer is not latex or linuxdoc
1064 MenuMakeDocBook(buffer);
1067 else if (extyp == "dvi") {
1068 // Run LaTeX as "Update dvi..." Bernhard.
1069 // We want the dvi in the current directory. This
1070 // is achieved by temporarily disabling use of
1071 // temp directory. As a side-effect, we get
1072 // *.log and *.aux files also. (Asger)
1073 bool flag = lyxrc->use_tempdir;
1074 lyxrc->use_tempdir = false;
1075 MenuRunLaTeX(buffer);
1076 lyxrc->use_tempdir = flag;
1079 else if (extyp == "postscript") {
1080 // Start Print-dialog. Not as good as dvi... Bernhard.
1082 // Since the MenuPrint is a pop-up, we can't use
1083 // the same trick as above. (Asger)
1084 // MISSING: Move of ps-file :-(
1087 else if (extyp == "ascii") {
1088 MenuMakeAscii(buffer);
1090 else if (extyp == "custom") {
1094 else if (extyp == "html") {
1095 MenuMakeHTML(buffer);
1098 minibuffer->Set(_("Unknown export type: ")+ extyp);
1105 lyxerr.debug() << "Running QuitLyX." << endl;
1107 if (!bufferlist.QwriteAll())
1110 lastfiles->writeFile(lyxrc->lastfiles);
1112 // Set a flag that we do quitting from the program,
1113 // so no refreshes are necessary.
1116 // close buffers first
1117 bufferlist.closeAll();
1119 // do any other cleanup procedures now
1120 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1122 DestroyLyXTmpDir(system_tempdir);
1130 // should probably be moved into BufferList (Lgb)
1131 // Perfect target for a thread...
1133 if (!current_view->getScreen() || !current_view->available())
1136 if (current_view->buffer()->isBakClean()
1137 || current_view->buffer()->isReadonly()) {
1138 // We don't save now, but we'll try again later
1139 current_view->owner()->resetAutosaveTimer();
1143 minibuffer->Set(_("Autosaving current document..."));
1145 // create autosave filename
1146 string fname = OnlyPath(current_view->buffer()->fileName());
1148 fname += OnlyFilename(current_view->buffer()->fileName());
1151 // tmp_ret will be located (usually) in /tmp
1152 // will that be a problem?
1153 string tmp_ret = tmpnam(0);
1155 pid_t pid = fork(); // If you want to debug the autosave
1156 // you should set pid to -1, and comment out the
1158 if (pid == 0 || pid == -1) {
1159 // pid = -1 signifies that lyx was unable
1160 // to fork. But we will do the save
1162 bool failed = false;
1163 if (!tmp_ret.empty()) {
1164 current_view->buffer()->writeFile(tmp_ret, 1);
1165 // assume successful write of tmp_ret
1166 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1168 // most likely couldn't move between filesystems
1169 // unless write of tmp_ret failed
1170 // so remove tmp file (if it exists)
1171 remove(tmp_ret.c_str());
1178 // failed to write/rename tmp_ret so try writing direct
1179 if (!current_view->buffer()->writeFile(fname, 1)) {
1180 // It is dangerous to do this in the child,
1181 // but safe in the parent, so...
1183 minibuffer->Set(_("Autosave Failed!"));
1186 if (pid == 0) { // we are the child so...
1191 current_view->buffer()->markBakClean();
1192 current_view->owner()->resetAutosaveTimer();
1197 // (c) CHT Software Service GmbH
1200 // create new file with template
1203 Buffer * NewLyxFile(string const & filename)
1205 // Split argument by :
1207 string tmpname = split(filename, name, ':');
1208 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1209 if (name.length() == 1
1210 && isalpha(static_cast<unsigned char>(name[0]))
1211 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1213 name += token(tmpname, ':', 0);
1214 tmpname = split(tmpname, ':');
1217 lyxerr.debug() << "Arg is " << filename
1218 << "\nName is " << name
1219 << "\nTemplate is " << tmpname << endl;
1221 // find a free buffer
1222 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1224 lastfiles->newFile(tmpbuf->fileName());
1229 // Insert ascii file (if filename is empty, prompt for one)
1230 void InsertAsciiFile(string const & f, bool asParagraph)
1235 if (!current_view->getScreen()) return;
1237 if (fname.empty()) {
1239 fname = fileDlg.Select(_("File to Insert"),
1240 current_view->owner()->buffer()->filepath,
1243 if (fname.empty()) return;
1248 if (!fi.readable()) {
1249 WriteFSAlert(_("Error! Specified file is unreadable: "),
1250 MakeDisplayPath(fname, 50));
1254 FilePtr myfile(fname, FilePtr::read);
1256 WriteFSAlert(_("Error! Cannot open specified file: "),
1257 MakeDisplayPath(fname, 50));
1260 LyXParagraph * tmppar = new LyXParagraph;
1261 tmppar->readSimpleWholeFile(myfile);
1263 // set the end of the string
1264 #ifdef WITH_WARNINGS
1265 #warning why do we do this?
1267 // I don't think this is needed. Actually it might be plain wrong.
1268 tmppar->InsertChar(tmppar->text.size() - 1, '\0');
1270 // insert the string
1271 current_view->getScreen()->HideCursor();
1273 // clear the selection
1277 current_view->text->InsertStringA(tmppar->text);
1279 current_view->text->InsertStringB(tmppar->text);
1281 current_view->update(1);
1284 current_view->buffer()->text->InsertStringA(tmppar->text);
1286 current_view->buffer()->text->InsertStringB(tmppar->text);
1288 current_view->buffer()->update(1);
1293 void MenuShowTableOfContents()
1295 static int ow = -1, oh;
1298 if (fd_form_toc->form_toc->visible) {
1299 fl_raise_form(fd_form_toc->form_toc);
1301 fl_show_form(fd_form_toc->form_toc,
1302 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1303 _("Table Of Contents"));
1305 ow = fd_form_toc->form_toc->w;
1306 oh = fd_form_toc->form_toc->h;
1308 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1313 void MenuInsertLabel(char const * arg)
1317 //string label = fl_show_input(_("Enter new label to insert:"), "");
1319 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1320 if (!label.empty()) {
1321 InsetLabel * new_inset = new InsetLabel;
1322 new_inset->setContents(label);
1323 current_view->buffer()->insertInset(new_inset);
1329 void MenuInsertRef()
1331 static int ow = -1, oh;
1334 if (fd_form_ref->form_ref->visible) {
1335 fl_raise_form(fd_form_ref->form_ref);
1337 fl_show_form(fd_form_ref->form_ref,
1338 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1339 _("Insert Reference"));
1341 ow = fd_form_ref->form_ref->w;
1342 oh = fd_form_ref->form_ref->h;
1344 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1349 void MenuPasteSelection(char at)
1351 if (!current_view->getScreen())
1356 Atom data_prop = XInternAtom(fl_display,
1359 if (data_prop == None)
1361 XConvertSelection(fl_display,
1362 XA_PRIMARY, XA_STRING, data_prop,
1363 fd_form_main->form_main->window, 0);
1368 // candidate for move to BufferView
1369 extern "C" void FootCB(FL_OBJECT *, long)
1371 if (!current_view->available())
1374 minibuffer->Set(_("Inserting Footnote..."));
1375 current_view->getScreen()->HideCursor();
1377 current_view->update(-2);
1378 current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1379 current_view->update(1);
1381 current_view->buffer()->update(-2);
1382 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1383 current_view->buffer()->update(1);
1388 // candidate for move to LyXView
1389 void LayoutsCB(int sel, void *)
1391 string tmp = tostr(sel);
1392 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1398 * SGML Linuxdoc support:
1399 * (flag == -1) import SGML file
1400 * (flag == 0) make TeX output
1401 * (flag == 1) make dvi output
1403 int RunLinuxDoc(int flag, string const & filename)
1412 /* generate a path-less extension name */
1413 name = ChangeExtension (filename, ".sgml", true);
1414 path = OnlyPath (filename);
1415 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1416 path = current_view->buffer()->tmppath;
1421 if (!current_view->available())
1423 current_view->buffer()->makeLinuxDocFile(name, 0);
1424 #ifdef WITH_WARNINGS
1425 #warning remove this once we have a proper geometry class
1427 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(current_view->buffer()->params.papersize);
1429 case BufferParams::PAPER_A4PAPER:
1430 add_flags = "-p a4";
1432 case BufferParams::PAPER_USLETTER:
1433 add_flags = "-p letter";
1435 default: /* nothing to be done yet ;-) */ break;
1443 case -1: /* Import file */
1444 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1445 MakeDisplayPath(filename), "'...");
1446 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1448 if (one.startscript(Systemcalls::System, s2))
1451 case 0: /* TeX output asked */
1452 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1453 s2 = "sgml2latex " + add_flags + " -o tex "
1454 + lyxrc->sgml_extra_options + ' ' + name;
1455 if (one.startscript(Systemcalls::System, s2))
1458 case 1: /* dvi output asked */
1459 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1460 s2 = "sgml2latex " + add_flags + " -o dvi "
1461 + lyxrc->sgml_extra_options + ' ' + name;
1462 if (one.startscript(Systemcalls::System, s2)) {
1465 current_view->buffer()->markDviClean();
1467 default: /* unknown output */
1473 current_view->buffer()->redraw();
1479 * SGML DocBook support:
1480 * (flag == 1) make dvi output
1482 int RunDocBook(int flag, string const & filename)
1484 /* generate a path-less extension name */
1485 string name = ChangeExtension (filename, ".sgml", true);
1486 string path = OnlyPath (filename);
1487 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1488 path = current_view->buffer()->tmppath;
1492 if (!current_view->available())
1495 current_view->buffer()->makeDocBookFile(name, 0);
1497 // Shall this code go or should it stay? (Lgb)
1498 // string add_flags;
1499 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1501 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1502 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1503 // default: /* nothing to be done yet ;-) */ break;
1510 case 1: /* dvi output asked */
1512 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1513 string s2 = "sgmltools --backend dvi " + name;
1514 if (one.startscript(Systemcalls::System, s2)) {
1517 current_view->buffer()->markDviClean();
1520 default: /* unknown output */
1526 current_view->buffer()->redraw();
1531 // candidate for move to BufferView
1532 void AllFloats(char flag, char figmar)
1534 if (!current_view->available())
1538 LyXCursor cursor = current_view->text->cursor;
1540 LyXCursor cursor = current_view->buffer()->text->cursor;
1543 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1545 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1546 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1548 && cursor.par->footnotekind != LyXParagraph::FIG
1549 && cursor.par->footnotekind != LyXParagraph::TAB
1550 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1551 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1552 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1557 LyXCursor tmpcursor = cursor;
1558 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1559 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1561 LyXParagraph *par = current_view->buffer()->paragraph;
1564 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1566 && par->footnotekind != LyXParagraph::FOOTNOTE
1567 && par->footnotekind != LyXParagraph::MARGIN)
1569 && par->footnotekind != LyXParagraph::FIG
1570 && par->footnotekind != LyXParagraph::TAB
1571 && par->footnotekind != LyXParagraph::WIDE_FIG
1572 && par->footnotekind != LyXParagraph::WIDE_TAB
1573 && par->footnotekind != LyXParagraph::ALGORITHM
1578 && par->previous->footnoteflag !=
1579 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1582 ->SetCursorIntern(par
1585 current_view->text->OpenFootnote();
1587 current_view->buffer()->text->SetCursorIntern(par->previous,
1589 current_view->buffer()->text->OpenFootnote();
1595 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1599 par->footnotekind != LyXParagraph::FOOTNOTE
1601 par->footnotekind != LyXParagraph::MARGIN
1606 par->footnotekind != LyXParagraph::FIG
1608 par->footnotekind != LyXParagraph::TAB
1610 par->footnotekind != LyXParagraph::WIDE_FIG
1612 par->footnotekind != LyXParagraph::WIDE_TAB
1614 par->footnotekind != LyXParagraph::ALGORITHM
1619 current_view->text->SetCursorIntern(par, 0);
1620 current_view->text->CloseFootnote();
1622 current_view->buffer()->text->SetCursorIntern(par, 0);
1623 current_view->buffer()->text->CloseFootnote();
1631 current_view->text->SetCursorIntern(cursor.par, cursor.pos);
1633 current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1635 current_view->redraw();
1636 current_view->fitCursor();
1637 current_view->updateScrollbar();
1641 void MenuLayoutCharacter()
1643 static int ow = -1, oh;
1645 if (fd_form_character->form_character->visible) {
1646 fl_raise_form(fd_form_character->form_character);
1648 fl_show_form(fd_form_character->form_character,
1649 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1650 _("Character Style"));
1652 ow = fd_form_character->form_character->w;
1653 oh = fd_form_character->form_character->h;
1655 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1660 inline void DeactivateParagraphButtons ()
1662 fl_deactivate_object (fd_form_paragraph->button_ok);
1663 fl_deactivate_object (fd_form_paragraph->button_apply);
1664 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1665 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1669 inline void ActivateParagraphButtons ()
1671 fl_activate_object (fd_form_paragraph->button_ok);
1672 fl_activate_object (fd_form_paragraph->button_apply);
1673 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1674 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1678 inline void DisableParagraphLayout ()
1680 DeactivateParagraphButtons();
1681 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1682 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1683 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1684 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1685 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1686 fl_deactivate_object (fd_form_paragraph->check_noindent);
1687 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1688 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1689 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1690 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1691 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1692 fl_deactivate_object (fd_form_paragraph->input_space_above);
1693 fl_deactivate_object (fd_form_paragraph->input_space_below);
1694 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1695 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1696 fl_deactivate_object (fd_form_paragraph->check_space_above);
1697 fl_deactivate_object (fd_form_paragraph->check_space_below);
1701 inline void EnableParagraphLayout ()
1703 ActivateParagraphButtons();
1704 fl_activate_object (fd_form_paragraph->input_labelwidth);
1705 fl_activate_object (fd_form_paragraph->check_lines_top);
1706 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1707 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1708 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1709 fl_activate_object (fd_form_paragraph->check_noindent);
1710 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1711 fl_activate_object (fd_form_paragraph->radio_align_right);
1712 fl_activate_object (fd_form_paragraph->radio_align_left);
1713 fl_activate_object (fd_form_paragraph->radio_align_block);
1714 fl_activate_object (fd_form_paragraph->radio_align_center);
1715 fl_activate_object (fd_form_paragraph->input_space_above);
1716 fl_activate_object (fd_form_paragraph->input_space_below);
1717 fl_activate_object (fd_form_paragraph->choice_space_above);
1718 fl_activate_object (fd_form_paragraph->choice_space_below);
1719 fl_activate_object (fd_form_paragraph->check_space_above);
1720 fl_activate_object (fd_form_paragraph->check_space_below);
1725 bool UpdateLayoutParagraph()
1727 if (!current_view->getScreen() || !current_view->available()) {
1728 if (fd_form_paragraph->form_paragraph->visible)
1729 fl_hide_form(fd_form_paragraph->form_paragraph);
1733 Buffer * buf = current_view->buffer();
1735 fl_set_input(fd_form_paragraph->input_labelwidth,
1736 current_view->text->cursor.par->GetLabelWidthString().c_str());
1737 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1738 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1739 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1740 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1742 int align = current_view->text->cursor.par->GetAlign();
1743 if (align == LYX_ALIGN_LAYOUT)
1744 align = textclasslist.Style(buf->params.textclass,
1745 current_view->text->cursor.par->GetLayout()).align;
1748 case LYX_ALIGN_RIGHT:
1749 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1751 case LYX_ALIGN_LEFT:
1752 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1754 case LYX_ALIGN_CENTER:
1755 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1758 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1762 fl_set_button(fd_form_paragraph->check_lines_top,
1763 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1764 fl_set_button(fd_form_paragraph->check_lines_bottom,
1765 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1766 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1767 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1768 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1769 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1770 fl_set_button(fd_form_paragraph->check_noindent,
1771 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1772 fl_set_input (fd_form_paragraph->input_space_above, "");
1774 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1776 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1778 case VSpace::DEFSKIP:
1779 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1781 case VSpace::SMALLSKIP:
1782 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1784 case VSpace::MEDSKIP:
1785 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1787 case VSpace::BIGSKIP:
1788 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1791 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1793 case VSpace::LENGTH:
1794 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1795 fl_set_input (fd_form_paragraph->input_space_above,
1796 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1799 fl_set_button (fd_form_paragraph->check_space_above,
1800 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1801 fl_set_input (fd_form_paragraph->input_space_below, "");
1802 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1804 fl_set_choice (fd_form_paragraph->choice_space_below,
1807 case VSpace::DEFSKIP:
1808 fl_set_choice (fd_form_paragraph->choice_space_below,
1811 case VSpace::SMALLSKIP:
1812 fl_set_choice (fd_form_paragraph->choice_space_below,
1815 case VSpace::MEDSKIP:
1816 fl_set_choice (fd_form_paragraph->choice_space_below,
1819 case VSpace::BIGSKIP:
1820 fl_set_choice (fd_form_paragraph->choice_space_below,
1824 fl_set_choice (fd_form_paragraph->choice_space_below,
1827 case VSpace::LENGTH:
1828 fl_set_choice (fd_form_paragraph->choice_space_below,
1830 fl_set_input (fd_form_paragraph->input_space_below,
1831 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1834 fl_set_button (fd_form_paragraph->check_space_below,
1835 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1837 fl_set_button(fd_form_paragraph->check_noindent,
1838 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1840 if (current_view->buffer()->isReadonly()) {
1841 DisableParagraphLayout();
1843 EnableParagraphLayout();
1848 bool UpdateLayoutParagraph()
1850 if (!current_view->getScreen() || !current_view->available()) {
1851 if (fd_form_paragraph->form_paragraph->visible)
1852 fl_hide_form(fd_form_paragraph->form_paragraph);
1856 Buffer * buf = current_view->buffer();
1858 fl_set_input(fd_form_paragraph->input_labelwidth,
1859 buf->text->cursor.par->GetLabelWidthString().c_str());
1860 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1861 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1862 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1863 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1865 int align = buf->text->cursor.par->GetAlign();
1866 if (align == LYX_ALIGN_LAYOUT)
1867 align = textclasslist.Style(buf->params.textclass,
1868 buf->text->cursor.par->GetLayout()).align;
1871 case LYX_ALIGN_RIGHT:
1872 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1874 case LYX_ALIGN_LEFT:
1875 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1877 case LYX_ALIGN_CENTER:
1878 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1881 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1885 fl_set_button(fd_form_paragraph->check_lines_top,
1886 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1887 fl_set_button(fd_form_paragraph->check_lines_bottom,
1888 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1889 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1890 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1891 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1892 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1893 fl_set_button(fd_form_paragraph->check_noindent,
1894 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1895 fl_set_input (fd_form_paragraph->input_space_above, "");
1897 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1899 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1901 case VSpace::DEFSKIP:
1902 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1904 case VSpace::SMALLSKIP:
1905 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1907 case VSpace::MEDSKIP:
1908 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1910 case VSpace::BIGSKIP:
1911 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1914 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1916 case VSpace::LENGTH:
1917 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1918 fl_set_input (fd_form_paragraph->input_space_above,
1919 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1922 fl_set_button (fd_form_paragraph->check_space_above,
1923 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1924 fl_set_input (fd_form_paragraph->input_space_below, "");
1925 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1927 fl_set_choice (fd_form_paragraph->choice_space_below,
1930 case VSpace::DEFSKIP:
1931 fl_set_choice (fd_form_paragraph->choice_space_below,
1934 case VSpace::SMALLSKIP:
1935 fl_set_choice (fd_form_paragraph->choice_space_below,
1938 case VSpace::MEDSKIP:
1939 fl_set_choice (fd_form_paragraph->choice_space_below,
1942 case VSpace::BIGSKIP:
1943 fl_set_choice (fd_form_paragraph->choice_space_below,
1947 fl_set_choice (fd_form_paragraph->choice_space_below,
1950 case VSpace::LENGTH:
1951 fl_set_choice (fd_form_paragraph->choice_space_below,
1953 fl_set_input (fd_form_paragraph->input_space_below,
1954 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1957 fl_set_button (fd_form_paragraph->check_space_below,
1958 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1960 fl_set_button(fd_form_paragraph->check_noindent,
1961 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1963 if (current_view->buffer()->isReadonly()) {
1964 DisableParagraphLayout();
1966 EnableParagraphLayout();
1972 void MenuLayoutParagraph()
1974 if (UpdateLayoutParagraph()) {
1975 if (fd_form_paragraph->form_paragraph->visible) {
1976 fl_raise_form(fd_form_paragraph->form_paragraph);
1978 fl_show_form(fd_form_paragraph->form_paragraph,
1979 FL_PLACE_MOUSE, FL_FULLBORDER,
1980 _("Paragraph Environment"));
1987 void DeactivateDocumentButtons ()
1989 fl_deactivate_object (fd_form_document->button_ok);
1990 fl_deactivate_object (fd_form_document->button_apply);
1991 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1992 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1997 void ActivateDocumentButtons ()
1999 fl_activate_object (fd_form_document->button_ok);
2000 fl_activate_object (fd_form_document->button_apply);
2001 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
2002 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
2007 void DisableDocumentLayout ()
2009 DeactivateDocumentButtons ();
2010 fl_deactivate_object (fd_form_document->group_radio_separation);
2011 fl_deactivate_object (fd_form_document->radio_indent);
2012 fl_deactivate_object (fd_form_document->radio_skip);
2013 fl_deactivate_object (fd_form_document->choice_class);
2014 fl_deactivate_object (fd_form_document->choice_pagestyle);
2015 fl_deactivate_object (fd_form_document->choice_fonts);
2016 fl_deactivate_object (fd_form_document->choice_fontsize);
2017 fl_deactivate_object (fd_form_document->input_float_placement);
2018 fl_deactivate_object (fd_form_document->choice_postscript_driver);
2019 fl_deactivate_object (fd_form_document->choice_inputenc);
2020 fl_deactivate_object (fd_form_document->group_radio_sides);
2021 fl_deactivate_object (fd_form_document->radio_sides_one);
2022 fl_deactivate_object (fd_form_document->radio_sides_two);
2023 fl_deactivate_object (fd_form_document->group_radio_columns);
2024 fl_deactivate_object (fd_form_document->radio_columns_one);
2025 fl_deactivate_object (fd_form_document->radio_columns_two);
2026 fl_deactivate_object (fd_form_document->input_extra);
2027 fl_deactivate_object (fd_form_document->choice_language);
2028 combo_language->deactivate();
2029 fl_deactivate_object (fd_form_document->input_default_skip);
2030 fl_deactivate_object (fd_form_document->choice_default_skip);
2031 fl_deactivate_object (fd_form_document->slider_secnumdepth);
2032 fl_deactivate_object (fd_form_document->slider_tocdepth);
2033 fl_deactivate_object (fd_form_document->choice_spacing);
2034 fl_deactivate_object (fd_form_document->input_spacing);
2035 fl_deactivate_object (fd_form_document->check_use_amsmath);
2040 void EnableDocumentLayout ()
2042 ActivateDocumentButtons ();
2043 fl_activate_object (fd_form_document->group_radio_separation);
2044 fl_activate_object (fd_form_document->radio_indent);
2045 fl_activate_object (fd_form_document->radio_skip);
2046 fl_activate_object (fd_form_document->choice_class);
2047 fl_activate_object (fd_form_document->choice_pagestyle);
2048 fl_activate_object (fd_form_document->choice_fonts);
2049 fl_activate_object (fd_form_document->choice_fontsize);
2050 fl_activate_object (fd_form_document->input_float_placement);
2051 fl_activate_object (fd_form_document->choice_postscript_driver);
2052 fl_activate_object (fd_form_document->choice_inputenc);
2053 fl_activate_object (fd_form_document->group_radio_sides);
2054 fl_activate_object (fd_form_document->radio_sides_one);
2055 fl_activate_object (fd_form_document->radio_sides_two);
2056 fl_activate_object (fd_form_document->group_radio_columns);
2057 fl_activate_object (fd_form_document->radio_columns_one);
2058 fl_activate_object (fd_form_document->radio_columns_two);
2059 fl_activate_object (fd_form_document->input_extra);
2060 fl_activate_object (fd_form_document->choice_language);
2061 combo_language->activate();
2062 fl_activate_object (fd_form_document->input_default_skip);
2063 fl_activate_object (fd_form_document->choice_default_skip);
2064 fl_activate_object (fd_form_document->slider_secnumdepth);
2065 fl_activate_object (fd_form_document->slider_tocdepth);
2066 fl_activate_object (fd_form_document->choice_spacing);
2067 fl_activate_object (fd_form_document->input_spacing);
2068 fl_activate_object (fd_form_document->check_use_amsmath);
2072 bool UpdateLayoutDocument(BufferParams * params)
2074 if (!current_view->getScreen() || !current_view->available()) {
2075 if (fd_form_document->form_document->visible)
2076 fl_hide_form(fd_form_document->form_document);
2081 params = ¤t_view->buffer()->params;
2082 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
2084 fl_set_choice_text(fd_form_document->choice_class,
2085 textclasslist.DescOfClass(params->textclass).c_str());
2086 combo_language->select_text(params->language.c_str());
2088 fl_set_choice_text(fd_form_document->choice_fonts,
2089 params->fonts.c_str());
2090 fl_set_choice_text(fd_form_document->choice_inputenc,
2091 params->inputenc.c_str());
2092 fl_set_choice_text(fd_form_document->choice_postscript_driver,
2093 params->graphicsDriver.c_str());
2095 // ale970405+lasgoutt970513
2096 fl_clear_choice(fd_form_document->choice_fontsize);
2097 fl_addto_choice(fd_form_document->choice_fontsize, "default");
2098 fl_addto_choice(fd_form_document->choice_fontsize,
2099 tclass.opt_fontsize().c_str());
2100 fl_set_choice(fd_form_document->choice_fontsize,
2101 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
2103 // ale970405+lasgoutt970513
2104 fl_clear_choice(fd_form_document->choice_pagestyle);
2105 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
2106 fl_addto_choice(fd_form_document->choice_pagestyle,
2107 tclass.opt_pagestyle().c_str());
2109 fl_set_choice(fd_form_document->choice_pagestyle,
2110 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
2112 fl_set_button(fd_form_document->radio_indent, 0);
2113 fl_set_button(fd_form_document->radio_skip, 0);
2116 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
2118 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
2119 fl_set_button(fd_form_document->radio_indent, 1);
2121 fl_set_button(fd_form_document->radio_skip, 1);
2123 switch (params->getDefSkip().kind()) {
2124 case VSpace::SMALLSKIP:
2125 fl_set_choice (fd_form_document->choice_default_skip, 1);
2127 case VSpace::MEDSKIP:
2128 fl_set_choice (fd_form_document->choice_default_skip, 2);
2130 case VSpace::BIGSKIP:
2131 fl_set_choice (fd_form_document->choice_default_skip, 3);
2133 case VSpace::LENGTH:
2134 fl_set_choice (fd_form_document->choice_default_skip, 4);
2135 fl_set_input (fd_form_document->input_default_skip,
2136 params->getDefSkip().asLyXCommand().c_str());
2139 fl_set_choice (fd_form_document->choice_default_skip, 2);
2143 fl_set_button(fd_form_document->radio_sides_one, 0);
2144 fl_set_button(fd_form_document->radio_sides_two, 0);
2146 if (params->sides == 2)
2147 fl_set_button(fd_form_document->radio_sides_two, 1);
2149 fl_set_button(fd_form_document->radio_sides_one, 1);
2151 fl_set_button(fd_form_document->radio_columns_one, 0);
2152 fl_set_button(fd_form_document->radio_columns_two, 0);
2154 if (params->columns == 2)
2155 fl_set_button(fd_form_document->radio_columns_two, 1);
2157 fl_set_button(fd_form_document->radio_columns_one, 1);
2159 fl_set_input(fd_form_document->input_spacing, "");
2160 switch (params->spacing.getSpace()) {
2161 case Spacing::Single:
2164 fl_set_choice(fd_form_document->choice_spacing, 1);
2167 case Spacing::Onehalf:
2170 fl_set_choice(fd_form_document->choice_spacing, 2);
2173 case Spacing::Double:
2176 fl_set_choice(fd_form_document->choice_spacing, 3);
2179 case Spacing::Other:
2181 fl_set_choice(fd_form_document->choice_spacing, 4);
2183 sprintf(sval, "%g", params->spacing.getValue());
2184 fl_set_input(fd_form_document->input_spacing, sval);
2190 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2191 params->secnumdepth);
2192 fl_set_counter_value(fd_form_document->slider_tocdepth,
2194 if (!params->float_placement.empty()) { // buffer local (Lgb)
2195 fl_set_input(fd_form_document->input_float_placement,
2196 params->float_placement.c_str());
2198 fl_set_input(fd_form_document->input_float_placement, "");
2200 if (!params->options.empty())
2201 fl_set_input(fd_form_document->input_extra,
2202 params->options.c_str());
2204 fl_set_input(fd_form_document->input_extra, "");
2206 if (current_view->buffer()->isSGML()) {
2207 // bullets not used in SGML derived documents
2208 fl_deactivate_object(fd_form_document->button_bullets);
2209 fl_set_object_lcol(fd_form_document->button_bullets,
2212 fl_activate_object(fd_form_document->button_bullets);
2213 fl_set_object_lcol(fd_form_document->button_bullets,
2217 if (current_view->buffer()->isReadonly()) {
2218 DisableDocumentLayout();
2220 EnableDocumentLayout();
2227 void MenuLayoutDocument()
2229 if (UpdateLayoutDocument()) {
2230 if (fd_form_document->form_document->visible) {
2231 fl_raise_form(fd_form_document->form_document);
2233 fl_show_form(fd_form_document->form_document,
2234 FL_PLACE_MOUSE, FL_FULLBORDER,
2235 _("Document Layout"));
2241 bool UpdateLayoutQuotes()
2244 if (!current_view->getScreen()
2245 || !current_view->available()
2246 || current_view->buffer()->isReadonly())
2250 fl_set_choice(fd_form_quotes->choice_quotes_language,
2251 current_view->buffer()->params.quotes_language + 1);
2252 fl_set_button(fd_form_quotes->radio_single, 0);
2253 fl_set_button(fd_form_quotes->radio_double, 0);
2255 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
2256 fl_set_button(fd_form_quotes->radio_single, 1);
2258 fl_set_button(fd_form_quotes->radio_double, 1);
2259 } else if (fd_form_quotes->form_quotes->visible) {
2260 fl_hide_form(fd_form_quotes->form_quotes);
2266 void MenuLayoutQuotes()
2268 if (UpdateLayoutQuotes()) {
2269 if (fd_form_quotes->form_quotes->visible) {
2270 fl_raise_form(fd_form_quotes->form_quotes);
2272 fl_show_form(fd_form_quotes->form_quotes,
2273 FL_PLACE_MOUSE, FL_FULLBORDER,
2280 bool UpdateLayoutPreamble()
2283 if (!current_view->getScreen() || ! current_view->available())
2287 fl_set_input(fd_form_preamble->input_preamble,
2288 current_view->buffer()->params.preamble.c_str());
2290 if (current_view->buffer()->isReadonly()) {
2291 fl_deactivate_object(fd_form_preamble->input_preamble);
2292 fl_deactivate_object(fd_form_preamble->button_ok);
2293 fl_deactivate_object(fd_form_preamble->button_apply);
2294 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
2295 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2298 fl_activate_object(fd_form_preamble->input_preamble);
2299 fl_activate_object(fd_form_preamble->button_ok);
2300 fl_activate_object(fd_form_preamble->button_apply);
2301 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2302 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2304 } else if (fd_form_preamble->form_preamble->visible) {
2305 fl_hide_form(fd_form_preamble->form_preamble);
2310 void MenuLayoutPreamble()
2312 static int ow = -1, oh;
2314 if (UpdateLayoutPreamble()) {
2315 if (fd_form_preamble->form_preamble->visible) {
2316 fl_raise_form(fd_form_preamble->form_preamble);
2318 fl_show_form(fd_form_preamble->form_preamble,
2319 FL_PLACE_MOUSE | FL_FREE_SIZE,
2321 _("LaTeX Preamble"));
2323 ow = fd_form_preamble->form_preamble->w;
2324 oh = fd_form_preamble->form_preamble->h;
2326 fl_set_form_minsize(fd_form_preamble->form_preamble,
2333 void MenuLayoutSave()
2335 if (!current_view->getScreen() || ! current_view->available())
2338 if (AskQuestion(_("Do you want to save the current settings"),
2339 _("for Character, Document, Paper and Quotes"),
2340 _("as default for new documents?")))
2341 current_view->buffer()->saveParamsAsDefaults();
2345 // candidate for move to BufferView
2348 InsetInfo * new_inset = new InsetInfo();
2349 current_view->buffer()->insertInset(new_inset);
2350 new_inset->Edit(0, 0);
2354 // candidate for move to BufferView
2357 if (current_view->available()) {
2358 minibuffer->Set(_("Open/Close..."));
2359 current_view->getScreen()->HideCursor();
2362 current_view->update(-2);
2363 current_view->text->OpenStuff();
2364 current_view->update(0);
2366 current_view->buffer()->update(-2);
2367 current_view->buffer()->text->OpenStuff();
2368 current_view->buffer()->update(0);
2374 // candidate for move to BufferView
2377 if (current_view->available()) {
2378 minibuffer->Set(_("Open/Close..."));
2379 current_view->getScreen()->HideCursor();
2382 current_view->update(-2);
2383 current_view->text->ToggleFootnote();
2384 current_view->update(0);
2386 current_view->buffer()->update(-2);
2387 current_view->buffer()->text->ToggleFootnote();
2388 current_view->buffer()->update(0);
2394 // candidate for move to BufferView
2397 /* if (current_view->buffer()->the_locking_inset) {
2398 minibuffer->Set(_("Undo not yet supported in math mode"));
2402 if (current_view->available()) {
2403 minibuffer->Set(_("Undo"));
2404 current_view->getScreen()->HideCursor();
2407 current_view->update(-2);
2408 if (!current_view->text->TextUndo())
2409 minibuffer->Set(_("No further undo information"));
2411 current_view->update(-1);
2413 current_view->buffer()->update(-2);
2414 if (!current_view->buffer()->text->TextUndo())
2415 minibuffer->Set(_("No further undo information"));
2417 current_view->buffer()->update(-1);
2423 // candidate for move to BufferView
2426 if (current_view->buffer()->the_locking_inset) {
2427 minibuffer->Set(_("Redo not yet supported in math mode"));
2431 if (current_view->available()) {
2432 minibuffer->Set(_("Redo"));
2433 current_view->getScreen()->HideCursor();
2436 current_view->update(-2);
2437 if (!current_view->text->TextRedo())
2438 minibuffer->Set(_("No further redo information"));
2440 current_view->update(-1);
2442 current_view->buffer()->update(-2);
2443 if (!current_view->buffer()->text->TextRedo())
2444 minibuffer->Set(_("No further redo information"));
2446 current_view->buffer()->update(-1);
2452 // candidate for move to BufferView
2453 void HyphenationPoint()
2455 if (current_view->available()) {
2456 current_view->getScreen()->HideCursor();
2458 current_view->update(-2);
2460 current_view->buffer()->update(-2);
2462 InsetSpecialChar * new_inset =
2463 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2464 current_view->buffer()->insertInset(new_inset);
2469 // candidate for move to BufferView
2472 if (current_view->available()) {
2473 current_view->getScreen()->HideCursor();
2475 current_view->update(-2);
2477 current_view->buffer()->update(-2);
2479 InsetSpecialChar * new_inset =
2480 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2481 current_view->buffer()->insertInset(new_inset);
2486 // candidate for move to BufferView
2487 void EndOfSentenceDot()
2489 if (current_view->available()) {
2490 current_view->getScreen()->HideCursor();
2492 current_view->update(-2);
2494 current_view->buffer()->update(-2);
2496 InsetSpecialChar * new_inset =
2497 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2498 current_view->buffer()->insertInset(new_inset);
2503 // candidate for move to BufferView
2504 void MenuSeparator()
2506 if (current_view->available()) {
2507 current_view->getScreen()->HideCursor();
2509 current_view->update(-2);
2511 current_view->buffer()->update(-2);
2513 InsetSpecialChar * new_inset =
2514 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2515 current_view->buffer()->insertInset(new_inset);
2520 // candidate for move to BufferView
2523 if (current_view->available()) {
2524 current_view->getScreen()->HideCursor();
2526 current_view->update(-2);
2527 current_view->text->InsertChar(LyXParagraph::META_NEWLINE);
2528 current_view->update(-1);
2530 current_view->buffer()->update(-2);
2531 current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE);
2532 current_view->buffer()->update(-1);
2538 // candidate for move to BufferView
2539 void ProtectedBlank()
2541 if (current_view->available()) {
2542 current_view->getScreen()->HideCursor();
2544 current_view->update(-2);
2545 current_view->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2546 current_view->update(-1);
2548 current_view->buffer()->update(-2);
2549 current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR);
2550 current_view->buffer()->update(-1);
2556 // candidate for move to BufferView
2559 if (current_view->available()) {
2560 current_view->getScreen()->HideCursor();
2562 current_view->update(-2);
2563 current_view->text->InsertChar(LyXParagraph::META_HFILL);
2564 current_view->update(-1);
2566 current_view->buffer()->update(-2);
2567 current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL);
2568 current_view->buffer()->update(-1);
2574 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2575 They also show the current font state. */
2578 void ToggleAndShow(LyXFont const &);
2581 void FontSizeCB(string const & size)
2583 LyXFont font(LyXFont::ALL_IGNORE);
2584 font.setGUISize(size);
2585 ToggleAndShow(font);
2591 LyXFont font(LyXFont::ALL_IGNORE);
2592 font.setEmph(LyXFont::TOGGLE);
2593 ToggleAndShow(font);
2599 LyXFont font(LyXFont::ALL_IGNORE);
2600 font.setNoun(LyXFont::TOGGLE);
2601 ToggleAndShow(font);
2607 LyXFont font(LyXFont::ALL_IGNORE);
2608 font.setSeries(LyXFont::BOLD_SERIES);
2609 ToggleAndShow(font);
2615 LyXFont font(LyXFont::ALL_IGNORE);
2616 font.setUnderbar(LyXFont::TOGGLE);
2617 ToggleAndShow(font);
2623 LyXFont font(LyXFont::ALL_IGNORE);
2624 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2625 ToggleAndShow(font);
2631 LyXFont font(LyXFont::ALL_IGNORE);
2632 font.setFamily(LyXFont::SANS_FAMILY);
2633 ToggleAndShow(font);
2639 LyXFont font(LyXFont::ALL_IGNORE);
2640 font.setFamily(LyXFont::ROMAN_FAMILY);
2641 ToggleAndShow(font);
2647 LyXFont font(LyXFont::ALL_IGNORE);
2648 font.setLatex (LyXFont::TOGGLE);
2649 ToggleAndShow(font);
2655 LyXFont font(LyXFont::ALL_INHERIT);
2656 ToggleAndShow(font);
2660 /* -------> Returns the current font and depth by printing a message. In the
2661 * future perhaps we could try to implement a callback to the button-bar.
2662 * That is, `light' the bold button when the font is currently bold, etc.
2665 string CurrentState()
2668 if (current_view->available()) {
2669 // I think we should only show changes from the default
2671 Buffer * buffer = current_view->buffer();
2672 LyXFont font = current_view->text->real_current_font;
2673 LyXFont defaultfont = textclasslist.TextClass(buffer->
2674 params.textclass).defaultfont();
2675 font.reduce(defaultfont);
2676 state = _("Font: ") + font.stateText();
2678 int depth = current_view->text->GetDepth();
2680 state += string(_(", Depth: ")) + tostr(depth);
2685 string CurrentState()
2688 if (current_view->available()) {
2689 // I think we should only show changes from the default
2691 Buffer * buffer = current_view->buffer();
2692 LyXFont font = buffer->text->real_current_font;
2693 LyXFont defaultfont = textclasslist.TextClass(buffer->
2694 params.textclass).defaultfont();
2695 font.reduce(defaultfont);
2696 state = _("Font: ") + font.stateText();
2698 int depth = buffer->text->GetDepth();
2700 state += string(_(", Depth: ")) + tostr(depth);
2706 // candidate for move to BufferView
2707 /* -------> Does the actual toggle job of the XxxCB() calls above.
2708 * Also shows the current font state.
2711 void ToggleAndShow(LyXFont const & font)
2713 if (current_view->available()) {
2714 current_view->getScreen()->HideCursor();
2716 current_view->update(-2);
2717 current_view->text->ToggleFree(font, toggleall);
2718 current_view->update(1);
2720 current_view->buffer()->update(-2);
2721 current_view->buffer()->text->ToggleFree(font, toggleall);
2722 current_view->buffer()->update(1);
2725 // removed since it overrides the ToggleFree Message about the style
2726 // Since Styles are more "High Level" than raw fonts I think the user
2727 // prefers it like this Matthias
2728 // FontStateShowCB( 0, 0 );
2732 // candidate for move to BufferView
2733 extern "C" void MarginCB(FL_OBJECT *, long)
2735 if (current_view->available()) {
2736 minibuffer->Set(_("Inserting margin note..."));
2737 current_view->getScreen()->HideCursor();
2739 current_view->update(-2);
2740 current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2741 current_view->update(1);
2743 current_view->buffer()->update(-2);
2744 current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2745 current_view->buffer()->update(1);
2751 extern "C" void FigureCB(FL_OBJECT *, long)
2753 if (fd_form_figure->form_figure->visible) {
2754 fl_raise_form(fd_form_figure->form_figure);
2756 fl_show_form(fd_form_figure->form_figure,
2757 FL_PLACE_MOUSE, FL_FULLBORDER,
2758 _("Insert Figure"));
2763 extern "C" void TableCB(FL_OBJECT *, long)
2765 if (fd_form_table->form_table->visible) {
2766 fl_raise_form(fd_form_table->form_table);
2768 fl_show_form(fd_form_table->form_table,
2769 FL_PLACE_MOUSE, FL_FULLBORDER,
2775 // candidate for move to BufferView
2776 void CopyEnvironmentCB()
2778 if (current_view->available()) {
2780 current_view->text->copyEnvironmentType();
2781 /* clear the selection, even if mark_set */
2782 current_view->getScreen()->ToggleSelection();
2783 current_view->text->ClearSelection();
2784 current_view->update(-2);
2785 minibuffer->Set(_("Paragraph environment type copied"));
2787 current_view->buffer()->text->copyEnvironmentType();
2788 /* clear the selection, even if mark_set */
2789 current_view->getScreen()->ToggleSelection();
2790 current_view->buffer()->text->ClearSelection();
2791 current_view->buffer()->update(-2);
2792 minibuffer->Set(_("Paragraph environment type copied"));
2798 // candidate for move to BufferView
2799 void PasteEnvironmentCB()
2801 if (current_view->available()) {
2803 current_view->text->pasteEnvironmentType();
2804 minibuffer->Set(_("Paragraph environment type set"));
2805 current_view->update(1);
2807 current_view->buffer()->text->pasteEnvironmentType();
2808 minibuffer->Set(_("Paragraph environment type set"));
2809 current_view->buffer()->update(1);
2815 // candidate for move to BufferView
2818 if (current_view->available()) {
2820 current_view->text->CopySelection();
2821 /* clear the selection, even if mark_set */
2822 current_view->getScreen()->ToggleSelection();
2823 current_view->text->ClearSelection();
2824 current_view->update(-2);
2825 minibuffer->Set(_("Copy"));
2827 current_view->buffer()->text->CopySelection();
2828 /* clear the selection, even if mark_set */
2829 current_view->getScreen()->ToggleSelection();
2830 current_view->buffer()->text->ClearSelection();
2831 current_view->buffer()->update(-2);
2832 minibuffer->Set(_("Copy"));
2838 // candidate for move to BufferView
2841 if (current_view->available()) {
2842 current_view->getScreen()->HideCursor();
2844 current_view->update(-2);
2845 current_view->text->CutSelection();
2846 current_view->update(1);
2848 current_view->buffer()->update(-2);
2849 current_view->buffer()->text->CutSelection();
2850 current_view->buffer()->update(1);
2852 minibuffer->Set(_("Cut"));
2857 // candidate for move to BufferView
2860 if (!current_view->available()) return;
2862 minibuffer->Set(_("Paste"));
2863 current_view->getScreen()->HideCursor();
2864 /* clear the selection */
2866 current_view->getScreen()->ToggleSelection();
2867 current_view->text->ClearSelection();
2868 current_view->update(-2);
2871 current_view->text->PasteSelection();
2872 current_view->update(1);
2874 /* clear the selection */
2875 current_view->getScreen()->ToggleSelection();
2876 current_view->text->ClearSelection();
2877 current_view->update(-2);
2879 current_view->getScreen()->ToggleSelection();
2880 current_view->buffer()->text->ClearSelection();
2881 current_view->buffer()->update(-2);
2884 current_view->buffer()->text->PasteSelection();
2885 current_view->buffer()->update(1);
2887 /* clear the selection */
2888 current_view->getScreen()->ToggleSelection();
2889 current_view->buffer()->text->ClearSelection();
2890 current_view->buffer()->update(-2);
2895 // candidate for move to BufferView
2896 extern "C" void MeltCB(FL_OBJECT *, long)
2898 if (!current_view->available()) return;
2900 minibuffer->Set(_("Melt"));
2901 current_view->getScreen()->HideCursor();
2904 current_view->update(-2);
2905 current_view->text->MeltFootnoteEnvironment();
2906 current_view->update(1);
2908 current_view->buffer()->update(-2);
2909 current_view->buffer()->text->MeltFootnoteEnvironment();
2910 current_view->buffer()->update(1);
2915 // candidate for move to BufferView
2916 // Change environment depth.
2917 // if decInc == 0, depth change taking mouse button number into account
2918 // if decInc == 1, increment depth
2919 // if decInc == -1, decrement depth
2920 extern "C" void DepthCB(FL_OBJECT * ob, long decInc)
2924 /* When decInc != 0, fake a mouse button. This allows us to
2925 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2926 /* check out wether ob is defined, too (Matthias) */
2929 else if (!decInc && ob) {
2930 button = fl_get_button_numb(ob);
2933 if (current_view->available()) {
2934 current_view->getScreen()->HideCursor();
2936 current_view->update(-2);
2938 current_view->text->IncDepth();
2940 current_view->text->DecDepth();
2941 current_view->update(1);
2943 current_view->buffer()->update(-2);
2945 current_view->buffer()->text->IncDepth();
2947 current_view->buffer()->text->DecDepth();
2948 current_view->buffer()->update(1);
2950 minibuffer->Set(_("Changed environment depth"
2951 " (in possible range, maybe not)"));
2956 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2957 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2958 LyXFont UserFreeFont()
2960 LyXFont font(LyXFont::ALL_IGNORE);
2962 int pos = fl_get_choice(fd_form_character->choice_family);
2964 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2965 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2966 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2967 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2968 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2971 pos = fl_get_choice(fd_form_character->choice_series);
2973 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2974 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2975 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2976 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2979 pos = fl_get_choice(fd_form_character->choice_shape);
2981 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2982 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2983 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2984 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2985 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2986 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2989 pos = fl_get_choice(fd_form_character->choice_size);
2991 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2992 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2993 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2994 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2995 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2996 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2997 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2998 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2999 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
3000 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
3001 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
3002 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
3003 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
3004 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
3007 pos = fl_get_choice(fd_form_character->choice_bar);
3009 case 1: font.setEmph(LyXFont::IGNORE);
3010 font.setUnderbar(LyXFont::IGNORE);
3011 font.setNoun(LyXFont::IGNORE);
3012 font.setLatex(LyXFont::IGNORE);
3014 case 2: font.setEmph(LyXFont::TOGGLE); break;
3015 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
3016 case 4: font.setNoun(LyXFont::TOGGLE); break;
3017 case 5: font.setLatex(LyXFont::TOGGLE); break;
3018 case 6: font.setEmph(LyXFont::INHERIT);
3019 font.setUnderbar(LyXFont::INHERIT);
3020 font.setNoun(LyXFont::INHERIT);
3021 font.setLatex(LyXFont::INHERIT);
3025 pos = fl_get_choice(fd_form_character->choice_color);
3027 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
3028 case 2: font.setColor(LyXFont::NONE); break;
3029 case 3: font.setColor(LyXFont::BLACK); break;
3030 case 4: font.setColor(LyXFont::WHITE); break;
3031 case 5: font.setColor(LyXFont::RED); break;
3032 case 6: font.setColor(LyXFont::GREEN); break;
3033 case 7: font.setColor(LyXFont::BLUE); break;
3034 case 8: font.setColor(LyXFont::CYAN); break;
3035 case 9: font.setColor(LyXFont::MAGENTA); break;
3036 case 10: font.setColor(LyXFont::YELLOW); break;
3037 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
3046 ToggleAndShow(UserFreeFont());
3050 /* callbacks for form form_title */
3051 extern "C" void TimerCB(FL_OBJECT *, long)
3053 // only if the form still exists
3054 if (fd_form_title->form_title != 0) {
3055 if (fd_form_title->form_title->visible) {
3056 fl_hide_form(fd_form_title->form_title);
3058 fl_free_form(fd_form_title->form_title);
3059 fd_form_title->form_title = 0;
3064 /* callbacks for form form_paragraph */
3066 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
3068 // "Synchronize" the choices and input fields, making it
3069 // impossible to commit senseless data.
3071 FD_form_paragraph const * fp = fd_form_paragraph;
3073 if (obj == fp->choice_space_above) {
3074 if (fl_get_choice (fp->choice_space_above) != 7) {
3075 fl_set_input (fp->input_space_above, "");
3076 ActivateParagraphButtons();
3078 } else if (obj == fp->choice_space_below) {
3079 if (fl_get_choice (fp->choice_space_below) != 7) {
3080 fl_set_input (fp->input_space_below, "");
3081 ActivateParagraphButtons();
3083 } else if (obj == fp->input_space_above) {
3084 string input = fl_get_input (fp->input_space_above);
3086 if (input.empty()) {
3087 fl_set_choice (fp->choice_space_above, 1);
3088 ActivateParagraphButtons();
3090 else if (isValidGlueLength (input)) {
3091 fl_set_choice (fp->choice_space_above, 7);
3092 ActivateParagraphButtons();
3095 fl_set_choice (fp->choice_space_above, 7);
3096 DeactivateParagraphButtons();
3098 } else if (obj == fp->input_space_below) {
3099 string input = fl_get_input (fp->input_space_below);
3101 if (input.empty()) {
3102 fl_set_choice (fp->choice_space_below, 1);
3103 ActivateParagraphButtons();
3105 else if (isValidGlueLength (input)) {
3106 fl_set_choice (fp->choice_space_below, 7);
3107 ActivateParagraphButtons();
3110 fl_set_choice (fp->choice_space_below, 7);
3111 DeactivateParagraphButtons();
3117 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
3119 if (!current_view->available())
3122 VSpace space_top, space_bottom;
3124 string labelwidthstring;
3127 // If a vspace kind is "Length" but there's no text in
3128 // the input field, reset the kind to "None".
3129 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
3130 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
3131 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
3133 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
3134 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
3135 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
3138 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
3139 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
3140 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
3141 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
3142 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
3143 case 1: space_top = VSpace(VSpace::NONE); break;
3144 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
3145 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
3146 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
3147 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
3148 case 6: space_top = VSpace(VSpace::VFILL); break;
3149 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
3151 if (fl_get_button (fd_form_paragraph->check_space_above))
3152 space_top.setKeep (true);
3153 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
3154 case 1: space_bottom = VSpace(VSpace::NONE); break;
3155 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
3156 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
3157 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
3158 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
3159 case 6: space_bottom = VSpace(VSpace::VFILL); break;
3160 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
3162 if (fl_get_button (fd_form_paragraph->check_space_below))
3163 space_bottom.setKeep (true);
3165 if (fl_get_button(fd_form_paragraph->radio_align_left))
3166 align = LYX_ALIGN_LEFT;
3167 else if (fl_get_button(fd_form_paragraph->radio_align_right))
3168 align = LYX_ALIGN_RIGHT;
3169 else if (fl_get_button(fd_form_paragraph->radio_align_center))
3170 align = LYX_ALIGN_CENTER;
3172 align = LYX_ALIGN_BLOCK;
3174 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
3175 noindent = fl_get_button(fd_form_paragraph->check_noindent);
3178 current_view->text->SetParagraph(line_top,
3187 current_view->update(1);
3189 current_view->buffer()->text->SetParagraph(line_top,
3198 current_view->buffer()->update(1);
3200 minibuffer->Set(_("Paragraph layout set"));
3204 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
3206 fl_hide_form(fd_form_paragraph->form_paragraph);
3210 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
3212 ParagraphApplyCB(ob, data);
3213 ParagraphCancelCB(ob, data);
3217 /* callbacks for form form_character */
3219 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
3221 // we set toggleall locally here, since it should be true for
3222 // all other uses of ToggleAndShow() (JMarc)
3223 toggleall = fl_get_button(fd_form_character->check_toggle_all);
3224 ToggleAndShow( UserFreeFont());
3229 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
3231 fl_hide_form(fd_form_character->form_character);
3235 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
3237 CharacterApplyCB(ob, data);
3238 CharacterCloseCB(ob, data);
3242 /* callbacks for form form_document */
3244 void UpdateDocumentButtons(BufferParams const & params)
3246 fl_set_choice(fd_form_document->choice_pagestyle, 1);
3248 if (params.sides == 2)
3249 fl_set_button(fd_form_document->radio_sides_two, 1);
3251 fl_set_button(fd_form_document->radio_sides_one, 1);
3253 if (params.columns == 2)
3254 fl_set_button(fd_form_document->radio_columns_two, 1);
3256 fl_set_button(fd_form_document->radio_columns_one, 1);
3258 fl_set_input(fd_form_document->input_extra, params.options.c_str());
3259 fl_set_counter_value(fd_form_document->slider_secnumdepth,
3260 params.secnumdepth);
3261 fl_set_counter_value(fd_form_document->slider_tocdepth,
3266 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
3269 if (textclasslist.Load(fl_get_choice(ob)-1)) {
3270 if (AskQuestion(_("Should I set some parameters to"),
3271 fl_get_choice_text(ob),
3272 _("the defaults of this document class?"))) {
3273 BufferParams params = BufferParams();
3274 params.textclass = fl_get_choice(ob)-1;
3275 params.useClassDefaults();
3276 UpdateLayoutDocument(¶ms);
3277 UpdateDocumentButtons(params);
3280 // unable to load new style
3281 WriteAlert(_("Conversion Errors!"),
3282 _("Unable to switch to new document class."),
3283 _("Reverting to original document class."));
3284 fl_set_choice(fd_form_document->choice_class,
3285 GetCurrentTextClass() + 1);
3291 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
3293 // "Synchronize" the choice and the input field, so that it
3294 // is impossible to commit senseless data.
3295 FD_form_document const * fd = fd_form_document;
3297 if (obj == fd->choice_default_skip) {
3298 if (fl_get_choice (fd->choice_default_skip) != 4) {
3299 fl_set_input (fd->input_default_skip, "");
3300 ActivateDocumentButtons();
3302 } else if (obj == fd->input_default_skip) {
3304 char const * input = fl_get_input (fd->input_default_skip);
3307 fl_set_choice (fd->choice_default_skip, 2);
3308 ActivateDocumentButtons();
3309 } else if (isValidGlueLength (input)) {
3310 fl_set_choice (fd->choice_default_skip, 4);
3311 ActivateDocumentButtons();
3313 fl_set_choice (fd->choice_default_skip, 4);
3314 DeactivateDocumentButtons();
3320 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
3322 // "Synchronize" the choice and the input field, so that it
3323 // is impossible to commit senseless data.
3324 FD_form_document const * fd = fd_form_document;
3326 if (obj == fd->choice_spacing
3327 && fl_get_choice (fd->choice_spacing) != 4) {
3328 fl_set_input(fd->input_spacing, "");
3329 } else if (obj == fd->input_spacing) {
3331 const char* input = fl_get_input (fd->input_spacing);
3334 fl_set_choice (fd->choice_spacing, 1);
3336 fl_set_choice (fd->choice_spacing, 4);
3342 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
3345 BufferParams *params = &(current_view->buffer()->params);
3346 current_view->buffer()->params.language =
3347 combo_language->getline();
3349 // If default skip is a "Length" but there's no text in the
3350 // input field, reset the kind to "Medskip", which is the default.
3351 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
3352 && !*(fl_get_input (fd_form_document->input_default_skip))) {
3353 fl_set_choice (fd_form_document->choice_default_skip, 2);
3356 /* this shouldn't be done automatically IMO. For example I write german
3357 * documents with an american keyboard very often. Matthias */
3359 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
3360 fl_get_choice(fd_form_document->choice_language)); */
3362 fl_get_choice_text(fd_form_document->choice_fonts);
3364 fl_get_choice_text(fd_form_document->choice_inputenc);
3366 fl_get_choice_text(fd_form_document->choice_fontsize);
3368 fl_get_choice_text(fd_form_document->choice_pagestyle);
3369 params->graphicsDriver =
3370 fl_get_choice_text(fd_form_document->choice_postscript_driver);
3371 params->use_amsmath =
3372 fl_get_button(fd_form_document->check_use_amsmath);
3374 if (!current_view->available())
3377 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
3378 if (params->textclass != new_class) {
3379 // try to load new_class
3380 if (textclasslist.Load(new_class)) {
3381 // successfully loaded
3383 minibuffer->Set(_("Converting document to new document class..."));
3385 int ret = current_view->text->
3386 SwitchLayoutsBetweenClasses(current_view->buffer()->
3389 current_view->buffer()->
3392 int ret = current_view->buffer()->
3394 SwitchLayoutsBetweenClasses(current_view->buffer()->
3397 current_view->buffer()->
3404 s = _("One paragraph couldn't be converted");
3407 s += _(" paragraphs couldn't be converted");
3409 WriteAlert(_("Conversion Errors!"), s,
3410 _("into chosen document class"));
3413 params->textclass = new_class;
3415 // problem changing class -- warn user and retain old style
3416 WriteAlert(_("Conversion Errors!"),
3417 _("Unable to switch to new document class."),
3418 _("Reverting to original document class."));
3419 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
3423 char tmpsep = params->paragraph_separation;
3424 if (fl_get_button(fd_form_document->radio_indent))
3425 params->paragraph_separation = BufferParams::PARSEP_INDENT;
3427 params->paragraph_separation = BufferParams::PARSEP_SKIP;
3428 if (tmpsep != params->paragraph_separation)
3431 VSpace tmpdefskip = params->getDefSkip();
3432 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
3433 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
3434 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3435 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
3436 case 4: params->setDefSkip(
3437 VSpace (LyXGlueLength (fl_get_input
3438 (fd_form_document->input_default_skip))));
3440 // DocumentDefskipCB assures that this never happens
3441 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
3443 if (!(tmpdefskip == params->getDefSkip()))
3446 if (fl_get_button(fd_form_document->radio_columns_two))
3447 params->columns = 2;
3449 params->columns = 1;
3450 if (fl_get_button(fd_form_document->radio_sides_two))
3451 params->sides = LyXTextClass::TwoSides;
3453 params->sides = LyXTextClass::OneSide;
3455 Spacing tmpSpacing = params->spacing;
3456 switch(fl_get_choice(fd_form_document->choice_spacing)) {
3458 lyxerr.debug() << "Spacing: SINGLE" << endl;
3459 params->spacing.set(Spacing::Single);
3462 lyxerr.debug() << "Spacing: ONEHALF" << endl;
3463 params->spacing.set(Spacing::Onehalf);
3466 lyxerr.debug() << "Spacing: DOUBLE" << endl;
3467 params->spacing.set(Spacing::Double);
3470 lyxerr.debug() << "Spacing: OTHER" << endl;
3471 params->spacing.set(Spacing::Other,
3472 fl_get_input(fd_form_document->input_spacing));
3475 if (tmpSpacing != params->spacing)
3478 signed char tmpchar =
3479 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
3480 if (params->secnumdepth != tmpchar)
3482 params->secnumdepth = tmpchar;
3485 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
3487 params->float_placement =
3488 fl_get_input(fd_form_document->input_float_placement);
3490 // More checking should be done to ensure the string doesn't have
3491 // spaces or illegal placement characters in it. (thornley)
3494 current_view->redoCurrentBuffer();
3496 minibuffer->Set(_("Document layout set"));
3497 current_view->buffer()->markDirty();
3500 fl_get_input(fd_form_document->input_extra);
3505 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3507 fl_hide_form(fd_form_document->form_document);
3511 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
3513 DocumentCancelCB(ob, data);
3514 DocumentApplyCB(ob, data);
3518 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3521 // bullet callbacks etc. in bullet_panel.C -- ARRae
3525 // candidate for move to BufferView
3529 if (!current_view->getScreen())
3532 current_view->getScreen()->HideCursor();
3534 current_view->update(-2);
3537 if (!current_view->text->GotoNextNote()) {
3538 if (current_view->text->cursor.pos
3539 || current_view->text->cursor.par !=
3540 current_view->text->FirstParagraph())
3542 tmp = current_view->text->cursor;
3543 current_view->text->cursor.par =
3544 current_view->text->FirstParagraph();
3545 current_view->text->cursor.pos = 0;
3546 if (!current_view->text->GotoNextNote()) {
3547 current_view->text->cursor = tmp;
3548 minibuffer->Set(_("No more notes"));
3552 minibuffer->Set(_("No more notes"));
3556 current_view->update(0);
3557 current_view->text->sel_cursor =
3558 current_view->text->cursor;
3563 if (!current_view->getScreen())
3566 current_view->getScreen()->HideCursor();
3568 current_view->buffer()->update(-2);
3571 if (!current_view->buffer()->text->GotoNextNote()) {
3572 if (current_view->buffer()->text->cursor.pos
3573 || current_view->buffer()->text->cursor.par !=
3574 current_view->buffer()->text->FirstParagraph())
3576 tmp = current_view->buffer()->text->cursor;
3577 current_view->buffer()->text->cursor.par =
3578 current_view->buffer()->text->FirstParagraph();
3579 current_view->buffer()->text->cursor.pos = 0;
3580 if (!current_view->buffer()->text->GotoNextNote()) {
3581 current_view->buffer()->text->cursor = tmp;
3582 minibuffer->Set(_("No more notes"));
3586 minibuffer->Set(_("No more notes"));
3590 current_view->buffer()->update(0);
3591 current_view->buffer()->text->sel_cursor =
3592 current_view->buffer()->text->cursor;
3596 // candidate for move to BufferView
3597 void InsertCorrectQuote()
3599 Buffer * cbuffer = current_view->buffer();
3603 if (current_view->text->cursor.pos )
3604 c = current_view->text->cursor.par->GetChar(current_view->text->cursor.pos - 1);
3608 if (cbuffer->text->cursor.pos )
3609 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3614 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3618 /* callbacks for form form_quotes */
3620 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3622 if (!current_view->available())
3625 minibuffer->Set(_("Quotes type set"));
3626 //current_view->buffer()->params.quotes_language =
3627 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3628 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3629 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3631 lga = InsetQuotes::EnglishQ;
3634 lga = InsetQuotes::SwedishQ;
3637 lga = InsetQuotes::GermanQ;
3640 lga = InsetQuotes::PolishQ;
3643 lga = InsetQuotes::FrenchQ;
3646 lga = InsetQuotes::DanishQ;
3649 current_view->buffer()->params.quotes_language = lga;
3650 if (fl_get_button(fd_form_quotes->radio_single))
3651 current_view->buffer()->
3652 params.quotes_times = InsetQuotes::SingleQ;
3654 current_view->buffer()->
3655 params.quotes_times = InsetQuotes::DoubleQ;
3659 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3661 fl_hide_form(fd_form_quotes->form_quotes);
3665 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
3667 QuotesApplyCB(ob, data);
3668 QuotesCancelCB(ob, data);
3673 /* callbacks for form form_preamble */
3675 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3677 fl_hide_form(fd_form_preamble->form_preamble);
3681 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3683 if (!current_view->available())
3686 current_view->buffer()->params.preamble =
3687 fl_get_input(fd_form_preamble->input_preamble);
3688 current_view->buffer()->markDirty();
3689 minibuffer->Set(_("LaTeX preamble set"));
3693 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
3695 PreambleApplyCB(ob, data);
3696 PreambleCancelCB(ob, data);
3700 /* callbacks for form form_table */
3703 extern "C" void TableApplyCB(FL_OBJECT *, long)
3705 if (!current_view->getScreen())
3708 // check for tables in tables
3709 if (current_view->text->cursor.par->table){
3710 WriteAlert(_("Impossible Operation!"),
3711 _("Cannot insert table in table."),
3716 minibuffer->Set(_("Inserting table..."));
3718 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3719 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3722 current_view->getScreen()->HideCursor();
3724 current_view->update(-2);
3726 current_view->text->SetCursorParUndo();
3727 current_view->text->FreezeUndo();
3729 current_view->text->BreakParagraph();
3730 current_view->update(-1);
3732 if (current_view->text->cursor.par->Last()) {
3733 current_view->text->CursorLeft();
3735 current_view->text->BreakParagraph();
3736 current_view->update(-1);
3739 current_view->text->current_font.setLatex(LyXFont::OFF);
3740 //if (!fl_get_button(fd_form_table->check_latex)){
3741 // insert the new wysiwy table
3742 current_view->text->SetLayout(0); // standard layout
3743 if (current_view->text->cursor.par->footnoteflag ==
3744 LyXParagraph::NO_FOOTNOTE) {
3746 ->SetParagraph(0, 0,
3748 VSpace (0.3 * current_view->buffer()->
3749 params.spacing.getValue(),
3751 VSpace (0.3 * current_view->buffer()->
3752 params.spacing.getValue(),
3760 ->SetParagraph(0, 0,
3762 VSpace(VSpace::NONE),
3763 VSpace(VSpace::NONE),
3768 current_view->text->cursor.par->table =
3769 new LyXTable(xsize, ysize);
3771 for (int i = 0; i < xsize * ysize - 1; ++i)
3772 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3773 current_view->text->RedoParagraph();
3775 current_view->text->UnFreezeUndo();
3777 current_view->update(1);
3778 minibuffer->Set(_("Table inserted"));
3781 extern "C" void TableApplyCB(FL_OBJECT *, long)
3783 if (!current_view->getScreen())
3786 // check for tables in tables
3787 if (current_view->buffer()->text->cursor.par->table){
3788 WriteAlert(_("Impossible Operation!"),
3789 _("Cannot insert table in table."),
3794 minibuffer->Set(_("Inserting table..."));
3796 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3797 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3800 current_view->getScreen()->HideCursor();
3802 current_view->buffer()->update(-2);
3804 current_view->buffer()->text->SetCursorParUndo();
3805 current_view->buffer()->text->FreezeUndo();
3807 current_view->buffer()->text->BreakParagraph();
3808 current_view->buffer()->update(-1);
3810 if (current_view->buffer()->text->cursor.par->Last()) {
3811 current_view->buffer()->text->CursorLeft();
3813 current_view->buffer()->text->BreakParagraph();
3814 current_view->buffer()->update(-1);
3817 current_view->buffer()->text->current_font.setLatex(LyXFont::OFF);
3818 //if (!fl_get_button(fd_form_table->check_latex)){
3819 // insert the new wysiwy table
3820 current_view->buffer()->text->SetLayout(0); // standard layout
3821 if (current_view->buffer()->text->cursor.par->footnoteflag ==
3822 LyXParagraph::NO_FOOTNOTE) {
3823 current_view->buffer()->
3824 text->SetParagraph(0, 0,
3826 VSpace (0.3 * current_view->buffer()->
3827 params.spacing.getValue(),
3829 VSpace (0.3 * current_view->buffer()->
3830 params.spacing.getValue(),
3837 current_view->buffer()->
3838 text->SetParagraph(0, 0,
3840 VSpace(VSpace::NONE),
3841 VSpace(VSpace::NONE),
3846 current_view->buffer()->text->cursor.par->table =
3847 new LyXTable(xsize, ysize);
3849 for (int i = 0; i < xsize * ysize - 1; ++i)
3850 current_view->buffer()->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
3851 current_view->buffer()->text->RedoParagraph();
3853 current_view->buffer()->text->UnFreezeUndo();
3855 current_view->buffer()->update(1);
3856 minibuffer->Set(_("Table inserted"));
3860 extern "C" void TableCancelCB(FL_OBJECT *, long)
3862 fl_hide_form(fd_form_table->form_table);
3866 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3868 TableApplyCB(ob, data);
3869 TableCancelCB(ob, data);
3873 /* callbacks for form form_print */
3875 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3877 fl_hide_form(fd_form_print->form_print);
3880 static bool stringOnlyContains (string const & LStr, char const * cset)
3882 char const * cstr = LStr.c_str() ;
3884 return strspn(cstr, cset) == strlen(cstr) ;
3887 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3889 if (!current_view->available())
3891 Buffer * buffer = current_view->buffer();
3892 string path = OnlyPath(buffer->fileName());
3895 if (fl_get_button(fd_form_print->radio_even_pages))
3896 pageflag = lyxrc->print_evenpage_flag + ' ';
3897 else if (fl_get_button(fd_form_print->radio_odd_pages))
3898 pageflag = lyxrc->print_oddpage_flag + ' ';
3900 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3901 // User may give a page (range) list
3902 // User may print multiple (unsorted) copies
3903 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3904 pages = subst(pages, '+',',');
3905 pages = frontStrip(strip(pages)) ;
3906 while (!pages.empty()) { // a page range was given
3908 pages = split (pages, piece, ',') ;
3909 piece = strip(piece) ;
3910 piece = frontStrip(piece) ;
3911 if ( !stringOnlyContains (piece, "0123456789-") ) {
3912 WriteAlert(_("ERROR! Unable to print!"),
3913 _("Check 'range of pages'!"));
3916 if (piece.find('-') == string::npos) { // not found
3917 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3918 } else if (suffixIs(piece, "-") ) { // missing last page
3919 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3920 } else if (prefixIs(piece, "-") ) { // missing first page
3921 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3923 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3927 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3928 if (!copies.empty()) { // a number of copies was given
3929 if ( !stringOnlyContains (copies, "0123456789") ) {
3930 WriteAlert(_("ERROR! Unable to print!"),
3931 _("Check 'number of copies'!"));
3934 if (fl_get_button(fd_form_print->do_unsorted))
3935 pageflag += lyxrc->print_copies_flag;
3937 pageflag += lyxrc->print_collcopies_flag;
3938 pageflag += " " + copies + ' ' ;
3942 if (fl_get_button(fd_form_print->radio_order_reverse))
3943 reverseflag = lyxrc->print_reverse_flag + ' ';
3945 string orientationflag;
3946 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3947 orientationflag = lyxrc->print_landscape_flag + ' ';
3949 string ps_file = fl_get_input(fd_form_print->input_file);
3950 string printer = strip(fl_get_input(fd_form_print->input_printer));
3953 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3954 && ! printer.empty()) // a printer name has been given
3955 printerflag = lyxrc->print_to_printer + printer + ' ';
3958 if (!lyxrc->print_extra_options.empty())
3959 extraflags = lyxrc->print_extra_options + ' ';
3961 string command = lyxrc->print_command + ' '
3962 + printerflag + pageflag + reverseflag
3963 + orientationflag + extraflags;
3965 char real_papersize = buffer->params.papersize;
3966 if (real_papersize == BufferParams::PAPER_DEFAULT)
3967 real_papersize = lyxrc->default_papersize;
3970 switch (real_papersize) {
3971 case BufferParams::PAPER_USLETTER:
3974 case BufferParams::PAPER_A3PAPER:
3977 case BufferParams::PAPER_A4PAPER:
3980 case BufferParams::PAPER_A5PAPER:
3983 case BufferParams::PAPER_B5PAPER:
3986 case BufferParams::PAPER_EXECUTIVEPAPER:
3989 case BufferParams::PAPER_LEGALPAPER:
3992 default: /* If nothing else fits, keep an empty value... */
3996 if (buffer->params.use_geometry
3997 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3998 && !lyxrc->print_paper_dimension_flag.empty()
3999 && !buffer->params.paperwidth.empty()
4000 && !buffer->params.paperheight.empty()) {
4001 // using a custom papersize
4003 command += lyxrc->print_paper_dimension_flag + ' ';
4004 command += buffer->params.paperwidth + ',';
4005 command += buffer->params.paperheight + ' ';
4006 } else if (!lyxrc->print_paper_flag.empty()
4008 && (real_papersize != BufferParams::PAPER_USLETTER ||
4009 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
4010 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
4012 if (fl_get_button(fd_form_print->radio_file))
4013 command += lyxrc->print_to_file
4014 + QuoteName(MakeAbsPath(ps_file, path));
4015 else if (!lyxrc->print_spool_command.empty())
4016 command += lyxrc->print_to_file
4017 + QuoteName(ps_file);
4019 // push directorypath, if necessary
4020 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
4021 path = buffer->tmppath;
4026 if (!lyxrc->print_spool_command.empty() &&
4027 !fl_get_button(fd_form_print->radio_file)) {
4028 string command2 = lyxrc->print_spool_command + ' ';
4029 if (!printer.empty())
4030 command2 += lyxrc->print_spool_printerprefix
4032 // First run dvips and, if succesful, then spool command
4033 if ((result = RunScript(buffer, true, command))) {
4034 result = RunScript(buffer, false, command2, ps_file);
4037 result = RunScript(buffer, false, command);
4040 WriteAlert(_("Error:"),
4041 _("Unable to print"),
4042 _("Check that your parameters are correct"));
4046 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
4048 PrintCancelCB(ob, data);
4049 PrintApplyCB(ob, data);
4053 /* callbacks for form form_figure */
4055 extern "C" void FigureApplyCB(FL_OBJECT *, long)
4057 if (!current_view->available())
4060 Buffer * buffer = current_view->buffer();
4061 if(buffer->isReadonly()) // paranoia
4064 minibuffer->Set(_("Inserting figure..."));
4065 if (fl_get_button(fd_form_figure->radio_inline)
4066 || current_view->text->cursor.par->table) {
4067 InsetFig * new_inset = new InsetFig(100, 20, buffer);
4068 buffer->insertInset(new_inset);
4069 minibuffer->Set(_("Figure inserted"));
4070 new_inset->Edit(0, 0);
4074 current_view->getScreen()->HideCursor();
4075 current_view->update(-2);
4078 current_view->text->SetCursorParUndo();
4079 current_view->text->FreezeUndo();
4081 current_view->text->BreakParagraph();
4082 current_view->update(-1);
4084 if (current_view->text->cursor.par->Last()) {
4085 current_view->text->CursorLeft();
4087 current_view->text->BreakParagraph();
4088 current_view->update(-1);
4091 // The standard layout should always be numer 0;
4092 current_view->text->SetLayout(0);
4094 if (current_view->text->cursor.par->footnoteflag ==
4095 LyXParagraph::NO_FOOTNOTE) {
4096 current_view->text->
4099 VSpace (0.3 * buffer->params.spacing.getValue(),
4102 buffer->params.spacing.getValue(),
4104 LYX_ALIGN_CENTER, string(), 0);
4106 current_view->text->SetParagraph(0, 0,
4108 VSpace(VSpace::NONE),
4109 VSpace(VSpace::NONE),
4114 current_view->update(-1);
4116 Inset * new_inset = new InsetFig(100, 100, buffer);
4117 buffer->insertInset(new_inset);
4118 new_inset->Edit(0, 0);
4119 current_view->update(0);
4120 minibuffer->Set(_("Figure inserted"));
4121 current_view->text->UnFreezeUndo();
4124 extern "C" void FigureApplyCB(FL_OBJECT *, long)
4126 if (!current_view->available())
4129 Buffer * buffer = current_view->buffer();
4130 if(buffer->isReadonly()) // paranoia
4133 minibuffer->Set(_("Inserting figure..."));
4134 if (fl_get_button(fd_form_figure->radio_inline)
4135 || buffer->text->cursor.par->table) {
4136 InsetFig * new_inset = new InsetFig(100, 20, buffer);
4137 buffer->insertInset(new_inset);
4138 minibuffer->Set(_("Figure inserted"));
4139 new_inset->Edit(0, 0);
4143 current_view->getScreen()->HideCursor();
4147 buffer->text->SetCursorParUndo();
4148 buffer->text->FreezeUndo();
4150 buffer->text->BreakParagraph();
4153 if (buffer->text->cursor.par->Last()) {
4154 buffer->text->CursorLeft();
4156 buffer->text->BreakParagraph();
4160 // The standard layout should always be numer 0;
4161 buffer->text->SetLayout(0);
4163 if (buffer->text->cursor.par->footnoteflag ==
4164 LyXParagraph::NO_FOOTNOTE) {
4168 VSpace (0.3 * buffer->params.spacing.getValue(),
4171 buffer->params.spacing.getValue(),
4173 LYX_ALIGN_CENTER, string(), 0);
4175 buffer->text->SetParagraph(0, 0,
4177 VSpace(VSpace::NONE),
4178 VSpace(VSpace::NONE),
4185 Inset * new_inset = new InsetFig(100, 100, buffer);
4186 buffer->insertInset(new_inset);
4187 new_inset->Edit(0, 0);
4189 minibuffer->Set(_("Figure inserted"));
4190 buffer->text->UnFreezeUndo();
4194 extern "C" void FigureCancelCB(FL_OBJECT *, long)
4196 fl_hide_form(fd_form_figure->form_figure);
4200 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
4202 FigureApplyCB(ob, data);
4203 FigureCancelCB(ob, data);
4207 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
4209 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
4210 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
4211 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
4212 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
4213 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
4214 fontloader.update();
4216 // All buffers will need resize
4217 bufferlist.resize();
4219 minibuffer->Set(_("Screen options set"));
4223 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
4225 fl_hide_form(fd_form_screen->form_screen);
4229 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
4231 ScreenCancelCB(ob, data);
4232 ScreenApplyCB(ob, data);
4238 if (!current_view->available())
4241 fl_set_button(fd_latex_options->accents,
4242 int(current_view->buffer()->params.allowAccents));
4244 if (fd_latex_options->LaTeXOptions->visible) {
4245 fl_raise_form(fd_latex_options->LaTeXOptions);
4247 fl_show_form(fd_latex_options->LaTeXOptions,
4248 FL_PLACE_MOUSE, FL_FULLBORDER,
4249 _("LaTeX Options"));
4254 // This function runs "configure" and then rereads lyx.defaults to
4255 // reconfigure the automatic settings.
4258 minibuffer->Set(_("Running configure..."));
4260 // Run configure in user lyx directory
4261 Path p(user_lyxdir);
4262 Systemcalls one(Systemcalls::System,
4263 AddName(system_lyxdir, "configure"));
4265 minibuffer->Set(_("Reloading configuration..."));
4266 lyxrc->read(LibFileSearch(string(), "lyxrc.defaults"));
4267 WriteAlert(_("The system has been reconfigured."),
4268 _("You need to restart LyX to make use of any"),
4269 _("updated document class specifications."));
4273 // candidate for move to BufferView
4274 /* these functions are for the spellchecker */
4275 char * NextWord(float & value)
4277 if (!current_view->available()){
4283 char * string = current_view->text->SelectNextWord(value);
4285 char * string = current_view->buffer()->text->SelectNextWord(value);
4292 // candidate for move to BufferView
4293 void SelectLastWord()
4295 if (!current_view->available())
4298 current_view->getScreen()->HideCursor();
4301 current_view->text->SelectSelectedWord();
4302 current_view->getScreen()->ToggleSelection(false);
4303 current_view->update(0);
4305 current_view->buffer()->text->SelectSelectedWord();
4306 current_view->getScreen()->ToggleSelection(false);
4307 current_view->buffer()->update(0);
4312 // candidate for move to BufferView
4313 void EndOfSpellCheck()
4315 if (!current_view->available())
4318 current_view->getScreen()->HideCursor();
4321 current_view->text->SelectSelectedWord();
4322 current_view->text->ClearSelection();
4323 current_view->update(0);
4325 current_view->buffer()->text->SelectSelectedWord();
4326 current_view->buffer()->text->ClearSelection();
4327 current_view->buffer()->update(0);
4332 // candidate for move to BufferView
4333 void ReplaceWord(string const & replacestring)
4335 if (!current_view->getScreen())
4338 current_view->getScreen()->HideCursor();
4340 current_view->update(-2);
4342 /* clear the selection (if there is any) */
4343 current_view->getScreen()->ToggleSelection(false);
4344 current_view->update(-2);
4346 /* clear the selection (if there is any) */
4347 current_view->getScreen()->ToggleSelection(false);
4348 current_view->text->
4349 ReplaceSelectionWithString(replacestring.c_str());
4351 current_view->text->SetSelectionOverString(replacestring.c_str());
4353 // Go back so that replacement string is also spellchecked
4354 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
4355 current_view->text->CursorLeftIntern();
4357 current_view->update(1);
4359 current_view->buffer()->update(-2);
4361 /* clear the selection (if there is any) */
4362 current_view->getScreen()->ToggleSelection(false);
4364 current_view->buffer()->update(-2);
4366 /* clear the selection (if there is any) */
4367 current_view->getScreen()->ToggleSelection(false);
4368 current_view->buffer()->text->
4369 ReplaceSelectionWithString(replacestring.c_str());
4371 current_view->buffer()->text->SetSelectionOverString(replacestring.c_str());
4373 // Go back so that replacement string is also spellchecked
4374 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
4375 current_view->buffer()->text->CursorLeftIntern();
4377 current_view->buffer()->update(1);
4380 // End of spellchecker stuff
4385 // Table of Contents
4395 static TocList * toclist = 0;
4398 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
4400 if (!current_view->available())
4403 TocList * tmptoclist = toclist;
4404 int i = fl_get_browser(ob);
4405 for (int a = 1; a < i && tmptoclist->next; ++a) {
4406 tmptoclist = tmptoclist->next;
4413 LyXParagraph * par = current_view->buffer()->paragraph;
4414 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
4415 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
4416 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
4417 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
4418 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
4419 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
4420 par->appendix != tmptoclist->appendix)) {
4421 par = par->LastPhysicalPar()->Next();
4427 current_view->text->SetCursor(par, 0);
4428 current_view->text->sel_cursor =
4429 current_view->text->cursor;
4430 current_view->update(0);
4433 current_view->buffer()->text->SetCursor(par, 0);
4434 current_view->buffer()->text->sel_cursor =
4435 current_view->buffer()->text->cursor;
4436 current_view->buffer()->update(0);
4440 WriteAlert(_("Error"),
4441 _("Couldn't find this label"),
4442 _("in current document."));
4448 extern "C" void TocCancelCB(FL_OBJECT *, long)
4450 fl_hide_form(fd_form_toc->form_toc);
4454 extern "C" void TocUpdateCB(FL_OBJECT *, long)
4456 static LyXParagraph * stapar = 0;
4457 TocList * tmptoclist = 0;
4459 /* deleted the toclist */
4462 tmptoclist = toclist->next;
4464 toclist = tmptoclist;
4468 tmptoclist = toclist;
4471 fl_clear_browser(fd_form_toc->browser_toc);
4472 if (!current_view->available()) {
4473 fl_add_browser_line(fd_form_toc->browser_toc,
4474 _("*** No Document ***"));
4477 fl_hide_object(fd_form_toc->browser_toc);
4478 /* get the table of contents */
4479 LyXParagraph * par = current_view->buffer()->paragraph;
4481 char * line = new char[200];
4487 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
4491 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
4492 par->GetLayout()).labeltype;
4494 if (labeltype >= LABEL_COUNTER_CHAPTER
4495 && labeltype <= LABEL_COUNTER_CHAPTER +
4496 current_view->buffer()->params.tocdepth) {
4497 /* insert this into the table of contents */
4498 /* first indent a little bit */
4502 textclasslist.TextClass(current_view->buffer()->
4503 params.textclass).maxcounter()) * 4 + 2;
4507 // Then the labestring
4508 if (!par->labelstring.empty()) {
4509 string::size_type i = 0;
4510 while (pos < 199 && i < par->labelstring.length()) {
4511 line[pos] = par->labelstring[i];
4520 /* now the contents */
4521 LyXParagraph::size_type i = 0;
4522 while (pos < 199 && i < par->size()) {
4523 c = par->GetChar(i);
4524 if (isprint(c) || c >= 128) {
4531 fl_add_browser_line(fd_form_toc->browser_toc, line);
4533 /* make a toclist entry */
4535 tmptoclist = new TocList;
4536 toclist = tmptoclist;
4538 tmptoclist->next = new TocList;
4539 tmptoclist = tmptoclist->next;
4542 tmptoclist->next = 0;
4544 for (a = 0; a < 6; ++a) {
4545 tmptoclist->counter[a] = par->GetFirstCounter(a);
4547 tmptoclist->appendix = par->appendix;
4549 par = par->LastPhysicalPar()->Next();
4553 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
4554 fl_show_object(fd_form_toc->browser_toc);
4558 /* callbacks for form form_ref */
4559 extern "C" void RefSelectCB(FL_OBJECT *, long data)
4561 if (!current_view->available())
4565 fl_get_browser_line(fd_form_ref->browser_ref,
4566 fl_get_browser(fd_form_ref->browser_ref));
4567 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
4573 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
4583 if(current_view->buffer()->isSGML())
4584 t += "[" + u + "]" + "{" + s + "}";
4589 new InsetRef(t, current_view->buffer());
4590 current_view->buffer()->insertInset(new_inset);
4594 extern "C" void RefUpdateCB(FL_OBJECT *, long)
4596 if (!current_view->available()) {
4597 fl_clear_browser(fd_form_ref->browser_ref);
4601 FL_OBJECT * brow = fd_form_ref->browser_ref;
4603 // Get the current line, in order to restore it later
4604 char const * const btmp = fl_get_browser_line(brow,
4605 fl_get_browser(brow));
4606 string currentstr = btmp ? btmp : "";
4608 fl_clear_browser(brow);
4610 string refs = current_view->buffer()->getReferenceList('\n');
4613 #if FL_REVISION > 85
4614 fl_addto_browser_chars(brow, refs.c_str());
4615 int total_lines = fl_get_browser_maxline(brow);
4616 for (int i = 1; i <= total_lines ; i++) {
4617 if (fl_get_browser_line(brow, i) == currentstr) {
4622 fl_set_browser_topline(brow, topline);
4624 // Keep the old ugly code for xforms 0.81 compatibility
4629 curr_ref = refs.token('\n', ref_num);
4630 if (curr_ref.empty())
4632 fl_add_browser_line(brow, curr_ref.c_str());
4637 if (!fl_get_browser_maxline(brow)) {
4638 fl_add_browser_line(brow,
4639 _("*** No labels found in document ***"));
4640 fl_deactivate_object(brow);
4642 fl_select_browser_line(brow, topline);
4643 fl_activate_object(brow);
4645 if (current_view->buffer()->isReadonly()) {
4646 // would be better to de/activate insert buttons
4647 // but that's more work... besides this works. ARRae
4648 fl_hide_form(fd_form_ref->form_ref);
4650 if (!current_view->buffer()->isSGML()) {
4651 fl_deactivate_object(fd_form_ref->ref_name);
4652 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
4655 fl_activate_object(fd_form_ref->ref_name);
4656 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
4661 extern "C" void RefHideCB(FL_OBJECT *, long)
4663 fl_hide_form(fd_form_ref->form_ref);
4667 // candidate for move to BufferView
4668 void UpdateInset(Inset * inset, bool mark_dirty)
4673 /* very first check for locking insets*/
4674 if (current_view->buffer()->the_locking_inset == inset){
4676 if (current_view->text->UpdateInset(inset)){
4677 current_view->update();
4679 if (current_view->buffer()->isLyxClean())
4680 minibuffer->setTimer(4);
4681 current_view->buffer()->markDirty();
4683 current_view->updateScrollbar();
4687 if (current_view->buffer()->text->UpdateInset(inset)){
4688 current_view->update();
4690 if (current_view->buffer()->isLyxClean())
4691 minibuffer->setTimer(4);
4692 current_view->buffer()->markDirty();
4694 current_view->updateScrollbar();
4700 /* first check the current buffer */
4701 if (current_view->available()){
4702 current_view->getScreen()->HideCursor();
4704 current_view->update(-3);
4705 if (current_view->text->UpdateInset(inset)){
4707 current_view->update(1);
4709 current_view->update(3);
4713 current_view->buffer()->update(-3);
4714 if (current_view->buffer()->text->UpdateInset(inset)){
4716 current_view->buffer()->update(1);
4718 current_view->buffer()->update(3);
4724 // check all buffers
4725 bufferlist.updateInset(inset, mark_dirty);
4730 // candidate for move to BufferView
4731 /* these functions return 1 if an error occured,
4733 int LockInset(UpdatableInset * inset)
4735 if (!current_view->buffer()->the_locking_inset && inset){
4736 current_view->buffer()->the_locking_inset = inset;
4743 // candidate for move to BufferView
4744 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
4746 if (current_view->buffer()->the_locking_inset &&
4747 current_view->getScreen()){
4749 y += current_view->text->cursor.y;
4751 y += current_view->buffer()->text->cursor.y;
4753 current_view->getScreen()->ShowManualCursor(x, y,
4759 // candidate for move to BufferView
4760 void HideLockedInsetCursor(long x, long y, int asc, int desc)
4762 if (current_view->buffer()->the_locking_inset &&
4763 current_view->getScreen()){
4765 y += current_view->text->cursor.y;
4767 y += current_view->buffer()->text->cursor.y;
4769 current_view->getScreen()->HideManualCursor(x, y,
4775 // candidate for move to BufferView
4776 void FitLockedInsetCursor(long x, long y, int asc, int desc)
4778 if (current_view->buffer()->the_locking_inset &&
4779 current_view->getScreen()){
4781 y += current_view->text->cursor.y;
4783 y += current_view->buffer()->text->cursor.y;
4785 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
4786 current_view->updateScrollbar();
4791 // candidate for move to BufferView
4792 int UnlockInset(UpdatableInset * inset)
4795 current_view->buffer()->the_locking_inset == inset){
4796 inset->InsetUnlock();
4797 current_view->buffer()->the_locking_inset = 0;
4799 current_view->text->FinishUndo();
4801 current_view->buffer()->text->FinishUndo();
4805 return bufferlist.unlockInset(inset);
4809 // candidate for move to BufferView
4810 void LockedInsetStoreUndo(Undo::undo_kind kind)
4812 if (!current_view->buffer()->the_locking_inset)
4813 return; // shouldn't happen
4814 if (kind == Undo::EDIT) // in this case insets would not be stored!
4815 kind = Undo::FINISH;
4817 current_view->text->SetUndo(kind,
4818 current_view->text->cursor.par->
4819 ParFromPos(current_view->text->cursor.pos)->previous,
4820 current_view->text->cursor.par->
4821 ParFromPos(current_view->text->cursor.pos)->next);
4823 current_view->buffer()->text->SetUndo(kind,
4824 current_view->buffer()->text->cursor.par->
4825 ParFromPos(current_view->buffer()->text->cursor.pos)->previous,
4826 current_view->buffer()->text->cursor.par->
4827 ParFromPos(current_view->buffer()->text->cursor.pos)->next);
4832 void PutInsetIntoInsetUpdateList(Inset * inset)
4835 InsetUpdateStruct * tmp = new InsetUpdateStruct();
4837 tmp->next = InsetUpdateList;
4838 InsetUpdateList = tmp;
4843 void UpdateInsetUpdateList()
4845 InsetUpdateStruct * tmp = InsetUpdateList;
4847 UpdateInset(tmp->inset, false); // "false" because no document change
4851 // delete the update list
4852 while (InsetUpdateList) {
4853 tmp = InsetUpdateList;
4854 InsetUpdateList = InsetUpdateList->next;
4857 InsetUpdateList = 0;
4861 #ifdef WITH_WARNINGS
4864 // I know we shouldn't put anything in here but this seems the fastest
4865 // way to do this (and the cleanest for now). This function just inserts
4866 // a newline in the string and the inserts 'depth'-spaces so that the
4867 // code is indented in the right way!!!
4868 void addNewlineAndDepth(string & file, int const depth)
4871 file.append(depth, ' ');