2 * \file FormBaseDeprecated.C
3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming <leeming@lyx.org>
12 #pragma implementation
16 #include "FormBaseDeprecated.h"
18 #include "xforms_resize.h"
20 #include FORMS_H_LOCATION
24 #include "frontends/LyXView.h"
26 #include "support/LAssert.h"
28 #include <boost/bind.hpp>
32 // Callback function invoked by xforms when the dialog is closed by the
34 static int C_WMHideCB(FL_FORM *, void *);
36 // Callback function invoked by the xforms pre- and post-handler routines
37 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
42 FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d,
43 string const & t, bool allowResize)
44 : lv_(lv), d_(d), title_(t),
45 minw_(0), minh_(0), allow_resize_(allowResize),
46 tooltips_(new Tooltips())
50 FormBaseDeprecated::~FormBaseDeprecated()
56 Tooltips & FormBaseDeprecated::tooltips()
62 void FormBaseDeprecated::redraw()
64 if (form() && form()->visible)
65 fl_redraw_form(form());
69 void FormBaseDeprecated::connect()
71 fl_set_form_minsize(form(), minw_, minh_);
72 r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this));
76 void FormBaseDeprecated::disconnect()
83 void FormBaseDeprecated::show()
88 double const scale = scale_to_fit_tabs(form());
90 scale_form(form(), scale);
94 // work around dumb xforms sizing bug
98 fl_set_form_atclose(form(), C_WMHideCB, 0);
101 fl_freeze_form(form());
103 fl_unfreeze_form(form());
105 if (form()->visible) {
106 fl_raise_form(form());
107 /* This XMapWindow() will hopefully ensure that
108 * iconified dialogs are de-iconified. Mad props
109 * out to those crazy Xlib guys for forgetting a
110 * XDeiconifyWindow(). At least WindowMaker, when
111 * being notified of the redirected MapRequest will
112 * specifically de-iconify. From source, fvwm2 seems
115 XMapWindow(fl_get_display(), form()->window);
119 // calls to fl_set_form_minsize/maxsize apply only to the next
120 // fl_show_form(), so this comes first.
121 fl_set_form_minsize(form(), minw_, minh_);
123 fl_set_form_maxsize(form(), minw_, minh_);
126 FL_PLACE_MOUSE | FL_FREE_SIZE,
127 (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
135 void FormBaseDeprecated::hide()
137 // xforms sometimes tries to process a hint-type MotionNotify, and
138 // use XQueryPointer, without verifying if the window still exists.
139 // So we try to clear out motion events in the queue before the
141 XSync(fl_get_display(), false);
143 if (form() && form()->visible) {
144 // some dialogs might do things to the form first
145 // such as the nested tabfolder problem in Preferences
147 fl_hide_form(form());
152 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
155 fl_set_object_prehandler(ob, C_PrehandlerCB);
159 void FormBaseDeprecated::WMHideCB()
166 void FormBaseDeprecated::ApplyCB()
173 void FormBaseDeprecated::OKCB()
180 void FormBaseDeprecated::CancelCB()
187 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
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);
195 bc().valid(input(ob, data));
199 void FormBaseDeprecated::RestoreCB()
206 FormBaseBI::FormBaseBI(LyXView & lv, Dialogs & d, string const & t,
208 : FormBaseDeprecated(lv, d, t, allowResize)
212 void FormBaseBI::connect()
214 h_ = d_.hideAll.connect(boost::bind(&FormBaseBI::hide, this));
215 FormBaseDeprecated::connect();
219 FormBaseBD::FormBaseBD(LyXView & lv, Dialogs & d, string const & t,
221 : FormBaseDeprecated(lv, d, t, allowResize)
225 void FormBaseBD::connect()
227 u_ = d_.updateBufferDependent.
228 connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
229 h_ = d_.hideBufferDependent.
230 connect(boost::bind(&FormBaseBD::hide, this));
231 FormBaseDeprecated::connect();
235 void FormBaseBD::disconnect()
238 FormBaseDeprecated::disconnect();
244 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
246 lyx::Assert(ob && ob->form && ob->form->u_vdata);
247 FormBaseDeprecated * ptr =
248 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
257 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
259 GetForm(ob)->ApplyCB();
263 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
269 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
271 GetForm(ob)->CancelCB();
275 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
277 GetForm(ob)->InputCB(ob, d);
281 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
283 GetForm(ob)->RestoreCB();
286 static int C_WMHideCB(FL_FORM * form, void *)
288 // Close the dialog cleanly, even if the WM is used to do so.
289 lyx::Assert(form && form->u_vdata);
290 FormBaseDeprecated * ptr =
291 static_cast<FormBaseDeprecated *>(form->u_vdata);
296 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
297 FL_Coord, FL_Coord, int key, void *)
299 // Note that the return value is important in the pre-emptive handler.
300 // Don't return anything other than 0.
303 // Don't Assert this one, as it can happen quite naturally when things
304 // are being deleted in the d-tor.
306 if (!ob->form) return 0;
308 FormBaseDeprecated * ptr =
309 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
312 ptr->PrehandlerCB(ob, event, key);