3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming, a.leeming@ic.ac.uk
12 #pragma implementation
18 #include "GUIRunTime.h"
20 #include "support/LAssert.h"
24 // Callback function invoked by xforms when the dialog is closed by the
26 static int C_WMHideCB(FL_FORM * form, void *);
28 // Callback function invoked by the xforms pre- and post-handler routines
29 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
34 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
35 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
36 title_(t), tooltips_(new Tooltips)
46 Tooltips & FormBase::tooltips()
52 void FormBase::redraw()
54 if (form() && form()->visible)
55 fl_redraw_form(form());
65 // use minw_ to flag whether the dialog has ever been shown
66 // (Needed now that build() is/should be called from the controller)
70 // work around dumb xforms sizing bug
74 fl_set_form_atclose(form(), C_WMHideCB, 0);
77 fl_freeze_form(form());
78 update(); // make sure its up-to-date
79 fl_unfreeze_form(form());
81 if (form()->visible) {
82 fl_raise_form(form());
83 /* This XMapWindow() will hopefully ensure that
84 * iconified dialogs are de-iconified. Mad props
85 * out to those crazy Xlib guys for forgetting a
86 * XDeiconifyWindow(). At least WindowMaker, when
87 * being notified of the redirected MapRequest will
88 * specifically de-iconify. From source, fvwm2 seems
91 XMapWindow(fl_get_display(), form()->window);
93 // calls to fl_set_form_minsize/maxsize apply only to the next
94 // fl_show_form(), so this comes first.
95 fl_set_form_minsize(form(), minw_, minh_);
97 fl_set_form_maxsize(form(), minw_, minh_);
100 FL_PLACE_MOUSE | FL_FREE_SIZE,
101 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
107 void FormBase::hide()
109 // xforms sometimes tries to process a hint-type MotionNotify, and
110 // use XQueryPointer, without verifying if the window still exists.
111 // So we try to clear out motion events in the queue before the
113 XSync(fl_get_display(), false);
114 GUIRunTime::processEvents();
116 if (form() && form()->visible)
117 fl_hide_form(form());
121 void FormBase::setPrehandler(FL_OBJECT * ob)
124 fl_set_object_prehandler(ob, C_PrehandlerCB);
128 void FormBase::InputCB(FL_OBJECT * ob, long data)
130 // It is possible to set the choice to 0 when using the
131 // keyboard shortcuts. This work-around deals with the problem.
132 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
133 fl_set_choice(ob, 1);
136 bc().input(input(ob, data));
140 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
142 return ButtonPolicy::SMI_VALID;
148 FormBase * GetForm(FL_OBJECT * ob)
150 lyx::Assert(ob && ob->form && ob->form->u_vdata);
151 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
160 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
162 GetForm(ob)->ApplyButton();
166 void C_FormBaseOKCB(FL_OBJECT * ob, long)
168 GetForm(ob)->OKButton();
172 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
174 FormBase * form = GetForm(ob);
175 form->CancelButton();
179 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
181 GetForm(ob)->RestoreButton();
185 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
187 GetForm(ob)->InputCB(ob, d);
191 static int C_WMHideCB(FL_FORM * form, void *)
193 // Close the dialog cleanly, even if the WM is used to do so.
194 lyx::Assert(form && form->u_vdata);
195 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
200 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
201 FL_Coord, FL_Coord, int key, void *)
203 // Note that the return value is important in the pre-emptive handler.
204 // Don't return anything other than 0.
207 // Don't Assert this one, as it can happen quite naturally when things
208 // are being deleted in the d-tor.
210 if (!ob->form) return 0;
212 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
215 ptr->PrehandlerCB(ob, event, key);