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),
48 minw_(0), minh_(0), allow_resize_(allowResize),
49 tooltips_(new Tooltips())
53 FormBaseDeprecated::~FormBaseDeprecated()
59 Tooltips & FormBaseDeprecated::tooltips()
65 void FormBaseDeprecated::redraw()
67 if (form() && form()->visible)
68 fl_redraw_form(form());
72 void FormBaseDeprecated::connect()
74 fl_set_form_minsize(form(), minw_, minh_);
75 r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this));
79 void FormBaseDeprecated::disconnect()
86 void FormBaseDeprecated::show()
91 double const scale = scale_to_fit_tabs(form());
93 scale_form(form(), scale);
97 // work around dumb xforms sizing bug
101 fl_set_form_atclose(form(), C_WMHideCB, 0);
104 fl_freeze_form(form());
106 fl_unfreeze_form(form());
108 if (form()->visible) {
109 fl_raise_form(form());
110 /* This XMapWindow() will hopefully ensure that
111 * iconified dialogs are de-iconified. Mad props
112 * out to those crazy Xlib guys for forgetting a
113 * XDeiconifyWindow(). At least WindowMaker, when
114 * being notified of the redirected MapRequest will
115 * specifically de-iconify. From source, fvwm2 seems
118 XMapWindow(fl_get_display(), form()->window);
122 // calls to fl_set_form_minsize/maxsize apply only to the next
123 // fl_show_form(), so this comes first.
124 fl_set_form_minsize(form(), minw_, minh_);
126 fl_set_form_maxsize(form(), minw_, minh_);
128 string const maximize_title = "LyX: " + title_;
129 int const iconify_policy = lyxrc.dialogs_iconify_with_main ?
133 FL_PLACE_MOUSE | FL_FREE_SIZE,
135 maximize_title.c_str());
137 if (iconify_policy == 0) {
138 // set title for minimized form
139 string const minimize_title = title_;
140 fl_winicontitle(form()->window, minimize_title.c_str());
142 // assign an icon to form
143 string const iconname = LibFileSearch("images", "lyx", "xpm");
144 if (!iconname.empty()) {
147 Pixmap const icon_p = fl_read_pixmapfile(fl_root,
152 0, 0, 0); // this leaks
153 fl_set_form_icon(form(), icon_p, icon_mask);
162 void FormBaseDeprecated::hide()
164 // xforms sometimes tries to process a hint-type MotionNotify, and
165 // use XQueryPointer, without verifying if the window still exists.
166 // So we try to clear out motion events in the queue before the
168 XSync(fl_get_display(), false);
170 if (form() && form()->visible) {
171 // some dialogs might do things to the form first
172 // such as the nested tabfolder problem in Preferences
174 fl_hide_form(form());
179 void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob)
182 fl_set_object_prehandler(ob, C_PrehandlerCB);
186 void FormBaseDeprecated::WMHideCB()
193 void FormBaseDeprecated::ApplyCB()
200 void FormBaseDeprecated::OKCB()
207 void FormBaseDeprecated::CancelCB()
214 void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data)
216 // It is possible to set the choice to 0 when using the
217 // keyboard shortcuts. This work-around deals with the problem.
218 if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) {
219 fl_set_choice(ob, 1);
222 bc().valid(input(ob, data));
226 void FormBaseDeprecated::RestoreCB()
233 FormBaseBI::FormBaseBI(LyXView & lv, Dialogs & d, string const & t,
235 : FormBaseDeprecated(lv, d, t, allowResize)
239 void FormBaseBI::connect()
241 h_ = d_.hideAll.connect(boost::bind(&FormBaseBI::hide, this));
242 FormBaseDeprecated::connect();
246 FormBaseBD::FormBaseBD(LyXView & lv, Dialogs & d, string const & t,
248 : FormBaseDeprecated(lv, d, t, allowResize)
252 void FormBaseBD::connect()
254 u_ = d_.updateBufferDependent.
255 connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
256 h_ = d_.hideBufferDependent.
257 connect(boost::bind(&FormBaseBD::hide, this));
258 FormBaseDeprecated::connect();
262 void FormBaseBD::disconnect()
265 FormBaseDeprecated::disconnect();
271 FormBaseDeprecated * GetForm(FL_OBJECT * ob)
273 lyx::Assert(ob && ob->form && ob->form->u_vdata);
274 FormBaseDeprecated * ptr =
275 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
284 void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long)
286 GetForm(ob)->ApplyCB();
290 void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long)
296 void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long)
298 GetForm(ob)->CancelCB();
302 void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d)
304 GetForm(ob)->InputCB(ob, d);
308 void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long)
310 GetForm(ob)->RestoreCB();
313 static int C_WMHideCB(FL_FORM * form, void *)
315 // Close the dialog cleanly, even if the WM is used to do so.
316 lyx::Assert(form && form->u_vdata);
317 FormBaseDeprecated * ptr =
318 static_cast<FormBaseDeprecated *>(form->u_vdata);
323 static int C_PrehandlerCB(FL_OBJECT * ob, int event,
324 FL_Coord, FL_Coord, int key, void *)
326 // Note that the return value is important in the pre-emptive handler.
327 // Don't return anything other than 0.
330 // Don't Assert this one, as it can happen quite naturally when things
331 // are being deleted in the d-tor.
333 if (!ob->form) return 0;
335 FormBaseDeprecated * ptr =
336 static_cast<FormBaseDeprecated *>(ob->form->u_vdata);
339 ptr->PrehandlerCB(ob, event, key);