2 * \file FormBaseDeprecated.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@ic.ac.uk
12 #pragma implementation
16 #include "FormBaseDeprecated.h"
18 #include "GUIRunTime.h"
22 #include "support/LAssert.h"
28 // Callback function invoked by xforms when the dialog is closed by the
30 static int C_WMHideCB(FL_FORM *, void *);
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 *);
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)
48 FormBaseDeprecated::~FormBaseDeprecated()
54 Tooltips & FormBaseDeprecated::tooltips()
60 void FormBaseDeprecated::redraw()
62 if (form() && form()->visible)
63 fl_redraw_form(form());
67 void FormBaseDeprecated::connect()
69 fl_set_form_minsize(form(), minw_, minh_);
70 r_ = Dialogs::redrawGUI.connect(slot(this,&FormBaseDeprecated::redraw));
74 void FormBaseDeprecated::disconnect()
81 void FormBaseDeprecated::show()
88 // work around dumb xforms sizing bug
92 fl_set_form_atclose(form(), C_WMHideCB, 0);
95 fl_freeze_form(form());
96 update(); // make sure its up-to-date
97 fl_unfreeze_form(form());
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
109 XMapWindow(fl_get_display(), form()->window);
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_);
117 fl_set_form_maxsize(form(), minw_, minh_);
120 FL_PLACE_MOUSE | FL_FREE_SIZE,
121 (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
127 void FormBaseDeprecated::hide()
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
133 XSync(fl_get_display(), false);
134 GUIRunTime::processEvents();
136 if (form() && form()->visible) {
137 // some dialogs might do things to the form first
138 // such as the nested tabfolder problem in Preferences
140 fl_hide_form(form());
145 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
148 fl_set_object_prehandler(ob, C_PrehandlerCB);
152 void FormBaseDeprecated::WMHideCB()
159 void FormBaseDeprecated::ApplyCB()
166 void FormBaseDeprecated::OKCB()
173 void FormBaseDeprecated::CancelCB()
180 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
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);
188 bc().valid(input(ob, data));
192 void FormBaseDeprecated::RestoreCB()
199 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
201 : FormBaseDeprecated(lv, d, t, allowResize)
205 void FormBaseBI::connect()
207 h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
208 FormBaseDeprecated::connect();
212 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
214 : FormBaseDeprecated(lv, d, t, allowResize),
219 void FormBaseBD::connect()
221 u_ = d_->updateBufferDependent.
222 connect(slot(this, &FormBaseBD::updateSlot));
223 h_ = d_->hideBufferDependent.
224 connect(slot(this, &FormBaseBD::hide));
225 FormBaseDeprecated::connect();
229 void FormBaseBD::disconnect()
232 FormBaseDeprecated::disconnect();
238 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
240 lyx::Assert(ob && ob->form && ob->form->u_vdata);
241 FormBaseDeprecated * ptr =
242 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
251 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
253 GetForm(ob)->ApplyCB();
257 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
263 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
265 GetForm(ob)->CancelCB();
269 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
271 GetForm(ob)->InputCB(ob, d);
275 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
277 GetForm(ob)->RestoreCB();
280 static int C_WMHideCB(FL_FORM * form, void *)
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);
290 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
291 FL_Coord, FL_Coord, int key, void *)
293 // Note that the return value is important in the pre-emptive handler.
294 // Don't return anything other than 0.
297 // Don't Assert this one, as it can happen quite naturally when things
298 // are being deleted in the d-tor.
300 if (!ob->form) return 0;
302 FormBaseDeprecated * ptr =
303 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
306 ptr->PrehandlerCB(ob, event, key);