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