X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Ffrontends%2Fxforms%2FFormBaseDeprecated.C;h=0984fb6bd2f9b04312a58875c33c77820c860992;hb=f991ac4421699843081001d6ef01791026068036;hp=f9ed4ef1fce84e8b3d38fe6483e9d926c6a0089f;hpb=625f8c79ac0d1ab747680a9537a8ba857f260c28;p=lyx.git diff --git a/src/frontends/xforms/FormBaseDeprecated.C b/src/frontends/xforms/FormBaseDeprecated.C index f9ed4ef1fc..0984fb6bd2 100644 --- a/src/frontends/xforms/FormBaseDeprecated.C +++ b/src/frontends/xforms/FormBaseDeprecated.C @@ -1,45 +1,67 @@ -/* This file is part of - * ====================================================== +/** + * \file FormBaseDeprecated.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. * - * LyX, The Document Processor + * \author Angus Leeming * - * Copyright 2000-2001 The LyX Team. - * - * ====================================================== + * Full author contact details are available in file CREDITS */ #include -#include FORMS_H_LOCATION - #ifdef __GNUG__ #pragma implementation #endif #include "Dialogs.h" #include "FormBaseDeprecated.h" -#include "LyXView.h" -#include "support/LAssert.h" #include "xformsBC.h" +#include "xforms_resize.h" +#include "Tooltips.h" +#include FORMS_H_LOCATION + #include "lyxrc.h" -using SigC::slot; +#include "frontends/LyXView.h" + +#include "support/LAssert.h" +#include "support/filetools.h" // LibFileSearch + +#include extern "C" { // Callback function invoked by xforms when the dialog is closed by the // window manager -static int C_FormBaseDeprecatedWMHideCB(FL_FORM *, void *); - +static int C_WMHideCB(FL_FORM *, void *); + +// Callback function invoked by the xforms pre- and post-handler routines +static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *); + } // extern "C" -FormBaseDeprecated::FormBaseDeprecated(LyXView * lv, Dialogs * d, +FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d, string const & t, bool allowResize) - : lv_(lv), d_(d), h_(0), r_(0), title_(t), - minw_(0), minh_(0), allow_resize_(allowResize) + : lv_(lv), d_(d), title_(t), icon_pixmap_(0), icon_mask_(0), + minw_(0), minh_(0), allow_resize_(allowResize), + tooltips_(new Tooltips()) +{} + + +FormBaseDeprecated::~FormBaseDeprecated() { - lyx::Assert(lv && d); + if (icon_pixmap_) + XFreePixmap(fl_get_display(), icon_pixmap_); + + delete tooltips_; +} + + +Tooltips & FormBaseDeprecated::tooltips() +{ + return *tooltips_; } @@ -53,7 +75,7 @@ void FormBaseDeprecated::redraw() void FormBaseDeprecated::connect() { fl_set_form_minsize(form(), minw_, minh_); - r_ = Dialogs::redrawGUI.connect(slot(this,&FormBaseDeprecated::redraw)); + r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this)); } @@ -64,36 +86,63 @@ void FormBaseDeprecated::disconnect() } -void FormBaseDeprecated::show() +void FormBaseDeprecated::prepare_to_show() { - if (!form()) { - build(); + build(); + + double const scale = scale_to_fit_tabs(form()); + if (scale > 1.001) + scale_form(form(), scale); + + bc().refresh(); + + // work around dumb xforms sizing bug + minw_ = form()->w; + minh_ = form()->h; + + fl_set_form_atclose(form(), C_WMHideCB, 0); + + // set the title for the minimized form + if (!lyxrc.dialogs_iconify_with_main) + fl_winicontitle(form()->window, title_.c_str()); + + // assign an icon to the form + string const iconname = LibFileSearch("images", "lyx", "xpm"); + if (!iconname.empty()) { + unsigned int w, h; + icon_pixmap_ = fl_read_pixmapfile(fl_root, + iconname.c_str(), + &w, + &h, + &icon_mask_, + 0, 0, 0); + fl_set_form_icon(form(), icon_pixmap_, icon_mask_); + } +} - bc().refresh(); - - // work around dumb xforms sizing bug - minw_ = form()->w; - minh_ = form()->h; - fl_set_form_atclose(form(), - C_FormBaseDeprecatedWMHideCB, 0); +void FormBaseDeprecated::show() +{ + if (!form()) { + prepare_to_show(); } + // make sure the form is up to date. fl_freeze_form(form()); - update(); // make sure its up-to-date + update(); fl_unfreeze_form(form()); if (form()->visible) { fl_raise_form(form()); - /* This XMapWindow() will hopefully ensure that - * iconified dialogs are de-iconified. Mad props - * out to those crazy Xlib guys for forgetting a - * XDeiconifyWindow(). At least WindowMaker, when - * being notified of the redirected MapRequest will - * specifically de-iconify. From source, fvwm2 seems - * to do the same. - */ - XMapWindow(fl_get_display(), form()->window); + /* This XMapWindow() will hopefully ensure that + * iconified dialogs are de-iconified. Mad props + * out to those crazy Xlib guys for forgetting a + * XDeiconifyWindow(). At least WindowMaker, when + * being notified of the redirected MapRequest will + * specifically de-iconify. From source, fvwm2 seems + * to do the same. + */ + XMapWindow(fl_get_display(), form()->window); } else { connect(); @@ -103,16 +152,30 @@ void FormBaseDeprecated::show() if (!allow_resize_) fl_set_form_maxsize(form(), minw_, minh_); + string const maximize_title = "LyX: " + title_; + int const iconify_policy = + lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0; + fl_show_form(form(), - FL_PLACE_MOUSE | FL_FREE_SIZE, - (lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0), - title_.c_str()); + FL_PLACE_MOUSE | FL_FREE_SIZE, + iconify_policy, + maximize_title.c_str()); } + + // For some strange reason known only to xforms, the tooltips can only + // be set on a form that is already visible... + tooltips().set(); } void FormBaseDeprecated::hide() { + // xforms sometimes tries to process a hint-type MotionNotify, and + // use XQueryPointer, without verifying if the window still exists. + // So we try to clear out motion events in the queue before the + // DestroyNotify + XSync(fl_get_display(), false); + if (form() && form()->visible) { // some dialogs might do things to the form first // such as the nested tabfolder problem in Preferences @@ -122,82 +185,61 @@ void FormBaseDeprecated::hide() } -int FormBaseDeprecated::WMHideCB(FL_FORM * form, void *) +void FormBaseDeprecated::setPrehandler(FL_OBJECT * ob) { - lyx::Assert(form); - // Ensure that the signals (u and h) are disconnected even if the - // window manager is used to close the dialog. - FormBaseDeprecated * pre = - static_cast(form->u_vdata); - lyx::Assert(pre); - pre->hide(); - pre->bc().hide(); - return FL_CANCEL; + lyx::Assert(ob); + fl_set_object_prehandler(ob, C_PrehandlerCB); } -void FormBaseDeprecated::ApplyCB(FL_OBJECT * ob, long) +void FormBaseDeprecated::WMHideCB() { - lyx::Assert(ob && ob->form); - FormBaseDeprecated * pre = - static_cast(ob->form->u_vdata); - lyx::Assert(pre); - pre->apply(); - pre->bc().apply(); + hide(); + bc().hide(); } -void FormBaseDeprecated::OKCB(FL_OBJECT * ob, long) +void FormBaseDeprecated::ApplyCB() { - lyx::Assert(ob && ob->form); - FormBaseDeprecated * pre = - static_cast(ob->form->u_vdata); - lyx::Assert(pre); - pre->ok(); - pre->bc().ok(); + apply(); + bc().apply(); } -void FormBaseDeprecated::CancelCB(FL_OBJECT * ob, long) +void FormBaseDeprecated::OKCB() { - lyx::Assert(ob && ob->form); - FormBaseDeprecated * pre = - static_cast(ob->form->u_vdata); - lyx::Assert(pre); - pre->cancel(); - pre->bc().cancel(); + ok(); + bc().ok(); } -void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data) +void FormBaseDeprecated::CancelCB() { - lyx::Assert(ob && ob->form); - FormBaseDeprecated * pre = - static_cast(ob->form->u_vdata); - lyx::Assert(pre); + cancel(); + bc().cancel(); +} + +void FormBaseDeprecated::InputCB(FL_OBJECT * ob, long data) +{ // It is possible to set the choice to 0 when using the // keyboard shortcuts. This work-around deals with the problem. if (ob && ob->objclass == FL_CHOICE && fl_get_choice(ob) < 1) { fl_set_choice(ob, 1); } - pre->bc().valid(pre->input(ob, data)); + bc().valid(input(ob, data)); } -void FormBaseDeprecated::RestoreCB(FL_OBJECT * ob, long) +void FormBaseDeprecated::RestoreCB() { - lyx::Assert(ob && ob->form); - FormBaseDeprecated * pre = - static_cast(ob->form->u_vdata); - lyx::Assert(pre); - pre->bc().restore(); - pre->restore(); + bc().restore(); + restore(); } -FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t, +FormBaseBI::FormBaseBI(LyXView & lv, Dialogs & d, string const & t, bool allowResize) : FormBaseDeprecated(lv, d, t, allowResize) {} @@ -205,24 +247,23 @@ FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t, void FormBaseBI::connect() { - h_ = d_->hideAll.connect(slot(this, &FormBaseBI::hide)); + h_ = d_.hideAll.connect(boost::bind(&FormBaseBI::hide, this)); FormBaseDeprecated::connect(); } -FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t, +FormBaseBD::FormBaseBD(LyXView & lv, Dialogs & d, string const & t, bool allowResize) - : FormBaseDeprecated(lv, d, t, allowResize), - u_(0) + : FormBaseDeprecated(lv, d, t, allowResize) {} void FormBaseBD::connect() { - u_ = d_->updateBufferDependent. - connect(slot(this, &FormBaseBD::updateSlot)); - h_ = d_->hideBufferDependent. - connect(slot(this, &FormBaseBD::hide)); + u_ = d_.updateBufferDependent. + connect(boost::bind(&FormBaseBD::updateSlot, this, _1)); + h_ = d_.hideBufferDependent. + connect(boost::bind(&FormBaseBD::hide, this)); FormBaseDeprecated::connect(); } @@ -234,42 +275,79 @@ void FormBaseBD::disconnect() } -extern "C" { - -static int C_FormBaseDeprecatedWMHideCB(FL_FORM * ob, void * d) +namespace { + +FormBaseDeprecated * GetForm(FL_OBJECT * ob) { - return FormBaseDeprecated::WMHideCB(ob, d); + lyx::Assert(ob && ob->form && ob->form->u_vdata); + FormBaseDeprecated * ptr = + static_cast(ob->form->u_vdata); + return ptr; } +} // namespace anon + + +extern "C" { -void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long d) +void C_FormBaseDeprecatedApplyCB(FL_OBJECT * ob, long) { - FormBaseDeprecated::ApplyCB(ob, d); + GetForm(ob)->ApplyCB(); } -void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long d) +void C_FormBaseDeprecatedOKCB(FL_OBJECT * ob, long) { - FormBaseDeprecated::OKCB(ob, d); + GetForm(ob)->OKCB(); } -void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long d) +void C_FormBaseDeprecatedCancelCB(FL_OBJECT * ob, long) { - FormBaseDeprecated::CancelCB(ob, d); + GetForm(ob)->CancelCB(); } void C_FormBaseDeprecatedInputCB(FL_OBJECT * ob, long d) { - FormBaseDeprecated::InputCB(ob, d); + GetForm(ob)->InputCB(ob, d); } -void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long d) +void C_FormBaseDeprecatedRestoreCB(FL_OBJECT * ob, long) { - FormBaseDeprecated::RestoreCB(ob, d); + GetForm(ob)->RestoreCB(); } -} // extern "C" +static int C_WMHideCB(FL_FORM * form, void *) +{ + // Close the dialog cleanly, even if the WM is used to do so. + lyx::Assert(form && form->u_vdata); + FormBaseDeprecated * ptr = + static_cast(form->u_vdata); + ptr->WMHideCB(); + return FL_CANCEL; +} + +static int C_PrehandlerCB(FL_OBJECT * ob, int event, + FL_Coord, FL_Coord, int key, void *) +{ + // Note that the return value is important in the pre-emptive handler. + // Don't return anything other than 0. + lyx::Assert(ob); + // Don't Assert this one, as it can happen quite naturally when things + // are being deleted in the d-tor. + //Assert(ob->form); + if (!ob->form) return 0; + + FormBaseDeprecated * ptr = + static_cast(ob->form->u_vdata); + + if (ptr) + ptr->PrehandlerCB(ob, event, key); + + return 0; +} + +} // extern "C"