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"
25 // Callback function invoked by xforms when the dialog is closed by the
27 static int C_FormBaseWMHideCB(FL_FORM * form, void *);
31 FormBase::FormBase(ControlButtons & c, string const & t, bool allowResize)
32 : ViewBC<xformsBC>(c), minw_(0), minh_(0), allow_resize_(allowResize),
37 void FormBase::redraw()
39 if (form() && form()->visible)
40 fl_redraw_form(form());
50 // use minw_ to flag whether the dialog has ever been shown
51 // (Needed now that build() is/should be called from the controller)
55 // work around dumb xforms sizing bug
59 fl_set_form_atclose(form(), C_FormBaseWMHideCB, 0);
62 fl_freeze_form(form());
63 update(); // make sure its up-to-date
64 fl_unfreeze_form(form());
66 if (form()->visible) {
67 fl_raise_form(form());
68 /* This XMapWindow() will hopefully ensure that
69 * iconified dialogs are de-iconified. Mad props
70 * out to those crazy Xlib guys for forgetting a
71 * XDeiconifyWindow(). At least WindowMaker, when
72 * being notified of the redirected MapRequest will
73 * specifically de-iconify. From source, fvwm2 seems
76 XMapWindow(fl_get_display(), form()->window);
78 // calls to fl_set_form_minsize/maxsize apply only to the next
79 // fl_show_form(), so this comes first.
80 fl_set_form_minsize(form(), minw_, minh_);
82 fl_set_form_maxsize(form(), minw_, minh_);
85 FL_PLACE_MOUSE | FL_FREE_SIZE,
86 (controller_.IconifyWithMain() ? FL_TRANSIENT : 0),
94 if (form() && form()->visible)
99 void FormBase::InputCB(FL_OBJECT * ob, long data)
101 // It is possible to set the choice to 0 when using the
102 // keyboard shortcuts. This work-around deals with the problem.
103 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
104 fl_set_choice(ob, 1);
107 bc().input(input(ob, data));
111 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
113 return ButtonPolicy::SMI_VALID;
119 FormBase * GetForm(FL_OBJECT * ob)
121 lyx::Assert(ob && ob->form && ob->form->u_vdata);
122 FormBase * pre = static_cast<FormBase *>(ob->form->u_vdata);
132 int C_FormBaseWMHideCB(FL_FORM * form, void *)
134 // Close the dialog cleanly, even if the WM is used to do so.
135 lyx::Assert(form && form->u_vdata);
136 FormBase * pre = static_cast<FormBase *>(form->u_vdata);
142 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
144 GetForm(ob)->ApplyButton();
148 void C_FormBaseOKCB(FL_OBJECT * ob, long)
150 GetForm(ob)->OKButton();
154 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
156 FormBase * form = GetForm(ob);
157 form->CancelButton();
161 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
163 GetForm(ob)->RestoreButton();
167 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
169 GetForm(ob)->InputCB(ob, d);
173 // To trigger an input event when pasting in an xforms input object
174 // using the middle mouse button.
175 int C_CutandPastePH(FL_OBJECT * ob, int event,
176 FL_Coord, FL_Coord, int key, void *)
178 if ((event == FL_PUSH) && (key == 2)
179 && (ob->objclass == FL_INPUT)) {
180 C_FormBaseInputCB(ob, 0);