]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/FormBaseDeprecated.C
Fix leaking pixmap icon.
[lyx.git] / src / frontends / xforms / FormBaseDeprecated.C
index 0fd20eee57f856e1aed913f15ae7c180f95441d3..0984fb6bd2f9b04312a58875c33c77820c860992 100644 (file)
@@ -1,9 +1,11 @@
 /**
  * \file FormBaseDeprecated.C
- * Copyright 2000-2001 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Angus Leeming, a.leeming@ic.ac.uk
+ * \author Angus Leeming 
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
@@ -24,6 +26,7 @@
 #include "frontends/LyXView.h"
 
 #include "support/LAssert.h"
+#include "support/filetools.h" //  LibFileSearch
 
 #include <boost/bind.hpp>
 
@@ -39,18 +42,19 @@ 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), title_(t),
+       : lv_(lv), d_(d), title_(t), icon_pixmap_(0), icon_mask_(0),
          minw_(0), minh_(0), allow_resize_(allowResize),
-         tooltips_(new Tooltips)
-{
-       lyx::Assert(lv && d);
-}
+         tooltips_(new Tooltips())
+{}
 
 
 FormBaseDeprecated::~FormBaseDeprecated()
 {
+       if (icon_pixmap_)
+               XFreePixmap(fl_get_display(), icon_pixmap_);
+
        delete tooltips_;
 }
 
@@ -71,7 +75,7 @@ void FormBaseDeprecated::redraw()
 void FormBaseDeprecated::connect()
 {
        fl_set_form_minsize(form(), minw_, minh_);
-       r_ = Dialogs::redrawGUI.connect(boost::bind(&FormBaseDeprecated::redraw, this));
+       r_ = d_.redrawGUI().connect(boost::bind(&FormBaseDeprecated::redraw, this));
 }
 
 
@@ -82,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());
@@ -124,12 +152,18 @@ 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());
+                            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();
 }
 
@@ -205,7 +239,7 @@ void FormBaseDeprecated::RestoreCB()
 }
 
 
-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)
 {}
@@ -213,12 +247,12 @@ FormBaseBI::FormBaseBI(LyXView * lv, Dialogs * d, string const & t,
 
 void FormBaseBI::connect()
 {
-       h_ = d_->hideAll.connect(boost::bind(&FormBaseBI::hide, this));
+       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)
 {}
@@ -226,9 +260,9 @@ FormBaseBD::FormBaseBD(LyXView * lv, Dialogs * d, string const & t,
 
 void FormBaseBD::connect()
 {
-       u_ = d_->updateBufferDependent.
+       u_ = d_.updateBufferDependent.
                connect(boost::bind(&FormBaseBD::updateSlot, this, _1));
-       h_ = d_->hideBufferDependent.
+       h_ = d_.hideBufferDependent.
                connect(boost::bind(&FormBaseBD::hide, this));
        FormBaseDeprecated::connect();
 }