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