]> git.saurik.com Git - wxWidgets.git/commitdiff
added state image support (patch 530155)
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 10 Jul 2003 11:16:34 +0000 (11:16 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 10 Jul 2003 11:16:34 +0000 (11:16 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21852 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/treectrl.h
src/msw/treectrl.cpp

index 2d2e4ff563ff62e6f1612bd3045ed2d9257e0fec..07be1b67ba2918861726db8129552d97b9b18a2d 100644 (file)
@@ -414,6 +414,10 @@ public:
     bool IsItemChecked(const wxTreeItemId& item) const;
     void SetItemCheck(const wxTreeItemId& item, bool check = TRUE);
 
+    // set/get the item state.image (state == -1 means cycle to the next one)
+    void SetState(const wxTreeItemId& node, int state);
+    int GetState(const wxTreeItemId& node);
+
 protected:
     // SetImageList helper
     void SetAnyImageList(wxImageList *imageList, int which);
index d49421936040278e84e6797b8e1beacd50b4f1e2..74fbf339be60c699ebd2096ce3350a5f8b8287d6 100644 (file)
@@ -795,7 +795,7 @@ wxImageList *wxTreeCtrl::GetImageList() const
 
 wxImageList *wxTreeCtrl::GetStateImageList() const
 {
-    return m_imageListNormal;
+    return m_imageListState;
 }
 
 void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
@@ -2582,6 +2582,23 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
             return true;
 #endif // _WIN32_IE >= 0x300
 
+        case NM_CLICK:
+            {
+                DWORD pos = GetMessagePos();
+                POINT point;
+                point.x = LOWORD(pos);
+                point.y = HIWORD(pos);
+                ::MapWindowPoints(HWND_DESKTOP, GetHwnd(), &point, 1);
+                int flags = 0;
+                wxTreeItemId item = HitTest(wxPoint(point.x, point.y), flags);
+                if (flags & wxTREE_HITTEST_ONITEMSTATEICON)
+                {
+                    event.m_item = item;
+                    eventType = wxEVT_COMMAND_TREE_STATE_IMAGE_CLICK;
+                }
+                break;
+            }
+
         case NM_DBLCLK:
         case NM_RCLICK:
             {
@@ -2768,6 +2785,50 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
     return processed;
 }
 
+// ----------------------------------------------------------------------------
+// State control.
+// ----------------------------------------------------------------------------
+
+// why do they define INDEXTOSTATEIMAGEMASK but not the inverse?
+#define STATEIMAGEMASKTOINDEX(state) (((state) & TVIS_STATEIMAGEMASK) >> 12)
+
+void wxTreeCtrl::SetState(const wxTreeItemId& node, int state)
+{
+    TV_ITEM tvi;
+    tvi.hItem = (HTREEITEM)node.m_pItem;
+    tvi.mask = TVIF_STATE;
+    tvi.stateMask = TVIS_STATEIMAGEMASK;
+
+    // Select the specified state, or -1 == cycle to the next one.
+    if ( state == -1 )
+    {
+        TreeView_GetItem(GetHwnd(), &tvi); 
+
+        state = STATEIMAGEMASKTOINDEX(tvi.state) + 1;
+        if ( state == m_imageListState->GetImageCount() )
+            state = 1;
+    }
+
+    wxCHECK_RET( state < m_imageListState->GetImageCount(),
+                 _T("wxTreeCtrl::SetState(): item index out of bounds") );
+
+    tvi.state = INDEXTOSTATEIMAGEMASK(state); 
+
+    TreeView_SetItem(GetHwnd(), &tvi);
+}
+
+int wxTreeCtrl::GetState(const wxTreeItemId& node)
+{
+    TV_ITEM tvi;
+    tvi.hItem = (HTREEITEM)node.m_pItem;
+    tvi.mask = TVIF_STATE;
+    tvi.stateMask = TVIS_STATEIMAGEMASK;
+    TreeView_GetItem(GetHwnd(), &tvi); 
+
+    return STATEIMAGEMASKTOINDEX(tvi.state);
+}
+
 #endif // __WIN95__
 
 #endif // wxUSE_TREECTRL
+