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_form_bullet * fd_form_bullet;
78 extern BufferView * current_view; // called too many times in this file...
80 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
82 extern bool send_fax(string const & fname, string const & sendcmd);
83 extern void MenuSendto();
85 extern LyXServer * lyxserver;
87 // this should be static, but I need it in buffer.C
88 bool quitting; // flag, that we are quitting the program
89 extern bool finished; // all cleanup done just let it run through now.
91 char ascii_type; /* for selection notify callbacks */
93 bool scrolling = false;
95 // This is used to make the dreaded font toggle problem hopefully go
96 // away. Definitely not the best solution, but I think it sorta works.
97 bool toggleall = true;
100 This is the inset locking stuff needed for mathed --------------------
102 an inset can simple call LockInset in it's edit call and *ONLY* in it's
104 Inset::Edit() can only be called by the main lyx module.
106 Then the inset may modify the menu's and/or iconbars.
108 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
110 During the lock, all button and keyboard events will be modified
111 and send to the inset through the following inset-features. Note that
112 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
113 to contain the code for restoring the menus and things like this.
116 virtual void InsetButtonPress(int x, int y, int button);
117 virtual void InsetButtonRelease(int x, int y, int button);
118 virtual void InsetKeyPress(XKeyEvent *ev);
119 virtual void InsetMotionNotify(int x, int y, int state);
120 virtual void InsetUnlock();
122 If a inset wishes any redraw and/or update it just has to call
124 It's is completly irrelevant, where the inset is. UpdateInset will
125 find it in any paragraph in any buffer.
126 Of course the_locking_inset and the insets in the current paragraph/buffer
127 are checked first, so no performance problem should occur.
129 Hope that's ok for the beginning, Alejandro,
130 sorry that I needed so much time,
135 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
137 /* these functions return 1 if an error occured,
139 // Now they work only for updatable insets. [Alejandro 080596]
140 //int LockInset(UpdatableInset * inset);
141 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
142 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
143 //int UnlockInset(UpdatableInset * inset);
144 //void LockedInsetStoreUndo(Undo::undo_kind kind);
146 /* this is for asyncron updating. UpdateInsetUpdateList will be called
147 automatically from LyX. Just insert the Inset into the Updatelist */
148 //void UpdateInsetUpdateList();
149 //void PutInsetIntoInsetUpdateList(Inset * inset);
151 //InsetUpdateStruct * InsetUpdateList = 0;
155 -----------------------------------------------------------------------
158 /* some function prototypes */
160 int RunLinuxDoc(BufferView *, int, string const &);
161 int RunDocBook(int, string const &);
162 void MenuWrite(Buffer * buf);
163 bool MenuWriteAs(Buffer * buffer);
164 void MenuReload(Buffer * buf);
165 void MenuLayoutSave();
168 void ShowMessage(Buffer * buf,
170 string const & msg2 = string(),
171 string const & msg3 = string(), int delay = 6)
174 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
177 // can somebody think of something more clever? cerr?
178 cout << msg1 << msg2 << msg3 << endl;
191 // should be moved to lyxfunc.C
192 void MenuWrite(Buffer * buffer)
195 if (!buffer->save()) {
196 string fname = buffer->fileName();
197 string s = MakeAbsPath(fname);
198 if (AskQuestion(_("Save failed. Rename and try again?"),
199 MakeDisplayPath(s, 50),
200 _("(If not, document is not saved.)"))) {
204 lastfiles->newFile(buffer->fileName());
209 // should be moved to BufferView.C
210 // Half of this func should be in LyXView, the rest in BufferView.
211 bool MenuWriteAs(Buffer * buffer)
213 // Why do we require BufferView::text to be able to write a
214 // document? I see no point in that. (Lgb)
215 //if (!bv->text) return;
217 string fname = buffer->fileName();
218 string oldname = fname;
221 ProhibitInput(current_view);
222 fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
223 fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
225 if (!IsLyXFilename(fname))
228 if (buffer->isUnnamed()) {
229 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
234 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
237 OnlyFilename(fname));
239 AllowInput(current_view);
244 // Make sure the absolute filename ends with appropriate suffix
245 string s = MakeAbsPath(fname);
246 if (!IsLyXFilename(s))
249 // Same name as we have already?
251 if (!AskQuestion(_("Same name as document already has:"),
252 MakeDisplayPath(s, 50),
255 // Falls through to name change and save
257 // No, but do we have another file with this name open?
258 else if (bufferlist.exists(s)) {
259 if (AskQuestion(_("Another document with same name open!"),
260 MakeDisplayPath(s, 50),
261 _("Replace with current document?")))
263 bufferlist.close(bufferlist.getBuffer(s));
265 // Ok, change the name of the buffer, but don't save!
269 ShowMessage(buffer, _("Document renamed to '"),
270 MakeDisplayPath(s), _("', but not saved..."));
273 } // Check whether the file exists
276 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
277 MakeDisplayPath(s, 50),
282 // Ok, change the name of the buffer
285 buffer->setUnnamed(false);
287 // Small bug: If the save fails, we have irreversible changed the name
294 int MenuRunLaTeX(Buffer * buffer)
298 if (buffer->isLinuxDoc())
299 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
300 else if (buffer->isLiterate())
301 ret = buffer->runLiterate();
302 else if (buffer->isDocBook())
303 ret = RunDocBook(1, buffer->fileName());
305 ret = buffer->runLaTeX();
311 s = _("One error detected");
312 t = _("You should try to fix it.");
315 s += _(" errors detected.");
316 t = _("You should try to fix them.");
318 WriteAlert(_("There were errors during the LaTeX run."), s, t);
324 int MenuBuildProg(Buffer * buffer)
328 if (buffer->isLiterate())
329 ret = buffer->buildProgram();
331 string s = _("Wrong type of document");
332 string t = _("The Build operation is not allowed in this document");
333 WriteAlert(_("There were errors during the Build process."), s, t);
341 s = _("One error detected");
342 t = _("You should try to fix it.");
345 s += _(" errors detected.");
346 t = _("You should try to fix them.");
348 WriteAlert(_("There were errors during the Build process."), s, t);
354 int MenuRunChktex(Buffer * buffer)
358 if (buffer->isSGML()) {
359 WriteAlert(_("Chktex does not work with SGML derived documents."));
362 ret = buffer->runChktex();
368 s = _("No warnings found.");
369 } else if (ret == 1) {
370 s = _("One warning found.");
371 t = _("Use 'Edit->Go to Error' to find it.");
374 s += _(" warnings found.");
375 t = _("Use 'Edit->Go to Error' to find them.");
377 WriteAlert(_("Chktex run successfully"), s, t);
379 WriteAlert(_("Error!"), _("It seems chktex does not work."));
385 int MakeLaTeXOutput(Buffer * buffer)
391 string path = OnlyPath(buffer->fileName());
392 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
393 path = buffer->tmppath;
397 ret = MenuRunLaTeX(buffer);
403 /* wait == false means don't wait for termination */
404 /* wait == true means wait for termination */
405 // The bool should be placed last on the argument line. (Lgb)
406 // Returns false if we fail.
407 bool RunScript(Buffer * buffer, bool wait,
408 string const & command,
409 string const & orgname = string(),
410 bool need_shell = true)
414 string name = orgname;
417 if (MakeLaTeXOutput(buffer) > 0)
419 /* get DVI-Filename */
421 name = ChangeExtension(buffer->getLatexName(), ".dvi");
423 path = OnlyPath(name);
424 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
425 path = buffer->tmppath;
428 // At this point we check whether the command contains the
429 // filename parameter $$FName and if that's the case we
430 // substitute the real file name otherwise the filename is
431 // simply appended. rokrau 1/12/00
434 if ( (i=command.find("$$FName")) != string::npos)
436 cmd.replace(i,7,QuoteName(name));
439 cmd = command + ' ' + QuoteName(name);
448 // OS/2 cmd.exe has another use for '&'
450 // This is not NLS safe, but it's OK, I think.
451 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
453 // COMSPEC is set, unless user unsets
454 sh = OnlyFilename(GetEnvPath("COMSPEC"));
459 if (contains(sh, "cmd.exe")
460 || contains(sh, "4os2.exe"))
461 cmd = "start /min/n " + cmd;
466 // It seems that, if wait is false, we never get back
467 // the return code of the command. This means that all
468 // the code I added in PrintApplyCB is currently
470 // CHECK What should we do here?
471 ShowMessage(buffer, _("Executing command:"), cmd);
472 result = one.startscript(Systemcalls::System, cmd);
474 ShowMessage(buffer, _("Executing command:"), cmd);
475 result = one.startscript(wait ? Systemcalls::Wait
476 : Systemcalls::DontWait, cmd);
482 // Returns false if we fail
483 bool CreatePostscript(Buffer * buffer, bool wait = false)
489 ProhibitInput(current_view);
492 if (MakeLaTeXOutput(buffer) > 0) {
493 AllowInput(current_view);
496 // Generate postscript file
497 string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
503 char real_papersize = buffer->params.papersize;
504 if (real_papersize == BufferParams::PAPER_DEFAULT)
505 real_papersize = lyxrc.default_papersize;
507 switch (real_papersize) {
508 case BufferParams::PAPER_USLETTER:
511 case BufferParams::PAPER_A3PAPER:
514 case BufferParams::PAPER_A4PAPER:
517 case BufferParams::PAPER_A5PAPER:
520 case BufferParams::PAPER_B5PAPER:
523 case BufferParams::PAPER_EXECUTIVEPAPER:
526 case BufferParams::PAPER_LEGALPAPER:
529 default: /* If nothing else fits, keep an empty value... */
533 // Make postscript file.
534 string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
535 command += QuoteName(psname);
536 if (buffer->params.use_geometry
537 && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
538 && !lyxrc.print_paper_dimension_flag.empty()
539 && !buffer->params.paperwidth.empty()
540 && !buffer->params.paperheight.empty()) {
541 // using a custom papersize
543 command += lyxrc.print_paper_dimension_flag + ' ';
544 command += buffer->params.paperwidth + ',';
545 command += buffer->params.paperheight;
546 } else if (!paper.empty()
547 && (real_papersize != BufferParams::PAPER_USLETTER ||
548 buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
549 // dvips won't accept -t letter -t landscape. In all other
550 // cases, include the paper size explicitly.
552 command += lyxrc.print_paper_flag + ' ' + paper;
554 if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
556 command += lyxrc.print_landscape_flag;
558 // push directorypath, if necessary
559 string path = OnlyPath(buffer->fileName());
560 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
561 path = buffer->tmppath;
564 bool ret = RunScript(buffer, wait, command);
565 AllowInput(current_view);
570 // Returns false if we fail
571 //bool MenuPreviewPS(Buffer * buffer)
572 bool PreviewPostscript(Buffer * buffer)
578 // Generate postscript file
579 if (!CreatePostscript(buffer, true)) {
583 // Start postscript viewer
584 ProhibitInput(current_view);
585 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
587 // push directorypath, if necessary
588 string path = OnlyPath(buffer->fileName());
589 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
590 path = buffer->tmppath;
593 bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
594 AllowInput(current_view);
599 void MenuFax(Buffer * buffer)
605 // Generate postscript file
606 if (!CreatePostscript(buffer, true)) {
611 string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
613 string path = OnlyPath (buffer->fileName());
614 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
615 path = buffer->tmppath;
618 if (!lyxrc.fax_program.empty()) {
619 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
621 Systemcalls one(Systemcalls::System, help2);
623 send_fax(ps, lyxrc.fax_command);
627 // Returns false if we fail
628 bool PreviewDVI(Buffer * buffer)
634 string paper = lyxrc.view_dvi_paper_option;
635 if (!paper.empty()) {
637 char real_papersize = buffer->params.papersize;
638 if (real_papersize == BufferParams::PAPER_DEFAULT)
639 real_papersize = lyxrc.default_papersize;
641 switch (real_papersize) {
642 case BufferParams::PAPER_USLETTER:
645 case BufferParams::PAPER_A3PAPER:
648 case BufferParams::PAPER_A4PAPER:
651 case BufferParams::PAPER_A5PAPER:
654 case BufferParams::PAPER_B5PAPER:
657 case BufferParams::PAPER_EXECUTIVEPAPER:
658 paper += " foolscap";
660 case BufferParams::PAPER_LEGALPAPER:
663 default: /* If nothing else fits, keep the empty value */
666 if (real_papersize==' ') {
667 // if (paper.empty()) {
668 if (buffer->params.orientation
669 == BufferParams::ORIENTATION_LANDSCAPE)
670 // we HAVE to give a size when the page is in
671 // landscape, so use USletter.
672 paper = " -paper usr";
674 // paper = " -paper " + paper;
675 if (buffer->params.orientation
676 == BufferParams::ORIENTATION_LANDSCAPE)
680 // push directorypath, if necessary
681 string path = OnlyPath(buffer->fileName());
682 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
683 path = buffer->tmppath;
687 string command = lyxrc.view_dvi_command + " " + paper;
688 bool ret = RunScript(buffer, false, command);
693 bool AskOverwrite(Buffer * buffer, string const & s)
696 // be friendly if there is a gui
699 !AskQuestion(_("File already exists:"),
700 MakeDisplayPath(s, 50),
701 _("Do you want to overwrite the file?"))) {
702 ShowMessage(buffer, _("Canceled"));
710 void MenuMakeLaTeX(Buffer * buffer)
712 // Why care about this?
716 // Get LaTeX-Filename
717 string s = buffer->getLatexName(false);
719 if (!AskOverwrite(buffer, s))
722 if (buffer->isDocBook())
723 ShowMessage(buffer, _("DocBook does not have a latex backend"));
725 if (buffer->isLinuxDoc())
726 RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
728 buffer->makeLaTeXFile(s, string(), true);
729 ShowMessage(buffer, _("Nice LaTeX file saved as"),
735 void MenuMakeLinuxDoc(Buffer * buffer)
738 //if (!bv->text) return;
740 if (!buffer->isLinuxDoc()) {
741 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
745 // Get LinuxDoc-Filename
746 string s = ChangeExtension(buffer->fileName(), ".sgml");
748 if (!AskOverwrite(buffer, s))
751 ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
752 MakeDisplayPath(s),"'...");
754 buffer->makeLinuxDocFile(s, true);
756 ShowMessage(buffer, _("LinuxDoc SGML file save as"),
761 void MenuMakeDocBook(Buffer * buffer)
764 //if (!bv->text) return;
766 if (!buffer->isDocBook()) {
767 WriteAlert(_("Error!"),
768 _("Document class must be docbook."));
772 // Get DocBook-Filename
773 string s = ChangeExtension(buffer->fileName(), ".sgml");
775 if (!AskOverwrite(buffer, s))
778 ShowMessage(buffer, _("Building DocBook SGML file `"),
779 MakeDisplayPath(s), "'...");
781 buffer->makeDocBookFile(s, true);
783 ShowMessage(buffer, _("DocBook SGML file save as"),
788 void MenuMakeAscii(Buffer * buffer)
791 //if (!bv->text) return;
793 /* get LaTeX-Filename */
794 string s = ChangeExtension (buffer->fileName(), ".txt");
797 if (!AskOverwrite(buffer, s))
800 buffer->writeFileAscii(s, lyxrc.ascii_linelen);
802 ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
806 void MenuMakeHTML(Buffer * buffer)
808 // First, create LaTeX file
809 MenuMakeLaTeX(buffer);
811 // And now, run the converter
812 string file = buffer->fileName();
813 Path path(OnlyPath(file));
814 // the tex file name has to be correct for
815 // latex, but the html file name can be
817 string result = ChangeExtension(file, ".html");
818 string infile = buffer->getLatexName(false);
819 string tmp = lyxrc.html_command;
820 tmp = subst(tmp, "$$FName", infile);
821 tmp = subst(tmp, "$$OutName", result);
823 int res = one.startscript(Systemcalls::System, tmp);
825 ShowMessage(buffer, _("Document exported as HTML to file `")
826 + MakeDisplayPath(result) +'\'');
828 ShowMessage(buffer, _("Unable to convert to HTML the file `")
829 + MakeDisplayPath(infile)
836 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
838 // First, create LinuxDoc file
839 MenuMakeLinuxDoc(buffer);
841 // And now, run the converter
842 string file = buffer->fileName();
844 string result = ChangeExtension(file, ".html");
845 string infile = ChangeExtension(file, ".sgml");
846 string tmp = lyxrc.linuxdoc_to_html_command;
847 tmp = subst(tmp, "$$FName", infile);
848 tmp = subst(tmp, "$$OutName", result);
850 int res = one.startscript(Systemcalls::System, tmp);
852 ShowMessage(buffer,_("Document exported as HTML to file `")
853 + MakeDisplayPath(result) +'\'');
855 ShowMessage(buffer,_("Unable to convert to HTML the file `")
856 + MakeDisplayPath(infile)
862 void MenuMakeHTML_DocBook(Buffer * buffer)
864 // First, create LaTeX file
865 MenuMakeDocBook(buffer);
867 // And now, run the converter
868 string file = buffer->fileName();
869 string result = ChangeExtension(file, ".html");
870 string infile = ChangeExtension(file, ".sgml");
871 string tmp = lyxrc.docbook_to_html_command;
872 tmp = subst(tmp, "$$FName", infile);
873 tmp = subst(tmp, "$$OutName", result);
875 int res = one.startscript(Systemcalls::System, tmp);
877 ShowMessage(buffer,_("Document exported as HTML to file `")
878 + MakeDisplayPath(result) +'\'');
880 ShowMessage(buffer,_("Unable to convert to HTML the file `")
881 + MakeDisplayPath(infile)
888 void MenuExport(Buffer * buffer, string const & extyp)
891 if (extyp == "latex") {
892 // make sure that this buffer is not linuxdoc
893 MenuMakeLaTeX(buffer);
896 else if (extyp == "linuxdoc") {
897 // make sure that this buffer is not latex
898 MenuMakeLinuxDoc(buffer);
901 else if (extyp == "docbook") {
902 // make sure that this buffer is not latex or linuxdoc
903 MenuMakeDocBook(buffer);
906 else if (extyp == "dvi") {
907 // Run LaTeX as "Update dvi..." Bernhard.
908 // We want the dvi in the current directory. This
909 // is achieved by temporarily disabling use of
910 // temp directory. As a side-effect, we get
911 // *.log and *.aux files also. (Asger)
912 bool flag = lyxrc.use_tempdir;
913 lyxrc.use_tempdir = false;
914 MenuRunLaTeX(buffer);
915 lyxrc.use_tempdir = flag;
918 else if (extyp == "postscript") {
919 // Start Print-dialog. Not as good as dvi... Bernhard.
920 //should start lyxview->getDialogs()->showPrint();
921 // to get same as before
922 // MenuPrint(buffer);
923 // Since the MenuPrint is a pop-up, we can't use
924 // the same trick as above. (Asger)
925 // MISSING: Move of ps-file :-(
926 // And MenuPrint should not be used for this at all...
929 else if (extyp == "ascii") {
930 MenuMakeAscii(buffer);
932 else if (extyp == "custom") {
936 else if (extyp == "html") {
937 if (buffer->isLinuxDoc())
938 MenuMakeHTML_LinuxDoc(buffer);
939 else if (buffer->isDocBook())
940 MenuMakeHTML_DocBook(buffer);
942 MenuMakeHTML(buffer);
945 ShowMessage(buffer, _("Unknown export type: ") + extyp);
952 lyxerr.debug() << "Running QuitLyX." << endl;
954 if (!bufferlist.QwriteAll())
957 lastfiles->writeFile(lyxrc.lastfiles);
959 // Set a flag that we do quitting from the program,
960 // so no refreshes are necessary.
963 // close buffers first
964 bufferlist.closeAll();
966 // do any other cleanup procedures now
967 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
969 DestroyLyXTmpDir(system_tempdir);
976 void AutoSave(BufferView * bv)
977 // should probably be moved into BufferList (Lgb)
978 // Perfect target for a thread...
980 if (!bv->available())
983 if (bv->buffer()->isBakClean() ||
984 bv->buffer()->isReadonly() || bv->buffer()->isUnnamed()) {
985 // We don't save now, but we'll try again later
986 bv->owner()->resetAutosaveTimer();
990 bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
992 // create autosave filename
993 string fname = OnlyPath(bv->buffer()->fileName());
995 fname += OnlyFilename(bv->buffer()->fileName());
998 // tmp_ret will be located (usually) in /tmp
999 // will that be a problem?
1000 string tmp_ret = tmpnam(0);
1002 pid_t pid = fork(); // If you want to debug the autosave
1003 // you should set pid to -1, and comment out the
1005 if (pid == 0 || pid == -1) {
1006 // pid = -1 signifies that lyx was unable
1007 // to fork. But we will do the save
1009 bool failed = false;
1010 if (!tmp_ret.empty()) {
1011 bv->buffer()->writeFile(tmp_ret, 1);
1012 // assume successful write of tmp_ret
1013 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1015 // most likely couldn't move between filesystems
1016 // unless write of tmp_ret failed
1017 // so remove tmp file (if it exists)
1018 remove(tmp_ret.c_str());
1025 // failed to write/rename tmp_ret so try writing direct
1026 if (!bv->buffer()->writeFile(fname, 1)) {
1027 // It is dangerous to do this in the child,
1028 // but safe in the parent, so...
1030 bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1033 if (pid == 0) { // we are the child so...
1038 bv->buffer()->markBakClean();
1039 bv->owner()->resetAutosaveTimer();
1044 // Copyright CHT Software Service GmbH
1047 // create new file with template
1050 Buffer * NewLyxFile(string const & filename)
1052 // Split argument by :
1054 string tmpname = split(filename, name, ':');
1055 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1056 if (name.length() == 1
1057 && isalpha(static_cast<unsigned char>(name[0]))
1058 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1060 name += token(tmpname, ':', 0);
1061 tmpname = split(tmpname, ':');
1064 lyxerr.debug() << "Arg is " << filename
1065 << "\nName is " << name
1066 << "\nTemplate is " << tmpname << endl;
1068 // find a free buffer
1069 Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1071 lastfiles->newFile(tmpbuf->fileName());
1076 // Insert ascii file (if filename is empty, prompt for one)
1077 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1082 if (!bv->available()) return;
1084 if (fname.empty()) {
1086 fname = fileDlg.Select(_("File to Insert"),
1087 bv->owner()->buffer()->filepath,
1090 if (fname.empty()) return;
1095 if (!fi.readable()) {
1096 WriteFSAlert(_("Error! Specified file is unreadable: "),
1097 MakeDisplayPath(fname, 50));
1101 ifstream ifs(fname.c_str());
1103 WriteFSAlert(_("Error! Cannot open specified file: "),
1104 MakeDisplayPath(fname, 50));
1108 ifs.unsetf(ios::skipws);
1109 istream_iterator<char> ii(ifs);
1110 istream_iterator<char> end;
1111 #if !defined(USE_INCLUDED_STRING) && !defined(STD_STRING_IS_GOOD)
1112 // We use this until the compilers get better...
1114 copy(ii, end, back_inserter(tmp));
1115 string tmpstr(tmp.begin(), tmp.end());
1117 // This is what we want to use and what we will use once the
1118 // compilers get good enough.
1119 //string tmpstr(ii, end); // yet a reason for using std::string
1120 // alternate approach to get the file into a string:
1122 copy(ii, end, back_inserter(tmpstr));
1124 // insert the string
1125 current_view->hideCursor();
1127 // clear the selection
1130 bv->text->InsertStringA(bv, tmpstr);
1132 bv->text->InsertStringB(bv, tmpstr);
1133 bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
1137 void MenuShowTableOfContents()
1139 static int ow = -1, oh;
1142 if (fd_form_toc->form_toc->visible) {
1143 fl_raise_form(fd_form_toc->form_toc);
1145 fl_show_form(fd_form_toc->form_toc,
1146 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1147 _("Table Of Contents"));
1149 ow = fd_form_toc->form_toc->w;
1150 oh = fd_form_toc->form_toc->h;
1152 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1157 void MenuInsertLabel(char const * arg)
1160 ProhibitInput(current_view);
1161 if (label.empty()) {
1163 result = askForText(_("Enter new label to insert:"));
1165 label = frontStrip(strip(result.second));
1168 if (!label.empty()) {
1169 InsetLabel * new_inset = new InsetLabel;
1170 new_inset->setContents(label);
1171 current_view->insertInset(new_inset);
1173 AllowInput(current_view);
1177 void MenuInsertRef()
1179 static int ow = -1, oh;
1182 if (fd_form_ref->form_ref->visible) {
1183 fl_raise_form(fd_form_ref->form_ref);
1185 fl_show_form(fd_form_ref->form_ref,
1186 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1187 _("Insert Reference"));
1189 ow = fd_form_ref->form_ref->w;
1190 oh = fd_form_ref->form_ref->h;
1192 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1197 // candidate for move to LyXView
1198 // This is only used in toolbar.C
1199 void LayoutsCB(int sel, void *)
1201 string tmp = tostr(sel);
1202 current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1208 * SGML Linuxdoc support:
1209 * (flag == 0) make TeX output
1210 * (flag == 1) make dvi output
1212 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1219 /* generate a path-less extension name */
1220 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1221 string path = OnlyPath (filename);
1222 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1223 path = bv->buffer()->tmppath;
1227 if (!bv->available())
1229 bv->buffer()->makeLinuxDocFile(name, false);
1231 // CHECK remove this once we have a proper geometry class
1233 BufferParams::PAPER_SIZE ps =
1234 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1236 case BufferParams::PAPER_A4PAPER:
1237 add_flags = "-p a4";
1239 case BufferParams::PAPER_USLETTER:
1240 add_flags = "-p letter";
1242 default: /* nothing to be done yet ;-) */ break;
1249 case 0: /* TeX output asked */
1250 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1251 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1252 if (one.startscript(Systemcalls::System, s2))
1255 case 1: /* dvi output asked */
1256 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1257 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1258 if (one.startscript(Systemcalls::System, s2)) {
1262 default: /* unknown output */
1268 bv->buffer()->redraw();
1274 * SGML DocBook support:
1275 * (flag == 1) make dvi output
1277 int RunDocBook(int flag, string const & filename)
1279 /* generate a path-less extension name */
1280 string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1281 string path = OnlyPath (filename);
1282 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1283 path = current_view->buffer()->tmppath;
1287 if (!current_view->available())
1290 current_view->buffer()->makeDocBookFile(name, false);
1292 // Shall this code go or should it stay? (Lgb)
1293 // This code is a placeholder for future implementation. (Jose')
1294 // string add_flags;
1295 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1297 // case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; break;
1298 // case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1299 // default: /* nothing to be done yet ;-) */ break;
1301 ProhibitInput(current_view);
1306 case 1: /* dvi output asked */
1308 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1309 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1310 if (one.startscript(Systemcalls::System, s2)) {
1315 default: /* unknown output */
1319 AllowInput(current_view);
1321 current_view->buffer()->redraw();
1326 void MenuLayoutCharacter()
1328 static int ow = -1, oh;
1330 if (fd_form_character->form_character->visible) {
1331 fl_raise_form(fd_form_character->form_character);
1333 fl_show_form(fd_form_character->form_character,
1334 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1335 _("Character Style"));
1337 ow = fd_form_character->form_character->w;
1338 oh = fd_form_character->form_character->h;
1340 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1346 void DeactivateParagraphButtons ()
1348 fl_deactivate_object (fd_form_paragraph->button_ok);
1349 fl_deactivate_object (fd_form_paragraph->button_apply);
1350 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1351 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1356 void ActivateParagraphButtons ()
1358 fl_activate_object (fd_form_paragraph->button_ok);
1359 fl_activate_object (fd_form_paragraph->button_apply);
1360 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1361 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1366 void DisableParagraphLayout ()
1368 DeactivateParagraphButtons();
1369 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1370 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1371 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1372 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1373 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1374 fl_deactivate_object (fd_form_paragraph->check_noindent);
1375 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1376 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1377 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1378 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1379 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1380 fl_deactivate_object (fd_form_paragraph->input_space_above);
1381 fl_deactivate_object (fd_form_paragraph->input_space_below);
1382 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1383 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1384 fl_deactivate_object (fd_form_paragraph->check_space_above);
1385 fl_deactivate_object (fd_form_paragraph->check_space_below);
1390 void EnableParagraphLayout ()
1392 ActivateParagraphButtons();
1393 fl_activate_object (fd_form_paragraph->input_labelwidth);
1394 fl_activate_object (fd_form_paragraph->check_lines_top);
1395 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1396 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1397 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1398 fl_activate_object (fd_form_paragraph->check_noindent);
1399 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1400 fl_activate_object (fd_form_paragraph->radio_align_right);
1401 fl_activate_object (fd_form_paragraph->radio_align_left);
1402 fl_activate_object (fd_form_paragraph->radio_align_block);
1403 fl_activate_object (fd_form_paragraph->radio_align_center);
1404 fl_activate_object (fd_form_paragraph->input_space_above);
1405 fl_activate_object (fd_form_paragraph->input_space_below);
1406 fl_activate_object (fd_form_paragraph->choice_space_above);
1407 fl_activate_object (fd_form_paragraph->choice_space_below);
1408 fl_activate_object (fd_form_paragraph->check_space_above);
1409 fl_activate_object (fd_form_paragraph->check_space_below);
1413 bool UpdateLayoutParagraph()
1415 if (!current_view->available()) {
1416 if (fd_form_paragraph->form_paragraph->visible)
1417 fl_hide_form(fd_form_paragraph->form_paragraph);
1421 Buffer * buf = current_view->buffer();
1423 if (current_view->the_locking_inset)
1424 text = current_view->the_locking_inset->getLyXText(current_view);
1426 text = current_view->text;
1428 fl_set_input(fd_form_paragraph->input_labelwidth,
1429 text->cursor.par()->GetLabelWidthString().c_str());
1430 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1431 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1432 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1433 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1435 int align = text->cursor.par()->GetAlign();
1436 if (align == LYX_ALIGN_LAYOUT)
1437 align = textclasslist.Style(buf->params.textclass,
1438 text->cursor.par()->GetLayout()).align;
1441 case LYX_ALIGN_RIGHT:
1442 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1444 case LYX_ALIGN_LEFT:
1445 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1447 case LYX_ALIGN_CENTER:
1448 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1451 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1456 fl_set_button(fd_form_paragraph->check_lines_top,
1457 text->cursor.par()->FirstPhysicalPar()->line_top);
1459 fl_set_button(fd_form_paragraph->check_lines_bottom,
1460 text->cursor.par()->FirstPhysicalPar()->line_bottom);
1462 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1463 text->cursor.par()->FirstPhysicalPar()->pagebreak_top);
1465 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1466 text->cursor.par()->FirstPhysicalPar()->pagebreak_bottom);
1467 fl_set_button(fd_form_paragraph->check_noindent,
1468 text->cursor.par()->FirstPhysicalPar()->noindent);
1470 fl_set_button(fd_form_paragraph->check_lines_top,
1471 text->cursor.par()->line_top);
1472 fl_set_button(fd_form_paragraph->check_lines_bottom,
1473 text->cursor.par()->line_bottom);
1474 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1475 text->cursor.par()->pagebreak_top);
1476 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1477 text->cursor.par()->pagebreak_bottom);
1478 fl_set_button(fd_form_paragraph->check_noindent,
1479 text->cursor.par()->noindent);
1481 fl_set_input (fd_form_paragraph->input_space_above, "");
1484 switch (text->cursor.par()->FirstPhysicalPar()->added_space_top.kind()) {
1486 switch (text->cursor.par()->added_space_top.kind()) {
1490 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1492 case VSpace::DEFSKIP:
1493 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1495 case VSpace::SMALLSKIP:
1496 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1498 case VSpace::MEDSKIP:
1499 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1501 case VSpace::BIGSKIP:
1502 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1505 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1507 case VSpace::LENGTH:
1508 fl_set_choice (fd_form_paragraph->choice_space_above, 7);
1510 fl_set_input (fd_form_paragraph->input_space_above,
1511 text->cursor.par()->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1513 fl_set_input (fd_form_paragraph->input_space_above,
1514 text->cursor.par()->added_space_top.length().asString().c_str());
1519 fl_set_button (fd_form_paragraph->check_space_above,
1520 text->cursor.par()->FirstPhysicalPar()->added_space_top.keep());
1521 fl_set_input (fd_form_paragraph->input_space_below, "");
1522 switch (text->cursor.par()->FirstPhysicalPar()->added_space_bottom.kind()) {
1524 fl_set_button (fd_form_paragraph->check_space_above,
1525 text->cursor.par()->added_space_top.keep());
1526 fl_set_input (fd_form_paragraph->input_space_below, "");
1527 switch (text->cursor.par()->added_space_bottom.kind()) {
1530 fl_set_choice (fd_form_paragraph->choice_space_below,
1533 case VSpace::DEFSKIP:
1534 fl_set_choice (fd_form_paragraph->choice_space_below,
1537 case VSpace::SMALLSKIP:
1538 fl_set_choice (fd_form_paragraph->choice_space_below,
1541 case VSpace::MEDSKIP:
1542 fl_set_choice (fd_form_paragraph->choice_space_below,
1545 case VSpace::BIGSKIP:
1546 fl_set_choice (fd_form_paragraph->choice_space_below,
1550 fl_set_choice (fd_form_paragraph->choice_space_below,
1553 case VSpace::LENGTH:
1554 fl_set_choice (fd_form_paragraph->choice_space_below,
1557 fl_set_input (fd_form_paragraph->input_space_below,
1558 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1561 fl_set_button (fd_form_paragraph->check_space_below,
1562 text->cursor.par()->FirstPhysicalPar()->added_space_bottom.keep());
1564 fl_set_button(fd_form_paragraph->check_noindent,
1565 text->cursor.par()->FirstPhysicalPar()->noindent);
1567 fl_set_input (fd_form_paragraph->input_space_below,
1568 text->cursor.par()->added_space_bottom.length().asString().c_str());
1571 fl_set_button (fd_form_paragraph->check_space_below,
1572 text->cursor.par()->added_space_bottom.keep());
1574 fl_set_button(fd_form_paragraph->check_noindent,
1575 text->cursor.par()->noindent);
1577 if (current_view->buffer()->isReadonly()) {
1578 DisableParagraphLayout();
1580 EnableParagraphLayout();
1586 void MenuLayoutParagraph()
1588 if (UpdateLayoutParagraph()) {
1589 if (fd_form_paragraph->form_paragraph->visible) {
1590 fl_raise_form(fd_form_paragraph->form_paragraph);
1592 fl_show_form(fd_form_paragraph->form_paragraph,
1593 FL_PLACE_MOUSE, FL_FULLBORDER,
1594 _("Paragraph Environment"));
1601 void DeactivateDocumentButtons ()
1603 fl_deactivate_object (fd_form_document->button_ok);
1604 fl_deactivate_object (fd_form_document->button_apply);
1605 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1606 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1611 void ActivateDocumentButtons ()
1613 fl_activate_object (fd_form_document->button_ok);
1614 fl_activate_object (fd_form_document->button_apply);
1615 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1616 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1621 void DisableDocumentLayout ()
1623 DeactivateDocumentButtons ();
1624 fl_deactivate_object (fd_form_document->group_radio_separation);
1625 fl_deactivate_object (fd_form_document->radio_indent);
1626 fl_deactivate_object (fd_form_document->radio_skip);
1627 fl_deactivate_object (fd_form_document->choice_class);
1628 fl_deactivate_object (fd_form_document->choice_pagestyle);
1629 fl_deactivate_object (fd_form_document->choice_fonts);
1630 fl_deactivate_object (fd_form_document->choice_fontsize);
1631 fl_deactivate_object (fd_form_document->input_float_placement);
1632 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1633 fl_deactivate_object (fd_form_document->choice_inputenc);
1634 fl_deactivate_object (fd_form_document->group_radio_sides);
1635 fl_deactivate_object (fd_form_document->radio_sides_one);
1636 fl_deactivate_object (fd_form_document->radio_sides_two);
1637 fl_deactivate_object (fd_form_document->group_radio_columns);
1638 fl_deactivate_object (fd_form_document->radio_columns_one);
1639 fl_deactivate_object (fd_form_document->radio_columns_two);
1640 fl_deactivate_object (fd_form_document->input_extra);
1641 fl_deactivate_object (fd_form_document->choice_language);
1642 combo_language->deactivate();
1643 fl_deactivate_object (fd_form_document->input_default_skip);
1644 fl_deactivate_object (fd_form_document->choice_default_skip);
1645 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1646 fl_deactivate_object (fd_form_document->slider_tocdepth);
1647 fl_deactivate_object (fd_form_document->choice_spacing);
1648 fl_deactivate_object (fd_form_document->input_spacing);
1649 fl_deactivate_object (fd_form_document->check_use_amsmath);
1654 void EnableDocumentLayout ()
1656 ActivateDocumentButtons ();
1657 fl_activate_object (fd_form_document->group_radio_separation);
1658 fl_activate_object (fd_form_document->radio_indent);
1659 fl_activate_object (fd_form_document->radio_skip);
1660 fl_activate_object (fd_form_document->choice_class);
1661 fl_activate_object (fd_form_document->choice_pagestyle);
1662 fl_activate_object (fd_form_document->choice_fonts);
1663 fl_activate_object (fd_form_document->choice_fontsize);
1664 fl_activate_object (fd_form_document->input_float_placement);
1665 fl_activate_object (fd_form_document->choice_postscript_driver);
1666 fl_activate_object (fd_form_document->choice_inputenc);
1667 fl_activate_object (fd_form_document->group_radio_sides);
1668 fl_activate_object (fd_form_document->radio_sides_one);
1669 fl_activate_object (fd_form_document->radio_sides_two);
1670 fl_activate_object (fd_form_document->group_radio_columns);
1671 fl_activate_object (fd_form_document->radio_columns_one);
1672 fl_activate_object (fd_form_document->radio_columns_two);
1673 fl_activate_object (fd_form_document->input_extra);
1674 fl_activate_object (fd_form_document->choice_language);
1675 combo_language->activate();
1676 fl_activate_object (fd_form_document->input_default_skip);
1677 fl_activate_object (fd_form_document->choice_default_skip);
1678 fl_activate_object (fd_form_document->slider_secnumdepth);
1679 fl_activate_object (fd_form_document->slider_tocdepth);
1680 fl_activate_object (fd_form_document->choice_spacing);
1681 fl_activate_object (fd_form_document->input_spacing);
1682 fl_activate_object (fd_form_document->check_use_amsmath);
1686 bool UpdateLayoutDocument(BufferParams * params)
1688 if (!current_view->available()) {
1689 if (fd_form_document->form_document->visible)
1690 fl_hide_form(fd_form_document->form_document);
1695 params = ¤t_view->buffer()->params;
1696 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1698 fl_set_choice_text(fd_form_document->choice_class,
1699 textclasslist.DescOfClass(params->textclass).c_str());
1700 combo_language->select_text(params->language.c_str());
1702 fl_set_choice_text(fd_form_document->choice_fonts,
1703 params->fonts.c_str());
1704 fl_set_choice_text(fd_form_document->choice_inputenc,
1705 params->inputenc.c_str());
1706 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1707 params->graphicsDriver.c_str());
1709 // ale970405+lasgoutt970513
1710 fl_clear_choice(fd_form_document->choice_fontsize);
1711 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1712 fl_addto_choice(fd_form_document->choice_fontsize,
1713 tclass.opt_fontsize().c_str());
1714 fl_set_choice(fd_form_document->choice_fontsize,
1715 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1717 // ale970405+lasgoutt970513
1718 fl_clear_choice(fd_form_document->choice_pagestyle);
1719 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1720 fl_addto_choice(fd_form_document->choice_pagestyle,
1721 tclass.opt_pagestyle().c_str());
1723 fl_set_choice(fd_form_document->choice_pagestyle,
1724 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1726 fl_set_button(fd_form_document->radio_indent, 0);
1727 fl_set_button(fd_form_document->radio_skip, 0);
1730 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1732 if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1733 fl_set_button(fd_form_document->radio_indent, 1);
1735 fl_set_button(fd_form_document->radio_skip, 1);
1737 switch (params->getDefSkip().kind()) {
1738 case VSpace::SMALLSKIP:
1739 fl_set_choice (fd_form_document->choice_default_skip, 1);
1741 case VSpace::MEDSKIP:
1742 fl_set_choice (fd_form_document->choice_default_skip, 2);
1744 case VSpace::BIGSKIP:
1745 fl_set_choice (fd_form_document->choice_default_skip, 3);
1747 case VSpace::LENGTH:
1748 fl_set_choice (fd_form_document->choice_default_skip, 4);
1749 fl_set_input (fd_form_document->input_default_skip,
1750 params->getDefSkip().asLyXCommand().c_str());
1753 fl_set_choice (fd_form_document->choice_default_skip, 2);
1757 fl_set_button(fd_form_document->radio_sides_one, 0);
1758 fl_set_button(fd_form_document->radio_sides_two, 0);
1760 switch (params->sides) {
1761 case LyXTextClass::OneSide:
1762 fl_set_button(fd_form_document->radio_sides_one, 1);
1764 case LyXTextClass::TwoSides:
1765 fl_set_button(fd_form_document->radio_sides_two, 1);
1769 fl_set_button(fd_form_document->radio_columns_one, 0);
1770 fl_set_button(fd_form_document->radio_columns_two, 0);
1772 if (params->columns == 2)
1773 fl_set_button(fd_form_document->radio_columns_two, 1);
1775 fl_set_button(fd_form_document->radio_columns_one, 1);
1777 fl_set_input(fd_form_document->input_spacing, "");
1778 switch (params->spacing.getSpace()) {
1779 case Spacing::Default: // nothing bad should happen with this
1780 case Spacing::Single:
1783 fl_set_choice(fd_form_document->choice_spacing, 1);
1786 case Spacing::Onehalf:
1789 fl_set_choice(fd_form_document->choice_spacing, 2);
1792 case Spacing::Double:
1795 fl_set_choice(fd_form_document->choice_spacing, 3);
1798 case Spacing::Other:
1800 fl_set_choice(fd_form_document->choice_spacing, 4);
1802 //sprintf(sval, "%g", params->spacing.getValue());
1804 std::ostringstream sval;
1805 sval << params->spacing.getValue(); // setw?
1806 fl_set_input(fd_form_document->input_spacing,
1807 sval.str().c_str());
1810 ostrstream sval(tval, 20);
1811 sval << params->spacing.getValue() << '\0'; // setw?
1812 fl_set_input(fd_form_document->input_spacing, sval.str());
1819 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1820 params->secnumdepth);
1821 fl_set_counter_value(fd_form_document->slider_tocdepth,
1823 if (!params->float_placement.empty()) { // buffer local (Lgb)
1824 fl_set_input(fd_form_document->input_float_placement,
1825 params->float_placement.c_str());
1827 fl_set_input(fd_form_document->input_float_placement, "");
1829 if (!params->options.empty())
1830 fl_set_input(fd_form_document->input_extra,
1831 params->options.c_str());
1833 fl_set_input(fd_form_document->input_extra, "");
1835 if (current_view->buffer()->isSGML()) {
1836 // bullets not used in SGML derived documents
1837 fl_deactivate_object(fd_form_document->button_bullets);
1838 fl_set_object_lcol(fd_form_document->button_bullets,
1841 fl_activate_object(fd_form_document->button_bullets);
1842 fl_set_object_lcol(fd_form_document->button_bullets,
1846 if (current_view->buffer()->isReadonly()) {
1847 DisableDocumentLayout();
1849 EnableDocumentLayout();
1856 void MenuLayoutDocument()
1858 if (UpdateLayoutDocument()) {
1859 if (fd_form_document->form_document->visible) {
1860 fl_raise_form(fd_form_document->form_document);
1862 fl_show_form(fd_form_document->form_document,
1863 FL_PLACE_MOUSE, FL_FULLBORDER,
1864 _("Document Layout"));
1870 bool UpdateLayoutQuotes()
1873 if (!current_view->available()
1874 || current_view->buffer()->isReadonly())
1878 fl_set_choice(fd_form_quotes->choice_quotes_language,
1879 current_view->buffer()->params.quotes_language + 1);
1880 fl_set_button(fd_form_quotes->radio_single, 0);
1881 fl_set_button(fd_form_quotes->radio_double, 0);
1883 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1884 fl_set_button(fd_form_quotes->radio_single, 1);
1886 fl_set_button(fd_form_quotes->radio_double, 1);
1887 } else if (fd_form_quotes->form_quotes->visible) {
1888 fl_hide_form(fd_form_quotes->form_quotes);
1894 void MenuLayoutQuotes()
1896 if (UpdateLayoutQuotes()) {
1897 if (fd_form_quotes->form_quotes->visible) {
1898 fl_raise_form(fd_form_quotes->form_quotes);
1900 fl_show_form(fd_form_quotes->form_quotes,
1901 FL_PLACE_MOUSE, FL_FULLBORDER,
1908 bool UpdateLayoutPreamble()
1911 if (!current_view->available())
1915 fl_set_input(fd_form_preamble->input_preamble,
1916 current_view->buffer()->params.preamble.c_str());
1918 if (current_view->buffer()->isReadonly()) {
1919 fl_deactivate_object(fd_form_preamble->input_preamble);
1920 fl_deactivate_object(fd_form_preamble->button_ok);
1921 fl_deactivate_object(fd_form_preamble->button_apply);
1922 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1923 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1926 fl_activate_object(fd_form_preamble->input_preamble);
1927 fl_activate_object(fd_form_preamble->button_ok);
1928 fl_activate_object(fd_form_preamble->button_apply);
1929 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1930 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1932 } else if (fd_form_preamble->form_preamble->visible) {
1933 fl_hide_form(fd_form_preamble->form_preamble);
1939 void MenuLayoutPreamble()
1941 static int ow = -1, oh;
1943 if (UpdateLayoutPreamble()) {
1944 if (fd_form_preamble->form_preamble->visible) {
1945 fl_raise_form(fd_form_preamble->form_preamble);
1947 fl_show_form(fd_form_preamble->form_preamble,
1948 FL_PLACE_MOUSE | FL_FREE_SIZE,
1950 _("LaTeX Preamble"));
1952 ow = fd_form_preamble->form_preamble->w;
1953 oh = fd_form_preamble->form_preamble->h;
1955 fl_set_form_minsize(fd_form_preamble->form_preamble,
1962 void MenuLayoutSave()
1964 if (!current_view->available())
1967 if (AskQuestion(_("Do you want to save the current settings"),
1968 _("for Character, Document, Paper and Quotes"),
1969 _("as default for new documents?")))
1970 current_view->buffer()->saveParamsAsDefaults();
1974 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1975 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1976 LyXFont UserFreeFont(BufferParams const & params)
1978 LyXFont font(LyXFont::ALL_IGNORE);
1980 int pos = fl_get_choice(fd_form_character->choice_family);
1982 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1983 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1984 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1985 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1986 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1989 pos = fl_get_choice(fd_form_character->choice_series);
1991 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1992 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1993 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1994 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1997 pos = fl_get_choice(fd_form_character->choice_shape);
1999 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2000 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2001 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2002 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2003 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2004 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2007 pos = fl_get_choice(fd_form_character->choice_size);
2009 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2010 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2011 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2012 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2013 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2014 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2015 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2016 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2017 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2018 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2019 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2020 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2021 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2022 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2025 pos = fl_get_choice(fd_form_character->choice_bar);
2027 case 1: font.setEmph(LyXFont::IGNORE);
2028 font.setUnderbar(LyXFont::IGNORE);
2029 font.setNoun(LyXFont::IGNORE);
2030 font.setLatex(LyXFont::IGNORE);
2032 case 2: font.setEmph(LyXFont::TOGGLE); break;
2033 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2034 case 4: font.setNoun(LyXFont::TOGGLE); break;
2035 case 5: font.setLatex(LyXFont::TOGGLE); break;
2036 case 6: font.setEmph(LyXFont::INHERIT);
2037 font.setUnderbar(LyXFont::INHERIT);
2038 font.setNoun(LyXFont::INHERIT);
2039 font.setLatex(LyXFont::INHERIT);
2043 pos = fl_get_choice(fd_form_character->choice_color);
2045 case 1: font.setColor(LColor::ignore); break;
2046 case 2: font.setColor(LColor::none); break;
2047 case 3: font.setColor(LColor::black); break;
2048 case 4: font.setColor(LColor::white); break;
2049 case 5: font.setColor(LColor::red); break;
2050 case 6: font.setColor(LColor::green); break;
2051 case 7: font.setColor(LColor::blue); break;
2052 case 8: font.setColor(LColor::cyan); break;
2053 case 9: font.setColor(LColor::magenta); break;
2054 case 10: font.setColor(LColor::yellow); break;
2055 case 11: font.setColor(LColor::inherit); break;
2058 int choice = combo_language2->get();
2060 font.setLanguage(ignore_language);
2061 else if (choice == 2)
2062 font.setLanguage(params.language_info);
2064 font.setLanguage(&languages[combo_language2->getline()]);
2070 /* callbacks for form form_title */
2071 extern "C" void TimerCB(FL_OBJECT *, long)
2073 // only if the form still exists
2074 if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2075 if (fd_form_title->form_title->visible) {
2076 fl_hide_form(fd_form_title->form_title);
2078 fl_free_form(fd_form_title->form_title);
2079 fd_form_title->form_title = 0;
2084 /* callbacks for form form_paragraph */
2086 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2088 // "Synchronize" the choices and input fields, making it
2089 // impossible to commit senseless data.
2091 FD_form_paragraph const * fp = fd_form_paragraph;
2093 if (obj == fp->choice_space_above) {
2094 if (fl_get_choice (fp->choice_space_above) != 7) {
2095 fl_set_input (fp->input_space_above, "");
2096 ActivateParagraphButtons();
2098 } else if (obj == fp->choice_space_below) {
2099 if (fl_get_choice (fp->choice_space_below) != 7) {
2100 fl_set_input (fp->input_space_below, "");
2101 ActivateParagraphButtons();
2103 } else if (obj == fp->input_space_above) {
2104 string input = fl_get_input (fp->input_space_above);
2106 if (input.empty()) {
2107 fl_set_choice (fp->choice_space_above, 1);
2108 ActivateParagraphButtons();
2110 else if (isValidGlueLength (input)) {
2111 fl_set_choice (fp->choice_space_above, 7);
2112 ActivateParagraphButtons();
2115 fl_set_choice (fp->choice_space_above, 7);
2116 DeactivateParagraphButtons();
2118 } else if (obj == fp->input_space_below) {
2119 string input = fl_get_input (fp->input_space_below);
2121 if (input.empty()) {
2122 fl_set_choice (fp->choice_space_below, 1);
2123 ActivateParagraphButtons();
2125 else if (isValidGlueLength (input)) {
2126 fl_set_choice (fp->choice_space_below, 7);
2127 ActivateParagraphButtons();
2130 fl_set_choice (fp->choice_space_below, 7);
2131 DeactivateParagraphButtons();
2137 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2139 if (!current_view->available())
2142 VSpace space_top, space_bottom;
2144 string labelwidthstring;
2147 // If a vspace kind is "Length" but there's no text in
2148 // the input field, reset the kind to "None".
2149 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2150 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2151 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2153 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2154 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2155 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2158 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2159 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2160 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2161 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2162 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2163 case 1: space_top = VSpace(VSpace::NONE); break;
2164 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2165 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2166 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2167 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2168 case 6: space_top = VSpace(VSpace::VFILL); break;
2169 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2171 if (fl_get_button (fd_form_paragraph->check_space_above))
2172 space_top.setKeep (true);
2173 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2174 case 1: space_bottom = VSpace(VSpace::NONE); break;
2175 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2176 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2177 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2178 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2179 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2180 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2182 if (fl_get_button (fd_form_paragraph->check_space_below))
2183 space_bottom.setKeep (true);
2185 if (fl_get_button(fd_form_paragraph->radio_align_left))
2186 align = LYX_ALIGN_LEFT;
2187 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2188 align = LYX_ALIGN_RIGHT;
2189 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2190 align = LYX_ALIGN_CENTER;
2192 align = LYX_ALIGN_BLOCK;
2194 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2195 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2198 if (current_view->the_locking_inset)
2199 text = current_view->the_locking_inset->getLyXText(current_view);
2201 text = current_view->text;
2202 text->SetParagraph(current_view,
2212 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2213 current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2217 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2219 fl_hide_form(fd_form_paragraph->form_paragraph);
2223 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2225 ParagraphApplyCB(ob, data);
2226 ParagraphCancelCB(ob, data);
2230 /* callbacks for form form_character */
2232 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2234 // we set toggleall locally here, since it should be true for
2235 // all other uses of ToggleAndShow() (JMarc)
2236 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2237 ToggleAndShow(current_view, UserFreeFont(current_view->buffer()->params));
2238 current_view->setState();
2243 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2245 fl_hide_form(fd_form_character->form_character);
2249 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2251 CharacterApplyCB(ob, data);
2252 CharacterCloseCB(ob, data);
2256 /* callbacks for form form_document */
2258 void UpdateDocumentButtons(BufferParams const & params)
2260 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2262 switch (params.sides) {
2263 case LyXTextClass::OneSide:
2264 fl_set_button(fd_form_document->radio_sides_one, 1);
2266 case LyXTextClass::TwoSides:
2267 fl_set_button(fd_form_document->radio_sides_two, 1);
2271 if (params.columns == 2)
2272 fl_set_button(fd_form_document->radio_columns_two, 1);
2274 fl_set_button(fd_form_document->radio_columns_one, 1);
2276 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2277 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2278 params.secnumdepth);
2279 fl_set_counter_value(fd_form_document->slider_tocdepth,
2284 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2286 ProhibitInput(current_view);
2287 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2288 if (AskQuestion(_("Should I set some parameters to"),
2289 fl_get_choice_text(ob),
2290 _("the defaults of this document class?"))) {
2291 BufferParams params = BufferParams();
2292 params.textclass = fl_get_choice(ob)-1;
2293 params.useClassDefaults();
2294 UpdateLayoutDocument(¶ms);
2295 UpdateDocumentButtons(params);
2298 // unable to load new style
2299 WriteAlert(_("Conversion Errors!"),
2300 _("Unable to switch to new document class."),
2301 _("Reverting to original document class."));
2302 fl_set_choice(fd_form_document->choice_class,
2303 current_view->buffer()->params.textclass + 1);
2305 AllowInput(current_view);
2309 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2311 // "Synchronize" the choice and the input field, so that it
2312 // is impossible to commit senseless data.
2313 FD_form_document const * fd = fd_form_document;
2315 if (obj == fd->choice_default_skip) {
2316 if (fl_get_choice (fd->choice_default_skip) != 4) {
2317 fl_set_input (fd->input_default_skip, "");
2318 ActivateDocumentButtons();
2320 } else if (obj == fd->input_default_skip) {
2322 char const * input = fl_get_input (fd->input_default_skip);
2325 fl_set_choice (fd->choice_default_skip, 2);
2326 ActivateDocumentButtons();
2327 } else if (isValidGlueLength (input)) {
2328 fl_set_choice (fd->choice_default_skip, 4);
2329 ActivateDocumentButtons();
2331 fl_set_choice (fd->choice_default_skip, 4);
2332 DeactivateDocumentButtons();
2338 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2340 // "Synchronize" the choice and the input field, so that it
2341 // is impossible to commit senseless data.
2342 FD_form_document const * fd = fd_form_document;
2344 if (obj == fd->choice_spacing
2345 && fl_get_choice (fd->choice_spacing) != 4) {
2346 fl_set_input(fd->input_spacing, "");
2347 } else if (obj == fd->input_spacing) {
2349 const char* input = fl_get_input (fd->input_spacing);
2352 fl_set_choice (fd->choice_spacing, 1);
2354 fl_set_choice (fd->choice_spacing, 4);
2360 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2363 BufferParams * params = &(current_view->buffer()->params);
2365 Language const * old_language = params->language_info;
2366 params->language = combo_language->getline();
2367 Languages::iterator lit = languages.find(params->language);
2369 Language const * new_language;
2370 if (lit != languages.end())
2371 new_language = &(*lit).second;
2373 new_language = default_language;
2375 if (current_view->available()) {
2376 if (old_language != new_language
2377 && old_language->RightToLeft() == new_language->RightToLeft()
2378 && !current_view->buffer()->isMultiLingual())
2379 current_view->buffer()->ChangeLanguage(old_language,
2381 if (old_language != new_language) {
2382 //current_view->buffer()->redraw();
2386 params->language_info = new_language;
2388 // If default skip is a "Length" but there's no text in the
2389 // input field, reset the kind to "Medskip", which is the default.
2390 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2391 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2392 fl_set_choice (fd_form_document->choice_default_skip, 2);
2395 /* this shouldn't be done automatically IMO. For example I write german
2396 * documents with an american keyboard very often. Matthias */
2398 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2399 fl_get_choice(fd_form_document->choice_language)); */
2401 fl_get_choice_text(fd_form_document->choice_fonts);
2403 fl_get_choice_text(fd_form_document->choice_inputenc);
2405 fl_get_choice_text(fd_form_document->choice_fontsize);
2407 fl_get_choice_text(fd_form_document->choice_pagestyle);
2408 params->graphicsDriver =
2409 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2410 params->use_amsmath =
2411 fl_get_button(fd_form_document->check_use_amsmath);
2413 if (!current_view->available())
2416 current_view->text->SetCursor(current_view,
2417 current_view->text->cursor.par(),
2418 current_view->text->cursor.pos());
2419 current_view->setState();
2421 LyXTextClassList::ClassList::size_type new_class =
2422 fl_get_choice(fd_form_document->choice_class) - 1;
2424 if (params->textclass != new_class) {
2425 // try to load new_class
2426 if (textclasslist.Load(new_class)) {
2427 // successfully loaded
2429 current_view->owner()->getMiniBuffer()->
2430 Set(_("Converting document to new document class..."));
2432 int ret = cap.SwitchLayoutsBetweenClasses(
2433 current_view->buffer()->params.textclass,
2435 current_view->buffer()->paragraph);
2440 s = _("One paragraph couldn't be converted");
2443 s += _(" paragraphs couldn't be converted");
2445 WriteAlert(_("Conversion Errors!"), s,
2446 _("into chosen document class"));
2449 params->textclass = new_class;
2451 // problem changing class -- warn user and retain old style
2452 WriteAlert(_("Conversion Errors!"),
2453 _("Unable to switch to new document class."),
2454 _("Reverting to original document class."));
2455 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2459 char tmpsep = params->paragraph_separation;
2460 if (fl_get_button(fd_form_document->radio_indent))
2461 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2463 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2464 if (tmpsep != params->paragraph_separation)
2467 VSpace tmpdefskip = params->getDefSkip();
2468 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2469 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2470 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2471 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2472 case 4: params->setDefSkip(
2473 VSpace (LyXGlueLength (fl_get_input
2474 (fd_form_document->input_default_skip))));
2476 // DocumentDefskipCB assures that this never happens
2477 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2479 if (!(tmpdefskip == params->getDefSkip()))
2482 if (fl_get_button(fd_form_document->radio_columns_two))
2483 params->columns = 2;
2485 params->columns = 1;
2486 if (fl_get_button(fd_form_document->radio_sides_two))
2487 params->sides = LyXTextClass::TwoSides;
2489 params->sides = LyXTextClass::OneSide;
2491 Spacing tmpSpacing = params->spacing;
2492 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2494 lyxerr.debug() << "Spacing: SINGLE" << endl;
2495 params->spacing.set(Spacing::Single);
2498 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2499 params->spacing.set(Spacing::Onehalf);
2502 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2503 params->spacing.set(Spacing::Double);
2506 lyxerr.debug() << "Spacing: OTHER" << endl;
2507 params->spacing.set(Spacing::Other,
2508 fl_get_input(fd_form_document->input_spacing));
2511 if (tmpSpacing != params->spacing)
2514 signed char tmpchar =
2515 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2516 if (params->secnumdepth != tmpchar)
2518 params->secnumdepth = tmpchar;
2521 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2523 params->float_placement =
2524 fl_get_input(fd_form_document->input_float_placement);
2526 // More checking should be done to ensure the string doesn't have
2527 // spaces or illegal placement characters in it. (thornley)
2530 current_view->redoCurrentBuffer();
2532 current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2533 current_view->buffer()->markDirty();
2536 fl_get_input(fd_form_document->input_extra);
2540 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2542 fl_hide_form(fd_form_document->form_document);
2546 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2548 DocumentCancelCB(ob, data);
2549 DocumentApplyCB(ob, data);
2553 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2556 // bullet callbacks etc. in bullet_panel.C -- ARRae
2560 /* callbacks for form form_quotes */
2562 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2564 if (!current_view->available())
2567 current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2568 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2569 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2571 lga = InsetQuotes::EnglishQ;
2574 lga = InsetQuotes::SwedishQ;
2577 lga = InsetQuotes::GermanQ;
2580 lga = InsetQuotes::PolishQ;
2583 lga = InsetQuotes::FrenchQ;
2586 lga = InsetQuotes::DanishQ;
2589 current_view->buffer()->params.quotes_language = lga;
2590 if (fl_get_button(fd_form_quotes->radio_single))
2591 current_view->buffer()->
2592 params.quotes_times = InsetQuotes::SingleQ;
2594 current_view->buffer()->
2595 params.quotes_times = InsetQuotes::DoubleQ;
2599 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2601 fl_hide_form(fd_form_quotes->form_quotes);
2605 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2607 QuotesApplyCB(ob, data);
2608 QuotesCancelCB(ob, data);
2613 /* callbacks for form form_preamble */
2615 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2617 fl_hide_form(fd_form_preamble->form_preamble);
2621 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2623 if (!current_view->available())
2626 current_view->buffer()->params.preamble =
2627 fl_get_input(fd_form_preamble->input_preamble);
2628 current_view->buffer()->markDirty();
2629 current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2633 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2635 PreambleApplyCB(ob, data);
2636 PreambleCancelCB(ob, data);
2640 /* callbacks for form form_table */
2643 void TableApplyCB(FL_OBJECT *, long)
2645 if (!current_view->available())
2649 // check for tables in tables
2650 if (current_view->text->cursor.par()->table){
2651 WriteAlert(_("Impossible Operation!"),
2652 _("Cannot insert table in table."),
2657 current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2659 int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2660 int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2663 current_view->hideCursor();
2664 current_view->beforeChange();
2665 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2667 current_view->text->SetCursorParUndo(current_view->buffer());
2668 current_view->text->FreezeUndo();
2670 current_view->text->BreakParagraph(current_view);
2671 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2673 if (current_view->text->cursor.par()->Last()) {
2674 current_view->text->CursorLeft(current_view);
2676 current_view->text->BreakParagraph(current_view);
2677 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2680 current_view->text->current_font.setLatex(LyXFont::OFF);
2681 //if (!fl_get_button(fd_form_table->check_latex)){
2682 // insert the new wysiwy table
2683 current_view->text->SetLayout(current_view, 0); // standard layout
2685 if (current_view->text->cursor.par()->footnoteflag ==
2686 LyXParagraph::NO_FOOTNOTE) {
2689 ->SetParagraph(current_view, 0, 0,
2691 VSpace (0.3 * current_view->buffer()->
2692 params.spacing.getValue(),
2694 VSpace (0.3 * current_view->buffer()->
2695 params.spacing.getValue(),
2703 ->SetParagraph(current_view, 0, 0,
2705 VSpace(VSpace::NONE),
2706 VSpace(VSpace::NONE),
2713 current_view->text->cursor.par()->table =
2714 new LyXTable(xsize, ysize);
2716 Language const * lang =
2717 current_view->text->cursor.par()->getParLanguage(current_view->buffer()->params);
2718 LyXFont font(LyXFont::ALL_INHERIT, lang);
2719 for (int i = 0; i < xsize * ysize - 1; ++i) {
2720 current_view->text->cursor.par()
2721 ->InsertChar(0, LyXParagraph::META_NEWLINE, font);
2723 current_view->text->RedoParagraph(current_view);
2725 current_view->text->UnFreezeUndo();
2727 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2728 current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2729 current_view->setState();
2734 void TableCancelCB(FL_OBJECT *, long)
2736 fl_hide_form(fd_form_table->form_table);
2741 void TableOKCB(FL_OBJECT * ob, long data)
2743 TableApplyCB(ob, data);
2744 TableCancelCB(ob, data);
2750 if (fd_form_figure->form_figure->visible) {
2751 fl_raise_form(fd_form_figure->form_figure);
2753 fl_show_form(fd_form_figure->form_figure,
2754 FL_PLACE_MOUSE, FL_FULLBORDER,
2755 _("Insert Figure"));
2762 if (fd_form_table->form_table->visible) {
2763 fl_raise_form(fd_form_table->form_table);
2765 fl_show_form(fd_form_table->form_table,
2766 FL_PLACE_MOUSE, FL_FULLBORDER,
2772 /* callbacks for form form_figure */
2774 void FigureApplyCB(FL_OBJECT *, long)
2776 if (!current_view->available())
2779 Buffer * buffer = current_view->buffer();
2780 if(buffer->isReadonly()) // paranoia
2783 current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2784 if (fl_get_button(fd_form_figure->radio_inline)
2786 || current_view->text->cursor.par()->table
2789 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2790 current_view->insertInset(new_inset);
2791 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2792 new_inset->Edit(current_view, 0, 0, 0);
2796 current_view->hideCursor();
2797 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2798 current_view->beforeChange();
2800 current_view->text->SetCursorParUndo(current_view->buffer());
2801 current_view->text->FreezeUndo();
2803 current_view->text->BreakParagraph(current_view);
2804 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2806 if (current_view->text->cursor.par()->Last()) {
2807 current_view->text->CursorLeft(current_view);
2809 current_view->text->BreakParagraph(current_view);
2810 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2813 // The standard layout should always be numer 0;
2814 current_view->text->SetLayout(current_view, 0);
2817 if (current_view->text->cursor.par()->footnoteflag ==
2818 LyXParagraph::NO_FOOTNOTE) {
2820 current_view->text->
2821 SetParagraph(current_view, 0, 0,
2823 VSpace (0.3 * buffer->params.spacing.getValue(),
2826 buffer->params.spacing.getValue(),
2828 LYX_ALIGN_CENTER, string(), 0);
2831 current_view->text->SetParagraph(current_view, 0, 0,
2833 VSpace(VSpace::NONE),
2834 VSpace(VSpace::NONE),
2841 current_view->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
2843 Inset * new_inset = new InsetFig(100, 100, buffer);
2844 current_view->insertInset(new_inset);
2845 new_inset->Edit(current_view, 0, 0, 0);
2846 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2847 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2848 current_view->text->UnFreezeUndo();
2849 current_view->setState();
2853 extern "C" void FigureCancelCB(FL_OBJECT *, long)
2855 fl_hide_form(fd_form_figure->form_figure);
2859 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
2861 FigureApplyCB(ob, data);
2862 FigureCancelCB(ob, data);
2866 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
2868 lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
2869 lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
2870 lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
2871 lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
2872 lyxrc.set_font_norm_type();
2873 lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
2874 fontloader.update();
2876 // Of course we should only to the resize and the textcahce.clear
2877 // if values really changed...but not very important right now. (Lgb)
2879 // All buffers will need resize
2880 bufferlist.resize();
2881 // We also need to empty the textcache so that
2882 // the buffer will be formatted correctly after
2886 current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
2890 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
2892 fl_hide_form(fd_form_screen->form_screen);
2896 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
2898 ScreenCancelCB(ob, data);
2899 ScreenApplyCB(ob, data);
2903 // This function runs "configure" and then rereads lyx.defaults to
2904 // reconfigure the automatic settings.
2905 void Reconfigure(BufferView * bv)
2907 bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
2909 // Run configure in user lyx directory
2910 Path p(user_lyxdir);
2911 Systemcalls one(Systemcalls::System,
2912 AddName(system_lyxdir, "configure"));
2914 bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
2915 lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
2916 WriteAlert(_("The system has been reconfigured."),
2917 _("You need to restart LyX to make use of any"),
2918 _("updated document class specifications."));
2923 // Table of Contents
2926 static vector<Buffer::TocItem> toclist;
2929 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
2931 if (!current_view->available())
2935 unsigned int choice = fl_get_browser(ob);
2936 if (0 < choice && choice - 1 < toclist.size()) {
2937 current_view->beforeChange();
2938 current_view->text->SetCursor(current_view, toclist[choice-1].par, 0);
2939 current_view->text->sel_cursor =
2940 current_view->text->cursor;
2941 current_view->update(BufferView::SELECT|BufferView::FITCUR);
2943 WriteAlert(_("Error"),
2944 _("Couldn't find this label"),
2945 _("in current document."));
2950 extern "C" void TocCancelCB(FL_OBJECT *, long)
2952 fl_hide_form(fd_form_toc->form_toc);
2957 void TocUpdateCB(FL_OBJECT *, long)
2959 if (!current_view->available()) {
2961 fl_clear_browser(fd_form_toc->browser_toc);
2962 fl_add_browser_line(fd_form_toc->browser_toc,
2963 _("*** No Document ***"));
2967 vector<vector<Buffer::TocItem> > tmp =
2968 current_view->buffer()->getTocList();
2969 int type = fl_get_choice(fd_form_toc->toctype)-1;
2970 //if (toclist == tmp[type])
2972 if (toclist.size() == tmp[type].size()) {
2973 // Check if all elements are the same.
2975 for (; i < toclist.size(); ++i) {
2976 if (toclist[i] != tmp[type][i])
2979 if (i >= toclist.size()) return;
2982 toclist = tmp[type];
2984 static Buffer * buffer = 0;
2987 if (buffer == current_view->buffer()) {
2988 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
2989 line = fl_get_browser(fd_form_toc->browser_toc);
2991 buffer = current_view->buffer();
2993 fl_clear_browser(fd_form_toc->browser_toc);
2994 fl_hide_object(fd_form_toc->browser_toc);
2996 for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
2997 it != toclist.end(); ++it)
2998 fl_add_browser_line(fd_form_toc->browser_toc,
2999 (string(4*(*it).depth,' ')+
3000 (*it).str).c_str());
3002 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3003 fl_select_browser_line(fd_form_toc->browser_toc, line);
3004 fl_show_object(fd_form_toc->browser_toc);
3008 /* callbacks for form form_ref */
3009 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3011 if (!current_view->available())
3015 fl_get_browser_line(fd_form_ref->browser_ref,
3016 fl_get_browser(fd_form_ref->browser_ref));
3017 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3023 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3024 if (!current_view->NoSavedPositions()) {
3025 fl_activate_object(fd_form_ref->back);
3026 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
3029 } else if (data >= 6) {
3030 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFBACK);
3031 if (current_view->NoSavedPositions()) {
3032 fl_deactivate_object(fd_form_ref->back);
3033 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
3038 static string const commands[5]
3039 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
3041 string t = commands[data];
3043 if (current_view->buffer()->isSGML())
3044 t += "[" + u + "]" + "{" + s + "}";
3049 new InsetRef(t, current_view->buffer());
3050 current_view->insertInset(new_inset);
3054 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3056 if (!current_view->available()) {
3057 fl_clear_browser(fd_form_ref->browser_ref);
3061 FL_OBJECT * brow = fd_form_ref->browser_ref;
3063 // Get the current line, in order to restore it later
3064 char const * const btmp = fl_get_browser_line(brow,
3065 fl_get_browser(brow));
3066 string currentstr = btmp ? btmp : "";
3068 fl_clear_browser(brow);
3069 fl_hide_object(brow);
3071 vector<string> refs = current_view->buffer()->getLabelList();
3072 if (fl_get_button(fd_form_ref->sort))
3073 sort(refs.begin(),refs.end());
3074 for (vector<string>::const_iterator it = refs.begin();
3075 it != refs.end(); ++it)
3076 fl_add_browser_line(brow, (*it).c_str());
3079 int total_lines = fl_get_browser_maxline(brow);
3080 for (int i = 1; i <= total_lines ; ++i) {
3081 if (fl_get_browser_line(brow, i) == currentstr) {
3086 fl_set_browser_topline(brow, topline);
3088 bool empty = refs.empty();
3089 bool sgml = current_view->buffer()->isSGML();
3090 bool readonly = current_view->buffer()->isReadonly();
3092 if (current_view->NoSavedPositions()) {
3093 fl_deactivate_object(fd_form_ref->back);
3094 fl_set_object_lcol(fd_form_ref->back, FL_INACTIVE);
3096 fl_activate_object(fd_form_ref->back);
3097 fl_set_object_lcol(fd_form_ref->back, FL_BLACK);
3101 fl_add_browser_line(brow,
3102 _("*** No labels found in document ***"));
3103 fl_deactivate_object(brow);
3104 fl_deactivate_object(fd_form_ref->gotoref);
3105 fl_set_object_lcol(fd_form_ref->gotoref, FL_INACTIVE);
3107 fl_select_browser_line(brow, topline);
3108 fl_activate_object(brow);
3109 fl_activate_object(fd_form_ref->gotoref);
3110 fl_set_object_lcol(fd_form_ref->gotoref, FL_BLACK);
3113 if (empty || readonly) {
3114 fl_deactivate_object(fd_form_ref->ref);
3115 fl_set_object_lcol(fd_form_ref->ref, FL_INACTIVE);
3116 fl_deactivate_object(fd_form_ref->pageref);
3117 fl_set_object_lcol(fd_form_ref->pageref, FL_INACTIVE);
3119 fl_activate_object(fd_form_ref->ref);
3120 fl_set_object_lcol(fd_form_ref->ref, FL_BLACK);
3121 fl_activate_object(fd_form_ref->pageref);
3122 fl_set_object_lcol(fd_form_ref->pageref, FL_BLACK);
3125 if (empty || readonly || sgml) {
3126 fl_deactivate_object(fd_form_ref->vref);
3127 fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
3128 fl_deactivate_object(fd_form_ref->vpageref);
3129 fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
3130 fl_deactivate_object(fd_form_ref->prettyref);
3131 fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
3133 fl_activate_object(fd_form_ref->vref);
3134 fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
3135 fl_activate_object(fd_form_ref->vpageref);
3136 fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
3137 fl_activate_object(fd_form_ref->prettyref);
3138 fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
3142 fl_activate_object(fd_form_ref->ref_name);
3143 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3145 fl_deactivate_object(fd_form_ref->ref_name);
3146 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3149 fl_show_object(brow);
3153 extern "C" void RefHideCB(FL_OBJECT *, long)
3155 fl_hide_form(fd_form_ref->form_ref);