1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
17 #include FORMS_H_LOCATION
19 #include "layout_forms.h"
20 #include "bullet_forms.h"
24 #include "insets/insetref.h"
25 #include "insets/insetlabel.h"
26 #include "insets/figinset.h"
28 #include "minibuffer.h"
30 #include "bufferlist.h"
32 #include "lyx_gui_misc.h"
34 #include "BufferView.h"
35 #include "lastfiles.h"
36 #include "bufferview_funcs.h"
37 #include "support/FileInfo.h"
38 #include "support/syscall.h"
39 #include "support/filetools.h"
40 #include "support/path.h"
41 #include "lyxserver.h"
44 #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,
166 string const & msg3, int delay)
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)
613 // Generate postscript file
614 if (!Exporter::Export(buffer, "ps", true))
618 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
621 // Generate postscript file
622 if (!CreatePostscript(buffer, true)) {
627 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
630 string path = OnlyPath (buffer->fileName());
631 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
632 path = buffer->tmppath;
635 if (!lyxrc.fax_program.empty()) {
636 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
638 Systemcalls one(Systemcalls::System, help2);
640 send_fax(ps, lyxrc.fax_command);
645 // Returns false if we fail
646 bool PreviewDVI(Buffer * buffer)
652 string paper = lyxrc.view_dvi_paper_option;
653 if (!paper.empty()) {
655 char real_papersize = buffer->params.papersize;
656 if (real_papersize == BufferParams::PAPER_DEFAULT)
657 real_papersize = lyxrc.default_papersize;
659 switch (real_papersize) {
660 case BufferParams::PAPER_USLETTER:
663 case BufferParams::PAPER_A3PAPER:
666 case BufferParams::PAPER_A4PAPER:
669 case BufferParams::PAPER_A5PAPER:
672 case BufferParams::PAPER_B5PAPER:
675 case BufferParams::PAPER_EXECUTIVEPAPER:
676 paper += " foolscap";
678 case BufferParams::PAPER_LEGALPAPER:
681 default: /* If nothing else fits, keep the empty value */
684 if (real_papersize==' ') {
685 // if (paper.empty()) {
686 if (buffer->params.orientation
687 == BufferParams::ORIENTATION_LANDSCAPE)
688 // we HAVE to give a size when the page is in
689 // landscape, so use USletter.
690 paper = " -paper usr";
692 // paper = " -paper " + paper;
693 if (buffer->params.orientation
694 == BufferParams::ORIENTATION_LANDSCAPE)
698 // push directorypath, if necessary
699 string path = OnlyPath(buffer->fileName());
700 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
701 path = buffer->tmppath;
705 string command = lyxrc.view_dvi_command + " " + paper;
706 bool ret = RunScript(buffer, false, command);
711 bool AskOverwrite(Buffer * buffer, string const & s)
714 // be friendly if there is a gui
717 !AskQuestion(_("File already exists:"),
718 MakeDisplayPath(s, 50),
719 _("Do you want to overwrite the file?"))) {
720 ShowMessage(buffer, _("Canceled"));
728 void MenuMakeLaTeX(Buffer * buffer)
730 // Why care about this?
734 // Get LaTeX-Filename
735 string s = buffer->getLatexName(false);
737 if (!AskOverwrite(buffer, s))
740 if (buffer->isDocBook())
741 ShowMessage(buffer, _("DocBook does not have a latex backend"));
743 if (buffer->isLinuxDoc())
744 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
746 buffer->makeLaTeXFile(s, string(), true);
747 ShowMessage(buffer, _("Nice LaTeX file saved as"),
753 void MenuMakeLinuxDoc(Buffer * buffer)
756 //if (!bv->text) return;
758 if (!buffer->isLinuxDoc()) {
759 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
763 // Get LinuxDoc-Filename
764 string s = ChangeExtension(buffer->fileName(), ".sgml");
766 if (!AskOverwrite(buffer, s))
769 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
770 MakeDisplayPath(s),"'...");
772 buffer->makeLinuxDocFile(s, true);
774 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
779 void MenuMakeDocBook(Buffer * buffer)
782 //if (!bv->text) return;
784 if (!buffer->isDocBook()) {
785 WriteAlert(_("Error!"),
786 _("Document class must be docbook."));
790 // Get DocBook-Filename
791 string s = ChangeExtension(buffer->fileName(), ".sgml");
793 if (!AskOverwrite(buffer, s))
796 ShowMessage(buffer, _("Building DocBook SGML file `"),
797 MakeDisplayPath(s), "'...");
799 buffer->makeDocBookFile(s, true);
801 ShowMessage(buffer, _("DocBook SGML file save as"),
806 void MenuMakeAscii(Buffer * buffer)
809 //if (!bv->text) return;
811 /* get LaTeX-Filename */
812 string s = ChangeExtension (buffer->fileName(), ".txt");
815 if (!AskOverwrite(buffer, s))
818 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
820 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
824 void MenuMakeHTML(Buffer * buffer)
826 // First, create LaTeX file
827 MenuMakeLaTeX(buffer);
829 // And now, run the converter
830 string file = buffer->fileName();
831 Path path(OnlyPath(file));
832 // the tex file name has to be correct for
833 // latex, but the html file name can be
835 string result = ChangeExtension(file, ".html");
836 string infile = buffer->getLatexName(false);
837 string tmp = lyxrc.html_command;
838 tmp = subst(tmp, "$$FName", infile);
839 tmp = subst(tmp, "$$OutName", result);
841 int res = one.startscript(Systemcalls::System, tmp);
843 ShowMessage(buffer, _("Document exported as HTML to file `")
844 + MakeDisplayPath(result) +'\'');
846 ShowMessage(buffer, _("Unable to convert to HTML the file `")
847 + MakeDisplayPath(infile)
854 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
856 // First, create LinuxDoc file
857 MenuMakeLinuxDoc(buffer);
859 // And now, run the converter
860 string file = buffer->fileName();
862 string result = ChangeExtension(file, ".html");
863 string infile = ChangeExtension(file, ".sgml");
864 string tmp = lyxrc.linuxdoc_to_html_command;
865 tmp = subst(tmp, "$$FName", infile);
866 tmp = subst(tmp, "$$OutName", result);
868 int res = one.startscript(Systemcalls::System, tmp);
870 ShowMessage(buffer,_("Document exported as HTML to file `")
871 + MakeDisplayPath(result) +'\'');
873 ShowMessage(buffer,_("Unable to convert to HTML the file `")
874 + MakeDisplayPath(infile)
880 void MenuMakeHTML_DocBook(Buffer * buffer)
882 // First, create LaTeX file
883 MenuMakeDocBook(buffer);
885 // And now, run the converter
886 string file = buffer->fileName();
887 string result = ChangeExtension(file, ".html");
888 string infile = ChangeExtension(file, ".sgml");
889 string tmp = lyxrc.docbook_to_html_command;
890 tmp = subst(tmp, "$$FName", infile);
891 tmp = subst(tmp, "$$OutName", result);
893 int res = one.startscript(Systemcalls::System, tmp);
895 ShowMessage(buffer,_("Document exported as HTML to file `")
896 + MakeDisplayPath(result) +'\'');
898 ShowMessage(buffer,_("Unable to convert to HTML the file `")
899 + MakeDisplayPath(infile)
906 void MenuExport(Buffer * buffer, string const & extyp)
909 if (extyp == "latex") {
910 // make sure that this buffer is not linuxdoc
911 MenuMakeLaTeX(buffer);
914 else if (extyp == "linuxdoc") {
915 // make sure that this buffer is not latex
916 MenuMakeLinuxDoc(buffer);
919 else if (extyp == "docbook") {
920 // make sure that this buffer is not latex or linuxdoc
921 MenuMakeDocBook(buffer);
924 else if (extyp == "dvi") {
925 // Run LaTeX as "Update dvi..." Bernhard.
926 // We want the dvi in the current directory. This
927 // is achieved by temporarily disabling use of
928 // temp directory. As a side-effect, we get
929 // *.log and *.aux files also. (Asger)
930 bool flag = lyxrc.use_tempdir;
931 lyxrc.use_tempdir = false;
932 MenuRunLaTeX(buffer);
933 lyxrc.use_tempdir = flag;
936 else if (extyp == "postscript") {
937 // Start Print-dialog. Not as good as dvi... Bernhard.
938 //should start lyxview->getDialogs()->showPrint();
939 // to get same as before
940 // MenuPrint(buffer);
941 // Since the MenuPrint is a pop-up, we can't use
942 // the same trick as above. (Asger)
943 // MISSING: Move of ps-file :-(
944 // And MenuPrint should not be used for this at all...
947 else if (extyp == "ascii") {
948 MenuMakeAscii(buffer);
950 else if (extyp == "custom") {
954 else if (extyp == "html") {
955 if (buffer->isLinuxDoc())
956 MenuMakeHTML_LinuxDoc(buffer);
957 else if (buffer->isDocBook())
958 MenuMakeHTML_DocBook(buffer);
960 MenuMakeHTML(buffer);
963 ShowMessage(buffer, _("Unknown export type: ") + extyp);
971 lyxerr.debug() << "Running QuitLyX." << endl;
973 if (!bufferlist.QwriteAll())
976 lastfiles->writeFile(lyxrc.lastfiles);
978 // Set a flag that we do quitting from the program,
979 // so no refreshes are necessary.
982 // close buffers first
983 bufferlist.closeAll();
985 // do any other cleanup procedures now
986 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
988 DestroyLyXTmpDir(system_tempdir);
995 void AutoSave(BufferView * bv)
996 // should probably be moved into BufferList (Lgb)
997 // Perfect target for a thread...
999 if (!bv->available())
1002 if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
1003 // We don't save now, but we'll try again later
1004 bv->owner()->resetAutosaveTimer();
1008 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1010 // create autosave filename
1011 string fname = OnlyPath(bv->buffer()->fileName());
1013 fname += OnlyFilename(bv->buffer()->fileName());
1016 // tmp_ret will be located (usually) in /tmp
1017 // will that be a problem?
1018 string tmp_ret = tmpnam(0);
1020 pid_t pid = fork(); // If you want to debug the autosave
1021 // you should set pid to -1, and comment out the
1023 if (pid == 0 || pid == -1) {
1024 // pid = -1 signifies that lyx was unable
1025 // to fork. But we will do the save
1027 bool failed = false;
1028 if (!tmp_ret.empty()) {
1029 bv->buffer()->writeFile(tmp_ret, 1);
1030 // assume successful write of tmp_ret
1031 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1033 // most likely couldn't move between filesystems
1034 // unless write of tmp_ret failed
1035 // so remove tmp file (if it exists)
1036 remove(tmp_ret.c_str());
1043 // failed to write/rename tmp_ret so try writing direct
1044 if (!bv->buffer()->writeFile(fname, 1)) {
1045 // It is dangerous to do this in the child,
1046 // but safe in the parent, so...
1048 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1051 if (pid == 0) { // we are the child so...
1056 bv->buffer()->markBakClean();
1057 bv->owner()->resetAutosaveTimer();
1062 // Copyright CHT Software Service GmbH
1065 // create new file with template
1068 Buffer * NewLyxFile(string const & filename)
1070 // Split argument by :
1072 string tmpname = split(filename, name, ':');
1073 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1074 if (name.length() == 1
1075 && isalpha(static_cast<unsigned char>(name[0]))
1076 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1078 name += token(tmpname, ':', 0);
1079 tmpname = split(tmpname, ':');
1082 lyxerr.debug() << "Arg is " << filename
1083 << "\nName is " << name
1084 << "\nTemplate is " << tmpname << endl;
1086 // find a free buffer
1087 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1089 lastfiles->newFile(tmpbuf->fileName());
1094 // Insert ascii file (if filename is empty, prompt for one)
1095 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1100 if (!bv->available()) return;
1102 if (fname.empty()) {
1104 fname = fileDlg.Select(_("File to Insert"),
1105 bv->owner()->buffer()->filepath,
1108 if (fname.empty()) return;
1113 if (!fi.readable()) {
1114 WriteFSAlert(_("Error! Specified file is unreadable: "),
1115 MakeDisplayPath(fname, 50));
1119 ifstream ifs(fname.c_str());
1121 WriteFSAlert(_("Error! Cannot open specified file: "),
1122 MakeDisplayPath(fname, 50));
1126 ifs.unsetf(ios::skipws);
1127 istream_iterator<char> ii(ifs);
1128 istream_iterator<char> end;
1129 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1130 // We use this until the compilers get better...
1132 copy(ii, end, back_inserter(tmp));
1133 string tmpstr(tmp.begin(), tmp.end());
1135 // This is what we want to use and what we will use once the
1136 // compilers get good enough.
1137 //string tmpstr(ii, end); // yet a reason for using std::string
1138 // alternate approach to get the file into a string:
1140 copy(ii, end, back_inserter(tmpstr));
1142 // insert the string
1143 current_view->hideCursor();
1145 // clear the selection
1148 bv->text->InsertStringA(bv, tmpstr);
1150 bv->text->InsertStringB(bv, tmpstr);
1151 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1155 void MenuInsertLabel(string const & arg)
1158 ProhibitInput(current_view);
1159 if (label.empty()) {
1161 result = askForText(_("Enter new label to insert:"));
1163 label = frontStrip(strip(result.second));
1166 if (!label.empty()) {
1167 InsetCommandParams p( "label", label );
1168 InsetLabel * inset = new InsetLabel( p );
1169 current_view->insertInset( inset );
1171 AllowInput(current_view);
1175 // candidate for move to LyXView
1176 // This is only used in toolbar.C
1177 void LayoutsCB(int sel, void *, Combox *)
1179 string tmp = tostr(sel);
1180 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1186 * SGML Linuxdoc support:
1187 * (flag == 0) make TeX output
1188 * (flag == 1) make dvi output
1190 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1197 /* generate a path-less extension name */
1198 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1199 string path = OnlyPath (filename);
1200 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1201 path = bv->buffer()->tmppath;
1205 if (!bv->available())
1207 bv->buffer()->makeLinuxDocFile(name, false);
1209 // CHECK remove this once we have a proper geometry class
1211 BufferParams::PAPER_SIZE ps =
1212 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1214 case BufferParams::PAPER_A4PAPER:
1215 add_flags = "-p a4";
1217 case BufferParams::PAPER_USLETTER:
1218 add_flags = "-p letter";
1220 default: /* nothing to be done yet ;-) */ break;
1227 case 0: /* TeX output asked */
1228 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1229 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1230 if (one.startscript(Systemcalls::System, s2))
1233 case 1: /* dvi output asked */
1234 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1235 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1236 if (one.startscript(Systemcalls::System, s2)) {
1240 default: /* unknown output */
1246 bv->buffer()->redraw();
1252 * SGML DocBook support:
1253 * (flag == 1) make dvi output
1255 int RunDocBook(int flag, string const & filename)
1257 /* generate a path-less extension name */
1258 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1259 string path = OnlyPath (filename);
1260 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1261 path = current_view->buffer()->tmppath;
1265 if (!current_view->available())
1268 current_view->buffer()->makeDocBookFile(name, false);
1270 // Shall this code go or should it stay? (Lgb)
1271 // This code is a placeholder for future implementation. (Jose')
1272 // string add_flags;
1273 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1275 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1276 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1277 // default: /* nothing to be done yet ;-) */ break;
1279 ProhibitInput(current_view);
1284 case 1: /* dvi output asked */
1286 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1287 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1288 if (one.startscript(Systemcalls::System, s2)) {
1293 default: /* unknown output */
1297 AllowInput(current_view);
1299 current_view->buffer()->redraw();
1304 void MenuLayoutCharacter()
1306 static int ow = -1, oh;
1308 if (fd_form_character->form_character->visible) {
1309 fl_raise_form(fd_form_character->form_character);
1311 fl_show_form(fd_form_character->form_character,
1312 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1313 _("Character Style"));
1315 ow = fd_form_character->form_character->w;
1316 oh = fd_form_character->form_character->h;
1318 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1324 void DeactivateParagraphButtons ()
1326 fl_deactivate_object (fd_form_paragraph->button_ok);
1327 fl_deactivate_object (fd_form_paragraph->button_apply);
1328 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1329 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1334 void ActivateParagraphButtons ()
1336 fl_activate_object (fd_form_paragraph->button_ok);
1337 fl_activate_object (fd_form_paragraph->button_apply);
1338 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1339 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1344 void DisableParagraphLayout ()
1346 DeactivateParagraphButtons();
1347 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1348 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1349 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1350 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1351 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1352 fl_deactivate_object (fd_form_paragraph->check_noindent);
1353 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1354 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1355 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1356 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1357 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1358 fl_deactivate_object (fd_form_paragraph->input_space_above);
1359 fl_deactivate_object (fd_form_paragraph->input_space_below);
1360 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1361 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1362 fl_deactivate_object (fd_form_paragraph->check_space_above);
1363 fl_deactivate_object (fd_form_paragraph->check_space_below);
1368 void EnableParagraphLayout ()
1370 ActivateParagraphButtons();
1371 fl_activate_object (fd_form_paragraph->input_labelwidth);
1372 fl_activate_object (fd_form_paragraph->check_lines_top);
1373 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1374 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1375 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1376 fl_activate_object (fd_form_paragraph->check_noindent);
1377 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1378 fl_activate_object (fd_form_paragraph->radio_align_right);
1379 fl_activate_object (fd_form_paragraph->radio_align_left);
1380 fl_activate_object (fd_form_paragraph->radio_align_block);
1381 fl_activate_object (fd_form_paragraph->radio_align_center);
1382 fl_activate_object (fd_form_paragraph->input_space_above);
1383 fl_activate_object (fd_form_paragraph->input_space_below);
1384 fl_activate_object (fd_form_paragraph->choice_space_above);
1385 fl_activate_object (fd_form_paragraph->choice_space_below);
1386 fl_activate_object (fd_form_paragraph->check_space_above);
1387 fl_activate_object (fd_form_paragraph->check_space_below);
1391 bool UpdateLayoutParagraph()
1393 if (!current_view->available()) {
1394 if (fd_form_paragraph->form_paragraph->visible)
1395 fl_hide_form(fd_form_paragraph->form_paragraph);
1399 Buffer * buf = current_view->buffer();
1401 if (current_view->the_locking_inset)
1402 text = current_view->the_locking_inset->getLyXText(current_view);
1404 text = current_view->text;
1406 fl_set_input(fd_form_paragraph->input_labelwidth,
1407 text->cursor.par()->GetLabelWidthString().c_str());
1408 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1409 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1410 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1411 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1413 int align = text->cursor.par()->GetAlign();
1414 if (align == LYX_ALIGN_LAYOUT)
1415 align = textclasslist.Style(buf->params.textclass,
1416 text->cursor.par()->GetLayout()).align;
1419 case LYX_ALIGN_RIGHT:
1420 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1422 case LYX_ALIGN_LEFT:
1423 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1425 case LYX_ALIGN_CENTER:
1426 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1429 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1434 fl_set_button(fd_form_paragraph->check_lines_top,
1435 text->cursor.par()->FirstPhysicalPar()->line_top);
1437 fl_set_button(fd_form_paragraph->check_lines_bottom,
1438 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1440 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1441 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1443 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1444 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1445 fl_set_button(fd_form_paragraph->check_noindent,
1446 text->cursor.par()->FirstPhysicalPar()->noindent);
1448 fl_set_button(fd_form_paragraph->check_lines_top,
1449 text->cursor.par()->line_top);
1450 fl_set_button(fd_form_paragraph->check_lines_bottom,
1451 text->cursor.par()->line_bottom);
1452 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1453 text->cursor.par()->pagebreak_top);
1454 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1455 text->cursor.par()->pagebreak_bottom);
1456 fl_set_button(fd_form_paragraph->check_noindent,
1457 text->cursor.par()->noindent);
1459 fl_set_input (fd_form_paragraph->input_space_above, "");
1462 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1464 switch (text->cursor.par()->added_space_top.kind()) {
1468 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1470 case VSpace::DEFSKIP:
1471 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1473 case VSpace::SMALLSKIP:
1474 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1476 case VSpace::MEDSKIP:
1477 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1479 case VSpace::BIGSKIP:
1480 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1483 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1485 case VSpace::LENGTH:
1486 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1488 fl_set_input (fd_form_paragraph->input_space_above,
1489 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1491 fl_set_input (fd_form_paragraph->input_space_above,
1492 text->cursor.par()->added_space_top.length().asString().c_str());
1497 fl_set_button (fd_form_paragraph->check_space_above,
1498 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1499 fl_set_input (fd_form_paragraph->input_space_below, "");
1500 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1502 fl_set_button (fd_form_paragraph->check_space_above,
1503 text->cursor.par()->added_space_top.keep());
1504 fl_set_input (fd_form_paragraph->input_space_below, "");
1505 switch (text->cursor.par()->added_space_bottom.kind()) {
1508 fl_set_choice (fd_form_paragraph->choice_space_below,
1511 case VSpace::DEFSKIP:
1512 fl_set_choice (fd_form_paragraph->choice_space_below,
1515 case VSpace::SMALLSKIP:
1516 fl_set_choice (fd_form_paragraph->choice_space_below,
1519 case VSpace::MEDSKIP:
1520 fl_set_choice (fd_form_paragraph->choice_space_below,
1523 case VSpace::BIGSKIP:
1524 fl_set_choice (fd_form_paragraph->choice_space_below,
1528 fl_set_choice (fd_form_paragraph->choice_space_below,
1531 case VSpace::LENGTH:
1532 fl_set_choice (fd_form_paragraph->choice_space_below,
1535 fl_set_input (fd_form_paragraph->input_space_below,
1536 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1539 fl_set_button (fd_form_paragraph->check_space_below,
1540 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1542 fl_set_button(fd_form_paragraph->check_noindent,
1543 text->cursor.par()->FirstPhysicalPar()->noindent);
1545 fl_set_input (fd_form_paragraph->input_space_below,
1546 text->cursor.par()->added_space_bottom.length().asString().c_str());
1549 fl_set_button (fd_form_paragraph->check_space_below,
1550 text->cursor.par()->added_space_bottom.keep());
1552 fl_set_button(fd_form_paragraph->check_noindent,
1553 text->cursor.par()->noindent);
1555 if (current_view->buffer()->isReadonly()) {
1556 DisableParagraphLayout();
1558 EnableParagraphLayout();
1564 void MenuLayoutParagraph()
1566 if (UpdateLayoutParagraph()) {
1567 if (fd_form_paragraph->form_paragraph->visible) {
1568 fl_raise_form(fd_form_paragraph->form_paragraph);
1570 fl_show_form(fd_form_paragraph->form_paragraph,
1571 FL_PLACE_MOUSE, FL_FULLBORDER,
1572 _("Paragraph Environment"));
1577 #ifdef USE_OLD_DOCUMENT_LAYOUT
1579 void DeactivateDocumentButtons ()
1581 fl_deactivate_object (fd_form_document->button_ok);
1582 fl_deactivate_object (fd_form_document->button_apply);
1583 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1584 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1589 void ActivateDocumentButtons ()
1591 fl_activate_object (fd_form_document->button_ok);
1592 fl_activate_object (fd_form_document->button_apply);
1593 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1594 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1599 void DisableDocumentLayout ()
1601 DeactivateDocumentButtons ();
1602 fl_deactivate_object (fd_form_document->group_radio_separation);
1603 fl_deactivate_object (fd_form_document->radio_indent);
1604 fl_deactivate_object (fd_form_document->radio_skip);
1605 fl_deactivate_object (fd_form_document->choice_class);
1606 fl_deactivate_object (fd_form_document->choice_pagestyle);
1607 fl_deactivate_object (fd_form_document->choice_fonts);
1608 fl_deactivate_object (fd_form_document->choice_fontsize);
1609 fl_deactivate_object (fd_form_document->input_float_placement);
1610 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1611 fl_deactivate_object (fd_form_document->choice_inputenc);
1612 fl_deactivate_object (fd_form_document->group_radio_sides);
1613 fl_deactivate_object (fd_form_document->radio_sides_one);
1614 fl_deactivate_object (fd_form_document->radio_sides_two);
1615 fl_deactivate_object (fd_form_document->group_radio_columns);
1616 fl_deactivate_object (fd_form_document->radio_columns_one);
1617 fl_deactivate_object (fd_form_document->radio_columns_two);
1618 fl_deactivate_object (fd_form_document->input_extra);
1619 fl_deactivate_object (fd_form_document->choice_language);
1620 combo_language->deactivate();
1621 fl_deactivate_object (fd_form_document->input_default_skip);
1622 fl_deactivate_object (fd_form_document->choice_default_skip);
1623 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1624 fl_deactivate_object (fd_form_document->slider_tocdepth);
1625 fl_deactivate_object (fd_form_document->choice_spacing);
1626 fl_deactivate_object (fd_form_document->input_spacing);
1627 fl_deactivate_object (fd_form_document->check_use_amsmath);
1632 void EnableDocumentLayout ()
1634 ActivateDocumentButtons ();
1635 fl_activate_object (fd_form_document->group_radio_separation);
1636 fl_activate_object (fd_form_document->radio_indent);
1637 fl_activate_object (fd_form_document->radio_skip);
1638 fl_activate_object (fd_form_document->choice_class);
1639 fl_activate_object (fd_form_document->choice_pagestyle);
1640 fl_activate_object (fd_form_document->choice_fonts);
1641 fl_activate_object (fd_form_document->choice_fontsize);
1642 fl_activate_object (fd_form_document->input_float_placement);
1643 fl_activate_object (fd_form_document->choice_postscript_driver);
1644 fl_activate_object (fd_form_document->choice_inputenc);
1645 fl_activate_object (fd_form_document->group_radio_sides);
1646 fl_activate_object (fd_form_document->radio_sides_one);
1647 fl_activate_object (fd_form_document->radio_sides_two);
1648 fl_activate_object (fd_form_document->group_radio_columns);
1649 fl_activate_object (fd_form_document->radio_columns_one);
1650 fl_activate_object (fd_form_document->radio_columns_two);
1651 fl_activate_object (fd_form_document->input_extra);
1652 fl_activate_object (fd_form_document->choice_language);
1653 combo_language->activate();
1654 fl_activate_object (fd_form_document->input_default_skip);
1655 fl_activate_object (fd_form_document->choice_default_skip);
1656 fl_activate_object (fd_form_document->slider_secnumdepth);
1657 fl_activate_object (fd_form_document->slider_tocdepth);
1658 fl_activate_object (fd_form_document->choice_spacing);
1659 fl_activate_object (fd_form_document->input_spacing);
1660 fl_activate_object (fd_form_document->check_use_amsmath);
1664 bool UpdateLayoutDocument(BufferParams * params)
1666 if (!current_view->available()) {
1667 if (fd_form_document->form_document->visible)
1668 fl_hide_form(fd_form_document->form_document);
1673 params = ¤t_view->buffer()->params;
1674 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1676 fl_set_choice_text(fd_form_document->choice_class,
1677 textclasslist.DescOfClass(params->textclass).c_str());
1678 combo_language->select_text(params->language.c_str());
1680 fl_set_choice_text(fd_form_document->choice_fonts,
1681 params->fonts.c_str());
1682 fl_set_choice_text(fd_form_document->choice_inputenc,
1683 params->inputenc.c_str());
1684 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1685 params->graphicsDriver.c_str());
1687 // ale970405+lasgoutt970513
1688 fl_clear_choice(fd_form_document->choice_fontsize);
1689 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1690 fl_addto_choice(fd_form_document->choice_fontsize,
1691 tclass.opt_fontsize().c_str());
1692 fl_set_choice(fd_form_document->choice_fontsize,
1693 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1695 // ale970405+lasgoutt970513
1696 fl_clear_choice(fd_form_document->choice_pagestyle);
1697 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1698 fl_addto_choice(fd_form_document->choice_pagestyle,
1699 tclass.opt_pagestyle().c_str());
1701 fl_set_choice(fd_form_document->choice_pagestyle,
1702 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1704 fl_set_button(fd_form_document->radio_indent, 0);
1705 fl_set_button(fd_form_document->radio_skip, 0);
1708 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1710 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1711 fl_set_button(fd_form_document->radio_indent, 1);
1713 fl_set_button(fd_form_document->radio_skip, 1);
1715 switch (params->getDefSkip().kind()) {
1716 case VSpace::SMALLSKIP:
1717 fl_set_choice (fd_form_document->choice_default_skip, 1);
1719 case VSpace::MEDSKIP:
1720 fl_set_choice (fd_form_document->choice_default_skip, 2);
1722 case VSpace::BIGSKIP:
1723 fl_set_choice (fd_form_document->choice_default_skip, 3);
1725 case VSpace::LENGTH:
1726 fl_set_choice (fd_form_document->choice_default_skip, 4);
1727 fl_set_input (fd_form_document->input_default_skip,
1728 params->getDefSkip().asLyXCommand().c_str());
1731 fl_set_choice (fd_form_document->choice_default_skip, 2);
1735 fl_set_button(fd_form_document->radio_sides_one, 0);
1736 fl_set_button(fd_form_document->radio_sides_two, 0);
1738 switch (params->sides) {
1739 case LyXTextClass::OneSide:
1740 fl_set_button(fd_form_document->radio_sides_one, 1);
1742 case LyXTextClass::TwoSides:
1743 fl_set_button(fd_form_document->radio_sides_two, 1);
1747 fl_set_button(fd_form_document->radio_columns_one, 0);
1748 fl_set_button(fd_form_document->radio_columns_two, 0);
1750 if (params->columns == 2)
1751 fl_set_button(fd_form_document->radio_columns_two, 1);
1753 fl_set_button(fd_form_document->radio_columns_one, 1);
1755 fl_set_input(fd_form_document->input_spacing, "");
1756 switch (params->spacing.getSpace()) {
1757 case Spacing::Default: // nothing bad should happen with this
1758 case Spacing::Single:
1761 fl_set_choice(fd_form_document->choice_spacing, 1);
1764 case Spacing::Onehalf:
1767 fl_set_choice(fd_form_document->choice_spacing, 2);
1770 case Spacing::Double:
1773 fl_set_choice(fd_form_document->choice_spacing, 3);
1776 case Spacing::Other:
1778 fl_set_choice(fd_form_document->choice_spacing, 4);
1779 std::ostringstream sval;
1780 sval << params->spacing.getValue(); // setw?
1781 fl_set_input(fd_form_document->input_spacing,
1782 sval.str().c_str());
1788 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1789 params->secnumdepth);
1790 fl_set_counter_value(fd_form_document->slider_tocdepth,
1792 if (!params->float_placement.empty()) { // buffer local (Lgb)
1793 fl_set_input(fd_form_document->input_float_placement,
1794 params->float_placement.c_str());
1796 fl_set_input(fd_form_document->input_float_placement, "");
1798 if (!params->options.empty())
1799 fl_set_input(fd_form_document->input_extra,
1800 params->options.c_str());
1802 fl_set_input(fd_form_document->input_extra, "");
1804 if (current_view->buffer()->isSGML()) {
1805 // bullets not used in SGML derived documents
1806 fl_deactivate_object(fd_form_document->button_bullets);
1807 fl_set_object_lcol(fd_form_document->button_bullets,
1810 fl_activate_object(fd_form_document->button_bullets);
1811 fl_set_object_lcol(fd_form_document->button_bullets,
1815 if (current_view->buffer()->isReadonly()) {
1816 DisableDocumentLayout();
1818 EnableDocumentLayout();
1825 void MenuLayoutDocument()
1827 if (UpdateLayoutDocument()) {
1828 if (fd_form_document->form_document->visible) {
1829 fl_raise_form(fd_form_document->form_document);
1831 fl_show_form(fd_form_document->form_document,
1832 FL_PLACE_MOUSE, FL_FULLBORDER,
1833 _("Document Layout"));
1839 bool UpdateLayoutQuotes()
1842 if (!current_view->available()
1843 || current_view->buffer()->isReadonly())
1847 fl_set_choice(fd_form_quotes->choice_quotes_language,
1848 current_view->buffer()->params.quotes_language + 1);
1849 fl_set_button(fd_form_quotes->radio_single, 0);
1850 fl_set_button(fd_form_quotes->radio_double, 0);
1852 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1853 fl_set_button(fd_form_quotes->radio_single, 1);
1855 fl_set_button(fd_form_quotes->radio_double, 1);
1856 } else if (fd_form_quotes->form_quotes->visible) {
1857 fl_hide_form(fd_form_quotes->form_quotes);
1863 void MenuLayoutQuotes()
1865 if (UpdateLayoutQuotes()) {
1866 if (fd_form_quotes->form_quotes->visible) {
1867 fl_raise_form(fd_form_quotes->form_quotes);
1869 fl_show_form(fd_form_quotes->form_quotes,
1870 FL_PLACE_MOUSE, FL_FULLBORDER,
1878 bool UpdateLayoutPreamble()
1881 if (!current_view->available())
1885 fl_set_input(fd_form_preamble->input_preamble,
1886 current_view->buffer()->params.preamble.c_str());
1888 if (current_view->buffer()->isReadonly()) {
1889 fl_deactivate_object(fd_form_preamble->input_preamble);
1890 fl_deactivate_object(fd_form_preamble->button_ok);
1891 fl_deactivate_object(fd_form_preamble->button_apply);
1892 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1893 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1896 fl_activate_object(fd_form_preamble->input_preamble);
1897 fl_activate_object(fd_form_preamble->button_ok);
1898 fl_activate_object(fd_form_preamble->button_apply);
1899 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1900 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1902 } else if (fd_form_preamble->form_preamble->visible) {
1903 fl_hide_form(fd_form_preamble->form_preamble);
1909 void MenuLayoutPreamble()
1911 static int ow = -1, oh;
1913 if (UpdateLayoutPreamble()) {
1914 if (fd_form_preamble->form_preamble->visible) {
1915 fl_raise_form(fd_form_preamble->form_preamble);
1917 fl_show_form(fd_form_preamble->form_preamble,
1918 FL_PLACE_MOUSE | FL_FREE_SIZE,
1920 _("LaTeX Preamble"));
1922 ow = fd_form_preamble->form_preamble->w;
1923 oh = fd_form_preamble->form_preamble->h;
1925 fl_set_form_minsize(fd_form_preamble->form_preamble,
1932 void MenuLayoutSave()
1934 if (!current_view->available())
1937 if (AskQuestion(_("Do you want to save the current settings"),
1938 _("for Character, Document, Paper and Quotes"),
1939 _("as default for new documents?")))
1940 current_view->buffer()->saveParamsAsDefaults();
1944 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1945 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1946 LyXFont const UserFreeFont(BufferParams const & params)
1948 LyXFont font(LyXFont::ALL_IGNORE);
1950 int pos = fl_get_choice(fd_form_character->choice_family);
1952 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1953 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1954 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1955 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1956 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1959 pos = fl_get_choice(fd_form_character->choice_series);
1961 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1962 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1963 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1964 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1967 pos = fl_get_choice(fd_form_character->choice_shape);
1969 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1970 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1971 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1972 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1973 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1974 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1977 pos = fl_get_choice(fd_form_character->choice_size);
1979 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1980 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1981 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1982 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1983 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1984 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1985 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1986 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1987 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1988 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1989 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1990 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1991 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1992 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1995 pos = fl_get_choice(fd_form_character->choice_bar);
1997 case 1: font.setEmph(LyXFont::IGNORE);
1998 font.setUnderbar(LyXFont::IGNORE);
1999 font.setNoun(LyXFont::IGNORE);
2000 font.setLatex(LyXFont::IGNORE);
2002 case 2: font.setEmph(LyXFont::TOGGLE); break;
2003 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2004 case 4: font.setNoun(LyXFont::TOGGLE); break;
2005 case 5: font.setLatex(LyXFont::TOGGLE); break;
2006 case 6: font.setEmph(LyXFont::INHERIT);
2007 font.setUnderbar(LyXFont::INHERIT);
2008 font.setNoun(LyXFont::INHERIT);
2009 font.setLatex(LyXFont::INHERIT);
2013 pos = fl_get_choice(fd_form_character->choice_color);
2015 case 1: font.setColor(LColor::ignore); break;
2016 case 2: font.setColor(LColor::none); break;
2017 case 3: font.setColor(LColor::black); break;
2018 case 4: font.setColor(LColor::white); break;
2019 case 5: font.setColor(LColor::red); break;
2020 case 6: font.setColor(LColor::green); break;
2021 case 7: font.setColor(LColor::blue); break;
2022 case 8: font.setColor(LColor::cyan); break;
2023 case 9: font.setColor(LColor::magenta); break;
2024 case 10: font.setColor(LColor::yellow); break;
2025 case 11: font.setColor(LColor::inherit); break;
2028 int choice = combo_language2->get();
2030 font.setLanguage(ignore_language);
2031 else if (choice == 2)
2032 font.setLanguage(params.language_info);
2034 font.setLanguage(&languages[combo_language2->getline()]);
2040 /* callbacks for form form_title */
2041 extern "C" void TimerCB(FL_OBJECT *, long)
2043 // only if the form still exists
2044 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2045 if (fd_form_title->form_title->visible) {
2046 fl_hide_form(fd_form_title->form_title);
2048 fl_free_form(fd_form_title->form_title);
2049 fd_form_title->form_title = 0;
2054 /* callbacks for form form_paragraph */
2056 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2058 // "Synchronize" the choices and input fields, making it
2059 // impossible to commit senseless data.
2061 FD_form_paragraph const * fp = fd_form_paragraph;
2063 if (obj == fp->choice_space_above) {
2064 if (fl_get_choice (fp->choice_space_above) != 7) {
2065 fl_set_input (fp->input_space_above, "");
2066 ActivateParagraphButtons();
2068 } else if (obj == fp->choice_space_below) {
2069 if (fl_get_choice (fp->choice_space_below) != 7) {
2070 fl_set_input (fp->input_space_below, "");
2071 ActivateParagraphButtons();
2073 } else if (obj == fp->input_space_above) {
2074 string input = fl_get_input (fp->input_space_above);
2076 if (input.empty()) {
2077 fl_set_choice (fp->choice_space_above, 1);
2078 ActivateParagraphButtons();
2080 else if (isValidGlueLength (input)) {
2081 fl_set_choice (fp->choice_space_above, 7);
2082 ActivateParagraphButtons();
2085 fl_set_choice (fp->choice_space_above, 7);
2086 DeactivateParagraphButtons();
2088 } else if (obj == fp->input_space_below) {
2089 string input = fl_get_input (fp->input_space_below);
2091 if (input.empty()) {
2092 fl_set_choice (fp->choice_space_below, 1);
2093 ActivateParagraphButtons();
2095 else if (isValidGlueLength (input)) {
2096 fl_set_choice (fp->choice_space_below, 7);
2097 ActivateParagraphButtons();
2100 fl_set_choice (fp->choice_space_below, 7);
2101 DeactivateParagraphButtons();
2107 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2109 if (!current_view->available())
2112 VSpace space_top, space_bottom;
2114 string labelwidthstring;
2117 // If a vspace kind is "Length" but there's no text in
2118 // the input field, reset the kind to "None".
2119 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2120 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2121 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2123 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2124 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2125 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2128 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2129 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2130 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2131 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2132 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2133 case 1: space_top = VSpace(VSpace::NONE); break;
2134 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2135 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2136 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2137 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2138 case 6: space_top = VSpace(VSpace::VFILL); break;
2139 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2141 if (fl_get_button (fd_form_paragraph->check_space_above))
2142 space_top.setKeep (true);
2143 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2144 case 1: space_bottom = VSpace(VSpace::NONE); break;
2145 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2146 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2147 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2148 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2149 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2150 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2152 if (fl_get_button (fd_form_paragraph->check_space_below))
2153 space_bottom.setKeep (true);
2155 if (fl_get_button(fd_form_paragraph->radio_align_left))
2156 align = LYX_ALIGN_LEFT;
2157 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2158 align = LYX_ALIGN_RIGHT;
2159 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2160 align = LYX_ALIGN_CENTER;
2162 align = LYX_ALIGN_BLOCK;
2164 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2165 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2168 if (current_view->the_locking_inset)
2169 text = current_view->the_locking_inset->getLyXText(current_view);
2171 text = current_view->text;
2172 text->SetParagraph(current_view,
2182 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2183 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2187 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2189 fl_hide_form(fd_form_paragraph->form_paragraph);
2193 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2195 ParagraphApplyCB(ob, data);
2196 ParagraphCancelCB(ob, data);
2200 /* callbacks for form form_character */
2202 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2204 // we set toggleall locally here, since it should be true for
2205 // all other uses of ToggleAndShow() (JMarc)
2206 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2207 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2208 current_view->setState();
2213 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2215 fl_hide_form(fd_form_character->form_character);
2219 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2221 CharacterApplyCB(ob, data);
2222 CharacterCloseCB(ob, data);
2226 #ifdef USE_OLD_DOCUMENT_LAYOUT
2227 /* callbacks for form form_document */
2228 void UpdateDocumentButtons(BufferParams const & params)
2230 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2232 switch (params.sides) {
2233 case LyXTextClass::OneSide:
2234 fl_set_button(fd_form_document->radio_sides_one, 1);
2236 case LyXTextClass::TwoSides:
2237 fl_set_button(fd_form_document->radio_sides_two, 1);
2241 if (params.columns == 2)
2242 fl_set_button(fd_form_document->radio_columns_two, 1);
2244 fl_set_button(fd_form_document->radio_columns_one, 1);
2246 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2247 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2248 params.secnumdepth);
2249 fl_set_counter_value(fd_form_document->slider_tocdepth,
2254 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2256 ProhibitInput(current_view);
2257 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2258 if (AskQuestion(_("Should I set some parameters to"),
2259 fl_get_choice_text(ob),
2260 _("the defaults of this document class?"))) {
2261 BufferParams params = BufferParams();
2262 params.textclass = fl_get_choice(ob)-1;
2263 params.useClassDefaults();
2264 UpdateLayoutDocument(¶ms);
2265 UpdateDocumentButtons(params);
2268 // unable to load new style
2269 WriteAlert(_("Conversion Errors!"),
2270 _("Unable to switch to new document class."),
2271 _("Reverting to original document class."));
2272 fl_set_choice(fd_form_document->choice_class,
2273 current_view->buffer()->params.textclass + 1);
2275 AllowInput(current_view);
2279 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2281 // "Synchronize" the choice and the input field, so that it
2282 // is impossible to commit senseless data.
2283 FD_form_document const * fd = fd_form_document;
2285 if (obj == fd->choice_default_skip) {
2286 if (fl_get_choice (fd->choice_default_skip) != 4) {
2287 fl_set_input (fd->input_default_skip, "");
2288 ActivateDocumentButtons();
2290 } else if (obj == fd->input_default_skip) {
2292 char const * input = fl_get_input (fd->input_default_skip);
2295 fl_set_choice (fd->choice_default_skip, 2);
2296 ActivateDocumentButtons();
2297 } else if (isValidGlueLength (input)) {
2298 fl_set_choice (fd->choice_default_skip, 4);
2299 ActivateDocumentButtons();
2301 fl_set_choice (fd->choice_default_skip, 4);
2302 DeactivateDocumentButtons();
2308 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2310 // "Synchronize" the choice and the input field, so that it
2311 // is impossible to commit senseless data.
2312 FD_form_document const * fd = fd_form_document;
2314 if (obj == fd->choice_spacing
2315 && fl_get_choice (fd->choice_spacing) != 4) {
2316 fl_set_input(fd->input_spacing, "");
2317 } else if (obj == fd->input_spacing) {
2319 const char* input = fl_get_input (fd->input_spacing);
2322 fl_set_choice (fd->choice_spacing, 1);
2324 fl_set_choice (fd->choice_spacing, 4);
2330 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2333 BufferParams * params = &(current_view->buffer()->params);
2335 Language const * old_language = params->language_info;
2336 params->language = combo_language->getline();
2337 Languages::iterator lit = languages.find(params->language);
2339 Language const * new_language;
2340 if (lit != languages.end())
2341 new_language = &(*lit).second;
2343 new_language = default_language;
2345 if (current_view->available()) {
2346 if (old_language != new_language
2347 && old_language->RightToLeft() == new_language->RightToLeft()
2348 && !current_view->buffer()->isMultiLingual())
2349 current_view->buffer()->ChangeLanguage(old_language,
2351 if (old_language != new_language) {
2352 //current_view->buffer()->redraw();
2356 params->language_info = new_language;
2358 // If default skip is a "Length" but there's no text in the
2359 // input field, reset the kind to "Medskip", which is the default.
2360 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2361 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2362 fl_set_choice (fd_form_document->choice_default_skip, 2);
2365 /* this shouldn't be done automatically IMO. For example I write german
2366 * documents with an american keyboard very often. Matthias */
2368 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2369 fl_get_choice(fd_form_document->choice_language)); */
2371 fl_get_choice_text(fd_form_document->choice_fonts);
2373 fl_get_choice_text(fd_form_document->choice_inputenc);
2375 fl_get_choice_text(fd_form_document->choice_fontsize);
2377 fl_get_choice_text(fd_form_document->choice_pagestyle);
2378 params->graphicsDriver =
2379 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2380 params->use_amsmath =
2381 fl_get_button(fd_form_document->check_use_amsmath);
2383 if (!current_view->available())
2386 current_view->text->SetCursor(current_view,
2387 current_view->text->cursor.par(),
2388 current_view->text->cursor.pos());
2389 current_view->setState();
2391 LyXTextClassList::ClassList::size_type new_class =
2392 fl_get_choice(fd_form_document->choice_class) - 1;
2394 if (params->textclass != new_class) {
2395 // try to load new_class
2396 if (textclasslist.Load(new_class)) {
2397 // successfully loaded
2399 current_view->owner()->getMiniBuffer()->
2400 Set(_("Converting document to new document class..."));
2402 int ret = cap.SwitchLayoutsBetweenClasses(
2403 current_view->buffer()->params.textclass,
2405 current_view->buffer()->paragraph);
2410 s = _("One paragraph couldn't be converted");
2413 s += _(" paragraphs couldn't be converted");
2415 WriteAlert(_("Conversion Errors!"), s,
2416 _("into chosen document class"));
2419 params->textclass = new_class;
2421 // problem changing class -- warn user and retain old style
2422 WriteAlert(_("Conversion Errors!"),
2423 _("Unable to switch to new document class."),
2424 _("Reverting to original document class."));
2425 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2429 char tmpsep = params->paragraph_separation;
2430 if (fl_get_button(fd_form_document->radio_indent))
2431 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2433 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2434 if (tmpsep != params->paragraph_separation)
2437 VSpace tmpdefskip = params->getDefSkip();
2438 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2439 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2440 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2441 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2442 case 4: params->setDefSkip(
2443 VSpace (LyXGlueLength (fl_get_input
2444 (fd_form_document->input_default_skip))));
2446 // DocumentDefskipCB assures that this never happens
2447 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2449 if (!(tmpdefskip == params->getDefSkip()))
2452 if (fl_get_button(fd_form_document->radio_columns_two))
2453 params->columns = 2;
2455 params->columns = 1;
2456 if (fl_get_button(fd_form_document->radio_sides_two))
2457 params->sides = LyXTextClass::TwoSides;
2459 params->sides = LyXTextClass::OneSide;
2461 Spacing tmpSpacing = params->spacing;
2462 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2464 lyxerr.debug() << "Spacing: SINGLE" << endl;
2465 params->spacing.set(Spacing::Single);
2468 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2469 params->spacing.set(Spacing::Onehalf);
2472 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2473 params->spacing.set(Spacing::Double);
2476 lyxerr.debug() << "Spacing: OTHER" << endl;
2477 params->spacing.set(Spacing::Other,
2478 fl_get_input(fd_form_document->input_spacing));
2481 if (tmpSpacing != params->spacing)
2484 signed char tmpchar =
2485 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2486 if (params->secnumdepth != tmpchar)
2488 params->secnumdepth = tmpchar;
2491 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2493 params->float_placement =
2494 fl_get_input(fd_form_document->input_float_placement);
2496 // More checking should be done to ensure the string doesn't have
2497 // spaces or illegal placement characters in it. (thornley)
2500 current_view->redoCurrentBuffer();
2502 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2503 current_view->buffer()->markDirty();
2506 fl_get_input(fd_form_document->input_extra);
2510 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2512 fl_hide_form(fd_form_document->form_document);
2516 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2518 DocumentCancelCB(ob, data);
2519 DocumentApplyCB(ob, data);
2523 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2526 // bullet callbacks etc. in bullet_panel.C -- ARRae
2529 /* callbacks for form form_quotes */
2531 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2533 if (!current_view->available())
2536 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2537 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2538 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2540 lga = InsetQuotes::EnglishQ;
2543 lga = InsetQuotes::SwedishQ;
2546 lga = InsetQuotes::GermanQ;
2549 lga = InsetQuotes::PolishQ;
2552 lga = InsetQuotes::FrenchQ;
2555 lga = InsetQuotes::DanishQ;
2558 current_view->buffer()->params.quotes_language = lga;
2559 if (fl_get_button(fd_form_quotes->radio_single))
2560 current_view->buffer()->
2561 params.quotes_times = InsetQuotes::SingleQ;
2563 current_view->buffer()->
2564 params.quotes_times = InsetQuotes::DoubleQ;
2568 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2570 fl_hide_form(fd_form_quotes->form_quotes);
2574 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2576 QuotesApplyCB(ob, data);
2577 QuotesCancelCB(ob, data);
2580 // this is needed for now!
2581 extern "C" void ChoiceClassCB(FL_OBJECT *, long) {}
2582 extern "C" void DocumentDefskipCB(FL_OBJECT *, long) {}
2583 extern "C" void DocumentSpacingCB(FL_OBJECT *, long) {}
2584 extern "C" void DocumentApplyCB(FL_OBJECT *, long) {}
2585 extern "C" void DocumentCancelCB(FL_OBJECT *, long) {}
2586 extern "C" void DocumentOKCB(FL_OBJECT *, long) {}
2587 extern "C" void DocumentBulletsCB(FL_OBJECT *, long) {}
2588 extern "C" void QuotesApplyCB(FL_OBJECT *, long) {}
2589 extern "C" void QuotesCancelCB(FL_OBJECT *, long) {}
2590 extern "C" void QuotesOKCB(FL_OBJECT *, long) {}
2594 /* callbacks for form form_preamble */
2596 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2598 fl_hide_form(fd_form_preamble->form_preamble);
2602 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2604 if (!current_view->available())
2607 current_view->buffer()->params.preamble =
2608 fl_get_input(fd_form_preamble->input_preamble);
2609 current_view->buffer()->markDirty();
2610 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2614 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2616 PreambleApplyCB(ob, data);
2617 PreambleCancelCB(ob, data);
2621 /* callbacks for form form_table */
2624 void TableApplyCB(FL_OBJECT *, long)
2626 if (!current_view->available())
2629 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2631 int const ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2632 int const xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2635 current_view->hideCursor();
2636 current_view->beforeChange();
2637 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2639 current_view->text->SetCursorParUndo(current_view->buffer());
2640 current_view->text->FreezeUndo();
2642 current_view->text->BreakParagraph(current_view);
2643 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2645 if (current_view->text->cursor.par()->Last()) {
2646 current_view->text->CursorLeft(current_view);
2648 current_view->text->BreakParagraph(current_view);
2649 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2652 current_view->text->current_font.setLatex(LyXFont::OFF);
2653 //if (!fl_get_button(fd_form_table->check_latex)){
2654 // insert the new wysiwy table
2655 current_view->text->SetLayout(current_view, 0); // standard layout
2657 if (current_view->text->cursor.par()->footnoteflag ==
2658 LyXParagraph::NO_FOOTNOTE) {
2661 ->SetParagraph(current_view, 0, 0,
2663 VSpace (0.3 * current_view->buffer()->
2664 params.spacing.getValue(),
2666 VSpace (0.3 * current_view->buffer()->
2667 params.spacing.getValue(),
2675 ->SetParagraph(current_view, 0, 0,
2677 VSpace(VSpace::NONE),
2678 VSpace(VSpace::NONE),
2684 Language const * lang =
2685 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2686 LyXFont font(LyXFont::ALL_INHERIT, lang);
2687 for (int i = 0; i < xsize * ysize - 1; ++i) {
2688 current_view->text->cursor.par()
2689 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2691 current_view->text->RedoParagraph(current_view);
2693 current_view->text->UnFreezeUndo();
2695 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2696 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2697 current_view->setState();
2702 void TableCancelCB(FL_OBJECT *, long)
2704 fl_hide_form(fd_form_table->form_table);
2709 void TableOKCB(FL_OBJECT * ob, long data)
2711 TableApplyCB(ob, data);
2712 TableCancelCB(ob, data);
2718 if (fd_form_figure->form_figure->visible) {
2719 fl_raise_form(fd_form_figure->form_figure);
2721 fl_show_form(fd_form_figure->form_figure,
2722 FL_PLACE_MOUSE, FL_FULLBORDER,
2723 _("Insert Figure"));
2730 if (fd_form_table->form_table->visible) {
2731 fl_raise_form(fd_form_table->form_table);
2733 fl_show_form(fd_form_table->form_table,
2734 FL_PLACE_MOUSE, FL_FULLBORDER,
2740 /* callbacks for form form_figure */
2742 void FigureApplyCB(FL_OBJECT *, long)
2744 if (!current_view->available())
2747 Buffer * buffer = current_view->buffer();
2748 if(buffer->isReadonly()) // paranoia
2751 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2752 if (fl_get_button(fd_form_figure->radio_inline)) {
2753 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2754 current_view->insertInset(new_inset);
2755 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2756 new_inset->Edit(current_view, 0, 0, 0);
2760 current_view->hideCursor();
2761 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2762 current_view->beforeChange();
2764 current_view->text->SetCursorParUndo(current_view->buffer());
2765 current_view->text->FreezeUndo();
2767 current_view->text->BreakParagraph(current_view);
2768 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2770 if (current_view->text->cursor.par()->Last()) {
2771 current_view->text->CursorLeft(current_view);
2773 current_view->text->BreakParagraph(current_view);
2774 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2777 // The standard layout should always be numer 0;
2778 current_view->text->SetLayout(current_view, 0);
2781 if (current_view->text->cursor.par()->footnoteflag ==
2782 LyXParagraph::NO_FOOTNOTE) {
2784 current_view->text->
2785 SetParagraph(current_view, 0, 0,
2787 VSpace (0.3 * buffer->params.spacing.getValue(),
2790 buffer->params.spacing.getValue(),
2792 LYX_ALIGN_CENTER, string(), 0);
2795 current_view->text->SetParagraph(current_view, 0, 0,
2797 VSpace(VSpace::NONE),
2798 VSpace(VSpace::NONE),
2805 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2807 Inset * new_inset = new InsetFig(100, 100, buffer);
2808 current_view->insertInset(new_inset);
2809 new_inset->Edit(current_view, 0, 0, 0);
2810 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2811 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2812 current_view->text->UnFreezeUndo();
2813 current_view->setState();
2817 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2819 fl_hide_form(fd_form_figure->form_figure);
2823 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2825 FigureApplyCB(ob, data);
2826 FigureCancelCB(ob, data);
2830 // This function runs "configure" and then rereads lyx.defaults to
2831 // reconfigure the automatic settings.
2832 void Reconfigure(BufferView * bv)
2834 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2836 // Run configure in user lyx directory
2837 Path p(user_lyxdir);
2838 Systemcalls one(Systemcalls::System,
2839 AddName(system_lyxdir, "configure"));
2841 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2842 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2843 WriteAlert(_("The system has been reconfigured."),
2844 _("You need to restart LyX to make use of any"),
2845 _("updated document class specifications."));