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),
125 // Set the initial state of the cursor
126 if (form()->visible) {
127 int const cursor = Tooltips::enabled() ?
128 XC_question_arrow : FL_DEFAULT_CURSOR;
129 fl_set_cursor(form()->window, cursor);
134 void FormBaseDeprecated::hide()
136 // xforms sometimes tries to process a hint-type MotionNotify, and
137 // use XQueryPointer, without verifying if the window still exists.
138 // So we try to clear out motion events in the queue before the
140 XSync(fl_get_display(), false);
141 GUIRunTime::processEvents();
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(slot(this, &FormBaseBI::hide));
215 FormBaseDeprecated::connect();
219 FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
221 : FormBaseDeprecated(lv, d, t, allowResize),
226 void FormBaseBD::connect()
228 u_ = d_->updateBufferDependent.
229 connect(slot(this, &FormBaseBD::updateSlot));
230 h_ = d_->hideBufferDependent.
231 connect(slot(this, &FormBaseBD::hide));
232 FormBaseDeprecated::connect();
236 void FormBaseBD::disconnect()
239 FormBaseDeprecated::disconnect();
245 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
247 lyx::Assert(ob && ob->form && ob->form->u_vdata);
248 FormBaseDeprecated * ptr =
249 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
258 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
260 GetForm(ob)->ApplyCB();
264 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
270 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
272 GetForm(ob)->CancelCB();
276 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
278 GetForm(ob)->InputCB(ob, d);
282 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
284 GetForm(ob)->RestoreCB();
287 static int C_WMHideCB(FL_FORM * form, void *)
289 // Close the dialog cleanly, even if the WM is used to do so.
290 lyx::Assert(form && form->u_vdata);
291 FormBaseDeprecated * ptr =
292 static_cast<FormBaseDeprecated *>(form->u_vdata);
297 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
298 FL_Coord, FL_Coord, int key, void *)
300 // Note that the return value is important in the pre-emptive handler.
301 // Don't return anything other than 0.
304 // Don't Assert this one, as it can happen quite naturally when things
305 // are being deleted in the d-tor.
307 if (!ob->form) return 0;
309 FormBaseDeprecated * ptr =
310 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
313 ptr->PrehandlerCB(ob, event, key);