2 * \file FormBaseDeprecated.C
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
18 #include "FormBaseDeprecated.h"
20 #include "xforms_resize.h"
22 #include FORMS_H_LOCATION
26 #include "frontends/LyXView.h"
28 #include "support/LAssert.h"
29 #include "support/filetools.h" // LibFileSearch
31 #include <boost/bind.hpp>
35 #if FL_VERSION > 0 || FL_REVISION >= 89
36 // This should be in forms.h but isn't
37 void fl_hide_tooltip();
40 // Callback function invoked by xforms when the dialog is closed by the
42 static int C_WMHideCB(FL_FORM *, void *);
44 // Callback function invoked by the xforms pre- and post-handler routines
45 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
50 FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d,
51 string const & t, bool allowResize)
52 : lv_(lv), d_(d), title_(t), icon_pixmap_(0), icon_mask_(0),
53 minw_(0), minh_(0), allow_resize_(allowResize),
54 tooltips_(new Tooltips())
58 FormBaseDeprecated::~FormBaseDeprecated()
61 XFreePixmap(fl_get_display(), icon_pixmap_);
67 Tooltips & FormBaseDeprecated::tooltips()
73 void FormBaseDeprecated::redraw()
75 if (form() && form()->visible)
76 fl_redraw_form(form());
80 void FormBaseDeprecated::connect()
82 fl_set_form_minsize(form(), minw_, minh_);
83 r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this));
87 void FormBaseDeprecated::disconnect()
94 void FormBaseDeprecated::prepare_to_show()
98 double const scale = scale_to_fit_tabs(form());
100 scale_form(form(), scale);
104 // work around dumb xforms sizing bug
108 fl_set_form_atclose(form(), C_WMHideCB, 0);
110 // set the title for the minimized form
111 if (!lyxrc.dialogs_iconify_with_main)
112 fl_winicontitle(form()->window, title_.c_str());
114 // assign an icon to the form
115 string const iconname = LibFileSearch("images", "lyx", "xpm");
116 if (!iconname.empty()) {
118 icon_pixmap_ = fl_read_pixmapfile(fl_root,
124 fl_set_form_icon(form(), icon_pixmap_, icon_mask_);
129 void FormBaseDeprecated::show()
135 // make sure the form is up to date.
136 fl_freeze_form(form());
138 fl_unfreeze_form(form());
140 if (form()->visible) {
141 fl_raise_form(form());
142 /* This XMapWindow() will hopefully ensure that
143 * iconified dialogs are de-iconified. Mad props
144 * out to those crazy Xlib guys for forgetting a
145 * XDeiconifyWindow(). At least WindowMaker, when
146 * being notified of the redirected MapRequest will
147 * specifically de-iconify. From source, fvwm2 seems
150 XMapWindow(fl_get_display(), form()->window);
154 // calls to fl_set_form_minsize/maxsize apply only to the next
155 // fl_show_form(), so this comes first.
156 fl_set_form_minsize(form(), minw_, minh_);
158 fl_set_form_maxsize(form(), minw_, minh_);
160 string const maximize_title = "LyX: " + title_;
161 int const iconify_policy =
162 lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0;
165 FL_PLACE_MOUSE | FL_FREE_SIZE,
167 maximize_title.c_str());
172 void FormBaseDeprecated::hide()
174 #if FL_VERSION > 0 || FL_REVISION >= 89
175 // Does no harm if none is visible and ensures that the tooltip form
176 // is hidden should the dialog be closed from the keyboard.
180 // xforms sometimes tries to process a hint-type MotionNotify, and
181 // use XQueryPointer, without verifying if the window still exists.
182 // So we try to clear out motion events in the queue before the
184 XSync(fl_get_display(), false);
186 if (form() && form()->visible) {
187 // some dialogs might do things to the form first
188 // such as the nested tabfolder problem in Preferences
190 fl_hide_form(form());
195 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
198 fl_set_object_prehandler(ob, C_PrehandlerCB);
202 void FormBaseDeprecated::WMHideCB()
209 void FormBaseDeprecated::ApplyCB()
216 void FormBaseDeprecated::OKCB()
223 void FormBaseDeprecated::CancelCB()
230 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
232 // It is possible to set the choice to 0 when using the
233 // keyboard shortcuts. This work-around deals with the problem.
234 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
235 fl_set_choice(ob, 1);
238 bc().valid(input(ob, data));
242 void FormBaseDeprecated::RestoreCB()
249 FormBaseBI::FormBaseBI(LyXView & lv, Dialogs & d, string const & t,
251 : FormBaseDeprecated(lv, d, t, allowResize)
255 void FormBaseBI::connect()
257 h_ = d_.hideAll.connect(boost::bind(&FormBaseBI::hide, this));
258 FormBaseDeprecated::connect();
262 FormBaseBD::FormBaseBD(LyXView & lv, Dialogs & d, string const & t,
264 : FormBaseDeprecated(lv, d, t, allowResize)
268 void FormBaseBD::connect()
270 u_ = d_.updateBufferDependent.
271 connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
272 h_ = d_.hideBufferDependent.
273 connect(boost::bind(&FormBaseBD::hide, this));
274 FormBaseDeprecated::connect();
278 void FormBaseBD::disconnect()
281 FormBaseDeprecated::disconnect();
287 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
289 lyx::Assert(ob && ob->form && ob->form->u_vdata);
290 FormBaseDeprecated * ptr =
291 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
300 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
302 GetForm(ob)->ApplyCB();
306 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
312 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
314 GetForm(ob)->CancelCB();
318 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
320 GetForm(ob)->InputCB(ob, d);
324 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
326 GetForm(ob)->RestoreCB();
329 static int C_WMHideCB(FL_FORM * form, void *)
331 // Close the dialog cleanly, even if the WM is used to do so.
332 lyx::Assert(form && form->u_vdata);
333 FormBaseDeprecated * ptr =
334 static_cast<FormBaseDeprecated *>(form->u_vdata);
339 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
340 FL_Coord, FL_Coord, int key, void *)
342 // Note that the return value is important in the pre-emptive handler.
343 // Don't return anything other than 0.
346 // Don't Assert this one, as it can happen quite naturally when things
347 // are being deleted in the d-tor.
349 if (!ob->form) return 0;
351 FormBaseDeprecated * ptr =
352 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
355 ptr->PrehandlerCB(ob, event, key);