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 // Callback function invoked by xforms when the dialog is closed by the
37 static int C_WMHideCB(FL_FORM *, void *);
39 // Callback function invoked by the xforms pre- and post-handler routines
40 static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
45 FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d,
46 string const & t, bool allowResize)
47 : lv_(lv), d_(d), title_(t), icon_pixmap_(0), icon_mask_(0),
48 minw_(0), minh_(0), allow_resize_(allowResize),
49 tooltips_(new Tooltips())
53 FormBaseDeprecated::~FormBaseDeprecated()
56 XFreePixmap(fl_get_display(), icon_pixmap_);
62 Tooltips & FormBaseDeprecated::tooltips()
68 void FormBaseDeprecated::redraw()
70 if (form() && form()->visible)
71 fl_redraw_form(form());
75 void FormBaseDeprecated::connect()
77 fl_set_form_minsize(form(), minw_, minh_);
78 r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this));
82 void FormBaseDeprecated::disconnect()
89 void FormBaseDeprecated::prepare_to_show()
93 double const scale = scale_to_fit_tabs(form());
95 scale_form(form(), scale);
99 // work around dumb xforms sizing bug
103 fl_set_form_atclose(form(), C_WMHideCB, 0);
105 // set the title for the minimized form
106 if (!lyxrc.dialogs_iconify_with_main)
107 fl_winicontitle(form()->window, title_.c_str());
109 // assign an icon to the form
110 string const iconname = LibFileSearch("images", "lyx", "xpm");
111 if (!iconname.empty()) {
113 icon_pixmap_ = fl_read_pixmapfile(fl_root,
119 fl_set_form_icon(form(), icon_pixmap_, icon_mask_);
124 void FormBaseDeprecated::show()
130 // make sure the form is up to date.
131 fl_freeze_form(form());
133 fl_unfreeze_form(form());
135 if (form()->visible) {
136 fl_raise_form(form());
137 /* This XMapWindow() will hopefully ensure that
138 * iconified dialogs are de-iconified. Mad props
139 * out to those crazy Xlib guys for forgetting a
140 * XDeiconifyWindow(). At least WindowMaker, when
141 * being notified of the redirected MapRequest will
142 * specifically de-iconify. From source, fvwm2 seems
145 XMapWindow(fl_get_display(), form()->window);
149 // calls to fl_set_form_minsize/maxsize apply only to the next
150 // fl_show_form(), so this comes first.
151 fl_set_form_minsize(form(), minw_, minh_);
153 fl_set_form_maxsize(form(), minw_, minh_);
155 string const maximize_title = "LyX: " + title_;
156 int const iconify_policy =
157 lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0;
160 FL_PLACE_MOUSE | FL_FREE_SIZE,
162 maximize_title.c_str());
165 // For some strange reason known only to xforms, the tooltips can only
166 // be set on a form that is already visible...
171 void FormBaseDeprecated::hide()
173 // xforms sometimes tries to process a hint-type MotionNotify, and
174 // use XQueryPointer, without verifying if the window still exists.
175 // So we try to clear out motion events in the queue before the
177 XSync(fl_get_display(), false);
179 if (form() && form()->visible) {
180 // some dialogs might do things to the form first
181 // such as the nested tabfolder problem in Preferences
183 fl_hide_form(form());
188 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
191 fl_set_object_prehandler(ob, C_PrehandlerCB);
195 void FormBaseDeprecated::WMHideCB()
202 void FormBaseDeprecated::ApplyCB()
209 void FormBaseDeprecated::OKCB()
216 void FormBaseDeprecated::CancelCB()
223 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
225 // It is possible to set the choice to 0 when using the
226 // keyboard shortcuts. This work-around deals with the problem.
227 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
228 fl_set_choice(ob, 1);
231 bc().valid(input(ob, data));
235 void FormBaseDeprecated::RestoreCB()
242 FormBaseBI::FormBaseBI(LyXView & lv, Dialogs & d, string const & t,
244 : FormBaseDeprecated(lv, d, t, allowResize)
248 void FormBaseBI::connect()
250 h_ = d_.hideAll.connect(boost::bind(&FormBaseBI::hide, this));
251 FormBaseDeprecated::connect();
255 FormBaseBD::FormBaseBD(LyXView & lv, Dialogs & d, string const & t,
257 : FormBaseDeprecated(lv, d, t, allowResize)
261 void FormBaseBD::connect()
263 u_ = d_.updateBufferDependent.
264 connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
265 h_ = d_.hideBufferDependent.
266 connect(boost::bind(&FormBaseBD::hide, this));
267 FormBaseDeprecated::connect();
271 void FormBaseBD::disconnect()
274 FormBaseDeprecated::disconnect();
280 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
282 lyx::Assert(ob && ob->form && ob->form->u_vdata);
283 FormBaseDeprecated * ptr =
284 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
293 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
295 GetForm(ob)->ApplyCB();
299 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
305 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
307 GetForm(ob)->CancelCB();
311 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
313 GetForm(ob)->InputCB(ob, d);
317 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
319 GetForm(ob)->RestoreCB();
322 static int C_WMHideCB(FL_FORM * form, void *)
324 // Close the dialog cleanly, even if the WM is used to do so.
325 lyx::Assert(form && form->u_vdata);
326 FormBaseDeprecated * ptr =
327 static_cast<FormBaseDeprecated *>(form->u_vdata);
332 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
333 FL_Coord, FL_Coord, int key, void *)
335 // Note that the return value is important in the pre-emptive handler.
336 // Don't return anything other than 0.
339 // Don't Assert this one, as it can happen quite naturally when things
340 // are being deleted in the d-tor.
342 if (!ob->form) return 0;
344 FormBaseDeprecated * ptr =
345 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
348 ptr->PrehandlerCB(ob, event, key);