]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/XFormsView.C
8fec911401d15e5bc52e4a3fc8fd696463bf990c
[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 #include FORMS_H_LOCATION
19 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
20 #include "frontends/xforms/lyxlookup.h"
21 #endif
22 #include "frontends/MiniBuffer.h"
23 #include "frontends/xforms/XMiniBuffer.h"
24 #include "debug.h"
25 #include "intl.h"
26 #include "lyxrc.h"
27 #include "support/filetools.h"        // OnlyFilename()
28 #include "frontends/Toolbar.h"
29 #include "frontends/Menubar.h"
30 #include "frontends/Timeout.h"
31 #include "frontends/Dialogs.h"
32 #include "MenuBackend.h"
33 #include "ToolbarDefaults.h"
34 #include "lyxfunc.h"
35 #include "BufferView.h"
36
37 #include <boost/bind.hpp>
38
39 using std::abs;
40 using std::endl;
41
42 //extern void AutoSave(BufferView *);
43 extern void QuitLyX();
44
45 // This is very temporary
46 BufferView * current_view;
47
48 extern "C" {
49
50 static
51 int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
52 {
53         return XFormsView::atCloseMainFormCB(form, p);
54 }
55
56 }
57
58
59 XFormsView::XFormsView(int width, int height)
60         : LyXView()
61 {
62         create_form_form_main(*getDialogs(), width, height);
63         fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
64
65         // Connect the minibuffer signals
66         minibuffer_->inputReady.connect(boost::bind(&LyXFunc::miniDispatch, getLyXFunc(), _1));
67         minibuffer_->timeout.connect(boost::bind(&LyXFunc::initMiniBuffer, getLyXFunc()));
68
69         // Make sure the buttons are disabled if needed.
70         updateToolbar();
71         getDialogs()->redrawGUI.connect(boost::bind(&XFormsView::redraw, this));
72 }
73
74
75 XFormsView::~XFormsView() {}
76
77
78 /// Redraw the main form.
79 void XFormsView::redraw()
80 {
81         lyxerr[Debug::INFO] << "XFormsView::redraw()" << endl;
82         fl_redraw_form(getForm());
83         // This is dangerous, but we know it is safe
84         XMiniBuffer * m = static_cast<XMiniBuffer *>(getMiniBuffer());
85         m->redraw();
86 }
87
88
89 FL_FORM * XFormsView::getForm() const
90 {
91         return form_.get();
92 }
93
94
95 // Callback for close main form from window manager
96 int XFormsView::atCloseMainFormCB(FL_FORM *, void *)
97 {
98         QuitLyX();
99         return FL_IGNORE;
100 }
101
102
103 void XFormsView::show(int x, int y, string const & title)
104 {
105         FL_FORM * form = getForm();
106
107         fl_set_form_minsize(form, form->w, form->h);
108
109         int placement = FL_PLACE_CENTER | FL_FREE_SIZE;
110
111         // Did we get a valid geometry position ?
112         if (x >= 0 && y >= 0) {
113                 fl_set_form_position(form, x, y);
114                 placement = FL_PLACE_POSITION;
115         }
116
117         fl_show_form(form, placement, FL_FULLBORDER, title.c_str());
118
119         getLyXFunc()->initMiniBuffer();
120 #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5))
121         InitLyXLookup(fl_get_display(), form_->window);
122 #endif
123 }
124
125
126 void XFormsView::create_form_form_main(Dialogs & dia, int width, int height)
127         /* to make this work as it should, .lyxrc should have been
128          * read first; OR maybe this one should be made dynamic.
129          * Hmmmm. Lgb.
130          * We will probably not have lyxrc before the main form is
131          * initialized, because error messages from lyxrc parsing
132          * are presented (and rightly so) in GUI popups. Asger.
133          */
134 {
135         // the main form
136         form_.reset(fl_bgn_form(FL_NO_BOX, width, height));
137         getForm()->u_vdata = this;
138         FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, "");
139         fl_set_object_color(obj, FL_MCOL, FL_MCOL);
140
141         // Parameters for the appearance of the main form
142         int const air = 2;
143         int const bw = abs(fl_get_border_width());
144
145         menubar_.reset(new Menubar(this, menubackend));
146
147         toolbar_.reset(new Toolbar(this, dia,
148                                    air, 30 + air + bw, toolbardefaults));
149         toolbar_->set(true);
150
151         int const ywork = 60 + 2 * air + bw;
152         int const workheight = height - ywork - (25 + 2 * air);
153
154         bufferview_.reset(new BufferView(this, air, ywork,
155                 width - 3 * air, workheight));
156         ::current_view = bufferview_.get();
157
158         minibuffer_.reset(new XMiniBuffer(this, air, height - (25 + air),
159                 width - (2 * air), 25));
160
161         // FIXME: why do this in xforms/ ?
162         autosave_timeout_->timeout.connect(boost::bind(&XFormsView::autoSave, this));
163
164         //  assign an icon to main form
165         string iconname = LibFileSearch("images", "lyx", "xpm");
166         if (!iconname.empty()) {
167                 unsigned int w, h;
168                 Pixmap lyx_p, lyx_mask;
169                 lyx_p = fl_read_pixmapfile(fl_root,
170                                            iconname.c_str(),
171                                            &w,
172                                            &h,
173                                            &lyx_mask,
174                                            0,
175                                            0,
176                                            0); // this leaks
177                 fl_set_form_icon(getForm(), lyx_p, lyx_mask);
178         }
179
180         // set min size
181         fl_set_form_minsize(getForm(), 50, 50);
182
183         fl_end_form();
184
185         // This is dangerous, but we know it is safe in this situation
186         static_cast<XMiniBuffer *>(minibuffer_.get())->dd_init();
187 }
188
189
190 void XFormsView::setWindowTitle(string const & title, string const & icon_title)
191 {
192         fl_set_form_title(getForm(), title.c_str());
193         fl_winicontitle(form_->window, icon_title.c_str());
194 }
195
196
197 // How should this actually work? Should it prohibit input in all BufferViews,
198 // or just in the current one? If "just the current one", then it should be
199 // placed in BufferView. If "all BufferViews" then LyXGUI (I think) should
200 // run "prohibitInput" on all LyXViews which will run prohibitInput on all
201 // BufferViews. Or is it perhaps just the (input in) BufferViews in the
202 // current LyxView that should be prohibited (Lgb) (This applies to
203 // "allowInput" as well.)
204 void XFormsView::prohibitInput() const
205 {
206         view()->hideCursor();
207
208         static Cursor cursor;
209         static bool cursor_undefined = true;
210
211         if (cursor_undefined) {
212                 cursor = XCreateFontCursor(fl_get_display(), XC_watch);
213                 XFlush(fl_get_display());
214                 cursor_undefined = false;
215         }
216
217         /* set the cursor to the watch for all forms and the canvas */
218         XDefineCursor(fl_get_display(), getForm()->window, cursor);
219
220         XFlush(fl_get_display());
221         fl_deactivate_all_forms();
222 }
223
224
225 void XFormsView::allowInput() const
226 {
227         /* reset the cursor from the watch for all forms and the canvas */
228
229         XUndefineCursor(fl_get_display(), getForm()->window);
230
231         XFlush(fl_get_display());
232         fl_activate_all_forms();
233 }