]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBaseDeprecated.C
guii2
[lyx.git] / src / frontends / xforms / FormBaseDeprecated.C
1 /**
2  * \file FormBaseDeprecated.C
3  * Copyright 2000-2001 The LyX Team.
4  * See the file COPYING.
5  *
6  * \author Angus Leeming, a.leeming@ic.ac.uk
7  */
8
9 #include <config.h>
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include "Dialogs.h"
16 #include "FormBaseDeprecated.h"
17 #include "xformsBC.h"
18 #include "xforms_resize.h"
19 #include "GUIRunTime.h"
20 #include "Tooltips.h"
21 #include "frontends/LyXView.h"
22 #include "lyxrc.h"
23 #include "support/LAssert.h"
24
25 using SigC::slot;
26
27 extern "C" {
28
29 // Callback function invoked by xforms when the dialog is closed by the
30 // window manager
31 static int C_WMHideCB(FL_FORM *, void *);
32
33 // Callback function invoked by the xforms pre- and post-handler routines
34 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
35
36 } // extern "C"
37
38
39 FormBaseDeprecated::FormBaseDeprecated(LyXView * lv, Dialogs * d,
40                                        string const & t, bool allowResize)
41         : lv_(lv), d_(d), h_(0), r_(0), title_(t),
42           minw_(0), minh_(0), allow_resize_(allowResize),
43           tooltips_(new Tooltips)
44 {
45         lyx::Assert(lv && d);
46 }
47
48
49 FormBaseDeprecated::~FormBaseDeprecated()
50 {
51         delete tooltips_;
52 }
53
54
55 Tooltips & FormBaseDeprecated::tooltips()
56 {
57         return *tooltips_;
58 }
59
60
61 void FormBaseDeprecated::redraw()
62 {
63         if (form() && form()->visible)
64                 fl_redraw_form(form());
65 }
66
67
68 void FormBaseDeprecated::connect()
69 {
70         fl_set_form_minsize(form(), minw_, minh_);
71         r_ = Dialogs::redrawGUI.connect(slot(this,&FormBaseDeprecated::redraw));
72 }
73
74
75 void FormBaseDeprecated::disconnect()
76 {
77         h_.disconnect();
78         r_.disconnect();
79 }
80
81
82 void FormBaseDeprecated::show()
83 {
84         if (!form()) {
85                 build();
86
87                 double const scale = scale_to_fit_tabs(form());
88                 if (scale > 1.001)
89                         scale_form(form(), scale);
90
91                 bc().refresh();
92
93                 // work around dumb xforms sizing bug
94                 minw_ = form()->w;
95                 minh_ = form()->h;
96
97                 fl_set_form_atclose(form(), C_WMHideCB, 0);
98         }
99
100         fl_freeze_form(form());
101         update();
102         fl_unfreeze_form(form());
103
104         if (form()->visible) {
105                 fl_raise_form(form());
106                 /* This XMapWindow() will hopefully ensure that
107                  * iconified dialogs are de-iconified. Mad props
108                  * out to those crazy Xlib guys for forgetting a
109                  * XDeiconifyWindow(). At least WindowMaker, when
110                  * being notified of the redirected MapRequest will
111                  * specifically de-iconify. From source, fvwm2 seems
112                  * to do the same.
113                  */
114                 XMapWindow(fl_get_display(), form()->window);
115         } else {
116                 connect();
117
118                 // calls to fl_set_form_minsize/maxsize apply only to the next
119                 // fl_show_form(), so this comes first.
120                 fl_set_form_minsize(form(), minw_, minh_);
121                 if (!allow_resize_)
122                         fl_set_form_maxsize(form(), minw_, minh_);
123
124                 fl_show_form(form(),
125                              FL_PLACE_MOUSE | FL_FREE_SIZE,
126                              (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
127                              title_.c_str());
128         }
129
130         tooltips().set();
131 }
132
133
134 void FormBaseDeprecated::hide()
135 {
136         // xforms sometimes tries to process a hint-type MotionNotify, and
137         // use XQueryPointer, without verifying if the window still exists.
138         // So we try to clear out motion events in the queue before the
139         // DestroyNotify
140         XSync(fl_get_display(), false);
141         GUIRunTime::processEvents();
142
143         if (form() && form()->visible) {
144                 // some dialogs might do things to the form first
145                 // such as the nested tabfolder problem in Preferences
146                 disconnect();
147                 fl_hide_form(form());
148         }
149 }
150
151
152 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
153 {
154         lyx::Assert(ob);
155         fl_set_object_prehandler(ob, C_PrehandlerCB);
156 }
157
158
159 void FormBaseDeprecated::WMHideCB()
160 {
161         hide();
162         bc().hide();
163 }
164
165
166 void FormBaseDeprecated::ApplyCB()
167 {
168         apply();
169         bc().apply();
170 }
171
172
173 void FormBaseDeprecated::OKCB()
174 {
175         ok();
176         bc().ok();
177 }
178
179
180 void FormBaseDeprecated::CancelCB()
181 {
182         cancel();
183         bc().cancel();
184 }
185
186
187 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
188 {
189         // It is possible to set the choice to 0 when using the
190         // keyboard shortcuts. This work-around deals with the problem.
191         if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
192                 fl_set_choice(ob, 1);
193         }
194
195         bc().valid(input(ob, data));
196 }
197
198
199 void FormBaseDeprecated::RestoreCB()
200 {
201         bc().restore();
202         restore();
203 }
204
205
206 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
207                        bool allowResize)
208         : FormBaseDeprecated(lv, d, t, allowResize)
209 {}
210
211
212 void FormBaseBI::connect()
213 {
214         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
215         FormBaseDeprecated::connect();
216 }
217
218
219 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
220                        bool allowResize)
221         : FormBaseDeprecated(lv, d, t, allowResize),
222           u_(0)
223 {}
224
225
226 void FormBaseBD::connect()
227 {
228         u_ = d_->updateBufferDependent.
229                 connect(slot(this, &FormBaseBD::updateSlot));
230         h_ = d_->hideBufferDependent.
231                 connect(slot(this, &FormBaseBD::hide));
232         FormBaseDeprecated::connect();
233 }
234
235
236 void FormBaseBD::disconnect()
237 {
238         u_.disconnect();
239         FormBaseDeprecated::disconnect();
240 }
241
242
243 namespace {
244
245 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
246 {
247         lyx::Assert(ob && ob->form && ob->form->u_vdata);
248         FormBaseDeprecated * ptr =
249                 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
250         return ptr;
251 }
252
253 } // namespace anon
254
255
256 extern "C" {
257
258 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
259 {
260         GetForm(ob)->ApplyCB();
261 }
262
263
264 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
265 {
266         GetForm(ob)->OKCB();
267 }
268
269
270 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
271 {
272         GetForm(ob)->CancelCB();
273 }
274
275
276 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
277 {
278         GetForm(ob)->InputCB(ob, d);
279 }
280
281
282 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
283 {
284         GetForm(ob)->RestoreCB();
285 }
286
287 static int C_WMHideCB(FL_FORM * form, void *)
288 {
289         // Close the dialog cleanly, even if the WM is used to do so.
290         lyx::Assert(form && form->u_vdata);
291         FormBaseDeprecated * ptr =
292                 static_cast<FormBaseDeprecated *>(form->u_vdata);
293         ptr->WMHideCB();
294         return FL_CANCEL;
295 }
296
297 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
298                           FL_Coord, FL_Coord, int key, void *)
299 {
300         // Note that the return value is important in the pre-emptive handler.
301         // Don't return anything other than 0.
302         lyx::Assert(ob);
303
304         // Don't Assert this one, as it can happen quite naturally when things
305         // are being deleted in the d-tor.
306         //Assert(ob->form);
307         if (!ob->form) return 0;
308
309         FormBaseDeprecated * ptr =
310                 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
311
312         if (ptr)
313                 ptr->PrehandlerCB(ob, event, key);
314
315         return 0;
316 }
317
318 } // extern "C"