1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * ======================================================
10 * \author Angus Leeming <a.leeming@ic.ac.uk>
16 #pragma implementation
22 #include "GUIRunTime.h"
24 #include "support/LAssert.h"
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(ControlButtons & c, string const & t, bool allowResize)
39 : ViewBC<xformsBC>(c), 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());
69 // use minw_ to flag whether the dialog has ever been shown
70 // (Needed now that build() is/should be called from the controller)
74 // work around dumb xforms sizing bug
78 fl_set_form_atclose(form(), C_WMHideCB, 0);
81 fl_freeze_form(form());
82 update(); // make sure its up-to-date
83 fl_unfreeze_form(form());
85 if (form()->visible) {
86 fl_raise_form(form());
87 /* This XMapWindow() will hopefully ensure that
88 * iconified dialogs are de-iconified. Mad props
89 * out to those crazy Xlib guys for forgetting a
90 * XDeiconifyWindow(). At least WindowMaker, when
91 * being notified of the redirected MapRequest will
92 * specifically de-iconify. From source, fvwm2 seems
95 XMapWindow(fl_get_display(), form()->window);
97 // calls to fl_set_form_minsize/maxsize apply only to the next
98 // fl_show_form(), so this comes first.
99 fl_set_form_minsize(form(), minw_, minh_);
101 fl_set_form_maxsize(form(), minw_, minh_);
104 FL_PLACE_MOUSE | FL_FREE_SIZE,
105 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
111 void FormBase::hide()
113 // xforms sometimes tries to process a hint-type MotionNotify, and
114 // use XQueryPointer, without verifying if the window still exists.
115 // So we try to clear out motion events in the queue before the
117 XSync(fl_get_display(), false);
118 GUIRunTime::processEvents();
120 if (form() && form()->visible)
121 fl_hide_form(form());
125 void FormBase::setPrehandler(FL_OBJECT * ob)
128 fl_set_object_prehandler(ob, C_PrehandlerCB);
132 void FormBase::InputCB(FL_OBJECT * ob, long data)
134 // It is possible to set the choice to 0 when using the
135 // keyboard shortcuts. This work-around deals with the problem.
136 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
137 fl_set_choice(ob, 1);
140 bc().input(input(ob, data));
144 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
146 return ButtonPolicy::SMI_VALID;
152 FormBase * GetForm(FL_OBJECT * ob)
154 lyx::Assert(ob && ob->form && ob->form->u_vdata);
155 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
164 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
166 GetForm(ob)->ApplyButton();
170 void C_FormBaseOKCB(FL_OBJECT * ob, long)
172 GetForm(ob)->OKButton();
176 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
178 FormBase * form = GetForm(ob);
179 form->CancelButton();
183 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
185 GetForm(ob)->RestoreButton();
189 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
191 GetForm(ob)->InputCB(ob, d);
195 static int C_WMHideCB(FL_FORM * form, void *)
197 // Close the dialog cleanly, even if the WM is used to do so.
198 lyx::Assert(form && form->u_vdata);
199 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
204 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
205 FL_Coord, FL_Coord, int key, void *)
207 // Note that the return value is important in the pre-emptive handler.
208 // Don't return anything other than 0.
211 // Don't Assert this one, as it can happen quite naturally when things
212 // are being deleted in the d-tor.
214 if (!ob->form) return 0;
216 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
219 ptr->PrehandlerCB(ob, event, key);