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);
1780 //sprintf(sval, "%g", params->spacing.getValue());
1781 //#ifdef HAVE_SSTREAM
1782 std::ostringstream sval;
1783 sval << params->spacing.getValue(); // setw?
1784 fl_set_input(fd_form_document->input_spacing,
1785 sval.str().c_str());
1788 // ostrstream sval(tval, 20);
1789 // sval << params->spacing.getValue() << '\0'; // setw?
1790 // fl_set_input(fd_form_document->input_spacing, sval.str());
1797 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1798 params->secnumdepth);
1799 fl_set_counter_value(fd_form_document->slider_tocdepth,
1801 if (!params->float_placement.empty()) { // buffer local (Lgb)
1802 fl_set_input(fd_form_document->input_float_placement,
1803 params->float_placement.c_str());
1805 fl_set_input(fd_form_document->input_float_placement, "");
1807 if (!params->options.empty())
1808 fl_set_input(fd_form_document->input_extra,
1809 params->options.c_str());
1811 fl_set_input(fd_form_document->input_extra, "");
1813 if (current_view->buffer()->isSGML()) {
1814 // bullets not used in SGML derived documents
1815 fl_deactivate_object(fd_form_document->button_bullets);
1816 fl_set_object_lcol(fd_form_document->button_bullets,
1819 fl_activate_object(fd_form_document->button_bullets);
1820 fl_set_object_lcol(fd_form_document->button_bullets,
1824 if (current_view->buffer()->isReadonly()) {
1825 DisableDocumentLayout();
1827 EnableDocumentLayout();
1834 void MenuLayoutDocument()
1836 if (UpdateLayoutDocument()) {
1837 if (fd_form_document->form_document->visible) {
1838 fl_raise_form(fd_form_document->form_document);
1840 fl_show_form(fd_form_document->form_document,
1841 FL_PLACE_MOUSE, FL_FULLBORDER,
1842 _("Document Layout"));
1848 bool UpdateLayoutQuotes()
1851 if (!current_view->available()
1852 || current_view->buffer()->isReadonly())
1856 fl_set_choice(fd_form_quotes->choice_quotes_language,
1857 current_view->buffer()->params.quotes_language + 1);
1858 fl_set_button(fd_form_quotes->radio_single, 0);
1859 fl_set_button(fd_form_quotes->radio_double, 0);
1861 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1862 fl_set_button(fd_form_quotes->radio_single, 1);
1864 fl_set_button(fd_form_quotes->radio_double, 1);
1865 } else if (fd_form_quotes->form_quotes->visible) {
1866 fl_hide_form(fd_form_quotes->form_quotes);
1872 void MenuLayoutQuotes()
1874 if (UpdateLayoutQuotes()) {
1875 if (fd_form_quotes->form_quotes->visible) {
1876 fl_raise_form(fd_form_quotes->form_quotes);
1878 fl_show_form(fd_form_quotes->form_quotes,
1879 FL_PLACE_MOUSE, FL_FULLBORDER,
1887 bool UpdateLayoutPreamble()
1890 if (!current_view->available())
1894 fl_set_input(fd_form_preamble->input_preamble,
1895 current_view->buffer()->params.preamble.c_str());
1897 if (current_view->buffer()->isReadonly()) {
1898 fl_deactivate_object(fd_form_preamble->input_preamble);
1899 fl_deactivate_object(fd_form_preamble->button_ok);
1900 fl_deactivate_object(fd_form_preamble->button_apply);
1901 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1902 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1905 fl_activate_object(fd_form_preamble->input_preamble);
1906 fl_activate_object(fd_form_preamble->button_ok);
1907 fl_activate_object(fd_form_preamble->button_apply);
1908 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1909 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1911 } else if (fd_form_preamble->form_preamble->visible) {
1912 fl_hide_form(fd_form_preamble->form_preamble);
1918 void MenuLayoutPreamble()
1920 static int ow = -1, oh;
1922 if (UpdateLayoutPreamble()) {
1923 if (fd_form_preamble->form_preamble->visible) {
1924 fl_raise_form(fd_form_preamble->form_preamble);
1926 fl_show_form(fd_form_preamble->form_preamble,
1927 FL_PLACE_MOUSE | FL_FREE_SIZE,
1929 _("LaTeX Preamble"));
1931 ow = fd_form_preamble->form_preamble->w;
1932 oh = fd_form_preamble->form_preamble->h;
1934 fl_set_form_minsize(fd_form_preamble->form_preamble,
1941 void MenuLayoutSave()
1943 if (!current_view->available())
1946 if (AskQuestion(_("Do you want to save the current settings"),
1947 _("for Character, Document, Paper and Quotes"),
1948 _("as default for new documents?")))
1949 current_view->buffer()->saveParamsAsDefaults();
1953 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1954 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1955 LyXFont const UserFreeFont(BufferParams const & params)
1957 LyXFont font(LyXFont::ALL_IGNORE);
1959 int pos = fl_get_choice(fd_form_character->choice_family);
1961 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1962 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1963 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1964 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1965 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1968 pos = fl_get_choice(fd_form_character->choice_series);
1970 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1971 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1972 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1973 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1976 pos = fl_get_choice(fd_form_character->choice_shape);
1978 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1979 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1980 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1981 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1982 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1983 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1986 pos = fl_get_choice(fd_form_character->choice_size);
1988 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1989 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1990 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1991 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1992 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1993 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1994 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1995 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1996 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1997 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1998 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1999 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2000 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2001 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2004 pos = fl_get_choice(fd_form_character->choice_bar);
2006 case 1: font.setEmph(LyXFont::IGNORE);
2007 font.setUnderbar(LyXFont::IGNORE);
2008 font.setNoun(LyXFont::IGNORE);
2009 font.setLatex(LyXFont::IGNORE);
2011 case 2: font.setEmph(LyXFont::TOGGLE); break;
2012 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2013 case 4: font.setNoun(LyXFont::TOGGLE); break;
2014 case 5: font.setLatex(LyXFont::TOGGLE); break;
2015 case 6: font.setEmph(LyXFont::INHERIT);
2016 font.setUnderbar(LyXFont::INHERIT);
2017 font.setNoun(LyXFont::INHERIT);
2018 font.setLatex(LyXFont::INHERIT);
2022 pos = fl_get_choice(fd_form_character->choice_color);
2024 case 1: font.setColor(LColor::ignore); break;
2025 case 2: font.setColor(LColor::none); break;
2026 case 3: font.setColor(LColor::black); break;
2027 case 4: font.setColor(LColor::white); break;
2028 case 5: font.setColor(LColor::red); break;
2029 case 6: font.setColor(LColor::green); break;
2030 case 7: font.setColor(LColor::blue); break;
2031 case 8: font.setColor(LColor::cyan); break;
2032 case 9: font.setColor(LColor::magenta); break;
2033 case 10: font.setColor(LColor::yellow); break;
2034 case 11: font.setColor(LColor::inherit); break;
2037 int choice = combo_language2->get();
2039 font.setLanguage(ignore_language);
2040 else if (choice == 2)
2041 font.setLanguage(params.language_info);
2043 font.setLanguage(&languages[combo_language2->getline()]);
2049 /* callbacks for form form_title */
2050 extern "C" void TimerCB(FL_OBJECT *, long)
2052 // only if the form still exists
2053 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2054 if (fd_form_title->form_title->visible) {
2055 fl_hide_form(fd_form_title->form_title);
2057 fl_free_form(fd_form_title->form_title);
2058 fd_form_title->form_title = 0;
2063 /* callbacks for form form_paragraph */
2065 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2067 // "Synchronize" the choices and input fields, making it
2068 // impossible to commit senseless data.
2070 FD_form_paragraph const * fp = fd_form_paragraph;
2072 if (obj == fp->choice_space_above) {
2073 if (fl_get_choice (fp->choice_space_above) != 7) {
2074 fl_set_input (fp->input_space_above, "");
2075 ActivateParagraphButtons();
2077 } else if (obj == fp->choice_space_below) {
2078 if (fl_get_choice (fp->choice_space_below) != 7) {
2079 fl_set_input (fp->input_space_below, "");
2080 ActivateParagraphButtons();
2082 } else if (obj == fp->input_space_above) {
2083 string input = fl_get_input (fp->input_space_above);
2085 if (input.empty()) {
2086 fl_set_choice (fp->choice_space_above, 1);
2087 ActivateParagraphButtons();
2089 else if (isValidGlueLength (input)) {
2090 fl_set_choice (fp->choice_space_above, 7);
2091 ActivateParagraphButtons();
2094 fl_set_choice (fp->choice_space_above, 7);
2095 DeactivateParagraphButtons();
2097 } else if (obj == fp->input_space_below) {
2098 string input = fl_get_input (fp->input_space_below);
2100 if (input.empty()) {
2101 fl_set_choice (fp->choice_space_below, 1);
2102 ActivateParagraphButtons();
2104 else if (isValidGlueLength (input)) {
2105 fl_set_choice (fp->choice_space_below, 7);
2106 ActivateParagraphButtons();
2109 fl_set_choice (fp->choice_space_below, 7);
2110 DeactivateParagraphButtons();
2116 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2118 if (!current_view->available())
2121 VSpace space_top, space_bottom;
2123 string labelwidthstring;
2126 // If a vspace kind is "Length" but there's no text in
2127 // the input field, reset the kind to "None".
2128 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2129 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2130 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2132 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2133 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2134 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2137 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2138 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2139 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2140 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2141 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2142 case 1: space_top = VSpace(VSpace::NONE); break;
2143 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2144 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2145 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2146 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2147 case 6: space_top = VSpace(VSpace::VFILL); break;
2148 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2150 if (fl_get_button (fd_form_paragraph->check_space_above))
2151 space_top.setKeep (true);
2152 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2153 case 1: space_bottom = VSpace(VSpace::NONE); break;
2154 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2155 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2156 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2157 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2158 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2159 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2161 if (fl_get_button (fd_form_paragraph->check_space_below))
2162 space_bottom.setKeep (true);
2164 if (fl_get_button(fd_form_paragraph->radio_align_left))
2165 align = LYX_ALIGN_LEFT;
2166 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2167 align = LYX_ALIGN_RIGHT;
2168 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2169 align = LYX_ALIGN_CENTER;
2171 align = LYX_ALIGN_BLOCK;
2173 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2174 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2177 if (current_view->the_locking_inset)
2178 text = current_view->the_locking_inset->getLyXText(current_view);
2180 text = current_view->text;
2181 text->SetParagraph(current_view,
2191 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2192 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2196 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2198 fl_hide_form(fd_form_paragraph->form_paragraph);
2202 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2204 ParagraphApplyCB(ob, data);
2205 ParagraphCancelCB(ob, data);
2209 /* callbacks for form form_character */
2211 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2213 // we set toggleall locally here, since it should be true for
2214 // all other uses of ToggleAndShow() (JMarc)
2215 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2216 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2217 current_view->setState();
2222 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2224 fl_hide_form(fd_form_character->form_character);
2228 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2230 CharacterApplyCB(ob, data);
2231 CharacterCloseCB(ob, data);
2235 #ifdef USE_OLD_DOCUMENT_LAYOUT
2236 /* callbacks for form form_document */
2237 void UpdateDocumentButtons(BufferParams const & params)
2239 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2241 switch (params.sides) {
2242 case LyXTextClass::OneSide:
2243 fl_set_button(fd_form_document->radio_sides_one, 1);
2245 case LyXTextClass::TwoSides:
2246 fl_set_button(fd_form_document->radio_sides_two, 1);
2250 if (params.columns == 2)
2251 fl_set_button(fd_form_document->radio_columns_two, 1);
2253 fl_set_button(fd_form_document->radio_columns_one, 1);
2255 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2256 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2257 params.secnumdepth);
2258 fl_set_counter_value(fd_form_document->slider_tocdepth,
2263 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2265 ProhibitInput(current_view);
2266 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2267 if (AskQuestion(_("Should I set some parameters to"),
2268 fl_get_choice_text(ob),
2269 _("the defaults of this document class?"))) {
2270 BufferParams params = BufferParams();
2271 params.textclass = fl_get_choice(ob)-1;
2272 params.useClassDefaults();
2273 UpdateLayoutDocument(¶ms);
2274 UpdateDocumentButtons(params);
2277 // unable to load new style
2278 WriteAlert(_("Conversion Errors!"),
2279 _("Unable to switch to new document class."),
2280 _("Reverting to original document class."));
2281 fl_set_choice(fd_form_document->choice_class,
2282 current_view->buffer()->params.textclass + 1);
2284 AllowInput(current_view);
2288 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2290 // "Synchronize" the choice and the input field, so that it
2291 // is impossible to commit senseless data.
2292 FD_form_document const * fd = fd_form_document;
2294 if (obj == fd->choice_default_skip) {
2295 if (fl_get_choice (fd->choice_default_skip) != 4) {
2296 fl_set_input (fd->input_default_skip, "");
2297 ActivateDocumentButtons();
2299 } else if (obj == fd->input_default_skip) {
2301 char const * input = fl_get_input (fd->input_default_skip);
2304 fl_set_choice (fd->choice_default_skip, 2);
2305 ActivateDocumentButtons();
2306 } else if (isValidGlueLength (input)) {
2307 fl_set_choice (fd->choice_default_skip, 4);
2308 ActivateDocumentButtons();
2310 fl_set_choice (fd->choice_default_skip, 4);
2311 DeactivateDocumentButtons();
2317 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2319 // "Synchronize" the choice and the input field, so that it
2320 // is impossible to commit senseless data.
2321 FD_form_document const * fd = fd_form_document;
2323 if (obj == fd->choice_spacing
2324 && fl_get_choice (fd->choice_spacing) != 4) {
2325 fl_set_input(fd->input_spacing, "");
2326 } else if (obj == fd->input_spacing) {
2328 const char* input = fl_get_input (fd->input_spacing);
2331 fl_set_choice (fd->choice_spacing, 1);
2333 fl_set_choice (fd->choice_spacing, 4);
2339 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2342 BufferParams * params = &(current_view->buffer()->params);
2344 Language const * old_language = params->language_info;
2345 params->language = combo_language->getline();
2346 Languages::iterator lit = languages.find(params->language);
2348 Language const * new_language;
2349 if (lit != languages.end())
2350 new_language = &(*lit).second;
2352 new_language = default_language;
2354 if (current_view->available()) {
2355 if (old_language != new_language
2356 && old_language->RightToLeft() == new_language->RightToLeft()
2357 && !current_view->buffer()->isMultiLingual())
2358 current_view->buffer()->ChangeLanguage(old_language,
2360 if (old_language != new_language) {
2361 //current_view->buffer()->redraw();
2365 params->language_info = new_language;
2367 // If default skip is a "Length" but there's no text in the
2368 // input field, reset the kind to "Medskip", which is the default.
2369 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2370 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2371 fl_set_choice (fd_form_document->choice_default_skip, 2);
2374 /* this shouldn't be done automatically IMO. For example I write german
2375 * documents with an american keyboard very often. Matthias */
2377 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2378 fl_get_choice(fd_form_document->choice_language)); */
2380 fl_get_choice_text(fd_form_document->choice_fonts);
2382 fl_get_choice_text(fd_form_document->choice_inputenc);
2384 fl_get_choice_text(fd_form_document->choice_fontsize);
2386 fl_get_choice_text(fd_form_document->choice_pagestyle);
2387 params->graphicsDriver =
2388 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2389 params->use_amsmath =
2390 fl_get_button(fd_form_document->check_use_amsmath);
2392 if (!current_view->available())
2395 current_view->text->SetCursor(current_view,
2396 current_view->text->cursor.par(),
2397 current_view->text->cursor.pos());
2398 current_view->setState();
2400 LyXTextClassList::ClassList::size_type new_class =
2401 fl_get_choice(fd_form_document->choice_class) - 1;
2403 if (params->textclass != new_class) {
2404 // try to load new_class
2405 if (textclasslist.Load(new_class)) {
2406 // successfully loaded
2408 current_view->owner()->getMiniBuffer()->
2409 Set(_("Converting document to new document class..."));
2411 int ret = cap.SwitchLayoutsBetweenClasses(
2412 current_view->buffer()->params.textclass,
2414 current_view->buffer()->paragraph);
2419 s = _("One paragraph couldn't be converted");
2422 s += _(" paragraphs couldn't be converted");
2424 WriteAlert(_("Conversion Errors!"), s,
2425 _("into chosen document class"));
2428 params->textclass = new_class;
2430 // problem changing class -- warn user and retain old style
2431 WriteAlert(_("Conversion Errors!"),
2432 _("Unable to switch to new document class."),
2433 _("Reverting to original document class."));
2434 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2438 char tmpsep = params->paragraph_separation;
2439 if (fl_get_button(fd_form_document->radio_indent))
2440 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2442 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2443 if (tmpsep != params->paragraph_separation)
2446 VSpace tmpdefskip = params->getDefSkip();
2447 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2448 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2449 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2450 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2451 case 4: params->setDefSkip(
2452 VSpace (LyXGlueLength (fl_get_input
2453 (fd_form_document->input_default_skip))));
2455 // DocumentDefskipCB assures that this never happens
2456 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2458 if (!(tmpdefskip == params->getDefSkip()))
2461 if (fl_get_button(fd_form_document->radio_columns_two))
2462 params->columns = 2;
2464 params->columns = 1;
2465 if (fl_get_button(fd_form_document->radio_sides_two))
2466 params->sides = LyXTextClass::TwoSides;
2468 params->sides = LyXTextClass::OneSide;
2470 Spacing tmpSpacing = params->spacing;
2471 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2473 lyxerr.debug() << "Spacing: SINGLE" << endl;
2474 params->spacing.set(Spacing::Single);
2477 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2478 params->spacing.set(Spacing::Onehalf);
2481 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2482 params->spacing.set(Spacing::Double);
2485 lyxerr.debug() << "Spacing: OTHER" << endl;
2486 params->spacing.set(Spacing::Other,
2487 fl_get_input(fd_form_document->input_spacing));
2490 if (tmpSpacing != params->spacing)
2493 signed char tmpchar =
2494 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2495 if (params->secnumdepth != tmpchar)
2497 params->secnumdepth = tmpchar;
2500 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2502 params->float_placement =
2503 fl_get_input(fd_form_document->input_float_placement);
2505 // More checking should be done to ensure the string doesn't have
2506 // spaces or illegal placement characters in it. (thornley)
2509 current_view->redoCurrentBuffer();
2511 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2512 current_view->buffer()->markDirty();
2515 fl_get_input(fd_form_document->input_extra);
2519 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2521 fl_hide_form(fd_form_document->form_document);
2525 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2527 DocumentCancelCB(ob, data);
2528 DocumentApplyCB(ob, data);
2532 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2535 // bullet callbacks etc. in bullet_panel.C -- ARRae
2538 /* callbacks for form form_quotes */
2540 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2542 if (!current_view->available())
2545 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2546 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2547 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2549 lga = InsetQuotes::EnglishQ;
2552 lga = InsetQuotes::SwedishQ;
2555 lga = InsetQuotes::GermanQ;
2558 lga = InsetQuotes::PolishQ;
2561 lga = InsetQuotes::FrenchQ;
2564 lga = InsetQuotes::DanishQ;
2567 current_view->buffer()->params.quotes_language = lga;
2568 if (fl_get_button(fd_form_quotes->radio_single))
2569 current_view->buffer()->
2570 params.quotes_times = InsetQuotes::SingleQ;
2572 current_view->buffer()->
2573 params.quotes_times = InsetQuotes::DoubleQ;
2577 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2579 fl_hide_form(fd_form_quotes->form_quotes);
2583 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2585 QuotesApplyCB(ob, data);
2586 QuotesCancelCB(ob, data);
2589 // this is needed for now!
2590 extern "C" void ChoiceClassCB(FL_OBJECT *, long) {}
2591 extern "C" void DocumentDefskipCB(FL_OBJECT *, long) {}
2592 extern "C" void DocumentSpacingCB(FL_OBJECT *, long) {}
2593 extern "C" void DocumentApplyCB(FL_OBJECT *, long) {}
2594 extern "C" void DocumentCancelCB(FL_OBJECT *, long) {}
2595 extern "C" void DocumentOKCB(FL_OBJECT *, long) {}
2596 extern "C" void DocumentBulletsCB(FL_OBJECT *, long) {}
2597 extern "C" void QuotesApplyCB(FL_OBJECT *, long) {}
2598 extern "C" void QuotesCancelCB(FL_OBJECT *, long) {}
2599 extern "C" void QuotesOKCB(FL_OBJECT *, long) {}
2603 /* callbacks for form form_preamble */
2605 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2607 fl_hide_form(fd_form_preamble->form_preamble);
2611 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2613 if (!current_view->available())
2616 current_view->buffer()->params.preamble =
2617 fl_get_input(fd_form_preamble->input_preamble);
2618 current_view->buffer()->markDirty();
2619 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2623 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2625 PreambleApplyCB(ob, data);
2626 PreambleCancelCB(ob, data);
2630 /* callbacks for form form_table */
2633 void TableApplyCB(FL_OBJECT *, long)
2635 if (!current_view->available())
2639 // check for tables in tables
2640 if (current_view->text->cursor.par()->table){
2641 WriteAlert(_("Impossible Operation!"),
2642 _("Cannot insert table in table."),
2647 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2649 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2650 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2653 current_view->hideCursor();
2654 current_view->beforeChange();
2655 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2657 current_view->text->SetCursorParUndo(current_view->buffer());
2658 current_view->text->FreezeUndo();
2660 current_view->text->BreakParagraph(current_view);
2661 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2663 if (current_view->text->cursor.par()->Last()) {
2664 current_view->text->CursorLeft(current_view);
2666 current_view->text->BreakParagraph(current_view);
2667 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2670 current_view->text->current_font.setLatex(LyXFont::OFF);
2671 //if (!fl_get_button(fd_form_table->check_latex)){
2672 // insert the new wysiwy table
2673 current_view->text->SetLayout(current_view, 0); // standard layout
2675 if (current_view->text->cursor.par()->footnoteflag ==
2676 LyXParagraph::NO_FOOTNOTE) {
2679 ->SetParagraph(current_view, 0, 0,
2681 VSpace (0.3 * current_view->buffer()->
2682 params.spacing.getValue(),
2684 VSpace (0.3 * current_view->buffer()->
2685 params.spacing.getValue(),
2693 ->SetParagraph(current_view, 0, 0,
2695 VSpace(VSpace::NONE),
2696 VSpace(VSpace::NONE),
2703 current_view->text->cursor.par()->table =
2704 new LyXTable(xsize, ysize);
2706 Language const * lang =
2707 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2708 LyXFont font(LyXFont::ALL_INHERIT, lang);
2709 for (int i = 0; i < xsize * ysize - 1; ++i) {
2710 current_view->text->cursor.par()
2711 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2713 current_view->text->RedoParagraph(current_view);
2715 current_view->text->UnFreezeUndo();
2717 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2718 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2719 current_view->setState();
2724 void TableCancelCB(FL_OBJECT *, long)
2726 fl_hide_form(fd_form_table->form_table);
2731 void TableOKCB(FL_OBJECT * ob, long data)
2733 TableApplyCB(ob, data);
2734 TableCancelCB(ob, data);
2740 if (fd_form_figure->form_figure->visible) {
2741 fl_raise_form(fd_form_figure->form_figure);
2743 fl_show_form(fd_form_figure->form_figure,
2744 FL_PLACE_MOUSE, FL_FULLBORDER,
2745 _("Insert Figure"));
2752 if (fd_form_table->form_table->visible) {
2753 fl_raise_form(fd_form_table->form_table);
2755 fl_show_form(fd_form_table->form_table,
2756 FL_PLACE_MOUSE, FL_FULLBORDER,
2762 /* callbacks for form form_figure */
2764 void FigureApplyCB(FL_OBJECT *, long)
2766 if (!current_view->available())
2769 Buffer * buffer = current_view->buffer();
2770 if(buffer->isReadonly()) // paranoia
2773 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2774 if (fl_get_button(fd_form_figure->radio_inline)
2776 || current_view->text->cursor.par()->table
2779 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2780 current_view->insertInset(new_inset);
2781 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2782 new_inset->Edit(current_view, 0, 0, 0);
2786 current_view->hideCursor();
2787 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2788 current_view->beforeChange();
2790 current_view->text->SetCursorParUndo(current_view->buffer());
2791 current_view->text->FreezeUndo();
2793 current_view->text->BreakParagraph(current_view);
2794 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2796 if (current_view->text->cursor.par()->Last()) {
2797 current_view->text->CursorLeft(current_view);
2799 current_view->text->BreakParagraph(current_view);
2800 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2803 // The standard layout should always be numer 0;
2804 current_view->text->SetLayout(current_view, 0);
2807 if (current_view->text->cursor.par()->footnoteflag ==
2808 LyXParagraph::NO_FOOTNOTE) {
2810 current_view->text->
2811 SetParagraph(current_view, 0, 0,
2813 VSpace (0.3 * buffer->params.spacing.getValue(),
2816 buffer->params.spacing.getValue(),
2818 LYX_ALIGN_CENTER, string(), 0);
2821 current_view->text->SetParagraph(current_view, 0, 0,
2823 VSpace(VSpace::NONE),
2824 VSpace(VSpace::NONE),
2831 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2833 Inset * new_inset = new InsetFig(100, 100, buffer);
2834 current_view->insertInset(new_inset);
2835 new_inset->Edit(current_view, 0, 0, 0);
2836 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2837 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2838 current_view->text->UnFreezeUndo();
2839 current_view->setState();
2843 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2845 fl_hide_form(fd_form_figure->form_figure);
2849 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2851 FigureApplyCB(ob, data);
2852 FigureCancelCB(ob, data);
2856 // This function runs "configure" and then rereads lyx.defaults to
2857 // reconfigure the automatic settings.
2858 void Reconfigure(BufferView * bv)
2860 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2862 // Run configure in user lyx directory
2863 Path p(user_lyxdir);
2864 Systemcalls one(Systemcalls::System,
2865 AddName(system_lyxdir, "configure"));
2867 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2868 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2869 WriteAlert(_("The system has been reconfigured."),
2870 _("You need to restart LyX to make use of any"),
2871 _("updated document class specifications."));