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"
26 // Callback function invoked by xforms when the dialog is closed by the
28 static int C_FormBaseWMHideCB(FL_FORM * form, void *);
30 // Use this to diaplay feedback messages or to trigger an input event on paste
31 // with the middle mouse button
32 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
33 FL_Coord, FL_Coord, int key, 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), warning_posted_(false)
45 void FormBase::redraw()
47 if (form() && form()->visible)
48 fl_redraw_form(form());
58 // use minw_ to flag whether the dialog has ever been shown
59 // (Needed now that build() is/should be called from the controller)
63 // work around dumb xforms sizing bug
67 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
70 fl_freeze_form(form());
71 update(); // make sure its up-to-date
72 fl_unfreeze_form(form());
74 if (form()->visible) {
75 fl_raise_form(form());
76 /* This XMapWindow() will hopefully ensure that
77 * iconified dialogs are de-iconified. Mad props
78 * out to those crazy Xlib guys for forgetting a
79 * XDeiconifyWindow(). At least WindowMaker, when
80 * being notified of the redirected MapRequest will
81 * specifically de-iconify. From source, fvwm2 seems
84 XMapWindow(fl_get_display(), form()->window);
86 // calls to fl_set_form_minsize/maxsize apply only to the next
87 // fl_show_form(), so this comes first.
88 fl_set_form_minsize(form(), minw_, minh_);
90 fl_set_form_maxsize(form(), minw_, minh_);
93 FL_PLACE_MOUSE | FL_FREE_SIZE,
94 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
100 void FormBase::hide()
102 if (form() && form()->visible)
103 fl_hide_form(form());
107 void FormBase::InputCB(FL_OBJECT * ob, long data)
109 // It is possible to set the choice to 0 when using the
110 // keyboard shortcuts. This work-around deals with the problem.
111 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
112 fl_set_choice(ob, 1);
115 bc().input(input(ob, data));
119 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
121 return ButtonPolicy::SMI_VALID;
125 // preemptive handler for feedback messages
126 void FormBase::FeedbackCB(FL_OBJECT * ob, int event)
132 warning_posted_ = false;
137 if (!warning_posted_)
147 void FormBase::setPrehandler(FL_OBJECT * ob)
150 fl_set_object_prehandler(ob, C_FormBasePrehandler);
154 void FormBase::setWarningPosted(bool warning)
156 warning_posted_ = warning;
162 FormBase * GetForm(FL_OBJECT * ob)
164 lyx::Assert(ob && ob->form && ob->form->u_vdata);
165 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
174 static int C_FormBaseWMHideCB(FL_FORM * form, void *)
176 // Close the dialog cleanly, even if the WM is used to do so.
177 lyx::Assert(form && form->u_vdata);
178 FormBase * pre = static_cast<FormBase *>(form->u_vdata);
184 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
186 GetForm(ob)->ApplyButton();
190 void C_FormBaseOKCB(FL_OBJECT * ob, long)
192 GetForm(ob)->OKButton();
196 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
198 FormBase * form = GetForm(ob);
199 form->CancelButton();
203 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
205 GetForm(ob)->RestoreButton();
209 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
211 GetForm(ob)->InputCB(ob, d);
215 static int C_FormBasePrehandler(FL_OBJECT * ob, int event,
216 FL_Coord, FL_Coord, int key, void *)
218 // Note that the return value is important in the pre-emptive handler.
219 // Don't return anything other than 0.
222 // Don't Assert this one, as it can happen quite naturally when things
223 // are being deleted in the d-tor.
225 if (!ob->form) return 0;
227 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
230 if (event == FL_PUSH && key == 2 && ob->objclass == FL_INPUT) {
231 // Trigger an input event when pasting in an xforms input object
232 // using the middle mouse button.
235 } else if (event == FL_ENTER || event == FL_LEAVE){
236 // Post feedback as the mouse enters the object,
237 // remove it as the mouse leaves.
238 pre->FeedbackCB(ob, event);