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_toc * fd_form_toc;
75 extern FD_form_ref * fd_form_ref;
76 extern FD_LaTeXOptions * fd_latex_options;
77 extern FD_form_bullet * fd_form_bullet;
79 extern BufferView * current_view; // called too many times in this file...
81 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
83 extern bool send_fax(string const & fname, string const & sendcmd);
84 extern void MenuSendto();
86 extern LyXServer * lyxserver;
88 // this should be static, but I need it in buffer.C
89 bool quitting; // flag, that we are quitting the program
90 extern bool finished; // all cleanup done just let it run through now.
92 char ascii_type; /* for selection notify callbacks */
94 bool scrolling = false;
96 // This is used to make the dreaded font toggle problem hopefully go
97 // away. Definitely not the best solution, but I think it sorta works.
98 bool toggleall = true;
101 This is the inset locking stuff needed for mathed --------------------
103 an inset can simple call LockInset in it's edit call and *ONLY* in it's
105 Inset::Edit() can only be called by the main lyx module.
107 Then the inset may modify the menu's and/or iconbars.
109 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
111 During the lock, all button and keyboard events will be modified
112 and send to the inset through the following inset-features. Note that
113 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
114 to contain the code for restoring the menus and things like this.
117 virtual void InsetButtonPress(int x, int y, int button);
118 virtual void InsetButtonRelease(int x, int y, int button);
119 virtual void InsetKeyPress(XKeyEvent *ev);
120 virtual void InsetMotionNotify(int x, int y, int state);
121 virtual void InsetUnlock();
123 If a inset wishes any redraw and/or update it just has to call
125 It's is completly irrelevant, where the inset is. UpdateInset will
126 find it in any paragraph in any buffer.
127 Of course the_locking_inset and the insets in the current paragraph/buffer
128 are checked first, so no performance problem should occur.
130 Hope that's ok for the beginning, Alejandro,
131 sorry that I needed so much time,
136 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
138 /* these functions return 1 if an error occured,
140 // Now they work only for updatable insets. [Alejandro 080596]
141 //int LockInset(UpdatableInset * inset);
142 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
143 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
144 //int UnlockInset(UpdatableInset * inset);
145 //void LockedInsetStoreUndo(Undo::undo_kind kind);
147 /* this is for asyncron updating. UpdateInsetUpdateList will be called
148 automatically from LyX. Just insert the Inset into the Updatelist */
149 //void UpdateInsetUpdateList();
150 //void PutInsetIntoInsetUpdateList(Inset * inset);
152 //InsetUpdateStruct * InsetUpdateList = 0;
156 -----------------------------------------------------------------------
159 /* some function prototypes */
161 int RunLinuxDoc(BufferView *, int, string const &);
162 int RunDocBook(int, string const &);
163 void MenuWrite(Buffer * buf);
164 void MenuWriteAs(Buffer * buffer);
165 void MenuReload(Buffer * buf);
166 void MenuLayoutSave();
169 void ShowMessage(Buffer * buf,
171 string const & msg2 = string(),
172 string const & msg3 = string(), int delay = 6)
175 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
178 // can somebody think of something more clever? cerr?
179 cout << msg1 << msg2 << msg3 << endl;
192 // should be moved to lyxfunc.C
193 void MenuWrite(Buffer * buffer)
196 if (!buffer->save()) {
197 string fname = buffer->fileName();
198 string s = MakeAbsPath(fname);
199 if (AskQuestion(_("Save failed. Rename and try again?"),
200 MakeDisplayPath(s, 50),
201 _("(If not, document is not saved.)"))) {
205 lastfiles->newFile(buffer->fileName());
210 // should be moved to BufferView.C
211 // Half of this func should be in LyXView, the rest in BufferView.
212 void MenuWriteAs(Buffer * buffer)
214 // Why do we require BufferView::text to be able to write a
215 // document? I see no point in that. (Lgb)
216 //if (!bv->text) return;
218 string fname = buffer->fileName();
219 string oldname = fname;
222 ProhibitInput(current_view);
223 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
224 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
226 if (!IsLyXFilename(fname))
229 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
232 OnlyFilename(fname));
233 AllowInput(current_view);
238 // Make sure the absolute filename ends with appropriate suffix
239 string s = MakeAbsPath(fname);
240 if (!IsLyXFilename(s))
243 // Same name as we have already?
245 if (!AskQuestion(_("Same name as document already has:"),
246 MakeDisplayPath(s, 50),
249 // Falls through to name change and save
251 // No, but do we have another file with this name open?
252 else if (bufferlist.exists(s)) {
253 if (AskQuestion(_("Another document with same name open!"),
254 MakeDisplayPath(s, 50),
255 _("Replace with current document?")))
257 bufferlist.close(bufferlist.getBuffer(s));
259 // Ok, change the name of the buffer, but don't save!
263 ShowMessage(buffer, _("Document renamed to '"),
264 MakeDisplayPath(s), _("', but not saved..."));
267 } // Check whether the file exists
270 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
271 MakeDisplayPath(s, 50),
276 // Ok, change the name of the buffer
280 // Small bug: If the save fails, we have irreversible changed the name
286 int MenuRunLaTeX(Buffer * buffer)
290 if (buffer->isLinuxDoc())
291 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
292 else if (buffer->isLiterate())
293 ret = buffer->runLiterate();
294 else if (buffer->isDocBook())
295 ret = RunDocBook(1, buffer->fileName());
297 ret = buffer->runLaTeX();
303 s = _("One error detected");
304 t = _("You should try to fix it.");
307 s += _(" errors detected.");
308 t = _("You should try to fix them.");
310 WriteAlert(_("There were errors during the LaTeX run."), s, t);
316 int MenuBuildProg(Buffer * buffer)
320 if (buffer->isLiterate())
321 ret = buffer->buildProgram();
323 string s = _("Wrong type of document");
324 string t = _("The Build operation is not allowed in this document");
325 WriteAlert(_("There were errors during the Build process."), s, t);
333 s = _("One error detected");
334 t = _("You should try to fix it.");
337 s += _(" errors detected.");
338 t = _("You should try to fix them.");
340 WriteAlert(_("There were errors during the Build process."), s, t);
346 int MenuRunChktex(Buffer * buffer)
350 if (buffer->isSGML()) {
351 WriteAlert(_("Chktex does not work with SGML derived documents."));
354 ret = buffer->runChktex();
360 s = _("No warnings found.");
361 } else if (ret == 1) {
362 s = _("One warning found.");
363 t = _("Use 'Edit->Go to Error' to find it.");
366 s += _(" warnings found.");
367 t = _("Use 'Edit->Go to Error' to find them.");
369 WriteAlert(_("Chktex run successfully"), s, t);
371 WriteAlert(_("Error!"), _("It seems chktex does not work."));
377 int MakeLaTeXOutput(Buffer * buffer)
383 string path = OnlyPath(buffer->fileName());
384 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
385 path = buffer->tmppath;
389 ret = MenuRunLaTeX(buffer);
395 /* wait == false means don't wait for termination */
396 /* wait == true means wait for termination */
397 // The bool should be placed last on the argument line. (Lgb)
398 // Returns false if we fail.
399 bool RunScript(Buffer * buffer, bool wait,
400 string const & command,
401 string const & orgname = string(),
402 bool need_shell = true)
406 string name = orgname;
409 if (MakeLaTeXOutput(buffer) > 0)
411 /* get DVI-Filename */
413 name = ChangeExtension(buffer->getLatexName(), ".dvi");
415 path = OnlyPath(name);
416 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
417 path = buffer->tmppath;
420 // At this point we check whether the command contains the
421 // filename parameter $$FName and if that's the case we
422 // substitute the real file name otherwise the filename is
423 // simply appended. rokrau 1/12/00
426 if ( (i=command.find("$$FName")) != string::npos)
428 cmd.replace(i,7,QuoteName(name));
431 cmd = command + ' ' + QuoteName(name);
440 // OS/2 cmd.exe has another use for '&'
442 // This is not NLS safe, but it's OK, I think.
443 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
445 // COMSPEC is set, unless user unsets
446 sh = OnlyFilename(GetEnvPath("COMSPEC"));
451 if (contains(sh, "cmd.exe")
452 || contains(sh, "4os2.exe"))
453 cmd = "start /min/n " + cmd;
458 // It seems that, if wait is false, we never get back
459 // the return code of the command. This means that all
460 // the code I added in PrintApplyCB is currently
462 // CHECK What should we do here?
463 ShowMessage(buffer, _("Executing command:"), cmd);
464 result = one.startscript(Systemcalls::System, cmd);
466 ShowMessage(buffer, _("Executing command:"), cmd);
467 result = one.startscript(wait ? Systemcalls::Wait
468 : Systemcalls::DontWait, cmd);
474 // Returns false if we fail
475 bool CreatePostscript(Buffer * buffer, bool wait = false)
481 ProhibitInput(current_view);
484 if (MakeLaTeXOutput(buffer) > 0) {
485 AllowInput(current_view);
488 // Generate postscript file
489 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
495 char real_papersize = buffer->params.papersize;
496 if (real_papersize == BufferParams::PAPER_DEFAULT)
497 real_papersize = lyxrc.default_papersize;
499 switch (real_papersize) {
500 case BufferParams::PAPER_USLETTER:
503 case BufferParams::PAPER_A3PAPER:
506 case BufferParams::PAPER_A4PAPER:
509 case BufferParams::PAPER_A5PAPER:
512 case BufferParams::PAPER_B5PAPER:
515 case BufferParams::PAPER_EXECUTIVEPAPER:
518 case BufferParams::PAPER_LEGALPAPER:
521 default: /* If nothing else fits, keep an empty value... */
525 // Make postscript file.
526 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
527 command += QuoteName(psname);
528 if (buffer->params.use_geometry
529 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
530 && !lyxrc.print_paper_dimension_flag.empty()
531 && !buffer->params.paperwidth.empty()
532 && !buffer->params.paperheight.empty()) {
533 // using a custom papersize
535 command += lyxrc.print_paper_dimension_flag + ' ';
536 command += buffer->params.paperwidth + ',';
537 command += buffer->params.paperheight;
538 } else if (!paper.empty()
539 && (real_papersize != BufferParams::PAPER_USLETTER ||
540 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
541 // dvips won't accept -t letter -t landscape. In all other
542 // cases, include the paper size explicitly.
544 command += lyxrc.print_paper_flag + ' ' + paper;
546 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
548 command += lyxrc.print_landscape_flag;
550 // push directorypath, if necessary
551 string path = OnlyPath(buffer->fileName());
552 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
553 path = buffer->tmppath;
556 bool ret = RunScript(buffer, wait, command);
557 AllowInput(current_view);
562 // Returns false if we fail
563 //bool MenuPreviewPS(Buffer * buffer)
564 bool PreviewPostscript(Buffer * buffer)
570 // Generate postscript file
571 if (!CreatePostscript(buffer, true)) {
575 // Start postscript viewer
576 ProhibitInput(current_view);
577 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
579 // push directorypath, if necessary
580 string path = OnlyPath(buffer->fileName());
581 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
582 path = buffer->tmppath;
585 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
586 AllowInput(current_view);
591 void MenuFax(Buffer * buffer)
597 // Generate postscript file
598 if (!CreatePostscript(buffer, true)) {
603 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
605 string path = OnlyPath (buffer->fileName());
606 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
607 path = buffer->tmppath;
610 if (!lyxrc.fax_program.empty()) {
611 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
613 Systemcalls one(Systemcalls::System, help2);
615 send_fax(ps, lyxrc.fax_command);
619 // Returns false if we fail
620 bool PreviewDVI(Buffer * buffer)
626 string paper = lyxrc.view_dvi_paper_option;
627 if (!paper.empty()) {
629 char real_papersize = buffer->params.papersize;
630 if (real_papersize == BufferParams::PAPER_DEFAULT)
631 real_papersize = lyxrc.default_papersize;
633 switch (real_papersize) {
634 case BufferParams::PAPER_USLETTER:
637 case BufferParams::PAPER_A3PAPER:
640 case BufferParams::PAPER_A4PAPER:
643 case BufferParams::PAPER_A5PAPER:
646 case BufferParams::PAPER_B5PAPER:
649 case BufferParams::PAPER_EXECUTIVEPAPER:
650 paper += " foolscap";
652 case BufferParams::PAPER_LEGALPAPER:
655 default: /* If nothing else fits, keep the empty value */
658 if (real_papersize==' ') {
659 // if (paper.empty()) {
660 if (buffer->params.orientation
661 == BufferParams::ORIENTATION_LANDSCAPE)
662 // we HAVE to give a size when the page is in
663 // landscape, so use USletter.
664 paper = " -paper usr";
666 // paper = " -paper " + paper;
667 if (buffer->params.orientation
668 == BufferParams::ORIENTATION_LANDSCAPE)
672 // push directorypath, if necessary
673 string path = OnlyPath(buffer->fileName());
674 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
675 path = buffer->tmppath;
679 string command = lyxrc.view_dvi_command + " " + paper;
680 bool ret = RunScript(buffer, false, command);
685 bool AskOverwrite(Buffer * buffer, string const & s)
688 // be friendly if there is a gui
691 !AskQuestion(_("File already exists:"),
692 MakeDisplayPath(s, 50),
693 _("Do you want to overwrite the file?"))) {
694 ShowMessage(buffer, _("Canceled"));
702 void MenuMakeLaTeX(Buffer * buffer)
704 // Why care about this?
708 // Get LaTeX-Filename
709 string s = buffer->getLatexName(false);
711 if (!AskOverwrite(buffer, s))
714 if (buffer->isDocBook())
715 ShowMessage(buffer, _("DocBook does not have a latex backend"));
717 if (buffer->isLinuxDoc())
718 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
720 buffer->makeLaTeXFile(s, string(), true);
721 ShowMessage(buffer, _("Nice LaTeX file saved as"),
727 void MenuMakeLinuxDoc(Buffer * buffer)
730 //if (!bv->text) return;
732 if (!buffer->isLinuxDoc()) {
733 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
737 // Get LinuxDoc-Filename
738 string s = ChangeExtension(buffer->fileName(), ".sgml");
740 if (!AskOverwrite(buffer, s))
743 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
744 MakeDisplayPath(s),"'...");
746 buffer->makeLinuxDocFile(s, true);
748 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
753 void MenuMakeDocBook(Buffer * buffer)
756 //if (!bv->text) return;
758 if (!buffer->isDocBook()) {
759 WriteAlert(_("Error!"),
760 _("Document class must be docbook."));
764 // Get DocBook-Filename
765 string s = ChangeExtension(buffer->fileName(), ".sgml");
767 if (!AskOverwrite(buffer, s))
770 ShowMessage(buffer, _("Building DocBook SGML file `"),
771 MakeDisplayPath(s), "'...");
773 buffer->makeDocBookFile(s, true);
775 ShowMessage(buffer, _("DocBook SGML file save as"),
780 void MenuMakeAscii(Buffer * buffer)
783 //if (!bv->text) return;
785 /* get LaTeX-Filename */
786 string s = ChangeExtension (buffer->fileName(), ".txt");
789 if (!AskOverwrite(buffer, s))
792 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
794 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
798 void MenuMakeHTML(Buffer * buffer)
800 // First, create LaTeX file
801 MenuMakeLaTeX(buffer);
803 // And now, run the converter
804 string file = buffer->fileName();
805 Path path(OnlyPath(file));
806 // the tex file name has to be correct for
807 // latex, but the html file name can be
809 string result = ChangeExtension(file, ".html");
810 string infile = buffer->getLatexName(false);
811 string tmp = lyxrc.html_command;
812 tmp = subst(tmp, "$$FName", infile);
813 tmp = subst(tmp, "$$OutName", result);
815 int res = one.startscript(Systemcalls::System, tmp);
817 ShowMessage(buffer, _("Document exported as HTML to file `")
818 + MakeDisplayPath(result) +'\'');
820 ShowMessage(buffer, _("Unable to convert to HTML the file `")
821 + MakeDisplayPath(infile)
828 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
830 // First, create LinuxDoc file
831 MenuMakeLinuxDoc(buffer);
833 // And now, run the converter
834 string file = buffer->fileName();
836 string result = ChangeExtension(file, ".html");
837 string infile = ChangeExtension(file, ".sgml");
838 string tmp = lyxrc.linuxdoc_to_html_command;
839 tmp = subst(tmp, "$$FName", infile);
840 tmp = subst(tmp, "$$OutName", result);
842 int res = one.startscript(Systemcalls::System, tmp);
844 ShowMessage(buffer,_("Document exported as HTML to file `")
845 + MakeDisplayPath(result) +'\'');
847 ShowMessage(buffer,_("Unable to convert to HTML the file `")
848 + MakeDisplayPath(infile)
854 void MenuMakeHTML_DocBook(Buffer * buffer)
856 // First, create LaTeX file
857 MenuMakeDocBook(buffer);
859 // And now, run the converter
860 string file = buffer->fileName();
861 string result = ChangeExtension(file, ".html");
862 string infile = ChangeExtension(file, ".sgml");
863 string tmp = lyxrc.docbook_to_html_command;
864 tmp = subst(tmp, "$$FName", infile);
865 tmp = subst(tmp, "$$OutName", result);
867 int res = one.startscript(Systemcalls::System, tmp);
869 ShowMessage(buffer,_("Document exported as HTML to file `")
870 + MakeDisplayPath(result) +'\'');
872 ShowMessage(buffer,_("Unable to convert to HTML the file `")
873 + MakeDisplayPath(infile)
880 void MenuExport(Buffer * buffer, string const & extyp)
883 if (extyp == "latex") {
884 // make sure that this buffer is not linuxdoc
885 MenuMakeLaTeX(buffer);
888 else if (extyp == "linuxdoc") {
889 // make sure that this buffer is not latex
890 MenuMakeLinuxDoc(buffer);
893 else if (extyp == "docbook") {
894 // make sure that this buffer is not latex or linuxdoc
895 MenuMakeDocBook(buffer);
898 else if (extyp == "dvi") {
899 // Run LaTeX as "Update dvi..." Bernhard.
900 // We want the dvi in the current directory. This
901 // is achieved by temporarily disabling use of
902 // temp directory. As a side-effect, we get
903 // *.log and *.aux files also. (Asger)
904 bool flag = lyxrc.use_tempdir;
905 lyxrc.use_tempdir = false;
906 MenuRunLaTeX(buffer);
907 lyxrc.use_tempdir = flag;
910 else if (extyp == "postscript") {
911 // Start Print-dialog. Not as good as dvi... Bernhard.
912 //should start lyxview->getDialogs()->showPrint();
913 // to get same as before
914 // MenuPrint(buffer);
915 // Since the MenuPrint is a pop-up, we can't use
916 // the same trick as above. (Asger)
917 // MISSING: Move of ps-file :-(
918 // And MenuPrint should not be used for this at all...
921 else if (extyp == "ascii") {
922 MenuMakeAscii(buffer);
924 else if (extyp == "custom") {
928 else if (extyp == "html") {
929 MenuMakeHTML(buffer);
931 // HTML from linuxdoc
932 else if (extyp == "html-linuxdoc") {
933 MenuMakeHTML_LinuxDoc(buffer);
936 else if (extyp == "html-docbook") {
937 MenuMakeHTML_DocBook(buffer);
940 ShowMessage(buffer, _("Unknown export type: ") + extyp);
947 lyxerr.debug() << "Running QuitLyX." << endl;
949 if (!bufferlist.QwriteAll())
952 lastfiles->writeFile(lyxrc.lastfiles);
954 // Set a flag that we do quitting from the program,
955 // so no refreshes are necessary.
958 // close buffers first
959 bufferlist.closeAll();
961 // do any other cleanup procedures now
962 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
964 DestroyLyXTmpDir(system_tempdir);
971 void AutoSave(BufferView * bv)
972 // should probably be moved into BufferList (Lgb)
973 // Perfect target for a thread...
975 if (!bv->available())
978 if (bv->buffer()->isBakClean()
979 || bv->buffer()->isReadonly()) {
980 // We don't save now, but we'll try again later
981 bv->owner()->resetAutosaveTimer();
985 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
987 // create autosave filename
988 string fname = OnlyPath(bv->buffer()->fileName());
990 fname += OnlyFilename(bv->buffer()->fileName());
993 // tmp_ret will be located (usually) in /tmp
994 // will that be a problem?
995 string tmp_ret = tmpnam(0);
997 pid_t pid = fork(); // If you want to debug the autosave
998 // you should set pid to -1, and comment out the
1000 if (pid == 0 || pid == -1) {
1001 // pid = -1 signifies that lyx was unable
1002 // to fork. But we will do the save
1004 bool failed = false;
1005 if (!tmp_ret.empty()) {
1006 bv->buffer()->writeFile(tmp_ret, 1);
1007 // assume successful write of tmp_ret
1008 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1010 // most likely couldn't move between filesystems
1011 // unless write of tmp_ret failed
1012 // so remove tmp file (if it exists)
1013 remove(tmp_ret.c_str());
1020 // failed to write/rename tmp_ret so try writing direct
1021 if (!bv->buffer()->writeFile(fname, 1)) {
1022 // It is dangerous to do this in the child,
1023 // but safe in the parent, so...
1025 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1028 if (pid == 0) { // we are the child so...
1033 bv->buffer()->markBakClean();
1034 bv->owner()->resetAutosaveTimer();
1039 // Copyright CHT Software Service GmbH
1042 // create new file with template
1045 Buffer * NewLyxFile(string const & filename)
1047 // Split argument by :
1049 string tmpname = split(filename, name, ':');
1050 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1051 if (name.length() == 1
1052 && isalpha(static_cast<unsigned char>(name[0]))
1053 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1055 name += token(tmpname, ':', 0);
1056 tmpname = split(tmpname, ':');
1059 lyxerr.debug() << "Arg is " << filename
1060 << "\nName is " << name
1061 << "\nTemplate is " << tmpname << endl;
1063 // find a free buffer
1064 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1066 lastfiles->newFile(tmpbuf->fileName());
1071 // Insert ascii file (if filename is empty, prompt for one)
1072 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1077 if (!bv->available()) return;
1079 if (fname.empty()) {
1081 fname = fileDlg.Select(_("File to Insert"),
1082 bv->owner()->buffer()->filepath,
1085 if (fname.empty()) return;
1090 if (!fi.readable()) {
1091 WriteFSAlert(_("Error! Specified file is unreadable: "),
1092 MakeDisplayPath(fname, 50));
1096 ifstream ifs(fname.c_str());
1098 WriteFSAlert(_("Error! Cannot open specified file: "),
1099 MakeDisplayPath(fname, 50));
1103 ifs.unsetf(ios::skipws);
1104 istream_iterator<char> ii(ifs);
1105 istream_iterator<char> end;
1106 //string tmpstr(ii, end); // yet a reason for using std::string
1107 // alternate approach to get the file into a string:
1109 copy(ii, end, back_inserter(tmpstr));
1110 // insert the string
1111 current_view->hideCursor();
1113 // clear the selection
1116 bv->text->InsertStringA(bv, tmpstr);
1118 bv->text->InsertStringB(bv, tmpstr);
1119 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1123 void MenuShowTableOfContents()
1125 static int ow = -1, oh;
1128 if (fd_form_toc->form_toc->visible) {
1129 fl_raise_form(fd_form_toc->form_toc);
1131 fl_show_form(fd_form_toc->form_toc,
1132 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1133 _("Table Of Contents"));
1135 ow = fd_form_toc->form_toc->w;
1136 oh = fd_form_toc->form_toc->h;
1138 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1143 void MenuInsertLabel(char const * arg)
1146 ProhibitInput(current_view);
1147 if (label.empty()) {
1149 result = askForText(_("Enter new label to insert:"));
1151 label = frontStrip(strip(result.second));
1154 if (!label.empty()) {
1155 InsetLabel * new_inset = new InsetLabel;
1156 new_inset->setContents(label);
1157 current_view->insertInset(new_inset);
1159 AllowInput(current_view);
1163 void MenuInsertRef()
1165 static int ow = -1, oh;
1168 if (fd_form_ref->form_ref->visible) {
1169 fl_raise_form(fd_form_ref->form_ref);
1171 fl_show_form(fd_form_ref->form_ref,
1172 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1173 _("Insert Reference"));
1175 ow = fd_form_ref->form_ref->w;
1176 oh = fd_form_ref->form_ref->h;
1178 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1183 // candidate for move to LyXView
1184 // This is only used in toolbar.C
1185 void LayoutsCB(int sel, void *)
1187 string tmp = tostr(sel);
1188 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1194 * SGML Linuxdoc support:
1195 * (flag == 0) make TeX output
1196 * (flag == 1) make dvi output
1198 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1205 /* generate a path-less extension name */
1206 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1207 string path = OnlyPath (filename);
1208 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1209 path = bv->buffer()->tmppath;
1213 if (!bv->available())
1215 bv->buffer()->makeLinuxDocFile(name, false);
1217 // CHECK remove this once we have a proper geometry class
1219 BufferParams::PAPER_SIZE ps =
1220 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1222 case BufferParams::PAPER_A4PAPER:
1223 add_flags = "-p a4";
1225 case BufferParams::PAPER_USLETTER:
1226 add_flags = "-p letter";
1228 default: /* nothing to be done yet ;-) */ break;
1235 case 0: /* TeX output asked */
1236 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1237 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1238 if (one.startscript(Systemcalls::System, s2))
1241 case 1: /* dvi output asked */
1242 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1243 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1244 if (one.startscript(Systemcalls::System, s2)) {
1248 default: /* unknown output */
1254 bv->buffer()->redraw();
1260 * SGML DocBook support:
1261 * (flag == 1) make dvi output
1263 int RunDocBook(int flag, string const & filename)
1265 /* generate a path-less extension name */
1266 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1267 string path = OnlyPath (filename);
1268 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1269 path = current_view->buffer()->tmppath;
1273 if (!current_view->available())
1276 current_view->buffer()->makeDocBookFile(name, false);
1278 // Shall this code go or should it stay? (Lgb)
1279 // This code is a placeholder for future implementation. (Jose')
1280 // string add_flags;
1281 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1283 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1284 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1285 // default: /* nothing to be done yet ;-) */ break;
1287 ProhibitInput(current_view);
1292 case 1: /* dvi output asked */
1294 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1295 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1296 if (one.startscript(Systemcalls::System, s2)) {
1301 default: /* unknown output */
1305 AllowInput(current_view);
1307 current_view->buffer()->redraw();
1312 void MenuLayoutCharacter()
1314 static int ow = -1, oh;
1316 if (fd_form_character->form_character->visible) {
1317 fl_raise_form(fd_form_character->form_character);
1319 fl_show_form(fd_form_character->form_character,
1320 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1321 _("Character Style"));
1323 ow = fd_form_character->form_character->w;
1324 oh = fd_form_character->form_character->h;
1326 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1332 void DeactivateParagraphButtons ()
1334 fl_deactivate_object (fd_form_paragraph->button_ok);
1335 fl_deactivate_object (fd_form_paragraph->button_apply);
1336 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1337 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1342 void ActivateParagraphButtons ()
1344 fl_activate_object (fd_form_paragraph->button_ok);
1345 fl_activate_object (fd_form_paragraph->button_apply);
1346 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1347 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1352 void DisableParagraphLayout ()
1354 DeactivateParagraphButtons();
1355 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1356 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1357 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1358 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1359 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1360 fl_deactivate_object (fd_form_paragraph->check_noindent);
1361 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1362 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1363 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1364 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1365 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1366 fl_deactivate_object (fd_form_paragraph->input_space_above);
1367 fl_deactivate_object (fd_form_paragraph->input_space_below);
1368 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1369 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1370 fl_deactivate_object (fd_form_paragraph->check_space_above);
1371 fl_deactivate_object (fd_form_paragraph->check_space_below);
1376 void EnableParagraphLayout ()
1378 ActivateParagraphButtons();
1379 fl_activate_object (fd_form_paragraph->input_labelwidth);
1380 fl_activate_object (fd_form_paragraph->check_lines_top);
1381 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1382 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1383 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1384 fl_activate_object (fd_form_paragraph->check_noindent);
1385 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1386 fl_activate_object (fd_form_paragraph->radio_align_right);
1387 fl_activate_object (fd_form_paragraph->radio_align_left);
1388 fl_activate_object (fd_form_paragraph->radio_align_block);
1389 fl_activate_object (fd_form_paragraph->radio_align_center);
1390 fl_activate_object (fd_form_paragraph->input_space_above);
1391 fl_activate_object (fd_form_paragraph->input_space_below);
1392 fl_activate_object (fd_form_paragraph->choice_space_above);
1393 fl_activate_object (fd_form_paragraph->choice_space_below);
1394 fl_activate_object (fd_form_paragraph->check_space_above);
1395 fl_activate_object (fd_form_paragraph->check_space_below);
1399 bool UpdateLayoutParagraph()
1401 if (!current_view->available()) {
1402 if (fd_form_paragraph->form_paragraph->visible)
1403 fl_hide_form(fd_form_paragraph->form_paragraph);
1407 Buffer * buf = current_view->buffer();
1409 fl_set_input(fd_form_paragraph->input_labelwidth,
1410 current_view->text->cursor.par()->GetLabelWidthString().c_str());
1411 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1412 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1413 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1414 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1416 int align = current_view->text->cursor.par()->GetAlign();
1417 if (align == LYX_ALIGN_LAYOUT)
1418 align = textclasslist.Style(buf->params.textclass,
1419 current_view->text->cursor.par()->GetLayout()).align;
1422 case LYX_ALIGN_RIGHT:
1423 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1425 case LYX_ALIGN_LEFT:
1426 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1428 case LYX_ALIGN_CENTER:
1429 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1432 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1436 fl_set_button(fd_form_paragraph->check_lines_top,
1437 current_view->text->cursor.par()->FirstPhysicalPar()->line_top);
1438 fl_set_button(fd_form_paragraph->check_lines_bottom,
1439 current_view->text->cursor.par()->FirstPhysicalPar()->line_bottom);
1440 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1441 current_view->text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1442 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1443 current_view->text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1444 fl_set_button(fd_form_paragraph->check_noindent,
1445 current_view->text->cursor.par()->FirstPhysicalPar()->noindent);
1446 fl_set_input (fd_form_paragraph->input_space_above, "");
1448 switch (current_view->text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1450 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1452 case VSpace::DEFSKIP:
1453 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1455 case VSpace::SMALLSKIP:
1456 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1458 case VSpace::MEDSKIP:
1459 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1461 case VSpace::BIGSKIP:
1462 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1465 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1467 case VSpace::LENGTH:
1468 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1469 fl_set_input (fd_form_paragraph->input_space_above,
1470 current_view->text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1473 fl_set_button (fd_form_paragraph->check_space_above,
1474 current_view->text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1475 fl_set_input (fd_form_paragraph->input_space_below, "");
1476 switch (current_view->text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1478 fl_set_choice (fd_form_paragraph->choice_space_below,
1481 case VSpace::DEFSKIP:
1482 fl_set_choice (fd_form_paragraph->choice_space_below,
1485 case VSpace::SMALLSKIP:
1486 fl_set_choice (fd_form_paragraph->choice_space_below,
1489 case VSpace::MEDSKIP:
1490 fl_set_choice (fd_form_paragraph->choice_space_below,
1493 case VSpace::BIGSKIP:
1494 fl_set_choice (fd_form_paragraph->choice_space_below,
1498 fl_set_choice (fd_form_paragraph->choice_space_below,
1501 case VSpace::LENGTH:
1502 fl_set_choice (fd_form_paragraph->choice_space_below,
1504 fl_set_input (fd_form_paragraph->input_space_below,
1505 current_view->text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1508 fl_set_button (fd_form_paragraph->check_space_below,
1509 current_view->text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1511 fl_set_button(fd_form_paragraph->check_noindent,
1512 current_view->text->cursor.par()->FirstPhysicalPar()->noindent);
1514 if (current_view->buffer()->isReadonly()) {
1515 DisableParagraphLayout();
1517 EnableParagraphLayout();
1523 void MenuLayoutParagraph()
1525 if (UpdateLayoutParagraph()) {
1526 if (fd_form_paragraph->form_paragraph->visible) {
1527 fl_raise_form(fd_form_paragraph->form_paragraph);
1529 fl_show_form(fd_form_paragraph->form_paragraph,
1530 FL_PLACE_MOUSE, FL_FULLBORDER,
1531 _("Paragraph Environment"));
1538 void DeactivateDocumentButtons ()
1540 fl_deactivate_object (fd_form_document->button_ok);
1541 fl_deactivate_object (fd_form_document->button_apply);
1542 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1543 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1548 void ActivateDocumentButtons ()
1550 fl_activate_object (fd_form_document->button_ok);
1551 fl_activate_object (fd_form_document->button_apply);
1552 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1553 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1558 void DisableDocumentLayout ()
1560 DeactivateDocumentButtons ();
1561 fl_deactivate_object (fd_form_document->group_radio_separation);
1562 fl_deactivate_object (fd_form_document->radio_indent);
1563 fl_deactivate_object (fd_form_document->radio_skip);
1564 fl_deactivate_object (fd_form_document->choice_class);
1565 fl_deactivate_object (fd_form_document->choice_pagestyle);
1566 fl_deactivate_object (fd_form_document->choice_fonts);
1567 fl_deactivate_object (fd_form_document->choice_fontsize);
1568 fl_deactivate_object (fd_form_document->input_float_placement);
1569 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1570 fl_deactivate_object (fd_form_document->choice_inputenc);
1571 fl_deactivate_object (fd_form_document->group_radio_sides);
1572 fl_deactivate_object (fd_form_document->radio_sides_one);
1573 fl_deactivate_object (fd_form_document->radio_sides_two);
1574 fl_deactivate_object (fd_form_document->group_radio_columns);
1575 fl_deactivate_object (fd_form_document->radio_columns_one);
1576 fl_deactivate_object (fd_form_document->radio_columns_two);
1577 fl_deactivate_object (fd_form_document->input_extra);
1578 fl_deactivate_object (fd_form_document->choice_language);
1579 combo_language->deactivate();
1580 fl_deactivate_object (fd_form_document->input_default_skip);
1581 fl_deactivate_object (fd_form_document->choice_default_skip);
1582 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1583 fl_deactivate_object (fd_form_document->slider_tocdepth);
1584 fl_deactivate_object (fd_form_document->choice_spacing);
1585 fl_deactivate_object (fd_form_document->input_spacing);
1586 fl_deactivate_object (fd_form_document->check_use_amsmath);
1591 void EnableDocumentLayout ()
1593 ActivateDocumentButtons ();
1594 fl_activate_object (fd_form_document->group_radio_separation);
1595 fl_activate_object (fd_form_document->radio_indent);
1596 fl_activate_object (fd_form_document->radio_skip);
1597 fl_activate_object (fd_form_document->choice_class);
1598 fl_activate_object (fd_form_document->choice_pagestyle);
1599 fl_activate_object (fd_form_document->choice_fonts);
1600 fl_activate_object (fd_form_document->choice_fontsize);
1601 fl_activate_object (fd_form_document->input_float_placement);
1602 fl_activate_object (fd_form_document->choice_postscript_driver);
1603 fl_activate_object (fd_form_document->choice_inputenc);
1604 fl_activate_object (fd_form_document->group_radio_sides);
1605 fl_activate_object (fd_form_document->radio_sides_one);
1606 fl_activate_object (fd_form_document->radio_sides_two);
1607 fl_activate_object (fd_form_document->group_radio_columns);
1608 fl_activate_object (fd_form_document->radio_columns_one);
1609 fl_activate_object (fd_form_document->radio_columns_two);
1610 fl_activate_object (fd_form_document->input_extra);
1611 fl_activate_object (fd_form_document->choice_language);
1612 combo_language->activate();
1613 fl_activate_object (fd_form_document->input_default_skip);
1614 fl_activate_object (fd_form_document->choice_default_skip);
1615 fl_activate_object (fd_form_document->slider_secnumdepth);
1616 fl_activate_object (fd_form_document->slider_tocdepth);
1617 fl_activate_object (fd_form_document->choice_spacing);
1618 fl_activate_object (fd_form_document->input_spacing);
1619 fl_activate_object (fd_form_document->check_use_amsmath);
1623 bool UpdateLayoutDocument(BufferParams * params)
1625 if (!current_view->available()) {
1626 if (fd_form_document->form_document->visible)
1627 fl_hide_form(fd_form_document->form_document);
1632 params = ¤t_view->buffer()->params;
1633 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1635 fl_set_choice_text(fd_form_document->choice_class,
1636 textclasslist.DescOfClass(params->textclass).c_str());
1637 combo_language->select_text(params->language.c_str());
1639 fl_set_choice_text(fd_form_document->choice_fonts,
1640 params->fonts.c_str());
1641 fl_set_choice_text(fd_form_document->choice_inputenc,
1642 params->inputenc.c_str());
1643 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1644 params->graphicsDriver.c_str());
1646 // ale970405+lasgoutt970513
1647 fl_clear_choice(fd_form_document->choice_fontsize);
1648 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1649 fl_addto_choice(fd_form_document->choice_fontsize,
1650 tclass.opt_fontsize().c_str());
1651 fl_set_choice(fd_form_document->choice_fontsize,
1652 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1654 // ale970405+lasgoutt970513
1655 fl_clear_choice(fd_form_document->choice_pagestyle);
1656 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1657 fl_addto_choice(fd_form_document->choice_pagestyle,
1658 tclass.opt_pagestyle().c_str());
1660 fl_set_choice(fd_form_document->choice_pagestyle,
1661 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1663 fl_set_button(fd_form_document->radio_indent, 0);
1664 fl_set_button(fd_form_document->radio_skip, 0);
1667 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1669 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1670 fl_set_button(fd_form_document->radio_indent, 1);
1672 fl_set_button(fd_form_document->radio_skip, 1);
1674 switch (params->getDefSkip().kind()) {
1675 case VSpace::SMALLSKIP:
1676 fl_set_choice (fd_form_document->choice_default_skip, 1);
1678 case VSpace::MEDSKIP:
1679 fl_set_choice (fd_form_document->choice_default_skip, 2);
1681 case VSpace::BIGSKIP:
1682 fl_set_choice (fd_form_document->choice_default_skip, 3);
1684 case VSpace::LENGTH:
1685 fl_set_choice (fd_form_document->choice_default_skip, 4);
1686 fl_set_input (fd_form_document->input_default_skip,
1687 params->getDefSkip().asLyXCommand().c_str());
1690 fl_set_choice (fd_form_document->choice_default_skip, 2);
1694 fl_set_button(fd_form_document->radio_sides_one, 0);
1695 fl_set_button(fd_form_document->radio_sides_two, 0);
1697 switch (params->sides) {
1698 case LyXTextClass::OneSide:
1699 fl_set_button(fd_form_document->radio_sides_one, 1);
1701 case LyXTextClass::TwoSides:
1702 fl_set_button(fd_form_document->radio_sides_two, 1);
1706 fl_set_button(fd_form_document->radio_columns_one, 0);
1707 fl_set_button(fd_form_document->radio_columns_two, 0);
1709 if (params->columns == 2)
1710 fl_set_button(fd_form_document->radio_columns_two, 1);
1712 fl_set_button(fd_form_document->radio_columns_one, 1);
1714 fl_set_input(fd_form_document->input_spacing, "");
1715 switch (params->spacing.getSpace()) {
1716 case Spacing::Default: // nothing bad should happen with this
1717 case Spacing::Single:
1720 fl_set_choice(fd_form_document->choice_spacing, 1);
1723 case Spacing::Onehalf:
1726 fl_set_choice(fd_form_document->choice_spacing, 2);
1729 case Spacing::Double:
1732 fl_set_choice(fd_form_document->choice_spacing, 3);
1735 case Spacing::Other:
1737 fl_set_choice(fd_form_document->choice_spacing, 4);
1739 //sprintf(sval, "%g", params->spacing.getValue());
1741 std::ostringstream sval;
1742 sval << params->spacing.getValue(); // setw?
1743 fl_set_input(fd_form_document->input_spacing,
1744 sval.str().c_str());
1747 ostrstream sval(tval, 20);
1748 sval << params->spacing.getValue() << '\0'; // setw?
1749 fl_set_input(fd_form_document->input_spacing, sval.str());
1756 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1757 params->secnumdepth);
1758 fl_set_counter_value(fd_form_document->slider_tocdepth,
1760 if (!params->float_placement.empty()) { // buffer local (Lgb)
1761 fl_set_input(fd_form_document->input_float_placement,
1762 params->float_placement.c_str());
1764 fl_set_input(fd_form_document->input_float_placement, "");
1766 if (!params->options.empty())
1767 fl_set_input(fd_form_document->input_extra,
1768 params->options.c_str());
1770 fl_set_input(fd_form_document->input_extra, "");
1772 if (current_view->buffer()->isSGML()) {
1773 // bullets not used in SGML derived documents
1774 fl_deactivate_object(fd_form_document->button_bullets);
1775 fl_set_object_lcol(fd_form_document->button_bullets,
1778 fl_activate_object(fd_form_document->button_bullets);
1779 fl_set_object_lcol(fd_form_document->button_bullets,
1783 if (current_view->buffer()->isReadonly()) {
1784 DisableDocumentLayout();
1786 EnableDocumentLayout();
1793 void MenuLayoutDocument()
1795 if (UpdateLayoutDocument()) {
1796 if (fd_form_document->form_document->visible) {
1797 fl_raise_form(fd_form_document->form_document);
1799 fl_show_form(fd_form_document->form_document,
1800 FL_PLACE_MOUSE, FL_FULLBORDER,
1801 _("Document Layout"));
1807 bool UpdateLayoutQuotes()
1810 if (!current_view->available()
1811 || current_view->buffer()->isReadonly())
1815 fl_set_choice(fd_form_quotes->choice_quotes_language,
1816 current_view->buffer()->params.quotes_language + 1);
1817 fl_set_button(fd_form_quotes->radio_single, 0);
1818 fl_set_button(fd_form_quotes->radio_double, 0);
1820 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1821 fl_set_button(fd_form_quotes->radio_single, 1);
1823 fl_set_button(fd_form_quotes->radio_double, 1);
1824 } else if (fd_form_quotes->form_quotes->visible) {
1825 fl_hide_form(fd_form_quotes->form_quotes);
1831 void MenuLayoutQuotes()
1833 if (UpdateLayoutQuotes()) {
1834 if (fd_form_quotes->form_quotes->visible) {
1835 fl_raise_form(fd_form_quotes->form_quotes);
1837 fl_show_form(fd_form_quotes->form_quotes,
1838 FL_PLACE_MOUSE, FL_FULLBORDER,
1845 bool UpdateLayoutPreamble()
1848 if (!current_view->available())
1852 fl_set_input(fd_form_preamble->input_preamble,
1853 current_view->buffer()->params.preamble.c_str());
1855 if (current_view->buffer()->isReadonly()) {
1856 fl_deactivate_object(fd_form_preamble->input_preamble);
1857 fl_deactivate_object(fd_form_preamble->button_ok);
1858 fl_deactivate_object(fd_form_preamble->button_apply);
1859 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1860 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1863 fl_activate_object(fd_form_preamble->input_preamble);
1864 fl_activate_object(fd_form_preamble->button_ok);
1865 fl_activate_object(fd_form_preamble->button_apply);
1866 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1867 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1869 } else if (fd_form_preamble->form_preamble->visible) {
1870 fl_hide_form(fd_form_preamble->form_preamble);
1876 void MenuLayoutPreamble()
1878 static int ow = -1, oh;
1880 if (UpdateLayoutPreamble()) {
1881 if (fd_form_preamble->form_preamble->visible) {
1882 fl_raise_form(fd_form_preamble->form_preamble);
1884 fl_show_form(fd_form_preamble->form_preamble,
1885 FL_PLACE_MOUSE | FL_FREE_SIZE,
1887 _("LaTeX Preamble"));
1889 ow = fd_form_preamble->form_preamble->w;
1890 oh = fd_form_preamble->form_preamble->h;
1892 fl_set_form_minsize(fd_form_preamble->form_preamble,
1899 void MenuLayoutSave()
1901 if (!current_view->available())
1904 if (AskQuestion(_("Do you want to save the current settings"),
1905 _("for Character, Document, Paper and Quotes"),
1906 _("as default for new documents?")))
1907 current_view->buffer()->saveParamsAsDefaults();
1911 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1912 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1913 LyXFont UserFreeFont(BufferParams const & params)
1915 LyXFont font(LyXFont::ALL_IGNORE);
1917 int pos = fl_get_choice(fd_form_character->choice_family);
1919 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1920 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1921 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1922 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1923 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1926 pos = fl_get_choice(fd_form_character->choice_series);
1928 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1929 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1930 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1931 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1934 pos = fl_get_choice(fd_form_character->choice_shape);
1936 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1937 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1938 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1939 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1940 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1941 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1944 pos = fl_get_choice(fd_form_character->choice_size);
1946 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1947 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1948 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1949 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1950 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1951 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1952 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1953 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1954 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1955 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1956 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1957 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
1958 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
1959 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
1962 pos = fl_get_choice(fd_form_character->choice_bar);
1964 case 1: font.setEmph(LyXFont::IGNORE);
1965 font.setUnderbar(LyXFont::IGNORE);
1966 font.setNoun(LyXFont::IGNORE);
1967 font.setLatex(LyXFont::IGNORE);
1969 case 2: font.setEmph(LyXFont::TOGGLE); break;
1970 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
1971 case 4: font.setNoun(LyXFont::TOGGLE); break;
1972 case 5: font.setLatex(LyXFont::TOGGLE); break;
1973 case 6: font.setEmph(LyXFont::INHERIT);
1974 font.setUnderbar(LyXFont::INHERIT);
1975 font.setNoun(LyXFont::INHERIT);
1976 font.setLatex(LyXFont::INHERIT);
1980 pos = fl_get_choice(fd_form_character->choice_color);
1982 case 1: font.setColor(LColor::ignore); break;
1983 case 2: font.setColor(LColor::none); break;
1984 case 3: font.setColor(LColor::black); break;
1985 case 4: font.setColor(LColor::white); break;
1986 case 5: font.setColor(LColor::red); break;
1987 case 6: font.setColor(LColor::green); break;
1988 case 7: font.setColor(LColor::blue); break;
1989 case 8: font.setColor(LColor::cyan); break;
1990 case 9: font.setColor(LColor::magenta); break;
1991 case 10: font.setColor(LColor::yellow); break;
1992 case 11: font.setColor(LColor::inherit); break;
1995 int choice = combo_language2->get();
1997 font.setLanguage(ignore_language);
1998 else if (choice == 2)
1999 font.setLanguage(params.language_info);
2001 font.setLanguage(&languages[combo_language2->getline()]);
2007 /* callbacks for form form_title */
2008 extern "C" void TimerCB(FL_OBJECT *, long)
2010 // only if the form still exists
2011 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2012 if (fd_form_title->form_title->visible) {
2013 fl_hide_form(fd_form_title->form_title);
2015 fl_free_form(fd_form_title->form_title);
2016 fd_form_title->form_title = 0;
2021 /* callbacks for form form_paragraph */
2023 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2025 // "Synchronize" the choices and input fields, making it
2026 // impossible to commit senseless data.
2028 FD_form_paragraph const * fp = fd_form_paragraph;
2030 if (obj == fp->choice_space_above) {
2031 if (fl_get_choice (fp->choice_space_above) != 7) {
2032 fl_set_input (fp->input_space_above, "");
2033 ActivateParagraphButtons();
2035 } else if (obj == fp->choice_space_below) {
2036 if (fl_get_choice (fp->choice_space_below) != 7) {
2037 fl_set_input (fp->input_space_below, "");
2038 ActivateParagraphButtons();
2040 } else if (obj == fp->input_space_above) {
2041 string input = fl_get_input (fp->input_space_above);
2043 if (input.empty()) {
2044 fl_set_choice (fp->choice_space_above, 1);
2045 ActivateParagraphButtons();
2047 else if (isValidGlueLength (input)) {
2048 fl_set_choice (fp->choice_space_above, 7);
2049 ActivateParagraphButtons();
2052 fl_set_choice (fp->choice_space_above, 7);
2053 DeactivateParagraphButtons();
2055 } else if (obj == fp->input_space_below) {
2056 string input = fl_get_input (fp->input_space_below);
2058 if (input.empty()) {
2059 fl_set_choice (fp->choice_space_below, 1);
2060 ActivateParagraphButtons();
2062 else if (isValidGlueLength (input)) {
2063 fl_set_choice (fp->choice_space_below, 7);
2064 ActivateParagraphButtons();
2067 fl_set_choice (fp->choice_space_below, 7);
2068 DeactivateParagraphButtons();
2074 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2076 if (!current_view->available())
2079 VSpace space_top, space_bottom;
2081 string labelwidthstring;
2084 // If a vspace kind is "Length" but there's no text in
2085 // the input field, reset the kind to "None".
2086 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2087 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2088 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2090 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2091 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2092 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2095 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2096 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2097 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2098 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2099 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2100 case 1: space_top = VSpace(VSpace::NONE); break;
2101 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2102 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2103 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2104 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2105 case 6: space_top = VSpace(VSpace::VFILL); break;
2106 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2108 if (fl_get_button (fd_form_paragraph->check_space_above))
2109 space_top.setKeep (true);
2110 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2111 case 1: space_bottom = VSpace(VSpace::NONE); break;
2112 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2113 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2114 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2115 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2116 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2117 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2119 if (fl_get_button (fd_form_paragraph->check_space_below))
2120 space_bottom.setKeep (true);
2122 if (fl_get_button(fd_form_paragraph->radio_align_left))
2123 align = LYX_ALIGN_LEFT;
2124 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2125 align = LYX_ALIGN_RIGHT;
2126 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2127 align = LYX_ALIGN_CENTER;
2129 align = LYX_ALIGN_BLOCK;
2131 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2132 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2134 current_view->text->SetParagraph(current_view,
2144 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2145 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2149 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2151 fl_hide_form(fd_form_paragraph->form_paragraph);
2155 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2157 ParagraphApplyCB(ob, data);
2158 ParagraphCancelCB(ob, data);
2162 /* callbacks for form form_character */
2164 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2166 // we set toggleall locally here, since it should be true for
2167 // all other uses of ToggleAndShow() (JMarc)
2168 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2169 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2170 current_view->setState();
2175 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2177 fl_hide_form(fd_form_character->form_character);
2181 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2183 CharacterApplyCB(ob, data);
2184 CharacterCloseCB(ob, data);
2188 /* callbacks for form form_document */
2190 void UpdateDocumentButtons(BufferParams const & params)
2192 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2194 switch (params.sides) {
2195 case LyXTextClass::OneSide:
2196 fl_set_button(fd_form_document->radio_sides_one, 1);
2198 case LyXTextClass::TwoSides:
2199 fl_set_button(fd_form_document->radio_sides_two, 1);
2203 if (params.columns == 2)
2204 fl_set_button(fd_form_document->radio_columns_two, 1);
2206 fl_set_button(fd_form_document->radio_columns_one, 1);
2208 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2209 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2210 params.secnumdepth);
2211 fl_set_counter_value(fd_form_document->slider_tocdepth,
2216 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2218 ProhibitInput(current_view);
2219 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2220 if (AskQuestion(_("Should I set some parameters to"),
2221 fl_get_choice_text(ob),
2222 _("the defaults of this document class?"))) {
2223 BufferParams params = BufferParams();
2224 params.textclass = fl_get_choice(ob)-1;
2225 params.useClassDefaults();
2226 UpdateLayoutDocument(¶ms);
2227 UpdateDocumentButtons(params);
2230 // unable to load new style
2231 WriteAlert(_("Conversion Errors!"),
2232 _("Unable to switch to new document class."),
2233 _("Reverting to original document class."));
2234 fl_set_choice(fd_form_document->choice_class,
2235 current_view->buffer()->params.textclass + 1);
2237 AllowInput(current_view);
2241 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2243 // "Synchronize" the choice and the input field, so that it
2244 // is impossible to commit senseless data.
2245 FD_form_document const * fd = fd_form_document;
2247 if (obj == fd->choice_default_skip) {
2248 if (fl_get_choice (fd->choice_default_skip) != 4) {
2249 fl_set_input (fd->input_default_skip, "");
2250 ActivateDocumentButtons();
2252 } else if (obj == fd->input_default_skip) {
2254 char const * input = fl_get_input (fd->input_default_skip);
2257 fl_set_choice (fd->choice_default_skip, 2);
2258 ActivateDocumentButtons();
2259 } else if (isValidGlueLength (input)) {
2260 fl_set_choice (fd->choice_default_skip, 4);
2261 ActivateDocumentButtons();
2263 fl_set_choice (fd->choice_default_skip, 4);
2264 DeactivateDocumentButtons();
2270 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2272 // "Synchronize" the choice and the input field, so that it
2273 // is impossible to commit senseless data.
2274 FD_form_document const * fd = fd_form_document;
2276 if (obj == fd->choice_spacing
2277 && fl_get_choice (fd->choice_spacing) != 4) {
2278 fl_set_input(fd->input_spacing, "");
2279 } else if (obj == fd->input_spacing) {
2281 const char* input = fl_get_input (fd->input_spacing);
2284 fl_set_choice (fd->choice_spacing, 1);
2286 fl_set_choice (fd->choice_spacing, 4);
2292 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2295 BufferParams * params = &(current_view->buffer()->params);
2297 Language const * old_language = params->language_info;
2298 params->language = combo_language->getline();
2299 Languages::iterator lit = languages.find(params->language);
2301 Language const * new_language;
2302 if (lit != languages.end())
2303 new_language = &(*lit).second;
2305 new_language = default_language;
2307 if (current_view->available()) {
2308 if (old_language != new_language
2309 && old_language->RightToLeft() == new_language->RightToLeft()
2310 && !current_view->buffer()->isMultiLingual())
2311 current_view->buffer()->ChangeLanguage(old_language,
2313 if (old_language != new_language) {
2314 //current_view->buffer()->redraw();
2318 params->language_info = new_language;
2320 // If default skip is a "Length" but there's no text in the
2321 // input field, reset the kind to "Medskip", which is the default.
2322 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2323 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2324 fl_set_choice (fd_form_document->choice_default_skip, 2);
2327 /* this shouldn't be done automatically IMO. For example I write german
2328 * documents with an american keyboard very often. Matthias */
2330 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2331 fl_get_choice(fd_form_document->choice_language)); */
2333 fl_get_choice_text(fd_form_document->choice_fonts);
2335 fl_get_choice_text(fd_form_document->choice_inputenc);
2337 fl_get_choice_text(fd_form_document->choice_fontsize);
2339 fl_get_choice_text(fd_form_document->choice_pagestyle);
2340 params->graphicsDriver =
2341 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2342 params->use_amsmath =
2343 fl_get_button(fd_form_document->check_use_amsmath);
2345 if (!current_view->available())
2348 current_view->text->SetCursor(current_view,
2349 current_view->text->cursor.par(),
2350 current_view->text->cursor.pos());
2351 current_view->setState();
2353 LyXTextClassList::ClassList::size_type new_class =
2354 fl_get_choice(fd_form_document->choice_class) - 1;
2356 if (params->textclass != new_class) {
2357 // try to load new_class
2358 if (textclasslist.Load(new_class)) {
2359 // successfully loaded
2361 current_view->owner()->getMiniBuffer()->
2362 Set(_("Converting document to new document class..."));
2364 int ret = cap.SwitchLayoutsBetweenClasses(
2365 current_view->buffer()->params.textclass,
2367 current_view->buffer()->paragraph);
2372 s = _("One paragraph couldn't be converted");
2375 s += _(" paragraphs couldn't be converted");
2377 WriteAlert(_("Conversion Errors!"), s,
2378 _("into chosen document class"));
2381 params->textclass = new_class;
2383 // problem changing class -- warn user and retain old style
2384 WriteAlert(_("Conversion Errors!"),
2385 _("Unable to switch to new document class."),
2386 _("Reverting to original document class."));
2387 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2391 char tmpsep = params->paragraph_separation;
2392 if (fl_get_button(fd_form_document->radio_indent))
2393 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2395 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2396 if (tmpsep != params->paragraph_separation)
2399 VSpace tmpdefskip = params->getDefSkip();
2400 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2401 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2402 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2403 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2404 case 4: params->setDefSkip(
2405 VSpace (LyXGlueLength (fl_get_input
2406 (fd_form_document->input_default_skip))));
2408 // DocumentDefskipCB assures that this never happens
2409 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2411 if (!(tmpdefskip == params->getDefSkip()))
2414 if (fl_get_button(fd_form_document->radio_columns_two))
2415 params->columns = 2;
2417 params->columns = 1;
2418 if (fl_get_button(fd_form_document->radio_sides_two))
2419 params->sides = LyXTextClass::TwoSides;
2421 params->sides = LyXTextClass::OneSide;
2423 Spacing tmpSpacing = params->spacing;
2424 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2426 lyxerr.debug() << "Spacing: SINGLE" << endl;
2427 params->spacing.set(Spacing::Single);
2430 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2431 params->spacing.set(Spacing::Onehalf);
2434 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2435 params->spacing.set(Spacing::Double);
2438 lyxerr.debug() << "Spacing: OTHER" << endl;
2439 params->spacing.set(Spacing::Other,
2440 fl_get_input(fd_form_document->input_spacing));
2443 if (tmpSpacing != params->spacing)
2446 signed char tmpchar =
2447 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2448 if (params->secnumdepth != tmpchar)
2450 params->secnumdepth = tmpchar;
2453 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2455 params->float_placement =
2456 fl_get_input(fd_form_document->input_float_placement);
2458 // More checking should be done to ensure the string doesn't have
2459 // spaces or illegal placement characters in it. (thornley)
2462 current_view->redoCurrentBuffer();
2464 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2465 current_view->buffer()->markDirty();
2468 fl_get_input(fd_form_document->input_extra);
2472 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2474 fl_hide_form(fd_form_document->form_document);
2478 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2480 DocumentCancelCB(ob, data);
2481 DocumentApplyCB(ob, data);
2485 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2488 // bullet callbacks etc. in bullet_panel.C -- ARRae
2492 /* callbacks for form form_quotes */
2494 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2496 if (!current_view->available())
2499 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2500 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2501 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2503 lga = InsetQuotes::EnglishQ;
2506 lga = InsetQuotes::SwedishQ;
2509 lga = InsetQuotes::GermanQ;
2512 lga = InsetQuotes::PolishQ;
2515 lga = InsetQuotes::FrenchQ;
2518 lga = InsetQuotes::DanishQ;
2521 current_view->buffer()->params.quotes_language = lga;
2522 if (fl_get_button(fd_form_quotes->radio_single))
2523 current_view->buffer()->
2524 params.quotes_times = InsetQuotes::SingleQ;
2526 current_view->buffer()->
2527 params.quotes_times = InsetQuotes::DoubleQ;
2531 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2533 fl_hide_form(fd_form_quotes->form_quotes);
2537 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2539 QuotesApplyCB(ob, data);
2540 QuotesCancelCB(ob, data);
2545 /* callbacks for form form_preamble */
2547 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2549 fl_hide_form(fd_form_preamble->form_preamble);
2553 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2555 if (!current_view->available())
2558 current_view->buffer()->params.preamble =
2559 fl_get_input(fd_form_preamble->input_preamble);
2560 current_view->buffer()->markDirty();
2561 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2565 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2567 PreambleApplyCB(ob, data);
2568 PreambleCancelCB(ob, data);
2572 /* callbacks for form form_table */
2574 extern "C" void TableApplyCB(FL_OBJECT *, long)
2576 if (!current_view->available())
2579 // check for tables in tables
2580 if (current_view->text->cursor.par()->table){
2581 WriteAlert(_("Impossible Operation!"),
2582 _("Cannot insert table in table."),
2587 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2589 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2590 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2593 current_view->hideCursor();
2594 current_view->beforeChange();
2595 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2597 current_view->text->SetCursorParUndo(current_view->buffer());
2598 current_view->text->FreezeUndo();
2600 current_view->text->BreakParagraph(current_view);
2601 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2603 if (current_view->text->cursor.par()->Last()) {
2604 current_view->text->CursorLeft(current_view);
2606 current_view->text->BreakParagraph(current_view);
2607 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2610 current_view->text->current_font.setLatex(LyXFont::OFF);
2611 //if (!fl_get_button(fd_form_table->check_latex)){
2612 // insert the new wysiwy table
2613 current_view->text->SetLayout(current_view, 0); // standard layout
2614 if (current_view->text->cursor.par()->footnoteflag ==
2615 LyXParagraph::NO_FOOTNOTE) {
2617 ->SetParagraph(current_view, 0, 0,
2619 VSpace (0.3 * current_view->buffer()->
2620 params.spacing.getValue(),
2622 VSpace (0.3 * current_view->buffer()->
2623 params.spacing.getValue(),
2630 ->SetParagraph(current_view, 0, 0,
2632 VSpace(VSpace::NONE),
2633 VSpace(VSpace::NONE),
2639 current_view->text->cursor.par()->table =
2640 new LyXTable(xsize, ysize);
2642 Language const * lang =
2643 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2644 LyXFont font(LyXFont::ALL_INHERIT, lang);
2645 for (int i = 0; i < xsize * ysize - 1; ++i) {
2646 current_view->text->cursor.par()
2647 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2649 current_view->text->RedoParagraph(current_view);
2651 current_view->text->UnFreezeUndo();
2653 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2654 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2655 current_view->setState();
2659 extern "C" void TableCancelCB(FL_OBJECT *, long)
2661 fl_hide_form(fd_form_table->form_table);
2665 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2667 TableApplyCB(ob, data);
2668 TableCancelCB(ob, data);
2674 if (fd_form_figure->form_figure->visible) {
2675 fl_raise_form(fd_form_figure->form_figure);
2677 fl_show_form(fd_form_figure->form_figure,
2678 FL_PLACE_MOUSE, FL_FULLBORDER,
2679 _("Insert Figure"));
2686 if (fd_form_table->form_table->visible) {
2687 fl_raise_form(fd_form_table->form_table);
2689 fl_show_form(fd_form_table->form_table,
2690 FL_PLACE_MOUSE, FL_FULLBORDER,
2696 /* callbacks for form form_figure */
2697 extern "C" void FigureApplyCB(FL_OBJECT *, long)
2699 if (!current_view->available())
2702 Buffer * buffer = current_view->buffer();
2703 if(buffer->isReadonly()) // paranoia
2706 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2707 if (fl_get_button(fd_form_figure->radio_inline)
2708 || current_view->text->cursor.par()->table) {
2709 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2710 current_view->insertInset(new_inset);
2711 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2712 new_inset->Edit(current_view, 0, 0, 0);
2716 current_view->hideCursor();
2717 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2718 current_view->beforeChange();
2720 current_view->text->SetCursorParUndo(current_view->buffer());
2721 current_view->text->FreezeUndo();
2723 current_view->text->BreakParagraph(current_view);
2724 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2726 if (current_view->text->cursor.par()->Last()) {
2727 current_view->text->CursorLeft(current_view);
2729 current_view->text->BreakParagraph(current_view);
2730 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2733 // The standard layout should always be numer 0;
2734 current_view->text->SetLayout(current_view, 0);
2736 if (current_view->text->cursor.par()->footnoteflag ==
2737 LyXParagraph::NO_FOOTNOTE) {
2738 current_view->text->
2739 SetParagraph(current_view, 0, 0,
2741 VSpace (0.3 * buffer->params.spacing.getValue(),
2744 buffer->params.spacing.getValue(),
2746 LYX_ALIGN_CENTER, string(), 0);
2748 current_view->text->SetParagraph(current_view, 0, 0,
2750 VSpace(VSpace::NONE),
2751 VSpace(VSpace::NONE),
2757 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2759 Inset * new_inset = new InsetFig(100, 100, buffer);
2760 current_view->insertInset(new_inset);
2761 new_inset->Edit(current_view, 0, 0, 0);
2762 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2763 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2764 current_view->text->UnFreezeUndo();
2765 current_view->setState();
2769 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2771 fl_hide_form(fd_form_figure->form_figure);
2775 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2777 FigureApplyCB(ob, data);
2778 FigureCancelCB(ob, data);
2782 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2784 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2785 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2786 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2787 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2788 lyxrc.set_font_norm_type();
2789 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2790 fontloader.update();
2792 // Of course we should only to the resize and the textcahce.clear
2793 // if values really changed...but not very important right now. (Lgb)
2795 // All buffers will need resize
2796 bufferlist.resize();
2797 // We also need to empty the textcache so that
2798 // the buffer will be formatted correctly after
2802 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2806 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2808 fl_hide_form(fd_form_screen->form_screen);
2812 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2814 ScreenCancelCB(ob, data);
2815 ScreenApplyCB(ob, data);
2819 void LaTeXOptions(BufferView * bv)
2821 if (!bv->available())
2824 fl_set_button(fd_latex_options->accents,
2825 int(bv->buffer()->params.allowAccents));
2827 if (fd_latex_options->LaTeXOptions->visible) {
2828 fl_raise_form(fd_latex_options->LaTeXOptions);
2830 fl_show_form(fd_latex_options->LaTeXOptions,
2831 FL_PLACE_MOUSE, FL_FULLBORDER,
2832 _("LaTeX Options"));
2837 // This function runs "configure" and then rereads lyx.defaults to
2838 // reconfigure the automatic settings.
2839 void Reconfigure(BufferView * bv)
2841 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2843 // Run configure in user lyx directory
2844 Path p(user_lyxdir);
2845 Systemcalls one(Systemcalls::System,
2846 AddName(system_lyxdir, "configure"));
2848 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2849 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2850 WriteAlert(_("The system has been reconfigured."),
2851 _("You need to restart LyX to make use of any"),
2852 _("updated document class specifications."));
2857 // Table of Contents
2860 static vector<Buffer::TocItem> toclist;
2863 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
2865 if (!current_view->available())
2869 unsigned int choice = fl_get_browser(ob);
2870 if (0 < choice && choice - 1 < toclist.size()) {
2871 current_view->beforeChange();
2872 current_view->text->SetCursor(current_view, toclist[choice-1].par, 0);
2873 current_view->text->sel_cursor =
2874 current_view->text->cursor;
2875 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2877 WriteAlert(_("Error"),
2878 _("Couldn't find this label"),
2879 _("in current document."));
2884 extern "C" void TocCancelCB(FL_OBJECT *, long)
2886 fl_hide_form(fd_form_toc->form_toc);
2891 void TocUpdateCB(FL_OBJECT *, long)
2893 if (!current_view->available()) {
2895 fl_clear_browser(fd_form_toc->browser_toc);
2896 fl_add_browser_line(fd_form_toc->browser_toc,
2897 _("*** No Document ***"));
2901 vector<vector<Buffer::TocItem> > tmp =
2902 current_view->buffer()->getTocList();
2903 int type = fl_get_choice(fd_form_toc->toctype)-1;
2904 //if (toclist == tmp[type])
2906 if (toclist.size() == tmp[type].size()) {
2907 // Check if all elements are the same.
2909 for (; i < toclist.size(); ++i) {
2910 if (toclist[i] != tmp[type][i])
2913 if (i >= toclist.size()) return;
2916 toclist = tmp[type];
2918 static Buffer * buffer = 0;
2921 if (buffer == current_view->buffer()) {
2922 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
2923 line = fl_get_browser(fd_form_toc->browser_toc);
2925 buffer = current_view->buffer();
2927 fl_clear_browser(fd_form_toc->browser_toc);
2928 fl_hide_object(fd_form_toc->browser_toc);
2930 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
2931 it != toclist.end(); ++it)
2932 fl_add_browser_line(fd_form_toc->browser_toc,
2933 (string(4*(*it).depth,' ')+
2934 (*it).str).c_str());
2936 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
2937 fl_select_browser_line(fd_form_toc->browser_toc, line);
2938 fl_show_object(fd_form_toc->browser_toc);
2942 /* callbacks for form form_ref */
2943 extern "C" void RefSelectCB(FL_OBJECT *, long data)
2945 if (!current_view->available())
2949 fl_get_browser_line(fd_form_ref->browser_ref,
2950 fl_get_browser(fd_form_ref->browser_ref));
2951 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
2957 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
2958 if (!current_view->NoSavedPositions()) {
2959 fl_activate_object(fd_form_ref->back);
2960 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
2963 } else if (data >= 6) {
2964 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK);
2965 if (current_view->NoSavedPositions()) {
2966 fl_deactivate_object(fd_form_ref->back);
2967 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
2972 static string const commands[5]
2973 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
2975 string t = commands[data];
2977 if (current_view->buffer()->isSGML())
2978 t += "[" + u + "]" + "{" + s + "}";
2983 new InsetRef(t, current_view->buffer());
2984 current_view->insertInset(new_inset);
2988 extern "C" void RefUpdateCB(FL_OBJECT *, long)
2990 if (!current_view->available()) {
2991 fl_clear_browser(fd_form_ref->browser_ref);
2995 FL_OBJECT * brow = fd_form_ref->browser_ref;
2997 // Get the current line, in order to restore it later
2998 char const * const btmp = fl_get_browser_line(brow,
2999 fl_get_browser(brow));
3000 string currentstr = btmp ? btmp : "";
3002 fl_clear_browser(brow);
3003 fl_hide_object(brow);
3005 vector<string> refs = current_view->buffer()->getLabelList();
3006 if (fl_get_button(fd_form_ref->sort))
3007 sort(refs.begin(),refs.end());
3008 for (vector<string>::const_iterator it = refs.begin();
3009 it != refs.end(); ++it)
3010 fl_add_browser_line(brow, (*it).c_str());
3013 int total_lines = fl_get_browser_maxline(brow);
3014 for (int i = 1; i <= total_lines ; ++i) {
3015 if (fl_get_browser_line(brow, i) == currentstr) {
3020 fl_set_browser_topline(brow, topline);
3022 bool empty = refs.empty();
3023 bool sgml = current_view->buffer()->isSGML();
3024 bool readonly = current_view->buffer()->isReadonly();
3026 if (current_view->NoSavedPositions()) {
3027 fl_deactivate_object(fd_form_ref->back);
3028 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
3030 fl_activate_object(fd_form_ref->back);
3031 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
3035 fl_add_browser_line(brow,
3036 _("*** No labels found in document ***"));
3037 fl_deactivate_object(brow);
3038 fl_deactivate_object(fd_form_ref->gotoref);
3039 fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE);
3041 fl_select_browser_line(brow, topline);
3042 fl_activate_object(brow);
3043 fl_activate_object(fd_form_ref->gotoref);
3044 fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK);
3047 if (empty || readonly) {
3048 fl_deactivate_object(fd_form_ref->ref);
3049 fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE);
3050 fl_deactivate_object(fd_form_ref->pageref);
3051 fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE);
3053 fl_activate_object(fd_form_ref->ref);
3054 fl_set_object_lcol(fd_form_ref->ref, FL_BLACK);
3055 fl_activate_object(fd_form_ref->pageref);
3056 fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK);
3059 if (empty || readonly || sgml) {
3060 fl_deactivate_object(fd_form_ref->vref);
3061 fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
3062 fl_deactivate_object(fd_form_ref->vpageref);
3063 fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
3064 fl_deactivate_object(fd_form_ref->prettyref);
3065 fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
3067 fl_activate_object(fd_form_ref->vref);
3068 fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
3069 fl_activate_object(fd_form_ref->vpageref);
3070 fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
3071 fl_activate_object(fd_form_ref->prettyref);
3072 fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
3076 fl_activate_object(fd_form_ref->ref_name);
3077 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3079 fl_deactivate_object(fd_form_ref->ref_name);
3080 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3083 fl_show_object(brow);
3087 extern "C" void RefHideCB(FL_OBJECT *, long)
3089 fl_hide_form(fd_form_ref->form_ref);