]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/treectrl.cpp
Swap client data pointers in wxRearrangeList too.
[wxWidgets.git] / src / os2 / treectrl.cpp
index ca250c5c162be802c4909d791d0f5b07f56f9be9..ab60bc7c09bd557d478644c97a035096f33388fe 100644 (file)
@@ -1,12 +1,12 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/msw/treectrl.cpp
+// Name:        src/os2/treectrl.cpp
 // Purpose:     wxTreeCtrl
 // Author:      Julian Smart
 // Modified by: Vadim Zeitlin to be less MSW-specific on 10.10.98
 // Created:     1997
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
-// Licence:     wxWidgets licence
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // ============================================================================
 // headers
 // ----------------------------------------------------------------------------
 
-#ifdef __GNUG__
-    #pragma implementation "treectrl.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
 
 #if wxUSE_TREECTRL
 
+#include "wx/treectrl.h"
+
+#ifndef WX_PRECOMP
+    #include "wx/dynarray.h"
+    #include "wx/log.h"
+    #include "wx/app.h"
+    #include "wx/settings.h"
+#endif
+
 #include "wx/os2/private.h"
 
-#include "wx/app.h"
-#include "wx/log.h"
-#include "wx/dynarray.h"
 #include "wx/imaglist.h"
-#include "wx/settings.h"
-#include "wx/os2/treectrl.h"
 
 // a macro to hide the ugliness of nested casts
 #define HITEM(item)     (HTREEITEM)(WXHTREEITEM)(item)
@@ -80,11 +80,7 @@ public:
     wxTreeItemInternalData() {}
     ~wxTreeItemInternalData()
     {
-        if(m_pAttr)
-        {
-            delete m_pAttr;
-            m_pAttr = NULL;
-        }
+        wxDELETE(m_pAttr);
     }
 
     wxTreeItemAttr*                 m_pAttr;
@@ -160,16 +156,16 @@ public:
 
     //
     // 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
+    // given one; return true if all items were traversed or false if the
+    // traversal was aborted because OnVisit returned false
     //
     bool DoTraverse( const wxTreeItemId& rRoot
-                    ,bool                bRecursively = TRUE
+                    ,bool                bRecursively = true
                    );
 
     //
     // Override this function to do whatever is needed for each item, return
-    // FALSE to stop traversing
+    // false to stop traversing
     //
     virtual bool OnVisit(const wxTreeItemId& rItem) = 0;
 
@@ -182,7 +178,7 @@ private:
                  );
 
     const wxTreeCtrl*               m_pTree;
-    DECLARE_NO_COPY_CLASS(wxTreeTraversal)
+    wxDECLARE_NO_COPY_CLASS(wxTreeTraversal);
 }; // end of CLASS wxTreeTraversal
 
 //
@@ -208,16 +204,16 @@ public:
         //
         if ((GetTree()->GetRootItem() == rItem) && (GetTree()->GetWindowStyle() & wxTR_HIDE_ROOT))
         {
-            return TRUE;
+            return true;
         }
-        PMYRECORD                   pRecord = FindOS2TreeRecordByID( GetTree()->GetHWND()
+        PMYRECORD                   pRecord = FindOS2TreeRecordByID( (HWND)GetTree()->GetHWND()
                                                                     ,rItem.m_pItem
                                                                    );
         if (pRecord->m_vRecord.flRecordAttr & CRA_SELECTED)
         {
             m_aSelections.Add(rItem);
         }
-        return TRUE;
+        return true;
     }
 
     size_t GetCount(void) const { return m_aSelections.GetCount(); }
@@ -245,7 +241,7 @@ public:
     virtual bool OnVisit(const wxTreeItemId& WXUNUSED(rItem))
     {
         m_nCount++;
-        return TRUE;
+        return true;
     }
 
     size_t GetCount(void) const { return m_nCount; }
