1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich,
7 * Copyright 1995-1999 The LyX Team.
9 * ======================================================*/
20 #include "support/lstrings.h"
22 #include FORMS_H_LOCATION
24 #include "layout_forms.h"
25 #include "bullet_forms.h"
26 #include "print_form.h"
28 #include "spellchecker.h"
32 #include "insets/insetref.h"
33 #include "insets/insetquotes.h"
34 #include "insets/insetlatex.h"
35 #include "insets/insetlabel.h"
36 #include "insets/insetinfo.h"
37 #include "insets/insetspecialchar.h"
38 #include "insets/figinset.h"
40 #include "latexoptions.h"
42 #include "minibuffer.h"
44 #include "bufferlist.h"
45 #include "support/filetools.h"
46 #include "support/path.h"
48 #include "lyx_gui_misc.h"
49 #include "LyXView.h" // only because of form_main
50 #include "lastfiles.h"
51 #include "support/FileInfo.h"
52 #include "lyxscreen.h"
54 #include "support/syscall.h"
55 #include "support/lyxlib.h"
56 #include "lyxserver.h"
57 #include "FontLoader.h"
63 extern MiniBuffer *minibuffer;
64 extern Combox *combo_language;
65 extern BufferList bufferlist;
66 extern void show_symbols_form();
67 extern FD_form_main *fd_form_main;
68 extern FD_form_title *fd_form_title;
69 extern FD_form_paragraph *fd_form_paragraph;
70 extern FD_form_character *fd_form_character;
71 extern FD_form_document *fd_form_document;
72 extern FD_form_quotes *fd_form_quotes;
73 extern FD_form_preamble *fd_form_preamble;
74 extern FD_form_table *fd_form_table;
75 extern FD_form_print *fd_form_print;
76 extern FD_form_figure *fd_form_figure;
77 extern FD_form_screen *fd_form_screen;
78 extern FD_form_toc *fd_form_toc;
79 extern FD_form_ref *fd_form_ref;
80 extern FD_LaTeXOptions *fd_latex_options;
81 extern FD_form_bullet *fd_form_bullet;
83 extern BufferView *current_view; // called too many times in this file...
85 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
87 extern bool send_fax(string const &fname, string const &sendcmd);
89 extern LyXServer *lyxserver;
90 extern FontLoader fontloader;
92 // this should be static, but I need it in buffer.C
93 bool quitting; // flag, that we are quitting the program
94 extern bool finished; // all cleanup done just let it run through now.
96 char ascii_type; /* for selection notify callbacks */
98 bool scrolling = false;
100 char updatetimer = 0;
102 /* whether the work area should get callbacks */
103 bool input_prohibited = false;
105 /* the selection possible is needed, that only motion events are
106 * used, where the bottom press event was on the drawing area too */
107 bool selection_possible = false;
109 // This is used to make the dreaded font toggle problem hopefully go
110 // away. Definitely not the best solution, but I think it sorta works.
111 bool toggleall = true;
113 void InsertCorrectQuote();
117 This is the inset locking stuff needed for mathed --------------------
119 an inset can simple call LockInset in it's edit call and *ONLY* in it's
121 Inset::Edit() can only be called by the main lyx module.
123 Then the inset may modify the menu's and/or iconbars.
125 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
127 During the lock, all button and keyboard events will be modified
128 and send to the inset through the following inset-features. Note that
129 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
130 to contain the code for restoring the menus and things like this.
133 virtual void InsetButtonPress(int x, int y, int button);
134 virtual void InsetButtonRelease(int x, int y, int button);
135 virtual void InsetKeyPress(XKeyEvent *ev);
136 virtual void InsetMotionNotify(int x, int y, int state);
137 virtual void InsetUnlock();
139 If a inset wishes any redraw and/or update it just has to call
141 It's is completly irrelevant, where the inset is. UpdateInset will
142 find it in any paragraph in any buffer.
143 Of course the_locking_inset and the insets in the current paragraph/buffer
144 are checked first, so no performance problem should occur.
146 Hope that's ok for the beginning, Alejandro,
147 sorry that I needed so much time,
152 void UpdateInset(Inset* inset, bool mark_dirty = true);
153 /* these functions return 1 if an error occured,
155 // Now they work only for updatable insets. [Alejandro 080596]
156 int LockInset(UpdatableInset* inset);
157 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
158 void FitLockedInsetCursor(long x, long y, int asc, int desc);
159 int UnlockInset(UpdatableInset* inset);
160 void LockedInsetStoreUndo(Undo::undo_kind kind);
162 /* this is for asyncron updating. UpdateInsetUpdateList will be called
163 automatically from LyX. Just insert the Inset into the Updatelist */
164 void UpdateInsetUpdateList();
165 void PutInsetIntoInsetUpdateList(Inset* inset);
167 InsetUpdateStruct *InsetUpdateList = 0;
171 -----------------------------------------------------------------------
174 /* some function prototypes */
181 void HyphenationPoint();
182 void MenuSeparator();
185 void ProtectedBlank();
187 int RunLinuxDoc(int, string const &);
188 int RunDocBook(int, string const &);
189 void MenuWrite(Buffer* buf);
190 void MenuWriteAs(Buffer *buffer);
191 void MenuReload(Buffer *buf);
192 void MenuLayoutSave();
194 unsigned char GetCurrentTextClass()
195 // Who are we asking?
196 // Shouldn't this question be directed to the buffer?
197 // Indeed it should. Asger.
199 return current_view->currentBuffer()->params.textclass;
203 // How should this actually work? Should it prohibit input in all BufferViews,
204 // or just in the current one? If "just the current one", then it should be
205 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
206 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
207 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
208 // current LyxView that should be prohibited (Lgb) (This applies to
209 // "AllowInput" as well.)
212 input_prohibited = true;
213 if (current_view->getScreen())
214 current_view->getScreen()->HideCursor();
216 static Cursor cursor;
217 static bool cursor_undefined = true;
219 if (cursor_undefined){
220 cursor = XCreateFontCursor(fl_display, XC_watch);
222 cursor_undefined = false;
225 /* set the cursor to the watch for all forms and the canvas */
226 XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
227 if (fd_form_paragraph->form_paragraph->visible)
228 XDefineCursor(fl_display,
229 fd_form_paragraph->form_paragraph->window,
231 if (fd_form_character->form_character->visible)
232 XDefineCursor(fl_display,
233 fd_form_character->form_character->window,
237 fl_deactivate_all_forms();
241 // Should find a way to move this into BufferView.C
242 void SetXtermCursor(Window win)
244 static Cursor cursor;
245 static char cursor_undefined = 1;
246 if (cursor_undefined){
247 cursor = XCreateFontCursor(fl_display, XC_xterm);
249 cursor_undefined = 0;
251 XDefineCursor(fl_display, win, cursor);
258 input_prohibited = false;
260 /* reset the cursor from the watch for all forms and the canvas */
262 XUndefineCursor(fl_display, fd_form_main->form_main->window);
263 if (fd_form_paragraph->form_paragraph->visible)
264 XUndefineCursor(fl_display,
265 fd_form_paragraph->form_paragraph->window);
266 if (fd_form_character->form_character->visible)
267 XUndefineCursor(fl_display,
268 fd_form_character->form_character->window);
269 if (current_view->getWorkArea()->belowmouse)
270 SetXtermCursor(fd_form_main->form_main->window);
273 fl_activate_all_forms();
277 void FreeUpdateTimer()
279 /* a real free timer would be better but I don't know
280 * how to do this with xforms */
285 void SetUpdateTimer(float time)
287 fl_set_timer(fd_form_main->timer_update, time);
294 current_view->getScreen()->ToggleSelection();
295 current_view->currentBuffer()->text->ClearSelection();
300 void SmallUpdate(signed char f)
302 current_view->getScreen()->SmallUpdate();
303 if (current_view->getScreen()->TopCursorVisible()
304 != current_view->getScreen()->first){
305 current_view->currentBuffer()->update(f);
309 current_view->fitCursor();
310 current_view->updateScrollbar();
312 if (!current_view->currentBuffer()->text->selection)
313 current_view->currentBuffer()->text->sel_cursor =
314 current_view->currentBuffer()->text->cursor;
317 if (current_view->currentBuffer()->isLyxClean()) {
318 current_view->currentBuffer()->markDirty();
319 minibuffer->setTimer(4);
322 current_view->currentBuffer()->markDirty();
336 // should be moved to lyxfunc.C
337 void MenuWrite(Buffer* buf)
340 if (!bufferlist.write(buf)) {
341 string fname = buf->getFileName();
342 string s = MakeAbsPath(fname);
343 if (AskQuestion(_("Save failed. Rename and try again?"),
344 MakeDisplayPath(s,50),
345 _("(If not, document is not saved.)"))) {
349 lastfiles->newFile(buf->getFileName());
354 // should be moved to BufferView.C
355 void MenuWriteAs(Buffer *buffer)
357 if (!buffer->text) return;
359 string fname = buffer->getFileName();
360 string oldname = fname;
364 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
365 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
367 if (!IsLyXFilename(fname))
370 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
373 OnlyFilename(fname));
377 minibuffer->Set(_("Canceled."));
381 // Make sure the absolute filename ends with appropriate suffix
382 string s= MakeAbsPath(fname);
383 if (!IsLyXFilename(s))
386 // Same name as we have already?
388 if (!AskQuestion(_("Same name as document already has:"),
389 MakeDisplayPath(s,50),
392 // Falls through to name change and save
394 // No, but do we have another file with this name open?
395 else if (bufferlist.exists(s)) {
396 if (AskQuestion(_("Another document with same name open!"),
397 MakeDisplayPath(s,50),
398 _("Replace with current document?")))
400 bufferlist.close(bufferlist.getBuffer(s));
402 // Ok, change the name of the buffer, but don't save!
403 buffer->setFileName(s);
406 minibuffer->Set(_("Document renamed to '"),
408 _("', but not saved..."));
411 } // Check whether the file exists
414 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
415 MakeDisplayPath(s,50),
420 // Ok, change the name of the buffer
421 buffer->setFileName(s);
424 // Small bug: If the save fails, we have irreversible changed the name
430 int MenuRunLaTeX(Buffer *buffer)
434 if (buffer->isLinuxDoc())
435 ret = RunLinuxDoc(1, buffer->getFileName());
436 else if (buffer->isLiterate())
437 ret = buffer->runLiterate();
438 else if (buffer->isDocBook())
439 ret = RunDocBook(1, buffer->getFileName());
441 ret = buffer->runLaTeX();
447 s = _("One error detected");
448 t = _("You should try to fix it.");
451 s += _(" errors detected.");
452 t = _("You should try to fix them.");
454 WriteAlert(_("There were errors during the LaTeX run."), s, t);
460 int MenuBuildProg(Buffer *buffer)
464 if (buffer->isLiterate())
465 ret = buffer->buildProgram();
469 s = _("Wrong type of document");
470 t = _("The Build operation is not allowed in this document");
471 WriteAlert(_("There were errors during the Build process."), s, t);
479 s = _("One error detected");
480 t = _("You should try to fix it.");
483 s += _(" errors detected.");
484 t = _("You should try to fix them.");
486 WriteAlert(_("There were errors during the Build process."), s, t);
492 int MenuRunChktex(Buffer *buffer)
496 if (buffer->isSGML()) {
497 WriteAlert(_("Chktex does not work with SGML derived documents."));
500 ret = buffer->runChktex();
506 s = _("No warnings found.");
507 } else if (ret == 1) {
508 s = _("One warning found.");
509 t = _("Use 'Edit->Go to Error' to find it.");
512 s += _(" warnings found.");
513 t = _("Use 'Edit->Go to Error' to find them.");
515 WriteAlert(_("Chktex run successfully"), s, t);
517 WriteAlert(_("Error!"),_("It seems chktex does not work."));
523 int MakeDVIOutput(Buffer *buffer)
530 string path = OnlyPath(buffer->getFileName());
531 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
532 path = buffer->tmppath;
534 if (!buffer->isDviClean()) {
536 ret = MenuRunLaTeX(buffer);
542 /* wait == false means don't wait for termination */
543 /* wait == true means wait for termination */
544 // The bool should be placed last on the argument line. (Lgb)
545 // Returns false if we fail.
546 bool RunScript(Buffer * buffer, bool wait,
547 string const & command, string const & orgname = string(),
548 bool need_shell=true)
552 string name= orgname;
555 if (MakeDVIOutput(buffer) > 0)
557 /* get DVI-Filename */
559 name = ChangeExtension(buffer->getFileName(),
562 path = OnlyPath(name);
563 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
564 path = buffer->tmppath;
568 cmd = command + ' ' + SpaceLess(name);
576 // OS/2 cmd.exe has another use for '&'
578 // This is not NLS safe, but it's OK, I think.
579 string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
581 // COMSPEC is set, unless user unsets
582 sh = OnlyFilename(GetEnvPath("COMSPEC"));
587 if (contains(sh, "cmd.exe")
588 || contains(sh, "4os2.exe"))
589 cmd = "start /min/n " + cmd;
594 // It seems that, if wait is false, we never get back
595 // the return code of the command. This means that all
596 // the code I added in PrintApplyCB is currently
599 #warning What should we do here?
601 minibuffer->Set(_("Executing command:"), cmd);
602 result = one.startscript(Systemcalls::System, cmd);
604 minibuffer->Set(_("Executing command:"), cmd);
605 result = one.startscript(wait ? Systemcalls::Wait
606 : Systemcalls::DontWait, cmd);
612 // Returns false if we fail
613 bool MenuRunDvips(Buffer *buffer, bool wait=false)
621 if (MakeDVIOutput(buffer) > 0) {
625 // Generate postscript file
626 string ps = ChangeExtension (buffer->getFileName(),
631 char real_papersize = buffer->params.papersize;
632 if (real_papersize == PAPER_DEFAULT)
633 real_papersize = lyxrc->default_papersize;
635 switch (real_papersize) {
651 case PAPER_EXECUTIVEPAPER:
654 case PAPER_LEGALPAPER:
657 default: /* If nothing else fits, keep an empty value... */
661 // Make postscript file.
662 string command = "dvips " + lyxrc->print_to_file + ' ';
663 command += SpaceLess(ps);
664 if (buffer->params.use_geometry
665 && buffer->params.papersize2 == VM_PAPER_CUSTOM
666 && !lyxrc->print_paper_dimension_flag.empty()
667 && !buffer->params.paperwidth.empty()
668 && !buffer->params.paperheight.empty()) {
669 // using a custom papersize
671 command += lyxrc->print_paper_dimension_flag + ' ';
672 command += buffer->params.paperwidth + ',';
673 command += buffer->params.paperheight;
674 } else if (!paper.empty()
675 && (real_papersize != PAPER_USLETTER ||
676 buffer->params.orientation == ORIENTATION_PORTRAIT)) {
677 // dvips won't accept -t letter -t landscape. In all other
678 // cases, include the paper size explicitly.
680 command += lyxrc->print_paper_flag + ' ' + paper;
682 if (buffer->params.orientation == ORIENTATION_LANDSCAPE) {
684 command += lyxrc->print_landscape_flag;
686 // push directorypath, if necessary
687 string path = OnlyPath(buffer->getFileName());
688 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
689 path = buffer->tmppath;
692 bool ret = RunScript(buffer, wait, command);
698 // Returns false if we fail
699 bool MenuPreviewPS(Buffer *buffer)
704 // Generate postscript file
705 if (!MenuRunDvips(buffer, true)) {
709 // Start postscript viewer
711 string ps = ChangeExtension (buffer->getFileName(),
713 // push directorypath, if necessary
714 string path = OnlyPath(buffer->getFileName());
715 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
716 path = buffer->tmppath;
719 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
725 void MenuFax(Buffer *buffer)
730 // Generate postscript file
731 if (!MenuRunDvips(buffer, true)) {
736 string ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true);
737 string path = OnlyPath (buffer->getFileName());
738 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
739 path = buffer->tmppath;
742 if (!lyxrc->fax_program.empty()) {
743 string help2 = subst(lyxrc->fax_program, "$$FName", ps);
745 Systemcalls one(Systemcalls::System, help2);
747 send_fax(ps,lyxrc->fax_command);
751 // Returns false if we fail
752 bool MenuPreview(Buffer *buffer)
759 char real_papersize = buffer->params.papersize;
760 if (real_papersize == PAPER_DEFAULT)
761 real_papersize = lyxrc->default_papersize;
763 switch (real_papersize) {
779 case PAPER_EXECUTIVEPAPER:
782 case PAPER_LEGALPAPER:
785 default: /* If nothing else fits, keep the empty value */
790 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
791 // we HAVE to give a size when the page is in
792 // landscape, so use USletter.
793 paper = " -paper usr";
795 paper = " -paper " + paper;
796 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
800 // push directorypath, if necessary
801 string path = OnlyPath(buffer->getFileName());
802 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
803 path = buffer->tmppath;
807 string command = lyxrc->view_dvi_command + paper ;
808 bool ret = RunScript(buffer, false, command);
813 void MenuMakeLaTeX(Buffer * buffer)
816 // Get LaTeX-Filename
817 string s = SpaceLess(ChangeExtension(
818 buffer->getFileName(),
821 FilePtr myfile(s, FilePtr::read);
823 !AskQuestion(_("File already exists:"),
824 MakeDisplayPath(s,50),
825 _("Do you want to overwrite the file?"))) {
826 minibuffer->Set(_("Canceled"));
830 if (buffer->isDocBook())
831 minibuffer->Set(_("DocBook does not have a latex backend"));
833 if (buffer->isLinuxDoc())
834 RunLinuxDoc(0, buffer->getFileName());
836 buffer->makeLaTeXFile(s, string(), true);
837 minibuffer->Set(_("Nice LaTeX file saved as"),
839 buffer->markDviDirty();
845 void MenuMakeLinuxDoc(Buffer *buffer)
849 if (!buffer->isLinuxDoc()) {
850 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
854 // Get LinuxDoc-Filename
855 string s = ChangeExtension (buffer->getFileName(),
858 FilePtr myfile(s, FilePtr::read);
860 !AskQuestion(_("File already exists:"),
861 MakeDisplayPath(s,50),
862 _("Do you want to overwrite the file?"))) {
863 minibuffer->Set(_("Canceled"));
867 minibuffer->Set(_("Building LinuxDoc SGML file `"),
868 MakeDisplayPath(s), "'...");
870 buffer->makeLinuxDocFile(s, 65);
872 minibuffer->Set(_("LinuxDoc SGML file save as"),
878 void MenuMakeDocBook(Buffer *buffer)
882 if (!buffer->isDocBook()) {
883 WriteAlert(_("Error!"), _("Document class must be docbook."));
887 // Get DocBook-Filename
888 string s = ChangeExtension (buffer->getFileName(),
891 FilePtr myfile(s, FilePtr::read);
893 !AskQuestion(_("File already exists:"),
894 MakeDisplayPath(s,50),
895 _("Do you want to overwrite the file?"))) {
896 minibuffer->Set(_("Canceled"));
900 minibuffer->Set(_("Building DocBook SGML file `"),
901 MakeDisplayPath(s), "'...");
903 buffer->makeDocBookFile(s, 65);
905 minibuffer->Set(_("DocBook SGML file save as"),
911 void MenuMakeAscii(Buffer *buffer)
914 /* get LaTeX-Filename */
915 string s = ChangeExtension (buffer->getFileName(),
918 FilePtr myfile(s, FilePtr::read);
920 !AskQuestion(_("File already exists:"),
921 MakeDisplayPath(s,50),
922 _("Do you want to overwrite the file?"))) {
923 minibuffer->Set(_("Canceled"));
927 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
929 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
934 void MenuPrint(Buffer *buffer)
941 input_file = ChangeExtension(buffer->getFileName(),
942 lyxrc->print_file_extension,
944 fl_set_input(fd_form_print->input_file, input_file.c_str());
946 if (fd_form_print->form_print->visible) {
947 fl_raise_form(fd_form_print->form_print);
950 fl_show_form(fd_form_print->form_print,
951 FL_PLACE_MOUSE, FL_FULLBORDER,
959 lyxerr.debug() << "Running QuitLyX." << endl;
961 if (!bufferlist.QwriteAll())
964 lastfiles->writeFile(lyxrc->lastfiles);
966 // Set a flag that we do quitting from the program,
967 // so no refreshes are necessary.
970 // close buffers first
971 bufferlist.closeAll();
973 // do any other cleanup procedures now
974 lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
976 DestroyLyXTmpDir(system_tempdir);
984 // should probably be moved into BufferList (Lgb)
985 // Perfect target for a thread...
987 if (!current_view->getScreen() || !current_view->available())
990 if (current_view->currentBuffer()->isBakClean()
991 || current_view->currentBuffer()->isReadonly()) {
992 // We don't save now, but we'll try again later
993 current_view->getOwner()->resetAutosaveTimer();
997 minibuffer->Set(_("Autosaving current document..."));
999 // create autosave filename
1000 string fname = OnlyPath(current_view->currentBuffer()->getFileName());
1002 fname += OnlyFilename(current_view->currentBuffer()->getFileName());
1005 // tmp_ret will be located (usually) in /tmp
1006 // will that be a problem?
1007 string tmp_ret = tmpnam(0);
1009 pid_t pid = fork(); // If you want to debug the autosave
1010 // you should set pid to -1, and comment out the
1012 if (pid == 0 || pid == -1) {
1013 // pid = -1 signifies that lyx was unable
1014 // to fork. But we will do the save
1016 bool failed = false;
1017 if (!tmp_ret.empty()) {
1018 current_view->currentBuffer()->writeFile(tmp_ret, 1);
1019 // assume successful write of tmp_ret
1020 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1022 // most likely couldn't move between filesystems
1023 // unless write of tmp_ret failed
1024 // so remove tmp file (if it exists)
1025 remove(tmp_ret.c_str());
1032 // failed to write/rename tmp_ret so try writing direct
1033 if (!current_view->currentBuffer()->writeFile(fname,
1035 // It is dangerous to do this in the child,
1036 // but safe in the parent, so...
1038 minibuffer->Set(_("Autosave Failed!"));
1041 if (pid == 0) { // we are the child so...
1046 current_view->currentBuffer()->markBakClean();
1047 current_view->getOwner()->resetAutosaveTimer();
1052 // (c) CHT Software Service GmbH
1055 // create new file with template
1058 Buffer * NewLyxFile(string const & filename)
1060 // Split argument by :
1062 string tmpname = split(filename, name, ':');
1063 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1064 if (name.length() == 1
1065 && isalpha(static_cast<unsigned char>(name[0]))
1066 && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1068 name += token(tmpname, ':', 0);
1069 tmpname = split(tmpname, ':');
1072 lyxerr.debug() << "Arg is " << filename
1073 << "\nName is " << name
1074 << "\nTemplate is " << tmpname << endl;
1076 // find a free buffer
1077 Buffer *tmpbuf = bufferlist.newFile(name,tmpname);
1079 lastfiles->newFile(tmpbuf->getFileName());
1084 // Insert ascii file (if filename is empty, prompt for one)
1085 void InsertAsciiFile(string const & f, bool asParagraph)
1088 LyXParagraph *tmppar;
1091 if (!current_view->getScreen()) return;
1093 if (fname.empty()) {
1095 fname = fileDlg.Select(_("File to Insert"),
1096 current_view->getOwner()->currentBuffer()->filepath,
1099 if (fname.empty()) return;
1103 FilePtr myfile(fname, FilePtr::read);
1105 if (!fi.exist() || !fi.readable() || !myfile()) {
1106 WriteFSAlert(_("Error! Cannot open specified file:"),
1107 MakeDisplayPath(fname,50));
1111 tmppar = new LyXParagraph();
1112 tmppar->readSimpleWholeFile(myfile);
1114 // set the end of the string
1116 // I don't think this is needed. Actually it might be plain wrong.
1117 tmppar->InsertChar(tmppar->text.size() - 1,'\0');
1119 tmppar->InsertChar(tmppar->last-1,'\0');
1121 // insert the string
1122 current_view->getScreen()->HideCursor();
1124 // clear the selection
1127 current_view->currentBuffer()->text->InsertStringA(tmppar->text);
1129 current_view->currentBuffer()->text->InsertStringB(tmppar->text);
1131 current_view->currentBuffer()->update(1);
1135 void MenuShowTableOfContents()
1137 static int ow = -1, oh;
1140 if (fd_form_toc->form_toc->visible) {
1141 fl_raise_form(fd_form_toc->form_toc);
1143 fl_show_form(fd_form_toc->form_toc,
1144 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1145 _("Table Of Contents"));
1147 ow = fd_form_toc->form_toc->w;
1148 oh = fd_form_toc->form_toc->h;
1150 fl_set_form_minsize(fd_form_toc->form_toc,ow,oh);
1155 void MenuInsertLabel(const char *arg)
1159 //string label = fl_show_input(_("Enter new label to insert:"),"");
1161 label = frontStrip(strip(askForText(_("Enter new label to insert:"))));
1162 if (!label.empty()) {
1163 InsetLabel *new_inset = new InsetLabel;
1164 new_inset->setContents(label);
1165 current_view->currentBuffer()->insertInset(new_inset);
1171 void MenuInsertRef()
1173 static int ow = -1, oh;
1176 if (fd_form_ref->form_ref->visible) {
1177 fl_raise_form(fd_form_ref->form_ref);
1179 fl_show_form(fd_form_ref->form_ref,
1180 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1181 _("Insert Reference"));
1183 ow = fd_form_ref->form_ref->w;
1184 oh = fd_form_ref->form_ref->h;
1186 fl_set_form_minsize(fd_form_ref->form_ref,ow,oh);
1191 void MenuPasteSelection(char at)
1193 if (!current_view->getScreen())
1198 Atom data_prop = XInternAtom(fl_display,
1201 if (data_prop == None)
1203 XConvertSelection(fl_display,
1204 XA_PRIMARY, XA_STRING, data_prop,
1205 fd_form_main->form_main->window, 0);
1210 extern "C" void FootCB(FL_OBJECT*, long)
1212 if (!current_view->available())
1215 minibuffer->Set(_("Inserting Footnote..."));
1216 current_view->getScreen()->HideCursor();
1217 current_view->currentBuffer()->update(-2);
1218 current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1219 current_view->currentBuffer()->update(1);
1223 void LayoutsCB(int sel, void *)
1225 string tmp = tostr(sel);
1226 current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1232 * SGML Linuxdoc support:
1233 * (flag == -1) import SGML file
1234 * (flag == 0) make TeX output
1235 * (flag == 1) make dvi output
1237 int RunLinuxDoc(int flag, string const & filename)
1246 /* generate a path-less extension name */
1247 name = ChangeExtension (filename, ".sgml", true);
1248 path = OnlyPath (filename);
1249 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1250 path = current_view->currentBuffer()->tmppath;
1255 if (!current_view->available())
1257 current_view->currentBuffer()->makeLinuxDocFile(name,0);
1258 LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
1260 case PAPER_A4PAPER: add_flags = "-p a4"; break;
1261 case PAPER_USLETTER: add_flags = "-p letter"; break;
1262 default: /* nothing to be done yet ;-) */ break;
1270 case -1: /* Import file */
1271 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1272 MakeDisplayPath(filename), "'...");
1273 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1275 if (one.startscript(Systemcalls::System, s2))
1278 case 0: /* TeX output asked */
1279 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1280 s2 = "sgml2latex " + add_flags + " -o tex "
1281 + lyxrc->sgml_extra_options + ' ' + name;
1282 if (one.startscript(Systemcalls::System, s2))
1285 case 1: /* dvi output asked */
1286 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1287 s2 = "sgml2latex " + add_flags + " -o dvi "
1288 + lyxrc->sgml_extra_options + ' ' + name;
1289 if (one.startscript(Systemcalls::System, s2)) {
1292 current_view->currentBuffer()->markDviClean();
1294 default: /* unknown output */
1300 current_view->currentBuffer()->redraw();
1306 * SGML DocBook support:
1307 * (flag == 1) make dvi output
1309 int RunDocBook(int flag, string const & filename)
1317 /* generate a path-less extension name */
1318 name = ChangeExtension (filename, ".sgml", true);
1319 path = OnlyPath (filename);
1320 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1321 path = current_view->currentBuffer()->tmppath;
1325 if (!current_view->available())
1328 current_view->currentBuffer()->makeDocBookFile(name,0);
1330 // Shall this code go or should it stay? (Lgb)
1331 // string add_flags;
1332 // LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
1334 // case PAPER_A4PAPER: add_flags = "-p a4"; break;
1335 // case PAPER_USLETTER: add_flags = "-p letter"; break;
1336 // default: /* nothing to be done yet ;-) */ break;
1342 case 1: /* dvi output asked */
1343 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1344 s2 = "sgmltools --backend dvi " + name;
1345 if (one.startscript(Systemcalls::System, s2)) {
1348 current_view->currentBuffer()->markDviClean();
1350 default: /* unknown output */
1356 current_view->currentBuffer()->redraw();
1361 void AllFloats(char flag, char figmar)
1363 if (!current_view->available())
1366 LyXCursor cursor = current_view->currentBuffer()->text->cursor;
1368 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1370 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1371 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1373 && cursor.par->footnotekind != LyXParagraph::FIG
1374 && cursor.par->footnotekind != LyXParagraph::TAB
1375 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1376 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1377 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1382 LyXCursor tmpcursor = cursor;
1383 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1384 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1386 LyXParagraph *par = current_view->currentBuffer()->paragraph;
1389 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1393 par->footnotekind != LyXParagraph::FOOTNOTE
1395 par->footnotekind != LyXParagraph::MARGIN
1400 par->footnotekind != LyXParagraph::FIG
1402 par->footnotekind != LyXParagraph::TAB
1404 par->footnotekind != LyXParagraph::WIDE_FIG
1406 par->footnotekind != LyXParagraph::WIDE_TAB
1408 par->footnotekind != LyXParagraph::ALGORITHM
1413 && par->previous->footnoteflag !=
1414 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1415 current_view->currentBuffer()->text->SetCursorIntern(par->previous,
1417 current_view->currentBuffer()->text->OpenFootnote();
1422 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1426 par->footnotekind != LyXParagraph::FOOTNOTE
1428 par->footnotekind != LyXParagraph::MARGIN
1433 par->footnotekind != LyXParagraph::FIG
1435 par->footnotekind != LyXParagraph::TAB
1437 par->footnotekind != LyXParagraph::WIDE_FIG
1439 par->footnotekind != LyXParagraph::WIDE_TAB
1441 par->footnotekind != LyXParagraph::ALGORITHM
1445 current_view->currentBuffer()->text->SetCursorIntern(par, 0);
1446 current_view->currentBuffer()->text->CloseFootnote();
1452 current_view->currentBuffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1453 current_view->redraw();
1454 current_view->fitCursor();
1455 current_view->updateScrollbar();
1459 void MenuLayoutCharacter()
1461 static int ow = -1, oh;
1463 if (fd_form_character->form_character->visible) {
1464 fl_raise_form(fd_form_character->form_character);
1466 fl_show_form(fd_form_character->form_character,
1467 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
1468 _("Character Style"));
1470 ow = fd_form_character->form_character->w;
1471 oh = fd_form_character->form_character->h;
1473 fl_set_form_minsize(fd_form_character->form_character,ow,oh);
1478 inline void DeactivateParagraphButtons ()
1480 fl_deactivate_object (fd_form_paragraph->button_ok);
1481 fl_deactivate_object (fd_form_paragraph->button_apply);
1482 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1483 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1486 inline void ActivateParagraphButtons ()
1488 fl_activate_object (fd_form_paragraph->button_ok);
1489 fl_activate_object (fd_form_paragraph->button_apply);
1490 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1491 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1494 inline void DisableParagraphLayout ()
1496 DeactivateParagraphButtons();
1497 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1498 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1499 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1500 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1501 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1502 fl_deactivate_object (fd_form_paragraph->check_noindent);
1503 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1504 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1505 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1506 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1507 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1508 fl_deactivate_object (fd_form_paragraph->input_space_above);
1509 fl_deactivate_object (fd_form_paragraph->input_space_below);
1510 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1511 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1512 fl_deactivate_object (fd_form_paragraph->check_space_above);
1513 fl_deactivate_object (fd_form_paragraph->check_space_below);
1516 inline void EnableParagraphLayout ()
1518 ActivateParagraphButtons();
1519 fl_activate_object (fd_form_paragraph->input_labelwidth);
1520 fl_activate_object (fd_form_paragraph->check_lines_top);
1521 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1522 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1523 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1524 fl_activate_object (fd_form_paragraph->check_noindent);
1525 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1526 fl_activate_object (fd_form_paragraph->radio_align_right);
1527 fl_activate_object (fd_form_paragraph->radio_align_left);
1528 fl_activate_object (fd_form_paragraph->radio_align_block);
1529 fl_activate_object (fd_form_paragraph->radio_align_center);
1530 fl_activate_object (fd_form_paragraph->input_space_above);
1531 fl_activate_object (fd_form_paragraph->input_space_below);
1532 fl_activate_object (fd_form_paragraph->choice_space_above);
1533 fl_activate_object (fd_form_paragraph->choice_space_below);
1534 fl_activate_object (fd_form_paragraph->check_space_above);
1535 fl_activate_object (fd_form_paragraph->check_space_below);
1538 bool UpdateLayoutParagraph()
1540 if (!current_view->getScreen() || !current_view->available()) {
1541 if (fd_form_paragraph->form_paragraph->visible)
1542 fl_hide_form(fd_form_paragraph->form_paragraph);
1546 Buffer * buf = current_view->currentBuffer();
1548 fl_set_input(fd_form_paragraph->input_labelwidth,
1549 buf->text->cursor.par->GetLabelWidthString().c_str());
1550 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1551 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1552 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1553 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1555 int align = buf->text->cursor.par->GetAlign();
1556 if (align == LYX_ALIGN_LAYOUT)
1557 align = textclasslist.Style(buf->params.textclass,
1558 buf->text->cursor.par->GetLayout()).align;
1561 case LYX_ALIGN_RIGHT:
1562 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1564 case LYX_ALIGN_LEFT:
1565 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1567 case LYX_ALIGN_CENTER:
1568 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1571 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1575 fl_set_button(fd_form_paragraph->check_lines_top,
1576 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1577 fl_set_button(fd_form_paragraph->check_lines_bottom,
1578 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1579 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1580 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1581 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1582 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1583 fl_set_button(fd_form_paragraph->check_noindent,
1584 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1585 fl_set_input (fd_form_paragraph->input_space_above, "");
1587 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1589 fl_set_choice (fd_form_paragraph->choice_space_above,
1592 case VSpace::DEFSKIP:
1593 fl_set_choice (fd_form_paragraph->choice_space_above,
1596 case VSpace::SMALLSKIP:
1597 fl_set_choice (fd_form_paragraph->choice_space_above,
1600 case VSpace::MEDSKIP:
1601 fl_set_choice (fd_form_paragraph->choice_space_above,
1604 case VSpace::BIGSKIP:
1605 fl_set_choice (fd_form_paragraph->choice_space_above,
1609 fl_set_choice (fd_form_paragraph->choice_space_above,
1612 case VSpace::LENGTH:
1613 fl_set_choice (fd_form_paragraph->choice_space_above,
1615 fl_set_input (fd_form_paragraph->input_space_above,
1616 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1619 fl_set_button (fd_form_paragraph->check_space_above,
1620 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1621 fl_set_input (fd_form_paragraph->input_space_below, "");
1622 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1624 fl_set_choice (fd_form_paragraph->choice_space_below,
1627 case VSpace::DEFSKIP:
1628 fl_set_choice (fd_form_paragraph->choice_space_below,
1631 case VSpace::SMALLSKIP:
1632 fl_set_choice (fd_form_paragraph->choice_space_below,
1635 case VSpace::MEDSKIP:
1636 fl_set_choice (fd_form_paragraph->choice_space_below,
1639 case VSpace::BIGSKIP:
1640 fl_set_choice (fd_form_paragraph->choice_space_below,
1644 fl_set_choice (fd_form_paragraph->choice_space_below,
1647 case VSpace::LENGTH:
1648 fl_set_choice (fd_form_paragraph->choice_space_below,
1650 fl_set_input (fd_form_paragraph->input_space_below,
1651 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1654 fl_set_button (fd_form_paragraph->check_space_below,
1655 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1657 fl_set_button(fd_form_paragraph->check_noindent,
1658 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1660 if (current_view->currentBuffer()->isReadonly()) {
1661 DisableParagraphLayout();
1663 EnableParagraphLayout();
1668 void MenuLayoutParagraph()
1670 if (UpdateLayoutParagraph()) {
1671 if (fd_form_paragraph->form_paragraph->visible) {
1672 fl_raise_form(fd_form_paragraph->form_paragraph);
1674 fl_show_form(fd_form_paragraph->form_paragraph,
1675 FL_PLACE_MOUSE, FL_FULLBORDER,
1676 _("Paragraph Environment"));
1683 void DeactivateDocumentButtons ()
1685 fl_deactivate_object (fd_form_document->button_ok);
1686 fl_deactivate_object (fd_form_document->button_apply);
1687 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1688 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1693 void ActivateDocumentButtons ()
1695 fl_activate_object (fd_form_document->button_ok);
1696 fl_activate_object (fd_form_document->button_apply);
1697 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1698 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1702 void DisableDocumentLayout ()
1704 DeactivateDocumentButtons ();
1705 fl_deactivate_object (fd_form_document->group_radio_separation);
1706 fl_deactivate_object (fd_form_document->radio_indent);
1707 fl_deactivate_object (fd_form_document->radio_skip);
1708 fl_deactivate_object (fd_form_document->choice_class);
1709 fl_deactivate_object (fd_form_document->choice_pagestyle);
1710 fl_deactivate_object (fd_form_document->choice_fonts);
1711 fl_deactivate_object (fd_form_document->choice_fontsize);
1712 fl_deactivate_object (fd_form_document->input_float_placement);
1713 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1714 fl_deactivate_object (fd_form_document->choice_inputenc);
1715 fl_deactivate_object (fd_form_document->group_radio_sides);
1716 fl_deactivate_object (fd_form_document->radio_sides_one);
1717 fl_deactivate_object (fd_form_document->radio_sides_two);
1718 fl_deactivate_object (fd_form_document->group_radio_columns);
1719 fl_deactivate_object (fd_form_document->radio_columns_one);
1720 fl_deactivate_object (fd_form_document->radio_columns_two);
1721 fl_deactivate_object (fd_form_document->input_extra);
1722 fl_deactivate_object (fd_form_document->choice_language);
1723 combo_language->deactivate();
1724 fl_deactivate_object (fd_form_document->input_default_skip);
1725 fl_deactivate_object (fd_form_document->choice_default_skip);
1726 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1727 fl_deactivate_object (fd_form_document->slider_tocdepth);
1728 fl_deactivate_object (fd_form_document->choice_spacing);
1729 fl_deactivate_object (fd_form_document->input_spacing);
1730 fl_deactivate_object (fd_form_document->check_use_amsmath);
1734 void EnableDocumentLayout ()
1736 ActivateDocumentButtons ();
1737 fl_activate_object (fd_form_document->group_radio_separation);
1738 fl_activate_object (fd_form_document->radio_indent);
1739 fl_activate_object (fd_form_document->radio_skip);
1740 fl_activate_object (fd_form_document->choice_class);
1741 fl_activate_object (fd_form_document->choice_pagestyle);
1742 fl_activate_object (fd_form_document->choice_fonts);
1743 fl_activate_object (fd_form_document->choice_fontsize);
1744 fl_activate_object (fd_form_document->input_float_placement);
1745 fl_activate_object (fd_form_document->choice_postscript_driver);
1746 fl_activate_object (fd_form_document->choice_inputenc);
1747 fl_activate_object (fd_form_document->group_radio_sides);
1748 fl_activate_object (fd_form_document->radio_sides_one);
1749 fl_activate_object (fd_form_document->radio_sides_two);
1750 fl_activate_object (fd_form_document->group_radio_columns);
1751 fl_activate_object (fd_form_document->radio_columns_one);
1752 fl_activate_object (fd_form_document->radio_columns_two);
1753 fl_activate_object (fd_form_document->input_extra);
1754 fl_activate_object (fd_form_document->choice_language);
1755 combo_language->activate();
1756 fl_activate_object (fd_form_document->input_default_skip);
1757 fl_activate_object (fd_form_document->choice_default_skip);
1758 fl_activate_object (fd_form_document->slider_secnumdepth);
1759 fl_activate_object (fd_form_document->slider_tocdepth);
1760 fl_activate_object (fd_form_document->choice_spacing);
1761 fl_activate_object (fd_form_document->input_spacing);
1762 fl_activate_object (fd_form_document->check_use_amsmath);
1765 bool UpdateLayoutDocument(BufferParams *params)
1767 if (!current_view->getScreen() || !current_view->available()) {
1768 if (fd_form_document->form_document->visible)
1769 fl_hide_form(fd_form_document->form_document);
1774 params = ¤t_view->currentBuffer()->params;
1775 LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1777 fl_set_choice_text(fd_form_document->choice_class,
1778 textclasslist.DescOfClass(params->textclass).c_str());
1779 combo_language->select_text(params->language.c_str());
1781 fl_set_choice_text(fd_form_document->choice_fonts,
1782 params->fonts.c_str());
1783 fl_set_choice_text(fd_form_document->choice_inputenc,
1784 params->inputenc.c_str());
1785 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1786 params->graphicsDriver.c_str());
1788 // ale970405+lasgoutt970513
1789 fl_clear_choice(fd_form_document->choice_fontsize);
1790 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1791 fl_addto_choice(fd_form_document->choice_fontsize,
1792 tclass.opt_fontsize().c_str());
1793 fl_set_choice(fd_form_document->choice_fontsize,
1794 tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1796 // ale970405+lasgoutt970513
1797 fl_clear_choice(fd_form_document->choice_pagestyle);
1798 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1799 fl_addto_choice(fd_form_document->choice_pagestyle,
1800 tclass.opt_pagestyle().c_str());
1802 fl_set_choice(fd_form_document->choice_pagestyle,
1803 tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1805 fl_set_button(fd_form_document->radio_indent, 0);
1806 fl_set_button(fd_form_document->radio_skip, 0);
1809 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1811 if (params->paragraph_separation == LYX_PARSEP_INDENT)
1812 fl_set_button(fd_form_document->radio_indent, 1);
1814 fl_set_button(fd_form_document->radio_skip, 1);
1816 switch (params->getDefSkip().kind()) {
1817 case VSpace::SMALLSKIP:
1818 fl_set_choice (fd_form_document->choice_default_skip, 1);
1820 case VSpace::MEDSKIP:
1821 fl_set_choice (fd_form_document->choice_default_skip, 2);
1823 case VSpace::BIGSKIP:
1824 fl_set_choice (fd_form_document->choice_default_skip, 3);
1826 case VSpace::LENGTH:
1827 fl_set_choice (fd_form_document->choice_default_skip, 4);
1828 fl_set_input (fd_form_document->input_default_skip,
1829 params->getDefSkip().asLyXCommand().c_str());
1832 fl_set_choice (fd_form_document->choice_default_skip, 2);
1836 fl_set_button(fd_form_document->radio_sides_one, 0);
1837 fl_set_button(fd_form_document->radio_sides_two, 0);
1839 if (params->sides == 2)
1840 fl_set_button(fd_form_document->radio_sides_two, 1);
1842 fl_set_button(fd_form_document->radio_sides_one, 1);
1844 fl_set_button(fd_form_document->radio_columns_one, 0);
1845 fl_set_button(fd_form_document->radio_columns_two, 0);
1847 if (params->columns == 2)
1848 fl_set_button(fd_form_document->radio_columns_two, 1);
1850 fl_set_button(fd_form_document->radio_columns_one, 1);
1852 fl_set_input(fd_form_document->input_spacing, "");
1853 switch (params->spacing.getSpace()) {
1854 case Spacing::Single:
1857 fl_set_choice(fd_form_document->choice_spacing, 1);
1860 case Spacing::Onehalf:
1863 fl_set_choice(fd_form_document->choice_spacing, 2);
1866 case Spacing::Double:
1869 fl_set_choice(fd_form_document->choice_spacing, 3);
1872 case Spacing::Other:
1874 fl_set_choice(fd_form_document->choice_spacing, 4);
1876 sprintf(sval,"%g",params->spacing.getValue());
1877 fl_set_input(fd_form_document->input_spacing, sval);
1883 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1884 params->secnumdepth);
1885 fl_set_counter_value(fd_form_document->slider_tocdepth,
1887 if (!params->float_placement.empty()) { // buffer local (Lgb)
1888 fl_set_input(fd_form_document->input_float_placement,
1889 params->float_placement.c_str());
1891 fl_set_input(fd_form_document->input_float_placement, "");
1893 if (!params->options.empty())
1894 fl_set_input(fd_form_document->input_extra,
1895 params->options.c_str());
1897 fl_set_input(fd_form_document->input_extra, "");
1899 if (current_view->currentBuffer()->isSGML()) {
1900 // bullets not used in SGML derived documents
1901 fl_deactivate_object(fd_form_document->button_bullets);
1902 fl_set_object_lcol(fd_form_document->button_bullets,
1905 fl_activate_object(fd_form_document->button_bullets);
1906 fl_set_object_lcol(fd_form_document->button_bullets,
1910 if (current_view->currentBuffer()->isReadonly()) {
1911 DisableDocumentLayout();
1913 EnableDocumentLayout();
1919 void MenuLayoutDocument()
1921 if (UpdateLayoutDocument()) {
1922 if (fd_form_document->form_document->visible) {
1923 fl_raise_form(fd_form_document->form_document);
1925 fl_show_form(fd_form_document->form_document,
1926 FL_PLACE_MOUSE, FL_FULLBORDER,
1927 _("Document Layout"));
1933 bool UpdateLayoutQuotes()
1936 if (!current_view->getScreen()
1937 || !current_view->available()
1938 || current_view->currentBuffer()->isReadonly())
1942 fl_set_choice(fd_form_quotes->choice_quotes_language,
1943 current_view->currentBuffer()->params.quotes_language + 1);
1944 fl_set_button(fd_form_quotes->radio_single, 0);
1945 fl_set_button(fd_form_quotes->radio_double, 0);
1947 if (current_view->currentBuffer()->params.quotes_times == InsetQuotes::SingleQ)
1948 fl_set_button(fd_form_quotes->radio_single, 1);
1950 fl_set_button(fd_form_quotes->radio_double, 1);
1951 } else if (fd_form_quotes->form_quotes->visible) {
1952 fl_hide_form(fd_form_quotes->form_quotes);
1957 void MenuLayoutQuotes()
1959 if (UpdateLayoutQuotes()) {
1960 if (fd_form_quotes->form_quotes->visible) {
1961 fl_raise_form(fd_form_quotes->form_quotes);
1963 fl_show_form(fd_form_quotes->form_quotes,
1964 FL_PLACE_MOUSE, FL_FULLBORDER,
1971 bool UpdateLayoutPreamble()
1974 if (!current_view->getScreen() || ! current_view->available())
1978 fl_set_input(fd_form_preamble->input_preamble,
1979 current_view->currentBuffer()->params.preamble.c_str());
1981 if (current_view->currentBuffer()->isReadonly()) {
1982 fl_deactivate_object(fd_form_preamble->input_preamble);
1983 fl_deactivate_object(fd_form_preamble->button_ok);
1984 fl_deactivate_object(fd_form_preamble->button_apply);
1985 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1986 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1989 fl_activate_object(fd_form_preamble->input_preamble);
1990 fl_activate_object(fd_form_preamble->button_ok);
1991 fl_activate_object(fd_form_preamble->button_apply);
1992 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1993 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1995 } else if (fd_form_preamble->form_preamble->visible) {
1996 fl_hide_form(fd_form_preamble->form_preamble);
2001 void MenuLayoutPreamble()
2003 static int ow = -1, oh;
2005 if (UpdateLayoutPreamble()) {
2006 if (fd_form_preamble->form_preamble->visible) {
2007 fl_raise_form(fd_form_preamble->form_preamble);
2009 fl_show_form(fd_form_preamble->form_preamble,
2010 FL_PLACE_MOUSE | FL_FREE_SIZE,
2012 _("LaTeX Preamble"));
2014 ow = fd_form_preamble->form_preamble->w;
2015 oh = fd_form_preamble->form_preamble->h;
2017 fl_set_form_minsize(fd_form_preamble->form_preamble,
2023 void MenuLayoutSave()
2025 if (!current_view->getScreen() || ! current_view->available())
2028 if (AskQuestion(_("Do you want to save the current settings"),
2029 _("for Character, Document, Paper and Quotes"),
2030 _("as default for new documents?")))
2031 current_view->currentBuffer()->saveParamsAsDefaults();
2037 InsetInfo *new_inset = new InsetInfo();
2038 current_view->currentBuffer()->insertInset(new_inset);
2039 new_inset->Edit(0,0);
2040 //current_view->currentBuffer()->update(-1);
2046 if (current_view->available()) {
2047 minibuffer->Set(_("Open/Close..."));
2048 current_view->getScreen()->HideCursor();
2050 current_view->currentBuffer()->update(-2);
2051 current_view->currentBuffer()->text->OpenStuff();
2052 current_view->currentBuffer()->update(0);
2058 if (current_view->available()) {
2059 minibuffer->Set(_("Open/Close..."));
2060 current_view->getScreen()->HideCursor();
2062 current_view->currentBuffer()->update(-2);
2063 current_view->currentBuffer()->text->ToggleFootnote();
2064 current_view->currentBuffer()->update(0);
2071 /* if (current_view->currentBuffer()->the_locking_inset) {
2072 minibuffer->Set(_("Undo not yet supported in math mode"));
2076 if (current_view->available()) {
2077 minibuffer->Set(_("Undo"));
2078 current_view->getScreen()->HideCursor();
2080 current_view->currentBuffer()->update(-2);
2081 if (!current_view->currentBuffer()->text->TextUndo())
2082 minibuffer->Set(_("No further undo information"));
2084 current_view->currentBuffer()->update(-1);
2091 if (current_view->currentBuffer()->the_locking_inset) {
2092 minibuffer->Set(_("Redo not yet supported in math mode"));
2096 if (current_view->available()) {
2097 minibuffer->Set(_("Redo"));
2098 current_view->getScreen()->HideCursor();
2100 current_view->currentBuffer()->update(-2);
2101 if (!current_view->currentBuffer()->text->TextRedo())
2102 minibuffer->Set(_("No further redo information"));
2104 current_view->currentBuffer()->update(-1);
2109 void HyphenationPoint()
2111 if (current_view->available()) {
2112 current_view->getScreen()->HideCursor();
2113 current_view->currentBuffer()->update(-2);
2114 InsetSpecialChar *new_inset =
2115 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2116 current_view->currentBuffer()->insertInset(new_inset);
2117 //current_view->currentBuffer()->update(-1);
2124 if (current_view->available()) {
2125 current_view->getScreen()->HideCursor();
2126 current_view->currentBuffer()->update(-2);
2127 InsetSpecialChar *new_inset =
2128 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2129 current_view->currentBuffer()->insertInset(new_inset);
2134 void EndOfSentenceDot()
2136 if (current_view->available()) {
2137 current_view->getScreen()->HideCursor();
2138 current_view->currentBuffer()->update(-2);
2139 InsetSpecialChar *new_inset =
2140 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2141 current_view->currentBuffer()->insertInset(new_inset);
2146 void MenuSeparator()
2148 if (current_view->available()) {
2149 current_view->getScreen()->HideCursor();
2150 current_view->currentBuffer()->update(-2);
2151 InsetSpecialChar *new_inset =
2152 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2153 current_view->currentBuffer()->insertInset(new_inset);
2154 //current_view->currentBuffer()->update(-1);
2161 if (current_view->available()) {
2162 current_view->getScreen()->HideCursor();
2163 current_view->currentBuffer()->update(-2);
2164 current_view->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
2165 current_view->currentBuffer()->update(-1);
2170 void ProtectedBlank()
2172 if (current_view->available()) {
2173 current_view->getScreen()->HideCursor();
2174 current_view->currentBuffer()->update(-2);
2175 current_view->currentBuffer()->text->InsertChar(LYX_META_PROTECTED_SEPARATOR);
2176 current_view->currentBuffer()->update(-1);
2183 if (current_view->available()) {
2184 current_view->getScreen()->HideCursor();
2185 current_view->currentBuffer()->update(-2);
2186 current_view->currentBuffer()->text->InsertChar(LYX_META_HFILL);
2187 current_view->currentBuffer()->update(-1);
2192 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2193 They also show the current font state. */
2196 void ToggleAndShow(LyXFont const &);
2199 void FontSizeCB(string const & size)
2201 LyXFont font(LyXFont::ALL_IGNORE);
2202 font.setGUISize(size);
2203 ToggleAndShow(font);
2209 LyXFont font(LyXFont::ALL_IGNORE);
2210 font.setEmph(LyXFont::TOGGLE);
2211 ToggleAndShow(font);
2217 LyXFont font(LyXFont::ALL_IGNORE);
2218 font.setNoun(LyXFont::TOGGLE);
2219 ToggleAndShow(font);
2225 LyXFont font(LyXFont::ALL_IGNORE);
2226 font.setSeries(LyXFont::BOLD_SERIES);
2227 ToggleAndShow(font);
2233 LyXFont font(LyXFont::ALL_IGNORE);
2234 font.setUnderbar(LyXFont::TOGGLE);
2235 ToggleAndShow(font);
2241 LyXFont font(LyXFont::ALL_IGNORE);
2242 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2243 ToggleAndShow(font);
2249 LyXFont font(LyXFont::ALL_IGNORE);
2250 font.setFamily(LyXFont::SANS_FAMILY);
2251 ToggleAndShow(font);
2257 LyXFont font(LyXFont::ALL_IGNORE);
2258 font.setFamily(LyXFont::ROMAN_FAMILY);
2259 ToggleAndShow(font);
2265 LyXFont font(LyXFont::ALL_IGNORE);
2266 font.setLatex (LyXFont::TOGGLE);
2267 ToggleAndShow(font);
2273 LyXFont font(LyXFont::ALL_INHERIT);
2274 ToggleAndShow(font);
2278 /* -------> Returns the current font and depth by printing a message. In the
2279 * future perhaps we could try to implement a callback to the button-bar.
2280 * That is, `light' the bold button when the font is currently bold, etc.
2282 string CurrentState()
2285 if (current_view->available()) {
2286 // I think we should only show changes from the default
2288 Buffer * buffer = current_view->currentBuffer();
2289 LyXFont font = buffer->text->real_current_font;
2290 LyXFont defaultfont = textclasslist.TextClass(buffer->
2291 params.textclass).defaultfont();
2292 font.reduce(defaultfont);
2293 state = _("Font: ") + font.stateText();
2295 int depth = buffer->text->GetDepth();
2297 state += string(_(", Depth: ")) + tostr(depth);
2303 /* -------> Does the actual toggle job of the XxxCB() calls above.
2304 * Also shows the current font state.
2307 void ToggleAndShow(LyXFont const & font)
2309 if (current_view->available()) {
2310 current_view->getScreen()->HideCursor();
2311 current_view->currentBuffer()->update(-2);
2312 current_view->currentBuffer()->text->ToggleFree(font, toggleall);
2313 current_view->currentBuffer()->update(1);
2315 // removed since it overrides the ToggleFree Message about the style
2316 // Since Styles are more "High Level" than raw fonts I think the user
2317 // prefers it like this Matthias
2318 // FontStateShowCB( 0, 0 );
2322 extern "C" void MarginCB(FL_OBJECT *, long)
2324 if (current_view->available()) {
2325 minibuffer->Set(_("Inserting margin note..."));
2326 current_view->getScreen()->HideCursor();
2327 current_view->currentBuffer()->update(-2);
2328 current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2329 current_view->currentBuffer()->update(1);
2334 extern "C" void FigureCB(FL_OBJECT *, long)
2336 if (fd_form_figure->form_figure->visible) {
2337 fl_raise_form(fd_form_figure->form_figure);
2339 fl_show_form(fd_form_figure->form_figure,
2340 FL_PLACE_MOUSE, FL_FULLBORDER,
2341 _("Insert Figure"));
2346 extern "C" void TableCB(FL_OBJECT *, long)
2348 if (fd_form_table->form_table->visible) {
2349 fl_raise_form(fd_form_table->form_table);
2351 fl_show_form(fd_form_table->form_table,
2352 FL_PLACE_MOUSE, FL_FULLBORDER,
2358 void CopyEnvironmentCB()
2360 if (current_view->available()) {
2361 current_view->currentBuffer()->text->copyEnvironmentType();
2362 /* clear the selection, even if mark_set */
2363 current_view->getScreen()->ToggleSelection();
2364 current_view->currentBuffer()->text->ClearSelection();
2365 current_view->currentBuffer()->update(-2);
2366 minibuffer->Set(_("Paragraph environment type copied"));
2371 void PasteEnvironmentCB()
2373 if (current_view->available()) {
2374 current_view->currentBuffer()->text->pasteEnvironmentType();
2375 minibuffer->Set(_("Paragraph environment type set"));
2376 current_view->currentBuffer()->update(1);
2383 if (current_view->available()) {
2384 current_view->currentBuffer()->text->CopySelection();
2385 /* clear the selection, even if mark_set */
2386 current_view->getScreen()->ToggleSelection();
2387 current_view->currentBuffer()->text->ClearSelection();
2388 current_view->currentBuffer()->update(-2);
2389 minibuffer->Set(_("Copy"));
2396 if (current_view->available()) {
2397 current_view->getScreen()->HideCursor();
2398 current_view->currentBuffer()->update(-2);
2399 current_view->currentBuffer()->text->CutSelection();
2400 current_view->currentBuffer()->update(1);
2401 minibuffer->Set(_("Cut"));
2408 if (!current_view->available()) return;
2410 minibuffer->Set(_("Paste"));
2411 current_view->getScreen()->HideCursor();
2412 /* clear the selection */
2413 current_view->getScreen()->ToggleSelection();
2414 current_view->currentBuffer()->text->ClearSelection();
2415 current_view->currentBuffer()->update(-2);
2418 current_view->currentBuffer()->text->PasteSelection();
2419 current_view->currentBuffer()->update(1);
2421 /* clear the selection */
2422 current_view->getScreen()->ToggleSelection();
2423 current_view->currentBuffer()->text->ClearSelection();
2424 current_view->currentBuffer()->update(-2);
2428 extern "C" void MeltCB(FL_OBJECT *, long)
2430 if (!current_view->available()) return;
2432 minibuffer->Set(_("Melt"));
2433 current_view->getScreen()->HideCursor();
2435 current_view->currentBuffer()->update(-2);
2436 current_view->currentBuffer()->text->MeltFootnoteEnvironment();
2437 current_view->currentBuffer()->update(1);
2441 // Change environment depth.
2442 // if decInc == 0, depth change taking mouse button number into account
2443 // if decInc == 1, increment depth
2444 // if decInc == -1, decrement depth
2445 extern "C" void DepthCB(FL_OBJECT *ob, long decInc)
2449 /* When decInc != 0, fake a mouse button. This allows us to
2450 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2451 /* check out wether ob is defined, too (Matthias) */
2454 else if (!decInc && ob) {
2455 button = fl_get_button_numb(ob);
2458 if (current_view->available()) {
2459 current_view->getScreen()->HideCursor();
2460 current_view->currentBuffer()->update(-2);
2462 current_view->currentBuffer()->text->IncDepth();
2464 current_view->currentBuffer()->text->DecDepth();
2465 current_view->currentBuffer()->update(1);
2466 minibuffer->Set(_("Changed environment depth"
2467 " (in possible range, maybe not)"));
2472 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2473 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2474 LyXFont UserFreeFont()
2476 LyXFont font(LyXFont::ALL_IGNORE);
2479 pos = fl_get_choice(fd_form_character->choice_family);
2481 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2482 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2483 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2484 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2485 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2488 pos = fl_get_choice(fd_form_character->choice_series);
2490 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2491 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2492 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2493 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2496 pos = fl_get_choice(fd_form_character->choice_shape);
2498 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2499 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2500 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2501 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2502 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2503 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2506 pos = fl_get_choice(fd_form_character->choice_size);
2508 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2509 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2510 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2511 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2512 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2513 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2514 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2515 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2516 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2517 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2518 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2519 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2520 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2521 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2524 pos = fl_get_choice(fd_form_character->choice_bar);
2526 case 1: font.setEmph(LyXFont::IGNORE);
2527 font.setUnderbar(LyXFont::IGNORE);
2528 font.setNoun(LyXFont::IGNORE);
2529 font.setLatex(LyXFont::IGNORE);
2531 case 2: font.setEmph(LyXFont::TOGGLE); break;
2532 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2533 case 4: font.setNoun(LyXFont::TOGGLE); break;
2534 case 5: font.setLatex(LyXFont::TOGGLE); break;
2535 case 6: font.setEmph(LyXFont::INHERIT);
2536 font.setUnderbar(LyXFont::INHERIT);
2537 font.setNoun(LyXFont::INHERIT);
2538 font.setLatex(LyXFont::INHERIT);
2542 pos = fl_get_choice(fd_form_character->choice_color);
2544 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2545 case 2: font.setColor(LyXFont::NONE); break;
2546 case 3: font.setColor(LyXFont::BLACK); break;
2547 case 4: font.setColor(LyXFont::WHITE); break;
2548 case 5: font.setColor(LyXFont::RED); break;
2549 case 6: font.setColor(LyXFont::GREEN); break;
2550 case 7: font.setColor(LyXFont::BLUE); break;
2551 case 8: font.setColor(LyXFont::CYAN); break;
2552 case 9: font.setColor(LyXFont::MAGENTA); break;
2553 case 10: font.setColor(LyXFont::YELLOW); break;
2554 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2563 ToggleAndShow(UserFreeFont());
2567 /* callbacks for form form_title */
2568 extern "C" void TimerCB(FL_OBJECT *, long)
2570 // only if the form still exists
2571 if (fd_form_title->form_title != 0) {
2572 if (fd_form_title->form_title->visible) {
2573 fl_hide_form(fd_form_title->form_title);
2575 fl_free_form(fd_form_title->form_title);
2576 fd_form_title->form_title = 0;
2581 /* callbacks for form form_paragraph */
2583 extern "C" void ParagraphVSpaceCB(FL_OBJECT* obj, long )
2585 // "Synchronize" the choices and input fields, making it
2586 // impossible to commit senseless data.
2588 const FD_form_paragraph* fp = fd_form_paragraph;
2590 if (obj == fp->choice_space_above) {
2591 if (fl_get_choice (fp->choice_space_above) != 7) {
2592 fl_set_input (fp->input_space_above, "");
2593 ActivateParagraphButtons();
2595 } else if (obj == fp->choice_space_below) {
2596 if (fl_get_choice (fp->choice_space_below) != 7) {
2597 fl_set_input (fp->input_space_below, "");
2598 ActivateParagraphButtons();
2600 } else if (obj == fp->input_space_above) {
2601 string input = fl_get_input (fp->input_space_above);
2603 if (input.empty()) {
2604 fl_set_choice (fp->choice_space_above, 1);
2605 ActivateParagraphButtons();
2607 else if (isValidGlueLength (input)) {
2608 fl_set_choice (fp->choice_space_above, 7);
2609 ActivateParagraphButtons();
2612 fl_set_choice (fp->choice_space_above, 7);
2613 DeactivateParagraphButtons();
2615 } else if (obj == fp->input_space_below) {
2616 string input = fl_get_input (fp->input_space_below);
2618 if (input.empty()) {
2619 fl_set_choice (fp->choice_space_below, 1);
2620 ActivateParagraphButtons();
2622 else if (isValidGlueLength (input)) {
2623 fl_set_choice (fp->choice_space_below, 7);
2624 ActivateParagraphButtons();
2627 fl_set_choice (fp->choice_space_below, 7);
2628 DeactivateParagraphButtons();
2634 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2636 if (!current_view->available())
2639 VSpace space_top, space_bottom;
2641 string labelwidthstring;
2644 // If a vspace kind is "Length" but there's no text in
2645 // the input field, reset the kind to "None".
2646 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2647 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2648 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2650 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2651 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2652 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2655 bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2656 bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2657 bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2658 bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2659 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2660 case 1: space_top = VSpace(VSpace::NONE); break;
2661 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2662 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2663 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2664 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2665 case 6: space_top = VSpace(VSpace::VFILL); break;
2666 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2668 if (fl_get_button (fd_form_paragraph->check_space_above))
2669 space_top.setKeep (true);
2670 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2671 case 1: space_bottom = VSpace(VSpace::NONE); break;
2672 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2673 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2674 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2675 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2676 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2677 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2679 if (fl_get_button (fd_form_paragraph->check_space_below))
2680 space_bottom.setKeep (true);
2682 if (fl_get_button(fd_form_paragraph->radio_align_left))
2683 align = LYX_ALIGN_LEFT;
2684 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2685 align = LYX_ALIGN_RIGHT;
2686 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2687 align = LYX_ALIGN_CENTER;
2689 align = LYX_ALIGN_BLOCK;
2691 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2692 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2694 current_view->currentBuffer()->text->SetParagraph(line_top,
2703 current_view->currentBuffer()->update(1);
2704 minibuffer->Set(_("Paragraph layout set"));
2708 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2710 fl_hide_form(fd_form_paragraph->form_paragraph);
2714 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2716 ParagraphApplyCB(ob, data);
2717 ParagraphCancelCB(ob, data);
2721 /* callbacks for form form_character */
2723 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2725 // we set toggleall locally here, since it should be true for
2726 // all other uses of ToggleAndShow() (JMarc)
2727 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2728 ToggleAndShow( UserFreeFont());
2733 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2735 fl_hide_form(fd_form_character->form_character);
2739 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2741 CharacterApplyCB(ob,data);
2742 CharacterCloseCB(ob,data);
2746 /* callbacks for form form_document */
2748 void UpdateDocumentButtons(BufferParams const ¶ms)
2750 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2752 if (params.sides == 2)
2753 fl_set_button(fd_form_document->radio_sides_two, 1);
2755 fl_set_button(fd_form_document->radio_sides_one, 1);
2757 if (params.columns == 2)
2758 fl_set_button(fd_form_document->radio_columns_two, 1);
2760 fl_set_button(fd_form_document->radio_columns_one, 1);
2762 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2763 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2764 params.secnumdepth);
2765 fl_set_counter_value(fd_form_document->slider_tocdepth,
2770 extern "C" void ChoiceClassCB(FL_OBJECT *ob, long)
2773 if (textclasslist.Load(fl_get_choice(ob)-1)) {
2774 if (AskQuestion(_("Should I set some parameters to"),
2775 fl_get_choice_text(ob),
2776 _("the defaults of this document class?"))) {
2777 BufferParams params = BufferParams();
2778 params.textclass = fl_get_choice(ob)-1;
2779 params.useClassDefaults();
2780 UpdateLayoutDocument(¶ms);
2781 UpdateDocumentButtons(params);
2784 // unable to load new style
2785 WriteAlert(_("Conversion Errors!"),
2786 _("Unable to switch to new document class."),
2787 _("Reverting to original document class."));
2788 fl_set_choice(fd_form_document->choice_class,
2789 GetCurrentTextClass() + 1);
2795 extern "C" void DocumentDefskipCB(FL_OBJECT *obj, long)
2797 // "Synchronize" the choice and the input field, so that it
2798 // is impossible to commit senseless data.
2799 const FD_form_document* fd = fd_form_document;
2801 if (obj == fd->choice_default_skip) {
2802 if (fl_get_choice (fd->choice_default_skip) != 4) {
2803 fl_set_input (fd->input_default_skip, "");
2804 ActivateDocumentButtons();
2806 } else if (obj == fd->input_default_skip) {
2808 const char* input = fl_get_input (fd->input_default_skip);
2811 fl_set_choice (fd->choice_default_skip, 2);
2812 ActivateDocumentButtons();
2813 } else if (isValidGlueLength (input)) {
2814 fl_set_choice (fd->choice_default_skip, 4);
2815 ActivateDocumentButtons();
2817 fl_set_choice (fd->choice_default_skip, 4);
2818 DeactivateDocumentButtons();
2824 extern "C" void DocumentSpacingCB(FL_OBJECT *obj, long)
2826 // "Synchronize" the choice and the input field, so that it
2827 // is impossible to commit senseless data.
2828 const FD_form_document* fd = fd_form_document;
2830 if (obj == fd->choice_spacing
2831 && fl_get_choice (fd->choice_spacing) != 4) {
2832 fl_set_input(fd->input_spacing, "");
2833 } else if (obj == fd->input_spacing) {
2835 const char* input = fl_get_input (fd->input_spacing);
2838 fl_set_choice (fd->choice_spacing, 1);
2840 fl_set_choice (fd->choice_spacing, 4);
2846 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2849 BufferParams *params = &(current_view->currentBuffer()->params);
2850 current_view->currentBuffer()->params.language =
2851 combo_language->getline();
2853 // If default skip is a "Length" but there's no text in the
2854 // input field, reset the kind to "Medskip", which is the default.
2855 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2856 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2857 fl_set_choice (fd_form_document->choice_default_skip, 2);
2860 /* this shouldn't be done automatically IMO. For example I write german
2861 * documents with an american keyboard very often. Matthias */
2863 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2864 fl_get_choice(fd_form_document->choice_language)); */
2866 fl_get_choice_text(fd_form_document->choice_fonts);
2868 fl_get_choice_text(fd_form_document->choice_inputenc);
2870 fl_get_choice_text(fd_form_document->choice_fontsize);
2872 fl_get_choice_text(fd_form_document->choice_pagestyle);
2873 params->graphicsDriver =
2874 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2875 params->use_amsmath =
2876 fl_get_button(fd_form_document->check_use_amsmath);
2878 if (!current_view->available())
2881 LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2882 if (params->textclass != new_class) {
2883 // try to load new_class
2884 if (textclasslist.Load(new_class)) {
2885 // successfully loaded
2887 minibuffer->Set(_("Converting document to new document class..."));
2888 int ret = current_view->currentBuffer()->
2890 SwitchLayoutsBetweenClasses(current_view->currentBuffer()->
2893 current_view->currentBuffer()->
2899 s= _("One paragraph couldn't be converted");
2902 s += _(" paragraphs couldn't be converted");
2904 WriteAlert(_("Conversion Errors!"),s,
2905 _("into chosen document class"));
2908 params->textclass = new_class;
2910 // problem changing class -- warn user and retain old style
2911 WriteAlert(_("Conversion Errors!"),
2912 _("Unable to switch to new document class."),
2913 _("Reverting to original document class."));
2914 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2918 char tmpsep = params->paragraph_separation;
2919 if (fl_get_button(fd_form_document->radio_indent))
2920 params->paragraph_separation = LYX_PARSEP_INDENT;
2922 params->paragraph_separation = LYX_PARSEP_SKIP;
2923 if (tmpsep != params->paragraph_separation)
2926 VSpace tmpdefskip = params->getDefSkip();
2927 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2928 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2929 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2930 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2931 case 4: params->setDefSkip(
2932 VSpace (LyXGlueLength (fl_get_input
2933 (fd_form_document->input_default_skip))));
2935 // DocumentDefskipCB assures that this never happens
2936 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2938 if (!(tmpdefskip == params->getDefSkip()))
2941 if (fl_get_button(fd_form_document->radio_columns_two))
2942 params->columns = 2;
2944 params->columns = 1;
2945 if (fl_get_button(fd_form_document->radio_sides_two))
2946 params->sides = LyXTextClass::TwoSides;
2948 params->sides = LyXTextClass::OneSide;
2950 Spacing tmpSpacing = params->spacing;
2951 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2953 lyxerr.debug() << "Spacing: SINGLE" << endl;
2954 params->spacing.set(Spacing::Single);
2957 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2958 params->spacing.set(Spacing::Onehalf);
2961 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2962 params->spacing.set(Spacing::Double);
2965 lyxerr.debug() << "Spacing: OTHER" << endl;
2966 params->spacing.set(Spacing::Other,
2967 fl_get_input(fd_form_document->input_spacing));
2970 if (tmpSpacing != params->spacing)
2973 signed char tmpchar =
2974 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2975 if (params->secnumdepth != tmpchar)
2977 params->secnumdepth = tmpchar;
2980 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2982 params->float_placement =
2983 fl_get_input(fd_form_document->input_float_placement);
2985 // More checking should be done to ensure the string doesn't have
2986 // spaces or illegal placement characters in it. (thornley)
2989 current_view->redoCurrentBuffer();
2991 minibuffer->Set(_("Document layout set"));
2992 current_view->currentBuffer()->markDirty();
2995 fl_get_input(fd_form_document->input_extra);
3000 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
3002 fl_hide_form(fd_form_document->form_document);
3006 extern "C" void DocumentOKCB(FL_OBJECT *ob, long data)
3008 DocumentCancelCB(ob,data);
3009 DocumentApplyCB(ob,data);
3013 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
3016 // bullet callbacks etc. in bullet_panel.C -- ARRae
3022 if (!current_view->getScreen())
3025 current_view->getScreen()->HideCursor();
3027 current_view->currentBuffer()->update(-2);
3030 if (!current_view->currentBuffer()->text->GotoNextNote()) {
3031 if (current_view->currentBuffer()->text->cursor.pos
3032 || current_view->currentBuffer()->text->cursor.par !=
3033 current_view->currentBuffer()->text->FirstParagraph())
3035 tmp = current_view->currentBuffer()->text->cursor;
3036 current_view->currentBuffer()->text->cursor.par =
3037 current_view->currentBuffer()->text->FirstParagraph();
3038 current_view->currentBuffer()->text->cursor.pos = 0;
3039 if (!current_view->currentBuffer()->text->GotoNextNote()) {
3040 current_view->currentBuffer()->text->cursor = tmp;
3041 minibuffer->Set(_("No more notes"));
3045 minibuffer->Set(_("No more notes"));
3049 current_view->currentBuffer()->update(0);
3050 current_view->currentBuffer()->text->sel_cursor =
3051 current_view->currentBuffer()->text->cursor;
3055 void InsertCorrectQuote()
3057 Buffer *cbuffer = current_view->currentBuffer();
3060 if (cbuffer->text->cursor.pos )
3061 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3065 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3069 /* callbacks for form form_quotes */
3071 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
3073 if (!current_view->available())
3076 minibuffer->Set(_("Quotes type set"));
3077 //current_view->currentBuffer()->params.quotes_language =
3078 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3079 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3080 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3082 lga = InsetQuotes::EnglishQ;
3085 lga = InsetQuotes::SwedishQ;
3088 lga = InsetQuotes::GermanQ;
3091 lga = InsetQuotes::PolishQ;
3094 lga = InsetQuotes::FrenchQ;
3097 lga = InsetQuotes::DanishQ;
3100 current_view->currentBuffer()->params.quotes_language = lga;
3101 if (fl_get_button(fd_form_quotes->radio_single))
3102 current_view->currentBuffer()->
3103 params.quotes_times = InsetQuotes::SingleQ;
3105 current_view->currentBuffer()->
3106 params.quotes_times = InsetQuotes::DoubleQ;
3110 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
3112 fl_hide_form(fd_form_quotes->form_quotes);
3116 extern "C" void QuotesOKCB(FL_OBJECT *ob, long data)
3118 QuotesApplyCB(ob, data);
3119 QuotesCancelCB(ob, data);
3124 /* callbacks for form form_preamble */
3126 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
3128 fl_hide_form(fd_form_preamble->form_preamble);
3132 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
3134 if (!current_view->available())
3137 current_view->currentBuffer()->params.preamble =
3138 fl_get_input(fd_form_preamble->input_preamble);
3139 current_view->currentBuffer()->markDirty();
3140 minibuffer->Set(_("LaTeX preamble set"));
3144 extern "C" void PreambleOKCB(FL_OBJECT *ob, long data)
3146 PreambleApplyCB(ob, data);
3147 PreambleCancelCB(ob, data);
3151 /* callbacks for form form_table */
3153 extern "C" void TableApplyCB(FL_OBJECT *, long)
3156 if (!current_view->getScreen())
3159 // check for tables in tables
3160 if (current_view->currentBuffer()->text->cursor.par->table){
3161 WriteAlert(_("Impossible Operation!"),
3162 _("Cannot insert table in table."),
3167 minibuffer->Set(_("Inserting table..."));
3169 ysize = (int)(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3170 xsize = (int)(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3173 current_view->getScreen()->HideCursor();
3175 current_view->currentBuffer()->update(-2);
3177 current_view->currentBuffer()->text->SetCursorParUndo();
3178 current_view->currentBuffer()->text->FreezeUndo();
3180 current_view->currentBuffer()->text->BreakParagraph();
3181 current_view->currentBuffer()->update(-1);
3183 if (current_view->currentBuffer()->text->cursor.par->Last()) {
3184 current_view->currentBuffer()->text->CursorLeft();
3186 current_view->currentBuffer()->text->BreakParagraph();
3187 current_view->currentBuffer()->update(-1);
3190 current_view->currentBuffer()->text->current_font.setLatex(LyXFont::OFF);
3191 //if (!fl_get_button(fd_form_table->check_latex)){
3192 // insert the new wysiwy table
3193 current_view->currentBuffer()->text->SetLayout(0); // standard layout
3194 if (current_view->currentBuffer()->text->cursor.par->footnoteflag ==
3195 LyXParagraph::NO_FOOTNOTE) {
3196 current_view->currentBuffer()->
3197 text->SetParagraph(0, 0,
3199 VSpace (0.3 * current_view->currentBuffer()->
3200 params.spacing.getValue(),
3202 VSpace (0.3 * current_view->currentBuffer()->
3203 params.spacing.getValue(),
3210 current_view->currentBuffer()->text->SetParagraph(0, 0,
3212 VSpace(VSpace::NONE),
3213 VSpace(VSpace::NONE),
3218 current_view->currentBuffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
3220 for (i=0; i<xsize * ysize - 1; i++)
3221 current_view->currentBuffer()->text->cursor.par->InsertChar(0,LYX_META_NEWLINE);
3222 current_view->currentBuffer()->text->RedoParagraph();
3224 current_view->currentBuffer()->text->UnFreezeUndo();
3226 current_view->currentBuffer()->update(1);
3227 minibuffer->Set(_("Table inserted"));
3231 extern "C" void TableCancelCB(FL_OBJECT *, long)
3233 fl_hide_form(fd_form_table->form_table);
3237 extern "C" void TableOKCB(FL_OBJECT *ob, long data)
3239 TableApplyCB(ob,data);
3240 TableCancelCB(ob,data);
3244 /* callbacks for form form_print */
3246 extern "C" void PrintCancelCB(FL_OBJECT *, long)
3248 fl_hide_form(fd_form_print->form_print);
3251 static bool stringOnlyContains (string const & LStr, const char * cset)
3253 const char * cstr = LStr.c_str() ;
3255 return strspn(cstr,cset) == strlen(cstr) ;
3258 extern "C" void PrintApplyCB(FL_OBJECT *, long)
3260 if (!current_view->available())
3262 Buffer *buffer = current_view->currentBuffer();
3263 string path = OnlyPath(buffer->getFileName());
3266 if (fl_get_button(fd_form_print->radio_even_pages))
3267 pageflag = lyxrc->print_evenpage_flag + ' ';
3268 else if (fl_get_button(fd_form_print->radio_odd_pages))
3269 pageflag = lyxrc->print_oddpage_flag + ' ';
3271 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3272 // User may give a page (range) list
3273 // User may print multiple (unsorted) copies
3274 string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
3275 pages = subst(pages, '+',',');
3276 pages = frontStrip(strip(pages)) ;
3277 while (!pages.empty()) { // a page range was given
3279 pages = split (pages, piece, ',') ;
3280 piece = strip(piece) ;
3281 piece = frontStrip(piece) ;
3282 if ( !stringOnlyContains (piece, "0123456789-") ) {
3283 WriteAlert(_("ERROR! Unable to print!"),
3284 _("Check 'range of pages'!"));
3287 if (piece.find('-') == string::npos) { // not found
3288 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3289 } else if (suffixIs(piece, "-") ) { // missing last page
3290 pageflag += lyxrc->print_pagerange_flag + piece + "1000 ";
3291 } else if (prefixIs(piece, "-") ) { // missing first page
3292 pageflag += lyxrc->print_pagerange_flag + '1' + piece + ' ' ;
3294 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3298 string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
3299 if (!copies.empty()) { // a number of copies was given
3300 if ( !stringOnlyContains (copies, "0123456789") ) {
3301 WriteAlert(_("ERROR! Unable to print!"),
3302 _("Check 'number of copies'!"));
3305 if (fl_get_button(fd_form_print->do_unsorted))
3306 pageflag += lyxrc->print_copies_flag;
3308 pageflag += lyxrc->print_collcopies_flag;
3309 pageflag += " " + copies + ' ' ;
3313 if (fl_get_button(fd_form_print->radio_order_reverse))
3314 reverseflag = lyxrc->print_reverse_flag + ' ';
3316 string orientationflag;
3317 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
3318 orientationflag = lyxrc->print_landscape_flag + ' ';
3320 string ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
3321 string printer = strip(fl_get_input(fd_form_print->input_printer));
3324 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3325 && ! printer.empty()) // a printer name has been given
3326 printerflag = lyxrc->print_to_printer + printer + ' ';
3329 if (!lyxrc->print_extra_options.empty())
3330 extraflags = lyxrc->print_extra_options + ' ';
3332 string command = lyxrc->print_command + ' '
3333 + printerflag + pageflag + reverseflag
3334 + orientationflag + extraflags;
3336 char real_papersize = buffer->params.papersize;
3337 if (real_papersize == PAPER_DEFAULT)
3338 real_papersize = lyxrc->default_papersize;
3342 switch (real_papersize) {
3343 case PAPER_USLETTER:
3358 case PAPER_EXECUTIVEPAPER:
3361 case PAPER_LEGALPAPER:
3364 default: /* If nothing else fits, keep an empty value... */
3368 if (buffer->params.use_geometry
3369 && buffer->params.papersize2 == VM_PAPER_CUSTOM
3370 && !lyxrc->print_paper_dimension_flag.empty()
3371 && !buffer->params.paperwidth.empty()
3372 && !buffer->params.paperheight.empty()) {
3373 // using a custom papersize
3375 command += lyxrc->print_paper_dimension_flag + ' ';
3376 command += buffer->params.paperwidth + ',';
3377 command += buffer->params.paperheight + ' ';
3378 } else if (!lyxrc->print_paper_flag.empty()
3380 && (real_papersize != PAPER_USLETTER ||
3381 buffer->params.orientation == ORIENTATION_PORTRAIT)) {
3382 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3384 if (fl_get_button(fd_form_print->radio_file))
3385 command += lyxrc->print_to_file + '\"'
3386 + MakeAbsPath(ps_file, path)
3388 else if (!lyxrc->print_spool_command.empty())
3389 command += lyxrc->print_to_file
3390 + '\"' + ps_file + '\"';
3392 // push directorypath, if necessary
3393 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3394 path = buffer->tmppath;
3399 if (!lyxrc->print_spool_command.empty() &&
3400 !fl_get_button(fd_form_print->radio_file)) {
3401 string command2 = lyxrc->print_spool_command + ' ';
3402 if (!printer.empty())
3403 command2 += lyxrc->print_spool_printerprefix
3405 // First run dvips and, if succesful, then spool command
3406 if ((result = RunScript(buffer, true, command))) {
3407 result = RunScript(buffer, false, command2, ps_file);
3410 result = RunScript(buffer, false, command);
3413 WriteAlert(_("Error:"),
3414 _("Unable to print"),
3415 _("Check that your parameters are correct"));
3419 extern "C" void PrintOKCB(FL_OBJECT *ob, long data)
3421 PrintCancelCB(ob, data);
3422 PrintApplyCB(ob,data);
3426 /* callbacks for form form_figure */
3428 extern "C" void FigureApplyCB(FL_OBJECT *, long)
3430 if (!current_view->available())
3433 Buffer * buffer = current_view->currentBuffer();
3434 if(buffer->isReadonly()) // paranoia
3437 minibuffer->Set(_("Inserting figure..."));
3438 if (fl_get_button(fd_form_figure->radio_inline)
3439 || buffer->text->cursor.par->table) {
3440 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3441 buffer->insertInset(new_inset);
3442 minibuffer->Set(_("Figure inserted"));
3443 new_inset->Edit(0, 0);
3447 current_view->getScreen()->HideCursor();
3451 buffer->text->SetCursorParUndo();
3452 buffer->text->FreezeUndo();
3454 buffer->text->BreakParagraph();
3457 if (buffer->text->cursor.par->Last()) {
3458 buffer->text->CursorLeft();
3460 buffer->text->BreakParagraph();
3464 // The standard layout should always be numer 0;
3465 buffer->text->SetLayout(0);
3467 if (buffer->text->cursor.par->footnoteflag ==
3468 LyXParagraph::NO_FOOTNOTE) {
3469 buffer->text->SetParagraph(0, 0,
3471 VSpace (0.3 * buffer->params.spacing.getValue(),
3474 buffer->params.spacing.getValue(),
3476 LYX_ALIGN_CENTER, string(), 0);
3478 buffer->text->SetParagraph(0, 0,
3480 VSpace(VSpace::NONE),
3481 VSpace(VSpace::NONE),
3488 Inset *new_inset = 0;
3490 new_inset = new InsetFig(100, 100, buffer);
3491 buffer->insertInset(new_inset);
3492 new_inset->Edit(0, 0);
3494 minibuffer->Set(_("Figure inserted"));
3495 buffer->text->UnFreezeUndo();
3499 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3501 fl_hide_form(fd_form_figure->form_figure);
3505 extern "C" void FigureOKCB(FL_OBJECT *ob, long data)
3507 FigureApplyCB(ob,data);
3508 FigureCancelCB(ob,data);
3511 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3513 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3514 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3515 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3516 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3517 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3518 fontloader.update();
3520 // All buffers will need resize
3521 bufferlist.resize();
3523 minibuffer->Set(_("Screen options set"));
3527 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3529 fl_hide_form(fd_form_screen->form_screen);
3533 extern "C" void ScreenOKCB(FL_OBJECT *ob, long data)
3535 ScreenCancelCB(ob,data);
3536 ScreenApplyCB(ob,data);
3542 if (!current_view->available())
3545 fl_set_button(fd_latex_options->accents,
3546 (int)current_view->currentBuffer()->params.allowAccents);
3548 if (fd_latex_options->LaTeXOptions->visible) {
3549 fl_raise_form(fd_latex_options->LaTeXOptions);
3551 fl_show_form(fd_latex_options->LaTeXOptions,
3552 FL_PLACE_MOUSE, FL_FULLBORDER,
3553 _("LaTeX Options"));
3558 // This function runs "configure" and then rereads lyx.defaults to
3559 // reconfigure the automatic settings.
3562 minibuffer->Set(_("Running configure..."));
3564 // Run configure in user lyx directory
3565 Path p(user_lyxdir);
3566 Systemcalls one(Systemcalls::System,
3567 AddName(system_lyxdir,"configure"));
3569 minibuffer->Set(_("Reloading configuration..."));
3570 lyxrc->Read(LibFileSearch(string(), "lyxrc.defaults"));
3571 WriteAlert(_("The system has been reconfigured."),
3572 _("You need to restart LyX to make use of any"),
3573 _("updated document class specifications."));
3577 /* these functions are for the spellchecker */
3578 char* NextWord(float &value)
3580 if (!current_view->available()){
3585 char* string = current_view->currentBuffer()->text->SelectNextWord(value);
3591 void SelectLastWord()
3593 if (!current_view->available())
3596 current_view->getScreen()->HideCursor();
3598 current_view->currentBuffer()->text->SelectSelectedWord();
3599 current_view->getScreen()->ToggleSelection(false);
3600 current_view->currentBuffer()->update(0);
3604 void EndOfSpellCheck()
3606 if (!current_view->available())
3609 current_view->getScreen()->HideCursor();
3611 current_view->currentBuffer()->text->SelectSelectedWord();
3612 current_view->currentBuffer()->text->ClearSelection();
3613 current_view->currentBuffer()->update(0);
3617 void ReplaceWord(string const & replacestring)
3619 if (!current_view->getScreen())
3622 current_view->getScreen()->HideCursor();
3623 current_view->currentBuffer()->update(-2);
3625 /* clear the selection (if there is any) */
3626 current_view->getScreen()->ToggleSelection(false);
3627 current_view->currentBuffer()->text->
3628 ReplaceSelectionWithString(replacestring.c_str());
3630 current_view->currentBuffer()->text->SetSelectionOverString(replacestring.c_str());
3632 // Go back so that replacement string is also spellchecked
3633 for (string::size_type i = 0; i < replacestring.length() + 1; ++i) {
3634 current_view->currentBuffer()->text->CursorLeftIntern();
3636 current_view->currentBuffer()->update(1);
3638 // End of spellchecker stuff
3643 // Table of Contents
3653 static TocList* toclist = 0;
3656 extern "C" void TocSelectCB(FL_OBJECT *ob, long)
3658 if (!current_view->available())
3661 TocList* tmptoclist = toclist;
3662 int i = fl_get_browser(ob);
3665 for (a=1; a<i && tmptoclist->next; a++){
3666 tmptoclist = tmptoclist->next;
3673 LyXParagraph *par = current_view->currentBuffer()->paragraph;
3674 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3675 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3676 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3677 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3678 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3679 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3680 par->appendix != tmptoclist->appendix)) {
3681 par = par->LastPhysicalPar()->Next();
3686 current_view->currentBuffer()->text->SetCursor(par, 0);
3687 current_view->currentBuffer()->text->sel_cursor =
3688 current_view->currentBuffer()->text->cursor;
3689 current_view->currentBuffer()->update(0);
3692 WriteAlert(_("Error"),
3693 _("Couldn't find this label"),
3694 _("in current document."));
3700 extern "C" void TocCancelCB(FL_OBJECT *, long)
3702 fl_hide_form(fd_form_toc->form_toc);
3706 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3708 static LyXParagraph * stapar = 0;
3709 TocList * tmptoclist = 0;
3711 /* deleted the toclist */
3714 tmptoclist = toclist->next;
3716 toclist = tmptoclist;
3720 tmptoclist = toclist;
3723 fl_clear_browser(fd_form_toc->browser_toc);
3724 if (!current_view->available()) {
3725 fl_add_browser_line(fd_form_toc->browser_toc, _("*** No Document ***"));
3728 fl_hide_object(fd_form_toc->browser_toc);
3729 /* get the table of contents */
3730 LyXParagraph * par = current_view->currentBuffer()->paragraph;
3732 char * line = new char[200];
3738 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3742 labeltype = textclasslist.Style(current_view->currentBuffer()->params.textclass,
3743 par->GetLayout()).labeltype;
3745 if (labeltype >= LABEL_COUNTER_CHAPTER
3746 && labeltype <= LABEL_COUNTER_CHAPTER +
3747 current_view->currentBuffer()->params.tocdepth) {
3748 /* insert this into the table of contents */
3749 /* first indent a little bit */
3753 textclasslist.TextClass(current_view->currentBuffer()->
3754 params.textclass).maxcounter()) * 4 + 2;
3758 // Then the labestring
3759 if (!par->labelstring.empty()) {
3760 string::size_type i = 0;
3761 while (pos < 199 && i < par->labelstring.length()) {
3762 line[pos] = par->labelstring[i];
3771 /* now the contents */
3773 LyXParagraph::size_type i = 0;
3774 while (pos < 199 && i < par->size()) {
3777 while (pos < 199 && i < par->last) {
3779 c = par->GetChar(i);
3780 if (isprint(c) || c >= 128) {
3787 fl_add_browser_line(fd_form_toc->browser_toc, line);
3789 /* make a toclist entry */
3791 tmptoclist = new TocList;
3792 toclist = tmptoclist;
3794 tmptoclist->next = new TocList;
3795 tmptoclist = tmptoclist->next;
3798 tmptoclist->next = 0;
3800 for (a=0; a<6; a++){
3801 tmptoclist->counter[a] = par->GetFirstCounter(a);
3803 tmptoclist->appendix = par->appendix;
3805 par = par->LastPhysicalPar()->Next();
3809 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3810 fl_show_object(fd_form_toc->browser_toc);
3814 /* callbacks for form form_ref */
3815 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3817 if (!current_view->available())
3821 fl_get_browser_line(fd_form_ref->browser_ref,
3822 fl_get_browser(fd_form_ref->browser_ref));
3823 string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3829 current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3839 if(current_view->currentBuffer()->isSGML())
3840 t += "[" + u + "]" + "{" + s + "}";
3845 new InsetRef(t, current_view->currentBuffer());
3846 current_view->currentBuffer()->insertInset(new_inset);
3850 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3852 if (!current_view->available()) {
3853 fl_clear_browser(fd_form_ref->browser_ref);
3857 FL_OBJECT * brow = fd_form_ref->browser_ref;
3859 // Get the current line, in order to restore it later
3860 char const * const btmp=fl_get_browser_line(brow,
3861 fl_get_browser(brow));
3862 string currentstr=btmp ? btmp : "";
3863 //string currentstr = fl_get_browser_line(brow,
3864 // fl_get_browser(brow));
3866 fl_clear_browser(brow);
3868 string refs = current_view->currentBuffer()->getReferenceList('\n');
3871 #if FL_REVISION > 85
3872 fl_addto_browser_chars(brow,refs.c_str());
3873 int total_lines = fl_get_browser_maxline(brow);
3874 for (int i = 1; i <= total_lines ; i++) {
3875 if (fl_get_browser_line(brow, i) == currentstr) {
3880 fl_set_browser_topline(brow, topline);
3882 // Keep the old ugly code for xforms 0.81 compatibility
3887 curr_ref = refs.token('\n',ref_num);
3888 if (curr_ref.empty())
3890 fl_add_browser_line(brow,curr_ref.c_str());
3895 if (!fl_get_browser_maxline(brow)) {
3896 fl_add_browser_line(brow,
3897 _("*** No labels found in document ***"));
3898 fl_deactivate_object(brow);
3900 fl_select_browser_line(brow, topline);
3901 fl_activate_object(brow);
3903 if (current_view->currentBuffer()->isReadonly()) {
3904 // would be better to de/activate insert buttons
3905 // but that's more work... besides this works. ARRae
3906 fl_hide_form(fd_form_ref->form_ref);
3908 if (!current_view->currentBuffer()->isSGML()) {
3909 fl_deactivate_object(fd_form_ref->ref_name);
3910 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3913 fl_activate_object(fd_form_ref->ref_name);
3914 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3919 extern "C" void RefHideCB(FL_OBJECT *, long)
3921 fl_hide_form(fd_form_ref->form_ref);
3925 void UpdateInset(Inset* inset, bool mark_dirty)
3930 /* very first check for locking insets*/
3931 if (current_view->currentBuffer()->the_locking_inset == inset){
3932 if (current_view->currentBuffer()->text->UpdateInset(inset)){
3933 current_view->update();
3935 if (current_view->currentBuffer()->isLyxClean())
3936 minibuffer->setTimer(4);
3937 current_view->currentBuffer()->markDirty();
3939 current_view->updateScrollbar();
3944 /* first check the current buffer */
3945 if (current_view->available()){
3946 current_view->getScreen()->HideCursor();
3947 current_view->currentBuffer()->update(-3);
3948 if (current_view->currentBuffer()->text->UpdateInset(inset)){
3950 current_view->currentBuffer()->update(1);
3952 current_view->currentBuffer()->update(3);
3957 // check all buffers
3958 bufferlist.updateInset(inset, mark_dirty);
3963 /* these functions return 1 if an error occured,
3965 int LockInset(UpdatableInset* inset)
3967 if (!current_view->currentBuffer()->the_locking_inset && inset){
3968 current_view->currentBuffer()->the_locking_inset = inset;
3975 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
3977 if (current_view->currentBuffer()->the_locking_inset &&
3978 current_view->getScreen()){
3979 y += current_view->currentBuffer()->text->cursor.y;
3980 current_view->getScreen()->ShowManualCursor(x, y,
3986 void HideLockedInsetCursor(long x, long y, int asc, int desc)
3988 if (current_view->currentBuffer()->the_locking_inset &&
3989 current_view->getScreen()){
3990 y += current_view->currentBuffer()->text->cursor.y;
3991 current_view->getScreen()->HideManualCursor(x, y,
3997 void FitLockedInsetCursor(long x, long y, int asc, int desc)
3999 if (current_view->currentBuffer()->the_locking_inset &&
4000 current_view->getScreen()){
4001 y += current_view->currentBuffer()->text->cursor.y;
4002 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
4003 current_view->updateScrollbar();
4008 int UnlockInset(UpdatableInset* inset)
4011 current_view->currentBuffer()->the_locking_inset == inset){
4012 inset->InsetUnlock();
4013 current_view->currentBuffer()->the_locking_inset = 0;
4014 current_view->currentBuffer()->text->FinishUndo();
4017 return bufferlist.unlockInset(inset);
4021 void LockedInsetStoreUndo(Undo::undo_kind kind)
4023 if (!current_view->currentBuffer()->the_locking_inset)
4024 return; // shouldn't happen
4025 if (kind == Undo::EDIT) // in this case insets would not be stored!
4026 kind = Undo::FINISH;
4027 current_view->currentBuffer()->text->SetUndo(kind,
4028 current_view->currentBuffer()->text->cursor.par->
4029 ParFromPos(current_view->currentBuffer()->text->cursor.pos)->previous,
4030 current_view->currentBuffer()->text->cursor.par->
4031 ParFromPos(current_view->currentBuffer()->text->cursor.pos)->next);
4035 void PutInsetIntoInsetUpdateList(Inset* inset)
4038 InsetUpdateStruct* tmp = new InsetUpdateStruct();
4040 tmp->next = InsetUpdateList;
4041 InsetUpdateList = tmp;
4046 void UpdateInsetUpdateList()
4048 InsetUpdateStruct *tmp = InsetUpdateList;
4050 UpdateInset(tmp->inset, false); // "false" because no document change
4054 /* delete the update list */
4055 while (InsetUpdateList) {
4056 tmp = InsetUpdateList;
4057 InsetUpdateList = InsetUpdateList->next;
4060 InsetUpdateList = 0;
4063 #ifdef WITH_WARNINGS
4066 // I know we shouldn't put anything in here but this seems the fastest
4067 // way to do this (and the cleanest for now). This function just inserts
4068 // a newline in the string and the inserts 'depth'-spaces so that the
4069 // code is indented in the right way!!!
4070 void addNewlineAndDepth(string &file, int const depth)
4073 file.append(' ', depth);