diff --git a/include/wx/generic/listctrl.h b/include/wx/generic/listctrl.h index 48949dac07..5c752446bf 100644 --- a/include/wx/generic/listctrl.h +++ b/include/wx/generic/listctrl.h @@ -119,9 +119,6 @@ public: void SetWindowStyleFlag( long style ) wxOVERRIDE; void RecreateWindow() {} long GetNextItem( long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE ) const; - wxImageList *GetImageList( int which ) const wxOVERRIDE; - void SetImageList( wxImageList *imageList, int which ) wxOVERRIDE; - void AssignImageList( wxImageList *imageList, int which ) wxOVERRIDE; bool Arrange( int flag = wxLIST_ALIGN_DEFAULT ); // always wxLIST_ALIGN_LEFT in wxGLC void ClearAll(); @@ -209,19 +206,13 @@ public: // implementation // -------------- - 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; protected: // Implement base class pure virtual methods. long DoInsertColumn(long col, const wxListItem& info) wxOVERRIDE; - + void DoSetImageList(wxImageList *imageList, int which) wxOVERRIDE; virtual wxSize DoGetBestClientSize() const wxOVERRIDE; diff --git a/include/wx/listbase.h b/include/wx/listbase.h index 677e16a29c..90eb31a90c 100644 --- a/include/wx/listbase.h +++ b/include/wx/listbase.h @@ -333,7 +333,8 @@ private: class WXDLLIMPEXP_CORE wxListCtrlBase : public wxSystemThemedControl { public: - wxListCtrlBase() { } + wxListCtrlBase(); + virtual ~wxListCtrlBase(); // Image list methods. // ------------------- @@ -344,14 +345,14 @@ public: // is destroyed. // // The value of "which" must be one of wxIMAGE_LIST_{NORMAL,SMALL,STATE}. - virtual void AssignImageList(wxImageList* imageList, int which) = 0; + virtual void AssignImageList(wxImageList* imageList, int which); // Same as AssignImageList() but the control does not delete the image list // so it can be shared among several controls. - virtual void SetImageList(wxImageList* imageList, int which) = 0; + virtual void SetImageList(wxImageList* imageList, int which); // Return the currently used image list, may be NULL. - virtual wxImageList* GetImageList(int which) const = 0; + virtual wxImageList* GetImageList(int which) const; // Column-related methods. @@ -440,6 +441,7 @@ public: protected: // Real implementations methods to which our public forwards. virtual long DoInsertColumn(long col, const wxListItem& info) = 0; + virtual void DoSetImageList(wxImageList *imageList, int which) = 0; // Overridden methods of the base class. virtual wxSize DoGetBestClientSize() const wxOVERRIDE; @@ -468,6 +470,13 @@ protected: virtual wxItemAttr* OnGetItemColumnAttr(long item, long column) const; private: + 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; + // user defined color to draw row lines, may be invalid wxItemAttr m_alternateRowColour; }; diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index cb5e16a2fe..882a6ceb74 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -250,13 +250,6 @@ public: // Returns the item or -1 if unsuccessful. long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const; - // Gets one of the three image lists - wxImageList *GetImageList(int which) const wxOVERRIDE; - - // Sets the image list - void SetImageList(wxImageList *imageList, int which) wxOVERRIDE; - void AssignImageList(wxImageList *imageList, int which) wxOVERRIDE; - // refresh items selectively (only useful for virtual list controls) void RefreshItem(long item); void RefreshItems(long itemFrom, long itemTo); @@ -407,6 +400,7 @@ protected: // Implement base class pure virtual methods. long DoInsertColumn(long col, const wxListItem& info) wxOVERRIDE; + void DoSetImageList(wxImageList *imageList, int which) wxOVERRIDE; // free memory taken by all internal data void FreeAllInternalData(); @@ -420,12 +414,6 @@ protected: wxTextCtrl* m_textCtrl; // The control used for editing a label - 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; int m_colCount; // Windows doesn't have GetColumnCount so must // keep track of inserted/deleted columns diff --git a/include/wx/qt/listctrl.h b/include/wx/qt/listctrl.h index 34a5eba779..25ddaa39a7 100644 --- a/include/wx/qt/listctrl.h +++ b/include/wx/qt/listctrl.h @@ -14,8 +14,6 @@ class wxQtListTreeWidget; class wxQtListModel; class wxQtVirtualListModel; -class WXDLLIMPEXP_FWD_CORE wxImageList; - class WXDLLIMPEXP_CORE wxListCtrl: public wxListCtrlBase { public: @@ -177,13 +175,6 @@ public: // Returns the item or -1 if unsuccessful. long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const; - // Gets one of the three image lists - wxImageList *GetImageList(int which) const wxOVERRIDE; - - // Sets the image list - void SetImageList(wxImageList *imageList, int which) wxOVERRIDE; - void AssignImageList(wxImageList *imageList, int which) wxOVERRIDE; - // refresh items selectively (only useful for virtual list controls) void RefreshItem(long item); void RefreshItems(long itemFrom, long itemTo); @@ -278,13 +269,8 @@ protected: // Implement base class pure virtual methods. virtual long DoInsertColumn(long col, const wxListItem& info) wxOVERRIDE; + void DoSetImageList(wxImageList *imageList, int which) wxOVERRIDE; - 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; bool m_hasCheckBoxes; private: diff --git a/src/common/listctrlcmn.cpp b/src/common/listctrlcmn.cpp index 4ff89fd097..f6ff500a5e 100644 --- a/src/common/listctrlcmn.cpp +++ b/src/common/listctrlcmn.cpp @@ -135,6 +135,26 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxListEvent, wxNotifyEvent); // wxListCtrlBase implementation // ---------------------------------------------------------------------------- +wxListCtrlBase::wxListCtrlBase() +{ + m_imageListNormal = + m_imageListSmall = + m_imageListState = NULL; + m_ownsImageListNormal = + m_ownsImageListSmall = + m_ownsImageListState = false; +} + +wxListCtrlBase::~wxListCtrlBase() +{ + if (m_ownsImageListNormal) + delete m_imageListNormal; + if (m_ownsImageListSmall) + delete m_imageListSmall; + if (m_ownsImageListState) + delete m_imageListState; +} + long wxListCtrlBase::AppendColumn(const wxString& heading, wxListColumnFormat format, @@ -288,4 +308,66 @@ wxItemAttr* wxListCtrlBase::OnGetItemColumnAttr(long item, long WXUNUSED(column) return OnGetItemAttr(item); } +// ---------------------------------------------------------------------------- +// Images support +// ---------------------------------------------------------------------------- + +wxImageList *wxListCtrlBase::GetImageList(int which) const +{ + if ( which == wxIMAGE_LIST_NORMAL ) + { + return m_imageListNormal; + } + else if ( which == wxIMAGE_LIST_SMALL ) + { + return m_imageListSmall; + } + else if ( which == wxIMAGE_LIST_STATE ) + { + return m_imageListState; + } + return NULL; +} + +void wxListCtrlBase::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; + } + else + { + wxFAIL_MSG("unknown image list"); + return; + } + + // Actually update the images shown in the control. + DoSetImageList(imageList, which); +} + +void wxListCtrlBase::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; +} + #endif // wxUSE_LISTCTRL diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 5d8023f6b3..2cd65838bb 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -4887,26 +4887,12 @@ wxEND_EVENT_TABLE() void wxGenericListCtrl::Init() { - m_imageListNormal = NULL; - m_imageListSmall = NULL; - m_imageListState = NULL; - - m_ownsImageListNormal = - m_ownsImageListSmall = - m_ownsImageListState = false; - m_mainWin = NULL; m_headerWin = NULL; } wxGenericListCtrl::~wxGenericListCtrl() { - if (m_ownsImageListNormal) - delete m_imageListNormal; - if (m_ownsImageListSmall) - delete m_imageListSmall; - if (m_ownsImageListState) - delete m_imageListState; } void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded() @@ -5416,56 +5402,11 @@ long wxGenericListCtrl::GetNextItem( long item, int geom, int state ) const return m_mainWin->GetNextItem( item, geom, state ); } -wxImageList *wxGenericListCtrl::GetImageList(int which) const +void wxGenericListCtrl::DoSetImageList( wxImageList *imageList, int which ) { - if (which == wxIMAGE_LIST_NORMAL) - return m_imageListNormal; - else if (which == wxIMAGE_LIST_SMALL) - return m_imageListSmall; - else if (which == wxIMAGE_LIST_STATE) - return m_imageListState; - - return NULL; -} - -void wxGenericListCtrl::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 wxGenericListCtrl::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 wxGenericListCtrl::Arrange( int WXUNUSED(flag) ) { return 0; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 6861baa1f3..8078adf6ba 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -275,13 +275,6 @@ wxEND_EVENT_TABLE() void wxListCtrl::Init() { - m_imageListNormal = - m_imageListSmall = - m_imageListState = NULL; - m_ownsImageListNormal = - m_ownsImageListSmall = - m_ownsImageListState = false; - m_colCount = 0; m_textCtrl = NULL; @@ -322,12 +315,12 @@ bool wxListCtrl::Create(wxWindow *parent, // If SetImageList() had been called before the control was created, take // it into account now. - if ( m_imageListNormal ) - ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListNormal), LVSIL_NORMAL); - if ( m_imageListSmall ) - ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListSmall), LVSIL_SMALL); - if ( m_imageListState ) - ListView_SetImageList(GetHwnd(), GetHimagelistOf(m_imageListState), LVSIL_STATE); + if ( wxImageList* const iml = GetImageList(wxIMAGE_LIST_NORMAL) ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(iml), LVSIL_NORMAL); + if ( wxImageList* const iml = GetImageList(wxIMAGE_LIST_SMALL) ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(iml), LVSIL_SMALL); + if ( wxImageList* const iml = GetImageList(wxIMAGE_LIST_STATE) ) + ListView_SetImageList(GetHwnd(), GetHimagelistOf(iml), LVSIL_STATE); return true; } @@ -536,13 +529,6 @@ wxListCtrl::~wxListCtrl() DeleteEditControl(); - if (m_ownsImageListNormal) - delete m_imageListNormal; - if (m_ownsImageListSmall) - delete m_imageListSmall; - if (m_ownsImageListState) - delete m_imageListState; - delete m_headerCustomDraw; } @@ -1523,54 +1509,34 @@ long wxListCtrl::GetNextItem(long item, int geom, int state) const } -wxImageList *wxListCtrl::GetImageList(int which) const +void wxListCtrl::DoSetImageList(wxImageList *imageList, int which) { - if ( which == wxIMAGE_LIST_NORMAL ) - { - return m_imageListNormal; - } - else if ( which == wxIMAGE_LIST_SMALL ) - { - return m_imageListSmall; - } - else if ( which == wxIMAGE_LIST_STATE ) - { - return m_imageListState; - } - return NULL; -} - -void wxListCtrl::SetImageList(wxImageList *imageList, int which) -{ - int flags = 0; - 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; - } - // It's possible that this function is called before the control is // created, don't do anything else in this case -- the image list will be // really set after creating it. if ( !GetHwnd() ) return; + int flags; + switch ( which ) + { + case wxIMAGE_LIST_NORMAL: + flags = LVSIL_NORMAL; + break; + + case wxIMAGE_LIST_SMALL: + flags = LVSIL_SMALL; + break; + + case wxIMAGE_LIST_STATE: + flags = LVSIL_STATE; + break; + + default: + wxFAIL_MSG("invalid image list"); + return; + } + (void) ListView_SetImageList(GetHwnd(), (HIMAGELIST) imageList ? imageList->GetHIMAGELIST() : 0, flags); // For ComCtl32 prior 6.0 we need to re-assign all existing @@ -1586,17 +1552,6 @@ void wxListCtrl::SetImageList(wxImageList *imageList, int 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; -} - // ---------------------------------------------------------------------------- // Geometry // ---------------------------------------------------------------------------- diff --git a/src/qt/listctrl.cpp b/src/qt/listctrl.cpp index c529640cdc..f06292f7cb 100644 --- a/src/qt/listctrl.cpp +++ b/src/qt/listctrl.cpp @@ -1083,28 +1083,11 @@ void wxListCtrl::Init() { m_hasCheckBoxes = false; m_model = NULL; - m_imageListNormal = NULL; - m_ownsImageListNormal = false; - m_imageListSmall = NULL; - m_ownsImageListSmall = false; - m_imageListState = NULL; - m_ownsImageListState = false; m_qtTreeWidget = NULL; } wxListCtrl::~wxListCtrl() { - if ( m_ownsImageListNormal ) - delete m_imageListNormal; - if ( m_ownsImageListSmall ) - delete m_imageListSmall; - if ( m_ownsImageListState ) - delete m_imageListState; - - m_imageListNormal = NULL; - m_imageListSmall = NULL; - m_imageListState = NULL; - m_qtTreeWidget->setModel(NULL); m_model->deleteLater(); } @@ -1551,58 +1534,9 @@ long wxListCtrl::GetNextItem(long item, int WXUNUSED(geometry), int state) const return -1; } -wxImageList *wxListCtrl::GetImageList(int which) const +void wxListCtrl::DoSetImageList(wxImageList* WXUNUSED(imageList), int WXUNUSED(which)) { - if ( which == wxIMAGE_LIST_NORMAL ) - { - return m_imageListNormal; - } - else if ( which == wxIMAGE_LIST_SMALL ) - { - return m_imageListSmall; - } - else if ( which == wxIMAGE_LIST_STATE ) - { - return m_imageListState; - } - return NULL; -} - - -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; - } -} - -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; + // TODO: Ensure the icons are actually updated. } void wxListCtrl::RefreshItem(long item)