]> git.lyx.org Git - lyx.git/blob - src/XFormsView.C
some mods I had in my local tree, mostly small stuff, perhaps minus the the Makefile...
[lyx.git] / src / XFormsView.C
1
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *        
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2001 The LyX Team.
9  *
10  * ====================================================== */
11
12 #include <config.h>
13
14 #ifdef __GNUG__
15 #pragma implementation
16 #endif
17
18 #include "XFormsView.h"
19 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
20 #include "lyxlookup.h"
21 #endif
22 #include "minibuffer.h"
23 #include "debug.h"
24 #include "intl.h"
25 #include "lyxrc.h"
26 #include "support/filetools.h"        // OnlyFilename()
27 #include "frontends/Toolbar.h"
28 #include "frontends/Menubar.h"
29 #include "MenuBackend.h"
30 #include "ToolbarDefaults.h"
31 #include "lyxfunc.h"
32 #include "BufferView.h"
33
34 using std::endl;
35
36 //extern void AutoSave(BufferView *);
37 extern void QuitLyX();
38
39 // This is very temporary
40 BufferView * current_view;
41
42 extern "C" {
43         
44 static
45 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
46 {
47         return XFormsView::atCloseMainFormCB(form, p);
48 }
49         
50 }
51
52
53 XFormsView::XFormsView(int width, int height)
54         : LyXView()
55 {
56         create_form_form_main(width, height);
57         fl_set_form_atclose(form_, C_XFormsView_atCloseMainFormCB, 0);
58
59         // Connect the minibuffer signals
60         minibuffer->stringReady.connect(SigC::slot(getLyXFunc(),
61                                                    &LyXFunc::miniDispatch));
62         minibuffer->timeout.connect(SigC::slot(getLyXFunc(),
63                                                &LyXFunc::initMiniBuffer));
64         
65         // Make sure the buttons are disabled if needed.
66         updateToolbar();
67 }
68
69
70 XFormsView::~XFormsView() {}
71
72
73 /// Redraw the main form.
74 void XFormsView::redraw() {
75         lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
76         fl_redraw_form(form_);
77         getMiniBuffer()->redraw();
78 }
79
80
81 FL_FORM * XFormsView::getForm() const
82 {
83         return form_;
84 }
85
86
87 // Callback for close main form from window manager
88 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
89 {
90         QuitLyX();
91         return FL_IGNORE;
92 }
93
94
95 void XFormsView::setPosition(int x, int y)
96 {
97         fl_set_form_position(form_, x, y);
98 }
99
100
101 void XFormsView::show(int place, int border, string const & title)
102 {
103         fl_show_form(form_, place, border, title.c_str());
104         getLyXFunc()->initMiniBuffer();
105 #if FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)
106         InitLyXLookup(fl_get_display(), form_->window);
107 #endif
108 }
109
110
111 void XFormsView::create_form_form_main(int width, int height)
112         /* to make this work as it should, .lyxrc should have been
113          * read first; OR maybe this one should be made dynamic.
114          * Hmmmm. Lgb. 
115          * We will probably not have lyxrc before the main form is
116          * initialized, because error messages from lyxrc parsing 
117          * are presented (and rightly so) in GUI popups. Asger. 
118          */
119 {
120         // the main form
121         form_ = fl_bgn_form(FL_NO_BOX, width, height);
122         form_->u_vdata = this;
123         FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
124         fl_set_object_color(obj, FL_MCOL, FL_MCOL);
125
126         // Parameters for the appearance of the main form
127         int const air = 2;
128         int const bw = abs(fl_get_border_width());
129         
130         //
131         // THE MENUBAR
132         //
133         menubar = new Menubar(this, menubackend);
134
135         //
136         // TOOLBAR
137         //
138
139         toolbar = new Toolbar(this, air, 30 + air + bw, toolbardefaults);
140
141         // Setup the toolbar
142         toolbar->set(true);
143
144         //
145         // WORKAREA
146         //
147
148         int const ywork = 60 + 2 * air + bw;
149         int const workheight = height - ywork - (25 + 2 * air);
150
151         ::current_view = bufferview = new BufferView(this, air, ywork,
152                                                      width - 3 * air,
153                                                      workheight);
154
155         //
156         // MINIBUFFER
157         //
158
159         minibuffer = new MiniBuffer(this, air, height - (25 + air), 
160                                     width - (2 * air), 25);
161
162         //
163         // TIMERS
164         //
165
166         autosave_timeout.timeout.connect(SigC::slot(this, &XFormsView::AutoSave));
167         
168         //
169         // Misc
170         //
171
172         //  assign an icon to main form
173         string iconname = LibFileSearch("images", "lyx", "xpm");
174         if (!iconname.empty()) {
175                 unsigned int w, h;
176                 Pixmap lyx_p, lyx_mask;
177                 lyx_p = fl_read_pixmapfile(fl_root,
178                                            iconname.c_str(),
179                                            &w,
180                                            &h,
181                                            &lyx_mask,
182                                            0,
183                                            0,
184                                            0); // this leaks
185                 fl_set_form_icon(form_, lyx_p, lyx_mask);
186         }
187
188         // set min size
189         fl_set_form_minsize(form_, 50, 50);
190         
191         fl_end_form();
192 }
193
194
195 void XFormsView::init()
196 {
197         // Set the textclass choice
198         invalidateLayoutChoice();
199         updateLayoutChoice();
200         updateMenubar();
201         
202         // Start autosave timer
203         if (lyxrc.autosave) {
204                 autosave_timeout.setTimeout(lyxrc.autosave * 1000);
205                 autosave_timeout.start();
206         }
207
208         intl->InitKeyMapper(lyxrc.use_kbmap);
209 }
210
211
212 void XFormsView::setWindowTitle(string const & title)
213 {
214         fl_set_form_title(form_, title.c_str());
215 }
216
217
218 // How should this actually work? Should it prohibit input in all BufferViews,
219 // or just in the current one? If "just the current one", then it should be
220 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
221 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
222 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
223 // current LyxView that should be prohibited (Lgb) (This applies to
224 // "allowInput" as well.)
225 void XFormsView::prohibitInput() const
226 {
227         view()->hideCursor();
228
229         static Cursor cursor;
230         static bool cursor_undefined = true;
231    
232         if (cursor_undefined){
233                 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
234                 XFlush(fl_get_display());
235                 cursor_undefined = false;
236         }
237    
238         /* set the cursor to the watch for all forms and the canvas */ 
239         XDefineCursor(fl_get_display(), getForm()->window, cursor);
240
241         XFlush(fl_get_display());
242         fl_deactivate_all_forms();
243 }
244
245
246 void XFormsView::allowInput() const
247 {
248         /* reset the cursor from the watch for all forms and the canvas */
249    
250         XUndefineCursor(fl_get_display(), getForm()->window);
251
252         XFlush(fl_get_display());
253         fl_activate_all_forms();
254 }