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 using std::back_inserter;
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"
34 #include "insets/insetlabel.h"
35 #include "insets/figinset.h"
37 #include "latexoptions.h"
39 #include "minibuffer.h"
41 #include "bufferlist.h"
42 #include "support/filetools.h"
43 #include "support/path.h"
45 #include "lyx_gui_misc.h"
47 #include "lastfiles.h"
48 #include "support/FileInfo.h"
50 #include "support/syscall.h"
51 #include "support/lyxlib.h"
52 #include "lyxserver.h"
53 #include "FontLoader.h"
60 extern Combox * combo_language;
61 extern BufferList bufferlist;
62 extern void show_symbols_form();
63 extern FD_form_title * fd_form_title;
64 extern FD_form_paragraph * fd_form_paragraph;
65 extern FD_form_character * fd_form_character;
66 extern FD_form_document * fd_form_document;
67 extern FD_form_quotes * fd_form_quotes;
68 extern FD_form_preamble * fd_form_preamble;
69 extern FD_form_table * fd_form_table;
70 extern FD_form_print * fd_form_print;
71 extern FD_form_figure * fd_form_figure;
72 extern FD_form_screen * fd_form_screen;
73 extern FD_form_toc * fd_form_toc;
74 extern FD_form_ref * fd_form_ref;
75 extern FD_LaTeXOptions * fd_latex_options;
76 extern FD_form_bullet * fd_form_bullet;
78 extern BufferView * current_view; // called too many times in this file...
80 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
82 extern bool send_fax(string const & fname, string const & sendcmd);
83 extern void MenuSendto();
85 extern LyXServer * lyxserver;
86 extern FontLoader fontloader;
88 // this should be static, but I need it in buffer.C
89 bool quitting; // flag, that we are quitting the program
90 extern bool finished; // all cleanup done just let it run through now.
92 char ascii_type; /* for selection notify callbacks */
94 bool scrolling = false;
98 /* whether the work area should get callbacks */
99 bool input_prohibited = false;
101 /* the selection possible is needed, that only motion events are
102 * used, where the bottom press event was on the drawing area too */
103 bool selection_possible = false;
105 // This is used to make the dreaded font toggle problem hopefully go
106 // away. Definitely not the best solution, but I think it sorta works.
107 bool toggleall = true;
110 This is the inset locking stuff needed for mathed --------------------
112 an inset can simple call LockInset in it's edit call and *ONLY* in it's
114 Inset::Edit() can only be called by the main lyx module.
116 Then the inset may modify the menu's and/or iconbars.
118 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
120 During the lock, all button and keyboard events will be modified
121 and send to the inset through the following inset-features. Note that
122 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
123 to contain the code for restoring the menus and things like this.
126 virtual void InsetButtonPress(int x, int y, int button);
127 virtual void InsetButtonRelease(int x, int y, int button);
128 virtual void InsetKeyPress(XKeyEvent *ev);
129 virtual void InsetMotionNotify(int x, int y, int state);
130 virtual void InsetUnlock();
132 If a inset wishes any redraw and/or update it just has to call
134 It's is completly irrelevant, where the inset is. UpdateInset will
135 find it in any paragraph in any buffer.
136 Of course the_locking_inset and the insets in the current paragraph/buffer
137 are checked first, so no performance problem should occur.
139 Hope that's ok for the beginning, Alejandro,
140 sorry that I needed so much time,
145 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
147 /* these functions return 1 if an error occured,
149 // Now they work only for updatable insets. [Alejandro 080596]
150 //int LockInset(UpdatableInset * inset);
151 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
152 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
153 //int UnlockInset(UpdatableInset * inset);
154 //void LockedInsetStoreUndo(Undo::undo_kind kind);
156 /* this is for asyncron updating. UpdateInsetUpdateList will be called
157 automatically from LyX. Just insert the Inset into the Updatelist */
158 //void UpdateInsetUpdateList();
159 //void PutInsetIntoInsetUpdateList(Inset * inset);
161 //InsetUpdateStruct * InsetUpdateList = 0;
165 -----------------------------------------------------------------------
168 /* some function prototypes */
170 int RunLinuxDoc(BufferView *, int, string const &);
171 int RunDocBook(int, string const &);
172 void MenuWrite(Buffer * buf);
173 void MenuWriteAs(Buffer * buffer);
174 void MenuReload(Buffer * buf);
175 void MenuLayoutSave();
178 void ShowMessage(Buffer * buf, string const & msg1,
179 string const & msg2 = string(), string const & msg3 = string(), int delay=6)
182 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2, msg3, delay);
185 // can somebody think of something more clever? cerr?
186 cout << msg1 << msg2 << msg3 << endl;
190 // How should this actually work? Should it prohibit input in all BufferViews,
191 // or just in the current one? If "just the current one", then it should be
192 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
193 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
194 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
195 // current LyxView that should be prohibited (Lgb) (This applies to
196 // "AllowInput" as well.)
199 input_prohibited = true;
200 current_view->hideCursor();
202 static Cursor cursor;
203 static bool cursor_undefined = true;
205 if (cursor_undefined){
206 cursor = XCreateFontCursor(fl_display, XC_watch);
208 cursor_undefined = false;
211 /* set the cursor to the watch for all forms and the canvas */
212 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
214 if (fd_form_paragraph->form_paragraph->visible)
215 XDefineCursor(fl_display,
216 fd_form_paragraph->form_paragraph->window,
218 if (fd_form_character->form_character->visible)
219 XDefineCursor(fl_display,
220 fd_form_character->form_character->window,
224 fl_deactivate_all_forms();
228 // Should find a way to move this into BufferView.C
229 void SetXtermCursor(Window win)
231 static Cursor cursor;
232 static bool cursor_undefined = true;
233 if (cursor_undefined){
234 cursor = XCreateFontCursor(fl_display, XC_xterm);
236 cursor_undefined = false;
238 XDefineCursor(fl_display, win, cursor);
245 input_prohibited = false;
247 /* reset the cursor from the watch for all forms and the canvas */
249 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
250 if (fd_form_paragraph->form_paragraph->visible)
251 XUndefineCursor(fl_display,
252 fd_form_paragraph->form_paragraph->window);
253 if (fd_form_character->form_character->visible)
254 XUndefineCursor(fl_display,
255 fd_form_character->form_character->window);
257 // What to do about this? (Lgb)
258 if (current_view->belowMouse())
259 SetXtermCursor(current_view->owner()->getForm()->window);
262 fl_activate_all_forms();
266 void FreeUpdateTimer()
268 /* a real free timer would be better but I don't know
269 * how to do this with xforms */
274 void SetUpdateTimer(float time)
276 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
289 // should be moved to lyxfunc.C
290 void MenuWrite(Buffer * buffer)
293 if (!buffer->save()) {
294 string fname = buffer->fileName();
295 string s = MakeAbsPath(fname);
296 if (AskQuestion(_("Save failed. Rename and try again?"),
297 MakeDisplayPath(s, 50),
298 _("(If not, document is not saved.)"))) {
302 lastfiles->newFile(buffer->fileName());
307 // should be moved to BufferView.C
308 // Half of this func should be in LyXView, the rest in BufferView.
309 void MenuWriteAs(Buffer * buffer)
311 // Why do we require BufferView::text to be able to write a
312 // document? I see no point in that. (Lgb)
313 //if (!bv->text) return;
315 string fname = buffer->fileName();
316 string oldname = fname;
320 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
321 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
323 if (!IsLyXFilename(fname))
326 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
329 OnlyFilename(fname));
335 // Make sure the absolute filename ends with appropriate suffix
336 string s = MakeAbsPath(fname);
337 if (!IsLyXFilename(s))
340 // Same name as we have already?
342 if (!AskQuestion(_("Same name as document already has:"),
343 MakeDisplayPath(s, 50),
346 // Falls through to name change and save
348 // No, but do we have another file with this name open?
349 else if (bufferlist.exists(s)) {
350 if (AskQuestion(_("Another document with same name open!"),
351 MakeDisplayPath(s, 50),
352 _("Replace with current document?")))
354 bufferlist.close(bufferlist.getBuffer(s));
356 // Ok, change the name of the buffer, but don't save!
360 ShowMessage(buffer, _("Document renamed to '"),
361 MakeDisplayPath(s), _("', but not saved..."));
364 } // Check whether the file exists
367 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
368 MakeDisplayPath(s, 50),
373 // Ok, change the name of the buffer
377 // Small bug: If the save fails, we have irreversible changed the name
383 int MenuRunLaTeX(Buffer * buffer)
387 if (buffer->isLinuxDoc())
388 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
389 else if (buffer->isLiterate())
390 ret = buffer->runLiterate();
391 else if (buffer->isDocBook())
392 ret = RunDocBook(1, buffer->fileName());
394 ret = buffer->runLaTeX();
400 s = _("One error detected");
401 t = _("You should try to fix it.");
404 s += _(" errors detected.");
405 t = _("You should try to fix them.");
407 WriteAlert(_("There were errors during the LaTeX run."), s, t);
413 int MenuBuildProg(Buffer * buffer)
417 if (buffer->isLiterate())
418 ret = buffer->buildProgram();
420 string s = _("Wrong type of document");
421 string t = _("The Build operation is not allowed in this document");
422 WriteAlert(_("There were errors during the Build process."), s, t);
430 s = _("One error detected");
431 t = _("You should try to fix it.");
434 s += _(" errors detected.");
435 t = _("You should try to fix them.");
437 WriteAlert(_("There were errors during the Build process."), s, t);
443 int MenuRunChktex(Buffer * buffer)
447 if (buffer->isSGML()) {
448 WriteAlert(_("Chktex does not work with SGML derived documents."));
451 ret = buffer->runChktex();
457 s = _("No warnings found.");
458 } else if (ret == 1) {
459 s = _("One warning found.");
460 t = _("Use 'Edit->Go to Error' to find it.");
463 s += _(" warnings found.");
464 t = _("Use 'Edit->Go to Error' to find them.");
466 WriteAlert(_("Chktex run successfully"), s, t);
468 WriteAlert(_("Error!"), _("It seems chktex does not work."));
474 int MakeLaTeXOutput(Buffer * buffer)
480 string path = OnlyPath(buffer->fileName());
481 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
482 path = buffer->tmppath;
484 if (!buffer->isDviClean()) {
486 ret = MenuRunLaTeX(buffer);
492 /* wait == false means don't wait for termination */
493 /* wait == true means wait for termination */
494 // The bool should be placed last on the argument line. (Lgb)
495 // Returns false if we fail.
496 bool RunScript(Buffer * buffer, bool wait,
497 string const & command,
498 string const & orgname = string(),
499 bool need_shell = true)
503 string name = orgname;
506 if (MakeLaTeXOutput(buffer) > 0)
508 /* get DVI-Filename */
510 name = ChangeExtension(buffer->getLatexName(),
513 path = OnlyPath(name);
514 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
515 path = buffer->tmppath;
518 // At this point we check whether the command contains the
519 // filename parameter $$FName and if that's the case we
520 // substitute the real file name otherwise the filename is
521 // simply appended. rokrau 1/12/00
523 std::string::size_type i;
524 if ( (i=command.find("$$FName")) != std::string::npos)
526 cmd.replace(i,7,QuoteName(name));
529 cmd = command + ' ' + QuoteName(name);
538 // OS/2 cmd.exe has another use for '&'
540 // This is not NLS safe, but it's OK, I think.
541 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
543 // COMSPEC is set, unless user unsets
544 sh = OnlyFilename(GetEnvPath("COMSPEC"));
549 if (contains(sh, "cmd.exe")
550 || contains(sh, "4os2.exe"))
551 cmd = "start /min/n " + cmd;
556 // It seems that, if wait is false, we never get back
557 // the return code of the command. This means that all
558 // the code I added in PrintApplyCB is currently
561 #warning What should we do here?
563 ShowMessage(buffer, _("Executing command:"), cmd);
564 result = one.startscript(Systemcalls::System, cmd);
566 ShowMessage(buffer, _("Executing command:"), cmd);
567 result = one.startscript(wait ? Systemcalls::Wait
568 : Systemcalls::DontWait, cmd);
574 // Returns false if we fail
575 bool CreatePostscript(Buffer * buffer, bool wait = false)
584 if (MakeLaTeXOutput(buffer) > 0) {
588 // Generate postscript file
589 string psname = ChangeExtension (buffer->fileName(),
595 char real_papersize = buffer->params.papersize;
596 if (real_papersize == BufferParams::PAPER_DEFAULT)
597 real_papersize = lyxrc.default_papersize;
599 switch (real_papersize) {
600 case BufferParams::PAPER_USLETTER:
603 case BufferParams::PAPER_A3PAPER:
606 case BufferParams::PAPER_A4PAPER:
609 case BufferParams::PAPER_A5PAPER:
612 case BufferParams::PAPER_B5PAPER:
615 case BufferParams::PAPER_EXECUTIVEPAPER:
618 case BufferParams::PAPER_LEGALPAPER:
621 default: /* If nothing else fits, keep an empty value... */
625 // Make postscript file.
626 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
627 command += QuoteName(psname);
628 if (buffer->params.use_geometry
629 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
630 && !lyxrc.print_paper_dimension_flag.empty()
631 && !buffer->params.paperwidth.empty()
632 && !buffer->params.paperheight.empty()) {
633 // using a custom papersize
635 command += lyxrc.print_paper_dimension_flag + ' ';
636 command += buffer->params.paperwidth + ',';
637 command += buffer->params.paperheight;
638 } else if (!paper.empty()
639 && (real_papersize != BufferParams::PAPER_USLETTER ||
640 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
641 // dvips won't accept -t letter -t landscape. In all other
642 // cases, include the paper size explicitly.
644 command += lyxrc.print_paper_flag + ' ' + paper;
646 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
648 command += lyxrc.print_landscape_flag;
650 // push directorypath, if necessary
651 string path = OnlyPath(buffer->fileName());
652 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
653 path = buffer->tmppath;
656 bool ret = RunScript(buffer, wait, command);
662 // Returns false if we fail
663 //bool MenuPreviewPS(Buffer * buffer)
664 bool PreviewPostscript(Buffer * buffer)
670 // Generate postscript file
671 if (!CreatePostscript(buffer, true)) {
675 // Start postscript viewer
677 string ps = ChangeExtension (buffer->fileName(),
679 // push directorypath, if necessary
680 string path = OnlyPath(buffer->fileName());
681 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
682 path = buffer->tmppath;
685 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
691 void MenuFax(Buffer * buffer)
697 // Generate postscript file
698 if (!CreatePostscript(buffer, true)) {
703 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
704 string path = OnlyPath (buffer->fileName());
705 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
706 path = buffer->tmppath;
709 if (!lyxrc.fax_program.empty()) {
710 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
712 Systemcalls one(Systemcalls::System, help2);
714 send_fax(ps, lyxrc.fax_command);
718 // Returns false if we fail
719 bool PreviewDVI(Buffer * buffer)
725 string paper = lyxrc.view_dvi_paper_option;
726 if (!paper.empty()) {
728 char real_papersize = buffer->params.papersize;
729 if (real_papersize == BufferParams::PAPER_DEFAULT)
730 real_papersize = lyxrc.default_papersize;
732 switch (real_papersize) {
733 case BufferParams::PAPER_USLETTER:
736 case BufferParams::PAPER_A3PAPER:
739 case BufferParams::PAPER_A4PAPER:
742 case BufferParams::PAPER_A5PAPER:
745 case BufferParams::PAPER_B5PAPER:
748 case BufferParams::PAPER_EXECUTIVEPAPER:
749 paper += " foolscap";
751 case BufferParams::PAPER_LEGALPAPER:
754 default: /* If nothing else fits, keep the empty value */
757 if (real_papersize==' ') {
758 // if (paper.empty()) {
759 if (buffer->params.orientation
760 == BufferParams::ORIENTATION_LANDSCAPE)
761 // we HAVE to give a size when the page is in
762 // landscape, so use USletter.
763 paper = " -paper usr";
765 // paper = " -paper " + paper;
766 if (buffer->params.orientation
767 == BufferParams::ORIENTATION_LANDSCAPE)
771 // push directorypath, if necessary
772 string path = OnlyPath(buffer->fileName());
773 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
774 path = buffer->tmppath;
778 string command = lyxrc.view_dvi_command + " " + paper;
779 bool ret = RunScript(buffer, false, command);
784 bool AskOverwrite(Buffer * buffer, string const & s)
787 // be friendly if there is a gui
790 !AskQuestion(_("File already exists:"),
791 MakeDisplayPath(s, 50),
792 _("Do you want to overwrite the file?"))) {
793 ShowMessage(buffer, _("Canceled"));
800 void MenuMakeLaTeX(Buffer * buffer)
802 // Why care about this?
806 // Get LaTeX-Filename
807 string s = buffer->getLatexName(false);
809 if (!AskOverwrite(buffer, s))
812 if (buffer->isDocBook())
813 ShowMessage(buffer, _("DocBook does not have a latex backend"));
815 if (buffer->isLinuxDoc())
816 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
818 buffer->makeLaTeXFile(s, string(), true);
819 ShowMessage(buffer, _("Nice LaTeX file saved as"),
821 buffer->markDviDirty();
826 void MenuMakeLinuxDoc(Buffer * buffer)
829 //if (!bv->text) return;
831 if (!buffer->isLinuxDoc()) {
832 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
836 // Get LinuxDoc-Filename
837 string s = ChangeExtension(buffer->fileName(),
840 if (!AskOverwrite(buffer, s))
843 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
844 MakeDisplayPath(s),"'...");
846 buffer->makeLinuxDocFile(s, 65);
848 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
853 void MenuMakeDocBook(Buffer * buffer)
856 //if (!bv->text) return;
858 if (!buffer->isDocBook()) {
859 WriteAlert(_("Error!"),
860 _("Document class must be docbook."));
864 // Get DocBook-Filename
865 string s = ChangeExtension(buffer->fileName(),
868 if (!AskOverwrite(buffer, s))
871 ShowMessage(buffer, _("Building DocBook SGML file `"),
872 MakeDisplayPath(s), "'...");
874 buffer->makeDocBookFile(s, 65);
876 ShowMessage(buffer, _("DocBook SGML file save as"),
881 void MenuMakeAscii(Buffer * buffer)
884 //if (!bv->text) return;
886 /* get LaTeX-Filename */
887 string s = ChangeExtension (buffer->fileName(),
891 if (!AskOverwrite(buffer, s))
894 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
896 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
900 void MenuPrint(Buffer * buffer)
906 string input_file = ChangeExtension(buffer->fileName(),
907 lyxrc.print_file_extension,
909 fl_set_input(fd_form_print->input_file, input_file.c_str());
911 if (fd_form_print->form_print->visible) {
912 fl_raise_form(fd_form_print->form_print);
915 fl_show_form(fd_form_print->form_print,
916 FL_PLACE_MOUSE, FL_FULLBORDER,
921 void MenuMakeHTML(Buffer * buffer)
923 // First, create LaTeX file
924 MenuMakeLaTeX(buffer);
926 // And now, run the converter
927 string file = buffer->fileName();
928 Path path(OnlyPath(file));
929 // the tex file name has to be correct for
930 // latex, but the html file name can be
932 string result = ChangeExtension(file, ".html", false);
933 string infile = buffer->getLatexName(false);
934 string tmp = lyxrc.html_command;
935 tmp = subst(tmp, "$$FName", infile);
936 tmp = subst(tmp, "$$OutName", result);
938 int res = one.startscript(Systemcalls::System, tmp);
940 ShowMessage(buffer, _("Document exported as HTML to file `")
941 + MakeDisplayPath(result) +'\'');
943 ShowMessage(buffer, _("Unable to convert to HTML the file `")
944 + MakeDisplayPath(infile)
950 void MenuExport(Buffer * buffer, string const & extyp)
953 if (extyp == "latex") {
954 // make sure that this buffer is not linuxdoc
955 MenuMakeLaTeX(buffer);
958 else if (extyp == "linuxdoc") {
959 // make sure that this buffer is not latex
960 MenuMakeLinuxDoc(buffer);
963 else if (extyp == "docbook") {
964 // make sure that this buffer is not latex or linuxdoc
965 MenuMakeDocBook(buffer);
968 else if (extyp == "dvi") {
969 // Run LaTeX as "Update dvi..." Bernhard.
970 // We want the dvi in the current directory. This
971 // is achieved by temporarily disabling use of
972 // temp directory. As a side-effect, we get
973 // *.log and *.aux files also. (Asger)
974 bool flag = lyxrc.use_tempdir;
975 lyxrc.use_tempdir = false;
976 MenuRunLaTeX(buffer);
977 lyxrc.use_tempdir = flag;
980 else if (extyp == "postscript") {
981 // Start Print-dialog. Not as good as dvi... Bernhard.
983 // Since the MenuPrint is a pop-up, we can't use
984 // the same trick as above. (Asger)
985 // MISSING: Move of ps-file :-(
986 // And MenuPrint should not be used for this at all...
989 else if (extyp == "ascii") {
990 MenuMakeAscii(buffer);
992 else if (extyp == "custom") {
996 else if (extyp == "html") {
997 MenuMakeHTML(buffer);
1000 ShowMessage(buffer, _("Unknown export type: ") + extyp);
1007 lyxerr.debug() << "Running QuitLyX." << endl;
1009 if (!bufferlist.QwriteAll())
1012 lastfiles->writeFile(lyxrc.lastfiles);
1014 // Set a flag that we do quitting from the program,
1015 // so no refreshes are necessary.
1018 // close buffers first
1019 bufferlist.closeAll();
1021 // do any other cleanup procedures now
1022 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1024 DestroyLyXTmpDir(system_tempdir);
1032 // should probably be moved into BufferList (Lgb)
1033 // Perfect target for a thread...
1035 if (!current_view->available())
1038 if (current_view->buffer()->isBakClean()
1039 || current_view->buffer()->isReadonly()) {
1040 // We don't save now, but we'll try again later
1041 current_view->owner()->resetAutosaveTimer();
1045 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1047 // create autosave filename
1048 string fname = OnlyPath(current_view->buffer()->fileName());
1050 fname += OnlyFilename(current_view->buffer()->fileName());
1053 // tmp_ret will be located (usually) in /tmp
1054 // will that be a problem?
1055 string tmp_ret = tmpnam(0);
1057 pid_t pid = fork(); // If you want to debug the autosave
1058 // you should set pid to -1, and comment out the
1060 if (pid == 0 || pid == -1) {
1061 // pid = -1 signifies that lyx was unable
1062 // to fork. But we will do the save
1064 bool failed = false;
1065 if (!tmp_ret.empty()) {
1066 current_view->buffer()->writeFile(tmp_ret, 1);
1067 // assume successful write of tmp_ret
1068 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1070 // most likely couldn't move between filesystems
1071 // unless write of tmp_ret failed
1072 // so remove tmp file (if it exists)
1073 remove(tmp_ret.c_str());
1080 // failed to write/rename tmp_ret so try writing direct
1081 if (!current_view->buffer()->writeFile(fname, 1)) {
1082 // It is dangerous to do this in the child,
1083 // but safe in the parent, so...
1085 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1088 if (pid == 0) { // we are the child so...
1093 current_view->buffer()->markBakClean();
1094 current_view->owner()->resetAutosaveTimer();
1099 // Copyright CHT Software Service GmbH
1102 // create new file with template
1105 Buffer * NewLyxFile(string const & filename)
1107 // Split argument by :
1109 string tmpname = split(filename, name, ':');
1110 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1111 if (name.length() == 1
1112 && isalpha(static_cast<unsigned char>(name[0]))
1113 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1115 name += token(tmpname, ':', 0);
1116 tmpname = split(tmpname, ':');
1119 lyxerr.debug() << "Arg is " << filename
1120 << "\nName is " << name
1121 << "\nTemplate is " << tmpname << endl;
1123 // find a free buffer
1124 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1126 lastfiles->newFile(tmpbuf->fileName());
1131 // Insert ascii file (if filename is empty, prompt for one)
1132 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1137 if (!bv->available()) return;
1139 if (fname.empty()) {
1141 fname = fileDlg.Select(_("File to Insert"),
1142 bv->owner()->buffer()->filepath,
1145 if (fname.empty()) return;
1150 if (!fi.readable()) {
1151 WriteFSAlert(_("Error! Specified file is unreadable: "),
1152 MakeDisplayPath(fname, 50));
1156 ifstream ifs(fname.c_str());
1158 WriteFSAlert(_("Error! Cannot open specified file: "),
1159 MakeDisplayPath(fname, 50));
1163 ifs.unsetf(std::ios::skipws);
1164 std::istream_iterator<char> ii(ifs);
1165 std::istream_iterator<char> end;
1166 //string tmpstr(ii, end); // yet a reason for using std::string
1167 // alternate approach to get the file into a string:
1169 copy(ii, end, back_inserter(tmpstr));
1170 // insert the string
1171 current_view->hideCursor();
1173 // clear the selection
1176 bv->text->InsertStringA(tmpstr);
1178 bv->text->InsertStringB(tmpstr);
1183 void MenuShowTableOfContents()
1185 static int ow = -1, oh;
1188 if (fd_form_toc->form_toc->visible) {
1189 fl_raise_form(fd_form_toc->form_toc);
1191 fl_show_form(fd_form_toc->form_toc,
1192 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1193 _("Table Of Contents"));
1195 ow = fd_form_toc->form_toc->w;
1196 oh = fd_form_toc->form_toc->h;
1198 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1203 void MenuInsertLabel(char const * arg)
1207 if (label.empty()) {
1209 result = askForText(_("Enter new label to insert:"));
1211 label = frontStrip(strip(result.second));
1214 if (!label.empty()) {
1215 InsetLabel * new_inset = new InsetLabel;
1216 new_inset->setContents(label);
1217 current_view->insertInset(new_inset);
1223 void MenuInsertRef()
1225 static int ow = -1, oh;
1228 if (fd_form_ref->form_ref->visible) {
1229 fl_raise_form(fd_form_ref->form_ref);
1231 fl_show_form(fd_form_ref->form_ref,
1232 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1233 _("Insert Reference"));
1235 ow = fd_form_ref->form_ref->w;
1236 oh = fd_form_ref->form_ref->h;
1238 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1243 void MenuPasteSelection(char at)
1245 if (!current_view->available())
1250 Atom data_prop = XInternAtom(fl_display,
1253 if (data_prop == None)
1255 XConvertSelection(fl_display,
1256 XA_PRIMARY, XA_STRING, data_prop,
1257 current_view->owner()->getForm()->window, 0);
1262 // candidate for move to BufferView
1263 void Foot(BufferView * bv)
1265 if (!bv->available())
1268 bv->owner()->getMiniBuffer()
1269 ->Set(_("Inserting Footnote..."));
1272 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1277 // candidate for move to LyXView
1278 // This is only used in toolbar.C
1279 void LayoutsCB(int sel, void *)
1281 string tmp = tostr(sel);
1282 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1288 * SGML Linuxdoc support:
1289 * (flag == 0) make TeX output
1290 * (flag == 1) make dvi output
1292 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1299 /* generate a path-less extension name */
1300 string name = ChangeExtension (filename, ".sgml", true);
1301 string path = OnlyPath (filename);
1302 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1303 path = bv->buffer()->tmppath;
1307 if (!bv->available())
1309 bv->buffer()->makeLinuxDocFile(name, 0);
1310 #ifdef WITH_WARNINGS
1311 #warning remove this once we have a proper geometry class
1313 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1315 case BufferParams::PAPER_A4PAPER:
1316 add_flags = "-p a4";
1318 case BufferParams::PAPER_USLETTER:
1319 add_flags = "-p letter";
1321 default: /* nothing to be done yet ;-) */ break;
1328 case 0: /* TeX output asked */
1329 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1330 s2 = "sgml2latex " + add_flags + " -o tex "
1331 + lyxrc.sgml_extra_options + ' ' + name;
1332 if (one.startscript(Systemcalls::System, s2))
1335 case 1: /* dvi output asked */
1336 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1337 s2 = "sgml2latex " + add_flags + " -o dvi "
1338 + lyxrc.sgml_extra_options + ' ' + name;
1339 if (one.startscript(Systemcalls::System, s2)) {
1342 bv->buffer()->markDviClean();
1344 default: /* unknown output */
1350 bv->buffer()->redraw();
1356 * SGML DocBook support:
1357 * (flag == 1) make dvi output
1359 int RunDocBook(int flag, string const & filename)
1361 /* generate a path-less extension name */
1362 string name = ChangeExtension (filename, ".sgml", true);
1363 string path = OnlyPath (filename);
1364 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1365 path = current_view->buffer()->tmppath;
1369 if (!current_view->available())
1372 current_view->buffer()->makeDocBookFile(name, 0);
1374 // Shall this code go or should it stay? (Lgb)
1375 // string add_flags;
1376 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1378 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1379 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1380 // default: /* nothing to be done yet ;-) */ break;
1387 case 1: /* dvi output asked */
1389 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1390 string s2 = "sgmltools --backend dvi " + name;
1391 if (one.startscript(Systemcalls::System, s2)) {
1394 current_view->buffer()->markDviClean();
1397 default: /* unknown output */
1403 current_view->buffer()->redraw();
1408 void MenuLayoutCharacter()
1410 static int ow = -1, oh;
1412 if (fd_form_character->form_character->visible) {
1413 fl_raise_form(fd_form_character->form_character);
1415 fl_show_form(fd_form_character->form_character,
1416 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1417 _("Character Style"));
1419 ow = fd_form_character->form_character->w;
1420 oh = fd_form_character->form_character->h;
1422 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1428 void DeactivateParagraphButtons ()
1430 fl_deactivate_object (fd_form_paragraph->button_ok);
1431 fl_deactivate_object (fd_form_paragraph->button_apply);
1432 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1433 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1438 void ActivateParagraphButtons ()
1440 fl_activate_object (fd_form_paragraph->button_ok);
1441 fl_activate_object (fd_form_paragraph->button_apply);
1442 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1443 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1448 void DisableParagraphLayout ()
1450 DeactivateParagraphButtons();
1451 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1452 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1453 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1454 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1455 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1456 fl_deactivate_object (fd_form_paragraph->check_noindent);
1457 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1458 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1459 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1460 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1461 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1462 fl_deactivate_object (fd_form_paragraph->input_space_above);
1463 fl_deactivate_object (fd_form_paragraph->input_space_below);
1464 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1465 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1466 fl_deactivate_object (fd_form_paragraph->check_space_above);
1467 fl_deactivate_object (fd_form_paragraph->check_space_below);
1472 void EnableParagraphLayout ()
1474 ActivateParagraphButtons();
1475 fl_activate_object (fd_form_paragraph->input_labelwidth);
1476 fl_activate_object (fd_form_paragraph->check_lines_top);
1477 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1478 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1479 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1480 fl_activate_object (fd_form_paragraph->check_noindent);
1481 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1482 fl_activate_object (fd_form_paragraph->radio_align_right);
1483 fl_activate_object (fd_form_paragraph->radio_align_left);
1484 fl_activate_object (fd_form_paragraph->radio_align_block);
1485 fl_activate_object (fd_form_paragraph->radio_align_center);
1486 fl_activate_object (fd_form_paragraph->input_space_above);
1487 fl_activate_object (fd_form_paragraph->input_space_below);
1488 fl_activate_object (fd_form_paragraph->choice_space_above);
1489 fl_activate_object (fd_form_paragraph->choice_space_below);
1490 fl_activate_object (fd_form_paragraph->check_space_above);
1491 fl_activate_object (fd_form_paragraph->check_space_below);
1495 bool UpdateLayoutParagraph()
1497 if (!current_view->available()) {
1498 if (fd_form_paragraph->form_paragraph->visible)
1499 fl_hide_form(fd_form_paragraph->form_paragraph);
1503 Buffer * buf = current_view->buffer();
1505 fl_set_input(fd_form_paragraph->input_labelwidth,
1506 current_view->text->cursor.par->GetLabelWidthString().c_str());
1507 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1508 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1509 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1510 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1512 int align = current_view->text->cursor.par->GetAlign();
1513 if (align == LYX_ALIGN_LAYOUT)
1514 align = textclasslist.Style(buf->params.textclass,
1515 current_view->text->cursor.par->GetLayout()).align;
1518 case LYX_ALIGN_RIGHT:
1519 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1521 case LYX_ALIGN_LEFT:
1522 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1524 case LYX_ALIGN_CENTER:
1525 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1528 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1532 fl_set_button(fd_form_paragraph->check_lines_top,
1533 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1534 fl_set_button(fd_form_paragraph->check_lines_bottom,
1535 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1536 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1537 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1538 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1539 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1540 fl_set_button(fd_form_paragraph->check_noindent,
1541 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1542 fl_set_input (fd_form_paragraph->input_space_above, "");
1544 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1546 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1548 case VSpace::DEFSKIP:
1549 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1551 case VSpace::SMALLSKIP:
1552 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1554 case VSpace::MEDSKIP:
1555 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1557 case VSpace::BIGSKIP:
1558 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1561 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1563 case VSpace::LENGTH:
1564 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1565 fl_set_input (fd_form_paragraph->input_space_above,
1566 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1569 fl_set_button (fd_form_paragraph->check_space_above,
1570 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1571 fl_set_input (fd_form_paragraph->input_space_below, "");
1572 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1574 fl_set_choice (fd_form_paragraph->choice_space_below,
1577 case VSpace::DEFSKIP:
1578 fl_set_choice (fd_form_paragraph->choice_space_below,
1581 case VSpace::SMALLSKIP:
1582 fl_set_choice (fd_form_paragraph->choice_space_below,
1585 case VSpace::MEDSKIP:
1586 fl_set_choice (fd_form_paragraph->choice_space_below,
1589 case VSpace::BIGSKIP:
1590 fl_set_choice (fd_form_paragraph->choice_space_below,
1594 fl_set_choice (fd_form_paragraph->choice_space_below,
1597 case VSpace::LENGTH:
1598 fl_set_choice (fd_form_paragraph->choice_space_below,
1600 fl_set_input (fd_form_paragraph->input_space_below,
1601 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1604 fl_set_button (fd_form_paragraph->check_space_below,
1605 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1607 fl_set_button(fd_form_paragraph->check_noindent,
1608 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1610 if (current_view->buffer()->isReadonly()) {
1611 DisableParagraphLayout();
1613 EnableParagraphLayout();
1619 void MenuLayoutParagraph()
1621 if (UpdateLayoutParagraph()) {
1622 if (fd_form_paragraph->form_paragraph->visible) {
1623 fl_raise_form(fd_form_paragraph->form_paragraph);
1625 fl_show_form(fd_form_paragraph->form_paragraph,
1626 FL_PLACE_MOUSE, FL_FULLBORDER,
1627 _("Paragraph Environment"));
1634 void DeactivateDocumentButtons ()
1636 fl_deactivate_object (fd_form_document->button_ok);
1637 fl_deactivate_object (fd_form_document->button_apply);
1638 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1639 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1644 void ActivateDocumentButtons ()
1646 fl_activate_object (fd_form_document->button_ok);
1647 fl_activate_object (fd_form_document->button_apply);
1648 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1649 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1654 void DisableDocumentLayout ()
1656 DeactivateDocumentButtons ();
1657 fl_deactivate_object (fd_form_document->group_radio_separation);
1658 fl_deactivate_object (fd_form_document->radio_indent);
1659 fl_deactivate_object (fd_form_document->radio_skip);
1660 fl_deactivate_object (fd_form_document->choice_class);
1661 fl_deactivate_object (fd_form_document->choice_pagestyle);
1662 fl_deactivate_object (fd_form_document->choice_fonts);
1663 fl_deactivate_object (fd_form_document->choice_fontsize);
1664 fl_deactivate_object (fd_form_document->input_float_placement);
1665 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1666 fl_deactivate_object (fd_form_document->choice_inputenc);
1667 fl_deactivate_object (fd_form_document->group_radio_sides);
1668 fl_deactivate_object (fd_form_document->radio_sides_one);
1669 fl_deactivate_object (fd_form_document->radio_sides_two);
1670 fl_deactivate_object (fd_form_document->group_radio_columns);
1671 fl_deactivate_object (fd_form_document->radio_columns_one);
1672 fl_deactivate_object (fd_form_document->radio_columns_two);
1673 fl_deactivate_object (fd_form_document->input_extra);
1674 fl_deactivate_object (fd_form_document->choice_language);
1675 combo_language->deactivate();
1676 fl_deactivate_object (fd_form_document->input_default_skip);
1677 fl_deactivate_object (fd_form_document->choice_default_skip);
1678 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1679 fl_deactivate_object (fd_form_document->slider_tocdepth);
1680 fl_deactivate_object (fd_form_document->choice_spacing);
1681 fl_deactivate_object (fd_form_document->input_spacing);
1682 fl_deactivate_object (fd_form_document->check_use_amsmath);
1687 void EnableDocumentLayout ()
1689 ActivateDocumentButtons ();
1690 fl_activate_object (fd_form_document->group_radio_separation);
1691 fl_activate_object (fd_form_document->radio_indent);
1692 fl_activate_object (fd_form_document->radio_skip);
1693 fl_activate_object (fd_form_document->choice_class);
1694 fl_activate_object (fd_form_document->choice_pagestyle);
1695 fl_activate_object (fd_form_document->choice_fonts);
1696 fl_activate_object (fd_form_document->choice_fontsize);
1697 fl_activate_object (fd_form_document->input_float_placement);
1698 fl_activate_object (fd_form_document->choice_postscript_driver);
1699 fl_activate_object (fd_form_document->choice_inputenc);
1700 fl_activate_object (fd_form_document->group_radio_sides);
1701 fl_activate_object (fd_form_document->radio_sides_one);
1702 fl_activate_object (fd_form_document->radio_sides_two);
1703 fl_activate_object (fd_form_document->group_radio_columns);
1704 fl_activate_object (fd_form_document->radio_columns_one);
1705 fl_activate_object (fd_form_document->radio_columns_two);
1706 fl_activate_object (fd_form_document->input_extra);
1707 fl_activate_object (fd_form_document->choice_language);
1708 combo_language->activate();
1709 fl_activate_object (fd_form_document->input_default_skip);
1710 fl_activate_object (fd_form_document->choice_default_skip);
1711 fl_activate_object (fd_form_document->slider_secnumdepth);
1712 fl_activate_object (fd_form_document->slider_tocdepth);
1713 fl_activate_object (fd_form_document->choice_spacing);
1714 fl_activate_object (fd_form_document->input_spacing);
1715 fl_activate_object (fd_form_document->check_use_amsmath);
1719 bool UpdateLayoutDocument(BufferParams * params)
1721 if (!current_view->available()) {
1722 if (fd_form_document->form_document->visible)
1723 fl_hide_form(fd_form_document->form_document);
1728 params = ¤t_view->buffer()->params;
1729 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1731 fl_set_choice_text(fd_form_document->choice_class,
1732 textclasslist.DescOfClass(params->textclass).c_str());
1733 combo_language->select_text(params->language.c_str());
1735 fl_set_choice_text(fd_form_document->choice_fonts,
1736 params->fonts.c_str());
1737 fl_set_choice_text(fd_form_document->choice_inputenc,
1738 params->inputenc.c_str());
1739 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1740 params->graphicsDriver.c_str());
1742 // ale970405+lasgoutt970513
1743 fl_clear_choice(fd_form_document->choice_fontsize);
1744 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1745 fl_addto_choice(fd_form_document->choice_fontsize,
1746 tclass.opt_fontsize().c_str());
1747 fl_set_choice(fd_form_document->choice_fontsize,
1748 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1750 // ale970405+lasgoutt970513
1751 fl_clear_choice(fd_form_document->choice_pagestyle);
1752 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1753 fl_addto_choice(fd_form_document->choice_pagestyle,
1754 tclass.opt_pagestyle().c_str());
1756 fl_set_choice(fd_form_document->choice_pagestyle,
1757 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1759 fl_set_button(fd_form_document->radio_indent, 0);
1760 fl_set_button(fd_form_document->radio_skip, 0);
1763 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1765 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1766 fl_set_button(fd_form_document->radio_indent, 1);
1768 fl_set_button(fd_form_document->radio_skip, 1);
1770 switch (params->getDefSkip().kind()) {
1771 case VSpace::SMALLSKIP:
1772 fl_set_choice (fd_form_document->choice_default_skip, 1);
1774 case VSpace::MEDSKIP:
1775 fl_set_choice (fd_form_document->choice_default_skip, 2);
1777 case VSpace::BIGSKIP:
1778 fl_set_choice (fd_form_document->choice_default_skip, 3);
1780 case VSpace::LENGTH:
1781 fl_set_choice (fd_form_document->choice_default_skip, 4);
1782 fl_set_input (fd_form_document->input_default_skip,
1783 params->getDefSkip().asLyXCommand().c_str());
1786 fl_set_choice (fd_form_document->choice_default_skip, 2);
1790 fl_set_button(fd_form_document->radio_sides_one, 0);
1791 fl_set_button(fd_form_document->radio_sides_two, 0);
1793 switch (params->sides) {
1794 case LyXTextClass::OneSide:
1795 fl_set_button(fd_form_document->radio_sides_one, 1);
1797 case LyXTextClass::TwoSides:
1798 fl_set_button(fd_form_document->radio_sides_two, 1);
1802 fl_set_button(fd_form_document->radio_columns_one, 0);
1803 fl_set_button(fd_form_document->radio_columns_two, 0);
1805 if (params->columns == 2)
1806 fl_set_button(fd_form_document->radio_columns_two, 1);
1808 fl_set_button(fd_form_document->radio_columns_one, 1);
1810 fl_set_input(fd_form_document->input_spacing, "");
1811 switch (params->spacing.getSpace()) {
1812 case Spacing::Single:
1815 fl_set_choice(fd_form_document->choice_spacing, 1);
1818 case Spacing::Onehalf:
1821 fl_set_choice(fd_form_document->choice_spacing, 2);
1824 case Spacing::Double:
1827 fl_set_choice(fd_form_document->choice_spacing, 3);
1830 case Spacing::Other:
1832 fl_set_choice(fd_form_document->choice_spacing, 4);
1834 //sprintf(sval, "%g", params->spacing.getValue());
1837 sval << params->spacing.getValue(); // setw?
1838 fl_set_input(fd_form_document->input_spacing,
1839 sval.str().c_str());
1842 ostrstream sval(tval, 20);
1843 sval << params->spacing.getValue() << '\0'; // setw?
1844 fl_set_input(fd_form_document->input_spacing, sval.str());
1851 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1852 params->secnumdepth);
1853 fl_set_counter_value(fd_form_document->slider_tocdepth,
1855 if (!params->float_placement.empty()) { // buffer local (Lgb)
1856 fl_set_input(fd_form_document->input_float_placement,
1857 params->float_placement.c_str());
1859 fl_set_input(fd_form_document->input_float_placement, "");
1861 if (!params->options.empty())
1862 fl_set_input(fd_form_document->input_extra,
1863 params->options.c_str());
1865 fl_set_input(fd_form_document->input_extra, "");
1867 if (current_view->buffer()->isSGML()) {
1868 // bullets not used in SGML derived documents
1869 fl_deactivate_object(fd_form_document->button_bullets);
1870 fl_set_object_lcol(fd_form_document->button_bullets,
1873 fl_activate_object(fd_form_document->button_bullets);
1874 fl_set_object_lcol(fd_form_document->button_bullets,
1878 if (current_view->buffer()->isReadonly()) {
1879 DisableDocumentLayout();
1881 EnableDocumentLayout();
1888 void MenuLayoutDocument()
1890 if (UpdateLayoutDocument()) {
1891 if (fd_form_document->form_document->visible) {
1892 fl_raise_form(fd_form_document->form_document);
1894 fl_show_form(fd_form_document->form_document,
1895 FL_PLACE_MOUSE, FL_FULLBORDER,
1896 _("Document Layout"));
1902 bool UpdateLayoutQuotes()
1905 if (!current_view->available()
1906 || current_view->buffer()->isReadonly())
1910 fl_set_choice(fd_form_quotes->choice_quotes_language,
1911 current_view->buffer()->params.quotes_language + 1);
1912 fl_set_button(fd_form_quotes->radio_single, 0);
1913 fl_set_button(fd_form_quotes->radio_double, 0);
1915 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1916 fl_set_button(fd_form_quotes->radio_single, 1);
1918 fl_set_button(fd_form_quotes->radio_double, 1);
1919 } else if (fd_form_quotes->form_quotes->visible) {
1920 fl_hide_form(fd_form_quotes->form_quotes);
1926 void MenuLayoutQuotes()
1928 if (UpdateLayoutQuotes()) {
1929 if (fd_form_quotes->form_quotes->visible) {
1930 fl_raise_form(fd_form_quotes->form_quotes);
1932 fl_show_form(fd_form_quotes->form_quotes,
1933 FL_PLACE_MOUSE, FL_FULLBORDER,
1940 bool UpdateLayoutPreamble()
1943 if (!current_view->available())
1947 fl_set_input(fd_form_preamble->input_preamble,
1948 current_view->buffer()->params.preamble.c_str());
1950 if (current_view->buffer()->isReadonly()) {
1951 fl_deactivate_object(fd_form_preamble->input_preamble);
1952 fl_deactivate_object(fd_form_preamble->button_ok);
1953 fl_deactivate_object(fd_form_preamble->button_apply);
1954 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1955 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1958 fl_activate_object(fd_form_preamble->input_preamble);
1959 fl_activate_object(fd_form_preamble->button_ok);
1960 fl_activate_object(fd_form_preamble->button_apply);
1961 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1962 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1964 } else if (fd_form_preamble->form_preamble->visible) {
1965 fl_hide_form(fd_form_preamble->form_preamble);
1971 void MenuLayoutPreamble()
1973 static int ow = -1, oh;
1975 if (UpdateLayoutPreamble()) {
1976 if (fd_form_preamble->form_preamble->visible) {
1977 fl_raise_form(fd_form_preamble->form_preamble);
1979 fl_show_form(fd_form_preamble->form_preamble,
1980 FL_PLACE_MOUSE | FL_FREE_SIZE,
1982 _("LaTeX Preamble"));
1984 ow = fd_form_preamble->form_preamble->w;
1985 oh = fd_form_preamble->form_preamble->h;
1987 fl_set_form_minsize(fd_form_preamble->form_preamble,
1994 void MenuLayoutSave()
1996 if (!current_view->available())
1999 if (AskQuestion(_("Do you want to save the current settings"),
2000 _("for Character, Document, Paper and Quotes"),
2001 _("as default for new documents?")))
2002 current_view->buffer()->saveParamsAsDefaults();
2006 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2007 They also show the current font state. */
2010 void ToggleAndShow(BufferView *, LyXFont const &);
2013 void FontSize(string const & size)
2015 LyXFont font(LyXFont::ALL_IGNORE);
2016 font.setGUISize(size);
2017 ToggleAndShow(current_view, font);
2023 LyXFont font(LyXFont::ALL_IGNORE);
2024 font.setEmph(LyXFont::TOGGLE);
2025 ToggleAndShow(current_view, font);
2031 LyXFont font(LyXFont::ALL_IGNORE);
2032 font.setNoun(LyXFont::TOGGLE);
2033 ToggleAndShow(current_view, font);
2039 LyXFont font(LyXFont::ALL_IGNORE);
2040 font.setSeries(LyXFont::BOLD_SERIES);
2041 ToggleAndShow(current_view, font);
2047 LyXFont font(LyXFont::ALL_IGNORE);
2048 font.setUnderbar(LyXFont::TOGGLE);
2049 ToggleAndShow(current_view, font);
2055 LyXFont font(LyXFont::ALL_IGNORE);
2056 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2057 ToggleAndShow(current_view, font);
2063 LyXFont font(LyXFont::ALL_IGNORE);
2064 font.setFamily(LyXFont::SANS_FAMILY);
2065 ToggleAndShow(current_view, font);
2071 LyXFont font(LyXFont::ALL_IGNORE);
2072 font.setFamily(LyXFont::ROMAN_FAMILY);
2073 ToggleAndShow(current_view, font);
2079 LyXFont font(LyXFont::ALL_IGNORE);
2080 font.setLatex (LyXFont::TOGGLE);
2081 ToggleAndShow(current_view, font);
2084 void LangCB(string const & l)
2086 LyXFont font(LyXFont::ALL_IGNORE);
2087 Languages::iterator lit = languages.find(l);
2088 if (lit != languages.end()) {
2089 font.setLanguage(&(*lit).second);
2090 ToggleAndShow(current_view, font);
2092 WriteAlert(_("Error! unknown language"),l);
2098 LyXFont font(LyXFont::ALL_INHERIT);
2099 ToggleAndShow(current_view, font);
2103 /* -------> Returns the current font and depth by printing a message. In the
2104 * future perhaps we could try to implement a callback to the button-bar.
2105 * That is, `light' the bold button when the font is currently bold, etc.
2107 string CurrentState()
2110 if (current_view->available()) {
2111 // I think we should only show changes from the default
2113 Buffer * buffer = current_view->buffer();
2114 LyXFont font = current_view->text->real_current_font;
2115 LyXFont defaultfont = textclasslist.TextClass(buffer->
2116 params.textclass).defaultfont();
2117 font.reduce(defaultfont);
2118 state = _("Font: ") + font.stateText();
2120 int depth = current_view->text->GetDepth();
2122 state += string(_(", Depth: ")) + tostr(depth);
2128 // candidate for move to BufferView
2129 /* -------> Does the actual toggle job of the XxxCB() calls above.
2130 * Also shows the current font state.
2133 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2135 if (bv->available()) {
2138 if (bv->the_locking_inset)
2139 bv->the_locking_inset->SetFont(bv, font, toggleall);
2141 bv->text->ToggleFree(font, toggleall);
2147 // candidate for move to BufferView
2148 void Margin(BufferView * bv)
2150 if (bv->available()) {
2151 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2154 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2162 if (fd_form_figure->form_figure->visible) {
2163 fl_raise_form(fd_form_figure->form_figure);
2165 fl_show_form(fd_form_figure->form_figure,
2166 FL_PLACE_MOUSE, FL_FULLBORDER,
2167 _("Insert Figure"));
2174 if (fd_form_table->form_table->visible) {
2175 fl_raise_form(fd_form_table->form_table);
2177 fl_show_form(fd_form_table->form_table,
2178 FL_PLACE_MOUSE, FL_FULLBORDER,
2184 // candidate for move to BufferView
2185 void Melt(BufferView * bv)
2187 if (!bv->available()) return;
2189 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2193 bv->text->MeltFootnoteEnvironment();
2198 // candidate for move to BufferView
2199 // Change environment depth.
2200 // if decInc >= 0, increment depth
2201 // if decInc < 0, decrement depth
2202 void changeDepth(BufferView * bv, int decInc)
2204 if (!bv->available()) return;
2209 bv->text->IncDepth();
2211 bv->text->DecDepth();
2213 bv->owner()->getMiniBuffer()
2214 ->Set(_("Changed environment depth"
2215 " (in possible range, maybe not)"));
2219 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2220 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2221 LyXFont UserFreeFont()
2223 LyXFont font(LyXFont::ALL_IGNORE);
2225 int pos = fl_get_choice(fd_form_character->choice_family);
2227 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2228 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2229 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2230 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2231 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2234 pos = fl_get_choice(fd_form_character->choice_series);
2236 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2237 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2238 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2239 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2242 pos = fl_get_choice(fd_form_character->choice_shape);
2244 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2245 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2246 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2247 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2248 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2249 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2252 pos = fl_get_choice(fd_form_character->choice_size);
2254 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2255 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2256 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2257 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2258 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2259 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2260 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2261 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2262 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2263 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2264 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2265 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2266 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2267 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2270 pos = fl_get_choice(fd_form_character->choice_bar);
2272 case 1: font.setEmph(LyXFont::IGNORE);
2273 font.setUnderbar(LyXFont::IGNORE);
2274 font.setNoun(LyXFont::IGNORE);
2275 font.setLatex(LyXFont::IGNORE);
2277 case 2: font.setEmph(LyXFont::TOGGLE); break;
2278 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2279 case 4: font.setNoun(LyXFont::TOGGLE); break;
2280 case 5: font.setLatex(LyXFont::TOGGLE); break;
2281 case 6: font.setEmph(LyXFont::INHERIT);
2282 font.setUnderbar(LyXFont::INHERIT);
2283 font.setNoun(LyXFont::INHERIT);
2284 font.setLatex(LyXFont::INHERIT);
2288 pos = fl_get_choice(fd_form_character->choice_color);
2290 case 1: font.setColor(LColor::ignore); break;
2291 case 2: font.setColor(LColor::none); break;
2292 case 3: font.setColor(LColor::black); break;
2293 case 4: font.setColor(LColor::white); break;
2294 case 5: font.setColor(LColor::red); break;
2295 case 6: font.setColor(LColor::green); break;
2296 case 7: font.setColor(LColor::blue); break;
2297 case 8: font.setColor(LColor::cyan); break;
2298 case 9: font.setColor(LColor::magenta); break;
2299 case 10: font.setColor(LColor::yellow); break;
2300 case 11: font.setColor(LColor::inherit); break;
2309 ToggleAndShow(current_view, UserFreeFont());
2313 /* callbacks for form form_title */
2314 extern "C" void TimerCB(FL_OBJECT *, long)
2316 // only if the form still exists
2317 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2318 if (fd_form_title->form_title->visible) {
2319 fl_hide_form(fd_form_title->form_title);
2321 fl_free_form(fd_form_title->form_title);
2322 fd_form_title->form_title = 0;
2327 /* callbacks for form form_paragraph */
2329 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2331 // "Synchronize" the choices and input fields, making it
2332 // impossible to commit senseless data.
2334 FD_form_paragraph const * fp = fd_form_paragraph;
2336 if (obj == fp->choice_space_above) {
2337 if (fl_get_choice (fp->choice_space_above) != 7) {
2338 fl_set_input (fp->input_space_above, "");
2339 ActivateParagraphButtons();
2341 } else if (obj == fp->choice_space_below) {
2342 if (fl_get_choice (fp->choice_space_below) != 7) {
2343 fl_set_input (fp->input_space_below, "");
2344 ActivateParagraphButtons();
2346 } else if (obj == fp->input_space_above) {
2347 string input = fl_get_input (fp->input_space_above);
2349 if (input.empty()) {
2350 fl_set_choice (fp->choice_space_above, 1);
2351 ActivateParagraphButtons();
2353 else if (isValidGlueLength (input)) {
2354 fl_set_choice (fp->choice_space_above, 7);
2355 ActivateParagraphButtons();
2358 fl_set_choice (fp->choice_space_above, 7);
2359 DeactivateParagraphButtons();
2361 } else if (obj == fp->input_space_below) {
2362 string input = fl_get_input (fp->input_space_below);
2364 if (input.empty()) {
2365 fl_set_choice (fp->choice_space_below, 1);
2366 ActivateParagraphButtons();
2368 else if (isValidGlueLength (input)) {
2369 fl_set_choice (fp->choice_space_below, 7);
2370 ActivateParagraphButtons();
2373 fl_set_choice (fp->choice_space_below, 7);
2374 DeactivateParagraphButtons();
2380 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2382 if (!current_view->available())
2385 VSpace space_top, space_bottom;
2387 string labelwidthstring;
2390 // If a vspace kind is "Length" but there's no text in
2391 // the input field, reset the kind to "None".
2392 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2393 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2394 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2396 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2397 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2398 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2401 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2402 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2403 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2404 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2405 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2406 case 1: space_top = VSpace(VSpace::NONE); break;
2407 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2408 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2409 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2410 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2411 case 6: space_top = VSpace(VSpace::VFILL); break;
2412 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2414 if (fl_get_button (fd_form_paragraph->check_space_above))
2415 space_top.setKeep (true);
2416 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2417 case 1: space_bottom = VSpace(VSpace::NONE); break;
2418 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2419 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2420 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2421 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2422 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2423 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2425 if (fl_get_button (fd_form_paragraph->check_space_below))
2426 space_bottom.setKeep (true);
2428 if (fl_get_button(fd_form_paragraph->radio_align_left))
2429 align = LYX_ALIGN_LEFT;
2430 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2431 align = LYX_ALIGN_RIGHT;
2432 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2433 align = LYX_ALIGN_CENTER;
2435 align = LYX_ALIGN_BLOCK;
2437 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2438 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2440 current_view->text->SetParagraph(line_top,
2449 current_view->update(1);
2450 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2454 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2456 fl_hide_form(fd_form_paragraph->form_paragraph);
2460 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2462 ParagraphApplyCB(ob, data);
2463 ParagraphCancelCB(ob, data);
2467 /* callbacks for form form_character */
2469 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2471 // we set toggleall locally here, since it should be true for
2472 // all other uses of ToggleAndShow() (JMarc)
2473 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2474 ToggleAndShow(current_view, UserFreeFont());
2479 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2481 fl_hide_form(fd_form_character->form_character);
2485 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2487 CharacterApplyCB(ob, data);
2488 CharacterCloseCB(ob, data);
2492 /* callbacks for form form_document */
2494 void UpdateDocumentButtons(BufferParams const & params)
2496 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2498 switch (params.sides) {
2499 case LyXTextClass::OneSide:
2500 fl_set_button(fd_form_document->radio_sides_one, 1);
2502 case LyXTextClass::TwoSides:
2503 fl_set_button(fd_form_document->radio_sides_two, 1);
2507 if (params.columns == 2)
2508 fl_set_button(fd_form_document->radio_columns_two, 1);
2510 fl_set_button(fd_form_document->radio_columns_one, 1);
2512 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2513 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2514 params.secnumdepth);
2515 fl_set_counter_value(fd_form_document->slider_tocdepth,
2520 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2523 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2524 if (AskQuestion(_("Should I set some parameters to"),
2525 fl_get_choice_text(ob),
2526 _("the defaults of this document class?"))) {
2527 BufferParams params = BufferParams();
2528 params.textclass = fl_get_choice(ob)-1;
2529 params.useClassDefaults();
2530 UpdateLayoutDocument(¶ms);
2531 UpdateDocumentButtons(params);
2534 // unable to load new style
2535 WriteAlert(_("Conversion Errors!"),
2536 _("Unable to switch to new document class."),
2537 _("Reverting to original document class."));
2538 fl_set_choice(fd_form_document->choice_class,
2539 current_view->buffer()->params.textclass + 1);
2545 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2547 // "Synchronize" the choice and the input field, so that it
2548 // is impossible to commit senseless data.
2549 FD_form_document const * fd = fd_form_document;
2551 if (obj == fd->choice_default_skip) {
2552 if (fl_get_choice (fd->choice_default_skip) != 4) {
2553 fl_set_input (fd->input_default_skip, "");
2554 ActivateDocumentButtons();
2556 } else if (obj == fd->input_default_skip) {
2558 char const * input = fl_get_input (fd->input_default_skip);
2561 fl_set_choice (fd->choice_default_skip, 2);
2562 ActivateDocumentButtons();
2563 } else if (isValidGlueLength (input)) {
2564 fl_set_choice (fd->choice_default_skip, 4);
2565 ActivateDocumentButtons();
2567 fl_set_choice (fd->choice_default_skip, 4);
2568 DeactivateDocumentButtons();
2574 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2576 // "Synchronize" the choice and the input field, so that it
2577 // is impossible to commit senseless data.
2578 FD_form_document const * fd = fd_form_document;
2580 if (obj == fd->choice_spacing
2581 && fl_get_choice (fd->choice_spacing) != 4) {
2582 fl_set_input(fd->input_spacing, "");
2583 } else if (obj == fd->input_spacing) {
2585 const char* input = fl_get_input (fd->input_spacing);
2588 fl_set_choice (fd->choice_spacing, 1);
2590 fl_set_choice (fd->choice_spacing, 4);
2596 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2599 BufferParams * params = &(current_view->buffer()->params);
2601 params->language = combo_language->getline();
2602 Languages::iterator lit = languages.find(params->language);
2603 if (lit != languages.end())
2604 params->language_info = &(*lit).second;
2606 params->language_info = default_language;
2608 // If default skip is a "Length" but there's no text in the
2609 // input field, reset the kind to "Medskip", which is the default.
2610 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2611 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2612 fl_set_choice (fd_form_document->choice_default_skip, 2);
2615 /* this shouldn't be done automatically IMO. For example I write german
2616 * documents with an american keyboard very often. Matthias */
2618 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2619 fl_get_choice(fd_form_document->choice_language)); */
2621 fl_get_choice_text(fd_form_document->choice_fonts);
2623 fl_get_choice_text(fd_form_document->choice_inputenc);
2625 fl_get_choice_text(fd_form_document->choice_fontsize);
2627 fl_get_choice_text(fd_form_document->choice_pagestyle);
2628 params->graphicsDriver =
2629 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2630 params->use_amsmath =
2631 fl_get_button(fd_form_document->check_use_amsmath);
2633 if (!current_view->available())
2635 if (lyxrc.rtl_support) {
2636 current_view->text->SetCursor(current_view->text->cursor.par,
2637 current_view->text->cursor.pos);
2638 current_view->setState();
2641 LyXTextClassList::ClassList::size_type new_class =
2642 fl_get_choice(fd_form_document->choice_class) - 1;
2644 if (params->textclass != new_class) {
2645 // try to load new_class
2646 if (textclasslist.Load(new_class)) {
2647 // successfully loaded
2649 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2650 int ret = current_view->text->
2651 SwitchLayoutsBetweenClasses(current_view->buffer()->
2654 current_view->buffer()->
2660 s = _("One paragraph couldn't be converted");
2663 s += _(" paragraphs couldn't be converted");
2665 WriteAlert(_("Conversion Errors!"), s,
2666 _("into chosen document class"));
2669 params->textclass = new_class;
2671 // problem changing class -- warn user and retain old style
2672 WriteAlert(_("Conversion Errors!"),
2673 _("Unable to switch to new document class."),
2674 _("Reverting to original document class."));
2675 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2679 char tmpsep = params->paragraph_separation;
2680 if (fl_get_button(fd_form_document->radio_indent))
2681 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2683 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2684 if (tmpsep != params->paragraph_separation)
2687 VSpace tmpdefskip = params->getDefSkip();
2688 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2689 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2690 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2691 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2692 case 4: params->setDefSkip(
2693 VSpace (LyXGlueLength (fl_get_input
2694 (fd_form_document->input_default_skip))));
2696 // DocumentDefskipCB assures that this never happens
2697 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2699 if (!(tmpdefskip == params->getDefSkip()))
2702 if (fl_get_button(fd_form_document->radio_columns_two))
2703 params->columns = 2;
2705 params->columns = 1;
2706 if (fl_get_button(fd_form_document->radio_sides_two))
2707 params->sides = LyXTextClass::TwoSides;
2709 params->sides = LyXTextClass::OneSide;
2711 Spacing tmpSpacing = params->spacing;
2712 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2714 lyxerr.debug() << "Spacing: SINGLE" << endl;
2715 params->spacing.set(Spacing::Single);
2718 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2719 params->spacing.set(Spacing::Onehalf);
2722 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2723 params->spacing.set(Spacing::Double);
2726 lyxerr.debug() << "Spacing: OTHER" << endl;
2727 params->spacing.set(Spacing::Other,
2728 fl_get_input(fd_form_document->input_spacing));
2731 if (tmpSpacing != params->spacing)
2734 signed char tmpchar =
2735 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2736 if (params->secnumdepth != tmpchar)
2738 params->secnumdepth = tmpchar;
2741 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2743 params->float_placement =
2744 fl_get_input(fd_form_document->input_float_placement);
2746 // More checking should be done to ensure the string doesn't have
2747 // spaces or illegal placement characters in it. (thornley)
2750 current_view->redoCurrentBuffer();
2752 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2753 current_view->buffer()->markDirty();
2756 fl_get_input(fd_form_document->input_extra);
2761 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2763 fl_hide_form(fd_form_document->form_document);
2767 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2769 DocumentCancelCB(ob, data);
2770 DocumentApplyCB(ob, data);
2774 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2777 // bullet callbacks etc. in bullet_panel.C -- ARRae
2781 /* callbacks for form form_quotes */
2783 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2785 if (!current_view->available())
2788 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2789 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2790 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2792 lga = InsetQuotes::EnglishQ;
2795 lga = InsetQuotes::SwedishQ;
2798 lga = InsetQuotes::GermanQ;
2801 lga = InsetQuotes::PolishQ;
2804 lga = InsetQuotes::FrenchQ;
2807 lga = InsetQuotes::DanishQ;
2810 current_view->buffer()->params.quotes_language = lga;
2811 if (fl_get_button(fd_form_quotes->radio_single))
2812 current_view->buffer()->
2813 params.quotes_times = InsetQuotes::SingleQ;
2815 current_view->buffer()->
2816 params.quotes_times = InsetQuotes::DoubleQ;
2820 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2822 fl_hide_form(fd_form_quotes->form_quotes);
2826 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2828 QuotesApplyCB(ob, data);
2829 QuotesCancelCB(ob, data);
2834 /* callbacks for form form_preamble */
2836 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2838 fl_hide_form(fd_form_preamble->form_preamble);
2842 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2844 if (!current_view->available())
2847 current_view->buffer()->params.preamble =
2848 fl_get_input(fd_form_preamble->input_preamble);
2849 current_view->buffer()->markDirty();
2850 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2854 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2856 PreambleApplyCB(ob, data);
2857 PreambleCancelCB(ob, data);
2861 /* callbacks for form form_table */
2863 extern "C" void TableApplyCB(FL_OBJECT *, long)
2865 if (!current_view->available())
2868 // check for tables in tables
2869 if (current_view->text->cursor.par->table){
2870 WriteAlert(_("Impossible Operation!"),
2871 _("Cannot insert table in table."),
2876 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2878 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2879 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2882 current_view->hideCursor();
2883 current_view->beforeChange();
2884 current_view->update(-2);
2886 current_view->text->SetCursorParUndo();
2887 current_view->text->FreezeUndo();
2889 current_view->text->BreakParagraph();
2890 current_view->update(-1);
2892 if (current_view->text->cursor.par->Last()) {
2893 current_view->text->CursorLeft();
2895 current_view->text->BreakParagraph();
2896 current_view->update(-1);
2899 current_view->text->current_font.setLatex(LyXFont::OFF);
2900 //if (!fl_get_button(fd_form_table->check_latex)){
2901 // insert the new wysiwy table
2902 current_view->text->SetLayout(0); // standard layout
2903 if (current_view->text->cursor.par->footnoteflag ==
2904 LyXParagraph::NO_FOOTNOTE) {
2906 ->SetParagraph(0, 0,
2908 VSpace (0.3 * current_view->buffer()->
2909 params.spacing.getValue(),
2911 VSpace (0.3 * current_view->buffer()->
2912 params.spacing.getValue(),
2919 ->SetParagraph(0, 0,
2921 VSpace(VSpace::NONE),
2922 VSpace(VSpace::NONE),
2928 current_view->text->cursor.par->table =
2929 new LyXTable(xsize, ysize);
2931 Language const * lang =
2932 current_view->text->cursor.par->getParLanguage();
2933 LyXFont font(LyXFont::ALL_INHERIT,lang);
2934 for (int i = 0; i < xsize * ysize - 1; ++i) {
2935 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2936 current_view->text->cursor.par->SetFont(0, font);
2938 current_view->text->RedoParagraph();
2940 current_view->text->UnFreezeUndo();
2942 current_view->update(1);
2943 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2944 current_view->setState();
2948 extern "C" void TableCancelCB(FL_OBJECT *, long)
2950 fl_hide_form(fd_form_table->form_table);
2954 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2956 TableApplyCB(ob, data);
2957 TableCancelCB(ob, data);
2961 /* callbacks for form form_print */
2963 extern "C" void PrintCancelCB(FL_OBJECT *, long)
2965 fl_hide_form(fd_form_print->form_print);
2970 bool stringOnlyContains (string const & LStr, char const * cset)
2972 char const * cstr = LStr.c_str() ;
2974 return strspn(cstr, cset) == strlen(cstr) ;
2978 extern "C" void PrintApplyCB(FL_OBJECT *, long)
2980 if (!current_view->available())
2982 Buffer * buffer = current_view->buffer();
2983 string path = OnlyPath(buffer->fileName());
2986 if (fl_get_button(fd_form_print->radio_even_pages))
2987 pageflag = lyxrc.print_evenpage_flag + ' ';
2988 else if (fl_get_button(fd_form_print->radio_odd_pages))
2989 pageflag = lyxrc.print_oddpage_flag + ' ';
2991 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
2992 // User may give a page (range) list
2993 // User may print multiple (unsorted) copies
2994 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
2995 pages = subst(pages, '+',',');
2996 pages = frontStrip(strip(pages)) ;
2997 while (!pages.empty()) { // a page range was given
2999 pages = split (pages, piece, ',') ;
3000 piece = strip(piece) ;
3001 piece = frontStrip(piece) ;
3002 if ( !stringOnlyContains (piece, "0123456789-") ) {
3003 WriteAlert(_("ERROR! Unable to print!"),
3004 _("Check 'range of pages'!"));
3007 if (piece.find('-') == string::npos) { // not found
3008 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
3009 } else if (suffixIs(piece, "-") ) { // missing last page
3010 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
3011 } else if (prefixIs(piece, "-") ) { // missing first page
3012 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
3014 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
3018 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3019 if (!copies.empty()) { // a number of copies was given
3020 if ( !stringOnlyContains (copies, "0123456789") ) {
3021 WriteAlert(_("ERROR! Unable to print!"),
3022 _("Check 'number of copies'!"));
3025 if (fl_get_button(fd_form_print->do_unsorted))
3026 pageflag += lyxrc.print_copies_flag;
3028 pageflag += lyxrc.print_collcopies_flag;
3029 pageflag += " " + copies + ' ' ;
3033 if (fl_get_button(fd_form_print->radio_order_reverse))
3034 reverseflag = lyxrc.print_reverse_flag + ' ';
3036 string orientationflag;
3037 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3038 orientationflag = lyxrc.print_landscape_flag + ' ';
3040 string ps_file = fl_get_input(fd_form_print->input_file);
3041 string printer = strip(fl_get_input(fd_form_print->input_printer));
3044 if (lyxrc.print_adapt_output // printer name should be passed to dvips
3045 && ! printer.empty()) // a printer name has been given
3046 printerflag = lyxrc.print_to_printer + printer + ' ';
3049 if (!lyxrc.print_extra_options.empty())
3050 extraflags = lyxrc.print_extra_options + ' ';
3052 string command = lyxrc.print_command + ' '
3053 + printerflag + pageflag + reverseflag
3054 + orientationflag + extraflags;
3056 char real_papersize = buffer->params.papersize;
3057 if (real_papersize == BufferParams::PAPER_DEFAULT)
3058 real_papersize = lyxrc.default_papersize;
3061 switch (real_papersize) {
3062 case BufferParams::PAPER_USLETTER:
3065 case BufferParams::PAPER_A3PAPER:
3068 case BufferParams::PAPER_A4PAPER:
3071 case BufferParams::PAPER_A5PAPER:
3074 case BufferParams::PAPER_B5PAPER:
3077 case BufferParams::PAPER_EXECUTIVEPAPER:
3080 case BufferParams::PAPER_LEGALPAPER:
3083 default: /* If nothing else fits, keep an empty value... */
3087 if (buffer->params.use_geometry
3088 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3089 && !lyxrc.print_paper_dimension_flag.empty()
3090 && !buffer->params.paperwidth.empty()
3091 && !buffer->params.paperheight.empty()) {
3092 // using a custom papersize
3094 command += lyxrc.print_paper_dimension_flag + ' ';
3095 command += buffer->params.paperwidth + ',';
3096 command += buffer->params.paperheight + ' ';
3097 } else if (!lyxrc.print_paper_flag.empty()
3099 && (real_papersize != BufferParams::PAPER_USLETTER ||
3100 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3101 command += " " + lyxrc.print_paper_flag + " " + paper + " ";
3103 if (fl_get_button(fd_form_print->radio_file))
3104 command += lyxrc.print_to_file
3105 + QuoteName(MakeAbsPath(ps_file, path));
3106 else if (!lyxrc.print_spool_command.empty())
3107 command += lyxrc.print_to_file
3108 + QuoteName(ps_file);
3110 // push directorypath, if necessary
3111 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
3112 path = buffer->tmppath;
3117 if (!lyxrc.print_spool_command.empty() &&
3118 !fl_get_button(fd_form_print->radio_file)) {
3119 string command2 = lyxrc.print_spool_command + ' ';
3120 if (!printer.empty())
3121 command2 += lyxrc.print_spool_printerprefix
3123 // First run dvips and, if succesful, then spool command
3124 if ((result = RunScript(buffer, true, command))) {
3125 result = RunScript(buffer, false, command2, ps_file);
3128 result = RunScript(buffer, false, command);
3131 WriteAlert(_("Error:"),
3132 _("Unable to print"),
3133 _("Check that your parameters are correct"));
3137 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3139 PrintCancelCB(ob, data);
3140 PrintApplyCB(ob, data);
3144 /* callbacks for form form_figure */
3145 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3147 if (!current_view->available())
3150 Buffer * buffer = current_view->buffer();
3151 if(buffer->isReadonly()) // paranoia
3154 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3155 if (fl_get_button(fd_form_figure->radio_inline)
3156 || current_view->text->cursor.par->table) {
3157 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3158 current_view->insertInset(new_inset);
3159 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3160 new_inset->Edit(current_view, 0, 0, 0);
3164 current_view->hideCursor();
3165 current_view->update(-2);
3166 current_view->beforeChange();
3168 current_view->text->SetCursorParUndo();
3169 current_view->text->FreezeUndo();
3171 current_view->text->BreakParagraph();
3172 current_view->update(-1);
3174 if (current_view->text->cursor.par->Last()) {
3175 current_view->text->CursorLeft();
3177 current_view->text->BreakParagraph();
3178 current_view->update(-1);
3181 // The standard layout should always be numer 0;
3182 current_view->text->SetLayout(0);
3184 if (current_view->text->cursor.par->footnoteflag ==
3185 LyXParagraph::NO_FOOTNOTE) {
3186 current_view->text->
3189 VSpace (0.3 * buffer->params.spacing.getValue(),
3192 buffer->params.spacing.getValue(),
3194 LYX_ALIGN_CENTER, string(), 0);
3196 current_view->text->SetParagraph(0, 0,
3198 VSpace(VSpace::NONE),
3199 VSpace(VSpace::NONE),
3205 current_view->update(-1);
3207 Inset * new_inset = new InsetFig(100, 100, buffer);
3208 current_view->insertInset(new_inset);
3209 new_inset->Edit(current_view, 0, 0, 0);
3210 current_view->update(0);
3211 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3212 current_view->text->UnFreezeUndo();
3213 current_view->setState();
3217 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3219 fl_hide_form(fd_form_figure->form_figure);
3223 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3225 FigureApplyCB(ob, data);
3226 FigureCancelCB(ob, data);
3230 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3232 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
3233 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
3234 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3235 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
3236 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3237 fontloader.update();
3239 // All buffers will need resize
3240 bufferlist.resize();
3242 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3246 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3248 fl_hide_form(fd_form_screen->form_screen);
3252 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3254 ScreenCancelCB(ob, data);
3255 ScreenApplyCB(ob, data);
3259 void LaTeXOptions(BufferView * bv)
3261 if (!bv->available())
3264 fl_set_button(fd_latex_options->accents,
3265 int(bv->buffer()->params.allowAccents));
3267 if (fd_latex_options->LaTeXOptions->visible) {
3268 fl_raise_form(fd_latex_options->LaTeXOptions);
3270 fl_show_form(fd_latex_options->LaTeXOptions,
3271 FL_PLACE_MOUSE, FL_FULLBORDER,
3272 _("LaTeX Options"));
3277 // This function runs "configure" and then rereads lyx.defaults to
3278 // reconfigure the automatic settings.
3279 void Reconfigure(BufferView * bv)
3281 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3283 // Run configure in user lyx directory
3284 Path p(user_lyxdir);
3285 Systemcalls one(Systemcalls::System,
3286 AddName(system_lyxdir, "configure"));
3288 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3289 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
3290 WriteAlert(_("The system has been reconfigured."),
3291 _("You need to restart LyX to make use of any"),
3292 _("updated document class specifications."));
3297 // Table of Contents
3307 static TocList * toclist = 0;
3310 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3312 if (!current_view->available())
3315 TocList * tmptoclist = toclist;
3316 int i = fl_get_browser(ob);
3317 for (int a = 1; a < i && tmptoclist->next; ++a) {
3318 tmptoclist = tmptoclist->next;
3325 LyXParagraph * par = current_view->buffer()->paragraph;
3326 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3327 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3328 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3329 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3330 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3331 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3332 par->appendix != tmptoclist->appendix)) {
3333 par = par->LastPhysicalPar()->Next();
3337 current_view->beforeChange();
3338 current_view->text->SetCursor(par, 0);
3339 current_view->text->sel_cursor =
3340 current_view->text->cursor;
3341 current_view->update(0);
3344 WriteAlert(_("Error"),
3345 _("Couldn't find this label"),
3346 _("in current document."));
3352 extern "C" void TocCancelCB(FL_OBJECT *, long)
3354 fl_hide_form(fd_form_toc->form_toc);
3358 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3360 static LyXParagraph * stapar = 0;
3361 TocList * tmptoclist = 0;
3363 /* deleted the toclist */
3366 tmptoclist = toclist->next;
3368 toclist = tmptoclist;
3372 tmptoclist = toclist;
3375 fl_clear_browser(fd_form_toc->browser_toc);
3376 if (!current_view->available()) {
3377 fl_add_browser_line(fd_form_toc->browser_toc,
3378 _("*** No Document ***"));
3381 fl_hide_object(fd_form_toc->browser_toc);
3382 /* get the table of contents */
3383 LyXParagraph * par = current_view->buffer()->paragraph;
3385 char * line = new char[200];
3391 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3395 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3396 par->GetLayout()).labeltype;
3398 if (labeltype >= LABEL_COUNTER_CHAPTER
3399 && labeltype <= LABEL_COUNTER_CHAPTER +
3400 current_view->buffer()->params.tocdepth) {
3401 /* insert this into the table of contents */
3402 /* first indent a little bit */
3406 textclasslist.TextClass(current_view->buffer()->
3407 params.textclass).maxcounter()) * 4 + 2;
3411 // Then the labestring
3412 if (!par->labelstring.empty()) {
3413 string::size_type i = 0;
3414 while (pos < 199 && i < par->labelstring.length()) {
3415 line[pos] = par->labelstring[i];
3424 /* now the contents */
3425 LyXParagraph::size_type i = 0;
3426 while (pos < 199 && i < par->size()) {
3427 c = par->GetChar(i);
3428 if (isprint(c) || c >= 128) {
3435 fl_add_browser_line(fd_form_toc->browser_toc, line);
3437 /* make a toclist entry */
3439 tmptoclist = new TocList;
3440 toclist = tmptoclist;
3442 tmptoclist->next = new TocList;
3443 tmptoclist = tmptoclist->next;
3446 tmptoclist->next = 0;
3448 for (a = 0; a < 6; ++a) {
3449 tmptoclist->counter[a] = par->GetFirstCounter(a);
3451 tmptoclist->appendix = par->appendix;
3453 par = par->LastPhysicalPar()->Next();
3457 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3458 fl_show_object(fd_form_toc->browser_toc);
3462 /* callbacks for form form_ref */
3463 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3465 if (!current_view->available())
3469 fl_get_browser_line(fd_form_ref->browser_ref,
3470 fl_get_browser(fd_form_ref->browser_ref));
3471 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3477 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3487 if(current_view->buffer()->isSGML())
3488 t += "[" + u + "]" + "{" + s + "}";
3493 new InsetRef(t, current_view->buffer());
3494 current_view->insertInset(new_inset);
3498 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3500 if (!current_view->available()) {
3501 fl_clear_browser(fd_form_ref->browser_ref);
3505 FL_OBJECT * brow = fd_form_ref->browser_ref;
3507 // Get the current line, in order to restore it later
3508 char const * const btmp = fl_get_browser_line(brow,
3509 fl_get_browser(brow));
3510 string currentstr = btmp ? btmp : "";
3512 fl_clear_browser(brow);
3514 string refs = current_view->buffer()->getReferenceList('\n');
3517 fl_addto_browser_chars(brow, refs.c_str());
3518 int total_lines = fl_get_browser_maxline(brow);
3519 for (int i = 1; i <= total_lines ; ++i) {
3520 if (fl_get_browser_line(brow, i) == currentstr) {
3525 fl_set_browser_topline(brow, topline);
3527 if (!fl_get_browser_maxline(brow)) {
3528 fl_add_browser_line(brow,
3529 _("*** No labels found in document ***"));
3530 fl_deactivate_object(brow);
3532 fl_select_browser_line(brow, topline);
3533 fl_activate_object(brow);
3535 if (current_view->buffer()->isReadonly()) {
3536 // would be better to de/activate insert buttons
3537 // but that's more work... besides this works. ARRae
3538 fl_hide_form(fd_form_ref->form_ref);
3540 if (!current_view->buffer()->isSGML()) {
3541 fl_deactivate_object(fd_form_ref->ref_name);
3542 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3545 fl_activate_object(fd_form_ref->ref_name);
3546 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3551 extern "C" void RefHideCB(FL_OBJECT *, long)
3553 fl_hide_form(fd_form_ref->form_ref);