]> git.saurik.com Git - wxWidgets.git/commitdiff
added wxListCtrl::AssignImageList
authorVáclav Slavík <vslavik@fastmail.fm>
Thu, 28 Sep 2000 22:29:26 +0000 (22:29 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Thu, 28 Sep 2000 22:29:26 +0000 (22:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8441 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/listctrl.tex
include/wx/generic/listctrl.h
include/wx/msw/listctrl.h
src/generic/listctrl.cpp
src/msw/listctrl.cpp

index 79a8478b031d68f4fee5a0a5d62dd93e6675d655..fbe8e5b3966825634f4d8726301d7361205d9f00 100644 (file)
@@ -129,6 +129,19 @@ Arranges the items in icon or small icon view. This only has effect on Win32. {\
 \twocolitem{wxLIST\_ALIGN\_SNAP\_TO\_GRID}{Snap to grid.}
 \end{twocollist}
 
+\membersection{wxListCtrl::AssignImageList}\label{wxlistctrlassignimagelist}
+
+\func{void}{AssignImageList}{\param{wxImageList*}{ imageList}, \param{int }{which}}
+
+Sets the image list associated with the control and 
+takes ownership of it (i.e. the control will, unlike when using
+SetImageList, delete the list when destroyed). {\it which} is one of
+wxIMAGE\_LIST\_NORMAL, wxIMAGE\_LIST\_SMALL, wxIMAGE\_LIST\_STATE (the last is unimplemented).
+
+\wxheading{See also}
+
+\helpref{wxListCtrl::SetImageList}{wxlistctrlsetimagelist}
+
 \membersection{wxListCtrl::Create}\label{wxlistctrlcreate}
 
 \func{bool}{Create}{\param{wxWindow*}{ parent}, \param{wxWindowID}{ id},\rtfsp
@@ -523,6 +536,14 @@ In small or normal icon view, {\it col} must be -1, and the column width is set
 Sets the image list associated with the control. {\it which} is one of
 wxIMAGE\_LIST\_NORMAL, wxIMAGE\_LIST\_SMALL, wxIMAGE\_LIST\_STATE (the last is unimplemented).
 
+This method does not take ownership of the image list, you have to
+delete it yourself.
+
+\wxheading{See also}
+
+\helpref{wxListCtrl::AssignImageList}{wxlistctrlassignimagelist}
+
+
 \membersection{wxListCtrl::SetItem}\label{wxlistctrlsetitem}
 
 \func{bool}{SetItem}{\param{wxListItem\& }{info}}
index 09bd6c5b227b370c5beffc76436cee9c1b5e18ca..2a719a8ea8e93f87588e0372af0212ec6b56d1ab 100644 (file)
@@ -113,6 +113,7 @@ public:
     long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const;
     wxImageList *GetImageList( int which ) const;
     void SetImageList( wxImageList *imageList, int which );
+    void AssignImageList( wxImageList *imageList, int which );
     bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC
 
     void ClearAll();
@@ -166,6 +167,9 @@ public:
     wxImageList         *m_imageListNormal;
     wxImageList         *m_imageListSmall;
     wxImageList         *m_imageListState;  // what's that ?
+    bool                 m_ownsImageListNormal, 
+                         m_ownsImageListSmall,
+                         m_ownsImageListState;
     wxListHeaderWindow  *m_headerWin;
     wxListMainWindow    *m_mainWin;
 
index 91e526c88c649ad790dcc29c5eff736a6365af6a..d9189c5eab69e5f66bc3349a5c38ba2b6b9f1e45 100644 (file)
@@ -230,6 +230,7 @@ public:
     // So you have to set a NULL small-icon image list to be sure that
     // the wxLC_LIST mode works without icons. Of course, you may want icons...
     void SetImageList(wxImageList *imageList, int which) ;
+    void AssignImageList(wxImageList *imageList, int which) ;
 
     // Operations
     ////////////////////////////////////////////////////////////////////////////
@@ -345,6 +346,9 @@ protected:
     wxImageList *     m_imageListNormal; // The image list for normal icons
     wxImageList *     m_imageListSmall;  // The image list for small icons
     wxImageList *     m_imageListState;  // The image list state icons (not implemented yet)
+    bool              m_ownsImageListNormal,
+                      m_ownsImageListSmall,
+                      m_ownsImageListState;
 
     long              m_baseStyle;  // Basic Windows style flags, for recreation purposes
     wxStringList      m_stringPool; // Pool of 3 strings to satisfy Windows callback requirements
index d0603a87659a8fca35614add8f1de30483103537..b546c685a7517ce1e6a0d5215ed289123a305b3c 100644 (file)
@@ -3192,12 +3192,16 @@ wxListCtrl::wxListCtrl()
     m_imageListNormal = (wxImageList *) NULL;
     m_imageListSmall = (wxImageList *) NULL;
     m_imageListState = (wxImageList *) NULL;
+    m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE;
     m_mainWin = (wxListMainWindow*) NULL;
     m_headerWin = (wxListHeaderWindow*) NULL;
 }
 
 wxListCtrl::~wxListCtrl()
 {
+    if (m_ownsImageListNormal) delete m_imageListNormal;
+    if (m_ownsImageListSmall) delete m_imageListSmall;
+    if (m_ownsImageListState) delete m_imageListState;
 }
 
 bool wxListCtrl::Create(wxWindow *parent,
@@ -3211,6 +3215,7 @@ bool wxListCtrl::Create(wxWindow *parent,
     m_imageListNormal = (wxImageList *) NULL;
     m_imageListSmall = (wxImageList *) NULL;
     m_imageListState = (wxImageList *) NULL;
+    m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE;
     m_mainWin = (wxListMainWindow*) NULL;
     m_headerWin = (wxListHeaderWindow*) NULL;
 
@@ -3508,9 +3513,39 @@ wxImageList *wxListCtrl::GetImageList(int which) const
 
 void wxListCtrl::SetImageList( wxImageList *imageList, int which )
 {
+    if ( which == wxIMAGE_LIST_NORMAL )
+    {
+        if (m_ownsImageListNormal) delete m_imageListNormal;
+        m_imageListNormal = imageList;
+        m_ownsImageListNormal = FALSE;
+    }
+    else if ( which == wxIMAGE_LIST_SMALL )
+    {
+        if (m_ownsImageListSmall) delete m_imageListSmall;
+        m_imageListSmall = imageList;
+        m_ownsImageListSmall = FALSE;
+    }
+    else if ( which == wxIMAGE_LIST_STATE )
+    {
+        if (m_ownsImageListState) delete m_imageListState;
+        m_imageListState = imageList;
+        m_ownsImageListState = FALSE;
+    }
+
     m_mainWin->SetImageList( imageList, which );
 }
 
+void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
+{
+    SetImageList(imageList, which);
+    if ( which == wxIMAGE_LIST_NORMAL )
+        m_ownsImageListNormal = TRUE;
+    else if ( which == wxIMAGE_LIST_SMALL )
+        m_ownsImageListSmall = TRUE;
+    else if ( which == wxIMAGE_LIST_STATE )
+        m_ownsImageListState = TRUE;
+}
+
 bool wxListCtrl::Arrange( int WXUNUSED(flag) )
 {
     return 0;
index 4530fe2b4bab9e5e01ff334e449563b784a5630f..b4bd7519b7cef9c8361baa3a124eab03c575f53c 100644 (file)
@@ -130,6 +130,7 @@ void wxListCtrl::Init()
     m_imageListNormal = NULL;
     m_imageListSmall = NULL;
     m_imageListState = NULL;
+    m_ownsImageListNormal = m_ownsImageListSmall = m_ownsImageListState = FALSE;
     m_baseStyle = 0;
     m_colCount = 0;
     m_textCtrl = NULL;
@@ -284,6 +285,10 @@ wxListCtrl::~wxListCtrl()
         delete m_textCtrl;
         m_textCtrl = NULL;
     }
+    
+    if (m_ownsImageListNormal) delete m_imageListNormal;
+    if (m_ownsImageListSmall) delete m_imageListSmall;
+    if (m_ownsImageListState) delete m_imageListState;
 }
 
 // ----------------------------------------------------------------------------
@@ -912,21 +917,38 @@ void wxListCtrl::SetImageList(wxImageList *imageList, int which)
     if ( which == wxIMAGE_LIST_NORMAL )
     {
         flags = LVSIL_NORMAL;
+        if (m_ownsImageListNormal) delete m_imageListNormal;
         m_imageListNormal = imageList;
+        m_ownsImageListNormal = FALSE;
     }
     else if ( which == wxIMAGE_LIST_SMALL )
     {
         flags = LVSIL_SMALL;
+        if (m_ownsImageListSmall) delete m_imageListSmall;
         m_imageListSmall = imageList;
+        m_ownsImageListSmall = FALSE;
     }
     else if ( which == wxIMAGE_LIST_STATE )
     {
         flags = LVSIL_STATE;
+        if (m_ownsImageListState) delete m_imageListState;
         m_imageListState = imageList;
+        m_ownsImageListState = FALSE;
     }
     ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags);
 }
 
+void wxListCtrl::AssignImageList(wxImageList *imageList, int which)
+{
+    SetImageList(imageList, which);
+    if ( which == wxIMAGE_LIST_NORMAL )
+        m_ownsImageListNormal = TRUE;
+    else if ( which == wxIMAGE_LIST_SMALL )
+        m_ownsImageListSmall = TRUE;
+    else if ( which == wxIMAGE_LIST_STATE )
+        m_ownsImageListState = TRUE;
+}
+
 // ----------------------------------------------------------------------------
 // Operations
 // ----------------------------------------------------------------------------