1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/treectrl.h"
32 #include "wx/dynarray.h"
35 #include "wx/settings.h"
38 #include "wx/os2/private.h"
40 #include "wx/imaglist.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( (HWND
)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 unsigned int wxTreeCtrl::GetCount () const
503 ::WinSendMsg( GetHWND()
506 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
509 return (unsigned int)vCnrInfo
.cRecords
;
510 } // end of wxTreeCtrl::GetCount
512 unsigned int wxTreeCtrl::GetIndent () const
516 ::WinSendMsg( GetHWND()
519 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
521 return (unsigned int)vCnrInfo
.cxTreeIndent
;
522 } // end of wxTreeCtrl::GetIndent
524 void wxTreeCtrl::SetIndent (
530 ::WinSendMsg( GetHWND()
533 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
535 vCnrInfo
.cxTreeIndent
= (LONG
)uIndent
;
536 ::WinSendMsg( GetHWND()
539 ,(MPARAM
)CMA_CXTREEINDENT
541 } // end of wxTreeCtrl::SetIndent
543 wxImageList
* wxTreeCtrl::GetImageList () const
545 return m_pImageListNormal
;
546 } // end of wxTreeCtrl::GetImageList
548 wxImageList
* wxTreeCtrl::GetStateImageList () const
550 return m_pImageListNormal
;
551 } // end of wxTreeCtrl::GetStateImageList
554 // The SETS of imagelists really do nothing under OS2 as a RECORDCORE
555 // struct has the icon imbedded in it that it uses for the icon being
556 // displayed via the TREEITEMDESC member. Provided for interface
557 // compatibility only
559 void wxTreeCtrl::SetAnyImageList (
560 wxImageList
* WXUNUSED(pImageList
)
561 , int WXUNUSED(nWhich
)
564 } // end of wxTreeCtrl::SetAnyImageList
566 void wxTreeCtrl::SetImageList (
567 wxImageList
* WXUNUSED(pImageList
)
570 if (m_bOwnsImageListNormal
)
571 delete m_pImageListNormal
;
572 m_bOwnsImageListNormal
= false;
573 } // end of wxTreeCtrl::SetImageList
575 void wxTreeCtrl::SetStateImageList (
576 wxImageList
* WXUNUSED(pImageList
)
579 if (m_bOwnsImageListState
)
580 delete m_pImageListState
;
581 m_bOwnsImageListState
= false;
582 } // end of wxTreeCtrl::SetStateImageList
584 void wxTreeCtrl::AssignImageList (
585 wxImageList
* WXUNUSED(pImageList
)
588 m_bOwnsImageListNormal
= true;
589 } // end of wxTreeCtrl::AssignImageList
591 void wxTreeCtrl::AssignStateImageList (
592 wxImageList
* WXUNUSED(pImageList
)
595 m_bOwnsImageListState
= true;
596 } // end of wxTreeCtrl::AssignStateImageList
598 size_t wxTreeCtrl::GetChildrenCount (
599 const wxTreeItemId
& rItem
603 TraverseCounter
vCounter( this
607 return vCounter
.GetCount() - 1;
608 } // end of wxTreeCtrl::GetChildrenCount
610 // ----------------------------------------------------------------------------
612 // ----------------------------------------------------------------------------
614 bool wxTreeCtrl::SetBackgroundColour (
615 const wxColour
& rColour
618 ULONG ulColor
= wxColourToRGB(rColour
);
620 if ( !wxWindowBase::SetBackgroundColour(rColour
) )
622 ::WinSetPresParam( GetHWND()
628 } // end of wxTreeCtrl::SetBackgroundColour
630 bool wxTreeCtrl::SetForegroundColour (
631 const wxColour
& rColour
634 ULONG ulColor
= wxColourToRGB(rColour
);
636 if (!wxWindowBase::SetForegroundColour(rColour
))
638 ::WinSetPresParam( GetHWND()
644 } // end of wxTreeCtrl::SetForegroundColour
646 // ----------------------------------------------------------------------------
648 // ----------------------------------------------------------------------------
650 wxString
wxTreeCtrl::GetItemText (
651 const wxTreeItemId
& rItem
654 wxChar zBuf
[512]; // the size is arbitrary...
655 wxTreeViewItem
vTvItem(rItem
);
657 if (!DoGetItem(&vTvItem
))
660 // Don't return some garbage which was on stack, but an empty string
665 strcpy(zBuf
, vTvItem
.m_vRecord
.pszTree
);
666 return wxString(zBuf
);
667 } // end of wxTreeCtrl::GetItemText
669 void wxTreeCtrl::SetItemText (
670 const wxTreeItemId
& rItem
671 , const wxString
& rsText
674 wxTreeViewItem
vTvItem(rItem
);
676 vTvItem
.m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str(); // conversion is ok
678 } // end of wxTreeCtrl::SetItemText
681 // These functions under OS/2 PM are not needed. OS/2 containers in tree view
682 // provide for storing a custom expanded and collapsed icons and selected
683 // and non selected icons, natively. For instance, by default, a disk display
684 // will display a tree list of folder icons with "+" icons (collapsed) beside
685 // those folder which contain child members. Double clicking a folder changes
686 // the closed folder icon to an open folder icon with hatched selection
687 // highlighting indicating an ICON view container of the folder is open
688 // elsewhere on the desktop. So the below is not really needed, but we will
689 // simply return the appropriate icon requested out of OS/2's native PM
692 int wxTreeCtrl::DoGetItemImageFromData (
693 const wxTreeItemId
& WXUNUSED(rItem
)
694 , wxTreeItemIcon nWhich
698 // Image handles stored in CNRINFO.
702 ::WinSendMsg( GetHWND()
705 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
709 // We really only have two to chose from. If not custom (set in CNRINFO
710 // then return the handle to system bitmap). OS/2 automatically provides
711 // in_use and selected bitmaps/icons
715 case wxTreeItemIcon_Normal
:
716 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
717 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
718 return vCnrInfo
.hbmCollapsed
;
721 case wxTreeItemIcon_Expanded
:
722 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
723 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
724 return vCnrInfo
.hbmExpanded
;
727 return vCnrInfo
.hbmCollapsed
;
731 void wxTreeCtrl::DoSetItemImageFromData (
732 const wxTreeItemId
& WXUNUSED(rItem
)
734 , wxTreeItemIcon nWhich
738 // Image handles stored in CNRINFO.
742 ::WinSendMsg( GetHWND()
745 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
747 if (nWhich
== wxTreeItemIcon_Normal
)
748 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
749 if (nWhich
== wxTreeItemIcon_Expanded
)
750 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
751 ::WinSendMsg( GetHWND()
754 ,(MPARAM
)CMA_TREEBITMAP
756 } // end of wxTreeCtrl::DoSetItemImageFromData
759 void wxTreeCtrl::DoSetItemImages (
760 const wxTreeItemId
& rItem
765 } // end of wxTreeCtrl::DoSetItemImages
767 int wxTreeCtrl::GetItemImage (
768 const wxTreeItemId
& rItem
769 , wxTreeItemIcon nWhich
772 if (HasIndirectData(rItem
))
774 return DoGetItemImageFromData( rItem
781 ::WinSendMsg( GetHWND()
784 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
789 wxFAIL_MSG( wxT("unknown tree item image type") );
791 case wxTreeItemIcon_Normal
:
792 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
793 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
794 return vCnrInfo
.hbmCollapsed
;
797 case wxTreeItemIcon_Expanded
:
798 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
799 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
800 return vCnrInfo
.hbmExpanded
;
802 case wxTreeItemIcon_Selected
:
803 case wxTreeItemIcon_SelectedExpanded
:
808 void wxTreeCtrl::SetItemImage (
809 const wxTreeItemId
& WXUNUSED(rItem
)
811 , wxTreeItemIcon nWhich
816 ::WinSendMsg( GetHWND()
819 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
823 case wxTreeItemIcon_Normal
:
824 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
827 case wxTreeItemIcon_Expanded
:
828 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
832 wxFAIL_MSG( wxT("unknown tree item image type") );
834 ::WinSendMsg( GetHWND()
837 ,(MPARAM
)CMA_TREEBITMAP
839 } // end of wxTreeCtrl::SetItemImage
841 wxTreeItemData
* wxTreeCtrl::GetItemData (
842 const wxTreeItemId
& rItem
845 wxTreeViewItem
vTvItem(rItem
);
847 if (!DoGetItem(&vTvItem
))
852 return (wxTreeItemData
*)vTvItem
.m_ulUserData
;
853 } // end of wxTreeCtrl::GetItemData
855 void wxTreeCtrl::SetItemData (
856 const wxTreeItemId
& rItem
857 , wxTreeItemData
* pData
861 // first, associate this piece of data with this item
867 wxTreeViewItem
vTvItem(rItem
);
869 vTvItem
.m_ulUserData
= (ULONG
)pData
;
871 } // end of wxTreeCtrl::SetItemData
873 // The following two do nothing under OS/2
874 void wxTreeCtrl::SetIndirectItemData (
875 const wxTreeItemId
& WXUNUSED(rItem
)
876 , wxTreeItemIndirectData
* WXUNUSED(pData
)
879 } // end of wxTreeCtrl::SetIndirectItemData
881 bool wxTreeCtrl::HasIndirectData (
882 const wxTreeItemId
& WXUNUSED(rItem
)
886 } // end of wxTreeCtrl::HasIndirectData
888 // Irreleveant under OS/2 --- item either has child records or it doesn't.
889 void wxTreeCtrl::SetItemHasChildren (
890 const wxTreeItemId
& WXUNUSED(rItem
)
891 , bool WXUNUSED(bHas
)
894 } // end of wxTreeCtrl::SetItemHasChildren
896 // Irreleveant under OS/2 --- function of the font in PM
897 void wxTreeCtrl::SetItemBold (
898 const wxTreeItemId
& WXUNUSED(rItem
)
899 , bool WXUNUSED(bBold
)
902 } // end of wxTreeCtrl::SetItemBold
904 void wxTreeCtrl::SetItemDropHighlight (
905 const wxTreeItemId
& rItem
909 wxTreeViewItem
vTvItem(rItem
);
911 ::WinSendMsg( GetHWND()
912 ,CM_SETRECORDEMPHASIS
914 ,MPFROM2SHORT(bHighlight
, CRA_SELECTED
)
917 } // end of wxTreeCtrl::SetItemDropHighlight
919 void wxTreeCtrl::RefreshItem (
920 const wxTreeItemId
& rItem
923 wxTreeViewItem
vTvItem(rItem
);
926 // This just does a record invalidate causing it to be re-displayed
929 } // end of wxTreeCtrl::RefreshItem
931 wxColour
wxTreeCtrl::GetItemTextColour (
932 const wxTreeItemId
& rItem
935 long lId
= (long)rItem
.m_pItem
;
936 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
942 return pAttr
->GetTextColour();
943 } // end of wxTreeCtrl::GetItemTextColour
945 wxColour
wxTreeCtrl::GetItemBackgroundColour (
946 const wxTreeItemId
& rItem
949 long lId
= (long)rItem
.m_pItem
;
950 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
956 return pAttr
->GetBackgroundColour();
957 } // end of wxTreeCtrl::GetItemBackgroundColour
959 wxFont
wxTreeCtrl::GetItemFont (
960 const wxTreeItemId
& rItem
963 long lId
= (long)rItem
.m_pItem
;
964 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
970 return pAttr
->GetFont();
971 } // end of wxTreeCtrl::GetItemFont
973 void wxTreeCtrl::SetItemTextColour (
974 const wxTreeItemId
& rItem
975 , const wxColour
& rCol
978 m_bHasAnyAttr
= true;
980 long lId
= (long)rItem
.m_pItem
;
981 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
985 pAttr
= new wxTreeItemAttr
;
986 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
988 pAttr
->SetTextColour(rCol
);
990 } // end of wxTreeCtrl::SetItemTextColour
992 void wxTreeCtrl::SetItemBackgroundColour (
993 const wxTreeItemId
& rItem
994 , const wxColour
& rCol
997 m_bHasAnyAttr
= true;
999 long lId
= (long)rItem
.m_pItem
;
1000 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1004 pAttr
= new wxTreeItemAttr
;
1005 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1007 pAttr
->SetBackgroundColour(rCol
);
1009 } // end of wxTreeCtrl::SetItemBackgroundColour
1011 void wxTreeCtrl::SetItemFont (
1012 const wxTreeItemId
& rItem
1013 , const wxFont
& rFont
1016 m_bHasAnyAttr
= true;
1018 long lId
= (long)rItem
.m_pItem
;
1019 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1023 pAttr
= new wxTreeItemAttr
;
1024 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1026 pAttr
->SetFont(rFont
);
1028 } // end of wxTreeCtrl::SetItemFont
1030 // ----------------------------------------------------------------------------
1032 // ----------------------------------------------------------------------------
1034 bool wxTreeCtrl::IsVisible (
1035 const wxTreeItemId
& rItem
1038 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
1040 RECTL vRectContainer
;
1041 wxRect vWxRectRecord
;
1042 wxRect vWxRectContainer
;
1043 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1046 QUERYRECORDRECT vQuery
;
1048 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1049 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1050 vQuery
.fRightSplitWindow
= FALSE
;
1051 vQuery
.fsExtent
= CMA_TREEICON
;
1053 ::WinSendMsg( GetHWND()
1054 ,CM_QUERYVIEWPORTRECT
1055 ,MPFROMP(&vRectContainer
)
1056 ,MPFROM2SHORT(CMA_WINDOW
, FALSE
)
1058 ::WinSendMsg( GetHWND()
1060 ,MPFROMP(&vRectRecord
)
1063 vWxRectRecord
.SetLeft(vRectRecord
.xLeft
);
1064 vWxRectRecord
.SetTop(vRectRecord
.yTop
);
1065 vWxRectRecord
.SetRight(vRectRecord
.xRight
);
1066 vWxRectRecord
.SetBottom(vRectRecord
.yBottom
);
1068 vWxRectContainer
.SetLeft(vRectContainer
.xLeft
);
1069 vWxRectContainer
.SetTop(vRectContainer
.yTop
);
1070 vWxRectContainer
.SetRight(vRectContainer
.xRight
);
1071 vWxRectContainer
.SetBottom(vRectContainer
.yBottom
);
1072 return (vWxRectContainer
.Contains(wxPoint(vWxRectRecord
.x
, vWxRectRecord
.y
)));
1073 } // end of wxTreeCtrl::IsVisible
1075 bool wxTreeCtrl::ItemHasChildren (
1076 const wxTreeItemId
& rItem
1079 wxTreeViewItem
vTvItem(rItem
);
1080 DoGetItem(&vTvItem
);
1083 // A tree record with children will have one of these attributes
1085 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
||
1086 vTvItem
.m_vRecord
.flRecordAttr
& CRA_COLLAPSED
) != 0;
1089 bool wxTreeCtrl::IsExpanded (
1090 const wxTreeItemId
& rItem
1093 wxTreeViewItem
vTvItem(rItem
);
1094 DoGetItem(&vTvItem
);
1096 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
) != 0;
1097 } // end of wxTreeCtrl::IsExpanded
1099 bool wxTreeCtrl::IsSelected (
1100 const wxTreeItemId
& rItem
1103 wxTreeViewItem
vTvItem(rItem
);
1104 DoGetItem(&vTvItem
);
1106 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
) != 0;
1107 } // end of wxTreeCtrl::IsSelected
1110 bool wxTreeCtrl::IsBold (
1111 const wxTreeItemId
& rItem
1115 } // end of wxTreeCtrl::IsBold
1117 // ----------------------------------------------------------------------------
1119 // ----------------------------------------------------------------------------
1121 wxTreeItemId
wxTreeCtrl::GetRootItem () const
1123 PMYRECORD pRecord
= NULL
;
1125 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1128 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1132 return wxTreeItemId(-1L);
1133 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1134 } // end of wxTreeCtrl::GetRootItem
1136 wxTreeItemId
wxTreeCtrl::GetSelection () const
1138 wxCHECK_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), (long)(WXHTREEITEM
)0,
1139 wxT("this only works with single selection controls") );
1141 PMYRECORD pRecord
= NULL
;
1143 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1144 ,CM_QUERYRECORDEMPHASIS
1146 ,MPARAM(CRA_SELECTED
)
1149 return wxTreeItemId(-1L);
1150 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1151 } // end of wxTreeCtrl::GetSelection
1153 wxTreeItemId
wxTreeCtrl::GetItemParent (
1154 const wxTreeItemId
& rItem
1157 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1162 return wxTreeItemId(-1L);
1163 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1166 ,MPFROM2SHORT(CMA_PARENT
, CMA_ITEMORDER
)
1169 return wxTreeItemId(-1L);
1170 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1171 } // end of wxTreeCtrl::GetItemParent
1173 wxTreeItemId
wxTreeCtrl::GetFirstChild (
1174 const wxTreeItemId
& rItem
1178 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1183 return wxTreeItemId(-1L);
1184 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1187 ,MPFROM2SHORT(CMA_FIRSTCHILD
, CMA_ITEMORDER
)
1190 return wxTreeItemId(-1L);
1192 // Remember the last child returned in 'cookie'
1194 rCookie
= (long)pRecord
->m_ulItemId
;
1195 return wxTreeItemId(rCookie
);
1196 } // end of wxTreeCtrl::GetFirstChild
1198 wxTreeItemId
wxTreeCtrl::GetNextChild (
1199 const wxTreeItemId
& WXUNUSED(rItem
)
1203 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1208 return wxTreeItemId(-1L);
1209 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1212 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1215 return wxTreeItemId(-1L);
1216 rCookie
= (long)pRecord
->m_ulItemId
;
1217 return wxTreeItemId(rCookie
);
1218 } // end of wxTreeCtrl::GetNextChild
1220 wxTreeItemId
wxTreeCtrl::GetLastChild (
1221 const wxTreeItemId
& rItem
1224 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1229 return wxTreeItemId(-1L);
1230 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1233 ,MPFROM2SHORT(CMA_LASTCHILD
, CMA_ITEMORDER
)
1236 return wxTreeItemId(-1L);
1237 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1238 } // end of wxTreeCtrl::GetLastChild
1240 wxTreeItemId
wxTreeCtrl::GetNextSibling (
1241 const wxTreeItemId
& rItem
1244 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1249 return wxTreeItemId(-1L);
1250 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1253 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1256 return wxTreeItemId(-1L);
1257 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1258 } // end of wxTreeCtrl::GetNextSibling
1260 wxTreeItemId
wxTreeCtrl::GetPrevSibling (
1261 const wxTreeItemId
& rItem
1264 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1269 return wxTreeItemId(-1L);
1270 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1273 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1276 return wxTreeItemId(-1L);
1277 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1278 } // end of wxTreeCtrl::GetPrevSibling
1280 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem () const
1282 PMYRECORD pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1285 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1288 return wxTreeItemId(-1L);
1290 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1291 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1294 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1297 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1300 return wxTreeItemId(-1L);
1301 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1302 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1304 return wxTreeItemId(-1L);
1305 } // end of wxTreeCtrl::GetFirstVisibleItem
1307 wxTreeItemId
wxTreeCtrl::GetNextVisible (
1308 const wxTreeItemId
& rItem
1311 wxASSERT_MSG(IsVisible(rItem
), wxT("The item you call GetNextVisible() for must be visible itself!"));
1313 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1318 return wxTreeItemId(-1L);
1321 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1324 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1327 return wxTreeItemId(-1L);
1328 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1329 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1331 return wxTreeItemId(-1L);
1332 } // end of wxTreeCtrl::GetNextVisible
1334 wxTreeItemId
wxTreeCtrl::GetPrevVisible (
1335 const wxTreeItemId
& rItem
1338 wxASSERT_MSG( IsVisible(rItem
), wxT("The item you call GetPrevVisible() for must be visible itself!"));
1340 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1345 return wxTreeItemId(-1L);
1348 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1351 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1354 return wxTreeItemId(-1L);
1355 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1356 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1358 return wxTreeItemId(-1L);
1359 } // end of wxTreeCtrl::GetPrevVisible
1361 // ----------------------------------------------------------------------------
1362 // multiple selections emulation -- under OS/2 checked tree items is not
1363 // supported, but multisel is. So we'll just check for selections here.
1364 // ----------------------------------------------------------------------------
1366 bool wxTreeCtrl::IsItemChecked (
1367 const wxTreeItemId
& rItem
1370 wxTreeViewItem
vTvItem(rItem
);
1372 DoGetItem(&vTvItem
);
1373 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
);
1374 } // end of wxTreeCtrl::IsItemChecked
1376 void wxTreeCtrl::SetItemCheck (
1377 const wxTreeItemId
& rItem
1381 wxTreeViewItem
vTvItem(rItem
);
1383 DoGetItem(&vTvItem
);
1384 ::WinSendMsg( GetHWND()
1385 ,CM_SETRECORDEMPHASIS
1387 ,MPFROM2SHORT(TRUE
, CRA_SELECTED
)
1389 DoSetItem(&vTvItem
);
1390 } // end of wxTreeCtrl::SetItemCheck
1392 size_t wxTreeCtrl::GetSelections (
1393 wxArrayTreeItemIds
& raSelections
1396 TraverseSelections
vSelector( this
1399 return vSelector
.GetCount();
1400 } // end of wxTreeCtrl::GetSelections
1402 // ----------------------------------------------------------------------------
1404 // ----------------------------------------------------------------------------
1406 wxTreeItemId
wxTreeCtrl::DoInsertItem (
1407 const wxTreeItemId
& rParent
1408 , wxTreeItemId vInsertAfter
1409 , const wxString
& rsText
1412 , wxTreeItemData
* pData
1415 PMYRECORD pRecordAfter
= FindOS2TreeRecordByID( GetHWND()
1416 ,vInsertAfter
.m_pItem
1419 PMYRECORD pRecordParent
= FindOS2TreeRecordByID( GetHWND()
1423 PMYRECORD pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1425 ,MPFROMLONG(sizeof(MYRECORD
) - sizeof(RECORDCORE
))
1428 RECORDINSERT vInsert
;
1430 vInsert
.cb
= sizeof(RECORDINSERT
);
1431 if (rParent
.m_pItem
== 0L)
1433 if (vInsertAfter
.m_pItem
== -1)
1434 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1436 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1437 vInsert
.pRecordParent
= NULL
;
1441 if (vInsertAfter
.m_pItem
== 0)
1442 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1443 else if (vInsertAfter
.m_pItem
== -1)
1444 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1446 vInsert
.pRecordOrder
= (PRECORDCORE
)pRecordAfter
;
1447 vInsert
.pRecordParent
= (PRECORDCORE
)pRecordParent
;
1449 vInsert
.fInvalidateRecord
= TRUE
;
1450 vInsert
.zOrder
= CMA_TOP
;
1451 vInsert
.cRecordsInsert
= 1;
1453 pRecord
->m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str();
1454 pRecord
->m_vRecord
.hbmBitmap
= nImage
;
1455 pRecord
->m_ulItemId
= pRecordAfter
->m_ulItemId
+ 1;
1458 pRecord
->m_ulUserData
= (ULONG
)pData
;
1460 ::WinSendMsg( GetHWND()
1467 // OS/2 must mannually bump the index's of following records
1469 BumpTreeRecordIds( GetHWND()
1475 // Associate the application tree item with PM tree item handle
1477 pData
->SetId((long)pRecord
->m_ulItemId
);
1479 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1482 wxTreeItemId
wxTreeCtrl::AddRoot (
1483 const wxString
& rsText
1485 , int nSelectedImage
1486 , wxTreeItemData
* pData
)
1489 return DoInsertItem( wxTreeItemId((long)0)
1490 ,wxTreeItemId((long)-1)
1496 } // end of wxTreeCtrl::AddRoot
1498 wxTreeItemId
wxTreeCtrl::PrependItem (
1499 const wxTreeItemId
& rParent
1500 , const wxString
& rsText
1502 , int nSelectedImage
1503 , wxTreeItemData
* pData
1506 return DoInsertItem( rParent
1507 ,wxTreeItemId((long)0)
1513 } // end of wxTreeCtrl::PrependItem
1515 wxTreeItemId
wxTreeCtrl::InsertItem (
1516 const wxTreeItemId
& rParent
1517 , const wxTreeItemId
& rIdPrevious
1518 , const wxString
& rsText
1520 , int nSelectedImage
1521 , wxTreeItemData
* pData
1524 return DoInsertItem( rParent
1531 } // end of wxTreeCtrl::InsertItem
1533 wxTreeItemId
wxTreeCtrl::InsertItem (
1534 const wxTreeItemId
& rParent
1536 , const wxString
& rsText
1538 , int nSelectedImage
1539 , wxTreeItemData
* pData
1542 return DoInsertItem( rParent
1543 ,wxTreeItemId((long)nIndex
)
1549 } // end of wxTreeCtrl::InsertItem
1551 wxTreeItemId
wxTreeCtrl::AppendItem (
1552 const wxTreeItemId
& rParent
1553 , const wxString
& rsText
1555 , int nSelectedImage
1556 , wxTreeItemData
* pData
1559 return DoInsertItem( rParent
1560 ,wxTreeItemId((long)-1)
1566 } // end of wxTreeCtrl::AppendItem
1568 void wxTreeCtrl::Delete (
1569 const wxTreeItemId
& rItem
1573 // OS/2 does not generate DELETEITEM events so do it here
1575 wxEventType vEventType
= wxEVT_NULL
;
1576 wxTreeEvent
vEvent( wxEVT_NULL
1579 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1582 vEvent
.SetEventObject(this);
1583 ::WinSendMsg( GetHWND()
1586 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1588 vEvent
.m_item
= rItem
.m_pItem
;
1591 delete (wxTreeItemAttr
*)m_vAttrs
.Delete((long)rItem
.m_pItem
);
1593 vEvent
.SetEventType(vEventType
);
1594 GetEventHandler()->ProcessEvent(vEvent
);
1595 } // end of wxTreeCtrl::Delete
1597 // delete all children (but don't delete the item itself)
1598 void wxTreeCtrl::DeleteChildren (
1599 const wxTreeItemId
& rItem
1603 wxArrayLong aChildren
;
1604 wxTreeItemId vChild
= GetFirstChild( rItem
1608 while (vChild
.IsOk())
1610 aChildren
.Add((long)(WXHTREEITEM
)vChild
);
1611 vChild
= GetNextChild( rItem
1616 size_t nCount
= aChildren
.Count();
1618 for (size_t n
= 0; n
< nCount
; n
++)
1620 Delete(aChildren
[n
]);
1622 } // end of wxTreeCtrl::DeleteChildren
1624 void wxTreeCtrl::DeleteAllItems ()
1626 ::WinSendMsg( GetHWND()
1629 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1631 } // end of wxTreeCtrl::DeleteAllItems
1633 void wxTreeCtrl::DoExpand (
1634 const wxTreeItemId
& rItem
1638 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1643 case wxTREE_EXPAND_EXPAND
:
1644 ::WinSendMsg( GetHWND()
1651 case wxTREE_EXPAND_COLLAPSE
:
1652 ::WinSendMsg( GetHWND()
1659 case wxTREE_EXPAND_COLLAPSE_RESET
:
1660 ::WinSendMsg( GetHWND()
1665 DeleteChildren(rItem
);
1668 case wxTREE_EXPAND_TOGGLE
:
1669 if (pRecord
->m_vRecord
.flRecordAttr
& CRA_COLLAPSED
)
1670 ::WinSendMsg( GetHWND()
1675 else if (pRecord
->m_vRecord
.flRecordAttr
& CRA_EXPANDED
)
1676 ::WinSendMsg( GetHWND()
1684 } // end of wxTreeCtrl::DoExpand
1686 void wxTreeCtrl::Expand (
1687 const wxTreeItemId
& rItem
1691 ,wxTREE_EXPAND_EXPAND
1693 } // end of wxTreeCtrl::Expand
1695 void wxTreeCtrl::Collapse (
1696 const wxTreeItemId
& rItem
1700 ,wxTREE_EXPAND_COLLAPSE
1702 } // end of wxTreeCtrl::Collapse
1704 void wxTreeCtrl::CollapseAndReset (
1705 const wxTreeItemId
& rItem
1709 ,wxTREE_EXPAND_COLLAPSE_RESET
1711 } // end of wxTreeCtrl::CollapseAndReset
1713 void wxTreeCtrl::Toggle (
1714 const wxTreeItemId
& rItem
1718 ,wxTREE_EXPAND_TOGGLE
1720 } // end of wxTreeCtrl::Toggle
1722 void wxTreeCtrl::Unselect ()
1724 wxASSERT_MSG( !(m_windowStyle
& wxTR_MULTIPLE
),
1725 wxT("doesn't make sense, may be you want UnselectAll()?") );
1728 // Just remove the selection
1730 SelectItem(wxTreeItemId((long)0));
1731 } // end of wxTreeCtrl::Unselect
1733 void wxTreeCtrl::UnselectAll ()
1735 if (m_windowStyle
& wxTR_MULTIPLE
)
1737 wxArrayTreeItemIds aSelections
;
1738 size_t nCount
= GetSelections(aSelections
);
1740 for (size_t n
= 0; n
< nCount
; n
++)
1742 SetItemCheck( aSelections
[n
]
1750 // Just remove the selection
1754 } // end of wxTreeCtrl::UnselectAll
1756 void wxTreeCtrl::SelectItem (
1757 const wxTreeItemId
& rItem
1760 SetItemCheck(rItem
);
1761 } // end of wxTreeCtrl::SelectItem
1763 void wxTreeCtrl::EnsureVisible (
1764 const wxTreeItemId
& rItem
1767 wxTreeViewItem
vTvItem(rItem
);
1769 DoGetItem(&vTvItem
);
1770 if (!::WinSendMsg( GetHWND()
1771 ,CM_INVALIDATERECORD
1773 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1775 } // end of wxTreeCtrl::EnsureVisible
1777 void wxTreeCtrl::ScrollTo (
1778 const wxTreeItemId
& rItem
1781 wxTreeViewItem
vTvItem(rItem
);
1783 DoGetItem(&vTvItem
);
1784 if (!::WinSendMsg( GetHWND()
1785 ,CM_INVALIDATERECORD
1787 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1791 wxTextCtrl
* wxTreeCtrl::EditLabel (
1792 const wxTreeItemId
& rItem
1793 , wxClassInfo
* WXUNUSED(pTextControlClass
)
1797 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1801 vEdit
.cb
= sizeof(CNREDITDATA
);
1802 vEdit
.hwndCnr
= GetHWND();
1803 vEdit
.pRecord
= &pRecord
->m_vRecord
;
1804 vEdit
.pFieldInfo
= NULL
;
1805 vEdit
.ppszText
= NULL
;
1809 ::WinSendMsg( GetHWND()
1815 } // end of wxTreeCtrl::EditLabel
1817 // End label editing, optionally cancelling the edit
1818 void wxTreeCtrl::EndEditLabel (
1819 const wxTreeItemId
& WXUNUSED(rItem
)
1820 , bool WXUNUSED(bDiscardChanges
)
1823 ::WinSendMsg( GetHWND()
1828 } // end of wxTreeCtrl::EndEditLabel
1830 wxTreeItemId
wxTreeCtrl::HitTest (
1831 const wxPoint
& rPoint
1832 , int& WXUNUSED(rFlags
)
1835 PMYRECORD pRecord
= NULL
;
1836 QUERYRECFROMRECT vQueryRect
;
1841 // Get height for OS/2 point conversion
1843 ::WinSendMsg( GetHWND()
1844 ,CM_QUERYVIEWPORTRECT
1846 ,MPFROM2SHORT(CMA_WINDOW
, TRUE
)
1848 lHeight
= vRect
.yTop
- vRect
.yBottom
;
1851 // For now just try and get a record in the general vicinity and forget
1854 vRect
.xLeft
= rPoint
.x
- 2;
1855 vRect
.xRight
= rPoint
.x
+ 2;
1856 vRect
.yTop
= (lHeight
- rPoint
.y
) + 2;
1857 vRect
.yBottom
= (lHeight
- rPoint
.y
) - 2;
1859 vQueryRect
.cb
= sizeof(QUERYRECFROMRECT
);
1860 vQueryRect
.rect
= vRect
;
1861 vQueryRect
.fsSearch
= CMA_PARTIAL
;
1863 pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1864 ,CM_QUERYRECORDFROMRECT
1866 ,MPFROMP(&vQueryRect
)
1871 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1872 } // end of wxTreeCtrl::HitTest
1874 bool wxTreeCtrl::GetBoundingRect (
1875 const wxTreeItemId
& rItem
1881 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1884 QUERYRECORDRECT vQuery
;
1886 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1887 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1888 vQuery
.fRightSplitWindow
= FALSE
;
1890 vQuery
.fsExtent
= CMA_TEXT
;
1892 vQuery
.fsExtent
= CMA_TREEICON
| CMA_TEXT
;
1894 if (!::WinSendMsg( GetHWND()
1896 ,MPFROMP(&vRectRecord
)
1900 rRect
.SetLeft(vRectRecord
.xLeft
);
1901 rRect
.SetTop(vRectRecord
.yTop
);
1902 rRect
.SetRight(vRectRecord
.xRight
);
1903 rRect
.SetBottom(vRectRecord
.yBottom
);
1905 } // end of wxTreeCtrl::GetBoundingRect
1907 // ----------------------------------------------------------------------------
1909 // ----------------------------------------------------------------------------
1911 SHORT EXPENTRY
InternalDataCompareTreeFunc (
1917 wxCHECK_MSG( p1
&& p2
, 0,
1918 wxT("sorting tree without data doesn't make sense") );
1920 wxTreeCtrl
* pTree
= (wxTreeCtrl
*)pStorage
;
1922 return pTree
->OnCompareItems( p1
->m_ulItemId
1925 } // end of wxTreeSortHelper::Compare
1927 int wxTreeCtrl::OnCompareItems (
1928 const wxTreeItemId
& rItem1
1929 , const wxTreeItemId
& rItem2
1932 return wxStrcmp( GetItemText(rItem1
)
1933 ,GetItemText(rItem2
)
1935 } // end of wxTreeCtrl::OnCompareItems
1937 void wxTreeCtrl::SortChildren (
1938 const wxTreeItemId
& rItem
1941 ::WinSendMsg( GetHWND()
1943 ,(PFN
)InternalDataCompareTreeFunc
1946 } // end of wxTreeCtrl::SortChildren
1948 // ----------------------------------------------------------------------------
1950 // ----------------------------------------------------------------------------
1952 bool wxTreeCtrl::OS2Command (
1957 if (uCmd
== CN_ENDEDIT
)
1959 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
1963 vEvent
.SetEventObject( this );
1964 ProcessCommand(vEvent
);
1967 else if (uCmd
== CN_KILLFOCUS
)
1969 wxCommandEvent
vEvent( wxEVT_KILL_FOCUS
1972 vEvent
.SetEventObject( this );
1973 ProcessCommand(vEvent
);
1978 } // end of wxTreeCtrl::OS2Command
1981 // TODO: Fully implement direct manipulation when I figure it out
1983 MRESULT
wxTreeCtrl::OS2WindowProc (
1989 bool bProcessed
= false;
1991 wxTreeEvent
vEvent( wxEVT_NULL
1994 wxEventType vEventType
= wxEVT_NULL
;
1995 PCNRDRAGINIT pDragInit
= NULL
;
1996 PCNREDITDATA pEditData
= NULL
;
1997 PNOTIFYRECORDENTER pNotifyEnter
= NULL
;
1999 vEvent
.SetEventObject(this);
2003 switch(SHORT2FROMMP(wParam
))
2006 pDragInit
= (PCNRDRAGINIT
)lParam
;
2009 PMYRECORD pRecord
= (PMYRECORD
)pDragInit
->pRecord
;
2011 vEventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
2012 vEvent
.m_item
= pRecord
->m_ulItemId
;
2013 vEvent
.m_pointDrag
.x
= pDragInit
->x
;
2014 vEvent
.m_pointDrag
.y
= pDragInit
->y
;
2019 pEditData
= (PCNREDITDATA
)lParam
;
2022 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2024 vEventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
2025 vEvent
.m_item
= pRecord
->m_ulItemId
;
2026 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2027 vEvent
.m_editCancelled
= false;
2032 pEditData
= (PCNREDITDATA
)lParam
;
2035 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2037 vEventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
2038 vEvent
.m_item
= pRecord
->m_ulItemId
;
2039 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2040 if (pRecord
->m_vRecord
.pszTree
== NULL
)
2042 vEvent
.m_editCancelled
= true;
2046 vEvent
.m_editCancelled
= false;
2053 PMYRECORD pRecord
= (PMYRECORD
)lParam
;
2055 vEventType
= gs_expandEvents
[IDX_EXPAND
][IDX_DONE
];
2056 vEvent
.m_item
= pRecord
->m_ulItemId
;
2060 vEvent
.SetEventType(vEventType
);
2061 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
2065 mRc
= wxControl::OS2WindowProc( uMsg
2070 } // end of wxTreeCtrl::OS2WindowProc
2072 #endif // wxUSE_TREECTRL