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