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 bool 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 bool 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.)"))) {
199 return MenuWriteAs(buffer);
203 lastfiles->newFile(buffer->fileName());
209 // should be moved to BufferView.C
210 // Half of this func should be in LyXView, the rest in BufferView.
211 bool MenuWriteAs(Buffer * buffer)
213 // Why do we require BufferView::text to be able to write a
214 // document? I see no point in that. (Lgb)
215 //if (!bv->text) return;
217 string fname = buffer->fileName();
218 string oldname = fname;
221 ProhibitInput(current_view);
222 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
223 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
225 if (!IsLyXFilename(fname))
228 if (buffer->isUnnamed()) {
229 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
234 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
237 OnlyFilename(fname));
239 AllowInput(current_view);
244 // Make sure the absolute filename ends with appropriate suffix
245 string s = MakeAbsPath(fname);
246 if (!IsLyXFilename(s))
249 // Same name as we have already?
251 if (!AskQuestion(_("Same name as document already has:"),
252 MakeDisplayPath(s, 50),
255 // Falls through to name change and save
257 // No, but do we have another file with this name open?
258 else if (bufferlist.exists(s)) {
259 if (AskQuestion(_("Another document with same name open!"),
260 MakeDisplayPath(s, 50),
261 _("Replace with current document?")))
263 bufferlist.close(bufferlist.getBuffer(s));
265 // Ok, change the name of the buffer, but don't save!
269 ShowMessage(buffer, _("Document renamed to '"),
270 MakeDisplayPath(s), _("', but not saved..."));
273 } // Check whether the file exists
276 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
277 MakeDisplayPath(s, 50),
282 // Ok, change the name of the buffer
285 bool unnamed = buffer->isUnnamed();
286 buffer->setUnnamed(false);
288 // Small bug: If the save fails, we have irreversible changed the name
290 // Hope this is fixed this way! (Jug)
291 if (!MenuWrite(buffer)) {
292 buffer->fileName(oldname);
293 buffer->setUnnamed(unnamed);
294 ShowMessage(buffer, _("Document could not be saved!"),
295 _("Holding the old name."), MakeDisplayPath(oldname));
298 // now remove the oldname autosave file if existant!
299 removeAutosaveFile(oldname);
304 int MenuRunLaTeX(Buffer * buffer)
308 if (buffer->isLinuxDoc())
309 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
310 else if (buffer->isLiterate())
311 ret = buffer->runLiterate();
312 else if (buffer->isDocBook())
313 ret = RunDocBook(1, buffer->fileName());
315 ret = buffer->runLaTeX();
321 s = _("One error detected");
322 t = _("You should try to fix it.");
325 s += _(" errors detected.");
326 t = _("You should try to fix them.");
328 WriteAlert(_("There were errors during the LaTeX run."), s, t);
334 int MenuBuildProg(Buffer * buffer)
338 if (buffer->isLiterate())
339 ret = buffer->buildProgram();
341 string s = _("Wrong type of document");
342 string t = _("The Build operation is not allowed in this document");
343 WriteAlert(_("There were errors during the Build process."), s, t);
351 s = _("One error detected");
352 t = _("You should try to fix it.");
355 s += _(" errors detected.");
356 t = _("You should try to fix them.");
358 WriteAlert(_("There were errors during the Build process."), s, t);
364 int MenuRunChktex(Buffer * buffer)
368 if (buffer->isSGML()) {
369 WriteAlert(_("Chktex does not work with SGML derived documents."));
372 ret = buffer->runChktex();
378 s = _("No warnings found.");
379 } else if (ret == 1) {
380 s = _("One warning found.");
381 t = _("Use 'Edit->Go to Error' to find it.");
384 s += _(" warnings found.");
385 t = _("Use 'Edit->Go to Error' to find them.");
387 WriteAlert(_("Chktex run successfully"), s, t);
389 WriteAlert(_("Error!"), _("It seems chktex does not work."));
395 int MakeLaTeXOutput(Buffer * buffer)
401 string path = OnlyPath(buffer->fileName());
402 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
403 path = buffer->tmppath;
407 ret = MenuRunLaTeX(buffer);
413 /* wait == false means don't wait for termination */
414 /* wait == true means wait for termination */
415 // The bool should be placed last on the argument line. (Lgb)
416 // Returns false if we fail.
417 bool RunScript(Buffer * buffer, bool wait,
418 string const & command,
419 string const & orgname = string(),
420 bool need_shell = true)
424 string name = orgname;
427 if (MakeLaTeXOutput(buffer) > 0)
429 /* get DVI-Filename */
431 name = ChangeExtension(buffer->getLatexName(), ".dvi");
433 path = OnlyPath(name);
434 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
435 path = buffer->tmppath;
438 // At this point we check whether the command contains the
439 // filename parameter $$FName and if that's the case we
440 // substitute the real file name otherwise the filename is
441 // simply appended. rokrau 1/12/00
444 if ( (i=command.find("$$FName")) != string::npos)
446 cmd.replace(i,7,QuoteName(name));
449 cmd = command + ' ' + QuoteName(name);
458 // OS/2 cmd.exe has another use for '&'
460 // This is not NLS safe, but it's OK, I think.
461 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
463 // COMSPEC is set, unless user unsets
464 sh = OnlyFilename(GetEnvPath("COMSPEC"));
469 if (contains(sh, "cmd.exe")
470 || contains(sh, "4os2.exe"))
471 cmd = "start /min/n " + cmd;
476 // It seems that, if wait is false, we never get back
477 // the return code of the command. This means that all
478 // the code I added in PrintApplyCB is currently
480 // CHECK What should we do here?
481 ShowMessage(buffer, _("Executing command:"), cmd);
482 result = one.startscript(Systemcalls::System, cmd);
484 ShowMessage(buffer, _("Executing command:"), cmd);
485 result = one.startscript(wait ? Systemcalls::Wait
486 : Systemcalls::DontWait, cmd);
492 // Returns false if we fail
493 bool CreatePostscript(Buffer * buffer, bool wait = false)
499 ProhibitInput(current_view);
502 if (MakeLaTeXOutput(buffer) > 0) {
503 AllowInput(current_view);
506 // Generate postscript file
507 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
513 char real_papersize = buffer->params.papersize;
514 if (real_papersize == BufferParams::PAPER_DEFAULT)
515 real_papersize = lyxrc.default_papersize;
517 switch (real_papersize) {
518 case BufferParams::PAPER_USLETTER:
521 case BufferParams::PAPER_A3PAPER:
524 case BufferParams::PAPER_A4PAPER:
527 case BufferParams::PAPER_A5PAPER:
530 case BufferParams::PAPER_B5PAPER:
533 case BufferParams::PAPER_EXECUTIVEPAPER:
536 case BufferParams::PAPER_LEGALPAPER:
539 default: /* If nothing else fits, keep an empty value... */
543 // Make postscript file.
544 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
545 command += QuoteName(psname);
546 if (buffer->params.use_geometry
547 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
548 && !lyxrc.print_paper_dimension_flag.empty()
549 && !buffer->params.paperwidth.empty()
550 && !buffer->params.paperheight.empty()) {
551 // using a custom papersize
553 command += lyxrc.print_paper_dimension_flag + ' ';
554 command += buffer->params.paperwidth + ',';
555 command += buffer->params.paperheight;
556 } else if (!paper.empty()
557 && (real_papersize != BufferParams::PAPER_USLETTER ||
558 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
559 // dvips won't accept -t letter -t landscape. In all other
560 // cases, include the paper size explicitly.
562 command += lyxrc.print_paper_flag + ' ' + paper;
564 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
566 command += lyxrc.print_landscape_flag;
568 // push directorypath, if necessary
569 string path = OnlyPath(buffer->fileName());
570 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
571 path = buffer->tmppath;
574 bool ret = RunScript(buffer, wait, command);
575 AllowInput(current_view);
580 // Returns false if we fail
581 //bool MenuPreviewPS(Buffer * buffer)
582 bool PreviewPostscript(Buffer * buffer)
588 // Generate postscript file
589 if (!CreatePostscript(buffer, true)) {
593 // Start postscript viewer
594 ProhibitInput(current_view);
595 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
597 // push directorypath, if necessary
598 string path = OnlyPath(buffer->fileName());
599 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
600 path = buffer->tmppath;
603 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
604 AllowInput(current_view);
609 void MenuFax(Buffer * buffer)
615 // Generate postscript file
616 if (!CreatePostscript(buffer, true)) {
621 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
623 string path = OnlyPath (buffer->fileName());
624 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
625 path = buffer->tmppath;
628 if (!lyxrc.fax_program.empty()) {
629 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
631 Systemcalls one(Systemcalls::System, help2);
633 send_fax(ps, lyxrc.fax_command);
637 // Returns false if we fail
638 bool PreviewDVI(Buffer * buffer)
644 string paper = lyxrc.view_dvi_paper_option;
645 if (!paper.empty()) {
647 char real_papersize = buffer->params.papersize;
648 if (real_papersize == BufferParams::PAPER_DEFAULT)
649 real_papersize = lyxrc.default_papersize;
651 switch (real_papersize) {
652 case BufferParams::PAPER_USLETTER:
655 case BufferParams::PAPER_A3PAPER:
658 case BufferParams::PAPER_A4PAPER:
661 case BufferParams::PAPER_A5PAPER:
664 case BufferParams::PAPER_B5PAPER:
667 case BufferParams::PAPER_EXECUTIVEPAPER:
668 paper += " foolscap";
670 case BufferParams::PAPER_LEGALPAPER:
673 default: /* If nothing else fits, keep the empty value */
676 if (real_papersize==' ') {
677 // if (paper.empty()) {
678 if (buffer->params.orientation
679 == BufferParams::ORIENTATION_LANDSCAPE)
680 // we HAVE to give a size when the page is in
681 // landscape, so use USletter.
682 paper = " -paper usr";
684 // paper = " -paper " + paper;
685 if (buffer->params.orientation
686 == BufferParams::ORIENTATION_LANDSCAPE)
690 // push directorypath, if necessary
691 string path = OnlyPath(buffer->fileName());
692 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
693 path = buffer->tmppath;
697 string command = lyxrc.view_dvi_command + " " + paper;
698 bool ret = RunScript(buffer, false, command);
703 bool AskOverwrite(Buffer * buffer, string const & s)
706 // be friendly if there is a gui
709 !AskQuestion(_("File already exists:"),
710 MakeDisplayPath(s, 50),
711 _("Do you want to overwrite the file?"))) {
712 ShowMessage(buffer, _("Canceled"));
720 void MenuMakeLaTeX(Buffer * buffer)
722 // Why care about this?
726 // Get LaTeX-Filename
727 string s = buffer->getLatexName(false);
729 if (!AskOverwrite(buffer, s))
732 if (buffer->isDocBook())
733 ShowMessage(buffer, _("DocBook does not have a latex backend"));
735 if (buffer->isLinuxDoc())
736 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
738 buffer->makeLaTeXFile(s, string(), true);
739 ShowMessage(buffer, _("Nice LaTeX file saved as"),
745 void MenuMakeLinuxDoc(Buffer * buffer)
748 //if (!bv->text) return;
750 if (!buffer->isLinuxDoc()) {
751 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
755 // Get LinuxDoc-Filename
756 string s = ChangeExtension(buffer->fileName(), ".sgml");
758 if (!AskOverwrite(buffer, s))
761 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
762 MakeDisplayPath(s),"'...");
764 buffer->makeLinuxDocFile(s, true);
766 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
771 void MenuMakeDocBook(Buffer * buffer)
774 //if (!bv->text) return;
776 if (!buffer->isDocBook()) {
777 WriteAlert(_("Error!"),
778 _("Document class must be docbook."));
782 // Get DocBook-Filename
783 string s = ChangeExtension(buffer->fileName(), ".sgml");
785 if (!AskOverwrite(buffer, s))
788 ShowMessage(buffer, _("Building DocBook SGML file `"),
789 MakeDisplayPath(s), "'...");
791 buffer->makeDocBookFile(s, true);
793 ShowMessage(buffer, _("DocBook SGML file save as"),
798 void MenuMakeAscii(Buffer * buffer)
801 //if (!bv->text) return;
803 /* get LaTeX-Filename */
804 string s = ChangeExtension (buffer->fileName(), ".txt");
807 if (!AskOverwrite(buffer, s))
810 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
812 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
816 void MenuMakeHTML(Buffer * buffer)
818 // First, create LaTeX file
819 MenuMakeLaTeX(buffer);
821 // And now, run the converter
822 string file = buffer->fileName();
823 Path path(OnlyPath(file));
824 // the tex file name has to be correct for
825 // latex, but the html file name can be
827 string result = ChangeExtension(file, ".html");
828 string infile = buffer->getLatexName(false);
829 string tmp = lyxrc.html_command;
830 tmp = subst(tmp, "$$FName", infile);
831 tmp = subst(tmp, "$$OutName", result);
833 int res = one.startscript(Systemcalls::System, tmp);
835 ShowMessage(buffer, _("Document exported as HTML to file `")
836 + MakeDisplayPath(result) +'\'');
838 ShowMessage(buffer, _("Unable to convert to HTML the file `")
839 + MakeDisplayPath(infile)
846 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
848 // First, create LinuxDoc file
849 MenuMakeLinuxDoc(buffer);
851 // And now, run the converter
852 string file = buffer->fileName();
854 string result = ChangeExtension(file, ".html");
855 string infile = ChangeExtension(file, ".sgml");
856 string tmp = lyxrc.linuxdoc_to_html_command;
857 tmp = subst(tmp, "$$FName", infile);
858 tmp = subst(tmp, "$$OutName", result);
860 int res = one.startscript(Systemcalls::System, tmp);
862 ShowMessage(buffer,_("Document exported as HTML to file `")
863 + MakeDisplayPath(result) +'\'');
865 ShowMessage(buffer,_("Unable to convert to HTML the file `")
866 + MakeDisplayPath(infile)
872 void MenuMakeHTML_DocBook(Buffer * buffer)
874 // First, create LaTeX file
875 MenuMakeDocBook(buffer);
877 // And now, run the converter
878 string file = buffer->fileName();
879 string result = ChangeExtension(file, ".html");
880 string infile = ChangeExtension(file, ".sgml");
881 string tmp = lyxrc.docbook_to_html_command;
882 tmp = subst(tmp, "$$FName", infile);
883 tmp = subst(tmp, "$$OutName", result);
885 int res = one.startscript(Systemcalls::System, tmp);
887 ShowMessage(buffer,_("Document exported as HTML to file `")
888 + MakeDisplayPath(result) +'\'');
890 ShowMessage(buffer,_("Unable to convert to HTML the file `")
891 + MakeDisplayPath(infile)
898 void MenuExport(Buffer * buffer, string const & extyp)
901 if (extyp == "latex") {
902 // make sure that this buffer is not linuxdoc
903 MenuMakeLaTeX(buffer);
906 else if (extyp == "linuxdoc") {
907 // make sure that this buffer is not latex
908 MenuMakeLinuxDoc(buffer);
911 else if (extyp == "docbook") {
912 // make sure that this buffer is not latex or linuxdoc
913 MenuMakeDocBook(buffer);
916 else if (extyp == "dvi") {
917 // Run LaTeX as "Update dvi..." Bernhard.
918 // We want the dvi in the current directory. This
919 // is achieved by temporarily disabling use of
920 // temp directory. As a side-effect, we get
921 // *.log and *.aux files also. (Asger)
922 bool flag = lyxrc.use_tempdir;
923 lyxrc.use_tempdir = false;
924 MenuRunLaTeX(buffer);
925 lyxrc.use_tempdir = flag;
928 else if (extyp == "postscript") {
929 // Start Print-dialog. Not as good as dvi... Bernhard.
930 //should start lyxview->getDialogs()->showPrint();
931 // to get same as before
932 // MenuPrint(buffer);
933 // Since the MenuPrint is a pop-up, we can't use
934 // the same trick as above. (Asger)
935 // MISSING: Move of ps-file :-(
936 // And MenuPrint should not be used for this at all...
939 else if (extyp == "ascii") {
940 MenuMakeAscii(buffer);
942 else if (extyp == "custom") {
946 else if (extyp == "html") {
947 if (buffer->isLinuxDoc())
948 MenuMakeHTML_LinuxDoc(buffer);
949 else if (buffer->isDocBook())
950 MenuMakeHTML_DocBook(buffer);
952 MenuMakeHTML(buffer);
955 ShowMessage(buffer, _("Unknown export type: ") + extyp);
962 lyxerr.debug() << "Running QuitLyX." << endl;
964 if (!bufferlist.QwriteAll())
967 lastfiles->writeFile(lyxrc.lastfiles);
969 // Set a flag that we do quitting from the program,
970 // so no refreshes are necessary.
973 // close buffers first
974 bufferlist.closeAll();
976 // do any other cleanup procedures now
977 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
979 DestroyLyXTmpDir(system_tempdir);
986 void AutoSave(BufferView * bv)
987 // should probably be moved into BufferList (Lgb)
988 // Perfect target for a thread...
990 if (!bv->available())
993 if (bv->buffer()->isBakClean() || bv->buffer()->isReadonly()) {
994 // We don't save now, but we'll try again later
995 bv->owner()->resetAutosaveTimer();
999 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1001 // create autosave filename
1002 string fname = OnlyPath(bv->buffer()->fileName());
1004 fname += OnlyFilename(bv->buffer()->fileName());
1007 // tmp_ret will be located (usually) in /tmp
1008 // will that be a problem?
1009 string tmp_ret = tmpnam(0);
1011 pid_t pid = fork(); // If you want to debug the autosave
1012 // you should set pid to -1, and comment out the
1014 if (pid == 0 || pid == -1) {
1015 // pid = -1 signifies that lyx was unable
1016 // to fork. But we will do the save
1018 bool failed = false;
1019 if (!tmp_ret.empty()) {
1020 bv->buffer()->writeFile(tmp_ret, 1);
1021 // assume successful write of tmp_ret
1022 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1024 // most likely couldn't move between filesystems
1025 // unless write of tmp_ret failed
1026 // so remove tmp file (if it exists)
1027 remove(tmp_ret.c_str());
1034 // failed to write/rename tmp_ret so try writing direct
1035 if (!bv->buffer()->writeFile(fname, 1)) {
1036 // It is dangerous to do this in the child,
1037 // but safe in the parent, so...
1039 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1042 if (pid == 0) { // we are the child so...
1047 bv->buffer()->markBakClean();
1048 bv->owner()->resetAutosaveTimer();
1053 // Copyright CHT Software Service GmbH
1056 // create new file with template
1059 Buffer * NewLyxFile(string const & filename)
1061 // Split argument by :
1063 string tmpname = split(filename, name, ':');
1064 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1065 if (name.length() == 1
1066 && isalpha(static_cast<unsigned char>(name[0]))
1067 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1069 name += token(tmpname, ':', 0);
1070 tmpname = split(tmpname, ':');
1073 lyxerr.debug() << "Arg is " << filename
1074 << "\nName is " << name
1075 << "\nTemplate is " << tmpname << endl;
1077 // find a free buffer
1078 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1080 lastfiles->newFile(tmpbuf->fileName());
1085 // Insert ascii file (if filename is empty, prompt for one)
1086 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1091 if (!bv->available()) return;
1093 if (fname.empty()) {
1095 fname = fileDlg.Select(_("File to Insert"),
1096 bv->owner()->buffer()->filepath,
1099 if (fname.empty()) return;
1104 if (!fi.readable()) {
1105 WriteFSAlert(_("Error! Specified file is unreadable: "),
1106 MakeDisplayPath(fname, 50));
1110 ifstream ifs(fname.c_str());
1112 WriteFSAlert(_("Error! Cannot open specified file: "),
1113 MakeDisplayPath(fname, 50));
1117 ifs.unsetf(ios::skipws);
1118 istream_iterator<char> ii(ifs);
1119 istream_iterator<char> end;
1120 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1121 // We use this until the compilers get better...
1123 copy(ii, end, back_inserter(tmp));
1124 string tmpstr(tmp.begin(), tmp.end());
1126 // This is what we want to use and what we will use once the
1127 // compilers get good enough.
1128 //string tmpstr(ii, end); // yet a reason for using std::string
1129 // alternate approach to get the file into a string:
1131 copy(ii, end, back_inserter(tmpstr));
1133 // insert the string
1134 current_view->hideCursor();
1136 // clear the selection
1139 bv->text->InsertStringA(bv, tmpstr);
1141 bv->text->InsertStringB(bv, tmpstr);
1142 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1146 void MenuInsertLabel(char const * arg)
1149 ProhibitInput(current_view);
1150 if (label.empty()) {
1152 result = askForText(_("Enter new label to insert:"));
1154 label = frontStrip(strip(result.second));
1157 if (!label.empty()) {
1158 InsetCommandParams p( "label", label );
1159 InsetLabel * inset = new InsetLabel( p );
1160 current_view->insertInset( inset );
1162 AllowInput(current_view);
1166 // candidate for move to LyXView
1167 // This is only used in toolbar.C
1168 void LayoutsCB(int sel, void *)
1170 string tmp = tostr(sel);
1171 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1177 * SGML Linuxdoc support:
1178 * (flag == 0) make TeX output
1179 * (flag == 1) make dvi output
1181 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1188 /* generate a path-less extension name */
1189 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1190 string path = OnlyPath (filename);
1191 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1192 path = bv->buffer()->tmppath;
1196 if (!bv->available())
1198 bv->buffer()->makeLinuxDocFile(name, false);
1200 // CHECK remove this once we have a proper geometry class
1202 BufferParams::PAPER_SIZE ps =
1203 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1205 case BufferParams::PAPER_A4PAPER:
1206 add_flags = "-p a4";
1208 case BufferParams::PAPER_USLETTER:
1209 add_flags = "-p letter";
1211 default: /* nothing to be done yet ;-) */ break;
1218 case 0: /* TeX output asked */
1219 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1220 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1221 if (one.startscript(Systemcalls::System, s2))
1224 case 1: /* dvi output asked */
1225 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1226 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1227 if (one.startscript(Systemcalls::System, s2)) {
1231 default: /* unknown output */
1237 bv->buffer()->redraw();
1243 * SGML DocBook support:
1244 * (flag == 1) make dvi output
1246 int RunDocBook(int flag, string const & filename)
1248 /* generate a path-less extension name */
1249 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1250 string path = OnlyPath (filename);
1251 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1252 path = current_view->buffer()->tmppath;
1256 if (!current_view->available())
1259 current_view->buffer()->makeDocBookFile(name, false);
1261 // Shall this code go or should it stay? (Lgb)
1262 // This code is a placeholder for future implementation. (Jose')
1263 // string add_flags;
1264 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1266 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1267 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1268 // default: /* nothing to be done yet ;-) */ break;
1270 ProhibitInput(current_view);
1275 case 1: /* dvi output asked */
1277 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1278 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1279 if (one.startscript(Systemcalls::System, s2)) {
1284 default: /* unknown output */
1288 AllowInput(current_view);
1290 current_view->buffer()->redraw();
1295 void MenuLayoutCharacter()
1297 static int ow = -1, oh;
1299 if (fd_form_character->form_character->visible) {
1300 fl_raise_form(fd_form_character->form_character);
1302 fl_show_form(fd_form_character->form_character,
1303 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1304 _("Character Style"));
1306 ow = fd_form_character->form_character->w;
1307 oh = fd_form_character->form_character->h;
1309 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1315 void DeactivateParagraphButtons ()
1317 fl_deactivate_object (fd_form_paragraph->button_ok);
1318 fl_deactivate_object (fd_form_paragraph->button_apply);
1319 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1320 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1325 void ActivateParagraphButtons ()
1327 fl_activate_object (fd_form_paragraph->button_ok);
1328 fl_activate_object (fd_form_paragraph->button_apply);
1329 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1330 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1335 void DisableParagraphLayout ()
1337 DeactivateParagraphButtons();
1338 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1339 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1340 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1341 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1342 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1343 fl_deactivate_object (fd_form_paragraph->check_noindent);
1344 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1345 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1346 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1347 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1348 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1349 fl_deactivate_object (fd_form_paragraph->input_space_above);
1350 fl_deactivate_object (fd_form_paragraph->input_space_below);
1351 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1352 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1353 fl_deactivate_object (fd_form_paragraph->check_space_above);
1354 fl_deactivate_object (fd_form_paragraph->check_space_below);
1359 void EnableParagraphLayout ()
1361 ActivateParagraphButtons();
1362 fl_activate_object (fd_form_paragraph->input_labelwidth);
1363 fl_activate_object (fd_form_paragraph->check_lines_top);
1364 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1365 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1366 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1367 fl_activate_object (fd_form_paragraph->check_noindent);
1368 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1369 fl_activate_object (fd_form_paragraph->radio_align_right);
1370 fl_activate_object (fd_form_paragraph->radio_align_left);
1371 fl_activate_object (fd_form_paragraph->radio_align_block);
1372 fl_activate_object (fd_form_paragraph->radio_align_center);
1373 fl_activate_object (fd_form_paragraph->input_space_above);
1374 fl_activate_object (fd_form_paragraph->input_space_below);
1375 fl_activate_object (fd_form_paragraph->choice_space_above);
1376 fl_activate_object (fd_form_paragraph->choice_space_below);
1377 fl_activate_object (fd_form_paragraph->check_space_above);
1378 fl_activate_object (fd_form_paragraph->check_space_below);
1382 bool UpdateLayoutParagraph()
1384 if (!current_view->available()) {
1385 if (fd_form_paragraph->form_paragraph->visible)
1386 fl_hide_form(fd_form_paragraph->form_paragraph);
1390 Buffer * buf = current_view->buffer();
1392 if (current_view->the_locking_inset)
1393 text = current_view->the_locking_inset->getLyXText(current_view);
1395 text = current_view->text;
1397 fl_set_input(fd_form_paragraph->input_labelwidth,
1398 text->cursor.par()->GetLabelWidthString().c_str());
1399 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1400 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1401 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1402 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1404 int align = text->cursor.par()->GetAlign();
1405 if (align == LYX_ALIGN_LAYOUT)
1406 align = textclasslist.Style(buf->params.textclass,
1407 text->cursor.par()->GetLayout()).align;
1410 case LYX_ALIGN_RIGHT:
1411 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1413 case LYX_ALIGN_LEFT:
1414 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1416 case LYX_ALIGN_CENTER:
1417 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1420 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1425 fl_set_button(fd_form_paragraph->check_lines_top,
1426 text->cursor.par()->FirstPhysicalPar()->line_top);
1428 fl_set_button(fd_form_paragraph->check_lines_bottom,
1429 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1431 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1432 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1434 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1435 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1436 fl_set_button(fd_form_paragraph->check_noindent,
1437 text->cursor.par()->FirstPhysicalPar()->noindent);
1439 fl_set_button(fd_form_paragraph->check_lines_top,
1440 text->cursor.par()->line_top);
1441 fl_set_button(fd_form_paragraph->check_lines_bottom,
1442 text->cursor.par()->line_bottom);
1443 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1444 text->cursor.par()->pagebreak_top);
1445 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1446 text->cursor.par()->pagebreak_bottom);
1447 fl_set_button(fd_form_paragraph->check_noindent,
1448 text->cursor.par()->noindent);
1450 fl_set_input (fd_form_paragraph->input_space_above, "");
1453 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1455 switch (text->cursor.par()->added_space_top.kind()) {
1459 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1461 case VSpace::DEFSKIP:
1462 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1464 case VSpace::SMALLSKIP:
1465 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1467 case VSpace::MEDSKIP:
1468 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1470 case VSpace::BIGSKIP:
1471 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1474 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1476 case VSpace::LENGTH:
1477 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1479 fl_set_input (fd_form_paragraph->input_space_above,
1480 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1482 fl_set_input (fd_form_paragraph->input_space_above,
1483 text->cursor.par()->added_space_top.length().asString().c_str());
1488 fl_set_button (fd_form_paragraph->check_space_above,
1489 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1490 fl_set_input (fd_form_paragraph->input_space_below, "");
1491 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1493 fl_set_button (fd_form_paragraph->check_space_above,
1494 text->cursor.par()->added_space_top.keep());
1495 fl_set_input (fd_form_paragraph->input_space_below, "");
1496 switch (text->cursor.par()->added_space_bottom.kind()) {
1499 fl_set_choice (fd_form_paragraph->choice_space_below,
1502 case VSpace::DEFSKIP:
1503 fl_set_choice (fd_form_paragraph->choice_space_below,
1506 case VSpace::SMALLSKIP:
1507 fl_set_choice (fd_form_paragraph->choice_space_below,
1510 case VSpace::MEDSKIP:
1511 fl_set_choice (fd_form_paragraph->choice_space_below,
1514 case VSpace::BIGSKIP:
1515 fl_set_choice (fd_form_paragraph->choice_space_below,
1519 fl_set_choice (fd_form_paragraph->choice_space_below,
1522 case VSpace::LENGTH:
1523 fl_set_choice (fd_form_paragraph->choice_space_below,
1526 fl_set_input (fd_form_paragraph->input_space_below,
1527 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1530 fl_set_button (fd_form_paragraph->check_space_below,
1531 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1533 fl_set_button(fd_form_paragraph->check_noindent,
1534 text->cursor.par()->FirstPhysicalPar()->noindent);
1536 fl_set_input (fd_form_paragraph->input_space_below,
1537 text->cursor.par()->added_space_bottom.length().asString().c_str());
1540 fl_set_button (fd_form_paragraph->check_space_below,
1541 text->cursor.par()->added_space_bottom.keep());
1543 fl_set_button(fd_form_paragraph->check_noindent,
1544 text->cursor.par()->noindent);
1546 if (current_view->buffer()->isReadonly()) {
1547 DisableParagraphLayout();
1549 EnableParagraphLayout();
1555 void MenuLayoutParagraph()
1557 if (UpdateLayoutParagraph()) {
1558 if (fd_form_paragraph->form_paragraph->visible) {
1559 fl_raise_form(fd_form_paragraph->form_paragraph);
1561 fl_show_form(fd_form_paragraph->form_paragraph,
1562 FL_PLACE_MOUSE, FL_FULLBORDER,
1563 _("Paragraph Environment"));
1570 void DeactivateDocumentButtons ()
1572 fl_deactivate_object (fd_form_document->button_ok);
1573 fl_deactivate_object (fd_form_document->button_apply);
1574 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1575 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1580 void ActivateDocumentButtons ()
1582 fl_activate_object (fd_form_document->button_ok);
1583 fl_activate_object (fd_form_document->button_apply);
1584 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1585 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1590 void DisableDocumentLayout ()
1592 DeactivateDocumentButtons ();
1593 fl_deactivate_object (fd_form_document->group_radio_separation);
1594 fl_deactivate_object (fd_form_document->radio_indent);
1595 fl_deactivate_object (fd_form_document->radio_skip);
1596 fl_deactivate_object (fd_form_document->choice_class);
1597 fl_deactivate_object (fd_form_document->choice_pagestyle);
1598 fl_deactivate_object (fd_form_document->choice_fonts);
1599 fl_deactivate_object (fd_form_document->choice_fontsize);
1600 fl_deactivate_object (fd_form_document->input_float_placement);
1601 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1602 fl_deactivate_object (fd_form_document->choice_inputenc);
1603 fl_deactivate_object (fd_form_document->group_radio_sides);
1604 fl_deactivate_object (fd_form_document->radio_sides_one);
1605 fl_deactivate_object (fd_form_document->radio_sides_two);
1606 fl_deactivate_object (fd_form_document->group_radio_columns);
1607 fl_deactivate_object (fd_form_document->radio_columns_one);
1608 fl_deactivate_object (fd_form_document->radio_columns_two);
1609 fl_deactivate_object (fd_form_document->input_extra);
1610 fl_deactivate_object (fd_form_document->choice_language);
1611 combo_language->deactivate();
1612 fl_deactivate_object (fd_form_document->input_default_skip);
1613 fl_deactivate_object (fd_form_document->choice_default_skip);
1614 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1615 fl_deactivate_object (fd_form_document->slider_tocdepth);
1616 fl_deactivate_object (fd_form_document->choice_spacing);
1617 fl_deactivate_object (fd_form_document->input_spacing);
1618 fl_deactivate_object (fd_form_document->check_use_amsmath);
1623 void EnableDocumentLayout ()
1625 ActivateDocumentButtons ();
1626 fl_activate_object (fd_form_document->group_radio_separation);
1627 fl_activate_object (fd_form_document->radio_indent);
1628 fl_activate_object (fd_form_document->radio_skip);
1629 fl_activate_object (fd_form_document->choice_class);
1630 fl_activate_object (fd_form_document->choice_pagestyle);
1631 fl_activate_object (fd_form_document->choice_fonts);
1632 fl_activate_object (fd_form_document->choice_fontsize);
1633 fl_activate_object (fd_form_document->input_float_placement);
1634 fl_activate_object (fd_form_document->choice_postscript_driver);
1635 fl_activate_object (fd_form_document->choice_inputenc);
1636 fl_activate_object (fd_form_document->group_radio_sides);
1637 fl_activate_object (fd_form_document->radio_sides_one);
1638 fl_activate_object (fd_form_document->radio_sides_two);
1639 fl_activate_object (fd_form_document->group_radio_columns);
1640 fl_activate_object (fd_form_document->radio_columns_one);
1641 fl_activate_object (fd_form_document->radio_columns_two);
1642 fl_activate_object (fd_form_document->input_extra);
1643 fl_activate_object (fd_form_document->choice_language);
1644 combo_language->activate();
1645 fl_activate_object (fd_form_document->input_default_skip);
1646 fl_activate_object (fd_form_document->choice_default_skip);
1647 fl_activate_object (fd_form_document->slider_secnumdepth);
1648 fl_activate_object (fd_form_document->slider_tocdepth);
1649 fl_activate_object (fd_form_document->choice_spacing);
1650 fl_activate_object (fd_form_document->input_spacing);
1651 fl_activate_object (fd_form_document->check_use_amsmath);
1655 bool UpdateLayoutDocument(BufferParams * params)
1657 if (!current_view->available()) {
1658 if (fd_form_document->form_document->visible)
1659 fl_hide_form(fd_form_document->form_document);
1664 params = ¤t_view->buffer()->params;
1665 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1667 fl_set_choice_text(fd_form_document->choice_class,
1668 textclasslist.DescOfClass(params->textclass).c_str());
1669 combo_language->select_text(params->language.c_str());
1671 fl_set_choice_text(fd_form_document->choice_fonts,
1672 params->fonts.c_str());
1673 fl_set_choice_text(fd_form_document->choice_inputenc,
1674 params->inputenc.c_str());
1675 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1676 params->graphicsDriver.c_str());
1678 // ale970405+lasgoutt970513
1679 fl_clear_choice(fd_form_document->choice_fontsize);
1680 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1681 fl_addto_choice(fd_form_document->choice_fontsize,
1682 tclass.opt_fontsize().c_str());
1683 fl_set_choice(fd_form_document->choice_fontsize,
1684 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1686 // ale970405+lasgoutt970513
1687 fl_clear_choice(fd_form_document->choice_pagestyle);
1688 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1689 fl_addto_choice(fd_form_document->choice_pagestyle,
1690 tclass.opt_pagestyle().c_str());
1692 fl_set_choice(fd_form_document->choice_pagestyle,
1693 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1695 fl_set_button(fd_form_document->radio_indent, 0);
1696 fl_set_button(fd_form_document->radio_skip, 0);
1699 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1701 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1702 fl_set_button(fd_form_document->radio_indent, 1);
1704 fl_set_button(fd_form_document->radio_skip, 1);
1706 switch (params->getDefSkip().kind()) {
1707 case VSpace::SMALLSKIP:
1708 fl_set_choice (fd_form_document->choice_default_skip, 1);
1710 case VSpace::MEDSKIP:
1711 fl_set_choice (fd_form_document->choice_default_skip, 2);
1713 case VSpace::BIGSKIP:
1714 fl_set_choice (fd_form_document->choice_default_skip, 3);
1716 case VSpace::LENGTH:
1717 fl_set_choice (fd_form_document->choice_default_skip, 4);
1718 fl_set_input (fd_form_document->input_default_skip,
1719 params->getDefSkip().asLyXCommand().c_str());
1722 fl_set_choice (fd_form_document->choice_default_skip, 2);
1726 fl_set_button(fd_form_document->radio_sides_one, 0);
1727 fl_set_button(fd_form_document->radio_sides_two, 0);
1729 switch (params->sides) {
1730 case LyXTextClass::OneSide:
1731 fl_set_button(fd_form_document->radio_sides_one, 1);
1733 case LyXTextClass::TwoSides:
1734 fl_set_button(fd_form_document->radio_sides_two, 1);
1738 fl_set_button(fd_form_document->radio_columns_one, 0);
1739 fl_set_button(fd_form_document->radio_columns_two, 0);
1741 if (params->columns == 2)
1742 fl_set_button(fd_form_document->radio_columns_two, 1);
1744 fl_set_button(fd_form_document->radio_columns_one, 1);
1746 fl_set_input(fd_form_document->input_spacing, "");
1747 switch (params->spacing.getSpace()) {
1748 case Spacing::Default: // nothing bad should happen with this
1749 case Spacing::Single:
1752 fl_set_choice(fd_form_document->choice_spacing, 1);
1755 case Spacing::Onehalf:
1758 fl_set_choice(fd_form_document->choice_spacing, 2);
1761 case Spacing::Double:
1764 fl_set_choice(fd_form_document->choice_spacing, 3);
1767 case Spacing::Other:
1769 fl_set_choice(fd_form_document->choice_spacing, 4);
1771 //sprintf(sval, "%g", params->spacing.getValue());
1773 std::ostringstream sval;
1774 sval << params->spacing.getValue(); // setw?
1775 fl_set_input(fd_form_document->input_spacing,
1776 sval.str().c_str());
1779 ostrstream sval(tval, 20);
1780 sval << params->spacing.getValue() << '\0'; // setw?
1781 fl_set_input(fd_form_document->input_spacing, sval.str());
1788 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1789 params->secnumdepth);
1790 fl_set_counter_value(fd_form_document->slider_tocdepth,
1792 if (!params->float_placement.empty()) { // buffer local (Lgb)
1793 fl_set_input(fd_form_document->input_float_placement,
1794 params->float_placement.c_str());
1796 fl_set_input(fd_form_document->input_float_placement, "");
1798 if (!params->options.empty())
1799 fl_set_input(fd_form_document->input_extra,
1800 params->options.c_str());
1802 fl_set_input(fd_form_document->input_extra, "");
1804 if (current_view->buffer()->isSGML()) {
1805 // bullets not used in SGML derived documents
1806 fl_deactivate_object(fd_form_document->button_bullets);
1807 fl_set_object_lcol(fd_form_document->button_bullets,
1810 fl_activate_object(fd_form_document->button_bullets);
1811 fl_set_object_lcol(fd_form_document->button_bullets,
1815 if (current_view->buffer()->isReadonly()) {
1816 DisableDocumentLayout();
1818 EnableDocumentLayout();
1825 void MenuLayoutDocument()
1827 if (UpdateLayoutDocument()) {
1828 if (fd_form_document->form_document->visible) {
1829 fl_raise_form(fd_form_document->form_document);
1831 fl_show_form(fd_form_document->form_document,
1832 FL_PLACE_MOUSE, FL_FULLBORDER,
1833 _("Document Layout"));
1839 bool UpdateLayoutQuotes()
1842 if (!current_view->available()
1843 || current_view->buffer()->isReadonly())
1847 fl_set_choice(fd_form_quotes->choice_quotes_language,
1848 current_view->buffer()->params.quotes_language + 1);
1849 fl_set_button(fd_form_quotes->radio_single, 0);
1850 fl_set_button(fd_form_quotes->radio_double, 0);
1852 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1853 fl_set_button(fd_form_quotes->radio_single, 1);
1855 fl_set_button(fd_form_quotes->radio_double, 1);
1856 } else if (fd_form_quotes->form_quotes->visible) {
1857 fl_hide_form(fd_form_quotes->form_quotes);
1863 void MenuLayoutQuotes()
1865 if (UpdateLayoutQuotes()) {
1866 if (fd_form_quotes->form_quotes->visible) {
1867 fl_raise_form(fd_form_quotes->form_quotes);
1869 fl_show_form(fd_form_quotes->form_quotes,
1870 FL_PLACE_MOUSE, FL_FULLBORDER,
1877 bool UpdateLayoutPreamble()
1880 if (!current_view->available())
1884 fl_set_input(fd_form_preamble->input_preamble,
1885 current_view->buffer()->params.preamble.c_str());
1887 if (current_view->buffer()->isReadonly()) {
1888 fl_deactivate_object(fd_form_preamble->input_preamble);
1889 fl_deactivate_object(fd_form_preamble->button_ok);
1890 fl_deactivate_object(fd_form_preamble->button_apply);
1891 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1892 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1895 fl_activate_object(fd_form_preamble->input_preamble);
1896 fl_activate_object(fd_form_preamble->button_ok);
1897 fl_activate_object(fd_form_preamble->button_apply);
1898 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1899 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1901 } else if (fd_form_preamble->form_preamble->visible) {
1902 fl_hide_form(fd_form_preamble->form_preamble);
1908 void MenuLayoutPreamble()
1910 static int ow = -1, oh;
1912 if (UpdateLayoutPreamble()) {
1913 if (fd_form_preamble->form_preamble->visible) {
1914 fl_raise_form(fd_form_preamble->form_preamble);
1916 fl_show_form(fd_form_preamble->form_preamble,
1917 FL_PLACE_MOUSE | FL_FREE_SIZE,
1919 _("LaTeX Preamble"));
1921 ow = fd_form_preamble->form_preamble->w;
1922 oh = fd_form_preamble->form_preamble->h;
1924 fl_set_form_minsize(fd_form_preamble->form_preamble,
1931 void MenuLayoutSave()
1933 if (!current_view->available())
1936 if (AskQuestion(_("Do you want to save the current settings"),
1937 _("for Character, Document, Paper and Quotes"),
1938 _("as default for new documents?")))
1939 current_view->buffer()->saveParamsAsDefaults();
1943 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1944 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1945 LyXFont UserFreeFont(BufferParams const & params)
1947 LyXFont font(LyXFont::ALL_IGNORE);
1949 int pos = fl_get_choice(fd_form_character->choice_family);
1951 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1952 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1953 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1954 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1955 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1958 pos = fl_get_choice(fd_form_character->choice_series);
1960 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1961 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1962 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1963 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1966 pos = fl_get_choice(fd_form_character->choice_shape);
1968 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1969 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1970 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1971 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1972 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1973 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1976 pos = fl_get_choice(fd_form_character->choice_size);
1978 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1979 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1980 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1981 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1982 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1983 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1984 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1985 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1986 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1987 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1988 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1989 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1990 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1991 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1994 pos = fl_get_choice(fd_form_character->choice_bar);
1996 case 1: font.setEmph(LyXFont::IGNORE);
1997 font.setUnderbar(LyXFont::IGNORE);
1998 font.setNoun(LyXFont::IGNORE);
1999 font.setLatex(LyXFont::IGNORE);
2001 case 2: font.setEmph(LyXFont::TOGGLE); break;
2002 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2003 case 4: font.setNoun(LyXFont::TOGGLE); break;
2004 case 5: font.setLatex(LyXFont::TOGGLE); break;
2005 case 6: font.setEmph(LyXFont::INHERIT);
2006 font.setUnderbar(LyXFont::INHERIT);
2007 font.setNoun(LyXFont::INHERIT);
2008 font.setLatex(LyXFont::INHERIT);
2012 pos = fl_get_choice(fd_form_character->choice_color);
2014 case 1: font.setColor(LColor::ignore); break;
2015 case 2: font.setColor(LColor::none); break;
2016 case 3: font.setColor(LColor::black); break;
2017 case 4: font.setColor(LColor::white); break;
2018 case 5: font.setColor(LColor::red); break;
2019 case 6: font.setColor(LColor::green); break;
2020 case 7: font.setColor(LColor::blue); break;
2021 case 8: font.setColor(LColor::cyan); break;
2022 case 9: font.setColor(LColor::magenta); break;
2023 case 10: font.setColor(LColor::yellow); break;
2024 case 11: font.setColor(LColor::inherit); break;
2027 int choice = combo_language2->get();
2029 font.setLanguage(ignore_language);
2030 else if (choice == 2)
2031 font.setLanguage(params.language_info);
2033 font.setLanguage(&languages[combo_language2->getline()]);
2039 /* callbacks for form form_title */
2040 extern "C" void TimerCB(FL_OBJECT *, long)
2042 // only if the form still exists
2043 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2044 if (fd_form_title->form_title->visible) {
2045 fl_hide_form(fd_form_title->form_title);
2047 fl_free_form(fd_form_title->form_title);
2048 fd_form_title->form_title = 0;
2053 /* callbacks for form form_paragraph */
2055 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2057 // "Synchronize" the choices and input fields, making it
2058 // impossible to commit senseless data.
2060 FD_form_paragraph const * fp = fd_form_paragraph;
2062 if (obj == fp->choice_space_above) {
2063 if (fl_get_choice (fp->choice_space_above) != 7) {
2064 fl_set_input (fp->input_space_above, "");
2065 ActivateParagraphButtons();
2067 } else if (obj == fp->choice_space_below) {
2068 if (fl_get_choice (fp->choice_space_below) != 7) {
2069 fl_set_input (fp->input_space_below, "");
2070 ActivateParagraphButtons();
2072 } else if (obj == fp->input_space_above) {
2073 string input = fl_get_input (fp->input_space_above);
2075 if (input.empty()) {
2076 fl_set_choice (fp->choice_space_above, 1);
2077 ActivateParagraphButtons();
2079 else if (isValidGlueLength (input)) {
2080 fl_set_choice (fp->choice_space_above, 7);
2081 ActivateParagraphButtons();
2084 fl_set_choice (fp->choice_space_above, 7);
2085 DeactivateParagraphButtons();
2087 } else if (obj == fp->input_space_below) {
2088 string input = fl_get_input (fp->input_space_below);
2090 if (input.empty()) {
2091 fl_set_choice (fp->choice_space_below, 1);
2092 ActivateParagraphButtons();
2094 else if (isValidGlueLength (input)) {
2095 fl_set_choice (fp->choice_space_below, 7);
2096 ActivateParagraphButtons();
2099 fl_set_choice (fp->choice_space_below, 7);
2100 DeactivateParagraphButtons();
2106 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2108 if (!current_view->available())
2111 VSpace space_top, space_bottom;
2113 string labelwidthstring;
2116 // If a vspace kind is "Length" but there's no text in
2117 // the input field, reset the kind to "None".
2118 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2119 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2120 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2122 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2123 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2124 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2127 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2128 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2129 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2130 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2131 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2132 case 1: space_top = VSpace(VSpace::NONE); break;
2133 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2134 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2135 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2136 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2137 case 6: space_top = VSpace(VSpace::VFILL); break;
2138 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2140 if (fl_get_button (fd_form_paragraph->check_space_above))
2141 space_top.setKeep (true);
2142 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2143 case 1: space_bottom = VSpace(VSpace::NONE); break;
2144 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2145 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2146 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2147 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2148 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2149 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2151 if (fl_get_button (fd_form_paragraph->check_space_below))
2152 space_bottom.setKeep (true);
2154 if (fl_get_button(fd_form_paragraph->radio_align_left))
2155 align = LYX_ALIGN_LEFT;
2156 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2157 align = LYX_ALIGN_RIGHT;
2158 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2159 align = LYX_ALIGN_CENTER;
2161 align = LYX_ALIGN_BLOCK;
2163 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2164 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2167 if (current_view->the_locking_inset)
2168 text = current_view->the_locking_inset->getLyXText(current_view);
2170 text = current_view->text;
2171 text->SetParagraph(current_view,
2181 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2182 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2186 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2188 fl_hide_form(fd_form_paragraph->form_paragraph);
2192 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2194 ParagraphApplyCB(ob, data);
2195 ParagraphCancelCB(ob, data);
2199 /* callbacks for form form_character */
2201 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2203 // we set toggleall locally here, since it should be true for
2204 // all other uses of ToggleAndShow() (JMarc)
2205 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2206 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2207 current_view->setState();
2212 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2214 fl_hide_form(fd_form_character->form_character);
2218 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2220 CharacterApplyCB(ob, data);
2221 CharacterCloseCB(ob, data);
2225 /* callbacks for form form_document */
2227 void UpdateDocumentButtons(BufferParams const & params)
2229 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2231 switch (params.sides) {
2232 case LyXTextClass::OneSide:
2233 fl_set_button(fd_form_document->radio_sides_one, 1);
2235 case LyXTextClass::TwoSides:
2236 fl_set_button(fd_form_document->radio_sides_two, 1);
2240 if (params.columns == 2)
2241 fl_set_button(fd_form_document->radio_columns_two, 1);
2243 fl_set_button(fd_form_document->radio_columns_one, 1);
2245 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2246 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2247 params.secnumdepth);
2248 fl_set_counter_value(fd_form_document->slider_tocdepth,
2253 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2255 ProhibitInput(current_view);
2256 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2257 if (AskQuestion(_("Should I set some parameters to"),
2258 fl_get_choice_text(ob),
2259 _("the defaults of this document class?"))) {
2260 BufferParams params = BufferParams();
2261 params.textclass = fl_get_choice(ob)-1;
2262 params.useClassDefaults();
2263 UpdateLayoutDocument(¶ms);
2264 UpdateDocumentButtons(params);
2267 // unable to load new style
2268 WriteAlert(_("Conversion Errors!"),
2269 _("Unable to switch to new document class."),
2270 _("Reverting to original document class."));
2271 fl_set_choice(fd_form_document->choice_class,
2272 current_view->buffer()->params.textclass + 1);
2274 AllowInput(current_view);
2278 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2280 // "Synchronize" the choice and the input field, so that it
2281 // is impossible to commit senseless data.
2282 FD_form_document const * fd = fd_form_document;
2284 if (obj == fd->choice_default_skip) {
2285 if (fl_get_choice (fd->choice_default_skip) != 4) {
2286 fl_set_input (fd->input_default_skip, "");
2287 ActivateDocumentButtons();
2289 } else if (obj == fd->input_default_skip) {
2291 char const * input = fl_get_input (fd->input_default_skip);
2294 fl_set_choice (fd->choice_default_skip, 2);
2295 ActivateDocumentButtons();
2296 } else if (isValidGlueLength (input)) {
2297 fl_set_choice (fd->choice_default_skip, 4);
2298 ActivateDocumentButtons();
2300 fl_set_choice (fd->choice_default_skip, 4);
2301 DeactivateDocumentButtons();
2307 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2309 // "Synchronize" the choice and the input field, so that it
2310 // is impossible to commit senseless data.
2311 FD_form_document const * fd = fd_form_document;
2313 if (obj == fd->choice_spacing
2314 && fl_get_choice (fd->choice_spacing) != 4) {
2315 fl_set_input(fd->input_spacing, "");
2316 } else if (obj == fd->input_spacing) {
2318 const char* input = fl_get_input (fd->input_spacing);
2321 fl_set_choice (fd->choice_spacing, 1);
2323 fl_set_choice (fd->choice_spacing, 4);
2329 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2332 BufferParams * params = &(current_view->buffer()->params);
2334 Language const * old_language = params->language_info;
2335 params->language = combo_language->getline();
2336 Languages::iterator lit = languages.find(params->language);
2338 Language const * new_language;
2339 if (lit != languages.end())
2340 new_language = &(*lit).second;
2342 new_language = default_language;
2344 if (current_view->available()) {
2345 if (old_language != new_language
2346 && old_language->RightToLeft() == new_language->RightToLeft()
2347 && !current_view->buffer()->isMultiLingual())
2348 current_view->buffer()->ChangeLanguage(old_language,
2350 if (old_language != new_language) {
2351 //current_view->buffer()->redraw();
2355 params->language_info = new_language;
2357 // If default skip is a "Length" but there's no text in the
2358 // input field, reset the kind to "Medskip", which is the default.
2359 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2360 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2361 fl_set_choice (fd_form_document->choice_default_skip, 2);
2364 /* this shouldn't be done automatically IMO. For example I write german
2365 * documents with an american keyboard very often. Matthias */
2367 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2368 fl_get_choice(fd_form_document->choice_language)); */
2370 fl_get_choice_text(fd_form_document->choice_fonts);
2372 fl_get_choice_text(fd_form_document->choice_inputenc);
2374 fl_get_choice_text(fd_form_document->choice_fontsize);
2376 fl_get_choice_text(fd_form_document->choice_pagestyle);
2377 params->graphicsDriver =
2378 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2379 params->use_amsmath =
2380 fl_get_button(fd_form_document->check_use_amsmath);
2382 if (!current_view->available())
2385 current_view->text->SetCursor(current_view,
2386 current_view->text->cursor.par(),
2387 current_view->text->cursor.pos());
2388 current_view->setState();
2390 LyXTextClassList::ClassList::size_type new_class =
2391 fl_get_choice(fd_form_document->choice_class) - 1;
2393 if (params->textclass != new_class) {
2394 // try to load new_class
2395 if (textclasslist.Load(new_class)) {
2396 // successfully loaded
2398 current_view->owner()->getMiniBuffer()->
2399 Set(_("Converting document to new document class..."));
2401 int ret = cap.SwitchLayoutsBetweenClasses(
2402 current_view->buffer()->params.textclass,
2404 current_view->buffer()->paragraph);
2409 s = _("One paragraph couldn't be converted");
2412 s += _(" paragraphs couldn't be converted");
2414 WriteAlert(_("Conversion Errors!"), s,
2415 _("into chosen document class"));
2418 params->textclass = new_class;
2420 // problem changing class -- warn user and retain old style
2421 WriteAlert(_("Conversion Errors!"),
2422 _("Unable to switch to new document class."),
2423 _("Reverting to original document class."));
2424 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2428 char tmpsep = params->paragraph_separation;
2429 if (fl_get_button(fd_form_document->radio_indent))
2430 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2432 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2433 if (tmpsep != params->paragraph_separation)
2436 VSpace tmpdefskip = params->getDefSkip();
2437 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2438 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2439 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2440 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2441 case 4: params->setDefSkip(
2442 VSpace (LyXGlueLength (fl_get_input
2443 (fd_form_document->input_default_skip))));
2445 // DocumentDefskipCB assures that this never happens
2446 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2448 if (!(tmpdefskip == params->getDefSkip()))
2451 if (fl_get_button(fd_form_document->radio_columns_two))
2452 params->columns = 2;
2454 params->columns = 1;
2455 if (fl_get_button(fd_form_document->radio_sides_two))
2456 params->sides = LyXTextClass::TwoSides;
2458 params->sides = LyXTextClass::OneSide;
2460 Spacing tmpSpacing = params->spacing;
2461 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2463 lyxerr.debug() << "Spacing: SINGLE" << endl;
2464 params->spacing.set(Spacing::Single);
2467 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2468 params->spacing.set(Spacing::Onehalf);
2471 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2472 params->spacing.set(Spacing::Double);
2475 lyxerr.debug() << "Spacing: OTHER" << endl;
2476 params->spacing.set(Spacing::Other,
2477 fl_get_input(fd_form_document->input_spacing));
2480 if (tmpSpacing != params->spacing)
2483 signed char tmpchar =
2484 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2485 if (params->secnumdepth != tmpchar)
2487 params->secnumdepth = tmpchar;
2490 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2492 params->float_placement =
2493 fl_get_input(fd_form_document->input_float_placement);
2495 // More checking should be done to ensure the string doesn't have
2496 // spaces or illegal placement characters in it. (thornley)
2499 current_view->redoCurrentBuffer();
2501 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2502 current_view->buffer()->markDirty();
2505 fl_get_input(fd_form_document->input_extra);
2509 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2511 fl_hide_form(fd_form_document->form_document);
2515 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2517 DocumentCancelCB(ob, data);
2518 DocumentApplyCB(ob, data);
2522 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2525 // bullet callbacks etc. in bullet_panel.C -- ARRae
2529 /* callbacks for form form_quotes */
2531 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2533 if (!current_view->available())
2536 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2537 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2538 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2540 lga = InsetQuotes::EnglishQ;
2543 lga = InsetQuotes::SwedishQ;
2546 lga = InsetQuotes::GermanQ;
2549 lga = InsetQuotes::PolishQ;
2552 lga = InsetQuotes::FrenchQ;
2555 lga = InsetQuotes::DanishQ;
2558 current_view->buffer()->params.quotes_language = lga;
2559 if (fl_get_button(fd_form_quotes->radio_single))
2560 current_view->buffer()->
2561 params.quotes_times = InsetQuotes::SingleQ;
2563 current_view->buffer()->
2564 params.quotes_times = InsetQuotes::DoubleQ;
2568 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2570 fl_hide_form(fd_form_quotes->form_quotes);
2574 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2576 QuotesApplyCB(ob, data);
2577 QuotesCancelCB(ob, data);
2582 /* callbacks for form form_preamble */
2584 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2586 fl_hide_form(fd_form_preamble->form_preamble);
2590 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2592 if (!current_view->available())
2595 current_view->buffer()->params.preamble =
2596 fl_get_input(fd_form_preamble->input_preamble);
2597 current_view->buffer()->markDirty();
2598 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2602 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2604 PreambleApplyCB(ob, data);
2605 PreambleCancelCB(ob, data);
2609 /* callbacks for form form_table */
2612 void TableApplyCB(FL_OBJECT *, long)
2614 if (!current_view->available())
2618 // check for tables in tables
2619 if (current_view->text->cursor.par()->table){
2620 WriteAlert(_("Impossible Operation!"),
2621 _("Cannot insert table in table."),
2626 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2628 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2629 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2632 current_view->hideCursor();
2633 current_view->beforeChange();
2634 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2636 current_view->text->SetCursorParUndo(current_view->buffer());
2637 current_view->text->FreezeUndo();
2639 current_view->text->BreakParagraph(current_view);
2640 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2642 if (current_view->text->cursor.par()->Last()) {
2643 current_view->text->CursorLeft(current_view);
2645 current_view->text->BreakParagraph(current_view);
2646 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2649 current_view->text->current_font.setLatex(LyXFont::OFF);
2650 //if (!fl_get_button(fd_form_table->check_latex)){
2651 // insert the new wysiwy table
2652 current_view->text->SetLayout(current_view, 0); // standard layout
2654 if (current_view->text->cursor.par()->footnoteflag ==
2655 LyXParagraph::NO_FOOTNOTE) {
2658 ->SetParagraph(current_view, 0, 0,
2660 VSpace (0.3 * current_view->buffer()->
2661 params.spacing.getValue(),
2663 VSpace (0.3 * current_view->buffer()->
2664 params.spacing.getValue(),
2672 ->SetParagraph(current_view, 0, 0,
2674 VSpace(VSpace::NONE),
2675 VSpace(VSpace::NONE),
2682 current_view->text->cursor.par()->table =
2683 new LyXTable(xsize, ysize);
2685 Language const * lang =
2686 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2687 LyXFont font(LyXFont::ALL_INHERIT, lang);
2688 for (int i = 0; i < xsize * ysize - 1; ++i) {
2689 current_view->text->cursor.par()
2690 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2692 current_view->text->RedoParagraph(current_view);
2694 current_view->text->UnFreezeUndo();
2696 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2697 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2698 current_view->setState();
2703 void TableCancelCB(FL_OBJECT *, long)
2705 fl_hide_form(fd_form_table->form_table);
2710 void TableOKCB(FL_OBJECT * ob, long data)
2712 TableApplyCB(ob, data);
2713 TableCancelCB(ob, data);
2719 if (fd_form_figure->form_figure->visible) {
2720 fl_raise_form(fd_form_figure->form_figure);
2722 fl_show_form(fd_form_figure->form_figure,
2723 FL_PLACE_MOUSE, FL_FULLBORDER,
2724 _("Insert Figure"));
2731 if (fd_form_table->form_table->visible) {
2732 fl_raise_form(fd_form_table->form_table);
2734 fl_show_form(fd_form_table->form_table,
2735 FL_PLACE_MOUSE, FL_FULLBORDER,
2741 /* callbacks for form form_figure */
2743 void FigureApplyCB(FL_OBJECT *, long)
2745 if (!current_view->available())
2748 Buffer * buffer = current_view->buffer();
2749 if(buffer->isReadonly()) // paranoia
2752 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2753 if (fl_get_button(fd_form_figure->radio_inline)
2755 || current_view->text->cursor.par()->table
2758 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2759 current_view->insertInset(new_inset);
2760 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2761 new_inset->Edit(current_view, 0, 0, 0);
2765 current_view->hideCursor();
2766 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2767 current_view->beforeChange();
2769 current_view->text->SetCursorParUndo(current_view->buffer());
2770 current_view->text->FreezeUndo();
2772 current_view->text->BreakParagraph(current_view);
2773 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2775 if (current_view->text->cursor.par()->Last()) {
2776 current_view->text->CursorLeft(current_view);
2778 current_view->text->BreakParagraph(current_view);
2779 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2782 // The standard layout should always be numer 0;
2783 current_view->text->SetLayout(current_view, 0);
2786 if (current_view->text->cursor.par()->footnoteflag ==
2787 LyXParagraph::NO_FOOTNOTE) {
2789 current_view->text->
2790 SetParagraph(current_view, 0, 0,
2792 VSpace (0.3 * buffer->params.spacing.getValue(),
2795 buffer->params.spacing.getValue(),
2797 LYX_ALIGN_CENTER, string(), 0);
2800 current_view->text->SetParagraph(current_view, 0, 0,
2802 VSpace(VSpace::NONE),
2803 VSpace(VSpace::NONE),
2810 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2812 Inset * new_inset = new InsetFig(100, 100, buffer);
2813 current_view->insertInset(new_inset);
2814 new_inset->Edit(current_view, 0, 0, 0);
2815 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2816 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2817 current_view->text->UnFreezeUndo();
2818 current_view->setState();
2822 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2824 fl_hide_form(fd_form_figure->form_figure);
2828 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2830 FigureApplyCB(ob, data);
2831 FigureCancelCB(ob, data);
2835 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2837 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2838 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2839 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2840 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2841 lyxrc.set_font_norm_type();
2842 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2843 fontloader.update();
2845 // Of course we should only to the resize and the textcahce.clear
2846 // if values really changed...but not very important right now. (Lgb)
2848 // All buffers will need resize
2849 bufferlist.resize();
2850 // We also need to empty the textcache so that
2851 // the buffer will be formatted correctly after
2855 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2859 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2861 fl_hide_form(fd_form_screen->form_screen);
2865 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2867 ScreenCancelCB(ob, data);
2868 ScreenApplyCB(ob, data);
2872 // This function runs "configure" and then rereads lyx.defaults to
2873 // reconfigure the automatic settings.
2874 void Reconfigure(BufferView * bv)
2876 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2878 // Run configure in user lyx directory
2879 Path p(user_lyxdir);
2880 Systemcalls one(Systemcalls::System,
2881 AddName(system_lyxdir, "configure"));
2883 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2884 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2885 WriteAlert(_("The system has been reconfigured."),
2886 _("You need to restart LyX to make use of any"),
2887 _("updated document class specifications."));