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"));
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,
1874 bool UpdateLayoutPreamble()
1877 if (!current_view->available())
1881 fl_set_input(fd_form_preamble->input_preamble,
1882 current_view->buffer()->params.preamble.c_str());
1884 if (current_view->buffer()->isReadonly()) {
1885 fl_deactivate_object(fd_form_preamble->input_preamble);
1886 fl_deactivate_object(fd_form_preamble->button_ok);
1887 fl_deactivate_object(fd_form_preamble->button_apply);
1888 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1889 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1892 fl_activate_object(fd_form_preamble->input_preamble);
1893 fl_activate_object(fd_form_preamble->button_ok);
1894 fl_activate_object(fd_form_preamble->button_apply);
1895 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1896 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1898 } else if (fd_form_preamble->form_preamble->visible) {
1899 fl_hide_form(fd_form_preamble->form_preamble);
1905 void MenuLayoutPreamble()
1907 static int ow = -1, oh;
1909 if (UpdateLayoutPreamble()) {
1910 if (fd_form_preamble->form_preamble->visible) {
1911 fl_raise_form(fd_form_preamble->form_preamble);
1913 fl_show_form(fd_form_preamble->form_preamble,
1914 FL_PLACE_MOUSE | FL_FREE_SIZE,
1916 _("LaTeX Preamble"));
1918 ow = fd_form_preamble->form_preamble->w;
1919 oh = fd_form_preamble->form_preamble->h;
1921 fl_set_form_minsize(fd_form_preamble->form_preamble,
1928 void MenuLayoutSave()
1930 if (!current_view->available())
1933 if (AskQuestion(_("Do you want to save the current settings"),
1934 _("for Character, Document, Paper and Quotes"),
1935 _("as default for new documents?")))
1936 current_view->buffer()->saveParamsAsDefaults();
1940 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1941 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1942 LyXFont UserFreeFont(BufferParams const & params)
1944 LyXFont font(LyXFont::ALL_IGNORE);
1946 int pos = fl_get_choice(fd_form_character->choice_family);
1948 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1949 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1950 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1951 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1952 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1955 pos = fl_get_choice(fd_form_character->choice_series);
1957 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1958 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1959 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1960 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1963 pos = fl_get_choice(fd_form_character->choice_shape);
1965 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1966 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1967 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1968 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1969 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1970 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1973 pos = fl_get_choice(fd_form_character->choice_size);
1975 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1976 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1977 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1978 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1979 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1980 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1981 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1982 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1983 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1984 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1985 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1986 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1987 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1988 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1991 pos = fl_get_choice(fd_form_character->choice_bar);
1993 case 1: font.setEmph(LyXFont::IGNORE);
1994 font.setUnderbar(LyXFont::IGNORE);
1995 font.setNoun(LyXFont::IGNORE);
1996 font.setLatex(LyXFont::IGNORE);
1998 case 2: font.setEmph(LyXFont::TOGGLE); break;
1999 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2000 case 4: font.setNoun(LyXFont::TOGGLE); break;
2001 case 5: font.setLatex(LyXFont::TOGGLE); break;
2002 case 6: font.setEmph(LyXFont::INHERIT);
2003 font.setUnderbar(LyXFont::INHERIT);
2004 font.setNoun(LyXFont::INHERIT);
2005 font.setLatex(LyXFont::INHERIT);
2009 pos = fl_get_choice(fd_form_character->choice_color);
2011 case 1: font.setColor(LColor::ignore); break;
2012 case 2: font.setColor(LColor::none); break;
2013 case 3: font.setColor(LColor::black); break;
2014 case 4: font.setColor(LColor::white); break;
2015 case 5: font.setColor(LColor::red); break;
2016 case 6: font.setColor(LColor::green); break;
2017 case 7: font.setColor(LColor::blue); break;
2018 case 8: font.setColor(LColor::cyan); break;
2019 case 9: font.setColor(LColor::magenta); break;
2020 case 10: font.setColor(LColor::yellow); break;
2021 case 11: font.setColor(LColor::inherit); break;
2024 int choice = combo_language2->get();
2026 font.setLanguage(ignore_language);
2027 else if (choice == 2)
2028 font.setLanguage(params.language_info);
2030 font.setLanguage(&languages[combo_language2->getline()]);
2036 /* callbacks for form form_title */
2037 extern "C" void TimerCB(FL_OBJECT *, long)
2039 // only if the form still exists
2040 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2041 if (fd_form_title->form_title->visible) {
2042 fl_hide_form(fd_form_title->form_title);
2044 fl_free_form(fd_form_title->form_title);
2045 fd_form_title->form_title = 0;
2050 /* callbacks for form form_paragraph */
2052 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2054 // "Synchronize" the choices and input fields, making it
2055 // impossible to commit senseless data.
2057 FD_form_paragraph const * fp = fd_form_paragraph;
2059 if (obj == fp->choice_space_above) {
2060 if (fl_get_choice (fp->choice_space_above) != 7) {
2061 fl_set_input (fp->input_space_above, "");
2062 ActivateParagraphButtons();
2064 } else if (obj == fp->choice_space_below) {
2065 if (fl_get_choice (fp->choice_space_below) != 7) {
2066 fl_set_input (fp->input_space_below, "");
2067 ActivateParagraphButtons();
2069 } else if (obj == fp->input_space_above) {
2070 string input = fl_get_input (fp->input_space_above);
2072 if (input.empty()) {
2073 fl_set_choice (fp->choice_space_above, 1);
2074 ActivateParagraphButtons();
2076 else if (isValidGlueLength (input)) {
2077 fl_set_choice (fp->choice_space_above, 7);
2078 ActivateParagraphButtons();
2081 fl_set_choice (fp->choice_space_above, 7);
2082 DeactivateParagraphButtons();
2084 } else if (obj == fp->input_space_below) {
2085 string input = fl_get_input (fp->input_space_below);
2087 if (input.empty()) {
2088 fl_set_choice (fp->choice_space_below, 1);
2089 ActivateParagraphButtons();
2091 else if (isValidGlueLength (input)) {
2092 fl_set_choice (fp->choice_space_below, 7);
2093 ActivateParagraphButtons();
2096 fl_set_choice (fp->choice_space_below, 7);
2097 DeactivateParagraphButtons();
2103 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2105 if (!current_view->available())
2108 VSpace space_top, space_bottom;
2110 string labelwidthstring;
2113 // If a vspace kind is "Length" but there's no text in
2114 // the input field, reset the kind to "None".
2115 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2116 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2117 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2119 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2120 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2121 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2124 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2125 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2126 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2127 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2128 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2129 case 1: space_top = VSpace(VSpace::NONE); break;
2130 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2131 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2132 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2133 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2134 case 6: space_top = VSpace(VSpace::VFILL); break;
2135 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2137 if (fl_get_button (fd_form_paragraph->check_space_above))
2138 space_top.setKeep (true);
2139 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2140 case 1: space_bottom = VSpace(VSpace::NONE); break;
2141 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2142 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2143 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2144 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2145 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2146 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2148 if (fl_get_button (fd_form_paragraph->check_space_below))
2149 space_bottom.setKeep (true);
2151 if (fl_get_button(fd_form_paragraph->radio_align_left))
2152 align = LYX_ALIGN_LEFT;
2153 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2154 align = LYX_ALIGN_RIGHT;
2155 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2156 align = LYX_ALIGN_CENTER;
2158 align = LYX_ALIGN_BLOCK;
2160 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2161 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2164 if (current_view->the_locking_inset)
2165 text = current_view->the_locking_inset->getLyXText(current_view);
2167 text = current_view->text;
2168 text->SetParagraph(current_view,
2178 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2179 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2183 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2185 fl_hide_form(fd_form_paragraph->form_paragraph);
2189 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2191 ParagraphApplyCB(ob, data);
2192 ParagraphCancelCB(ob, data);
2196 /* callbacks for form form_character */
2198 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2200 // we set toggleall locally here, since it should be true for
2201 // all other uses of ToggleAndShow() (JMarc)
2202 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2203 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2204 current_view->setState();
2209 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2211 fl_hide_form(fd_form_character->form_character);
2215 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2217 CharacterApplyCB(ob, data);
2218 CharacterCloseCB(ob, data);
2222 /* callbacks for form form_document */
2224 void UpdateDocumentButtons(BufferParams const & params)
2226 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2228 switch (params.sides) {
2229 case LyXTextClass::OneSide:
2230 fl_set_button(fd_form_document->radio_sides_one, 1);
2232 case LyXTextClass::TwoSides:
2233 fl_set_button(fd_form_document->radio_sides_two, 1);
2237 if (params.columns == 2)
2238 fl_set_button(fd_form_document->radio_columns_two, 1);
2240 fl_set_button(fd_form_document->radio_columns_one, 1);
2242 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2243 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2244 params.secnumdepth);
2245 fl_set_counter_value(fd_form_document->slider_tocdepth,
2250 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2252 ProhibitInput(current_view);
2253 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2254 if (AskQuestion(_("Should I set some parameters to"),
2255 fl_get_choice_text(ob),
2256 _("the defaults of this document class?"))) {
2257 BufferParams params = BufferParams();
2258 params.textclass = fl_get_choice(ob)-1;
2259 params.useClassDefaults();
2260 UpdateLayoutDocument(¶ms);
2261 UpdateDocumentButtons(params);
2264 // unable to load new style
2265 WriteAlert(_("Conversion Errors!"),
2266 _("Unable to switch to new document class."),
2267 _("Reverting to original document class."));
2268 fl_set_choice(fd_form_document->choice_class,
2269 current_view->buffer()->params.textclass + 1);
2271 AllowInput(current_view);
2275 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2277 // "Synchronize" the choice and the input field, so that it
2278 // is impossible to commit senseless data.
2279 FD_form_document const * fd = fd_form_document;
2281 if (obj == fd->choice_default_skip) {
2282 if (fl_get_choice (fd->choice_default_skip) != 4) {
2283 fl_set_input (fd->input_default_skip, "");
2284 ActivateDocumentButtons();
2286 } else if (obj == fd->input_default_skip) {
2288 char const * input = fl_get_input (fd->input_default_skip);
2291 fl_set_choice (fd->choice_default_skip, 2);
2292 ActivateDocumentButtons();
2293 } else if (isValidGlueLength (input)) {
2294 fl_set_choice (fd->choice_default_skip, 4);
2295 ActivateDocumentButtons();
2297 fl_set_choice (fd->choice_default_skip, 4);
2298 DeactivateDocumentButtons();
2304 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2306 // "Synchronize" the choice and the input field, so that it
2307 // is impossible to commit senseless data.
2308 FD_form_document const * fd = fd_form_document;
2310 if (obj == fd->choice_spacing
2311 && fl_get_choice (fd->choice_spacing) != 4) {
2312 fl_set_input(fd->input_spacing, "");
2313 } else if (obj == fd->input_spacing) {
2315 const char* input = fl_get_input (fd->input_spacing);
2318 fl_set_choice (fd->choice_spacing, 1);
2320 fl_set_choice (fd->choice_spacing, 4);
2326 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2329 BufferParams * params = &(current_view->buffer()->params);
2331 Language const * old_language = params->language_info;
2332 params->language = combo_language->getline();
2333 Languages::iterator lit = languages.find(params->language);
2335 Language const * new_language;
2336 if (lit != languages.end())
2337 new_language = &(*lit).second;
2339 new_language = default_language;
2341 if (current_view->available()) {
2342 if (old_language != new_language
2343 && old_language->RightToLeft() == new_language->RightToLeft()
2344 && !current_view->buffer()->isMultiLingual())
2345 current_view->buffer()->ChangeLanguage(old_language,
2347 if (old_language != new_language) {
2348 //current_view->buffer()->redraw();
2352 params->language_info = new_language;
2354 // If default skip is a "Length" but there's no text in the
2355 // input field, reset the kind to "Medskip", which is the default.
2356 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2357 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2358 fl_set_choice (fd_form_document->choice_default_skip, 2);
2361 /* this shouldn't be done automatically IMO. For example I write german
2362 * documents with an american keyboard very often. Matthias */
2364 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2365 fl_get_choice(fd_form_document->choice_language)); */
2367 fl_get_choice_text(fd_form_document->choice_fonts);
2369 fl_get_choice_text(fd_form_document->choice_inputenc);
2371 fl_get_choice_text(fd_form_document->choice_fontsize);
2373 fl_get_choice_text(fd_form_document->choice_pagestyle);
2374 params->graphicsDriver =
2375 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2376 params->use_amsmath =
2377 fl_get_button(fd_form_document->check_use_amsmath);
2379 if (!current_view->available())
2382 current_view->text->SetCursor(current_view,
2383 current_view->text->cursor.par(),
2384 current_view->text->cursor.pos());
2385 current_view->setState();
2387 LyXTextClassList::ClassList::size_type new_class =
2388 fl_get_choice(fd_form_document->choice_class) - 1;
2390 if (params->textclass != new_class) {
2391 // try to load new_class
2392 if (textclasslist.Load(new_class)) {
2393 // successfully loaded
2395 current_view->owner()->getMiniBuffer()->
2396 Set(_("Converting document to new document class..."));
2398 int ret = cap.SwitchLayoutsBetweenClasses(
2399 current_view->buffer()->params.textclass,
2401 current_view->buffer()->paragraph);
2406 s = _("One paragraph couldn't be converted");
2409 s += _(" paragraphs couldn't be converted");
2411 WriteAlert(_("Conversion Errors!"), s,
2412 _("into chosen document class"));
2415 params->textclass = new_class;
2417 // problem changing class -- warn user and retain old style
2418 WriteAlert(_("Conversion Errors!"),
2419 _("Unable to switch to new document class."),
2420 _("Reverting to original document class."));
2421 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2425 char tmpsep = params->paragraph_separation;
2426 if (fl_get_button(fd_form_document->radio_indent))
2427 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2429 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2430 if (tmpsep != params->paragraph_separation)
2433 VSpace tmpdefskip = params->getDefSkip();
2434 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2435 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2436 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2437 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2438 case 4: params->setDefSkip(
2439 VSpace (LyXGlueLength (fl_get_input
2440 (fd_form_document->input_default_skip))));
2442 // DocumentDefskipCB assures that this never happens
2443 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2445 if (!(tmpdefskip == params->getDefSkip()))
2448 if (fl_get_button(fd_form_document->radio_columns_two))
2449 params->columns = 2;
2451 params->columns = 1;
2452 if (fl_get_button(fd_form_document->radio_sides_two))
2453 params->sides = LyXTextClass::TwoSides;
2455 params->sides = LyXTextClass::OneSide;
2457 Spacing tmpSpacing = params->spacing;
2458 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2460 lyxerr.debug() << "Spacing: SINGLE" << endl;
2461 params->spacing.set(Spacing::Single);
2464 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2465 params->spacing.set(Spacing::Onehalf);
2468 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2469 params->spacing.set(Spacing::Double);
2472 lyxerr.debug() << "Spacing: OTHER" << endl;
2473 params->spacing.set(Spacing::Other,
2474 fl_get_input(fd_form_document->input_spacing));
2477 if (tmpSpacing != params->spacing)
2480 signed char tmpchar =
2481 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2482 if (params->secnumdepth != tmpchar)
2484 params->secnumdepth = tmpchar;
2487 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2489 params->float_placement =
2490 fl_get_input(fd_form_document->input_float_placement);
2492 // More checking should be done to ensure the string doesn't have
2493 // spaces or illegal placement characters in it. (thornley)
2496 current_view->redoCurrentBuffer();
2498 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2499 current_view->buffer()->markDirty();
2502 fl_get_input(fd_form_document->input_extra);
2506 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2508 fl_hide_form(fd_form_document->form_document);
2512 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2514 DocumentCancelCB(ob, data);
2515 DocumentApplyCB(ob, data);
2519 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2522 // 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);
2579 /* callbacks for form form_preamble */
2581 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2583 fl_hide_form(fd_form_preamble->form_preamble);
2587 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2589 if (!current_view->available())
2592 current_view->buffer()->params.preamble =
2593 fl_get_input(fd_form_preamble->input_preamble);
2594 current_view->buffer()->markDirty();
2595 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2599 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2601 PreambleApplyCB(ob, data);
2602 PreambleCancelCB(ob, data);
2606 /* callbacks for form form_table */
2609 void TableApplyCB(FL_OBJECT *, long)
2611 if (!current_view->available())
2615 // check for tables in tables
2616 if (current_view->text->cursor.par()->table){
2617 WriteAlert(_("Impossible Operation!"),
2618 _("Cannot insert table in table."),
2623 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2625 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2626 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2629 current_view->hideCursor();
2630 current_view->beforeChange();
2631 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2633 current_view->text->SetCursorParUndo(current_view->buffer());
2634 current_view->text->FreezeUndo();
2636 current_view->text->BreakParagraph(current_view);
2637 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2639 if (current_view->text->cursor.par()->Last()) {
2640 current_view->text->CursorLeft(current_view);
2642 current_view->text->BreakParagraph(current_view);
2643 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2646 current_view->text->current_font.setLatex(LyXFont::OFF);
2647 //if (!fl_get_button(fd_form_table->check_latex)){
2648 // insert the new wysiwy table
2649 current_view->text->SetLayout(current_view, 0); // standard layout
2651 if (current_view->text->cursor.par()->footnoteflag ==
2652 LyXParagraph::NO_FOOTNOTE) {
2655 ->SetParagraph(current_view, 0, 0,
2657 VSpace (0.3 * current_view->buffer()->
2658 params.spacing.getValue(),
2660 VSpace (0.3 * current_view->buffer()->
2661 params.spacing.getValue(),
2669 ->SetParagraph(current_view, 0, 0,
2671 VSpace(VSpace::NONE),
2672 VSpace(VSpace::NONE),
2679 current_view->text->cursor.par()->table =
2680 new LyXTable(xsize, ysize);
2682 Language const * lang =
2683 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2684 LyXFont font(LyXFont::ALL_INHERIT, lang);
2685 for (int i = 0; i < xsize * ysize - 1; ++i) {
2686 current_view->text->cursor.par()
2687 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2689 current_view->text->RedoParagraph(current_view);
2691 current_view->text->UnFreezeUndo();
2693 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2694 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2695 current_view->setState();
2700 void TableCancelCB(FL_OBJECT *, long)
2702 fl_hide_form(fd_form_table->form_table);
2707 void TableOKCB(FL_OBJECT * ob, long data)
2709 TableApplyCB(ob, data);
2710 TableCancelCB(ob, data);
2716 if (fd_form_figure->form_figure->visible) {
2717 fl_raise_form(fd_form_figure->form_figure);
2719 fl_show_form(fd_form_figure->form_figure,
2720 FL_PLACE_MOUSE, FL_FULLBORDER,
2721 _("Insert Figure"));
2728 if (fd_form_table->form_table->visible) {
2729 fl_raise_form(fd_form_table->form_table);
2731 fl_show_form(fd_form_table->form_table,
2732 FL_PLACE_MOUSE, FL_FULLBORDER,
2738 /* callbacks for form form_figure */
2740 void FigureApplyCB(FL_OBJECT *, long)
2742 if (!current_view->available())
2745 Buffer * buffer = current_view->buffer();
2746 if(buffer->isReadonly()) // paranoia
2749 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2750 if (fl_get_button(fd_form_figure->radio_inline)
2752 || current_view->text->cursor.par()->table
2755 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2756 current_view->insertInset(new_inset);
2757 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2758 new_inset->Edit(current_view, 0, 0, 0);
2762 current_view->hideCursor();
2763 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2764 current_view->beforeChange();
2766 current_view->text->SetCursorParUndo(current_view->buffer());
2767 current_view->text->FreezeUndo();
2769 current_view->text->BreakParagraph(current_view);
2770 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2772 if (current_view->text->cursor.par()->Last()) {
2773 current_view->text->CursorLeft(current_view);
2775 current_view->text->BreakParagraph(current_view);
2776 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2779 // The standard layout should always be numer 0;
2780 current_view->text->SetLayout(current_view, 0);
2783 if (current_view->text->cursor.par()->footnoteflag ==
2784 LyXParagraph::NO_FOOTNOTE) {
2786 current_view->text->
2787 SetParagraph(current_view, 0, 0,
2789 VSpace (0.3 * buffer->params.spacing.getValue(),
2792 buffer->params.spacing.getValue(),
2794 LYX_ALIGN_CENTER, string(), 0);
2797 current_view->text->SetParagraph(current_view, 0, 0,
2799 VSpace(VSpace::NONE),
2800 VSpace(VSpace::NONE),
2807 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2809 Inset * new_inset = new InsetFig(100, 100, buffer);
2810 current_view->insertInset(new_inset);
2811 new_inset->Edit(current_view, 0, 0, 0);
2812 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2813 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2814 current_view->text->UnFreezeUndo();
2815 current_view->setState();
2819 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2821 fl_hide_form(fd_form_figure->form_figure);
2825 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2827 FigureApplyCB(ob, data);
2828 FigureCancelCB(ob, data);
2832 // This function runs "configure" and then rereads lyx.defaults to
2833 // reconfigure the automatic settings.
2834 void Reconfigure(BufferView * bv)
2836 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2838 // Run configure in user lyx directory
2839 Path p(user_lyxdir);
2840 Systemcalls one(Systemcalls::System,
2841 AddName(system_lyxdir, "configure"));
2843 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2844 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2845 WriteAlert(_("The system has been reconfigured."),
2846 _("You need to restart LyX to make use of any"),
2847 _("updated document class specifications."));