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