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_ref * fd_form_ref;
75 extern FD_form_bullet * fd_form_bullet;
77 extern BufferView * current_view; // called too many times in this file...
79 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
81 extern bool send_fax(string const & fname, string const & sendcmd);
82 extern void MenuSendto();
84 extern LyXServer * lyxserver;
86 // this should be static, but I need it in buffer.C
87 bool quitting; // flag, that we are quitting the program
88 extern bool finished; // all cleanup done just let it run through now.
90 char ascii_type; /* for selection notify callbacks */
92 bool scrolling = false;
94 // This is used to make the dreaded font toggle problem hopefully go
95 // away. Definitely not the best solution, but I think it sorta works.
96 bool toggleall = true;
99 This is the inset locking stuff needed for mathed --------------------
101 an inset can simple call LockInset in it's edit call and *ONLY* in it's
103 Inset::Edit() can only be called by the main lyx module.
105 Then the inset may modify the menu's and/or iconbars.
107 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
109 During the lock, all button and keyboard events will be modified
110 and send to the inset through the following inset-features. Note that
111 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
112 to contain the code for restoring the menus and things like this.
115 virtual void InsetButtonPress(int x, int y, int button);
116 virtual void InsetButtonRelease(int x, int y, int button);
117 virtual void InsetKeyPress(XKeyEvent *ev);
118 virtual void InsetMotionNotify(int x, int y, int state);
119 virtual void InsetUnlock();
121 If a inset wishes any redraw and/or update it just has to call
123 It's is completly irrelevant, where the inset is. UpdateInset will
124 find it in any paragraph in any buffer.
125 Of course the_locking_inset and the insets in the current paragraph/buffer
126 are checked first, so no performance problem should occur.
128 Hope that's ok for the beginning, Alejandro,
129 sorry that I needed so much time,
134 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
136 /* these functions return 1 if an error occured,
138 // Now they work only for updatable insets. [Alejandro 080596]
139 //int LockInset(UpdatableInset * inset);
140 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
141 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
142 //int UnlockInset(UpdatableInset * inset);
143 //void LockedInsetStoreUndo(Undo::undo_kind kind);
145 /* this is for asyncron updating. UpdateInsetUpdateList will be called
146 automatically from LyX. Just insert the Inset into the Updatelist */
147 //void UpdateInsetUpdateList();
148 //void PutInsetIntoInsetUpdateList(Inset * inset);
150 //InsetUpdateStruct * InsetUpdateList = 0;
154 -----------------------------------------------------------------------
157 /* some function prototypes */
159 int RunLinuxDoc(BufferView *, int, string const &);
160 int RunDocBook(int, string const &);
161 void MenuWrite(Buffer * buf);
162 bool MenuWriteAs(Buffer * buffer);
163 void MenuReload(Buffer * buf);
164 void MenuLayoutSave();
167 void ShowMessage(Buffer * buf,
169 string const & msg2 = string(),
170 string const & msg3 = string(), int delay = 6)
173 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
176 // can somebody think of something more clever? cerr?
177 cout << msg1 << msg2 << msg3 << endl;
190 // should be moved to lyxfunc.C
191 void MenuWrite(Buffer * buffer)
194 if (!buffer->save()) {
195 string fname = buffer->fileName();
196 string s = MakeAbsPath(fname);
197 if (AskQuestion(_("Save failed. Rename and try again?"),
198 MakeDisplayPath(s, 50),
199 _("(If not, document is not saved.)"))) {
203 lastfiles->newFile(buffer->fileName());
208 // should be moved to BufferView.C
209 // Half of this func should be in LyXView, the rest in BufferView.
210 bool MenuWriteAs(Buffer * buffer)
212 // Why do we require BufferView::text to be able to write a
213 // document? I see no point in that. (Lgb)
214 //if (!bv->text) return;
216 string fname = buffer->fileName();
217 string oldname = fname;
220 ProhibitInput(current_view);
221 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
222 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
224 if (!IsLyXFilename(fname))
227 if (buffer->isUnnamed()) {
228 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
233 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
236 OnlyFilename(fname));
238 AllowInput(current_view);
243 // Make sure the absolute filename ends with appropriate suffix
244 string s = MakeAbsPath(fname);
245 if (!IsLyXFilename(s))
248 // Same name as we have already?
250 if (!AskQuestion(_("Same name as document already has:"),
251 MakeDisplayPath(s, 50),
254 // Falls through to name change and save
256 // No, but do we have another file with this name open?
257 else if (bufferlist.exists(s)) {
258 if (AskQuestion(_("Another document with same name open!"),
259 MakeDisplayPath(s, 50),
260 _("Replace with current document?")))
262 bufferlist.close(bufferlist.getBuffer(s));
264 // Ok, change the name of the buffer, but don't save!
268 ShowMessage(buffer, _("Document renamed to '"),
269 MakeDisplayPath(s), _("', but not saved..."));
272 } // Check whether the file exists
275 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
276 MakeDisplayPath(s, 50),
281 // Ok, change the name of the buffer
284 buffer->setUnnamed(false);
286 // Small bug: If the save fails, we have irreversible changed the name
293 int MenuRunLaTeX(Buffer * buffer)
297 if (buffer->isLinuxDoc())
298 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
299 else if (buffer->isLiterate())
300 ret = buffer->runLiterate();
301 else if (buffer->isDocBook())
302 ret = RunDocBook(1, buffer->fileName());
304 ret = buffer->runLaTeX();
310 s = _("One error detected");
311 t = _("You should try to fix it.");
314 s += _(" errors detected.");
315 t = _("You should try to fix them.");
317 WriteAlert(_("There were errors during the LaTeX run."), s, t);
323 int MenuBuildProg(Buffer * buffer)
327 if (buffer->isLiterate())
328 ret = buffer->buildProgram();
330 string s = _("Wrong type of document");
331 string t = _("The Build operation is not allowed in this document");
332 WriteAlert(_("There were errors during the Build process."), s, t);
340 s = _("One error detected");
341 t = _("You should try to fix it.");
344 s += _(" errors detected.");
345 t = _("You should try to fix them.");
347 WriteAlert(_("There were errors during the Build process."), s, t);
353 int MenuRunChktex(Buffer * buffer)
357 if (buffer->isSGML()) {
358 WriteAlert(_("Chktex does not work with SGML derived documents."));
361 ret = buffer->runChktex();
367 s = _("No warnings found.");
368 } else if (ret == 1) {
369 s = _("One warning found.");
370 t = _("Use 'Edit->Go to Error' to find it.");
373 s += _(" warnings found.");
374 t = _("Use 'Edit->Go to Error' to find them.");
376 WriteAlert(_("Chktex run successfully"), s, t);
378 WriteAlert(_("Error!"), _("It seems chktex does not work."));
384 int MakeLaTeXOutput(Buffer * buffer)
390 string path = OnlyPath(buffer->fileName());
391 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
392 path = buffer->tmppath;
396 ret = MenuRunLaTeX(buffer);
402 /* wait == false means don't wait for termination */
403 /* wait == true means wait for termination */
404 // The bool should be placed last on the argument line. (Lgb)
405 // Returns false if we fail.
406 bool RunScript(Buffer * buffer, bool wait,
407 string const & command,
408 string const & orgname = string(),
409 bool need_shell = true)
413 string name = orgname;
416 if (MakeLaTeXOutput(buffer) > 0)
418 /* get DVI-Filename */
420 name = ChangeExtension(buffer->getLatexName(), ".dvi");
422 path = OnlyPath(name);
423 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
424 path = buffer->tmppath;
427 // At this point we check whether the command contains the
428 // filename parameter $$FName and if that's the case we
429 // substitute the real file name otherwise the filename is
430 // simply appended. rokrau 1/12/00
433 if ( (i=command.find("$$FName")) != string::npos)
435 cmd.replace(i,7,QuoteName(name));
438 cmd = command + ' ' + QuoteName(name);
447 // OS/2 cmd.exe has another use for '&'
449 // This is not NLS safe, but it's OK, I think.
450 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
452 // COMSPEC is set, unless user unsets
453 sh = OnlyFilename(GetEnvPath("COMSPEC"));
458 if (contains(sh, "cmd.exe")
459 || contains(sh, "4os2.exe"))
460 cmd = "start /min/n " + cmd;
465 // It seems that, if wait is false, we never get back
466 // the return code of the command. This means that all
467 // the code I added in PrintApplyCB is currently
469 // CHECK What should we do here?
470 ShowMessage(buffer, _("Executing command:"), cmd);
471 result = one.startscript(Systemcalls::System, cmd);
473 ShowMessage(buffer, _("Executing command:"), cmd);
474 result = one.startscript(wait ? Systemcalls::Wait
475 : Systemcalls::DontWait, cmd);
481 // Returns false if we fail
482 bool CreatePostscript(Buffer * buffer, bool wait = false)
488 ProhibitInput(current_view);
491 if (MakeLaTeXOutput(buffer) > 0) {
492 AllowInput(current_view);
495 // Generate postscript file
496 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
502 char real_papersize = buffer->params.papersize;
503 if (real_papersize == BufferParams::PAPER_DEFAULT)
504 real_papersize = lyxrc.default_papersize;
506 switch (real_papersize) {
507 case BufferParams::PAPER_USLETTER:
510 case BufferParams::PAPER_A3PAPER:
513 case BufferParams::PAPER_A4PAPER:
516 case BufferParams::PAPER_A5PAPER:
519 case BufferParams::PAPER_B5PAPER:
522 case BufferParams::PAPER_EXECUTIVEPAPER:
525 case BufferParams::PAPER_LEGALPAPER:
528 default: /* If nothing else fits, keep an empty value... */
532 // Make postscript file.
533 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
534 command += QuoteName(psname);
535 if (buffer->params.use_geometry
536 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
537 && !lyxrc.print_paper_dimension_flag.empty()
538 && !buffer->params.paperwidth.empty()
539 && !buffer->params.paperheight.empty()) {
540 // using a custom papersize
542 command += lyxrc.print_paper_dimension_flag + ' ';
543 command += buffer->params.paperwidth + ',';
544 command += buffer->params.paperheight;
545 } else if (!paper.empty()
546 && (real_papersize != BufferParams::PAPER_USLETTER ||
547 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
548 // dvips won't accept -t letter -t landscape. In all other
549 // cases, include the paper size explicitly.
551 command += lyxrc.print_paper_flag + ' ' + paper;
553 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
555 command += lyxrc.print_landscape_flag;
557 // push directorypath, if necessary
558 string path = OnlyPath(buffer->fileName());
559 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
560 path = buffer->tmppath;
563 bool ret = RunScript(buffer, wait, command);
564 AllowInput(current_view);
569 // Returns false if we fail
570 //bool MenuPreviewPS(Buffer * buffer)
571 bool PreviewPostscript(Buffer * buffer)
577 // Generate postscript file
578 if (!CreatePostscript(buffer, true)) {
582 // Start postscript viewer
583 ProhibitInput(current_view);
584 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
586 // push directorypath, if necessary
587 string path = OnlyPath(buffer->fileName());
588 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
589 path = buffer->tmppath;
592 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
593 AllowInput(current_view);
598 void MenuFax(Buffer * buffer)
604 // Generate postscript file
605 if (!CreatePostscript(buffer, true)) {
610 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
612 string path = OnlyPath (buffer->fileName());
613 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
614 path = buffer->tmppath;
617 if (!lyxrc.fax_program.empty()) {
618 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
620 Systemcalls one(Systemcalls::System, help2);
622 send_fax(ps, lyxrc.fax_command);
626 // Returns false if we fail
627 bool PreviewDVI(Buffer * buffer)
633 string paper = lyxrc.view_dvi_paper_option;
634 if (!paper.empty()) {
636 char real_papersize = buffer->params.papersize;
637 if (real_papersize == BufferParams::PAPER_DEFAULT)
638 real_papersize = lyxrc.default_papersize;
640 switch (real_papersize) {
641 case BufferParams::PAPER_USLETTER:
644 case BufferParams::PAPER_A3PAPER:
647 case BufferParams::PAPER_A4PAPER:
650 case BufferParams::PAPER_A5PAPER:
653 case BufferParams::PAPER_B5PAPER:
656 case BufferParams::PAPER_EXECUTIVEPAPER:
657 paper += " foolscap";
659 case BufferParams::PAPER_LEGALPAPER:
662 default: /* If nothing else fits, keep the empty value */
665 if (real_papersize==' ') {
666 // if (paper.empty()) {
667 if (buffer->params.orientation
668 == BufferParams::ORIENTATION_LANDSCAPE)
669 // we HAVE to give a size when the page is in
670 // landscape, so use USletter.
671 paper = " -paper usr";
673 // paper = " -paper " + paper;
674 if (buffer->params.orientation
675 == BufferParams::ORIENTATION_LANDSCAPE)
679 // push directorypath, if necessary
680 string path = OnlyPath(buffer->fileName());
681 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
682 path = buffer->tmppath;
686 string command = lyxrc.view_dvi_command + " " + paper;
687 bool ret = RunScript(buffer, false, command);
692 bool AskOverwrite(Buffer * buffer, string const & s)
695 // be friendly if there is a gui
698 !AskQuestion(_("File already exists:"),
699 MakeDisplayPath(s, 50),
700 _("Do you want to overwrite the file?"))) {
701 ShowMessage(buffer, _("Canceled"));
709 void MenuMakeLaTeX(Buffer * buffer)
711 // Why care about this?
715 // Get LaTeX-Filename
716 string s = buffer->getLatexName(false);
718 if (!AskOverwrite(buffer, s))
721 if (buffer->isDocBook())
722 ShowMessage(buffer, _("DocBook does not have a latex backend"));
724 if (buffer->isLinuxDoc())
725 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
727 buffer->makeLaTeXFile(s, string(), true);
728 ShowMessage(buffer, _("Nice LaTeX file saved as"),
734 void MenuMakeLinuxDoc(Buffer * buffer)
737 //if (!bv->text) return;
739 if (!buffer->isLinuxDoc()) {
740 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
744 // Get LinuxDoc-Filename
745 string s = ChangeExtension(buffer->fileName(), ".sgml");
747 if (!AskOverwrite(buffer, s))
750 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
751 MakeDisplayPath(s),"'...");
753 buffer->makeLinuxDocFile(s, true);
755 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
760 void MenuMakeDocBook(Buffer * buffer)
763 //if (!bv->text) return;
765 if (!buffer->isDocBook()) {
766 WriteAlert(_("Error!"),
767 _("Document class must be docbook."));
771 // Get DocBook-Filename
772 string s = ChangeExtension(buffer->fileName(), ".sgml");
774 if (!AskOverwrite(buffer, s))
777 ShowMessage(buffer, _("Building DocBook SGML file `"),
778 MakeDisplayPath(s), "'...");
780 buffer->makeDocBookFile(s, true);
782 ShowMessage(buffer, _("DocBook SGML file save as"),
787 void MenuMakeAscii(Buffer * buffer)
790 //if (!bv->text) return;
792 /* get LaTeX-Filename */
793 string s = ChangeExtension (buffer->fileName(), ".txt");
796 if (!AskOverwrite(buffer, s))
799 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
801 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
805 void MenuMakeHTML(Buffer * buffer)
807 // First, create LaTeX file
808 MenuMakeLaTeX(buffer);
810 // And now, run the converter
811 string file = buffer->fileName();
812 Path path(OnlyPath(file));
813 // the tex file name has to be correct for
814 // latex, but the html file name can be
816 string result = ChangeExtension(file, ".html");
817 string infile = buffer->getLatexName(false);
818 string tmp = lyxrc.html_command;
819 tmp = subst(tmp, "$$FName", infile);
820 tmp = subst(tmp, "$$OutName", result);
822 int res = one.startscript(Systemcalls::System, tmp);
824 ShowMessage(buffer, _("Document exported as HTML to file `")
825 + MakeDisplayPath(result) +'\'');
827 ShowMessage(buffer, _("Unable to convert to HTML the file `")
828 + MakeDisplayPath(infile)
835 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
837 // First, create LinuxDoc file
838 MenuMakeLinuxDoc(buffer);
840 // And now, run the converter
841 string file = buffer->fileName();
843 string result = ChangeExtension(file, ".html");
844 string infile = ChangeExtension(file, ".sgml");
845 string tmp = lyxrc.linuxdoc_to_html_command;
846 tmp = subst(tmp, "$$FName", infile);
847 tmp = subst(tmp, "$$OutName", result);
849 int res = one.startscript(Systemcalls::System, tmp);
851 ShowMessage(buffer,_("Document exported as HTML to file `")
852 + MakeDisplayPath(result) +'\'');
854 ShowMessage(buffer,_("Unable to convert to HTML the file `")
855 + MakeDisplayPath(infile)
861 void MenuMakeHTML_DocBook(Buffer * buffer)
863 // First, create LaTeX file
864 MenuMakeDocBook(buffer);
866 // And now, run the converter
867 string file = buffer->fileName();
868 string result = ChangeExtension(file, ".html");
869 string infile = ChangeExtension(file, ".sgml");
870 string tmp = lyxrc.docbook_to_html_command;
871 tmp = subst(tmp, "$$FName", infile);
872 tmp = subst(tmp, "$$OutName", result);
874 int res = one.startscript(Systemcalls::System, tmp);
876 ShowMessage(buffer,_("Document exported as HTML to file `")
877 + MakeDisplayPath(result) +'\'');
879 ShowMessage(buffer,_("Unable to convert to HTML the file `")
880 + MakeDisplayPath(infile)
887 void MenuExport(Buffer * buffer, string const & extyp)
890 if (extyp == "latex") {
891 // make sure that this buffer is not linuxdoc
892 MenuMakeLaTeX(buffer);
895 else if (extyp == "linuxdoc") {
896 // make sure that this buffer is not latex
897 MenuMakeLinuxDoc(buffer);
900 else if (extyp == "docbook") {
901 // make sure that this buffer is not latex or linuxdoc
902 MenuMakeDocBook(buffer);
905 else if (extyp == "dvi") {
906 // Run LaTeX as "Update dvi..." Bernhard.
907 // We want the dvi in the current directory. This
908 // is achieved by temporarily disabling use of
909 // temp directory. As a side-effect, we get
910 // *.log and *.aux files also. (Asger)
911 bool flag = lyxrc.use_tempdir;
912 lyxrc.use_tempdir = false;
913 MenuRunLaTeX(buffer);
914 lyxrc.use_tempdir = flag;
917 else if (extyp == "postscript") {
918 // Start Print-dialog. Not as good as dvi... Bernhard.
919 //should start lyxview->getDialogs()->showPrint();
920 // to get same as before
921 // MenuPrint(buffer);
922 // Since the MenuPrint is a pop-up, we can't use
923 // the same trick as above. (Asger)
924 // MISSING: Move of ps-file :-(
925 // And MenuPrint should not be used for this at all...
928 else if (extyp == "ascii") {
929 MenuMakeAscii(buffer);
931 else if (extyp == "custom") {
935 else if (extyp == "html") {
936 if (buffer->isLinuxDoc())
937 MenuMakeHTML_LinuxDoc(buffer);
938 else if (buffer->isDocBook())
939 MenuMakeHTML_DocBook(buffer);
941 MenuMakeHTML(buffer);
944 ShowMessage(buffer, _("Unknown export type: ") + extyp);
951 lyxerr.debug() << "Running QuitLyX." << endl;
953 if (!bufferlist.QwriteAll())
956 lastfiles->writeFile(lyxrc.lastfiles);
958 // Set a flag that we do quitting from the program,
959 // so no refreshes are necessary.
962 // close buffers first
963 bufferlist.closeAll();
965 // do any other cleanup procedures now
966 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
968 DestroyLyXTmpDir(system_tempdir);
975 void AutoSave(BufferView * bv)
976 // should probably be moved into BufferList (Lgb)
977 // Perfect target for a thread...
979 if (!bv->available())
982 if (bv->buffer()->isBakClean() ||
983 bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
984 // We don't save now, but we'll try again later
985 bv->owner()->resetAutosaveTimer();
989 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
991 // create autosave filename
992 string fname = OnlyPath(bv->buffer()->fileName());
994 fname += OnlyFilename(bv->buffer()->fileName());
997 // tmp_ret will be located (usually) in /tmp
998 // will that be a problem?
999 string tmp_ret = tmpnam(0);
1001 pid_t pid = fork(); // If you want to debug the autosave
1002 // you should set pid to -1, and comment out the
1004 if (pid == 0 || pid == -1) {
1005 // pid = -1 signifies that lyx was unable
1006 // to fork. But we will do the save
1008 bool failed = false;
1009 if (!tmp_ret.empty()) {
1010 bv->buffer()->writeFile(tmp_ret, 1);
1011 // assume successful write of tmp_ret
1012 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1014 // most likely couldn't move between filesystems
1015 // unless write of tmp_ret failed
1016 // so remove tmp file (if it exists)
1017 remove(tmp_ret.c_str());
1024 // failed to write/rename tmp_ret so try writing direct
1025 if (!bv->buffer()->writeFile(fname, 1)) {
1026 // It is dangerous to do this in the child,
1027 // but safe in the parent, so...
1029 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1032 if (pid == 0) { // we are the child so...
1037 bv->buffer()->markBakClean();
1038 bv->owner()->resetAutosaveTimer();
1043 // Copyright CHT Software Service GmbH
1046 // create new file with template
1049 Buffer * NewLyxFile(string const & filename)
1051 // Split argument by :
1053 string tmpname = split(filename, name, ':');
1054 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1055 if (name.length() == 1
1056 && isalpha(static_cast<unsigned char>(name[0]))
1057 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1059 name += token(tmpname, ':', 0);
1060 tmpname = split(tmpname, ':');
1063 lyxerr.debug() << "Arg is " << filename
1064 << "\nName is " << name
1065 << "\nTemplate is " << tmpname << endl;
1067 // find a free buffer
1068 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1070 lastfiles->newFile(tmpbuf->fileName());
1075 // Insert ascii file (if filename is empty, prompt for one)
1076 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1081 if (!bv->available()) return;
1083 if (fname.empty()) {
1085 fname = fileDlg.Select(_("File to Insert"),
1086 bv->owner()->buffer()->filepath,
1089 if (fname.empty()) return;
1094 if (!fi.readable()) {
1095 WriteFSAlert(_("Error! Specified file is unreadable: "),
1096 MakeDisplayPath(fname, 50));
1100 ifstream ifs(fname.c_str());
1102 WriteFSAlert(_("Error! Cannot open specified file: "),
1103 MakeDisplayPath(fname, 50));
1107 ifs.unsetf(ios::skipws);
1108 istream_iterator<char> ii(ifs);
1109 istream_iterator<char> end;
1110 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1111 // We use this until the compilers get better...
1113 copy(ii, end, back_inserter(tmp));
1114 string tmpstr(tmp.begin(), tmp.end());
1116 // This is what we want to use and what we will use once the
1117 // compilers get good enough.
1118 //string tmpstr(ii, end); // yet a reason for using std::string
1119 // alternate approach to get the file into a string:
1121 copy(ii, end, back_inserter(tmpstr));
1123 // insert the string
1124 current_view->hideCursor();
1126 // clear the selection
1129 bv->text->InsertStringA(bv, tmpstr);
1131 bv->text->InsertStringB(bv, tmpstr);
1132 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1136 void MenuInsertLabel(char const * arg)
1139 ProhibitInput(current_view);
1140 if (label.empty()) {
1142 result = askForText(_("Enter new label to insert:"));
1144 label = frontStrip(strip(result.second));
1147 if (!label.empty()) {
1148 InsetLabel * new_inset = new InsetLabel;
1149 new_inset->setContents(label);
1150 current_view->insertInset(new_inset);
1152 AllowInput(current_view);
1156 void MenuInsertRef()
1158 static int ow = -1, oh;
1161 if (fd_form_ref->form_ref->visible) {
1162 fl_raise_form(fd_form_ref->form_ref);
1164 fl_show_form(fd_form_ref->form_ref,
1165 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1166 _("Insert Reference"));
1168 ow = fd_form_ref->form_ref->w;
1169 oh = fd_form_ref->form_ref->h;
1171 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1176 // candidate for move to LyXView
1177 // This is only used in toolbar.C
1178 void LayoutsCB(int sel, void *)
1180 string tmp = tostr(sel);
1181 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1187 * SGML Linuxdoc support:
1188 * (flag == 0) make TeX output
1189 * (flag == 1) make dvi output
1191 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1198 /* generate a path-less extension name */
1199 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1200 string path = OnlyPath (filename);
1201 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1202 path = bv->buffer()->tmppath;
1206 if (!bv->available())
1208 bv->buffer()->makeLinuxDocFile(name, false);
1210 // CHECK remove this once we have a proper geometry class
1212 BufferParams::PAPER_SIZE ps =
1213 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1215 case BufferParams::PAPER_A4PAPER:
1216 add_flags = "-p a4";
1218 case BufferParams::PAPER_USLETTER:
1219 add_flags = "-p letter";
1221 default: /* nothing to be done yet ;-) */ break;
1228 case 0: /* TeX output asked */
1229 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1230 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1231 if (one.startscript(Systemcalls::System, s2))
1234 case 1: /* dvi output asked */
1235 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1236 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1237 if (one.startscript(Systemcalls::System, s2)) {
1241 default: /* unknown output */
1247 bv->buffer()->redraw();
1253 * SGML DocBook support:
1254 * (flag == 1) make dvi output
1256 int RunDocBook(int flag, string const & filename)
1258 /* generate a path-less extension name */
1259 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1260 string path = OnlyPath (filename);
1261 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1262 path = current_view->buffer()->tmppath;
1266 if (!current_view->available())
1269 current_view->buffer()->makeDocBookFile(name, false);
1271 // Shall this code go or should it stay? (Lgb)
1272 // This code is a placeholder for future implementation. (Jose')
1273 // string add_flags;
1274 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1276 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1277 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1278 // default: /* nothing to be done yet ;-) */ break;
1280 ProhibitInput(current_view);
1285 case 1: /* dvi output asked */
1287 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1288 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1289 if (one.startscript(Systemcalls::System, s2)) {
1294 default: /* unknown output */
1298 AllowInput(current_view);
1300 current_view->buffer()->redraw();
1305 void MenuLayoutCharacter()
1307 static int ow = -1, oh;
1309 if (fd_form_character->form_character->visible) {
1310 fl_raise_form(fd_form_character->form_character);
1312 fl_show_form(fd_form_character->form_character,
1313 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1314 _("Character Style"));
1316 ow = fd_form_character->form_character->w;
1317 oh = fd_form_character->form_character->h;
1319 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1325 void DeactivateParagraphButtons ()
1327 fl_deactivate_object (fd_form_paragraph->button_ok);
1328 fl_deactivate_object (fd_form_paragraph->button_apply);
1329 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1330 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1335 void ActivateParagraphButtons ()
1337 fl_activate_object (fd_form_paragraph->button_ok);
1338 fl_activate_object (fd_form_paragraph->button_apply);
1339 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1340 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1345 void DisableParagraphLayout ()
1347 DeactivateParagraphButtons();
1348 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1349 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1350 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1351 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1352 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1353 fl_deactivate_object (fd_form_paragraph->check_noindent);
1354 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1355 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1356 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1357 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1358 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1359 fl_deactivate_object (fd_form_paragraph->input_space_above);
1360 fl_deactivate_object (fd_form_paragraph->input_space_below);
1361 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1362 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1363 fl_deactivate_object (fd_form_paragraph->check_space_above);
1364 fl_deactivate_object (fd_form_paragraph->check_space_below);
1369 void EnableParagraphLayout ()
1371 ActivateParagraphButtons();
1372 fl_activate_object (fd_form_paragraph->input_labelwidth);
1373 fl_activate_object (fd_form_paragraph->check_lines_top);
1374 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1375 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1376 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1377 fl_activate_object (fd_form_paragraph->check_noindent);
1378 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1379 fl_activate_object (fd_form_paragraph->radio_align_right);
1380 fl_activate_object (fd_form_paragraph->radio_align_left);
1381 fl_activate_object (fd_form_paragraph->radio_align_block);
1382 fl_activate_object (fd_form_paragraph->radio_align_center);
1383 fl_activate_object (fd_form_paragraph->input_space_above);
1384 fl_activate_object (fd_form_paragraph->input_space_below);
1385 fl_activate_object (fd_form_paragraph->choice_space_above);
1386 fl_activate_object (fd_form_paragraph->choice_space_below);
1387 fl_activate_object (fd_form_paragraph->check_space_above);
1388 fl_activate_object (fd_form_paragraph->check_space_below);
1392 bool UpdateLayoutParagraph()
1394 if (!current_view->available()) {
1395 if (fd_form_paragraph->form_paragraph->visible)
1396 fl_hide_form(fd_form_paragraph->form_paragraph);
1400 Buffer * buf = current_view->buffer();
1402 if (current_view->the_locking_inset)
1403 text = current_view->the_locking_inset->getLyXText(current_view);
1405 text = current_view->text;
1407 fl_set_input(fd_form_paragraph->input_labelwidth,
1408 text->cursor.par()->GetLabelWidthString().c_str());
1409 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1410 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1411 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1412 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1414 int align = text->cursor.par()->GetAlign();
1415 if (align == LYX_ALIGN_LAYOUT)
1416 align = textclasslist.Style(buf->params.textclass,
1417 text->cursor.par()->GetLayout()).align;
1420 case LYX_ALIGN_RIGHT:
1421 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1423 case LYX_ALIGN_LEFT:
1424 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1426 case LYX_ALIGN_CENTER:
1427 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1430 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1435 fl_set_button(fd_form_paragraph->check_lines_top,
1436 text->cursor.par()->FirstPhysicalPar()->line_top);
1438 fl_set_button(fd_form_paragraph->check_lines_bottom,
1439 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1441 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1442 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1444 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1445 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1446 fl_set_button(fd_form_paragraph->check_noindent,
1447 text->cursor.par()->FirstPhysicalPar()->noindent);
1449 fl_set_button(fd_form_paragraph->check_lines_top,
1450 text->cursor.par()->line_top);
1451 fl_set_button(fd_form_paragraph->check_lines_bottom,
1452 text->cursor.par()->line_bottom);
1453 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1454 text->cursor.par()->pagebreak_top);
1455 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1456 text->cursor.par()->pagebreak_bottom);
1457 fl_set_button(fd_form_paragraph->check_noindent,
1458 text->cursor.par()->noindent);
1460 fl_set_input (fd_form_paragraph->input_space_above, "");
1463 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1465 switch (text->cursor.par()->added_space_top.kind()) {
1469 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1471 case VSpace::DEFSKIP:
1472 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1474 case VSpace::SMALLSKIP:
1475 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1477 case VSpace::MEDSKIP:
1478 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1480 case VSpace::BIGSKIP:
1481 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1484 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1486 case VSpace::LENGTH:
1487 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1489 fl_set_input (fd_form_paragraph->input_space_above,
1490 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1492 fl_set_input (fd_form_paragraph->input_space_above,
1493 text->cursor.par()->added_space_top.length().asString().c_str());
1498 fl_set_button (fd_form_paragraph->check_space_above,
1499 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1500 fl_set_input (fd_form_paragraph->input_space_below, "");
1501 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1503 fl_set_button (fd_form_paragraph->check_space_above,
1504 text->cursor.par()->added_space_top.keep());
1505 fl_set_input (fd_form_paragraph->input_space_below, "");
1506 switch (text->cursor.par()->added_space_bottom.kind()) {
1509 fl_set_choice (fd_form_paragraph->choice_space_below,
1512 case VSpace::DEFSKIP:
1513 fl_set_choice (fd_form_paragraph->choice_space_below,
1516 case VSpace::SMALLSKIP:
1517 fl_set_choice (fd_form_paragraph->choice_space_below,
1520 case VSpace::MEDSKIP:
1521 fl_set_choice (fd_form_paragraph->choice_space_below,
1524 case VSpace::BIGSKIP:
1525 fl_set_choice (fd_form_paragraph->choice_space_below,
1529 fl_set_choice (fd_form_paragraph->choice_space_below,
1532 case VSpace::LENGTH:
1533 fl_set_choice (fd_form_paragraph->choice_space_below,
1536 fl_set_input (fd_form_paragraph->input_space_below,
1537 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1540 fl_set_button (fd_form_paragraph->check_space_below,
1541 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1543 fl_set_button(fd_form_paragraph->check_noindent,
1544 text->cursor.par()->FirstPhysicalPar()->noindent);
1546 fl_set_input (fd_form_paragraph->input_space_below,
1547 text->cursor.par()->added_space_bottom.length().asString().c_str());
1550 fl_set_button (fd_form_paragraph->check_space_below,
1551 text->cursor.par()->added_space_bottom.keep());
1553 fl_set_button(fd_form_paragraph->check_noindent,
1554 text->cursor.par()->noindent);
1556 if (current_view->buffer()->isReadonly()) {
1557 DisableParagraphLayout();
1559 EnableParagraphLayout();
1565 void MenuLayoutParagraph()
1567 if (UpdateLayoutParagraph()) {
1568 if (fd_form_paragraph->form_paragraph->visible) {
1569 fl_raise_form(fd_form_paragraph->form_paragraph);
1571 fl_show_form(fd_form_paragraph->form_paragraph,
1572 FL_PLACE_MOUSE, FL_FULLBORDER,
1573 _("Paragraph Environment"));
1580 void DeactivateDocumentButtons ()
1582 fl_deactivate_object (fd_form_document->button_ok);
1583 fl_deactivate_object (fd_form_document->button_apply);
1584 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1585 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1590 void ActivateDocumentButtons ()
1592 fl_activate_object (fd_form_document->button_ok);
1593 fl_activate_object (fd_form_document->button_apply);
1594 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1595 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1600 void DisableDocumentLayout ()
1602 DeactivateDocumentButtons ();
1603 fl_deactivate_object (fd_form_document->group_radio_separation);
1604 fl_deactivate_object (fd_form_document->radio_indent);
1605 fl_deactivate_object (fd_form_document->radio_skip);
1606 fl_deactivate_object (fd_form_document->choice_class);
1607 fl_deactivate_object (fd_form_document->choice_pagestyle);
1608 fl_deactivate_object (fd_form_document->choice_fonts);
1609 fl_deactivate_object (fd_form_document->choice_fontsize);
1610 fl_deactivate_object (fd_form_document->input_float_placement);
1611 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1612 fl_deactivate_object (fd_form_document->choice_inputenc);
1613 fl_deactivate_object (fd_form_document->group_radio_sides);
1614 fl_deactivate_object (fd_form_document->radio_sides_one);
1615 fl_deactivate_object (fd_form_document->radio_sides_two);
1616 fl_deactivate_object (fd_form_document->group_radio_columns);
1617 fl_deactivate_object (fd_form_document->radio_columns_one);
1618 fl_deactivate_object (fd_form_document->radio_columns_two);
1619 fl_deactivate_object (fd_form_document->input_extra);
1620 fl_deactivate_object (fd_form_document->choice_language);
1621 combo_language->deactivate();
1622 fl_deactivate_object (fd_form_document->input_default_skip);
1623 fl_deactivate_object (fd_form_document->choice_default_skip);
1624 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1625 fl_deactivate_object (fd_form_document->slider_tocdepth);
1626 fl_deactivate_object (fd_form_document->choice_spacing);
1627 fl_deactivate_object (fd_form_document->input_spacing);
1628 fl_deactivate_object (fd_form_document->check_use_amsmath);
1633 void EnableDocumentLayout ()
1635 ActivateDocumentButtons ();
1636 fl_activate_object (fd_form_document->group_radio_separation);
1637 fl_activate_object (fd_form_document->radio_indent);
1638 fl_activate_object (fd_form_document->radio_skip);
1639 fl_activate_object (fd_form_document->choice_class);
1640 fl_activate_object (fd_form_document->choice_pagestyle);
1641 fl_activate_object (fd_form_document->choice_fonts);
1642 fl_activate_object (fd_form_document->choice_fontsize);
1643 fl_activate_object (fd_form_document->input_float_placement);
1644 fl_activate_object (fd_form_document->choice_postscript_driver);
1645 fl_activate_object (fd_form_document->choice_inputenc);
1646 fl_activate_object (fd_form_document->group_radio_sides);
1647 fl_activate_object (fd_form_document->radio_sides_one);
1648 fl_activate_object (fd_form_document->radio_sides_two);
1649 fl_activate_object (fd_form_document->group_radio_columns);
1650 fl_activate_object (fd_form_document->radio_columns_one);
1651 fl_activate_object (fd_form_document->radio_columns_two);
1652 fl_activate_object (fd_form_document->input_extra);
1653 fl_activate_object (fd_form_document->choice_language);
1654 combo_language->activate();
1655 fl_activate_object (fd_form_document->input_default_skip);
1656 fl_activate_object (fd_form_document->choice_default_skip);
1657 fl_activate_object (fd_form_document->slider_secnumdepth);
1658 fl_activate_object (fd_form_document->slider_tocdepth);
1659 fl_activate_object (fd_form_document->choice_spacing);
1660 fl_activate_object (fd_form_document->input_spacing);
1661 fl_activate_object (fd_form_document->check_use_amsmath);
1665 bool UpdateLayoutDocument(BufferParams * params)
1667 if (!current_view->available()) {
1668 if (fd_form_document->form_document->visible)
1669 fl_hide_form(fd_form_document->form_document);
1674 params = ¤t_view->buffer()->params;
1675 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1677 fl_set_choice_text(fd_form_document->choice_class,
1678 textclasslist.DescOfClass(params->textclass).c_str());
1679 combo_language->select_text(params->language.c_str());
1681 fl_set_choice_text(fd_form_document->choice_fonts,
1682 params->fonts.c_str());
1683 fl_set_choice_text(fd_form_document->choice_inputenc,
1684 params->inputenc.c_str());
1685 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1686 params->graphicsDriver.c_str());
1688 // ale970405+lasgoutt970513
1689 fl_clear_choice(fd_form_document->choice_fontsize);
1690 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1691 fl_addto_choice(fd_form_document->choice_fontsize,
1692 tclass.opt_fontsize().c_str());
1693 fl_set_choice(fd_form_document->choice_fontsize,
1694 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1696 // ale970405+lasgoutt970513
1697 fl_clear_choice(fd_form_document->choice_pagestyle);
1698 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1699 fl_addto_choice(fd_form_document->choice_pagestyle,
1700 tclass.opt_pagestyle().c_str());
1702 fl_set_choice(fd_form_document->choice_pagestyle,
1703 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1705 fl_set_button(fd_form_document->radio_indent, 0);
1706 fl_set_button(fd_form_document->radio_skip, 0);
1709 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1711 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1712 fl_set_button(fd_form_document->radio_indent, 1);
1714 fl_set_button(fd_form_document->radio_skip, 1);
1716 switch (params->getDefSkip().kind()) {
1717 case VSpace::SMALLSKIP:
1718 fl_set_choice (fd_form_document->choice_default_skip, 1);
1720 case VSpace::MEDSKIP:
1721 fl_set_choice (fd_form_document->choice_default_skip, 2);
1723 case VSpace::BIGSKIP:
1724 fl_set_choice (fd_form_document->choice_default_skip, 3);
1726 case VSpace::LENGTH:
1727 fl_set_choice (fd_form_document->choice_default_skip, 4);
1728 fl_set_input (fd_form_document->input_default_skip,
1729 params->getDefSkip().asLyXCommand().c_str());
1732 fl_set_choice (fd_form_document->choice_default_skip, 2);
1736 fl_set_button(fd_form_document->radio_sides_one, 0);
1737 fl_set_button(fd_form_document->radio_sides_two, 0);
1739 switch (params->sides) {
1740 case LyXTextClass::OneSide:
1741 fl_set_button(fd_form_document->radio_sides_one, 1);
1743 case LyXTextClass::TwoSides:
1744 fl_set_button(fd_form_document->radio_sides_two, 1);
1748 fl_set_button(fd_form_document->radio_columns_one, 0);
1749 fl_set_button(fd_form_document->radio_columns_two, 0);
1751 if (params->columns == 2)
1752 fl_set_button(fd_form_document->radio_columns_two, 1);
1754 fl_set_button(fd_form_document->radio_columns_one, 1);
1756 fl_set_input(fd_form_document->input_spacing, "");
1757 switch (params->spacing.getSpace()) {
1758 case Spacing::Default: // nothing bad should happen with this
1759 case Spacing::Single:
1762 fl_set_choice(fd_form_document->choice_spacing, 1);
1765 case Spacing::Onehalf:
1768 fl_set_choice(fd_form_document->choice_spacing, 2);
1771 case Spacing::Double:
1774 fl_set_choice(fd_form_document->choice_spacing, 3);
1777 case Spacing::Other:
1779 fl_set_choice(fd_form_document->choice_spacing, 4);
1781 //sprintf(sval, "%g", params->spacing.getValue());
1783 std::ostringstream sval;
1784 sval << params->spacing.getValue(); // setw?
1785 fl_set_input(fd_form_document->input_spacing,
1786 sval.str().c_str());
1789 ostrstream sval(tval, 20);
1790 sval << params->spacing.getValue() << '\0'; // setw?
1791 fl_set_input(fd_form_document->input_spacing, sval.str());
1798 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1799 params->secnumdepth);
1800 fl_set_counter_value(fd_form_document->slider_tocdepth,
1802 if (!params->float_placement.empty()) { // buffer local (Lgb)
1803 fl_set_input(fd_form_document->input_float_placement,
1804 params->float_placement.c_str());
1806 fl_set_input(fd_form_document->input_float_placement, "");
1808 if (!params->options.empty())
1809 fl_set_input(fd_form_document->input_extra,
1810 params->options.c_str());
1812 fl_set_input(fd_form_document->input_extra, "");
1814 if (current_view->buffer()->isSGML()) {
1815 // bullets not used in SGML derived documents
1816 fl_deactivate_object(fd_form_document->button_bullets);
1817 fl_set_object_lcol(fd_form_document->button_bullets,
1820 fl_activate_object(fd_form_document->button_bullets);
1821 fl_set_object_lcol(fd_form_document->button_bullets,
1825 if (current_view->buffer()->isReadonly()) {
1826 DisableDocumentLayout();
1828 EnableDocumentLayout();
1835 void MenuLayoutDocument()
1837 if (UpdateLayoutDocument()) {
1838 if (fd_form_document->form_document->visible) {
1839 fl_raise_form(fd_form_document->form_document);
1841 fl_show_form(fd_form_document->form_document,
1842 FL_PLACE_MOUSE, FL_FULLBORDER,
1843 _("Document Layout"));
1849 bool UpdateLayoutQuotes()
1852 if (!current_view->available()
1853 || current_view->buffer()->isReadonly())
1857 fl_set_choice(fd_form_quotes->choice_quotes_language,
1858 current_view->buffer()->params.quotes_language + 1);
1859 fl_set_button(fd_form_quotes->radio_single, 0);
1860 fl_set_button(fd_form_quotes->radio_double, 0);
1862 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1863 fl_set_button(fd_form_quotes->radio_single, 1);
1865 fl_set_button(fd_form_quotes->radio_double, 1);
1866 } else if (fd_form_quotes->form_quotes->visible) {
1867 fl_hide_form(fd_form_quotes->form_quotes);
1873 void MenuLayoutQuotes()
1875 if (UpdateLayoutQuotes()) {
1876 if (fd_form_quotes->form_quotes->visible) {
1877 fl_raise_form(fd_form_quotes->form_quotes);
1879 fl_show_form(fd_form_quotes->form_quotes,
1880 FL_PLACE_MOUSE, FL_FULLBORDER,
1887 bool UpdateLayoutPreamble()
1890 if (!current_view->available())
1894 fl_set_input(fd_form_preamble->input_preamble,
1895 current_view->buffer()->params.preamble.c_str());
1897 if (current_view->buffer()->isReadonly()) {
1898 fl_deactivate_object(fd_form_preamble->input_preamble);
1899 fl_deactivate_object(fd_form_preamble->button_ok);
1900 fl_deactivate_object(fd_form_preamble->button_apply);
1901 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1902 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1905 fl_activate_object(fd_form_preamble->input_preamble);
1906 fl_activate_object(fd_form_preamble->button_ok);
1907 fl_activate_object(fd_form_preamble->button_apply);
1908 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1909 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1911 } else if (fd_form_preamble->form_preamble->visible) {
1912 fl_hide_form(fd_form_preamble->form_preamble);
1918 void MenuLayoutPreamble()
1920 static int ow = -1, oh;
1922 if (UpdateLayoutPreamble()) {
1923 if (fd_form_preamble->form_preamble->visible) {
1924 fl_raise_form(fd_form_preamble->form_preamble);
1926 fl_show_form(fd_form_preamble->form_preamble,
1927 FL_PLACE_MOUSE | FL_FREE_SIZE,
1929 _("LaTeX Preamble"));
1931 ow = fd_form_preamble->form_preamble->w;
1932 oh = fd_form_preamble->form_preamble->h;
1934 fl_set_form_minsize(fd_form_preamble->form_preamble,
1941 void MenuLayoutSave()
1943 if (!current_view->available())
1946 if (AskQuestion(_("Do you want to save the current settings"),
1947 _("for Character, Document, Paper and Quotes"),
1948 _("as default for new documents?")))
1949 current_view->buffer()->saveParamsAsDefaults();
1953 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1954 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1955 LyXFont UserFreeFont(BufferParams const & params)
1957 LyXFont font(LyXFont::ALL_IGNORE);
1959 int pos = fl_get_choice(fd_form_character->choice_family);
1961 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1962 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1963 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1964 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1965 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1968 pos = fl_get_choice(fd_form_character->choice_series);
1970 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1971 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1972 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1973 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1976 pos = fl_get_choice(fd_form_character->choice_shape);
1978 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
1979 case 2: font.setShape(LyXFont::UP_SHAPE); break;
1980 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
1981 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
1982 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
1983 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
1986 pos = fl_get_choice(fd_form_character->choice_size);
1988 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
1989 case 2: font.setSize(LyXFont::SIZE_TINY); break;
1990 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
1991 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
1992 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
1993 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
1994 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
1995 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
1996 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
1997 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
1998 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
1999 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2000 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2001 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2004 pos = fl_get_choice(fd_form_character->choice_bar);
2006 case 1: font.setEmph(LyXFont::IGNORE);
2007 font.setUnderbar(LyXFont::IGNORE);
2008 font.setNoun(LyXFont::IGNORE);
2009 font.setLatex(LyXFont::IGNORE);
2011 case 2: font.setEmph(LyXFont::TOGGLE); break;
2012 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2013 case 4: font.setNoun(LyXFont::TOGGLE); break;
2014 case 5: font.setLatex(LyXFont::TOGGLE); break;
2015 case 6: font.setEmph(LyXFont::INHERIT);
2016 font.setUnderbar(LyXFont::INHERIT);
2017 font.setNoun(LyXFont::INHERIT);
2018 font.setLatex(LyXFont::INHERIT);
2022 pos = fl_get_choice(fd_form_character->choice_color);
2024 case 1: font.setColor(LColor::ignore); break;
2025 case 2: font.setColor(LColor::none); break;
2026 case 3: font.setColor(LColor::black); break;
2027 case 4: font.setColor(LColor::white); break;
2028 case 5: font.setColor(LColor::red); break;
2029 case 6: font.setColor(LColor::green); break;
2030 case 7: font.setColor(LColor::blue); break;
2031 case 8: font.setColor(LColor::cyan); break;
2032 case 9: font.setColor(LColor::magenta); break;
2033 case 10: font.setColor(LColor::yellow); break;
2034 case 11: font.setColor(LColor::inherit); break;
2037 int choice = combo_language2->get();
2039 font.setLanguage(ignore_language);
2040 else if (choice == 2)
2041 font.setLanguage(params.language_info);
2043 font.setLanguage(&languages[combo_language2->getline()]);
2049 /* callbacks for form form_title */
2050 extern "C" void TimerCB(FL_OBJECT *, long)
2052 // only if the form still exists
2053 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2054 if (fd_form_title->form_title->visible) {
2055 fl_hide_form(fd_form_title->form_title);
2057 fl_free_form(fd_form_title->form_title);
2058 fd_form_title->form_title = 0;
2063 /* callbacks for form form_paragraph */
2065 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2067 // "Synchronize" the choices and input fields, making it
2068 // impossible to commit senseless data.
2070 FD_form_paragraph const * fp = fd_form_paragraph;
2072 if (obj == fp->choice_space_above) {
2073 if (fl_get_choice (fp->choice_space_above) != 7) {
2074 fl_set_input (fp->input_space_above, "");
2075 ActivateParagraphButtons();
2077 } else if (obj == fp->choice_space_below) {
2078 if (fl_get_choice (fp->choice_space_below) != 7) {
2079 fl_set_input (fp->input_space_below, "");
2080 ActivateParagraphButtons();
2082 } else if (obj == fp->input_space_above) {
2083 string input = fl_get_input (fp->input_space_above);
2085 if (input.empty()) {
2086 fl_set_choice (fp->choice_space_above, 1);
2087 ActivateParagraphButtons();
2089 else if (isValidGlueLength (input)) {
2090 fl_set_choice (fp->choice_space_above, 7);
2091 ActivateParagraphButtons();
2094 fl_set_choice (fp->choice_space_above, 7);
2095 DeactivateParagraphButtons();
2097 } else if (obj == fp->input_space_below) {
2098 string input = fl_get_input (fp->input_space_below);
2100 if (input.empty()) {
2101 fl_set_choice (fp->choice_space_below, 1);
2102 ActivateParagraphButtons();
2104 else if (isValidGlueLength (input)) {
2105 fl_set_choice (fp->choice_space_below, 7);
2106 ActivateParagraphButtons();
2109 fl_set_choice (fp->choice_space_below, 7);
2110 DeactivateParagraphButtons();
2116 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2118 if (!current_view->available())
2121 VSpace space_top, space_bottom;
2123 string labelwidthstring;
2126 // If a vspace kind is "Length" but there's no text in
2127 // the input field, reset the kind to "None".
2128 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2129 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2130 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2132 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2133 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2134 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2137 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2138 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2139 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2140 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2141 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2142 case 1: space_top = VSpace(VSpace::NONE); break;
2143 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2144 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2145 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2146 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2147 case 6: space_top = VSpace(VSpace::VFILL); break;
2148 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2150 if (fl_get_button (fd_form_paragraph->check_space_above))
2151 space_top.setKeep (true);
2152 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2153 case 1: space_bottom = VSpace(VSpace::NONE); break;
2154 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2155 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2156 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2157 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2158 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2159 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2161 if (fl_get_button (fd_form_paragraph->check_space_below))
2162 space_bottom.setKeep (true);
2164 if (fl_get_button(fd_form_paragraph->radio_align_left))
2165 align = LYX_ALIGN_LEFT;
2166 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2167 align = LYX_ALIGN_RIGHT;
2168 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2169 align = LYX_ALIGN_CENTER;
2171 align = LYX_ALIGN_BLOCK;
2173 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2174 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2177 if (current_view->the_locking_inset)
2178 text = current_view->the_locking_inset->getLyXText(current_view);
2180 text = current_view->text;
2181 text->SetParagraph(current_view,
2191 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2192 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2196 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2198 fl_hide_form(fd_form_paragraph->form_paragraph);
2202 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2204 ParagraphApplyCB(ob, data);
2205 ParagraphCancelCB(ob, data);
2209 /* callbacks for form form_character */
2211 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2213 // we set toggleall locally here, since it should be true for
2214 // all other uses of ToggleAndShow() (JMarc)
2215 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2216 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2217 current_view->setState();
2222 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2224 fl_hide_form(fd_form_character->form_character);
2228 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2230 CharacterApplyCB(ob, data);
2231 CharacterCloseCB(ob, data);
2235 /* callbacks for form form_document */
2237 void UpdateDocumentButtons(BufferParams const & params)
2239 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2241 switch (params.sides) {
2242 case LyXTextClass::OneSide:
2243 fl_set_button(fd_form_document->radio_sides_one, 1);
2245 case LyXTextClass::TwoSides:
2246 fl_set_button(fd_form_document->radio_sides_two, 1);
2250 if (params.columns == 2)
2251 fl_set_button(fd_form_document->radio_columns_two, 1);
2253 fl_set_button(fd_form_document->radio_columns_one, 1);
2255 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2256 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2257 params.secnumdepth);
2258 fl_set_counter_value(fd_form_document->slider_tocdepth,
2263 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2265 ProhibitInput(current_view);
2266 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2267 if (AskQuestion(_("Should I set some parameters to"),
2268 fl_get_choice_text(ob),
2269 _("the defaults of this document class?"))) {
2270 BufferParams params = BufferParams();
2271 params.textclass = fl_get_choice(ob)-1;
2272 params.useClassDefaults();
2273 UpdateLayoutDocument(¶ms);
2274 UpdateDocumentButtons(params);
2277 // unable to load new style
2278 WriteAlert(_("Conversion Errors!"),
2279 _("Unable to switch to new document class."),
2280 _("Reverting to original document class."));
2281 fl_set_choice(fd_form_document->choice_class,
2282 current_view->buffer()->params.textclass + 1);
2284 AllowInput(current_view);
2288 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2290 // "Synchronize" the choice and the input field, so that it
2291 // is impossible to commit senseless data.
2292 FD_form_document const * fd = fd_form_document;
2294 if (obj == fd->choice_default_skip) {
2295 if (fl_get_choice (fd->choice_default_skip) != 4) {
2296 fl_set_input (fd->input_default_skip, "");
2297 ActivateDocumentButtons();
2299 } else if (obj == fd->input_default_skip) {
2301 char const * input = fl_get_input (fd->input_default_skip);
2304 fl_set_choice (fd->choice_default_skip, 2);
2305 ActivateDocumentButtons();
2306 } else if (isValidGlueLength (input)) {
2307 fl_set_choice (fd->choice_default_skip, 4);
2308 ActivateDocumentButtons();
2310 fl_set_choice (fd->choice_default_skip, 4);
2311 DeactivateDocumentButtons();
2317 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2319 // "Synchronize" the choice and the input field, so that it
2320 // is impossible to commit senseless data.
2321 FD_form_document const * fd = fd_form_document;
2323 if (obj == fd->choice_spacing
2324 && fl_get_choice (fd->choice_spacing) != 4) {
2325 fl_set_input(fd->input_spacing, "");
2326 } else if (obj == fd->input_spacing) {
2328 const char* input = fl_get_input (fd->input_spacing);
2331 fl_set_choice (fd->choice_spacing, 1);
2333 fl_set_choice (fd->choice_spacing, 4);
2339 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2342 BufferParams * params = &(current_view->buffer()->params);
2344 Language const * old_language = params->language_info;
2345 params->language = combo_language->getline();
2346 Languages::iterator lit = languages.find(params->language);
2348 Language const * new_language;
2349 if (lit != languages.end())
2350 new_language = &(*lit).second;
2352 new_language = default_language;
2354 if (current_view->available()) {
2355 if (old_language != new_language
2356 && old_language->RightToLeft() == new_language->RightToLeft()
2357 && !current_view->buffer()->isMultiLingual())
2358 current_view->buffer()->ChangeLanguage(old_language,
2360 if (old_language != new_language) {
2361 //current_view->buffer()->redraw();
2365 params->language_info = new_language;
2367 // If default skip is a "Length" but there's no text in the
2368 // input field, reset the kind to "Medskip", which is the default.
2369 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2370 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2371 fl_set_choice (fd_form_document->choice_default_skip, 2);
2374 /* this shouldn't be done automatically IMO. For example I write german
2375 * documents with an american keyboard very often. Matthias */
2377 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2378 fl_get_choice(fd_form_document->choice_language)); */
2380 fl_get_choice_text(fd_form_document->choice_fonts);
2382 fl_get_choice_text(fd_form_document->choice_inputenc);
2384 fl_get_choice_text(fd_form_document->choice_fontsize);
2386 fl_get_choice_text(fd_form_document->choice_pagestyle);
2387 params->graphicsDriver =
2388 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2389 params->use_amsmath =
2390 fl_get_button(fd_form_document->check_use_amsmath);
2392 if (!current_view->available())
2395 current_view->text->SetCursor(current_view,
2396 current_view->text->cursor.par(),
2397 current_view->text->cursor.pos());
2398 current_view->setState();
2400 LyXTextClassList::ClassList::size_type new_class =
2401 fl_get_choice(fd_form_document->choice_class) - 1;
2403 if (params->textclass != new_class) {
2404 // try to load new_class
2405 if (textclasslist.Load(new_class)) {
2406 // successfully loaded
2408 current_view->owner()->getMiniBuffer()->
2409 Set(_("Converting document to new document class..."));
2411 int ret = cap.SwitchLayoutsBetweenClasses(
2412 current_view->buffer()->params.textclass,
2414 current_view->buffer()->paragraph);
2419 s = _("One paragraph couldn't be converted");
2422 s += _(" paragraphs couldn't be converted");
2424 WriteAlert(_("Conversion Errors!"), s,
2425 _("into chosen document class"));
2428 params->textclass = new_class;
2430 // problem changing class -- warn user and retain old style
2431 WriteAlert(_("Conversion Errors!"),
2432 _("Unable to switch to new document class."),
2433 _("Reverting to original document class."));
2434 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2438 char tmpsep = params->paragraph_separation;
2439 if (fl_get_button(fd_form_document->radio_indent))
2440 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2442 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2443 if (tmpsep != params->paragraph_separation)
2446 VSpace tmpdefskip = params->getDefSkip();
2447 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2448 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2449 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2450 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2451 case 4: params->setDefSkip(
2452 VSpace (LyXGlueLength (fl_get_input
2453 (fd_form_document->input_default_skip))));
2455 // DocumentDefskipCB assures that this never happens
2456 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2458 if (!(tmpdefskip == params->getDefSkip()))
2461 if (fl_get_button(fd_form_document->radio_columns_two))
2462 params->columns = 2;
2464 params->columns = 1;
2465 if (fl_get_button(fd_form_document->radio_sides_two))
2466 params->sides = LyXTextClass::TwoSides;
2468 params->sides = LyXTextClass::OneSide;
2470 Spacing tmpSpacing = params->spacing;
2471 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2473 lyxerr.debug() << "Spacing: SINGLE" << endl;
2474 params->spacing.set(Spacing::Single);
2477 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2478 params->spacing.set(Spacing::Onehalf);
2481 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2482 params->spacing.set(Spacing::Double);
2485 lyxerr.debug() << "Spacing: OTHER" << endl;
2486 params->spacing.set(Spacing::Other,
2487 fl_get_input(fd_form_document->input_spacing));
2490 if (tmpSpacing != params->spacing)
2493 signed char tmpchar =
2494 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2495 if (params->secnumdepth != tmpchar)
2497 params->secnumdepth = tmpchar;
2500 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2502 params->float_placement =
2503 fl_get_input(fd_form_document->input_float_placement);
2505 // More checking should be done to ensure the string doesn't have
2506 // spaces or illegal placement characters in it. (thornley)
2509 current_view->redoCurrentBuffer();
2511 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2512 current_view->buffer()->markDirty();
2515 fl_get_input(fd_form_document->input_extra);
2519 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2521 fl_hide_form(fd_form_document->form_document);
2525 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2527 DocumentCancelCB(ob, data);
2528 DocumentApplyCB(ob, data);
2532 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2535 // bullet callbacks etc. in bullet_panel.C -- ARRae
2539 /* callbacks for form form_quotes */
2541 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2543 if (!current_view->available())
2546 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2547 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2548 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2550 lga = InsetQuotes::EnglishQ;
2553 lga = InsetQuotes::SwedishQ;
2556 lga = InsetQuotes::GermanQ;
2559 lga = InsetQuotes::PolishQ;
2562 lga = InsetQuotes::FrenchQ;
2565 lga = InsetQuotes::DanishQ;
2568 current_view->buffer()->params.quotes_language = lga;
2569 if (fl_get_button(fd_form_quotes->radio_single))
2570 current_view->buffer()->
2571 params.quotes_times = InsetQuotes::SingleQ;
2573 current_view->buffer()->
2574 params.quotes_times = InsetQuotes::DoubleQ;
2578 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2580 fl_hide_form(fd_form_quotes->form_quotes);
2584 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2586 QuotesApplyCB(ob, data);
2587 QuotesCancelCB(ob, data);
2592 /* callbacks for form form_preamble */
2594 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2596 fl_hide_form(fd_form_preamble->form_preamble);
2600 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2602 if (!current_view->available())
2605 current_view->buffer()->params.preamble =
2606 fl_get_input(fd_form_preamble->input_preamble);
2607 current_view->buffer()->markDirty();
2608 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2612 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2614 PreambleApplyCB(ob, data);
2615 PreambleCancelCB(ob, data);
2619 /* callbacks for form form_table */
2622 void TableApplyCB(FL_OBJECT *, long)
2624 if (!current_view->available())
2628 // check for tables in tables
2629 if (current_view->text->cursor.par()->table){
2630 WriteAlert(_("Impossible Operation!"),
2631 _("Cannot insert table in table."),
2636 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2638 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2639 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2642 current_view->hideCursor();
2643 current_view->beforeChange();
2644 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2646 current_view->text->SetCursorParUndo(current_view->buffer());
2647 current_view->text->FreezeUndo();
2649 current_view->text->BreakParagraph(current_view);
2650 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2652 if (current_view->text->cursor.par()->Last()) {
2653 current_view->text->CursorLeft(current_view);
2655 current_view->text->BreakParagraph(current_view);
2656 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2659 current_view->text->current_font.setLatex(LyXFont::OFF);
2660 //if (!fl_get_button(fd_form_table->check_latex)){
2661 // insert the new wysiwy table
2662 current_view->text->SetLayout(current_view, 0); // standard layout
2664 if (current_view->text->cursor.par()->footnoteflag ==
2665 LyXParagraph::NO_FOOTNOTE) {
2668 ->SetParagraph(current_view, 0, 0,
2670 VSpace (0.3 * current_view->buffer()->
2671 params.spacing.getValue(),
2673 VSpace (0.3 * current_view->buffer()->
2674 params.spacing.getValue(),
2682 ->SetParagraph(current_view, 0, 0,
2684 VSpace(VSpace::NONE),
2685 VSpace(VSpace::NONE),
2692 current_view->text->cursor.par()->table =
2693 new LyXTable(xsize, ysize);
2695 Language const * lang =
2696 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2697 LyXFont font(LyXFont::ALL_INHERIT, lang);
2698 for (int i = 0; i < xsize * ysize - 1; ++i) {
2699 current_view->text->cursor.par()
2700 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2702 current_view->text->RedoParagraph(current_view);
2704 current_view->text->UnFreezeUndo();
2706 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2707 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2708 current_view->setState();
2713 void TableCancelCB(FL_OBJECT *, long)
2715 fl_hide_form(fd_form_table->form_table);
2720 void TableOKCB(FL_OBJECT * ob, long data)
2722 TableApplyCB(ob, data);
2723 TableCancelCB(ob, data);
2729 if (fd_form_figure->form_figure->visible) {
2730 fl_raise_form(fd_form_figure->form_figure);
2732 fl_show_form(fd_form_figure->form_figure,
2733 FL_PLACE_MOUSE, FL_FULLBORDER,
2734 _("Insert Figure"));
2741 if (fd_form_table->form_table->visible) {
2742 fl_raise_form(fd_form_table->form_table);
2744 fl_show_form(fd_form_table->form_table,
2745 FL_PLACE_MOUSE, FL_FULLBORDER,
2751 /* callbacks for form form_figure */
2753 void FigureApplyCB(FL_OBJECT *, long)
2755 if (!current_view->available())
2758 Buffer * buffer = current_view->buffer();
2759 if(buffer->isReadonly()) // paranoia
2762 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2763 if (fl_get_button(fd_form_figure->radio_inline)
2765 || current_view->text->cursor.par()->table
2768 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2769 current_view->insertInset(new_inset);
2770 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2771 new_inset->Edit(current_view, 0, 0, 0);
2775 current_view->hideCursor();
2776 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2777 current_view->beforeChange();
2779 current_view->text->SetCursorParUndo(current_view->buffer());
2780 current_view->text->FreezeUndo();
2782 current_view->text->BreakParagraph(current_view);
2783 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2785 if (current_view->text->cursor.par()->Last()) {
2786 current_view->text->CursorLeft(current_view);
2788 current_view->text->BreakParagraph(current_view);
2789 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2792 // The standard layout should always be numer 0;
2793 current_view->text->SetLayout(current_view, 0);
2796 if (current_view->text->cursor.par()->footnoteflag ==
2797 LyXParagraph::NO_FOOTNOTE) {
2799 current_view->text->
2800 SetParagraph(current_view, 0, 0,
2802 VSpace (0.3 * buffer->params.spacing.getValue(),
2805 buffer->params.spacing.getValue(),
2807 LYX_ALIGN_CENTER, string(), 0);
2810 current_view->text->SetParagraph(current_view, 0, 0,
2812 VSpace(VSpace::NONE),
2813 VSpace(VSpace::NONE),
2820 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2822 Inset * new_inset = new InsetFig(100, 100, buffer);
2823 current_view->insertInset(new_inset);
2824 new_inset->Edit(current_view, 0, 0, 0);
2825 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2826 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2827 current_view->text->UnFreezeUndo();
2828 current_view->setState();
2832 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2834 fl_hide_form(fd_form_figure->form_figure);
2838 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2840 FigureApplyCB(ob, data);
2841 FigureCancelCB(ob, data);
2845 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2847 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2848 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2849 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2850 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2851 lyxrc.set_font_norm_type();
2852 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2853 fontloader.update();
2855 // Of course we should only to the resize and the textcahce.clear
2856 // if values really changed...but not very important right now. (Lgb)
2858 // All buffers will need resize
2859 bufferlist.resize();
2860 // We also need to empty the textcache so that
2861 // the buffer will be formatted correctly after
2865 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2869 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2871 fl_hide_form(fd_form_screen->form_screen);
2875 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2877 ScreenCancelCB(ob, data);
2878 ScreenApplyCB(ob, data);
2882 // This function runs "configure" and then rereads lyx.defaults to
2883 // reconfigure the automatic settings.
2884 void Reconfigure(BufferView * bv)
2886 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2888 // Run configure in user lyx directory
2889 Path p(user_lyxdir);
2890 Systemcalls one(Systemcalls::System,
2891 AddName(system_lyxdir, "configure"));
2893 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2894 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2895 WriteAlert(_("The system has been reconfigured."),
2896 _("You need to restart LyX to make use of any"),
2897 _("updated document class specifications."));
2901 /* callbacks for form form_ref */
2902 extern "C" void RefSelectCB(FL_OBJECT *, long data)
2904 if (!current_view->available())
2908 fl_get_browser_line(fd_form_ref->browser_ref,
2909 fl_get_browser(fd_form_ref->browser_ref));
2910 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
2916 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
2917 if (!current_view->NoSavedPositions()) {
2918 fl_activate_object(fd_form_ref->back);
2919 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
2922 } else if (data >= 6) {
2923 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK);
2924 if (current_view->NoSavedPositions()) {
2925 fl_deactivate_object(fd_form_ref->back);
2926 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
2931 static string const commands[5]
2932 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
2934 string t = commands[data];
2936 if (current_view->buffer()->isSGML())
2937 t += "[" + u + "]" + "{" + s + "}";
2942 new InsetRef(t, current_view->buffer());
2943 current_view->insertInset(new_inset);
2947 extern "C" void RefUpdateCB(FL_OBJECT *, long)
2949 if (!current_view->available()) {
2950 fl_clear_browser(fd_form_ref->browser_ref);
2954 FL_OBJECT * brow = fd_form_ref->browser_ref;
2956 // Get the current line, in order to restore it later
2957 char const * const btmp = fl_get_browser_line(brow,
2958 fl_get_browser(brow));
2959 string currentstr = btmp ? btmp : "";
2961 fl_clear_browser(brow);
2962 fl_hide_object(brow);
2964 vector<string> refs = current_view->buffer()->getLabelList();
2965 if (fl_get_button(fd_form_ref->sort))
2966 sort(refs.begin(),refs.end());
2967 for (vector<string>::const_iterator it = refs.begin();
2968 it != refs.end(); ++it)
2969 fl_add_browser_line(brow, (*it).c_str());
2972 int total_lines = fl_get_browser_maxline(brow);
2973 for (int i = 1; i <= total_lines ; ++i) {
2974 if (fl_get_browser_line(brow, i) == currentstr) {
2979 fl_set_browser_topline(brow, topline);
2981 bool empty = refs.empty();
2982 bool sgml = current_view->buffer()->isSGML();
2983 bool readonly = current_view->buffer()->isReadonly();
2985 if (current_view->NoSavedPositions()) {
2986 fl_deactivate_object(fd_form_ref->back);
2987 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
2989 fl_activate_object(fd_form_ref->back);
2990 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
2994 fl_add_browser_line(brow,
2995 _("*** No labels found in document ***"));
2996 fl_deactivate_object(brow);
2997 fl_deactivate_object(fd_form_ref->gotoref);
2998 fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE);
3000 fl_select_browser_line(brow, topline);
3001 fl_activate_object(brow);
3002 fl_activate_object(fd_form_ref->gotoref);
3003 fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK);
3006 if (empty || readonly) {
3007 fl_deactivate_object(fd_form_ref->ref);
3008 fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE);
3009 fl_deactivate_object(fd_form_ref->pageref);
3010 fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE);
3012 fl_activate_object(fd_form_ref->ref);
3013 fl_set_object_lcol(fd_form_ref->ref, FL_BLACK);
3014 fl_activate_object(fd_form_ref->pageref);
3015 fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK);
3018 if (empty || readonly || sgml) {
3019 fl_deactivate_object(fd_form_ref->vref);
3020 fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
3021 fl_deactivate_object(fd_form_ref->vpageref);
3022 fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
3023 fl_deactivate_object(fd_form_ref->prettyref);
3024 fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
3026 fl_activate_object(fd_form_ref->vref);
3027 fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
3028 fl_activate_object(fd_form_ref->vpageref);
3029 fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
3030 fl_activate_object(fd_form_ref->prettyref);
3031 fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
3035 fl_activate_object(fd_form_ref->ref_name);
3036 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3038 fl_deactivate_object(fd_form_ref->ref_name);
3039 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3042 fl_show_object(brow);
3046 extern "C" void RefHideCB(FL_OBJECT *, long)
3048 fl_hide_form(fd_form_ref->form_ref);