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 "support/LAssert.h"
28 int TooltipHandler(FL_OBJECT *ob, int event);
30 void TooltipTimerCB(FL_OBJECT * timer, long data);
36 static int C_FormBaseTooltipHandler(FL_OBJECT * ob, int event,
37 FL_Coord, FL_Coord, int, void *)
39 return TooltipHandler(ob, event);
42 static void C_FormBaseTooltipTimerCB(FL_OBJECT * ob, long data)
44 TooltipTimerCB(ob, data);
49 #endif // FL_REVISION < 89
54 // Callback function invoked by xforms when the dialog is closed by the
56 static int C_FormBaseWMHideCB(FL_FORM * form, void *);
58 // Use this to diaplay feedback messages or to trigger an input event on paste
59 // with the middle mouse button
60 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
61 FL_Coord, FL_Coord, int key, void *);
66 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
67 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
68 title_(t), warning_posted_(false)
77 void FormBase::redraw()
79 if (form() && form()->visible)
80 fl_redraw_form(form());
90 // use minw_ to flag whether the dialog has ever been shown
91 // (Needed now that build() is/should be called from the controller)
95 // work around dumb xforms sizing bug
99 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
102 fl_freeze_form(form());
103 update(); // make sure its up-to-date
104 fl_unfreeze_form(form());
106 if (form()->visible) {
107 fl_raise_form(form());
108 /* This XMapWindow() will hopefully ensure that
109 * iconified dialogs are de-iconified. Mad props
110 * out to those crazy Xlib guys for forgetting a
111 * XDeiconifyWindow(). At least WindowMaker, when
112 * being notified of the redirected MapRequest will
113 * specifically de-iconify. From source, fvwm2 seems
116 XMapWindow(fl_get_display(), form()->window);
118 // calls to fl_set_form_minsize/maxsize apply only to the next
119 // fl_show_form(), so this comes first.
120 fl_set_form_minsize(form(), minw_, minh_);
122 fl_set_form_maxsize(form(), minw_, minh_);
125 FL_PLACE_MOUSE | FL_FREE_SIZE,
126 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
132 void FormBase::hide()
134 if (form() && form()->visible)
135 fl_hide_form(form());
139 void FormBase::InputCB(FL_OBJECT * ob, long data)
141 // It is possible to set the choice to 0 when using the
142 // keyboard shortcuts. This work-around deals with the problem.
143 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
144 fl_set_choice(ob, 1);
147 bc().input(input(ob, data));
151 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
153 return ButtonPolicy::SMI_VALID;
157 // preemptive handler for feedback messages
158 void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
164 warning_posted_ = false;
169 if (!warning_posted_)
179 void FormBase::setTooltipHandler(FL_OBJECT * ob)
184 if (!tooltip_timer_) {
185 fl_addto_form(form());
186 tooltip_timer_ = fl_add_timer(FL_HIDDEN_TIMER, 0, 0, 0, 0, "");
190 fl_set_object_posthandler(ob, C_FormBaseTooltipHandler);
191 ob->u_cdata = reinterpret_cast<char *>(tooltip_timer_);
194 string const help(getTooltip(ob));
196 fl_set_object_helper(ob, help.c_str());
197 #endif // FL_REVISION < 89
201 void FormBase::setPrehandler(FL_OBJECT * ob)
204 fl_set_object_prehandler(ob, C_FormBasePrehandler);
208 void FormBase::setWarningPosted(bool warning)
210 warning_posted_ = warning;
216 string const FormBase::getTooltipCB(FL_OBJECT * ob)
218 return getTooltip(ob);
221 #endif // FL_REVISION < 89
226 FormBase * GetForm(FL_OBJECT * ob)
228 lyx::Assert(ob && ob->form && ob->form->u_vdata);
229 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
238 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
240 GetForm(ob)->ApplyButton();
244 void C_FormBaseOKCB(FL_OBJECT * ob, long)
246 GetForm(ob)->OKButton();
250 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
252 FormBase * form = GetForm(ob);
253 form->CancelButton();
257 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
259 GetForm(ob)->RestoreButton();
263 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
265 GetForm(ob)->InputCB(ob, d);
269 static int C_FormBaseWMHideCB(FL_FORM * form, void *)
271 // Close the dialog cleanly, even if the WM is used to do so.
272 lyx::Assert(form && form->u_vdata);
273 FormBase * pre = static_cast<FormBase *>(form->u_vdata);
279 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
280 FL_Coord, FL_Coord, int key, void *)
282 // Note that the return value is important in the pre-emptive handler.
283 // Don't return anything other than 0.
286 // Don't Assert this one, as it can happen quite naturally when things
287 // are being deleted in the d-tor.
289 if (!ob->form) return 0;
291 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
294 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
295 // Trigger an input event when pasting in an xforms input object
296 // using the middle mouse button.
299 } else if (event == FL_ENTER || event == FL_LEAVE){
300 // Post feedback as the mouse enters the object,
301 // remove it as the mouse leaves.
302 pre->FeedbackCB(ob, event);
315 void TooltipTimerCB(FL_OBJECT * timer, long data)
317 FL_OBJECT * ob = reinterpret_cast<FL_OBJECT*>(data);
318 lyx::Assert(ob && ob->form);
320 string const help = GetForm(timer)->getTooltipCB(ob);
324 fl_show_oneliner(help.c_str(),
326 ob->form->y + ob->y + ob->h);
330 // post_handler for bubble-help (Matthias)
331 int TooltipHandler(FL_OBJECT *ob, int event)
334 FL_OBJECT * timer = reinterpret_cast<FL_OBJECT *>(ob->u_cdata);
337 // We do not test for empty help here, since this can never happen
338 if (event == FL_ENTER){
339 fl_set_object_callback(timer,
340 C_FormBaseTooltipTimerCB,
341 reinterpret_cast<long>(ob));
342 fl_set_timer(timer, 1);
344 else if (event != FL_MOTION){
345 fl_set_timer(timer, 0);
353 #endif // FL_REVISION < 89