1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #include "support/lstrings.h"
19 #include FORMS_H_LOCATION
21 #include "layout_forms.h"
22 #include "bullet_forms.h"
23 #include "print_form.h"
25 #include "spellchecker.h"
29 #include "insets/insetref.h"
30 #include "insets/insetquotes.h"
31 #include "insets/insetlabel.h"
32 #include "insets/figinset.h"
34 #include "latexoptions.h"
36 #include "minibuffer.h"
38 #include "bufferlist.h"
39 #include "support/filetools.h"
40 #include "support/path.h"
42 #include "lyx_gui_misc.h"
44 #include "lastfiles.h"
45 #include "support/FileInfo.h"
47 #include "support/syscall.h"
48 #include "support/lyxlib.h"
49 #include "lyxserver.h"
50 #include "FontLoader.h"
59 using std::back_inserter;
63 using std::istream_iterator;
66 extern Combox * combo_language;
67 extern BufferList bufferlist;
68 extern void show_symbols_form();
69 extern FD_form_title * fd_form_title;
70 extern FD_form_paragraph * fd_form_paragraph;
71 extern FD_form_character * fd_form_character;
72 extern FD_form_document * fd_form_document;
73 extern FD_form_quotes * fd_form_quotes;
74 extern FD_form_preamble * fd_form_preamble;
75 extern FD_form_table * fd_form_table;
76 extern FD_form_print * fd_form_print;
77 extern FD_form_figure * fd_form_figure;
78 extern FD_form_screen * fd_form_screen;
79 extern FD_form_toc * fd_form_toc;
80 extern FD_form_ref * fd_form_ref;
81 extern FD_LaTeXOptions * fd_latex_options;
82 extern FD_form_bullet * fd_form_bullet;
84 extern BufferView * current_view; // called too many times in this file...
86 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
88 extern bool send_fax(string const & fname, string const & sendcmd);
89 extern void MenuSendto();
91 extern LyXServer * lyxserver;
93 // this should be static, but I need it in buffer.C
94 bool quitting; // flag, that we are quitting the program
95 extern bool finished; // all cleanup done just let it run through now.
97 char ascii_type; /* for selection notify callbacks */
99 bool scrolling = false;
101 char updatetimer = 0;
103 /* whether the work area should get callbacks */
104 bool input_prohibited = false;
106 /* the selection possible is needed, that only motion events are
107 * used, where the bottom press event was on the drawing area too */
108 bool selection_possible = false;
110 // This is used to make the dreaded font toggle problem hopefully go
111 // away. Definitely not the best solution, but I think it sorta works.
112 bool toggleall = true;
115 This is the inset locking stuff needed for mathed --------------------
117 an inset can simple call LockInset in it's edit call and *ONLY* in it's
119 Inset::Edit() can only be called by the main lyx module.
121 Then the inset may modify the menu's and/or iconbars.
123 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
125 During the lock, all button and keyboard events will be modified
126 and send to the inset through the following inset-features. Note that
127 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
128 to contain the code for restoring the menus and things like this.
131 virtual void InsetButtonPress(int x, int y, int button);
132 virtual void InsetButtonRelease(int x, int y, int button);
133 virtual void InsetKeyPress(XKeyEvent *ev);
134 virtual void InsetMotionNotify(int x, int y, int state);
135 virtual void InsetUnlock();
137 If a inset wishes any redraw and/or update it just has to call
139 It's is completly irrelevant, where the inset is. UpdateInset will
140 find it in any paragraph in any buffer.
141 Of course the_locking_inset and the insets in the current paragraph/buffer
142 are checked first, so no performance problem should occur.
144 Hope that's ok for the beginning, Alejandro,
145 sorry that I needed so much time,
150 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
152 /* these functions return 1 if an error occured,
154 // Now they work only for updatable insets. [Alejandro 080596]
155 //int LockInset(UpdatableInset * inset);
156 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
157 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
158 //int UnlockInset(UpdatableInset * inset);
159 //void LockedInsetStoreUndo(Undo::undo_kind kind);
161 /* this is for asyncron updating. UpdateInsetUpdateList will be called
162 automatically from LyX. Just insert the Inset into the Updatelist */
163 //void UpdateInsetUpdateList();
164 //void PutInsetIntoInsetUpdateList(Inset * inset);
166 //InsetUpdateStruct * InsetUpdateList = 0;
170 -----------------------------------------------------------------------
173 /* some function prototypes */
175 int RunLinuxDoc(BufferView *, int, string const &);
176 int RunDocBook(int, string const &);
177 void MenuWrite(Buffer * buf);
178 void MenuWriteAs(Buffer * buffer);
179 void MenuReload(Buffer * buf);
180 void MenuLayoutSave();
183 void ShowMessage(Buffer * buf,
185 string const & msg2 = string(),
186 string const & msg3 = string(), int delay = 6)
189 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
192 // can somebody think of something more clever? cerr?
193 cout << msg1 << msg2 << msg3 << endl;
197 // How should this actually work? Should it prohibit input in all BufferViews,
198 // or just in the current one? If "just the current one", then it should be
199 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
200 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
201 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
202 // current LyxView that should be prohibited (Lgb) (This applies to
203 // "AllowInput" as well.)
206 input_prohibited = true;
207 current_view->hideCursor();
209 static Cursor cursor;
210 static bool cursor_undefined = true;
212 if (cursor_undefined){
213 cursor = XCreateFontCursor(fl_display, XC_watch);
215 cursor_undefined = false;
218 /* set the cursor to the watch for all forms and the canvas */
219 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
221 if (fd_form_paragraph->form_paragraph->visible)
222 XDefineCursor(fl_display,
223 fd_form_paragraph->form_paragraph->window,
225 if (fd_form_character->form_character->visible)
226 XDefineCursor(fl_display,
227 fd_form_character->form_character->window,
231 fl_deactivate_all_forms();
235 // Should find a way to move this into BufferView.C
236 void SetXtermCursor(Window win)
238 static Cursor cursor;
239 static bool cursor_undefined = true;
240 if (cursor_undefined){
241 cursor = XCreateFontCursor(fl_display, XC_xterm);
243 cursor_undefined = false;
245 XDefineCursor(fl_display, win, cursor);
252 input_prohibited = false;
254 /* reset the cursor from the watch for all forms and the canvas */
256 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
257 if (fd_form_paragraph->form_paragraph->visible)
258 XUndefineCursor(fl_display,
259 fd_form_paragraph->form_paragraph->window);
260 if (fd_form_character->form_character->visible)
261 XUndefineCursor(fl_display,
262 fd_form_character->form_character->window);
264 // What to do about this? (Lgb)
265 if (current_view->belowMouse())
266 SetXtermCursor(current_view->owner()->getForm()->window);
269 fl_activate_all_forms();
273 void FreeUpdateTimer()
275 /* a real free timer would be better but I don't know
276 * how to do this with xforms */
281 void SetUpdateTimer(float time)
283 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
296 // should be moved to lyxfunc.C
297 void MenuWrite(Buffer * buffer)
300 if (!buffer->save()) {
301 string fname = buffer->fileName();
302 string s = MakeAbsPath(fname);
303 if (AskQuestion(_("Save failed. Rename and try again?"),
304 MakeDisplayPath(s, 50),
305 _("(If not, document is not saved.)"))) {
309 lastfiles->newFile(buffer->fileName());
314 // should be moved to BufferView.C
315 // Half of this func should be in LyXView, the rest in BufferView.
316 void MenuWriteAs(Buffer * buffer)
318 // Why do we require BufferView::text to be able to write a
319 // document? I see no point in that. (Lgb)
320 //if (!bv->text) return;
322 string fname = buffer->fileName();
323 string oldname = fname;
327 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
328 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
330 if (!IsLyXFilename(fname))
333 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
336 OnlyFilename(fname));
342 // Make sure the absolute filename ends with appropriate suffix
343 string s = MakeAbsPath(fname);
344 if (!IsLyXFilename(s))
347 // Same name as we have already?
349 if (!AskQuestion(_("Same name as document already has:"),
350 MakeDisplayPath(s, 50),
353 // Falls through to name change and save
355 // No, but do we have another file with this name open?
356 else if (bufferlist.exists(s)) {
357 if (AskQuestion(_("Another document with same name open!"),
358 MakeDisplayPath(s, 50),
359 _("Replace with current document?")))
361 bufferlist.close(bufferlist.getBuffer(s));
363 // Ok, change the name of the buffer, but don't save!
367 ShowMessage(buffer, _("Document renamed to '"),
368 MakeDisplayPath(s), _("', but not saved..."));
371 } // Check whether the file exists
374 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
375 MakeDisplayPath(s, 50),
380 // Ok, change the name of the buffer
384 // Small bug: If the save fails, we have irreversible changed the name
390 int MenuRunLaTeX(Buffer * buffer)
394 if (buffer->isLinuxDoc())
395 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
396 else if (buffer->isLiterate())
397 ret = buffer->runLiterate();
398 else if (buffer->isDocBook())
399 ret = RunDocBook(1, buffer->fileName());
401 ret = buffer->runLaTeX();
407 s = _("One error detected");
408 t = _("You should try to fix it.");
411 s += _(" errors detected.");
412 t = _("You should try to fix them.");
414 WriteAlert(_("There were errors during the LaTeX run."), s, t);
420 int MenuBuildProg(Buffer * buffer)
424 if (buffer->isLiterate())
425 ret = buffer->buildProgram();
427 string s = _("Wrong type of document");
428 string t = _("The Build operation is not allowed in this document");
429 WriteAlert(_("There were errors during the Build process."), s, t);
437 s = _("One error detected");
438 t = _("You should try to fix it.");
441 s += _(" errors detected.");
442 t = _("You should try to fix them.");
444 WriteAlert(_("There were errors during the Build process."), s, t);
450 int MenuRunChktex(Buffer * buffer)
454 if (buffer->isSGML()) {
455 WriteAlert(_("Chktex does not work with SGML derived documents."));
458 ret = buffer->runChktex();
464 s = _("No warnings found.");
465 } else if (ret == 1) {
466 s = _("One warning found.");
467 t = _("Use 'Edit->Go to Error' to find it.");
470 s += _(" warnings found.");
471 t = _("Use 'Edit->Go to Error' to find them.");
473 WriteAlert(_("Chktex run successfully"), s, t);
475 WriteAlert(_("Error!"), _("It seems chktex does not work."));
481 int MakeLaTeXOutput(Buffer * buffer)
487 string path = OnlyPath(buffer->fileName());
488 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
489 path = buffer->tmppath;
491 if (!buffer->isDviClean()) {
493 ret = MenuRunLaTeX(buffer);
499 /* wait == false means don't wait for termination */
500 /* wait == true means wait for termination */
501 // The bool should be placed last on the argument line. (Lgb)
502 // Returns false if we fail.
503 bool RunScript(Buffer * buffer, bool wait,
504 string const & command,
505 string const & orgname = string(),
506 bool need_shell = true)
510 string name = orgname;
513 if (MakeLaTeXOutput(buffer) > 0)
515 /* get DVI-Filename */
517 name = ChangeExtension(buffer->getLatexName(),
520 path = OnlyPath(name);
521 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
522 path = buffer->tmppath;
525 // At this point we check whether the command contains the
526 // filename parameter $$FName and if that's the case we
527 // substitute the real file name otherwise the filename is
528 // simply appended. rokrau 1/12/00
531 if ( (i=command.find("$$FName")) != string::npos)
533 cmd.replace(i,7,QuoteName(name));
536 cmd = command + ' ' + QuoteName(name);
545 // OS/2 cmd.exe has another use for '&'
547 // This is not NLS safe, but it's OK, I think.
548 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
550 // COMSPEC is set, unless user unsets
551 sh = OnlyFilename(GetEnvPath("COMSPEC"));
556 if (contains(sh, "cmd.exe")
557 || contains(sh, "4os2.exe"))
558 cmd = "start /min/n " + cmd;
563 // It seems that, if wait is false, we never get back
564 // the return code of the command. This means that all
565 // the code I added in PrintApplyCB is currently
568 #warning What should we do here?
570 ShowMessage(buffer, _("Executing command:"), cmd);
571 result = one.startscript(Systemcalls::System, cmd);
573 ShowMessage(buffer, _("Executing command:"), cmd);
574 result = one.startscript(wait ? Systemcalls::Wait
575 : Systemcalls::DontWait, cmd);
581 // Returns false if we fail
582 bool CreatePostscript(Buffer * buffer, bool wait = false)
591 if (MakeLaTeXOutput(buffer) > 0) {
595 // Generate postscript file
596 string psname = ChangeExtension (buffer->fileName(),
602 char real_papersize = buffer->params.papersize;
603 if (real_papersize == BufferParams::PAPER_DEFAULT)
604 real_papersize = lyxrc.default_papersize;
606 switch (real_papersize) {
607 case BufferParams::PAPER_USLETTER:
610 case BufferParams::PAPER_A3PAPER:
613 case BufferParams::PAPER_A4PAPER:
616 case BufferParams::PAPER_A5PAPER:
619 case BufferParams::PAPER_B5PAPER:
622 case BufferParams::PAPER_EXECUTIVEPAPER:
625 case BufferParams::PAPER_LEGALPAPER:
628 default: /* If nothing else fits, keep an empty value... */
632 // Make postscript file.
633 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
634 command += QuoteName(psname);
635 if (buffer->params.use_geometry
636 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
637 && !lyxrc.print_paper_dimension_flag.empty()
638 && !buffer->params.paperwidth.empty()
639 && !buffer->params.paperheight.empty()) {
640 // using a custom papersize
642 command += lyxrc.print_paper_dimension_flag + ' ';
643 command += buffer->params.paperwidth + ',';
644 command += buffer->params.paperheight;
645 } else if (!paper.empty()
646 && (real_papersize != BufferParams::PAPER_USLETTER ||
647 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
648 // dvips won't accept -t letter -t landscape. In all other
649 // cases, include the paper size explicitly.
651 command += lyxrc.print_paper_flag + ' ' + paper;
653 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
655 command += lyxrc.print_landscape_flag;
657 // push directorypath, if necessary
658 string path = OnlyPath(buffer->fileName());
659 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
660 path = buffer->tmppath;
663 bool ret = RunScript(buffer, wait, command);
669 // Returns false if we fail
670 //bool MenuPreviewPS(Buffer * buffer)
671 bool PreviewPostscript(Buffer * buffer)
677 // Generate postscript file
678 if (!CreatePostscript(buffer, true)) {
682 // Start postscript viewer
684 string ps = ChangeExtension (buffer->fileName(),
686 // push directorypath, if necessary
687 string path = OnlyPath(buffer->fileName());
688 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
689 path = buffer->tmppath;
692 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
698 void MenuFax(Buffer * buffer)
704 // Generate postscript file
705 if (!CreatePostscript(buffer, true)) {
710 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
711 string path = OnlyPath (buffer->fileName());
712 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
713 path = buffer->tmppath;
716 if (!lyxrc.fax_program.empty()) {
717 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
719 Systemcalls one(Systemcalls::System, help2);
721 send_fax(ps, lyxrc.fax_command);
725 // Returns false if we fail
726 bool PreviewDVI(Buffer * buffer)
732 string paper = lyxrc.view_dvi_paper_option;
733 if (!paper.empty()) {
735 char real_papersize = buffer->params.papersize;
736 if (real_papersize == BufferParams::PAPER_DEFAULT)
737 real_papersize = lyxrc.default_papersize;
739 switch (real_papersize) {
740 case BufferParams::PAPER_USLETTER:
743 case BufferParams::PAPER_A3PAPER:
746 case BufferParams::PAPER_A4PAPER:
749 case BufferParams::PAPER_A5PAPER:
752 case BufferParams::PAPER_B5PAPER:
755 case BufferParams::PAPER_EXECUTIVEPAPER:
756 paper += " foolscap";
758 case BufferParams::PAPER_LEGALPAPER:
761 default: /* If nothing else fits, keep the empty value */
764 if (real_papersize==' ') {
765 // if (paper.empty()) {
766 if (buffer->params.orientation
767 == BufferParams::ORIENTATION_LANDSCAPE)
768 // we HAVE to give a size when the page is in
769 // landscape, so use USletter.
770 paper = " -paper usr";
772 // paper = " -paper " + paper;
773 if (buffer->params.orientation
774 == BufferParams::ORIENTATION_LANDSCAPE)
778 // push directorypath, if necessary
779 string path = OnlyPath(buffer->fileName());
780 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
781 path = buffer->tmppath;
785 string command = lyxrc.view_dvi_command + " " + paper;
786 bool ret = RunScript(buffer, false, command);
791 bool AskOverwrite(Buffer * buffer, string const & s)
794 // be friendly if there is a gui
797 !AskQuestion(_("File already exists:"),
798 MakeDisplayPath(s, 50),
799 _("Do you want to overwrite the file?"))) {
800 ShowMessage(buffer, _("Canceled"));
807 void MenuMakeLaTeX(Buffer * buffer)
809 // Why care about this?
813 // Get LaTeX-Filename
814 string s = buffer->getLatexName(false);
816 if (!AskOverwrite(buffer, s))
819 if (buffer->isDocBook())
820 ShowMessage(buffer, _("DocBook does not have a latex backend"));
822 if (buffer->isLinuxDoc())
823 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
825 buffer->makeLaTeXFile(s, string(), true);
826 ShowMessage(buffer, _("Nice LaTeX file saved as"),
828 buffer->markDviDirty();
833 void MenuMakeLinuxDoc(Buffer * buffer)
836 //if (!bv->text) return;
838 if (!buffer->isLinuxDoc()) {
839 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
843 // Get LinuxDoc-Filename
844 string s = ChangeExtension(buffer->fileName(),
847 if (!AskOverwrite(buffer, s))
850 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
851 MakeDisplayPath(s),"'...");
853 buffer->makeLinuxDocFile(s, 65);
855 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
860 void MenuMakeDocBook(Buffer * buffer)
863 //if (!bv->text) return;
865 if (!buffer->isDocBook()) {
866 WriteAlert(_("Error!"),
867 _("Document class must be docbook."));
871 // Get DocBook-Filename
872 string s = ChangeExtension(buffer->fileName(),
875 if (!AskOverwrite(buffer, s))
878 ShowMessage(buffer, _("Building DocBook SGML file `"),
879 MakeDisplayPath(s), "'...");
881 buffer->makeDocBookFile(s, 65);
883 ShowMessage(buffer, _("DocBook SGML file save as"),
888 void MenuMakeAscii(Buffer * buffer)
891 //if (!bv->text) return;
893 /* get LaTeX-Filename */
894 string s = ChangeExtension (buffer->fileName(),
898 if (!AskOverwrite(buffer, s))
901 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
903 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
907 void MenuPrint(Buffer * buffer)
913 string input_file = ChangeExtension(buffer->fileName(),
914 lyxrc.print_file_extension,
916 fl_set_input(fd_form_print->input_file, input_file.c_str());
918 if (fd_form_print->form_print->visible) {
919 fl_raise_form(fd_form_print->form_print);
922 fl_show_form(fd_form_print->form_print,
923 FL_PLACE_MOUSE, FL_FULLBORDER,
928 void MenuMakeHTML(Buffer * buffer)
930 // First, create LaTeX file
931 MenuMakeLaTeX(buffer);
933 // And now, run the converter
934 string file = buffer->fileName();
935 Path path(OnlyPath(file));
936 // the tex file name has to be correct for
937 // latex, but the html file name can be
939 string result = ChangeExtension(file, ".html", false);
940 string infile = buffer->getLatexName(false);
941 string tmp = lyxrc.html_command;
942 tmp = subst(tmp, "$$FName", infile);
943 tmp = subst(tmp, "$$OutName", result);
945 int res = one.startscript(Systemcalls::System, tmp);
947 ShowMessage(buffer, _("Document exported as HTML to file `")
948 + MakeDisplayPath(result) +'\'');
950 ShowMessage(buffer, _("Unable to convert to HTML the file `")
951 + MakeDisplayPath(infile)
957 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
959 // First, create LinuxDoc file
960 MenuMakeLinuxDoc(buffer);
962 // And now, run the converter
963 string file = buffer->fileName();
965 string result = ChangeExtension(file, ".html", false);
966 string infile = ChangeExtension(file, ".sgml", false);
967 string tmp = lyxrc.linuxdoc_to_html_command;
968 tmp = subst(tmp, "$$FName", infile);
969 tmp = subst(tmp, "$$OutName", result);
971 int res = one.startscript(Systemcalls::System, tmp);
973 ShowMessage(buffer,_("Document exported as HTML to file `")
974 + MakeDisplayPath(result) +'\'');
976 ShowMessage(buffer,_("Unable to convert to HTML the file `")
977 + MakeDisplayPath(infile)
983 void MenuMakeHTML_DocBook(Buffer * buffer)
985 // First, create LaTeX file
986 MenuMakeDocBook(buffer);
988 // And now, run the converter
989 string file = buffer->fileName();
990 string result = ChangeExtension(file, ".html", false);
991 string infile = ChangeExtension(file, ".sgml", false);
992 string tmp = lyxrc.docbook_to_html_command;
993 tmp = subst(tmp, "$$FName", infile);
994 tmp = subst(tmp, "$$OutName", result);
996 int res = one.startscript(Systemcalls::System, tmp);
998 ShowMessage(buffer,_("Document exported as HTML to file `")
999 + MakeDisplayPath(result) +'\'');
1001 ShowMessage(buffer,_("Unable to convert to HTML the file `")
1002 + MakeDisplayPath(infile)
1008 void MenuExport(Buffer * buffer, string const & extyp)
1011 if (extyp == "latex") {
1012 // make sure that this buffer is not linuxdoc
1013 MenuMakeLaTeX(buffer);
1016 else if (extyp == "linuxdoc") {
1017 // make sure that this buffer is not latex
1018 MenuMakeLinuxDoc(buffer);
1021 else if (extyp == "docbook") {
1022 // make sure that this buffer is not latex or linuxdoc
1023 MenuMakeDocBook(buffer);
1026 else if (extyp == "dvi") {
1027 // Run LaTeX as "Update dvi..." Bernhard.
1028 // We want the dvi in the current directory. This
1029 // is achieved by temporarily disabling use of
1030 // temp directory. As a side-effect, we get
1031 // *.log and *.aux files also. (Asger)
1032 bool flag = lyxrc.use_tempdir;
1033 lyxrc.use_tempdir = false;
1034 MenuRunLaTeX(buffer);
1035 lyxrc.use_tempdir = flag;
1038 else if (extyp == "postscript") {
1039 // Start Print-dialog. Not as good as dvi... Bernhard.
1041 // Since the MenuPrint is a pop-up, we can't use
1042 // the same trick as above. (Asger)
1043 // MISSING: Move of ps-file :-(
1044 // And MenuPrint should not be used for this at all...
1047 else if (extyp == "ascii") {
1048 MenuMakeAscii(buffer);
1050 else if (extyp == "custom") {
1054 else if (extyp == "html") {
1055 MenuMakeHTML(buffer);
1057 // HTML from linuxdoc
1058 else if (extyp == "html-linuxdoc") {
1059 MenuMakeHTML_LinuxDoc(buffer);
1061 // HTML from docbook
1062 else if (extyp == "html-docbook") {
1063 MenuMakeHTML_DocBook(buffer);
1066 ShowMessage(buffer, _("Unknown export type: ") + extyp);
1073 lyxerr.debug() << "Running QuitLyX." << endl;
1075 if (!bufferlist.QwriteAll())
1078 lastfiles->writeFile(lyxrc.lastfiles);
1080 // Set a flag that we do quitting from the program,
1081 // so no refreshes are necessary.
1084 // close buffers first
1085 bufferlist.closeAll();
1087 // do any other cleanup procedures now
1088 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1090 DestroyLyXTmpDir(system_tempdir);
1098 // should probably be moved into BufferList (Lgb)
1099 // Perfect target for a thread...
1101 if (!current_view->available())
1104 if (current_view->buffer()->isBakClean()
1105 || current_view->buffer()->isReadonly()) {
1106 // We don't save now, but we'll try again later
1107 current_view->owner()->resetAutosaveTimer();
1111 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1113 // create autosave filename
1114 string fname = OnlyPath(current_view->buffer()->fileName());
1116 fname += OnlyFilename(current_view->buffer()->fileName());
1119 // tmp_ret will be located (usually) in /tmp
1120 // will that be a problem?
1121 string tmp_ret = tmpnam(0);
1123 pid_t pid = fork(); // If you want to debug the autosave
1124 // you should set pid to -1, and comment out the
1126 if (pid == 0 || pid == -1) {
1127 // pid = -1 signifies that lyx was unable
1128 // to fork. But we will do the save
1130 bool failed = false;
1131 if (!tmp_ret.empty()) {
1132 current_view->buffer()->writeFile(tmp_ret, 1);
1133 // assume successful write of tmp_ret
1134 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1136 // most likely couldn't move between filesystems
1137 // unless write of tmp_ret failed
1138 // so remove tmp file (if it exists)
1139 remove(tmp_ret.c_str());
1146 // failed to write/rename tmp_ret so try writing direct
1147 if (!current_view->buffer()->writeFile(fname, 1)) {
1148 // It is dangerous to do this in the child,
1149 // but safe in the parent, so...
1151 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1154 if (pid == 0) { // we are the child so...
1159 current_view->buffer()->markBakClean();
1160 current_view->owner()->resetAutosaveTimer();
1165 // Copyright CHT Software Service GmbH
1168 // create new file with template
1171 Buffer * NewLyxFile(string const & filename)
1173 // Split argument by :
1175 string tmpname = split(filename, name, ':');
1176 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1177 if (name.length() == 1
1178 && isalpha(static_cast<unsigned char>(name[0]))
1179 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1181 name += token(tmpname, ':', 0);
1182 tmpname = split(tmpname, ':');
1185 lyxerr.debug() << "Arg is " << filename
1186 << "\nName is " << name
1187 << "\nTemplate is " << tmpname << endl;
1189 // find a free buffer
1190 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1192 lastfiles->newFile(tmpbuf->fileName());
1197 // Insert ascii file (if filename is empty, prompt for one)
1198 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1203 if (!bv->available()) return;
1205 if (fname.empty()) {
1207 fname = fileDlg.Select(_("File to Insert"),
1208 bv->owner()->buffer()->filepath,
1211 if (fname.empty()) return;
1216 if (!fi.readable()) {
1217 WriteFSAlert(_("Error! Specified file is unreadable: "),
1218 MakeDisplayPath(fname, 50));
1222 ifstream ifs(fname.c_str());
1224 WriteFSAlert(_("Error! Cannot open specified file: "),
1225 MakeDisplayPath(fname, 50));
1229 ifs.unsetf(ios::skipws);
1230 istream_iterator<char> ii(ifs);
1231 istream_iterator<char> end;
1232 //string tmpstr(ii, end); // yet a reason for using std::string
1233 // alternate approach to get the file into a string:
1235 copy(ii, end, back_inserter(tmpstr));
1236 // insert the string
1237 current_view->hideCursor();
1239 // clear the selection
1242 bv->text->InsertStringA(tmpstr);
1244 bv->text->InsertStringB(tmpstr);
1249 void MenuShowTableOfContents()
1251 static int ow = -1, oh;
1254 if (fd_form_toc->form_toc->visible) {
1255 fl_raise_form(fd_form_toc->form_toc);
1257 fl_show_form(fd_form_toc->form_toc,
1258 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1259 _("Table Of Contents"));
1261 ow = fd_form_toc->form_toc->w;
1262 oh = fd_form_toc->form_toc->h;
1264 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1269 void MenuInsertLabel(char const * arg)
1273 if (label.empty()) {
1275 result = askForText(_("Enter new label to insert:"));
1277 label = frontStrip(strip(result.second));
1280 if (!label.empty()) {
1281 InsetLabel * new_inset = new InsetLabel;
1282 new_inset->setContents(label);
1283 current_view->insertInset(new_inset);
1289 void MenuInsertRef()
1291 static int ow = -1, oh;
1294 if (fd_form_ref->form_ref->visible) {
1295 fl_raise_form(fd_form_ref->form_ref);
1297 fl_show_form(fd_form_ref->form_ref,
1298 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1299 _("Insert Reference"));
1301 ow = fd_form_ref->form_ref->w;
1302 oh = fd_form_ref->form_ref->h;
1304 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1309 void MenuPasteSelection(char at)
1311 if (!current_view->available())
1316 Atom data_prop = XInternAtom(fl_display,
1319 if (data_prop == None)
1321 XConvertSelection(fl_display,
1322 XA_PRIMARY, XA_STRING, data_prop,
1323 current_view->owner()->getForm()->window, 0);
1328 // candidate for move to BufferView
1329 void Foot(BufferView * bv)
1331 if (!bv->available())
1334 bv->owner()->getMiniBuffer()
1335 ->Set(_("Inserting Footnote..."));
1338 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1343 // candidate for move to LyXView
1344 // This is only used in toolbar.C
1345 void LayoutsCB(int sel, void *)
1347 string tmp = tostr(sel);
1348 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1354 * SGML Linuxdoc support:
1355 * (flag == 0) make TeX output
1356 * (flag == 1) make dvi output
1358 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1365 /* generate a path-less extension name */
1366 string name = ChangeExtension (filename, ".sgml", true);
1367 string path = OnlyPath (filename);
1368 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1369 path = bv->buffer()->tmppath;
1373 if (!bv->available())
1375 bv->buffer()->makeLinuxDocFile(name, 0);
1376 #ifdef WITH_WARNINGS
1377 #warning remove this once we have a proper geometry class
1379 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1381 case BufferParams::PAPER_A4PAPER:
1382 add_flags = "-p a4";
1384 case BufferParams::PAPER_USLETTER:
1385 add_flags = "-p letter";
1387 default: /* nothing to be done yet ;-) */ break;
1394 case 0: /* TeX output asked */
1395 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1396 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1397 if (one.startscript(Systemcalls::System, s2))
1400 case 1: /* dvi output asked */
1401 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1402 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1403 if (one.startscript(Systemcalls::System, s2)) {
1406 bv->buffer()->markDviClean();
1408 default: /* unknown output */
1414 bv->buffer()->redraw();
1420 * SGML DocBook support:
1421 * (flag == 1) make dvi output
1423 int RunDocBook(int flag, string const & filename)
1425 /* generate a path-less extension name */
1426 string name = ChangeExtension (filename, ".sgml", true);
1427 string path = OnlyPath (filename);
1428 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1429 path = current_view->buffer()->tmppath;
1433 if (!current_view->available())
1436 current_view->buffer()->makeDocBookFile(name, 0);
1438 // Shall this code go or should it stay? (Lgb)
1439 // This code is a placeholder for future implementation. (Jose')
1440 // string add_flags;
1441 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1443 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1444 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1445 // default: /* nothing to be done yet ;-) */ break;
1452 case 1: /* dvi output asked */
1454 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1455 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1456 if (one.startscript(Systemcalls::System, s2)) {
1459 current_view->buffer()->markDviClean();
1462 default: /* unknown output */
1468 current_view->buffer()->redraw();
1473 void MenuLayoutCharacter()
1475 static int ow = -1, oh;
1477 if (fd_form_character->form_character->visible) {
1478 fl_raise_form(fd_form_character->form_character);
1480 fl_show_form(fd_form_character->form_character,
1481 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1482 _("Character Style"));
1484 ow = fd_form_character->form_character->w;
1485 oh = fd_form_character->form_character->h;
1487 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1493 void DeactivateParagraphButtons ()
1495 fl_deactivate_object (fd_form_paragraph->button_ok);
1496 fl_deactivate_object (fd_form_paragraph->button_apply);
1497 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1498 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1503 void ActivateParagraphButtons ()
1505 fl_activate_object (fd_form_paragraph->button_ok);
1506 fl_activate_object (fd_form_paragraph->button_apply);
1507 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1508 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1513 void DisableParagraphLayout ()
1515 DeactivateParagraphButtons();
1516 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1517 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1518 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1519 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1520 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1521 fl_deactivate_object (fd_form_paragraph->check_noindent);
1522 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1523 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1524 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1525 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1526 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1527 fl_deactivate_object (fd_form_paragraph->input_space_above);
1528 fl_deactivate_object (fd_form_paragraph->input_space_below);
1529 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1530 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1531 fl_deactivate_object (fd_form_paragraph->check_space_above);
1532 fl_deactivate_object (fd_form_paragraph->check_space_below);
1537 void EnableParagraphLayout ()
1539 ActivateParagraphButtons();
1540 fl_activate_object (fd_form_paragraph->input_labelwidth);
1541 fl_activate_object (fd_form_paragraph->check_lines_top);
1542 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1543 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1544 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1545 fl_activate_object (fd_form_paragraph->check_noindent);
1546 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1547 fl_activate_object (fd_form_paragraph->radio_align_right);
1548 fl_activate_object (fd_form_paragraph->radio_align_left);
1549 fl_activate_object (fd_form_paragraph->radio_align_block);
1550 fl_activate_object (fd_form_paragraph->radio_align_center);
1551 fl_activate_object (fd_form_paragraph->input_space_above);
1552 fl_activate_object (fd_form_paragraph->input_space_below);
1553 fl_activate_object (fd_form_paragraph->choice_space_above);
1554 fl_activate_object (fd_form_paragraph->choice_space_below);
1555 fl_activate_object (fd_form_paragraph->check_space_above);
1556 fl_activate_object (fd_form_paragraph->check_space_below);
1560 bool UpdateLayoutParagraph()
1562 if (!current_view->available()) {
1563 if (fd_form_paragraph->form_paragraph->visible)
1564 fl_hide_form(fd_form_paragraph->form_paragraph);
1568 Buffer * buf = current_view->buffer();
1570 fl_set_input(fd_form_paragraph->input_labelwidth,
1571 current_view->text->cursor.par->GetLabelWidthString().c_str());
1572 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1573 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1574 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1575 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1577 int align = current_view->text->cursor.par->GetAlign();
1578 if (align == LYX_ALIGN_LAYOUT)
1579 align = textclasslist.Style(buf->params.textclass,
1580 current_view->text->cursor.par->GetLayout()).align;
1583 case LYX_ALIGN_RIGHT:
1584 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1586 case LYX_ALIGN_LEFT:
1587 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1589 case LYX_ALIGN_CENTER:
1590 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1593 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1597 fl_set_button(fd_form_paragraph->check_lines_top,
1598 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1599 fl_set_button(fd_form_paragraph->check_lines_bottom,
1600 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1601 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1602 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1603 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1604 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1605 fl_set_button(fd_form_paragraph->check_noindent,
1606 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1607 fl_set_input (fd_form_paragraph->input_space_above, "");
1609 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1611 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1613 case VSpace::DEFSKIP:
1614 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1616 case VSpace::SMALLSKIP:
1617 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1619 case VSpace::MEDSKIP:
1620 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1622 case VSpace::BIGSKIP:
1623 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1626 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1628 case VSpace::LENGTH:
1629 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1630 fl_set_input (fd_form_paragraph->input_space_above,
1631 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1634 fl_set_button (fd_form_paragraph->check_space_above,
1635 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1636 fl_set_input (fd_form_paragraph->input_space_below, "");
1637 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1639 fl_set_choice (fd_form_paragraph->choice_space_below,
1642 case VSpace::DEFSKIP:
1643 fl_set_choice (fd_form_paragraph->choice_space_below,
1646 case VSpace::SMALLSKIP:
1647 fl_set_choice (fd_form_paragraph->choice_space_below,
1650 case VSpace::MEDSKIP:
1651 fl_set_choice (fd_form_paragraph->choice_space_below,
1654 case VSpace::BIGSKIP:
1655 fl_set_choice (fd_form_paragraph->choice_space_below,
1659 fl_set_choice (fd_form_paragraph->choice_space_below,
1662 case VSpace::LENGTH:
1663 fl_set_choice (fd_form_paragraph->choice_space_below,
1665 fl_set_input (fd_form_paragraph->input_space_below,
1666 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1669 fl_set_button (fd_form_paragraph->check_space_below,
1670 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1672 fl_set_button(fd_form_paragraph->check_noindent,
1673 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1675 if (current_view->buffer()->isReadonly()) {
1676 DisableParagraphLayout();
1678 EnableParagraphLayout();
1684 void MenuLayoutParagraph()
1686 if (UpdateLayoutParagraph()) {
1687 if (fd_form_paragraph->form_paragraph->visible) {
1688 fl_raise_form(fd_form_paragraph->form_paragraph);
1690 fl_show_form(fd_form_paragraph->form_paragraph,
1691 FL_PLACE_MOUSE, FL_FULLBORDER,
1692 _("Paragraph Environment"));
1699 void DeactivateDocumentButtons ()
1701 fl_deactivate_object (fd_form_document->button_ok);
1702 fl_deactivate_object (fd_form_document->button_apply);
1703 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1704 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1709 void ActivateDocumentButtons ()
1711 fl_activate_object (fd_form_document->button_ok);
1712 fl_activate_object (fd_form_document->button_apply);
1713 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1714 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1719 void DisableDocumentLayout ()
1721 DeactivateDocumentButtons ();
1722 fl_deactivate_object (fd_form_document->group_radio_separation);
1723 fl_deactivate_object (fd_form_document->radio_indent);
1724 fl_deactivate_object (fd_form_document->radio_skip);
1725 fl_deactivate_object (fd_form_document->choice_class);
1726 fl_deactivate_object (fd_form_document->choice_pagestyle);
1727 fl_deactivate_object (fd_form_document->choice_fonts);
1728 fl_deactivate_object (fd_form_document->choice_fontsize);
1729 fl_deactivate_object (fd_form_document->input_float_placement);
1730 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1731 fl_deactivate_object (fd_form_document->choice_inputenc);
1732 fl_deactivate_object (fd_form_document->group_radio_sides);
1733 fl_deactivate_object (fd_form_document->radio_sides_one);
1734 fl_deactivate_object (fd_form_document->radio_sides_two);
1735 fl_deactivate_object (fd_form_document->group_radio_columns);
1736 fl_deactivate_object (fd_form_document->radio_columns_one);
1737 fl_deactivate_object (fd_form_document->radio_columns_two);
1738 fl_deactivate_object (fd_form_document->input_extra);
1739 fl_deactivate_object (fd_form_document->choice_language);
1740 combo_language->deactivate();
1741 fl_deactivate_object (fd_form_document->input_default_skip);
1742 fl_deactivate_object (fd_form_document->choice_default_skip);
1743 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1744 fl_deactivate_object (fd_form_document->slider_tocdepth);
1745 fl_deactivate_object (fd_form_document->choice_spacing);
1746 fl_deactivate_object (fd_form_document->input_spacing);
1747 fl_deactivate_object (fd_form_document->check_use_amsmath);
1752 void EnableDocumentLayout ()
1754 ActivateDocumentButtons ();
1755 fl_activate_object (fd_form_document->group_radio_separation);
1756 fl_activate_object (fd_form_document->radio_indent);
1757 fl_activate_object (fd_form_document->radio_skip);
1758 fl_activate_object (fd_form_document->choice_class);
1759 fl_activate_object (fd_form_document->choice_pagestyle);
1760 fl_activate_object (fd_form_document->choice_fonts);
1761 fl_activate_object (fd_form_document->choice_fontsize);
1762 fl_activate_object (fd_form_document->input_float_placement);
1763 fl_activate_object (fd_form_document->choice_postscript_driver);
1764 fl_activate_object (fd_form_document->choice_inputenc);
1765 fl_activate_object (fd_form_document->group_radio_sides);
1766 fl_activate_object (fd_form_document->radio_sides_one);
1767 fl_activate_object (fd_form_document->radio_sides_two);
1768 fl_activate_object (fd_form_document->group_radio_columns);
1769 fl_activate_object (fd_form_document->radio_columns_one);
1770 fl_activate_object (fd_form_document->radio_columns_two);
1771 fl_activate_object (fd_form_document->input_extra);
1772 fl_activate_object (fd_form_document->choice_language);
1773 combo_language->activate();
1774 fl_activate_object (fd_form_document->input_default_skip);
1775 fl_activate_object (fd_form_document->choice_default_skip);
1776 fl_activate_object (fd_form_document->slider_secnumdepth);
1777 fl_activate_object (fd_form_document->slider_tocdepth);
1778 fl_activate_object (fd_form_document->choice_spacing);
1779 fl_activate_object (fd_form_document->input_spacing);
1780 fl_activate_object (fd_form_document->check_use_amsmath);
1784 bool UpdateLayoutDocument(BufferParams * params)
1786 if (!current_view->available()) {
1787 if (fd_form_document->form_document->visible)
1788 fl_hide_form(fd_form_document->form_document);
1793 params = ¤t_view->buffer()->params;
1794 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1796 fl_set_choice_text(fd_form_document->choice_class,
1797 textclasslist.DescOfClass(params->textclass).c_str());
1798 combo_language->select_text(params->language.c_str());
1800 fl_set_choice_text(fd_form_document->choice_fonts,
1801 params->fonts.c_str());
1802 fl_set_choice_text(fd_form_document->choice_inputenc,
1803 params->inputenc.c_str());
1804 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1805 params->graphicsDriver.c_str());
1807 // ale970405+lasgoutt970513
1808 fl_clear_choice(fd_form_document->choice_fontsize);
1809 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1810 fl_addto_choice(fd_form_document->choice_fontsize,
1811 tclass.opt_fontsize().c_str());
1812 fl_set_choice(fd_form_document->choice_fontsize,
1813 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1815 // ale970405+lasgoutt970513
1816 fl_clear_choice(fd_form_document->choice_pagestyle);
1817 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1818 fl_addto_choice(fd_form_document->choice_pagestyle,
1819 tclass.opt_pagestyle().c_str());
1821 fl_set_choice(fd_form_document->choice_pagestyle,
1822 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1824 fl_set_button(fd_form_document->radio_indent, 0);
1825 fl_set_button(fd_form_document->radio_skip, 0);
1828 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1830 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1831 fl_set_button(fd_form_document->radio_indent, 1);
1833 fl_set_button(fd_form_document->radio_skip, 1);
1835 switch (params->getDefSkip().kind()) {
1836 case VSpace::SMALLSKIP:
1837 fl_set_choice (fd_form_document->choice_default_skip, 1);
1839 case VSpace::MEDSKIP:
1840 fl_set_choice (fd_form_document->choice_default_skip, 2);
1842 case VSpace::BIGSKIP:
1843 fl_set_choice (fd_form_document->choice_default_skip, 3);
1845 case VSpace::LENGTH:
1846 fl_set_choice (fd_form_document->choice_default_skip, 4);
1847 fl_set_input (fd_form_document->input_default_skip,
1848 params->getDefSkip().asLyXCommand().c_str());
1851 fl_set_choice (fd_form_document->choice_default_skip, 2);
1855 fl_set_button(fd_form_document->radio_sides_one, 0);
1856 fl_set_button(fd_form_document->radio_sides_two, 0);
1858 switch (params->sides) {
1859 case LyXTextClass::OneSide:
1860 fl_set_button(fd_form_document->radio_sides_one, 1);
1862 case LyXTextClass::TwoSides:
1863 fl_set_button(fd_form_document->radio_sides_two, 1);
1867 fl_set_button(fd_form_document->radio_columns_one, 0);
1868 fl_set_button(fd_form_document->radio_columns_two, 0);
1870 if (params->columns == 2)
1871 fl_set_button(fd_form_document->radio_columns_two, 1);
1873 fl_set_button(fd_form_document->radio_columns_one, 1);
1875 fl_set_input(fd_form_document->input_spacing, "");
1876 switch (params->spacing.getSpace()) {
1877 case Spacing::Single:
1880 fl_set_choice(fd_form_document->choice_spacing, 1);
1883 case Spacing::Onehalf:
1886 fl_set_choice(fd_form_document->choice_spacing, 2);
1889 case Spacing::Double:
1892 fl_set_choice(fd_form_document->choice_spacing, 3);
1895 case Spacing::Other:
1897 fl_set_choice(fd_form_document->choice_spacing, 4);
1899 //sprintf(sval, "%g", params->spacing.getValue());
1901 std::ostringstream sval;
1902 sval << params->spacing.getValue(); // setw?
1903 fl_set_input(fd_form_document->input_spacing,
1904 sval.str().c_str());
1907 ostrstream sval(tval, 20);
1908 sval << params->spacing.getValue() << '\0'; // setw?
1909 fl_set_input(fd_form_document->input_spacing, sval.str());
1916 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1917 params->secnumdepth);
1918 fl_set_counter_value(fd_form_document->slider_tocdepth,
1920 if (!params->float_placement.empty()) { // buffer local (Lgb)
1921 fl_set_input(fd_form_document->input_float_placement,
1922 params->float_placement.c_str());
1924 fl_set_input(fd_form_document->input_float_placement, "");
1926 if (!params->options.empty())
1927 fl_set_input(fd_form_document->input_extra,
1928 params->options.c_str());
1930 fl_set_input(fd_form_document->input_extra, "");
1932 if (current_view->buffer()->isSGML()) {
1933 // bullets not used in SGML derived documents
1934 fl_deactivate_object(fd_form_document->button_bullets);
1935 fl_set_object_lcol(fd_form_document->button_bullets,
1938 fl_activate_object(fd_form_document->button_bullets);
1939 fl_set_object_lcol(fd_form_document->button_bullets,
1943 if (current_view->buffer()->isReadonly()) {
1944 DisableDocumentLayout();
1946 EnableDocumentLayout();
1953 void MenuLayoutDocument()
1955 if (UpdateLayoutDocument()) {
1956 if (fd_form_document->form_document->visible) {
1957 fl_raise_form(fd_form_document->form_document);
1959 fl_show_form(fd_form_document->form_document,
1960 FL_PLACE_MOUSE, FL_FULLBORDER,
1961 _("Document Layout"));
1967 bool UpdateLayoutQuotes()
1970 if (!current_view->available()
1971 || current_view->buffer()->isReadonly())
1975 fl_set_choice(fd_form_quotes->choice_quotes_language,
1976 current_view->buffer()->params.quotes_language + 1);
1977 fl_set_button(fd_form_quotes->radio_single, 0);
1978 fl_set_button(fd_form_quotes->radio_double, 0);
1980 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1981 fl_set_button(fd_form_quotes->radio_single, 1);
1983 fl_set_button(fd_form_quotes->radio_double, 1);
1984 } else if (fd_form_quotes->form_quotes->visible) {
1985 fl_hide_form(fd_form_quotes->form_quotes);
1991 void MenuLayoutQuotes()
1993 if (UpdateLayoutQuotes()) {
1994 if (fd_form_quotes->form_quotes->visible) {
1995 fl_raise_form(fd_form_quotes->form_quotes);
1997 fl_show_form(fd_form_quotes->form_quotes,
1998 FL_PLACE_MOUSE, FL_FULLBORDER,
2005 bool UpdateLayoutPreamble()
2008 if (!current_view->available())
2012 fl_set_input(fd_form_preamble->input_preamble,
2013 current_view->buffer()->params.preamble.c_str());
2015 if (current_view->buffer()->isReadonly()) {
2016 fl_deactivate_object(fd_form_preamble->input_preamble);
2017 fl_deactivate_object(fd_form_preamble->button_ok);
2018 fl_deactivate_object(fd_form_preamble->button_apply);
2019 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
2020 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2023 fl_activate_object(fd_form_preamble->input_preamble);
2024 fl_activate_object(fd_form_preamble->button_ok);
2025 fl_activate_object(fd_form_preamble->button_apply);
2026 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2027 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2029 } else if (fd_form_preamble->form_preamble->visible) {
2030 fl_hide_form(fd_form_preamble->form_preamble);
2036 void MenuLayoutPreamble()
2038 static int ow = -1, oh;
2040 if (UpdateLayoutPreamble()) {
2041 if (fd_form_preamble->form_preamble->visible) {
2042 fl_raise_form(fd_form_preamble->form_preamble);
2044 fl_show_form(fd_form_preamble->form_preamble,
2045 FL_PLACE_MOUSE | FL_FREE_SIZE,
2047 _("LaTeX Preamble"));
2049 ow = fd_form_preamble->form_preamble->w;
2050 oh = fd_form_preamble->form_preamble->h;
2052 fl_set_form_minsize(fd_form_preamble->form_preamble,
2059 void MenuLayoutSave()
2061 if (!current_view->available())
2064 if (AskQuestion(_("Do you want to save the current settings"),
2065 _("for Character, Document, Paper and Quotes"),
2066 _("as default for new documents?")))
2067 current_view->buffer()->saveParamsAsDefaults();
2071 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2072 They also show the current font state. */
2075 void ToggleAndShow(BufferView *, LyXFont const &);
2078 void FontSize(string const & size)
2080 LyXFont font(LyXFont::ALL_IGNORE);
2081 font.setGUISize(size);
2082 ToggleAndShow(current_view, font);
2088 LyXFont font(LyXFont::ALL_IGNORE);
2089 font.setEmph(LyXFont::TOGGLE);
2090 ToggleAndShow(current_view, font);
2096 LyXFont font(LyXFont::ALL_IGNORE);
2097 font.setNoun(LyXFont::TOGGLE);
2098 ToggleAndShow(current_view, font);
2104 LyXFont font(LyXFont::ALL_IGNORE);
2105 font.setSeries(LyXFont::BOLD_SERIES);
2106 ToggleAndShow(current_view, font);
2112 LyXFont font(LyXFont::ALL_IGNORE);
2113 font.setUnderbar(LyXFont::TOGGLE);
2114 ToggleAndShow(current_view, font);
2120 LyXFont font(LyXFont::ALL_IGNORE);
2121 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2122 ToggleAndShow(current_view, font);
2128 LyXFont font(LyXFont::ALL_IGNORE);
2129 font.setFamily(LyXFont::SANS_FAMILY);
2130 ToggleAndShow(current_view, font);
2136 LyXFont font(LyXFont::ALL_IGNORE);
2137 font.setFamily(LyXFont::ROMAN_FAMILY);
2138 ToggleAndShow(current_view, font);
2144 LyXFont font(LyXFont::ALL_IGNORE);
2145 font.setLatex (LyXFont::TOGGLE);
2146 ToggleAndShow(current_view, font);
2149 void LangCB(string const & l)
2151 LyXFont font(LyXFont::ALL_IGNORE);
2152 Languages::iterator lit = languages.find(l);
2153 if (lit != languages.end()) {
2154 font.setLanguage(&(*lit).second);
2155 ToggleAndShow(current_view, font);
2157 WriteAlert(_("Error! unknown language"),l);
2163 LyXFont font(LyXFont::ALL_INHERIT, ignore_language);
2164 ToggleAndShow(current_view, font);
2168 /* -------> Returns the current font and depth by printing a message. In the
2169 * future perhaps we could try to implement a callback to the button-bar.
2170 * That is, `light' the bold button when the font is currently bold, etc.
2172 string CurrentState()
2175 if (current_view->available()) {
2176 // I think we should only show changes from the default
2178 Buffer * buffer = current_view->buffer();
2179 LyXFont font = current_view->text->real_current_font;
2180 LyXFont defaultfont = textclasslist.TextClass(buffer->
2181 params.textclass).defaultfont();
2182 font.reduce(defaultfont);
2183 state = _("Font: ") + font.stateText();
2185 int depth = current_view->text->GetDepth();
2187 state += string(_(", Depth: ")) + tostr(depth);
2193 // candidate for move to BufferView
2194 /* -------> Does the actual toggle job of the XxxCB() calls above.
2195 * Also shows the current font state.
2198 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2200 if (bv->available()) {
2203 if (bv->the_locking_inset)
2204 bv->the_locking_inset->SetFont(bv, font, toggleall);
2206 bv->text->ToggleFree(font, toggleall);
2212 // candidate for move to BufferView
2213 void Margin(BufferView * bv)
2215 if (bv->available()) {
2216 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2219 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2227 if (fd_form_figure->form_figure->visible) {
2228 fl_raise_form(fd_form_figure->form_figure);
2230 fl_show_form(fd_form_figure->form_figure,
2231 FL_PLACE_MOUSE, FL_FULLBORDER,
2232 _("Insert Figure"));
2239 if (fd_form_table->form_table->visible) {
2240 fl_raise_form(fd_form_table->form_table);
2242 fl_show_form(fd_form_table->form_table,
2243 FL_PLACE_MOUSE, FL_FULLBORDER,
2249 // candidate for move to BufferView
2250 void Melt(BufferView * bv)
2252 if (!bv->available()) return;
2254 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2258 bv->text->MeltFootnoteEnvironment();
2263 // candidate for move to BufferView
2264 // Change environment depth.
2265 // if decInc >= 0, increment depth
2266 // if decInc < 0, decrement depth
2267 void changeDepth(BufferView * bv, int decInc)
2269 if (!bv->available()) return;
2274 bv->text->IncDepth();
2276 bv->text->DecDepth();
2278 bv->owner()->getMiniBuffer()
2279 ->Set(_("Changed environment depth"
2280 " (in possible range, maybe not)"));
2284 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2285 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2286 LyXFont UserFreeFont()
2288 LyXFont font(LyXFont::ALL_IGNORE);
2290 int pos = fl_get_choice(fd_form_character->choice_family);
2292 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2293 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2294 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2295 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2296 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2299 pos = fl_get_choice(fd_form_character->choice_series);
2301 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2302 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2303 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2304 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2307 pos = fl_get_choice(fd_form_character->choice_shape);
2309 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2310 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2311 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2312 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2313 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2314 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2317 pos = fl_get_choice(fd_form_character->choice_size);
2319 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2320 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2321 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2322 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2323 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2324 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2325 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2326 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2327 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2328 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2329 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2330 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2331 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2332 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2335 pos = fl_get_choice(fd_form_character->choice_bar);
2337 case 1: font.setEmph(LyXFont::IGNORE);
2338 font.setUnderbar(LyXFont::IGNORE);
2339 font.setNoun(LyXFont::IGNORE);
2340 font.setLatex(LyXFont::IGNORE);
2342 case 2: font.setEmph(LyXFont::TOGGLE); break;
2343 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2344 case 4: font.setNoun(LyXFont::TOGGLE); break;
2345 case 5: font.setLatex(LyXFont::TOGGLE); break;
2346 case 6: font.setEmph(LyXFont::INHERIT);
2347 font.setUnderbar(LyXFont::INHERIT);
2348 font.setNoun(LyXFont::INHERIT);
2349 font.setLatex(LyXFont::INHERIT);
2353 pos = fl_get_choice(fd_form_character->choice_color);
2355 case 1: font.setColor(LColor::ignore); break;
2356 case 2: font.setColor(LColor::none); break;
2357 case 3: font.setColor(LColor::black); break;
2358 case 4: font.setColor(LColor::white); break;
2359 case 5: font.setColor(LColor::red); break;
2360 case 6: font.setColor(LColor::green); break;
2361 case 7: font.setColor(LColor::blue); break;
2362 case 8: font.setColor(LColor::cyan); break;
2363 case 9: font.setColor(LColor::magenta); break;
2364 case 10: font.setColor(LColor::yellow); break;
2365 case 11: font.setColor(LColor::inherit); break;
2374 ToggleAndShow(current_view, UserFreeFont());
2378 /* callbacks for form form_title */
2379 extern "C" void TimerCB(FL_OBJECT *, long)
2381 // only if the form still exists
2382 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2383 if (fd_form_title->form_title->visible) {
2384 fl_hide_form(fd_form_title->form_title);
2386 fl_free_form(fd_form_title->form_title);
2387 fd_form_title->form_title = 0;
2392 /* callbacks for form form_paragraph */
2394 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2396 // "Synchronize" the choices and input fields, making it
2397 // impossible to commit senseless data.
2399 FD_form_paragraph const * fp = fd_form_paragraph;
2401 if (obj == fp->choice_space_above) {
2402 if (fl_get_choice (fp->choice_space_above) != 7) {
2403 fl_set_input (fp->input_space_above, "");
2404 ActivateParagraphButtons();
2406 } else if (obj == fp->choice_space_below) {
2407 if (fl_get_choice (fp->choice_space_below) != 7) {
2408 fl_set_input (fp->input_space_below, "");
2409 ActivateParagraphButtons();
2411 } else if (obj == fp->input_space_above) {
2412 string input = fl_get_input (fp->input_space_above);
2414 if (input.empty()) {
2415 fl_set_choice (fp->choice_space_above, 1);
2416 ActivateParagraphButtons();
2418 else if (isValidGlueLength (input)) {
2419 fl_set_choice (fp->choice_space_above, 7);
2420 ActivateParagraphButtons();
2423 fl_set_choice (fp->choice_space_above, 7);
2424 DeactivateParagraphButtons();
2426 } else if (obj == fp->input_space_below) {
2427 string input = fl_get_input (fp->input_space_below);
2429 if (input.empty()) {
2430 fl_set_choice (fp->choice_space_below, 1);
2431 ActivateParagraphButtons();
2433 else if (isValidGlueLength (input)) {
2434 fl_set_choice (fp->choice_space_below, 7);
2435 ActivateParagraphButtons();
2438 fl_set_choice (fp->choice_space_below, 7);
2439 DeactivateParagraphButtons();
2445 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2447 if (!current_view->available())
2450 VSpace space_top, space_bottom;
2452 string labelwidthstring;
2455 // If a vspace kind is "Length" but there's no text in
2456 // the input field, reset the kind to "None".
2457 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2458 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2459 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2461 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2462 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2463 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2466 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2467 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2468 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2469 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2470 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2471 case 1: space_top = VSpace(VSpace::NONE); break;
2472 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2473 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2474 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2475 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2476 case 6: space_top = VSpace(VSpace::VFILL); break;
2477 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2479 if (fl_get_button (fd_form_paragraph->check_space_above))
2480 space_top.setKeep (true);
2481 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2482 case 1: space_bottom = VSpace(VSpace::NONE); break;
2483 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2484 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2485 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2486 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2487 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2488 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2490 if (fl_get_button (fd_form_paragraph->check_space_below))
2491 space_bottom.setKeep (true);
2493 if (fl_get_button(fd_form_paragraph->radio_align_left))
2494 align = LYX_ALIGN_LEFT;
2495 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2496 align = LYX_ALIGN_RIGHT;
2497 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2498 align = LYX_ALIGN_CENTER;
2500 align = LYX_ALIGN_BLOCK;
2502 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2503 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2505 current_view->text->SetParagraph(line_top,
2514 current_view->update(1);
2515 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2519 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2521 fl_hide_form(fd_form_paragraph->form_paragraph);
2525 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2527 ParagraphApplyCB(ob, data);
2528 ParagraphCancelCB(ob, data);
2532 /* callbacks for form form_character */
2534 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2536 // we set toggleall locally here, since it should be true for
2537 // all other uses of ToggleAndShow() (JMarc)
2538 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2539 ToggleAndShow(current_view, UserFreeFont());
2544 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2546 fl_hide_form(fd_form_character->form_character);
2550 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2552 CharacterApplyCB(ob, data);
2553 CharacterCloseCB(ob, data);
2557 /* callbacks for form form_document */
2559 void UpdateDocumentButtons(BufferParams const & params)
2561 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2563 switch (params.sides) {
2564 case LyXTextClass::OneSide:
2565 fl_set_button(fd_form_document->radio_sides_one, 1);
2567 case LyXTextClass::TwoSides:
2568 fl_set_button(fd_form_document->radio_sides_two, 1);
2572 if (params.columns == 2)
2573 fl_set_button(fd_form_document->radio_columns_two, 1);
2575 fl_set_button(fd_form_document->radio_columns_one, 1);
2577 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2578 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2579 params.secnumdepth);
2580 fl_set_counter_value(fd_form_document->slider_tocdepth,
2585 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2588 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2589 if (AskQuestion(_("Should I set some parameters to"),
2590 fl_get_choice_text(ob),
2591 _("the defaults of this document class?"))) {
2592 BufferParams params = BufferParams();
2593 params.textclass = fl_get_choice(ob)-1;
2594 params.useClassDefaults();
2595 UpdateLayoutDocument(¶ms);
2596 UpdateDocumentButtons(params);
2599 // unable to load new style
2600 WriteAlert(_("Conversion Errors!"),
2601 _("Unable to switch to new document class."),
2602 _("Reverting to original document class."));
2603 fl_set_choice(fd_form_document->choice_class,
2604 current_view->buffer()->params.textclass + 1);
2610 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2612 // "Synchronize" the choice and the input field, so that it
2613 // is impossible to commit senseless data.
2614 FD_form_document const * fd = fd_form_document;
2616 if (obj == fd->choice_default_skip) {
2617 if (fl_get_choice (fd->choice_default_skip) != 4) {
2618 fl_set_input (fd->input_default_skip, "");
2619 ActivateDocumentButtons();
2621 } else if (obj == fd->input_default_skip) {
2623 char const * input = fl_get_input (fd->input_default_skip);
2626 fl_set_choice (fd->choice_default_skip, 2);
2627 ActivateDocumentButtons();
2628 } else if (isValidGlueLength (input)) {
2629 fl_set_choice (fd->choice_default_skip, 4);
2630 ActivateDocumentButtons();
2632 fl_set_choice (fd->choice_default_skip, 4);
2633 DeactivateDocumentButtons();
2639 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2641 // "Synchronize" the choice and the input field, so that it
2642 // is impossible to commit senseless data.
2643 FD_form_document const * fd = fd_form_document;
2645 if (obj == fd->choice_spacing
2646 && fl_get_choice (fd->choice_spacing) != 4) {
2647 fl_set_input(fd->input_spacing, "");
2648 } else if (obj == fd->input_spacing) {
2650 const char* input = fl_get_input (fd->input_spacing);
2653 fl_set_choice (fd->choice_spacing, 1);
2655 fl_set_choice (fd->choice_spacing, 4);
2661 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2664 BufferParams * params = &(current_view->buffer()->params);
2666 params->language = combo_language->getline();
2667 Languages::iterator lit = languages.find(params->language);
2668 if (lit != languages.end())
2669 params->language_info = &(*lit).second;
2671 params->language_info = default_language;
2673 // If default skip is a "Length" but there's no text in the
2674 // input field, reset the kind to "Medskip", which is the default.
2675 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2676 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2677 fl_set_choice (fd_form_document->choice_default_skip, 2);
2680 /* this shouldn't be done automatically IMO. For example I write german
2681 * documents with an american keyboard very often. Matthias */
2683 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2684 fl_get_choice(fd_form_document->choice_language)); */
2686 fl_get_choice_text(fd_form_document->choice_fonts);
2688 fl_get_choice_text(fd_form_document->choice_inputenc);
2690 fl_get_choice_text(fd_form_document->choice_fontsize);
2692 fl_get_choice_text(fd_form_document->choice_pagestyle);
2693 params->graphicsDriver =
2694 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2695 params->use_amsmath =
2696 fl_get_button(fd_form_document->check_use_amsmath);
2698 if (!current_view->available())
2700 current_view->text->SetCursor(current_view->text->cursor.par,
2701 current_view->text->cursor.pos);
2702 current_view->setState();
2704 LyXTextClassList::ClassList::size_type new_class =
2705 fl_get_choice(fd_form_document->choice_class) - 1;
2707 if (params->textclass != new_class) {
2708 // try to load new_class
2709 if (textclasslist.Load(new_class)) {
2710 // successfully loaded
2712 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2713 int ret = current_view->text->
2714 SwitchLayoutsBetweenClasses(current_view->buffer()->
2717 current_view->buffer()->
2723 s = _("One paragraph couldn't be converted");
2726 s += _(" paragraphs couldn't be converted");
2728 WriteAlert(_("Conversion Errors!"), s,
2729 _("into chosen document class"));
2732 params->textclass = new_class;
2734 // problem changing class -- warn user and retain old style
2735 WriteAlert(_("Conversion Errors!"),
2736 _("Unable to switch to new document class."),
2737 _("Reverting to original document class."));
2738 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2742 char tmpsep = params->paragraph_separation;
2743 if (fl_get_button(fd_form_document->radio_indent))
2744 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2746 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2747 if (tmpsep != params->paragraph_separation)
2750 VSpace tmpdefskip = params->getDefSkip();
2751 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2752 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2753 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2754 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2755 case 4: params->setDefSkip(
2756 VSpace (LyXGlueLength (fl_get_input
2757 (fd_form_document->input_default_skip))));
2759 // DocumentDefskipCB assures that this never happens
2760 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2762 if (!(tmpdefskip == params->getDefSkip()))
2765 if (fl_get_button(fd_form_document->radio_columns_two))
2766 params->columns = 2;
2768 params->columns = 1;
2769 if (fl_get_button(fd_form_document->radio_sides_two))
2770 params->sides = LyXTextClass::TwoSides;
2772 params->sides = LyXTextClass::OneSide;
2774 Spacing tmpSpacing = params->spacing;
2775 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2777 lyxerr.debug() << "Spacing: SINGLE" << endl;
2778 params->spacing.set(Spacing::Single);
2781 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2782 params->spacing.set(Spacing::Onehalf);
2785 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2786 params->spacing.set(Spacing::Double);
2789 lyxerr.debug() << "Spacing: OTHER" << endl;
2790 params->spacing.set(Spacing::Other,
2791 fl_get_input(fd_form_document->input_spacing));
2794 if (tmpSpacing != params->spacing)
2797 signed char tmpchar =
2798 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2799 if (params->secnumdepth != tmpchar)
2801 params->secnumdepth = tmpchar;
2804 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2806 params->float_placement =
2807 fl_get_input(fd_form_document->input_float_placement);
2809 // More checking should be done to ensure the string doesn't have
2810 // spaces or illegal placement characters in it. (thornley)
2813 current_view->redoCurrentBuffer();
2815 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2816 current_view->buffer()->markDirty();
2819 fl_get_input(fd_form_document->input_extra);
2824 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2826 fl_hide_form(fd_form_document->form_document);
2830 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2832 DocumentCancelCB(ob, data);
2833 DocumentApplyCB(ob, data);
2837 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2840 // bullet callbacks etc. in bullet_panel.C -- ARRae
2844 /* callbacks for form form_quotes */
2846 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2848 if (!current_view->available())
2851 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2852 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2853 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2855 lga = InsetQuotes::EnglishQ;
2858 lga = InsetQuotes::SwedishQ;
2861 lga = InsetQuotes::GermanQ;
2864 lga = InsetQuotes::PolishQ;
2867 lga = InsetQuotes::FrenchQ;
2870 lga = InsetQuotes::DanishQ;
2873 current_view->buffer()->params.quotes_language = lga;
2874 if (fl_get_button(fd_form_quotes->radio_single))
2875 current_view->buffer()->
2876 params.quotes_times = InsetQuotes::SingleQ;
2878 current_view->buffer()->
2879 params.quotes_times = InsetQuotes::DoubleQ;
2883 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2885 fl_hide_form(fd_form_quotes->form_quotes);
2889 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2891 QuotesApplyCB(ob, data);
2892 QuotesCancelCB(ob, data);
2897 /* callbacks for form form_preamble */
2899 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2901 fl_hide_form(fd_form_preamble->form_preamble);
2905 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2907 if (!current_view->available())
2910 current_view->buffer()->params.preamble =
2911 fl_get_input(fd_form_preamble->input_preamble);
2912 current_view->buffer()->markDirty();
2913 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2917 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2919 PreambleApplyCB(ob, data);
2920 PreambleCancelCB(ob, data);
2924 /* callbacks for form form_table */
2926 extern "C" void TableApplyCB(FL_OBJECT *, long)
2928 if (!current_view->available())
2931 // check for tables in tables
2932 if (current_view->text->cursor.par->table){
2933 WriteAlert(_("Impossible Operation!"),
2934 _("Cannot insert table in table."),
2939 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2941 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2942 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2945 current_view->hideCursor();
2946 current_view->beforeChange();
2947 current_view->update(-2);
2949 current_view->text->SetCursorParUndo();
2950 current_view->text->FreezeUndo();
2952 current_view->text->BreakParagraph();
2953 current_view->update(-1);
2955 if (current_view->text->cursor.par->Last()) {
2956 current_view->text->CursorLeft();
2958 current_view->text->BreakParagraph();
2959 current_view->update(-1);
2962 current_view->text->current_font.setLatex(LyXFont::OFF);
2963 //if (!fl_get_button(fd_form_table->check_latex)){
2964 // insert the new wysiwy table
2965 current_view->text->SetLayout(0); // standard layout
2966 if (current_view->text->cursor.par->footnoteflag ==
2967 LyXParagraph::NO_FOOTNOTE) {
2969 ->SetParagraph(0, 0,
2971 VSpace (0.3 * current_view->buffer()->
2972 params.spacing.getValue(),
2974 VSpace (0.3 * current_view->buffer()->
2975 params.spacing.getValue(),
2982 ->SetParagraph(0, 0,
2984 VSpace(VSpace::NONE),
2985 VSpace(VSpace::NONE),
2991 current_view->text->cursor.par->table =
2992 new LyXTable(xsize, ysize);
2994 Language const * lang =
2995 current_view->text->cursor.par->getParLanguage();
2996 LyXFont font(LyXFont::ALL_INHERIT,lang);
2997 for (int i = 0; i < xsize * ysize - 1; ++i) {
2998 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2999 current_view->text->cursor.par->SetFont(0, font);
3001 current_view->text->RedoParagraph();
3003 current_view->text->UnFreezeUndo();
3005 current_view->update(1);
3006 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
3007 current_view->setState();
3011 extern "C" void TableCancelCB(FL_OBJECT *, long)
3013 fl_hide_form(fd_form_table->form_table);
3017 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
3019 TableApplyCB(ob, data);
3020 TableCancelCB(ob, data);
3024 /* callbacks for form form_print */
3026 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3028 fl_hide_form(fd_form_print->form_print);
3033 bool stringOnlyContains (string const & LStr, char const * cset)
3036 char const * cstr = LStr.c_str();
3038 return strspn(cstr, cset) == strlen(cstr);
3040 return LStr.find_first_not_of(cset) == string::npos;
3045 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3047 if (!current_view->available())
3049 Buffer * buffer = current_view->buffer();
3050 string path = OnlyPath(buffer->fileName());
3053 if (fl_get_button(fd_form_print->radio_even_pages))
3054 pageflag = lyxrc.print_evenpage_flag + ' ';
3055 else if (fl_get_button(fd_form_print->radio_odd_pages))
3056 pageflag = lyxrc.print_oddpage_flag + ' ';
3058 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3059 // User may give a page (range) list
3060 // User may print multiple (unsorted) copies
3061 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3062 pages = subst(pages, '+',',');
3063 pages = frontStrip(strip(pages)) ;
3064 while (!pages.empty()) { // a page range was given
3066 pages = split (pages, piece, ',') ;
3067 piece = strip(piece) ;
3068 piece = frontStrip(piece) ;
3069 if ( !stringOnlyContains (piece, "0123456789-") ) {
3070 WriteAlert(_("ERROR! Unable to print!"),
3071 _("Check 'range of pages'!"));
3074 if (piece.find('-') == string::npos) { // not found
3075 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
3076 } else if (suffixIs(piece, "-") ) { // missing last page
3077 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
3078 } else if (prefixIs(piece, "-") ) { // missing first page
3079 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
3081 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
3085 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3086 if (!copies.empty()) { // a number of copies was given
3087 if ( !stringOnlyContains (copies, "0123456789") ) {
3088 WriteAlert(_("ERROR! Unable to print!"),
3089 _("Check 'number of copies'!"));
3092 if (fl_get_button(fd_form_print->do_unsorted))
3093 pageflag += lyxrc.print_copies_flag;
3095 pageflag += lyxrc.print_collcopies_flag;
3096 pageflag += " " + copies + ' ' ;
3100 if (fl_get_button(fd_form_print->radio_order_reverse))
3101 reverseflag = lyxrc.print_reverse_flag + ' ';
3103 string orientationflag;
3104 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3105 orientationflag = lyxrc.print_landscape_flag + ' ';
3107 string ps_file = fl_get_input(fd_form_print->input_file);
3108 string printer = strip(fl_get_input(fd_form_print->input_printer));
3111 if (lyxrc.print_adapt_output // printer name should be passed to dvips
3112 && ! printer.empty()) // a printer name has been given
3113 printerflag = lyxrc.print_to_printer + printer + ' ';
3116 if (!lyxrc.print_extra_options.empty())
3117 extraflags = lyxrc.print_extra_options + ' ';
3119 string command = lyxrc.print_command + ' '
3120 + printerflag + pageflag + reverseflag
3121 + orientationflag + extraflags;
3123 char real_papersize = buffer->params.papersize;
3124 if (real_papersize == BufferParams::PAPER_DEFAULT)
3125 real_papersize = lyxrc.default_papersize;
3128 switch (real_papersize) {
3129 case BufferParams::PAPER_USLETTER:
3132 case BufferParams::PAPER_A3PAPER:
3135 case BufferParams::PAPER_A4PAPER:
3138 case BufferParams::PAPER_A5PAPER:
3141 case BufferParams::PAPER_B5PAPER:
3144 case BufferParams::PAPER_EXECUTIVEPAPER:
3147 case BufferParams::PAPER_LEGALPAPER:
3150 default: /* If nothing else fits, keep an empty value... */
3154 if (buffer->params.use_geometry
3155 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3156 && !lyxrc.print_paper_dimension_flag.empty()
3157 && !buffer->params.paperwidth.empty()
3158 && !buffer->params.paperheight.empty()) {
3159 // using a custom papersize
3161 command += lyxrc.print_paper_dimension_flag + ' ';
3162 command += buffer->params.paperwidth + ',';
3163 command += buffer->params.paperheight + ' ';
3164 } else if (!lyxrc.print_paper_flag.empty()
3166 && (real_papersize != BufferParams::PAPER_USLETTER ||
3167 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3168 command += " " + lyxrc.print_paper_flag + " " + paper + " ";
3170 if (fl_get_button(fd_form_print->radio_file))
3171 command += lyxrc.print_to_file
3172 + QuoteName(MakeAbsPath(ps_file, path));
3173 else if (!lyxrc.print_spool_command.empty())
3174 command += lyxrc.print_to_file
3175 + QuoteName(ps_file);
3177 // push directorypath, if necessary
3178 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
3179 path = buffer->tmppath;
3184 if (!lyxrc.print_spool_command.empty() &&
3185 !fl_get_button(fd_form_print->radio_file)) {
3186 string command2 = lyxrc.print_spool_command + ' ';
3187 if (!printer.empty())
3188 command2 += lyxrc.print_spool_printerprefix
3190 // First run dvips and, if succesful, then spool command
3191 if ((result = RunScript(buffer, true, command))) {
3192 result = RunScript(buffer, false, command2, ps_file);
3195 result = RunScript(buffer, false, command);
3198 WriteAlert(_("Error:"),
3199 _("Unable to print"),
3200 _("Check that your parameters are correct"));
3204 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3206 PrintCancelCB(ob, data);
3207 PrintApplyCB(ob, data);
3211 /* callbacks for form form_figure */
3212 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3214 if (!current_view->available())
3217 Buffer * buffer = current_view->buffer();
3218 if(buffer->isReadonly()) // paranoia
3221 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3222 if (fl_get_button(fd_form_figure->radio_inline)
3223 || current_view->text->cursor.par->table) {
3224 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3225 current_view->insertInset(new_inset);
3226 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3227 new_inset->Edit(current_view, 0, 0, 0);
3231 current_view->hideCursor();
3232 current_view->update(-2);
3233 current_view->beforeChange();
3235 current_view->text->SetCursorParUndo();
3236 current_view->text->FreezeUndo();
3238 current_view->text->BreakParagraph();
3239 current_view->update(-1);
3241 if (current_view->text->cursor.par->Last()) {
3242 current_view->text->CursorLeft();
3244 current_view->text->BreakParagraph();
3245 current_view->update(-1);
3248 // The standard layout should always be numer 0;
3249 current_view->text->SetLayout(0);
3251 if (current_view->text->cursor.par->footnoteflag ==
3252 LyXParagraph::NO_FOOTNOTE) {
3253 current_view->text->
3256 VSpace (0.3 * buffer->params.spacing.getValue(),
3259 buffer->params.spacing.getValue(),
3261 LYX_ALIGN_CENTER, string(), 0);
3263 current_view->text->SetParagraph(0, 0,
3265 VSpace(VSpace::NONE),
3266 VSpace(VSpace::NONE),
3272 current_view->update(-1);
3274 Inset * new_inset = new InsetFig(100, 100, buffer);
3275 current_view->insertInset(new_inset);
3276 new_inset->Edit(current_view, 0, 0, 0);
3277 current_view->update(0);
3278 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3279 current_view->text->UnFreezeUndo();
3280 current_view->setState();
3284 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3286 fl_hide_form(fd_form_figure->form_figure);
3290 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3292 FigureApplyCB(ob, data);
3293 FigureCancelCB(ob, data);
3297 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3299 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
3300 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
3301 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3302 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
3303 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3304 fontloader.update();
3306 // All buffers will need resize
3307 bufferlist.resize();
3309 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3313 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3315 fl_hide_form(fd_form_screen->form_screen);
3319 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3321 ScreenCancelCB(ob, data);
3322 ScreenApplyCB(ob, data);
3326 void LaTeXOptions(BufferView * bv)
3328 if (!bv->available())
3331 fl_set_button(fd_latex_options->accents,
3332 int(bv->buffer()->params.allowAccents));
3334 if (fd_latex_options->LaTeXOptions->visible) {
3335 fl_raise_form(fd_latex_options->LaTeXOptions);
3337 fl_show_form(fd_latex_options->LaTeXOptions,
3338 FL_PLACE_MOUSE, FL_FULLBORDER,
3339 _("LaTeX Options"));
3344 // This function runs "configure" and then rereads lyx.defaults to
3345 // reconfigure the automatic settings.
3346 void Reconfigure(BufferView * bv)
3348 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3350 // Run configure in user lyx directory
3351 Path p(user_lyxdir);
3352 Systemcalls one(Systemcalls::System,
3353 AddName(system_lyxdir, "configure"));
3355 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3356 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
3357 WriteAlert(_("The system has been reconfigured."),
3358 _("You need to restart LyX to make use of any"),
3359 _("updated document class specifications."));
3364 // Table of Contents
3374 static TocList * toclist = 0;
3377 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3379 if (!current_view->available())
3382 TocList * tmptoclist = toclist;
3383 int i = fl_get_browser(ob);
3384 for (int a = 1; a < i && tmptoclist->next; ++a) {
3385 tmptoclist = tmptoclist->next;
3392 LyXParagraph * par = current_view->buffer()->paragraph;
3393 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3394 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3395 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3396 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3397 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3398 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3399 par->appendix != tmptoclist->appendix)) {
3400 par = par->LastPhysicalPar()->Next();
3404 current_view->beforeChange();
3405 current_view->text->SetCursor(par, 0);
3406 current_view->text->sel_cursor =
3407 current_view->text->cursor;
3408 current_view->update(0);
3411 WriteAlert(_("Error"),
3412 _("Couldn't find this label"),
3413 _("in current document."));
3419 extern "C" void TocCancelCB(FL_OBJECT *, long)
3421 fl_hide_form(fd_form_toc->form_toc);
3425 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3427 static LyXParagraph * stapar = 0;
3428 TocList * tmptoclist = 0;
3430 /* deleted the toclist */
3433 tmptoclist = toclist->next;
3435 toclist = tmptoclist;
3439 tmptoclist = toclist;
3442 fl_clear_browser(fd_form_toc->browser_toc);
3443 if (!current_view->available()) {
3444 fl_add_browser_line(fd_form_toc->browser_toc,
3445 _("*** No Document ***"));
3448 fl_hide_object(fd_form_toc->browser_toc);
3449 /* get the table of contents */
3450 LyXParagraph * par = current_view->buffer()->paragraph;
3452 char * line = new char[200];
3458 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3462 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3463 par->GetLayout()).labeltype;
3465 if (labeltype >= LABEL_COUNTER_CHAPTER
3466 && labeltype <= LABEL_COUNTER_CHAPTER +
3467 current_view->buffer()->params.tocdepth) {
3468 /* insert this into the table of contents */
3469 /* first indent a little bit */
3473 textclasslist.TextClass(current_view->buffer()->
3474 params.textclass).maxcounter()) * 4 + 2;
3478 // Then the labestring
3479 if (!par->labelstring.empty()) {
3480 string::size_type i = 0;
3481 while (pos < 199 && i < par->labelstring.length()) {
3482 line[pos] = par->labelstring[i];
3491 /* now the contents */
3492 LyXParagraph::size_type i = 0;
3493 while (pos < 199 && i < par->size()) {
3494 c = par->GetChar(i);
3495 if (isprint(c) || c >= 128) {
3502 fl_add_browser_line(fd_form_toc->browser_toc, line);
3504 /* make a toclist entry */
3506 tmptoclist = new TocList;
3507 toclist = tmptoclist;
3509 tmptoclist->next = new TocList;
3510 tmptoclist = tmptoclist->next;
3513 tmptoclist->next = 0;
3515 for (a = 0; a < 6; ++a) {
3516 tmptoclist->counter[a] = par->GetFirstCounter(a);
3518 tmptoclist->appendix = par->appendix;
3520 par = par->LastPhysicalPar()->Next();
3524 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3525 fl_show_object(fd_form_toc->browser_toc);
3529 /* callbacks for form form_ref */
3530 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3532 if (!current_view->available())
3536 fl_get_browser_line(fd_form_ref->browser_ref,
3537 fl_get_browser(fd_form_ref->browser_ref));
3538 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3544 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3554 if(current_view->buffer()->isSGML())
3555 t += "[" + u + "]" + "{" + s + "}";
3560 new InsetRef(t, current_view->buffer());
3561 current_view->insertInset(new_inset);
3565 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3567 if (!current_view->available()) {
3568 fl_clear_browser(fd_form_ref->browser_ref);
3572 FL_OBJECT * brow = fd_form_ref->browser_ref;
3574 // Get the current line, in order to restore it later
3575 char const * const btmp = fl_get_browser_line(brow,
3576 fl_get_browser(brow));
3577 string currentstr = btmp ? btmp : "";
3579 fl_clear_browser(brow);
3581 string refs = current_view->buffer()->getReferenceList('\n');
3584 fl_addto_browser_chars(brow, refs.c_str());
3585 int total_lines = fl_get_browser_maxline(brow);
3586 for (int i = 1; i <= total_lines ; ++i) {
3587 if (fl_get_browser_line(brow, i) == currentstr) {
3592 fl_set_browser_topline(brow, topline);
3594 if (!fl_get_browser_maxline(brow)) {
3595 fl_add_browser_line(brow,
3596 _("*** No labels found in document ***"));
3597 fl_deactivate_object(brow);
3599 fl_select_browser_line(brow, topline);
3600 fl_activate_object(brow);
3602 if (current_view->buffer()->isReadonly()) {
3603 // would be better to de/activate insert buttons
3604 // but that's more work... besides this works. ARRae
3605 fl_hide_form(fd_form_ref->form_ref);
3607 if (!current_view->buffer()->isSGML()) {
3608 fl_deactivate_object(fd_form_ref->ref_name);
3609 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3612 fl_activate_object(fd_form_ref->ref_name);
3613 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3618 extern "C" void RefHideCB(FL_OBJECT *, long)
3620 fl_hide_form(fd_form_ref->form_ref);