1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/msw/treectrl.cpp 
   4 // Author:      Julian Smart 
   5 // Modified by: Vadim Zeitlin to be less MSW-specific on 10.10.98 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  21     #pragma implementation "treectrl.h" 
  24 // For compilers that support precompilation, includes "wx.h". 
  25 #include "wx/wxprec.h" 
  33 #include "wx/os2/private.h" 
  37 #include "wx/dynarray.h" 
  38 #include "wx/imaglist.h" 
  39 #include "wx/settings.h" 
  40 #include "wx/os2/treectrl.h" 
  42 // a macro to hide the ugliness of nested casts 
  43 #define HITEM(item)     (HTREEITEM)(WXHTREEITEM)(item) 
  45 // the native control doesn't support multiple selections under MSW and we 
  46 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let 
  47 // checkboxes be the selection status (checked == selected) or by really 
  48 // emulating everything, i.e. intercepting mouse and key events &c. The first 
  49 // approach is much easier but doesn't work with comctl32.dll < 4.71 and also 
  51 #define wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE 0 
  53 // ---------------------------------------------------------------------------- 
  55 // ---------------------------------------------------------------------------- 
  57 // ---------------------------------------------------------------------------- 
  59 // ---------------------------------------------------------------------------- 
  61 typedef struct _MYRECORD
 
  66 } MYRECORD
, *PMYRECORD
; 
  68 struct wxTreeViewItem 
: public MYRECORD
 
  70     wxTreeViewItem(const wxTreeItemId
& rItem
) 
  72         m_ulItemId 
= (ULONG
)rItem
.m_pItem
; 
  74 }; // end of STRUCT wxTreeViewItem 
  76 class wxTreeItemInternalData
 
  80     wxTreeItemInternalData() {} 
  81     ~wxTreeItemInternalData() 
  90     wxTreeItemAttr
*                 m_pAttr
; 
  91     WXLPARAM                        m_lParam
; // user data 
  92 #if defined(C_CM_COS232) 
  93     PMYRECORD                       m_pMyRecord
; // so we can set the m_ulUserData to 0 when this is deleted 
  95 }; // end of CLASS wxTreeItemInternalData 
  97 void BumpTreeRecordIds ( 
 104         pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
 
 107                                                       ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
 110             pRecord
->m_ulItemId
++; 
 112 } // end of BumpTreeRecordIds 
 114 PMYRECORD 
