]> git.lyx.org Git - lyx.git/blob - src/lyx_cb.C
f51570f0fd8dd3e8d21ce1322e718c6159fc69e3
[lyx.git] / src / lyx_cb.C
1 /* This file is part of
2  * ====================================================== 
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1995 Matthias Ettrich,
7  *          Copyright 1995-2000 The LyX Team.
8  *
9  * ====================================================== */
10
11 #include <config.h>
12
13 #include <fstream>
14 #include <algorithm>
15 #include <iostream>
16
17 #include "LString.h"
18 #include FORMS_H_LOCATION
19 #include "lyx.h"
20 #include "layout_forms.h"
21 #include "bullet_forms.h"
22 #include "print_form.h"
23 #include "form1.h"
24 #include "lyx_main.h"
25 #include "lyx_cb.h"
26 #include "insets/insetref.h"
27 #include "insets/insetlabel.h"
28 #include "insets/figinset.h"
29 #include "lyxfunc.h"
30 #include "minibuffer.h"
31 #include "combox.h"
32 #include "bufferlist.h"
33 #include "filedlg.h"
34 #include "lyx_gui_misc.h"
35 #include "LyXView.h"
36 #include "BufferView.h"
37 #include "lastfiles.h"
38 #include "bufferview_funcs.h"
39 #include "support/FileInfo.h"
40 #include "support/syscall.h"
41 #include "support/filetools.h"
42 #include "support/path.h"
43 #include "lyxserver.h"
44 #include "FontLoader.h"
45 #include "lyxrc.h"
46 #include "lyxtext.h"
47 #include "CutAndPaste.h"
48 #include "TextCache.h"
49
50 using std::ifstream;
51 using std::copy;
52 using std::back_inserter;
53 using std::endl;
54 using std::cout;
55 using std::ios;
56 using std::istream_iterator;
57 using std::pair;
58 using std::vector;
59 using std::sort;
60
61 extern Combox * combo_language;
62 extern Combox * combo_language2;
63 extern BufferList bufferlist;
64 extern void show_symbols_form();
65 extern FD_form_title * fd_form_title;
66 extern FD_form_paragraph * fd_form_paragraph;
67 extern FD_form_character * fd_form_character;
68 extern FD_form_document * fd_form_document;
69 extern FD_form_quotes * fd_form_quotes;
70 extern FD_form_preamble * fd_form_preamble;
71 extern FD_form_table * fd_form_table;
72 extern FD_form_print * fd_form_print;
73 extern FD_form_figure * fd_form_figure;
74 extern FD_form_screen * fd_form_screen;
75 extern FD_form_toc * fd_form_toc;
76 extern FD_form_ref * fd_form_ref;
77 extern FD_LaTeXOptions * fd_latex_options;
78 extern FD_form_bullet * fd_form_bullet;
79
80 extern BufferView * current_view; // called too many times in this file...
81
82 extern void DeleteSimpleCutBuffer(); /* for the cleanup when exiting */
83
84 extern bool send_fax(string const & fname, string const & sendcmd);
85 extern void MenuSendto();
86
87 extern LyXServer * lyxserver;
88
89 // this should be static, but I need it in buffer.C
90 bool quitting;  // flag, that we are quitting the program
91 extern bool finished; // all cleanup done just let it run through now.
92
93 char ascii_type; /* for selection notify callbacks */
94
95 bool scrolling = false;
96
97 // This is used to make the dreaded font toggle problem hopefully go
98 // away. Definitely not the best solution, but I think it sorta works.
99 bool toggleall = true;
100
101 /* 
102    This is the inset locking stuff needed for mathed --------------------
103
104    an inset can simple call LockInset in it's edit call and *ONLY* in it's
105    edit call.
106    Inset::Edit() can only be called by the main lyx module.
107
108    Then the inset may modify the menu's and/or iconbars. 
109
110    Unlocking is either done by LyX or the inset itself with a UnlockInset-call
111
112    During the lock, all button and keyboard events will be modified
113    and send to the inset through the following inset-features. Note that
114    Inset::InsetUnlock will be called from inside UnlockInset. It is meant
115    to contain the code for restoring the menus and things like this.
116
117    
118    virtual void InsetButtonPress(int x, int y, int button);
119    virtual void InsetButtonRelease(int x, int y, int button);
120    virtual void InsetKeyPress(XKeyEvent *ev);
121    virtual void InsetMotionNotify(int x, int y, int state);
122    virtual void InsetUnlock();
123
124    If a inset wishes any redraw and/or update it just has to call
125    UpdateInset(this).
126    It's is completly irrelevant, where the inset is. UpdateInset will
127    find it in any paragraph in any buffer. 
128    Of course the_locking_inset and the insets in the current paragraph/buffer
129    are checked first, so no performance problem should occur.
130    
131    Hope that's ok for the beginning, Alejandro,
132    sorry that I needed so much time,
133
134                   Matthias
135    */
136
137 //void UpdateInset(BufferView * bv, Inset * inset, bool mark_dirty = true);
138
139 /* these functions return 1 if an error occured, 
140    otherwise 0 */
141 // Now they work only for updatable insets. [Alejandro 080596]
142 //int LockInset(UpdatableInset * inset);
143 void ToggleLockedInsetCursor(long x, long y, int asc, int desc);
144 //void FitLockedInsetCursor(long x, long y, int asc, int desc);
145 //int UnlockInset(UpdatableInset * inset);
146 //void LockedInsetStoreUndo(Undo::undo_kind kind);
147
148 /* this is for asyncron updating. UpdateInsetUpdateList will be called
149    automatically from LyX. Just insert the Inset into the Updatelist */
150 //void UpdateInsetUpdateList();
151 //void PutInsetIntoInsetUpdateList(Inset * inset);
152
153 //InsetUpdateStruct * InsetUpdateList = 0;
154
155
156 /*
157   -----------------------------------------------------------------------
158  */
159
160 /* some function prototypes */
161
162 int RunLinuxDoc(BufferView *, int, string const &);
163 int RunDocBook(int, string const &);
164 void MenuWrite(Buffer * buf);
165 void MenuWriteAs(Buffer * buffer);
166 void MenuReload(Buffer * buf);
167 void MenuLayoutSave();
168
169
170 void ShowMessage(Buffer * buf,
171                  string const & msg1,
172                  string const & msg2 = string(),
173                  string const & msg3 = string(), int delay = 6)
174 {
175         if (lyxrc.use_gui) {
176                 buf->getUser()->owner()->getMiniBuffer()->Set(msg1, msg2,
177                                                               msg3, delay);
178         } else {
179                 // can somebody think of something more clever? cerr?
180                 cout << msg1 << msg2 << msg3 << endl;
181         }
182 }
183
184
185 // only called from this file, LyXView and LyXFunc
186 char updatetimer = 0;
187
188
189 // only called from BufferView_pimpl and LyXFunc
190 void FreeUpdateTimer()
191 {
192         /* a real free timer would be better but I don't know 
193          * how to do this with xforms */
194         updatetimer = 0;
195 }
196
197
198 // Only called from LyXFunc
199 void SetUpdateTimer(float time)
200 {
201         fl_set_timer(current_view->owner()->getMainForm()->timer_update, time);
202         updatetimer = 1;
203 }
204
205
206 //
207 // Menu callbacks
208 //
209
210 //
211 // File menu
212 //
213
214 // should be moved to lyxfunc.C
215 void MenuWrite(Buffer * buffer)
216 {
217         XFlush(fl_display);
218         if (!buffer->save()) {
219                 string fname = buffer->fileName();
220                 string s = MakeAbsPath(fname);
221                 if (AskQuestion(_("Save failed. Rename and try again?"),
222                                 MakeDisplayPath(s, 50),
223                                 _("(If not, document is not saved.)"))) {
224                         MenuWriteAs(buffer);
225                 }
226         } else {
227                 lastfiles->newFile(buffer->fileName());
228         }
229 }
230
231
232 // should be moved to BufferView.C
233 // Half of this func should be in LyXView, the rest in BufferView.
234 void MenuWriteAs(Buffer * buffer)
235 {
236         // Why do we require BufferView::text to be able to write a
237         // document? I see no point in that. (Lgb)
238         //if (!bv->text) return;
239
240         string fname = buffer->fileName();
241         string oldname = fname;
242         LyXFileDlg fileDlg;
243
244         ProhibitInput(current_view);
245         fileDlg.SetButton(0, _("Documents"), lyxrc.document_path);
246         fileDlg.SetButton(1, _("Templates"), lyxrc.template_path);
247
248         if (!IsLyXFilename(fname))
249                 fname += ".lyx";
250
251         fname = fileDlg.Select(_("Enter Filename to Save Document as"), 
252                                OnlyPath(fname),
253                                "*.lyx", 
254                                OnlyFilename(fname));
255         AllowInput(current_view);
256
257         if (fname.empty()) {
258                 return;
259         }
260         // Make sure the absolute filename ends with appropriate suffix
261         string s = MakeAbsPath(fname);
262         if (!IsLyXFilename(s))
263                 s += ".lyx";
264
265         // Same name as we have already?
266         if (s == oldname) {
267                 if (!AskQuestion(_("Same name as document already has:"),
268                                  MakeDisplayPath(s, 50),
269                                  _("Save anyway?")))
270                         return;
271                 // Falls through to name change and save
272         } 
273         // No, but do we have another file with this name open?
274         else if (bufferlist.exists(s)) {
275                 if (AskQuestion(_("Another document with same name open!"),
276                                 MakeDisplayPath(s, 50),
277                                 _("Replace with current document?")))
278                         {
279                                 bufferlist.close(bufferlist.getBuffer(s));
280
281                                 // Ok, change the name of the buffer, but don't save!
282                                 buffer->fileName(s);
283                                 buffer->markDirty();
284
285                                 ShowMessage(buffer, _("Document renamed to '"),
286                                                 MakeDisplayPath(s), _("', but not saved..."));
287                         }
288                 return;
289         } // Check whether the file exists
290         else {
291                 FileInfo myfile(s);
292                 if (myfile.isOK() && !AskQuestion(_("Document already exists:"), 
293                                                   MakeDisplayPath(s, 50),
294                                                   _("Replace file?")))
295                         return;
296         }
297
298         // Ok, change the name of the buffer
299         buffer->fileName(s);
300         buffer->markDirty();
301         // And save
302         // Small bug: If the save fails, we have irreversible changed the name
303         // of the document.
304         MenuWrite(buffer);
305 }    
306
307
308 int MenuRunLaTeX(Buffer * buffer)
309 {
310         int ret = 0;
311
312         if (buffer->isLinuxDoc())
313                 ret = RunLinuxDoc(buffer->getUser(), 1, buffer->fileName());
314         else if (buffer->isLiterate())
315                 ret = buffer->runLiterate();
316         else if (buffer->isDocBook())
317                 ret = RunDocBook(1, buffer->fileName());
318         else
319                 ret = buffer->runLaTeX();
320    
321         if (ret > 0) {
322                 string s;
323                 string t;
324                 if (ret == 1) {
325                         s = _("One error detected");
326                         t = _("You should try to fix it.");
327                 } else {
328                         s += tostr(ret);
329                         s += _(" errors detected.");
330                         t = _("You should try to fix them.");
331                 }
332                 WriteAlert(_("There were errors during the LaTeX run."), s, t);
333         }
334         return ret;
335 }
336
337
338 int MenuBuildProg(Buffer * buffer)
339 {
340         int ret = 0;
341         
342         if (buffer->isLiterate())
343                 ret = buffer->buildProgram();
344         else {
345                 string s = _("Wrong type of document");
346                 string t = _("The Build operation is not allowed in this document");
347                 WriteAlert(_("There were errors during the Build process."), s, t);
348                 return 1;
349         }
350         
351         if (ret > 0) {
352                 string s;
353                 string t;
354                 if (ret == 1) {
355                         s = _("One error detected");
356                         t = _("You should try to fix it.");
357                 } else {
358                         s += tostr(ret);
359                         s += _(" errors detected.");
360                         t = _("You should try to fix them.");
361                 }
362                 WriteAlert(_("There were errors during the Build process."), s, t);
363         }
364         return ret;
365 }
366
367
368 int MenuRunChktex(Buffer * buffer)
369 {
370         int ret;
371
372         if (buffer->isSGML()) {
373                 WriteAlert(_("Chktex does not work with SGML derived documents."));
374                 return 0;
375         } else 
376                 ret = buffer->runChktex();
377    
378         if (ret >= 0) {
379                 string s;
380                 string t;
381                 if (ret == 0) {
382                         s = _("No warnings found.");
383                 } else if (ret == 1) {
384                         s = _("One warning found.");
385                         t = _("Use 'Edit->Go to Error' to find it.");
386                 } else {
387                         s += tostr(ret);
388                         s += _(" warnings found.");
389                         t = _("Use 'Edit->Go to Error' to find them.");
390                 }
391                 WriteAlert(_("Chktex run successfully"), s, t);
392         } else {
393                 WriteAlert(_("Error!"), _("It seems chktex does not work."));
394         }
395         return ret;
396 }
397
398  
399 int MakeLaTeXOutput(Buffer * buffer)
400 {
401         // Who cares?
402         //if (!bv->text)
403         //      return 1;
404         int ret = 0;
405         string path = OnlyPath(buffer->fileName());
406         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
407                 path = buffer->tmppath;
408         }
409         if (!buffer->isDviClean()) {
410                 Path p(path);
411                 ret = MenuRunLaTeX(buffer);
412         }
413         return ret;
414 }
415
416
417 /* wait == false means don't wait for termination */
418 /* wait == true means wait for termination       */
419 // The bool should be placed last on the argument line. (Lgb)
420 // Returns false if we fail.
421 bool RunScript(Buffer * buffer, bool wait,
422                string const & command,
423                string const & orgname = string(),
424                bool need_shell = true)
425 {
426         string path;
427         string cmd;
428         string name = orgname;
429         int result = 0;
430         
431         if (MakeLaTeXOutput(buffer) > 0)
432                 return false;
433         /* get DVI-Filename */
434         if (name.empty())
435                 name = ChangeExtension(buffer->getLatexName(), ".dvi");
436
437         path = OnlyPath(name);
438         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
439                 path = buffer->tmppath;
440         }
441         Path p(path);
442         // At this point we check whether the command contains the
443         // filename parameter $$FName and if that's the case we
444         // substitute the real file name otherwise the filename is
445         // simply appended. rokrau 1/12/00
446         cmd = command;
447         string::size_type i;
448         if ( (i=command.find("$$FName")) != string::npos)
449         {
450                 cmd.replace(i,7,QuoteName(name));
451         }
452         else
453                 cmd = command + ' ' + QuoteName(name);
454
455         Systemcalls one;
456
457         if (need_shell) {
458 #ifndef __EMX__
459                 if (!wait)
460                         cmd += " &";
461 #else
462                 // OS/2 cmd.exe has another use for '&'
463                 if (!wait) {
464                         // This is not NLS safe, but it's OK, I think.
465                         string sh = OnlyFilename(GetEnvPath("EMXSHELL"));
466                         if (sh.empty()) {
467                                 // COMSPEC is set, unless user unsets 
468                                 sh = OnlyFilename(GetEnvPath("COMSPEC"));
469                                 if (sh.empty())
470                                         sh = "cmd.exe";
471                         }
472                         sh = lowercase(sh);
473                         if (contains(sh, "cmd.exe")
474                             || contains(sh, "4os2.exe"))
475                                 cmd = "start /min/n " + cmd;
476                         else
477                                 cmd += " &";
478                 }
479 #endif
480                 // It seems that, if wait is false, we never get back
481                 // the return code of the command. This means that all
482                 // the code I added in PrintApplyCB is currently
483                 // useless...
484                 // CHECK What should we do here?
485                 ShowMessage(buffer, _("Executing command:"), cmd);
486                 result = one.startscript(Systemcalls::System, cmd);
487         } else {
488                 ShowMessage(buffer, _("Executing command:"), cmd);
489                 result = one.startscript(wait ? Systemcalls::Wait
490                                          : Systemcalls::DontWait, cmd);
491         }
492         return result == 0;
493 }
494
495
496 // Returns false if we fail
497 bool CreatePostscript(Buffer * buffer, bool wait = false)
498 {
499         // Who cares?
500         //if (!bv->text)
501         //      return false;
502
503         ProhibitInput(current_view);
504
505         // Generate dvi file
506         if (MakeLaTeXOutput(buffer) > 0) {
507                 AllowInput(current_view);
508                 return false;
509         }
510         // Generate postscript file
511         string psname = OnlyFilename(ChangeExtension (buffer->fileName(),
512                                          ".ps_tmp"));
513
514         string paper;
515
516         // Wrong type
517         char real_papersize = buffer->params.papersize;
518         if (real_papersize == BufferParams::PAPER_DEFAULT)
519                 real_papersize = lyxrc.default_papersize;
520
521         switch (real_papersize) {
522         case BufferParams::PAPER_USLETTER:
523                 paper = "letter";
524                 break;
525         case BufferParams::PAPER_A3PAPER:
526                 paper = "a3";
527                 break;
528         case BufferParams::PAPER_A4PAPER:
529                 paper = "a4";
530                 break;
531         case BufferParams::PAPER_A5PAPER:
532                 paper = "a5";
533                 break;
534         case BufferParams::PAPER_B5PAPER:
535                 paper = "b5";
536                 break;
537         case BufferParams::PAPER_EXECUTIVEPAPER:
538                 paper = "foolscap";
539                 break;
540         case BufferParams::PAPER_LEGALPAPER:
541                 paper = "legal";
542                 break;
543         default: /* If nothing else fits, keep an empty value... */
544                 break;
545         }
546
547         // Make postscript file.
548         string command = lyxrc.dvi_to_ps_command + ' ' + lyxrc.print_to_file + ' ';
549         command += QuoteName(psname);
550         if (buffer->params.use_geometry
551             && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
552             && !lyxrc.print_paper_dimension_flag.empty()
553             && !buffer->params.paperwidth.empty()
554             && !buffer->params.paperheight.empty()) {
555                 // using a custom papersize
556                 command += ' ';
557                 command += lyxrc.print_paper_dimension_flag + ' ';
558                 command += buffer->params.paperwidth + ',';
559                 command += buffer->params.paperheight;
560         } else if (!paper.empty()
561                    && (real_papersize != BufferParams::PAPER_USLETTER ||
562                        buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
563                 // dvips won't accept -t letter -t landscape.  In all other
564                 // cases, include the paper size explicitly.
565                 command += ' ';
566                 command += lyxrc.print_paper_flag + ' ' + paper;
567         }
568         if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE) {
569                 command += ' ';
570                 command += lyxrc.print_landscape_flag;
571         }
572         // push directorypath, if necessary 
573         string path = OnlyPath(buffer->fileName());
574         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
575                 path = buffer->tmppath;
576         }
577         Path p(path);
578         bool ret = RunScript(buffer, wait, command);
579         AllowInput(current_view);
580         return ret;
581 }
582
583
584 // Returns false if we fail
585 //bool MenuPreviewPS(Buffer * buffer)
586 bool PreviewPostscript(Buffer * buffer)
587 {
588         // Who cares?
589         //if (!bv->text)
590         //      return false;
591
592         // Generate postscript file
593         if (!CreatePostscript(buffer, true)) {
594                 return false;
595         }
596
597         // Start postscript viewer
598         ProhibitInput(current_view);
599         string ps = OnlyFilename(ChangeExtension (buffer->fileName(),
600                                      ".ps_tmp"));
601         // push directorypath, if necessary 
602         string path = OnlyPath(buffer->fileName());
603         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
604                 path = buffer->tmppath;
605         }
606         Path p(path);
607         bool ret = RunScript(buffer, false, lyxrc.view_ps_command, ps);
608         AllowInput(current_view);
609         return ret;
610 }
611
612
613 void MenuFax(Buffer * buffer)
614 {
615         // Who cares?
616         //if (!bv->text)
617         //      return;
618
619         // Generate postscript file
620         if (!CreatePostscript(buffer, true)) {
621                 return;
622         }
623
624         // Send fax
625         string ps = OnlyFilename(ChangeExtension (buffer->fileName(), 
626                                                   ".ps_tmp"));
627         string path = OnlyPath (buffer->fileName());
628         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
629                 path = buffer->tmppath;
630         }
631         Path p(path);
632         if (!lyxrc.fax_program.empty()) {
633                 string help2 = subst(lyxrc.fax_program, "$$FName", ps);
634                 help2 += " &";
635                 Systemcalls one(Systemcalls::System, help2);
636         } else
637                 send_fax(ps, lyxrc.fax_command);
638 }
639
640
641 // Returns false if we fail
642 bool PreviewDVI(Buffer * buffer)
643 {
644         // Who cares?
645         //if (!bv->text)
646         //      return false;
647
648         string paper = lyxrc.view_dvi_paper_option;
649         if (!paper.empty()) {
650                 // wrong type
651                 char real_papersize = buffer->params.papersize;
652                 if (real_papersize == BufferParams::PAPER_DEFAULT)
653                         real_papersize = lyxrc.default_papersize;
654   
655                 switch (real_papersize) {
656                 case BufferParams::PAPER_USLETTER:
657                         paper += " us";
658                         break;
659                 case BufferParams::PAPER_A3PAPER:
660                         paper += " a3";
661                         break;
662                 case BufferParams::PAPER_A4PAPER:
663                         paper += " a4";
664                         break;
665                 case BufferParams::PAPER_A5PAPER:
666                         paper += " a5";
667                         break;
668                 case BufferParams::PAPER_B5PAPER:
669                         paper += " b5";
670                         break;
671                 case BufferParams::PAPER_EXECUTIVEPAPER:
672                         paper += " foolscap";
673                         break;
674                 case BufferParams::PAPER_LEGALPAPER:
675                         paper += " legal";
676                         break;
677                 default: /* If nothing else fits, keep the empty value */
678                         break;
679                 }
680                 if (real_papersize==' ') {
681                         //      if (paper.empty()) {
682                         if (buffer->params.orientation 
683                             == BufferParams::ORIENTATION_LANDSCAPE)
684                           // we HAVE to give a size when the page is in
685                           // landscape, so use USletter.          
686                                 paper = " -paper usr";
687                 } else {
688                         // paper = " -paper " + paper;
689                         if (buffer->params.orientation 
690                             == BufferParams::ORIENTATION_LANDSCAPE)
691                                paper+= 'r';
692                 }
693         }
694         // push directorypath, if necessary 
695         string path = OnlyPath(buffer->fileName());
696         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
697                 path = buffer->tmppath;
698         }
699         Path p(path);
700         // Run dvi-viewer
701         string command = lyxrc.view_dvi_command + " " + paper;
702         bool ret = RunScript(buffer, false, command);
703         return ret;
704 }
705
706
707 bool AskOverwrite(Buffer * buffer, string const & s)
708 {
709         if (lyxrc.use_gui) {
710                 // be friendly if there is a gui
711                 FileInfo fi(s);
712                 if (fi.readable() &&
713                                 !AskQuestion(_("File already exists:"), 
714                                  MakeDisplayPath(s, 50),
715                                  _("Do you want to overwrite the file?"))) {
716                         ShowMessage(buffer, _("Canceled"));
717                         return false;
718                 }
719         }
720         return true;
721 }
722
723
724 void MenuMakeLaTeX(Buffer * buffer)
725 {
726         // Why care about this?
727         //if (!bv->text)
728         //      return;
729         
730         // Get LaTeX-Filename
731         string s = buffer->getLatexName(false);
732         
733         if (!AskOverwrite(buffer, s))
734                 return; 
735         
736         if (buffer->isDocBook())
737                 ShowMessage(buffer, _("DocBook does not have a latex backend"));
738         else {
739                 if (buffer->isLinuxDoc())
740                         RunLinuxDoc(buffer->getUser(), 0, buffer->fileName());
741                 else
742                         buffer->makeLaTeXFile(s, string(), true);
743                 ShowMessage(buffer, _("Nice LaTeX file saved as"), 
744                             MakeDisplayPath(s));
745                 buffer->markDviDirty();
746         }
747 }
748
749
750 void MenuMakeLinuxDoc(Buffer * buffer)
751 {
752         // Who cares?
753         //if (!bv->text) return;
754         
755         if (!buffer->isLinuxDoc()) {
756                 WriteAlert(_("Error!"), _("Document class must be linuxdoc."));
757                 return;
758         }
759         
760         // Get LinuxDoc-Filename
761         string s = ChangeExtension(buffer->fileName(), ".sgml");
762
763         if (!AskOverwrite(buffer, s))
764                 return;
765         
766         ShowMessage(buffer, _("Building LinuxDoc SGML file `"),
767                                           MakeDisplayPath(s),"'...");
768         
769         buffer->makeLinuxDocFile(s, 65);
770         buffer->redraw();
771         ShowMessage(buffer, _("LinuxDoc SGML file save as"),
772                                           MakeDisplayPath(s)); 
773 }
774
775
776 void MenuMakeDocBook(Buffer * buffer)
777 {
778         // Who cares?
779         //if (!bv->text) return;
780         
781         if (!buffer->isDocBook()) {
782                 WriteAlert(_("Error!"),
783                            _("Document class must be docbook."));
784                 return;
785         }
786         
787         // Get DocBook-Filename
788         string s = ChangeExtension(buffer->fileName(), ".sgml");
789
790         if (!AskOverwrite(buffer, s))
791                 return;
792         
793         ShowMessage(buffer, _("Building DocBook SGML file `"),
794                                           MakeDisplayPath(s), "'..."); 
795         
796         buffer->makeDocBookFile(s, 65);
797         buffer->redraw();
798         ShowMessage(buffer, _("DocBook SGML file save as"),
799                                           MakeDisplayPath(s)); 
800 }
801
802
803 void MenuMakeAscii(Buffer * buffer)
804 {
805         // Who cares?
806         //if (!bv->text) return;
807         
808         /* get LaTeX-Filename */
809         string s = ChangeExtension (buffer->fileName(), ".txt");
810         
811
812         if (!AskOverwrite(buffer, s))
813                 return;
814         
815         buffer->writeFileAscii(s, lyxrc.ascii_linelen);
816         
817         ShowMessage(buffer, _("Ascii file saved as"), MakeDisplayPath(s));
818 }
819
820
821 void MenuPrint(Buffer * buffer)
822 {
823         // Who cares?
824         //if (!bv->text)
825         //      return;
826
827         string input_file = OnlyFilename(ChangeExtension(buffer->fileName(),
828                                             lyxrc.print_file_extension));
829         fl_set_input(fd_form_print->input_file, input_file.c_str());
830         
831         if (fd_form_print->form_print->visible) {
832                 fl_raise_form(fd_form_print->form_print);
833         } 
834         else {
835                 fl_show_form(fd_form_print->form_print,
836                              FL_PLACE_MOUSE, FL_FULLBORDER,
837                              _("Print"));
838         }
839 }
840
841
842 void MenuMakeHTML(Buffer * buffer)
843 {
844         // First, create LaTeX file
845         MenuMakeLaTeX(buffer);
846
847         // And now, run the converter
848         string file = buffer->fileName();
849         Path path(OnlyPath(file));
850         // the tex file name has to be correct for
851         // latex, but the html file name can be
852         // anything.
853         string result = ChangeExtension(file, ".html");
854         string infile = buffer->getLatexName(false);
855         string tmp = lyxrc.html_command;
856         tmp = subst(tmp, "$$FName", infile);
857         tmp = subst(tmp, "$$OutName", result);
858         Systemcalls one;
859         int res = one.startscript(Systemcalls::System, tmp);
860         if (res == 0) {
861                 ShowMessage(buffer, _("Document exported as HTML to file `")
862                                                   + MakeDisplayPath(result) +'\'');
863         } else {
864                 ShowMessage(buffer, _("Unable to convert to HTML the file `")
865                                                   + MakeDisplayPath(infile) 
866                                                   + '\'');
867         }
868
869 }
870
871
872 void MenuMakeHTML_LinuxDoc(Buffer * buffer)
873 {
874         // First, create LinuxDoc file
875         MenuMakeLinuxDoc(buffer);
876
877         // And now, run the converter
878         string file = buffer->fileName();
879
880         string result = ChangeExtension(file, ".html");
881         string infile = ChangeExtension(file, ".sgml");
882         string tmp = lyxrc.linuxdoc_to_html_command;
883         tmp = subst(tmp, "$$FName", infile);
884         tmp = subst(tmp, "$$OutName", result);
885         Systemcalls one;
886         int res = one.startscript(Systemcalls::System, tmp);
887         if (res == 0) {
888                 ShowMessage(buffer,_("Document exported as HTML to file `")
889                                                   + MakeDisplayPath(result) +'\'');
890         } else {
891                 ShowMessage(buffer,_("Unable to convert to HTML the file `")
892                                                   + MakeDisplayPath(infile) 
893                                                   + '\'');
894         }
895
896 }
897
898 void MenuMakeHTML_DocBook(Buffer * buffer)
899 {
900         // First, create LaTeX file
901         MenuMakeDocBook(buffer);
902
903         // And now, run the converter
904         string file = buffer->fileName();
905         string result = ChangeExtension(file, ".html");
906         string infile = ChangeExtension(file, ".sgml");
907         string tmp = lyxrc.docbook_to_html_command;
908         tmp = subst(tmp, "$$FName", infile);
909         tmp = subst(tmp, "$$OutName", result);
910         Systemcalls one;
911         int res = one.startscript(Systemcalls::System, tmp);
912         if (res == 0) {
913                 ShowMessage(buffer,_("Document exported as HTML to file `")
914                                                   + MakeDisplayPath(result) +'\'');
915         } else {
916                 ShowMessage(buffer,_("Unable to convert to HTML the file `")
917                                                   + MakeDisplayPath(infile) 
918                                                   + '\'');
919         }
920
921 }
922
923
924 void MenuExport(Buffer * buffer, string const & extyp) 
925 {
926         // latex
927         if (extyp == "latex") {
928                 // make sure that this buffer is not linuxdoc
929                 MenuMakeLaTeX(buffer);
930         }
931         // linuxdoc
932         else if (extyp == "linuxdoc") {
933                 // make sure that this buffer is not latex
934                 MenuMakeLinuxDoc(buffer);
935         }
936         // docbook
937         else if (extyp == "docbook") {
938                 // make sure that this buffer is not latex or linuxdoc
939                 MenuMakeDocBook(buffer);
940         }
941         // dvi
942         else if (extyp == "dvi") {
943                 // Run LaTeX as "Update dvi..." Bernhard.
944                 // We want the dvi in the current directory. This
945                 // is achieved by temporarily disabling use of
946                 // temp directory. As a side-effect, we get
947                 // *.log and *.aux files also. (Asger)
948                 bool flag = lyxrc.use_tempdir;
949                 lyxrc.use_tempdir = false;
950                 MenuRunLaTeX(buffer);
951                 lyxrc.use_tempdir = flag;
952         }
953         // postscript
954         else if (extyp == "postscript") {
955                 // Start Print-dialog. Not as good as dvi... Bernhard.
956                 MenuPrint(buffer);
957                 // Since the MenuPrint is a pop-up, we can't use
958                 // the same trick as above. (Asger)
959                 // MISSING: Move of ps-file :-(
960                 // And MenuPrint should not be used for this at all...
961         }
962         // ascii
963         else if (extyp == "ascii") {
964                 MenuMakeAscii(buffer);
965         }
966         else if (extyp == "custom") {
967                 MenuSendto();
968         }
969         // HTML
970         else if (extyp == "html") {
971                 MenuMakeHTML(buffer);
972         }
973         // HTML from linuxdoc
974         else if (extyp == "html-linuxdoc") {
975                 MenuMakeHTML_LinuxDoc(buffer);
976         }
977         // HTML from docbook
978         else if (extyp == "html-docbook") {
979                 MenuMakeHTML_DocBook(buffer);
980         }
981         else {
982                 ShowMessage(buffer, _("Unknown export type: ") + extyp);
983         }
984 }
985
986
987 void QuitLyX()
988 {
989         lyxerr.debug() << "Running QuitLyX." << endl;
990
991         if (!bufferlist.QwriteAll())
992                 return;
993
994         lastfiles->writeFile(lyxrc.lastfiles);
995
996         // Set a flag that we do quitting from the program,
997         // so no refreshes are necessary.
998         quitting = true;
999
1000         // close buffers first
1001         bufferlist.closeAll();
1002
1003         // do any other cleanup procedures now
1004         lyxerr.debug() << "Deleting tmp dir " << system_tempdir << endl;
1005
1006         DestroyLyXTmpDir(system_tempdir);
1007
1008         finished = true;
1009 }
1010
1011
1012
1013 void AutoSave(BufferView * bv)
1014         // should probably be moved into BufferList (Lgb)
1015         // Perfect target for a thread...
1016 {
1017         if (!bv->available())
1018                 return;
1019
1020         if (bv->buffer()->isBakClean()
1021             || bv->buffer()->isReadonly()) {
1022                 // We don't save now, but we'll try again later
1023                 bv->owner()->resetAutosaveTimer();
1024                 return;
1025         }
1026
1027         bv->owner()->getMiniBuffer()->Set(_("Autosaving current document..."));
1028         
1029         // create autosave filename
1030         string fname =  OnlyPath(bv->buffer()->fileName());
1031         fname += "#";
1032         fname += OnlyFilename(bv->buffer()->fileName());
1033         fname += "#";
1034         
1035         // tmp_ret will be located (usually) in /tmp
1036         // will that be a problem?
1037         string tmp_ret = tmpnam(0);
1038         
1039         pid_t pid = fork(); // If you want to debug the autosave
1040         // you should set pid to -1, and comment out the
1041         // fork.
1042         if (pid == 0 || pid == -1) {
1043                 // pid = -1 signifies that lyx was unable
1044                 // to fork. But we will do the save
1045                 // anyway.
1046                 bool failed = false;
1047                 if (!tmp_ret.empty()) {
1048                         bv->buffer()->writeFile(tmp_ret, 1);
1049                         // assume successful write of tmp_ret
1050                         if (rename(tmp_ret.c_str(), fname.c_str()) == -1) {
1051                                 failed = true;
1052                                 // most likely couldn't move between filesystems
1053                                 // unless write of tmp_ret failed
1054                                 // so remove tmp file (if it exists)
1055                                 remove(tmp_ret.c_str());
1056                         }
1057                 } else {
1058                         failed = true;
1059                 }
1060                 
1061                 if (failed) {
1062                         // failed to write/rename tmp_ret so try writing direct
1063                         if (!bv->buffer()->writeFile(fname, 1)) {
1064                                 // It is dangerous to do this in the child,
1065                                 // but safe in the parent, so...
1066                                 if (pid == -1)
1067                                         bv->owner()->getMiniBuffer()->Set(_("Autosave Failed!"));
1068                         }
1069                 }
1070                 if (pid == 0) { // we are the child so...
1071                         _exit(0);
1072                 }
1073         }
1074         
1075         bv->buffer()->markBakClean();
1076         bv->owner()->resetAutosaveTimer();
1077 }
1078
1079
1080 //
1081 // Copyright CHT Software Service GmbH
1082 // Uwe C. Schroeder
1083 //
1084 // create new file with template
1085 // SERVERCMD !
1086 //
1087 Buffer * NewLyxFile(string const & filename)
1088 {
1089         // Split argument by :
1090         string name;
1091         string tmpname = split(filename, name, ':');
1092 #ifdef __EMX__ // Fix me! lyx_cb.C may not be low level enough to allow this.
1093         if (name.length() == 1
1094             && isalpha(static_cast<unsigned char>(name[0]))
1095             && (prefixIs(tmpname, "/") || prefixIs(tmpname, "\\"))) {
1096                 name += ':';
1097                 name += token(tmpname, ':', 0);
1098                 tmpname = split(tmpname, ':');
1099         }
1100 #endif
1101         lyxerr.debug() << "Arg is " << filename
1102                        << "\nName is " << name
1103                        << "\nTemplate is " << tmpname << endl;
1104
1105         // find a free buffer 
1106         Buffer * tmpbuf = bufferlist.newFile(name, tmpname);
1107         if (tmpbuf)
1108                 lastfiles->newFile(tmpbuf->fileName());
1109         return tmpbuf;
1110 }
1111
1112
1113 // Insert ascii file (if filename is empty, prompt for one)
1114 void InsertAsciiFile(BufferView * bv, string const & f, bool asParagraph)
1115 {
1116         string fname = f;
1117         LyXFileDlg fileDlg;
1118  
1119         if (!bv->available()) return;
1120      
1121         if (fname.empty()) {
1122                 ProhibitInput(bv);
1123                 fname = fileDlg.Select(_("File to Insert"), 
1124                                        bv->owner()->buffer()->filepath,
1125                                        "*");
1126                 AllowInput(bv);
1127                 if (fname.empty()) return;
1128         }
1129
1130         FileInfo fi(fname);
1131
1132         if (!fi.readable()) {
1133                 WriteFSAlert(_("Error! Specified file is unreadable: "),
1134                              MakeDisplayPath(fname, 50));
1135                 return;
1136         }
1137
1138         ifstream ifs(fname.c_str());
1139         if (!ifs) {
1140                 WriteFSAlert(_("Error! Cannot open specified file: "),
1141                              MakeDisplayPath(fname, 50));
1142                 return;
1143         }
1144
1145         ifs.unsetf(ios::skipws);
1146         istream_iterator<char> ii(ifs);
1147         istream_iterator<char> end;
1148         //string tmpstr(ii, end); // yet a reason for using std::string
1149         // alternate approach to get the file into a string:
1150         string tmpstr;
1151         copy(ii, end, back_inserter(tmpstr));
1152         // insert the string
1153         current_view->hideCursor();
1154         
1155         // clear the selection
1156         bv->beforeChange();
1157         if (!asParagraph)
1158                 bv->text->InsertStringA(tmpstr);
1159         else
1160                 bv->text->InsertStringB(tmpstr);
1161         bv->update(1);
1162 }
1163
1164
1165 void MenuShowTableOfContents()
1166 {
1167         static int ow = -1, oh;
1168
1169         TocUpdateCB(0, 0);
1170         if (fd_form_toc->form_toc->visible) {
1171                 fl_raise_form(fd_form_toc->form_toc);
1172         } else {
1173                 fl_show_form(fd_form_toc->form_toc,
1174                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1175                              _("Table Of Contents"));
1176                 if (ow < 0) {
1177                         ow = fd_form_toc->form_toc->w;
1178                         oh = fd_form_toc->form_toc->h;
1179                 }
1180                 fl_set_form_minsize(fd_form_toc->form_toc, ow, oh);
1181         }
1182 }
1183
1184
1185 void MenuInsertLabel(char const * arg)
1186 {
1187         string label = arg;
1188         ProhibitInput(current_view);
1189         if (label.empty()) {
1190                 pair<bool, string>
1191                         result = askForText(_("Enter new label to insert:"));
1192                 if (result.first) {
1193                         label = frontStrip(strip(result.second));
1194                 }
1195         }
1196         if (!label.empty()) {
1197                 InsetLabel * new_inset = new InsetLabel;
1198                 new_inset->setContents(label);
1199                 current_view->insertInset(new_inset);
1200         }
1201         AllowInput(current_view);
1202 }
1203
1204
1205 void MenuInsertRef()
1206 {
1207         static int ow = -1, oh;
1208
1209         RefUpdateCB(0, 0);
1210         if (fd_form_ref->form_ref->visible) {
1211                 fl_raise_form(fd_form_ref->form_ref);
1212         } else {
1213                 fl_show_form(fd_form_ref->form_ref,
1214                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1215                              _("Insert Reference"));
1216                 if (ow < 0) {
1217                         ow = fd_form_ref->form_ref->w;
1218                         oh = fd_form_ref->form_ref->h;
1219                 }
1220                 fl_set_form_minsize(fd_form_ref->form_ref, ow, oh);
1221         }
1222 }
1223
1224
1225 void MenuPasteSelection(char at)
1226 {
1227         if (!current_view->available())
1228                 return;
1229
1230         ascii_type = at;
1231   
1232         Atom data_prop = XInternAtom(fl_display, 
1233                                      "LyX_Primary",
1234                                      false);
1235         if (data_prop == None) 
1236                 return;
1237         XConvertSelection(fl_display,
1238                           XA_PRIMARY, XA_STRING, data_prop, 
1239                           current_view->owner()->getForm()->window, 0);
1240         XFlush(fl_display);
1241 }
1242
1243
1244
1245
1246 // candidate for move to LyXView
1247 // This is only used in toolbar.C
1248 void LayoutsCB(int sel, void *)
1249 {
1250         string tmp = tostr(sel);
1251         current_view->owner()->getLyXFunc()->Dispatch(LFUN_LAYOUTNO,
1252                                                       tmp.c_str());
1253 }
1254
1255
1256 /*
1257  * SGML Linuxdoc support:
1258  * (flag == 0) make TeX output
1259  * (flag == 1) make dvi output
1260  */
1261 int RunLinuxDoc(BufferView * bv, int flag, string const & filename)
1262 {
1263         string s2;
1264         string add_flags;
1265
1266         int errorcode = 0;
1267
1268         /* generate a path-less extension name */
1269         string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1270         string path = OnlyPath (filename);
1271         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1272                 path = bv->buffer()->tmppath;
1273         }
1274         Path p(path);
1275         
1276         if (!bv->available())
1277                 return 0;
1278         bv->buffer()->makeLinuxDocFile(name, 0);
1279
1280         // CHECK remove this once we have a proper geometry class
1281
1282         BufferParams::PAPER_SIZE ps =
1283                 static_cast<BufferParams::PAPER_SIZE>(bv->buffer()->params.papersize);
1284         switch (ps) {
1285         case BufferParams::PAPER_A4PAPER:
1286                 add_flags = "-p a4";
1287                 break;
1288         case BufferParams::PAPER_USLETTER:
1289                 add_flags = "-p letter";
1290                 break;
1291         default: /* nothing to be done yet ;-) */     break; 
1292         }
1293         
1294         ProhibitInput(bv);
1295         
1296         Systemcalls one;
1297         switch (flag) {
1298         case 0: /* TeX output asked */
1299               bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to TeX file..."));
1300                 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o tex " + ' ' + name;
1301                 if (one.startscript(Systemcalls::System, s2)) 
1302                         errorcode = 1;
1303                 break;
1304         case 1: /* dvi output asked */
1305                 bv->owner()->getMiniBuffer()->Set(_("Converting LinuxDoc SGML to dvi file..."));
1306                 s2 = lyxrc.linuxdoc_to_latex_command + ' ' + add_flags + " -o dvi " + ' ' + name;
1307                 if (one.startscript(Systemcalls::System, s2)) {
1308                         errorcode = 1;
1309                 } else
1310                         bv->buffer()->markDviClean();
1311                 break;
1312         default: /* unknown output */
1313                 break;
1314         }
1315         
1316         AllowInput(bv);
1317
1318         bv->buffer()->redraw();
1319         return errorcode;
1320 }
1321
1322
1323 /*
1324  * SGML DocBook support:
1325  * (flag == 1) make dvi output
1326  */
1327 int RunDocBook(int flag, string const & filename)
1328 {
1329         /* generate a path-less extension name */
1330         string name = OnlyFilename(ChangeExtension (filename, ".sgml"));
1331         string path = OnlyPath (filename);
1332         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
1333                 path = current_view->buffer()->tmppath;
1334         }
1335         Path p(path);
1336
1337         if (!current_view->available())
1338                 return 0;
1339         
1340         current_view->buffer()->makeDocBookFile(name, 0);
1341
1342         // Shall this code go or should it stay? (Lgb)
1343         // This code is a placeholder for future implementation. (Jose')
1344 //      string add_flags;
1345 //      LYX_PAPER_SIZE ps = (LYX_PAPER_SIZE) current_view->buffer()->params.papersize;
1346 //      switch (ps) {
1347 //      case BufferParams::PAPER_A4PAPER:  add_flags = "-p a4";     break;
1348 //      case BufferParams::PAPER_USLETTER: add_flags = "-p letter"; break;
1349 //      default: /* nothing to be done yet ;-) */     break; 
1350 //      }
1351         ProhibitInput(current_view);
1352         
1353         int errorcode = 0;
1354         Systemcalls one;
1355         switch (flag) {
1356         case 1: /* dvi output asked */
1357         {
1358                 current_view->owner()->getMiniBuffer()->Set(_("Converting DocBook SGML to dvi file..."));
1359                 string s2 = lyxrc.docbook_to_dvi_command + ' ' + name;
1360                 if (one.startscript(Systemcalls::System, s2)) {
1361                         errorcode = 1;
1362                 } else
1363                         current_view->buffer()->markDviClean();
1364         }
1365         break;
1366         default: /* unknown output */
1367                 break;
1368         }
1369         
1370         AllowInput(current_view);
1371
1372         current_view->buffer()->redraw();
1373         return errorcode;
1374 }
1375
1376
1377 void MenuLayoutCharacter()
1378 {
1379         static int ow = -1, oh;
1380
1381         if (fd_form_character->form_character->visible) {
1382                 fl_raise_form(fd_form_character->form_character);
1383         } else {
1384                 fl_show_form(fd_form_character->form_character,
1385                              FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
1386                              _("Character Style"));
1387                 if (ow < 0) {
1388                         ow = fd_form_character->form_character->w;
1389                         oh = fd_form_character->form_character->h;
1390                 }
1391                 fl_set_form_minsize(fd_form_character->form_character, ow, oh);
1392         }
1393 }
1394
1395
1396 inline
1397 void DeactivateParagraphButtons ()
1398 {
1399         fl_deactivate_object (fd_form_paragraph->button_ok);
1400         fl_deactivate_object (fd_form_paragraph->button_apply);
1401         fl_set_object_lcol (fd_form_paragraph->button_ok, FL_INACTIVE);
1402         fl_set_object_lcol (fd_form_paragraph->button_apply, FL_INACTIVE);
1403 }
1404
1405
1406 inline
1407 void ActivateParagraphButtons ()
1408 {
1409         fl_activate_object (fd_form_paragraph->button_ok);
1410         fl_activate_object (fd_form_paragraph->button_apply);
1411         fl_set_object_lcol (fd_form_paragraph->button_ok, FL_BLACK);
1412         fl_set_object_lcol (fd_form_paragraph->button_apply, FL_BLACK);
1413 }
1414
1415
1416 inline
1417 void DisableParagraphLayout ()
1418 {
1419         DeactivateParagraphButtons();
1420         fl_deactivate_object (fd_form_paragraph->input_labelwidth);
1421         fl_deactivate_object (fd_form_paragraph->check_lines_top);
1422         fl_deactivate_object (fd_form_paragraph->check_lines_bottom);
1423         fl_deactivate_object (fd_form_paragraph->check_pagebreaks_top);
1424         fl_deactivate_object (fd_form_paragraph->check_pagebreaks_bottom);
1425         fl_deactivate_object (fd_form_paragraph->check_noindent);
1426         fl_deactivate_object (fd_form_paragraph->group_radio_alignment);
1427         fl_deactivate_object (fd_form_paragraph->radio_align_right);
1428         fl_deactivate_object (fd_form_paragraph->radio_align_left);
1429         fl_deactivate_object (fd_form_paragraph->radio_align_block);
1430         fl_deactivate_object (fd_form_paragraph->radio_align_center);
1431         fl_deactivate_object (fd_form_paragraph->input_space_above);
1432         fl_deactivate_object (fd_form_paragraph->input_space_below);
1433         fl_deactivate_object (fd_form_paragraph->choice_space_above);
1434         fl_deactivate_object (fd_form_paragraph->choice_space_below);
1435         fl_deactivate_object (fd_form_paragraph->check_space_above);
1436         fl_deactivate_object (fd_form_paragraph->check_space_below);
1437 }
1438
1439
1440 inline
1441 void EnableParagraphLayout ()
1442 {
1443         ActivateParagraphButtons();
1444         fl_activate_object (fd_form_paragraph->input_labelwidth);
1445         fl_activate_object (fd_form_paragraph->check_lines_top);
1446         fl_activate_object (fd_form_paragraph->check_lines_bottom);
1447         fl_activate_object (fd_form_paragraph->check_pagebreaks_top);
1448         fl_activate_object (fd_form_paragraph->check_pagebreaks_bottom);
1449         fl_activate_object (fd_form_paragraph->check_noindent);
1450         fl_activate_object (fd_form_paragraph->group_radio_alignment);
1451         fl_activate_object (fd_form_paragraph->radio_align_right);
1452         fl_activate_object (fd_form_paragraph->radio_align_left);
1453         fl_activate_object (fd_form_paragraph->radio_align_block);
1454         fl_activate_object (fd_form_paragraph->radio_align_center);
1455         fl_activate_object (fd_form_paragraph->input_space_above);
1456         fl_activate_object (fd_form_paragraph->input_space_below);
1457         fl_activate_object (fd_form_paragraph->choice_space_above);
1458         fl_activate_object (fd_form_paragraph->choice_space_below);
1459         fl_activate_object (fd_form_paragraph->check_space_above);
1460         fl_activate_object (fd_form_paragraph->check_space_below);
1461 }
1462
1463
1464 bool UpdateLayoutParagraph()
1465 {
1466         if (!current_view->available()) {
1467                 if (fd_form_paragraph->form_paragraph->visible) 
1468                         fl_hide_form(fd_form_paragraph->form_paragraph);
1469                 return false;
1470         }
1471
1472         Buffer * buf = current_view->buffer();
1473
1474         fl_set_input(fd_form_paragraph->input_labelwidth,
1475                      current_view->text->cursor.par->GetLabelWidthString().c_str());
1476         fl_set_button(fd_form_paragraph->radio_align_right, 0);
1477         fl_set_button(fd_form_paragraph->radio_align_left, 0);
1478         fl_set_button(fd_form_paragraph->radio_align_center, 0);
1479         fl_set_button(fd_form_paragraph->radio_align_block, 0);
1480
1481         int align = current_view->text->cursor.par->GetAlign();
1482         if (align == LYX_ALIGN_LAYOUT)
1483                 align = textclasslist.Style(buf->params.textclass,
1484                                             current_view->text->cursor.par->GetLayout()).align;
1485          
1486         switch (align) {
1487         case LYX_ALIGN_RIGHT:
1488                 fl_set_button(fd_form_paragraph->radio_align_right, 1);
1489                 break;
1490         case LYX_ALIGN_LEFT:
1491                 fl_set_button(fd_form_paragraph->radio_align_left, 1);
1492                 break;
1493         case LYX_ALIGN_CENTER:
1494                 fl_set_button(fd_form_paragraph->radio_align_center, 1);
1495                 break;
1496         default:
1497                 fl_set_button(fd_form_paragraph->radio_align_block, 1);
1498                 break;
1499         }
1500          
1501         fl_set_button(fd_form_paragraph->check_lines_top,
1502                       current_view->text->cursor.par->FirstPhysicalPar()->line_top);
1503         fl_set_button(fd_form_paragraph->check_lines_bottom,
1504                       current_view->text->cursor.par->FirstPhysicalPar()->line_bottom);
1505         fl_set_button(fd_form_paragraph->check_pagebreaks_top,
1506                       current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top);
1507         fl_set_button(fd_form_paragraph->check_pagebreaks_bottom,
1508                       current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom);
1509         fl_set_button(fd_form_paragraph->check_noindent,
1510                       current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1511         fl_set_input (fd_form_paragraph->input_space_above, "");
1512         
1513         switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) {
1514         case VSpace::NONE:
1515                 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
1516                 break;
1517         case VSpace::DEFSKIP:
1518                 fl_set_choice (fd_form_paragraph->choice_space_above, 2);
1519                 break;
1520         case VSpace::SMALLSKIP:
1521                 fl_set_choice (fd_form_paragraph->choice_space_above, 3);
1522                 break;
1523         case VSpace::MEDSKIP:
1524                 fl_set_choice (fd_form_paragraph->choice_space_above, 4);
1525                 break;
1526         case VSpace::BIGSKIP:
1527                 fl_set_choice (fd_form_paragraph->choice_space_above, 5);
1528                 break;
1529         case VSpace::VFILL:
1530                 fl_set_choice (fd_form_paragraph->choice_space_above, 6);
1531                 break;
1532         case VSpace::LENGTH:
1533                 fl_set_choice (fd_form_paragraph->choice_space_above, 7); 
1534                 fl_set_input  (fd_form_paragraph->input_space_above, 
1535                                current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str());
1536                 break;
1537         }
1538         fl_set_button (fd_form_paragraph->check_space_above,
1539                        current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep());
1540         fl_set_input (fd_form_paragraph->input_space_below, "");
1541         switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) {
1542         case VSpace::NONE:
1543                 fl_set_choice (fd_form_paragraph->choice_space_below,
1544                                1);
1545                 break;
1546         case VSpace::DEFSKIP:
1547                 fl_set_choice (fd_form_paragraph->choice_space_below,
1548                                2);
1549                 break;
1550         case VSpace::SMALLSKIP:
1551                 fl_set_choice (fd_form_paragraph->choice_space_below,
1552                                3);
1553                 break;
1554         case VSpace::MEDSKIP:
1555                 fl_set_choice (fd_form_paragraph->choice_space_below,
1556                                4);
1557                 break;
1558         case VSpace::BIGSKIP:
1559                 fl_set_choice (fd_form_paragraph->choice_space_below,
1560                                5);
1561                 break;
1562         case VSpace::VFILL:
1563                 fl_set_choice (fd_form_paragraph->choice_space_below,
1564                                6);
1565                 break;
1566         case VSpace::LENGTH:
1567                 fl_set_choice (fd_form_paragraph->choice_space_below,
1568                                7); 
1569                 fl_set_input  (fd_form_paragraph->input_space_below, 
1570                                current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str());
1571                 break;
1572         }
1573         fl_set_button (fd_form_paragraph->check_space_below,
1574                        current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep());
1575
1576         fl_set_button(fd_form_paragraph->check_noindent,
1577                       current_view->text->cursor.par->FirstPhysicalPar()->noindent);
1578
1579         if (current_view->buffer()->isReadonly()) {
1580                 DisableParagraphLayout();
1581         } else {
1582                 EnableParagraphLayout();
1583         }
1584         return true;
1585 }
1586
1587
1588 void MenuLayoutParagraph()
1589 {
1590         if (UpdateLayoutParagraph()) {
1591                 if (fd_form_paragraph->form_paragraph->visible) {
1592                         fl_raise_form(fd_form_paragraph->form_paragraph);
1593                 } else {
1594                         fl_show_form(fd_form_paragraph->form_paragraph,
1595                                      FL_PLACE_MOUSE, FL_FULLBORDER,
1596                                      _("Paragraph Environment"));
1597                 }
1598         }
1599 }
1600
1601
1602 inline
1603 void DeactivateDocumentButtons ()
1604 {
1605         fl_deactivate_object (fd_form_document->button_ok);
1606         fl_deactivate_object (fd_form_document->button_apply);
1607         fl_set_object_lcol (fd_form_document->button_ok, FL_INACTIVE);
1608         fl_set_object_lcol (fd_form_document->button_apply, FL_INACTIVE);
1609 }
1610
1611
1612 inline
1613 void ActivateDocumentButtons ()
1614 {
1615         fl_activate_object (fd_form_document->button_ok);
1616         fl_activate_object (fd_form_document->button_apply);
1617         fl_set_object_lcol (fd_form_document->button_ok, FL_BLACK);
1618         fl_set_object_lcol (fd_form_document->button_apply, FL_BLACK);
1619 }
1620
1621
1622 inline
1623 void DisableDocumentLayout ()
1624 {
1625         DeactivateDocumentButtons ();
1626         fl_deactivate_object (fd_form_document->group_radio_separation);
1627         fl_deactivate_object (fd_form_document->radio_indent);
1628         fl_deactivate_object (fd_form_document->radio_skip);
1629         fl_deactivate_object (fd_form_document->choice_class);
1630         fl_deactivate_object (fd_form_document->choice_pagestyle);
1631         fl_deactivate_object (fd_form_document->choice_fonts);
1632         fl_deactivate_object (fd_form_document->choice_fontsize);
1633         fl_deactivate_object (fd_form_document->input_float_placement);
1634         fl_deactivate_object (fd_form_document->choice_postscript_driver);
1635         fl_deactivate_object (fd_form_document->choice_inputenc);
1636         fl_deactivate_object (fd_form_document->group_radio_sides);
1637         fl_deactivate_object (fd_form_document->radio_sides_one);
1638         fl_deactivate_object (fd_form_document->radio_sides_two);
1639         fl_deactivate_object (fd_form_document->group_radio_columns);
1640         fl_deactivate_object (fd_form_document->radio_columns_one);
1641         fl_deactivate_object (fd_form_document->radio_columns_two);
1642         fl_deactivate_object (fd_form_document->input_extra);
1643         fl_deactivate_object (fd_form_document->choice_language);
1644         combo_language->deactivate();
1645         fl_deactivate_object (fd_form_document->input_default_skip);
1646         fl_deactivate_object (fd_form_document->choice_default_skip);
1647         fl_deactivate_object (fd_form_document->slider_secnumdepth);
1648         fl_deactivate_object (fd_form_document->slider_tocdepth);
1649         fl_deactivate_object (fd_form_document->choice_spacing);
1650         fl_deactivate_object (fd_form_document->input_spacing);
1651         fl_deactivate_object (fd_form_document->check_use_amsmath);
1652 }
1653
1654
1655 inline
1656 void EnableDocumentLayout ()
1657 {
1658         ActivateDocumentButtons ();
1659         fl_activate_object (fd_form_document->group_radio_separation);
1660         fl_activate_object (fd_form_document->radio_indent);
1661         fl_activate_object (fd_form_document->radio_skip);
1662         fl_activate_object (fd_form_document->choice_class);
1663         fl_activate_object (fd_form_document->choice_pagestyle);
1664         fl_activate_object (fd_form_document->choice_fonts);
1665         fl_activate_object (fd_form_document->choice_fontsize);
1666         fl_activate_object (fd_form_document->input_float_placement);
1667         fl_activate_object (fd_form_document->choice_postscript_driver);
1668         fl_activate_object (fd_form_document->choice_inputenc);
1669         fl_activate_object (fd_form_document->group_radio_sides);
1670         fl_activate_object (fd_form_document->radio_sides_one);
1671         fl_activate_object (fd_form_document->radio_sides_two);
1672         fl_activate_object (fd_form_document->group_radio_columns);
1673         fl_activate_object (fd_form_document->radio_columns_one);
1674         fl_activate_object (fd_form_document->radio_columns_two);
1675         fl_activate_object (fd_form_document->input_extra);
1676         fl_activate_object (fd_form_document->choice_language);
1677         combo_language->activate();
1678         fl_activate_object (fd_form_document->input_default_skip);
1679         fl_activate_object (fd_form_document->choice_default_skip);
1680         fl_activate_object (fd_form_document->slider_secnumdepth);
1681         fl_activate_object (fd_form_document->slider_tocdepth);
1682         fl_activate_object (fd_form_document->choice_spacing);
1683         fl_activate_object (fd_form_document->input_spacing);
1684         fl_activate_object (fd_form_document->check_use_amsmath);
1685 }
1686
1687
1688 bool UpdateLayoutDocument(BufferParams * params)
1689 {
1690         if (!current_view->available()) {
1691                 if (fd_form_document->form_document->visible) 
1692                         fl_hide_form(fd_form_document->form_document);
1693                 return false;
1694         }               
1695
1696         if (params == 0)
1697                 params = &current_view->buffer()->params;
1698         LyXTextClass const & tclass = textclasslist.TextClass(params->textclass);
1699         
1700         fl_set_choice_text(fd_form_document->choice_class, 
1701                            textclasslist.DescOfClass(params->textclass).c_str());
1702         combo_language->select_text(params->language.c_str());
1703         
1704         fl_set_choice_text(fd_form_document->choice_fonts, 
1705                            params->fonts.c_str());
1706         fl_set_choice_text(fd_form_document->choice_inputenc, 
1707                            params->inputenc.c_str());
1708         fl_set_choice_text(fd_form_document->choice_postscript_driver, 
1709                            params->graphicsDriver.c_str());
1710
1711         // ale970405+lasgoutt970513
1712         fl_clear_choice(fd_form_document->choice_fontsize);
1713         fl_addto_choice(fd_form_document->choice_fontsize, "default");
1714         fl_addto_choice(fd_form_document->choice_fontsize, 
1715                         tclass.opt_fontsize().c_str());
1716         fl_set_choice(fd_form_document->choice_fontsize, 
1717                       tokenPos(tclass.opt_fontsize(), '|', params->fontsize) + 2);
1718
1719         // ale970405+lasgoutt970513
1720         fl_clear_choice(fd_form_document->choice_pagestyle);
1721         fl_addto_choice(fd_form_document->choice_pagestyle, "default");
1722         fl_addto_choice(fd_form_document->choice_pagestyle, 
1723                         tclass.opt_pagestyle().c_str());
1724     
1725         fl_set_choice(fd_form_document->choice_pagestyle,
1726                       tokenPos(tclass.opt_pagestyle(), '|', params->pagestyle) + 2);
1727
1728         fl_set_button(fd_form_document->radio_indent, 0);
1729         fl_set_button(fd_form_document->radio_skip, 0);
1730     
1731         
1732         fl_set_button(fd_form_document->check_use_amsmath, params->use_amsmath);
1733
1734         if (params->paragraph_separation == BufferParams::PARSEP_INDENT)
1735                 fl_set_button(fd_form_document->radio_indent, 1);
1736         else
1737                 fl_set_button(fd_form_document->radio_skip, 1);
1738
1739         switch (params->getDefSkip().kind()) {
1740         case VSpace::SMALLSKIP: 
1741                 fl_set_choice (fd_form_document->choice_default_skip, 1);
1742                 break;
1743         case VSpace::MEDSKIP: 
1744                 fl_set_choice (fd_form_document->choice_default_skip, 2);
1745                 break;
1746         case VSpace::BIGSKIP: 
1747                 fl_set_choice (fd_form_document->choice_default_skip, 3);
1748                 break;
1749         case VSpace::LENGTH: 
1750                 fl_set_choice (fd_form_document->choice_default_skip, 4);
1751                 fl_set_input (fd_form_document->input_default_skip,
1752                               params->getDefSkip().asLyXCommand().c_str());
1753                 break;
1754         default:
1755                 fl_set_choice (fd_form_document->choice_default_skip, 2);
1756                 break;
1757         }
1758    
1759         fl_set_button(fd_form_document->radio_sides_one, 0);
1760         fl_set_button(fd_form_document->radio_sides_two, 0);
1761    
1762         switch (params->sides) {
1763         case LyXTextClass::OneSide:
1764                 fl_set_button(fd_form_document->radio_sides_one, 1);
1765                 break;
1766         case LyXTextClass::TwoSides:
1767                 fl_set_button(fd_form_document->radio_sides_two, 1);
1768                 break;
1769         }
1770    
1771         fl_set_button(fd_form_document->radio_columns_one, 0);
1772         fl_set_button(fd_form_document->radio_columns_two, 0);
1773    
1774         if (params->columns == 2)
1775                 fl_set_button(fd_form_document->radio_columns_two, 1);
1776         else
1777                 fl_set_button(fd_form_document->radio_columns_one, 1);
1778    
1779         fl_set_input(fd_form_document->input_spacing, "");
1780         switch (params->spacing.getSpace()) {
1781         case Spacing::Default: // nothing bad should happen with this
1782         case Spacing::Single:
1783         {
1784                 // \singlespacing
1785                 fl_set_choice(fd_form_document->choice_spacing, 1);
1786                 break;
1787         }
1788         case Spacing::Onehalf:
1789         {
1790                 // \onehalfspacing
1791                 fl_set_choice(fd_form_document->choice_spacing, 2);
1792                 break;
1793         }
1794         case Spacing::Double:
1795         {
1796                 // \ doublespacing
1797                 fl_set_choice(fd_form_document->choice_spacing, 3);
1798                 break;
1799         }
1800         case Spacing::Other:
1801         {
1802                 fl_set_choice(fd_form_document->choice_spacing, 4);
1803                 //char sval[20];
1804                 //sprintf(sval, "%g", params->spacing.getValue()); 
1805 #ifdef HAVE_SSTREAM
1806                 std::ostringstream sval;
1807                 sval << params->spacing.getValue(); // setw?
1808                 fl_set_input(fd_form_document->input_spacing,
1809                              sval.str().c_str());
1810 #else
1811                 char tval[20];
1812                 ostrstream sval(tval, 20);
1813                 sval << params->spacing.getValue() << '\0'; // setw?
1814                 fl_set_input(fd_form_document->input_spacing, sval.str());
1815 #endif
1816                 break;
1817         }
1818         }
1819
1820
1821         fl_set_counter_value(fd_form_document->slider_secnumdepth, 
1822                              params->secnumdepth);
1823         fl_set_counter_value(fd_form_document->slider_tocdepth, 
1824                              params->tocdepth);
1825         if (!params->float_placement.empty()) { // buffer local (Lgb)
1826                 fl_set_input(fd_form_document->input_float_placement,
1827                              params->float_placement.c_str());
1828         } else {
1829                 fl_set_input(fd_form_document->input_float_placement, "");
1830         }
1831         if (!params->options.empty())
1832                 fl_set_input(fd_form_document->input_extra,
1833                              params->options.c_str());
1834         else
1835                 fl_set_input(fd_form_document->input_extra, "");
1836
1837         if (current_view->buffer()->isSGML()) {
1838                 // bullets not used in SGML derived documents
1839                 fl_deactivate_object(fd_form_document->button_bullets);
1840                 fl_set_object_lcol(fd_form_document->button_bullets,
1841                                    FL_INACTIVE);
1842         } else {
1843                 fl_activate_object(fd_form_document->button_bullets);
1844                 fl_set_object_lcol(fd_form_document->button_bullets,
1845                                    FL_BLACK);
1846         }
1847
1848         if (current_view->buffer()->isReadonly()) {
1849                 DisableDocumentLayout();
1850         } else {
1851                 EnableDocumentLayout();
1852         }
1853
1854         return true;
1855 }
1856
1857
1858 void MenuLayoutDocument()
1859 {
1860         if (UpdateLayoutDocument()) {
1861                 if (fd_form_document->form_document->visible) {
1862                         fl_raise_form(fd_form_document->form_document);
1863                 } else {
1864                         fl_show_form(fd_form_document->form_document,
1865                                      FL_PLACE_MOUSE, FL_FULLBORDER,
1866                                      _("Document Layout"));
1867                 }
1868         }
1869 }
1870
1871
1872 bool UpdateLayoutQuotes()
1873 {
1874         bool update = true;
1875         if (!current_view->available()
1876             || current_view->buffer()->isReadonly())
1877                 update = false;
1878         
1879         if (update) {
1880                 fl_set_choice(fd_form_quotes->choice_quotes_language,
1881                               current_view->buffer()->params.quotes_language + 1);
1882                 fl_set_button(fd_form_quotes->radio_single, 0);
1883                 fl_set_button(fd_form_quotes->radio_double, 0);
1884         
1885                 if (current_view->buffer()->params.quotes_times == InsetQuotes::SingleQ)
1886                         fl_set_button(fd_form_quotes->radio_single, 1);
1887                 else
1888                         fl_set_button(fd_form_quotes->radio_double, 1);
1889         } else if (fd_form_quotes->form_quotes->visible) {
1890                 fl_hide_form(fd_form_quotes->form_quotes);
1891         }
1892         return update;
1893 }
1894
1895
1896 void MenuLayoutQuotes()
1897 {
1898         if (UpdateLayoutQuotes()) {
1899                 if (fd_form_quotes->form_quotes->visible) {
1900                         fl_raise_form(fd_form_quotes->form_quotes);
1901                 } else {
1902                         fl_show_form(fd_form_quotes->form_quotes,
1903                                      FL_PLACE_MOUSE, FL_FULLBORDER,
1904                                      _("Quotes"));
1905                 }
1906         }
1907 }
1908
1909
1910 bool UpdateLayoutPreamble()
1911 {
1912         bool update = true;
1913         if (!current_view->available())
1914                 update = false;
1915
1916         if (update) {
1917                 fl_set_input(fd_form_preamble->input_preamble,
1918                              current_view->buffer()->params.preamble.c_str());
1919
1920                 if (current_view->buffer()->isReadonly()) {
1921                         fl_deactivate_object(fd_form_preamble->input_preamble);
1922                         fl_deactivate_object(fd_form_preamble->button_ok);
1923                         fl_deactivate_object(fd_form_preamble->button_apply);
1924                         fl_set_object_lcol(fd_form_preamble->button_ok, FL_INACTIVE);
1925                         fl_set_object_lcol(fd_form_preamble->button_apply, FL_INACTIVE);
1926                 }
1927                 else {
1928                         fl_activate_object(fd_form_preamble->input_preamble);
1929                         fl_activate_object(fd_form_preamble->button_ok);
1930                         fl_activate_object(fd_form_preamble->button_apply);
1931                         fl_set_object_lcol(fd_form_preamble->button_ok, FL_BLACK);
1932                         fl_set_object_lcol(fd_form_preamble->button_apply, FL_BLACK);
1933                 }
1934         } else if (fd_form_preamble->form_preamble->visible) {
1935                 fl_hide_form(fd_form_preamble->form_preamble);
1936         }
1937         return update;
1938 }
1939
1940
1941 void MenuLayoutPreamble()
1942 {
1943         static int ow = -1, oh;
1944
1945         if (UpdateLayoutPreamble()) {
1946                 if (fd_form_preamble->form_preamble->visible) {
1947                         fl_raise_form(fd_form_preamble->form_preamble);
1948                 } else {
1949                         fl_show_form(fd_form_preamble->form_preamble,
1950                                      FL_PLACE_MOUSE | FL_FREE_SIZE,
1951                                      FL_FULLBORDER,
1952                                      _("LaTeX Preamble"));
1953                         if (ow < 0) {
1954                                 ow = fd_form_preamble->form_preamble->w;
1955                                 oh = fd_form_preamble->form_preamble->h;
1956                         }
1957                         fl_set_form_minsize(fd_form_preamble->form_preamble,
1958                                             ow, oh);
1959                 }
1960         }
1961 }
1962
1963
1964 void MenuLayoutSave()
1965 {
1966         if (!current_view->available())
1967                 return;
1968
1969         if (AskQuestion(_("Do you want to save the current settings"),
1970                         _("for Character, Document, Paper and Quotes"),
1971                         _("as default for new documents?")))
1972                 current_view->buffer()->saveParamsAsDefaults();
1973 }
1974
1975
1976 // This is both GUI and LyXFont dependent. Don't know where to put it. (Asger)
1977 // Well, it's mostly GUI dependent, so I guess it will stay here. (Asger)
1978 LyXFont UserFreeFont()
1979 {
1980         LyXFont font(LyXFont::ALL_IGNORE);
1981
1982         int pos = fl_get_choice(fd_form_character->choice_family);
1983         switch(pos) {
1984         case 1: font.setFamily(LyXFont::IGNORE_FAMILY); break;
1985         case 2: font.setFamily(LyXFont::ROMAN_FAMILY); break;
1986         case 3: font.setFamily(LyXFont::SANS_FAMILY); break;
1987         case 4: font.setFamily(LyXFont::TYPEWRITER_FAMILY); break;
1988         case 5: font.setFamily(LyXFont::INHERIT_FAMILY); break;
1989         }
1990
1991         pos = fl_get_choice(fd_form_character->choice_series);
1992         switch(pos) {
1993         case 1: font.setSeries(LyXFont::IGNORE_SERIES); break;
1994         case 2: font.setSeries(LyXFont::MEDIUM_SERIES); break;
1995         case 3: font.setSeries(LyXFont::BOLD_SERIES); break;
1996         case 4: font.setSeries(LyXFont::INHERIT_SERIES); break;
1997         }
1998
1999         pos = fl_get_choice(fd_form_character->choice_shape);
2000         switch(pos) {
2001         case 1: font.setShape(LyXFont::IGNORE_SHAPE); break;
2002         case 2: font.setShape(LyXFont::UP_SHAPE); break;
2003         case 3: font.setShape(LyXFont::ITALIC_SHAPE); break;
2004         case 4: font.setShape(LyXFont::SLANTED_SHAPE); break;
2005         case 5: font.setShape(LyXFont::SMALLCAPS_SHAPE); break;
2006         case 6: font.setShape(LyXFont::INHERIT_SHAPE); break;
2007         }
2008
2009         pos = fl_get_choice(fd_form_character->choice_size);
2010         switch(pos) {
2011         case 1: font.setSize(LyXFont::IGNORE_SIZE); break;
2012         case 2: font.setSize(LyXFont::SIZE_TINY); break;
2013         case 3: font.setSize(LyXFont::SIZE_SCRIPT); break;
2014         case 4: font.setSize(LyXFont::SIZE_FOOTNOTE); break;
2015         case 5: font.setSize(LyXFont::SIZE_SMALL); break;
2016         case 6: font.setSize(LyXFont::SIZE_NORMAL); break;
2017         case 7: font.setSize(LyXFont::SIZE_LARGE); break;
2018         case 8: font.setSize(LyXFont::SIZE_LARGER); break;
2019         case 9: font.setSize(LyXFont::SIZE_LARGEST); break;
2020         case 10: font.setSize(LyXFont::SIZE_HUGE); break;
2021         case 11: font.setSize(LyXFont::SIZE_HUGER); break;
2022         case 12: font.setSize(LyXFont::INCREASE_SIZE); break;
2023         case 13: font.setSize(LyXFont::DECREASE_SIZE); break;
2024         case 14: font.setSize(LyXFont::INHERIT_SIZE); break;
2025         }
2026
2027         pos = fl_get_choice(fd_form_character->choice_bar);
2028         switch(pos) {
2029         case 1: font.setEmph(LyXFont::IGNORE);
2030                 font.setUnderbar(LyXFont::IGNORE);
2031                 font.setNoun(LyXFont::IGNORE);
2032                 font.setLatex(LyXFont::IGNORE);
2033                 break;
2034         case 2: font.setEmph(LyXFont::TOGGLE); break;
2035         case 3: font.setUnderbar(LyXFont::TOGGLE); break;
2036         case 4: font.setNoun(LyXFont::TOGGLE); break;
2037         case 5: font.setLatex(LyXFont::TOGGLE); break;
2038         case 6: font.setEmph(LyXFont::INHERIT);
2039                 font.setUnderbar(LyXFont::INHERIT);
2040                 font.setNoun(LyXFont::INHERIT);
2041                 font.setLatex(LyXFont::INHERIT);
2042                 break;
2043         }
2044
2045         pos = fl_get_choice(fd_form_character->choice_color);
2046         switch(pos) {
2047         case 1: font.setColor(LColor::ignore); break;
2048         case 2: font.setColor(LColor::none); break;
2049         case 3: font.setColor(LColor::black); break;
2050         case 4: font.setColor(LColor::white); break;
2051         case 5: font.setColor(LColor::red); break;
2052         case 6: font.setColor(LColor::green); break;
2053         case 7: font.setColor(LColor::blue); break;
2054         case 8: font.setColor(LColor::cyan); break;
2055         case 9: font.setColor(LColor::magenta); break;
2056         case 10: font.setColor(LColor::yellow); break;
2057         case 11: font.setColor(LColor::inherit); break;
2058         }
2059
2060         string language = combo_language2->getline();
2061         Languages::iterator lit = languages.find(language);
2062         if (lit != languages.end()) 
2063                 font.setLanguage(&(*lit).second);
2064         else
2065                 font.setLanguage(ignore_language);
2066
2067
2068         return font; 
2069 }
2070
2071
2072
2073
2074 /* callbacks for form form_title */
2075 extern "C" void TimerCB(FL_OBJECT *, long)
2076 {
2077         // only if the form still exists
2078         if (lyxrc.show_banner && fd_form_title->form_title != 0) {
2079                 if (fd_form_title->form_title->visible) {
2080                         fl_hide_form(fd_form_title->form_title);
2081                 }
2082                 fl_free_form(fd_form_title->form_title);
2083                 fd_form_title->form_title = 0;
2084         }
2085 }
2086
2087
2088 /* callbacks for form form_paragraph */
2089
2090 extern "C" void ParagraphVSpaceCB(FL_OBJECT * obj, long )
2091 {
2092         // "Synchronize" the choices and input fields, making it
2093         // impossible to commit senseless data.
2094
2095         FD_form_paragraph const * fp = fd_form_paragraph;
2096
2097         if (obj == fp->choice_space_above) {
2098                 if (fl_get_choice (fp->choice_space_above) != 7) {
2099                         fl_set_input (fp->input_space_above, "");
2100                         ActivateParagraphButtons();
2101                 }
2102         } else if (obj == fp->choice_space_below) {
2103                 if (fl_get_choice (fp->choice_space_below) != 7) {
2104                         fl_set_input (fp->input_space_below, "");
2105                         ActivateParagraphButtons();
2106                 }
2107         } else if (obj == fp->input_space_above) {
2108                 string input = fl_get_input (fp->input_space_above);
2109
2110                 if (input.empty()) {
2111                         fl_set_choice (fp->choice_space_above, 1);
2112                         ActivateParagraphButtons();
2113                 }
2114                 else if (isValidGlueLength (input)) {
2115                         fl_set_choice (fp->choice_space_above, 7);
2116                         ActivateParagraphButtons();
2117                 }
2118                 else {
2119                         fl_set_choice (fp->choice_space_above, 7);
2120                         DeactivateParagraphButtons();
2121                 }
2122         } else if (obj == fp->input_space_below) {
2123                 string input = fl_get_input (fp->input_space_below);
2124
2125                 if (input.empty()) {
2126                         fl_set_choice (fp->choice_space_below, 1);
2127                         ActivateParagraphButtons();
2128                 }
2129                 else if (isValidGlueLength (input)) {
2130                         fl_set_choice (fp->choice_space_below, 7);
2131                         ActivateParagraphButtons();
2132                 }
2133                 else {
2134                         fl_set_choice (fp->choice_space_below, 7);
2135                         DeactivateParagraphButtons();
2136                 }
2137         }
2138 }
2139
2140
2141 extern "C" void ParagraphApplyCB(FL_OBJECT *, long)
2142 {
2143         if (!current_view->available())
2144                 return;
2145         
2146         VSpace space_top, space_bottom;
2147         LyXAlignment align;
2148         string labelwidthstring;
2149         bool noindent;
2150
2151         // If a vspace kind is "Length" but there's no text in
2152         // the input field, reset the kind to "None". 
2153         if (fl_get_choice (fd_form_paragraph->choice_space_above) == 7
2154             && !*(fl_get_input (fd_form_paragraph->input_space_above))) {
2155                 fl_set_choice (fd_form_paragraph->choice_space_above, 1);
2156         }
2157         if (fl_get_choice (fd_form_paragraph->choice_space_below) == 7
2158             && !*(fl_get_input (fd_form_paragraph->input_space_below))) {
2159                 fl_set_choice (fd_form_paragraph->choice_space_below, 1);
2160         }
2161    
2162         bool line_top = fl_get_button(fd_form_paragraph->check_lines_top);
2163         bool line_bottom = fl_get_button(fd_form_paragraph->check_lines_bottom);
2164         bool pagebreak_top = fl_get_button(fd_form_paragraph->check_pagebreaks_top);
2165         bool pagebreak_bottom = fl_get_button(fd_form_paragraph->check_pagebreaks_bottom);
2166         switch (fl_get_choice (fd_form_paragraph->choice_space_above)) {
2167         case 1: space_top = VSpace(VSpace::NONE); break;
2168         case 2: space_top = VSpace(VSpace::DEFSKIP); break;
2169         case 3: space_top = VSpace(VSpace::SMALLSKIP); break;
2170         case 4: space_top = VSpace(VSpace::MEDSKIP); break;
2171         case 5: space_top = VSpace(VSpace::BIGSKIP); break;
2172         case 6: space_top = VSpace(VSpace::VFILL); break;
2173         case 7: space_top = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_above))); break;
2174         }
2175         if (fl_get_button (fd_form_paragraph->check_space_above))
2176                 space_top.setKeep (true);
2177         switch (fl_get_choice (fd_form_paragraph->choice_space_below)) {
2178         case 1: space_bottom = VSpace(VSpace::NONE); break;
2179         case 2: space_bottom = VSpace(VSpace::DEFSKIP); break;
2180         case 3: space_bottom = VSpace(VSpace::SMALLSKIP); break;
2181         case 4: space_bottom = VSpace(VSpace::MEDSKIP); break;
2182         case 5: space_bottom = VSpace(VSpace::BIGSKIP); break;
2183         case 6: space_bottom = VSpace(VSpace::VFILL); break;
2184         case 7: space_bottom = VSpace(LyXGlueLength (fl_get_input (fd_form_paragraph->input_space_below))); break;
2185         }
2186         if (fl_get_button (fd_form_paragraph->check_space_below))
2187                 space_bottom.setKeep (true);
2188
2189         if (fl_get_button(fd_form_paragraph->radio_align_left))
2190                 align = LYX_ALIGN_LEFT;
2191         else if (fl_get_button(fd_form_paragraph->radio_align_right))
2192                 align = LYX_ALIGN_RIGHT;
2193         else if (fl_get_button(fd_form_paragraph->radio_align_center))
2194                 align = LYX_ALIGN_CENTER;
2195         else 
2196                 align = LYX_ALIGN_BLOCK;
2197    
2198         labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth);
2199         noindent = fl_get_button(fd_form_paragraph->check_noindent);
2200
2201         current_view->text->SetParagraph(line_top,
2202                                          line_bottom,
2203                                          pagebreak_top,
2204                                          pagebreak_bottom,
2205                                          space_top,
2206                                          space_bottom,
2207                                          align, 
2208                                          labelwidthstring,
2209                                          noindent);
2210         current_view->update(1);
2211         current_view->owner()->getMiniBuffer()->Set(_("Paragraph layout set"));
2212 }
2213
2214
2215 extern "C" void ParagraphCancelCB(FL_OBJECT *, long)
2216 {
2217         fl_hide_form(fd_form_paragraph->form_paragraph);
2218 }
2219
2220
2221 extern "C" void ParagraphOKCB(FL_OBJECT *ob, long data)
2222 {
2223         ParagraphApplyCB(ob, data);
2224         ParagraphCancelCB(ob, data);
2225 }
2226
2227
2228 /* callbacks for form form_character */
2229
2230 extern "C" void CharacterApplyCB(FL_OBJECT *, long)
2231 {
2232         // we set toggleall locally here, since it should be true for
2233         // all other uses of ToggleAndShow() (JMarc)
2234         toggleall = fl_get_button(fd_form_character->check_toggle_all);
2235         ToggleAndShow(current_view, UserFreeFont());
2236         current_view->setState();
2237         toggleall = true;
2238 }
2239
2240
2241 extern "C" void CharacterCloseCB(FL_OBJECT *, long)
2242 {
2243         fl_hide_form(fd_form_character->form_character);
2244 }
2245
2246
2247 extern "C" void CharacterOKCB(FL_OBJECT *ob, long data)
2248 {
2249         CharacterApplyCB(ob, data);
2250         CharacterCloseCB(ob, data);
2251 }
2252
2253
2254 /* callbacks for form form_document */
2255
2256 void UpdateDocumentButtons(BufferParams const & params) 
2257 {
2258         fl_set_choice(fd_form_document->choice_pagestyle, 1);
2259
2260         switch (params.sides) {
2261         case LyXTextClass::OneSide:
2262                 fl_set_button(fd_form_document->radio_sides_one, 1);
2263                 break;
2264         case LyXTextClass::TwoSides:
2265                 fl_set_button(fd_form_document->radio_sides_two, 1);
2266                 break;
2267         }
2268    
2269         if (params.columns == 2)
2270                 fl_set_button(fd_form_document->radio_columns_two, 1);
2271         else
2272                 fl_set_button(fd_form_document->radio_columns_one, 1);
2273         
2274         fl_set_input(fd_form_document->input_extra, params.options.c_str());
2275         fl_set_counter_value(fd_form_document->slider_secnumdepth, 
2276                              params.secnumdepth);
2277         fl_set_counter_value(fd_form_document->slider_tocdepth, 
2278                              params.tocdepth);
2279         
2280 }
2281
2282 extern "C" void ChoiceClassCB(FL_OBJECT * ob, long)
2283 {
2284         ProhibitInput(current_view);
2285         if (textclasslist.Load(fl_get_choice(ob)-1)) {
2286                 if (AskQuestion(_("Should I set some parameters to"),
2287                                 fl_get_choice_text(ob),
2288                                 _("the defaults of this document class?"))) {
2289                         BufferParams params = BufferParams();
2290                         params.textclass = fl_get_choice(ob)-1;
2291                         params.useClassDefaults();
2292                         UpdateLayoutDocument(&params);
2293                         UpdateDocumentButtons(params);
2294                 }
2295         } else {
2296                 // unable to load new style
2297                 WriteAlert(_("Conversion Errors!"),
2298                            _("Unable to switch to new document class."),
2299                            _("Reverting to original document class."));
2300                 fl_set_choice(fd_form_document->choice_class, 
2301                               current_view->buffer()->params.textclass + 1);
2302         }
2303         AllowInput(current_view);
2304 }
2305
2306
2307 extern "C" void DocumentDefskipCB(FL_OBJECT * obj, long)
2308 {
2309         // "Synchronize" the choice and the input field, so that it
2310         // is impossible to commit senseless data.
2311         FD_form_document const * fd = fd_form_document;
2312
2313         if (obj == fd->choice_default_skip) {
2314                 if (fl_get_choice (fd->choice_default_skip) != 4) {
2315                         fl_set_input (fd->input_default_skip, "");
2316                         ActivateDocumentButtons();
2317                 }
2318         } else if (obj == fd->input_default_skip) {
2319
2320                 char const * input = fl_get_input (fd->input_default_skip);
2321
2322                 if (!*input) {
2323                         fl_set_choice (fd->choice_default_skip, 2);
2324                         ActivateDocumentButtons();
2325                 } else if (isValidGlueLength (input)) {
2326                         fl_set_choice (fd->choice_default_skip, 4);
2327                         ActivateDocumentButtons();
2328                 } else {
2329                         fl_set_choice (fd->choice_default_skip, 4);
2330                         DeactivateDocumentButtons();
2331                 }
2332         }
2333 }
2334
2335
2336 extern "C" void DocumentSpacingCB(FL_OBJECT * obj, long)
2337 {
2338         // "Synchronize" the choice and the input field, so that it
2339         // is impossible to commit senseless data.
2340         FD_form_document const * fd = fd_form_document;
2341
2342         if (obj == fd->choice_spacing
2343             && fl_get_choice (fd->choice_spacing) != 4) {
2344                 fl_set_input(fd->input_spacing, "");
2345         } else if (obj == fd->input_spacing) {
2346
2347                 const char* input = fl_get_input (fd->input_spacing);
2348
2349                 if (!*input) {
2350                         fl_set_choice (fd->choice_spacing, 1);
2351                 } else {
2352                         fl_set_choice (fd->choice_spacing, 4);
2353                 }
2354         }
2355 }
2356
2357
2358 extern "C" void DocumentApplyCB(FL_OBJECT *, long)
2359 {
2360         bool redo = false;
2361         BufferParams * params = &(current_view->buffer()->params);
2362
2363         Language const * old_language = params->language_info;
2364         params->language = combo_language->getline();
2365         Languages::iterator lit = languages.find(params->language);
2366
2367         Language const * new_language;
2368         if (lit != languages.end()) 
2369                 new_language = &(*lit).second;
2370         else
2371                 new_language = default_language;
2372
2373         if (current_view->available()) {
2374                 if (old_language != new_language &&
2375                     old_language->RightToLeft == new_language->RightToLeft && 
2376                     ! current_view->buffer()->isMultiLingual() ) {
2377                         current_view->buffer()->ChangeLanguage(old_language,
2378                                                                new_language);
2379                         current_view->buffer()->redraw();
2380                 }
2381         }
2382         params->language_info = new_language;
2383
2384         // If default skip is a "Length" but there's no text in the
2385         // input field, reset the kind to "Medskip", which is the default.
2386         if (fl_get_choice (fd_form_document->choice_default_skip) == 4
2387             && !*(fl_get_input (fd_form_document->input_default_skip))) {
2388                 fl_set_choice (fd_form_document->choice_default_skip, 2);
2389         }
2390
2391         /* this shouldn't be done automatically IMO. For example I write german
2392          * documents with an american keyboard very often. Matthias */
2393    
2394         /* ChangeKeymap(buffer->parameters.language, TRUE, false,
2395            fl_get_choice(fd_form_document->choice_language)); */
2396         params->fonts = 
2397                 fl_get_choice_text(fd_form_document->choice_fonts);
2398         params->inputenc = 
2399                 fl_get_choice_text(fd_form_document->choice_inputenc);
2400         params->fontsize = 
2401                 fl_get_choice_text(fd_form_document->choice_fontsize);
2402         params->pagestyle = 
2403                 fl_get_choice_text(fd_form_document->choice_pagestyle);
2404         params->graphicsDriver = 
2405                 fl_get_choice_text(fd_form_document->choice_postscript_driver);
2406         params->use_amsmath = 
2407                 fl_get_button(fd_form_document->check_use_amsmath);
2408    
2409         if (!current_view->available())
2410                 return;
2411
2412         current_view->text->SetCursor(current_view->text->cursor.par,
2413                                       current_view->text->cursor.pos);
2414         current_view->setState();
2415
2416         LyXTextClassList::ClassList::size_type new_class =
2417                 fl_get_choice(fd_form_document->choice_class) - 1;
2418
2419         if (params->textclass != new_class) {
2420                 // try to load new_class
2421                 if (textclasslist.Load(new_class)) {
2422                         // successfully loaded
2423                         redo = true;
2424                         current_view->owner()->getMiniBuffer()->
2425                                 Set(_("Converting document to new document class..."));
2426                         CutAndPaste cap;
2427                         int ret = cap.SwitchLayoutsBetweenClasses(
2428                                 current_view->buffer()->params.textclass,
2429                                 new_class,
2430                                 current_view->buffer()->paragraph);
2431
2432                         if (ret) {
2433                                 string s;
2434                                 if (ret == 1)
2435                                         s = _("One paragraph couldn't be converted");
2436                                 else {
2437                                         s += tostr(ret);
2438                                         s += _(" paragraphs couldn't be converted");
2439                                 }
2440                                 WriteAlert(_("Conversion Errors!"), s,
2441                                            _("into chosen document class"));
2442                         }
2443
2444                         params->textclass = new_class;
2445                 } else {
2446                         // problem changing class -- warn user and retain old style
2447                         WriteAlert(_("Conversion Errors!"),
2448                                    _("Unable to switch to new document class."),
2449                                    _("Reverting to original document class."));
2450                         fl_set_choice(fd_form_document->choice_class, params->textclass + 1);
2451                 }
2452         }
2453
2454         char tmpsep = params->paragraph_separation;
2455         if (fl_get_button(fd_form_document->radio_indent))
2456                 params->paragraph_separation = BufferParams::PARSEP_INDENT;
2457         else
2458                 params->paragraph_separation = BufferParams::PARSEP_SKIP;
2459         if (tmpsep != params->paragraph_separation)
2460                 redo = true;
2461    
2462         VSpace tmpdefskip = params->getDefSkip();
2463         switch (fl_get_choice (fd_form_document->choice_default_skip)) {
2464         case 1: params->setDefSkip(VSpace(VSpace::SMALLSKIP)); break;
2465         case 2: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2466         case 3: params->setDefSkip(VSpace(VSpace::BIGSKIP)); break;
2467         case 4: params->setDefSkip( 
2468                 VSpace (LyXGlueLength (fl_get_input 
2469                                        (fd_form_document->input_default_skip))));
2470         break;
2471         // DocumentDefskipCB assures that this never happens
2472         default: params->setDefSkip(VSpace(VSpace::MEDSKIP)); break;
2473         }
2474         if (!(tmpdefskip == params->getDefSkip()))
2475                 redo = true;
2476
2477         if (fl_get_button(fd_form_document->radio_columns_two))
2478                 params->columns = 2;
2479         else
2480                 params->columns = 1;
2481         if (fl_get_button(fd_form_document->radio_sides_two))
2482                 params->sides = LyXTextClass::TwoSides;
2483         else
2484                 params->sides = LyXTextClass::OneSide;
2485
2486         Spacing tmpSpacing = params->spacing;
2487         switch(fl_get_choice(fd_form_document->choice_spacing)) {
2488         case 1:
2489                 lyxerr.debug() << "Spacing: SINGLE" << endl;
2490                 params->spacing.set(Spacing::Single);
2491                 break;
2492         case 2:
2493                 lyxerr.debug() << "Spacing: ONEHALF" << endl;
2494                 params->spacing.set(Spacing::Onehalf);
2495                 break;
2496         case 3:
2497                 lyxerr.debug() << "Spacing: DOUBLE" << endl;
2498                 params->spacing.set(Spacing::Double);
2499                 break;
2500         case 4:
2501                 lyxerr.debug() << "Spacing: OTHER" << endl;
2502                 params->spacing.set(Spacing::Other, 
2503                                     fl_get_input(fd_form_document->input_spacing));
2504                 break;
2505         }
2506         if (tmpSpacing != params->spacing)
2507                 redo = true;
2508         
2509         signed char tmpchar =  
2510                 static_cast<signed char>(fl_get_counter_value(fd_form_document->slider_secnumdepth));
2511         if (params->secnumdepth != tmpchar)
2512                 redo = true;
2513         params->secnumdepth = tmpchar;
2514    
2515         params->tocdepth =  
2516                 static_cast<int>(fl_get_counter_value(fd_form_document->slider_tocdepth));
2517
2518         params->float_placement = 
2519                 fl_get_input(fd_form_document->input_float_placement);
2520
2521         // More checking should be done to ensure the string doesn't have
2522         // spaces or illegal placement characters in it. (thornley)
2523
2524         if (redo)
2525                 current_view->redoCurrentBuffer();
2526    
2527         current_view->owner()->getMiniBuffer()->Set(_("Document layout set"));
2528         current_view->buffer()->markDirty();
2529
2530         params->options = 
2531                 fl_get_input(fd_form_document->input_extra);
2532    
2533 }
2534
2535
2536 extern "C" void DocumentCancelCB(FL_OBJECT *, long)
2537 {
2538         fl_hide_form(fd_form_document->form_document);
2539 }
2540
2541
2542 extern "C" void DocumentOKCB(FL_OBJECT * ob, long data)
2543 {
2544         DocumentCancelCB(ob, data);
2545         DocumentApplyCB(ob, data);
2546 }
2547
2548
2549 extern "C" void DocumentBulletsCB(FL_OBJECT *, long)
2550 {
2551         bulletForm();
2552         // bullet callbacks etc. in bullet_panel.C -- ARRae
2553 }
2554
2555
2556 /* callbacks for form form_quotes */
2557
2558 extern "C" void QuotesApplyCB(FL_OBJECT *, long)
2559 {
2560         if (!current_view->available())
2561                 return;
2562         
2563         current_view->owner()->getMiniBuffer()->Set(_("Quotes type set"));
2564         InsetQuotes::quote_language lga = InsetQuotes::EnglishQ;
2565         switch(fl_get_choice(fd_form_quotes->choice_quotes_language) - 1) {
2566         case 0:
2567                 lga = InsetQuotes::EnglishQ;
2568                 break;
2569         case 1:
2570                 lga = InsetQuotes::SwedishQ;
2571                 break;
2572         case 2:
2573                 lga = InsetQuotes::GermanQ;
2574                 break;
2575         case 3:
2576                 lga = InsetQuotes::PolishQ;
2577                 break;
2578         case 4:
2579                 lga = InsetQuotes::FrenchQ;
2580                 break;
2581         case 5:
2582                 lga = InsetQuotes::DanishQ;
2583                 break;
2584         }
2585         current_view->buffer()->params.quotes_language = lga;
2586         if (fl_get_button(fd_form_quotes->radio_single))   
2587                 current_view->buffer()->
2588                         params.quotes_times = InsetQuotes::SingleQ;
2589         else
2590                 current_view->buffer()->
2591                         params.quotes_times = InsetQuotes::DoubleQ;
2592 }
2593
2594
2595 extern "C" void QuotesCancelCB(FL_OBJECT *, long)
2596 {
2597         fl_hide_form(fd_form_quotes->form_quotes);
2598 }
2599
2600
2601 extern "C" void QuotesOKCB(FL_OBJECT * ob, long data)
2602 {
2603         QuotesApplyCB(ob, data);
2604         QuotesCancelCB(ob, data);
2605 }
2606
2607
2608
2609 /* callbacks for form form_preamble */
2610
2611 extern "C" void PreambleCancelCB(FL_OBJECT *, long)
2612 {
2613         fl_hide_form(fd_form_preamble->form_preamble);
2614 }
2615
2616
2617 extern "C" void PreambleApplyCB(FL_OBJECT *, long)
2618 {
2619         if (!current_view->available())
2620                 return;
2621         
2622         current_view->buffer()->params.preamble = 
2623                 fl_get_input(fd_form_preamble->input_preamble);
2624         current_view->buffer()->markDirty();
2625         current_view->owner()->getMiniBuffer()->Set(_("LaTeX preamble set"));
2626 }
2627
2628    
2629 extern "C" void PreambleOKCB(FL_OBJECT * ob, long data)
2630 {
2631         PreambleApplyCB(ob, data);
2632         PreambleCancelCB(ob, data);
2633 }
2634
2635
2636 /* callbacks for form form_table */
2637
2638 extern "C" void TableApplyCB(FL_OBJECT *, long)
2639 {
2640         if (!current_view->available())
2641                 return;
2642    
2643         // check for tables in tables
2644         if (current_view->text->cursor.par->table){
2645                 WriteAlert(_("Impossible Operation!"),
2646                            _("Cannot insert table in table."),
2647                            _("Sorry."));
2648                 return;
2649         }
2650  
2651         current_view->owner()->getMiniBuffer()->Set(_("Inserting table..."));
2652
2653         int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5);
2654         int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5);
2655    
2656    
2657         current_view->hideCursor();
2658         current_view->beforeChange();
2659         current_view->update(-2);
2660    
2661         current_view->text->SetCursorParUndo(); 
2662         current_view->text->FreezeUndo();
2663
2664         current_view->text->BreakParagraph();
2665         current_view->update(-1);
2666    
2667         if (current_view->text->cursor.par->Last()) {
2668                 current_view->text->CursorLeft();
2669       
2670                 current_view->text->BreakParagraph();
2671                 current_view->update(-1);
2672         }
2673
2674         current_view->text->current_font.setLatex(LyXFont::OFF);
2675         //if (!fl_get_button(fd_form_table->check_latex)){
2676         // insert the new wysiwy table
2677         current_view->text->SetLayout(0); // standard layout
2678         if (current_view->text->cursor.par->footnoteflag == 
2679             LyXParagraph::NO_FOOTNOTE) {
2680                 current_view->text
2681                         ->SetParagraph(0, 0,
2682                                        0, 0,
2683                                        VSpace (0.3 * current_view->buffer()->
2684                                                params.spacing.getValue(),
2685                                                LyXLength::CM),
2686                                        VSpace (0.3 * current_view->buffer()->
2687                                                params.spacing.getValue(),
2688                                                LyXLength::CM),
2689                                        LYX_ALIGN_CENTER,
2690                                        string(),
2691                                        0);
2692         } else {
2693                 current_view->text
2694                         ->SetParagraph(0, 0,
2695                                        0, 0,
2696                                        VSpace(VSpace::NONE),
2697                                        VSpace(VSpace::NONE),
2698                                        LYX_ALIGN_CENTER, 
2699                                        string(),
2700                                        0);
2701         }
2702         
2703         current_view->text->cursor.par->table =
2704                 new LyXTable(xsize, ysize);
2705
2706         Language const * lang = 
2707                 current_view->text->cursor.par->getParLanguage();
2708         LyXFont font(LyXFont::ALL_INHERIT, lang);
2709         for (int i = 0; i < xsize * ysize - 1; ++i) {
2710                 current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE);
2711                 current_view->text->cursor.par->SetFont(0, font);
2712         }
2713         current_view->text->RedoParagraph();
2714    
2715         current_view->text->UnFreezeUndo();
2716      
2717         current_view->update(1);
2718         current_view->owner()->getMiniBuffer()->Set(_("Table inserted"));
2719         current_view->setState();
2720 }
2721
2722
2723 extern "C" void TableCancelCB(FL_OBJECT *, long)
2724 {
2725         fl_hide_form(fd_form_table->form_table);
2726 }
2727
2728
2729 extern "C" void TableOKCB(FL_OBJECT * ob, long data)
2730 {
2731         TableApplyCB(ob, data);
2732         TableCancelCB(ob, data);
2733 }
2734
2735
2736 /* callbacks for form form_print */
2737
2738 extern "C" void PrintCancelCB(FL_OBJECT *, long)
2739 {
2740         fl_hide_form(fd_form_print->form_print);
2741 }
2742
2743
2744 static
2745 bool stringOnlyContains (string const & LStr, char const * cset)
2746 {
2747         return LStr.find_first_not_of(cset) == string::npos;
2748 }
2749
2750
2751 extern "C" void PrintApplyCB(FL_OBJECT *, long)
2752 {
2753         if (!current_view->available())
2754                 return;
2755         Buffer * buffer = current_view->buffer();
2756         string path = OnlyPath(buffer->fileName());
2757
2758         string pageflag;
2759         if (fl_get_button(fd_form_print->radio_even_pages))
2760                 pageflag = lyxrc.print_evenpage_flag + ' ';
2761         else if (fl_get_button(fd_form_print->radio_odd_pages))
2762                 pageflag = lyxrc.print_oddpage_flag + ' ';
2763
2764 // Changes by Stephan Witt (stephan.witt@beusen.de), 19-Jan-99
2765 // User may give a page (range) list
2766 // User may print multiple (unsorted) copies
2767         string pages = subst(fl_get_input(fd_form_print->input_pages), ';',',');
2768         pages = subst(pages, '+',',');
2769         pages = frontStrip(strip(pages)) ;
2770         while (!pages.empty()) { // a page range was given
2771                 string piece ;
2772                 pages = split (pages, piece, ',') ;
2773                 piece = strip(piece) ;
2774                 piece = frontStrip(piece) ;
2775                 if ( !stringOnlyContains (piece, "0123456789-") ) {
2776                         WriteAlert(_("ERROR!  Unable to print!"),
2777                                    _("Check 'range of pages'!"));
2778                         return;
2779                 }
2780                 if (piece.find('-') == string::npos) { // not found
2781                         pageflag += lyxrc.print_pagerange_flag + piece + '-' + piece + ' ' ;
2782                 } else if (suffixIs(piece, "-") ) { // missing last page
2783                         pageflag += lyxrc.print_pagerange_flag + piece + "1000 ";
2784                 } else if (prefixIs(piece, "-") ) { // missing first page
2785                         pageflag += lyxrc.print_pagerange_flag + '1' + piece + ' ' ;
2786                 } else {
2787                         pageflag += lyxrc.print_pagerange_flag + piece + ' ' ;
2788                 }
2789         }
2790    
2791         string copies = frontStrip(strip(fl_get_input(fd_form_print->input_copies)));
2792         if (!copies.empty()) { // a number of copies was given
2793                 if ( !stringOnlyContains (copies, "0123456789") ) {
2794                         WriteAlert(_("ERROR!  Unable to print!"),
2795                                    _("Check 'number of copies'!"));
2796                         return;
2797                 }
2798                 if (fl_get_button(fd_form_print->do_unsorted))
2799                         pageflag += lyxrc.print_copies_flag;
2800                 else
2801                         pageflag += lyxrc.print_collcopies_flag;
2802                 pageflag += " " + copies + ' ' ;
2803         }
2804
2805         string reverseflag;
2806         if (fl_get_button(fd_form_print->radio_order_reverse))
2807                 reverseflag = lyxrc.print_reverse_flag + ' ';
2808    
2809         string orientationflag;
2810         if (buffer->params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2811                 orientationflag = lyxrc.print_landscape_flag + ' ';
2812    
2813         string ps_file = fl_get_input(fd_form_print->input_file);
2814         string printer = strip(fl_get_input(fd_form_print->input_printer));
2815
2816         string printerflag;
2817         if (lyxrc.print_adapt_output // printer name should be passed to dvips
2818             && ! printer.empty()) // a printer name has been given
2819                 printerflag = lyxrc.print_to_printer + printer + ' ';
2820      
2821         string extraflags;
2822         if (!lyxrc.print_extra_options.empty())
2823                 extraflags = lyxrc.print_extra_options + ' ';
2824
2825         string command = lyxrc.print_command + ' ' 
2826                 + printerflag + pageflag + reverseflag 
2827                 + orientationflag + extraflags;
2828  
2829         char real_papersize = buffer->params.papersize;
2830         if (real_papersize == BufferParams::PAPER_DEFAULT)
2831                 real_papersize = lyxrc.default_papersize;
2832         
2833         string paper;
2834         switch (real_papersize) {
2835         case BufferParams::PAPER_USLETTER:
2836                 paper = "letter";
2837                 break;
2838         case BufferParams::PAPER_A3PAPER:
2839                 paper = "a3";
2840                 break;
2841         case BufferParams::PAPER_A4PAPER:
2842                 paper = "a4";
2843                 break;
2844         case BufferParams::PAPER_A5PAPER:
2845                 paper = "a5";
2846                 break;
2847         case BufferParams::PAPER_B5PAPER:
2848                 paper = "b5";
2849                 break;
2850         case BufferParams::PAPER_EXECUTIVEPAPER:
2851                 paper = "foolscap";
2852                 break;
2853         case BufferParams::PAPER_LEGALPAPER:
2854                 paper = "legal";
2855                 break;
2856         default: /* If nothing else fits, keep an empty value... */
2857                 break;
2858         }
2859
2860         if (buffer->params.use_geometry
2861             && buffer->params.papersize2 == BufferParams::VM_PAPER_CUSTOM
2862             && !lyxrc.print_paper_dimension_flag.empty()
2863             && !buffer->params.paperwidth.empty()
2864             && !buffer->params.paperheight.empty()) {
2865                 // using a custom papersize
2866                 command += ' ';
2867                 command += lyxrc.print_paper_dimension_flag + ' ';
2868                 command += buffer->params.paperwidth + ',';
2869                 command += buffer->params.paperheight + ' ';
2870         } else if (!lyxrc.print_paper_flag.empty()
2871                    && !paper.empty()
2872                    && (real_papersize != BufferParams::PAPER_USLETTER ||
2873                        buffer->params.orientation == BufferParams::ORIENTATION_PORTRAIT)) {
2874                 command += " " + lyxrc.print_paper_flag + " " + paper + " ";
2875         }
2876         if (fl_get_button(fd_form_print->radio_file))
2877                 command += lyxrc.print_to_file 
2878                         + QuoteName(MakeAbsPath(ps_file, path));
2879         else if (!lyxrc.print_spool_command.empty())
2880                 command += lyxrc.print_to_file 
2881                         + QuoteName(ps_file);
2882         
2883         // push directorypath, if necessary 
2884         if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)){
2885                 path = buffer->tmppath;
2886         }
2887         Path p(path);
2888
2889         bool result;
2890         if (!lyxrc.print_spool_command.empty() && 
2891             !fl_get_button(fd_form_print->radio_file)) {
2892                 string command2 = lyxrc.print_spool_command + ' ';
2893                 if (!printer.empty())
2894                         command2 += lyxrc.print_spool_printerprefix 
2895                                 + printer;
2896                 // First run dvips and, if succesful, then spool command
2897                 if ((result = RunScript(buffer, true, command))) {
2898                         result = RunScript(buffer, false, command2, ps_file);
2899                 }
2900         } else
2901                 result = RunScript(buffer, false, command);
2902
2903         if (!result)
2904                 WriteAlert(_("Error:"),
2905                            _("Unable to print"),
2906                            _("Check that your parameters are correct"));
2907 }
2908
2909
2910 extern "C" void PrintOKCB(FL_OBJECT * ob, long data)
2911 {
2912         PrintCancelCB(ob, data);  
2913         PrintApplyCB(ob, data);
2914 }
2915
2916
2917 void Figure()
2918 {
2919         if (fd_form_figure->form_figure->visible) {
2920                 fl_raise_form(fd_form_figure->form_figure);
2921         } else {
2922                 fl_show_form(fd_form_figure->form_figure,
2923                              FL_PLACE_MOUSE, FL_FULLBORDER,
2924                              _("Insert Figure"));
2925         }
2926 }
2927
2928
2929 void Table()
2930 {
2931         if (fd_form_table->form_table->visible) {
2932                 fl_raise_form(fd_form_table->form_table);
2933         } else {
2934                 fl_show_form(fd_form_table->form_table,
2935                              FL_PLACE_MOUSE, FL_FULLBORDER,
2936                              _("Insert Table"));
2937         }
2938 }
2939
2940
2941 /* callbacks for form form_figure */
2942 extern "C" void FigureApplyCB(FL_OBJECT *, long)
2943 {
2944         if (!current_view->available())
2945                 return;
2946
2947         Buffer * buffer = current_view->buffer();
2948         if(buffer->isReadonly()) // paranoia
2949                 return;
2950         
2951         current_view->owner()->getMiniBuffer()->Set(_("Inserting figure..."));
2952         if (fl_get_button(fd_form_figure->radio_inline)
2953             || current_view->text->cursor.par->table) {
2954                 InsetFig * new_inset = new InsetFig(100, 20, buffer);
2955                 current_view->insertInset(new_inset);
2956                 current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
2957                 new_inset->Edit(current_view, 0, 0, 0);
2958                 return;
2959         }
2960         
2961         current_view->hideCursor();
2962         current_view->update(-2);
2963         current_view->beforeChange();
2964       
2965         current_view->text->SetCursorParUndo(); 
2966         current_view->text->FreezeUndo();
2967
2968         current_view->text->BreakParagraph();
2969         current_view->update(-1);
2970       
2971         if (current_view->text->cursor.par->Last()) {
2972                 current_view->text->CursorLeft();
2973          
2974                 current_view->text->BreakParagraph();
2975                 current_view->update(-1);
2976         }
2977
2978         // The standard layout should always be numer 0;
2979         current_view->text->SetLayout(0);
2980         
2981         if (current_view->text->cursor.par->footnoteflag == 
2982             LyXParagraph::NO_FOOTNOTE) {
2983                 current_view->text->
2984                         SetParagraph(0, 0,
2985                                      0, 0,
2986                                      VSpace (0.3 * buffer->params.spacing.getValue(),
2987                                              LyXLength::CM),
2988                                      VSpace (0.3 *
2989                                              buffer->params.spacing.getValue(),
2990                                              LyXLength::CM),
2991                                      LYX_ALIGN_CENTER, string(), 0);
2992         } else {
2993                 current_view->text->SetParagraph(0, 0,
2994                                                  0, 0,
2995                                                  VSpace(VSpace::NONE),
2996                                                  VSpace(VSpace::NONE),
2997                                                  LYX_ALIGN_CENTER, 
2998                                                  string(),
2999                                                  0);
3000         }
3001         
3002         current_view->update(-1);
3003       
3004         Inset * new_inset = new InsetFig(100, 100, buffer);
3005         current_view->insertInset(new_inset);
3006         new_inset->Edit(current_view, 0, 0, 0);
3007         current_view->update(0);
3008         current_view->owner()->getMiniBuffer()->Set(_("Figure inserted"));
3009         current_view->text->UnFreezeUndo();
3010         current_view->setState();
3011 }
3012
3013
3014 extern "C" void FigureCancelCB(FL_OBJECT *, long)
3015 {
3016         fl_hide_form(fd_form_figure->form_figure);
3017 }
3018
3019
3020 extern "C" void FigureOKCB(FL_OBJECT * ob, long data)
3021 {
3022         FigureApplyCB(ob, data);
3023         FigureCancelCB(ob, data);
3024 }
3025
3026
3027 extern "C" void ScreenApplyCB(FL_OBJECT *, long)
3028 {
3029         lyxrc.roman_font_name = fl_get_input(fd_form_screen->input_roman);
3030         lyxrc.sans_font_name = fl_get_input(fd_form_screen->input_sans);
3031         lyxrc.typewriter_font_name = fl_get_input(fd_form_screen->input_typewriter);
3032         lyxrc.font_norm = fl_get_input(fd_form_screen->input_font_norm);
3033         lyxrc.zoom = atoi(fl_get_input(fd_form_screen->intinput_size));
3034         fontloader.update();
3035
3036         // Of course we should only to the resize and the textcahce.clear
3037         // if values really changed...but not very important right now. (Lgb)
3038         
3039         // All buffers will need resize
3040         bufferlist.resize();
3041         // We also need to empty the textcache so that
3042         // the buffer will be formatted correctly after
3043         // a zoom change.
3044         textcache.clear();
3045         
3046         current_view->owner()->getMiniBuffer()->Set(_("Screen options set"));
3047 }
3048
3049
3050 extern "C" void ScreenCancelCB(FL_OBJECT *, long)
3051 {
3052         fl_hide_form(fd_form_screen->form_screen);
3053 }
3054
3055
3056 extern "C" void ScreenOKCB(FL_OBJECT * ob, long data)
3057 {
3058         ScreenCancelCB(ob, data);
3059         ScreenApplyCB(ob, data);
3060 }
3061
3062
3063 void LaTeXOptions(BufferView * bv)
3064 {
3065         if (!bv->available())
3066                 return;
3067
3068         fl_set_button(fd_latex_options->accents,
3069                       int(bv->buffer()->params.allowAccents));
3070         
3071         if (fd_latex_options->LaTeXOptions->visible) {
3072                 fl_raise_form(fd_latex_options->LaTeXOptions);
3073         } else {
3074                 fl_show_form(fd_latex_options->LaTeXOptions,
3075                              FL_PLACE_MOUSE, FL_FULLBORDER,
3076                              _("LaTeX Options"));
3077         }
3078 }
3079
3080
3081 // This function runs "configure" and then rereads lyx.defaults to
3082 // reconfigure the automatic settings.
3083 void Reconfigure(BufferView * bv)
3084 {
3085         bv->owner()->getMiniBuffer()->Set(_("Running configure..."));
3086
3087         // Run configure in user lyx directory
3088         Path p(user_lyxdir);
3089         Systemcalls one(Systemcalls::System, 
3090                         AddName(system_lyxdir, "configure"));
3091         p.pop();
3092         bv->owner()->getMiniBuffer()->Set(_("Reloading configuration..."));
3093         lyxrc.read(LibFileSearch(string(), "lyxrc.defaults"));
3094         WriteAlert(_("The system has been reconfigured."), 
3095                    _("You need to restart LyX to make use of any"),
3096                    _("updated document class specifications."));
3097 }
3098
3099
3100 //
3101 // Table of Contents
3102 //
3103
3104 static vector<Buffer::TocItem> toclist;
3105
3106
3107 extern "C" void TocSelectCB(FL_OBJECT * ob, long)
3108 {
3109         if (!current_view->available())
3110                 return;
3111    
3112         TocUpdateCB(0, 0);
3113         unsigned int choice = fl_get_browser(ob);
3114         if (0 < choice && choice - 1 < toclist.size()) {
3115                 current_view->beforeChange();
3116                 current_view->text->SetCursor(toclist[choice-1].par, 0);
3117                 current_view->text->sel_cursor = 
3118                         current_view->text->cursor;
3119                 current_view->update(0);
3120         } else {
3121                 WriteAlert(_("Error"), 
3122                            _("Couldn't find this label"), 
3123                            _("in current document."));
3124         }
3125 }
3126
3127
3128 extern "C" void TocCancelCB(FL_OBJECT *, long)
3129 {
3130         fl_hide_form(fd_form_toc->form_toc);
3131 }
3132
3133
3134 extern "C" void TocUpdateCB(FL_OBJECT *, long)
3135 {
3136         if (!current_view->available()) {
3137                 toclist.clear();
3138                 fl_clear_browser(fd_form_toc->browser_toc);
3139                 fl_add_browser_line(fd_form_toc->browser_toc,
3140                                     _("*** No Document ***"));
3141                 return;
3142         }
3143
3144         vector<vector<Buffer::TocItem> > tmp =
3145                 current_view->buffer()->getTocList();
3146         if (toclist == tmp[0])
3147                 return;
3148         toclist = tmp[0];
3149
3150         static Buffer * buffer = 0;
3151         int topline = 0;
3152         int line = 0;
3153         if (buffer == current_view->buffer()) {
3154                 topline = fl_get_browser_topline(fd_form_toc->browser_toc);
3155                 line = fl_get_browser(fd_form_toc->browser_toc);
3156         } else
3157                 buffer = current_view->buffer();
3158
3159         fl_clear_browser(fd_form_toc->browser_toc);
3160         fl_hide_object(fd_form_toc->browser_toc);
3161
3162         for (vector<Buffer::TocItem>::const_iterator it = toclist.begin();
3163              it != toclist.end(); ++it)
3164                 fl_add_browser_line(fd_form_toc->browser_toc,
3165                                     (string(4*(*it).depth,' ')+
3166                                      (*it).str).c_str());
3167
3168         fl_set_browser_topline(fd_form_toc->browser_toc, topline);
3169         fl_select_browser_line(fd_form_toc->browser_toc, line);
3170         fl_show_object(fd_form_toc->browser_toc);
3171 }
3172
3173
3174 /* callbacks for form form_ref */
3175 extern "C" void RefSelectCB(FL_OBJECT *, long data)
3176 {
3177         if (!current_view->available())
3178                 return;
3179
3180         string s = 
3181                 fl_get_browser_line(fd_form_ref->browser_ref,
3182                                     fl_get_browser(fd_form_ref->browser_ref));
3183         string u = frontStrip(strip(fl_get_input(fd_form_ref->ref_name)));
3184
3185         if (s.empty())
3186                 return;
3187
3188         if (data >= 5) {
3189                 current_view->owner()->getLyXFunc()->Dispatch(LFUN_REFGOTO, s.c_str());
3190                 return;
3191         }
3192
3193         static string const commands[5]
3194                 = { "\\ref", "\\pageref", "\\vref", "\\vpageref",
3195                     "\\prettyref"};
3196         string t = commands[data];
3197
3198         if (current_view->buffer()->isSGML())
3199                 t += "[" + u + "]" + "{" + s + "}";
3200         else
3201                 t += "{" + s + "}";
3202
3203         Inset * new_inset = 
3204                 new InsetRef(t, current_view->buffer());
3205         current_view->insertInset(new_inset);
3206 }
3207
3208
3209 extern "C" void RefUpdateCB(FL_OBJECT *, long)
3210 {
3211         if (!current_view->available()) {
3212                 fl_clear_browser(fd_form_ref->browser_ref);
3213                 return;
3214         }
3215
3216         FL_OBJECT * brow = fd_form_ref->browser_ref;
3217
3218         // Get the current line, in order to restore it later
3219         char const * const btmp = fl_get_browser_line(brow,
3220                                                       fl_get_browser(brow));
3221         string currentstr = btmp ? btmp : "";
3222
3223         fl_clear_browser(brow);
3224         fl_hide_object(brow);
3225
3226         vector<string> refs = current_view->buffer()->getLabelList();
3227         if (fl_get_button(fd_form_ref->sort))
3228                 sort(refs.begin(),refs.end());
3229         for (vector<string>::const_iterator it = refs.begin();
3230              it != refs.end(); ++it)
3231                 fl_add_browser_line(brow, (*it).c_str());
3232
3233         int topline = 1;
3234         int total_lines = fl_get_browser_maxline(brow);
3235         for (int i = 1; i <= total_lines ; ++i) {
3236                 if (fl_get_browser_line(brow, i) == currentstr) {
3237                         topline = i;
3238                         break;
3239                 }
3240         }
3241         fl_set_browser_topline(brow, topline);
3242
3243         if (!fl_get_browser_maxline(brow)) {
3244                 fl_add_browser_line(brow, 
3245                                     _("*** No labels found in document ***"));
3246                 fl_deactivate_object(brow);
3247         } else {
3248                 fl_select_browser_line(brow, topline);
3249                 fl_activate_object(brow);
3250         }
3251         if (current_view->buffer()->isReadonly()) {
3252                 // would be better to de/activate insert buttons
3253                 // but that's more work... besides this works. ARRae
3254                 fl_hide_form(fd_form_ref->form_ref);
3255         }
3256         if (!current_view->buffer()->isSGML()) {
3257                 fl_deactivate_object(fd_form_ref->ref_name);
3258                 fl_set_object_lcol(fd_form_ref->ref_name, FL_INACTIVE);
3259
3260                 fl_activate_object(fd_form_ref->vref);
3261                 fl_set_object_lcol(fd_form_ref->vref, FL_BLACK);
3262                 fl_activate_object(fd_form_ref->vpageref);
3263                 fl_set_object_lcol(fd_form_ref->vpageref, FL_BLACK);
3264                 fl_activate_object(fd_form_ref->prettyref);
3265                 fl_set_object_lcol(fd_form_ref->prettyref, FL_BLACK);
3266         } else {
3267                 fl_activate_object(fd_form_ref->ref_name);
3268                 fl_set_object_lcol(fd_form_ref->ref_name, FL_BLACK);
3269
3270                 fl_deactivate_object(fd_form_ref->vref);
3271                 fl_set_object_lcol(fd_form_ref->vref, FL_INACTIVE);
3272                 fl_deactivate_object(fd_form_ref->vpageref);
3273                 fl_set_object_lcol(fd_form_ref->vpageref, FL_INACTIVE);
3274                 fl_deactivate_object(fd_form_ref->prettyref);
3275                 fl_set_object_lcol(fd_form_ref->prettyref, FL_INACTIVE);
3276         }
3277         fl_show_object(brow);
3278 }
3279
3280
3281 extern "C" void RefHideCB(FL_OBJECT *, long)
3282 {
3283         fl_hide_form(fd_form_ref->form_ref);
3284 }