3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
19 #include "ControlButtons.h"
21 #include "xforms_resize.h"
24 #include "support/LAssert.h"
25 #include "support/filetools.h" // LibFileSearch
27 #include FORMS_H_LOCATION
31 // Callback function invoked by xforms when the dialog is closed by the
33 static int C_WMHideCB(FL_FORM * form, void *);
35 // Callback function invoked by the xforms pre- and post-handler routines
36 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
41 FormBase::FormBase(string const & t, bool allowResize)
42 : ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
43 title_(t), tooltips_(new Tooltips())
53 Tooltips & FormBase::tooltips()
59 void FormBase::redraw()
61 if (form() && form()->visible)
62 fl_redraw_form(form());
66 xformsBC & FormBase::bc()
68 return static_cast<xformsBC &>(getController().bc());
69 // return dynamic_cast<GUIbc &>(controller_ptr_->bc());
79 // use minw_ to flag whether the dialog has ever been shown
80 // (Needed now that build() is/should be called from the controller)
82 double const scale = scale_to_fit_tabs(form());
84 scale_form(form(), scale);
88 // work around dumb xforms sizing bug
92 fl_set_form_atclose(form(), C_WMHideCB, 0);
95 fl_freeze_form(form());
96 update(); // make sure its up-to-date
97 fl_unfreeze_form(form());
99 if (form()->visible) {
100 fl_raise_form(form());
101 /* This XMapWindow() will hopefully ensure that
102 * iconified dialogs are de-iconified. Mad props
103 * out to those crazy Xlib guys for forgetting a
104 * XDeiconifyWindow(). At least WindowMaker, when
105 * being notified of the redirected MapRequest will
106 * specifically de-iconify. From source, fvwm2 seems
109 XMapWindow(fl_get_display(), form()->window);
111 // calls to fl_set_form_minsize/maxsize apply only to the next
112 // fl_show_form(), so this comes first.
113 fl_set_form_minsize(form(), minw_, minh_);
115 fl_set_form_maxsize(form(), minw_, minh_);
117 string const maximize_title = "LyX: " + title_;
118 int const iconify_policy = getController().IconifyWithMain() ?
122 FL_PLACE_MOUSE | FL_FREE_SIZE,
124 maximize_title.c_str());
126 if (iconify_policy == 0) {
127 // set title for minimized form
128 string const minimize_title = title_;
129 fl_winicontitle(form()->window, minimize_title.c_str());
131 // assign an icon to form
132 string const iconname = LibFileSearch("images", "lyx", "xpm");
133 if (!iconname.empty()) {
136 Pixmap const icon_p = fl_read_pixmapfile(fl_root,
141 0, 0, 0); // this leaks
142 fl_set_form_icon(form(), icon_p, icon_mask);
151 void FormBase::hide()
153 // xforms sometimes tries to process a hint-type MotionNotify, and
154 // use XQueryPointer, without verifying if the window still exists.
155 // So we try to clear out motion events in the queue before the
157 XSync(fl_get_display(), false);
159 if (form() && form()->visible)
160 fl_hide_form(form());
164 void FormBase::setPrehandler(FL_OBJECT * ob)
167 fl_set_object_prehandler(ob, C_PrehandlerCB);
171 void FormBase::InputCB(FL_OBJECT * ob, long data)
173 // It is possible to set the choice to 0 when using the
174 // keyboard shortcuts. This work-around deals with the problem.
175 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
176 fl_set_choice(ob, 1);
179 bc().input(input(ob, data));
183 ButtonPolicy::SMInput FormBase::input(FL_OBJECT *, long)
185 return ButtonPolicy::SMI_VALID;
191 FormBase * GetForm(FL_OBJECT * ob)
193 lyx::Assert(ob && ob->form && ob->form->u_vdata);
194 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
203 void C_FormBaseApplyCB(FL_OBJECT * ob, long)
205 GetForm(ob)->getController().ApplyButton();
209 void C_FormBaseOKCB(FL_OBJECT * ob, long)
211 GetForm(ob)->getController().OKButton();
215 void C_FormBaseCancelCB(FL_OBJECT * ob, long)
217 FormBase * form = GetForm(ob);
218 form->getController().CancelButton();
222 void C_FormBaseRestoreCB(FL_OBJECT * ob, long)
224 GetForm(ob)->getController().RestoreButton();
228 void C_FormBaseInputCB(FL_OBJECT * ob, long d)
230 GetForm(ob)->InputCB(ob, d);
234 static int C_WMHideCB(FL_FORM * form, void *)
236 // Close the dialog cleanly, even if the WM is used to do so.
237 lyx::Assert(form && form->u_vdata);
238 FormBase * ptr = static_cast<FormBase *>(form->u_vdata);
239 ptr->getController().CancelButton();
243 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
244 FL_Coord, FL_Coord, int key, void *)
246 // Note that the return value is important in the pre-emptive handler.
247 // Don't return anything other than 0.
250 // Don't Assert this one, as it can happen quite naturally when things
251 // are being deleted in the d-tor.
253 if (!ob->form) return 0;
255 FormBase * ptr = static_cast<FormBase *>(ob->form->u_vdata);
258 ptr->PrehandlerCB(ob, event, key);