FindOS2TreeRecordByID ( 
 119     PMYRECORD                       pRecord 
= NULL
; 
 123     if (!::WinSendMsg( hWnd
 
 126                       ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 129     for (i 
= 0; i 
< vCnrInfo
.cRecords
; i
++) 
 132             pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
 
 135                                                           ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
) 
 138             pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
 
 141                                                           ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
 145         if (pRecord
->m_ulItemId 
== (ULONG
)lItemId
) 
 149 } // end of FindOS2ListRecordByID 
 153 class wxTreeTraversal
 
 156     wxTreeTraversal(const wxTreeCtrl
* pTree
) 
 162     // Do traverse the tree: visit all items (recursively by default) under the 
 163     // given one; return TRUE if all items were traversed or FALSE if the 
 164     // traversal was aborted because OnVisit returned FALSE 
 166     bool DoTraverse( const wxTreeItemId
& rRoot
 
 167                     ,bool                bRecursively 
= TRUE
 
 171     // Override this function to do whatever is needed for each item, return 
 172     // FALSE to stop traversing 
 174     virtual bool OnVisit(const wxTreeItemId
& rItem
) = 0; 
 177     const wxTreeCtrl
* GetTree(void) const { return m_pTree
; } 
 180     bool Traverse( const wxTreeItemId
& rRoot
 
 184     const wxTreeCtrl
*               m_pTree
; 
 185     DECLARE_NO_COPY_CLASS(wxTreeTraversal
) 
 186 }; // end of CLASS wxTreeTraversal 
 189 // Internal class for getting the selected items 
 191 class TraverseSelections 
: public wxTreeTraversal
 
 194     TraverseSelections( const wxTreeCtrl
*   pTree
 
 195                        ,wxArrayTreeItemIds
& raSelections
 
 197                       : wxTreeTraversal(pTree
) 
 198                       , m_aSelections(raSelections
) 
 200         m_aSelections
.Empty(); 
 201         DoTraverse(pTree
->GetRootItem()); 
 204     virtual bool OnVisit(const wxTreeItemId
& rItem
) 
 207         // Can't visit a virtual node. 
 209         if ((GetTree()->GetRootItem() == rItem
) && (GetTree()->GetWindowStyle() & wxTR_HIDE_ROOT
)) 
 213         PMYRECORD                   pRecord 
= FindOS2TreeRecordByID( GetTree()->GetHWND() 
 216         if (pRecord
->m_vRecord
.flRecordAttr 
& CRA_SELECTED
) 
 218             m_aSelections
.Add(rItem
); 
 223     size_t GetCount(void) const { return m_aSelections
.GetCount(); } 
 226     wxArrayTreeItemIds
&             m_aSelections
; 
 227 }; // end of CLASS TraverseSelections 
 230 // Internal class for counting tree items 
 232 class TraverseCounter 
: public wxTreeTraversal
 
 235     TraverseCounter( const wxTreeCtrl
*   pTree
 
 236                     ,const wxTreeItemId
& rRoot
 
 239                    : wxTreeTraversal(pTree
) 
 242         DoTraverse(rRoot
, bRecursively
); 
 245     virtual bool OnVisit(const wxTreeItemId
& WXUNUSED(rItem
)) 
 251     size_t GetCount(void) const { return m_nCount
; } 
 255 }; // end of CLASS TraverseCounter 
 257 // ---------------------------------------------------------------------------- 
 259 // ---------------------------------------------------------------------------- 
 261 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
) 
 263 // ---------------------------------------------------------------------------- 
 265 // ---------------------------------------------------------------------------- 
 267 // indices in gs_expandEvents table below 
 282 // handy table for sending events - it has to be initialized during run-time 
 283 // now so can't be const any more 
 284 static /* const */ wxEventType gs_expandEvents
[IDX_WHAT_MAX
][IDX_HOW_MAX
]; 
 287    but logically it's a const table with the following entries: 
 290     { wxEVT_COMMAND_TREE_ITEM_COLLAPSED, wxEVT_COMMAND_TREE_ITEM_COLLAPSING }, 
 291     { wxEVT_COMMAND_TREE_ITEM_EXPANDED,  wxEVT_COMMAND_TREE_ITEM_EXPANDING  } 
 295 // ============================================================================ 
 297 // ============================================================================ 
 299 // ---------------------------------------------------------------------------- 
 301 // ---------------------------------------------------------------------------- 
 303 bool wxTreeTraversal::DoTraverse ( 
 304   const wxTreeItemId
&               rRoot
 
 311     return Traverse( rRoot
 
 314 } // end of wxTreeTraversal::DoTraverse 
 316 bool wxTreeTraversal::Traverse ( 
 317   const wxTreeItemId
&               rRoot
 
 322     wxTreeItemId                    vChild 
= m_pTree
->GetFirstChild( rRoot
 
 325     while (vChild
.IsOk()) 
 328         // Depth first traversal 
 330         if (bRecursively 
&& !Traverse(vChild
, TRUE
)) 
 332         if (!OnVisit(vChild
)) 
 334         vChild 
= m_pTree
->GetNextChild( rRoot
 
 339 } // end of wxTreeTraversal::Traverse 
 341 // ---------------------------------------------------------------------------- 
 342 // construction and destruction 
 343 // ---------------------------------------------------------------------------- 
 345 void wxTreeCtrl::Init () 
 347     m_pImageListNormal     
= NULL
; 
 348     m_pImageListState      
= NULL
; 
 349     m_bOwnsImageListNormal 
= FALSE
; 
 350     m_bOwnsImageListState  
= FALSE
; 
 351     m_bHasAnyAttr          
= FALSE
; 
 355     // Initialize the global array of events now as it can't be done statically 
 356     // with the wxEVT_XXX values being allocated during run-time only 
 358     gs_expandEvents
[IDX_COLLAPSE
][IDX_DONE
]  = wxEVT_COMMAND_TREE_ITEM_COLLAPSED
; 
 359     gs_expandEvents
[IDX_COLLAPSE
][IDX_DOING
] = wxEVT_COMMAND_TREE_ITEM_COLLAPSING
; 
 360     gs_expandEvents
[IDX_EXPAND
][IDX_DONE
]    = wxEVT_COMMAND_TREE_ITEM_EXPANDED
; 
 361     gs_expandEvents
[IDX_EXPAND
][IDX_DOING
]   = wxEVT_COMMAND_TREE_ITEM_EXPANDING
; 
 362 } // end of wxTreeCtrl::Init 
 364 bool wxTreeCtrl::Create ( 
 367 , const wxPoint
&                    rPos
 
 368 , const wxSize
&                     rSize
 
 370 , const wxValidator
&                rValidator
 
 371 , const wxString
&                   rsName
 
 377     if (!CreateControl( pParent
 
 387     DWORD                           dwStyle 
= WS_VISIBLE 
| WS_TABSTOP
; 
 389     if (m_windowStyle 
& wxCLIP_SIBLINGS
) 
 390         dwStyle 
|= WS_CLIPSIBLINGS
; 
 392     // Create the tree control. 
 393     if (!OS2CreateControl( "CONTAINER" 
 399     // Now set the display attributes to show a TREE/ICON view of the 
 402     if (!::WinSendMsg( GetHWND() 
 405                       ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 408     vCnrInfo
.flWindowAttr 
= CV_TREE
|CV_ICON
; 
 409     vCnrInfo
.flWindowAttr 
|= CA_DRAWBITMAP
; 
 410     if (m_windowStyle 
& wxTR_NO_LINES
) 
 411         vCnrInfo
.flWindowAttr 
|= CA_TREELINE
; 
 413     ::WinSendMsg( GetHWND() 
 416                  ,(MPARAM
)CMA_FLWINDOWATTR
 
 419     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)); 
 420     SetForegroundColour(wxWindow::GetParent()->GetForegroundColour()); 
 421     SetFont(*wxSMALL_FONT
); 
 430 } // end of wxTreeCtrl::Create 
 432 wxTreeCtrl::~wxTreeCtrl () 
 435     // Delete any attributes 
 439         for (wxNode
* pNode 
= m_vAttrs
.Next(); pNode
; pNode 
= m_vAttrs
.Next()) 
 441             delete (wxTreeItemAttr 
*)pNode
->Data(); 
 443         m_bHasAnyAttr 
= FALSE
; 
 448     // Delete user data to prevent memory leaks 
 449     // also deletes hidden root node storage. 
 452     if (m_bOwnsImageListNormal
) 
 453         delete m_pImageListNormal
; 
 454     if (m_bOwnsImageListState
) 
 455         delete m_pImageListState
; 
 456 } // end of wxTreeCtrl::~wxTreeCtrl 
 458 // ---------------------------------------------------------------------------- 
 460 // ---------------------------------------------------------------------------- 
 463 // simple wrappers which add error checking in debug mode.  These methods 
 464 // assume the items are properly filled out already.  If not, you get errors 
 466 bool wxTreeCtrl::DoGetItem ( 
 467   wxTreeViewItem
*                   pTvItem
 
 470     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID( GetHWND() 
 476         wxLogLastError(wxT("Item not obtained")); 
 480 } // end of wxTreeCtrl::DoGetItem 
 482 void wxTreeCtrl::DoSetItem ( 
 483   wxTreeViewItem
*                   pTvItem
 
 487     // Just invalidate the record to redisplay it 
 489     if (!::WinSendMsg( GetHWND() 
 492                       ,MPFROM2SHORT(1, CMA_ERASE 
| CMA_REPOSITION 
| CMA_TEXTCHANGED
) 
 495         wxLogLastError(wxT("CM_INVALIDATERECORD")); 
 497 } // end of wxTreeCtrl::DoSetItem 
 499 size_t wxTreeCtrl::GetCount () const 
 503     ::WinSendMsg( GetHWND() 
 506                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 508     return (size_t)vCnrInfo
.cRecords
; 
 509 } // end of wxTreeCtrl::GetCount 
 511 unsigned int wxTreeCtrl::GetIndent () const 
 515     ::WinSendMsg( GetHWND() 
 518                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 520     return (unsigned int)vCnrInfo
.cxTreeIndent
; 
 521 } // end of wxTreeCtrl::GetIndent 
 523 void wxTreeCtrl::SetIndent ( 
 529     ::WinSendMsg( GetHWND() 
 532                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 534     vCnrInfo
.cxTreeIndent 
= (LONG
)uIndent
; 
 535     ::WinSendMsg( GetHWND() 
 538                  ,(MPARAM
)CMA_CXTREEINDENT
 
 540 } // end of wxTreeCtrl::SetIndent 
 542 wxImageList
* wxTreeCtrl::GetImageList () const 
 544     return m_pImageListNormal
; 
 545 } // end of wxTreeCtrl::GetImageList 
 547 wxImageList
* wxTreeCtrl::GetStateImageList () const 
 549     return m_pImageListNormal
; 
 550 } // end of wxTreeCtrl::GetStateImageList 
 553 // The SETS of imagelists really do nothing under OS2 as a RECORDCORE 
 554 // struct has the icon imbedded in it that it uses for the icon being 
 555 // displayed via the TREEITEMDESC member.  Provided for interface 
 556 // compatability only 
 558 void wxTreeCtrl::SetAnyImageList ( 
 559   wxImageList
*                      WXUNUSED(pImageList
) 
 560 , int                               WXUNUSED(nWhich
) 
 563 } // end of wxTreeCtrl::SetAnyImageList 
 565 void wxTreeCtrl::SetImageList ( 
 566   wxImageList
*                      WXUNUSED(pImageList
) 
 569     if (m_bOwnsImageListNormal
) 
 570         delete m_pImageListNormal
; 
 571     m_bOwnsImageListNormal 
= FALSE
; 
 572 } // end of wxTreeCtrl::SetImageList 
 574 void wxTreeCtrl::SetStateImageList ( 
 575   wxImageList
*                      WXUNUSED(pImageList
) 
 578     if (m_bOwnsImageListState
) 
 579         delete m_pImageListState
; 
 580     m_bOwnsImageListState 
= FALSE
; 
 581 } // end of wxTreeCtrl::SetStateImageList 
 583 void wxTreeCtrl::AssignImageList ( 
 584   wxImageList
*                      WXUNUSED(pImageList
) 
 587     m_bOwnsImageListNormal 
= TRUE
; 
 588 } // end of wxTreeCtrl::AssignImageList 
 590 void wxTreeCtrl::AssignStateImageList ( 
 591   wxImageList
*                      WXUNUSED(pImageList
) 
 594     m_bOwnsImageListState 
= TRUE
; 
 595 } // end of wxTreeCtrl::AssignStateImageList 
 597 size_t wxTreeCtrl::GetChildrenCount ( 
 598   const wxTreeItemId
&               rItem
 
 602     TraverseCounter                 
vCounter( this 
 606     return vCounter
.GetCount() - 1; 
 607 } // end of wxTreeCtrl::GetChildrenCount 
 609 // ---------------------------------------------------------------------------- 
 611 // ---------------------------------------------------------------------------- 
 613 bool wxTreeCtrl::SetBackgroundColour ( 
 614   const wxColour
&                   rColour
 
 617     ULONG                           ulColor 
= wxColourToRGB(rColour
); 
 619     if ( !wxWindowBase::SetBackgroundColour(rColour
) ) 
 621     ::WinSetPresParam( GetHWND() 
 627 } // end of wxTreeCtrl::SetBackgroundColour 
 629 bool wxTreeCtrl::SetForegroundColour ( 
 630   const wxColour
&                   rColour
 
 633     ULONG                           ulColor 
= wxColourToRGB(rColour
); 
 635     if (!wxWindowBase::SetForegroundColour(rColour
)) 
 637     ::WinSetPresParam( GetHWND() 
 643 } // end of wxTreeCtrl::SetForegroundColour 
 645 // ---------------------------------------------------------------------------- 
 647 // ---------------------------------------------------------------------------- 
 649 wxString 
wxTreeCtrl::GetItemText ( 
 650   const wxTreeItemId
&               rItem
 
 653     wxChar                          zBuf
[512];  // the size is arbitrary... 
 654     wxTreeViewItem                  
vTvItem(rItem
); 
 656     if (!DoGetItem(&vTvItem
)) 
 659         // Don't return some garbage which was on stack, but an empty string 
 664         strcpy(zBuf
, vTvItem
.m_vRecord
.pszTree
); 
 665     return wxString(zBuf
); 
 666 } // end of wxTreeCtrl::GetItemText 
 668 void wxTreeCtrl::SetItemText ( 
 669   const wxTreeItemId
&               rItem
 
 670 , const wxString
&                   rsText
 
 673     wxTreeViewItem                  
vTvItem(rItem
); 
 675     vTvItem
.m_vRecord
.pszTree 
= (wxChar 
*)rsText
.c_str();  // conversion is ok 
 677 } // end of wxTreeCtrl::SetItemText 
 680 // These functions under OS/2 PM are not needed.  OS/2 containers in tree view 
 681 // provide for storing a custom expanded and collapsed icons and selected 
 682 // and non selected icons, natively.  For instance, by default, a disk display 
 683 // will display a tree list of folder icons with "+" icons (collapsed) beside 
 684 // those folder which contain child members.  Double clicking a folder changes 
 685 // the closed folder icon to an open folder icon with hatched selection 
 686 // highlighting indicating an ICON view container of the folder is open 
 687 // elsewhere on the desktop.  So the below is not really needed, but we will 
 688 // simply return the appropriate icon requested out of OS/2's native PM 
 691 int wxTreeCtrl::DoGetItemImageFromData ( 
 692   const wxTreeItemId
&               WXUNUSED(rItem
) 
 693 , wxTreeItemIcon                    nWhich
 
 697     // Image handles stored in CNRINFO. 
 701     ::WinSendMsg( GetHWND() 
 704                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 708     // We really only have two to chose from.  If not custom (set in CNRINFO 
 709     // then return the handle to system bitmap).  OS/2 automatically provides 
 710     // in_use and selected bitmaps/icons 
 714         case wxTreeItemIcon_Normal
: 
 715             if (vCnrInfo
.hbmCollapsed 
== NULLHANDLE
) 
 716                 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
); 
 717             return vCnrInfo
.hbmCollapsed
; 
 720         case wxTreeItemIcon_Expanded
: 
 721             if (vCnrInfo
.hbmExpanded 
== NULLHANDLE
) 
 722                 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
); 
 723             return vCnrInfo
.hbmExpanded
; 
 726             return vCnrInfo
.hbmCollapsed
; 
 730 void wxTreeCtrl::DoSetItemImageFromData ( 
 731   const wxTreeItemId
&               WXUNUSED(rItem
) 
 733 , wxTreeItemIcon                    nWhich
 
 737     // Image handles stored in CNRINFO. 
 741     ::WinSendMsg( GetHWND() 
 744                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 746     if (nWhich 
== wxTreeItemIcon_Normal
) 
 747          vCnrInfo
.hbmCollapsed 
= (HBITMAP
)nImage
; 
 748     if (nWhich 
== wxTreeItemIcon_Expanded
) 
 749         vCnrInfo
.hbmExpanded 
= (HBITMAP
)nImage
; 
 750     ::WinSendMsg( GetHWND() 
 753                  ,(MPARAM
)CMA_TREEBITMAP
 
 755 } // end of wxTreeCtrl::DoSetItemImageFromData 
 758 void wxTreeCtrl::DoSetItemImages ( 
 759   const wxTreeItemId
&               rItem
 
 764 } // end of wxTreeCtrl::DoSetItemImages 
 766 int wxTreeCtrl::GetItemImage ( 
 767   const wxTreeItemId
&               rItem
 
 768 , wxTreeItemIcon                    nWhich
 
 771     if (HasIndirectData(rItem
)) 
 773         return DoGetItemImageFromData( rItem
 
 780     ::WinSendMsg( GetHWND() 
 783                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 788             wxFAIL_MSG( wxT("unknown tree item image type") ); 
 790         case wxTreeItemIcon_Normal
: 
 791             if (vCnrInfo
.hbmCollapsed 
== NULLHANDLE
) 
 792                 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
); 
 793             return vCnrInfo
.hbmCollapsed
; 
 796         case wxTreeItemIcon_Expanded
: 
 797             if (vCnrInfo
.hbmExpanded 
== NULLHANDLE
) 
 798                 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
); 
 799             return vCnrInfo
.hbmExpanded
; 
 801         case wxTreeItemIcon_Selected
: 
 802         case wxTreeItemIcon_SelectedExpanded
: 
 807 void wxTreeCtrl::SetItemImage ( 
 808   const wxTreeItemId
&               WXUNUSED(rItem
) 
 810 , wxTreeItemIcon                    nWhich
 
 815     ::WinSendMsg( GetHWND() 
 818                  ,(MPARAM
)(USHORT
)sizeof(CNRINFO
) 
 822         case wxTreeItemIcon_Normal
: 
 823             vCnrInfo
.hbmCollapsed 
= (HBITMAP
)nImage
; 
 826         case wxTreeItemIcon_Expanded
: 
 827             vCnrInfo
.hbmExpanded 
= (HBITMAP
)nImage
; 
 831             wxFAIL_MSG( wxT("unknown tree item image type") ); 
 833     ::WinSendMsg( GetHWND() 
 836                  ,(MPARAM
)CMA_TREEBITMAP
 
 838 } // end of wxTreeCtrl::SetItemImage 
 840 wxTreeItemData
* wxTreeCtrl::GetItemData ( 
 841   const wxTreeItemId
&               rItem
 
 844     wxTreeViewItem                  
vTvItem(rItem
); 
 846     if (!DoGetItem(&vTvItem
)) 
 851     return (wxTreeItemData 
*)vTvItem
.m_ulUserData
; 
 852 } // end of wxTreeCtrl::GetItemData 
 854 void wxTreeCtrl::SetItemData ( 
 855   const wxTreeItemId
&               rItem
 
 856 , wxTreeItemData
*                   pData
 
 860     // first, associate this piece of data with this item 
 866     wxTreeViewItem                  
vTvItem(rItem
); 
 868     vTvItem
.m_ulUserData 
= (ULONG
)pData
; 
 870 } // end of wxTreeCtrl::SetItemData 
 872 // The following two do nothing under OS/2 
 873 void wxTreeCtrl::SetIndirectItemData ( 
 874   const wxTreeItemId
&               WXUNUSED(rItem
) 
 875 , wxTreeItemIndirectData
*           WXUNUSED(pData
) 
 878 } // end of wxTreeCtrl::SetIndirectItemData 
 880 bool wxTreeCtrl::HasIndirectData ( 
 881   const wxTreeItemId
&               WXUNUSED(rItem
) 
 885 } // end of wxTreeCtrl::HasIndirectData 
 887 // Irreleveant under OS/2 --- item either has child records or it doesn't. 
 888 void wxTreeCtrl::SetItemHasChildren ( 
 889   const wxTreeItemId
&               WXUNUSED(rItem
) 
 890 , bool                              WXUNUSED(bHas
) 
 893 } // end of wxTreeCtrl::SetItemHasChildren 
 895 // Irreleveant under OS/2 --- function of the font in PM 
 896 void wxTreeCtrl::SetItemBold ( 
 897   const wxTreeItemId
&               WXUNUSED(rItem
) 
 898 , bool                              WXUNUSED(bBold
) 
 901 } // end of wxTreeCtrl::SetItemBold 
 903 void wxTreeCtrl::SetItemDropHighlight ( 
 904   const wxTreeItemId
&               rItem
 
 908     wxTreeViewItem                  
vTvItem(rItem
); 
 910     ::WinSendMsg( GetHWND() 
 911                  ,CM_SETRECORDEMPHASIS
 
 913                  ,MPFROM2SHORT(bHighlight
, CRA_SELECTED
) 
 916 } // end of wxTreeCtrl::SetItemDropHighlight 
 918 void wxTreeCtrl::RefreshItem ( 
 919   const wxTreeItemId
&               rItem
 
 922     wxTreeViewItem                  
vTvItem(rItem
); 
 925     // This just does a record invalidate causing it to be re-displayed 
 928 } // end of wxTreeCtrl::RefreshItem 
 930 wxColour 
wxTreeCtrl::GetItemTextColour ( 
 931   const wxTreeItemId
&               rItem
 
 934     long                            lId 
= (long)rItem
.m_pItem
; 
 935     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
 941     return pAttr
->GetTextColour(); 
 942 } // end of wxTreeCtrl::GetItemTextColour 
 944 wxColour 
wxTreeCtrl::GetItemBackgroundColour ( 
 945   const wxTreeItemId
&               rItem
 
 948     long                            lId 
= (long)rItem
.m_pItem
; 
 949     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
 955     return pAttr
->GetBackgroundColour(); 
 956 } // end of wxTreeCtrl::GetItemBackgroundColour 
 958 wxFont 
wxTreeCtrl::GetItemFont ( 
 959   const wxTreeItemId
&               rItem
 
 962     long                            lId 
= (long)rItem
.m_pItem
; 
 963     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
 969     return pAttr
->GetFont(); 
 970 } // end of wxTreeCtrl::GetItemFont 
 972 void wxTreeCtrl::SetItemTextColour ( 
 973   const wxTreeItemId
&               rItem
 
 974 , const wxColour
&                   rCol
 
 977     m_bHasAnyAttr 
= TRUE
; 
 979     long                            lId 
= (long)rItem
.m_pItem
; 
 980     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
 984         pAttr 
= new wxTreeItemAttr
; 
 985         m_vAttrs
.Put(lId
, (wxObject 
*)pAttr
); 
 987     pAttr
->SetTextColour(rCol
); 
 989 } // end of wxTreeCtrl::SetItemTextColour 
 991 void wxTreeCtrl::SetItemBackgroundColour ( 
 992   const wxTreeItemId
&               rItem
 
 993 , const wxColour
&                   rCol
 
 996     m_bHasAnyAttr 
= TRUE
; 
 998     long                            lId 
= (long)rItem
.m_pItem
; 
 999     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
1003         pAttr 
= new wxTreeItemAttr
; 
1004         m_vAttrs
.Put(lId
, (wxObject 
*)pAttr
); 
1006     pAttr
->SetBackgroundColour(rCol
); 
1008 } // end of wxTreeCtrl::SetItemBackgroundColour 
1010 void wxTreeCtrl::SetItemFont ( 
1011   const wxTreeItemId
&               rItem
 
1012 , const wxFont
&                     rFont
 
1015     m_bHasAnyAttr 
= TRUE
; 
1017     long                            lId 
= (long)rItem
.m_pItem
; 
1018     wxTreeItemAttr
*                 pAttr 
= (wxTreeItemAttr 
*)m_vAttrs
.Get(lId
); 
1022         pAttr 
= new wxTreeItemAttr
; 
1023         m_vAttrs
.Put(lId
, (wxObject 
*)pAttr
); 
1025     pAttr
->SetFont(rFont
); 
1027 } // end of wxTreeCtrl::SetItemFont 
1029 // ---------------------------------------------------------------------------- 
1031 // ---------------------------------------------------------------------------- 
1033 bool wxTreeCtrl::IsVisible ( 
1034   const wxTreeItemId
&               rItem
 
1037     // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect 
1039     RECTL                           vRectContainer
; 
1040     wxRect                          vWxRectRecord
; 
1041     wxRect                          vWxRectContainer
; 
1042     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1045     QUERYRECORDRECT                 vQuery
; 
1047     vQuery
.cb                
= sizeof(QUERYRECORDRECT
); 
1048     vQuery
.pRecord           
= (PRECORDCORE
)pRecord
; 
1049     vQuery
.fRightSplitWindow 
= FALSE
; 
1050     vQuery
.fsExtent          
= CMA_TREEICON
; 
1052     ::WinSendMsg( GetHWND() 
1053                  ,CM_QUERYVIEWPORTRECT
 
1054                  ,MPFROMP(&vRectContainer
) 
1055                  ,MPFROM2SHORT(CMA_WINDOW
, FALSE
) 
1057     ::WinSendMsg( GetHWND() 
1059                  ,MPFROMP(&vRectRecord
) 
1062     vWxRectRecord
.SetLeft(vRectRecord
.xLeft
); 
1063     vWxRectRecord
.SetTop(vRectRecord
.yTop
); 
1064     vWxRectRecord
.SetRight(vRectRecord
.xRight
); 
1065     vWxRectRecord
.SetBottom(vRectRecord
.yBottom
); 
1067     vWxRectContainer
.SetLeft(vRectContainer
.xLeft
); 
1068     vWxRectContainer
.SetTop(vRectContainer
.yTop
); 
1069     vWxRectContainer
.SetRight(vRectContainer
.xRight
); 
1070     vWxRectContainer
.SetBottom(vRectContainer
.yBottom
); 
1071     return (vWxRectContainer
.Inside(wxPoint(vWxRectRecord
.x
, vWxRectRecord
.y
))); 
1072 } // end of wxTreeCtrl::IsVisible 
1074 bool wxTreeCtrl::ItemHasChildren ( 
1075   const wxTreeItemId
&               rItem
 
1078     wxTreeViewItem                  
vTvItem(rItem
); 
1079     DoGetItem(&vTvItem
); 
1082     // A tree record with children will have one of these attributes 
1084     return (vTvItem
.m_vRecord
.flRecordAttr 
& CRA_EXPANDED 
|| 
1085             vTvItem
.m_vRecord
.flRecordAttr 
& CRA_COLLAPSED
) != 0; 
1088 bool wxTreeCtrl::IsExpanded ( 
1089   const wxTreeItemId
&               rItem
 
1092     wxTreeViewItem                  
vTvItem(rItem
); 
1093     DoGetItem(&vTvItem
); 
1095     return (vTvItem
.m_vRecord
.flRecordAttr 
& CRA_EXPANDED
) != 0; 
1096 } // end of wxTreeCtrl::IsExpanded 
1098 bool wxTreeCtrl::IsSelected ( 
1099   const wxTreeItemId
&               rItem
 
1102     wxTreeViewItem                  
vTvItem(rItem
); 
1103     DoGetItem(&vTvItem
); 
1105     return (vTvItem
.m_vRecord
.flRecordAttr 
& CRA_SELECTED
) != 0; 
1106 } // end of wxTreeCtrl::IsSelected 
1109 bool wxTreeCtrl::IsBold ( 
1110   const wxTreeItemId
&               rItem
 
1114 } // end of wxTreeCtrl::IsBold 
1116 // ---------------------------------------------------------------------------- 
1118 // ---------------------------------------------------------------------------- 
1120 wxTreeItemId 
wxTreeCtrl::GetRootItem () const 
1122     PMYRECORD                       pRecord 
= NULL
; 
1124     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1127                                                   ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
) 
1131         return wxTreeItemId(-1L); 
1132     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1133 } // end of wxTreeCtrl::GetRootItem 
1135 wxTreeItemId 
wxTreeCtrl::GetSelection () const 
1137     wxCHECK_MSG( !(m_windowStyle 
& wxTR_MULTIPLE
), (long)(WXHTREEITEM
)0, 
1138                  wxT("this only works with single selection controls") ); 
1140     PMYRECORD                       pRecord 
= NULL
; 
1142     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1143                                                   ,CM_QUERYRECORDEMPHASIS
 
1145                                                   ,MPARAM(CRA_SELECTED
) 
1148         return wxTreeItemId(-1L); 
1149     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1150 } // end of wxTreeCtrl::GetSelection 
1152 wxTreeItemId 
wxTreeCtrl::GetItemParent ( 
1153   const wxTreeItemId
&               rItem
 
1156     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1161         return wxTreeItemId(-1L); 
1162     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1165                                                   ,MPFROM2SHORT(CMA_PARENT
, CMA_ITEMORDER
) 
1168         return wxTreeItemId(-1L); 
1169     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1170 } // end of wxTreeCtrl::GetItemParent 
1172 wxTreeItemId 
wxTreeCtrl::GetFirstChild ( 
1173   const wxTreeItemId
&               rItem
 
1177     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1182         return wxTreeItemId(-1L); 
1183     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1186                                                   ,MPFROM2SHORT(CMA_FIRSTCHILD
, CMA_ITEMORDER
) 
1189         return wxTreeItemId(-1L); 
1191     // Remember the last child returned in 'cookie' 
1193     rCookie 
= (long)pRecord
->m_ulItemId
; 
1194     return wxTreeItemId(rCookie
); 
1195 } // end of wxTreeCtrl::GetFirstChild 
1197 wxTreeItemId 
wxTreeCtrl::GetNextChild ( 
1198   const wxTreeItemId
&               WXUNUSED(rItem
) 
1202     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1207         return wxTreeItemId(-1L); 
1208     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1211                                                   ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
1214         return wxTreeItemId(-1L); 
1215     rCookie 
= (long)pRecord
->m_ulItemId
; 
1216     return wxTreeItemId(rCookie
); 
1217 } // end of wxTreeCtrl::GetNextChild 
1219 wxTreeItemId 
wxTreeCtrl::GetLastChild ( 
1220   const wxTreeItemId
&               rItem
 
1223     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1228         return wxTreeItemId(-1L); 
1229     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1232                                                   ,MPFROM2SHORT(CMA_LASTCHILD
, CMA_ITEMORDER
) 
1235         return wxTreeItemId(-1L); 
1236     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1237 } // end of wxTreeCtrl::GetLastChild 
1239 wxTreeItemId 
wxTreeCtrl::GetNextSibling ( 
1240   const wxTreeItemId
&               rItem
 
1243     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1248         return wxTreeItemId(-1L); 
1249     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1252                                                   ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
1255         return wxTreeItemId(-1L); 
1256     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1257 } // end of wxTreeCtrl::GetNextSibling 
1259 wxTreeItemId 
wxTreeCtrl::GetPrevSibling ( 
1260   const wxTreeItemId
&               rItem
 
1263     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1268         return wxTreeItemId(-1L); 
1269     pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1272                                                   ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
) 
1275         return wxTreeItemId(-1L); 
1276     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1277 } // end of wxTreeCtrl::GetPrevSibling 
1279 wxTreeItemId 
wxTreeCtrl::GetFirstVisibleItem () const 
1281     PMYRECORD                       pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1284                                                                                   ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
) 
1287         return wxTreeItemId(-1L); 
1289     if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
))) 
1290         return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1293         pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1296                                                       ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
1299             return wxTreeItemId(-1L); 
1300         if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
))) 
1301             return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1303     return wxTreeItemId(-1L); 
1304 } // end of wxTreeCtrl::GetFirstVisibleItem 
1306 wxTreeItemId 
wxTreeCtrl::GetNextVisible ( 
1307   const wxTreeItemId
&               rItem
 
1310     wxASSERT_MSG(IsVisible(rItem
), wxT("The item you call GetNextVisible() for must be visible itself!")); 
1312     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1317         return wxTreeItemId(-1L); 
1320         pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1323                                                       ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
) 
1326             return wxTreeItemId(-1L); 
1327         if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
))) 
1328             return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1330     return wxTreeItemId(-1L); 
1331 } // end of wxTreeCtrl::GetNextVisible 
1333 wxTreeItemId 
wxTreeCtrl::GetPrevVisible ( 
1334   const wxTreeItemId
&               rItem
 
1337     wxASSERT_MSG( IsVisible(rItem
), wxT("The item you call GetPrevVisible() for must be visible itself!")); 
1339     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1344         return wxTreeItemId(-1L); 
1347         pRecord 
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND() 
1350                                                       ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
) 
1353             return wxTreeItemId(-1L); 
1354         if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
))) 
1355             return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1357     return wxTreeItemId(-1L); 
1358 } // end of wxTreeCtrl::GetPrevVisible 
1360 // ---------------------------------------------------------------------------- 
1361 // multiple selections emulation -- under OS/2 checked tree items is not 
1362 // supported, but multisel is.  So we'll just check for selections here. 
1363 // ---------------------------------------------------------------------------- 
1365 bool wxTreeCtrl::IsItemChecked ( 
1366   const wxTreeItemId
&               rItem
 
1369     wxTreeViewItem                  
vTvItem(rItem
); 
1371     DoGetItem(&vTvItem
); 
1372     return (vTvItem
.m_vRecord
.flRecordAttr 
& CRA_SELECTED
); 
1373 } // end of wxTreeCtrl::IsItemChecked 
1375 void wxTreeCtrl::SetItemCheck ( 
1376   const wxTreeItemId
&               rItem
 
1380     wxTreeViewItem                  
vTvItem(rItem
); 
1382     DoGetItem(&vTvItem
); 
1383     ::WinSendMsg( GetHWND() 
1384                  ,CM_SETRECORDEMPHASIS
 
1386                  ,MPFROM2SHORT(TRUE
, CRA_SELECTED
) 
1388     DoSetItem(&vTvItem
); 
1389 } // end of wxTreeCtrl::SetItemCheck 
1391 size_t wxTreeCtrl::GetSelections ( 
1392   wxArrayTreeItemIds
&               raSelections
 
1395     TraverseSelections              
vSelector( this 
1398     return vSelector
.GetCount(); 
1399 } // end of wxTreeCtrl::GetSelections 
1401 // ---------------------------------------------------------------------------- 
1403 // ---------------------------------------------------------------------------- 
1405 wxTreeItemId 
wxTreeCtrl::DoInsertItem ( 
1406   const wxTreeItemId
&               rParent
 
1407 , wxTreeItemId                      vInsertAfter
 
1408 , const wxString
&                   rsText
 
1411 , wxTreeItemData
*                   pData
 
1414     PMYRECORD                       pRecordAfter 
= FindOS2TreeRecordByID( GetHWND() 
1415                                                                          ,vInsertAfter
.m_pItem
 
1418     PMYRECORD                       pRecordParent 
= FindOS2TreeRecordByID( GetHWND() 
1422     PMYRECORD                       pRecord 
= (PMYRECORD
)::WinSendMsg( GetHWND() 
1424                                                                       ,MPFROMLONG(sizeof(MYRECORD
) - sizeof(RECORDCORE
)) 
1427     RECORDINSERT                    vInsert
; 
1429     vInsert
.cb                
= sizeof(RECORDINSERT
); 
1430     if (rParent
.m_pItem 
== 0L) 
1432         if (vInsertAfter
.m_pItem 
== -1) 
1433             vInsert
.pRecordOrder      
= (PRECORDCORE
)CMA_END
; 
1435             vInsert
.pRecordOrder      
= (PRECORDCORE
)CMA_FIRST
; 
1436         vInsert
.pRecordParent     
= NULL
; 
1440         if (vInsertAfter
.m_pItem 
== 0) 
1441             vInsert
.pRecordOrder      
= (PRECORDCORE
)CMA_FIRST
; 
1442         else if (vInsertAfter
.m_pItem 
== -1) 
1443             vInsert
.pRecordOrder      
= (PRECORDCORE
)CMA_END
; 
1445             vInsert
.pRecordOrder  
= (PRECORDCORE
)pRecordAfter
; 
1446         vInsert
.pRecordParent     
= (PRECORDCORE
)pRecordParent
; 
1448     vInsert
.fInvalidateRecord 
= TRUE
; 
1449     vInsert
.zOrder            
= CMA_TOP
; 
1450     vInsert
.cRecordsInsert    
= 1; 
1452     pRecord
->m_vRecord
.pszTree   
= (wxChar
*)rsText
.c_str(); 
1453     pRecord
->m_vRecord
.hbmBitmap 
= nImage
; 
1454     pRecord
->m_ulItemId 
= pRecordAfter
->m_ulItemId 
+ 1; 
1457         pRecord
->m_ulUserData 
= (ULONG
)pData
; 
1459     ::WinSendMsg( GetHWND() 
1466     // OS/2 must mannually bump the index's of following records 
1468     BumpTreeRecordIds( GetHWND() 
1474         // Associate the application tree item with PM tree item handle 
1476         pData
->SetId((long)pRecord
->m_ulItemId
); 
1478     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1481 // for compatibility only 
1482 wxTreeItemId 
wxTreeCtrl::InsertItem ( 
1483   const wxTreeItemId
&               rParent
 
1484 , const wxString
&                   rsText
 
1490     return DoInsertItem( rParent
 
1491                         ,wxTreeItemId(lInsertAfter
) 
1497 } // end of wxTreeCtrl::InsertItem 
1499 wxTreeItemId 
wxTreeCtrl::AddRoot ( 
1500   const wxString
&                   rsText
 
1502 , int                               nSelectedImage
 
1503 , wxTreeItemData
*                   pData
) 
1506     return DoInsertItem( wxTreeItemId((long)0) 
1507                         ,wxTreeItemId((long)-1) 
1513 } // end of wxTreeCtrl::AddRoot 
1515 wxTreeItemId 
wxTreeCtrl::PrependItem ( 
1516   const wxTreeItemId
&               rParent
 
1517 , const wxString
&                   rsText
 
1519 , int                               nSelectedImage
 
1520 , wxTreeItemData
*                   pData
 
1523     return DoInsertItem( rParent
 
1524                         ,wxTreeItemId((long)0) 
1530 } // end of wxTreeCtrl::PrependItem 
1532 wxTreeItemId 
wxTreeCtrl::InsertItem ( 
1533   const wxTreeItemId
&               rParent
 
1534 , const wxTreeItemId
&               rIdPrevious
 
1535 , const wxString
&                   rsText
 
1537 , int                               nSelectedImage
 
1538 , wxTreeItemData
*                   pData
 
1541     return DoInsertItem( rParent
 
1548 } // end of wxTreeCtrl::InsertItem 
1550 wxTreeItemId 
wxTreeCtrl::InsertItem ( 
1551   const wxTreeItemId
&               rParent
 
1553 , const wxString
&                   rsText
 
1555 , int                               nSelectedImage
 
1556 , wxTreeItemData
*                   pData
 
1559     return DoInsertItem( rParent
 
1560                         ,wxTreeItemId((long)nIndex
) 
1566 } // end of wxTreeCtrl::InsertItem 
1568 wxTreeItemId 
wxTreeCtrl::AppendItem ( 
1569   const wxTreeItemId
&               rParent
 
1570 , const wxString
&                   rsText
 
1572 , int                               nSelectedImage
 
1573 , wxTreeItemData
*                   pData
 
1576     return DoInsertItem( rParent
 
1577                         ,wxTreeItemId((long)-1) 
1583 } // end of wxTreeCtrl::AppendItem 
1585 void wxTreeCtrl::Delete ( 
1586   const wxTreeItemId
&               rItem
 
1590     // OS/2 does not generate DELETEITEM events so do it here 
1592     wxEventType                     vEventType 
= wxEVT_NULL
; 
1593     wxTreeEvent                     
vEvent( wxEVT_NULL
 
1596     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID( GetHWND() 
1599     vEvent
.SetEventObject(this); 
1600     ::WinSendMsg( GetHWND() 
1603                  ,(MPARAM
)(CMA_FREE 
| CMA_INVALIDATE
) 
1605     vEvent
.m_item 
= rItem
.m_pItem
; 
1608         delete (wxTreeItemAttr 
*)m_vAttrs
.Delete((long)rItem
.m_pItem
); 
1610     vEvent
.SetEventType(vEventType
); 
1611     GetEventHandler()->ProcessEvent(vEvent
); 
1612 } // end of wxTreeCtrl::Delete 
1614 // delete all children (but don't delete the item itself) 
1615 void wxTreeCtrl::DeleteChildren ( 
1616   const wxTreeItemId
&               rItem
 
1620     wxArrayLong                     aChildren
; 
1621     wxTreeItemId                    vChild 
= GetFirstChild( rItem
 
1625     while (vChild
.IsOk()) 
1627         aChildren
.Add((long)(WXHTREEITEM
)vChild
); 
1628         vChild 
= GetNextChild( rItem
 
1633     size_t                          nCount 
= aChildren
.Count(); 
1635     for (size_t n 
= 0; n 
< nCount
; n
++) 
1637         Delete(aChildren
[n
]); 
1639 } // end of wxTreeCtrl::DeleteChildren 
1641 void wxTreeCtrl::DeleteAllItems () 
1643     ::WinSendMsg( GetHWND() 
1646                  ,(MPARAM
)(CMA_FREE 
| CMA_INVALIDATE
) 
1648 } // end of wxTreeCtrl::DeleteAllItems 
1650 void wxTreeCtrl::DoExpand ( 
1651   const wxTreeItemId
&               rItem
 
1655     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID( GetHWND() 
1660         case wxTREE_EXPAND_EXPAND
: 
1661             ::WinSendMsg( GetHWND() 
1668         case wxTREE_EXPAND_COLLAPSE
: 
1669             ::WinSendMsg( GetHWND() 
1676         case wxTREE_EXPAND_COLLAPSE_RESET
: 
1677             ::WinSendMsg( GetHWND() 
1682             DeleteChildren(rItem
); 
1685         case wxTREE_EXPAND_TOGGLE
: 
1686             if (pRecord
->m_vRecord
.flRecordAttr 
& CRA_COLLAPSED
) 
1687                 ::WinSendMsg( GetHWND() 
1692             else if (pRecord
->m_vRecord
.flRecordAttr 
& CRA_EXPANDED
) 
1693                 ::WinSendMsg( GetHWND() 
1701 } // end of wxTreeCtrl::DoExpand 
1703 void wxTreeCtrl::Expand ( 
1704   const wxTreeItemId
&               rItem
 
1708              ,wxTREE_EXPAND_EXPAND
 
1710 } // end of wxTreeCtrl::Expand 
1712 void wxTreeCtrl::Collapse ( 
1713   const wxTreeItemId
&               rItem
 
1717              ,wxTREE_EXPAND_COLLAPSE
 
1719 } // end of wxTreeCtrl::Collapse 
1721 void wxTreeCtrl::CollapseAndReset ( 
1722   const wxTreeItemId
&               rItem
 
1726              ,wxTREE_EXPAND_COLLAPSE_RESET
 
1728 } // end of wxTreeCtrl::CollapseAndReset 
1730 void wxTreeCtrl::Toggle ( 
1731   const wxTreeItemId
&               rItem
 
1735              ,wxTREE_EXPAND_TOGGLE
 
1737 } // end of wxTreeCtrl::Toggle 
1739 void wxTreeCtrl::ExpandItem ( 
1740   const wxTreeItemId
&               rItem
 
1747 } // end of wxTreeCtrl::ExpandItem 
1749 void wxTreeCtrl::Unselect () 
1751     wxASSERT_MSG( !(m_windowStyle 
& wxTR_MULTIPLE
), 
1752                   wxT("doesn't make sense, may be you want UnselectAll()?") ); 
1755     // Just remove the selection 
1757     SelectItem(wxTreeItemId((long)0)); 
1758 } // end of wxTreeCtrl::Unselect 
1760 void wxTreeCtrl::UnselectAll () 
1762     if (m_windowStyle 
& wxTR_MULTIPLE
) 
1764         wxArrayTreeItemIds          aSelections
; 
1765         size_t                      nCount 
= GetSelections(aSelections
); 
1767         for (size_t n 
= 0; n 
< nCount
; n
++) 
1769             SetItemCheck( aSelections
[n
] 
1777         // Just remove the selection 
1781 } // end of wxTreeCtrl::UnselectAll 
1783 void wxTreeCtrl::SelectItem ( 
1784   const wxTreeItemId
&               rItem
 
1787     SetItemCheck(rItem
); 
1788 } // end of wxTreeCtrl::SelectItem 
1790 void wxTreeCtrl::EnsureVisible ( 
1791   const wxTreeItemId
&               rItem
 
1794     wxTreeViewItem                  
vTvItem(rItem
); 
1796     DoGetItem(&vTvItem
); 
1797     if (!::WinSendMsg( GetHWND() 
1798                       ,CM_INVALIDATERECORD
 
1800                       ,MPFROM2SHORT(1, CMA_ERASE 
| CMA_REPOSITION 
| CMA_TEXTCHANGED
) 
1802 } // end of wxTreeCtrl::EnsureVisible 
1804 void wxTreeCtrl::ScrollTo ( 
1805   const wxTreeItemId
&               rItem
 
1808     wxTreeViewItem                  
vTvItem(rItem
); 
1810     DoGetItem(&vTvItem
); 
1811     if (!::WinSendMsg( GetHWND() 
1812                       ,CM_INVALIDATERECORD
 
1814                       ,MPFROM2SHORT(1, CMA_ERASE 
| CMA_REPOSITION 
| CMA_TEXTCHANGED
) 
1818 wxTextCtrl
* wxTreeCtrl::EditLabel ( 
1819   const wxTreeItemId
&               rItem
 
1820 , wxClassInfo
*                      WXUNUSED(pTextControlClass
) 
1824     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID( GetHWND() 
1828     vEdit
.cb         
= sizeof(CNREDITDATA
); 
1829     vEdit
.hwndCnr    
= GetHWND(); 
1830     vEdit
.pRecord    
= &pRecord
->m_vRecord
; 
1831     vEdit
.pFieldInfo 
= NULL
; 
1832     vEdit
.ppszText   
= NULL
; 
1836     ::WinSendMsg( GetHWND() 
1842 } // end of wxTreeCtrl::EditLabel 
1844 // End label editing, optionally cancelling the edit 
1845 void wxTreeCtrl::EndEditLabel ( 
1846   const wxTreeItemId
&               WXUNUSED(rItem
) 
1847 , bool                              WXUNUSED(bDiscardChanges
) 
1850     ::WinSendMsg( GetHWND() 
1855 } // end of wxTreeCtrl::EndEditLabel 
1857 wxTreeItemId 
wxTreeCtrl::HitTest ( 
1858   const wxPoint
&                    rPoint
 
1859 , int&                              WXUNUSED(rFlags
) 
1862     PMYRECORD                       pRecord 
= NULL
; 
1863     QUERYRECFROMRECT                vQueryRect
; 
1868     // Get height for OS/2 point conversion 
1870     ::WinSendMsg( GetHWND() 
1871                  ,CM_QUERYVIEWPORTRECT
 
1873                  ,MPFROM2SHORT(CMA_WINDOW
, TRUE
) 
1875     lHeight 
= vRect
.yTop 
- vRect
.yBottom
; 
1878     // For now just try and get a record in the general vicinity and forget 
1881     vRect
.xLeft   
= rPoint
.x 
- 2; 
1882     vRect
.xRight  
= rPoint
.x 
+ 2; 
1883     vRect
.yTop    
= (lHeight 
- rPoint
.y
) + 2; 
1884     vRect
.yBottom 
= (lHeight 
- rPoint
.y
) - 2; 
1886     vQueryRect
.cb 
= sizeof(QUERYRECFROMRECT
); 
1887     vQueryRect
.rect 
= vRect
; 
1888     vQueryRect
.fsSearch 
= CMA_PARTIAL
; 
1890     pRecord 
= (PMYRECORD
)::WinSendMsg( GetHWND() 
1891                                       ,CM_QUERYRECORDFROMRECT
 
1893                                       ,MPFROMP(&vQueryRect
) 
1898     return wxTreeItemId((long)pRecord
->m_ulItemId
); 
1899 } // end of wxTreeCtrl::HitTest 
1901 bool wxTreeCtrl::GetBoundingRect ( 
1902   const wxTreeItemId
&               rItem
 
1908     PMYRECORD                       pRecord 
= FindOS2TreeRecordByID ( GetHWND() 
1911     QUERYRECORDRECT                 vQuery
; 
1913     vQuery
.cb                
= sizeof(QUERYRECORDRECT
); 
1914     vQuery
.pRecord           
= (PRECORDCORE
)pRecord
; 
1915     vQuery
.fRightSplitWindow 
= FALSE
; 
1917         vQuery
.fsExtent          
= CMA_TEXT
; 
1919         vQuery
.fsExtent          
= CMA_TREEICON 
| CMA_TEXT
; 
1921     if (!::WinSendMsg( GetHWND() 
1923                       ,MPFROMP(&vRectRecord
) 
1927     rRect
.SetLeft(vRectRecord
.xLeft
); 
1928     rRect
.SetTop(vRectRecord
.yTop
); 
1929     rRect
.SetRight(vRectRecord
.xRight
); 
1930     rRect
.SetBottom(vRectRecord
.yBottom
); 
1932 } // end of wxTreeCtrl::GetBoundingRect 
1934 // ---------------------------------------------------------------------------- 
1936 // ---------------------------------------------------------------------------- 
1938 SHORT EXPENTRY 
InternalDataCompareTreeFunc ( 
1944     wxCHECK_MSG( p1 
&& p2
, 0, 
1945                  wxT("sorting tree without data doesn't make sense") ); 
1947     wxTreeCtrl
*                     pTree 
= (wxTreeCtrl
*)pStorage
; 
1949     return pTree
->OnCompareItems( p1
->m_ulItemId
 
1952 } // end of wxTreeSortHelper::Compare 
1954 int wxTreeCtrl::OnCompareItems ( 
1955   const wxTreeItemId
&               rItem1
 
1956 , const wxTreeItemId
&               rItem2
 
1959     return wxStrcmp( GetItemText(rItem1
) 
1960                     ,GetItemText(rItem2
) 
1962 } // end of wxTreeCtrl::OnCompareItems 
1964 void wxTreeCtrl::SortChildren ( 
1965   const wxTreeItemId
&               rItem
 
1968     ::WinSendMsg( GetHWND() 
1970                  ,(PFN
)InternalDataCompareTreeFunc
 
1973 } // end of wxTreeCtrl::SortChildren 
1975 // ---------------------------------------------------------------------------- 
1977 // ---------------------------------------------------------------------------- 
1979 bool wxTreeCtrl::OS2Command ( 
1984     if (uCmd 
== CN_ENDEDIT
) 
1986         wxCommandEvent              
vEvent( wxEVT_COMMAND_TEXT_UPDATED
 
1990         vEvent
.SetEventObject( this ); 
1991         ProcessCommand(vEvent
); 
1994     else if (uCmd 
== CN_KILLFOCUS
) 
1996         wxCommandEvent              
vEvent( wxEVT_KILL_FOCUS
 
1999         vEvent
.SetEventObject( this ); 
2000         ProcessCommand(vEvent
); 
2005 } // end of wxTreeCtrl::OS2Command 
2008 // TODO:  Fully implement direct manipulation when I figure it out 
2010 MRESULT 
wxTreeCtrl::OS2WindowProc ( 
2016     bool                            bProcessed 
= FALSE
; 
2018     wxTreeEvent                     
vEvent( wxEVT_NULL
 
2021     wxEventType                     vEventType 
= wxEVT_NULL
; 
2022     PCNRDRAGINIT                    pDragInit 
= NULL
; 
2023     PCNREDITDATA                    pEditData 
= NULL
; 
2024     PNOTIFYRECORDENTER              pNotifyEnter 
= NULL
; 
2026     vEvent
.SetEventObject(this); 
2030             switch(SHORT2FROMMP(wParam
)) 
2033                     pDragInit 
= (PCNRDRAGINIT
)lParam
; 
2036                         PMYRECORD       pRecord 
= (PMYRECORD
)pDragInit
->pRecord
; 
2038                         vEventType 
= wxEVT_COMMAND_TREE_BEGIN_DRAG
; 
2039                         vEvent
.m_item        
= pRecord
->m_ulItemId
; 
2040                         vEvent
.m_pointDrag
.x 
= pDragInit
->x
; 
2041                         vEvent
.m_pointDrag
.y 
= pDragInit
->y
; 
2046                     pEditData 
= (PCNREDITDATA
)lParam
; 
2049                         PMYRECORD       pRecord 
= (PMYRECORD
)pEditData
->pRecord
; 
2051                         vEventType 
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
; 
2052                         vEvent
.m_item 
= pRecord
->m_ulItemId
; 
2053                         vEvent
.m_label 
= pRecord
->m_vRecord
.pszTree
; 
2054                         vEvent
.m_editCancelled 
= FALSE
; 
2059                     pEditData 
= (PCNREDITDATA
)lParam
; 
2062                         PMYRECORD       pRecord 
= (PMYRECORD
)pEditData
->pRecord
; 
2064                         vEventType 
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
; 
2065                         vEvent
.m_item 
= pRecord
->m_ulItemId
; 
2066                         vEvent
.m_label 
= pRecord
->m_vRecord
.pszTree
; 
2067                         if (pRecord
->m_vRecord
.pszTree 
== NULL
) 
2069                             vEvent
.m_editCancelled 
= TRUE
; 
2073                             vEvent
.m_editCancelled 
= FALSE
; 
2080                         PMYRECORD       pRecord 
= (PMYRECORD
)lParam
; 
2082                         vEventType 
= gs_expandEvents
[IDX_EXPAND
][IDX_DONE
]; 
2083                         vEvent
.m_item 
= pRecord
->m_ulItemId
; 
2087             vEvent
.SetEventType(vEventType
); 
2088             bProcessed 
= GetEventHandler()->ProcessEvent(vEvent
); 
2092         mRc 
= wxControl::OS2WindowProc( uMsg
 
2097 } // end of wxTreeCtrl::OS2WindowProc 
2099 #endif // wxUSE_TREECTRL