1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-2000 The LyX Team.
9 * ====================================================== */
18 #include FORMS_H_LOCATION
20 #include "layout_forms.h"
21 #include "bullet_forms.h"
25 #include "insets/insetref.h"
26 #include "insets/insetlabel.h"
27 #include "insets/figinset.h"
29 #include "minibuffer.h"
31 #include "bufferlist.h"
33 #include "lyx_gui_misc.h"
35 #include "BufferView.h"
36 #include "lastfiles.h"
37 #include "bufferview_funcs.h"
38 #include "support/FileInfo.h"
39 #include "support/syscall.h"
40 #include "support/filetools.h"
41 #include "support/path.h"
42 #include "lyxserver.h"
43 #include "FontLoader.h"
46 #include "CutAndPaste.h"
47 #include "TextCache.h"
51 using std::back_inserter;
55 using std::istream_iterator;
61 extern Combox * combo_language;
62 extern Combox * combo_language2;
63 extern BufferList bufferlist;
64 extern void show_symbols_form();
65 extern FD_form_title * fd_form_title;
66 extern FD_form_paragraph * fd_form_paragraph;
67 extern FD_form_character * fd_form_character;
68 extern FD_form_document * fd_form_document;
69 extern FD_form_quotes * fd_form_quotes;
70 extern FD_form_preamble * fd_form_preamble;
71 extern FD_form_table * fd_form_table;
72 extern FD_form_figure * fd_form_figure;
73 extern FD_form_screen * fd_form_screen;
74 extern FD_form_bullet * fd_form_bullet;
76 extern BufferView * current_view; // called too many times in this file...
78 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
80 extern bool send_fax(string const & fname, string const & sendcmd);
81 extern void MenuSendto();
83 extern LyXServer * lyxserver;
85 // this should be static, but I need it in buffer.C
86 bool quitting; // flag, that we are quitting the program
87 extern bool finished; // all cleanup done just let it run through now.
89 char ascii_type; /* for selection notify callbacks */
91 bool scrolling = false;
93 // This is used to make the dreaded font toggle problem hopefully go
94 // away. Definitely not the best solution, but I think it sorta works.
95 bool toggleall = true;
98 This is the inset locking stuff needed for mathed --------------------
100 an inset can simple call LockInset in it's edit call and *ONLY* in it's
102 Inset::Edit() can only be called by the main lyx module.
104 Then the inset may modify the menu's and/or iconbars.
106 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
108 During the lock, all button and keyboard events will be modified
109 and send to the inset through the following inset-features. Note that
110 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
111 to contain the code for restoring the menus and things like this.
114 virtual void InsetButtonPress(int x, int y, int button);
115 virtual void InsetButtonRelease(int x, int y, int button);
116 virtual void InsetKeyPress(XKeyEvent *ev);
117 virtual void InsetMotionNotify(int x, int y, int state);
118 virtual void InsetUnlock();
120 If a inset wishes any redraw and/or update it just has to call
122 It's is completly irrelevant, where the inset is. UpdateInset will
123 find it in any paragraph in any buffer.
124 Of course the_locking_inset and the insets in the current paragraph/buffer
125 are checked first, so no performance problem should occur.
127 Hope that's ok for the beginning, Alejandro,
128 sorry that I needed so much time,
133 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
135 /* these functions return 1 if an error occured,
137 // Now they work only for updatable insets. [Alejandro 080596]
138 //int LockInset(UpdatableInset * inset);
139 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
140 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
141 //int UnlockInset(UpdatableInset * inset);
142 //void LockedInsetStoreUndo(Undo::undo_kind kind);
144 /* this is for asyncron updating. UpdateInsetUpdateList will be called
145 automatically from LyX. Just insert the Inset into the Updatelist */
146 //void UpdateInsetUpdateList();
147 //void PutInsetIntoInsetUpdateList(Inset * inset);
149 //InsetUpdateStruct * InsetUpdateList = 0;
153 -----------------------------------------------------------------------
156 /* some function prototypes */
158 int RunLinuxDoc(BufferView *, int, string const &);
159 int RunDocBook(int, string const &);
160 void MenuWrite(Buffer * buf);
161 bool MenuWriteAs(Buffer * buffer);
162 void MenuReload(Buffer * buf);
163 void MenuLayoutSave();
166 void ShowMessage(Buffer * buf,
168 string const & msg2 = string(),
169 string const & msg3 = string(), int delay = 6)
172 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
175 // can somebody think of something more clever? cerr?
176 cout << msg1 << msg2 << msg3 << endl;
189 // should be moved to lyxfunc.C
190 void MenuWrite(Buffer * buffer)
193 if (!buffer->save()) {
194 string fname = buffer->fileName();
195 string s = MakeAbsPath(fname);
196 if (AskQuestion(_("Save failed. Rename and try again?"),
197 MakeDisplayPath(s, 50),
198 _("(If not, document is not saved.)"))) {
202 lastfiles->newFile(buffer->fileName());
207 // should be moved to BufferView.C
208 // Half of this func should be in LyXView, the rest in BufferView.
209 bool MenuWriteAs(Buffer * buffer)
211 // Why do we require BufferView::text to be able to write a
212 // document? I see no point in that. (Lgb)
213 //if (!bv->text) return;
215 string fname = buffer->fileName();
216 string oldname = fname;
219 ProhibitInput(current_view);
220 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
221 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
223 if (!IsLyXFilename(fname))
226 if (buffer->isUnnamed()) {
227 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
232 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
235 OnlyFilename(fname));
237 AllowInput(current_view);
242 // Make sure the absolute filename ends with appropriate suffix
243 string s = MakeAbsPath(fname);
244 if (!IsLyXFilename(s))
247 // Same name as we have already?
249 if (!AskQuestion(_("Same name as document already has:"),
250 MakeDisplayPath(s, 50),
253 // Falls through to name change and save
255 // No, but do we have another file with this name open?
256 else if (bufferlist.exists(s)) {
257 if (AskQuestion(_("Another document with same name open!"),
258 MakeDisplayPath(s, 50),
259 _("Replace with current document?")))
261 bufferlist.close(bufferlist.getBuffer(s));
263 // Ok, change the name of the buffer, but don't save!
267 ShowMessage(buffer, _("Document renamed to '"),
268 MakeDisplayPath(s), _("', but not saved..."));
271 } // Check whether the file exists
274 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
275 MakeDisplayPath(s, 50),
280 // Ok, change the name of the buffer
283 buffer->setUnnamed(false);
285 // Small bug: If the save fails, we have irreversible changed the name
292 int MenuRunLaTeX(Buffer * buffer)
296 if (buffer->isLinuxDoc())
297 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
298 else if (buffer->isLiterate())
299 ret = buffer->runLiterate();
300 else if (buffer->isDocBook())
301 ret = RunDocBook(1, buffer->fileName());
303 ret = buffer->runLaTeX();
309 s = _("One error detected");
310 t = _("You should try to fix it.");
313 s += _(" errors detected.");
314 t = _("You should try to fix them.");
316 WriteAlert(_("There were errors during the LaTeX run."), s, t);
322 int MenuBuildProg(Buffer * buffer)
326 if (buffer->isLiterate())
327 ret = buffer->buildProgram();
329 string s = _("Wrong type of document");
330 string t = _("The Build operation is not allowed in this document");
331 WriteAlert(_("There were errors during the Build process."), s, t);
339 s = _("One error detected");
340 t = _("You should try to fix it.");
343 s += _(" errors detected.");
344 t = _("You should try to fix them.");
346 WriteAlert(_("There were errors during the Build process."), s, t);
352 int MenuRunChktex(Buffer * buffer)
356 if (buffer->isSGML()) {
357 WriteAlert(_("Chktex does not work with SGML derived documents."));
360 ret = buffer->runChktex();
366 s = _("No warnings found.");
367 } else if (ret == 1) {
368 s = _("One warning found.");
369 t = _("Use 'Edit->Go to Error' to find it.");
372 s += _(" warnings found.");
373 t = _("Use 'Edit->Go to Error' to find them.");
375 WriteAlert(_("Chktex run successfully"), s, t);
377 WriteAlert(_("Error!"), _("It seems chktex does not work."));
383 int MakeLaTeXOutput(Buffer * buffer)
389 string path = OnlyPath(buffer->fileName());
390 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
391 path = buffer->tmppath;
395 ret = MenuRunLaTeX(buffer);
401 /* wait == false means don't wait for termination */
402 /* wait == true means wait for termination */
403 // The bool should be placed last on the argument line. (Lgb)
404 // Returns false if we fail.
405 bool RunScript(Buffer * buffer, bool wait,
406 string const & command,
407 string const & orgname = string(),
408 bool need_shell = true)
412 string name = orgname;
415 if (MakeLaTeXOutput(buffer) > 0)
417 /* get DVI-Filename */
419 name = ChangeExtension(buffer->getLatexName(), ".dvi");
421 path = OnlyPath(name);
422 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
423 path = buffer->tmppath;
426 // At this point we check whether the command contains the
427 // filename parameter $$FName and if that's the case we
428 // substitute the real file name otherwise the filename is
429 // simply appended. rokrau 1/12/00
432 if ( (i=command.find("$$FName")) != string::npos)
434 cmd.replace(i,7,QuoteName(name));
437 cmd = command + ' ' + QuoteName(name);
446 // OS/2 cmd.exe has another use for '&'
448 // This is not NLS safe, but it's OK, I think.
449 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
451 // COMSPEC is set, unless user unsets
452 sh = OnlyFilename(GetEnvPath("COMSPEC"));
457 if (contains(sh, "cmd.exe")
458 || contains(sh, "4os2.exe"))
459 cmd = "start /min/n " + cmd;
464 // It seems that, if wait is false, we never get back
465 // the return code of the command. This means that all
466 // the code I added in PrintApplyCB is currently
468 // CHECK What should we do here?
469 ShowMessage(buffer, _("Executing command:"), cmd);
470 result = one.startscript(Systemcalls::System, cmd);
472 ShowMessage(buffer, _("Executing command:"), cmd);
473 result = one.startscript(wait ? Systemcalls::Wait
474 : Systemcalls::DontWait, cmd);
480 // Returns false if we fail
481 bool CreatePostscript(Buffer * buffer, bool wait = false)
487 ProhibitInput(current_view);
490 if (MakeLaTeXOutput(buffer) > 0) {
491 AllowInput(current_view);
494 // Generate postscript file
495 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
501 char real_papersize = buffer->params.papersize;
502 if (real_papersize == BufferParams::PAPER_DEFAULT)
503 real_papersize = lyxrc.default_papersize;
505 switch (real_papersize) {
506 case BufferParams::PAPER_USLETTER:
509 case BufferParams::PAPER_A3PAPER:
512 case BufferParams::PAPER_A4PAPER:
515 case BufferParams::PAPER_A5PAPER:
518 case BufferParams::PAPER_B5PAPER:
521 case BufferParams::PAPER_EXECUTIVEPAPER:
524 case BufferParams::PAPER_LEGALPAPER:
527 default: /* If nothing else fits, keep an empty value... */
531 // Make postscript file.
532 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
533 command += QuoteName(psname);
534 if (buffer->params.use_geometry
535 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
536 && !lyxrc.print_paper_dimension_flag.empty()
537 && !buffer->params.paperwidth.empty()
538 && !buffer->params.paperheight.empty()) {
539 // using a custom papersize
541 command += lyxrc.print_paper_dimension_flag + ' ';
542 command += buffer->params.paperwidth + ',';
543 command += buffer->params.paperheight;
544 } else if (!paper.empty()
545 && (real_papersize != BufferParams::PAPER_USLETTER ||
546 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
547 // dvips won't accept -t letter -t landscape. In all other
548 // cases, include the paper size explicitly.
550 command += lyxrc.print_paper_flag + ' ' + paper;
552 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
554 command += lyxrc.print_landscape_flag;
556 // push directorypath, if necessary
557 string path = OnlyPath(buffer->fileName());
558 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
559 path = buffer->tmppath;
562 bool ret = RunScript(buffer, wait, command);
563 AllowInput(current_view);
568 // Returns false if we fail
569 //bool MenuPreviewPS(Buffer * buffer)
570 bool PreviewPostscript(Buffer * buffer)
576 // Generate postscript file
577 if (!CreatePostscript(buffer, true)) {
581 // Start postscript viewer
582 ProhibitInput(current_view);
583 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
585 // push directorypath, if necessary
586 string path = OnlyPath(buffer->fileName());
587 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
588 path = buffer->tmppath;
591 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
592 AllowInput(current_view);
597 void MenuFax(Buffer * buffer)
603 // Generate postscript file
604 if (!CreatePostscript(buffer, true)) {
609 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
611 string path = OnlyPath (buffer->fileName());
612 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
613 path = buffer->tmppath;
616 if (!lyxrc.fax_program.empty()) {
617 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
619 Systemcalls one(Systemcalls::System, help2);
621 send_fax(ps, lyxrc.fax_command);
625 // Returns false if we fail
626 bool PreviewDVI(Buffer * buffer)
632 string paper = lyxrc.view_dvi_paper_option;
633 if (!paper.empty()) {
635 char real_papersize = buffer->params.papersize;
636 if (real_papersize == BufferParams::PAPER_DEFAULT)
637 real_papersize = lyxrc.default_papersize;
639 switch (real_papersize) {
640 case BufferParams::PAPER_USLETTER:
643 case BufferParams::PAPER_A3PAPER:
646 case BufferParams::PAPER_A4PAPER:
649 case BufferParams::PAPER_A5PAPER:
652 case BufferParams::PAPER_B5PAPER:
655 case BufferParams::PAPER_EXECUTIVEPAPER:
656 paper += " foolscap";
658 case BufferParams::PAPER_LEGALPAPER:
661 default: /* If nothing else fits, keep the empty value */
664 if (real_papersize==' ') {
665 // if (paper.empty()) {
666 if (buffer->params.orientation
667 == BufferParams::ORIENTATION_LANDSCAPE)
668 // we HAVE to give a size when the page is in
669 // landscape, so use USletter.
670 paper = " -paper usr";
672 // paper = " -paper " + paper;
673 if (buffer->params.orientation
674 == BufferParams::ORIENTATION_LANDSCAPE)
678 // push directorypath, if necessary
679 string path = OnlyPath(buffer->fileName());
680 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
681 path = buffer->tmppath;
685 string command = lyxrc.view_dvi_command + " " + paper;
686 bool ret = RunScript(buffer, false, command);
691 bool AskOverwrite(Buffer * buffer, string const & s)
694 // be friendly if there is a gui
697 !AskQuestion(_("File already exists:"),
698 MakeDisplayPath(s, 50),
699 _("Do you want to overwrite the file?"))) {
700 ShowMessage(buffer, _("Canceled"));
708 void MenuMakeLaTeX(Buffer * buffer)
710 // Why care about this?
714 // Get LaTeX-Filename
715 string s = buffer->getLatexName(false);
717 if (!AskOverwrite(buffer, s))
720 if (buffer->isDocBook())
721 ShowMessage(buffer, _("DocBook does not have a latex backend"));
723 if (buffer->isLinuxDoc())
724 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
726 buffer->makeLaTeXFile(s, string(), true);
727 ShowMessage(buffer, _("Nice LaTeX file saved as"),
733 void MenuMakeLinuxDoc(Buffer * buffer)
736 //if (!bv->text) return;
738 if (!buffer->isLinuxDoc()) {
739 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
743 // Get LinuxDoc-Filename
744 string s = ChangeExtension(buffer->fileName(), ".sgml");
746 if (!AskOverwrite(buffer, s))
749 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
750 MakeDisplayPath(s),"'...");
752 buffer->makeLinuxDocFile(s, true);
754 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
759 void MenuMakeDocBook(Buffer * buffer)
762 //if (!bv->text) return;
764 if (!buffer->isDocBook()) {
765 WriteAlert(_("Error!"),
766 _("Document class must be docbook."));
770 // Get DocBook-Filename
771 string s = ChangeExtension(buffer->fileName(), ".sgml");
773 if (!AskOverwrite(buffer, s))
776 ShowMessage(buffer, _("Building DocBook SGML file `"),
777 MakeDisplayPath(s), "'...");
779 buffer->makeDocBookFile(s, true);
781 ShowMessage(buffer, _("DocBook SGML file save as"),
786 void MenuMakeAscii(Buffer * buffer)
789 //if (!bv->text) return;
791 /* get LaTeX-Filename */
792 string s = ChangeExtension (buffer->fileName(), ".txt");
795 if (!AskOverwrite(buffer, s))
798 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
800 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
804 void MenuMakeHTML(Buffer * buffer)
806 // First, create LaTeX file
807 MenuMakeLaTeX(buffer);
809 // And now, run the converter
810 string file = buffer->fileName();
811 Path path(OnlyPath(file));
812 // the tex file name has to be correct for
813 // latex, but the html file name can be
815 string result = ChangeExtension(file, ".html");
816 string infile = buffer->getLatexName(false);
817 string tmp = lyxrc.html_command;
818 tmp = subst(tmp, "$$FName", infile);
819 tmp = subst(tmp, "$$OutName", result);
821 int res = one.startscript(Systemcalls::System, tmp);
823 ShowMessage(buffer, _("Document exported as HTML to file `")
824 + MakeDisplayPath(result) +'\'');
826 ShowMessage(buffer, _("Unable to convert to HTML the file `")
827 + MakeDisplayPath(infile)
834 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
836 // First, create LinuxDoc file
837 MenuMakeLinuxDoc(buffer);
839 // And now, run the converter
840 string file = buffer->fileName();
842 string result = ChangeExtension(file, ".html");
843 string infile = ChangeExtension(file, ".sgml");
844 string tmp = lyxrc.linuxdoc_to_html_command;
845 tmp = subst(tmp, "$$FName", infile);
846 tmp = subst(tmp, "$$OutName", result);
848 int res = one.startscript(Systemcalls::System, tmp);
850 ShowMessage(buffer,_("Document exported as HTML to file `")
851 + MakeDisplayPath(result) +'\'');
853 ShowMessage(buffer,_("Unable to convert to HTML the file `")
854 + MakeDisplayPath(infile)
860 void MenuMakeHTML_DocBook(Buffer * buffer)
862 // First, create LaTeX file
863 MenuMakeDocBook(buffer);
865 // And now, run the converter
866 string file = buffer->fileName();
867 string result = ChangeExtension(file, ".html");
868 string infile = ChangeExtension(file, ".sgml");
869 string tmp = lyxrc.docbook_to_html_command;
870 tmp = subst(tmp, "$$FName", infile);
871 tmp = subst(tmp, "$$OutName", result);
873 int res = one.startscript(Systemcalls::System, tmp);
875 ShowMessage(buffer,_("Document exported as HTML to file `")
876 + MakeDisplayPath(result) +'\'');
878 ShowMessage(buffer,_("Unable to convert to HTML the file `")
879 + MakeDisplayPath(infile)
886 void MenuExport(Buffer * buffer, string const & extyp)
889 if (extyp == "latex") {
890 // make sure that this buffer is not linuxdoc
891 MenuMakeLaTeX(buffer);
894 else if (extyp == "linuxdoc") {
895 // make sure that this buffer is not latex
896 MenuMakeLinuxDoc(buffer);
899 else if (extyp == "docbook") {
900 // make sure that this buffer is not latex or linuxdoc
901 MenuMakeDocBook(buffer);
904 else if (extyp == "dvi") {
905 // Run LaTeX as "Update dvi..." Bernhard.
906 // We want the dvi in the current directory. This
907 // is achieved by temporarily disabling use of
908 // temp directory. As a side-effect, we get
909 // *.log and *.aux files also. (Asger)
910 bool flag = lyxrc.use_tempdir;
911 lyxrc.use_tempdir = false;
912 MenuRunLaTeX(buffer);
913 lyxrc.use_tempdir = flag;
916 else if (extyp == "postscript") {
917 // Start Print-dialog. Not as good as dvi... Bernhard.
918 //should start lyxview->getDialogs()->showPrint();
919 // to get same as before
920 // MenuPrint(buffer);
921 // Since the MenuPrint is a pop-up, we can't use
922 // the same trick as above. (Asger)
923 // MISSING: Move of ps-file :-(
924 // And MenuPrint should not be used for this at all...
927 else if (extyp == "ascii") {
928 MenuMakeAscii(buffer);
930 else if (extyp == "custom") {
934 else if (extyp == "html") {
935 if (buffer->isLinuxDoc())
936 MenuMakeHTML_LinuxDoc(buffer);
937 else if (buffer->isDocBook())
938 MenuMakeHTML_DocBook(buffer);
940 MenuMakeHTML(buffer);
943 ShowMessage(buffer, _("Unknown export type: ") + extyp);
950 lyxerr.debug() << "Running QuitLyX." << endl;
952 if (!bufferlist.QwriteAll())
955 lastfiles->writeFile(lyxrc.lastfiles);
957 // Set a flag that we do quitting from the program,
958 // so no refreshes are necessary.
961 // close buffers first
962 bufferlist.closeAll();
964 // do any other cleanup procedures now
965 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
967 DestroyLyXTmpDir(system_tempdir);
974 void AutoSave(BufferView * bv)
975 // should probably be moved into BufferList (Lgb)
976 // Perfect target for a thread...
978 if (!bv->available())
981 if (bv->buffer()->isBakClean() ||
982 bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
983 // We don't save now, but we'll try again later
984 bv->owner()->resetAutosaveTimer();
988 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
990 // create autosave filename
991 string fname = OnlyPath(bv->buffer()->fileName());
993 fname += OnlyFilename(bv->buffer()->fileName());
996 // tmp_ret will be located (usually) in /tmp
997 // will that be a problem?
998 string tmp_ret = tmpnam(0);
1000 pid_t pid = fork(); // If you want to debug the autosave
1001 // you should set pid to -1, and comment out the
1003 if (pid == 0 || pid == -1) {
1004 // pid = -1 signifies that lyx was unable
1005 // to fork. But we will do the save
1007 bool failed = false;
1008 if (!tmp_ret.empty()) {
1009 bv->buffer()->writeFile(tmp_ret, 1);
1010 // assume successful write of tmp_ret
1011 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1013 // most likely couldn't move between filesystems
1014 // unless write of tmp_ret failed
1015 // so remove tmp file (if it exists)
1016 remove(tmp_ret.c_str());
1023 // failed to write/rename tmp_ret so try writing direct
1024 if (!bv->buffer()->writeFile(fname, 1)) {
1025 // It is dangerous to do this in the child,
1026 // but safe in the parent, so...
1028 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1031 if (pid == 0) { // we are the child so...
1036 bv->buffer()->markBakClean();
1037 bv->owner()->resetAutosaveTimer();
1042 // Copyright CHT Software Service GmbH
1045 // create new file with template
1048 Buffer * NewLyxFile(string const & filename)
1050 // Split argument by :
1052 string tmpname = split(filename, name, ':');
1053 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1054 if (name.length() == 1
1055 && isalpha(static_cast<unsigned char>(name[0]))
1056 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1058 name += token(tmpname, ':', 0);
1059 tmpname = split(tmpname, ':');
1062 lyxerr.debug() << "Arg is " << filename
1063 << "\nName is " << name
1064 << "\nTemplate is " << tmpname << endl;
1066 // find a free buffer
1067 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1069 lastfiles->newFile(tmpbuf->fileName());
1074 // Insert ascii file (if filename is empty, prompt for one)
1075 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1080 if (!bv->available()) return;
1082 if (fname.empty()) {
1084 fname = fileDlg.Select(_("File to Insert"),
1085 bv->owner()->buffer()->filepath,
1088 if (fname.empty()) return;
1093 if (!fi.readable()) {
1094 WriteFSAlert(_("Error! Specified file is unreadable: "),
1095 MakeDisplayPath(fname, 50));
1099 ifstream ifs(fname.c_str());
1101 WriteFSAlert(_("Error! Cannot open specified file: "),
1102 MakeDisplayPath(fname, 50));
1106 ifs.unsetf(ios::skipws);
1107 istream_iterator<char> ii(ifs);
1108 istream_iterator<char> end;
1109 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1110 // We use this until the compilers get better...
1112 copy(ii, end, back_inserter(tmp));
1113 string tmpstr(tmp.begin(), tmp.end());
1115 // This is what we want to use and what we will use once the
1116 // compilers get good enough.
1117 //string tmpstr(ii, end); // yet a reason for using std::string
1118 // alternate approach to get the file into a string:
1120 copy(ii, end, back_inserter(tmpstr));
1122 // insert the string
1123 current_view->hideCursor();
1125 // clear the selection
1128 bv->text->InsertStringA(bv, tmpstr);
1130 bv->text->InsertStringB(bv, tmpstr);
1131 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1135 void MenuInsertLabel(char const * arg)
1138 ProhibitInput(current_view);
1139 if (label.empty()) {
1141 result = askForText(_("Enter new label to insert:"));
1143 label = frontStrip(strip(result.second));
1146 if (!label.empty()) {
1147 InsetCommandParams p( "label", label );
1148 InsetLabel * inset = new InsetLabel( p );
1149 current_view->insertInset( inset );
1151 AllowInput(current_view);
1155 // candidate for move to LyXView
1156 // This is only used in toolbar.C
1157 void LayoutsCB(int sel, void *)
1159 string tmp = tostr(sel);
1160 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1166 * SGML Linuxdoc support:
1167 * (flag == 0) make TeX output
1168 * (flag == 1) make dvi output
1170 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1177 /* generate a path-less extension name */
1178 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1179 string path = OnlyPath (filename);
1180 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1181 path = bv->buffer()->tmppath;
1185 if (!bv->available())
1187 bv->buffer()->makeLinuxDocFile(name, false);
1189 // CHECK remove this once we have a proper geometry class
1191 BufferParams::PAPER_SIZE ps =
1192 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1194 case BufferParams::PAPER_A4PAPER:
1195 add_flags = "-p a4";
1197 case BufferParams::PAPER_USLETTER:
1198 add_flags = "-p letter";
1200 default: /* nothing to be done yet ;-) */ break;
1207 case 0: /* TeX output asked */
1208 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1209 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1210 if (one.startscript(Systemcalls::System, s2))
1213 case 1: /* dvi output asked */
1214 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1215 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1216 if (one.startscript(Systemcalls::System, s2)) {
1220 default: /* unknown output */
1226 bv->buffer()->redraw();
1232 * SGML DocBook support:
1233 * (flag == 1) make dvi output
1235 int RunDocBook(int flag, string const & filename)
1237 /* generate a path-less extension name */
1238 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1239 string path = OnlyPath (filename);
1240 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1241 path = current_view->buffer()->tmppath;
1245 if (!current_view->available())
1248 current_view->buffer()->makeDocBookFile(name, false);
1250 // Shall this code go or should it stay? (Lgb)
1251 // This code is a placeholder for future implementation. (Jose')
1252 // string add_flags;
1253 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1255 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1256 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1257 // default: /* nothing to be done yet ;-) */ break;
1259 ProhibitInput(current_view);
1264 case 1: /* dvi output asked */
1266 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1267 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1268 if (one.startscript(Systemcalls::System, s2)) {
1273 default: /* unknown output */
1277 AllowInput(current_view);
1279 current_view->buffer()->redraw();
1284 void MenuLayoutCharacter()
1286 static int ow = -1, oh;
1288 if (fd_form_character->form_character->visible) {
1289 fl_raise_form(fd_form_character->form_character);
1291 fl_show_form(fd_form_character->form_character,
1292 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1293 _("Character Style"));
1295 ow = fd_form_character->form_character->w;
1296 oh = fd_form_character->form_character->h;
1298 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1304 void DeactivateParagraphButtons ()
1306 fl_deactivate_object (fd_form_paragraph->button_ok);
1307 fl_deactivate_object (fd_form_paragraph->button_apply);
1308 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1309 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1314 void ActivateParagraphButtons ()
1316 fl_activate_object (fd_form_paragraph->button_ok);
1317 fl_activate_object (fd_form_paragraph->button_apply);
1318 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1319 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1324 void DisableParagraphLayout ()
1326 DeactivateParagraphButtons();
1327 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1328 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1329 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1330 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1331 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1332 fl_deactivate_object (fd_form_paragraph->check_noindent);
1333 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1334 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1335 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1336 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1337 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1338 fl_deactivate_object (fd_form_paragraph->input_space_above);
1339 fl_deactivate_object (fd_form_paragraph->input_space_below);
1340 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1341 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1342 fl_deactivate_object (fd_form_paragraph->check_space_above);
1343 fl_deactivate_object (fd_form_paragraph->check_space_below);
1348 void EnableParagraphLayout ()
1350 ActivateParagraphButtons();
1351 fl_activate_object (fd_form_paragraph->input_labelwidth);
1352 fl_activate_object (fd_form_paragraph->check_lines_top);
1353 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1354 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1355 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1356 fl_activate_object (fd_form_paragraph->check_noindent);
1357 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1358 fl_activate_object (fd_form_paragraph->radio_align_right);
1359 fl_activate_object (fd_form_paragraph->radio_align_left);
1360 fl_activate_object (fd_form_paragraph->radio_align_block);
1361 fl_activate_object (fd_form_paragraph->radio_align_center);
1362 fl_activate_object (fd_form_paragraph->input_space_above);
1363 fl_activate_object (fd_form_paragraph->input_space_below);
1364 fl_activate_object (fd_form_paragraph->choice_space_above);
1365 fl_activate_object (fd_form_paragraph->choice_space_below);
1366 fl_activate_object (fd_form_paragraph->check_space_above);
1367 fl_activate_object (fd_form_paragraph->check_space_below);
1371 bool UpdateLayoutParagraph()
1373 if (!current_view->available()) {
1374 if (fd_form_paragraph->form_paragraph->visible)
1375 fl_hide_form(fd_form_paragraph->form_paragraph);
1379 Buffer * buf = current_view->buffer();
1381 if (current_view->the_locking_inset)
1382 text = current_view->the_locking_inset->getLyXText(current_view);
1384 text = current_view->text;
1386 fl_set_input(fd_form_paragraph->input_labelwidth,
1387 text->cursor.par()->GetLabelWidthString().c_str());
1388 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1389 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1390 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1391 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1393 int align = text->cursor.par()->GetAlign();
1394 if (align == LYX_ALIGN_LAYOUT)
1395 align = textclasslist.Style(buf->params.textclass,
1396 text->cursor.par()->GetLayout()).align;
1399 case LYX_ALIGN_RIGHT:
1400 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1402 case LYX_ALIGN_LEFT:
1403 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1405 case LYX_ALIGN_CENTER:
1406 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1409 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1414 fl_set_button(fd_form_paragraph->check_lines_top,
1415 text->cursor.par()->FirstPhysicalPar()->line_top);
1417 fl_set_button(fd_form_paragraph->check_lines_bottom,
1418 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1420 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1421 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1423 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1424 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1425 fl_set_button(fd_form_paragraph->check_noindent,
1426 text->cursor.par()->FirstPhysicalPar()->noindent);
1428 fl_set_button(fd_form_paragraph->check_lines_top,
1429 text->cursor.par()->line_top);
1430 fl_set_button(fd_form_paragraph->check_lines_bottom,
1431 text->cursor.par()->line_bottom);
1432 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1433 text->cursor.par()->pagebreak_top);
1434 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1435 text->cursor.par()->pagebreak_bottom);
1436 fl_set_button(fd_form_paragraph->check_noindent,
1437 text->cursor.par()->noindent);
1439 fl_set_input (fd_form_paragraph->input_space_above, "");
1442 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1444 switch (text->cursor.par()->added_space_top.kind()) {
1448 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1450 case VSpace::DEFSKIP:
1451 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1453 case VSpace::SMALLSKIP:
1454 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1456 case VSpace::MEDSKIP:
1457 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1459 case VSpace::BIGSKIP:
1460 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1463 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1465 case VSpace::LENGTH:
1466 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1468 fl_set_input (fd_form_paragraph->input_space_above,
1469 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1471 fl_set_input (fd_form_paragraph->input_space_above,
1472 text->cursor.par()->added_space_top.length().asString().c_str());
1477 fl_set_button (fd_form_paragraph->check_space_above,
1478 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1479 fl_set_input (fd_form_paragraph->input_space_below, "");
1480 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1482 fl_set_button (fd_form_paragraph->check_space_above,
1483 text->cursor.par()->added_space_top.keep());
1484 fl_set_input (fd_form_paragraph->input_space_below, "");
1485 switch (text->cursor.par()->added_space_bottom.kind()) {
1488 fl_set_choice (fd_form_paragraph->choice_space_below,
1491 case VSpace::DEFSKIP:
1492 fl_set_choice (fd_form_paragraph->choice_space_below,
1495 case VSpace::SMALLSKIP:
1496 fl_set_choice (fd_form_paragraph->choice_space_below,
1499 case VSpace::MEDSKIP:
1500 fl_set_choice (fd_form_paragraph->choice_space_below,
1503 case VSpace::BIGSKIP:
1504 fl_set_choice (fd_form_paragraph->choice_space_below,
1508 fl_set_choice (fd_form_paragraph->choice_space_below,
1511 case VSpace::LENGTH:
1512 fl_set_choice (fd_form_paragraph->choice_space_below,
1515 fl_set_input (fd_form_paragraph->input_space_below,
1516 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1519 fl_set_button (fd_form_paragraph->check_space_below,
1520 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1522 fl_set_button(fd_form_paragraph->check_noindent,
1523 text->cursor.par()->FirstPhysicalPar()->noindent);
1525 fl_set_input (fd_form_paragraph->input_space_below,
1526 text->cursor.par()->added_space_bottom.length().asString().c_str());
1529 fl_set_button (fd_form_paragraph->check_space_below,
1530 text->cursor.par()->added_space_bottom.keep());
1532 fl_set_button(fd_form_paragraph->check_noindent,
1533 text->cursor.par()->noindent);
1535 if (current_view->buffer()->isReadonly()) {
1536 DisableParagraphLayout();
1538 EnableParagraphLayout();
1544 void MenuLayoutParagraph()
1546 if (UpdateLayoutParagraph()) {
1547 if (fd_form_paragraph->form_paragraph->visible) {
1548 fl_raise_form(fd_form_paragraph->form_paragraph);
1550 fl_show_form(fd_form_paragraph->form_paragraph,
1551 FL_PLACE_MOUSE, FL_FULLBORDER,
1552 _("Paragraph Environment"));
1559 void DeactivateDocumentButtons ()
1561 fl_deactivate_object (fd_form_document->button_ok);
1562 fl_deactivate_object (fd_form_document->button_apply);
1563 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1564 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1569 void ActivateDocumentButtons ()
1571 fl_activate_object (fd_form_document->button_ok);
1572 fl_activate_object (fd_form_document->button_apply);
1573 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1574 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1579 void DisableDocumentLayout ()
1581 DeactivateDocumentButtons ();
1582 fl_deactivate_object (fd_form_document->group_radio_separation);
1583 fl_deactivate_object (fd_form_document->radio_indent);
1584 fl_deactivate_object (fd_form_document->radio_skip);
1585 fl_deactivate_object (fd_form_document->choice_class);
1586 fl_deactivate_object (fd_form_document->choice_pagestyle);
1587 fl_deactivate_object (fd_form_document->choice_fonts);
1588 fl_deactivate_object (fd_form_document->choice_fontsize);
1589 fl_deactivate_object (fd_form_document->input_float_placement);
1590 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1591 fl_deactivate_object (fd_form_document->choice_inputenc);
1592 fl_deactivate_object (fd_form_document->group_radio_sides);
1593 fl_deactivate_object (fd_form_document->radio_sides_one);
1594 fl_deactivate_object (fd_form_document->radio_sides_two);
1595 fl_deactivate_object (fd_form_document->group_radio_columns);
1596 fl_deactivate_object (fd_form_document->radio_columns_one);
1597 fl_deactivate_object (fd_form_document->radio_columns_two);
1598 fl_deactivate_object (fd_form_document->input_extra);
1599 fl_deactivate_object (fd_form_document->choice_language);
1600 combo_language->deactivate();
1601 fl_deactivate_object (fd_form_document->input_default_skip);
1602 fl_deactivate_object (fd_form_document->choice_default_skip);
1603 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1604 fl_deactivate_object (fd_form_document->slider_tocdepth);
1605 fl_deactivate_object (fd_form_document->choice_spacing);
1606 fl_deactivate_object (fd_form_document->input_spacing);
1607 fl_deactivate_object (fd_form_document->check_use_amsmath);
1612 void EnableDocumentLayout ()
1614 ActivateDocumentButtons ();
1615 fl_activate_object (fd_form_document->group_radio_separation);
1616 fl_activate_object (fd_form_document->radio_indent);
1617 fl_activate_object (fd_form_document->radio_skip);
1618 fl_activate_object (fd_form_document->choice_class);
1619 fl_activate_object (fd_form_document->choice_pagestyle);
1620 fl_activate_object (fd_form_document->choice_fonts);
1621 fl_activate_object (fd_form_document->choice_fontsize);
1622 fl_activate_object (fd_form_document->input_float_placement);
1623 fl_activate_object (fd_form_document->choice_postscript_driver);
1624 fl_activate_object (fd_form_document->choice_inputenc);
1625 fl_activate_object (fd_form_document->group_radio_sides);
1626 fl_activate_object (fd_form_document->radio_sides_one);
1627 fl_activate_object (fd_form_document->radio_sides_two);
1628 fl_activate_object (fd_form_document->group_radio_columns);
1629 fl_activate_object (fd_form_document->radio_columns_one);
1630 fl_activate_object (fd_form_document->radio_columns_two);
1631 fl_activate_object (fd_form_document->input_extra);
1632 fl_activate_object (fd_form_document->choice_language);
1633 combo_language->activate();
1634 fl_activate_object (fd_form_document->input_default_skip);
1635 fl_activate_object (fd_form_document->choice_default_skip);
1636 fl_activate_object (fd_form_document->slider_secnumdepth);
1637 fl_activate_object (fd_form_document->slider_tocdepth);
1638 fl_activate_object (fd_form_document->choice_spacing);
1639 fl_activate_object (fd_form_document->input_spacing);
1640 fl_activate_object (fd_form_document->check_use_amsmath);
1644 bool UpdateLayoutDocument(BufferParams * params)
1646 if (!current_view->available()) {
1647 if (fd_form_document->form_document->visible)
1648 fl_hide_form(fd_form_document->form_document);
1653 params = ¤t_view->buffer()->params;
1654 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1656 fl_set_choice_text(fd_form_document->choice_class,
1657 textclasslist.DescOfClass(params->textclass).c_str());
1658 combo_language->select_text(params->language.c_str());
1660 fl_set_choice_text(fd_form_document->choice_fonts,
1661 params->fonts.c_str());
1662 fl_set_choice_text(fd_form_document->choice_inputenc,
1663 params->inputenc.c_str());
1664 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1665 params->graphicsDriver.c_str());
1667 // ale970405+lasgoutt970513
1668 fl_clear_choice(fd_form_document->choice_fontsize);
1669 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1670 fl_addto_choice(fd_form_document->choice_fontsize,
1671 tclass.opt_fontsize().c_str());
1672 fl_set_choice(fd_form_document->choice_fontsize,
1673 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1675 // ale970405+lasgoutt970513
1676 fl_clear_choice(fd_form_document->choice_pagestyle);
1677 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1678 fl_addto_choice(fd_form_document->choice_pagestyle,
1679 tclass.opt_pagestyle().c_str());
1681 fl_set_choice(fd_form_document->choice_pagestyle,
1682 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1684 fl_set_button(fd_form_document->radio_indent, 0);
1685 fl_set_button(fd_form_document->radio_skip, 0);
1688 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1690 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1691 fl_set_button(fd_form_document->radio_indent, 1);
1693 fl_set_button(fd_form_document->radio_skip, 1);
1695 switch (params->getDefSkip().kind()) {
1696 case VSpace::SMALLSKIP:
1697 fl_set_choice (fd_form_document->choice_default_skip, 1);
1699 case VSpace::MEDSKIP:
1700 fl_set_choice (fd_form_document->choice_default_skip, 2);
1702 case VSpace::BIGSKIP:
1703 fl_set_choice (fd_form_document->choice_default_skip, 3);
1705 case VSpace::LENGTH:
1706 fl_set_choice (fd_form_document->choice_default_skip, 4);
1707 fl_set_input (fd_form_document->input_default_skip,
1708 params->getDefSkip().asLyXCommand().c_str());
1711 fl_set_choice (fd_form_document->choice_default_skip, 2);
1715 fl_set_button(fd_form_document->radio_sides_one, 0);
1716 fl_set_button(fd_form_document->radio_sides_two, 0);
1718 switch (params->sides) {
1719 case LyXTextClass::OneSide:
1720 fl_set_button(fd_form_document->radio_sides_one, 1);
1722 case LyXTextClass::TwoSides:
1723 fl_set_button(fd_form_document->radio_sides_two, 1);
1727 fl_set_button(fd_form_document->radio_columns_one, 0);
1728 fl_set_button(fd_form_document->radio_columns_two, 0);
1730 if (params->columns == 2)
1731 fl_set_button(fd_form_document->radio_columns_two, 1);
1733 fl_set_button(fd_form_document->radio_columns_one, 1);
1735 fl_set_input(fd_form_document->input_spacing, "");
1736 switch (params->spacing.getSpace()) {
1737 case Spacing::Default: // nothing bad should happen with this
1738 case Spacing::Single:
1741 fl_set_choice(fd_form_document->choice_spacing, 1);
1744 case Spacing::Onehalf:
1747 fl_set_choice(fd_form_document->choice_spacing, 2);
1750 case Spacing::Double:
1753 fl_set_choice(fd_form_document->choice_spacing, 3);
1756 case Spacing::Other:
1758 fl_set_choice(fd_form_document->choice_spacing, 4);
1760 //sprintf(sval, "%g", params->spacing.getValue());
1762 std::ostringstream sval;
1763 sval << params->spacing.getValue(); // setw?
1764 fl_set_input(fd_form_document->input_spacing,
1765 sval.str().c_str());
1768 ostrstream sval(tval, 20);
1769 sval << params->spacing.getValue() << '\0'; // setw?
1770 fl_set_input(fd_form_document->input_spacing, sval.str());
1777 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1778 params->secnumdepth);
1779 fl_set_counter_value(fd_form_document->slider_tocdepth,
1781 if (!params->float_placement.empty()) { // buffer local (Lgb)
1782 fl_set_input(fd_form_document->input_float_placement,
1783 params->float_placement.c_str());
1785 fl_set_input(fd_form_document->input_float_placement, "");
1787 if (!params->options.empty())
1788 fl_set_input(fd_form_document->input_extra,
1789 params->options.c_str());
1791 fl_set_input(fd_form_document->input_extra, "");
1793 if (current_view->buffer()->isSGML()) {
1794 // bullets not used in SGML derived documents
1795 fl_deactivate_object(fd_form_document->button_bullets);
1796 fl_set_object_lcol(fd_form_document->button_bullets,
1799 fl_activate_object(fd_form_document->button_bullets);
1800 fl_set_object_lcol(fd_form_document->button_bullets,
1804 if (current_view->buffer()->isReadonly()) {
1805 DisableDocumentLayout();
1807 EnableDocumentLayout();
1814 void MenuLayoutDocument()
1816 if (UpdateLayoutDocument()) {
1817 if (fd_form_document->form_document->visible) {
1818 fl_raise_form(fd_form_document->form_document);
1820 fl_show_form(fd_form_document->form_document,
1821 FL_PLACE_MOUSE, FL_FULLBORDER,
1822 _("Document Layout"));
1828 bool UpdateLayoutQuotes()
1831 if (!current_view->available()
1832 || current_view->buffer()->isReadonly())
1836 fl_set_choice(fd_form_quotes->choice_quotes_language,
1837 current_view->buffer()->params.quotes_language + 1);
1838 fl_set_button(fd_form_quotes->radio_single, 0);
1839 fl_set_button(fd_form_quotes->radio_double, 0);
1841 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1842 fl_set_button(fd_form_quotes->radio_single, 1);
1844 fl_set_button(fd_form_quotes->radio_double, 1);
1845 } else if (fd_form_quotes->form_quotes->visible) {
1846 fl_hide_form(fd_form_quotes->form_quotes);
1852 void MenuLayoutQuotes()
1854 if (UpdateLayoutQuotes()) {
1855 if (fd_form_quotes->form_quotes->visible) {
1856 fl_raise_form(fd_form_quotes->form_quotes);
1858 fl_show_form(fd_form_quotes->form_quotes,
1859 FL_PLACE_MOUSE, FL_FULLBORDER,
1866 bool UpdateLayoutPreamble()
1869 if (!current_view->available())
1873 fl_set_input(fd_form_preamble->input_preamble,
1874 current_view->buffer()->params.preamble.c_str());
1876 if (current_view->buffer()->isReadonly()) {
1877 fl_deactivate_object(fd_form_preamble->input_preamble);
1878 fl_deactivate_object(fd_form_preamble->button_ok);
1879 fl_deactivate_object(fd_form_preamble->button_apply);
1880 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1881 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1884 fl_activate_object(fd_form_preamble->input_preamble);
1885 fl_activate_object(fd_form_preamble->button_ok);
1886 fl_activate_object(fd_form_preamble->button_apply);
1887 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1888 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1890 } else if (fd_form_preamble->form_preamble->visible) {
1891 fl_hide_form(fd_form_preamble->form_preamble);
1897 void MenuLayoutPreamble()
1899 static int ow = -1, oh;
1901 if (UpdateLayoutPreamble()) {
1902 if (fd_form_preamble->form_preamble->visible) {
1903 fl_raise_form(fd_form_preamble->form_preamble);
1905 fl_show_form(fd_form_preamble->form_preamble,
1906 FL_PLACE_MOUSE | FL_FREE_SIZE,
1908 _("LaTeX Preamble"));
1910 ow = fd_form_preamble->form_preamble->w;
1911 oh = fd_form_preamble->form_preamble->h;
1913 fl_set_form_minsize(fd_form_preamble->form_preamble,
1920 void MenuLayoutSave()
1922 if (!current_view->available())
1925 if (AskQuestion(_("Do you want to save the current settings"),
1926 _("for Character, Document, Paper and Quotes"),
1927 _("as default for new documents?")))
1928 current_view->buffer()->saveParamsAsDefaults();
1932 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1933 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1934 LyXFont UserFreeFont(BufferParams const & params)
1936 LyXFont font(LyXFont::ALL_IGNORE);
1938 int pos = fl_get_choice(fd_form_character->choice_family);
1940 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1941 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1942 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1943 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1944 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1947 pos = fl_get_choice(fd_form_character->choice_series);
1949 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1950 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1951 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1952 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1955 pos = fl_get_choice(fd_form_character->choice_shape);
1957 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1958 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1959 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1960 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1961 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1962 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1965 pos = fl_get_choice(fd_form_character->choice_size);
1967 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1968 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1969 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1970 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1971 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1972 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1973 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1974 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1975 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1976 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1977 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1978 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1979 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1980 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1983 pos = fl_get_choice(fd_form_character->choice_bar);
1985 case 1: font.setEmph(LyXFont::IGNORE);
1986 font.setUnderbar(LyXFont::IGNORE);
1987 font.setNoun(LyXFont::IGNORE);
1988 font.setLatex(LyXFont::IGNORE);
1990 case 2: font.setEmph(LyXFont::TOGGLE); break;
1991 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
1992 case 4: font.setNoun(LyXFont::TOGGLE); break;
1993 case 5: font.setLatex(LyXFont::TOGGLE); break;
1994 case 6: font.setEmph(LyXFont::INHERIT);
1995 font.setUnderbar(LyXFont::INHERIT);
1996 font.setNoun(LyXFont::INHERIT);
1997 font.setLatex(LyXFont::INHERIT);
2001 pos = fl_get_choice(fd_form_character->choice_color);
2003 case 1: font.setColor(LColor::ignore); break;
2004 case 2: font.setColor(LColor::none); break;
2005 case 3: font.setColor(LColor::black); break;
2006 case 4: font.setColor(LColor::white); break;
2007 case 5: font.setColor(LColor::red); break;
2008 case 6: font.setColor(LColor::green); break;
2009 case 7: font.setColor(LColor::blue); break;
2010 case 8: font.setColor(LColor::cyan); break;
2011 case 9: font.setColor(LColor::magenta); break;
2012 case 10: font.setColor(LColor::yellow); break;
2013 case 11: font.setColor(LColor::inherit); break;
2016 int choice = combo_language2->get();
2018 font.setLanguage(ignore_language);
2019 else if (choice == 2)
2020 font.setLanguage(params.language_info);
2022 font.setLanguage(&languages[combo_language2->getline()]);
2028 /* callbacks for form form_title */
2029 extern "C" void TimerCB(FL_OBJECT *, long)
2031 // only if the form still exists
2032 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2033 if (fd_form_title->form_title->visible) {
2034 fl_hide_form(fd_form_title->form_title);
2036 fl_free_form(fd_form_title->form_title);
2037 fd_form_title->form_title = 0;
2042 /* callbacks for form form_paragraph */
2044 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2046 // "Synchronize" the choices and input fields, making it
2047 // impossible to commit senseless data.
2049 FD_form_paragraph const * fp = fd_form_paragraph;
2051 if (obj == fp->choice_space_above) {
2052 if (fl_get_choice (fp->choice_space_above) != 7) {
2053 fl_set_input (fp->input_space_above, "");
2054 ActivateParagraphButtons();
2056 } else if (obj == fp->choice_space_below) {
2057 if (fl_get_choice (fp->choice_space_below) != 7) {
2058 fl_set_input (fp->input_space_below, "");
2059 ActivateParagraphButtons();
2061 } else if (obj == fp->input_space_above) {
2062 string input = fl_get_input (fp->input_space_above);
2064 if (input.empty()) {
2065 fl_set_choice (fp->choice_space_above, 1);
2066 ActivateParagraphButtons();
2068 else if (isValidGlueLength (input)) {
2069 fl_set_choice (fp->choice_space_above, 7);
2070 ActivateParagraphButtons();
2073 fl_set_choice (fp->choice_space_above, 7);
2074 DeactivateParagraphButtons();
2076 } else if (obj == fp->input_space_below) {
2077 string input = fl_get_input (fp->input_space_below);
2079 if (input.empty()) {
2080 fl_set_choice (fp->choice_space_below, 1);
2081 ActivateParagraphButtons();
2083 else if (isValidGlueLength (input)) {
2084 fl_set_choice (fp->choice_space_below, 7);
2085 ActivateParagraphButtons();
2088 fl_set_choice (fp->choice_space_below, 7);
2089 DeactivateParagraphButtons();
2095 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2097 if (!current_view->available())
2100 VSpace space_top, space_bottom;
2102 string labelwidthstring;
2105 // If a vspace kind is "Length" but there's no text in
2106 // the input field, reset the kind to "None".
2107 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2108 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2109 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2111 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2112 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2113 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2116 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2117 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2118 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2119 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2120 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2121 case 1: space_top = VSpace(VSpace::NONE); break;
2122 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2123 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2124 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2125 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2126 case 6: space_top = VSpace(VSpace::VFILL); break;
2127 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2129 if (fl_get_button (fd_form_paragraph->check_space_above))
2130 space_top.setKeep (true);
2131 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2132 case 1: space_bottom = VSpace(VSpace::NONE); break;
2133 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2134 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2135 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2136 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2137 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2138 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2140 if (fl_get_button (fd_form_paragraph->check_space_below))
2141 space_bottom.setKeep (true);
2143 if (fl_get_button(fd_form_paragraph->radio_align_left))
2144 align = LYX_ALIGN_LEFT;
2145 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2146 align = LYX_ALIGN_RIGHT;
2147 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2148 align = LYX_ALIGN_CENTER;
2150 align = LYX_ALIGN_BLOCK;
2152 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2153 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2156 if (current_view->the_locking_inset)
2157 text = current_view->the_locking_inset->getLyXText(current_view);
2159 text = current_view->text;
2160 text->SetParagraph(current_view,
2170 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2171 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2175 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2177 fl_hide_form(fd_form_paragraph->form_paragraph);
2181 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2183 ParagraphApplyCB(ob, data);
2184 ParagraphCancelCB(ob, data);
2188 /* callbacks for form form_character */
2190 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2192 // we set toggleall locally here, since it should be true for
2193 // all other uses of ToggleAndShow() (JMarc)
2194 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2195 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2196 current_view->setState();
2201 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2203 fl_hide_form(fd_form_character->form_character);
2207 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2209 CharacterApplyCB(ob, data);
2210 CharacterCloseCB(ob, data);
2214 /* callbacks for form form_document */
2216 void UpdateDocumentButtons(BufferParams const & params)
2218 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2220 switch (params.sides) {
2221 case LyXTextClass::OneSide:
2222 fl_set_button(fd_form_document->radio_sides_one, 1);
2224 case LyXTextClass::TwoSides:
2225 fl_set_button(fd_form_document->radio_sides_two, 1);
2229 if (params.columns == 2)
2230 fl_set_button(fd_form_document->radio_columns_two, 1);
2232 fl_set_button(fd_form_document->radio_columns_one, 1);
2234 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2235 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2236 params.secnumdepth);
2237 fl_set_counter_value(fd_form_document->slider_tocdepth,
2242 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2244 ProhibitInput(current_view);
2245 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2246 if (AskQuestion(_("Should I set some parameters to"),
2247 fl_get_choice_text(ob),
2248 _("the defaults of this document class?"))) {
2249 BufferParams params = BufferParams();
2250 params.textclass = fl_get_choice(ob)-1;
2251 params.useClassDefaults();
2252 UpdateLayoutDocument(¶ms);
2253 UpdateDocumentButtons(params);
2256 // unable to load new style
2257 WriteAlert(_("Conversion Errors!"),
2258 _("Unable to switch to new document class."),
2259 _("Reverting to original document class."));
2260 fl_set_choice(fd_form_document->choice_class,
2261 current_view->buffer()->params.textclass + 1);
2263 AllowInput(current_view);
2267 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2269 // "Synchronize" the choice and the input field, so that it
2270 // is impossible to commit senseless data.
2271 FD_form_document const * fd = fd_form_document;
2273 if (obj == fd->choice_default_skip) {
2274 if (fl_get_choice (fd->choice_default_skip) != 4) {
2275 fl_set_input (fd->input_default_skip, "");
2276 ActivateDocumentButtons();
2278 } else if (obj == fd->input_default_skip) {
2280 char const * input = fl_get_input (fd->input_default_skip);
2283 fl_set_choice (fd->choice_default_skip, 2);
2284 ActivateDocumentButtons();
2285 } else if (isValidGlueLength (input)) {
2286 fl_set_choice (fd->choice_default_skip, 4);
2287 ActivateDocumentButtons();
2289 fl_set_choice (fd->choice_default_skip, 4);
2290 DeactivateDocumentButtons();
2296 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2298 // "Synchronize" the choice and the input field, so that it
2299 // is impossible to commit senseless data.
2300 FD_form_document const * fd = fd_form_document;
2302 if (obj == fd->choice_spacing
2303 && fl_get_choice (fd->choice_spacing) != 4) {
2304 fl_set_input(fd->input_spacing, "");
2305 } else if (obj == fd->input_spacing) {
2307 const char* input = fl_get_input (fd->input_spacing);
2310 fl_set_choice (fd->choice_spacing, 1);
2312 fl_set_choice (fd->choice_spacing, 4);
2318 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2321 BufferParams * params = &(current_view->buffer()->params);
2323 Language const * old_language = params->language_info;
2324 params->language = combo_language->getline();
2325 Languages::iterator lit = languages.find(params->language);
2327 Language const * new_language;
2328 if (lit != languages.end())
2329 new_language = &(*lit).second;
2331 new_language = default_language;
2333 if (current_view->available()) {
2334 if (old_language != new_language
2335 && old_language->RightToLeft() == new_language->RightToLeft()
2336 && !current_view->buffer()->isMultiLingual())
2337 current_view->buffer()->ChangeLanguage(old_language,
2339 if (old_language != new_language) {
2340 //current_view->buffer()->redraw();
2344 params->language_info = new_language;
2346 // If default skip is a "Length" but there's no text in the
2347 // input field, reset the kind to "Medskip", which is the default.
2348 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2349 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2350 fl_set_choice (fd_form_document->choice_default_skip, 2);
2353 /* this shouldn't be done automatically IMO. For example I write german
2354 * documents with an american keyboard very often. Matthias */
2356 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2357 fl_get_choice(fd_form_document->choice_language)); */
2359 fl_get_choice_text(fd_form_document->choice_fonts);
2361 fl_get_choice_text(fd_form_document->choice_inputenc);
2363 fl_get_choice_text(fd_form_document->choice_fontsize);
2365 fl_get_choice_text(fd_form_document->choice_pagestyle);
2366 params->graphicsDriver =
2367 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2368 params->use_amsmath =
2369 fl_get_button(fd_form_document->check_use_amsmath);
2371 if (!current_view->available())
2374 current_view->text->SetCursor(current_view,
2375 current_view->text->cursor.par(),
2376 current_view->text->cursor.pos());
2377 current_view->setState();
2379 LyXTextClassList::ClassList::size_type new_class =
2380 fl_get_choice(fd_form_document->choice_class) - 1;
2382 if (params->textclass != new_class) {
2383 // try to load new_class
2384 if (textclasslist.Load(new_class)) {
2385 // successfully loaded
2387 current_view->owner()->getMiniBuffer()->
2388 Set(_("Converting document to new document class..."));
2390 int ret = cap.SwitchLayoutsBetweenClasses(
2391 current_view->buffer()->params.textclass,
2393 current_view->buffer()->paragraph);
2398 s = _("One paragraph couldn't be converted");
2401 s += _(" paragraphs couldn't be converted");
2403 WriteAlert(_("Conversion Errors!"), s,
2404 _("into chosen document class"));
2407 params->textclass = new_class;
2409 // problem changing class -- warn user and retain old style
2410 WriteAlert(_("Conversion Errors!"),
2411 _("Unable to switch to new document class."),
2412 _("Reverting to original document class."));
2413 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2417 char tmpsep = params->paragraph_separation;
2418 if (fl_get_button(fd_form_document->radio_indent))
2419 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2421 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2422 if (tmpsep != params->paragraph_separation)
2425 VSpace tmpdefskip = params->getDefSkip();
2426 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2427 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2428 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2429 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2430 case 4: params->setDefSkip(
2431 VSpace (LyXGlueLength (fl_get_input
2432 (fd_form_document->input_default_skip))));
2434 // DocumentDefskipCB assures that this never happens
2435 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2437 if (!(tmpdefskip == params->getDefSkip()))
2440 if (fl_get_button(fd_form_document->radio_columns_two))
2441 params->columns = 2;
2443 params->columns = 1;
2444 if (fl_get_button(fd_form_document->radio_sides_two))
2445 params->sides = LyXTextClass::TwoSides;
2447 params->sides = LyXTextClass::OneSide;
2449 Spacing tmpSpacing = params->spacing;
2450 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2452 lyxerr.debug() << "Spacing: SINGLE" << endl;
2453 params->spacing.set(Spacing::Single);
2456 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2457 params->spacing.set(Spacing::Onehalf);
2460 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2461 params->spacing.set(Spacing::Double);
2464 lyxerr.debug() << "Spacing: OTHER" << endl;
2465 params->spacing.set(Spacing::Other,
2466 fl_get_input(fd_form_document->input_spacing));
2469 if (tmpSpacing != params->spacing)
2472 signed char tmpchar =
2473 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2474 if (params->secnumdepth != tmpchar)
2476 params->secnumdepth = tmpchar;
2479 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2481 params->float_placement =
2482 fl_get_input(fd_form_document->input_float_placement);
2484 // More checking should be done to ensure the string doesn't have
2485 // spaces or illegal placement characters in it. (thornley)
2488 current_view->redoCurrentBuffer();
2490 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2491 current_view->buffer()->markDirty();
2494 fl_get_input(fd_form_document->input_extra);
2498 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2500 fl_hide_form(fd_form_document->form_document);
2504 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2506 DocumentCancelCB(ob, data);
2507 DocumentApplyCB(ob, data);
2511 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2514 // bullet callbacks etc. in bullet_panel.C -- ARRae
2518 /* callbacks for form form_quotes */
2520 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2522 if (!current_view->available())
2525 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2526 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2527 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2529 lga = InsetQuotes::EnglishQ;
2532 lga = InsetQuotes::SwedishQ;
2535 lga = InsetQuotes::GermanQ;
2538 lga = InsetQuotes::PolishQ;
2541 lga = InsetQuotes::FrenchQ;
2544 lga = InsetQuotes::DanishQ;
2547 current_view->buffer()->params.quotes_language = lga;
2548 if (fl_get_button(fd_form_quotes->radio_single))
2549 current_view->buffer()->
2550 params.quotes_times = InsetQuotes::SingleQ;
2552 current_view->buffer()->
2553 params.quotes_times = InsetQuotes::DoubleQ;
2557 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2559 fl_hide_form(fd_form_quotes->form_quotes);
2563 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2565 QuotesApplyCB(ob, data);
2566 QuotesCancelCB(ob, data);
2571 /* callbacks for form form_preamble */
2573 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2575 fl_hide_form(fd_form_preamble->form_preamble);
2579 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2581 if (!current_view->available())
2584 current_view->buffer()->params.preamble =
2585 fl_get_input(fd_form_preamble->input_preamble);
2586 current_view->buffer()->markDirty();
2587 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2591 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2593 PreambleApplyCB(ob, data);
2594 PreambleCancelCB(ob, data);
2598 /* callbacks for form form_table */
2601 void TableApplyCB(FL_OBJECT *, long)
2603 if (!current_view->available())
2607 // check for tables in tables
2608 if (current_view->text->cursor.par()->table){
2609 WriteAlert(_("Impossible Operation!"),
2610 _("Cannot insert table in table."),
2615 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2617 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2618 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2621 current_view->hideCursor();
2622 current_view->beforeChange();
2623 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2625 current_view->text->SetCursorParUndo(current_view->buffer());
2626 current_view->text->FreezeUndo();
2628 current_view->text->BreakParagraph(current_view);
2629 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2631 if (current_view->text->cursor.par()->Last()) {
2632 current_view->text->CursorLeft(current_view);
2634 current_view->text->BreakParagraph(current_view);
2635 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2638 current_view->text->current_font.setLatex(LyXFont::OFF);
2639 //if (!fl_get_button(fd_form_table->check_latex)){
2640 // insert the new wysiwy table
2641 current_view->text->SetLayout(current_view, 0); // standard layout
2643 if (current_view->text->cursor.par()->footnoteflag ==
2644 LyXParagraph::NO_FOOTNOTE) {
2647 ->SetParagraph(current_view, 0, 0,
2649 VSpace (0.3 * current_view->buffer()->
2650 params.spacing.getValue(),
2652 VSpace (0.3 * current_view->buffer()->
2653 params.spacing.getValue(),
2661 ->SetParagraph(current_view, 0, 0,
2663 VSpace(VSpace::NONE),
2664 VSpace(VSpace::NONE),
2671 current_view->text->cursor.par()->table =
2672 new LyXTable(xsize, ysize);
2674 Language const * lang =
2675 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2676 LyXFont font(LyXFont::ALL_INHERIT, lang);
2677 for (int i = 0; i < xsize * ysize - 1; ++i) {
2678 current_view->text->cursor.par()
2679 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2681 current_view->text->RedoParagraph(current_view);
2683 current_view->text->UnFreezeUndo();
2685 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2686 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2687 current_view->setState();
2692 void TableCancelCB(FL_OBJECT *, long)
2694 fl_hide_form(fd_form_table->form_table);
2699 void TableOKCB(FL_OBJECT * ob, long data)
2701 TableApplyCB(ob, data);
2702 TableCancelCB(ob, data);
2708 if (fd_form_figure->form_figure->visible) {
2709 fl_raise_form(fd_form_figure->form_figure);
2711 fl_show_form(fd_form_figure->form_figure,
2712 FL_PLACE_MOUSE, FL_FULLBORDER,
2713 _("Insert Figure"));
2720 if (fd_form_table->form_table->visible) {
2721 fl_raise_form(fd_form_table->form_table);
2723 fl_show_form(fd_form_table->form_table,
2724 FL_PLACE_MOUSE, FL_FULLBORDER,
2730 /* callbacks for form form_figure */
2732 void FigureApplyCB(FL_OBJECT *, long)
2734 if (!current_view->available())
2737 Buffer * buffer = current_view->buffer();
2738 if(buffer->isReadonly()) // paranoia
2741 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2742 if (fl_get_button(fd_form_figure->radio_inline)
2744 || current_view->text->cursor.par()->table
2747 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2748 current_view->insertInset(new_inset);
2749 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2750 new_inset->Edit(current_view, 0, 0, 0);
2754 current_view->hideCursor();
2755 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2756 current_view->beforeChange();
2758 current_view->text->SetCursorParUndo(current_view->buffer());
2759 current_view->text->FreezeUndo();
2761 current_view->text->BreakParagraph(current_view);
2762 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2764 if (current_view->text->cursor.par()->Last()) {
2765 current_view->text->CursorLeft(current_view);
2767 current_view->text->BreakParagraph(current_view);
2768 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2771 // The standard layout should always be numer 0;
2772 current_view->text->SetLayout(current_view, 0);
2775 if (current_view->text->cursor.par()->footnoteflag ==
2776 LyXParagraph::NO_FOOTNOTE) {
2778 current_view->text->
2779 SetParagraph(current_view, 0, 0,
2781 VSpace (0.3 * buffer->params.spacing.getValue(),
2784 buffer->params.spacing.getValue(),
2786 LYX_ALIGN_CENTER, string(), 0);
2789 current_view->text->SetParagraph(current_view, 0, 0,
2791 VSpace(VSpace::NONE),
2792 VSpace(VSpace::NONE),
2799 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2801 Inset * new_inset = new InsetFig(100, 100, buffer);
2802 current_view->insertInset(new_inset);
2803 new_inset->Edit(current_view, 0, 0, 0);
2804 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2805 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2806 current_view->text->UnFreezeUndo();
2807 current_view->setState();
2811 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2813 fl_hide_form(fd_form_figure->form_figure);
2817 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2819 FigureApplyCB(ob, data);
2820 FigureCancelCB(ob, data);
2824 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2826 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2827 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2828 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2829 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2830 lyxrc.set_font_norm_type();
2831 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2832 fontloader.update();
2834 // Of course we should only to the resize and the textcahce.clear
2835 // if values really changed...but not very important right now. (Lgb)
2837 // All buffers will need resize
2838 bufferlist.resize();
2839 // We also need to empty the textcache so that
2840 // the buffer will be formatted correctly after
2844 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2848 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2850 fl_hide_form(fd_form_screen->form_screen);
2854 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2856 ScreenCancelCB(ob, data);
2857 ScreenApplyCB(ob, data);
2861 // This function runs "configure" and then rereads lyx.defaults to
2862 // reconfigure the automatic settings.
2863 void Reconfigure(BufferView * bv)
2865 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2867 // Run configure in user lyx directory
2868 Path p(user_lyxdir);
2869 Systemcalls one(Systemcalls::System,
2870 AddName(system_lyxdir, "configure"));
2872 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2873 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2874 WriteAlert(_("The system has been reconfigured."),
2875 _("You need to restart LyX to make use of any"),
2876 _("updated document class specifications."));