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"
45 #include "CutAndPaste.h"
49 using std::back_inserter;
53 using std::istream_iterator;
59 extern Combox * combo_language;
60 extern Combox * combo_language2;
61 extern BufferList bufferlist;
62 extern void show_symbols_form();
63 extern FD_form_title * fd_form_title;
64 extern FD_form_paragraph * fd_form_paragraph;
65 extern FD_form_character * fd_form_character;
66 extern FD_form_document * fd_form_document;
67 extern FD_form_quotes * fd_form_quotes;
68 extern FD_form_preamble * fd_form_preamble;
69 extern FD_form_table * fd_form_table;
70 extern FD_form_figure * fd_form_figure;
71 extern FD_form_bullet * fd_form_bullet;
73 extern BufferView * current_view; // called too many times in this file...
75 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
77 extern bool send_fax(string const & fname, string const & sendcmd);
78 extern void MenuSendto();
80 extern LyXServer * lyxserver;
82 // this should be static, but I need it in buffer.C
83 bool quitting; // flag, that we are quitting the program
84 extern bool finished; // all cleanup done just let it run through now.
86 char ascii_type; /* for selection notify callbacks */
88 bool scrolling = false;
90 // This is used to make the dreaded font toggle problem hopefully go
91 // away. Definitely not the best solution, but I think it sorta works.
92 bool toggleall = true;
95 This is the inset locking stuff needed for mathed --------------------
97 an inset can simple call LockInset in it's edit call and *ONLY* in it's
99 Inset::Edit() can only be called by the main lyx module.
101 Then the inset may modify the menu's and/or iconbars.
103 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
105 During the lock, all button and keyboard events will be modified
106 and send to the inset through the following inset-features. Note that
107 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
108 to contain the code for restoring the menus and things like this.
111 virtual void InsetButtonPress(int x, int y, int button);
112 virtual void InsetButtonRelease(int x, int y, int button);
113 virtual void InsetKeyPress(XKeyEvent *ev);
114 virtual void InsetMotionNotify(int x, int y, int state);
115 virtual void InsetUnlock();
117 If a inset wishes any redraw and/or update it just has to call
119 It's is completly irrelevant, where the inset is. UpdateInset will
120 find it in any paragraph in any buffer.
121 Of course the_locking_inset and the insets in the current paragraph/buffer
122 are checked first, so no performance problem should occur.
124 Hope that's ok for the beginning, Alejandro,
125 sorry that I needed so much time,
130 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
132 /* these functions return 1 if an error occured,
134 // Now they work only for updatable insets. [Alejandro 080596]
135 //int LockInset(UpdatableInset * inset);
136 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
137 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
138 //int UnlockInset(UpdatableInset * inset);
139 //void LockedInsetStoreUndo(Undo::undo_kind kind);
141 /* this is for asyncron updating. UpdateInsetUpdateList will be called
142 automatically from LyX. Just insert the Inset into the Updatelist */
143 //void UpdateInsetUpdateList();
144 //void PutInsetIntoInsetUpdateList(Inset * inset);
146 //InsetUpdateStruct * InsetUpdateList = 0;
150 -----------------------------------------------------------------------
153 /* some function prototypes */
155 int RunLinuxDoc(BufferView *, int, string const &);
156 int RunDocBook(int, string const &);
157 bool MenuWrite(Buffer * buf);
158 bool MenuWriteAs(Buffer * buffer);
159 void MenuReload(Buffer * buf);
160 void MenuLayoutSave();
163 void ShowMessage(Buffer * buf,
165 string const & msg2 = string(),
166 string const & msg3 = string(), int delay = 6)
169 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
172 // can somebody think of something more clever? cerr?
173 cout << msg1 << msg2 << msg3 << endl;
186 // should be moved to lyxfunc.C
187 bool MenuWrite(Buffer * buffer)
190 if (!buffer->save()) {
191 string fname = buffer->fileName();
192 string s = MakeAbsPath(fname);
193 if (AskQuestion(_("Save failed. Rename and try again?"),
194 MakeDisplayPath(s, 50),
195 _("(If not, document is not saved.)"))) {
196 return MenuWriteAs(buffer);
200 lastfiles->newFile(buffer->fileName());
206 // should be moved to BufferView.C
207 // Half of this func should be in LyXView, the rest in BufferView.
208 bool MenuWriteAs(Buffer * buffer)
210 // Why do we require BufferView::text to be able to write a
211 // document? I see no point in that. (Lgb)
212 //if (!bv->text) return;
214 string fname = buffer->fileName();
215 string oldname = fname;
218 ProhibitInput(current_view);
219 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
220 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
222 if (!IsLyXFilename(fname))
225 if (buffer->isUnnamed()) {
226 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
231 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
234 OnlyFilename(fname));
236 AllowInput(current_view);
241 // Make sure the absolute filename ends with appropriate suffix
242 string s = MakeAbsPath(fname);
243 if (!IsLyXFilename(s))
246 // Same name as we have already?
248 if (!AskQuestion(_("Same name as document already has:"),
249 MakeDisplayPath(s, 50),
252 // Falls through to name change and save
254 // No, but do we have another file with this name open?
255 else if (bufferlist.exists(s)) {
256 if (AskQuestion(_("Another document with same name open!"),
257 MakeDisplayPath(s, 50),
258 _("Replace with current document?")))
260 bufferlist.close(bufferlist.getBuffer(s));
262 // Ok, change the name of the buffer, but don't save!
266 ShowMessage(buffer, _("Document renamed to '"),
267 MakeDisplayPath(s), _("', but not saved..."));
270 } // Check whether the file exists
273 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
274 MakeDisplayPath(s, 50),
279 // Ok, change the name of the buffer
282 bool unnamed = buffer->isUnnamed();
283 buffer->setUnnamed(false);
285 // Small bug: If the save fails, we have irreversible changed the name
287 // Hope this is fixed this way! (Jug)
288 if (!MenuWrite(buffer)) {
289 buffer->fileName(oldname);
290 buffer->setUnnamed(unnamed);
291 ShowMessage(buffer, _("Document could not be saved!"),
292 _("Holding the old name."), MakeDisplayPath(oldname));
295 // now remove the oldname autosave file if existant!
296 removeAutosaveFile(oldname);
301 int MenuRunLaTeX(Buffer * buffer)
305 if (buffer->isLinuxDoc())
306 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
307 else if (buffer->isLiterate())
308 ret = buffer->runLiterate();
309 else if (buffer->isDocBook())
310 ret = RunDocBook(1, buffer->fileName());
312 ret = buffer->runLaTeX();
318 s = _("One error detected");
319 t = _("You should try to fix it.");
322 s += _(" errors detected.");
323 t = _("You should try to fix them.");
325 WriteAlert(_("There were errors during the LaTeX run."), s, t);
331 int MenuBuildProg(Buffer * buffer)
335 if (buffer->isLiterate())
336 ret = buffer->buildProgram();
338 string s = _("Wrong type of document");
339 string t = _("The Build operation is not allowed in this document");
340 WriteAlert(_("There were errors during the Build process."), s, t);
348 s = _("One error detected");
349 t = _("You should try to fix it.");
352 s += _(" errors detected.");
353 t = _("You should try to fix them.");
355 WriteAlert(_("There were errors during the Build process."), s, t);
361 int MenuRunChktex(Buffer * buffer)
365 if (buffer->isSGML()) {
366 WriteAlert(_("Chktex does not work with SGML derived documents."));
369 ret = buffer->runChktex();
375 s = _("No warnings found.");
376 } else if (ret == 1) {
377 s = _("One warning found.");
378 t = _("Use 'Edit->Go to Error' to find it.");
381 s += _(" warnings found.");
382 t = _("Use 'Edit->Go to Error' to find them.");
384 WriteAlert(_("Chktex run successfully"), s, t);
386 WriteAlert(_("Error!"), _("It seems chktex does not work."));
392 int MakeLaTeXOutput(Buffer * buffer)
398 string path = OnlyPath(buffer->fileName());
399 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
400 path = buffer->tmppath;
404 ret = MenuRunLaTeX(buffer);
410 /* wait == false means don't wait for termination */
411 /* wait == true means wait for termination */
412 // The bool should be placed last on the argument line. (Lgb)
413 // Returns false if we fail.
414 bool RunScript(Buffer * buffer, bool wait,
415 string const & command,
416 string const & orgname = string(),
417 bool need_shell = true)
421 string name = orgname;
424 if (MakeLaTeXOutput(buffer) > 0)
426 /* get DVI-Filename */
428 name = ChangeExtension(buffer->getLatexName(), ".dvi");
430 path = OnlyPath(name);
431 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
432 path = buffer->tmppath;
435 // At this point we check whether the command contains the
436 // filename parameter $$FName and if that's the case we
437 // substitute the real file name otherwise the filename is
438 // simply appended. rokrau 1/12/00
441 if ( (i=command.find("$$FName")) != string::npos)
443 cmd.replace(i,7,QuoteName(name));
446 cmd = command + ' ' + QuoteName(name);
455 // OS/2 cmd.exe has another use for '&'
457 // This is not NLS safe, but it's OK, I think.
458 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
460 // COMSPEC is set, unless user unsets
461 sh = OnlyFilename(GetEnvPath("COMSPEC"));
466 if (contains(sh, "cmd.exe")
467 || contains(sh, "4os2.exe"))
468 cmd = "start /min/n " + cmd;
473 // It seems that, if wait is false, we never get back
474 // the return code of the command. This means that all
475 // the code I added in PrintApplyCB is currently
477 // CHECK What should we do here?
478 ShowMessage(buffer, _("Executing command:"), cmd);
479 result = one.startscript(Systemcalls::System, cmd);
481 ShowMessage(buffer, _("Executing command:"), cmd);
482 result = one.startscript(wait ? Systemcalls::Wait
483 : Systemcalls::DontWait, cmd);
489 // Returns false if we fail
490 bool CreatePostscript(Buffer * buffer, bool wait = false)
496 ProhibitInput(current_view);
499 if (MakeLaTeXOutput(buffer) > 0) {
500 AllowInput(current_view);
503 // Generate postscript file
504 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
510 char real_papersize = buffer->params.papersize;
511 if (real_papersize == BufferParams::PAPER_DEFAULT)
512 real_papersize = lyxrc.default_papersize;
514 switch (real_papersize) {
515 case BufferParams::PAPER_USLETTER:
518 case BufferParams::PAPER_A3PAPER:
521 case BufferParams::PAPER_A4PAPER:
524 case BufferParams::PAPER_A5PAPER:
527 case BufferParams::PAPER_B5PAPER:
530 case BufferParams::PAPER_EXECUTIVEPAPER:
533 case BufferParams::PAPER_LEGALPAPER:
536 default: /* If nothing else fits, keep an empty value... */
540 // Make postscript file.
541 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
542 command += QuoteName(psname);
543 if (buffer->params.use_geometry
544 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
545 && !lyxrc.print_paper_dimension_flag.empty()
546 && !buffer->params.paperwidth.empty()
547 && !buffer->params.paperheight.empty()) {
548 // using a custom papersize
550 command += lyxrc.print_paper_dimension_flag + ' ';
551 command += buffer->params.paperwidth + ',';
552 command += buffer->params.paperheight;
553 } else if (!paper.empty()
554 && (real_papersize != BufferParams::PAPER_USLETTER ||
555 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
556 // dvips won't accept -t letter -t landscape. In all other
557 // cases, include the paper size explicitly.
559 command += lyxrc.print_paper_flag + ' ' + paper;
561 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
563 command += lyxrc.print_landscape_flag;
565 // push directorypath, if necessary
566 string path = OnlyPath(buffer->fileName());
567 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
568 path = buffer->tmppath;
571 bool ret = RunScript(buffer, wait, command);
572 AllowInput(current_view);
577 // Returns false if we fail
578 //bool MenuPreviewPS(Buffer * buffer)
579 bool PreviewPostscript(Buffer * buffer)
585 // Generate postscript file
586 if (!CreatePostscript(buffer, true)) {
590 // Start postscript viewer
591 ProhibitInput(current_view);
592 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
594 // push directorypath, if necessary
595 string path = OnlyPath(buffer->fileName());
596 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
597 path = buffer->tmppath;
600 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
601 AllowInput(current_view);
606 void MenuFax(Buffer * buffer)
612 // Generate postscript file
613 if (!CreatePostscript(buffer, true)) {
618 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
620 string path = OnlyPath (buffer->fileName());
621 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
622 path = buffer->tmppath;
625 if (!lyxrc.fax_program.empty()) {
626 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
628 Systemcalls one(Systemcalls::System, help2);
630 send_fax(ps, lyxrc.fax_command);
634 // Returns false if we fail
635 bool PreviewDVI(Buffer * buffer)
641 string paper = lyxrc.view_dvi_paper_option;
642 if (!paper.empty()) {
644 char real_papersize = buffer->params.papersize;
645 if (real_papersize == BufferParams::PAPER_DEFAULT)
646 real_papersize = lyxrc.default_papersize;
648 switch (real_papersize) {
649 case BufferParams::PAPER_USLETTER:
652 case BufferParams::PAPER_A3PAPER:
655 case BufferParams::PAPER_A4PAPER:
658 case BufferParams::PAPER_A5PAPER:
661 case BufferParams::PAPER_B5PAPER:
664 case BufferParams::PAPER_EXECUTIVEPAPER:
665 paper += " foolscap";
667 case BufferParams::PAPER_LEGALPAPER:
670 default: /* If nothing else fits, keep the empty value */
673 if (real_papersize==' ') {
674 // if (paper.empty()) {
675 if (buffer->params.orientation
676 == BufferParams::ORIENTATION_LANDSCAPE)
677 // we HAVE to give a size when the page is in
678 // landscape, so use USletter.
679 paper = " -paper usr";
681 // paper = " -paper " + paper;
682 if (buffer->params.orientation
683 == BufferParams::ORIENTATION_LANDSCAPE)
687 // push directorypath, if necessary
688 string path = OnlyPath(buffer->fileName());
689 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
690 path = buffer->tmppath;
694 string command = lyxrc.view_dvi_command + " " + paper;
695 bool ret = RunScript(buffer, false, command);
700 bool AskOverwrite(Buffer * buffer, string const & s)
703 // be friendly if there is a gui
706 !AskQuestion(_("File already exists:"),
707 MakeDisplayPath(s, 50),
708 _("Do you want to overwrite the file?"))) {
709 ShowMessage(buffer, _("Canceled"));
717 void MenuMakeLaTeX(Buffer * buffer)
719 // Why care about this?
723 // Get LaTeX-Filename
724 string s = buffer->getLatexName(false);
726 if (!AskOverwrite(buffer, s))
729 if (buffer->isDocBook())
730 ShowMessage(buffer, _("DocBook does not have a latex backend"));
732 if (buffer->isLinuxDoc())
733 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
735 buffer->makeLaTeXFile(s, string(), true);
736 ShowMessage(buffer, _("Nice LaTeX file saved as"),
742 void MenuMakeLinuxDoc(Buffer * buffer)
745 //if (!bv->text) return;
747 if (!buffer->isLinuxDoc()) {
748 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
752 // Get LinuxDoc-Filename
753 string s = ChangeExtension(buffer->fileName(), ".sgml");
755 if (!AskOverwrite(buffer, s))
758 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
759 MakeDisplayPath(s),"'...");
761 buffer->makeLinuxDocFile(s, true);
763 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
768 void MenuMakeDocBook(Buffer * buffer)
771 //if (!bv->text) return;
773 if (!buffer->isDocBook()) {
774 WriteAlert(_("Error!"),
775 _("Document class must be docbook."));
779 // Get DocBook-Filename
780 string s = ChangeExtension(buffer->fileName(), ".sgml");
782 if (!AskOverwrite(buffer, s))
785 ShowMessage(buffer, _("Building DocBook SGML file `"),
786 MakeDisplayPath(s), "'...");
788 buffer->makeDocBookFile(s, true);
790 ShowMessage(buffer, _("DocBook SGML file save as"),
795 void MenuMakeAscii(Buffer * buffer)
798 //if (!bv->text) return;
800 /* get LaTeX-Filename */
801 string s = ChangeExtension (buffer->fileName(), ".txt");
804 if (!AskOverwrite(buffer, s))
807 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
809 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
813 void MenuMakeHTML(Buffer * buffer)
815 // First, create LaTeX file
816 MenuMakeLaTeX(buffer);
818 // And now, run the converter
819 string file = buffer->fileName();
820 Path path(OnlyPath(file));
821 // the tex file name has to be correct for
822 // latex, but the html file name can be
824 string result = ChangeExtension(file, ".html");
825 string infile = buffer->getLatexName(false);
826 string tmp = lyxrc.html_command;
827 tmp = subst(tmp, "$$FName", infile);
828 tmp = subst(tmp, "$$OutName", result);
830 int res = one.startscript(Systemcalls::System, tmp);
832 ShowMessage(buffer, _("Document exported as HTML to file `")
833 + MakeDisplayPath(result) +'\'');
835 ShowMessage(buffer, _("Unable to convert to HTML the file `")
836 + MakeDisplayPath(infile)
843 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
845 // First, create LinuxDoc file
846 MenuMakeLinuxDoc(buffer);
848 // And now, run the converter
849 string file = buffer->fileName();
851 string result = ChangeExtension(file, ".html");
852 string infile = ChangeExtension(file, ".sgml");
853 string tmp = lyxrc.linuxdoc_to_html_command;
854 tmp = subst(tmp, "$$FName", infile);
855 tmp = subst(tmp, "$$OutName", result);
857 int res = one.startscript(Systemcalls::System, tmp);
859 ShowMessage(buffer,_("Document exported as HTML to file `")
860 + MakeDisplayPath(result) +'\'');
862 ShowMessage(buffer,_("Unable to convert to HTML the file `")
863 + MakeDisplayPath(infile)
869 void MenuMakeHTML_DocBook(Buffer * buffer)
871 // First, create LaTeX file
872 MenuMakeDocBook(buffer);
874 // And now, run the converter
875 string file = buffer->fileName();
876 string result = ChangeExtension(file, ".html");
877 string infile = ChangeExtension(file, ".sgml");
878 string tmp = lyxrc.docbook_to_html_command;
879 tmp = subst(tmp, "$$FName", infile);
880 tmp = subst(tmp, "$$OutName", result);
882 int res = one.startscript(Systemcalls::System, tmp);
884 ShowMessage(buffer,_("Document exported as HTML to file `")
885 + MakeDisplayPath(result) +'\'');
887 ShowMessage(buffer,_("Unable to convert to HTML the file `")
888 + MakeDisplayPath(infile)
895 void MenuExport(Buffer * buffer, string const & extyp)
898 if (extyp == "latex") {
899 // make sure that this buffer is not linuxdoc
900 MenuMakeLaTeX(buffer);
903 else if (extyp == "linuxdoc") {
904 // make sure that this buffer is not latex
905 MenuMakeLinuxDoc(buffer);
908 else if (extyp == "docbook") {
909 // make sure that this buffer is not latex or linuxdoc
910 MenuMakeDocBook(buffer);
913 else if (extyp == "dvi") {
914 // Run LaTeX as "Update dvi..." Bernhard.
915 // We want the dvi in the current directory. This
916 // is achieved by temporarily disabling use of
917 // temp directory. As a side-effect, we get
918 // *.log and *.aux files also. (Asger)
919 bool flag = lyxrc.use_tempdir;
920 lyxrc.use_tempdir = false;
921 MenuRunLaTeX(buffer);
922 lyxrc.use_tempdir = flag;
925 else if (extyp == "postscript") {
926 // Start Print-dialog. Not as good as dvi... Bernhard.
927 //should start lyxview->getDialogs()->showPrint();
928 // to get same as before
929 // MenuPrint(buffer);
930 // Since the MenuPrint is a pop-up, we can't use
931 // the same trick as above. (Asger)
932 // MISSING: Move of ps-file :-(
933 // And MenuPrint should not be used for this at all...
936 else if (extyp == "ascii") {
937 MenuMakeAscii(buffer);
939 else if (extyp == "custom") {
943 else if (extyp == "html") {
944 if (buffer->isLinuxDoc())
945 MenuMakeHTML_LinuxDoc(buffer);
946 else if (buffer->isDocBook())
947 MenuMakeHTML_DocBook(buffer);
949 MenuMakeHTML(buffer);
952 ShowMessage(buffer, _("Unknown export type: ") + extyp);
959 lyxerr.debug() << "Running QuitLyX." << endl;
961 if (!bufferlist.QwriteAll())
964 lastfiles->writeFile(lyxrc.lastfiles);
966 // Set a flag that we do quitting from the program,
967 // so no refreshes are necessary.
970 // close buffers first
971 bufferlist.closeAll();
973 // do any other cleanup procedures now
974 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
976 DestroyLyXTmpDir(system_tempdir);
983 void AutoSave(BufferView * bv)
984 // should probably be moved into BufferList (Lgb)
985 // Perfect target for a thread...
987 if (!bv->available())
990 if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
991 // We don't save now, but we'll try again later
992 bv->owner()->resetAutosaveTimer();
996 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
998 // create autosave filename
999 string fname = OnlyPath(bv->buffer()->fileName());
1001 fname += OnlyFilename(bv->buffer()->fileName());
1004 // tmp_ret will be located (usually) in /tmp
1005 // will that be a problem?
1006 string tmp_ret = tmpnam(0);
1008 pid_t pid = fork(); // If you want to debug the autosave
1009 // you should set pid to -1, and comment out the
1011 if (pid == 0 || pid == -1) {
1012 // pid = -1 signifies that lyx was unable
1013 // to fork. But we will do the save
1015 bool failed = false;
1016 if (!tmp_ret.empty()) {
1017 bv->buffer()->writeFile(tmp_ret, 1);
1018 // assume successful write of tmp_ret
1019 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1021 // most likely couldn't move between filesystems
1022 // unless write of tmp_ret failed
1023 // so remove tmp file (if it exists)
1024 remove(tmp_ret.c_str());
1031 // failed to write/rename tmp_ret so try writing direct
1032 if (!bv->buffer()->writeFile(fname, 1)) {
1033 // It is dangerous to do this in the child,
1034 // but safe in the parent, so...
1036 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1039 if (pid == 0) { // we are the child so...
1044 bv->buffer()->markBakClean();
1045 bv->owner()->resetAutosaveTimer();
1050 // Copyright CHT Software Service GmbH
1053 // create new file with template
1056 Buffer * NewLyxFile(string const & filename)
1058 // Split argument by :
1060 string tmpname = split(filename, name, ':');
1061 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1062 if (name.length() == 1
1063 && isalpha(static_cast<unsigned char>(name[0]))
1064 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1066 name += token(tmpname, ':', 0);
1067 tmpname = split(tmpname, ':');
1070 lyxerr.debug() << "Arg is " << filename
1071 << "\nName is " << name
1072 << "\nTemplate is " << tmpname << endl;
1074 // find a free buffer
1075 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1077 lastfiles->newFile(tmpbuf->fileName());
1082 // Insert ascii file (if filename is empty, prompt for one)
1083 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1088 if (!bv->available()) return;
1090 if (fname.empty()) {
1092 fname = fileDlg.Select(_("File to Insert"),
1093 bv->owner()->buffer()->filepath,
1096 if (fname.empty()) return;
1101 if (!fi.readable()) {
1102 WriteFSAlert(_("Error! Specified file is unreadable: "),
1103 MakeDisplayPath(fname, 50));
1107 ifstream ifs(fname.c_str());
1109 WriteFSAlert(_("Error! Cannot open specified file: "),
1110 MakeDisplayPath(fname, 50));
1114 ifs.unsetf(ios::skipws);
1115 istream_iterator<char> ii(ifs);
1116 istream_iterator<char> end;
1117 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1118 // We use this until the compilers get better...
1120 copy(ii, end, back_inserter(tmp));
1121 string tmpstr(tmp.begin(), tmp.end());
1123 // This is what we want to use and what we will use once the
1124 // compilers get good enough.
1125 //string tmpstr(ii, end); // yet a reason for using std::string
1126 // alternate approach to get the file into a string:
1128 copy(ii, end, back_inserter(tmpstr));
1130 // insert the string
1131 current_view->hideCursor();
1133 // clear the selection
1136 bv->text->InsertStringA(bv, tmpstr);
1138 bv->text->InsertStringB(bv, tmpstr);
1139 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1143 void MenuInsertLabel(char const * arg)
1146 ProhibitInput(current_view);
1147 if (label.empty()) {
1149 result = askForText(_("Enter new label to insert:"));
1151 label = frontStrip(strip(result.second));
1154 if (!label.empty()) {
1155 InsetCommandParams p( "label", label );
1156 InsetLabel * inset = new InsetLabel( p );
1157 current_view->insertInset( inset );
1159 AllowInput(current_view);
1163 // candidate for move to LyXView
1164 // This is only used in toolbar.C
1165 void LayoutsCB(int sel, void *)
1167 string tmp = tostr(sel);
1168 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1174 * SGML Linuxdoc support:
1175 * (flag == 0) make TeX output
1176 * (flag == 1) make dvi output
1178 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1185 /* generate a path-less extension name */
1186 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1187 string path = OnlyPath (filename);
1188 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1189 path = bv->buffer()->tmppath;
1193 if (!bv->available())
1195 bv->buffer()->makeLinuxDocFile(name, false);
1197 // CHECK remove this once we have a proper geometry class
1199 BufferParams::PAPER_SIZE ps =
1200 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1202 case BufferParams::PAPER_A4PAPER:
1203 add_flags = "-p a4";
1205 case BufferParams::PAPER_USLETTER:
1206 add_flags = "-p letter";
1208 default: /* nothing to be done yet ;-) */ break;
1215 case 0: /* TeX output asked */
1216 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1217 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1218 if (one.startscript(Systemcalls::System, s2))
1221 case 1: /* dvi output asked */
1222 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1223 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1224 if (one.startscript(Systemcalls::System, s2)) {
1228 default: /* unknown output */
1234 bv->buffer()->redraw();
1240 * SGML DocBook support:
1241 * (flag == 1) make dvi output
1243 int RunDocBook(int flag, string const & filename)
1245 /* generate a path-less extension name */
1246 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1247 string path = OnlyPath (filename);
1248 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1249 path = current_view->buffer()->tmppath;
1253 if (!current_view->available())
1256 current_view->buffer()->makeDocBookFile(name, false);
1258 // Shall this code go or should it stay? (Lgb)
1259 // This code is a placeholder for future implementation. (Jose')
1260 // string add_flags;
1261 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1263 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1264 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1265 // default: /* nothing to be done yet ;-) */ break;
1267 ProhibitInput(current_view);
1272 case 1: /* dvi output asked */
1274 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1275 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1276 if (one.startscript(Systemcalls::System, s2)) {
1281 default: /* unknown output */
1285 AllowInput(current_view);
1287 current_view->buffer()->redraw();
1292 void MenuLayoutCharacter()
1294 static int ow = -1, oh;
1296 if (fd_form_character->form_character->visible) {
1297 fl_raise_form(fd_form_character->form_character);
1299 fl_show_form(fd_form_character->form_character,
1300 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1301 _("Character Style"));
1303 ow = fd_form_character->form_character->w;
1304 oh = fd_form_character->form_character->h;
1306 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1312 void DeactivateParagraphButtons ()
1314 fl_deactivate_object (fd_form_paragraph->button_ok);
1315 fl_deactivate_object (fd_form_paragraph->button_apply);
1316 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1317 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1322 void ActivateParagraphButtons ()
1324 fl_activate_object (fd_form_paragraph->button_ok);
1325 fl_activate_object (fd_form_paragraph->button_apply);
1326 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1327 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1332 void DisableParagraphLayout ()
1334 DeactivateParagraphButtons();
1335 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1336 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1337 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1338 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1339 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1340 fl_deactivate_object (fd_form_paragraph->check_noindent);
1341 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1342 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1343 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1344 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1345 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1346 fl_deactivate_object (fd_form_paragraph->input_space_above);
1347 fl_deactivate_object (fd_form_paragraph->input_space_below);
1348 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1349 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1350 fl_deactivate_object (fd_form_paragraph->check_space_above);
1351 fl_deactivate_object (fd_form_paragraph->check_space_below);
1356 void EnableParagraphLayout ()
1358 ActivateParagraphButtons();
1359 fl_activate_object (fd_form_paragraph->input_labelwidth);
1360 fl_activate_object (fd_form_paragraph->check_lines_top);
1361 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1362 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1363 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1364 fl_activate_object (fd_form_paragraph->check_noindent);
1365 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1366 fl_activate_object (fd_form_paragraph->radio_align_right);
1367 fl_activate_object (fd_form_paragraph->radio_align_left);
1368 fl_activate_object (fd_form_paragraph->radio_align_block);
1369 fl_activate_object (fd_form_paragraph->radio_align_center);
1370 fl_activate_object (fd_form_paragraph->input_space_above);
1371 fl_activate_object (fd_form_paragraph->input_space_below);
1372 fl_activate_object (fd_form_paragraph->choice_space_above);
1373 fl_activate_object (fd_form_paragraph->choice_space_below);
1374 fl_activate_object (fd_form_paragraph->check_space_above);
1375 fl_activate_object (fd_form_paragraph->check_space_below);
1379 bool UpdateLayoutParagraph()
1381 if (!current_view->available()) {
1382 if (fd_form_paragraph->form_paragraph->visible)
1383 fl_hide_form(fd_form_paragraph->form_paragraph);
1387 Buffer * buf = current_view->buffer();
1389 if (current_view->the_locking_inset)
1390 text = current_view->the_locking_inset->getLyXText(current_view);
1392 text = current_view->text;
1394 fl_set_input(fd_form_paragraph->input_labelwidth,
1395 text->cursor.par()->GetLabelWidthString().c_str());
1396 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1397 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1398 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1399 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1401 int align = text->cursor.par()->GetAlign();
1402 if (align == LYX_ALIGN_LAYOUT)
1403 align = textclasslist.Style(buf->params.textclass,
1404 text->cursor.par()->GetLayout()).align;
1407 case LYX_ALIGN_RIGHT:
1408 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1410 case LYX_ALIGN_LEFT:
1411 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1413 case LYX_ALIGN_CENTER:
1414 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1417 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1422 fl_set_button(fd_form_paragraph->check_lines_top,
1423 text->cursor.par()->FirstPhysicalPar()->line_top);
1425 fl_set_button(fd_form_paragraph->check_lines_bottom,
1426 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1428 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1429 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1431 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1432 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1433 fl_set_button(fd_form_paragraph->check_noindent,
1434 text->cursor.par()->FirstPhysicalPar()->noindent);
1436 fl_set_button(fd_form_paragraph->check_lines_top,
1437 text->cursor.par()->line_top);
1438 fl_set_button(fd_form_paragraph->check_lines_bottom,
1439 text->cursor.par()->line_bottom);
1440 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1441 text->cursor.par()->pagebreak_top);
1442 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1443 text->cursor.par()->pagebreak_bottom);
1444 fl_set_button(fd_form_paragraph->check_noindent,
1445 text->cursor.par()->noindent);
1447 fl_set_input (fd_form_paragraph->input_space_above, "");
1450 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1452 switch (text->cursor.par()->added_space_top.kind()) {
1456 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1458 case VSpace::DEFSKIP:
1459 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1461 case VSpace::SMALLSKIP:
1462 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1464 case VSpace::MEDSKIP:
1465 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1467 case VSpace::BIGSKIP:
1468 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1471 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1473 case VSpace::LENGTH:
1474 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1476 fl_set_input (fd_form_paragraph->input_space_above,
1477 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1479 fl_set_input (fd_form_paragraph->input_space_above,
1480 text->cursor.par()->added_space_top.length().asString().c_str());
1485 fl_set_button (fd_form_paragraph->check_space_above,
1486 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1487 fl_set_input (fd_form_paragraph->input_space_below, "");
1488 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1490 fl_set_button (fd_form_paragraph->check_space_above,
1491 text->cursor.par()->added_space_top.keep());
1492 fl_set_input (fd_form_paragraph->input_space_below, "");
1493 switch (text->cursor.par()->added_space_bottom.kind()) {
1496 fl_set_choice (fd_form_paragraph->choice_space_below,
1499 case VSpace::DEFSKIP:
1500 fl_set_choice (fd_form_paragraph->choice_space_below,
1503 case VSpace::SMALLSKIP:
1504 fl_set_choice (fd_form_paragraph->choice_space_below,
1507 case VSpace::MEDSKIP:
1508 fl_set_choice (fd_form_paragraph->choice_space_below,
1511 case VSpace::BIGSKIP:
1512 fl_set_choice (fd_form_paragraph->choice_space_below,
1516 fl_set_choice (fd_form_paragraph->choice_space_below,
1519 case VSpace::LENGTH:
1520 fl_set_choice (fd_form_paragraph->choice_space_below,
1523 fl_set_input (fd_form_paragraph->input_space_below,
1524 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1527 fl_set_button (fd_form_paragraph->check_space_below,
1528 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1530 fl_set_button(fd_form_paragraph->check_noindent,
1531 text->cursor.par()->FirstPhysicalPar()->noindent);
1533 fl_set_input (fd_form_paragraph->input_space_below,
1534 text->cursor.par()->added_space_bottom.length().asString().c_str());
1537 fl_set_button (fd_form_paragraph->check_space_below,
1538 text->cursor.par()->added_space_bottom.keep());
1540 fl_set_button(fd_form_paragraph->check_noindent,
1541 text->cursor.par()->noindent);
1543 if (current_view->buffer()->isReadonly()) {
1544 DisableParagraphLayout();
1546 EnableParagraphLayout();
1552 void MenuLayoutParagraph()
1554 if (UpdateLayoutParagraph()) {
1555 if (fd_form_paragraph->form_paragraph->visible) {
1556 fl_raise_form(fd_form_paragraph->form_paragraph);
1558 fl_show_form(fd_form_paragraph->form_paragraph,
1559 FL_PLACE_MOUSE, FL_FULLBORDER,
1560 _("Paragraph Environment"));
1565 #ifdef USE_OLD_DOCUMENT_LAYOUT
1567 void DeactivateDocumentButtons ()
1569 fl_deactivate_object (fd_form_document->button_ok);
1570 fl_deactivate_object (fd_form_document->button_apply);
1571 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1572 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1577 void ActivateDocumentButtons ()
1579 fl_activate_object (fd_form_document->button_ok);
1580 fl_activate_object (fd_form_document->button_apply);
1581 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1582 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1587 void DisableDocumentLayout ()
1589 DeactivateDocumentButtons ();
1590 fl_deactivate_object (fd_form_document->group_radio_separation);
1591 fl_deactivate_object (fd_form_document->radio_indent);
1592 fl_deactivate_object (fd_form_document->radio_skip);
1593 fl_deactivate_object (fd_form_document->choice_class);
1594 fl_deactivate_object (fd_form_document->choice_pagestyle);
1595 fl_deactivate_object (fd_form_document->choice_fonts);
1596 fl_deactivate_object (fd_form_document->choice_fontsize);
1597 fl_deactivate_object (fd_form_document->input_float_placement);
1598 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1599 fl_deactivate_object (fd_form_document->choice_inputenc);
1600 fl_deactivate_object (fd_form_document->group_radio_sides);
1601 fl_deactivate_object (fd_form_document->radio_sides_one);
1602 fl_deactivate_object (fd_form_document->radio_sides_two);
1603 fl_deactivate_object (fd_form_document->group_radio_columns);
1604 fl_deactivate_object (fd_form_document->radio_columns_one);
1605 fl_deactivate_object (fd_form_document->radio_columns_two);
1606 fl_deactivate_object (fd_form_document->input_extra);
1607 fl_deactivate_object (fd_form_document->choice_language);
1608 combo_language->deactivate();
1609 fl_deactivate_object (fd_form_document->input_default_skip);
1610 fl_deactivate_object (fd_form_document->choice_default_skip);
1611 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1612 fl_deactivate_object (fd_form_document->slider_tocdepth);
1613 fl_deactivate_object (fd_form_document->choice_spacing);
1614 fl_deactivate_object (fd_form_document->input_spacing);
1615 fl_deactivate_object (fd_form_document->check_use_amsmath);
1620 void EnableDocumentLayout ()
1622 ActivateDocumentButtons ();
1623 fl_activate_object (fd_form_document->group_radio_separation);
1624 fl_activate_object (fd_form_document->radio_indent);
1625 fl_activate_object (fd_form_document->radio_skip);
1626 fl_activate_object (fd_form_document->choice_class);
1627 fl_activate_object (fd_form_document->choice_pagestyle);
1628 fl_activate_object (fd_form_document->choice_fonts);
1629 fl_activate_object (fd_form_document->choice_fontsize);
1630 fl_activate_object (fd_form_document->input_float_placement);
1631 fl_activate_object (fd_form_document->choice_postscript_driver);
1632 fl_activate_object (fd_form_document->choice_inputenc);
1633 fl_activate_object (fd_form_document->group_radio_sides);
1634 fl_activate_object (fd_form_document->radio_sides_one);
1635 fl_activate_object (fd_form_document->radio_sides_two);
1636 fl_activate_object (fd_form_document->group_radio_columns);
1637 fl_activate_object (fd_form_document->radio_columns_one);
1638 fl_activate_object (fd_form_document->radio_columns_two);
1639 fl_activate_object (fd_form_document->input_extra);
1640 fl_activate_object (fd_form_document->choice_language);
1641 combo_language->activate();
1642 fl_activate_object (fd_form_document->input_default_skip);
1643 fl_activate_object (fd_form_document->choice_default_skip);
1644 fl_activate_object (fd_form_document->slider_secnumdepth);
1645 fl_activate_object (fd_form_document->slider_tocdepth);
1646 fl_activate_object (fd_form_document->choice_spacing);
1647 fl_activate_object (fd_form_document->input_spacing);
1648 fl_activate_object (fd_form_document->check_use_amsmath);
1652 bool UpdateLayoutDocument(BufferParams * params)
1654 if (!current_view->available()) {
1655 if (fd_form_document->form_document->visible)
1656 fl_hide_form(fd_form_document->form_document);
1661 params = ¤t_view->buffer()->params;
1662 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1664 fl_set_choice_text(fd_form_document->choice_class,
1665 textclasslist.DescOfClass(params->textclass).c_str());
1666 combo_language->select_text(params->language.c_str());
1668 fl_set_choice_text(fd_form_document->choice_fonts,
1669 params->fonts.c_str());
1670 fl_set_choice_text(fd_form_document->choice_inputenc,
1671 params->inputenc.c_str());
1672 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1673 params->graphicsDriver.c_str());
1675 // ale970405+lasgoutt970513
1676 fl_clear_choice(fd_form_document->choice_fontsize);
1677 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1678 fl_addto_choice(fd_form_document->choice_fontsize,
1679 tclass.opt_fontsize().c_str());
1680 fl_set_choice(fd_form_document->choice_fontsize,
1681 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1683 // ale970405+lasgoutt970513
1684 fl_clear_choice(fd_form_document->choice_pagestyle);
1685 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1686 fl_addto_choice(fd_form_document->choice_pagestyle,
1687 tclass.opt_pagestyle().c_str());
1689 fl_set_choice(fd_form_document->choice_pagestyle,
1690 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1692 fl_set_button(fd_form_document->radio_indent, 0);
1693 fl_set_button(fd_form_document->radio_skip, 0);
1696 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1698 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1699 fl_set_button(fd_form_document->radio_indent, 1);
1701 fl_set_button(fd_form_document->radio_skip, 1);
1703 switch (params->getDefSkip().kind()) {
1704 case VSpace::SMALLSKIP:
1705 fl_set_choice (fd_form_document->choice_default_skip, 1);
1707 case VSpace::MEDSKIP:
1708 fl_set_choice (fd_form_document->choice_default_skip, 2);
1710 case VSpace::BIGSKIP:
1711 fl_set_choice (fd_form_document->choice_default_skip, 3);
1713 case VSpace::LENGTH:
1714 fl_set_choice (fd_form_document->choice_default_skip, 4);
1715 fl_set_input (fd_form_document->input_default_skip,
1716 params->getDefSkip().asLyXCommand().c_str());
1719 fl_set_choice (fd_form_document->choice_default_skip, 2);
1723 fl_set_button(fd_form_document->radio_sides_one, 0);
1724 fl_set_button(fd_form_document->radio_sides_two, 0);
1726 switch (params->sides) {
1727 case LyXTextClass::OneSide:
1728 fl_set_button(fd_form_document->radio_sides_one, 1);
1730 case LyXTextClass::TwoSides:
1731 fl_set_button(fd_form_document->radio_sides_two, 1);
1735 fl_set_button(fd_form_document->radio_columns_one, 0);
1736 fl_set_button(fd_form_document->radio_columns_two, 0);
1738 if (params->columns == 2)
1739 fl_set_button(fd_form_document->radio_columns_two, 1);
1741 fl_set_button(fd_form_document->radio_columns_one, 1);
1743 fl_set_input(fd_form_document->input_spacing, "");
1744 switch (params->spacing.getSpace()) {
1745 case Spacing::Default: // nothing bad should happen with this
1746 case Spacing::Single:
1749 fl_set_choice(fd_form_document->choice_spacing, 1);
1752 case Spacing::Onehalf:
1755 fl_set_choice(fd_form_document->choice_spacing, 2);
1758 case Spacing::Double:
1761 fl_set_choice(fd_form_document->choice_spacing, 3);
1764 case Spacing::Other:
1766 fl_set_choice(fd_form_document->choice_spacing, 4);
1768 //sprintf(sval, "%g", params->spacing.getValue());
1770 std::ostringstream sval;
1771 sval << params->spacing.getValue(); // setw?
1772 fl_set_input(fd_form_document->input_spacing,
1773 sval.str().c_str());
1776 ostrstream sval(tval, 20);
1777 sval << params->spacing.getValue() << '\0'; // setw?
1778 fl_set_input(fd_form_document->input_spacing, sval.str());
1785 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1786 params->secnumdepth);
1787 fl_set_counter_value(fd_form_document->slider_tocdepth,
1789 if (!params->float_placement.empty()) { // buffer local (Lgb)
1790 fl_set_input(fd_form_document->input_float_placement,
1791 params->float_placement.c_str());
1793 fl_set_input(fd_form_document->input_float_placement, "");
1795 if (!params->options.empty())
1796 fl_set_input(fd_form_document->input_extra,
1797 params->options.c_str());
1799 fl_set_input(fd_form_document->input_extra, "");
1801 if (current_view->buffer()->isSGML()) {
1802 // bullets not used in SGML derived documents
1803 fl_deactivate_object(fd_form_document->button_bullets);
1804 fl_set_object_lcol(fd_form_document->button_bullets,
1807 fl_activate_object(fd_form_document->button_bullets);
1808 fl_set_object_lcol(fd_form_document->button_bullets,
1812 if (current_view->buffer()->isReadonly()) {
1813 DisableDocumentLayout();
1815 EnableDocumentLayout();
1822 void MenuLayoutDocument()
1824 if (UpdateLayoutDocument()) {
1825 if (fd_form_document->form_document->visible) {
1826 fl_raise_form(fd_form_document->form_document);
1828 fl_show_form(fd_form_document->form_document,
1829 FL_PLACE_MOUSE, FL_FULLBORDER,
1830 _("Document Layout"));
1836 bool UpdateLayoutQuotes()
1839 if (!current_view->available()
1840 || current_view->buffer()->isReadonly())
1844 fl_set_choice(fd_form_quotes->choice_quotes_language,
1845 current_view->buffer()->params.quotes_language + 1);
1846 fl_set_button(fd_form_quotes->radio_single, 0);
1847 fl_set_button(fd_form_quotes->radio_double, 0);
1849 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1850 fl_set_button(fd_form_quotes->radio_single, 1);
1852 fl_set_button(fd_form_quotes->radio_double, 1);
1853 } else if (fd_form_quotes->form_quotes->visible) {
1854 fl_hide_form(fd_form_quotes->form_quotes);
1860 void MenuLayoutQuotes()
1862 if (UpdateLayoutQuotes()) {
1863 if (fd_form_quotes->form_quotes->visible) {
1864 fl_raise_form(fd_form_quotes->form_quotes);
1866 fl_show_form(fd_form_quotes->form_quotes,
1867 FL_PLACE_MOUSE, FL_FULLBORDER,
1875 bool UpdateLayoutPreamble()
1878 if (!current_view->available())
1882 fl_set_input(fd_form_preamble->input_preamble,
1883 current_view->buffer()->params.preamble.c_str());
1885 if (current_view->buffer()->isReadonly()) {
1886 fl_deactivate_object(fd_form_preamble->input_preamble);
1887 fl_deactivate_object(fd_form_preamble->button_ok);
1888 fl_deactivate_object(fd_form_preamble->button_apply);
1889 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1890 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1893 fl_activate_object(fd_form_preamble->input_preamble);
1894 fl_activate_object(fd_form_preamble->button_ok);
1895 fl_activate_object(fd_form_preamble->button_apply);
1896 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1897 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1899 } else if (fd_form_preamble->form_preamble->visible) {
1900 fl_hide_form(fd_form_preamble->form_preamble);
1906 void MenuLayoutPreamble()
1908 static int ow = -1, oh;
1910 if (UpdateLayoutPreamble()) {
1911 if (fd_form_preamble->form_preamble->visible) {
1912 fl_raise_form(fd_form_preamble->form_preamble);
1914 fl_show_form(fd_form_preamble->form_preamble,
1915 FL_PLACE_MOUSE | FL_FREE_SIZE,
1917 _("LaTeX Preamble"));
1919 ow = fd_form_preamble->form_preamble->w;
1920 oh = fd_form_preamble->form_preamble->h;
1922 fl_set_form_minsize(fd_form_preamble->form_preamble,
1929 void MenuLayoutSave()
1931 if (!current_view->available())
1934 if (AskQuestion(_("Do you want to save the current settings"),
1935 _("for Character, Document, Paper and Quotes"),
1936 _("as default for new documents?")))
1937 current_view->buffer()->saveParamsAsDefaults();
1941 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1942 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1943 LyXFont UserFreeFont(BufferParams const & params)
1945 LyXFont font(LyXFont::ALL_IGNORE);
1947 int pos = fl_get_choice(fd_form_character->choice_family);
1949 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1950 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1951 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1952 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1953 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1956 pos = fl_get_choice(fd_form_character->choice_series);
1958 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1959 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1960 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1961 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1964 pos = fl_get_choice(fd_form_character->choice_shape);
1966 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1967 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1968 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1969 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1970 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1971 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1974 pos = fl_get_choice(fd_form_character->choice_size);
1976 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1977 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1978 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1979 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1980 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1981 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1982 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1983 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1984 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1985 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1986 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1987 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1988 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1989 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1992 pos = fl_get_choice(fd_form_character->choice_bar);
1994 case 1: font.setEmph(LyXFont::IGNORE);
1995 font.setUnderbar(LyXFont::IGNORE);
1996 font.setNoun(LyXFont::IGNORE);
1997 font.setLatex(LyXFont::IGNORE);
1999 case 2: font.setEmph(LyXFont::TOGGLE); break;
2000 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2001 case 4: font.setNoun(LyXFont::TOGGLE); break;
2002 case 5: font.setLatex(LyXFont::TOGGLE); break;
2003 case 6: font.setEmph(LyXFont::INHERIT);
2004 font.setUnderbar(LyXFont::INHERIT);
2005 font.setNoun(LyXFont::INHERIT);
2006 font.setLatex(LyXFont::INHERIT);
2010 pos = fl_get_choice(fd_form_character->choice_color);
2012 case 1: font.setColor(LColor::ignore); break;
2013 case 2: font.setColor(LColor::none); break;
2014 case 3: font.setColor(LColor::black); break;
2015 case 4: font.setColor(LColor::white); break;
2016 case 5: font.setColor(LColor::red); break;
2017 case 6: font.setColor(LColor::green); break;
2018 case 7: font.setColor(LColor::blue); break;
2019 case 8: font.setColor(LColor::cyan); break;
2020 case 9: font.setColor(LColor::magenta); break;
2021 case 10: font.setColor(LColor::yellow); break;
2022 case 11: font.setColor(LColor::inherit); break;
2025 int choice = combo_language2->get();
2027 font.setLanguage(ignore_language);
2028 else if (choice == 2)
2029 font.setLanguage(params.language_info);
2031 font.setLanguage(&languages[combo_language2->getline()]);
2037 /* callbacks for form form_title */
2038 extern "C" void TimerCB(FL_OBJECT *, long)
2040 // only if the form still exists
2041 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2042 if (fd_form_title->form_title->visible) {
2043 fl_hide_form(fd_form_title->form_title);
2045 fl_free_form(fd_form_title->form_title);
2046 fd_form_title->form_title = 0;
2051 /* callbacks for form form_paragraph */
2053 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2055 // "Synchronize" the choices and input fields, making it
2056 // impossible to commit senseless data.
2058 FD_form_paragraph const * fp = fd_form_paragraph;
2060 if (obj == fp->choice_space_above) {
2061 if (fl_get_choice (fp->choice_space_above) != 7) {
2062 fl_set_input (fp->input_space_above, "");
2063 ActivateParagraphButtons();
2065 } else if (obj == fp->choice_space_below) {
2066 if (fl_get_choice (fp->choice_space_below) != 7) {
2067 fl_set_input (fp->input_space_below, "");
2068 ActivateParagraphButtons();
2070 } else if (obj == fp->input_space_above) {
2071 string input = fl_get_input (fp->input_space_above);
2073 if (input.empty()) {
2074 fl_set_choice (fp->choice_space_above, 1);
2075 ActivateParagraphButtons();
2077 else if (isValidGlueLength (input)) {
2078 fl_set_choice (fp->choice_space_above, 7);
2079 ActivateParagraphButtons();
2082 fl_set_choice (fp->choice_space_above, 7);
2083 DeactivateParagraphButtons();
2085 } else if (obj == fp->input_space_below) {
2086 string input = fl_get_input (fp->input_space_below);
2088 if (input.empty()) {
2089 fl_set_choice (fp->choice_space_below, 1);
2090 ActivateParagraphButtons();
2092 else if (isValidGlueLength (input)) {
2093 fl_set_choice (fp->choice_space_below, 7);
2094 ActivateParagraphButtons();
2097 fl_set_choice (fp->choice_space_below, 7);
2098 DeactivateParagraphButtons();
2104 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2106 if (!current_view->available())
2109 VSpace space_top, space_bottom;
2111 string labelwidthstring;
2114 // If a vspace kind is "Length" but there's no text in
2115 // the input field, reset the kind to "None".
2116 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2117 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2118 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2120 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2121 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2122 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2125 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2126 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2127 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2128 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2129 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2130 case 1: space_top = VSpace(VSpace::NONE); break;
2131 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2132 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2133 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2134 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2135 case 6: space_top = VSpace(VSpace::VFILL); break;
2136 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2138 if (fl_get_button (fd_form_paragraph->check_space_above))
2139 space_top.setKeep (true);
2140 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2141 case 1: space_bottom = VSpace(VSpace::NONE); break;
2142 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2143 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2144 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2145 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2146 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2147 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2149 if (fl_get_button (fd_form_paragraph->check_space_below))
2150 space_bottom.setKeep (true);
2152 if (fl_get_button(fd_form_paragraph->radio_align_left))
2153 align = LYX_ALIGN_LEFT;
2154 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2155 align = LYX_ALIGN_RIGHT;
2156 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2157 align = LYX_ALIGN_CENTER;
2159 align = LYX_ALIGN_BLOCK;
2161 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2162 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2165 if (current_view->the_locking_inset)
2166 text = current_view->the_locking_inset->getLyXText(current_view);
2168 text = current_view->text;
2169 text->SetParagraph(current_view,
2179 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2180 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2184 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2186 fl_hide_form(fd_form_paragraph->form_paragraph);
2190 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2192 ParagraphApplyCB(ob, data);
2193 ParagraphCancelCB(ob, data);
2197 /* callbacks for form form_character */
2199 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2201 // we set toggleall locally here, since it should be true for
2202 // all other uses of ToggleAndShow() (JMarc)
2203 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2204 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2205 current_view->setState();
2210 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2212 fl_hide_form(fd_form_character->form_character);
2216 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2218 CharacterApplyCB(ob, data);
2219 CharacterCloseCB(ob, data);
2223 #ifdef USE_OLD_DOCUMENT_LAYOUT
2224 /* callbacks for form form_document */
2225 void UpdateDocumentButtons(BufferParams const & params)
2227 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2229 switch (params.sides) {
2230 case LyXTextClass::OneSide:
2231 fl_set_button(fd_form_document->radio_sides_one, 1);
2233 case LyXTextClass::TwoSides:
2234 fl_set_button(fd_form_document->radio_sides_two, 1);
2238 if (params.columns == 2)
2239 fl_set_button(fd_form_document->radio_columns_two, 1);
2241 fl_set_button(fd_form_document->radio_columns_one, 1);
2243 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2244 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2245 params.secnumdepth);
2246 fl_set_counter_value(fd_form_document->slider_tocdepth,
2251 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2253 ProhibitInput(current_view);
2254 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2255 if (AskQuestion(_("Should I set some parameters to"),
2256 fl_get_choice_text(ob),
2257 _("the defaults of this document class?"))) {
2258 BufferParams params = BufferParams();
2259 params.textclass = fl_get_choice(ob)-1;
2260 params.useClassDefaults();
2261 UpdateLayoutDocument(¶ms);
2262 UpdateDocumentButtons(params);
2265 // unable to load new style
2266 WriteAlert(_("Conversion Errors!"),
2267 _("Unable to switch to new document class."),
2268 _("Reverting to original document class."));
2269 fl_set_choice(fd_form_document->choice_class,
2270 current_view->buffer()->params.textclass + 1);
2272 AllowInput(current_view);
2276 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2278 // "Synchronize" the choice and the input field, so that it
2279 // is impossible to commit senseless data.
2280 FD_form_document const * fd = fd_form_document;
2282 if (obj == fd->choice_default_skip) {
2283 if (fl_get_choice (fd->choice_default_skip) != 4) {
2284 fl_set_input (fd->input_default_skip, "");
2285 ActivateDocumentButtons();
2287 } else if (obj == fd->input_default_skip) {
2289 char const * input = fl_get_input (fd->input_default_skip);
2292 fl_set_choice (fd->choice_default_skip, 2);
2293 ActivateDocumentButtons();
2294 } else if (isValidGlueLength (input)) {
2295 fl_set_choice (fd->choice_default_skip, 4);
2296 ActivateDocumentButtons();
2298 fl_set_choice (fd->choice_default_skip, 4);
2299 DeactivateDocumentButtons();
2305 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2307 // "Synchronize" the choice and the input field, so that it
2308 // is impossible to commit senseless data.
2309 FD_form_document const * fd = fd_form_document;
2311 if (obj == fd->choice_spacing
2312 && fl_get_choice (fd->choice_spacing) != 4) {
2313 fl_set_input(fd->input_spacing, "");
2314 } else if (obj == fd->input_spacing) {
2316 const char* input = fl_get_input (fd->input_spacing);
2319 fl_set_choice (fd->choice_spacing, 1);
2321 fl_set_choice (fd->choice_spacing, 4);
2327 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2330 BufferParams * params = &(current_view->buffer()->params);
2332 Language const * old_language = params->language_info;
2333 params->language = combo_language->getline();
2334 Languages::iterator lit = languages.find(params->language);
2336 Language const * new_language;
2337 if (lit != languages.end())
2338 new_language = &(*lit).second;
2340 new_language = default_language;
2342 if (current_view->available()) {
2343 if (old_language != new_language
2344 && old_language->RightToLeft() == new_language->RightToLeft()
2345 && !current_view->buffer()->isMultiLingual())
2346 current_view->buffer()->ChangeLanguage(old_language,
2348 if (old_language != new_language) {
2349 //current_view->buffer()->redraw();
2353 params->language_info = new_language;
2355 // If default skip is a "Length" but there's no text in the
2356 // input field, reset the kind to "Medskip", which is the default.
2357 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2358 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2359 fl_set_choice (fd_form_document->choice_default_skip, 2);
2362 /* this shouldn't be done automatically IMO. For example I write german
2363 * documents with an american keyboard very often. Matthias */
2365 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2366 fl_get_choice(fd_form_document->choice_language)); */
2368 fl_get_choice_text(fd_form_document->choice_fonts);
2370 fl_get_choice_text(fd_form_document->choice_inputenc);
2372 fl_get_choice_text(fd_form_document->choice_fontsize);
2374 fl_get_choice_text(fd_form_document->choice_pagestyle);
2375 params->graphicsDriver =
2376 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2377 params->use_amsmath =
2378 fl_get_button(fd_form_document->check_use_amsmath);
2380 if (!current_view->available())
2383 current_view->text->SetCursor(current_view,
2384 current_view->text->cursor.par(),
2385 current_view->text->cursor.pos());
2386 current_view->setState();
2388 LyXTextClassList::ClassList::size_type new_class =
2389 fl_get_choice(fd_form_document->choice_class) - 1;
2391 if (params->textclass != new_class) {
2392 // try to load new_class
2393 if (textclasslist.Load(new_class)) {
2394 // successfully loaded
2396 current_view->owner()->getMiniBuffer()->
2397 Set(_("Converting document to new document class..."));
2399 int ret = cap.SwitchLayoutsBetweenClasses(
2400 current_view->buffer()->params.textclass,
2402 current_view->buffer()->paragraph);
2407 s = _("One paragraph couldn't be converted");
2410 s += _(" paragraphs couldn't be converted");
2412 WriteAlert(_("Conversion Errors!"), s,
2413 _("into chosen document class"));
2416 params->textclass = new_class;
2418 // problem changing class -- warn user and retain old style
2419 WriteAlert(_("Conversion Errors!"),
2420 _("Unable to switch to new document class."),
2421 _("Reverting to original document class."));
2422 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2426 char tmpsep = params->paragraph_separation;
2427 if (fl_get_button(fd_form_document->radio_indent))
2428 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2430 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2431 if (tmpsep != params->paragraph_separation)
2434 VSpace tmpdefskip = params->getDefSkip();
2435 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2436 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2437 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2438 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2439 case 4: params->setDefSkip(
2440 VSpace (LyXGlueLength (fl_get_input
2441 (fd_form_document->input_default_skip))));
2443 // DocumentDefskipCB assures that this never happens
2444 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2446 if (!(tmpdefskip == params->getDefSkip()))
2449 if (fl_get_button(fd_form_document->radio_columns_two))
2450 params->columns = 2;
2452 params->columns = 1;
2453 if (fl_get_button(fd_form_document->radio_sides_two))
2454 params->sides = LyXTextClass::TwoSides;
2456 params->sides = LyXTextClass::OneSide;
2458 Spacing tmpSpacing = params->spacing;
2459 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2461 lyxerr.debug() << "Spacing: SINGLE" << endl;
2462 params->spacing.set(Spacing::Single);
2465 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2466 params->spacing.set(Spacing::Onehalf);
2469 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2470 params->spacing.set(Spacing::Double);
2473 lyxerr.debug() << "Spacing: OTHER" << endl;
2474 params->spacing.set(Spacing::Other,
2475 fl_get_input(fd_form_document->input_spacing));
2478 if (tmpSpacing != params->spacing)
2481 signed char tmpchar =
2482 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2483 if (params->secnumdepth != tmpchar)
2485 params->secnumdepth = tmpchar;
2488 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2490 params->float_placement =
2491 fl_get_input(fd_form_document->input_float_placement);
2493 // More checking should be done to ensure the string doesn't have
2494 // spaces or illegal placement characters in it. (thornley)
2497 current_view->redoCurrentBuffer();
2499 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2500 current_view->buffer()->markDirty();
2503 fl_get_input(fd_form_document->input_extra);
2507 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2509 fl_hide_form(fd_form_document->form_document);
2513 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2515 DocumentCancelCB(ob, data);
2516 DocumentApplyCB(ob, data);
2520 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2523 // bullet callbacks etc. in bullet_panel.C -- ARRae
2526 /* callbacks for form form_quotes */
2528 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2530 if (!current_view->available())
2533 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2534 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2535 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2537 lga = InsetQuotes::EnglishQ;
2540 lga = InsetQuotes::SwedishQ;
2543 lga = InsetQuotes::GermanQ;
2546 lga = InsetQuotes::PolishQ;
2549 lga = InsetQuotes::FrenchQ;
2552 lga = InsetQuotes::DanishQ;
2555 current_view->buffer()->params.quotes_language = lga;
2556 if (fl_get_button(fd_form_quotes->radio_single))
2557 current_view->buffer()->
2558 params.quotes_times = InsetQuotes::SingleQ;
2560 current_view->buffer()->
2561 params.quotes_times = InsetQuotes::DoubleQ;
2565 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2567 fl_hide_form(fd_form_quotes->form_quotes);
2571 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2573 QuotesApplyCB(ob, data);
2574 QuotesCancelCB(ob, data);
2577 // this is needed for now!
2578 extern "C" void ChoiceClassCB(FL_OBJECT *, long) {}
2579 extern "C" void DocumentDefskipCB(FL_OBJECT *, long) {}
2580 extern "C" void DocumentSpacingCB(FL_OBJECT *, long) {}
2581 extern "C" void DocumentApplyCB(FL_OBJECT *, long) {}
2582 extern "C" void DocumentCancelCB(FL_OBJECT *, long) {}
2583 extern "C" void DocumentOKCB(FL_OBJECT *, long) {}
2584 extern "C" void DocumentBulletsCB(FL_OBJECT *, long) {}
2585 extern "C" void QuotesApplyCB(FL_OBJECT *, long) {}
2586 extern "C" void QuotesCancelCB(FL_OBJECT *, long) {}
2587 extern "C" void QuotesOKCB(FL_OBJECT *, long) {}
2591 /* callbacks for form form_preamble */
2593 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2595 fl_hide_form(fd_form_preamble->form_preamble);
2599 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2601 if (!current_view->available())
2604 current_view->buffer()->params.preamble =
2605 fl_get_input(fd_form_preamble->input_preamble);
2606 current_view->buffer()->markDirty();
2607 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2611 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2613 PreambleApplyCB(ob, data);
2614 PreambleCancelCB(ob, data);
2618 /* callbacks for form form_table */
2621 void TableApplyCB(FL_OBJECT *, long)
2623 if (!current_view->available())
2627 // check for tables in tables
2628 if (current_view->text->cursor.par()->table){
2629 WriteAlert(_("Impossible Operation!"),
2630 _("Cannot insert table in table."),
2635 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2637 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2638 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2641 current_view->hideCursor();
2642 current_view->beforeChange();
2643 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2645 current_view->text->SetCursorParUndo(current_view->buffer());
2646 current_view->text->FreezeUndo();
2648 current_view->text->BreakParagraph(current_view);
2649 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2651 if (current_view->text->cursor.par()->Last()) {
2652 current_view->text->CursorLeft(current_view);
2654 current_view->text->BreakParagraph(current_view);
2655 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2658 current_view->text->current_font.setLatex(LyXFont::OFF);
2659 //if (!fl_get_button(fd_form_table->check_latex)){
2660 // insert the new wysiwy table
2661 current_view->text->SetLayout(current_view, 0); // standard layout
2663 if (current_view->text->cursor.par()->footnoteflag ==
2664 LyXParagraph::NO_FOOTNOTE) {
2667 ->SetParagraph(current_view, 0, 0,
2669 VSpace (0.3 * current_view->buffer()->
2670 params.spacing.getValue(),
2672 VSpace (0.3 * current_view->buffer()->
2673 params.spacing.getValue(),
2681 ->SetParagraph(current_view, 0, 0,
2683 VSpace(VSpace::NONE),
2684 VSpace(VSpace::NONE),
2691 current_view->text->cursor.par()->table =
2692 new LyXTable(xsize, ysize);
2694 Language const * lang =
2695 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2696 LyXFont font(LyXFont::ALL_INHERIT, lang);
2697 for (int i = 0; i < xsize * ysize - 1; ++i) {
2698 current_view->text->cursor.par()
2699 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2701 current_view->text->RedoParagraph(current_view);
2703 current_view->text->UnFreezeUndo();
2705 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2706 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2707 current_view->setState();
2712 void TableCancelCB(FL_OBJECT *, long)
2714 fl_hide_form(fd_form_table->form_table);
2719 void TableOKCB(FL_OBJECT * ob, long data)
2721 TableApplyCB(ob, data);
2722 TableCancelCB(ob, data);
2728 if (fd_form_figure->form_figure->visible) {
2729 fl_raise_form(fd_form_figure->form_figure);
2731 fl_show_form(fd_form_figure->form_figure,
2732 FL_PLACE_MOUSE, FL_FULLBORDER,
2733 _("Insert Figure"));
2740 if (fd_form_table->form_table->visible) {
2741 fl_raise_form(fd_form_table->form_table);
2743 fl_show_form(fd_form_table->form_table,
2744 FL_PLACE_MOUSE, FL_FULLBORDER,
2750 /* callbacks for form form_figure */
2752 void FigureApplyCB(FL_OBJECT *, long)
2754 if (!current_view->available())
2757 Buffer * buffer = current_view->buffer();
2758 if(buffer->isReadonly()) // paranoia
2761 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2762 if (fl_get_button(fd_form_figure->radio_inline)
2764 || current_view->text->cursor.par()->table
2767 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2768 current_view->insertInset(new_inset);
2769 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2770 new_inset->Edit(current_view, 0, 0, 0);
2774 current_view->hideCursor();
2775 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2776 current_view->beforeChange();
2778 current_view->text->SetCursorParUndo(current_view->buffer());
2779 current_view->text->FreezeUndo();
2781 current_view->text->BreakParagraph(current_view);
2782 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2784 if (current_view->text->cursor.par()->Last()) {
2785 current_view->text->CursorLeft(current_view);
2787 current_view->text->BreakParagraph(current_view);
2788 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2791 // The standard layout should always be numer 0;
2792 current_view->text->SetLayout(current_view, 0);
2795 if (current_view->text->cursor.par()->footnoteflag ==
2796 LyXParagraph::NO_FOOTNOTE) {
2798 current_view->text->
2799 SetParagraph(current_view, 0, 0,
2801 VSpace (0.3 * buffer->params.spacing.getValue(),
2804 buffer->params.spacing.getValue(),
2806 LYX_ALIGN_CENTER, string(), 0);
2809 current_view->text->SetParagraph(current_view, 0, 0,
2811 VSpace(VSpace::NONE),
2812 VSpace(VSpace::NONE),
2819 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2821 Inset * new_inset = new InsetFig(100, 100, buffer);
2822 current_view->insertInset(new_inset);
2823 new_inset->Edit(current_view, 0, 0, 0);
2824 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2825 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2826 current_view->text->UnFreezeUndo();
2827 current_view->setState();
2831 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2833 fl_hide_form(fd_form_figure->form_figure);
2837 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2839 FigureApplyCB(ob, data);
2840 FigureCancelCB(ob, data);
2844 // This function runs "configure" and then rereads lyx.defaults to
2845 // reconfigure the automatic settings.
2846 void Reconfigure(BufferView * bv)
2848 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2850 // Run configure in user lyx directory
2851 Path p(user_lyxdir);
2852 Systemcalls one(Systemcalls::System,
2853 AddName(system_lyxdir, "configure"));
2855 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2856 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2857 WriteAlert(_("The system has been reconfigured."),
2858 _("You need to restart LyX to make use of any"),
2859 _("updated document class specifications."));