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 "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(*d))
52 FormBaseDeprecated::~FormBaseDeprecated()
58 Tooltips & FormBaseDeprecated::tooltips()
64 void FormBaseDeprecated::redraw()
66 if (form() && form()->visible)
67 fl_redraw_form(form());
71 void FormBaseDeprecated::connect()
73 fl_set_form_minsize(form(), minw_, minh_);
74 r_ = d_->redrawGUI.connect(boost::bind(&FormBaseDeprecated::redraw, this));
78 void FormBaseDeprecated::disconnect()
85 void FormBaseDeprecated::show()
90 double const scale = scale_to_fit_tabs(form());
92 scale_form(form(), scale);
96 // work around dumb xforms sizing bug
100 fl_set_form_atclose(form(), C_WMHideCB, 0);
103 fl_freeze_form(form());
105 fl_unfreeze_form(form());
107 if (form()->visible) {
108 fl_raise_form(form());
109 /* This XMapWindow() will hopefully ensure that
110 * iconified dialogs are de-iconified. Mad props
111 * out to those crazy Xlib guys for forgetting a
112 * XDeiconifyWindow(). At least WindowMaker, when
113 * being notified of the redirected MapRequest will
114 * specifically de-iconify. From source, fvwm2 seems
117 XMapWindow(fl_get_display(), form()->window);
121 // calls to fl_set_form_minsize/maxsize apply only to the next
122 // fl_show_form(), so this comes first.
123 fl_set_form_minsize(form(), minw_, minh_);
125 fl_set_form_maxsize(form(), minw_, minh_);
128 FL_PLACE_MOUSE | FL_FREE_SIZE,
129 (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0),
137 void FormBaseDeprecated::hide()
139 // xforms sometimes tries to process a hint-type MotionNotify, and
140 // use XQueryPointer, without verifying if the window still exists.
141 // So we try to clear out motion events in the queue before the
143 XSync(fl_get_display(), false);
145 if (form() && form()->visible) {
146 // some dialogs might do things to the form first
147 // such as the nested tabfolder problem in Preferences
149 fl_hide_form(form());
154 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
157 fl_set_object_prehandler(ob, C_PrehandlerCB);
161 void FormBaseDeprecated::WMHideCB()
168 void FormBaseDeprecated::ApplyCB()
175 void FormBaseDeprecated::OKCB()
182 void FormBaseDeprecated::CancelCB()
189 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
191 // It is possible to set the choice to 0 when using the
192 // keyboard shortcuts. This work-around deals with the problem.
193 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
194 fl_set_choice(ob, 1);
197 bc().valid(input(ob, data));
201 void FormBaseDeprecated::RestoreCB()
208 FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
210 : FormBaseDeprecated(lv, d, t, allowResize)
214 void FormBaseBI::connect()
216 h_ = d_->hideAll.connect(boost::bind(&FormBaseBI::hide, this));
217 FormBaseDeprecated::connect();
221 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
223 : FormBaseDeprecated(lv, d, t, allowResize)
227 void FormBaseBD::connect()
229 u_ = d_->updateBufferDependent.
230 connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
231 h_ = d_->hideBufferDependent.
232 connect(boost::bind(&FormBaseBD::hide, this));
233 FormBaseDeprecated::connect();
237 void FormBaseBD::disconnect()
240 FormBaseDeprecated::disconnect();
246 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
248 lyx::Assert(ob && ob->form && ob->form->u_vdata);
249 FormBaseDeprecated * ptr =
250 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
259 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
261 GetForm(ob)->ApplyCB();
265 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
271 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
273 GetForm(ob)->CancelCB();
277 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
279 GetForm(ob)->InputCB(ob, d);
283 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
285 GetForm(ob)->RestoreCB();
288 static int C_WMHideCB(FL_FORM * form, void *)
290 // Close the dialog cleanly, even if the WM is used to do so.
291 lyx::Assert(form && form->u_vdata);
292 FormBaseDeprecated * ptr =
293 static_cast<FormBaseDeprecated *>(form->u_vdata);
298 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
299 FL_Coord, FL_Coord, int key, void *)
301 // Note that the return value is important in the pre-emptive handler.
302 // Don't return anything other than 0.
305 // Don't Assert this one, as it can happen quite naturally when things
306 // are being deleted in the d-tor.
308 if (!ob->form) return 0;
310 FormBaseDeprecated * ptr =
311 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
314 ptr->PrehandlerCB(ob, event, key);