]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/treectrl.cpp
Further attempts at WinCE media control
[wxWidgets.git] / src / msw / treectrl.cpp
index b04f9d9cc75c173fd4a1df401390d6e05efadd06..1a0cf91a8837453752022aed081e4d0233ca5540 100644 (file)
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "treectrl.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 #include "wx/dynarray.h"
 #include "wx/imaglist.h"
 #include "wx/settings.h"
 #include "wx/dynarray.h"
 #include "wx/imaglist.h"
 #include "wx/settings.h"
-#include "wx/msw/treectrl.h"
+#include "wx/treectrl.h"
 #include "wx/msw/dragimag.h"
 
 // macros to hide the cast ugliness
 // --------------------------------
 
 #include "wx/msw/dragimag.h"
 
 // macros to hide the cast ugliness
 // --------------------------------
 
-// ptr is the real item id, i.e. wxTreeItemId::m_pItem
-#define HITEM_PTR(ptr)     (HTREEITEM)(ptr)
-
-// item here is a wxTreeItemId
-#define HITEM(item)     HITEM_PTR((item).m_pItem)
+// get HTREEITEM from wxTreeItemId
+#define HITEM(item)     ((HTREEITEM)(((item).m_pItem)))
 
 // the native control doesn't support multiple selections under MSW and we
 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
 
 // the native control doesn't support multiple selections under MSW and we
 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
@@ -318,6 +311,11 @@ public:
         m_tree = tree;
     }
 
         m_tree = tree;
     }
 
+    // give it a virtual dtor: not really needed as the class is never used
+    // polymorphically and not even allocated on heap at all, but this is safer
+    // (in case it ever is) and silences the compiler warnings for now
+    virtual ~wxTreeTraversal() { }
+
     // do traverse the tree: visit all items (recursively by default) under the
     // given one; return true if all items were traversed or false if the
     // traversal was aborted because OnVisit returned false
     // do traverse the tree: visit all items (recursively by default) under the
     // given one; return true if all items were traversed or false if the
     // traversal was aborted because OnVisit returned false
@@ -613,9 +611,6 @@ bool wxTreeTraversal::Traverse(const wxTreeItemId& root, bool recursively)
 
 void wxTreeCtrl::Init()
 {
 
 void wxTreeCtrl::Init()
 {
-    m_imageListNormal = NULL;
-    m_imageListState = NULL;
-    m_ownsImageListNormal = m_ownsImageListState = false;
     m_textCtrl = NULL;
     m_hasAnyAttr = false;
     m_dragImage = NULL;
     m_textCtrl = NULL;
     m_hasAnyAttr = false;
     m_dragImage = NULL;
@@ -779,9 +774,6 @@ wxTreeCtrl::~wxTreeCtrl()
     // delete user data to prevent memory leaks
     // also deletes hidden root node storage.
     DeleteAllItems();
     // delete user data to prevent memory leaks
     // also deletes hidden root node storage.
     DeleteAllItems();
-
-    if (m_ownsImageListNormal) delete m_imageListNormal;
-    if (m_ownsImageListState) delete m_imageListState;
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------
@@ -840,22 +832,12 @@ void wxTreeCtrl::SetIndent(unsigned int indent)
     TreeView_SetIndent(GetHwnd(), indent);
 }
 
     TreeView_SetIndent(GetHwnd(), indent);
 }
 
-wxImageList *wxTreeCtrl::GetImageList() const
-{
-    return m_imageListNormal;
-}
-
-wxImageList *wxTreeCtrl::GetStateImageList() const
-{
-    return m_imageListState;
-}
-
 void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
 {
     // no error return
 void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
 {
     // no error return
-    TreeView_SetImageList(GetHwnd(),
-                          imageList ? imageList->GetHIMAGELIST() : 0,
-                          which);
+    (void) TreeView_SetImageList(GetHwnd(),
+                                 imageList ? imageList->GetHIMAGELIST() : 0,
+                                 which);
 }
 
 void wxTreeCtrl::SetImageList(wxImageList *imageList)
 }
 
 void wxTreeCtrl::SetImageList(wxImageList *imageList)
@@ -874,18 +856,6 @@ void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
     m_ownsImageListState = false;
 }
 
     m_ownsImageListState = false;
 }
 
