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 * ====================================================== */
18 #include FORMS_H_LOCATION
20 #include "layout_forms.h"
21 #include "bullet_forms.h"
25 #include "insets/insetref.h"
26 #include "insets/insetlabel.h"
27 #include "insets/figinset.h"
29 #include "minibuffer.h"
31 #include "bufferlist.h"
33 #include "lyx_gui_misc.h"
35 #include "BufferView.h"
36 #include "lastfiles.h"
37 #include "bufferview_funcs.h"
38 #include "support/FileInfo.h"
39 #include "support/syscall.h"
40 #include "support/filetools.h"
41 #include "support/path.h"
42 #include "lyxserver.h"
43 #include "FontLoader.h"
46 #include "CutAndPaste.h"
47 #include "TextCache.h"
51 using std::back_inserter;
55 using std::istream_iterator;
61 extern Combox * combo_language;
62 extern Combox * combo_language2;
63 extern BufferList bufferlist;
64 extern void show_symbols_form();
65 extern FD_form_title * fd_form_title;
66 extern FD_form_paragraph * fd_form_paragraph;
67 extern FD_form_character * fd_form_character;
68 extern FD_form_document * fd_form_document;
69 extern FD_form_quotes * fd_form_quotes;
70 extern FD_form_preamble * fd_form_preamble;
71 extern FD_form_table * fd_form_table;
72 extern FD_form_figure * fd_form_figure;
73 extern FD_form_screen * fd_form_screen;
74 extern FD_form_toc * fd_form_toc;
75 extern FD_form_ref * fd_form_ref;
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;
87 // this should be static, but I need it in buffer.C
88 bool quitting; // flag, that we are quitting the program
89 extern bool finished; // all cleanup done just let it run through now.
91 char ascii_type; /* for selection notify callbacks */
93 bool scrolling = false;
95 // This is used to make the dreaded font toggle problem hopefully go
96 // away. Definitely not the best solution, but I think it sorta works.
97 bool toggleall = true;
100 This is the inset locking stuff needed for mathed --------------------
102 an inset can simple call LockInset in it's edit call and *ONLY* in it's
104 Inset::Edit() can only be called by the main lyx module.
106 Then the inset may modify the menu's and/or iconbars.
108 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
110 During the lock, all button and keyboard events will be modified
111 and send to the inset through the following inset-features. Note that
112 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
113 to contain the code for restoring the menus and things like this.
116 virtual void InsetButtonPress(int x, int y, int button);
117 virtual void InsetButtonRelease(int x, int y, int button);
118 virtual void InsetKeyPress(XKeyEvent *ev);
119 virtual void InsetMotionNotify(int x, int y, int state);
120 virtual void InsetUnlock();
122 If a inset wishes any redraw and/or update it just has to call
124 It's is completly irrelevant, where the inset is. UpdateInset will
125 find it in any paragraph in any buffer.
126 Of course the_locking_inset and the insets in the current paragraph/buffer
127 are checked first, so no performance problem should occur.
129 Hope that's ok for the beginning, Alejandro,
130 sorry that I needed so much time,
135 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
137 /* these functions return 1 if an error occured,
139 // Now they work only for updatable insets. [Alejandro 080596]
140 //int LockInset(UpdatableInset * inset);
141 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
142 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
143 //int UnlockInset(UpdatableInset * inset);
144 //void LockedInsetStoreUndo(Undo::undo_kind kind);
146 /* this is for asyncron updating. UpdateInsetUpdateList will be called
147 automatically from LyX. Just insert the Inset into the Updatelist */
148 //void UpdateInsetUpdateList();
149 //void PutInsetIntoInsetUpdateList(Inset * inset);
151 //InsetUpdateStruct * InsetUpdateList = 0;
155 -----------------------------------------------------------------------
158 /* some function prototypes */
160 int RunLinuxDoc(BufferView *, int, string const &);
161 int RunDocBook(int, string const &);
162 void MenuWrite(Buffer * buf);
163 void MenuWriteAs(Buffer * buffer);
164 void MenuReload(Buffer * buf);
165 void MenuLayoutSave();
168 void ShowMessage(Buffer * buf,
170 string const & msg2 = string(),
171 string const & msg3 = string(), int delay = 6)
174 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
177 // can somebody think of something more clever? cerr?
178 cout << msg1 << msg2 << msg3 << endl;
191 // should be moved to lyxfunc.C
192 void MenuWrite(Buffer * buffer)
195 if (!buffer->save()) {
196 string fname = buffer->fileName();
197 string s = MakeAbsPath(fname);
198 if (AskQuestion(_("Save failed. Rename and try again?"),
199 MakeDisplayPath(s, 50),
200 _("(If not, document is not saved.)"))) {
204 lastfiles->newFile(buffer->fileName());
209 // should be moved to BufferView.C
210 // Half of this func should be in LyXView, the rest in BufferView.
211 void MenuWriteAs(Buffer * buffer)
213 // Why do we require BufferView::text to be able to write a
214 // document? I see no point in that. (Lgb)
215 //if (!bv->text) return;
217 string fname = buffer->fileName();
218 string oldname = fname;
221 ProhibitInput(current_view);
222 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
223 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
225 if (!IsLyXFilename(fname))
228 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
231 OnlyFilename(fname));
232 AllowInput(current_view);
237 // Make sure the absolute filename ends with appropriate suffix
238 string s = MakeAbsPath(fname);
239 if (!IsLyXFilename(s))
242 // Same name as we have already?
244 if (!AskQuestion(_("Same name as document already has:"),
245 MakeDisplayPath(s, 50),
248 // Falls through to name change and save
250 // No, but do we have another file with this name open?
251 else if (bufferlist.exists(s)) {
252 if (AskQuestion(_("Another document with same name open!"),
253 MakeDisplayPath(s, 50),
254 _("Replace with current document?")))
256 bufferlist.close(bufferlist.getBuffer(s));
258 // Ok, change the name of the buffer, but don't save!
262 ShowMessage(buffer, _("Document renamed to '"),
263 MakeDisplayPath(s), _("', but not saved..."));
266 } // Check whether the file exists
269 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
270 MakeDisplayPath(s, 50),
275 // Ok, change the name of the buffer
279 // Small bug: If the save fails, we have irreversible changed the name
285 int MenuRunLaTeX(Buffer * buffer)
289 if (buffer->isLinuxDoc())
290 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
291 else if (buffer->isLiterate())
292 ret = buffer->runLiterate();
293 else if (buffer->isDocBook())
294 ret = RunDocBook(1, buffer->fileName());
296 ret = buffer->runLaTeX();
302 s = _("One error detected");
303 t = _("You should try to fix it.");
306 s += _(" errors detected.");
307 t = _("You should try to fix them.");
309 WriteAlert(_("There were errors during the LaTeX run."), s, t);
315 int MenuBuildProg(Buffer * buffer)
319 if (buffer->isLiterate())
320 ret = buffer->buildProgram();
322 string s = _("Wrong type of document");
323 string t = _("The Build operation is not allowed in this document");
324 WriteAlert(_("There were errors during the Build process."), s, t);
332 s = _("One error detected");
333 t = _("You should try to fix it.");
336 s += _(" errors detected.");
337 t = _("You should try to fix them.");
339 WriteAlert(_("There were errors during the Build process."), s, t);
345 int MenuRunChktex(Buffer * buffer)
349 if (buffer->isSGML()) {
350 WriteAlert(_("Chktex does not work with SGML derived documents."));
353 ret = buffer->runChktex();
359 s = _("No warnings found.");
360 } else if (ret == 1) {
361 s = _("One warning found.");
362 t = _("Use 'Edit->Go to Error' to find it.");
365 s += _(" warnings found.");
366 t = _("Use 'Edit->Go to Error' to find them.");
368 WriteAlert(_("Chktex run successfully"), s, t);
370 WriteAlert(_("Error!"), _("It seems chktex does not work."));
376 int MakeLaTeXOutput(Buffer * buffer)
382 string path = OnlyPath(buffer->fileName());
383 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
384 path = buffer->tmppath;
388 ret = MenuRunLaTeX(buffer);
394 /* wait == false means don't wait for termination */
395 /* wait == true means wait for termination */
396 // The bool should be placed last on the argument line. (Lgb)
397 // Returns false if we fail.
398 bool RunScript(Buffer * buffer, bool wait,
399 string const & command,
400 string const & orgname = string(),
401 bool need_shell = true)
405 string name = orgname;
408 if (MakeLaTeXOutput(buffer) > 0)
410 /* get DVI-Filename */
412 name = ChangeExtension(buffer->getLatexName(), ".dvi");
414 path = OnlyPath(name);
415 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
416 path = buffer->tmppath;
419 // At this point we check whether the command contains the
420 // filename parameter $$FName and if that's the case we
421 // substitute the real file name otherwise the filename is
422 // simply appended. rokrau 1/12/00
425 if ( (i=command.find("$$FName")) != string::npos)
427 cmd.replace(i,7,QuoteName(name));
430 cmd = command + ' ' + QuoteName(name);
439 // OS/2 cmd.exe has another use for '&'
441 // This is not NLS safe, but it's OK, I think.
442 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
444 // COMSPEC is set, unless user unsets
445 sh = OnlyFilename(GetEnvPath("COMSPEC"));
450 if (contains(sh, "cmd.exe")
451 || contains(sh, "4os2.exe"))
452 cmd = "start /min/n " + cmd;
457 // It seems that, if wait is false, we never get back
458 // the return code of the command. This means that all
459 // the code I added in PrintApplyCB is currently
461 // CHECK What should we do here?
462 ShowMessage(buffer, _("Executing command:"), cmd);
463 result = one.startscript(Systemcalls::System, cmd);
465 ShowMessage(buffer, _("Executing command:"), cmd);
466 result = one.startscript(wait ? Systemcalls::Wait
467 : Systemcalls::DontWait, cmd);
473 // Returns false if we fail
474 bool CreatePostscript(Buffer * buffer, bool wait = false)
480 ProhibitInput(current_view);
483 if (MakeLaTeXOutput(buffer) > 0) {
484 AllowInput(current_view);
487 // Generate postscript file
488 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
494 char real_papersize = buffer->params.papersize;
495 if (real_papersize == BufferParams::PAPER_DEFAULT)
496 real_papersize = lyxrc.default_papersize;
498 switch (real_papersize) {
499 case BufferParams::PAPER_USLETTER:
502 case BufferParams::PAPER_A3PAPER:
505 case BufferParams::PAPER_A4PAPER:
508 case BufferParams::PAPER_A5PAPER:
511 case BufferParams::PAPER_B5PAPER:
514 case BufferParams::PAPER_EXECUTIVEPAPER:
517 case BufferParams::PAPER_LEGALPAPER:
520 default: /* If nothing else fits, keep an empty value... */
524 // Make postscript file.
525 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
526 command += QuoteName(psname);
527 if (buffer->params.use_geometry
528 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
529 && !lyxrc.print_paper_dimension_flag.empty()
530 && !buffer->params.paperwidth.empty()
531 && !buffer->params.paperheight.empty()) {
532 // using a custom papersize
534 command += lyxrc.print_paper_dimension_flag + ' ';
535 command += buffer->params.paperwidth + ',';
536 command += buffer->params.paperheight;
537 } else if (!paper.empty()
538 && (real_papersize != BufferParams::PAPER_USLETTER ||
539 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
540 // dvips won't accept -t letter -t landscape. In all other
541 // cases, include the paper size explicitly.
543 command += lyxrc.print_paper_flag + ' ' + paper;
545 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
547 command += lyxrc.print_landscape_flag;
549 // push directorypath, if necessary
550 string path = OnlyPath(buffer->fileName());
551 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
552 path = buffer->tmppath;
555 bool ret = RunScript(buffer, wait, command);
556 AllowInput(current_view);
561 // Returns false if we fail
562 //bool MenuPreviewPS(Buffer * buffer)
563 bool PreviewPostscript(Buffer * buffer)
569 // Generate postscript file
570 if (!CreatePostscript(buffer, true)) {
574 // Start postscript viewer
575 ProhibitInput(current_view);
576 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
578 // push directorypath, if necessary
579 string path = OnlyPath(buffer->fileName());
580 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
581 path = buffer->tmppath;
584 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
585 AllowInput(current_view);
590 void MenuFax(Buffer * buffer)
596 // Generate postscript file
597 if (!CreatePostscript(buffer, true)) {
602 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
604 string path = OnlyPath (buffer->fileName());
605 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
606 path = buffer->tmppath;
609 if (!lyxrc.fax_program.empty()) {
610 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
612 Systemcalls one(Systemcalls::System, help2);
614 send_fax(ps, lyxrc.fax_command);
618 // Returns false if we fail
619 bool PreviewDVI(Buffer * buffer)
625 string paper = lyxrc.view_dvi_paper_option;
626 if (!paper.empty()) {
628 char real_papersize = buffer->params.papersize;
629 if (real_papersize == BufferParams::PAPER_DEFAULT)
630 real_papersize = lyxrc.default_papersize;
632 switch (real_papersize) {
633 case BufferParams::PAPER_USLETTER:
636 case BufferParams::PAPER_A3PAPER:
639 case BufferParams::PAPER_A4PAPER:
642 case BufferParams::PAPER_A5PAPER:
645 case BufferParams::PAPER_B5PAPER:
648 case BufferParams::PAPER_EXECUTIVEPAPER:
649 paper += " foolscap";
651 case BufferParams::PAPER_LEGALPAPER:
654 default: /* If nothing else fits, keep the empty value */
657 if (real_papersize==' ') {
658 // if (paper.empty()) {
659 if (buffer->params.orientation
660 == BufferParams::ORIENTATION_LANDSCAPE)
661 // we HAVE to give a size when the page is in
662 // landscape, so use USletter.
663 paper = " -paper usr";
665 // paper = " -paper " + paper;
666 if (buffer->params.orientation
667 == BufferParams::ORIENTATION_LANDSCAPE)
671 // push directorypath, if necessary
672 string path = OnlyPath(buffer->fileName());
673 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
674 path = buffer->tmppath;
678 string command = lyxrc.view_dvi_command + " " + paper;
679 bool ret = RunScript(buffer, false, command);
684 bool AskOverwrite(Buffer * buffer, string const & s)
687 // be friendly if there is a gui
690 !AskQuestion(_("File already exists:"),
691 MakeDisplayPath(s, 50),
692 _("Do you want to overwrite the file?"))) {
693 ShowMessage(buffer, _("Canceled"));
701 void MenuMakeLaTeX(Buffer * buffer)
703 // Why care about this?
707 // Get LaTeX-Filename
708 string s = buffer->getLatexName(false);
710 if (!AskOverwrite(buffer, s))
713 if (buffer->isDocBook())
714 ShowMessage(buffer, _("DocBook does not have a latex backend"));
716 if (buffer->isLinuxDoc())
717 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
719 buffer->makeLaTeXFile(s, string(), true);
720 ShowMessage(buffer, _("Nice LaTeX file saved as"),
726 void MenuMakeLinuxDoc(Buffer * buffer)
729 //if (!bv->text) return;
731 if (!buffer->isLinuxDoc()) {
732 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
736 // Get LinuxDoc-Filename
737 string s = ChangeExtension(buffer->fileName(), ".sgml");
739 if (!AskOverwrite(buffer, s))
742 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
743 MakeDisplayPath(s),"'...");
745 buffer->makeLinuxDocFile(s, true);
747 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
752 void MenuMakeDocBook(Buffer * buffer)
755 //if (!bv->text) return;
757 if (!buffer->isDocBook()) {
758 WriteAlert(_("Error!"),
759 _("Document class must be docbook."));
763 // Get DocBook-Filename
764 string s = ChangeExtension(buffer->fileName(), ".sgml");
766 if (!AskOverwrite(buffer, s))
769 ShowMessage(buffer, _("Building DocBook SGML file `"),
770 MakeDisplayPath(s), "'...");
772 buffer->makeDocBookFile(s, true);
774 ShowMessage(buffer, _("DocBook SGML file save as"),
779 void MenuMakeAscii(Buffer * buffer)
782 //if (!bv->text) return;
784 /* get LaTeX-Filename */
785 string s = ChangeExtension (buffer->fileName(), ".txt");
788 if (!AskOverwrite(buffer, s))
791 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
793 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
797 void MenuMakeHTML(Buffer * buffer)
799 // First, create LaTeX file
800 MenuMakeLaTeX(buffer);
802 // And now, run the converter
803 string file = buffer->fileName();
804 Path path(OnlyPath(file));
805 // the tex file name has to be correct for
806 // latex, but the html file name can be
808 string result = ChangeExtension(file, ".html");
809 string infile = buffer->getLatexName(false);
810 string tmp = lyxrc.html_command;
811 tmp = subst(tmp, "$$FName", infile);
812 tmp = subst(tmp, "$$OutName", result);
814 int res = one.startscript(Systemcalls::System, tmp);
816 ShowMessage(buffer, _("Document exported as HTML to file `")
817 + MakeDisplayPath(result) +'\'');
819 ShowMessage(buffer, _("Unable to convert to HTML the file `")
820 + MakeDisplayPath(infile)
827 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
829 // First, create LinuxDoc file
830 MenuMakeLinuxDoc(buffer);
832 // And now, run the converter
833 string file = buffer->fileName();
835 string result = ChangeExtension(file, ".html");
836 string infile = ChangeExtension(file, ".sgml");
837 string tmp = lyxrc.linuxdoc_to_html_command;
838 tmp = subst(tmp, "$$FName", infile);
839 tmp = subst(tmp, "$$OutName", result);
841 int res = one.startscript(Systemcalls::System, tmp);
843 ShowMessage(buffer,_("Document exported as HTML to file `")
844 + MakeDisplayPath(result) +'\'');
846 ShowMessage(buffer,_("Unable to convert to HTML the file `")
847 + MakeDisplayPath(infile)
853 void MenuMakeHTML_DocBook(Buffer * buffer)
855 // First, create LaTeX file
856 MenuMakeDocBook(buffer);
858 // And now, run the converter
859 string file = buffer->fileName();
860 string result = ChangeExtension(file, ".html");
861 string infile = ChangeExtension(file, ".sgml");
862 string tmp = lyxrc.docbook_to_html_command;
863 tmp = subst(tmp, "$$FName", infile);
864 tmp = subst(tmp, "$$OutName", result);
866 int res = one.startscript(Systemcalls::System, tmp);
868 ShowMessage(buffer,_("Document exported as HTML to file `")
869 + MakeDisplayPath(result) +'\'');
871 ShowMessage(buffer,_("Unable to convert to HTML the file `")
872 + MakeDisplayPath(infile)
879 void MenuExport(Buffer * buffer, string const & extyp)
882 if (extyp == "latex") {
883 // make sure that this buffer is not linuxdoc
884 MenuMakeLaTeX(buffer);
887 else if (extyp == "linuxdoc") {
888 // make sure that this buffer is not latex
889 MenuMakeLinuxDoc(buffer);
892 else if (extyp == "docbook") {
893 // make sure that this buffer is not latex or linuxdoc
894 MenuMakeDocBook(buffer);
897 else if (extyp == "dvi") {
898 // Run LaTeX as "Update dvi..." Bernhard.
899 // We want the dvi in the current directory. This
900 // is achieved by temporarily disabling use of
901 // temp directory. As a side-effect, we get
902 // *.log and *.aux files also. (Asger)
903 bool flag = lyxrc.use_tempdir;
904 lyxrc.use_tempdir = false;
905 MenuRunLaTeX(buffer);
906 lyxrc.use_tempdir = flag;
909 else if (extyp == "postscript") {
910 // Start Print-dialog. Not as good as dvi... Bernhard.
911 //should start lyxview->getDialogs()->showPrint();
912 // to get same as before
913 // MenuPrint(buffer);
914 // Since the MenuPrint is a pop-up, we can't use
915 // the same trick as above. (Asger)
916 // MISSING: Move of ps-file :-(
917 // And MenuPrint should not be used for this at all...
920 else if (extyp == "ascii") {
921 MenuMakeAscii(buffer);
923 else if (extyp == "custom") {
927 else if (extyp == "html") {
928 MenuMakeHTML(buffer);
930 // HTML from linuxdoc
931 else if (extyp == "html-linuxdoc") {
932 MenuMakeHTML_LinuxDoc(buffer);
935 else if (extyp == "html-docbook") {
936 MenuMakeHTML_DocBook(buffer);
939 ShowMessage(buffer, _("Unknown export type: ") + extyp);
946 lyxerr.debug() << "Running QuitLyX." << endl;
948 if (!bufferlist.QwriteAll())
951 lastfiles->writeFile(lyxrc.lastfiles);
953 // Set a flag that we do quitting from the program,
954 // so no refreshes are necessary.
957 // close buffers first
958 bufferlist.closeAll();
960 // do any other cleanup procedures now
961 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
963 DestroyLyXTmpDir(system_tempdir);
970 void AutoSave(BufferView * bv)
971 // should probably be moved into BufferList (Lgb)
972 // Perfect target for a thread...
974 if (!bv->available())
977 if (bv->buffer()->isBakClean()
978 || bv->buffer()->isReadonly()) {
979 // We don't save now, but we'll try again later
980 bv->owner()->resetAutosaveTimer();
984 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
986 // create autosave filename
987 string fname = OnlyPath(bv->buffer()->fileName());
989 fname += OnlyFilename(bv->buffer()->fileName());
992 // tmp_ret will be located (usually) in /tmp
993 // will that be a problem?
994 string tmp_ret = tmpnam(0);
996 pid_t pid = fork(); // If you want to debug the autosave
997 // you should set pid to -1, and comment out the
999 if (pid == 0 || pid == -1) {
1000 // pid = -1 signifies that lyx was unable
1001 // to fork. But we will do the save
1003 bool failed = false;
1004 if (!tmp_ret.empty()) {
1005 bv->buffer()->writeFile(tmp_ret, 1);
1006 // assume successful write of tmp_ret
1007 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1009 // most likely couldn't move between filesystems
1010 // unless write of tmp_ret failed
1011 // so remove tmp file (if it exists)
1012 remove(tmp_ret.c_str());
1019 // failed to write/rename tmp_ret so try writing direct
1020 if (!bv->buffer()->writeFile(fname, 1)) {
1021 // It is dangerous to do this in the child,
1022 // but safe in the parent, so...
1024 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1027 if (pid == 0) { // we are the child so...
1032 bv->buffer()->markBakClean();
1033 bv->owner()->resetAutosaveTimer();
1038 // Copyright CHT Software Service GmbH
1041 // create new file with template
1044 Buffer * NewLyxFile(string const & filename)
1046 // Split argument by :
1048 string tmpname = split(filename, name, ':');
1049 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1050 if (name.length() == 1
1051 && isalpha(static_cast<unsigned char>(name[0]))
1052 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1054 name += token(tmpname, ':', 0);
1055 tmpname = split(tmpname, ':');
1058 lyxerr.debug() << "Arg is " << filename
1059 << "\nName is " << name
1060 << "\nTemplate is " << tmpname << endl;
1062 // find a free buffer
1063 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1065 lastfiles->newFile(tmpbuf->fileName());
1070 // Insert ascii file (if filename is empty, prompt for one)
1071 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1076 if (!bv->available()) return;
1078 if (fname.empty()) {
1080 fname = fileDlg.Select(_("File to Insert"),
1081 bv->owner()->buffer()->filepath,
1084 if (fname.empty()) return;
1089 if (!fi.readable()) {
1090 WriteFSAlert(_("Error! Specified file is unreadable: "),
1091 MakeDisplayPath(fname, 50));
1095 ifstream ifs(fname.c_str());
1097 WriteFSAlert(_("Error! Cannot open specified file: "),
1098 MakeDisplayPath(fname, 50));
1102 ifs.unsetf(ios::skipws);
1103 istream_iterator<char> ii(ifs);
1104 istream_iterator<char> end;
1105 //string tmpstr(ii, end); // yet a reason for using std::string
1106 // alternate approach to get the file into a string:
1108 copy(ii, end, back_inserter(tmpstr));
1109 // insert the string
1110 current_view->hideCursor();
1112 // clear the selection
1115 bv->text->InsertStringA(bv, tmpstr);
1117 bv->text->InsertStringB(bv, tmpstr);
1118 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1122 void MenuShowTableOfContents()
1124 static int ow = -1, oh;
1127 if (fd_form_toc->form_toc->visible) {
1128 fl_raise_form(fd_form_toc->form_toc);
1130 fl_show_form(fd_form_toc->form_toc,
1131 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1132 _("Table Of Contents"));
1134 ow = fd_form_toc->form_toc->w;
1135 oh = fd_form_toc->form_toc->h;
1137 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1142 void MenuInsertLabel(char const * arg)
1145 ProhibitInput(current_view);
1146 if (label.empty()) {
1148 result = askForText(_("Enter new label to insert:"));
1150 label = frontStrip(strip(result.second));
1153 if (!label.empty()) {
1154 InsetLabel * new_inset = new InsetLabel;
1155 new_inset->setContents(label);
1156 current_view->insertInset(new_inset);
1158 AllowInput(current_view);
1162 void MenuInsertRef()
1164 static int ow = -1, oh;
1167 if (fd_form_ref->form_ref->visible) {
1168 fl_raise_form(fd_form_ref->form_ref);
1170 fl_show_form(fd_form_ref->form_ref,
1171 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1172 _("Insert Reference"));
1174 ow = fd_form_ref->form_ref->w;
1175 oh = fd_form_ref->form_ref->h;
1177 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1182 // candidate for move to LyXView
1183 // This is only used in toolbar.C
1184 void LayoutsCB(int sel, void *)
1186 string tmp = tostr(sel);
1187 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1193 * SGML Linuxdoc support:
1194 * (flag == 0) make TeX output
1195 * (flag == 1) make dvi output
1197 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1204 /* generate a path-less extension name */
1205 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1206 string path = OnlyPath (filename);
1207 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1208 path = bv->buffer()->tmppath;
1212 if (!bv->available())
1214 bv->buffer()->makeLinuxDocFile(name, false);
1216 // CHECK remove this once we have a proper geometry class
1218 BufferParams::PAPER_SIZE ps =
1219 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1221 case BufferParams::PAPER_A4PAPER:
1222 add_flags = "-p a4";
1224 case BufferParams::PAPER_USLETTER:
1225 add_flags = "-p letter";
1227 default: /* nothing to be done yet ;-) */ break;
1234 case 0: /* TeX output asked */
1235 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1236 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1237 if (one.startscript(Systemcalls::System, s2))
1240 case 1: /* dvi output asked */
1241 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1242 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1243 if (one.startscript(Systemcalls::System, s2)) {
1247 default: /* unknown output */
1253 bv->buffer()->redraw();
1259 * SGML DocBook support:
1260 * (flag == 1) make dvi output
1262 int RunDocBook(int flag, string const & filename)
1264 /* generate a path-less extension name */
1265 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1266 string path = OnlyPath (filename);
1267 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1268 path = current_view->buffer()->tmppath;
1272 if (!current_view->available())
1275 current_view->buffer()->makeDocBookFile(name, false);
1277 // Shall this code go or should it stay? (Lgb)
1278 // This code is a placeholder for future implementation. (Jose')
1279 // string add_flags;
1280 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1282 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1283 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1284 // default: /* nothing to be done yet ;-) */ break;
1286 ProhibitInput(current_view);
1291 case 1: /* dvi output asked */
1293 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1294 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1295 if (one.startscript(Systemcalls::System, s2)) {
1300 default: /* unknown output */
1304 AllowInput(current_view);
1306 current_view->buffer()->redraw();
1311 void MenuLayoutCharacter()
1313 static int ow = -1, oh;
1315 if (fd_form_character->form_character->visible) {
1316 fl_raise_form(fd_form_character->form_character);
1318 fl_show_form(fd_form_character->form_character,
1319 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1320 _("Character Style"));
1322 ow = fd_form_character->form_character->w;
1323 oh = fd_form_character->form_character->h;
1325 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1331 void DeactivateParagraphButtons ()
1333 fl_deactivate_object (fd_form_paragraph->button_ok);
1334 fl_deactivate_object (fd_form_paragraph->button_apply);
1335 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1336 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1341 void ActivateParagraphButtons ()
1343 fl_activate_object (fd_form_paragraph->button_ok);
1344 fl_activate_object (fd_form_paragraph->button_apply);
1345 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1346 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1351 void DisableParagraphLayout ()
1353 DeactivateParagraphButtons();
1354 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1355 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1356 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1357 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1358 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1359 fl_deactivate_object (fd_form_paragraph->check_noindent);
1360 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1361 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1362 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1363 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1364 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1365 fl_deactivate_object (fd_form_paragraph->input_space_above);
1366 fl_deactivate_object (fd_form_paragraph->input_space_below);
1367 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1368 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1369 fl_deactivate_object (fd_form_paragraph->check_space_above);
1370 fl_deactivate_object (fd_form_paragraph->check_space_below);
1375 void EnableParagraphLayout ()
1377 ActivateParagraphButtons();
1378 fl_activate_object (fd_form_paragraph->input_labelwidth);
1379 fl_activate_object (fd_form_paragraph->check_lines_top);
1380 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1381 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1382 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1383 fl_activate_object (fd_form_paragraph->check_noindent);
1384 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1385 fl_activate_object (fd_form_paragraph->radio_align_right);
1386 fl_activate_object (fd_form_paragraph->radio_align_left);
1387 fl_activate_object (fd_form_paragraph->radio_align_block);
1388 fl_activate_object (fd_form_paragraph->radio_align_center);
1389 fl_activate_object (fd_form_paragraph->input_space_above);
1390 fl_activate_object (fd_form_paragraph->input_space_below);
1391 fl_activate_object (fd_form_paragraph->choice_space_above);
1392 fl_activate_object (fd_form_paragraph->choice_space_below);
1393 fl_activate_object (fd_form_paragraph->check_space_above);
1394 fl_activate_object (fd_form_paragraph->check_space_below);
1398 bool UpdateLayoutParagraph()
1400 if (!current_view->available()) {
1401 if (fd_form_paragraph->form_paragraph->visible)
1402 fl_hide_form(fd_form_paragraph->form_paragraph);
1406 Buffer * buf = current_view->buffer();
1408 if (current_view->the_locking_inset)
1409 text = current_view->the_locking_inset->getLyXText(current_view);
1411 text = current_view->text;
1413 fl_set_input(fd_form_paragraph->input_labelwidth,
1414 text->cursor.par()->GetLabelWidthString().c_str());
1415 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1416 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1417 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1418 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1420 int align = text->cursor.par()->GetAlign();
1421 if (align == LYX_ALIGN_LAYOUT)
1422 align = textclasslist.Style(buf->params.textclass,
1423 text->cursor.par()->GetLayout()).align;
1426 case LYX_ALIGN_RIGHT:
1427 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1429 case LYX_ALIGN_LEFT:
1430 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1432 case LYX_ALIGN_CENTER:
1433 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1436 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1441 fl_set_button(fd_form_paragraph->check_lines_top,
1442 text->cursor.par()->FirstPhysicalPar()->line_top);
1444 fl_set_button(fd_form_paragraph->check_lines_bottom,
1445 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1447 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1448 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1450 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1451 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1452 fl_set_button(fd_form_paragraph->check_noindent,
1453 text->cursor.par()->FirstPhysicalPar()->noindent);
1455 fl_set_button(fd_form_paragraph->check_lines_top,
1456 text->cursor.par()->line_top);
1457 fl_set_button(fd_form_paragraph->check_lines_bottom,
1458 text->cursor.par()->line_bottom);
1459 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1460 text->cursor.par()->pagebreak_top);
1461 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1462 text->cursor.par()->pagebreak_bottom);
1463 fl_set_button(fd_form_paragraph->check_noindent,
1464 text->cursor.par()->noindent);
1466 fl_set_input (fd_form_paragraph->input_space_above, "");
1469 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1471 switch (text->cursor.par()->added_space_top.kind()) {
1475 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1477 case VSpace::DEFSKIP:
1478 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1480 case VSpace::SMALLSKIP:
1481 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1483 case VSpace::MEDSKIP:
1484 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1486 case VSpace::BIGSKIP:
1487 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1490 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1492 case VSpace::LENGTH:
1493 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1495 fl_set_input (fd_form_paragraph->input_space_above,
1496 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1498 fl_set_input (fd_form_paragraph->input_space_above,
1499 text->cursor.par()->added_space_top.length().asString().c_str());
1504 fl_set_button (fd_form_paragraph->check_space_above,
1505 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1506 fl_set_input (fd_form_paragraph->input_space_below, "");
1507 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1509 fl_set_button (fd_form_paragraph->check_space_above,
1510 text->cursor.par()->added_space_top.keep());
1511 fl_set_input (fd_form_paragraph->input_space_below, "");
1512 switch (text->cursor.par()->added_space_bottom.kind()) {
1515 fl_set_choice (fd_form_paragraph->choice_space_below,
1518 case VSpace::DEFSKIP:
1519 fl_set_choice (fd_form_paragraph->choice_space_below,
1522 case VSpace::SMALLSKIP:
1523 fl_set_choice (fd_form_paragraph->choice_space_below,
1526 case VSpace::MEDSKIP:
1527 fl_set_choice (fd_form_paragraph->choice_space_below,
1530 case VSpace::BIGSKIP:
1531 fl_set_choice (fd_form_paragraph->choice_space_below,
1535 fl_set_choice (fd_form_paragraph->choice_space_below,
1538 case VSpace::LENGTH:
1539 fl_set_choice (fd_form_paragraph->choice_space_below,
1542 fl_set_input (fd_form_paragraph->input_space_below,
1543 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1546 fl_set_button (fd_form_paragraph->check_space_below,
1547 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1549 fl_set_button(fd_form_paragraph->check_noindent,
1550 text->cursor.par()->FirstPhysicalPar()->noindent);
1552 fl_set_input (fd_form_paragraph->input_space_below,
1553 text->cursor.par()->added_space_bottom.length().asString().c_str());
1556 fl_set_button (fd_form_paragraph->check_space_below,
1557 text->cursor.par()->added_space_bottom.keep());
1559 fl_set_button(fd_form_paragraph->check_noindent,
1560 text->cursor.par()->noindent);
1562 if (current_view->buffer()->isReadonly()) {
1563 DisableParagraphLayout();
1565 EnableParagraphLayout();
1571 void MenuLayoutParagraph()
1573 if (UpdateLayoutParagraph()) {
1574 if (fd_form_paragraph->form_paragraph->visible) {
1575 fl_raise_form(fd_form_paragraph->form_paragraph);
1577 fl_show_form(fd_form_paragraph->form_paragraph,
1578 FL_PLACE_MOUSE, FL_FULLBORDER,
1579 _("Paragraph Environment"));
1586 void DeactivateDocumentButtons ()
1588 fl_deactivate_object (fd_form_document->button_ok);
1589 fl_deactivate_object (fd_form_document->button_apply);
1590 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1591 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1596 void ActivateDocumentButtons ()
1598 fl_activate_object (fd_form_document->button_ok);
1599 fl_activate_object (fd_form_document->button_apply);
1600 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1601 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1606 void DisableDocumentLayout ()
1608 DeactivateDocumentButtons ();
1609 fl_deactivate_object (fd_form_document->group_radio_separation);
1610 fl_deactivate_object (fd_form_document->radio_indent);
1611 fl_deactivate_object (fd_form_document->radio_skip);
1612 fl_deactivate_object (fd_form_document->choice_class);
1613 fl_deactivate_object (fd_form_document->choice_pagestyle);
1614 fl_deactivate_object (fd_form_document->choice_fonts);
1615 fl_deactivate_object (fd_form_document->choice_fontsize);
1616 fl_deactivate_object (fd_form_document->input_float_placement);
1617 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1618 fl_deactivate_object (fd_form_document->choice_inputenc);
1619 fl_deactivate_object (fd_form_document->group_radio_sides);
1620 fl_deactivate_object (fd_form_document->radio_sides_one);
1621 fl_deactivate_object (fd_form_document->radio_sides_two);
1622 fl_deactivate_object (fd_form_document->group_radio_columns);
1623 fl_deactivate_object (fd_form_document->radio_columns_one);
1624 fl_deactivate_object (fd_form_document->radio_columns_two);
1625 fl_deactivate_object (fd_form_document->input_extra);
1626 fl_deactivate_object (fd_form_document->choice_language);
1627 combo_language->deactivate();
1628 fl_deactivate_object (fd_form_document->input_default_skip);
1629 fl_deactivate_object (fd_form_document->choice_default_skip);
1630 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1631 fl_deactivate_object (fd_form_document->slider_tocdepth);
1632 fl_deactivate_object (fd_form_document->choice_spacing);
1633 fl_deactivate_object (fd_form_document->input_spacing);
1634 fl_deactivate_object (fd_form_document->check_use_amsmath);
1639 void EnableDocumentLayout ()
1641 ActivateDocumentButtons ();
1642 fl_activate_object (fd_form_document->group_radio_separation);
1643 fl_activate_object (fd_form_document->radio_indent);
1644 fl_activate_object (fd_form_document->radio_skip);
1645 fl_activate_object (fd_form_document->choice_class);
1646 fl_activate_object (fd_form_document->choice_pagestyle);
1647 fl_activate_object (fd_form_document->choice_fonts);
1648 fl_activate_object (fd_form_document->choice_fontsize);
1649 fl_activate_object (fd_form_document->input_float_placement);
1650 fl_activate_object (fd_form_document->choice_postscript_driver);
1651 fl_activate_object (fd_form_document->choice_inputenc);
1652 fl_activate_object (fd_form_document->group_radio_sides);
1653 fl_activate_object (fd_form_document->radio_sides_one);
1654 fl_activate_object (fd_form_document->radio_sides_two);
1655 fl_activate_object (fd_form_document->group_radio_columns);
1656 fl_activate_object (fd_form_document->radio_columns_one);
1657 fl_activate_object (fd_form_document->radio_columns_two);
1658 fl_activate_object (fd_form_document->input_extra);
1659 fl_activate_object (fd_form_document->choice_language);
1660 combo_language->activate();
1661 fl_activate_object (fd_form_document->input_default_skip);
1662 fl_activate_object (fd_form_document->choice_default_skip);
1663 fl_activate_object (fd_form_document->slider_secnumdepth);
1664 fl_activate_object (fd_form_document->slider_tocdepth);
1665 fl_activate_object (fd_form_document->choice_spacing);
1666 fl_activate_object (fd_form_document->input_spacing);
1667 fl_activate_object (fd_form_document->check_use_amsmath);
1671 bool UpdateLayoutDocument(BufferParams * params)
1673 if (!current_view->available()) {
1674 if (fd_form_document->form_document->visible)
1675 fl_hide_form(fd_form_document->form_document);
1680 params = ¤t_view->buffer()->params;
1681 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1683 fl_set_choice_text(fd_form_document->choice_class,
1684 textclasslist.DescOfClass(params->textclass).c_str());
1685 combo_language->select_text(params->language.c_str());
1687 fl_set_choice_text(fd_form_document->choice_fonts,
1688 params->fonts.c_str());
1689 fl_set_choice_text(fd_form_document->choice_inputenc,
1690 params->inputenc.c_str());
1691 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1692 params->graphicsDriver.c_str());
1694 // ale970405+lasgoutt970513
1695 fl_clear_choice(fd_form_document->choice_fontsize);
1696 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1697 fl_addto_choice(fd_form_document->choice_fontsize,
1698 tclass.opt_fontsize().c_str());
1699 fl_set_choice(fd_form_document->choice_fontsize,
1700 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1702 // ale970405+lasgoutt970513
1703 fl_clear_choice(fd_form_document->choice_pagestyle);
1704 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1705 fl_addto_choice(fd_form_document->choice_pagestyle,
1706 tclass.opt_pagestyle().c_str());
1708 fl_set_choice(fd_form_document->choice_pagestyle,
1709 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1711 fl_set_button(fd_form_document->radio_indent, 0);
1712 fl_set_button(fd_form_document->radio_skip, 0);
1715 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1717 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1718 fl_set_button(fd_form_document->radio_indent, 1);
1720 fl_set_button(fd_form_document->radio_skip, 1);
1722 switch (params->getDefSkip().kind()) {
1723 case VSpace::SMALLSKIP:
1724 fl_set_choice (fd_form_document->choice_default_skip, 1);
1726 case VSpace::MEDSKIP:
1727 fl_set_choice (fd_form_document->choice_default_skip, 2);
1729 case VSpace::BIGSKIP:
1730 fl_set_choice (fd_form_document->choice_default_skip, 3);
1732 case VSpace::LENGTH:
1733 fl_set_choice (fd_form_document->choice_default_skip, 4);
1734 fl_set_input (fd_form_document->input_default_skip,
1735 params->getDefSkip().asLyXCommand().c_str());
1738 fl_set_choice (fd_form_document->choice_default_skip, 2);
1742 fl_set_button(fd_form_document->radio_sides_one, 0);
1743 fl_set_button(fd_form_document->radio_sides_two, 0);
1745 switch (params->sides) {
1746 case LyXTextClass::OneSide:
1747 fl_set_button(fd_form_document->radio_sides_one, 1);
1749 case LyXTextClass::TwoSides:
1750 fl_set_button(fd_form_document->radio_sides_two, 1);
1754 fl_set_button(fd_form_document->radio_columns_one, 0);
1755 fl_set_button(fd_form_document->radio_columns_two, 0);
1757 if (params->columns == 2)
1758 fl_set_button(fd_form_document->radio_columns_two, 1);
1760 fl_set_button(fd_form_document->radio_columns_one, 1);
1762 fl_set_input(fd_form_document->input_spacing, "");
1763 switch (params->spacing.getSpace()) {
1764 case Spacing::Default: // nothing bad should happen with this
1765 case Spacing::Single:
1768 fl_set_choice(fd_form_document->choice_spacing, 1);
1771 case Spacing::Onehalf:
1774 fl_set_choice(fd_form_document->choice_spacing, 2);
1777 case Spacing::Double:
1780 fl_set_choice(fd_form_document->choice_spacing, 3);
1783 case Spacing::Other:
1785 fl_set_choice(fd_form_document->choice_spacing, 4);
1787 //sprintf(sval, "%g", params->spacing.getValue());
1789 std::ostringstream sval;
1790 sval << params->spacing.getValue(); // setw?
1791 fl_set_input(fd_form_document->input_spacing,
1792 sval.str().c_str());
1795 ostrstream sval(tval, 20);
1796 sval << params->spacing.getValue() << '\0'; // setw?
1797 fl_set_input(fd_form_document->input_spacing, sval.str());
1804 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1805 params->secnumdepth);
1806 fl_set_counter_value(fd_form_document->slider_tocdepth,
1808 if (!params->float_placement.empty()) { // buffer local (Lgb)
1809 fl_set_input(fd_form_document->input_float_placement,
1810 params->float_placement.c_str());
1812 fl_set_input(fd_form_document->input_float_placement, "");
1814 if (!params->options.empty())
1815 fl_set_input(fd_form_document->input_extra,
1816 params->options.c_str());
1818 fl_set_input(fd_form_document->input_extra, "");
1820 if (current_view->buffer()->isSGML()) {
1821 // bullets not used in SGML derived documents
1822 fl_deactivate_object(fd_form_document->button_bullets);
1823 fl_set_object_lcol(fd_form_document->button_bullets,
1826 fl_activate_object(fd_form_document->button_bullets);
1827 fl_set_object_lcol(fd_form_document->button_bullets,
1831 if (current_view->buffer()->isReadonly()) {
1832 DisableDocumentLayout();
1834 EnableDocumentLayout();
1841 void MenuLayoutDocument()
1843 if (UpdateLayoutDocument()) {
1844 if (fd_form_document->form_document->visible) {
1845 fl_raise_form(fd_form_document->form_document);
1847 fl_show_form(fd_form_document->form_document,
1848 FL_PLACE_MOUSE, FL_FULLBORDER,
1849 _("Document Layout"));
1855 bool UpdateLayoutQuotes()
1858 if (!current_view->available()
1859 || current_view->buffer()->isReadonly())
1863 fl_set_choice(fd_form_quotes->choice_quotes_language,
1864 current_view->buffer()->params.quotes_language + 1);
1865 fl_set_button(fd_form_quotes->radio_single, 0);
1866 fl_set_button(fd_form_quotes->radio_double, 0);
1868 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1869 fl_set_button(fd_form_quotes->radio_single, 1);
1871 fl_set_button(fd_form_quotes->radio_double, 1);
1872 } else if (fd_form_quotes->form_quotes->visible) {
1873 fl_hide_form(fd_form_quotes->form_quotes);
1879 void MenuLayoutQuotes()
1881 if (UpdateLayoutQuotes()) {
1882 if (fd_form_quotes->form_quotes->visible) {
1883 fl_raise_form(fd_form_quotes->form_quotes);
1885 fl_show_form(fd_form_quotes->form_quotes,
1886 FL_PLACE_MOUSE, FL_FULLBORDER,
1893 bool UpdateLayoutPreamble()
1896 if (!current_view->available())
1900 fl_set_input(fd_form_preamble->input_preamble,
1901 current_view->buffer()->params.preamble.c_str());
1903 if (current_view->buffer()->isReadonly()) {
1904 fl_deactivate_object(fd_form_preamble->input_preamble);
1905 fl_deactivate_object(fd_form_preamble->button_ok);
1906 fl_deactivate_object(fd_form_preamble->button_apply);
1907 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1908 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1911 fl_activate_object(fd_form_preamble->input_preamble);
1912 fl_activate_object(fd_form_preamble->button_ok);
1913 fl_activate_object(fd_form_preamble->button_apply);
1914 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1915 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1917 } else if (fd_form_preamble->form_preamble->visible) {
1918 fl_hide_form(fd_form_preamble->form_preamble);
1924 void MenuLayoutPreamble()
1926 static int ow = -1, oh;
1928 if (UpdateLayoutPreamble()) {
1929 if (fd_form_preamble->form_preamble->visible) {
1930 fl_raise_form(fd_form_preamble->form_preamble);
1932 fl_show_form(fd_form_preamble->form_preamble,
1933 FL_PLACE_MOUSE | FL_FREE_SIZE,
1935 _("LaTeX Preamble"));
1937 ow = fd_form_preamble->form_preamble->w;
1938 oh = fd_form_preamble->form_preamble->h;
1940 fl_set_form_minsize(fd_form_preamble->form_preamble,
1947 void MenuLayoutSave()
1949 if (!current_view->available())
1952 if (AskQuestion(_("Do you want to save the current settings"),
1953 _("for Character, Document, Paper and Quotes"),
1954 _("as default for new documents?")))
1955 current_view->buffer()->saveParamsAsDefaults();
1959 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1960 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1961 LyXFont UserFreeFont(BufferParams const & params)
1963 LyXFont font(LyXFont::ALL_IGNORE);
1965 int pos = fl_get_choice(fd_form_character->choice_family);
1967 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1968 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1969 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1970 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1971 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1974 pos = fl_get_choice(fd_form_character->choice_series);
1976 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1977 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1978 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1979 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1982 pos = fl_get_choice(fd_form_character->choice_shape);
1984 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1985 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1986 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1987 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1988 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1989 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1992 pos = fl_get_choice(fd_form_character->choice_size);
1994 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1995 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1996 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1997 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1998 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1999 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2000 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2001 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2002 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2003 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2004 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2005 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2006 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2007 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2010 pos = fl_get_choice(fd_form_character->choice_bar);
2012 case 1: font.setEmph(LyXFont::IGNORE);
2013 font.setUnderbar(LyXFont::IGNORE);
2014 font.setNoun(LyXFont::IGNORE);
2015 font.setLatex(LyXFont::IGNORE);
2017 case 2: font.setEmph(LyXFont::TOGGLE); break;
2018 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2019 case 4: font.setNoun(LyXFont::TOGGLE); break;
2020 case 5: font.setLatex(LyXFont::TOGGLE); break;
2021 case 6: font.setEmph(LyXFont::INHERIT);
2022 font.setUnderbar(LyXFont::INHERIT);
2023 font.setNoun(LyXFont::INHERIT);
2024 font.setLatex(LyXFont::INHERIT);
2028 pos = fl_get_choice(fd_form_character->choice_color);
2030 case 1: font.setColor(LColor::ignore); break;
2031 case 2: font.setColor(LColor::none); break;
2032 case 3: font.setColor(LColor::black); break;
2033 case 4: font.setColor(LColor::white); break;
2034 case 5: font.setColor(LColor::red); break;
2035 case 6: font.setColor(LColor::green); break;
2036 case 7: font.setColor(LColor::blue); break;
2037 case 8: font.setColor(LColor::cyan); break;
2038 case 9: font.setColor(LColor::magenta); break;
2039 case 10: font.setColor(LColor::yellow); break;
2040 case 11: font.setColor(LColor::inherit); break;
2043 int choice = combo_language2->get();
2045 font.setLanguage(ignore_language);
2046 else if (choice == 2)
2047 font.setLanguage(params.language_info);
2049 font.setLanguage(&languages[combo_language2->getline()]);
2055 /* callbacks for form form_title */
2056 extern "C" void TimerCB(FL_OBJECT *, long)
2058 // only if the form still exists
2059 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2060 if (fd_form_title->form_title->visible) {
2061 fl_hide_form(fd_form_title->form_title);
2063 fl_free_form(fd_form_title->form_title);
2064 fd_form_title->form_title = 0;
2069 /* callbacks for form form_paragraph */
2071 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2073 // "Synchronize" the choices and input fields, making it
2074 // impossible to commit senseless data.
2076 FD_form_paragraph const * fp = fd_form_paragraph;
2078 if (obj == fp->choice_space_above) {
2079 if (fl_get_choice (fp->choice_space_above) != 7) {
2080 fl_set_input (fp->input_space_above, "");
2081 ActivateParagraphButtons();
2083 } else if (obj == fp->choice_space_below) {
2084 if (fl_get_choice (fp->choice_space_below) != 7) {
2085 fl_set_input (fp->input_space_below, "");
2086 ActivateParagraphButtons();
2088 } else if (obj == fp->input_space_above) {
2089 string input = fl_get_input (fp->input_space_above);
2091 if (input.empty()) {
2092 fl_set_choice (fp->choice_space_above, 1);
2093 ActivateParagraphButtons();
2095 else if (isValidGlueLength (input)) {
2096 fl_set_choice (fp->choice_space_above, 7);
2097 ActivateParagraphButtons();
2100 fl_set_choice (fp->choice_space_above, 7);
2101 DeactivateParagraphButtons();
2103 } else if (obj == fp->input_space_below) {
2104 string input = fl_get_input (fp->input_space_below);
2106 if (input.empty()) {
2107 fl_set_choice (fp->choice_space_below, 1);
2108 ActivateParagraphButtons();
2110 else if (isValidGlueLength (input)) {
2111 fl_set_choice (fp->choice_space_below, 7);
2112 ActivateParagraphButtons();
2115 fl_set_choice (fp->choice_space_below, 7);
2116 DeactivateParagraphButtons();
2122 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2124 if (!current_view->available())
2127 VSpace space_top, space_bottom;
2129 string labelwidthstring;
2132 // If a vspace kind is "Length" but there's no text in
2133 // the input field, reset the kind to "None".
2134 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2135 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2136 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2138 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2139 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2140 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2143 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2144 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2145 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2146 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2147 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2148 case 1: space_top = VSpace(VSpace::NONE); break;
2149 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2150 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2151 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2152 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2153 case 6: space_top = VSpace(VSpace::VFILL); break;
2154 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2156 if (fl_get_button (fd_form_paragraph->check_space_above))
2157 space_top.setKeep (true);
2158 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2159 case 1: space_bottom = VSpace(VSpace::NONE); break;
2160 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2161 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2162 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2163 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2164 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2165 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2167 if (fl_get_button (fd_form_paragraph->check_space_below))
2168 space_bottom.setKeep (true);
2170 if (fl_get_button(fd_form_paragraph->radio_align_left))
2171 align = LYX_ALIGN_LEFT;
2172 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2173 align = LYX_ALIGN_RIGHT;
2174 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2175 align = LYX_ALIGN_CENTER;
2177 align = LYX_ALIGN_BLOCK;
2179 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2180 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2183 if (current_view->the_locking_inset)
2184 text = current_view->the_locking_inset->getLyXText(current_view);
2186 text = current_view->text;
2187 text->SetParagraph(current_view,
2197 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2198 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2202 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2204 fl_hide_form(fd_form_paragraph->form_paragraph);
2208 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2210 ParagraphApplyCB(ob, data);
2211 ParagraphCancelCB(ob, data);
2215 /* callbacks for form form_character */
2217 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2219 // we set toggleall locally here, since it should be true for
2220 // all other uses of ToggleAndShow() (JMarc)
2221 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2222 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2223 current_view->setState();
2228 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2230 fl_hide_form(fd_form_character->form_character);
2234 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2236 CharacterApplyCB(ob, data);
2237 CharacterCloseCB(ob, data);
2241 /* callbacks for form form_document */
2243 void UpdateDocumentButtons(BufferParams const & params)
2245 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2247 switch (params.sides) {
2248 case LyXTextClass::OneSide:
2249 fl_set_button(fd_form_document->radio_sides_one, 1);
2251 case LyXTextClass::TwoSides:
2252 fl_set_button(fd_form_document->radio_sides_two, 1);
2256 if (params.columns == 2)
2257 fl_set_button(fd_form_document->radio_columns_two, 1);
2259 fl_set_button(fd_form_document->radio_columns_one, 1);
2261 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2262 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2263 params.secnumdepth);
2264 fl_set_counter_value(fd_form_document->slider_tocdepth,
2269 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2271 ProhibitInput(current_view);
2272 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2273 if (AskQuestion(_("Should I set some parameters to"),
2274 fl_get_choice_text(ob),
2275 _("the defaults of this document class?"))) {
2276 BufferParams params = BufferParams();
2277 params.textclass = fl_get_choice(ob)-1;
2278 params.useClassDefaults();
2279 UpdateLayoutDocument(¶ms);
2280 UpdateDocumentButtons(params);
2283 // unable to load new style
2284 WriteAlert(_("Conversion Errors!"),
2285 _("Unable to switch to new document class."),
2286 _("Reverting to original document class."));
2287 fl_set_choice(fd_form_document->choice_class,
2288 current_view->buffer()->params.textclass + 1);
2290 AllowInput(current_view);
2294 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2296 // "Synchronize" the choice and the input field, so that it
2297 // is impossible to commit senseless data.
2298 FD_form_document const * fd = fd_form_document;
2300 if (obj == fd->choice_default_skip) {
2301 if (fl_get_choice (fd->choice_default_skip) != 4) {
2302 fl_set_input (fd->input_default_skip, "");
2303 ActivateDocumentButtons();
2305 } else if (obj == fd->input_default_skip) {
2307 char const * input = fl_get_input (fd->input_default_skip);
2310 fl_set_choice (fd->choice_default_skip, 2);
2311 ActivateDocumentButtons();
2312 } else if (isValidGlueLength (input)) {
2313 fl_set_choice (fd->choice_default_skip, 4);
2314 ActivateDocumentButtons();
2316 fl_set_choice (fd->choice_default_skip, 4);
2317 DeactivateDocumentButtons();
2323 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2325 // "Synchronize" the choice and the input field, so that it
2326 // is impossible to commit senseless data.
2327 FD_form_document const * fd = fd_form_document;
2329 if (obj == fd->choice_spacing
2330 && fl_get_choice (fd->choice_spacing) != 4) {
2331 fl_set_input(fd->input_spacing, "");
2332 } else if (obj == fd->input_spacing) {
2334 const char* input = fl_get_input (fd->input_spacing);
2337 fl_set_choice (fd->choice_spacing, 1);
2339 fl_set_choice (fd->choice_spacing, 4);
2345 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2348 BufferParams * params = &(current_view->buffer()->params);
2350 Language const * old_language = params->language_info;
2351 params->language = combo_language->getline();
2352 Languages::iterator lit = languages.find(params->language);
2354 Language const * new_language;
2355 if (lit != languages.end())
2356 new_language = &(*lit).second;
2358 new_language = default_language;
2360 if (current_view->available()) {
2361 if (old_language != new_language
2362 && old_language->RightToLeft() == new_language->RightToLeft()
2363 && !current_view->buffer()->isMultiLingual())
2364 current_view->buffer()->ChangeLanguage(old_language,
2366 if (old_language != new_language) {
2367 //current_view->buffer()->redraw();
2371 params->language_info = new_language;
2373 // If default skip is a "Length" but there's no text in the
2374 // input field, reset the kind to "Medskip", which is the default.
2375 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2376 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2377 fl_set_choice (fd_form_document->choice_default_skip, 2);
2380 /* this shouldn't be done automatically IMO. For example I write german
2381 * documents with an american keyboard very often. Matthias */
2383 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2384 fl_get_choice(fd_form_document->choice_language)); */
2386 fl_get_choice_text(fd_form_document->choice_fonts);
2388 fl_get_choice_text(fd_form_document->choice_inputenc);
2390 fl_get_choice_text(fd_form_document->choice_fontsize);
2392 fl_get_choice_text(fd_form_document->choice_pagestyle);
2393 params->graphicsDriver =
2394 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2395 params->use_amsmath =
2396 fl_get_button(fd_form_document->check_use_amsmath);
2398 if (!current_view->available())
2401 current_view->text->SetCursor(current_view,
2402 current_view->text->cursor.par(),
2403 current_view->text->cursor.pos());
2404 current_view->setState();
2406 LyXTextClassList::ClassList::size_type new_class =
2407 fl_get_choice(fd_form_document->choice_class) - 1;
2409 if (params->textclass != new_class) {
2410 // try to load new_class
2411 if (textclasslist.Load(new_class)) {
2412 // successfully loaded
2414 current_view->owner()->getMiniBuffer()->
2415 Set(_("Converting document to new document class..."));
2417 int ret = cap.SwitchLayoutsBetweenClasses(
2418 current_view->buffer()->params.textclass,
2420 current_view->buffer()->paragraph);
2425 s = _("One paragraph couldn't be converted");
2428 s += _(" paragraphs couldn't be converted");
2430 WriteAlert(_("Conversion Errors!"), s,
2431 _("into chosen document class"));
2434 params->textclass = new_class;
2436 // problem changing class -- warn user and retain old style
2437 WriteAlert(_("Conversion Errors!"),
2438 _("Unable to switch to new document class."),
2439 _("Reverting to original document class."));
2440 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2444 char tmpsep = params->paragraph_separation;
2445 if (fl_get_button(fd_form_document->radio_indent))
2446 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2448 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2449 if (tmpsep != params->paragraph_separation)
2452 VSpace tmpdefskip = params->getDefSkip();
2453 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2454 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2455 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2456 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2457 case 4: params->setDefSkip(
2458 VSpace (LyXGlueLength (fl_get_input
2459 (fd_form_document->input_default_skip))));
2461 // DocumentDefskipCB assures that this never happens
2462 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2464 if (!(tmpdefskip == params->getDefSkip()))
2467 if (fl_get_button(fd_form_document->radio_columns_two))
2468 params->columns = 2;
2470 params->columns = 1;
2471 if (fl_get_button(fd_form_document->radio_sides_two))
2472 params->sides = LyXTextClass::TwoSides;
2474 params->sides = LyXTextClass::OneSide;
2476 Spacing tmpSpacing = params->spacing;
2477 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2479 lyxerr.debug() << "Spacing: SINGLE" << endl;
2480 params->spacing.set(Spacing::Single);
2483 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2484 params->spacing.set(Spacing::Onehalf);
2487 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2488 params->spacing.set(Spacing::Double);
2491 lyxerr.debug() << "Spacing: OTHER" << endl;
2492 params->spacing.set(Spacing::Other,
2493 fl_get_input(fd_form_document->input_spacing));
2496 if (tmpSpacing != params->spacing)
2499 signed char tmpchar =
2500 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2501 if (params->secnumdepth != tmpchar)
2503 params->secnumdepth = tmpchar;
2506 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2508 params->float_placement =
2509 fl_get_input(fd_form_document->input_float_placement);
2511 // More checking should be done to ensure the string doesn't have
2512 // spaces or illegal placement characters in it. (thornley)
2515 current_view->redoCurrentBuffer();
2517 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2518 current_view->buffer()->markDirty();
2521 fl_get_input(fd_form_document->input_extra);
2525 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2527 fl_hide_form(fd_form_document->form_document);
2531 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2533 DocumentCancelCB(ob, data);
2534 DocumentApplyCB(ob, data);
2538 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2541 // bullet callbacks etc. in bullet_panel.C -- ARRae
2545 /* callbacks for form form_quotes */
2547 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2549 if (!current_view->available())
2552 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2553 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2554 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2556 lga = InsetQuotes::EnglishQ;
2559 lga = InsetQuotes::SwedishQ;
2562 lga = InsetQuotes::GermanQ;
2565 lga = InsetQuotes::PolishQ;
2568 lga = InsetQuotes::FrenchQ;
2571 lga = InsetQuotes::DanishQ;
2574 current_view->buffer()->params.quotes_language = lga;
2575 if (fl_get_button(fd_form_quotes->radio_single))
2576 current_view->buffer()->
2577 params.quotes_times = InsetQuotes::SingleQ;
2579 current_view->buffer()->
2580 params.quotes_times = InsetQuotes::DoubleQ;
2584 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2586 fl_hide_form(fd_form_quotes->form_quotes);
2590 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2592 QuotesApplyCB(ob, data);
2593 QuotesCancelCB(ob, data);
2598 /* callbacks for form form_preamble */
2600 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2602 fl_hide_form(fd_form_preamble->form_preamble);
2606 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2608 if (!current_view->available())
2611 current_view->buffer()->params.preamble =
2612 fl_get_input(fd_form_preamble->input_preamble);
2613 current_view->buffer()->markDirty();
2614 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2618 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2620 PreambleApplyCB(ob, data);
2621 PreambleCancelCB(ob, data);
2625 /* callbacks for form form_table */
2628 void TableApplyCB(FL_OBJECT *, long)
2630 if (!current_view->available())
2634 // check for tables in tables
2635 if (current_view->text->cursor.par()->table){
2636 WriteAlert(_("Impossible Operation!"),
2637 _("Cannot insert table in table."),
2642 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2644 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2645 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2648 current_view->hideCursor();
2649 current_view->beforeChange();
2650 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2652 current_view->text->SetCursorParUndo(current_view->buffer());
2653 current_view->text->FreezeUndo();
2655 current_view->text->BreakParagraph(current_view);
2656 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2658 if (current_view->text->cursor.par()->Last()) {
2659 current_view->text->CursorLeft(current_view);
2661 current_view->text->BreakParagraph(current_view);
2662 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2665 current_view->text->current_font.setLatex(LyXFont::OFF);
2666 //if (!fl_get_button(fd_form_table->check_latex)){
2667 // insert the new wysiwy table
2668 current_view->text->SetLayout(current_view, 0); // standard layout
2670 if (current_view->text->cursor.par()->footnoteflag ==
2671 LyXParagraph::NO_FOOTNOTE) {
2674 ->SetParagraph(current_view, 0, 0,
2676 VSpace (0.3 * current_view->buffer()->
2677 params.spacing.getValue(),
2679 VSpace (0.3 * current_view->buffer()->
2680 params.spacing.getValue(),
2688 ->SetParagraph(current_view, 0, 0,
2690 VSpace(VSpace::NONE),
2691 VSpace(VSpace::NONE),
2698 current_view->text->cursor.par()->table =
2699 new LyXTable(xsize, ysize);
2701 Language const * lang =
2702 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2703 LyXFont font(LyXFont::ALL_INHERIT, lang);
2704 for (int i = 0; i < xsize * ysize - 1; ++i) {
2705 current_view->text->cursor.par()
2706 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2708 current_view->text->RedoParagraph(current_view);
2710 current_view->text->UnFreezeUndo();
2712 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2713 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2714 current_view->setState();
2719 void TableCancelCB(FL_OBJECT *, long)
2721 fl_hide_form(fd_form_table->form_table);
2726 void TableOKCB(FL_OBJECT * ob, long data)
2728 TableApplyCB(ob, data);
2729 TableCancelCB(ob, data);
2735 if (fd_form_figure->form_figure->visible) {
2736 fl_raise_form(fd_form_figure->form_figure);
2738 fl_show_form(fd_form_figure->form_figure,
2739 FL_PLACE_MOUSE, FL_FULLBORDER,
2740 _("Insert Figure"));
2747 if (fd_form_table->form_table->visible) {
2748 fl_raise_form(fd_form_table->form_table);
2750 fl_show_form(fd_form_table->form_table,
2751 FL_PLACE_MOUSE, FL_FULLBORDER,
2757 /* callbacks for form form_figure */
2759 void FigureApplyCB(FL_OBJECT *, long)
2761 if (!current_view->available())
2764 Buffer * buffer = current_view->buffer();
2765 if(buffer->isReadonly()) // paranoia
2768 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2769 if (fl_get_button(fd_form_figure->radio_inline)
2771 || current_view->text->cursor.par()->table
2774 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2775 current_view->insertInset(new_inset);
2776 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2777 new_inset->Edit(current_view, 0, 0, 0);
2781 current_view->hideCursor();
2782 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2783 current_view->beforeChange();
2785 current_view->text->SetCursorParUndo(current_view->buffer());
2786 current_view->text->FreezeUndo();
2788 current_view->text->BreakParagraph(current_view);
2789 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2791 if (current_view->text->cursor.par()->Last()) {
2792 current_view->text->CursorLeft(current_view);
2794 current_view->text->BreakParagraph(current_view);
2795 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2798 // The standard layout should always be numer 0;
2799 current_view->text->SetLayout(current_view, 0);
2802 if (current_view->text->cursor.par()->footnoteflag ==
2803 LyXParagraph::NO_FOOTNOTE) {
2805 current_view->text->
2806 SetParagraph(current_view, 0, 0,
2808 VSpace (0.3 * buffer->params.spacing.getValue(),
2811 buffer->params.spacing.getValue(),
2813 LYX_ALIGN_CENTER, string(), 0);
2816 current_view->text->SetParagraph(current_view, 0, 0,
2818 VSpace(VSpace::NONE),
2819 VSpace(VSpace::NONE),
2826 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2828 Inset * new_inset = new InsetFig(100, 100, buffer);
2829 current_view->insertInset(new_inset);
2830 new_inset->Edit(current_view, 0, 0, 0);
2831 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2832 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2833 current_view->text->UnFreezeUndo();
2834 current_view->setState();
2838 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2840 fl_hide_form(fd_form_figure->form_figure);
2844 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2846 FigureApplyCB(ob, data);
2847 FigureCancelCB(ob, data);
2851 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2853 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2854 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2855 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2856 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2857 lyxrc.set_font_norm_type();
2858 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2859 fontloader.update();
2861 // Of course we should only to the resize and the textcahce.clear
2862 // if values really changed...but not very important right now. (Lgb)
2864 // All buffers will need resize
2865 bufferlist.resize();
2866 // We also need to empty the textcache so that
2867 // the buffer will be formatted correctly after
2871 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2875 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2877 fl_hide_form(fd_form_screen->form_screen);
2881 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2883 ScreenCancelCB(ob, data);
2884 ScreenApplyCB(ob, data);
2888 // This function runs "configure" and then rereads lyx.defaults to
2889 // reconfigure the automatic settings.
2890 void Reconfigure(BufferView * bv)
2892 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2894 // Run configure in user lyx directory
2895 Path p(user_lyxdir);
2896 Systemcalls one(Systemcalls::System,
2897 AddName(system_lyxdir, "configure"));
2899 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2900 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2901 WriteAlert(_("The system has been reconfigured."),
2902 _("You need to restart LyX to make use of any"),
2903 _("updated document class specifications."));
2908 // Table of Contents
2911 static vector<Buffer::TocItem> toclist;
2914 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
2916 if (!current_view->available())
2920 unsigned int choice = fl_get_browser(ob);
2921 if (0 < choice && choice - 1 < toclist.size()) {
2922 current_view->beforeChange();
2923 current_view->text->SetCursor(current_view, toclist[choice-1].par, 0);
2924 current_view->text->sel_cursor =
2925 current_view->text->cursor;
2926 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2928 WriteAlert(_("Error"),
2929 _("Couldn't find this label"),
2930 _("in current document."));
2935 extern "C" void TocCancelCB(FL_OBJECT *, long)
2937 fl_hide_form(fd_form_toc->form_toc);
2942 void TocUpdateCB(FL_OBJECT *, long)
2944 if (!current_view->available()) {
2946 fl_clear_browser(fd_form_toc->browser_toc);
2947 fl_add_browser_line(fd_form_toc->browser_toc,
2948 _("*** No Document ***"));
2952 vector<vector<Buffer::TocItem> > tmp =
2953 current_view->buffer()->getTocList();
2954 int type = fl_get_choice(fd_form_toc->toctype)-1;
2955 //if (toclist == tmp[type])
2957 if (toclist.size() == tmp[type].size()) {
2958 // Check if all elements are the same.
2960 for (; i < toclist.size(); ++i) {
2961 if (toclist[i] != tmp[type][i])
2964 if (i >= toclist.size()) return;
2967 toclist = tmp[type];
2969 static Buffer * buffer = 0;
2972 if (buffer == current_view->buffer()) {
2973 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
2974 line = fl_get_browser(fd_form_toc->browser_toc);
2976 buffer = current_view->buffer();
2978 fl_clear_browser(fd_form_toc->browser_toc);
2979 fl_hide_object(fd_form_toc->browser_toc);
2981 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
2982 it != toclist.end(); ++it)
2983 fl_add_browser_line(fd_form_toc->browser_toc,
2984 (string(4*(*it).depth,' ')+
2985 (*it).str).c_str());
2987 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
2988 fl_select_browser_line(fd_form_toc->browser_toc, line);
2989 fl_show_object(fd_form_toc->browser_toc);
2993 /* callbacks for form form_ref */
2994 extern "C" void RefSelectCB(FL_OBJECT *, long data)
2996 if (!current_view->available())
3000 fl_get_browser_line(fd_form_ref->browser_ref,
3001 fl_get_browser(fd_form_ref->browser_ref));
3002 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3008 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3009 if (!current_view->NoSavedPositions()) {
3010 fl_activate_object(fd_form_ref->back);
3011 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
3014 } else if (data >= 6) {
3015 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK);
3016 if (current_view->NoSavedPositions()) {
3017 fl_deactivate_object(fd_form_ref->back);
3018 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
3023 static string const commands[5]
3024 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
3026 string t = commands[data];
3028 if (current_view->buffer()->isSGML())
3029 t += "[" + u + "]" + "{" + s + "}";
3034 new InsetRef(t, current_view->buffer());
3035 current_view->insertInset(new_inset);
3039 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3041 if (!current_view->available()) {
3042 fl_clear_browser(fd_form_ref->browser_ref);
3046 FL_OBJECT * brow = fd_form_ref->browser_ref;
3048 // Get the current line, in order to restore it later
3049 char const * const btmp = fl_get_browser_line(brow,
3050 fl_get_browser(brow));
3051 string currentstr = btmp ? btmp : "";
3053 fl_clear_browser(brow);
3054 fl_hide_object(brow);
3056 vector<string> refs = current_view->buffer()->getLabelList();
3057 if (fl_get_button(fd_form_ref->sort))
3058 sort(refs.begin(),refs.end());
3059 for (vector<string>::const_iterator it = refs.begin();
3060 it != refs.end(); ++it)
3061 fl_add_browser_line(brow, (*it).c_str());
3064 int total_lines = fl_get_browser_maxline(brow);
3065 for (int i = 1; i <= total_lines ; ++i) {
3066 if (fl_get_browser_line(brow, i) == currentstr) {
3071 fl_set_browser_topline(brow, topline);
3073 bool empty = refs.empty();
3074 bool sgml = current_view->buffer()->isSGML();
3075 bool readonly = current_view->buffer()->isReadonly();
3077 if (current_view->NoSavedPositions()) {
3078 fl_deactivate_object(fd_form_ref->back);
3079 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
3081 fl_activate_object(fd_form_ref->back);
3082 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
3086 fl_add_browser_line(brow,
3087 _("*** No labels found in document ***"));
3088 fl_deactivate_object(brow);
3089 fl_deactivate_object(fd_form_ref->gotoref);
3090 fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE);
3092 fl_select_browser_line(brow, topline);
3093 fl_activate_object(brow);
3094 fl_activate_object(fd_form_ref->gotoref);
3095 fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK);
3098 if (empty || readonly) {
3099 fl_deactivate_object(fd_form_ref->ref);
3100 fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE);
3101 fl_deactivate_object(fd_form_ref->pageref);
3102 fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE);
3104 fl_activate_object(fd_form_ref->ref);
3105 fl_set_object_lcol(fd_form_ref->ref, FL_BLACK);
3106 fl_activate_object(fd_form_ref->pageref);
3107 fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK);
3110 if (empty || readonly || sgml) {
3111 fl_deactivate_object(fd_form_ref->vref);
3112 fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
3113 fl_deactivate_object(fd_form_ref->vpageref);
3114 fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
3115 fl_deactivate_object(fd_form_ref->prettyref);
3116 fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
3118 fl_activate_object(fd_form_ref->vref);
3119 fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
3120 fl_activate_object(fd_form_ref->vpageref);
3121 fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
3122 fl_activate_object(fd_form_ref->prettyref);
3123 fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
3127 fl_activate_object(fd_form_ref->ref_name);
3128 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3130 fl_deactivate_object(fd_form_ref->ref_name);
3131 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3134 fl_show_object(brow);
3138 extern "C" void RefHideCB(FL_OBJECT *, long)
3140 fl_hide_form(fd_form_ref->form_ref);