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, string const & t, bool allowResize)
36 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
37 title_(t), tooltips_(new Tooltips)
47 Tooltips & FormBase::tooltips()
53 void FormBase::redraw()
55 if (form() && form()->visible)
56 fl_redraw_form(form());
66 // use minw_ to flag whether the dialog has ever been shown
67 // (Needed now that build() is/should be called from the controller)
69 double const scale = scale_to_fit_tabs(form());
71 scale_form(form(), scale);
75 // work around dumb xforms sizing bug
79 fl_set_form_atclose(form(), C_WMHideCB, 0);
82 fl_freeze_form(form());
83 update(); // make sure its up-to-date
84 fl_unfreeze_form(form());
86 if (form()->visible) {
87 fl_raise_form(form());
88 /* This XMapWindow() will hopefully ensure that
89 * iconified dialogs are de-iconified. Mad props
90 * out to those crazy Xlib guys for forgetting a
91 * XDeiconifyWindow(). At least WindowMaker, when
92 * being notified of the redirected MapRequest will
93 * specifically de-iconify. From source, fvwm2 seems
96 XMapWindow(fl_get_display(), form()->window);
98 // calls to fl_set_form_minsize/maxsize apply only to the next
99 // fl_show_form(), so this comes first.
100 fl_set_form_minsize(form(), minw_, minh_);
102 fl_set_form_maxsize(form(), minw_, minh_);
105 FL_PLACE_MOUSE | FL_FREE_SIZE,
106 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
114 void FormBase::hide()
116 // xforms sometimes tries to process a hint-type MotionNotify, and
117 // use XQueryPointer, without verifying if the window still exists.
118 // So we try to clear out motion events in the queue before the
120 XSync(fl_get_display(), false);
122 if (form() && form()->visible)
123 fl_hide_form(form());
127 void FormBase::setPrehandler(FL_OBJECT * ob)
130 fl_set_object_prehandler(ob, C_PrehandlerCB);
134 void FormBase::InputCB(FL_OBJECT * ob, long data)
136 // It is possible to set the choice to 0 when using the
137 // keyboard shortcuts. This work-around deals with the problem.
138 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
139 fl_set_choice(ob, 1);
142 bc().input(input(ob, data));
146 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
148 return ButtonPolicy::SMI_VALID;
154 FormBase * GetForm(FL_OBJECT * ob)
156 lyx::Assert(ob && ob->form && ob->form->u_vdata);
157 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
166 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
168 GetForm(ob)->ApplyButton();
172 void C_FormBaseOKCB(FL_OBJECT * ob, long)
174 GetForm(ob)->OKButton();
178 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
180 FormBase * form = GetForm(ob);
181 form->CancelButton();
185 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
187 GetForm(ob)->RestoreButton();
191 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
193 GetForm(ob)->InputCB(ob, d);
197 static int C_WMHideCB(FL_FORM * form, void *)
199 // Close the dialog cleanly, even if the WM is used to do so.
200 lyx::Assert(form && form->u_vdata);
201 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
206 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
207 FL_Coord, FL_Coord, int key, void *)
209 // Note that the return value is important in the pre-emptive handler.
210 // Don't return anything other than 0.
213 // Don't Assert this one, as it can happen quite naturally when things
214 // are being deleted in the d-tor.
216 if (!ob->form) return 0;
218 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
221 ptr->PrehandlerCB(ob, event, key);