]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormBaseDeprecated.C
whitespace changes only (believe it or not!)
[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         tooltips().set();
126 }
127
128
129 void FormBaseDeprecated::hide()
130 {
131         // xforms sometimes tries to process a hint-type MotionNotify, and
132         // use XQueryPointer, without verifying if the window still exists.
133         // So we try to clear out motion events in the queue before the
134         // DestroyNotify
135         XSync(fl_get_display(), false);
136         GUIRunTime::processEvents();
137
138         if (form() && form()->visible) {
139                 // some dialogs might do things to the form first
140                 // such as the nested tabfolder problem in Preferences
141                 disconnect();
142                 fl_hide_form(form());
143         }
144 }
145
146
147 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
148 {
149         lyx::Assert(ob);
150         fl_set_object_prehandler(ob, C_PrehandlerCB);
151 }
152
153
154 void FormBaseDeprecated::WMHideCB()
155 {
156         hide();
157         bc().hide();
158 }
159
160
161 void FormBaseDeprecated::ApplyCB()
162 {
163         apply();
164         bc().apply();
165 }
166
167
168 void FormBaseDeprecated::OKCB()
169 {
170         ok();
171         bc().ok();
172 }
173
174
175 void FormBaseDeprecated::CancelCB()
176 {
177         cancel();
178         bc().cancel();
179 }
180
181
182 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
183 {
184         // It is possible to set the choice to 0 when using the
185         // keyboard shortcuts. This work-around deals with the problem.
186         if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
187                 fl_set_choice(ob, 1);
188         }
189
190         bc().valid(input(ob, data));
191 }
192
193
194 void FormBaseDeprecated::RestoreCB()
195 {
196         bc().restore();
197         restore();
198 }
199
200
201 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
202                        bool allowResize)
203         : FormBaseDeprecated(lv, d, t, allowResize)
204 {}
205
206
207 void FormBaseBI::connect()
208 {
209         h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
210         FormBaseDeprecated::connect();
211 }
212
213
214 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
215                        bool allowResize)
216         : FormBaseDeprecated(lv, d, t, allowResize),
217           u_(0)
218 {}
219
220
221 void FormBaseBD::connect()
222 {
223         u_ = d_->updateBufferDependent.
224                 connect(slot(this, &FormBaseBD::updateSlot));
225         h_ = d_->hideBufferDependent.
226                 connect(slot(this, &FormBaseBD::hide));
227         FormBaseDeprecated::connect();
228 }
229
230
231 void FormBaseBD::disconnect()
232 {
233         u_.disconnect();
234         FormBaseDeprecated::disconnect();
235 }
236
237
238 namespace {
239
240 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
241 {
242         lyx::Assert(ob && ob->form && ob->form->u_vdata);
243         FormBaseDeprecated * ptr =
244                 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
245         return ptr;
246 }
247
248 } // namespace anon
249
250
251 extern "C" {
252
253 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
254 {
255         GetForm(ob)->ApplyCB();
256 }
257
258
259 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
260 {
261         GetForm(ob)->OKCB();
262 }
263
264
265 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
266 {
267         GetForm(ob)->CancelCB();
268 }
269
270
271 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
272 {
273         GetForm(ob)->InputCB(ob, d);
274 }
275
276
277 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
278 {
279         GetForm(ob)->RestoreCB();
280 }
281
282 static int C_WMHideCB(FL_FORM * form, void *)
283 {
284         // Close the dialog cleanly, even if the WM is used to do so.
285         lyx::Assert(form && form->u_vdata);
286         FormBaseDeprecated * ptr =
287                 static_cast<FormBaseDeprecated *>(form->u_vdata);
288         ptr->WMHideCB();
289         return FL_CANCEL;
290 }
291
292 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
293                           FL_Coord, FL_Coord, int key, void *)
294 {
295         // Note that the return value is important in the pre-emptive handler.
296         // Don't return anything other than 0.
297         lyx::Assert(ob);
298
299         // Don't Assert this one, as it can happen quite naturally when things
300         // are being deleted in the d-tor.
301         //Assert(ob->form);
302         if (!ob->form) return 0;
303
304         FormBaseDeprecated * ptr =
305                 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
306
307         if (ptr)
308                 ptr->PrehandlerCB(ob, event, key);
309
310         return 0;
311 }
312
313 } // extern "C"