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),
129 void FormBaseDeprecated::hide()
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
135 XSync(fl_get_display(), false);
136 GUIRunTime::processEvents();
138 if (form() && form()->visible) {
139 // some dialogs might do things to the form first
140 // such as the nested tabfolder problem in Preferences
142 fl_hide_form(form());
147 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
150 fl_set_object_prehandler(ob, C_PrehandlerCB);
154 void FormBaseDeprecated::WMHideCB()
161 void FormBaseDeprecated::ApplyCB()
168 void FormBaseDeprecated::OKCB()
175 void FormBaseDeprecated::CancelCB()
182 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
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);
190 bc().valid(input(ob, data));
194 void FormBaseDeprecated::RestoreCB()
201 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
203 : FormBaseDeprecated(lv, d, t, allowResize)
207 void FormBaseBI::connect()
209 h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide));
210 FormBaseDeprecated::connect();
214 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
216 : FormBaseDeprecated(lv, d, t, allowResize),
221 void FormBaseBD::connect()
223 u_ = d_->updateBufferDependent.
224 connect(slot(this, &FormBaseBD::updateSlot));
225 h_ = d_->hideBufferDependent.
226 connect(slot(this, &FormBaseBD::hide));
227 FormBaseDeprecated::connect();
231 void FormBaseBD::disconnect()
234 FormBaseDeprecated::disconnect();
240 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
242 lyx::Assert(ob && ob->form && ob->form->u_vdata);
243 FormBaseDeprecated * ptr =
244 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
253 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
255 GetForm(ob)->ApplyCB();
259 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
265 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
267 GetForm(ob)->CancelCB();
271 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
273 GetForm(ob)->InputCB(ob, d);
277 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
279 GetForm(ob)->RestoreCB();
282 static int C_WMHideCB(FL_FORM * form, void *)
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);
292 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
293 FL_Coord, FL_Coord, int key, void *)
295 // Note that the return value is important in the pre-emptive handler.
296 // Don't return anything other than 0.
299 // Don't Assert this one, as it can happen quite naturally when things
300 // are being deleted in the d-tor.
302 if (!ob->form) return 0;
304 FormBaseDeprecated * ptr =
305 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
308 ptr->PrehandlerCB(ob, event, key);