3 * Copyright 2000-2001 The LyX Team.
4 * See the file COPYING.
6 * \author Angus Leeming <leeming@lyx.org>
12 #pragma implementation
17 #include "ControlButtons.h"
19 #include "xforms_resize.h"
21 #include "support/LAssert.h"
22 #include FORMS_H_LOCATION
26 // Callback function invoked by xforms when the dialog is closed by the
28 static int C_WMHideCB(FL_FORM * form, void *);
30 // Callback function invoked by the xforms pre- and post-handler routines
31 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
36 FormBase::FormBase(string const & t, bool allowResize)
37 : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
38 title_(t), tooltips_(new Tooltips())
48 Tooltips & FormBase::tooltips()
54 void FormBase::redraw()
56 if (form() && form()->visible)
57 fl_redraw_form(form());
61 xformsBC & FormBase::bc()
63 return static_cast<xformsBC &>(getController().bc());
64 // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
74 // use minw_ to flag whether the dialog has ever been shown
75 // (Needed now that build() is/should be called from the controller)
77 double const scale = scale_to_fit_tabs(form());
79 scale_form(form(), scale);
83 // work around dumb xforms sizing bug
87 fl_set_form_atclose(form(), C_WMHideCB, 0);
90 fl_freeze_form(form());
91 update(); // make sure its up-to-date
92 fl_unfreeze_form(form());
94 if (form()->visible) {
95 fl_raise_form(form());
96 /* This XMapWindow() will hopefully ensure that
97 * iconified dialogs are de-iconified. Mad props
98 * out to those crazy Xlib guys for forgetting a
99 * XDeiconifyWindow(). At least WindowMaker, when
100 * being notified of the redirected MapRequest will
101 * specifically de-iconify. From source, fvwm2 seems
104 XMapWindow(fl_get_display(), form()->window);
106 // calls to fl_set_form_minsize/maxsize apply only to the next
107 // fl_show_form(), so this comes first.
108 fl_set_form_minsize(form(), minw_, minh_);
110 fl_set_form_maxsize(form(), minw_, minh_);
112 int const iconify = getController().IconifyWithMain() ?
116 FL_PLACE_MOUSE | FL_FREE_SIZE,
125 void FormBase::hide()
127 // xforms sometimes tries to process a hint-type MotionNotify, and
128 // use XQueryPointer, without verifying if the window still exists.
129 // So we try to clear out motion events in the queue before the
131 XSync(fl_get_display(), false);
133 if (form() && form()->visible)
134 fl_hide_form(form());
138 void FormBase::setPrehandler(FL_OBJECT * ob)
141 fl_set_object_prehandler(ob, C_PrehandlerCB);
145 void FormBase::InputCB(FL_OBJECT * ob, long data)
147 // It is possible to set the choice to 0 when using the
148 // keyboard shortcuts. This work-around deals with the problem.
149 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
150 fl_set_choice(ob, 1);
153 bc().input(input(ob, data));
157 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
159 return ButtonPolicy::SMI_VALID;
165 FormBase * GetForm(FL_OBJECT * ob)
167 lyx::Assert(ob && ob->form && ob->form->u_vdata);
168 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
177 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
179 GetForm(ob)->getController().ApplyButton();
183 void C_FormBaseOKCB(FL_OBJECT * ob, long)
185 GetForm(ob)->getController().OKButton();
189 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
191 FormBase * form = GetForm(ob);
192 form->getController().CancelButton();
196 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
198 GetForm(ob)->getController().RestoreButton();
202 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
204 GetForm(ob)->InputCB(ob, d);
208 static int C_WMHideCB(FL_FORM * form, void *)
210 // Close the dialog cleanly, even if the WM is used to do so.
211 lyx::Assert(form && form->u_vdata);
212 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
213 ptr->getController().CancelButton();
217 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
218 FL_Coord, FL_Coord, int key, void *)
220 // Note that the return value is important in the pre-emptive handler.
221 // Don't return anything other than 0.
224 // Don't Assert this one, as it can happen quite naturally when things
225 // are being deleted in the d-tor.
227 if (!ob->form) return 0;
229 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
232 ptr->PrehandlerCB(ob, event, key);