1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 //#include "LString.h"
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"
45 #include "CutAndPaste.h"
50 using std::back_inserter;
54 using std::istream_iterator;
60 extern Combox * combo_language;
61 extern Combox * combo_language2;
62 extern BufferList bufferlist;
63 extern void show_symbols_form();
64 extern FD_form_title * fd_form_title;
65 extern FD_form_paragraph * fd_form_paragraph;
66 extern FD_form_character * fd_form_character;
67 extern FD_form_document * fd_form_document;
68 extern FD_form_quotes * fd_form_quotes;
69 extern FD_form_preamble * fd_form_preamble;
70 extern FD_form_table * fd_form_table;
71 extern FD_form_figure * fd_form_figure;
72 extern FD_form_bullet * fd_form_bullet;
74 extern BufferView * current_view; // called too many times in this file...
76 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
78 extern bool send_fax(string const & fname, string const & sendcmd);
79 extern void MenuSendto();
81 extern LyXServer * lyxserver;
83 // this should be static, but I need it in buffer.C
84 bool quitting; // flag, that we are quitting the program
85 extern bool finished; // all cleanup done just let it run through now.
87 char ascii_type; /* for selection notify callbacks */
89 bool scrolling = false;
91 // This is used to make the dreaded font toggle problem hopefully go
92 // away. Definitely not the best solution, but I think it sorta works.
93 bool toggleall = true;
96 This is the inset locking stuff needed for mathed --------------------
98 an inset can simple call LockInset in it's edit call and *ONLY* in it's
100 Inset::Edit() can only be called by the main lyx module.
102 Then the inset may modify the menu's and/or iconbars.
104 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
106 During the lock, all button and keyboard events will be modified
107 and send to the inset through the following inset-features. Note that
108 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
109 to contain the code for restoring the menus and things like this.
112 virtual void InsetButtonPress(int x, int y, int button);
113 virtual void InsetButtonRelease(int x, int y, int button);
114 virtual void InsetKeyPress(XKeyEvent *ev);
115 virtual void InsetMotionNotify(int x, int y, int state);
116 virtual void InsetUnlock();
118 If a inset wishes any redraw and/or update it just has to call
120 It's is completly irrelevant, where the inset is. UpdateInset will
121 find it in any paragraph in any buffer.
122 Of course the_locking_inset and the insets in the current paragraph/buffer
123 are checked first, so no performance problem should occur.
125 Hope that's ok for the beginning, Alejandro,
126 sorry that I needed so much time,
131 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
133 /* these functions return 1 if an error occured,
135 // Now they work only for updatable insets. [Alejandro 080596]
136 //int LockInset(UpdatableInset * inset);
137 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
138 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
139 //int UnlockInset(UpdatableInset * inset);
140 //void LockedInsetStoreUndo(Undo::undo_kind kind);
142 /* this is for asyncron updating. UpdateInsetUpdateList will be called
143 automatically from LyX. Just insert the Inset into the Updatelist */
144 //void UpdateInsetUpdateList();
145 //void PutInsetIntoInsetUpdateList(Inset * inset);
147 //InsetUpdateStruct * InsetUpdateList = 0;
151 -----------------------------------------------------------------------
154 /* some function prototypes */
156 int RunLinuxDoc(BufferView *, int, string const &);
157 int RunDocBook(int, string const &);
158 bool MenuWrite(Buffer * buf);
159 bool MenuWriteAs(Buffer * buffer);
160 void MenuReload(Buffer * buf);
161 void MenuLayoutSave();
164 void ShowMessage(Buffer * buf,
167 string const & msg3, int delay)
170 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
173 // can somebody think of something more clever? cerr?
174 cout << msg1 << msg2 << msg3 << endl;
187 // should be moved to lyxfunc.C
188 bool MenuWrite(Buffer * buffer)
191 if (!buffer->save()) {
192 string fname = buffer->fileName();
193 string s = MakeAbsPath(fname);
194 if (AskQuestion(_("Save failed. Rename and try again?"),
195 MakeDisplayPath(s, 50),
196 _("(If not, document is not saved.)"))) {
197 return MenuWriteAs(buffer);
201 lastfiles->newFile(buffer->fileName());
207 // should be moved to BufferView.C
208 // Half of this func should be in LyXView, the rest in BufferView.
209 bool MenuWriteAs(Buffer * buffer)
211 // Why do we require BufferView::text to be able to write a
212 // document? I see no point in that. (Lgb)
213 //if (!bv->text) return;
215 string fname = buffer->fileName();
216 string oldname = fname;
219 ProhibitInput(current_view);
220 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
221 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
223 if (!IsLyXFilename(fname))
226 if (buffer->isUnnamed()) {
227 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
232 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
235 OnlyFilename(fname));
237 AllowInput(current_view);
242 // Make sure the absolute filename ends with appropriate suffix
243 string s = MakeAbsPath(fname);
244 if (!IsLyXFilename(s))
247 // Same name as we have already?
249 if (!AskQuestion(_("Same name as document already has:"),
250 MakeDisplayPath(s, 50),
253 // Falls through to name change and save
255 // No, but do we have another file with this name open?
256 else if (bufferlist.exists(s)) {
257 if (AskQuestion(_("Another document with same name open!"),
258 MakeDisplayPath(s, 50),
259 _("Replace with current document?")))
261 bufferlist.close(bufferlist.getBuffer(s));
263 // Ok, change the name of the buffer, but don't save!
267 ShowMessage(buffer, _("Document renamed to '"),
268 MakeDisplayPath(s), _("', but not saved..."));
271 } // Check whether the file exists
274 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
275 MakeDisplayPath(s, 50),
280 // Ok, change the name of the buffer
283 bool unnamed = buffer->isUnnamed();
284 buffer->setUnnamed(false);
286 // Small bug: If the save fails, we have irreversible changed the name
288 // Hope this is fixed this way! (Jug)
289 if (!MenuWrite(buffer)) {
290 buffer->fileName(oldname);
291 buffer->setUnnamed(unnamed);
292 ShowMessage(buffer, _("Document could not be saved!"),
293 _("Holding the old name."), MakeDisplayPath(oldname));
296 // now remove the oldname autosave file if existant!
297 removeAutosaveFile(oldname);
302 int MenuRunLaTeX(Buffer * buffer)
306 if (buffer->isLinuxDoc())
307 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
308 else if (buffer->isLiterate())
309 ret = buffer->runLiterate();
310 else if (buffer->isDocBook())
311 ret = RunDocBook(1, buffer->fileName());
313 ret = buffer->runLaTeX();
319 s = _("One error detected");
320 t = _("You should try to fix it.");
323 s += _(" errors detected.");
324 t = _("You should try to fix them.");
326 WriteAlert(_("There were errors during the LaTeX run."), s, t);
332 int MenuBuildProg(Buffer * buffer)
336 if (buffer->isLiterate())
337 ret = buffer->buildProgram();
339 string s = _("Wrong type of document");
340 string t = _("The Build operation is not allowed in this document");
341 WriteAlert(_("There were errors during the Build process."), s, t);
349 s = _("One error detected");
350 t = _("You should try to fix it.");
353 s += _(" errors detected.");
354 t = _("You should try to fix them.");
356 WriteAlert(_("There were errors during the Build process."), s, t);
362 int MenuRunChktex(Buffer * buffer)
366 if (buffer->isSGML()) {
367 WriteAlert(_("Chktex does not work with SGML derived documents."));
370 ret = buffer->runChktex();
376 s = _("No warnings found.");
377 } else if (ret == 1) {
378 s = _("One warning found.");
379 t = _("Use 'Edit->Go to Error' to find it.");
382 s += _(" warnings found.");
383 t = _("Use 'Edit->Go to Error' to find them.");
385 WriteAlert(_("Chktex run successfully"), s, t);
387 WriteAlert(_("Error!"), _("It seems chktex does not work."));
393 int MakeLaTeXOutput(Buffer * buffer)
399 string path = OnlyPath(buffer->fileName());
400 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
401 path = buffer->tmppath;
405 ret = MenuRunLaTeX(buffer);
411 /* wait == false means don't wait for termination */
412 /* wait == true means wait for termination */
413 // The bool should be placed last on the argument line. (Lgb)
414 // Returns false if we fail.
415 bool RunScript(Buffer * buffer, bool wait,
416 string const & command,
417 string const & orgname = string(),
418 bool need_shell = true)
422 string name = orgname;
425 if (MakeLaTeXOutput(buffer) > 0)
427 /* get DVI-Filename */
429 name = ChangeExtension(buffer->getLatexName(), ".dvi");
431 path = OnlyPath(name);
432 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
433 path = buffer->tmppath;
436 // At this point we check whether the command contains the
437 // filename parameter $$FName and if that's the case we
438 // substitute the real file name otherwise the filename is
439 // simply appended. rokrau 1/12/00
442 if ( (i=command.find("$$FName")) != string::npos)
444 cmd.replace(i,7,QuoteName(name));
447 cmd = command + ' ' + QuoteName(name);
456 // OS/2 cmd.exe has another use for '&'
458 // This is not NLS safe, but it's OK, I think.
459 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
461 // COMSPEC is set, unless user unsets
462 sh = OnlyFilename(GetEnvPath("COMSPEC"));
467 if (contains(sh, "cmd.exe")
468 || contains(sh, "4os2.exe"))
469 cmd = "start /min/n " + cmd;
474 // It seems that, if wait is false, we never get back
475 // the return code of the command. This means that all
476 // the code I added in PrintApplyCB is currently
478 // CHECK What should we do here?
479 ShowMessage(buffer, _("Executing command:"), cmd);
480 result = one.startscript(Systemcalls::System, cmd);
482 ShowMessage(buffer, _("Executing command:"), cmd);
483 result = one.startscript(wait ? Systemcalls::Wait
484 : Systemcalls::DontWait, cmd);
490 // Returns false if we fail
491 bool CreatePostscript(Buffer * buffer, bool wait = false)
497 ProhibitInput(current_view);
500 if (MakeLaTeXOutput(buffer) > 0) {
501 AllowInput(current_view);
504 // Generate postscript file
505 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
511 char real_papersize = buffer->params.papersize;
512 if (real_papersize == BufferParams::PAPER_DEFAULT)
513 real_papersize = lyxrc.default_papersize;
515 switch (real_papersize) {
516 case BufferParams::PAPER_USLETTER:
519 case BufferParams::PAPER_A3PAPER:
522 case BufferParams::PAPER_A4PAPER:
525 case BufferParams::PAPER_A5PAPER:
528 case BufferParams::PAPER_B5PAPER:
531 case BufferParams::PAPER_EXECUTIVEPAPER:
534 case BufferParams::PAPER_LEGALPAPER:
537 default: /* If nothing else fits, keep an empty value... */
541 // Make postscript file.
542 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
543 command += QuoteName(psname);
544 if (buffer->params.use_geometry
545 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
546 && !lyxrc.print_paper_dimension_flag.empty()
547 && !buffer->params.paperwidth.empty()
548 && !buffer->params.paperheight.empty()) {
549 // using a custom papersize
551 command += lyxrc.print_paper_dimension_flag + ' ';
552 command += buffer->params.paperwidth + ',';
553 command += buffer->params.paperheight;
554 } else if (!paper.empty()
555 && (real_papersize != BufferParams::PAPER_USLETTER ||
556 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
557 // dvips won't accept -t letter -t landscape. In all other
558 // cases, include the paper size explicitly.
560 command += lyxrc.print_paper_flag + ' ' + paper;
562 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
564 command += lyxrc.print_landscape_flag;
566 // push directorypath, if necessary
567 string path = OnlyPath(buffer->fileName());
568 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
569 path = buffer->tmppath;
572 bool ret = RunScript(buffer, wait, command);
573 AllowInput(current_view);
578 // Returns false if we fail
579 //bool MenuPreviewPS(Buffer * buffer)
580 bool PreviewPostscript(Buffer * buffer)
586 // Generate postscript file
587 if (!CreatePostscript(buffer, true)) {
591 // Start postscript viewer
592 ProhibitInput(current_view);
593 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
595 // push directorypath, if necessary
596 string path = OnlyPath(buffer->fileName());
597 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
598 path = buffer->tmppath;
601 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
602 AllowInput(current_view);
607 void MenuFax(Buffer * buffer)
614 // Generate postscript file
615 if (!Exporter::Export(buffer, "ps", true))
619 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
622 // Generate postscript file
623 if (!CreatePostscript(buffer, true)) {
628 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
631 string path = OnlyPath (buffer->fileName());
632 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
633 path = buffer->tmppath;
636 if (!lyxrc.fax_program.empty()) {
637 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
639 Systemcalls one(Systemcalls::System, help2);
641 send_fax(ps, lyxrc.fax_command);
646 // Returns false if we fail
647 bool PreviewDVI(Buffer * buffer)
653 string paper = lyxrc.view_dvi_paper_option;
654 if (!paper.empty()) {
656 char real_papersize = buffer->params.papersize;
657 if (real_papersize == BufferParams::PAPER_DEFAULT)
658 real_papersize = lyxrc.default_papersize;
660 switch (real_papersize) {
661 case BufferParams::PAPER_USLETTER:
664 case BufferParams::PAPER_A3PAPER:
667 case BufferParams::PAPER_A4PAPER:
670 case BufferParams::PAPER_A5PAPER:
673 case BufferParams::PAPER_B5PAPER:
676 case BufferParams::PAPER_EXECUTIVEPAPER:
677 paper += " foolscap";
679 case BufferParams::PAPER_LEGALPAPER:
682 default: /* If nothing else fits, keep the empty value */
685 if (real_papersize==' ') {
686 // if (paper.empty()) {
687 if (buffer->params.orientation
688 == BufferParams::ORIENTATION_LANDSCAPE)
689 // we HAVE to give a size when the page is in
690 // landscape, so use USletter.
691 paper = " -paper usr";
693 // paper = " -paper " + paper;
694 if (buffer->params.orientation
695 == BufferParams::ORIENTATION_LANDSCAPE)
699 // push directorypath, if necessary
700 string path = OnlyPath(buffer->fileName());
701 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
702 path = buffer->tmppath;
706 string command = lyxrc.view_dvi_command + " " + paper;
707 bool ret = RunScript(buffer, false, command);
712 bool AskOverwrite(Buffer * buffer, string const & s)
715 // be friendly if there is a gui
718 !AskQuestion(_("File already exists:"),
719 MakeDisplayPath(s, 50),
720 _("Do you want to overwrite the file?"))) {
721 ShowMessage(buffer, _("Canceled"));
729 void MenuMakeLaTeX(Buffer * buffer)
731 // Why care about this?
735 // Get LaTeX-Filename
736 string s = buffer->getLatexName(false);
738 if (!AskOverwrite(buffer, s))
741 if (buffer->isDocBook())
742 ShowMessage(buffer, _("DocBook does not have a latex backend"));
744 if (buffer->isLinuxDoc())
745 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
747 buffer->makeLaTeXFile(s, string(), true);
748 ShowMessage(buffer, _("Nice LaTeX file saved as"),
754 void MenuMakeLinuxDoc(Buffer * buffer)
757 //if (!bv->text) return;
759 if (!buffer->isLinuxDoc()) {
760 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
764 // Get LinuxDoc-Filename
765 string s = ChangeExtension(buffer->fileName(), ".sgml");
767 if (!AskOverwrite(buffer, s))
770 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
771 MakeDisplayPath(s),"'...");
773 buffer->makeLinuxDocFile(s, true);
775 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
780 void MenuMakeDocBook(Buffer * buffer)
783 //if (!bv->text) return;
785 if (!buffer->isDocBook()) {
786 WriteAlert(_("Error!"),
787 _("Document class must be docbook."));
791 // Get DocBook-Filename
792 string s = ChangeExtension(buffer->fileName(), ".sgml");
794 if (!AskOverwrite(buffer, s))
797 ShowMessage(buffer, _("Building DocBook SGML file `"),
798 MakeDisplayPath(s), "'...");
800 buffer->makeDocBookFile(s, true);
802 ShowMessage(buffer, _("DocBook SGML file save as"),
807 void MenuMakeAscii(Buffer * buffer)
810 //if (!bv->text) return;
812 /* get LaTeX-Filename */
813 string s = ChangeExtension (buffer->fileName(), ".txt");
816 if (!AskOverwrite(buffer, s))
819 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
821 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
825 void MenuMakeHTML(Buffer * buffer)
827 // First, create LaTeX file
828 MenuMakeLaTeX(buffer);
830 // And now, run the converter
831 string file = buffer->fileName();
832 Path path(OnlyPath(file));
833 // the tex file name has to be correct for
834 // latex, but the html file name can be
836 string result = ChangeExtension(file, ".html");
837 string infile = buffer->getLatexName(false);
838 string tmp = lyxrc.html_command;
839 tmp = subst(tmp, "$$FName", infile);
840 tmp = subst(tmp, "$$OutName", result);
842 int res = one.startscript(Systemcalls::System, tmp);
844 ShowMessage(buffer, _("Document exported as HTML to file `")
845 + MakeDisplayPath(result) +'\'');
847 ShowMessage(buffer, _("Unable to convert to HTML the file `")
848 + MakeDisplayPath(infile)
855 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
857 // First, create LinuxDoc file
858 MenuMakeLinuxDoc(buffer);
860 // And now, run the converter
861 string file = buffer->fileName();
863 string result = ChangeExtension(file, ".html");
864 string infile = ChangeExtension(file, ".sgml");
865 string tmp = lyxrc.linuxdoc_to_html_command;
866 tmp = subst(tmp, "$$FName", infile);
867 tmp = subst(tmp, "$$OutName", result);
869 int res = one.startscript(Systemcalls::System, tmp);
871 ShowMessage(buffer,_("Document exported as HTML to file `")
872 + MakeDisplayPath(result) +'\'');
874 ShowMessage(buffer,_("Unable to convert to HTML the file `")
875 + MakeDisplayPath(infile)
881 void MenuMakeHTML_DocBook(Buffer * buffer)
883 // First, create LaTeX file
884 MenuMakeDocBook(buffer);
886 // And now, run the converter
887 string file = buffer->fileName();
888 string result = ChangeExtension(file, ".html");
889 string infile = ChangeExtension(file, ".sgml");
890 string tmp = lyxrc.docbook_to_html_command;
891 tmp = subst(tmp, "$$FName", infile);
892 tmp = subst(tmp, "$$OutName", result);
894 int res = one.startscript(Systemcalls::System, tmp);
896 ShowMessage(buffer,_("Document exported as HTML to file `")
897 + MakeDisplayPath(result) +'\'');
899 ShowMessage(buffer,_("Unable to convert to HTML the file `")
900 + MakeDisplayPath(infile)
907 void MenuExport(Buffer * buffer, string const & extyp)
910 if (extyp == "latex") {
911 // make sure that this buffer is not linuxdoc
912 MenuMakeLaTeX(buffer);
915 else if (extyp == "linuxdoc") {
916 // make sure that this buffer is not latex
917 MenuMakeLinuxDoc(buffer);
920 else if (extyp == "docbook") {
921 // make sure that this buffer is not latex or linuxdoc
922 MenuMakeDocBook(buffer);
925 else if (extyp == "dvi") {
926 // Run LaTeX as "Update dvi..." Bernhard.
927 // We want the dvi in the current directory. This
928 // is achieved by temporarily disabling use of
929 // temp directory. As a side-effect, we get
930 // *.log and *.aux files also. (Asger)
931 bool flag = lyxrc.use_tempdir;
932 lyxrc.use_tempdir = false;
933 MenuRunLaTeX(buffer);
934 lyxrc.use_tempdir = flag;
937 else if (extyp == "postscript") {
938 // Start Print-dialog. Not as good as dvi... Bernhard.
939 //should start lyxview->getDialogs()->showPrint();
940 // to get same as before
941 // MenuPrint(buffer);
942 // Since the MenuPrint is a pop-up, we can't use
943 // the same trick as above. (Asger)
944 // MISSING: Move of ps-file :-(
945 // And MenuPrint should not be used for this at all...
948 else if (extyp == "ascii") {
949 MenuMakeAscii(buffer);
951 else if (extyp == "custom") {
955 else if (extyp == "html") {
956 if (buffer->isLinuxDoc())
957 MenuMakeHTML_LinuxDoc(buffer);
958 else if (buffer->isDocBook())
959 MenuMakeHTML_DocBook(buffer);
961 MenuMakeHTML(buffer);
964 ShowMessage(buffer, _("Unknown export type: ") + extyp);
972 lyxerr.debug() << "Running QuitLyX." << endl;
974 if (!bufferlist.QwriteAll())
977 lastfiles->writeFile(lyxrc.lastfiles);
979 // Set a flag that we do quitting from the program,
980 // so no refreshes are necessary.
983 // close buffers first
984 bufferlist.closeAll();
986 // do any other cleanup procedures now
987 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
989 DestroyLyXTmpDir(system_tempdir);
996 void AutoSave(BufferView * bv)
997 // should probably be moved into BufferList (Lgb)
998 // Perfect target for a thread...
1000 if (!bv->available())
1003 if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
1004 // We don't save now, but we'll try again later
1005 bv->owner()->resetAutosaveTimer();
1009 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1011 // create autosave filename
1012 string fname = OnlyPath(bv->buffer()->fileName());
1014 fname += OnlyFilename(bv->buffer()->fileName());
1017 // tmp_ret will be located (usually) in /tmp
1018 // will that be a problem?
1019 string tmp_ret = tmpnam(0);
1021 pid_t pid = fork(); // If you want to debug the autosave
1022 // you should set pid to -1, and comment out the
1024 if (pid == 0 || pid == -1) {
1025 // pid = -1 signifies that lyx was unable
1026 // to fork. But we will do the save
1028 bool failed = false;
1029 if (!tmp_ret.empty()) {
1030 bv->buffer()->writeFile(tmp_ret, 1);
1031 // assume successful write of tmp_ret
1032 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1034 // most likely couldn't move between filesystems
1035 // unless write of tmp_ret failed
1036 // so remove tmp file (if it exists)
1037 remove(tmp_ret.c_str());
1044 // failed to write/rename tmp_ret so try writing direct
1045 if (!bv->buffer()->writeFile(fname, 1)) {
1046 // It is dangerous to do this in the child,
1047 // but safe in the parent, so...
1049 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1052 if (pid == 0) { // we are the child so...
1057 bv->buffer()->markBakClean();
1058 bv->owner()->resetAutosaveTimer();
1063 // Copyright CHT Software Service GmbH
1066 // create new file with template
1069 Buffer * NewLyxFile(string const & filename)
1071 // Split argument by :
1073 string tmpname = split(filename, name, ':');
1074 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1075 if (name.length() == 1
1076 && isalpha(static_cast<unsigned char>(name[0]))
1077 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1079 name += token(tmpname, ':', 0);
1080 tmpname = split(tmpname, ':');
1083 lyxerr.debug() << "Arg is " << filename
1084 << "\nName is " << name
1085 << "\nTemplate is " << tmpname << endl;
1087 // find a free buffer
1088 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1090 lastfiles->newFile(tmpbuf->fileName());
1095 // Insert ascii file (if filename is empty, prompt for one)
1096 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1101 if (!bv->available()) return;
1103 if (fname.empty()) {
1105 fname = fileDlg.Select(_("File to Insert"),
1106 bv->owner()->buffer()->filepath,
1109 if (fname.empty()) return;
1114 if (!fi.readable()) {
1115 WriteFSAlert(_("Error! Specified file is unreadable: "),
1116 MakeDisplayPath(fname, 50));
1120 ifstream ifs(fname.c_str());
1122 WriteFSAlert(_("Error! Cannot open specified file: "),
1123 MakeDisplayPath(fname, 50));
1127 ifs.unsetf(ios::skipws);
1128 istream_iterator<char> ii(ifs);
1129 istream_iterator<char> end;
1130 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1131 // We use this until the compilers get better...
1133 copy(ii, end, back_inserter(tmp));
1134 string tmpstr(tmp.begin(), tmp.end());
1136 // This is what we want to use and what we will use once the
1137 // compilers get good enough.
1138 //string tmpstr(ii, end); // yet a reason for using std::string
1139 // alternate approach to get the file into a string:
1141 copy(ii, end, back_inserter(tmpstr));
1143 // insert the string
1144 current_view->hideCursor();
1146 // clear the selection
1149 bv->text->InsertStringA(bv, tmpstr);
1151 bv->text->InsertStringB(bv, tmpstr);
1152 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1156 void MenuInsertLabel(char const * arg)
1159 ProhibitInput(current_view);
1160 if (label.empty()) {
1162 result = askForText(_("Enter new label to insert:"));
1164 label = frontStrip(strip(result.second));
1167 if (!label.empty()) {
1168 InsetCommandParams p( "label", label );
1169 InsetLabel * inset = new InsetLabel( p );
1170 current_view->insertInset( inset );
1172 AllowInput(current_view);
1176 // candidate for move to LyXView
1177 // This is only used in toolbar.C
1178 void LayoutsCB(int sel, void *, Combox *)
1180 string tmp = tostr(sel);
1181 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1187 * SGML Linuxdoc support:
1188 * (flag == 0) make TeX output
1189 * (flag == 1) make dvi output
1191 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1198 /* generate a path-less extension name */
1199 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1200 string path = OnlyPath (filename);
1201 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1202 path = bv->buffer()->tmppath;
1206 if (!bv->available())
1208 bv->buffer()->makeLinuxDocFile(name, false);
1210 // CHECK remove this once we have a proper geometry class
1212 BufferParams::PAPER_SIZE ps =
1213 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1215 case BufferParams::PAPER_A4PAPER:
1216 add_flags = "-p a4";
1218 case BufferParams::PAPER_USLETTER:
1219 add_flags = "-p letter";
1221 default: /* nothing to be done yet ;-) */ break;
1228 case 0: /* TeX output asked */
1229 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1230 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1231 if (one.startscript(Systemcalls::System, s2))
1234 case 1: /* dvi output asked */
1235 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1236 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1237 if (one.startscript(Systemcalls::System, s2)) {
1241 default: /* unknown output */
1247 bv->buffer()->redraw();
1253 * SGML DocBook support:
1254 * (flag == 1) make dvi output
1256 int RunDocBook(int flag, string const & filename)
1258 /* generate a path-less extension name */
1259 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1260 string path = OnlyPath (filename);
1261 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1262 path = current_view->buffer()->tmppath;
1266 if (!current_view->available())
1269 current_view->buffer()->makeDocBookFile(name, false);
1271 // Shall this code go or should it stay? (Lgb)
1272 // This code is a placeholder for future implementation. (Jose')
1273 // string add_flags;
1274 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1276 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1277 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1278 // default: /* nothing to be done yet ;-) */ break;
1280 ProhibitInput(current_view);
1285 case 1: /* dvi output asked */
1287 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1288 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1289 if (one.startscript(Systemcalls::System, s2)) {
1294 default: /* unknown output */
1298 AllowInput(current_view);
1300 current_view->buffer()->redraw();
1305 void MenuLayoutCharacter()
1307 static int ow = -1, oh;
1309 if (fd_form_character->form_character->visible) {
1310 fl_raise_form(fd_form_character->form_character);
1312 fl_show_form(fd_form_character->form_character,
1313 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1314 _("Character Style"));
1316 ow = fd_form_character->form_character->w;
1317 oh = fd_form_character->form_character->h;
1319 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1325 void DeactivateParagraphButtons ()
1327 fl_deactivate_object (fd_form_paragraph->button_ok);
1328 fl_deactivate_object (fd_form_paragraph->button_apply);
1329 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1330 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1335 void ActivateParagraphButtons ()
1337 fl_activate_object (fd_form_paragraph->button_ok);
1338 fl_activate_object (fd_form_paragraph->button_apply);
1339 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1340 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1345 void DisableParagraphLayout ()
1347 DeactivateParagraphButtons();
1348 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1349 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1350 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1351 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1352 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1353 fl_deactivate_object (fd_form_paragraph->check_noindent);
1354 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1355 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1356 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1357 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1358 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1359 fl_deactivate_object (fd_form_paragraph->input_space_above);
1360 fl_deactivate_object (fd_form_paragraph->input_space_below);
1361 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1362 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1363 fl_deactivate_object (fd_form_paragraph->check_space_above);
1364 fl_deactivate_object (fd_form_paragraph->check_space_below);
1369 void EnableParagraphLayout ()
1371 ActivateParagraphButtons();
1372 fl_activate_object (fd_form_paragraph->input_labelwidth);
1373 fl_activate_object (fd_form_paragraph->check_lines_top);
1374 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1375 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1376 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1377 fl_activate_object (fd_form_paragraph->check_noindent);
1378 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1379 fl_activate_object (fd_form_paragraph->radio_align_right);
1380 fl_activate_object (fd_form_paragraph->radio_align_left);
1381 fl_activate_object (fd_form_paragraph->radio_align_block);
1382 fl_activate_object (fd_form_paragraph->radio_align_center);
1383 fl_activate_object (fd_form_paragraph->input_space_above);
1384 fl_activate_object (fd_form_paragraph->input_space_below);
1385 fl_activate_object (fd_form_paragraph->choice_space_above);
1386 fl_activate_object (fd_form_paragraph->choice_space_below);
1387 fl_activate_object (fd_form_paragraph->check_space_above);
1388 fl_activate_object (fd_form_paragraph->check_space_below);
1392 bool UpdateLayoutParagraph()
1394 if (!current_view->available()) {
1395 if (fd_form_paragraph->form_paragraph->visible)
1396 fl_hide_form(fd_form_paragraph->form_paragraph);
1400 Buffer * buf = current_view->buffer();
1402 if (current_view->the_locking_inset)
1403 text = current_view->the_locking_inset->getLyXText(current_view);
1405 text = current_view->text;
1407 fl_set_input(fd_form_paragraph->input_labelwidth,
1408 text->cursor.par()->GetLabelWidthString().c_str());
1409 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1410 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1411 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1412 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1414 int align = text->cursor.par()->GetAlign();
1415 if (align == LYX_ALIGN_LAYOUT)
1416 align = textclasslist.Style(buf->params.textclass,
1417 text->cursor.par()->GetLayout()).align;
1420 case LYX_ALIGN_RIGHT:
1421 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1423 case LYX_ALIGN_LEFT:
1424 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1426 case LYX_ALIGN_CENTER:
1427 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1430 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1435 fl_set_button(fd_form_paragraph->check_lines_top,
1436 text->cursor.par()->FirstPhysicalPar()->line_top);
1438 fl_set_button(fd_form_paragraph->check_lines_bottom,
1439 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1441 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1442 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1444 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1445 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1446 fl_set_button(fd_form_paragraph->check_noindent,
1447 text->cursor.par()->FirstPhysicalPar()->noindent);
1449 fl_set_button(fd_form_paragraph->check_lines_top,
1450 text->cursor.par()->line_top);
1451 fl_set_button(fd_form_paragraph->check_lines_bottom,
1452 text->cursor.par()->line_bottom);
1453 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1454 text->cursor.par()->pagebreak_top);
1455 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1456 text->cursor.par()->pagebreak_bottom);
1457 fl_set_button(fd_form_paragraph->check_noindent,
1458 text->cursor.par()->noindent);
1460 fl_set_input (fd_form_paragraph->input_space_above, "");
1463 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1465 switch (text->cursor.par()->added_space_top.kind()) {
1469 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1471 case VSpace::DEFSKIP:
1472 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1474 case VSpace::SMALLSKIP:
1475 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1477 case VSpace::MEDSKIP:
1478 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1480 case VSpace::BIGSKIP:
1481 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1484 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1486 case VSpace::LENGTH:
1487 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1489 fl_set_input (fd_form_paragraph->input_space_above,
1490 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1492 fl_set_input (fd_form_paragraph->input_space_above,
1493 text->cursor.par()->added_space_top.length().asString().c_str());
1498 fl_set_button (fd_form_paragraph->check_space_above,
1499 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1500 fl_set_input (fd_form_paragraph->input_space_below, "");
1501 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1503 fl_set_button (fd_form_paragraph->check_space_above,
1504 text->cursor.par()->added_space_top.keep());
1505 fl_set_input (fd_form_paragraph->input_space_below, "");
1506 switch (text->cursor.par()->added_space_bottom.kind()) {
1509 fl_set_choice (fd_form_paragraph->choice_space_below,
1512 case VSpace::DEFSKIP:
1513 fl_set_choice (fd_form_paragraph->choice_space_below,
1516 case VSpace::SMALLSKIP:
1517 fl_set_choice (fd_form_paragraph->choice_space_below,
1520 case VSpace::MEDSKIP:
1521 fl_set_choice (fd_form_paragraph->choice_space_below,
1524 case VSpace::BIGSKIP:
1525 fl_set_choice (fd_form_paragraph->choice_space_below,
1529 fl_set_choice (fd_form_paragraph->choice_space_below,
1532 case VSpace::LENGTH:
1533 fl_set_choice (fd_form_paragraph->choice_space_below,
1536 fl_set_input (fd_form_paragraph->input_space_below,
1537 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1540 fl_set_button (fd_form_paragraph->check_space_below,
1541 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1543 fl_set_button(fd_form_paragraph->check_noindent,
1544 text->cursor.par()->FirstPhysicalPar()->noindent);
1546 fl_set_input (fd_form_paragraph->input_space_below,
1547 text->cursor.par()->added_space_bottom.length().asString().c_str());
1550 fl_set_button (fd_form_paragraph->check_space_below,
1551 text->cursor.par()->added_space_bottom.keep());
1553 fl_set_button(fd_form_paragraph->check_noindent,
1554 text->cursor.par()->noindent);
1556 if (current_view->buffer()->isReadonly()) {
1557 DisableParagraphLayout();
1559 EnableParagraphLayout();
1565 void MenuLayoutParagraph()
1567 if (UpdateLayoutParagraph()) {
1568 if (fd_form_paragraph->form_paragraph->visible) {
1569 fl_raise_form(fd_form_paragraph->form_paragraph);
1571 fl_show_form(fd_form_paragraph->form_paragraph,
1572 FL_PLACE_MOUSE, FL_FULLBORDER,
1573 _("Paragraph Environment"));
1578 #ifdef USE_OLD_DOCUMENT_LAYOUT
1580 void DeactivateDocumentButtons ()
1582 fl_deactivate_object (fd_form_document->button_ok);
1583 fl_deactivate_object (fd_form_document->button_apply);
1584 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1585 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1590 void ActivateDocumentButtons ()
1592 fl_activate_object (fd_form_document->button_ok);
1593 fl_activate_object (fd_form_document->button_apply);
1594 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1595 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1600 void DisableDocumentLayout ()
1602 DeactivateDocumentButtons ();
1603 fl_deactivate_object (fd_form_document->group_radio_separation);
1604 fl_deactivate_object (fd_form_document->radio_indent);
1605 fl_deactivate_object (fd_form_document->radio_skip);
1606 fl_deactivate_object (fd_form_document->choice_class);
1607 fl_deactivate_object (fd_form_document->choice_pagestyle);
1608 fl_deactivate_object (fd_form_document->choice_fonts);
1609 fl_deactivate_object (fd_form_document->choice_fontsize);
1610 fl_deactivate_object (fd_form_document->input_float_placement);
1611 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1612 fl_deactivate_object (fd_form_document->choice_inputenc);
1613 fl_deactivate_object (fd_form_document->group_radio_sides);
1614 fl_deactivate_object (fd_form_document->radio_sides_one);
1615 fl_deactivate_object (fd_form_document->radio_sides_two);
1616 fl_deactivate_object (fd_form_document->group_radio_columns);
1617 fl_deactivate_object (fd_form_document->radio_columns_one);
1618 fl_deactivate_object (fd_form_document->radio_columns_two);
1619 fl_deactivate_object (fd_form_document->input_extra);
1620 fl_deactivate_object (fd_form_document->choice_language);
1621 combo_language->deactivate();
1622 fl_deactivate_object (fd_form_document->input_default_skip);
1623 fl_deactivate_object (fd_form_document->choice_default_skip);
1624 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1625 fl_deactivate_object (fd_form_document->slider_tocdepth);
1626 fl_deactivate_object (fd_form_document->choice_spacing);
1627 fl_deactivate_object (fd_form_document->input_spacing);
1628 fl_deactivate_object (fd_form_document->check_use_amsmath);
1633 void EnableDocumentLayout ()
1635 ActivateDocumentButtons ();
1636 fl_activate_object (fd_form_document->group_radio_separation);
1637 fl_activate_object (fd_form_document->radio_indent);
1638 fl_activate_object (fd_form_document->radio_skip);
1639 fl_activate_object (fd_form_document->choice_class);
1640 fl_activate_object (fd_form_document->choice_pagestyle);
1641 fl_activate_object (fd_form_document->choice_fonts);
1642 fl_activate_object (fd_form_document->choice_fontsize);
1643 fl_activate_object (fd_form_document->input_float_placement);
1644 fl_activate_object (fd_form_document->choice_postscript_driver);
1645 fl_activate_object (fd_form_document->choice_inputenc);
1646 fl_activate_object (fd_form_document->group_radio_sides);
1647 fl_activate_object (fd_form_document->radio_sides_one);
1648 fl_activate_object (fd_form_document->radio_sides_two);
1649 fl_activate_object (fd_form_document->group_radio_columns);
1650 fl_activate_object (fd_form_document->radio_columns_one);
1651 fl_activate_object (fd_form_document->radio_columns_two);
1652 fl_activate_object (fd_form_document->input_extra);
1653 fl_activate_object (fd_form_document->choice_language);
1654 combo_language->activate();
1655 fl_activate_object (fd_form_document->input_default_skip);
1656 fl_activate_object (fd_form_document->choice_default_skip);
1657 fl_activate_object (fd_form_document->slider_secnumdepth);
1658 fl_activate_object (fd_form_document->slider_tocdepth);
1659 fl_activate_object (fd_form_document->choice_spacing);
1660 fl_activate_object (fd_form_document->input_spacing);
1661 fl_activate_object (fd_form_document->check_use_amsmath);
1665 bool UpdateLayoutDocument(BufferParams * params)
1667 if (!current_view->available()) {
1668 if (fd_form_document->form_document->visible)
1669 fl_hide_form(fd_form_document->form_document);
1674 params = ¤t_view->buffer()->params;
1675 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1677 fl_set_choice_text(fd_form_document->choice_class,
1678 textclasslist.DescOfClass(params->textclass).c_str());
1679 combo_language->select_text(params->language.c_str());
1681 fl_set_choice_text(fd_form_document->choice_fonts,
1682 params->fonts.c_str());
1683 fl_set_choice_text(fd_form_document->choice_inputenc,
1684 params->inputenc.c_str());
1685 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1686 params->graphicsDriver.c_str());
1688 // ale970405+lasgoutt970513
1689 fl_clear_choice(fd_form_document->choice_fontsize);
1690 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1691 fl_addto_choice(fd_form_document->choice_fontsize,
1692 tclass.opt_fontsize().c_str());
1693 fl_set_choice(fd_form_document->choice_fontsize,
1694 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1696 // ale970405+lasgoutt970513
1697 fl_clear_choice(fd_form_document->choice_pagestyle);
1698 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1699 fl_addto_choice(fd_form_document->choice_pagestyle,
1700 tclass.opt_pagestyle().c_str());
1702 fl_set_choice(fd_form_document->choice_pagestyle,
1703 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1705 fl_set_button(fd_form_document->radio_indent, 0);
1706 fl_set_button(fd_form_document->radio_skip, 0);
1709 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1711 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1712 fl_set_button(fd_form_document->radio_indent, 1);
1714 fl_set_button(fd_form_document->radio_skip, 1);
1716 switch (params->getDefSkip().kind()) {
1717 case VSpace::SMALLSKIP:
1718 fl_set_choice (fd_form_document->choice_default_skip, 1);
1720 case VSpace::MEDSKIP:
1721 fl_set_choice (fd_form_document->choice_default_skip, 2);
1723 case VSpace::BIGSKIP:
1724 fl_set_choice (fd_form_document->choice_default_skip, 3);
1726 case VSpace::LENGTH:
1727 fl_set_choice (fd_form_document->choice_default_skip, 4);
1728 fl_set_input (fd_form_document->input_default_skip,
1729 params->getDefSkip().asLyXCommand().c_str());
1732 fl_set_choice (fd_form_document->choice_default_skip, 2);
1736 fl_set_button(fd_form_document->radio_sides_one, 0);
1737 fl_set_button(fd_form_document->radio_sides_two, 0);
1739 switch (params->sides) {
1740 case LyXTextClass::OneSide:
1741 fl_set_button(fd_form_document->radio_sides_one, 1);
1743 case LyXTextClass::TwoSides:
1744 fl_set_button(fd_form_document->radio_sides_two, 1);
1748 fl_set_button(fd_form_document->radio_columns_one, 0);
1749 fl_set_button(fd_form_document->radio_columns_two, 0);
1751 if (params->columns == 2)
1752 fl_set_button(fd_form_document->radio_columns_two, 1);
1754 fl_set_button(fd_form_document->radio_columns_one, 1);
1756 fl_set_input(fd_form_document->input_spacing, "");
1757 switch (params->spacing.getSpace()) {
1758 case Spacing::Default: // nothing bad should happen with this
1759 case Spacing::Single:
1762 fl_set_choice(fd_form_document->choice_spacing, 1);
1765 case Spacing::Onehalf:
1768 fl_set_choice(fd_form_document->choice_spacing, 2);
1771 case Spacing::Double:
1774 fl_set_choice(fd_form_document->choice_spacing, 3);
1777 case Spacing::Other:
1779 fl_set_choice(fd_form_document->choice_spacing, 4);
1781 //sprintf(sval, "%g", params->spacing.getValue());
1783 std::ostringstream sval;
1784 sval << params->spacing.getValue(); // setw?
1785 fl_set_input(fd_form_document->input_spacing,
1786 sval.str().c_str());
1789 ostrstream sval(tval, 20);
1790 sval << params->spacing.getValue() << '\0'; // setw?
1791 fl_set_input(fd_form_document->input_spacing, sval.str());
1798 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1799 params->secnumdepth);
1800 fl_set_counter_value(fd_form_document->slider_tocdepth,
1802 if (!params->float_placement.empty()) { // buffer local (Lgb)
1803 fl_set_input(fd_form_document->input_float_placement,
1804 params->float_placement.c_str());
1806 fl_set_input(fd_form_document->input_float_placement, "");
1808 if (!params->options.empty())
1809 fl_set_input(fd_form_document->input_extra,
1810 params->options.c_str());
1812 fl_set_input(fd_form_document->input_extra, "");
1814 if (current_view->buffer()->isSGML()) {
1815 // bullets not used in SGML derived documents
1816 fl_deactivate_object(fd_form_document->button_bullets);
1817 fl_set_object_lcol(fd_form_document->button_bullets,
1820 fl_activate_object(fd_form_document->button_bullets);
1821 fl_set_object_lcol(fd_form_document->button_bullets,
1825 if (current_view->buffer()->isReadonly()) {
1826 DisableDocumentLayout();
1828 EnableDocumentLayout();
1835 void MenuLayoutDocument()
1837 if (UpdateLayoutDocument()) {
1838 if (fd_form_document->form_document->visible) {
1839 fl_raise_form(fd_form_document->form_document);
1841 fl_show_form(fd_form_document->form_document,
1842 FL_PLACE_MOUSE, FL_FULLBORDER,
1843 _("Document Layout"));
1849 bool UpdateLayoutQuotes()
1852 if (!current_view->available()
1853 || current_view->buffer()->isReadonly())
1857 fl_set_choice(fd_form_quotes->choice_quotes_language,
1858 current_view->buffer()->params.quotes_language + 1);
1859 fl_set_button(fd_form_quotes->radio_single, 0);
1860 fl_set_button(fd_form_quotes->radio_double, 0);
1862 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1863 fl_set_button(fd_form_quotes->radio_single, 1);
1865 fl_set_button(fd_form_quotes->radio_double, 1);
1866 } else if (fd_form_quotes->form_quotes->visible) {
1867 fl_hide_form(fd_form_quotes->form_quotes);
1873 void MenuLayoutQuotes()
1875 if (UpdateLayoutQuotes()) {
1876 if (fd_form_quotes->form_quotes->visible) {
1877 fl_raise_form(fd_form_quotes->form_quotes);
1879 fl_show_form(fd_form_quotes->form_quotes,
1880 FL_PLACE_MOUSE, FL_FULLBORDER,
1888 bool UpdateLayoutPreamble()
1891 if (!current_view->available())
1895 fl_set_input(fd_form_preamble->input_preamble,
1896 current_view->buffer()->params.preamble.c_str());
1898 if (current_view->buffer()->isReadonly()) {
1899 fl_deactivate_object(fd_form_preamble->input_preamble);
1900 fl_deactivate_object(fd_form_preamble->button_ok);
1901 fl_deactivate_object(fd_form_preamble->button_apply);
1902 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1903 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1906 fl_activate_object(fd_form_preamble->input_preamble);
1907 fl_activate_object(fd_form_preamble->button_ok);
1908 fl_activate_object(fd_form_preamble->button_apply);
1909 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1910 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1912 } else if (fd_form_preamble->form_preamble->visible) {
1913 fl_hide_form(fd_form_preamble->form_preamble);
1919 void MenuLayoutPreamble()
1921 static int ow = -1, oh;
1923 if (UpdateLayoutPreamble()) {
1924 if (fd_form_preamble->form_preamble->visible) {
1925 fl_raise_form(fd_form_preamble->form_preamble);
1927 fl_show_form(fd_form_preamble->form_preamble,
1928 FL_PLACE_MOUSE | FL_FREE_SIZE,
1930 _("LaTeX Preamble"));
1932 ow = fd_form_preamble->form_preamble->w;
1933 oh = fd_form_preamble->form_preamble->h;
1935 fl_set_form_minsize(fd_form_preamble->form_preamble,
1942 void MenuLayoutSave()
1944 if (!current_view->available())
1947 if (AskQuestion(_("Do you want to save the current settings"),
1948 _("for Character, Document, Paper and Quotes"),
1949 _("as default for new documents?")))
1950 current_view->buffer()->saveParamsAsDefaults();
1954 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1955 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1956 LyXFont UserFreeFont(BufferParams const & params)
1958 LyXFont font(LyXFont::ALL_IGNORE);
1960 int pos = fl_get_choice(fd_form_character->choice_family);
1962 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1963 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1964 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1965 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1966 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1969 pos = fl_get_choice(fd_form_character->choice_series);
1971 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1972 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1973 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1974 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1977 pos = fl_get_choice(fd_form_character->choice_shape);
1979 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1980 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1981 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1982 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1983 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1984 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1987 pos = fl_get_choice(fd_form_character->choice_size);
1989 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1990 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1991 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1992 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1993 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1994 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1995 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1996 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1997 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1998 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1999 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2000 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2001 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2002 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2005 pos = fl_get_choice(fd_form_character->choice_bar);
2007 case 1: font.setEmph(LyXFont::IGNORE);
2008 font.setUnderbar(LyXFont::IGNORE);
2009 font.setNoun(LyXFont::IGNORE);
2010 font.setLatex(LyXFont::IGNORE);
2012 case 2: font.setEmph(LyXFont::TOGGLE); break;
2013 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2014 case 4: font.setNoun(LyXFont::TOGGLE); break;
2015 case 5: font.setLatex(LyXFont::TOGGLE); break;
2016 case 6: font.setEmph(LyXFont::INHERIT);
2017 font.setUnderbar(LyXFont::INHERIT);
2018 font.setNoun(LyXFont::INHERIT);
2019 font.setLatex(LyXFont::INHERIT);
2023 pos = fl_get_choice(fd_form_character->choice_color);
2025 case 1: font.setColor(LColor::ignore); break;
2026 case 2: font.setColor(LColor::none); break;
2027 case 3: font.setColor(LColor::black); break;
2028 case 4: font.setColor(LColor::white); break;
2029 case 5: font.setColor(LColor::red); break;
2030 case 6: font.setColor(LColor::green); break;
2031 case 7: font.setColor(LColor::blue); break;
2032 case 8: font.setColor(LColor::cyan); break;
2033 case 9: font.setColor(LColor::magenta); break;
2034 case 10: font.setColor(LColor::yellow); break;
2035 case 11: font.setColor(LColor::inherit); break;
2038 int choice = combo_language2->get();
2040 font.setLanguage(ignore_language);
2041 else if (choice == 2)
2042 font.setLanguage(params.language_info);
2044 font.setLanguage(&languages[combo_language2->getline()]);
2050 /* callbacks for form form_title */
2051 extern "C" void TimerCB(FL_OBJECT *, long)
2053 // only if the form still exists
2054 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2055 if (fd_form_title->form_title->visible) {
2056 fl_hide_form(fd_form_title->form_title);
2058 fl_free_form(fd_form_title->form_title);
2059 fd_form_title->form_title = 0;
2064 /* callbacks for form form_paragraph */
2066 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2068 // "Synchronize" the choices and input fields, making it
2069 // impossible to commit senseless data.
2071 FD_form_paragraph const * fp = fd_form_paragraph;
2073 if (obj == fp->choice_space_above) {
2074 if (fl_get_choice (fp->choice_space_above) != 7) {
2075 fl_set_input (fp->input_space_above, "");
2076 ActivateParagraphButtons();
2078 } else if (obj == fp->choice_space_below) {
2079 if (fl_get_choice (fp->choice_space_below) != 7) {
2080 fl_set_input (fp->input_space_below, "");
2081 ActivateParagraphButtons();
2083 } else if (obj == fp->input_space_above) {
2084 string input = fl_get_input (fp->input_space_above);
2086 if (input.empty()) {
2087 fl_set_choice (fp->choice_space_above, 1);
2088 ActivateParagraphButtons();
2090 else if (isValidGlueLength (input)) {
2091 fl_set_choice (fp->choice_space_above, 7);
2092 ActivateParagraphButtons();
2095 fl_set_choice (fp->choice_space_above, 7);
2096 DeactivateParagraphButtons();
2098 } else if (obj == fp->input_space_below) {
2099 string input = fl_get_input (fp->input_space_below);
2101 if (input.empty()) {
2102 fl_set_choice (fp->choice_space_below, 1);
2103 ActivateParagraphButtons();
2105 else if (isValidGlueLength (input)) {
2106 fl_set_choice (fp->choice_space_below, 7);
2107 ActivateParagraphButtons();
2110 fl_set_choice (fp->choice_space_below, 7);
2111 DeactivateParagraphButtons();
2117 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2119 if (!current_view->available())
2122 VSpace space_top, space_bottom;
2124 string labelwidthstring;
2127 // If a vspace kind is "Length" but there's no text in
2128 // the input field, reset the kind to "None".
2129 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2130 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2131 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2133 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2134 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2135 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2138 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2139 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2140 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2141 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2142 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2143 case 1: space_top = VSpace(VSpace::NONE); break;
2144 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2145 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2146 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2147 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2148 case 6: space_top = VSpace(VSpace::VFILL); break;
2149 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2151 if (fl_get_button (fd_form_paragraph->check_space_above))
2152 space_top.setKeep (true);
2153 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2154 case 1: space_bottom = VSpace(VSpace::NONE); break;
2155 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2156 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2157 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2158 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2159 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2160 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2162 if (fl_get_button (fd_form_paragraph->check_space_below))
2163 space_bottom.setKeep (true);
2165 if (fl_get_button(fd_form_paragraph->radio_align_left))
2166 align = LYX_ALIGN_LEFT;
2167 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2168 align = LYX_ALIGN_RIGHT;
2169 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2170 align = LYX_ALIGN_CENTER;
2172 align = LYX_ALIGN_BLOCK;
2174 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2175 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2178 if (current_view->the_locking_inset)
2179 text = current_view->the_locking_inset->getLyXText(current_view);
2181 text = current_view->text;
2182 text->SetParagraph(current_view,
2192 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2193 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2197 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2199 fl_hide_form(fd_form_paragraph->form_paragraph);
2203 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2205 ParagraphApplyCB(ob, data);
2206 ParagraphCancelCB(ob, data);
2210 /* callbacks for form form_character */
2212 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2214 // we set toggleall locally here, since it should be true for
2215 // all other uses of ToggleAndShow() (JMarc)
2216 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2217 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2218 current_view->setState();
2223 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2225 fl_hide_form(fd_form_character->form_character);
2229 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2231 CharacterApplyCB(ob, data);
2232 CharacterCloseCB(ob, data);
2236 #ifdef USE_OLD_DOCUMENT_LAYOUT
2237 /* callbacks for form form_document */
2238 void UpdateDocumentButtons(BufferParams const & params)
2240 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2242 switch (params.sides) {
2243 case LyXTextClass::OneSide:
2244 fl_set_button(fd_form_document->radio_sides_one, 1);
2246 case LyXTextClass::TwoSides:
2247 fl_set_button(fd_form_document->radio_sides_two, 1);
2251 if (params.columns == 2)
2252 fl_set_button(fd_form_document->radio_columns_two, 1);
2254 fl_set_button(fd_form_document->radio_columns_one, 1);
2256 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2257 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2258 params.secnumdepth);
2259 fl_set_counter_value(fd_form_document->slider_tocdepth,
2264 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2266 ProhibitInput(current_view);
2267 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2268 if (AskQuestion(_("Should I set some parameters to"),
2269 fl_get_choice_text(ob),
2270 _("the defaults of this document class?"))) {
2271 BufferParams params = BufferParams();
2272 params.textclass = fl_get_choice(ob)-1;
2273 params.useClassDefaults();
2274 UpdateLayoutDocument(¶ms);
2275 UpdateDocumentButtons(params);
2278 // unable to load new style
2279 WriteAlert(_("Conversion Errors!"),
2280 _("Unable to switch to new document class."),
2281 _("Reverting to original document class."));
2282 fl_set_choice(fd_form_document->choice_class,
2283 current_view->buffer()->params.textclass + 1);
2285 AllowInput(current_view);
2289 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2291 // "Synchronize" the choice and the input field, so that it
2292 // is impossible to commit senseless data.
2293 FD_form_document const * fd = fd_form_document;
2295 if (obj == fd->choice_default_skip) {
2296 if (fl_get_choice (fd->choice_default_skip) != 4) {
2297 fl_set_input (fd->input_default_skip, "");
2298 ActivateDocumentButtons();
2300 } else if (obj == fd->input_default_skip) {
2302 char const * input = fl_get_input (fd->input_default_skip);
2305 fl_set_choice (fd->choice_default_skip, 2);
2306 ActivateDocumentButtons();
2307 } else if (isValidGlueLength (input)) {
2308 fl_set_choice (fd->choice_default_skip, 4);
2309 ActivateDocumentButtons();
2311 fl_set_choice (fd->choice_default_skip, 4);
2312 DeactivateDocumentButtons();
2318 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2320 // "Synchronize" the choice and the input field, so that it
2321 // is impossible to commit senseless data.
2322 FD_form_document const * fd = fd_form_document;
2324 if (obj == fd->choice_spacing
2325 && fl_get_choice (fd->choice_spacing) != 4) {
2326 fl_set_input(fd->input_spacing, "");
2327 } else if (obj == fd->input_spacing) {
2329 const char* input = fl_get_input (fd->input_spacing);
2332 fl_set_choice (fd->choice_spacing, 1);
2334 fl_set_choice (fd->choice_spacing, 4);
2340 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2343 BufferParams * params = &(current_view->buffer()->params);
2345 Language const * old_language = params->language_info;
2346 params->language = combo_language->getline();
2347 Languages::iterator lit = languages.find(params->language);
2349 Language const * new_language;
2350 if (lit != languages.end())
2351 new_language = &(*lit).second;
2353 new_language = default_language;
2355 if (current_view->available()) {
2356 if (old_language != new_language
2357 && old_language->RightToLeft() == new_language->RightToLeft()
2358 && !current_view->buffer()->isMultiLingual())
2359 current_view->buffer()->ChangeLanguage(old_language,
2361 if (old_language != new_language) {
2362 //current_view->buffer()->redraw();
2366 params->language_info = new_language;
2368 // If default skip is a "Length" but there's no text in the
2369 // input field, reset the kind to "Medskip", which is the default.
2370 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2371 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2372 fl_set_choice (fd_form_document->choice_default_skip, 2);
2375 /* this shouldn't be done automatically IMO. For example I write german
2376 * documents with an american keyboard very often. Matthias */
2378 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2379 fl_get_choice(fd_form_document->choice_language)); */
2381 fl_get_choice_text(fd_form_document->choice_fonts);
2383 fl_get_choice_text(fd_form_document->choice_inputenc);
2385 fl_get_choice_text(fd_form_document->choice_fontsize);
2387 fl_get_choice_text(fd_form_document->choice_pagestyle);
2388 params->graphicsDriver =
2389 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2390 params->use_amsmath =
2391 fl_get_button(fd_form_document->check_use_amsmath);
2393 if (!current_view->available())
2396 current_view->text->SetCursor(current_view,
2397 current_view->text->cursor.par(),
2398 current_view->text->cursor.pos());
2399 current_view->setState();
2401 LyXTextClassList::ClassList::size_type new_class =
2402 fl_get_choice(fd_form_document->choice_class) - 1;
2404 if (params->textclass != new_class) {
2405 // try to load new_class
2406 if (textclasslist.Load(new_class)) {
2407 // successfully loaded
2409 current_view->owner()->getMiniBuffer()->
2410 Set(_("Converting document to new document class..."));
2412 int ret = cap.SwitchLayoutsBetweenClasses(
2413 current_view->buffer()->params.textclass,
2415 current_view->buffer()->paragraph);
2420 s = _("One paragraph couldn't be converted");
2423 s += _(" paragraphs couldn't be converted");
2425 WriteAlert(_("Conversion Errors!"), s,
2426 _("into chosen document class"));
2429 params->textclass = new_class;
2431 // problem changing class -- warn user and retain old style
2432 WriteAlert(_("Conversion Errors!"),
2433 _("Unable to switch to new document class."),
2434 _("Reverting to original document class."));
2435 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2439 char tmpsep = params->paragraph_separation;
2440 if (fl_get_button(fd_form_document->radio_indent))
2441 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2443 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2444 if (tmpsep != params->paragraph_separation)
2447 VSpace tmpdefskip = params->getDefSkip();
2448 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2449 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2450 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2451 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2452 case 4: params->setDefSkip(
2453 VSpace (LyXGlueLength (fl_get_input
2454 (fd_form_document->input_default_skip))));
2456 // DocumentDefskipCB assures that this never happens
2457 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2459 if (!(tmpdefskip == params->getDefSkip()))
2462 if (fl_get_button(fd_form_document->radio_columns_two))
2463 params->columns = 2;
2465 params->columns = 1;
2466 if (fl_get_button(fd_form_document->radio_sides_two))
2467 params->sides = LyXTextClass::TwoSides;
2469 params->sides = LyXTextClass::OneSide;
2471 Spacing tmpSpacing = params->spacing;
2472 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2474 lyxerr.debug() << "Spacing: SINGLE" << endl;
2475 params->spacing.set(Spacing::Single);
2478 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2479 params->spacing.set(Spacing::Onehalf);
2482 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2483 params->spacing.set(Spacing::Double);
2486 lyxerr.debug() << "Spacing: OTHER" << endl;
2487 params->spacing.set(Spacing::Other,
2488 fl_get_input(fd_form_document->input_spacing));
2491 if (tmpSpacing != params->spacing)
2494 signed char tmpchar =
2495 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2496 if (params->secnumdepth != tmpchar)
2498 params->secnumdepth = tmpchar;
2501 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2503 params->float_placement =
2504 fl_get_input(fd_form_document->input_float_placement);
2506 // More checking should be done to ensure the string doesn't have
2507 // spaces or illegal placement characters in it. (thornley)
2510 current_view->redoCurrentBuffer();
2512 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2513 current_view->buffer()->markDirty();
2516 fl_get_input(fd_form_document->input_extra);
2520 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2522 fl_hide_form(fd_form_document->form_document);
2526 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2528 DocumentCancelCB(ob, data);
2529 DocumentApplyCB(ob, data);
2533 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2536 // bullet callbacks etc. in bullet_panel.C -- ARRae
2539 /* callbacks for form form_quotes */
2541 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2543 if (!current_view->available())
2546 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2547 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2548 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2550 lga = InsetQuotes::EnglishQ;
2553 lga = InsetQuotes::SwedishQ;
2556 lga = InsetQuotes::GermanQ;
2559 lga = InsetQuotes::PolishQ;
2562 lga = InsetQuotes::FrenchQ;
2565 lga = InsetQuotes::DanishQ;
2568 current_view->buffer()->params.quotes_language = lga;
2569 if (fl_get_button(fd_form_quotes->radio_single))
2570 current_view->buffer()->
2571 params.quotes_times = InsetQuotes::SingleQ;
2573 current_view->buffer()->
2574 params.quotes_times = InsetQuotes::DoubleQ;
2578 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2580 fl_hide_form(fd_form_quotes->form_quotes);
2584 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2586 QuotesApplyCB(ob, data);
2587 QuotesCancelCB(ob, data);
2590 // this is needed for now!
2591 extern "C" void ChoiceClassCB(FL_OBJECT *, long) {}
2592 extern "C" void DocumentDefskipCB(FL_OBJECT *, long) {}
2593 extern "C" void DocumentSpacingCB(FL_OBJECT *, long) {}
2594 extern "C" void DocumentApplyCB(FL_OBJECT *, long) {}
2595 extern "C" void DocumentCancelCB(FL_OBJECT *, long) {}
2596 extern "C" void DocumentOKCB(FL_OBJECT *, long) {}
2597 extern "C" void DocumentBulletsCB(FL_OBJECT *, long) {}
2598 extern "C" void QuotesApplyCB(FL_OBJECT *, long) {}
2599 extern "C" void QuotesCancelCB(FL_OBJECT *, long) {}
2600 extern "C" void QuotesOKCB(FL_OBJECT *, long) {}
2604 /* callbacks for form form_preamble */
2606 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2608 fl_hide_form(fd_form_preamble->form_preamble);
2612 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2614 if (!current_view->available())
2617 current_view->buffer()->params.preamble =
2618 fl_get_input(fd_form_preamble->input_preamble);
2619 current_view->buffer()->markDirty();
2620 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2624 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2626 PreambleApplyCB(ob, data);
2627 PreambleCancelCB(ob, data);
2631 /* callbacks for form form_table */
2634 void TableApplyCB(FL_OBJECT *, long)
2636 if (!current_view->available())
2640 // check for tables in tables
2641 if (current_view->text->cursor.par()->table){
2642 WriteAlert(_("Impossible Operation!"),
2643 _("Cannot insert table in table."),
2648 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2650 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2651 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2654 current_view->hideCursor();
2655 current_view->beforeChange();
2656 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2658 current_view->text->SetCursorParUndo(current_view->buffer());
2659 current_view->text->FreezeUndo();
2661 current_view->text->BreakParagraph(current_view);
2662 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2664 if (current_view->text->cursor.par()->Last()) {
2665 current_view->text->CursorLeft(current_view);
2667 current_view->text->BreakParagraph(current_view);
2668 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2671 current_view->text->current_font.setLatex(LyXFont::OFF);
2672 //if (!fl_get_button(fd_form_table->check_latex)){
2673 // insert the new wysiwy table
2674 current_view->text->SetLayout(current_view, 0); // standard layout
2676 if (current_view->text->cursor.par()->footnoteflag ==
2677 LyXParagraph::NO_FOOTNOTE) {
2680 ->SetParagraph(current_view, 0, 0,
2682 VSpace (0.3 * current_view->buffer()->
2683 params.spacing.getValue(),
2685 VSpace (0.3 * current_view->buffer()->
2686 params.spacing.getValue(),
2694 ->SetParagraph(current_view, 0, 0,
2696 VSpace(VSpace::NONE),
2697 VSpace(VSpace::NONE),
2704 current_view->text->cursor.par()->table =
2705 new LyXTable(xsize, ysize);
2707 Language const * lang =
2708 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2709 LyXFont font(LyXFont::ALL_INHERIT, lang);
2710 for (int i = 0; i < xsize * ysize - 1; ++i) {
2711 current_view->text->cursor.par()
2712 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2714 current_view->text->RedoParagraph(current_view);
2716 current_view->text->UnFreezeUndo();
2718 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2719 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2720 current_view->setState();
2725 void TableCancelCB(FL_OBJECT *, long)
2727 fl_hide_form(fd_form_table->form_table);
2732 void TableOKCB(FL_OBJECT * ob, long data)
2734 TableApplyCB(ob, data);
2735 TableCancelCB(ob, data);
2741 if (fd_form_figure->form_figure->visible) {
2742 fl_raise_form(fd_form_figure->form_figure);
2744 fl_show_form(fd_form_figure->form_figure,
2745 FL_PLACE_MOUSE, FL_FULLBORDER,
2746 _("Insert Figure"));
2753 if (fd_form_table->form_table->visible) {
2754 fl_raise_form(fd_form_table->form_table);
2756 fl_show_form(fd_form_table->form_table,
2757 FL_PLACE_MOUSE, FL_FULLBORDER,
2763 /* callbacks for form form_figure */
2765 void FigureApplyCB(FL_OBJECT *, long)
2767 if (!current_view->available())
2770 Buffer * buffer = current_view->buffer();
2771 if(buffer->isReadonly()) // paranoia
2774 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2775 if (fl_get_button(fd_form_figure->radio_inline)
2777 || current_view->text->cursor.par()->table
2780 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2781 current_view->insertInset(new_inset);
2782 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2783 new_inset->Edit(current_view, 0, 0, 0);
2787 current_view->hideCursor();
2788 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2789 current_view->beforeChange();
2791 current_view->text->SetCursorParUndo(current_view->buffer());
2792 current_view->text->FreezeUndo();
2794 current_view->text->BreakParagraph(current_view);
2795 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2797 if (current_view->text->cursor.par()->Last()) {
2798 current_view->text->CursorLeft(current_view);
2800 current_view->text->BreakParagraph(current_view);
2801 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2804 // The standard layout should always be numer 0;
2805 current_view->text->SetLayout(current_view, 0);
2808 if (current_view->text->cursor.par()->footnoteflag ==
2809 LyXParagraph::NO_FOOTNOTE) {
2811 current_view->text->
2812 SetParagraph(current_view, 0, 0,
2814 VSpace (0.3 * buffer->params.spacing.getValue(),
2817 buffer->params.spacing.getValue(),
2819 LYX_ALIGN_CENTER, string(), 0);
2822 current_view->text->SetParagraph(current_view, 0, 0,
2824 VSpace(VSpace::NONE),
2825 VSpace(VSpace::NONE),
2832 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2834 Inset * new_inset = new InsetFig(100, 100, buffer);
2835 current_view->insertInset(new_inset);
2836 new_inset->Edit(current_view, 0, 0, 0);
2837 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2838 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2839 current_view->text->UnFreezeUndo();
2840 current_view->setState();
2844 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2846 fl_hide_form(fd_form_figure->form_figure);
2850 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2852 FigureApplyCB(ob, data);
2853 FigureCancelCB(ob, data);
2857 // This function runs "configure" and then rereads lyx.defaults to
2858 // reconfigure the automatic settings.
2859 void Reconfigure(BufferView * bv)
2861 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2863 // Run configure in user lyx directory
2864 Path p(user_lyxdir);
2865 Systemcalls one(Systemcalls::System,
2866 AddName(system_lyxdir, "configure"));
2868 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2869 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2870 WriteAlert(_("The system has been reconfigured."),
2871 _("You need to restart LyX to make use of any"),
2872 _("updated document class specifications."));