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 // How should this actually work? Should it prohibit input in all BufferViews,
179 // or just in the current one? If "just the current one", then it should be
180 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
181 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
182 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
183 // current LyxView that should be prohibited (Lgb) (This applies to
184 // "AllowInput" as well.)
187 input_prohibited = true;
188 current_view->hideCursor();
190 static Cursor cursor;
191 static bool cursor_undefined = true;
193 if (cursor_undefined){
194 cursor = XCreateFontCursor(fl_display, XC_watch);
196 cursor_undefined = false;
199 /* set the cursor to the watch for all forms and the canvas */
200 XDefineCursor(fl_display, current_view->owner()->getForm()->window,
202 if (fd_form_paragraph->form_paragraph->visible)
203 XDefineCursor(fl_display,
204 fd_form_paragraph->form_paragraph->window,
206 if (fd_form_character->form_character->visible)
207 XDefineCursor(fl_display,
208 fd_form_character->form_character->window,
212 fl_deactivate_all_forms();
216 // Should find a way to move this into BufferView.C
217 void SetXtermCursor(Window win)
219 static Cursor cursor;
220 static bool cursor_undefined = true;
221 if (cursor_undefined){
222 cursor = XCreateFontCursor(fl_display, XC_xterm);
224 cursor_undefined = false;
226 XDefineCursor(fl_display, win, cursor);
233 input_prohibited = false;
235 /* reset the cursor from the watch for all forms and the canvas */
237 XUndefineCursor(fl_display, current_view->owner()->getForm()->window);
238 if (fd_form_paragraph->form_paragraph->visible)
239 XUndefineCursor(fl_display,
240 fd_form_paragraph->form_paragraph->window);
241 if (fd_form_character->form_character->visible)
242 XUndefineCursor(fl_display,
243 fd_form_character->form_character->window);
245 // What to do about this? (Lgb)
246 if (current_view->belowMouse())
247 SetXtermCursor(current_view->owner()->getForm()->window);
250 fl_activate_all_forms();
254 void FreeUpdateTimer()
256 /* a real free timer would be better but I don't know
257 * how to do this with xforms */
262 void SetUpdateTimer(float time)
264 fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
277 // should be moved to lyxfunc.C
278 void MenuWrite(Buffer * buffer)
281 if (!buffer->save()) {
282 string fname = buffer->fileName();
283 string s = MakeAbsPath(fname);
284 if (AskQuestion(_("Save failed. Rename and try again?"),
285 MakeDisplayPath(s, 50),
286 _("(If not, document is not saved.)"))) {
290 lastfiles->newFile(buffer->fileName());
295 // should be moved to BufferView.C
296 // Half of this func should be in LyXView, the rest in BufferView.
297 void MenuWriteAs(Buffer * buffer)
299 // Why do we require BufferView::text to be able to write a
300 // document? I see no point in that. (Lgb)
301 //if (!bv->text) return;
303 string fname = buffer->fileName();
304 string oldname = fname;
308 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
309 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
311 if (!IsLyXFilename(fname))
314 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
317 OnlyFilename(fname));
323 // Make sure the absolute filename ends with appropriate suffix
324 string s = MakeAbsPath(fname);
325 if (!IsLyXFilename(s))
328 // Same name as we have already?
330 if (!AskQuestion(_("Same name as document already has:"),
331 MakeDisplayPath(s, 50),
334 // Falls through to name change and save
336 // No, but do we have another file with this name open?
337 else if (bufferlist.exists(s)) {
338 if (AskQuestion(_("Another document with same name open!"),
339 MakeDisplayPath(s, 50),
340 _("Replace with current document?")))
342 bufferlist.close(bufferlist.getBuffer(s));
344 // Ok, change the name of the buffer, but don't save!
348 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document renamed to '"),
350 _("', but not saved..."));
353 } // Check whether the file exists
356 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
357 MakeDisplayPath(s, 50),
362 // Ok, change the name of the buffer
366 // Small bug: If the save fails, we have irreversible changed the name
372 int MenuRunLaTeX(Buffer * buffer)
376 if (buffer->isLinuxDoc())
377 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
378 else if (buffer->isLiterate())
379 ret = buffer->runLiterate();
380 else if (buffer->isDocBook())
381 ret = RunDocBook(1, buffer->fileName());
383 ret = buffer->runLaTeX();
389 s = _("One error detected");
390 t = _("You should try to fix it.");
393 s += _(" errors detected.");
394 t = _("You should try to fix them.");
396 WriteAlert(_("There were errors during the LaTeX run."), s, t);
402 int MenuBuildProg(Buffer * buffer)
406 if (buffer->isLiterate())
407 ret = buffer->buildProgram();
409 string s = _("Wrong type of document");
410 string t = _("The Build operation is not allowed in this document");
411 WriteAlert(_("There were errors during the Build process."), s, t);
419 s = _("One error detected");
420 t = _("You should try to fix it.");
423 s += _(" errors detected.");
424 t = _("You should try to fix them.");
426 WriteAlert(_("There were errors during the Build process."), s, t);
432 int MenuRunChktex(Buffer * buffer)
436 if (buffer->isSGML()) {
437 WriteAlert(_("Chktex does not work with SGML derived documents."));
440 ret = buffer->runChktex();
446 s = _("No warnings found.");
447 } else if (ret == 1) {
448 s = _("One warning found.");
449 t = _("Use 'Edit->Go to Error' to find it.");
452 s += _(" warnings found.");
453 t = _("Use 'Edit->Go to Error' to find them.");
455 WriteAlert(_("Chktex run successfully"), s, t);
457 WriteAlert(_("Error!"), _("It seems chktex does not work."));
463 int MakeLaTeXOutput(Buffer * buffer)
469 string path = OnlyPath(buffer->fileName());
470 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
471 path = buffer->tmppath;
473 if (!buffer->isDviClean()) {
475 ret = MenuRunLaTeX(buffer);
481 /* wait == false means don't wait for termination */
482 /* wait == true means wait for termination */
483 // The bool should be placed last on the argument line. (Lgb)
484 // Returns false if we fail.
485 bool RunScript(Buffer * buffer, bool wait,
486 string const & command,
487 string const & orgname = string(),
488 bool need_shell = true)
492 string name = orgname;
495 if (MakeLaTeXOutput(buffer) > 0)
497 /* get DVI-Filename */
499 name = ChangeExtension(buffer->getLatexName(),
502 path = OnlyPath(name);
503 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
504 path = buffer->tmppath;
507 // At this point we check whether the command contains the
508 // filename parameter $$FName and if that's the case we
509 // substitute the real file name otherwise the filename is
510 // simply appended. rokrau 1/12/00
512 std::string::size_type i;
513 if ( (i=command.find("$$FName")) != std::string::npos)
515 cmd.replace(i,7,QuoteName(name));
518 cmd = command + ' ' + QuoteName(name);
527 // OS/2 cmd.exe has another use for '&'
529 // This is not NLS safe, but it's OK, I think.
530 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
532 // COMSPEC is set, unless user unsets
533 sh = OnlyFilename(GetEnvPath("COMSPEC"));
538 if (contains(sh, "cmd.exe")
539 || contains(sh, "4os2.exe"))
540 cmd = "start /min/n " + cmd;
545 // It seems that, if wait is false, we never get back
546 // the return code of the command. This means that all
547 // the code I added in PrintApplyCB is currently
550 #warning What should we do here?
552 buffer->getUser()->owner()->getMiniBuffer()->Set(
553 _("Executing command:"), cmd);
554 result = one.startscript(Systemcalls::System, cmd);
556 buffer->getUser()->owner()->getMiniBuffer()->Set(
557 _("Executing command:"), cmd);
558 result = one.startscript(wait ? Systemcalls::Wait
559 : Systemcalls::DontWait, cmd);
565 // Returns false if we fail
566 bool CreatePostscript(Buffer * buffer, bool wait = false)
575 if (MakeLaTeXOutput(buffer) > 0) {
579 // Generate postscript file
580 string psname = ChangeExtension (buffer->fileName(),
586 char real_papersize = buffer->params.papersize;
587 if (real_papersize == BufferParams::PAPER_DEFAULT)
588 real_papersize = lyxrc.default_papersize;
590 switch (real_papersize) {
591 case BufferParams::PAPER_USLETTER:
594 case BufferParams::PAPER_A3PAPER:
597 case BufferParams::PAPER_A4PAPER:
600 case BufferParams::PAPER_A5PAPER:
603 case BufferParams::PAPER_B5PAPER:
606 case BufferParams::PAPER_EXECUTIVEPAPER:
609 case BufferParams::PAPER_LEGALPAPER:
612 default: /* If nothing else fits, keep an empty value... */
616 // Make postscript file.
617 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
618 command += QuoteName(psname);
619 if (buffer->params.use_geometry
620 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
621 && !lyxrc.print_paper_dimension_flag.empty()
622 && !buffer->params.paperwidth.empty()
623 && !buffer->params.paperheight.empty()) {
624 // using a custom papersize
626 command += lyxrc.print_paper_dimension_flag + ' ';
627 command += buffer->params.paperwidth + ',';
628 command += buffer->params.paperheight;
629 } else if (!paper.empty()
630 && (real_papersize != BufferParams::PAPER_USLETTER ||
631 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
632 // dvips won't accept -t letter -t landscape. In all other
633 // cases, include the paper size explicitly.
635 command += lyxrc.print_paper_flag + ' ' + paper;
637 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
639 command += lyxrc.print_landscape_flag;
641 // push directorypath, if necessary
642 string path = OnlyPath(buffer->fileName());
643 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
644 path = buffer->tmppath;
647 bool ret = RunScript(buffer, wait, command);
653 // Returns false if we fail
654 //bool MenuPreviewPS(Buffer * buffer)
655 bool PreviewPostscript(Buffer * buffer)
661 // Generate postscript file
662 if (!CreatePostscript(buffer, true)) {
666 // Start postscript viewer
668 string ps = ChangeExtension (buffer->fileName(),
670 // push directorypath, if necessary
671 string path = OnlyPath(buffer->fileName());
672 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
673 path = buffer->tmppath;
676 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
682 void MenuFax(Buffer * buffer)
688 // Generate postscript file
689 if (!CreatePostscript(buffer, true)) {
694 string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true);
695 string path = OnlyPath (buffer->fileName());
696 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
697 path = buffer->tmppath;
700 if (!lyxrc.fax_program.empty()) {
701 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
703 Systemcalls one(Systemcalls::System, help2);
705 send_fax(ps, lyxrc.fax_command);
709 // Returns false if we fail
710 bool PreviewDVI(Buffer * buffer)
716 string paper = lyxrc.view_dvi_paper_option;
717 if (!paper.empty()) {
719 char real_papersize = buffer->params.papersize;
720 if (real_papersize == BufferParams::PAPER_DEFAULT)
721 real_papersize = lyxrc.default_papersize;
723 switch (real_papersize) {
724 case BufferParams::PAPER_USLETTER:
727 case BufferParams::PAPER_A3PAPER:
730 case BufferParams::PAPER_A4PAPER:
733 case BufferParams::PAPER_A5PAPER:
736 case BufferParams::PAPER_B5PAPER:
739 case BufferParams::PAPER_EXECUTIVEPAPER:
740 paper += " foolscap";
742 case BufferParams::PAPER_LEGALPAPER:
745 default: /* If nothing else fits, keep the empty value */
748 if (real_papersize==' ') {
749 // if (paper.empty()) {
750 if (buffer->params.orientation
751 == BufferParams::ORIENTATION_LANDSCAPE)
752 // we HAVE to give a size when the page is in
753 // landscape, so use USletter.
754 paper = " -paper usr";
756 // paper = " -paper " + paper;
757 if (buffer->params.orientation
758 == BufferParams::ORIENTATION_LANDSCAPE)
762 // push directorypath, if necessary
763 string path = OnlyPath(buffer->fileName());
764 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
765 path = buffer->tmppath;
769 string command = lyxrc.view_dvi_command + " " + paper;
770 bool ret = RunScript(buffer, false, command);
775 void MenuMakeLaTeX(Buffer * buffer)
777 // Why care about this?
781 // Get LaTeX-Filename
782 string s = buffer->getLatexName(false);
786 !AskQuestion(_("File already exists:"),
787 MakeDisplayPath(s, 50),
788 _("Do you want to overwrite the file?"))) {
789 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
793 if (buffer->isDocBook())
794 buffer->getUser()->owner()->getMiniBuffer()->Set(
795 _("DocBook does not have a latex backend"));
797 if (buffer->isLinuxDoc())
798 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
800 buffer->makeLaTeXFile(s, string(), true);
801 buffer->getUser()->owner()->getMiniBuffer()->Set(
802 _("Nice LaTeX file saved as"), MakeDisplayPath(s));
803 buffer->markDviDirty();
808 void MenuMakeLinuxDoc(Buffer * buffer)
811 //if (!bv->text) return;
813 if (!buffer->isLinuxDoc()) {
814 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
818 // Get LinuxDoc-Filename
819 string s = ChangeExtension(buffer->fileName(),
824 !AskQuestion(_("File already exists:"),
825 MakeDisplayPath(s, 50),
826 _("Do you want to overwrite the file?"))) {
827 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
831 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building LinuxDoc SGML file `"),
832 MakeDisplayPath(s),"'...");
834 buffer->makeLinuxDocFile(s, 65);
836 buffer->getUser()->owner()->getMiniBuffer()->Set(_("LinuxDoc SGML file save as"),
841 void MenuMakeDocBook(Buffer * buffer)
844 //if (!bv->text) return;
846 if (!buffer->isDocBook()) {
847 WriteAlert(_("Error!"),
848 _("Document class must be docbook."));
852 // Get DocBook-Filename
853 string s = ChangeExtension(buffer->fileName(),
858 !AskQuestion(_("File already exists:"),
859 MakeDisplayPath(s, 50),
860 _("Do you want to overwrite the file?"))) {
861 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
865 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Building DocBook SGML file `"),
866 MakeDisplayPath(s), "'...");
868 buffer->makeDocBookFile(s, 65);
870 buffer->getUser()->owner()->getMiniBuffer()->Set(_("DocBook SGML file save as"),
875 void MenuMakeAscii(Buffer * buffer)
878 //if (!bv->text) return;
880 /* get LaTeX-Filename */
881 string s = ChangeExtension (buffer->fileName(),
886 !AskQuestion(_("File already exists:"),
887 MakeDisplayPath(s, 50),
888 _("Do you want to overwrite the file?"))) {
889 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Canceled"));
893 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
895 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Ascii file saved as"), MakeDisplayPath(s));
899 void MenuPrint(Buffer * buffer)
905 string input_file = ChangeExtension(buffer->fileName(),
906 lyxrc.print_file_extension,
908 fl_set_input(fd_form_print->input_file, input_file.c_str());
910 if (fd_form_print->form_print->visible) {
911 fl_raise_form(fd_form_print->form_print);
914 fl_show_form(fd_form_print->form_print,
915 FL_PLACE_MOUSE, FL_FULLBORDER,
920 void MenuMakeHTML(Buffer * buffer)
922 // First, create LaTeX file
923 MenuMakeLaTeX(buffer);
925 // And now, run the converter
926 string file = buffer->fileName();
927 Path path(OnlyPath(file));
928 // the tex file name has to be correct for
929 // latex, but the html file name can be
931 string result = ChangeExtension(file, ".html", false);
932 string infile = buffer->getLatexName(false);
933 string tmp = lyxrc.html_command;
934 tmp = subst(tmp, "$$FName", infile);
935 tmp = subst(tmp, "$$OutName", result);
937 int res = one.startscript(Systemcalls::System, tmp);
939 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Document exported as HTML to file `")
940 + MakeDisplayPath(result) +'\'');
942 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unable to convert to HTML the file `")
943 + MakeDisplayPath(infile)
949 void MenuExport(Buffer * buffer, string const & extyp)
952 if (extyp == "latex") {
953 // make sure that this buffer is not linuxdoc
954 MenuMakeLaTeX(buffer);
957 else if (extyp == "linuxdoc") {
958 // make sure that this buffer is not latex
959 MenuMakeLinuxDoc(buffer);
962 else if (extyp == "docbook") {
963 // make sure that this buffer is not latex or linuxdoc
964 MenuMakeDocBook(buffer);
967 else if (extyp == "dvi") {
968 // Run LaTeX as "Update dvi..." Bernhard.
969 // We want the dvi in the current directory. This
970 // is achieved by temporarily disabling use of
971 // temp directory. As a side-effect, we get
972 // *.log and *.aux files also. (Asger)
973 bool flag = lyxrc.use_tempdir;
974 lyxrc.use_tempdir = false;
975 MenuRunLaTeX(buffer);
976 lyxrc.use_tempdir = flag;
979 else if (extyp == "postscript") {
980 // Start Print-dialog. Not as good as dvi... Bernhard.
982 // Since the MenuPrint is a pop-up, we can't use
983 // the same trick as above. (Asger)
984 // MISSING: Move of ps-file :-(
985 // And MenuPrint should not be used for this at all...
988 else if (extyp == "ascii") {
989 MenuMakeAscii(buffer);
991 else if (extyp == "custom") {
995 else if (extyp == "html") {
996 MenuMakeHTML(buffer);
999 buffer->getUser()->owner()->getMiniBuffer()->Set(_("Unknown export type: ") + extyp);
1006 lyxerr.debug() << "Running QuitLyX." << endl;
1008 if (!bufferlist.QwriteAll())
1011 lastfiles->writeFile(lyxrc.lastfiles);
1013 // Set a flag that we do quitting from the program,
1014 // so no refreshes are necessary.
1017 // close buffers first
1018 bufferlist.closeAll();
1020 // do any other cleanup procedures now
1021 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1023 DestroyLyXTmpDir(system_tempdir);
1031 // should probably be moved into BufferList (Lgb)
1032 // Perfect target for a thread...
1034 if (!current_view->available())
1037 if (current_view->buffer()->isBakClean()
1038 || current_view->buffer()->isReadonly()) {
1039 // We don't save now, but we'll try again later
1040 current_view->owner()->resetAutosaveTimer();
1044 current_view->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1046 // create autosave filename
1047 string fname = OnlyPath(current_view->buffer()->fileName());
1049 fname += OnlyFilename(current_view->buffer()->fileName());
1052 // tmp_ret will be located (usually) in /tmp
1053 // will that be a problem?
1054 string tmp_ret = tmpnam(0);
1056 pid_t pid = fork(); // If you want to debug the autosave
1057 // you should set pid to -1, and comment out the
1059 if (pid == 0 || pid == -1) {
1060 // pid = -1 signifies that lyx was unable
1061 // to fork. But we will do the save
1063 bool failed = false;
1064 if (!tmp_ret.empty()) {
1065 current_view->buffer()->writeFile(tmp_ret, 1);
1066 // assume successful write of tmp_ret
1067 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1069 // most likely couldn't move between filesystems
1070 // unless write of tmp_ret failed
1071 // so remove tmp file (if it exists)
1072 remove(tmp_ret.c_str());
1079 // failed to write/rename tmp_ret so try writing direct
1080 if (!current_view->buffer()->writeFile(fname, 1)) {
1081 // It is dangerous to do this in the child,
1082 // but safe in the parent, so...
1084 current_view->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1087 if (pid == 0) { // we are the child so...
1092 current_view->buffer()->markBakClean();
1093 current_view->owner()->resetAutosaveTimer();
1098 // Copyright CHT Software Service GmbH
1101 // create new file with template
1104 Buffer * NewLyxFile(string const & filename)
1106 // Split argument by :
1108 string tmpname = split(filename, name, ':');
1109 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1110 if (name.length() == 1
1111 && isalpha(static_cast<unsigned char>(name[0]))
1112 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1114 name += token(tmpname, ':', 0);
1115 tmpname = split(tmpname, ':');
1118 lyxerr.debug() << "Arg is " << filename
1119 << "\nName is " << name
1120 << "\nTemplate is " << tmpname << endl;
1122 // find a free buffer
1123 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1125 lastfiles->newFile(tmpbuf->fileName());
1130 // Insert ascii file (if filename is empty, prompt for one)
1131 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1136 if (!bv->available()) return;
1138 if (fname.empty()) {
1140 fname = fileDlg.Select(_("File to Insert"),
1141 bv->owner()->buffer()->filepath,
1144 if (fname.empty()) return;
1149 if (!fi.readable()) {
1150 WriteFSAlert(_("Error! Specified file is unreadable: "),
1151 MakeDisplayPath(fname, 50));
1155 ifstream ifs(fname.c_str());
1157 WriteFSAlert(_("Error! Cannot open specified file: "),
1158 MakeDisplayPath(fname, 50));
1162 ifs.unsetf(std::ios::skipws);
1163 std::istream_iterator<char> ii(ifs);
1164 std::istream_iterator<char> end;
1165 //string tmpstr(ii, end); // yet a reason for using std::string
1166 // alternate approach to get the file into a string:
1168 copy(ii, end, back_inserter(tmpstr));
1169 // insert the string
1170 current_view->hideCursor();
1172 // clear the selection
1175 bv->text->InsertStringA(tmpstr);
1177 bv->text->InsertStringB(tmpstr);
1182 void MenuShowTableOfContents()
1184 static int ow = -1, oh;
1187 if (fd_form_toc->form_toc->visible) {
1188 fl_raise_form(fd_form_toc->form_toc);
1190 fl_show_form(fd_form_toc->form_toc,
1191 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1192 _("Table Of Contents"));
1194 ow = fd_form_toc->form_toc->w;
1195 oh = fd_form_toc->form_toc->h;
1197 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1202 void MenuInsertLabel(char const * arg)
1206 if (label.empty()) {
1208 result = askForText(_("Enter new label to insert:"));
1210 label = frontStrip(strip(result.second));
1213 if (!label.empty()) {
1214 InsetLabel * new_inset = new InsetLabel;
1215 new_inset->setContents(label);
1216 current_view->insertInset(new_inset);
1222 void MenuInsertRef()
1224 static int ow = -1, oh;
1227 if (fd_form_ref->form_ref->visible) {
1228 fl_raise_form(fd_form_ref->form_ref);
1230 fl_show_form(fd_form_ref->form_ref,
1231 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1232 _("Insert Reference"));
1234 ow = fd_form_ref->form_ref->w;
1235 oh = fd_form_ref->form_ref->h;
1237 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1242 void MenuPasteSelection(char at)
1244 if (!current_view->available())
1249 Atom data_prop = XInternAtom(fl_display,
1252 if (data_prop == None)
1254 XConvertSelection(fl_display,
1255 XA_PRIMARY, XA_STRING, data_prop,
1256 current_view->owner()->getForm()->window, 0);
1261 // candidate for move to BufferView
1262 void Foot(BufferView * bv)
1264 if (!bv->available())
1267 bv->owner()->getMiniBuffer()
1268 ->Set(_("Inserting Footnote..."));
1271 bv->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1276 // candidate for move to LyXView
1277 // This is only used in toolbar.C
1278 void LayoutsCB(int sel, void *)
1280 string tmp = tostr(sel);
1281 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1287 * SGML Linuxdoc support:
1288 * (flag == 0) make TeX output
1289 * (flag == 1) make dvi output
1291 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1298 /* generate a path-less extension name */
1299 string name = ChangeExtension (filename, ".sgml", true);
1300 string path = OnlyPath (filename);
1301 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1302 path = bv->buffer()->tmppath;
1306 if (!bv->available())
1308 bv->buffer()->makeLinuxDocFile(name, 0);
1309 #ifdef WITH_WARNINGS
1310 #warning remove this once we have a proper geometry class
1312 BufferParams::PAPER_SIZE ps = static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1314 case BufferParams::PAPER_A4PAPER:
1315 add_flags = "-p a4";
1317 case BufferParams::PAPER_USLETTER:
1318 add_flags = "-p letter";
1320 default: /* nothing to be done yet ;-) */ break;
1327 case 0: /* TeX output asked */
1328 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1329 s2 = "sgml2latex " + add_flags + " -o tex "
1330 + lyxrc.sgml_extra_options + ' ' + name;
1331 if (one.startscript(Systemcalls::System, s2))
1334 case 1: /* dvi output asked */
1335 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1336 s2 = "sgml2latex " + add_flags + " -o dvi "
1337 + lyxrc.sgml_extra_options + ' ' + name;
1338 if (one.startscript(Systemcalls::System, s2)) {
1341 bv->buffer()->markDviClean();
1343 default: /* unknown output */
1349 bv->buffer()->redraw();
1355 * SGML DocBook support:
1356 * (flag == 1) make dvi output
1358 int RunDocBook(int flag, string const & filename)
1360 /* generate a path-less extension name */
1361 string name = ChangeExtension (filename, ".sgml", true);
1362 string path = OnlyPath (filename);
1363 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1364 path = current_view->buffer()->tmppath;
1368 if (!current_view->available())
1371 current_view->buffer()->makeDocBookFile(name, 0);
1373 // Shall this code go or should it stay? (Lgb)
1374 // string add_flags;
1375 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1377 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1378 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1379 // default: /* nothing to be done yet ;-) */ break;
1386 case 1: /* dvi output asked */
1388 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1389 string s2 = "sgmltools --backend dvi " + name;
1390 if (one.startscript(Systemcalls::System, s2)) {
1393 current_view->buffer()->markDviClean();
1396 default: /* unknown output */
1402 current_view->buffer()->redraw();
1407 void MenuLayoutCharacter()
1409 static int ow = -1, oh;
1411 if (fd_form_character->form_character->visible) {
1412 fl_raise_form(fd_form_character->form_character);
1414 fl_show_form(fd_form_character->form_character,
1415 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1416 _("Character Style"));
1418 ow = fd_form_character->form_character->w;
1419 oh = fd_form_character->form_character->h;
1421 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1427 void DeactivateParagraphButtons ()
1429 fl_deactivate_object (fd_form_paragraph->button_ok);
1430 fl_deactivate_object (fd_form_paragraph->button_apply);
1431 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1432 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1437 void ActivateParagraphButtons ()
1439 fl_activate_object (fd_form_paragraph->button_ok);
1440 fl_activate_object (fd_form_paragraph->button_apply);
1441 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1442 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1447 void DisableParagraphLayout ()
1449 DeactivateParagraphButtons();
1450 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1451 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1452 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1453 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1454 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1455 fl_deactivate_object (fd_form_paragraph->check_noindent);
1456 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1457 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1458 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1459 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1460 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1461 fl_deactivate_object (fd_form_paragraph->input_space_above);
1462 fl_deactivate_object (fd_form_paragraph->input_space_below);
1463 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1464 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1465 fl_deactivate_object (fd_form_paragraph->check_space_above);
1466 fl_deactivate_object (fd_form_paragraph->check_space_below);
1471 void EnableParagraphLayout ()
1473 ActivateParagraphButtons();
1474 fl_activate_object (fd_form_paragraph->input_labelwidth);
1475 fl_activate_object (fd_form_paragraph->check_lines_top);
1476 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1477 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1478 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1479 fl_activate_object (fd_form_paragraph->check_noindent);
1480 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1481 fl_activate_object (fd_form_paragraph->radio_align_right);
1482 fl_activate_object (fd_form_paragraph->radio_align_left);
1483 fl_activate_object (fd_form_paragraph->radio_align_block);
1484 fl_activate_object (fd_form_paragraph->radio_align_center);
1485 fl_activate_object (fd_form_paragraph->input_space_above);
1486 fl_activate_object (fd_form_paragraph->input_space_below);
1487 fl_activate_object (fd_form_paragraph->choice_space_above);
1488 fl_activate_object (fd_form_paragraph->choice_space_below);
1489 fl_activate_object (fd_form_paragraph->check_space_above);
1490 fl_activate_object (fd_form_paragraph->check_space_below);
1494 bool UpdateLayoutParagraph()
1496 if (!current_view->available()) {
1497 if (fd_form_paragraph->form_paragraph->visible)
1498 fl_hide_form(fd_form_paragraph->form_paragraph);
1502 Buffer * buf = current_view->buffer();
1504 fl_set_input(fd_form_paragraph->input_labelwidth,
1505 current_view->text->cursor.par->GetLabelWidthString().c_str());
1506 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1507 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1508 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1509 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1511 int align = current_view->text->cursor.par->GetAlign();
1512 if (align == LYX_ALIGN_LAYOUT)
1513 align = textclasslist.Style(buf->params.textclass,
1514 current_view->text->cursor.par->GetLayout()).align;
1517 case LYX_ALIGN_RIGHT:
1518 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1520 case LYX_ALIGN_LEFT:
1521 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1523 case LYX_ALIGN_CENTER:
1524 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1527 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1531 fl_set_button(fd_form_paragraph->check_lines_top,
1532 current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1533 fl_set_button(fd_form_paragraph->check_lines_bottom,
1534 current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1535 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1536 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1537 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1538 current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1539 fl_set_button(fd_form_paragraph->check_noindent,
1540 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1541 fl_set_input (fd_form_paragraph->input_space_above, "");
1543 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1545 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1547 case VSpace::DEFSKIP:
1548 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1550 case VSpace::SMALLSKIP:
1551 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1553 case VSpace::MEDSKIP:
1554 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1556 case VSpace::BIGSKIP:
1557 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1560 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1562 case VSpace::LENGTH:
1563 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1564 fl_set_input (fd_form_paragraph->input_space_above,
1565 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1568 fl_set_button (fd_form_paragraph->check_space_above,
1569 current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1570 fl_set_input (fd_form_paragraph->input_space_below, "");
1571 switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1573 fl_set_choice (fd_form_paragraph->choice_space_below,
1576 case VSpace::DEFSKIP:
1577 fl_set_choice (fd_form_paragraph->choice_space_below,
1580 case VSpace::SMALLSKIP:
1581 fl_set_choice (fd_form_paragraph->choice_space_below,
1584 case VSpace::MEDSKIP:
1585 fl_set_choice (fd_form_paragraph->choice_space_below,
1588 case VSpace::BIGSKIP:
1589 fl_set_choice (fd_form_paragraph->choice_space_below,
1593 fl_set_choice (fd_form_paragraph->choice_space_below,
1596 case VSpace::LENGTH:
1597 fl_set_choice (fd_form_paragraph->choice_space_below,
1599 fl_set_input (fd_form_paragraph->input_space_below,
1600 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1603 fl_set_button (fd_form_paragraph->check_space_below,
1604 current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1606 fl_set_button(fd_form_paragraph->check_noindent,
1607 current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1609 if (current_view->buffer()->isReadonly()) {
1610 DisableParagraphLayout();
1612 EnableParagraphLayout();
1618 void MenuLayoutParagraph()
1620 if (UpdateLayoutParagraph()) {
1621 if (fd_form_paragraph->form_paragraph->visible) {
1622 fl_raise_form(fd_form_paragraph->form_paragraph);
1624 fl_show_form(fd_form_paragraph->form_paragraph,
1625 FL_PLACE_MOUSE, FL_FULLBORDER,
1626 _("Paragraph Environment"));
1633 void DeactivateDocumentButtons ()
1635 fl_deactivate_object (fd_form_document->button_ok);
1636 fl_deactivate_object (fd_form_document->button_apply);
1637 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1638 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1643 void ActivateDocumentButtons ()
1645 fl_activate_object (fd_form_document->button_ok);
1646 fl_activate_object (fd_form_document->button_apply);
1647 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1648 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1653 void DisableDocumentLayout ()
1655 DeactivateDocumentButtons ();
1656 fl_deactivate_object (fd_form_document->group_radio_separation);
1657 fl_deactivate_object (fd_form_document->radio_indent);
1658 fl_deactivate_object (fd_form_document->radio_skip);
1659 fl_deactivate_object (fd_form_document->choice_class);
1660 fl_deactivate_object (fd_form_document->choice_pagestyle);
1661 fl_deactivate_object (fd_form_document->choice_fonts);
1662 fl_deactivate_object (fd_form_document->choice_fontsize);
1663 fl_deactivate_object (fd_form_document->input_float_placement);
1664 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1665 fl_deactivate_object (fd_form_document->choice_inputenc);
1666 fl_deactivate_object (fd_form_document->group_radio_sides);
1667 fl_deactivate_object (fd_form_document->radio_sides_one);
1668 fl_deactivate_object (fd_form_document->radio_sides_two);
1669 fl_deactivate_object (fd_form_document->group_radio_columns);
1670 fl_deactivate_object (fd_form_document->radio_columns_one);
1671 fl_deactivate_object (fd_form_document->radio_columns_two);
1672 fl_deactivate_object (fd_form_document->input_extra);
1673 fl_deactivate_object (fd_form_document->choice_language);
1674 combo_language->deactivate();
1675 fl_deactivate_object (fd_form_document->input_default_skip);
1676 fl_deactivate_object (fd_form_document->choice_default_skip);
1677 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1678 fl_deactivate_object (fd_form_document->slider_tocdepth);
1679 fl_deactivate_object (fd_form_document->choice_spacing);
1680 fl_deactivate_object (fd_form_document->input_spacing);
1681 fl_deactivate_object (fd_form_document->check_use_amsmath);
1686 void EnableDocumentLayout ()
1688 ActivateDocumentButtons ();
1689 fl_activate_object (fd_form_document->group_radio_separation);
1690 fl_activate_object (fd_form_document->radio_indent);
1691 fl_activate_object (fd_form_document->radio_skip);
1692 fl_activate_object (fd_form_document->choice_class);
1693 fl_activate_object (fd_form_document->choice_pagestyle);
1694 fl_activate_object (fd_form_document->choice_fonts);
1695 fl_activate_object (fd_form_document->choice_fontsize);
1696 fl_activate_object (fd_form_document->input_float_placement);
1697 fl_activate_object (fd_form_document->choice_postscript_driver);
1698 fl_activate_object (fd_form_document->choice_inputenc);
1699 fl_activate_object (fd_form_document->group_radio_sides);
1700 fl_activate_object (fd_form_document->radio_sides_one);
1701 fl_activate_object (fd_form_document->radio_sides_two);
1702 fl_activate_object (fd_form_document->group_radio_columns);
1703 fl_activate_object (fd_form_document->radio_columns_one);
1704 fl_activate_object (fd_form_document->radio_columns_two);
1705 fl_activate_object (fd_form_document->input_extra);
1706 fl_activate_object (fd_form_document->choice_language);
1707 combo_language->activate();
1708 fl_activate_object (fd_form_document->input_default_skip);
1709 fl_activate_object (fd_form_document->choice_default_skip);
1710 fl_activate_object (fd_form_document->slider_secnumdepth);
1711 fl_activate_object (fd_form_document->slider_tocdepth);
1712 fl_activate_object (fd_form_document->choice_spacing);
1713 fl_activate_object (fd_form_document->input_spacing);
1714 fl_activate_object (fd_form_document->check_use_amsmath);
1718 bool UpdateLayoutDocument(BufferParams * params)
1720 if (!current_view->available()) {
1721 if (fd_form_document->form_document->visible)
1722 fl_hide_form(fd_form_document->form_document);
1727 params = ¤t_view->buffer()->params;
1728 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1730 fl_set_choice_text(fd_form_document->choice_class,
1731 textclasslist.DescOfClass(params->textclass).c_str());
1732 combo_language->select_text(params->language.c_str());
1734 fl_set_choice_text(fd_form_document->choice_fonts,
1735 params->fonts.c_str());
1736 fl_set_choice_text(fd_form_document->choice_inputenc,
1737 params->inputenc.c_str());
1738 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1739 params->graphicsDriver.c_str());
1741 // ale970405+lasgoutt970513
1742 fl_clear_choice(fd_form_document->choice_fontsize);
1743 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1744 fl_addto_choice(fd_form_document->choice_fontsize,
1745 tclass.opt_fontsize().c_str());
1746 fl_set_choice(fd_form_document->choice_fontsize,
1747 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1749 // ale970405+lasgoutt970513
1750 fl_clear_choice(fd_form_document->choice_pagestyle);
1751 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1752 fl_addto_choice(fd_form_document->choice_pagestyle,
1753 tclass.opt_pagestyle().c_str());
1755 fl_set_choice(fd_form_document->choice_pagestyle,
1756 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1758 fl_set_button(fd_form_document->radio_indent, 0);
1759 fl_set_button(fd_form_document->radio_skip, 0);
1762 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1764 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1765 fl_set_button(fd_form_document->radio_indent, 1);
1767 fl_set_button(fd_form_document->radio_skip, 1);
1769 switch (params->getDefSkip().kind()) {
1770 case VSpace::SMALLSKIP:
1771 fl_set_choice (fd_form_document->choice_default_skip, 1);
1773 case VSpace::MEDSKIP:
1774 fl_set_choice (fd_form_document->choice_default_skip, 2);
1776 case VSpace::BIGSKIP:
1777 fl_set_choice (fd_form_document->choice_default_skip, 3);
1779 case VSpace::LENGTH:
1780 fl_set_choice (fd_form_document->choice_default_skip, 4);
1781 fl_set_input (fd_form_document->input_default_skip,
1782 params->getDefSkip().asLyXCommand().c_str());
1785 fl_set_choice (fd_form_document->choice_default_skip, 2);
1789 fl_set_button(fd_form_document->radio_sides_one, 0);
1790 fl_set_button(fd_form_document->radio_sides_two, 0);
1792 switch (params->sides) {
1793 case LyXTextClass::OneSide:
1794 fl_set_button(fd_form_document->radio_sides_one, 1);
1796 case LyXTextClass::TwoSides:
1797 fl_set_button(fd_form_document->radio_sides_two, 1);
1801 fl_set_button(fd_form_document->radio_columns_one, 0);
1802 fl_set_button(fd_form_document->radio_columns_two, 0);
1804 if (params->columns == 2)
1805 fl_set_button(fd_form_document->radio_columns_two, 1);
1807 fl_set_button(fd_form_document->radio_columns_one, 1);
1809 fl_set_input(fd_form_document->input_spacing, "");
1810 switch (params->spacing.getSpace()) {
1811 case Spacing::Single:
1814 fl_set_choice(fd_form_document->choice_spacing, 1);
1817 case Spacing::Onehalf:
1820 fl_set_choice(fd_form_document->choice_spacing, 2);
1823 case Spacing::Double:
1826 fl_set_choice(fd_form_document->choice_spacing, 3);
1829 case Spacing::Other:
1831 fl_set_choice(fd_form_document->choice_spacing, 4);
1833 //sprintf(sval, "%g", params->spacing.getValue());
1836 sval << params->spacing.getValue(); // setw?
1837 fl_set_input(fd_form_document->input_spacing,
1838 sval.str().c_str());
1841 ostrstream sval(tval, 20);
1842 sval << params->spacing.getValue() << '\0'; // setw?
1843 fl_set_input(fd_form_document->input_spacing, sval.str());
1850 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1851 params->secnumdepth);
1852 fl_set_counter_value(fd_form_document->slider_tocdepth,
1854 if (!params->float_placement.empty()) { // buffer local (Lgb)
1855 fl_set_input(fd_form_document->input_float_placement,
1856 params->float_placement.c_str());
1858 fl_set_input(fd_form_document->input_float_placement, "");
1860 if (!params->options.empty())
1861 fl_set_input(fd_form_document->input_extra,
1862 params->options.c_str());
1864 fl_set_input(fd_form_document->input_extra, "");
1866 if (current_view->buffer()->isSGML()) {
1867 // bullets not used in SGML derived documents
1868 fl_deactivate_object(fd_form_document->button_bullets);
1869 fl_set_object_lcol(fd_form_document->button_bullets,
1872 fl_activate_object(fd_form_document->button_bullets);
1873 fl_set_object_lcol(fd_form_document->button_bullets,
1877 if (current_view->buffer()->isReadonly()) {
1878 DisableDocumentLayout();
1880 EnableDocumentLayout();
1887 void MenuLayoutDocument()
1889 if (UpdateLayoutDocument()) {
1890 if (fd_form_document->form_document->visible) {
1891 fl_raise_form(fd_form_document->form_document);
1893 fl_show_form(fd_form_document->form_document,
1894 FL_PLACE_MOUSE, FL_FULLBORDER,
1895 _("Document Layout"));
1901 bool UpdateLayoutQuotes()
1904 if (!current_view->available()
1905 || current_view->buffer()->isReadonly())
1909 fl_set_choice(fd_form_quotes->choice_quotes_language,
1910 current_view->buffer()->params.quotes_language + 1);
1911 fl_set_button(fd_form_quotes->radio_single, 0);
1912 fl_set_button(fd_form_quotes->radio_double, 0);
1914 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1915 fl_set_button(fd_form_quotes->radio_single, 1);
1917 fl_set_button(fd_form_quotes->radio_double, 1);
1918 } else if (fd_form_quotes->form_quotes->visible) {
1919 fl_hide_form(fd_form_quotes->form_quotes);
1925 void MenuLayoutQuotes()
1927 if (UpdateLayoutQuotes()) {
1928 if (fd_form_quotes->form_quotes->visible) {
1929 fl_raise_form(fd_form_quotes->form_quotes);
1931 fl_show_form(fd_form_quotes->form_quotes,
1932 FL_PLACE_MOUSE, FL_FULLBORDER,
1939 bool UpdateLayoutPreamble()
1942 if (!current_view->available())
1946 fl_set_input(fd_form_preamble->input_preamble,
1947 current_view->buffer()->params.preamble.c_str());
1949 if (current_view->buffer()->isReadonly()) {
1950 fl_deactivate_object(fd_form_preamble->input_preamble);
1951 fl_deactivate_object(fd_form_preamble->button_ok);
1952 fl_deactivate_object(fd_form_preamble->button_apply);
1953 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1954 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1957 fl_activate_object(fd_form_preamble->input_preamble);
1958 fl_activate_object(fd_form_preamble->button_ok);
1959 fl_activate_object(fd_form_preamble->button_apply);
1960 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1961 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1963 } else if (fd_form_preamble->form_preamble->visible) {
1964 fl_hide_form(fd_form_preamble->form_preamble);
1970 void MenuLayoutPreamble()
1972 static int ow = -1, oh;
1974 if (UpdateLayoutPreamble()) {
1975 if (fd_form_preamble->form_preamble->visible) {
1976 fl_raise_form(fd_form_preamble->form_preamble);
1978 fl_show_form(fd_form_preamble->form_preamble,
1979 FL_PLACE_MOUSE | FL_FREE_SIZE,
1981 _("LaTeX Preamble"));
1983 ow = fd_form_preamble->form_preamble->w;
1984 oh = fd_form_preamble->form_preamble->h;
1986 fl_set_form_minsize(fd_form_preamble->form_preamble,
1993 void MenuLayoutSave()
1995 if (!current_view->available())
1998 if (AskQuestion(_("Do you want to save the current settings"),
1999 _("for Character, Document, Paper and Quotes"),
2000 _("as default for new documents?")))
2001 current_view->buffer()->saveParamsAsDefaults();
2005 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2006 They also show the current font state. */
2009 void ToggleAndShow(BufferView *, LyXFont const &);
2012 void FontSize(string const & size)
2014 LyXFont font(LyXFont::ALL_IGNORE);
2015 font.setGUISize(size);
2016 ToggleAndShow(current_view, font);
2022 LyXFont font(LyXFont::ALL_IGNORE);
2023 font.setEmph(LyXFont::TOGGLE);
2024 ToggleAndShow(current_view, font);
2030 LyXFont font(LyXFont::ALL_IGNORE);
2031 font.setNoun(LyXFont::TOGGLE);
2032 ToggleAndShow(current_view, font);
2038 LyXFont font(LyXFont::ALL_IGNORE);
2039 font.setSeries(LyXFont::BOLD_SERIES);
2040 ToggleAndShow(current_view, font);
2046 LyXFont font(LyXFont::ALL_IGNORE);
2047 font.setUnderbar(LyXFont::TOGGLE);
2048 ToggleAndShow(current_view, font);
2054 LyXFont font(LyXFont::ALL_IGNORE);
2055 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2056 ToggleAndShow(current_view, font);
2062 LyXFont font(LyXFont::ALL_IGNORE);
2063 font.setFamily(LyXFont::SANS_FAMILY);
2064 ToggleAndShow(current_view, font);
2070 LyXFont font(LyXFont::ALL_IGNORE);
2071 font.setFamily(LyXFont::ROMAN_FAMILY);
2072 ToggleAndShow(current_view, font);
2078 LyXFont font(LyXFont::ALL_IGNORE);
2079 font.setLatex (LyXFont::TOGGLE);
2080 ToggleAndShow(current_view, font);
2083 void LangCB(string const & l)
2085 LyXFont font(LyXFont::ALL_IGNORE);
2086 Languages::iterator lit = languages.find(l);
2087 if (lit != languages.end()) {
2088 font.setLanguage(&(*lit).second);
2089 ToggleAndShow(current_view, font);
2091 WriteAlert(_("Error! unknown language"),l);
2097 LyXFont font(LyXFont::ALL_INHERIT);
2098 ToggleAndShow(current_view, font);
2102 /* -------> Returns the current font and depth by printing a message. In the
2103 * future perhaps we could try to implement a callback to the button-bar.
2104 * That is, `light' the bold button when the font is currently bold, etc.
2106 string CurrentState()
2109 if (current_view->available()) {
2110 // I think we should only show changes from the default
2112 Buffer * buffer = current_view->buffer();
2113 LyXFont font = current_view->text->real_current_font;
2114 LyXFont defaultfont = textclasslist.TextClass(buffer->
2115 params.textclass).defaultfont();
2116 font.reduce(defaultfont);
2117 state = _("Font: ") + font.stateText();
2119 int depth = current_view->text->GetDepth();
2121 state += string(_(", Depth: ")) + tostr(depth);
2127 // candidate for move to BufferView
2128 /* -------> Does the actual toggle job of the XxxCB() calls above.
2129 * Also shows the current font state.
2132 void ToggleAndShow(BufferView * bv, LyXFont const & font)
2134 if (bv->available()) {
2137 if (bv->the_locking_inset)
2138 bv->the_locking_inset->SetFont(bv, font, toggleall);
2140 bv->text->ToggleFree(font, toggleall);
2146 // candidate for move to BufferView
2147 void Margin(BufferView * bv)
2149 if (bv->available()) {
2150 bv->owner()->getMiniBuffer()->Set(_("Inserting margin note..."));
2153 bv->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2161 if (fd_form_figure->form_figure->visible) {
2162 fl_raise_form(fd_form_figure->form_figure);
2164 fl_show_form(fd_form_figure->form_figure,
2165 FL_PLACE_MOUSE, FL_FULLBORDER,
2166 _("Insert Figure"));
2173 if (fd_form_table->form_table->visible) {
2174 fl_raise_form(fd_form_table->form_table);
2176 fl_show_form(fd_form_table->form_table,
2177 FL_PLACE_MOUSE, FL_FULLBORDER,
2183 // candidate for move to BufferView
2184 void Melt(BufferView * bv)
2186 if (!bv->available()) return;
2188 bv->owner()->getMiniBuffer()->Set(_("Melt"));
2192 bv->text->MeltFootnoteEnvironment();
2197 // candidate for move to BufferView
2198 // Change environment depth.
2199 // if decInc >= 0, increment depth
2200 // if decInc < 0, decrement depth
2201 void changeDepth(BufferView * bv, int decInc)
2203 if (!bv->available()) return;
2208 bv->text->IncDepth();
2210 bv->text->DecDepth();
2212 bv->owner()->getMiniBuffer()
2213 ->Set(_("Changed environment depth"
2214 " (in possible range, maybe not)"));
2218 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2219 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2220 LyXFont UserFreeFont()
2222 LyXFont font(LyXFont::ALL_IGNORE);
2224 int pos = fl_get_choice(fd_form_character->choice_family);
2226 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2227 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2228 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2229 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2230 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2233 pos = fl_get_choice(fd_form_character->choice_series);
2235 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2236 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2237 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2238 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2241 pos = fl_get_choice(fd_form_character->choice_shape);
2243 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2244 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2245 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2246 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2247 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2248 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2251 pos = fl_get_choice(fd_form_character->choice_size);
2253 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2254 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2255 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2256 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2257 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2258 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2259 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2260 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2261 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2262 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2263 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2264 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2265 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2266 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2269 pos = fl_get_choice(fd_form_character->choice_bar);
2271 case 1: font.setEmph(LyXFont::IGNORE);
2272 font.setUnderbar(LyXFont::IGNORE);
2273 font.setNoun(LyXFont::IGNORE);
2274 font.setLatex(LyXFont::IGNORE);
2276 case 2: font.setEmph(LyXFont::TOGGLE); break;
2277 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2278 case 4: font.setNoun(LyXFont::TOGGLE); break;
2279 case 5: font.setLatex(LyXFont::TOGGLE); break;
2280 case 6: font.setEmph(LyXFont::INHERIT);
2281 font.setUnderbar(LyXFont::INHERIT);
2282 font.setNoun(LyXFont::INHERIT);
2283 font.setLatex(LyXFont::INHERIT);
2287 pos = fl_get_choice(fd_form_character->choice_color);
2289 case 1: font.setColor(LColor::ignore); break;
2290 case 2: font.setColor(LColor::none); break;
2291 case 3: font.setColor(LColor::black); break;
2292 case 4: font.setColor(LColor::white); break;
2293 case 5: font.setColor(LColor::red); break;
2294 case 6: font.setColor(LColor::green); break;
2295 case 7: font.setColor(LColor::blue); break;
2296 case 8: font.setColor(LColor::cyan); break;
2297 case 9: font.setColor(LColor::magenta); break;
2298 case 10: font.setColor(LColor::yellow); break;
2299 case 11: font.setColor(LColor::inherit); break;
2308 ToggleAndShow(current_view, UserFreeFont());
2312 /* callbacks for form form_title */
2313 extern "C" void TimerCB(FL_OBJECT *, long)
2315 // only if the form still exists
2316 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2317 if (fd_form_title->form_title->visible) {
2318 fl_hide_form(fd_form_title->form_title);
2320 fl_free_form(fd_form_title->form_title);
2321 fd_form_title->form_title = 0;
2326 /* callbacks for form form_paragraph */
2328 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2330 // "Synchronize" the choices and input fields, making it
2331 // impossible to commit senseless data.
2333 FD_form_paragraph const * fp = fd_form_paragraph;
2335 if (obj == fp->choice_space_above) {
2336 if (fl_get_choice (fp->choice_space_above) != 7) {
2337 fl_set_input (fp->input_space_above, "");
2338 ActivateParagraphButtons();
2340 } else if (obj == fp->choice_space_below) {
2341 if (fl_get_choice (fp->choice_space_below) != 7) {
2342 fl_set_input (fp->input_space_below, "");
2343 ActivateParagraphButtons();
2345 } else if (obj == fp->input_space_above) {
2346 string input = fl_get_input (fp->input_space_above);
2348 if (input.empty()) {
2349 fl_set_choice (fp->choice_space_above, 1);
2350 ActivateParagraphButtons();
2352 else if (isValidGlueLength (input)) {
2353 fl_set_choice (fp->choice_space_above, 7);
2354 ActivateParagraphButtons();
2357 fl_set_choice (fp->choice_space_above, 7);
2358 DeactivateParagraphButtons();
2360 } else if (obj == fp->input_space_below) {
2361 string input = fl_get_input (fp->input_space_below);
2363 if (input.empty()) {
2364 fl_set_choice (fp->choice_space_below, 1);
2365 ActivateParagraphButtons();
2367 else if (isValidGlueLength (input)) {
2368 fl_set_choice (fp->choice_space_below, 7);
2369 ActivateParagraphButtons();
2372 fl_set_choice (fp->choice_space_below, 7);
2373 DeactivateParagraphButtons();
2379 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2381 if (!current_view->available())
2384 VSpace space_top, space_bottom;
2386 string labelwidthstring;
2389 // If a vspace kind is "Length" but there's no text in
2390 // the input field, reset the kind to "None".
2391 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2392 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2393 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2395 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2396 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2397 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2400 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2401 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2402 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2403 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2404 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2405 case 1: space_top = VSpace(VSpace::NONE); break;
2406 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2407 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2408 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2409 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2410 case 6: space_top = VSpace(VSpace::VFILL); break;
2411 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2413 if (fl_get_button (fd_form_paragraph->check_space_above))
2414 space_top.setKeep (true);
2415 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2416 case 1: space_bottom = VSpace(VSpace::NONE); break;
2417 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2418 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2419 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2420 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2421 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2422 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2424 if (fl_get_button (fd_form_paragraph->check_space_below))
2425 space_bottom.setKeep (true);
2427 if (fl_get_button(fd_form_paragraph->radio_align_left))
2428 align = LYX_ALIGN_LEFT;
2429 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2430 align = LYX_ALIGN_RIGHT;
2431 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2432 align = LYX_ALIGN_CENTER;
2434 align = LYX_ALIGN_BLOCK;
2436 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2437 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2439 current_view->text->SetParagraph(line_top,
2448 current_view->update(1);
2449 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2453 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2455 fl_hide_form(fd_form_paragraph->form_paragraph);
2459 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2461 ParagraphApplyCB(ob, data);
2462 ParagraphCancelCB(ob, data);
2466 /* callbacks for form form_character */
2468 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2470 // we set toggleall locally here, since it should be true for
2471 // all other uses of ToggleAndShow() (JMarc)
2472 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2473 ToggleAndShow(current_view, UserFreeFont());
2478 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2480 fl_hide_form(fd_form_character->form_character);
2484 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2486 CharacterApplyCB(ob, data);
2487 CharacterCloseCB(ob, data);
2491 /* callbacks for form form_document */
2493 void UpdateDocumentButtons(BufferParams const & params)
2495 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2497 switch (params.sides) {
2498 case LyXTextClass::OneSide:
2499 fl_set_button(fd_form_document->radio_sides_one, 1);
2501 case LyXTextClass::TwoSides:
2502 fl_set_button(fd_form_document->radio_sides_two, 1);
2506 if (params.columns == 2)
2507 fl_set_button(fd_form_document->radio_columns_two, 1);
2509 fl_set_button(fd_form_document->radio_columns_one, 1);
2511 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2512 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2513 params.secnumdepth);
2514 fl_set_counter_value(fd_form_document->slider_tocdepth,
2519 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2522 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2523 if (AskQuestion(_("Should I set some parameters to"),
2524 fl_get_choice_text(ob),
2525 _("the defaults of this document class?"))) {
2526 BufferParams params = BufferParams();
2527 params.textclass = fl_get_choice(ob)-1;
2528 params.useClassDefaults();
2529 UpdateLayoutDocument(¶ms);
2530 UpdateDocumentButtons(params);
2533 // unable to load new style
2534 WriteAlert(_("Conversion Errors!"),
2535 _("Unable to switch to new document class."),
2536 _("Reverting to original document class."));
2537 fl_set_choice(fd_form_document->choice_class,
2538 current_view->buffer()->params.textclass + 1);
2544 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2546 // "Synchronize" the choice and the input field, so that it
2547 // is impossible to commit senseless data.
2548 FD_form_document const * fd = fd_form_document;
2550 if (obj == fd->choice_default_skip) {
2551 if (fl_get_choice (fd->choice_default_skip) != 4) {
2552 fl_set_input (fd->input_default_skip, "");
2553 ActivateDocumentButtons();
2555 } else if (obj == fd->input_default_skip) {
2557 char const * input = fl_get_input (fd->input_default_skip);
2560 fl_set_choice (fd->choice_default_skip, 2);
2561 ActivateDocumentButtons();
2562 } else if (isValidGlueLength (input)) {
2563 fl_set_choice (fd->choice_default_skip, 4);
2564 ActivateDocumentButtons();
2566 fl_set_choice (fd->choice_default_skip, 4);
2567 DeactivateDocumentButtons();
2573 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2575 // "Synchronize" the choice and the input field, so that it
2576 // is impossible to commit senseless data.
2577 FD_form_document const * fd = fd_form_document;
2579 if (obj == fd->choice_spacing
2580 && fl_get_choice (fd->choice_spacing) != 4) {
2581 fl_set_input(fd->input_spacing, "");
2582 } else if (obj == fd->input_spacing) {
2584 const char* input = fl_get_input (fd->input_spacing);
2587 fl_set_choice (fd->choice_spacing, 1);
2589 fl_set_choice (fd->choice_spacing, 4);
2595 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2598 BufferParams * params = &(current_view->buffer()->params);
2600 params->language = combo_language->getline();
2601 Languages::iterator lit = languages.find(params->language);
2602 if (lit != languages.end())
2603 params->language_info = &(*lit).second;
2605 params->language_info = default_language;
2607 // If default skip is a "Length" but there's no text in the
2608 // input field, reset the kind to "Medskip", which is the default.
2609 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2610 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2611 fl_set_choice (fd_form_document->choice_default_skip, 2);
2614 /* this shouldn't be done automatically IMO. For example I write german
2615 * documents with an american keyboard very often. Matthias */
2617 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2618 fl_get_choice(fd_form_document->choice_language)); */
2620 fl_get_choice_text(fd_form_document->choice_fonts);
2622 fl_get_choice_text(fd_form_document->choice_inputenc);
2624 fl_get_choice_text(fd_form_document->choice_fontsize);
2626 fl_get_choice_text(fd_form_document->choice_pagestyle);
2627 params->graphicsDriver =
2628 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2629 params->use_amsmath =
2630 fl_get_button(fd_form_document->check_use_amsmath);
2632 if (!current_view->available())
2634 if (lyxrc.rtl_support) {
2635 current_view->text->SetCursor(current_view->text->cursor.par,
2636 current_view->text->cursor.pos);
2637 current_view->setState();
2640 LyXTextClassList::ClassList::size_type new_class =
2641 fl_get_choice(fd_form_document->choice_class) - 1;
2643 if (params->textclass != new_class) {
2644 // try to load new_class
2645 if (textclasslist.Load(new_class)) {
2646 // successfully loaded
2648 current_view->owner()->getMiniBuffer()->Set(_("Converting document to new document class..."));
2649 int ret = current_view->text->
2650 SwitchLayoutsBetweenClasses(current_view->buffer()->
2653 current_view->buffer()->
2659 s = _("One paragraph couldn't be converted");
2662 s += _(" paragraphs couldn't be converted");
2664 WriteAlert(_("Conversion Errors!"), s,
2665 _("into chosen document class"));
2668 params->textclass = new_class;
2670 // problem changing class -- warn user and retain old style
2671 WriteAlert(_("Conversion Errors!"),
2672 _("Unable to switch to new document class."),
2673 _("Reverting to original document class."));
2674 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2678 char tmpsep = params->paragraph_separation;
2679 if (fl_get_button(fd_form_document->radio_indent))
2680 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2682 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2683 if (tmpsep != params->paragraph_separation)
2686 VSpace tmpdefskip = params->getDefSkip();
2687 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2688 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2689 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2690 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2691 case 4: params->setDefSkip(
2692 VSpace (LyXGlueLength (fl_get_input
2693 (fd_form_document->input_default_skip))));
2695 // DocumentDefskipCB assures that this never happens
2696 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2698 if (!(tmpdefskip == params->getDefSkip()))
2701 if (fl_get_button(fd_form_document->radio_columns_two))
2702 params->columns = 2;
2704 params->columns = 1;
2705 if (fl_get_button(fd_form_document->radio_sides_two))
2706 params->sides = LyXTextClass::TwoSides;
2708 params->sides = LyXTextClass::OneSide;
2710 Spacing tmpSpacing = params->spacing;
2711 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2713 lyxerr.debug() << "Spacing: SINGLE" << endl;
2714 params->spacing.set(Spacing::Single);
2717 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2718 params->spacing.set(Spacing::Onehalf);
2721 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2722 params->spacing.set(Spacing::Double);
2725 lyxerr.debug() << "Spacing: OTHER" << endl;
2726 params->spacing.set(Spacing::Other,
2727 fl_get_input(fd_form_document->input_spacing));
2730 if (tmpSpacing != params->spacing)
2733 signed char tmpchar =
2734 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2735 if (params->secnumdepth != tmpchar)
2737 params->secnumdepth = tmpchar;
2740 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2742 params->float_placement =
2743 fl_get_input(fd_form_document->input_float_placement);
2745 // More checking should be done to ensure the string doesn't have
2746 // spaces or illegal placement characters in it. (thornley)
2749 current_view->redoCurrentBuffer();
2751 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2752 current_view->buffer()->markDirty();
2755 fl_get_input(fd_form_document->input_extra);
2760 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2762 fl_hide_form(fd_form_document->form_document);
2766 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2768 DocumentCancelCB(ob, data);
2769 DocumentApplyCB(ob, data);
2773 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2776 // bullet callbacks etc. in bullet_panel.C -- ARRae
2780 /* callbacks for form form_quotes */
2782 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2784 if (!current_view->available())
2787 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2788 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2789 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2791 lga = InsetQuotes::EnglishQ;
2794 lga = InsetQuotes::SwedishQ;
2797 lga = InsetQuotes::GermanQ;
2800 lga = InsetQuotes::PolishQ;
2803 lga = InsetQuotes::FrenchQ;
2806 lga = InsetQuotes::DanishQ;
2809 current_view->buffer()->params.quotes_language = lga;
2810 if (fl_get_button(fd_form_quotes->radio_single))
2811 current_view->buffer()->
2812 params.quotes_times = InsetQuotes::SingleQ;
2814 current_view->buffer()->
2815 params.quotes_times = InsetQuotes::DoubleQ;
2819 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2821 fl_hide_form(fd_form_quotes->form_quotes);
2825 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2827 QuotesApplyCB(ob, data);
2828 QuotesCancelCB(ob, data);
2833 /* callbacks for form form_preamble */
2835 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2837 fl_hide_form(fd_form_preamble->form_preamble);
2841 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2843 if (!current_view->available())
2846 current_view->buffer()->params.preamble =
2847 fl_get_input(fd_form_preamble->input_preamble);
2848 current_view->buffer()->markDirty();
2849 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2853 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2855 PreambleApplyCB(ob, data);
2856 PreambleCancelCB(ob, data);
2860 /* callbacks for form form_table */
2862 extern "C" void TableApplyCB(FL_OBJECT *, long)
2864 if (!current_view->available())
2867 // check for tables in tables
2868 if (current_view->text->cursor.par->table){
2869 WriteAlert(_("Impossible Operation!"),
2870 _("Cannot insert table in table."),
2875 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2877 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2878 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2881 current_view->hideCursor();
2882 current_view->beforeChange();
2883 current_view->update(-2);
2885 current_view->text->SetCursorParUndo();
2886 current_view->text->FreezeUndo();
2888 current_view->text->BreakParagraph();
2889 current_view->update(-1);
2891 if (current_view->text->cursor.par->Last()) {
2892 current_view->text->CursorLeft();
2894 current_view->text->BreakParagraph();
2895 current_view->update(-1);
2898 current_view->text->current_font.setLatex(LyXFont::OFF);
2899 //if (!fl_get_button(fd_form_table->check_latex)){
2900 // insert the new wysiwy table
2901 current_view->text->SetLayout(0); // standard layout
2902 if (current_view->text->cursor.par->footnoteflag ==
2903 LyXParagraph::NO_FOOTNOTE) {
2905 ->SetParagraph(0, 0,
2907 VSpace (0.3 * current_view->buffer()->
2908 params.spacing.getValue(),
2910 VSpace (0.3 * current_view->buffer()->
2911 params.spacing.getValue(),
2918 ->SetParagraph(0, 0,
2920 VSpace(VSpace::NONE),
2921 VSpace(VSpace::NONE),
2927 current_view->text->cursor.par->table =
2928 new LyXTable(xsize, ysize);
2930 Language const * lang =
2931 current_view->text->cursor.par->getParLanguage();
2932 LyXFont font(LyXFont::ALL_INHERIT,lang);
2933 for (int i = 0; i < xsize * ysize - 1; ++i) {
2934 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2935 current_view->text->cursor.par->SetFont(0, font);
2937 current_view->text->RedoParagraph();
2939 current_view->text->UnFreezeUndo();
2941 current_view->update(1);
2942 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2943 current_view->setState();
2947 extern "C" void TableCancelCB(FL_OBJECT *, long)
2949 fl_hide_form(fd_form_table->form_table);
2953 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2955 TableApplyCB(ob, data);
2956 TableCancelCB(ob, data);
2960 /* callbacks for form form_print */
2962 extern "C" void PrintCancelCB(FL_OBJECT *, long)
2964 fl_hide_form(fd_form_print->form_print);
2969 bool stringOnlyContains (string const & LStr, char const * cset)
2971 char const * cstr = LStr.c_str() ;
2973 return strspn(cstr, cset) == strlen(cstr) ;
2977 extern "C" void PrintApplyCB(FL_OBJECT *, long)
2979 if (!current_view->available())
2981 Buffer * buffer = current_view->buffer();
2982 string path = OnlyPath(buffer->fileName());
2985 if (fl_get_button(fd_form_print->radio_even_pages))
2986 pageflag = lyxrc.print_evenpage_flag + ' ';
2987 else if (fl_get_button(fd_form_print->radio_odd_pages))
2988 pageflag = lyxrc.print_oddpage_flag + ' ';
2990 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
2991 // User may give a page (range) list
2992 // User may print multiple (unsorted) copies
2993 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
2994 pages = subst(pages, '+',',');
2995 pages = frontStrip(strip(pages)) ;
2996 while (!pages.empty()) { // a page range was given
2998 pages = split (pages, piece, ',') ;
2999 piece = strip(piece) ;
3000 piece = frontStrip(piece) ;
3001 if ( !stringOnlyContains (piece, "0123456789-") ) {
3002 WriteAlert(_("ERROR! Unable to print!"),
3003 _("Check 'range of pages'!"));
3006 if (piece.find('-') == string::npos) { // not found
3007 pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
3008 } else if (suffixIs(piece, "-") ) { // missing last page
3009 pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
3010 } else if (prefixIs(piece, "-") ) { // missing first page
3011 pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
3013 pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
3017 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3018 if (!copies.empty()) { // a number of copies was given
3019 if ( !stringOnlyContains (copies, "0123456789") ) {
3020 WriteAlert(_("ERROR! Unable to print!"),
3021 _("Check 'number of copies'!"));
3024 if (fl_get_button(fd_form_print->do_unsorted))
3025 pageflag += lyxrc.print_copies_flag;
3027 pageflag += lyxrc.print_collcopies_flag;
3028 pageflag += " " + copies + ' ' ;
3032 if (fl_get_button(fd_form_print->radio_order_reverse))
3033 reverseflag = lyxrc.print_reverse_flag + ' ';
3035 string orientationflag;
3036 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
3037 orientationflag = lyxrc.print_landscape_flag + ' ';
3039 string ps_file = fl_get_input(fd_form_print->input_file);
3040 string printer = strip(fl_get_input(fd_form_print->input_printer));
3043 if (lyxrc.print_adapt_output // printer name should be passed to dvips
3044 && ! printer.empty()) // a printer name has been given
3045 printerflag = lyxrc.print_to_printer + printer + ' ';
3048 if (!lyxrc.print_extra_options.empty())
3049 extraflags = lyxrc.print_extra_options + ' ';
3051 string command = lyxrc.print_command + ' '
3052 + printerflag + pageflag + reverseflag
3053 + orientationflag + extraflags;
3055 char real_papersize = buffer->params.papersize;
3056 if (real_papersize == BufferParams::PAPER_DEFAULT)
3057 real_papersize = lyxrc.default_papersize;
3060 switch (real_papersize) {
3061 case BufferParams::PAPER_USLETTER:
3064 case BufferParams::PAPER_A3PAPER:
3067 case BufferParams::PAPER_A4PAPER:
3070 case BufferParams::PAPER_A5PAPER:
3073 case BufferParams::PAPER_B5PAPER:
3076 case BufferParams::PAPER_EXECUTIVEPAPER:
3079 case BufferParams::PAPER_LEGALPAPER:
3082 default: /* If nothing else fits, keep an empty value... */
3086 if (buffer->params.use_geometry
3087 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
3088 && !lyxrc.print_paper_dimension_flag.empty()
3089 && !buffer->params.paperwidth.empty()
3090 && !buffer->params.paperheight.empty()) {
3091 // using a custom papersize
3093 command += lyxrc.print_paper_dimension_flag + ' ';
3094 command += buffer->params.paperwidth + ',';
3095 command += buffer->params.paperheight + ' ';
3096 } else if (!lyxrc.print_paper_flag.empty()
3098 && (real_papersize != BufferParams::PAPER_USLETTER ||
3099 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
3100 command += " " + lyxrc.print_paper_flag + " " + paper + " ";
3102 if (fl_get_button(fd_form_print->radio_file))
3103 command += lyxrc.print_to_file
3104 + QuoteName(MakeAbsPath(ps_file, path));
3105 else if (!lyxrc.print_spool_command.empty())
3106 command += lyxrc.print_to_file
3107 + QuoteName(ps_file);
3109 // push directorypath, if necessary
3110 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
3111 path = buffer->tmppath;
3116 if (!lyxrc.print_spool_command.empty() &&
3117 !fl_get_button(fd_form_print->radio_file)) {
3118 string command2 = lyxrc.print_spool_command + ' ';
3119 if (!printer.empty())
3120 command2 += lyxrc.print_spool_printerprefix
3122 // First run dvips and, if succesful, then spool command
3123 if ((result = RunScript(buffer, true, command))) {
3124 result = RunScript(buffer, false, command2, ps_file);
3127 result = RunScript(buffer, false, command);
3130 WriteAlert(_("Error:"),
3131 _("Unable to print"),
3132 _("Check that your parameters are correct"));
3136 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
3138 PrintCancelCB(ob, data);
3139 PrintApplyCB(ob, data);
3143 /* callbacks for form form_figure */
3144 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3146 if (!current_view->available())
3149 Buffer * buffer = current_view->buffer();
3150 if(buffer->isReadonly()) // paranoia
3153 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
3154 if (fl_get_button(fd_form_figure->radio_inline)
3155 || current_view->text->cursor.par->table) {
3156 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3157 current_view->insertInset(new_inset);
3158 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3159 new_inset->Edit(current_view, 0, 0, 0);
3163 current_view->hideCursor();
3164 current_view->update(-2);
3165 current_view->beforeChange();
3167 current_view->text->SetCursorParUndo();
3168 current_view->text->FreezeUndo();
3170 current_view->text->BreakParagraph();
3171 current_view->update(-1);
3173 if (current_view->text->cursor.par->Last()) {
3174 current_view->text->CursorLeft();
3176 current_view->text->BreakParagraph();
3177 current_view->update(-1);
3180 // The standard layout should always be numer 0;
3181 current_view->text->SetLayout(0);
3183 if (current_view->text->cursor.par->footnoteflag ==
3184 LyXParagraph::NO_FOOTNOTE) {
3185 current_view->text->
3188 VSpace (0.3 * buffer->params.spacing.getValue(),
3191 buffer->params.spacing.getValue(),
3193 LYX_ALIGN_CENTER, string(), 0);
3195 current_view->text->SetParagraph(0, 0,
3197 VSpace(VSpace::NONE),
3198 VSpace(VSpace::NONE),
3204 current_view->update(-1);
3206 Inset * new_inset = new InsetFig(100, 100, buffer);
3207 current_view->insertInset(new_inset);
3208 new_inset->Edit(current_view, 0, 0, 0);
3209 current_view->update(0);
3210 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3211 current_view->text->UnFreezeUndo();
3212 current_view->setState();
3216 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3218 fl_hide_form(fd_form_figure->form_figure);
3222 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3224 FigureApplyCB(ob, data);
3225 FigureCancelCB(ob, data);
3229 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3231 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
3232 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
3233 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3234 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
3235 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3236 fontloader.update();
3238 // All buffers will need resize
3239 bufferlist.resize();
3241 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3245 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3247 fl_hide_form(fd_form_screen->form_screen);
3251 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3253 ScreenCancelCB(ob, data);
3254 ScreenApplyCB(ob, data);
3258 void LaTeXOptions(BufferView * bv)
3260 if (!bv->available())
3263 fl_set_button(fd_latex_options->accents,
3264 int(bv->buffer()->params.allowAccents));
3266 if (fd_latex_options->LaTeXOptions->visible) {
3267 fl_raise_form(fd_latex_options->LaTeXOptions);
3269 fl_show_form(fd_latex_options->LaTeXOptions,
3270 FL_PLACE_MOUSE, FL_FULLBORDER,
3271 _("LaTeX Options"));
3276 // This function runs "configure" and then rereads lyx.defaults to
3277 // reconfigure the automatic settings.
3278 void Reconfigure(BufferView * bv)
3280 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3282 // Run configure in user lyx directory
3283 Path p(user_lyxdir);
3284 Systemcalls one(Systemcalls::System,
3285 AddName(system_lyxdir, "configure"));
3287 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3288 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
3289 WriteAlert(_("The system has been reconfigured."),
3290 _("You need to restart LyX to make use of any"),
3291 _("updated document class specifications."));
3296 // Table of Contents
3306 static TocList * toclist = 0;
3309 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3311 if (!current_view->available())
3314 TocList * tmptoclist = toclist;
3315 int i = fl_get_browser(ob);
3316 for (int a = 1; a < i && tmptoclist->next; ++a) {
3317 tmptoclist = tmptoclist->next;
3324 LyXParagraph * par = current_view->buffer()->paragraph;
3325 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3326 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3327 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3328 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3329 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3330 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3331 par->appendix != tmptoclist->appendix)) {
3332 par = par->LastPhysicalPar()->Next();
3336 current_view->beforeChange();
3337 current_view->text->SetCursor(par, 0);
3338 current_view->text->sel_cursor =
3339 current_view->text->cursor;
3340 current_view->update(0);
3343 WriteAlert(_("Error"),
3344 _("Couldn't find this label"),
3345 _("in current document."));
3351 extern "C" void TocCancelCB(FL_OBJECT *, long)
3353 fl_hide_form(fd_form_toc->form_toc);
3357 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3359 static LyXParagraph * stapar = 0;
3360 TocList * tmptoclist = 0;
3362 /* deleted the toclist */
3365 tmptoclist = toclist->next;
3367 toclist = tmptoclist;
3371 tmptoclist = toclist;
3374 fl_clear_browser(fd_form_toc->browser_toc);
3375 if (!current_view->available()) {
3376 fl_add_browser_line(fd_form_toc->browser_toc,
3377 _("*** No Document ***"));
3380 fl_hide_object(fd_form_toc->browser_toc);
3381 /* get the table of contents */
3382 LyXParagraph * par = current_view->buffer()->paragraph;
3384 char * line = new char[200];
3390 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3394 labeltype = textclasslist.Style(current_view->buffer()->params.textclass,
3395 par->GetLayout()).labeltype;
3397 if (labeltype >= LABEL_COUNTER_CHAPTER
3398 && labeltype <= LABEL_COUNTER_CHAPTER +
3399 current_view->buffer()->params.tocdepth) {
3400 /* insert this into the table of contents */
3401 /* first indent a little bit */
3405 textclasslist.TextClass(current_view->buffer()->
3406 params.textclass).maxcounter()) * 4 + 2;
3410 // Then the labestring
3411 if (!par->labelstring.empty()) {
3412 string::size_type i = 0;
3413 while (pos < 199 && i < par->labelstring.length()) {
3414 line[pos] = par->labelstring[i];
3423 /* now the contents */
3424 LyXParagraph::size_type i = 0;
3425 while (pos < 199 && i < par->size()) {
3426 c = par->GetChar(i);
3427 if (isprint(c) || c >= 128) {
3434 fl_add_browser_line(fd_form_toc->browser_toc, line);
3436 /* make a toclist entry */
3438 tmptoclist = new TocList;
3439 toclist = tmptoclist;
3441 tmptoclist->next = new TocList;
3442 tmptoclist = tmptoclist->next;
3445 tmptoclist->next = 0;
3447 for (a = 0; a < 6; ++a) {
3448 tmptoclist->counter[a] = par->GetFirstCounter(a);
3450 tmptoclist->appendix = par->appendix;
3452 par = par->LastPhysicalPar()->Next();
3456 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3457 fl_show_object(fd_form_toc->browser_toc);
3461 /* callbacks for form form_ref */
3462 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3464 if (!current_view->available())
3468 fl_get_browser_line(fd_form_ref->browser_ref,
3469 fl_get_browser(fd_form_ref->browser_ref));
3470 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3476 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3486 if(current_view->buffer()->isSGML())
3487 t += "[" + u + "]" + "{" + s + "}";
3492 new InsetRef(t, current_view->buffer());
3493 current_view->insertInset(new_inset);
3497 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3499 if (!current_view->available()) {
3500 fl_clear_browser(fd_form_ref->browser_ref);
3504 FL_OBJECT * brow = fd_form_ref->browser_ref;
3506 // Get the current line, in order to restore it later
3507 char const * const btmp = fl_get_browser_line(brow,
3508 fl_get_browser(brow));
3509 string currentstr = btmp ? btmp : "";
3511 fl_clear_browser(brow);
3513 string refs = current_view->buffer()->getReferenceList('\n');
3516 fl_addto_browser_chars(brow, refs.c_str());
3517 int total_lines = fl_get_browser_maxline(brow);
3518 for (int i = 1; i <= total_lines ; ++i) {
3519 if (fl_get_browser_line(brow, i) == currentstr) {
3524 fl_set_browser_topline(brow, topline);
3526 if (!fl_get_browser_maxline(brow)) {
3527 fl_add_browser_line(brow,
3528 _("*** No labels found in document ***"));
3529 fl_deactivate_object(brow);
3531 fl_select_browser_line(brow, topline);
3532 fl_activate_object(brow);
3534 if (current_view->buffer()->isReadonly()) {
3535 // would be better to de/activate insert buttons
3536 // but that's more work... besides this works. ARRae
3537 fl_hide_form(fd_form_ref->form_ref);
3539 if (!current_view->buffer()->isSGML()) {
3540 fl_deactivate_object(fd_form_ref->ref_name);
3541 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3544 fl_activate_object(fd_form_ref->ref_name);
3545 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3550 extern "C" void RefHideCB(FL_OBJECT *, long)
3552 fl_hide_form(fd_form_ref->form_ref);