@@ -306,7 +302,7 @@ bool wxTreeTraversal::DoTraverse (
 )
 {
     if (!OnVisit(rRoot))
-        return FALSE;
+        return false;
 
     return Traverse( rRoot
                     ,bRecursively
@@ -327,15 +323,15 @@ bool wxTreeTraversal::Traverse (
         //
         // Depth first traversal
         //
-        if (bRecursively && !Traverse(vChild, TRUE))
-            return FALSE;
+        if (bRecursively && !Traverse(vChild, true))
+            return false;
         if (!OnVisit(vChild))
-            return FALSE;
+            return false;
         vChild = m_pTree->GetNextChild( rRoot
                                        ,lCookie
                                       );
     }
-    return TRUE;
+    return true;
 } // end of wxTreeTraversal::Traverse
 
 // ----------------------------------------------------------------------------
@@ -346,9 +342,9 @@ void wxTreeCtrl::Init ()
 {
     m_pImageListNormal     = NULL;
     m_pImageListState      = NULL;
-    m_bOwnsImageListNormal = FALSE;
-    m_bOwnsImageListState  = FALSE;
-    m_bHasAnyAttr          = FALSE;
+    m_bOwnsImageListNormal = false;
+    m_bOwnsImageListState  = false;
+    m_bHasAnyAttr          = false;
     m_pDragImage           = NULL;
 
     //
@@ -382,7 +378,7 @@ bool wxTreeCtrl::Create (
                        ,rValidator
                        ,rsName
                       ))
-        return FALSE;
+        return false;
 
     DWORD                           dwStyle = WS_VISIBLE | WS_TABSTOP;
 
@@ -393,7 +389,7 @@ bool wxTreeCtrl::Create (
     if (!OS2CreateControl( "CONTAINER"
                           ,dwStyle
                          ))
-        return FALSE;
+        return false;
 
     //
     // Now set the display attributes to show a TREE/ICON view of the
@@ -426,7 +422,7 @@ bool wxTreeCtrl::Create (
             ,rSize.x
             ,rSize.y
            );
-    return TRUE;
+    return true;
 } // end of wxTreeCtrl::Create
 
 wxTreeCtrl::~wxTreeCtrl ()
@@ -440,7 +436,7 @@ wxTreeCtrl::~wxTreeCtrl ()
         {
             delete (wxTreeItemAttr *)pNode->Data();
         }
-        m_bHasAnyAttr = FALSE;
+        m_bHasAnyAttr = false;
     }
     DeleteTextCtrl();
 
@@ -474,9 +470,9 @@ bool wxTreeCtrl::DoGetItem (
     if (!pRecord)
     {
         wxLogLastError(wxT("Item not obtained"));
-        return FALSE;
+        return false;
     }
-    return TRUE;
+    return true;
 } // end of wxTreeCtrl::DoGetItem
 
 void wxTreeCtrl::DoSetItem (
@@ -496,16 +492,17 @@ void wxTreeCtrl::DoSetItem (
     }
 } // end of wxTreeCtrl::DoSetItem
 
-size_t wxTreeCtrl::GetCount () const
+unsigned int wxTreeCtrl::GetCount () const
 {
-    CNRINFO                         vCnrInfo;
+    CNRINFO  vCnrInfo;
 
     ::WinSendMsg( GetHWND()
                  ,CM_QUERYCNRINFO
                  ,MPFROMP(&vCnrInfo)
                  ,(MPARAM)(USHORT)sizeof(CNRINFO)
                 );
-    return (size_t)vCnrInfo.cRecords;
+
+    return (unsigned int)vCnrInfo.cRecords;
 } // end of wxTreeCtrl::GetCount
 
 unsigned int wxTreeCtrl::GetIndent () const
@@ -553,7 +550,7 @@ wxImageList* wxTreeCtrl::GetStateImageList () const
 // The SETS of imagelists really do nothing under OS2 as a RECORDCORE
 // struct has the icon imbedded in it that it uses for the icon being
 // displayed via the TREEITEMDESC member.  Provided for interface