-void wxTreeCtrl::AssignImageList(wxImageList *imageList)
-{
-    SetImageList(imageList);
-    m_ownsImageListNormal = true;
-}
-
-void wxTreeCtrl::AssignStateImageList(wxImageList *imageList)
-{
-    SetStateImageList(imageList);
-    m_ownsImageListState = true;
-}
-
 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
                                     bool recursively) const
 {
 size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
                                     bool recursively) const
 {
@@ -1636,11 +1606,11 @@ size_t wxTreeCtrl::GetSelections(wxArrayTreeItemIds& selections) const
 // Usual operations
 // ----------------------------------------------------------------------------
 
 // Usual operations
 // ----------------------------------------------------------------------------
 
-wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
-                                      wxTreeItemId hInsertAfter,
-                                      const wxString& text,
-                                      int image, int selectedImage,
-                                      wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertAfter(const wxTreeItemId& parent,
+                                       const wxTreeItemId& hInsertAfter,
+                                       const wxString& text,
+                                       int image, int selectedImage,
+                                       wxTreeItemData *data)
 {
     wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
                  wxTreeItemId(),
 {
     wxCHECK_MSG( parent.IsOk() || !TreeView_GetRoot(GetHwnd()),
                  wxTreeItemId(),
@@ -1713,20 +1683,6 @@ wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
 // for compatibility only
 #if WXWIN_COMPATIBILITY_2_4
 
 // for compatibility only
 #if WXWIN_COMPATIBILITY_2_4
 
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
-                                    const wxString& text,
-                                    int image, int selImage,
-                                    long insertAfter)
-{
-    return DoInsertItem(parent, wxTreeItemId((void *)insertAfter), text,
-                        image, selImage, NULL);
-}
-
-wxImageList *wxTreeCtrl::GetImageList(int) const
-{
-    return GetImageList();
-}
-
 void wxTreeCtrl::SetImageList(wxImageList *imageList, int)
 {
     SetImageList(imageList);
 void wxTreeCtrl::SetImageList(wxImageList *imageList, int)
 {
     SetImageList(imageList);
@@ -1757,59 +1713,40 @@ wxTreeItemId wxTreeCtrl::AddRoot(const wxString& text,
         return TVI_ROOT;
     }
 
         return TVI_ROOT;
     }
 
-    return DoInsertItem(wxTreeItemId(), wxTreeItemId(),
-                        text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::PrependItem(const wxTreeItemId& parent,
-                                     const wxString& text,
-                                     int image, int selectedImage,
-                                     wxTreeItemData *data)
-{
-    return DoInsertItem(parent, TVI_FIRST,
-                        text, image, selectedImage, data);
+    return DoInsertAfter(wxTreeItemId(), wxTreeItemId(),
+                           text, image, selectedImage, data);
 }
 
 }
 
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
-                                    const wxTreeItemId& idPrevious,
-                                    const wxString& text,
-                                    int image, int selectedImage,
-                                    wxTreeItemData *data)
-{
-    return DoInsertItem(parent, idPrevious, text, image, selectedImage, data);
-}
-
-wxTreeItemId wxTreeCtrl::InsertItem(const wxTreeItemId& parent,
-                                    size_t index,
-                                    const wxString& text,
-                                    int image, int selectedImage,
-                                    wxTreeItemData *data)
+wxTreeItemId wxTreeCtrl::DoInsertItem(const wxTreeItemId& parent,
+                                      size_t index,
+                                      const wxString& text,
+                                      int image, int selectedImage,
+                                      wxTreeItemData *data)
 {
 {
-    // find the item from index
-    wxTreeItemIdValue cookie;
-    wxTreeItemId idPrev, idCur = GetFirstChild(parent, cookie);
-    while ( index != 0 && idCur.IsOk() )
+    wxTreeItemId idPrev;
+    if ( index == (size_t)-1 )
     {
     {
-        index--;
-
-        idPrev = idCur;
-        idCur = GetNextChild(parent, cookie);
+        // special value: append to the end
+        idPrev = TVI_LAST;
     }
     }
+    else // find the item from index
+    {
+        wxTreeItemIdValue cookie;
+        wxTreeItemId idCur = GetFirstChild(parent, cookie);
+        while ( index != 0 && idCur.IsOk() )
+        {
+            index--;
 
 
-    // assert, not check: if the index is invalid, we will append the item
-    // to the end
-    wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+            idPrev = idCur;
+            idCur = GetNextChild(parent, cookie);
+        }
 
 
-    return DoInsertItem(parent, idPrev, text, image, selectedImage, data);
-}
+        // assert, not check: if the index is invalid, we will append the item
+        // to the end
+        wxASSERT_MSG( index == 0, _T("bad index in wxTreeCtrl::InsertItem") );
+    }
 
 
-wxTreeItemId wxTreeCtrl::AppendItem(const wxTreeItemId& parent,
-                                    const wxString& text,
-                                    int image, int selectedImage,
-                                    wxTreeItemData *data)
-{
-    return DoInsertItem(parent, TVI_LAST,
-                        text, image, selectedImage, data);
+    return DoInsertAfter(parent, idPrev, text, image, selectedImage, data);
 }
 
 void wxTreeCtrl::Delete(const wxTreeItemId& item)
 }
 
 void wxTreeCtrl::Delete(const wxTreeItemId& item)
@@ -1837,7 +1774,7 @@ void wxTreeCtrl::DeleteChildren(const wxTreeItemId& item)
     size_t nCount = children.Count();
     for ( size_t n = 0; n < nCount; n++ )
     {
     size_t nCount = children.Count();
     for ( size_t n = 0; n < nCount; n++ )
     {
-        if ( !TreeView_DeleteItem(GetHwnd(), HITEM_PTR(children[n])) )
+        if ( !TreeView_DeleteItem(GetHwnd(), HITEM(children[n])) )
         {
             wxLogLastError(wxT("TreeView_DeleteItem"));
         }
         {
             wxLogLastError(wxT("TreeView_DeleteItem"));
         }
@@ -1949,9 +1886,9 @@ void wxTreeCtrl::UnselectAll()
         for ( size_t n = 0; n < count; n++ )
         {
 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
         for ( size_t n = 0; n < count; n++ )
         {
 #if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
-            SetItemCheck(HITEM_PTR(selections[n]), false);
+            SetItemCheck(HITEM(selections[n]), false);
 #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
 #else // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
-            ::UnselectItem(GetHwnd(), HITEM_PTR(selections[n]));
+            ::UnselectItem(GetHwnd(), HITEM(selections[n]));
 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
         }
 
 #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE/!wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
         }
 
@@ -2005,16 +1942,6 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
     }
 }
 
     }
 }
 
-void wxTreeCtrl::UnselectItem(const wxTreeItemId& item)
-{
-    SelectItem(item, false);
-}
-
-void wxTreeCtrl::ToggleItemSelection(const wxTreeItemId& item)
-{
-    SelectItem(item, !IsSelected(item));
-}
-
 void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
 {
     // no error return
 void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
 {
     // no error return
@@ -2087,13 +2014,13 @@ void wxTreeCtrl::DoEndEditLabel(bool discardChanges)
     DeleteTextCtrl();
 }
 
     DeleteTextCtrl();
 }
 
-wxTreeItemId wxTreeCtrl::HitTest(const wxPoint& point, int& flags)
+wxTreeItemId wxTreeCtrl::DoTreeHitTest(const wxPoint& point, int& flags)
 {
     TV_HITTESTINFO hitTestInfo;
     hitTestInfo.pt.x = (int)point.x;
     hitTestInfo.pt.y = (int)point.y;
 
 {
     TV_HITTESTINFO hitTestInfo;
     hitTestInfo.pt.x = (int)point.x;
     hitTestInfo.pt.y = (int)point.y;
 
-    TreeView_HitTest(GetHwnd(), &hitTestInfo);
+    (void) TreeView_HitTest(GetHwnd(), &hitTestInfo);
 
     flags = 0;
 
 
     flags = 0;
 
@@ -2181,12 +2108,6 @@ int CALLBACK wxTreeSortHelper::Compare(LPARAM pItem1,
                                 GetIdFromData(tree, pItem2));
 }
 
                                 GetIdFromData(tree, pItem2));
 }
 
