1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich,
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================*/
21 #include FORMS_H_LOCATION
23 #include "layout_forms.h"
24 #include "bullet_forms.h"
25 #include "print_form.h"
27 #include "spellchecker.h"
31 #include "insets/insetref.h"
32 #include "insets/insetquotes.h"
33 #include "insets/insetlatex.h"
34 #include "insets/insetlabel.h"
35 #include "insets/insetinfo.h"
36 #include "insets/insetspecialchar.h"
37 #include "insets/figinset.h"
39 #include "latexoptions.h"
41 #include "minibuffer.h"
43 #include "bufferlist.h"
44 #include "filetools.h"
45 #include "pathstack.h"
47 #include "lyx_gui_misc.h"
48 #include "LyXView.h" // only because of form_main
49 #include "lastfiles.h"
51 #include "lyxscreen.h"
55 #include "lyxserver.h"
56 #include "FontLoader.h"
61 // $Id: lyx_cb.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $
63 #if !defined(lint) && !defined(WITH_WARNINGS)
64 static char vcid[] = "$Id: lyx_cb.C,v 1.1 1999/09/27 18:44:37 larsbj Exp $";
67 extern MiniBuffer *minibuffer;
68 extern Combox *combo_language;
69 extern BufferList bufferlist;
70 extern void show_symbols_form();
71 extern FD_form_main *fd_form_main;
72 extern FD_form_title *fd_form_title;
73 extern FD_form_paragraph *fd_form_paragraph;
74 extern FD_form_character *fd_form_character;
75 extern FD_form_document *fd_form_document;
76 extern FD_form_quotes *fd_form_quotes;
77 extern FD_form_preamble *fd_form_preamble;
78 extern FD_form_table *fd_form_table;
79 extern FD_form_print *fd_form_print;
80 extern FD_form_figure *fd_form_figure;
81 extern FD_form_screen *fd_form_screen;
82 extern FD_form_toc *fd_form_toc;
83 extern FD_form_ref *fd_form_ref;
84 extern FD_LaTeXOptions *fd_latex_options;
85 extern FD_form_bullet *fd_form_bullet;
87 extern BufferView *current_view; // called too many times in this file...
89 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
91 extern bool send_fax(LString const &fname, LString const &sendcmd);
93 extern LyXServer *lyxserver;
94 extern FontLoader fontloader;
96 // this should be static, but I need it in buffer.C
97 bool quitting; // flag, that we are quitting the program
98 extern bool finished; // all cleanup done just let it run through now.
100 char ascii_type; /* for selection notify callbacks */
102 bool scrolling = false;
104 char updatetimer = 0;
106 /* whether the work area should get callbacks */
107 bool input_prohibited = false;
109 /* the selection possible is needed, that only motion events are
110 * used, where the bottom press event was on the drawing area too */
111 bool selection_possible = false;
113 // This is used to make the dreaded font toggle problem hopefully go
114 // away. Definitely not the best solution, but I think it sorta works.
115 bool toggleall = true;
117 void InsertCorrectQuote();
121 This is the inset locking stuff needed for mathed --------------------
123 an inset can simple call LockInset in it's edit call and *ONLY* in it's
125 Inset::Edit() can only be called by the main lyx module.
127 Then the inset may modify the menu's and/or iconbars.
129 Unlocking is either done by LyX or the inset itself with a UnlockInset-call
131 During the lock, all button and keyboard events will be modified
132 and send to the inset through the following inset-features. Note that
133 Inset::InsetUnlock will be called from inside UnlockInset. It is meant
134 to contain the code for restoring the menus and things like this.
137 virtual void InsetButtonPress(int x, int y, int button);
138 virtual void InsetButtonRelease(int x, int y, int button);
139 virtual void InsetKeyPress(XKeyEvent *ev);
140 virtual void InsetMotionNotify(int x, int y, int state);
141 virtual void InsetUnlock();
143 If a inset wishes any redraw and/or update it just has to call
145 It's is completly irrelevant, where the inset is. UpdateInset will
146 find it in any paragraph in any buffer.
147 Of course the_locking_inset and the insets in the current paragraph/buffer
148 are checked first, so no performance problem should occur.
150 Hope that's ok for the beginning, Alejandro,
151 sorry that I needed so much time,
156 void UpdateInset(Inset* inset, bool mark_dirty = true);
157 /* these functions return 1 if an error occured,
159 // Now they work only for updatable insets. [Alejandro 080596]
160 int LockInset(UpdatableInset* inset);
161 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
162 void FitLockedInsetCursor(long x, long y, int asc, int desc);
163 int UnlockInset(UpdatableInset* inset);
164 void LockedInsetStoreUndo(Undo::undo_kind kind);
166 /* this is for asyncron updating. UpdateInsetUpdateList will be called
167 automatically from LyX. Just insert the Inset into the Updatelist */
168 void UpdateInsetUpdateList();
169 void PutInsetIntoInsetUpdateList(Inset* inset);
171 InsetUpdateStruct *InsetUpdateList = NULL;
175 -----------------------------------------------------------------------
178 /* some function prototypes */
185 void HyphenationPoint();
186 void MenuSeparator();
189 void ProtectedBlank();
191 int RunLinuxDoc(int, LString const &);
192 int RunDocBook(int, LString const &);
193 void MenuWrite(Buffer* buf);
194 void MenuWriteAs(Buffer *buffer);
195 void MenuReload(Buffer *buf);
196 void MenuLayoutSave();
198 unsigned char GetCurrentTextClass()
199 // Who are we asking?
200 // Shouldn't this question be directed to the buffer?
201 // Indeed it should. Asger.
203 return current_view->currentBuffer()->params.textclass;
207 // How should this actually work? Should it prohibit input in all BufferViews,
208 // or just in the current one? If "just the current one", then it should be
209 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
210 // run "ProhibitInput" on all LyXViews which will run prohibitInput on all
211 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
212 // current LyxView that should be prohibited (Lgb) (This applies to
213 // "AllowInput" as well.)
216 input_prohibited = true;
217 if (current_view->getScreen())
218 current_view->getScreen()->HideCursor();
220 static Cursor cursor;
221 static bool cursor_undefined = true;
223 if (cursor_undefined){
224 cursor = XCreateFontCursor(fl_display, XC_watch);
226 cursor_undefined = false;
229 /* set the cursor to the watch for all forms and the canvas */
230 XDefineCursor(fl_display, fd_form_main->form_main->window, cursor);
231 if (fd_form_paragraph->form_paragraph->visible)
232 XDefineCursor(fl_display,
233 fd_form_paragraph->form_paragraph->window,
235 if (fd_form_character->form_character->visible)
236 XDefineCursor(fl_display,
237 fd_form_character->form_character->window,
241 fl_deactivate_all_forms();
245 // Should find a way to move this into BufferView.C
246 void SetXtermCursor(Window win)
248 static Cursor cursor;
249 static char cursor_undefined = 1;
250 if (cursor_undefined){
251 cursor = XCreateFontCursor(fl_display, XC_xterm);
253 cursor_undefined = 0;
255 XDefineCursor(fl_display, win, cursor);
262 input_prohibited = false;
264 /* reset the cursor from the watch for all forms and the canvas */
266 XUndefineCursor(fl_display, fd_form_main->form_main->window);
267 if (fd_form_paragraph->form_paragraph->visible)
268 XUndefineCursor(fl_display,
269 fd_form_paragraph->form_paragraph->window);
270 if (fd_form_character->form_character->visible)
271 XUndefineCursor(fl_display,
272 fd_form_character->form_character->window);
273 if (current_view->getWorkArea()->belowmouse)
274 SetXtermCursor(fd_form_main->form_main->window);
277 fl_activate_all_forms();
281 void FreeUpdateTimer()
283 /* a real free timer would be better but I don't know
284 * how to do this with xforms */
289 void SetUpdateTimer(float time)
291 fl_set_timer(fd_form_main->timer_update, time);
298 current_view->getScreen()->ToggleSelection();
299 current_view->currentBuffer()->text->ClearSelection();
304 void SmallUpdate(signed char f)
306 current_view->getScreen()->SmallUpdate();
307 if (current_view->getScreen()->TopCursorVisible()
308 != current_view->getScreen()->first){
309 current_view->currentBuffer()->update(f);
313 current_view->fitCursor();
314 current_view->updateScrollbar();
316 if (!current_view->currentBuffer()->text->selection)
317 current_view->currentBuffer()->text->sel_cursor =
318 current_view->currentBuffer()->text->cursor;
321 if (current_view->currentBuffer()->isLyxClean()) {
322 current_view->currentBuffer()->markDirty();
323 minibuffer->setTimer(4);
326 current_view->currentBuffer()->markDirty();
340 // should be moved to lyxfunc.C
341 void MenuWrite(Buffer* buf)
344 if (!bufferlist.write(buf)) {
345 LString fname = buf->getFileName();
346 LString s = MakeAbsPath(fname);
347 if (AskQuestion(_("Save failed. Rename and try again?"),
348 MakeDisplayPath(s,50),
349 _("(If not, document is not saved.)"))) {
353 lastfiles->newFile(buf->getFileName());
358 // should be moved to BufferView.C
359 void MenuWriteAs(Buffer *buffer)
361 if (!buffer->text) return;
363 LString fname = buffer->getFileName();
364 LString oldname = fname;
368 fileDlg.SetButton(0, _("Documents"), lyxrc->document_path);
369 fileDlg.SetButton(1, _("Templates"), lyxrc->template_path);
371 if (!IsLyXFilename(fname))
374 fname = fileDlg.Select(_("Enter Filename to Save Document as"),
377 OnlyFilename(fname));
381 minibuffer->Set(_("Canceled."));
385 // Make sure the absolute filename ends with appropriate suffix
386 LString s= MakeAbsPath(fname);
387 if (!IsLyXFilename(s))
390 // Same name as we have already?
392 if (!AskQuestion(_("Same name as document already has:"),
393 MakeDisplayPath(s,50),
396 // Falls through to name change and save
398 // No, but do we have another file with this name open?
399 else if (bufferlist.exists(s)) {
400 if (AskQuestion(_("Another document with same name open!"),
401 MakeDisplayPath(s,50),
402 _("Replace with current document?")))
404 bufferlist.close(bufferlist.getBuffer(s));
406 // Ok, change the name of the buffer, but don't save!
407 buffer->setFileName(s);
410 minibuffer->Set(_("Document renamed to '"),
412 _("', but not saved..."));
415 } // Check whether the file exists
418 if (myfile.isOK() && !AskQuestion(_("Document already exists:"),
419 MakeDisplayPath(s,50),
424 // Ok, change the name of the buffer
425 buffer->setFileName(s);
428 // Small bug: If the save fails, we have irreversible changed the name
434 extern bool gsworking();
437 int MenuRunLaTeX(Buffer *buffer)
443 WriteAlert(_("Sorry, can't do this while pictures are being rendered."),
444 _("Please wait a few seconds for this to finish and try again."),
445 _("(or kill runaway gs processes by hand and try again.)"));
448 extern pid_t isp_pid; // from spellchecker.C
451 WriteAlert(_("Can't do this while the spellchecker is running."),
452 _("Stop the spellchecker first."));
457 if (buffer->isLinuxDoc())
458 ret = RunLinuxDoc(1, buffer->getFileName());
459 else if (buffer->isLiterate())
460 ret = buffer->runLiterate();
461 else if (buffer->isDocBook())
462 ret = RunDocBook(1, buffer->getFileName());
464 ret = buffer->runLaTeX();
470 s = _("One error detected");
471 t = _("You should try to fix it.");
474 s += _(" errors detected.");
475 t = _("You should try to fix them.");
477 WriteAlert(_("There were errors during the LaTeX run."), s, t);
483 int MenuBuildProg(Buffer *buffer)
487 if (buffer->isLiterate())
488 ret = buffer->buildProgram();
492 s = _("Wrong type of document");
493 t = _("The Build operation is not allowed in this document");
494 WriteAlert(_("There were errors during the Build process."), s, t);
502 s = _("One error detected");
503 t = _("You should try to fix it.");
506 s += _(" errors detected.");
507 t = _("You should try to fix them.");
509 WriteAlert(_("There were errors during the Build process."), s, t);
515 int MenuRunChktex(Buffer *buffer)
519 if (buffer->isSGML()) {
520 WriteAlert(_("Chktex does not work with SGML derived documents."));
523 ret = buffer->runChktex();
529 s = _("No warnings found.");
530 } else if (ret == 1) {
531 s = _("One warning found.");
532 t = _("Use 'Edit->Go to Error' to find it.");
535 s += _(" warnings found.");
536 t = _("Use 'Edit->Go to Error' to find them.");
538 WriteAlert(_("Chktex run successfully"), s, t);
540 WriteAlert(_("Error!"),_("It seems chktex does not work."));
546 int MakeDVIOutput(Buffer *buffer)
553 LString path = OnlyPath(buffer->getFileName());
554 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
555 path = buffer->tmppath;
557 if (!buffer->isDviClean()) {
559 ret = MenuRunLaTeX(buffer);
566 /* wait == false means don't wait for termination */
567 /* wait == true means wait for termination */
568 // The bool should be placed last on the argument line. (Lgb)
569 // Returns false if we fail.
570 bool RunScript(Buffer *buffer, bool wait,
571 LString const & command, LString const & orgname = LString(),
572 bool need_shell=true)
576 LString name= orgname;
579 if (MakeDVIOutput(buffer) > 0)
581 /* get DVI-Filename */
583 name = ChangeExtension(buffer->getFileName(),
586 path = OnlyPath(name);
587 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
588 path = buffer->tmppath;
592 cmd = command + ' ' + SpaceLess(name);
600 // OS/2 cmd.exe has another use for '&'
602 // This is not NLS safe, but it's OK, I think.
603 LString sh = OnlyFilename(getEnvPath("EMXSHELL"));
605 // COMSPEC is set, unless user unsets
606 sh = OnlyFilename(getEnvPath("COMSPEC"));
611 if (sh.contains("cmd.exe") || sh.contains("4os2.exe"))
612 cmd = "start /min/n " + cmd;
617 // It seems that, if wait is false, we never get back
618 // the return code of the command. This means that all
619 // the code I added in PrintApplyCB is currently
622 #warning What should we do here?
624 minibuffer->Set(_("Executing command:"), cmd);
625 result = one.Startscript(Systemcalls::System, cmd);
627 minibuffer->Set(_("Executing command:"), cmd);
628 result = one.Startscript(wait ? Systemcalls::Wait
629 : Systemcalls::DontWait, cmd);
636 // Returns false if we fail
637 bool MenuRunDvips(Buffer *buffer, bool wait=false)
645 if (MakeDVIOutput(buffer) > 0) {
649 // Generate postscript file
650 LString ps = ChangeExtension (buffer->getFileName(),
655 char real_papersize = buffer->params.papersize;
656 if (real_papersize == PAPER_DEFAULT)
657 real_papersize = lyxrc->default_papersize;
659 switch (real_papersize) {
675 case PAPER_EXECUTIVEPAPER:
678 case PAPER_LEGALPAPER:
681 default: /* If nothing else fits, keep an empty value... */
685 // Make postscript file.
686 LString command = "dvips " + lyxrc->print_to_file + ' ';
687 command += SpaceLess(ps);
688 if (buffer->params.use_geometry
689 && buffer->params.papersize2 == VM_PAPER_CUSTOM
690 && !lyxrc->print_paper_dimension_flag.empty()
691 && !buffer->params.paperwidth.empty()
692 && !buffer->params.paperheight.empty()) {
693 // using a custom papersize
695 command += lyxrc->print_paper_dimension_flag + ' ';
696 command += buffer->params.paperwidth + ',';
697 command += buffer->params.paperheight;
698 } else if (!paper.empty()
699 && (real_papersize != PAPER_USLETTER ||
700 buffer->params.orientation == ORIENTATION_PORTRAIT)) {
701 // dvips won't accept -t letter -t landscape. In all other
702 // cases, include the paper size explicitly.
704 command += lyxrc->print_paper_flag + ' ' + paper;
706 if (buffer->params.orientation == ORIENTATION_LANDSCAPE) {
708 command += lyxrc->print_landscape_flag;
710 // push directorypath, if necessary
711 LString path = OnlyPath(buffer->getFileName());
712 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
713 path = buffer->tmppath;
716 bool ret = RunScript(buffer, wait, command);
723 // Returns false if we fail
724 bool MenuPreviewPS(Buffer *buffer)
729 // Generate postscript file
730 if (!MenuRunDvips(buffer, true)) {
734 // Start postscript viewer
736 LString ps = ChangeExtension (buffer->getFileName(),
738 // push directorypath, if necessary
739 LString path = OnlyPath(buffer->getFileName());
740 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
741 path = buffer->tmppath;
744 bool ret = RunScript(buffer, false, lyxrc->view_ps_command, ps);
751 void MenuFax(Buffer *buffer)
756 // Generate postscript file
757 if (!MenuRunDvips(buffer, true)) {
762 LString ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true);
763 LString path = OnlyPath (buffer->getFileName());
764 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
765 path = buffer->tmppath;
768 if (!lyxrc->fax_program.empty()) {
769 LString help2 = lyxrc->fax_program;
770 help2.subst("$$FName",ps);
772 Systemcalls one(Systemcalls::System, help2);
774 send_fax(ps,lyxrc->fax_command);
779 // Returns false if we fail
780 bool MenuPreview(Buffer *buffer)
787 char real_papersize = buffer->params.papersize;
788 if (real_papersize == PAPER_DEFAULT)
789 real_papersize = lyxrc->default_papersize;
791 switch (real_papersize) {
807 case PAPER_EXECUTIVEPAPER:
810 case PAPER_LEGALPAPER:
813 default: /* If nothing else fits, keep the empty value */
818 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
819 // we HAVE to give a size when the page is in
820 // landscape, so use USletter.
821 paper = " -paper usr";
823 paper = " -paper " + paper;
824 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
828 // push directorypath, if necessary
829 LString path = OnlyPath(buffer->getFileName());
830 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
831 path = buffer->tmppath;
835 LString command = lyxrc->view_dvi_command + paper ;
836 bool ret = RunScript(buffer, false, command);
842 void MenuMakeLaTeX(Buffer *buffer)
845 // Get LaTeX-Filename
846 LString s = SpaceLess(ChangeExtension(
847 buffer->getFileName(),
850 FilePtr myfile(s, FilePtr::read);
852 !AskQuestion(_("File already exists:"),
853 MakeDisplayPath(s,50),
854 _("Do you want to overwrite the file?"))) {
855 minibuffer->Set(_("Canceled"));
859 if (buffer->isDocBook())
860 minibuffer->Set(_("DocBook does not have a latex backend"));
862 if (buffer->isLinuxDoc())
863 RunLinuxDoc(0, buffer->getFileName());
865 buffer->makeLaTeXFile(s, LString(), true);
866 minibuffer->Set(_("Nice LaTeX file saved as"),
868 buffer->markDviDirty();
874 void MenuMakeLinuxDoc(Buffer *buffer)
878 if (!buffer->isLinuxDoc()) {
879 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
883 // Get LinuxDoc-Filename
884 LString s = ChangeExtension (buffer->getFileName(),
887 FilePtr myfile(s, FilePtr::read);
889 !AskQuestion(_("File already exists:"),
890 MakeDisplayPath(s,50),
891 _("Do you want to overwrite the file?"))) {
892 minibuffer->Set(_("Canceled"));
896 minibuffer->Set(_("Building LinuxDoc SGML file `"),
897 MakeDisplayPath(s), "'...");
899 buffer->makeLinuxDocFile(s, 65);
901 minibuffer->Set(_("LinuxDoc SGML file save as"),
907 void MenuMakeDocBook(Buffer *buffer)
911 if (!buffer->isDocBook()) {
912 WriteAlert(_("Error!"), _("Document class must be docbook."));
916 // Get DocBook-Filename
917 LString s = ChangeExtension (buffer->getFileName(),
920 FilePtr myfile(s, FilePtr::read);
922 !AskQuestion(_("File already exists:"),
923 MakeDisplayPath(s,50),
924 _("Do you want to overwrite the file?"))) {
925 minibuffer->Set(_("Canceled"));
929 minibuffer->Set(_("Building DocBook SGML file `"),
930 MakeDisplayPath(s), "'...");
932 buffer->makeDocBookFile(s, 65);
934 minibuffer->Set(_("DocBook SGML file save as"),
940 void MenuMakeAscii(Buffer *buffer)
943 /* get LaTeX-Filename */
944 LString s = ChangeExtension (buffer->getFileName(),
947 FilePtr myfile(s, FilePtr::read);
949 !AskQuestion(_("File already exists:"),
950 MakeDisplayPath(s,50),
951 _("Do you want to overwrite the file?"))) {
952 minibuffer->Set(_("Canceled"));
956 buffer->writeFileAscii(s, lyxrc->ascii_linelen);
958 minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s));
963 void MenuPrint(Buffer *buffer)
970 input_file = ChangeExtension(buffer->getFileName(),
971 lyxrc->print_file_extension,
973 fl_set_input(fd_form_print->input_file, input_file.c_str());
975 if (fd_form_print->form_print->visible) {
976 fl_raise_form(fd_form_print->form_print);
979 fl_show_form(fd_form_print->form_print,
980 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
988 lyxerr.debug("Running QuitLyX.");
990 if (!bufferlist.QwriteAll())
993 lastfiles->writeFile(lyxrc->lastfiles);
995 // Set a flag that we do quitting from the program,
996 // so no refreshes are necessary.
999 // close buffers first
1000 bufferlist.closeAll();
1002 // do any other cleanup procedures now
1003 lyxerr.debug("Deleting tmp dir " + system_tempdir);
1005 DestroyLyXTmpDir(system_tempdir);
1013 // should probably be moved into BufferList (Lgb)
1014 // Perfect target for a thread...
1016 if (!current_view->getScreen() || !current_view->available())
1019 if (current_view->currentBuffer()->isBakClean()
1020 || current_view->currentBuffer()->isReadonly()) {
1021 // We don't save now, but we'll try again later
1022 current_view->getOwner()->resetAutosaveTimer();
1026 minibuffer->Set(_("Autosaving current document..."));
1028 // create autosave filename
1029 LString fname = OnlyPath(current_view->currentBuffer()->getFileName());
1031 fname += OnlyFilename(current_view->currentBuffer()->getFileName());
1034 // tmp_ret will be located (usually) in /tmp
1035 // will that be a problem?
1036 LString tmp_ret = tmpnam(NULL);
1038 pid_t pid = fork(); // If you want to debug the autosave
1039 // you should set pid to -1, and comment out the
1041 if (pid == 0 || pid == -1) {
1042 // pid = -1 signifies that lyx was unable
1043 // to fork. But we will do the save
1045 bool failed = false;
1046 if (!tmp_ret.empty()) {
1047 current_view->currentBuffer()->writeFile(tmp_ret, 1);
1048 // assume successful write of tmp_ret
1049 if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1051 // most likely couldn't move between filesystems
1052 // unless write of tmp_ret failed
1053 // so remove tmp file (if it exists)
1054 remove(tmp_ret.c_str());
1061 // failed to write/rename tmp_ret so try writing direct
1062 if (!current_view->currentBuffer()->writeFile(fname,
1064 // It is dangerous to do this in the child,
1065 // but safe in the parent, so...
1067 minibuffer->Set(_("Autosave Failed!"));
1070 if (pid == 0) { // we are the child so...
1075 current_view->currentBuffer()->markBakClean();
1076 current_view->getOwner()->resetAutosaveTimer();
1081 // (c) CHT Software Service GmbH
1084 // create new file with template
1087 Buffer * NewLyxFile(LString const & filename)
1089 // Split argument by :
1090 LString tmpname = filename;
1092 tmpname.split(name, ':');
1093 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1094 if (name.length() == 1 && isalpha((unsigned char) name[0]) &&
1095 (tmpname.prefixIs("/") || tmpname.prefixIs("\\"))) {
1097 name += tmpname.token(':');
1101 lyxerr.debug("Arg is " + filename);
1102 lyxerr.debug("Name is " + name);
1103 lyxerr.debug("Template is " + tmpname);
1105 // find a free buffer
1106 Buffer *tmpbuf = bufferlist.newFile(name,tmpname);
1108 lastfiles->newFile(tmpbuf->getFileName());
1113 // Insert ascii file (if filename is empty, prompt for one)
1114 void InsertAsciiFile(LString const & f, bool asParagraph)
1117 LyXParagraph *tmppar;
1120 if (!current_view->getScreen()) return;
1122 if (fname.empty()) {
1124 fname = fileDlg.Select(_("File to Insert"),
1125 current_view->getOwner()->currentBuffer()->filepath,
1128 if (fname.empty()) return;
1132 FilePtr myfile(fname, FilePtr::read);
1134 if (!fi.exist() || !fi.readable() || !myfile()) {
1135 WriteFSAlert(_("Error! Cannot open specified file:"),
1136 MakeDisplayPath(fname,50));
1140 tmppar = new LyXParagraph();
1141 tmppar->readSimpleWholeFile(myfile);
1143 // set the end of the string
1144 tmppar->InsertChar(tmppar->last-1,'\0');
1146 // insert the string
1147 current_view->getScreen()->HideCursor();
1149 // clear the selection
1152 current_view->currentBuffer()->text->InsertStringA(tmppar->text);
1154 current_view->currentBuffer()->text->InsertStringB(tmppar->text);
1156 current_view->currentBuffer()->update(1);
1160 void MenuShowTableOfContents()
1162 TocUpdateCB(NULL, 0);
1163 if (fd_form_toc->form_toc->visible) {
1164 fl_raise_form(fd_form_toc->form_toc);
1166 fl_show_form(fd_form_toc->form_toc,
1167 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1168 _("Table Of Contents"));
1173 void MenuInsertLabel(const char *arg)
1175 LString label = arg;
1177 //LString label = fl_show_input(_("Enter new label to insert:"),"");
1179 label = askForText(_("Enter new label to insert:"));
1182 if (!label.empty()) {
1183 InsetLabel *new_inset = new InsetLabel;
1184 new_inset->setContents(label);
1185 current_view->currentBuffer()->insertInset(new_inset);
1191 void MenuInsertRef()
1193 RefUpdateCB(NULL, 0);
1194 if (fd_form_ref->form_ref->visible) {
1195 fl_raise_form(fd_form_ref->form_ref);
1197 fl_show_form(fd_form_ref->form_ref,
1198 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1199 _("Insert Reference"));
1204 void MenuPasteSelection(char at)
1206 if (!current_view->getScreen())
1211 Atom data_prop = XInternAtom(fl_display,
1214 if (data_prop == None)
1216 XConvertSelection(fl_display,
1217 XA_PRIMARY, XA_STRING, data_prop,
1218 fd_form_main->form_main->window, 0);
1223 void FootCB(FL_OBJECT*, long)
1225 if (!current_view->available())
1228 minibuffer->Set(_("Inserting Footnote..."));
1229 current_view->getScreen()->HideCursor();
1230 current_view->currentBuffer()->update(-2);
1231 current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE);
1232 current_view->currentBuffer()->update(1);
1236 void LayoutsCB(int sel, void *)
1240 current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1246 * SGML Linuxdoc support:
1247 * (flag == -1) import SGML file
1248 * (flag == 0) make TeX output
1249 * (flag == 1) make dvi output
1251 int RunLinuxDoc(int flag, LString const & filename)
1260 /* generate a path-less extension name */
1261 name = ChangeExtension (filename, ".sgml", true);
1262 path = OnlyPath (filename);
1263 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1264 path = current_view->currentBuffer()->tmppath;
1269 if (!current_view->available())
1271 current_view->currentBuffer()->makeLinuxDocFile(name,0);
1272 LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
1274 case PAPER_A4PAPER: add_flags = "-p a4"; break;
1275 case PAPER_USLETTER: add_flags = "-p letter"; break;
1276 default: /* nothing to be done yet ;-) */ break;
1284 case -1: /* Import file */
1285 minibuffer->Set(_("Importing LinuxDoc SGML file `"),
1286 MakeDisplayPath(filename), "'...");
1287 s2 = "sgml2lyx " + lyxrc->sgml_extra_options + ' '
1289 if (one.Startscript(Systemcalls::System, s2))
1292 case 0: /* TeX output asked */
1293 minibuffer->Set(_("Converting LinuxDoc SGML to TeX file..."));
1294 s2 = "sgml2latex " + add_flags + " -o tex "
1295 + lyxrc->sgml_extra_options + ' ' + name;
1296 if (one.Startscript(Systemcalls::System, s2))
1299 case 1: /* dvi output asked */
1300 minibuffer->Set(_("Converting LinuxDoc SGML to dvi file..."));
1301 s2 = "sgml2latex " + add_flags + " -o dvi "
1302 + lyxrc->sgml_extra_options + ' ' + name;
1303 if (one.Startscript(Systemcalls::System, s2)) {
1306 current_view->currentBuffer()->markDviClean();
1308 default: /* unknown output */
1315 current_view->currentBuffer()->redraw();
1321 * SGML DocBook support:
1322 * (flag == 1) make dvi output
1324 int RunDocBook(int flag, LString const & filename)
1332 /* generate a path-less extension name */
1333 name = ChangeExtension (filename, ".sgml", true);
1334 path = OnlyPath (filename);
1335 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) {
1336 path = current_view->currentBuffer()->tmppath;
1340 if (!current_view->available())
1343 current_view->currentBuffer()->makeDocBookFile(name,0);
1346 LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->currentBuffer()->params.papersize;
1348 case PAPER_A4PAPER: add_flags = "-p a4"; break;
1349 case PAPER_USLETTER: add_flags = "-p letter"; break;
1350 default: /* nothing to be done yet ;-) */ break;
1357 case 1: /* dvi output asked */
1358 minibuffer->Set(_("Converting DocBook SGML to dvi file..."));
1359 s2 = "sgmltools --backend dvi " + name;
1360 if (one.Startscript(Systemcalls::System, s2)) {
1363 current_view->currentBuffer()->markDviClean();
1365 default: /* unknown output */
1372 current_view->currentBuffer()->redraw();
1377 void AllFloats(char flag, char figmar)
1379 if (!current_view->available())
1382 LyXCursor cursor = current_view->currentBuffer()->text->cursor;
1384 if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1386 && cursor.par->footnotekind != LyXParagraph::FOOTNOTE
1387 && cursor.par->footnotekind != LyXParagraph::MARGIN)
1389 && cursor.par->footnotekind != LyXParagraph::FIG
1390 && cursor.par->footnotekind != LyXParagraph::TAB
1391 && cursor.par->footnotekind != LyXParagraph::WIDE_FIG
1392 && cursor.par->footnotekind != LyXParagraph::WIDE_TAB
1393 && cursor.par->footnotekind != LyXParagraph::ALGORITHM)))
1398 LyXCursor tmpcursor = cursor;
1399 cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos);
1400 cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos);
1402 LyXParagraph *par = current_view->currentBuffer()->paragraph;
1405 if (par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE
1409 par->footnotekind != LyXParagraph::FOOTNOTE
1411 par->footnotekind != LyXParagraph::MARGIN
1416 par->footnotekind != LyXParagraph::FIG
1418 par->footnotekind != LyXParagraph::TAB
1420 par->footnotekind != LyXParagraph::WIDE_FIG
1422 par->footnotekind != LyXParagraph::WIDE_TAB
1424 par->footnotekind != LyXParagraph::ALGORITHM
1429 && par->previous->footnoteflag !=
1430 LyXParagraph::CLOSED_FOOTNOTE){ /* should be */
1431 current_view->currentBuffer()->text->SetCursorIntern(par->previous,
1433 current_view->currentBuffer()->text->OpenFootnote();
1438 if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE
1442 par->footnotekind != LyXParagraph::FOOTNOTE
1444 par->footnotekind != LyXParagraph::MARGIN
1449 par->footnotekind != LyXParagraph::FIG
1451 par->footnotekind != LyXParagraph::TAB
1453 par->footnotekind != LyXParagraph::WIDE_FIG
1455 par->footnotekind != LyXParagraph::WIDE_TAB
1457 par->footnotekind != LyXParagraph::ALGORITHM
1461 current_view->currentBuffer()->text->SetCursorIntern(par, 0);
1462 current_view->currentBuffer()->text->CloseFootnote();
1468 current_view->currentBuffer()->text->SetCursorIntern(cursor.par, cursor.pos);
1469 current_view->redraw();
1470 current_view->fitCursor();
1471 current_view->updateScrollbar();
1475 void MenuLayoutCharacter()
1477 if (fd_form_character->form_character->visible) {
1478 fl_raise_form(fd_form_character->form_character);
1480 fl_show_form(fd_form_character->form_character,
1481 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
1482 _("Character Style"));
1487 inline void DeactivateParagraphButtons ()
1489 fl_deactivate_object (fd_form_paragraph->button_ok);
1490 fl_deactivate_object (fd_form_paragraph->button_apply);
1491 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1492 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1495 inline void ActivateParagraphButtons ()
1497 fl_activate_object (fd_form_paragraph->button_ok);
1498 fl_activate_object (fd_form_paragraph->button_apply);
1499 fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1500 fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1503 inline void DisableParagraphLayout ()
1505 DeactivateParagraphButtons();
1506 fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1507 fl_deactivate_object (fd_form_paragraph->check_lines_top);
1508 fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1509 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1510 fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1511 fl_deactivate_object (fd_form_paragraph->check_noindent);
1512 fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1513 fl_deactivate_object (fd_form_paragraph->radio_align_right);
1514 fl_deactivate_object (fd_form_paragraph->radio_align_left);
1515 fl_deactivate_object (fd_form_paragraph->radio_align_block);
1516 fl_deactivate_object (fd_form_paragraph->radio_align_center);
1517 fl_deactivate_object (fd_form_paragraph->input_space_above);
1518 fl_deactivate_object (fd_form_paragraph->input_space_below);
1519 fl_deactivate_object (fd_form_paragraph->choice_space_above);
1520 fl_deactivate_object (fd_form_paragraph->choice_space_below);
1521 fl_deactivate_object (fd_form_paragraph->check_space_above);
1522 fl_deactivate_object (fd_form_paragraph->check_space_below);
1525 inline void EnableParagraphLayout ()
1527 ActivateParagraphButtons();
1528 fl_activate_object (fd_form_paragraph->input_labelwidth);
1529 fl_activate_object (fd_form_paragraph->check_lines_top);
1530 fl_activate_object (fd_form_paragraph->check_lines_bottom);
1531 fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1532 fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1533 fl_activate_object (fd_form_paragraph->check_noindent);
1534 fl_activate_object (fd_form_paragraph->group_radio_alignment);
1535 fl_activate_object (fd_form_paragraph->radio_align_right);
1536 fl_activate_object (fd_form_paragraph->radio_align_left);
1537 fl_activate_object (fd_form_paragraph->radio_align_block);
1538 fl_activate_object (fd_form_paragraph->radio_align_center);
1539 fl_activate_object (fd_form_paragraph->input_space_above);
1540 fl_activate_object (fd_form_paragraph->input_space_below);
1541 fl_activate_object (fd_form_paragraph->choice_space_above);
1542 fl_activate_object (fd_form_paragraph->choice_space_below);
1543 fl_activate_object (fd_form_paragraph->check_space_above);
1544 fl_activate_object (fd_form_paragraph->check_space_below);
1547 bool UpdateLayoutParagraph()
1549 if (!current_view->getScreen() || !current_view->available()) {
1550 if (fd_form_paragraph->form_paragraph->visible)
1551 fl_hide_form(fd_form_paragraph->form_paragraph);
1555 Buffer * buf = current_view->currentBuffer();
1557 fl_set_input(fd_form_paragraph->input_labelwidth,
1558 buf->text->cursor.par->GetLabelWidthString().c_str());
1559 fl_set_button(fd_form_paragraph->radio_align_right, 0);
1560 fl_set_button(fd_form_paragraph->radio_align_left, 0);
1561 fl_set_button(fd_form_paragraph->radio_align_center, 0);
1562 fl_set_button(fd_form_paragraph->radio_align_block, 0);
1564 int align = buf->text->cursor.par->GetAlign();
1565 if (align == LYX_ALIGN_LAYOUT)
1566 align = lyxstyle.Style(buf->params.textclass,
1567 buf->text->cursor.par->GetLayout())->align;
1570 case LYX_ALIGN_RIGHT:
1571 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1573 case LYX_ALIGN_LEFT:
1574 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1576 case LYX_ALIGN_CENTER:
1577 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1580 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1584 fl_set_button(fd_form_paragraph->check_lines_top,
1585 buf->text->cursor.par->FirstPhysicalPar()->line_top);
1586 fl_set_button(fd_form_paragraph->check_lines_bottom,
1587 buf->text->cursor.par->FirstPhysicalPar()->line_bottom);
1588 fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1589 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1590 fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1591 buf->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1592 fl_set_button(fd_form_paragraph->check_noindent,
1593 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1594 fl_set_input (fd_form_paragraph->input_space_above, "");
1596 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1598 fl_set_choice (fd_form_paragraph->choice_space_above,
1601 case VSpace::DEFSKIP:
1602 fl_set_choice (fd_form_paragraph->choice_space_above,
1605 case VSpace::SMALLSKIP:
1606 fl_set_choice (fd_form_paragraph->choice_space_above,
1609 case VSpace::MEDSKIP:
1610 fl_set_choice (fd_form_paragraph->choice_space_above,
1613 case VSpace::BIGSKIP:
1614 fl_set_choice (fd_form_paragraph->choice_space_above,
1618 fl_set_choice (fd_form_paragraph->choice_space_above,
1621 case VSpace::LENGTH:
1622 fl_set_choice (fd_form_paragraph->choice_space_above,
1624 fl_set_input (fd_form_paragraph->input_space_above,
1625 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1628 fl_set_button (fd_form_paragraph->check_space_above,
1629 buf->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1630 fl_set_input (fd_form_paragraph->input_space_below, "");
1631 switch (buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1633 fl_set_choice (fd_form_paragraph->choice_space_below,
1636 case VSpace::DEFSKIP:
1637 fl_set_choice (fd_form_paragraph->choice_space_below,
1640 case VSpace::SMALLSKIP:
1641 fl_set_choice (fd_form_paragraph->choice_space_below,
1644 case VSpace::MEDSKIP:
1645 fl_set_choice (fd_form_paragraph->choice_space_below,
1648 case VSpace::BIGSKIP:
1649 fl_set_choice (fd_form_paragraph->choice_space_below,
1653 fl_set_choice (fd_form_paragraph->choice_space_below,
1656 case VSpace::LENGTH:
1657 fl_set_choice (fd_form_paragraph->choice_space_below,
1659 fl_set_input (fd_form_paragraph->input_space_below,
1660 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1663 fl_set_button (fd_form_paragraph->check_space_below,
1664 buf->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1666 fl_set_button(fd_form_paragraph->check_noindent,
1667 buf->text->cursor.par->FirstPhysicalPar()->noindent);
1669 if (current_view->currentBuffer()->isReadonly()) {
1670 DisableParagraphLayout();
1672 EnableParagraphLayout();
1677 void MenuLayoutParagraph()
1679 if (UpdateLayoutParagraph()) {
1680 if (fd_form_paragraph->form_paragraph->visible) {
1681 fl_raise_form(fd_form_paragraph->form_paragraph);
1683 fl_show_form(fd_form_paragraph->form_paragraph,
1684 FL_PLACE_MOUSE | FL_FREE_SIZE,FL_FULLBORDER,
1685 _("Paragraph Environment"));
1692 void DeactivateDocumentButtons ()
1694 fl_deactivate_object (fd_form_document->button_ok);
1695 fl_deactivate_object (fd_form_document->button_apply);
1696 fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1697 fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1702 void ActivateDocumentButtons ()
1704 fl_activate_object (fd_form_document->button_ok);
1705 fl_activate_object (fd_form_document->button_apply);
1706 fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1707 fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1711 void DisableDocumentLayout ()
1713 DeactivateDocumentButtons ();
1714 fl_deactivate_object (fd_form_document->group_radio_separation);
1715 fl_deactivate_object (fd_form_document->radio_indent);
1716 fl_deactivate_object (fd_form_document->radio_skip);
1717 fl_deactivate_object (fd_form_document->choice_class);
1718 fl_deactivate_object (fd_form_document->choice_pagestyle);
1719 fl_deactivate_object (fd_form_document->choice_fonts);
1720 fl_deactivate_object (fd_form_document->choice_fontsize);
1721 fl_deactivate_object (fd_form_document->input_float_placement);
1722 fl_deactivate_object (fd_form_document->choice_postscript_driver);
1723 fl_deactivate_object (fd_form_document->choice_inputenc);
1724 fl_deactivate_object (fd_form_document->group_radio_sides);
1725 fl_deactivate_object (fd_form_document->radio_sides_one);
1726 fl_deactivate_object (fd_form_document->radio_sides_two);
1727 fl_deactivate_object (fd_form_document->group_radio_columns);
1728 fl_deactivate_object (fd_form_document->radio_columns_one);
1729 fl_deactivate_object (fd_form_document->radio_columns_two);
1730 fl_deactivate_object (fd_form_document->input_extra);
1731 fl_deactivate_object (fd_form_document->choice_language);
1732 combo_language->deactivate();
1733 fl_deactivate_object (fd_form_document->input_default_skip);
1734 fl_deactivate_object (fd_form_document->choice_default_skip);
1735 fl_deactivate_object (fd_form_document->slider_secnumdepth);
1736 fl_deactivate_object (fd_form_document->slider_tocdepth);
1737 fl_deactivate_object (fd_form_document->choice_spacing);
1738 fl_deactivate_object (fd_form_document->input_spacing);
1739 fl_deactivate_object (fd_form_document->check_use_amsmath);
1743 void EnableDocumentLayout ()
1745 ActivateDocumentButtons ();
1746 fl_activate_object (fd_form_document->group_radio_separation);
1747 fl_activate_object (fd_form_document->radio_indent);
1748 fl_activate_object (fd_form_document->radio_skip);
1749 fl_activate_object (fd_form_document->choice_class);
1750 fl_activate_object (fd_form_document->choice_pagestyle);
1751 fl_activate_object (fd_form_document->choice_fonts);
1752 fl_activate_object (fd_form_document->choice_fontsize);
1753 fl_activate_object (fd_form_document->input_float_placement);
1754 fl_activate_object (fd_form_document->choice_postscript_driver);
1755 fl_activate_object (fd_form_document->choice_inputenc);
1756 fl_activate_object (fd_form_document->group_radio_sides);
1757 fl_activate_object (fd_form_document->radio_sides_one);
1758 fl_activate_object (fd_form_document->radio_sides_two);
1759 fl_activate_object (fd_form_document->group_radio_columns);
1760 fl_activate_object (fd_form_document->radio_columns_one);
1761 fl_activate_object (fd_form_document->radio_columns_two);
1762 fl_activate_object (fd_form_document->input_extra);
1763 fl_activate_object (fd_form_document->choice_language);
1764 combo_language->activate();
1765 fl_activate_object (fd_form_document->input_default_skip);
1766 fl_activate_object (fd_form_document->choice_default_skip);
1767 fl_activate_object (fd_form_document->slider_secnumdepth);
1768 fl_activate_object (fd_form_document->slider_tocdepth);
1769 fl_activate_object (fd_form_document->choice_spacing);
1770 fl_activate_object (fd_form_document->input_spacing);
1771 fl_activate_object (fd_form_document->check_use_amsmath);
1774 bool UpdateLayoutDocument(BufferParams *params)
1776 if (!current_view->getScreen() || !current_view->available()) {
1777 if (fd_form_document->form_document->visible)
1778 fl_hide_form(fd_form_document->form_document);
1783 params = ¤t_view->currentBuffer()->params;
1784 LyXTextClass *tclass = lyxstyle.TextClass(params->textclass);
1786 fl_set_choice_text(fd_form_document->choice_class,
1787 lyxstyle.DescOfClass(params->textclass).c_str());
1788 combo_language->select_text(params->language.c_str());
1790 fl_set_choice_text(fd_form_document->choice_fonts,
1791 params->fonts.c_str());
1792 fl_set_choice_text(fd_form_document->choice_inputenc,
1793 params->inputenc.c_str());
1794 fl_set_choice_text(fd_form_document->choice_postscript_driver,
1795 params->graphicsDriver.c_str());
1797 // ale970405+lasgoutt970513
1798 fl_clear_choice(fd_form_document->choice_fontsize);
1799 fl_addto_choice(fd_form_document->choice_fontsize, "default");
1800 fl_addto_choice(fd_form_document->choice_fontsize,
1801 tclass->opt_fontsize.c_str());
1802 fl_set_choice(fd_form_document->choice_fontsize,
1803 tclass->opt_fontsize.tokenPos('|', params->fontsize) + 2);
1805 // ale970405+lasgoutt970513
1806 fl_clear_choice(fd_form_document->choice_pagestyle);
1807 fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1808 fl_addto_choice(fd_form_document->choice_pagestyle,
1809 tclass->opt_pagestyle.c_str());
1811 fl_set_choice(fd_form_document->choice_pagestyle,
1812 tclass->opt_pagestyle.tokenPos('|', params->pagestyle) + 2);
1814 fl_set_button(fd_form_document->radio_indent, 0);
1815 fl_set_button(fd_form_document->radio_skip, 0);
1818 fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1820 if (params->paragraph_separation == LYX_PARSEP_INDENT)
1821 fl_set_button(fd_form_document->radio_indent, 1);
1823 fl_set_button(fd_form_document->radio_skip, 1);
1825 switch (params->getDefSkip().kind()) {
1826 case VSpace::SMALLSKIP:
1827 fl_set_choice (fd_form_document->choice_default_skip, 1);
1829 case VSpace::MEDSKIP:
1830 fl_set_choice (fd_form_document->choice_default_skip, 2);
1832 case VSpace::BIGSKIP:
1833 fl_set_choice (fd_form_document->choice_default_skip, 3);
1835 case VSpace::LENGTH:
1836 fl_set_choice (fd_form_document->choice_default_skip, 4);
1837 fl_set_input (fd_form_document->input_default_skip,
1838 params->getDefSkip().asLyXCommand().c_str());
1841 fl_set_choice (fd_form_document->choice_default_skip, 2);
1845 fl_set_button(fd_form_document->radio_sides_one, 0);
1846 fl_set_button(fd_form_document->radio_sides_two, 0);
1848 if (params->sides == 2)
1849 fl_set_button(fd_form_document->radio_sides_two, 1);
1851 fl_set_button(fd_form_document->radio_sides_one, 1);
1853 fl_set_button(fd_form_document->radio_columns_one, 0);
1854 fl_set_button(fd_form_document->radio_columns_two, 0);
1856 if (params->columns == 2)
1857 fl_set_button(fd_form_document->radio_columns_two, 1);
1859 fl_set_button(fd_form_document->radio_columns_one, 1);
1861 fl_set_input(fd_form_document->input_spacing, "");
1862 switch (params->spacing.getSpace()) {
1863 case Spacing::Single:
1866 fl_set_choice(fd_form_document->choice_spacing, 1);
1869 case Spacing::Onehalf:
1872 fl_set_choice(fd_form_document->choice_spacing, 2);
1875 case Spacing::Double:
1878 fl_set_choice(fd_form_document->choice_spacing, 3);
1881 case Spacing::Other:
1883 fl_set_choice(fd_form_document->choice_spacing, 4);
1885 sprintf(sval,"%g",params->spacing.getValue());
1886 fl_set_input(fd_form_document->input_spacing, sval);
1892 fl_set_counter_value(fd_form_document->slider_secnumdepth,
1893 params->secnumdepth);
1894 fl_set_counter_value(fd_form_document->slider_tocdepth,
1896 if (!params->float_placement.empty()) { // buffer local (Lgb)
1897 fl_set_input(fd_form_document->input_float_placement,
1898 params->float_placement.c_str());
1900 fl_set_input(fd_form_document->input_float_placement, "");
1902 if (!params->options.empty())
1903 fl_set_input(fd_form_document->input_extra,
1904 params->options.c_str());
1906 fl_set_input(fd_form_document->input_extra, "");
1908 if (current_view->currentBuffer()->isSGML()) {
1909 // bullets not used in SGML derived documents
1910 fl_deactivate_object(fd_form_document->button_bullets);
1911 fl_set_object_lcol(fd_form_document->button_bullets,
1914 fl_activate_object(fd_form_document->button_bullets);
1915 fl_set_object_lcol(fd_form_document->button_bullets,
1919 if (current_view->currentBuffer()->isReadonly()) {
1920 DisableDocumentLayout();
1922 EnableDocumentLayout();
1928 void MenuLayoutDocument()
1930 if (UpdateLayoutDocument()) {
1931 if (fd_form_document->form_document->visible) {
1932 fl_raise_form(fd_form_document->form_document);
1934 fl_show_form(fd_form_document->form_document,
1935 FL_PLACE_MOUSE | FL_FREE_SIZE,
1937 _("Document Layout"));
1943 bool UpdateLayoutQuotes()
1946 if (!current_view->getScreen()
1947 || !current_view->available()
1948 || current_view->currentBuffer()->isReadonly())
1952 fl_set_choice(fd_form_quotes->choice_quotes_language,
1953 current_view->currentBuffer()->params.quotes_language + 1);
1954 fl_set_button(fd_form_quotes->radio_single, 0);
1955 fl_set_button(fd_form_quotes->radio_double, 0);
1957 if (current_view->currentBuffer()->params.quotes_times == InsetQuotes::SingleQ)
1958 fl_set_button(fd_form_quotes->radio_single, 1);
1960 fl_set_button(fd_form_quotes->radio_double, 1);
1961 } else if (fd_form_quotes->form_quotes->visible) {
1962 fl_hide_form(fd_form_quotes->form_quotes);
1967 void MenuLayoutQuotes()
1969 if (UpdateLayoutQuotes()) {
1970 if (fd_form_quotes->form_quotes->visible) {
1971 fl_raise_form(fd_form_quotes->form_quotes);
1973 fl_show_form(fd_form_quotes->form_quotes,
1974 FL_PLACE_MOUSE | FL_FREE_SIZE,
1982 bool UpdateLayoutPreamble()
1985 if (!current_view->getScreen() || ! current_view->available())
1989 fl_set_input(fd_form_preamble->input_preamble,
1990 current_view->currentBuffer()->params.preamble.c_str());
1992 if (current_view->currentBuffer()->isReadonly()) {
1993 fl_deactivate_object(fd_form_preamble->input_preamble);
1994 fl_deactivate_object(fd_form_preamble->button_ok);
1995 fl_deactivate_object(fd_form_preamble->button_apply);
1996 fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1997 fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
2000 fl_activate_object(fd_form_preamble->input_preamble);
2001 fl_activate_object(fd_form_preamble->button_ok);
2002 fl_activate_object(fd_form_preamble->button_apply);
2003 fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
2004 fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
2006 } else if (fd_form_preamble->form_preamble->visible) {
2007 fl_hide_form(fd_form_preamble->form_preamble);
2012 void MenuLayoutPreamble()
2014 if (UpdateLayoutPreamble()) {
2015 if (fd_form_preamble->form_preamble->visible) {
2016 fl_raise_form(fd_form_preamble->form_preamble);
2018 fl_show_form(fd_form_preamble->form_preamble,
2019 FL_PLACE_MOUSE | FL_FREE_SIZE,
2021 _("LaTeX Preamble"));
2026 void MenuLayoutSave()
2028 if (!current_view->getScreen() || ! current_view->available())
2031 if (AskQuestion(_("Do you want to save the current settings"),
2032 _("for Character, Document, Paper and Quotes"),
2033 _("as default for new documents?")))
2034 current_view->currentBuffer()->saveParamsAsDefaults();
2040 InsetInfo *new_inset = new InsetInfo();
2041 current_view->currentBuffer()->insertInset(new_inset);
2042 new_inset->Edit(0,0);
2043 //current_view->currentBuffer()->update(-1);
2049 if (current_view->available()) {
2050 minibuffer->Set(_("Open/Close..."));
2051 current_view->getScreen()->HideCursor();
2053 current_view->currentBuffer()->update(-2);
2054 current_view->currentBuffer()->text->OpenStuff();
2055 current_view->currentBuffer()->update(0);
2061 if (current_view->available()) {
2062 minibuffer->Set(_("Open/Close..."));
2063 current_view->getScreen()->HideCursor();
2065 current_view->currentBuffer()->update(-2);
2066 current_view->currentBuffer()->text->ToggleFootnote();
2067 current_view->currentBuffer()->update(0);
2074 /* if (current_view->currentBuffer()->the_locking_inset) {
2075 minibuffer->Set(_("Undo not yet supported in math mode"));
2079 if (current_view->available()) {
2080 minibuffer->Set(_("Undo"));
2081 current_view->getScreen()->HideCursor();
2083 current_view->currentBuffer()->update(-2);
2084 if (!current_view->currentBuffer()->text->TextUndo())
2085 minibuffer->Set(_("No further undo information"));
2087 current_view->currentBuffer()->update(-1);
2094 if (current_view->currentBuffer()->the_locking_inset) {
2095 minibuffer->Set(_("Redo not yet supported in math mode"));
2099 if (current_view->available()) {
2100 minibuffer->Set(_("Redo"));
2101 current_view->getScreen()->HideCursor();
2103 current_view->currentBuffer()->update(-2);
2104 if (!current_view->currentBuffer()->text->TextRedo())
2105 minibuffer->Set(_("No further redo information"));
2107 current_view->currentBuffer()->update(-1);
2112 void HyphenationPoint()
2114 if (current_view->available()) {
2115 current_view->getScreen()->HideCursor();
2116 current_view->currentBuffer()->update(-2);
2117 InsetSpecialChar *new_inset =
2118 new InsetSpecialChar(InsetSpecialChar::HYPHENATION);
2119 current_view->currentBuffer()->insertInset(new_inset);
2120 //current_view->currentBuffer()->update(-1);
2127 if (current_view->available()) {
2128 current_view->getScreen()->HideCursor();
2129 current_view->currentBuffer()->update(-2);
2130 InsetSpecialChar *new_inset =
2131 new InsetSpecialChar(InsetSpecialChar::LDOTS);
2132 current_view->currentBuffer()->insertInset(new_inset);
2137 void EndOfSentenceDot()
2139 if (current_view->available()) {
2140 current_view->getScreen()->HideCursor();
2141 current_view->currentBuffer()->update(-2);
2142 InsetSpecialChar *new_inset =
2143 new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE);
2144 current_view->currentBuffer()->insertInset(new_inset);
2149 void MenuSeparator()
2151 if (current_view->available()) {
2152 current_view->getScreen()->HideCursor();
2153 current_view->currentBuffer()->update(-2);
2154 InsetSpecialChar *new_inset =
2155 new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR);
2156 current_view->currentBuffer()->insertInset(new_inset);
2157 //current_view->currentBuffer()->update(-1);
2164 if (current_view->available()) {
2165 current_view->getScreen()->HideCursor();
2166 current_view->currentBuffer()->update(-2);
2167 current_view->currentBuffer()->text->InsertChar(LYX_META_NEWLINE);
2168 current_view->currentBuffer()->update(-1);
2173 void ProtectedBlank()
2175 if (current_view->available()) {
2176 current_view->getScreen()->HideCursor();
2177 current_view->currentBuffer()->update(-2);
2178 current_view->currentBuffer()->text->InsertChar(LYX_META_PROTECTED_SEPARATOR);
2179 current_view->currentBuffer()->update(-1);
2186 if (current_view->available()) {
2187 current_view->getScreen()->HideCursor();
2188 current_view->currentBuffer()->update(-2);
2189 current_view->currentBuffer()->text->InsertChar(LYX_META_HFILL);
2190 current_view->currentBuffer()->update(-1);
2195 /* -------> These CB's use ToggleFree() as the (one and only?) font-changer.
2196 They also show the current font state. */
2199 void ToggleAndShow(LyXFont const &);
2202 void FontSizeCB(LString const & size)
2204 LyXFont font(LyXFont::ALL_IGNORE);
2205 font.setGUISize(size);
2206 ToggleAndShow(font);
2212 LyXFont font(LyXFont::ALL_IGNORE);
2213 font.setEmph(LyXFont::TOGGLE);
2214 ToggleAndShow(font);
2220 LyXFont font(LyXFont::ALL_IGNORE);
2221 font.setNoun(LyXFont::TOGGLE);
2222 ToggleAndShow(font);
2228 LyXFont font(LyXFont::ALL_IGNORE);
2229 font.setSeries(LyXFont::BOLD_SERIES);
2230 ToggleAndShow(font);
2236 LyXFont font(LyXFont::ALL_IGNORE);
2237 font.setUnderbar(LyXFont::TOGGLE);
2238 ToggleAndShow(font);
2244 LyXFont font(LyXFont::ALL_IGNORE);
2245 font.setFamily(LyXFont::TYPEWRITER_FAMILY); // no good
2246 ToggleAndShow(font);
2252 LyXFont font(LyXFont::ALL_IGNORE);
2253 font.setFamily(LyXFont::SANS_FAMILY);
2254 ToggleAndShow(font);
2260 LyXFont font(LyXFont::ALL_IGNORE);
2261 font.setFamily(LyXFont::ROMAN_FAMILY);
2262 ToggleAndShow(font);
2268 LyXFont font(LyXFont::ALL_IGNORE);
2269 font.setLatex (LyXFont::TOGGLE);
2270 ToggleAndShow(font);
2276 LyXFont font(LyXFont::ALL_INHERIT);
2277 ToggleAndShow(font);
2281 /* -------> Returns the current font and depth by printing a message. In the
2282 * future perhaps we could try to implement a callback to the button-bar.
2283 * That is, `light' the bold button when the font is currently bold, etc.
2285 LString CurrentState()
2288 if (current_view->available()) {
2289 // I think we should only show changes from the default
2291 Buffer * buffer = current_view->currentBuffer();
2292 LyXFont font = buffer->text->real_current_font;
2293 LyXFont defaultfont = lyxstyle.TextClass(buffer->
2294 params.textclass)->defaultfont;
2295 font.reduce(defaultfont);
2296 state = _("Font: ") + font.stateText();
2298 int depth = buffer->text->GetDepth();
2300 state += LString(_(", Depth: ")) + depth;
2306 /* -------> Does the actual toggle job of the XxxCB() calls above.
2307 * Also shows the current font state.
2310 void ToggleAndShow(LyXFont const & font)
2312 if (current_view->available()) {
2313 current_view->getScreen()->HideCursor();
2314 current_view->currentBuffer()->update(-2);
2315 current_view->currentBuffer()->text->ToggleFree(font, toggleall);
2316 current_view->currentBuffer()->update(1);
2318 // removed since it overrides the ToggleFree Message about the style
2319 // Since Styles are more "High Level" than raw fonts I think the user
2320 // prefers it like this Matthias
2321 // FontStateShowCB( 0, 0 );
2325 void MarginCB(FL_OBJECT *, long)
2327 if (current_view->available()) {
2328 minibuffer->Set(_("Inserting margin note..."));
2329 current_view->getScreen()->HideCursor();
2330 current_view->currentBuffer()->update(-2);
2331 current_view->currentBuffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN);
2332 current_view->currentBuffer()->update(1);
2337 void FigureCB(FL_OBJECT *, long)
2339 if (fd_form_figure->form_figure->visible) {
2340 fl_raise_form(fd_form_figure->form_figure);
2342 fl_show_form(fd_form_figure->form_figure,
2343 FL_PLACE_MOUSE, FL_FULLBORDER,
2344 _("Insert Figure"));
2349 void TableCB(FL_OBJECT *, long)
2351 if (fd_form_table->form_table->visible) {
2352 fl_raise_form(fd_form_table->form_table);
2354 fl_show_form(fd_form_table->form_table,
2355 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
2361 void CopyEnvironmentCB()
2363 if (current_view->available()) {
2364 current_view->currentBuffer()->text->copyEnvironmentType();
2365 /* clear the selection, even if mark_set */
2366 current_view->getScreen()->ToggleSelection();
2367 current_view->currentBuffer()->text->ClearSelection();
2368 current_view->currentBuffer()->update(-2);
2369 minibuffer->Set(_("Paragraph environment type copied"));
2374 void PasteEnvironmentCB()
2376 if (current_view->available()) {
2377 current_view->currentBuffer()->text->pasteEnvironmentType();
2378 minibuffer->Set(_("Paragraph environment type set"));
2379 current_view->currentBuffer()->update(1);
2386 if (current_view->available()) {
2387 current_view->currentBuffer()->text->CopySelection();
2388 /* clear the selection, even if mark_set */
2389 current_view->getScreen()->ToggleSelection();
2390 current_view->currentBuffer()->text->ClearSelection();
2391 current_view->currentBuffer()->update(-2);
2392 minibuffer->Set(_("Copy"));
2399 if (current_view->available()) {
2400 current_view->getScreen()->HideCursor();
2401 current_view->currentBuffer()->update(-2);
2402 current_view->currentBuffer()->text->CutSelection();
2403 current_view->currentBuffer()->update(1);
2404 minibuffer->Set(_("Cut"));
2411 if (!current_view->available()) return;
2413 minibuffer->Set(_("Paste"));
2414 current_view->getScreen()->HideCursor();
2415 /* clear the selection */
2416 current_view->getScreen()->ToggleSelection();
2417 current_view->currentBuffer()->text->ClearSelection();
2418 current_view->currentBuffer()->update(-2);
2421 current_view->currentBuffer()->text->PasteSelection();
2422 current_view->currentBuffer()->update(1);
2424 /* clear the selection */
2425 current_view->getScreen()->ToggleSelection();
2426 current_view->currentBuffer()->text->ClearSelection();
2427 current_view->currentBuffer()->update(-2);
2431 void MeltCB(FL_OBJECT *, long)
2433 if (!current_view->available()) return;
2435 minibuffer->Set(_("Melt"));
2436 current_view->getScreen()->HideCursor();
2438 current_view->currentBuffer()->update(-2);
2439 current_view->currentBuffer()->text->MeltFootnoteEnvironment();
2440 current_view->currentBuffer()->update(1);
2444 // Change environment depth.
2445 // if decInc == 0, depth change taking mouse button number into account
2446 // if decInc == 1, increment depth
2447 // if decInc == -1, decrement depth
2448 void DepthCB(FL_OBJECT *ob, long decInc)
2452 /* When decInc != 0, fake a mouse button. This allows us to
2453 implement depth-plus and depth-min commands. RVDK_PATCH_5. */
2454 /* check out wether ob is defined, too (Matthias) */
2457 else if (!decInc && ob) {
2458 button = fl_get_button_numb(ob);
2461 if (current_view->available()) {
2462 current_view->getScreen()->HideCursor();
2463 current_view->currentBuffer()->update(-2);
2465 current_view->currentBuffer()->text->IncDepth();
2467 current_view->currentBuffer()->text->DecDepth();
2468 current_view->currentBuffer()->update(1);
2469 minibuffer->Set(_("Changed environment depth"
2470 " (in possible range, maybe not)"));
2475 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
2476 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
2477 LyXFont UserFreeFont()
2479 LyXFont font(LyXFont::ALL_IGNORE);
2482 pos = fl_get_choice(fd_form_character->choice_family);
2484 case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
2485 case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
2486 case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
2487 case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
2488 case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
2491 pos = fl_get_choice(fd_form_character->choice_series);
2493 case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
2494 case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
2495 case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
2496 case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
2499 pos = fl_get_choice(fd_form_character->choice_shape);
2501 case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2502 case 2: font.setShape(LyXFont::UP_SHAPE); break;
2503 case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2504 case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2505 case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2506 case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2509 pos = fl_get_choice(fd_form_character->choice_size);
2511 case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2512 case 2: font.setSize(LyXFont::SIZE_TINY); break;
2513 case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2514 case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2515 case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2516 case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2517 case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2518 case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2519 case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2520 case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2521 case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2522 case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2523 case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2524 case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2527 pos = fl_get_choice(fd_form_character->choice_bar);
2529 case 1: font.setEmph(LyXFont::IGNORE);
2530 font.setUnderbar(LyXFont::IGNORE);
2531 font.setNoun(LyXFont::IGNORE);
2532 font.setLatex(LyXFont::IGNORE);
2534 case 2: font.setEmph(LyXFont::TOGGLE); break;
2535 case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2536 case 4: font.setNoun(LyXFont::TOGGLE); break;
2537 case 5: font.setLatex(LyXFont::TOGGLE); break;
2538 case 6: font.setEmph(LyXFont::INHERIT);
2539 font.setUnderbar(LyXFont::INHERIT);
2540 font.setNoun(LyXFont::INHERIT);
2541 font.setLatex(LyXFont::INHERIT);
2545 pos = fl_get_choice(fd_form_character->choice_color);
2547 case 1: font.setColor(LyXFont::IGNORE_COLOR); break;
2548 case 2: font.setColor(LyXFont::NONE); break;
2549 case 3: font.setColor(LyXFont::BLACK); break;
2550 case 4: font.setColor(LyXFont::WHITE); break;
2551 case 5: font.setColor(LyXFont::RED); break;
2552 case 6: font.setColor(LyXFont::GREEN); break;
2553 case 7: font.setColor(LyXFont::BLUE); break;
2554 case 8: font.setColor(LyXFont::CYAN); break;
2555 case 9: font.setColor(LyXFont::MAGENTA); break;
2556 case 10: font.setColor(LyXFont::YELLOW); break;
2557 case 11: font.setColor(LyXFont::INHERIT_COLOR); break;
2566 ToggleAndShow(UserFreeFont());
2570 /* callbacks for form form_title */
2571 void TimerCB(FL_OBJECT *, long)
2573 // only if the form still exists
2574 if (fd_form_title->form_title != NULL) {
2575 if (fd_form_title->form_title->visible) {
2576 fl_hide_form(fd_form_title->form_title);
2578 fl_free_form(fd_form_title->form_title);
2579 fd_form_title->form_title = NULL;
2584 /* callbacks for form form_paragraph */
2586 void ParagraphVSpaceCB(FL_OBJECT* obj, long )
2588 // "Synchronize" the choices and input fields, making it
2589 // impossible to commit senseless data.
2591 const FD_form_paragraph* fp = fd_form_paragraph;
2593 if (obj == fp->choice_space_above) {
2594 if (fl_get_choice (fp->choice_space_above) != 7) {
2595 fl_set_input (fp->input_space_above, "");
2596 ActivateParagraphButtons();
2598 } else if (obj == fp->choice_space_below) {
2599 if (fl_get_choice (fp->choice_space_below) != 7) {
2600 fl_set_input (fp->input_space_below, "");
2601 ActivateParagraphButtons();
2603 } else if (obj == fp->input_space_above) {
2604 LString input = fl_get_input (fp->input_space_above);
2606 if (input.empty()) {
2607 fl_set_choice (fp->choice_space_above, 1);
2608 ActivateParagraphButtons();
2610 else if (isValidGlueLength (input)) {
2611 fl_set_choice (fp->choice_space_above, 7);
2612 ActivateParagraphButtons();
2615 fl_set_choice (fp->choice_space_above, 7);
2616 DeactivateParagraphButtons();
2618 } else if (obj == fp->input_space_below) {
2619 LString input = fl_get_input (fp->input_space_below);
2621 if (input.empty()) {
2622 fl_set_choice (fp->choice_space_below, 1);
2623 ActivateParagraphButtons();
2625 else if (isValidGlueLength (input)) {
2626 fl_set_choice (fp->choice_space_below, 7);
2627 ActivateParagraphButtons();
2630 fl_set_choice (fp->choice_space_below, 7);
2631 DeactivateParagraphButtons();
2637 void ParagraphApplyCB(FL_OBJECT *, long)
2639 if (!current_view->available())
2642 bool line_top, line_bottom;
2643 bool pagebreak_top, pagebreak_bottom;
2644 VSpace space_top, space_bottom;
2646 LString labelwidthstring;
2649 // If a vspace kind is "Length" but there's no text in
2650 // the input field, reset the kind to "None".
2651 if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2652 && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2653 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2655 if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2656 && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2657 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2660 line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2661 line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2662 pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2663 pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2664 switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2665 case 1: space_top = VSpace(VSpace::NONE); break;
2666 case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2667 case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2668 case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2669 case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2670 case 6: space_top = VSpace(VSpace::VFILL); break;
2671 case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2673 if (fl_get_button (fd_form_paragraph->check_space_above))
2674 space_top.setKeep (true);
2675 switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2676 case 1: space_bottom = VSpace(VSpace::NONE); break;
2677 case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2678 case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2679 case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2680 case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2681 case 6: space_bottom = VSpace(VSpace::VFILL); break;
2682 case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2684 if (fl_get_button (fd_form_paragraph->check_space_below))
2685 space_bottom.setKeep (true);
2687 if (fl_get_button(fd_form_paragraph->radio_align_left))
2688 align = LYX_ALIGN_LEFT;
2689 else if (fl_get_button(fd_form_paragraph->radio_align_right))
2690 align = LYX_ALIGN_RIGHT;
2691 else if (fl_get_button(fd_form_paragraph->radio_align_center))
2692 align = LYX_ALIGN_CENTER;
2694 align = LYX_ALIGN_BLOCK;
2696 labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2697 noindent = fl_get_button(fd_form_paragraph->check_noindent);
2699 current_view->currentBuffer()->text->SetParagraph(line_top,
2708 current_view->currentBuffer()->update(1);
2709 minibuffer->Set(_("Paragraph layout set"));
2713 void ParagraphCancelCB(FL_OBJECT *, long)
2715 fl_hide_form(fd_form_paragraph->form_paragraph);
2719 void ParagraphOKCB(FL_OBJECT *ob, long data)
2721 ParagraphApplyCB(ob, data);
2722 ParagraphCancelCB(ob, data);
2726 /* callbacks for form form_character */
2728 void CharacterApplyCB(FL_OBJECT *, long)
2730 // we set toggleall locally here, since it should be true for
2731 // all other uses of ToggleAndShow() (JMarc)
2732 toggleall = fl_get_button(fd_form_character->check_toggle_all);
2733 ToggleAndShow( UserFreeFont());
2738 void CharacterCloseCB(FL_OBJECT *, long)
2740 fl_hide_form(fd_form_character->form_character);
2744 void CharacterOKCB(FL_OBJECT *ob, long data)
2746 CharacterApplyCB(ob,data);
2747 CharacterCloseCB(ob,data);
2751 /* callbacks for form form_document */
2753 void UpdateDocumentButtons(BufferParams const ¶ms)
2755 fl_set_choice(fd_form_document->choice_pagestyle, 1);
2757 if (params.sides == 2)
2758 fl_set_button(fd_form_document->radio_sides_two, 1);
2760 fl_set_button(fd_form_document->radio_sides_one, 1);
2762 if (params.columns == 2)
2763 fl_set_button(fd_form_document->radio_columns_two, 1);
2765 fl_set_button(fd_form_document->radio_columns_one, 1);
2767 fl_set_input(fd_form_document->input_extra, params.options.c_str());
2768 fl_set_counter_value(fd_form_document->slider_secnumdepth,
2769 params.secnumdepth);
2770 fl_set_counter_value(fd_form_document->slider_tocdepth,
2775 void ChoiceClassCB(FL_OBJECT *ob, long)
2778 if (lyxstyle.Load(fl_get_choice(ob)-1)) {
2779 if (AskQuestion(_("Should I set some parameters to"),
2780 fl_get_choice_text(ob),
2781 _("the defaults of this document class?"))) {
2782 BufferParams params = BufferParams();
2783 params.textclass = fl_get_choice(ob)-1;
2784 params.useClassDefaults();
2785 UpdateLayoutDocument(¶ms);
2786 UpdateDocumentButtons(params);
2789 // unable to load new style
2790 WriteAlert(_("Conversion Errors!"),
2791 _("Unable to switch to new document class."),
2792 _("Reverting to original document class."));
2793 fl_set_choice(fd_form_document->choice_class,
2794 GetCurrentTextClass() + 1);
2800 void DocumentDefskipCB(FL_OBJECT *obj, long)
2802 // "Synchronize" the choice and the input field, so that it
2803 // is impossible to commit senseless data.
2804 const FD_form_document* fd = fd_form_document;
2806 if (obj == fd->choice_default_skip) {
2807 if (fl_get_choice (fd->choice_default_skip) != 4) {
2808 fl_set_input (fd->input_default_skip, "");
2809 ActivateDocumentButtons();
2811 } else if (obj == fd->input_default_skip) {
2813 const char* input = fl_get_input (fd->input_default_skip);
2816 fl_set_choice (fd->choice_default_skip, 2);
2817 ActivateDocumentButtons();
2818 } else if (isValidGlueLength (input)) {
2819 fl_set_choice (fd->choice_default_skip, 4);
2820 ActivateDocumentButtons();
2822 fl_set_choice (fd->choice_default_skip, 4);
2823 DeactivateDocumentButtons();
2829 void DocumentSpacingCB(FL_OBJECT *obj, long)
2831 // "Synchronize" the choice and the input field, so that it
2832 // is impossible to commit senseless data.
2833 const FD_form_document* fd = fd_form_document;
2835 if (obj == fd->choice_spacing
2836 && fl_get_choice (fd->choice_spacing) != 4) {
2837 fl_set_input(fd->input_spacing, "");
2838 } else if (obj == fd->input_spacing) {
2840 const char* input = fl_get_input (fd->input_spacing);
2843 fl_set_choice (fd->choice_spacing, 1);
2845 fl_set_choice (fd->choice_spacing, 4);
2851 void DocumentApplyCB(FL_OBJECT *, long)
2854 BufferParams *params = &(current_view->currentBuffer()->params);
2855 current_view->currentBuffer()->params.language =
2856 combo_language->getline();
2858 // If default skip is a "Length" but there's no text in the
2859 // input field, reset the kind to "Medskip", which is the default.
2860 if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2861 && !*(fl_get_input (fd_form_document->input_default_skip))) {
2862 fl_set_choice (fd_form_document->choice_default_skip, 2);
2865 /* this shouldn't be done automatically IMO. For example I write german
2866 * documents with an american keyboard very often. Matthias */
2868 /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2869 fl_get_choice(fd_form_document->choice_language)); */
2871 fl_get_choice_text(fd_form_document->choice_fonts);
2873 fl_get_choice_text(fd_form_document->choice_inputenc);
2875 fl_get_choice_text(fd_form_document->choice_fontsize);
2877 fl_get_choice_text(fd_form_document->choice_pagestyle);
2878 params->graphicsDriver =
2879 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2880 params->use_amsmath =
2881 fl_get_button(fd_form_document->check_use_amsmath);
2883 if (!current_view->available())
2886 char new_class = fl_get_choice(fd_form_document->choice_class) - 1;
2887 if (params->textclass != new_class) {
2888 // try to load new_class
2889 if (lyxstyle.Load(new_class)) {
2890 // successfully loaded
2892 minibuffer->Set(_("Converting document to new document class..."));
2893 int ret = current_view->currentBuffer()->
2895 SwitchLayoutsBetweenClasses(current_view->currentBuffer()->
2898 current_view->currentBuffer()->
2904 s= _("One paragraph couldn't be converted");
2907 s += _(" paragraphs couldn't be converted");
2909 WriteAlert(_("Conversion Errors!"),s,
2910 _("into chosen document class"));
2913 params->textclass = new_class;
2915 // problem changing class -- warn user and retain old style
2916 WriteAlert(_("Conversion Errors!"),
2917 _("Unable to switch to new document class."),
2918 _("Reverting to original document class."));
2919 fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2923 char tmpsep = params->paragraph_separation;
2924 if (fl_get_button(fd_form_document->radio_indent))
2925 params->paragraph_separation = LYX_PARSEP_INDENT;
2927 params->paragraph_separation = LYX_PARSEP_SKIP;
2928 if (tmpsep != params->paragraph_separation)
2931 VSpace tmpdefskip = params->getDefSkip();
2932 switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2933 case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2934 case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2935 case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2936 case 4: params->setDefSkip(
2937 VSpace (LyXGlueLength (fl_get_input
2938 (fd_form_document->input_default_skip))));
2940 // DocumentDefskipCB assures that this never happens
2941 default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2943 if (!(tmpdefskip == params->getDefSkip()))
2946 if (fl_get_button(fd_form_document->radio_columns_two))
2947 params->columns = 2;
2949 params->columns = 1;
2950 if (fl_get_button(fd_form_document->radio_sides_two))
2955 Spacing tmpSpacing = params->spacing;
2956 switch(fl_get_choice(fd_form_document->choice_spacing)) {
2958 lyxerr.debug("Spacing: SINGLE");
2959 params->spacing.set(Spacing::Single);
2962 lyxerr.debug("Spacing: ONEHALF");
2963 params->spacing.set(Spacing::Onehalf);
2966 lyxerr.debug("Spacing: DOUBLE");
2967 params->spacing.set(Spacing::Double);
2970 lyxerr.debug("Spacing: OTHER");
2971 params->spacing.set(Spacing::Other,
2972 fl_get_input(fd_form_document->input_spacing));
2975 if (tmpSpacing != params->spacing)
2978 signed char tmpchar = (signed char)
2979 fl_get_counter_value(fd_form_document->slider_secnumdepth);;
2980 if (params->secnumdepth != tmpchar)
2982 params->secnumdepth = tmpchar;
2984 params->tocdepth = (signed char)
2985 fl_get_counter_value(fd_form_document->slider_tocdepth);;
2987 params->float_placement =
2988 fl_get_input(fd_form_document->input_float_placement);
2990 // More checking should be done to ensure the string doesn't have
2991 // spaces or illegal placement characters in it. (thornley)
2994 current_view->redoCurrentBuffer();
2996 minibuffer->Set(_("Document layout set"));
2997 current_view->currentBuffer()->markDirty();
3000 fl_get_input(fd_form_document->input_extra);
3005 void DocumentCancelCB(FL_OBJECT *, long)
3007 fl_hide_form(fd_form_document->form_document);
3011 void DocumentOKCB(FL_OBJECT *ob, long data)
3013 DocumentCancelCB(ob,data);
3014 DocumentApplyCB(ob,data);
3018 void DocumentBulletsCB(FL_OBJECT *, long)
3021 // bullet callbacks etc. in bullet_panel.C -- ARRae
3027 if (!current_view->getScreen())
3030 current_view->getScreen()->HideCursor();
3032 current_view->currentBuffer()->update(-2);
3035 if (!current_view->currentBuffer()->text->GotoNextNote()) {
3036 if (current_view->currentBuffer()->text->cursor.pos
3037 || current_view->currentBuffer()->text->cursor.par !=
3038 current_view->currentBuffer()->text->FirstParagraph())
3040 tmp = current_view->currentBuffer()->text->cursor;
3041 current_view->currentBuffer()->text->cursor.par =
3042 current_view->currentBuffer()->text->FirstParagraph();
3043 current_view->currentBuffer()->text->cursor.pos = 0;
3044 if (!current_view->currentBuffer()->text->GotoNextNote()) {
3045 current_view->currentBuffer()->text->cursor = tmp;
3046 minibuffer->Set(_("No more notes"));
3050 minibuffer->Set(_("No more notes"));
3054 current_view->currentBuffer()->update(0);
3055 current_view->currentBuffer()->text->sel_cursor =
3056 current_view->currentBuffer()->text->cursor;
3060 void InsertCorrectQuote()
3062 Buffer *cbuffer = current_view->currentBuffer();
3065 if (cbuffer->text->cursor.pos )
3066 c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1);
3070 cbuffer->insertInset(new InsetQuotes(c, cbuffer->params));
3074 /* callbacks for form form_quotes */
3076 void QuotesApplyCB(FL_OBJECT *, long)
3078 if (!current_view->available())
3081 minibuffer->Set(_("Quotes type set"));
3082 //current_view->currentBuffer()->params.quotes_language =
3083 // fl_get_choice(fd_form_quotes->choice_quotes_language) - 1;
3084 InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
3085 switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
3087 lga = InsetQuotes::EnglishQ;
3090 lga = InsetQuotes::SwedishQ;
3093 lga = InsetQuotes::GermanQ;
3096 lga = InsetQuotes::PolishQ;
3099 lga = InsetQuotes::FrenchQ;
3102 lga = InsetQuotes::DanishQ;
3105 current_view->currentBuffer()->params.quotes_language = lga;
3106 if (fl_get_button(fd_form_quotes->radio_single))
3107 current_view->currentBuffer()->
3108 params.quotes_times = InsetQuotes::SingleQ;
3110 current_view->currentBuffer()->
3111 params.quotes_times = InsetQuotes::DoubleQ;
3115 void QuotesCancelCB(FL_OBJECT *, long)
3117 fl_hide_form(fd_form_quotes->form_quotes);
3121 void QuotesOKCB(FL_OBJECT *ob, long data)
3123 QuotesApplyCB(ob, data);
3124 QuotesCancelCB(ob, data);
3129 /* callbacks for form form_preamble */
3131 void PreambleCancelCB(FL_OBJECT *, long)
3133 fl_hide_form(fd_form_preamble->form_preamble);
3137 void PreambleApplyCB(FL_OBJECT *, long)
3139 if (!current_view->available())
3142 current_view->currentBuffer()->params.preamble =
3143 fl_get_input(fd_form_preamble->input_preamble);
3144 current_view->currentBuffer()->markDirty();
3145 minibuffer->Set(_("LaTeX preamble set"));
3149 void PreambleOKCB(FL_OBJECT *ob, long data)
3151 PreambleApplyCB(ob, data);
3152 PreambleCancelCB(ob, data);
3156 /* callbacks for form form_table */
3158 void TableApplyCB(FL_OBJECT *, long)
3161 if (!current_view->getScreen())
3164 // check for tables in tables
3165 if (current_view->currentBuffer()->text->cursor.par->table){
3166 WriteAlert(_("Impossible Operation!"),
3167 _("Cannot insert table in table."),
3172 minibuffer->Set(_("Inserting table..."));
3174 ysize = (int)(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
3175 xsize = (int)(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
3178 current_view->getScreen()->HideCursor();
3180 current_view->currentBuffer()->update(-2);
3182 current_view->currentBuffer()->text->SetCursorParUndo();
3183 current_view->currentBuffer()->text->FreezeUndo();
3185 current_view->currentBuffer()->text->BreakParagraph();
3186 current_view->currentBuffer()->update(-1);
3188 if (current_view->currentBuffer()->text->cursor.par->Last()) {
3189 current_view->currentBuffer()->text->CursorLeft();
3191 current_view->currentBuffer()->text->BreakParagraph();
3192 current_view->currentBuffer()->update(-1);
3195 current_view->currentBuffer()->text->current_font.setLatex(LyXFont::OFF);
3196 //if (!fl_get_button(fd_form_table->check_latex)){
3197 // insert the new wysiwy table
3198 current_view->currentBuffer()->text->SetLayout(0); // standard layout
3199 if (current_view->currentBuffer()->text->cursor.par->footnoteflag ==
3200 LyXParagraph::NO_FOOTNOTE) {
3201 current_view->currentBuffer()->
3202 text->SetParagraph(0, 0,
3204 VSpace (0.3 * current_view->currentBuffer()->
3205 params.spacing.getValue(),
3207 VSpace (0.3 * current_view->currentBuffer()->
3208 params.spacing.getValue(),
3215 current_view->currentBuffer()->text->SetParagraph(0, 0,
3217 VSpace(VSpace::NONE),
3218 VSpace(VSpace::NONE),
3223 current_view->currentBuffer()->text->cursor.par->table = new LyXTable(xsize, ysize);
3225 for (i=0; i<xsize * ysize - 1; i++)
3226 current_view->currentBuffer()->text->cursor.par->InsertChar(0,LYX_META_NEWLINE);
3227 current_view->currentBuffer()->text->RedoParagraph();
3229 current_view->currentBuffer()->text->UnFreezeUndo();
3231 current_view->currentBuffer()->update(1);
3232 minibuffer->Set(_("Table inserted"));
3236 void TableCancelCB(FL_OBJECT *, long)
3238 fl_hide_form(fd_form_table->form_table);
3242 void TableOKCB(FL_OBJECT *ob, long data)
3244 TableApplyCB(ob,data);
3245 TableCancelCB(ob,data);
3249 /* callbacks for form form_print */
3251 void PrintCancelCB(FL_OBJECT *, long)
3253 fl_hide_form(fd_form_print->form_print);
3256 static bool LStringOnlyContains (LString const & LStr, const char * cset)
3258 const char * cstr = LStr.c_str() ;
3260 return strspn(cstr,cset) == strlen(cstr) ;
3263 void PrintApplyCB(FL_OBJECT *, long)
3265 if (!current_view->available())
3267 Buffer *buffer = current_view->currentBuffer();
3268 LString path = OnlyPath(buffer->getFileName());
3271 if (fl_get_button(fd_form_print->radio_even_pages))
3272 pageflag = lyxrc->print_evenpage_flag + ' ';
3273 else if (fl_get_button(fd_form_print->radio_odd_pages))
3274 pageflag = lyxrc->print_oddpage_flag + ' ';
3276 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
3277 // User may give a page (range) list
3278 // User may print multiple (unsorted) copies
3279 LString pages = fl_get_input(fd_form_print->input_pages);
3280 pages.subst(';',',');
3281 pages.subst('+',',');
3283 pages.frontStrip () ;
3284 while (!pages.empty()) { // a page range was given
3286 //int dashpos ; // unused
3287 pages = pages.split (piece, ',') ;
3289 piece.frontStrip () ;
3290 if ( !LStringOnlyContains (piece, "0123456789-") ) {
3291 WriteAlert(_("ERROR! Unable to print!"),
3292 _("Check 'range of pages'!"));
3295 if ( -1 == piece.charPos ('-') ) { // not found
3296 pageflag += lyxrc->print_pagerange_flag + piece + '-' + piece + ' ' ;
3297 } else if ( piece.suffixIs("-") ) { // missing last page
3298 pageflag += lyxrc->print_pagerange_flag + piece + 1000 + ' ' ;
3299 } else if ( piece.prefixIs("-") ) { // missing first page
3300 pageflag += lyxrc->print_pagerange_flag + 1 + piece + ' ' ;
3302 pageflag += lyxrc->print_pagerange_flag + piece + ' ' ;
3306 LString copies = fl_get_input(fd_form_print->input_copies);
3308 copies.frontStrip () ;
3309 if (!copies.empty()) { // a number of copies was given
3310 if ( !LStringOnlyContains (copies, "0123456789") ) {
3311 WriteAlert(_("ERROR! Unable to print!"),
3312 _("Check 'number of copies'!"));
3315 if (fl_get_button(fd_form_print->do_unsorted))
3316 pageflag += lyxrc->print_copies_flag;
3318 pageflag += lyxrc->print_collcopies_flag;
3319 pageflag += " " + copies + ' ' ;
3322 LString reverseflag;
3323 if (fl_get_button(fd_form_print->radio_order_reverse))
3324 reverseflag = lyxrc->print_reverse_flag + ' ';
3326 LString orientationflag;
3327 if (buffer->params.orientation == ORIENTATION_LANDSCAPE)
3328 orientationflag = lyxrc->print_landscape_flag + ' ';
3330 LString ps_file = SpaceLess(fl_get_input(fd_form_print->input_file));
3331 LString printer = fl_get_input(fd_form_print->input_printer);
3334 LString printerflag;
3335 if (lyxrc->print_adapt_output // printer name should be passed to dvips
3336 && ! printer.empty()) // a printer name has been given
3337 printerflag = lyxrc->print_to_printer + printer + ' ';
3340 if (!lyxrc->print_extra_options.empty())
3341 extraflags = lyxrc->print_extra_options + ' ';
3343 LString command = lyxrc->print_command + ' '
3344 + printerflag + pageflag + reverseflag
3345 + orientationflag + extraflags;
3347 char real_papersize = buffer->params.papersize;
3348 if (real_papersize == PAPER_DEFAULT)
3349 real_papersize = lyxrc->default_papersize;
3353 switch (real_papersize) {
3354 case PAPER_USLETTER:
3369 case PAPER_EXECUTIVEPAPER:
3372 case PAPER_LEGALPAPER:
3375 default: /* If nothing else fits, keep an empty value... */
3379 if (buffer->params.use_geometry
3380 && buffer->params.papersize2 == VM_PAPER_CUSTOM
3381 && !lyxrc->print_paper_dimension_flag.empty()
3382 && !buffer->params.paperwidth.empty()
3383 && !buffer->params.paperheight.empty()) {
3384 // using a custom papersize
3386 command += lyxrc->print_paper_dimension_flag + ' ';
3387 command += buffer->params.paperwidth + ',';
3388 command += buffer->params.paperheight + ' ';
3389 } else if (!lyxrc->print_paper_flag.empty()
3391 && (real_papersize != PAPER_USLETTER ||
3392 buffer->params.orientation == ORIENTATION_PORTRAIT)) {
3393 command += " " + lyxrc->print_paper_flag + " " + paper + " ";
3395 if (fl_get_button(fd_form_print->radio_file))
3396 command += lyxrc->print_to_file + '\"'
3397 + MakeAbsPath(ps_file, path)
3399 else if (!lyxrc->print_spool_command.empty())
3400 command += lyxrc->print_to_file
3401 + '\"' + ps_file + '\"';
3403 // push directorypath, if necessary
3404 if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){
3405 path = buffer->tmppath;
3410 if (!lyxrc->print_spool_command.empty() &&
3411 !fl_get_button(fd_form_print->radio_file)) {
3412 LString command2 = lyxrc->print_spool_command + ' ';
3413 if (!printer.empty())
3414 command2 += lyxrc->print_spool_printerprefix
3416 // First run dvips and, if succesful, then spool command
3417 if ((result = RunScript(buffer, true, command))) {
3418 result = RunScript(buffer, false, command2, ps_file);
3421 result = RunScript(buffer, false, command);
3425 WriteAlert(_("Error:"),
3426 _("Unable to print"),
3427 _("Check that your parameters are correct"));
3431 void PrintOKCB(FL_OBJECT *ob, long data)
3433 PrintCancelCB(ob, data);
3434 PrintApplyCB(ob,data);
3438 /* callbacks for form form_figure */
3440 void FigureApplyCB(FL_OBJECT *, long)
3442 if (!current_view->available())
3445 Buffer * buffer = current_view->currentBuffer();
3446 if(buffer->isReadonly()) // paranoia
3449 minibuffer->Set(_("Inserting figure..."));
3450 if (fl_get_button(fd_form_figure->radio_inline)
3451 || buffer->text->cursor.par->table) {
3452 InsetFig * new_inset = new InsetFig(100, 20, buffer);
3453 buffer->insertInset(new_inset);
3454 minibuffer->Set(_("Figure inserted"));
3455 new_inset->Edit(0, 0);
3459 current_view->getScreen()->HideCursor();
3463 buffer->text->SetCursorParUndo();
3464 buffer->text->FreezeUndo();
3466 buffer->text->BreakParagraph();
3469 if (buffer->text->cursor.par->Last()) {
3470 buffer->text->CursorLeft();
3472 buffer->text->BreakParagraph();
3476 // The standard layout should always be numer 0;
3477 buffer->text->SetLayout(0);
3479 if (buffer->text->cursor.par->footnoteflag ==
3480 LyXParagraph::NO_FOOTNOTE) {
3481 buffer->text->SetParagraph(0, 0,
3483 VSpace (0.3 * buffer->params.spacing.getValue(),
3486 buffer->params.spacing.getValue(),
3488 LYX_ALIGN_CENTER, LString(), 0);
3490 buffer->text->SetParagraph(0, 0,
3492 VSpace(VSpace::NONE),
3493 VSpace(VSpace::NONE),
3500 Inset *new_inset = NULL;
3502 new_inset = new InsetFig(100, 100, buffer);
3503 buffer->insertInset(new_inset);
3504 new_inset->Edit(0, 0);
3506 minibuffer->Set(_("Figure inserted"));
3507 buffer->text->UnFreezeUndo();
3511 void FigureCancelCB(FL_OBJECT *, long)
3513 fl_hide_form(fd_form_figure->form_figure);
3517 void FigureOKCB(FL_OBJECT *ob, long data)
3519 FigureApplyCB(ob,data);
3520 FigureCancelCB(ob,data);
3523 void ScreenApplyCB(FL_OBJECT *, long)
3525 lyxrc->roman_font_name = fl_get_input(fd_form_screen->input_roman);
3526 lyxrc->sans_font_name = fl_get_input(fd_form_screen->input_sans);
3527 lyxrc->typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3528 lyxrc->font_norm = fl_get_input(fd_form_screen->input_font_norm);
3529 lyxrc->zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3530 fontloader.update();
3532 // All buffers will need resize
3533 bufferlist.resize();
3535 minibuffer->Set(_("Screen options set"));
3539 void ScreenCancelCB(FL_OBJECT *, long)
3541 fl_hide_form(fd_form_screen->form_screen);
3545 void ScreenOKCB(FL_OBJECT *ob, long data)
3547 ScreenCancelCB(ob,data);
3548 ScreenApplyCB(ob,data);
3554 if (!current_view->available())
3557 fl_set_button(fd_latex_options->accents,
3558 (int)current_view->currentBuffer()->params.allowAccents);
3560 if (fd_latex_options->LaTeXOptions->visible) {
3561 fl_raise_form(fd_latex_options->LaTeXOptions);
3563 fl_show_form(fd_latex_options->LaTeXOptions,
3564 FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
3565 _("LaTeX Options"));
3570 // This function runs "configure" and then rereads lyx.defaults to
3571 // reconfigure the automatic settings.
3574 minibuffer->Set(_("Running configure..."));
3576 // Run configure in user lyx directory
3577 PathPush(user_lyxdir);
3578 Systemcalls one(Systemcalls::System,
3579 AddName(system_lyxdir,"configure"));
3581 minibuffer->Set(_("Reloading configuration..."));
3582 lyxrc->Read(LibFileSearch(LString(), "lyxrc.defaults"));
3583 WriteAlert(_("The system has been reconfigured."),
3584 _("You need to restart LyX to make use of any"),
3585 _("updated document class specifications."));
3589 /* these functions are for the spellchecker */
3590 char* NextWord(float &value)
3592 if (!current_view->available()){
3597 char* string = current_view->currentBuffer()->text->SelectNextWord(value);
3603 void SelectLastWord()
3605 if (!current_view->available())
3608 current_view->getScreen()->HideCursor();
3610 current_view->currentBuffer()->text->SelectSelectedWord();
3611 current_view->getScreen()->ToggleSelection(false);
3612 current_view->currentBuffer()->update(0);
3616 void EndOfSpellCheck()
3618 if (!current_view->available())
3621 current_view->getScreen()->HideCursor();
3623 current_view->currentBuffer()->text->SelectSelectedWord();
3624 current_view->currentBuffer()->text->ClearSelection();
3625 current_view->currentBuffer()->update(0);
3629 void ReplaceWord(LString const & replacestring)
3631 if (!current_view->getScreen())
3634 current_view->getScreen()->HideCursor();
3635 current_view->currentBuffer()->update(-2);
3637 /* clear the selection (if there is any) */
3638 current_view->getScreen()->ToggleSelection(false);
3639 current_view->currentBuffer()->text->
3640 ReplaceSelectionWithString(replacestring.c_str());
3642 current_view->currentBuffer()->text->SetSelectionOverString(replacestring.c_str());
3644 // Go back so that replacement string is also spellchecked
3645 for (int i=-1; i< replacestring.length(); i++) {
3646 current_view->currentBuffer()->text->CursorLeftIntern();
3648 current_view->currentBuffer()->update(1);
3650 // End of spellchecker stuff
3655 // Table of Contents
3665 static TocList* toclist = NULL;
3668 void TocSelectCB(FL_OBJECT *ob, long)
3670 if (!current_view->available())
3673 TocList* tmptoclist = toclist;
3674 int i = fl_get_browser(ob);
3677 for (a=1; a<i && tmptoclist->next; a++){
3678 tmptoclist = tmptoclist->next;
3685 LyXParagraph *par = current_view->currentBuffer()->paragraph;
3686 while (par && (par->GetFirstCounter(0) != tmptoclist->counter[0] ||
3687 par->GetFirstCounter(1) != tmptoclist->counter[1] ||
3688 par->GetFirstCounter(2) != tmptoclist->counter[2] ||
3689 par->GetFirstCounter(3) != tmptoclist->counter[3] ||
3690 par->GetFirstCounter(4) != tmptoclist->counter[4] ||
3691 par->GetFirstCounter(5) != tmptoclist->counter[5] ||
3692 par->appendix != tmptoclist->appendix)) {
3693 par = par->LastPhysicalPar()->Next();
3698 current_view->currentBuffer()->text->SetCursor(par, 0);
3699 current_view->currentBuffer()->text->sel_cursor =
3700 current_view->currentBuffer()->text->cursor;
3701 current_view->currentBuffer()->update(0);
3704 WriteAlert(_("Error"),
3705 _("Couldn't find this label"),
3706 _("in current document."));
3712 void TocCancelCB(FL_OBJECT *, long)
3714 fl_hide_form(fd_form_toc->form_toc);
3718 void TocUpdateCB(FL_OBJECT *, long)
3720 static LyXParagraph* stapar = NULL;
3721 TocList *tmptoclist = NULL;
3723 /* deleted the toclist */
3726 tmptoclist = toclist->next;
3728 toclist = tmptoclist;
3732 tmptoclist = toclist;
3735 fl_clear_browser(fd_form_toc->browser_toc);
3736 if (!current_view->available()) {
3737 fl_add_browser_line(fd_form_toc->browser_toc, _("*** No Document ***"));
3740 fl_hide_object(fd_form_toc->browser_toc);
3741 /* get the table of contents */
3742 LyXParagraph *par = current_view->currentBuffer()->paragraph;
3744 char* line = new char[200];
3751 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3755 labeltype = lyxstyle.Style(current_view->currentBuffer()->params.textclass,
3756 par->GetLayout())->labeltype;
3758 if (labeltype >= LABEL_COUNTER_CHAPTER
3759 && labeltype <= LABEL_COUNTER_CHAPTER +
3760 current_view->currentBuffer()->params.tocdepth) {
3761 /* insert this into the table of contents */
3762 /* first indent a little bit */
3766 lyxstyle.TextClass(current_view->currentBuffer()->
3767 params.textclass)->maxcounter) * 4 + 2;
3771 /* then the labelstring */
3773 if (!par->labelstring.empty()) {
3774 while (pos < 199 && i < par->labelstring.length()) {
3775 line[pos] = par->labelstring[i];
3784 /* now the contents */
3786 while (pos < 199 && i < par->last) {
3787 c = par->GetChar(i);
3788 if (isprint((unsigned char) c) || c >= 128) {
3795 fl_add_browser_line(fd_form_toc->browser_toc, line);
3797 /* make a toclist entry */
3799 tmptoclist = new TocList;
3800 toclist = tmptoclist;
3802 tmptoclist->next = new TocList;
3803 tmptoclist = tmptoclist->next;
3806 tmptoclist->next = NULL;
3808 for (a=0; a<6; a++){
3809 tmptoclist->counter[a] = par->GetFirstCounter(a);
3811 tmptoclist->appendix = par->appendix;
3813 par = par->LastPhysicalPar()->Next();
3817 fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3818 fl_show_object(fd_form_toc->browser_toc);
3822 /* callbacks for form form_ref */
3823 void RefSelectCB(FL_OBJECT *, long data)
3825 if (!current_view->available())
3829 fl_get_browser_line(fd_form_ref->browser_ref,
3830 fl_get_browser(fd_form_ref->browser_ref));
3831 LString u = fl_get_input(fd_form_ref->ref_name);
3838 current_view->getOwner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3848 if(current_view->currentBuffer()->isSGML())
3849 t += "[" + u + "]" + "{" + s + "}";
3854 new InsetRef(t, current_view->currentBuffer());
3855 current_view->currentBuffer()->insertInset(new_inset);
3859 void RefUpdateCB(FL_OBJECT *, long)
3861 if (!current_view->available()) {
3862 fl_clear_browser(fd_form_ref->browser_ref);
3866 FL_OBJECT * brow = fd_form_ref->browser_ref;
3868 // Get the current line, in order to restore it later
3869 LString currentstr = fl_get_browser_line(brow,
3870 fl_get_browser(brow));
3872 fl_clear_browser(brow);
3874 LString refs = current_view->currentBuffer()->getReferenceList('\n');
3877 #if FL_REVISION > 85
3878 fl_addto_browser_chars(brow,refs.c_str());
3879 int total_lines = fl_get_browser_maxline(brow);
3880 for (int i = 1; i <= total_lines ; i++) {
3881 if (fl_get_browser_line(brow, i) == currentstr) {
3886 fl_set_browser_topline(brow, topline);
3888 // Keep the old ugly code for xforms 0.81 compatibility
3893 curr_ref = refs.token('\n',ref_num);
3894 if (curr_ref.empty())
3896 fl_add_browser_line(brow,curr_ref.c_str());
3901 if (!fl_get_browser_maxline(brow)) {
3902 fl_add_browser_line(brow,
3903 _("*** No labels found in document ***"));
3904 fl_deactivate_object(brow);
3906 fl_select_browser_line(brow, topline);
3907 fl_activate_object(brow);
3909 if (current_view->currentBuffer()->isReadonly()) {
3910 // would be better to de/activate insert buttons
3911 // but that's more work... besides this works. ARRae
3912 fl_hide_form(fd_form_ref->form_ref);
3914 if (!current_view->currentBuffer()->isSGML()) {
3915 fl_deactivate_object(fd_form_ref->ref_name);
3916 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3919 fl_activate_object(fd_form_ref->ref_name);
3920 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3925 void RefHideCB(FL_OBJECT *, long)
3927 fl_hide_form(fd_form_ref->form_ref);
3931 void UpdateInset(Inset* inset, bool mark_dirty)
3936 /* very first check for locking insets*/
3937 if (current_view->currentBuffer()->the_locking_inset == inset){
3938 if (current_view->currentBuffer()->text->UpdateInset(inset)){
3939 current_view->update();
3941 if (current_view->currentBuffer()->isLyxClean())
3942 minibuffer->setTimer(4);
3943 current_view->currentBuffer()->markDirty();
3945 current_view->updateScrollbar();
3950 /* first check the current buffer */
3951 if (current_view->available()){
3952 current_view->getScreen()->HideCursor();
3953 current_view->currentBuffer()->update(-3);
3954 if (current_view->currentBuffer()->text->UpdateInset(inset)){
3956 current_view->currentBuffer()->update(1);
3958 current_view->currentBuffer()->update(3);
3963 // check all buffers
3964 bufferlist.updateInset(inset, mark_dirty);
3969 /* these functions return 1 if an error occured,
3971 int LockInset(UpdatableInset* inset)
3973 if (!current_view->currentBuffer()->the_locking_inset && inset){
3974 current_view->currentBuffer()->the_locking_inset = inset;
3981 void ShowLockedInsetCursor(long x, long y, int asc, int desc)
3983 if (current_view->currentBuffer()->the_locking_inset &&
3984 current_view->getScreen()){
3985 y += current_view->currentBuffer()->text->cursor.y;
3986 current_view->getScreen()->ShowManualCursor(x, y,
3992 void HideLockedInsetCursor(long x, long y, int asc, int desc)
3994 if (current_view->currentBuffer()->the_locking_inset &&
3995 current_view->getScreen()){
3996 y += current_view->currentBuffer()->text->cursor.y;
3997 current_view->getScreen()->HideManualCursor(x, y,
4003 void FitLockedInsetCursor(long x, long y, int asc, int desc)
4005 if (current_view->currentBuffer()->the_locking_inset &&
4006 current_view->getScreen()){
4007 y += current_view->currentBuffer()->text->cursor.y;
4008 if (current_view->getScreen()->FitManualCursor(x, y, asc, desc))
4009 current_view->updateScrollbar();
4014 int UnlockInset(UpdatableInset* inset)
4017 current_view->currentBuffer()->the_locking_inset == inset){
4018 inset->InsetUnlock();
4019 current_view->currentBuffer()->the_locking_inset = NULL;
4020 current_view->currentBuffer()->text->FinishUndo();
4023 return bufferlist.unlockInset(inset);
4027 void LockedInsetStoreUndo(Undo::undo_kind kind)
4029 if (!current_view->currentBuffer()->the_locking_inset)
4030 return; // shouldn't happen
4031 if (kind == Undo::EDIT) // in this case insets would not be stored!
4032 kind = Undo::FINISH;
4033 current_view->currentBuffer()->text->SetUndo(kind,
4034 current_view->currentBuffer()->text->cursor.par->
4035 ParFromPos(current_view->currentBuffer()->text->cursor.pos)->previous,
4036 current_view->currentBuffer()->text->cursor.par->
4037 ParFromPos(current_view->currentBuffer()->text->cursor.pos)->next);
4041 void PutInsetIntoInsetUpdateList(Inset* inset)
4044 InsetUpdateStruct* tmp = new InsetUpdateStruct();
4046 tmp->next = InsetUpdateList;
4047 InsetUpdateList = tmp;
4052 void UpdateInsetUpdateList()
4054 InsetUpdateStruct *tmp = InsetUpdateList;
4056 UpdateInset(tmp->inset, false); // "false" because no document change
4060 /* delete the update list */
4061 while (InsetUpdateList) {
4062 tmp = InsetUpdateList;
4063 InsetUpdateList = InsetUpdateList->next;
4066 InsetUpdateList = NULL;
4070 // I know we shouldn't put anything in here but this seems the fastest
4071 // way to do this (and the cleanest for now). This function just inserts
4072 // a newline in the LString and the inserts 'depth'-spaces so that the
4073 // code is indented in the right way!!!
4074 void addNewlineAndDepth(LString &file, int const depth)
4077 for (int j=0;j< depth;j++)