mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-31 07:45:44 +00:00
Fix leaking pixmap icon.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5352 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
b1b47074ed
commit
f991ac4421
@ -1,3 +1,19 @@
|
||||
2002-09-30 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* FormBase.[Ch]:
|
||||
* FormBaseDeprecated.[Ch]:
|
||||
(icon_pixmap_, icon_mask_) new member variables.
|
||||
(prepare_to_show) new method, containing initialisation code invoked
|
||||
the first time show() is called.
|
||||
(d-tor) destroy icon_pixmap_, if it exists.
|
||||
(show) ensure that the icon pixmap is generated only once.
|
||||
|
||||
* XFormsView.[Ch]:
|
||||
(icon_pixmap_, icon_mask_) new member variables.
|
||||
(d-tor) destroy icon_pixmap_, if it exists.
|
||||
(create_form_form_main) assign the generated pixmap to the new
|
||||
icon_pixmap_ member variable.
|
||||
|
||||
2002-09-26 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* xscreen.h: don't #include "XWorkArea.h", forward-declare XWorkArea.
|
||||
|
@ -40,12 +40,16 @@ static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
|
||||
|
||||
FormBase::FormBase(string const & t, bool allowResize)
|
||||
: ViewBase(), minw_(0), minh_(0), allow_resize_(allowResize),
|
||||
title_(t), tooltips_(new Tooltips())
|
||||
title_(t), icon_pixmap_(0), icon_mask_(0),
|
||||
tooltips_(new Tooltips())
|
||||
{}
|
||||
|
||||
|
||||
FormBase::~FormBase()
|
||||
{
|
||||
if (icon_pixmap_)
|
||||
XFreePixmap(fl_get_display(), icon_pixmap_);
|
||||
|
||||
delete tooltips_;
|
||||
}
|
||||
|
||||
@ -70,30 +74,55 @@ xformsBC & FormBase::bc()
|
||||
}
|
||||
|
||||
|
||||
void FormBase::prepare_to_show()
|
||||
{
|
||||
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 (!getController().IconifyWithMain())
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FormBase::show()
|
||||
{
|
||||
if (!form()) {
|
||||
build();
|
||||
}
|
||||
// build() is/should be called from the controller, so form() should
|
||||
// always exist.
|
||||
lyx::Assert(form());
|
||||
|
||||
// use minw_ to flag whether the dialog has ever been shown
|
||||
// (Needed now that build() is/should be called from the controller)
|
||||
// we use minw_ to flag whether the dialog has ever been shown.
|
||||
// In turn, prepare_to_show() initialises various bits 'n' pieces
|
||||
// (including minw_).
|
||||
if (minw_ == 0) {
|
||||
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);
|
||||
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) {
|
||||
@ -115,35 +144,17 @@ void FormBase::show()
|
||||
fl_set_form_maxsize(form(), minw_, minh_);
|
||||
|
||||
string const maximize_title = "LyX: " + title_;
|
||||
int const iconify_policy = getController().IconifyWithMain() ?
|
||||
FL_TRANSIENT : 0;
|
||||
int const iconify_policy =
|
||||
getController().IconifyWithMain() ? FL_TRANSIENT : 0;
|
||||
|
||||
fl_show_form(form(),
|
||||
FL_PLACE_MOUSE | FL_FREE_SIZE,
|
||||
iconify_policy,
|
||||
maximize_title.c_str());
|
||||
|
||||
if (iconify_policy == 0) {
|
||||
// set title for minimized form
|
||||
string const minimize_title = title_;
|
||||
fl_winicontitle(form()->window, minimize_title.c_str());
|
||||
|
||||
// assign an icon to form
|
||||
string const iconname = LibFileSearch("images", "lyx", "xpm");
|
||||
if (!iconname.empty()) {
|
||||
unsigned int w, h;
|
||||
Pixmap icon_mask;
|
||||
Pixmap const icon_p = fl_read_pixmapfile(fl_root,
|
||||
iconname.c_str(),
|
||||
&w,
|
||||
&h,
|
||||
&icon_mask,
|
||||
0, 0, 0); // this leaks
|
||||
fl_set_form_icon(form(), icon_p, icon_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For some strange reason known only to xforms, the tooltips can only
|
||||
// be set on a form that is already visible...
|
||||
tooltips().set();
|
||||
}
|
||||
|
||||
|
@ -20,14 +20,14 @@
|
||||
#endif
|
||||
|
||||
#include "ViewBase.h"
|
||||
#include "LString.h"
|
||||
#include "ButtonPolicies.h"
|
||||
#include "FeedbackController.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include "forms_fwd.h"
|
||||
|
||||
#include "LString.h"
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
#include <X11/Xlib.h> // for Pixmap
|
||||
|
||||
class xformsBC;
|
||||
class Tooltips;
|
||||
|
||||
@ -79,14 +79,23 @@ private:
|
||||
*/
|
||||
virtual void redraw();
|
||||
|
||||
/** Called on the first show() request, initialising various bits and
|
||||
* pieces.
|
||||
*/
|
||||
void prepare_to_show();
|
||||
|
||||
/// The dialog's minimum allowable dimensions.
|
||||
int minw_;
|
||||
///
|
||||
int minh_;
|
||||
/// Can the dialog be resized after it has been created?
|
||||
bool allow_resize_;
|
||||
/// dialog title, displayed by WM.
|
||||
/// dialog title, displayed by the window manager.
|
||||
string title_;
|
||||
/// Passed to the window manager to give a pretty little symbol ;-)
|
||||
Pixmap icon_pixmap_;
|
||||
///
|
||||
Pixmap icon_mask_;
|
||||
///
|
||||
Tooltips * tooltips_;
|
||||
};
|
||||
|
@ -44,7 +44,7 @@ static int C_PrehandlerCB(FL_OBJECT *, int, FL_Coord, FL_Coord, int, void *);
|
||||
|
||||
FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d,
|
||||
string const & t, bool allowResize)
|
||||
: lv_(lv), d_(d), title_(t),
|
||||
: lv_(lv), d_(d), title_(t), icon_pixmap_(0), icon_mask_(0),
|
||||
minw_(0), minh_(0), allow_resize_(allowResize),
|
||||
tooltips_(new Tooltips())
|
||||
{}
|
||||
@ -52,6 +52,9 @@ FormBaseDeprecated::FormBaseDeprecated(LyXView & lv, Dialogs & d,
|
||||
|
||||
FormBaseDeprecated::~FormBaseDeprecated()
|
||||
{
|
||||
if (icon_pixmap_)
|
||||
XFreePixmap(fl_get_display(), icon_pixmap_);
|
||||
|
||||
delete tooltips_;
|
||||
}
|
||||
|
||||
@ -83,24 +86,48 @@ void FormBaseDeprecated::disconnect()
|
||||
}
|
||||
|
||||
|
||||
void FormBaseDeprecated::prepare_to_show()
|
||||
{
|
||||
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_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FormBaseDeprecated::show()
|
||||
{
|
||||
if (!form()) {
|
||||
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);
|
||||
prepare_to_show();
|
||||
}
|
||||
|
||||
// make sure the form is up to date.
|
||||
fl_freeze_form(form());
|
||||
update();
|
||||
fl_unfreeze_form(form());
|
||||
@ -126,35 +153,17 @@ void FormBaseDeprecated::show()
|
||||
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;
|
||||
int const iconify_policy =
|
||||
lyxrc.dialogs_iconify_with_main ? FL_TRANSIENT : 0;
|
||||
|
||||
fl_show_form(form(),
|
||||
FL_PLACE_MOUSE | FL_FREE_SIZE,
|
||||
iconify_policy,
|
||||
maximize_title.c_str());
|
||||
|
||||
if (iconify_policy == 0) {
|
||||
// set title for minimized form
|
||||
string const minimize_title = title_;
|
||||
fl_winicontitle(form()->window, minimize_title.c_str());
|
||||
|
||||
// assign an icon to form
|
||||
string const iconname = LibFileSearch("images", "lyx", "xpm");
|
||||
if (!iconname.empty()) {
|
||||
unsigned int w, h;
|
||||
Pixmap icon_mask;
|
||||
Pixmap const icon_p = fl_read_pixmapfile(fl_root,
|
||||
iconname.c_str(),
|
||||
&w,
|
||||
&h,
|
||||
&icon_mask,
|
||||
0, 0, 0); // this leaks
|
||||
fl_set_form_icon(form(), icon_p, icon_mask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For some strange reason known only to xforms, the tooltips can only
|
||||
// be set on a form that is already visible...
|
||||
tooltips().set();
|
||||
}
|
||||
|
||||
|
@ -22,14 +22,14 @@
|
||||
#pragma interface
|
||||
#endif
|
||||
|
||||
#include "LString.h"
|
||||
#include "xformsBC.h"
|
||||
#include "FeedbackController.h"
|
||||
|
||||
#include "forms_fwd.h"
|
||||
|
||||
#include "LString.h"
|
||||
#include <boost/utility.hpp>
|
||||
#include <boost/signals/connection.hpp>
|
||||
#include <X11/Xlib.h> // for Pixmap
|
||||
|
||||
class Buffer;
|
||||
class Dialogs;
|
||||
@ -131,6 +131,15 @@ protected: // methods
|
||||
string title_;
|
||||
|
||||
private:
|
||||
/** Called on the first show() request, initialising various bits and
|
||||
* pieces.
|
||||
*/
|
||||
void prepare_to_show();
|
||||
|
||||
/// Passed to the window manager to give a pretty little symbol ;-)
|
||||
Pixmap icon_pixmap_;
|
||||
///
|
||||
Pixmap icon_mask_;
|
||||
/// The dialog's minimum allowable dimensions.
|
||||
int minw_;
|
||||
///
|
||||
|
@ -57,7 +57,8 @@ int C_XFormsView_atCloseMainFormCB(FL_FORM * form, void * p)
|
||||
|
||||
|
||||
XFormsView::XFormsView(int width, int height)
|
||||
: LyXView()
|
||||
: LyXView(),
|
||||
icon_pixmap_(0), icon_mask_(0)
|
||||
{
|
||||
create_form_form_main(width, height);
|
||||
fl_set_form_atclose(getForm(), C_XFormsView_atCloseMainFormCB, 0);
|
||||
@ -73,6 +74,9 @@ XFormsView::XFormsView(int width, int height)
|
||||
|
||||
XFormsView::~XFormsView()
|
||||
{
|
||||
if (icon_pixmap_)
|
||||
XFreePixmap(fl_get_display(), icon_pixmap_);
|
||||
|
||||
minibuffer_->freeze();
|
||||
fl_hide_form(form_);
|
||||
fl_free_form(form_);
|
||||
@ -159,19 +163,18 @@ void XFormsView::create_form_form_main(int width, int height)
|
||||
air, height - (25 + air), width - (2 * air), 25));
|
||||
|
||||
// assign an icon to main form
|
||||
string iconname = LibFileSearch("images", "lyx", "xpm");
|
||||
string const iconname = LibFileSearch("images", "lyx", "xpm");
|
||||
if (!iconname.empty()) {
|
||||
unsigned int w, h;
|
||||
Pixmap lyx_p, lyx_mask;
|
||||
lyx_p = fl_read_pixmapfile(fl_root,
|
||||
icon_pixmap_ = fl_read_pixmapfile(fl_root,
|
||||
iconname.c_str(),
|
||||
&w,
|
||||
&h,
|
||||
&lyx_mask,
|
||||
&icon_mask_,
|
||||
0,
|
||||
0,
|
||||
0); // this leaks
|
||||
fl_set_form_icon(getForm(), lyx_p, lyx_mask);
|
||||
0);
|
||||
fl_set_form_icon(getForm(), icon_pixmap_, icon_mask_);
|
||||
}
|
||||
|
||||
// set min size
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "forms_fwd.h"
|
||||
|
||||
#include "frontends/LyXView.h"
|
||||
#include <X11/Xlib.h> // for Pixmap
|
||||
|
||||
class XMiniBuffer;
|
||||
|
||||
@ -81,5 +82,9 @@ private:
|
||||
|
||||
/// the main form.
|
||||
FL_FORM * form_;
|
||||
/// Passed to the window manager to give a pretty little symbol ;-)
|
||||
Pixmap icon_pixmap_;
|
||||
///
|
||||
Pixmap icon_mask_;
|
||||
};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user