3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "ControlButtons.h"
21 #include "xforms_resize.h"
23 #include "support/LAssert.h"
24 #include FORMS_H_LOCATION
28 // Callback function invoked by xforms when the dialog is closed by the
30 static int C_WMHideCB(FL_FORM * 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 FormBase::FormBase(string const & t, bool allowResize)
39 : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
40 title_(t), tooltips_(new Tooltips())
50 Tooltips & FormBase::tooltips()
56 void FormBase::redraw()
58 if (form() && form()->visible)
59 fl_redraw_form(form());
63 xformsBC & FormBase::bc()
65 return static_cast<xformsBC &>(getController().bc());
66 // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
76 // use minw_ to flag whether the dialog has ever been shown
77 // (Needed now that build() is/should be called from the controller)
79 double const scale = scale_to_fit_tabs(form());
81 scale_form(form(), scale);
85 // work around dumb xforms sizing bug
89 fl_set_form_atclose(form(), C_WMHideCB, 0);
92 fl_freeze_form(form());
93 update(); // make sure its up-to-date
94 fl_unfreeze_form(form());
96 if (form()->visible) {
97 fl_raise_form(form());
98 /* This XMapWindow() will hopefully ensure that
99 * iconified dialogs are de-iconified. Mad props
100 * out to those crazy Xlib guys for forgetting a
101 * XDeiconifyWindow(). At least WindowMaker, when
102 * being notified of the redirected MapRequest will
103 * specifically de-iconify. From source, fvwm2 seems
106 XMapWindow(fl_get_display(), form()->window);
108 // calls to fl_set_form_minsize/maxsize apply only to the next
109 // fl_show_form(), so this comes first.
110 fl_set_form_minsize(form(), minw_, minh_);
112 fl_set_form_maxsize(form(), minw_, minh_);
114 int const iconify = getController().IconifyWithMain() ?
118 FL_PLACE_MOUSE | FL_FREE_SIZE,
127 void FormBase::hide()
129 // xforms sometimes tries to process a hint-type MotionNotify, and
130 // use XQueryPointer, without verifying if the window still exists.
131 // So we try to clear out motion events in the queue before the
133 XSync(fl_get_display(), false);
135 if (form() && form()->visible)
136 fl_hide_form(form());
140 void FormBase::setPrehandler(FL_OBJECT * ob)
143 fl_set_object_prehandler(ob, C_PrehandlerCB);
147 void FormBase::InputCB(FL_OBJECT * ob, long data)
149 // It is possible to set the choice to 0 when using the
150 // keyboard shortcuts. This work-around deals with the problem.
151 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
152 fl_set_choice(ob, 1);
155 bc().input(input(ob, data));
159 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
161 return ButtonPolicy::SMI_VALID;
167 FormBase * GetForm(FL_OBJECT * ob)
169 lyx::Assert(ob && ob->form && ob->form->u_vdata);
170 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
179 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
181 GetForm(ob)->getController().ApplyButton();
185 void C_FormBaseOKCB(FL_OBJECT * ob, long)
187 GetForm(ob)->getController().OKButton();
191 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
193 FormBase * form = GetForm(ob);
194 form->getController().CancelButton();
198 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
200 GetForm(ob)->getController().RestoreButton();
204 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
206 GetForm(ob)->InputCB(ob, d);
210 static int C_WMHideCB(FL_FORM * form, void *)
212 // Close the dialog cleanly, even if the WM is used to do so.
213 lyx::Assert(form && form->u_vdata);
214 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
215 ptr->getController().CancelButton();
219 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
220 FL_Coord, FL_Coord, int key, void *)
222 // Note that the return value is important in the pre-emptive handler.
223 // Don't return anything other than 0.
226 // Don't Assert this one, as it can happen quite naturally when things
227 // are being deleted in the d-tor.
229 if (!ob->form) return 0;
231 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
234 ptr->PrehandlerCB(ob, event, key);