-int wxTreeCtrl::OnCompareItems(const wxTreeItemId& item1,
-                               const wxTreeItemId& item2)
-{
-    return wxStrcmp(GetItemText(item1), GetItemText(item2));
-}
-
 void wxTreeCtrl::SortChildren(const wxTreeItemId& item)
 {
     wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
 void wxTreeCtrl::SortChildren(const wxTreeItemId& item)
 {
     wxCHECK_RET( item.IsOk(), wxT("invalid tree item") );
@@ -2289,12 +2210,12 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
         int x = GET_X_LPARAM(lParam),
             y = GET_Y_LPARAM(lParam);
         HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y);
         int x = GET_X_LPARAM(lParam),
             y = GET_Y_LPARAM(lParam);
         HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y);
-        
+
         TV_HITTESTINFO tvht;
         tvht.pt.x = x;
         tvht.pt.y = y;
         TV_HITTESTINFO tvht;
         tvht.pt.x = x;
         tvht.pt.y = y;
-    
-        TreeView_HitTest(GetHwnd(), &tvht);
+
+        (void) TreeView_HitTest(GetHwnd(), &tvht);
 
         switch ( nMsg )
         {
 
         switch ( nMsg )
         {
@@ -2319,7 +2240,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                 {
                     m_htClickedItem = (WXHTREEITEM) htItem;
                     m_ptClick = wxPoint(x, y);
                 {
                     m_htClickedItem = (WXHTREEITEM) htItem;
                     m_ptClick = wxPoint(x, y);
-                    
+
                     if ( wParam & MK_CONTROL )
                     {
                         SetFocus();
                     if ( wParam & MK_CONTROL )
                     {
                         SetFocus();
@@ -2359,14 +2280,14 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                     {
                         // avoid doing anything if we click on the only
                         // currently selected item
                     {
                         // avoid doing anything if we click on the only
                         // currently selected item
-                        
+
                         SetFocus();
 
                         wxArrayTreeItemIds selections;
                         size_t count = GetSelections(selections);
                         if ( count == 0 ||
                              count > 1 ||
                         SetFocus();
 
                         wxArrayTreeItemIds selections;
                         size_t count = GetSelections(selections);
                         if ( count == 0 ||
                              count > 1 ||
-                             HITEM_PTR(selections[0]) != htItem )
+                             HITEM(selections[0]) != htItem )
                         {
                             // clear the previously selected items, if the
                             // user clicked outside of the present selection.
                         {
                             // clear the previously selected items, if the
                             // user clicked outside of the present selection.
@@ -2413,29 +2334,29 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
                             tv.hdr.hwndFrom = GetHwnd();
                             tv.hdr.idFrom = ::GetWindowLong( GetHwnd(), GWL_ID );
                             tv.hdr.code = TVN_BEGINDRAG;
                             tv.hdr.hwndFrom = GetHwnd();
                             tv.hdr.idFrom = ::GetWindowLong( GetHwnd(), GWL_ID );
                             tv.hdr.code = TVN_BEGINDRAG;
-            
+
                             tv.itemNew.hItem = HITEM(m_htClickedItem);
                             tv.itemNew.hItem = HITEM(m_htClickedItem);
-                            
+
                             TVITEM tviAux;
                             ZeroMemory(&tviAux, sizeof(tviAux));
                             tviAux.hItem = HITEM(m_htClickedItem);
                             tviAux.mask = TVIF_STATE | TVIF_PARAM;
                             tviAux.stateMask = 0xffffffff;
                             TreeView_GetItem( GetHwnd(), &tviAux );
                             TVITEM tviAux;
                             ZeroMemory(&tviAux, sizeof(tviAux));
                             tviAux.hItem = HITEM(m_htClickedItem);
                             tviAux.mask = TVIF_STATE | TVIF_PARAM;
                             tviAux.stateMask = 0xffffffff;
                             TreeView_GetItem( GetHwnd(), &tviAux );
-                            
+
                             tv.itemNew.state = tviAux.state;
                             tv.itemNew.lParam = tviAux.lParam;
                             tv.itemNew.state = tviAux.state;
                             tv.itemNew.lParam = tviAux.lParam;
-            
+
                             tv.ptDrag.x = x;
                             tv.ptDrag.y = y;
                             tv.ptDrag.x = x;
                             tv.ptDrag.y = y;
-            
+
                             ::SendMessage( pWnd, WM_NOTIFY, tv.hdr.idFrom, (LPARAM)&tv );
                         }
                         m_htClickedItem.Unset();
                     }
                 }
 #endif // __WXWINCE__
                             ::SendMessage( pWnd, WM_NOTIFY, tv.hdr.idFrom, (LPARAM)&tv );
                         }
                         m_htClickedItem.Unset();
                     }
                 }
 #endif // __WXWINCE__
-                
+
                 if ( m_dragImage )
                 {
                     m_dragImage->Move(wxPoint(x, y));
                 if ( m_dragImage )
                 {
                     m_dragImage->Move(wxPoint(x, y));
@@ -2508,7 +2429,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
         {
             // TreeView_GetItemRect() will return false if item is not visible,
             // which may happen perfectly well
         {
             // TreeView_GetItemRect() will return false if item is not visible,
             // which may happen perfectly well
-            if ( TreeView_GetItemRect(GetHwnd(), HITEM_PTR(selections[n]),
+            if ( TreeView_GetItemRect(GetHwnd(), HITEM(selections[n]),
                                       &rect, TRUE) )
             {
                 ::InvalidateRect(GetHwnd(), &rect, FALSE);
                                       &rect, TRUE) )
             {
                 ::InvalidateRect(GetHwnd(), &rect, FALSE);
@@ -3230,14 +3151,4 @@ int wxTreeCtrl::GetState(const wxTreeItemId& node)
     return STATEIMAGEMASKTOINDEX(tvi.state);
 }
 
     return STATEIMAGEMASKTOINDEX(tvi.state);
 }
 
-#if WXWIN_COMPATIBILITY_2_2
-
-wxTreeItemId wxTreeCtrl::GetParent(const wxTreeItemId& item) const
-{
-    return GetItemParent( item );
-}
-
-#endif  // WXWIN_COMPATIBILITY_2_2
-
 #endif // wxUSE_TREECTRL
 #endif // wxUSE_TREECTRL
-