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 "xforms_resize.h"
20 #include "support/LAssert.h"
21 #include FORMS_H_LOCATION
25 // Callback function invoked by xforms when the dialog is closed by the
27 static int C_WMHideCB(FL_FORM * form, void *);
29 // Callback function invoked by the xforms pre- and post-handler routines
30 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
35 FormBase::FormBase(ControlButtons & c, Dialogs & d,
36 string const & t, bool allowResize)
37 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
38 title_(t), tooltips_(new Tooltips(d))
48 Tooltips & FormBase::tooltips()
54 void FormBase::redraw()
56 if (form() && form()->visible)
57 fl_redraw_form(form());
67 // use minw_ to flag whether the dialog has ever been shown
68 // (Needed now that build() is/should be called from the controller)
70 double const scale = scale_to_fit_tabs(form());
72 scale_form(form(), scale);
76 // work around dumb xforms sizing bug
80 fl_set_form_atclose(form(), C_WMHideCB, 0);
83 fl_freeze_form(form());
84 update(); // make sure its up-to-date
85 fl_unfreeze_form(form());
87 if (form()->visible) {
88 fl_raise_form(form());
89 /* This XMapWindow() will hopefully ensure that
90 * iconified dialogs are de-iconified. Mad props
91 * out to those crazy Xlib guys for forgetting a
92 * XDeiconifyWindow(). At least WindowMaker, when
93 * being notified of the redirected MapRequest will
94 * specifically de-iconify. From source, fvwm2 seems
97 XMapWindow(fl_get_display(), form()->window);
99 // calls to fl_set_form_minsize/maxsize apply only to the next
100 // fl_show_form(), so this comes first.
101 fl_set_form_minsize(form(), minw_, minh_);
103 fl_set_form_maxsize(form(), minw_, minh_);
106 FL_PLACE_MOUSE | FL_FREE_SIZE,
107 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
115 void FormBase::hide()
117 // xforms sometimes tries to process a hint-type MotionNotify, and
118 // use XQueryPointer, without verifying if the window still exists.
119 // So we try to clear out motion events in the queue before the
121 XSync(fl_get_display(), false);
123 if (form() && form()->visible)
124 fl_hide_form(form());
128 void FormBase::setPrehandler(FL_OBJECT * ob)
131 fl_set_object_prehandler(ob, C_PrehandlerCB);
135 void FormBase::InputCB(FL_OBJECT * ob, long data)
137 // It is possible to set the choice to 0 when using the
138 // keyboard shortcuts. This work-around deals with the problem.
139 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
140 fl_set_choice(ob, 1);
143 bc().input(input(ob, data));
147 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
149 return ButtonPolicy::SMI_VALID;
155 FormBase * GetForm(FL_OBJECT * ob)
157 lyx::Assert(ob && ob->form && ob->form->u_vdata);
158 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
167 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
169 GetForm(ob)->ApplyButton();
173 void C_FormBaseOKCB(FL_OBJECT * ob, long)
175 GetForm(ob)->OKButton();
179 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
181 FormBase * form = GetForm(ob);
182 form->CancelButton();
186 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
188 GetForm(ob)->RestoreButton();
192 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
194 GetForm(ob)->InputCB(ob, d);
198 static int C_WMHideCB(FL_FORM * form, void *)
200 // Close the dialog cleanly, even if the WM is used to do so.
201 lyx::Assert(form && form->u_vdata);
202 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
207 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
208 FL_Coord, FL_Coord, int key, void *)
210 // Note that the return value is important in the pre-emptive handler.
211 // Don't return anything other than 0.
214 // Don't Assert this one, as it can happen quite naturally when things
215 // are being deleted in the d-tor.
217 if (!ob->form) return 0;
219 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
222 ptr->PrehandlerCB(ob, event, key);