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