-// compatability only
+// compatibility only
 //
 void wxTreeCtrl::SetAnyImageList (
   wxImageList*                      WXUNUSED(pImageList)
@@ -568,7 +565,7 @@ void wxTreeCtrl::SetImageList (
 {
     if (m_bOwnsImageListNormal)
         delete m_pImageListNormal;
-    m_bOwnsImageListNormal = FALSE;
+    m_bOwnsImageListNormal = false;
 } // end of wxTreeCtrl::SetImageList
 
 void wxTreeCtrl::SetStateImageList (
@@ -577,21 +574,21 @@ void wxTreeCtrl::SetStateImageList (
 {
     if (m_bOwnsImageListState)
         delete m_pImageListState;
-    m_bOwnsImageListState = FALSE;
+    m_bOwnsImageListState = false;
 } // end of wxTreeCtrl::SetStateImageList
 
 void wxTreeCtrl::AssignImageList (
   wxImageList*                      WXUNUSED(pImageList)
 )
 {
-    m_bOwnsImageListNormal = TRUE;
+    m_bOwnsImageListNormal = true;
 } // end of wxTreeCtrl::AssignImageList
 
 void wxTreeCtrl::AssignStateImageList (
   wxImageList*                      WXUNUSED(pImageList)
 )
 {
-    m_bOwnsImageListState = TRUE;
+    m_bOwnsImageListState = true;
 } // end of wxTreeCtrl::AssignStateImageList
 
 size_t wxTreeCtrl::GetChildrenCount (
@@ -617,13 +614,13 @@ bool wxTreeCtrl::SetBackgroundColour (
     ULONG                           ulColor = wxColourToRGB(rColour);
 
     if ( !wxWindowBase::SetBackgroundColour(rColour) )
-        return FALSE;
+        return false;
     ::WinSetPresParam( GetHWND()
                       ,PP_BACKGROUNDCOLOR
                       ,sizeof(ULONG)
                       ,&ulColor
                      );
-    return TRUE;
+    return true;
 } // end of wxTreeCtrl::SetBackgroundColour
 
 bool wxTreeCtrl::SetForegroundColour (
@@ -633,13 +630,13 @@ bool wxTreeCtrl::SetForegroundColour (
     ULONG                           ulColor = wxColourToRGB(rColour);
 
     if (!wxWindowBase::SetForegroundColour(rColour))
-        return FALSE;
+        return false;
     ::WinSetPresParam( GetHWND()
                       ,PP_FOREGROUNDCOLOR
                       ,sizeof(ULONG)
                       ,&ulColor
                      );
-    return TRUE;
+    return true;
 } // end of wxTreeCtrl::SetForegroundColour
 
 // ----------------------------------------------------------------------------
@@ -881,7 +878,7 @@ bool wxTreeCtrl::HasIndirectData (
   const wxTreeItemId&               WXUNUSED(rItem)
 ) const
 {
-    return FALSE;
+    return false;
 } // end of wxTreeCtrl::HasIndirectData
 
 // Irreleveant under OS/2 --- item either has child records or it doesn't.
@@ -974,7 +971,7 @@ void wxTreeCtrl::SetItemTextColour (
 , const wxColour&                   rCol
 )
 {
-    m_bHasAnyAttr = TRUE;
+    m_bHasAnyAttr = true;
 
     long                            lId = (long)rItem.m_pItem;
     wxTreeItemAttr*                 pAttr = (wxTreeItemAttr *)m_vAttrs.Get(lId);
@@ -993,7 +990,7 @@ void wxTreeCtrl::SetItemBackgroundColour (
 , const wxColour&                   rCol
 )
 {
-    m_bHasAnyAttr = TRUE;
+    m_bHasAnyAttr = true;
 
     long                            lId = (long)rItem.m_pItem;
     wxTreeItemAttr*                 pAttr = (wxTreeItemAttr *)m_vAttrs.Get(lId);
@@ -1012,7 +1009,7 @@ void wxTreeCtrl::SetItemFont (
 , const wxFont&                     rFont
 )
 {
-    m_bHasAnyAttr = TRUE;
+    m_bHasAnyAttr = true;
 
     long                            lId = (long)rItem.m_pItem;
     wxTreeItemAttr*                 pAttr = (wxTreeItemAttr *)m_vAttrs.Get(lId);
@@ -1068,7 +1065,7 @@ bool wxTreeCtrl::IsVisible (
     vWxRectContainer.SetTop(vRectContainer.yTop);
     vWxRectContainer.SetRight(vRectContainer.xRight);
     vWxRectContainer.SetBottom(vRectContainer.yBottom);
-    return (vWxRectContainer.Inside(wxPoint(vWxRectRecord.x, vWxRectRecord.y)));
+    return (vWxRectContainer.Contains(wxPoint(vWxRectRecord.x, vWxRectRecord.y)));
 } // end of wxTreeCtrl::IsVisible
 
 bool wxTreeCtrl::ItemHasChildren (
@@ -1110,7 +1107,7 @@ bool wxTreeCtrl::IsBold (
   const wxTreeItemId&               rItem
 ) const
 {
-    return FALSE;
+    return false;
 } // end of wxTreeCtrl::IsBold
 
 // ----------------------------------------------------------------------------
@@ -1478,24 +1475,6 @@ wxTreeItemId wxTreeCtrl::DoInsertItem (
     return wxTreeItemId((long)pRecord->m_ulItemId);
 }
 
-// for compatibility only
-wxTreeItemId wxTreeCtrl::InsertItem (
-  const wxTreeItemId&               rParent
-, const wxString&                   rsText
-, int                               nImage
-, int                               nSelImage
-, long                              lInsertAfter
-)
-{
-    return DoInsertItem( rParent
-                        ,wxTreeItemId(lInsertAfter)
-                        ,rsText
-                        ,nImage
-                        ,nSelImage
-                        ,NULL
-                       );
-} // end of wxTreeCtrl::InsertItem
-
 wxTreeItemId wxTreeCtrl::AddRoot (
   const wxString&                   rsText
 , int                               nImage
@@ -1608,7 +1587,7 @@ void wxTreeCtrl::Delete (
         delete (wxTreeItemAttr *)m_vAttrs.Delete((long)rItem.m_pItem);
     }
     vEvent.SetEventType(vEventType);
-    GetEventHandler()->ProcessEvent(vEvent);
+    HandleWindowEvent(vEvent);
 } // end of wxTreeCtrl::Delete
 
 // delete all children (but don't delete the item itself)
@@ -1736,16 +1715,6 @@ void wxTreeCtrl::Toggle (
             );
 } // end of wxTreeCtrl::Toggle
 
-void wxTreeCtrl::ExpandItem (
-  const wxTreeItemId&               rItem
-, int                               nAction
-)
-{
-    DoExpand( rItem
-             ,nAction
-            );
-} // end of wxTreeCtrl::ExpandItem
-
 void wxTreeCtrl::Unselect ()
 {
     wxASSERT_MSG( !(m_windowStyle & wxTR_MULTIPLE),
@@ -1767,7 +1736,7 @@ void wxTreeCtrl::UnselectAll ()
         for (size_t n = 0; n < nCount; n++)
         {
             SetItemCheck( aSelections[n]
-                         ,FALSE
+                         ,false
                         );
         }
     }
@@ -1923,12 +1892,12 @@ bool wxTreeCtrl::GetBoundingRect (
                       ,MPFROMP(&vRectRecord)
                       ,MPFROMP(&vQuery)
                      ))
-        return FALSE;
+        return false;
     rRect.SetLeft(vRectRecord.xLeft);
     rRect.SetTop(vRectRecord.yTop);
     rRect.SetRight(vRectRecord.xRight);
     rRect.SetBottom(vRectRecord.yBottom);
-    return TRUE;
+    return true;
 } // end of wxTreeCtrl::GetBoundingRect
 
 // ----------------------------------------------------------------------------
@@ -1989,7 +1958,7 @@ bool wxTreeCtrl::OS2Command (
 
         vEvent.SetEventObject( this );
         ProcessCommand(vEvent);
-        return TRUE;
+        return true;
     }
     else if (uCmd == CN_KILLFOCUS)
     {
@@ -1998,10 +1967,10 @@ bool wxTreeCtrl::OS2Command (
                                           );
         vEvent.SetEventObject( this );
         ProcessCommand(vEvent);
-        return TRUE;
+        return true;
     }
     else
-        return FALSE;
+        return false;
 } // end of wxTreeCtrl::OS2Command
 
 //
@@ -2013,7 +1982,7 @@ MRESULT wxTreeCtrl::OS2WindowProc (
 , WXLPARAM                          lParam
 )
 {
-    bool                            bProcessed = FALSE;
+    bool                            bProcessed = false;
     MRESULT                         mRc = 0;
     wxTreeEvent                     vEvent( wxEVT_NULL
                                            ,m_windowId
@@ -2051,7 +2020,7 @@ MRESULT wxTreeCtrl::OS2WindowProc (
                         vEventType = wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
                         vEvent.m_item = pRecord->m_ulItemId;
                         vEvent.m_label = pRecord->m_vRecord.pszTree;
-                        vEvent.m_editCancelled = FALSE;
+                        vEvent.m_editCancelled = false;
                     }
                     break;
 
@@ -2066,11 +2035,11 @@ MRESULT wxTreeCtrl::OS2WindowProc (
                         vEvent.m_label = pRecord->m_vRecord.pszTree;
                         if (pRecord->m_vRecord.pszTree == NULL)
                         {
-                            vEvent.m_editCancelled = TRUE;
+                            vEvent.m_editCancelled = true;
                         }
                         else
                         {
-                            vEvent.m_editCancelled = FALSE;
+                            vEvent.m_editCancelled = false;
                         }
                     }
                     break;
@@ -2085,7 +2054,7 @@ MRESULT wxTreeCtrl::OS2WindowProc (
                     break;
             }
             vEvent.SetEventType(vEventType);
-            bProcessed = GetEventHandler()->ProcessEvent(vEvent);
+            bProcessed = HandleWindowEvent(vEvent);
             break;
     }
     if (!bProcessed)