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"
24 #include "xforms_helpers.h" // formatted
28 // Callback function invoked by xforms when the dialog is closed by the
30 static int C_FormBaseWMHideCB(FL_FORM * form, void *);
32 // Use this to diaplay feedback messages or to trigger an input event on paste
33 // with the middle mouse button
34 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
35 FL_Coord, FL_Coord, int key, void *);
40 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
41 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
42 title_(t), warning_posted_(false), tooltip_level_(NO_TOOLTIP)
45 tooltip_ = new Tooltips;
46 tooltip_->getTooltip.connect(SigC::slot(this, &FormBase::getTooltip));
55 void FormBase::redraw()
57 if (form() && form()->visible)
58 fl_redraw_form(form());
68 // use minw_ to flag whether the dialog has ever been shown
69 // (Needed now that build() is/should be called from the controller)
73 // work around dumb xforms sizing bug
77 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
80 fl_freeze_form(form());
81 update(); // make sure its up-to-date
82 fl_unfreeze_form(form());
84 if (form()->visible) {
85 fl_raise_form(form());
86 /* This XMapWindow() will hopefully ensure that
87 * iconified dialogs are de-iconified. Mad props
88 * out to those crazy Xlib guys for forgetting a
89 * XDeiconifyWindow(). At least WindowMaker, when
90 * being notified of the redirected MapRequest will
91 * specifically de-iconify. From source, fvwm2 seems
94 XMapWindow(fl_get_display(), form()->window);
96 // calls to fl_set_form_minsize/maxsize apply only to the next
97 // fl_show_form(), so this comes first.
98 fl_set_form_minsize(form(), minw_, minh_);
100 fl_set_form_maxsize(form(), minw_, minh_);
103 FL_PLACE_MOUSE | FL_FREE_SIZE,
104 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
110 void FormBase::hide()
112 if (form() && form()->visible)
113 fl_hide_form(form());
117 void FormBase::InputCB(FL_OBJECT * ob, long data)
119 // It is possible to set the choice to 0 when using the
120 // keyboard shortcuts. This work-around deals with the problem.
121 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
122 fl_set_choice(ob, 1);
125 bc().input(input(ob, data));
129 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
131 return ButtonPolicy::SMI_VALID;
135 // preemptive handler for feedback messages
136 void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
142 warning_posted_ = false;
147 if (!warning_posted_)
157 void FormBase::setTooltipHandler(FL_OBJECT * ob)
159 tooltip_->activateTooltip(ob);
163 string FormBase::getTooltip(FL_OBJECT const * ob)
167 switch (tooltip_level_) {
168 case VERBOSE_TOOLTIP:
170 string str = getVerboseTooltip(ob);
172 return formatted(_(str), 400);
173 // else, fall through
176 case MINIMAL_TOOLTIP:
177 return getMinimalTooltip(ob);
187 /// Fill the tooltips chooser with the standard descriptions
188 void FormBase::fillTooltipChoice(FL_OBJECT * ob)
190 lyx::Assert(ob && ob->objclass == FL_CHOICE);
193 fl_addto_choice(ob, _(" None | Normal | Verbose "));
195 switch(tooltip_level_){
197 fl_set_choice(ob, 1);
199 case MINIMAL_TOOLTIP:
200 fl_set_choice(ob, 2);
202 case VERBOSE_TOOLTIP:
203 fl_set_choice(ob, 3);
209 void FormBase::setTooltipLevel(FL_OBJECT * ob)
211 lyx::Assert(ob && ob->objclass == FL_CHOICE &&
212 fl_get_choice_maxitems(ob) == 3);
214 switch(fl_get_choice(ob)){
216 tooltip_level_ = NO_TOOLTIP;
219 tooltip_level_ = MINIMAL_TOOLTIP;
222 tooltip_level_ = VERBOSE_TOOLTIP;
228 void FormBase::setPrehandler(FL_OBJECT * ob)
231 fl_set_object_prehandler(ob, C_FormBasePrehandler);
235 void FormBase::setWarningPosted(bool warning)
237 warning_posted_ = warning;
243 FormBase * GetForm(FL_OBJECT * ob)
245 lyx::Assert(ob && ob->form && ob->form->u_vdata);
246 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
255 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
257 GetForm(ob)->ApplyButton();
261 void C_FormBaseOKCB(FL_OBJECT * ob, long)
263 GetForm(ob)->OKButton();
267 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
269 FormBase * form = GetForm(ob);
270 form->CancelButton();
274 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
276 GetForm(ob)->RestoreButton();
280 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
282 GetForm(ob)->InputCB(ob, d);
286 static int C_FormBaseWMHideCB(FL_FORM * form, void *)
288 // Close the dialog cleanly, even if the WM is used to do so.
289 lyx::Assert(form && form->u_vdata);
290 FormBase * pre = static_cast<FormBase *>(form->u_vdata);
296 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
297 FL_Coord, FL_Coord, int key, void *)
299 // Note that the return value is important in the pre-emptive handler.
300 // Don't return anything other than 0.
303 // Don't Assert this one, as it can happen quite naturally when things
304 // are being deleted in the d-tor.
306 if (!ob->form) return 0;
308 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
311 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
312 // Trigger an input event when pasting in an xforms input object
313 // using the middle mouse button.
316 } else if (event == FL_ENTER || event == FL_LEAVE){
317 // Post feedback as the mouse enters the object,
318 // remove it as the mouse leaves.
319 pre->FeedbackCB(ob, event);