3 * See the file COPYING.
5 * \author Angus Leeming
7 * Full author contact details are available in file CREDITS
13 #pragma implementation
18 #include "ControlButtons.h"
20 #include "xforms_resize.h"
22 #include "support/LAssert.h"
23 #include FORMS_H_LOCATION
27 // Callback function invoked by xforms when the dialog is closed by the
29 static int C_WMHideCB(FL_FORM * form, void *);
31 // Callback function invoked by the xforms pre- and post-handler routines
32 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
37 FormBase::FormBase(string const & t, bool allowResize)
38 : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
39 title_(t), tooltips_(new Tooltips())
49 Tooltips & FormBase::tooltips()
55 void FormBase::redraw()
57 if (form() && form()->visible)
58 fl_redraw_form(form());
62 xformsBC & FormBase::bc()
64 return static_cast<xformsBC &>(getController().bc());
65 // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
75 // use minw_ to flag whether the dialog has ever been shown
76 // (Needed now that build() is/should be called from the controller)
78 double const scale = scale_to_fit_tabs(form());
80 scale_form(form(), scale);
84 // work around dumb xforms sizing bug
88 fl_set_form_atclose(form(), C_WMHideCB, 0);
91 fl_freeze_form(form());
92 update(); // make sure its up-to-date
93 fl_unfreeze_form(form());
95 if (form()->visible) {
96 fl_raise_form(form());
97 /* This XMapWindow() will hopefully ensure that
98 * iconified dialogs are de-iconified. Mad props
99 * out to those crazy Xlib guys for forgetting a
100 * XDeiconifyWindow(). At least WindowMaker, when
101 * being notified of the redirected MapRequest will
102 * specifically de-iconify. From source, fvwm2 seems
105 XMapWindow(fl_get_display(), form()->window);
107 // calls to fl_set_form_minsize/maxsize apply only to the next
108 // fl_show_form(), so this comes first.
109 fl_set_form_minsize(form(), minw_, minh_);
111 fl_set_form_maxsize(form(), minw_, minh_);
113 int const iconify = getController().IconifyWithMain() ?
117 FL_PLACE_MOUSE | FL_FREE_SIZE,
126 void FormBase::hide()
128 // xforms sometimes tries to process a hint-type MotionNotify, and
129 // use XQueryPointer, without verifying if the window still exists.
130 // So we try to clear out motion events in the queue before the
132 XSync(fl_get_display(), false);
134 if (form() && form()->visible)
135 fl_hide_form(form());
139 void FormBase::setPrehandler(FL_OBJECT * ob)
142 fl_set_object_prehandler(ob, C_PrehandlerCB);
146 void FormBase::InputCB(FL_OBJECT * ob, long data)
148 // It is possible to set the choice to 0 when using the
149 // keyboard shortcuts. This work-around deals with the problem.
150 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
151 fl_set_choice(ob, 1);
154 bc().input(input(ob, data));
158 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
160 return ButtonPolicy::SMI_VALID;
166 FormBase * GetForm(FL_OBJECT * ob)
168 lyx::Assert(ob && ob->form && ob->form->u_vdata);
169 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
178 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
180 GetForm(ob)->getController().ApplyButton();
184 void C_FormBaseOKCB(FL_OBJECT * ob, long)
186 GetForm(ob)->getController().OKButton();
190 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
192 FormBase * form = GetForm(ob);
193 form->getController().CancelButton();
197 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
199 GetForm(ob)->getController().RestoreButton();
203 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
205 GetForm(ob)->InputCB(ob, d);
209 static int C_WMHideCB(FL_FORM * form, void *)
211 // Close the dialog cleanly, even if the WM is used to do so.
212 lyx::Assert(form && form->u_vdata);
213 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
214 ptr->getController().CancelButton();
218 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
219 FL_Coord, FL_Coord, int key, void *)
221 // Note that the return value is important in the pre-emptive handler.
222 // Don't return anything other than 0.
225 // Don't Assert this one, as it can happen quite naturally when things
226 // are being deleted in the d-tor.
228 if (!ob->form) return 0;
230 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
233 ptr->PrehandlerCB(ob, event, key);