]> git.lyx.org Git - features.git/commitdiff
Fix leaking pixmap icon.
authorAngus Leeming <leeming@lyx.org>
Mon, 30 Sep 2002 20:00:42 +0000 (20:00 +0000)
committerAngus Leeming <leeming@lyx.org>
Mon, 30 Sep 2002 20:00:42 +0000 (20:00 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5352 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/xforms/ChangeLog
src/frontends/xforms/FormBase.C
src/frontends/xforms/FormBase.h
src/frontends/xforms/FormBaseDeprecated.C
src/frontends/xforms/FormBaseDeprecated.h
src/frontends/xforms/XFormsView.C
src/frontends/xforms/XFormsView.h

index 9b9968ce002ffc930dcdbb0551b01a50d4041c9d..fedad6633c362f31f73b4ee8d0b6d2c93fc48092 100644 (file)
@@ -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.
index 4486572f8846d55616ad08e1c690dd35232d95e3..545234c9efd8b6a5469d4973111f7067b7c9507a 100644 (file)
@@ -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::show()
+void FormBase::prepare_to_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);
+
+       // 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_);
        }
+}
 
-       // use minw_ to flag whether the dialog has ever been shown
-       // (Needed now that build() is/should be called from the controller)
-       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;
+void FormBase::show()
+{
+       // build() is/should be called from the controller, so form() should
+       // always exist.
+       lyx::Assert(form());
 
-               fl_set_form_atclose(form(), C_WMHideCB, 0);
+       // 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) {
+               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();
 }
 
index f67731cd0febc9ed6c0c68b6255b6fcd82edd5d3..d578803b4fcf1069714f54687f4dab8d66df526a 100644 (file)
 #endif
 
 #include "ViewBase.h"
-#include "LString.h"
 #include "ButtonPolicies.h"
 #include "FeedbackController.h"
+#include "forms_fwd.h"
 
+#include "LString.h"
 #include <boost/scoped_ptr.hpp>
-
-#include "forms_fwd.h"
+#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_;
 };
index d07bb0a13bfc503ab0ab6a07755de524d98a7e65..0984fb6bd2f9b04312a58875c33c77820c860992 100644 (file)
@@ -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::show()
+void FormBaseDeprecated::prepare_to_show()
 {
-       if (!form()) {
-               build();
-
-               double const scale = scale_to_fit_tabs(form());
-               if (scale > 1.001)
-                       scale_form(form(), scale);
-
-               bc().refresh();
+       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_);
+       }
+}
 
-               // work around dumb xforms sizing bug
-               minw_ = form()->w;
-               minh_ = form()->h;
 
-               fl_set_form_atclose(form(), C_WMHideCB, 0);
+void FormBaseDeprecated::show()
+{
+       if (!form()) {
+               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();
 }
 
index 5a8d181a7e9dfb1dc5deabaf987d7cb1127471f8..65c2c7dfd2e239c397a10889b96de2ef28ebecdf 100644 (file)
 #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_;
        ///
index 1f504959d85576d689c39b69a6aabed4937f7023..59e25ac9bceed52c8dc762abadde45f62a07b145 100644 (file)
@@ -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
index 6577cc3bdb82082ff5215293e09740fa30ca6db9..bb81268005302b742d87cc988cf8250c1790630b 100644 (file)
@@ -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