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 #if WXWIN_COMPATIBILITY_2_4
550 wxImageList
* wxTreeCtrl::GetImageList(int nVal
) const
552 return GetImageList();
555 void wxTreeCtrl::SetImageList(wxImageList
* pImageList
, int nVal
)
557 SetImageList(pImageList
);
560 int wxTreeCtrl::GetItemSelectedImage(const wxTreeItemId
& rItem
) const
562 return GetItemImage(rItem
, wxTreeItemIcon_Selected
);
565 void wxTreeCtrl::SetItemSelectedImage(const wxTreeItemId
& rItem
, int nImage
)
567 SetItemImage(rItem
, nImage
, wxTreeItemIcon_Selected
);
570 #endif // WXWIN_COMPATIBILITY_2_4
572 wxImageList
* wxTreeCtrl::GetStateImageList () const
574 return m_pImageListNormal
;
575 } // end of wxTreeCtrl::GetStateImageList
578 // The SETS of imagelists really do nothing under OS2 as a RECORDCORE
579 // struct has the icon imbedded in it that it uses for the icon being
580 // displayed via the TREEITEMDESC member. Provided for interface
581 // compatibility only
583 void wxTreeCtrl::SetAnyImageList (
584 wxImageList
* WXUNUSED(pImageList
)
585 , int WXUNUSED(nWhich
)
588 } // end of wxTreeCtrl::SetAnyImageList
590 void wxTreeCtrl::SetImageList (
591 wxImageList
* WXUNUSED(pImageList
)
594 if (m_bOwnsImageListNormal
)
595 delete m_pImageListNormal
;
596 m_bOwnsImageListNormal
= false;
597 } // end of wxTreeCtrl::SetImageList
599 void wxTreeCtrl::SetStateImageList (
600 wxImageList
* WXUNUSED(pImageList
)
603 if (m_bOwnsImageListState
)
604 delete m_pImageListState
;
605 m_bOwnsImageListState
= false;
606 } // end of wxTreeCtrl::SetStateImageList
608 void wxTreeCtrl::AssignImageList (
609 wxImageList
* WXUNUSED(pImageList
)
612 m_bOwnsImageListNormal
= true;
613 } // end of wxTreeCtrl::AssignImageList
615 void wxTreeCtrl::AssignStateImageList (
616 wxImageList
* WXUNUSED(pImageList
)
619 m_bOwnsImageListState
= true;
620 } // end of wxTreeCtrl::AssignStateImageList
622 size_t wxTreeCtrl::GetChildrenCount (
623 const wxTreeItemId
& rItem
627 TraverseCounter
vCounter( this
631 return vCounter
.GetCount() - 1;
632 } // end of wxTreeCtrl::GetChildrenCount
634 // ----------------------------------------------------------------------------
636 // ----------------------------------------------------------------------------
638 bool wxTreeCtrl::SetBackgroundColour (
639 const wxColour
& rColour
642 ULONG ulColor
= wxColourToRGB(rColour
);
644 if ( !wxWindowBase::SetBackgroundColour(rColour
) )
646 ::WinSetPresParam( GetHWND()
652 } // end of wxTreeCtrl::SetBackgroundColour
654 bool wxTreeCtrl::SetForegroundColour (
655 const wxColour
& rColour
658 ULONG ulColor
= wxColourToRGB(rColour
);
660 if (!wxWindowBase::SetForegroundColour(rColour
))
662 ::WinSetPresParam( GetHWND()
668 } // end of wxTreeCtrl::SetForegroundColour
670 // ----------------------------------------------------------------------------
672 // ----------------------------------------------------------------------------
674 wxString
wxTreeCtrl::GetItemText (
675 const wxTreeItemId
& rItem
678 wxChar zBuf
[512]; // the size is arbitrary...
679 wxTreeViewItem
vTvItem(rItem
);
681 if (!DoGetItem(&vTvItem
))
684 // Don't return some garbage which was on stack, but an empty string
689 strcpy(zBuf
, vTvItem
.m_vRecord
.pszTree
);
690 return wxString(zBuf
);
691 } // end of wxTreeCtrl::GetItemText
693 void wxTreeCtrl::SetItemText (
694 const wxTreeItemId
& rItem
695 , const wxString
& rsText
698 wxTreeViewItem
vTvItem(rItem
);
700 vTvItem
.m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str(); // conversion is ok
702 } // end of wxTreeCtrl::SetItemText
705 // These functions under OS/2 PM are not needed. OS/2 containers in tree view
706 // provide for storing a custom expanded and collapsed icons and selected
707 // and non selected icons, natively. For instance, by default, a disk display
708 // will display a tree list of folder icons with "+" icons (collapsed) beside
709 // those folder which contain child members. Double clicking a folder changes
710 // the closed folder icon to an open folder icon with hatched selection
711 // highlighting indicating an ICON view container of the folder is open
712 // elsewhere on the desktop. So the below is not really needed, but we will
713 // simply return the appropriate icon requested out of OS/2's native PM
716 int wxTreeCtrl::DoGetItemImageFromData (
717 const wxTreeItemId
& WXUNUSED(rItem
)
718 , wxTreeItemIcon nWhich
722 // Image handles stored in CNRINFO.
726 ::WinSendMsg( GetHWND()
729 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
733 // We really only have two to chose from. If not custom (set in CNRINFO
734 // then return the handle to system bitmap). OS/2 automatically provides
735 // in_use and selected bitmaps/icons
739 case wxTreeItemIcon_Normal
:
740 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
741 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
742 return vCnrInfo
.hbmCollapsed
;
745 case wxTreeItemIcon_Expanded
:
746 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
747 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
748 return vCnrInfo
.hbmExpanded
;
751 return vCnrInfo
.hbmCollapsed
;
755 void wxTreeCtrl::DoSetItemImageFromData (
756 const wxTreeItemId
& WXUNUSED(rItem
)
758 , wxTreeItemIcon nWhich
762 // Image handles stored in CNRINFO.
766 ::WinSendMsg( GetHWND()
769 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
771 if (nWhich
== wxTreeItemIcon_Normal
)
772 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
773 if (nWhich
== wxTreeItemIcon_Expanded
)
774 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
775 ::WinSendMsg( GetHWND()
778 ,(MPARAM
)CMA_TREEBITMAP
780 } // end of wxTreeCtrl::DoSetItemImageFromData
783 void wxTreeCtrl::DoSetItemImages (
784 const wxTreeItemId
& rItem
789 } // end of wxTreeCtrl::DoSetItemImages
791 int wxTreeCtrl::GetItemImage (
792 const wxTreeItemId
& rItem
793 , wxTreeItemIcon nWhich
796 if (HasIndirectData(rItem
))
798 return DoGetItemImageFromData( rItem
805 ::WinSendMsg( GetHWND()
808 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
813 wxFAIL_MSG( wxT("unknown tree item image type") );
815 case wxTreeItemIcon_Normal
:
816 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
817 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
818 return vCnrInfo
.hbmCollapsed
;
821 case wxTreeItemIcon_Expanded
:
822 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
823 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
824 return vCnrInfo
.hbmExpanded
;
826 case wxTreeItemIcon_Selected
:
827 case wxTreeItemIcon_SelectedExpanded
:
832 void wxTreeCtrl::SetItemImage (
833 const wxTreeItemId
& WXUNUSED(rItem
)
835 , wxTreeItemIcon nWhich
840 ::WinSendMsg( GetHWND()
843 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
847 case wxTreeItemIcon_Normal
:
848 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
851 case wxTreeItemIcon_Expanded
:
852 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
856 wxFAIL_MSG( wxT("unknown tree item image type") );
858 ::WinSendMsg( GetHWND()
861 ,(MPARAM
)CMA_TREEBITMAP
863 } // end of wxTreeCtrl::SetItemImage
865 wxTreeItemData
* wxTreeCtrl::GetItemData (
866 const wxTreeItemId
& rItem
869 wxTreeViewItem
vTvItem(rItem
);
871 if (!DoGetItem(&vTvItem
))
876 return (wxTreeItemData
*)vTvItem
.m_ulUserData
;
877 } // end of wxTreeCtrl::GetItemData
879 void wxTreeCtrl::SetItemData (
880 const wxTreeItemId
& rItem
881 , wxTreeItemData
* pData
885 // first, associate this piece of data with this item
891 wxTreeViewItem
vTvItem(rItem
);
893 vTvItem
.m_ulUserData
= (ULONG
)pData
;
895 } // end of wxTreeCtrl::SetItemData
897 // The following two do nothing under OS/2
898 void wxTreeCtrl::SetIndirectItemData (
899 const wxTreeItemId
& WXUNUSED(rItem
)
900 , wxTreeItemIndirectData
* WXUNUSED(pData
)
903 } // end of wxTreeCtrl::SetIndirectItemData
905 bool wxTreeCtrl::HasIndirectData (
906 const wxTreeItemId
& WXUNUSED(rItem
)
910 } // end of wxTreeCtrl::HasIndirectData
912 // Irreleveant under OS/2 --- item either has child records or it doesn't.
913 void wxTreeCtrl::SetItemHasChildren (
914 const wxTreeItemId
& WXUNUSED(rItem
)
915 , bool WXUNUSED(bHas
)
918 } // end of wxTreeCtrl::SetItemHasChildren
920 // Irreleveant under OS/2 --- function of the font in PM
921 void wxTreeCtrl::SetItemBold (
922 const wxTreeItemId
& WXUNUSED(rItem
)
923 , bool WXUNUSED(bBold
)
926 } // end of wxTreeCtrl::SetItemBold
928 void wxTreeCtrl::SetItemDropHighlight (
929 const wxTreeItemId
& rItem
933 wxTreeViewItem
vTvItem(rItem
);
935 ::WinSendMsg( GetHWND()
936 ,CM_SETRECORDEMPHASIS
938 ,MPFROM2SHORT(bHighlight
, CRA_SELECTED
)
941 } // end of wxTreeCtrl::SetItemDropHighlight
943 void wxTreeCtrl::RefreshItem (
944 const wxTreeItemId
& rItem
947 wxTreeViewItem
vTvItem(rItem
);
950 // This just does a record invalidate causing it to be re-displayed
953 } // end of wxTreeCtrl::RefreshItem
955 wxColour
wxTreeCtrl::GetItemTextColour (
956 const wxTreeItemId
& rItem
959 long lId
= (long)rItem
.m_pItem
;
960 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
966 return pAttr
->GetTextColour();
967 } // end of wxTreeCtrl::GetItemTextColour
969 wxColour
wxTreeCtrl::GetItemBackgroundColour (
970 const wxTreeItemId
& rItem
973 long lId
= (long)rItem
.m_pItem
;
974 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
980 return pAttr
->GetBackgroundColour();
981 } // end of wxTreeCtrl::GetItemBackgroundColour
983 wxFont
wxTreeCtrl::GetItemFont (
984 const wxTreeItemId
& rItem
987 long lId
= (long)rItem
.m_pItem
;
988 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
994 return pAttr
->GetFont();
995 } // end of wxTreeCtrl::GetItemFont
997 void wxTreeCtrl::SetItemTextColour (
998 const wxTreeItemId
& rItem
999 , const wxColour
& rCol
1002 m_bHasAnyAttr
= true;
1004 long lId
= (long)rItem
.m_pItem
;
1005 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1009 pAttr
= new wxTreeItemAttr
;
1010 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1012 pAttr
->SetTextColour(rCol
);
1014 } // end of wxTreeCtrl::SetItemTextColour
1016 void wxTreeCtrl::SetItemBackgroundColour (
1017 const wxTreeItemId
& rItem
1018 , const wxColour
& rCol
1021 m_bHasAnyAttr
= true;
1023 long lId
= (long)rItem
.m_pItem
;
1024 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1028 pAttr
= new wxTreeItemAttr
;
1029 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1031 pAttr
->SetBackgroundColour(rCol
);
1033 } // end of wxTreeCtrl::SetItemBackgroundColour
1035 void wxTreeCtrl::SetItemFont (
1036 const wxTreeItemId
& rItem
1037 , const wxFont
& rFont
1040 m_bHasAnyAttr
= true;
1042 long lId
= (long)rItem
.m_pItem
;
1043 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1047 pAttr
= new wxTreeItemAttr
;
1048 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1050 pAttr
->SetFont(rFont
);
1052 } // end of wxTreeCtrl::SetItemFont
1054 // ----------------------------------------------------------------------------
1056 // ----------------------------------------------------------------------------
1058 bool wxTreeCtrl::IsVisible (
1059 const wxTreeItemId
& rItem
1062 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
1064 RECTL vRectContainer
;
1065 wxRect vWxRectRecord
;
1066 wxRect vWxRectContainer
;
1067 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1070 QUERYRECORDRECT vQuery
;
1072 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1073 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1074 vQuery
.fRightSplitWindow
= FALSE
;
1075 vQuery
.fsExtent
= CMA_TREEICON
;
1077 ::WinSendMsg( GetHWND()
1078 ,CM_QUERYVIEWPORTRECT
1079 ,MPFROMP(&vRectContainer
)
1080 ,MPFROM2SHORT(CMA_WINDOW
, FALSE
)
1082 ::WinSendMsg( GetHWND()
1084 ,MPFROMP(&vRectRecord
)
1087 vWxRectRecord
.SetLeft(vRectRecord
.xLeft
);
1088 vWxRectRecord
.SetTop(vRectRecord
.yTop
);
1089 vWxRectRecord
.SetRight(vRectRecord
.xRight
);
1090 vWxRectRecord
.SetBottom(vRectRecord
.yBottom
);
1092 vWxRectContainer
.SetLeft(vRectContainer
.xLeft
);
1093 vWxRectContainer
.SetTop(vRectContainer
.yTop
);
1094 vWxRectContainer
.SetRight(vRectContainer
.xRight
);
1095 vWxRectContainer
.SetBottom(vRectContainer
.yBottom
);
1096 return (vWxRectContainer
.Inside(wxPoint(vWxRectRecord
.x
, vWxRectRecord
.y
)));
1097 } // end of wxTreeCtrl::IsVisible
1099 bool wxTreeCtrl::ItemHasChildren (
1100 const wxTreeItemId
& rItem
1103 wxTreeViewItem
vTvItem(rItem
);
1104 DoGetItem(&vTvItem
);
1107 // A tree record with children will have one of these attributes
1109 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
||
1110 vTvItem
.m_vRecord
.flRecordAttr
& CRA_COLLAPSED
) != 0;
1113 bool wxTreeCtrl::IsExpanded (
1114 const wxTreeItemId
& rItem
1117 wxTreeViewItem
vTvItem(rItem
);
1118 DoGetItem(&vTvItem
);
1120 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
) != 0;
1121 } // end of wxTreeCtrl::IsExpanded
1123 bool wxTreeCtrl::IsSelected (
1124 const wxTreeItemId
& rItem
1127 wxTreeViewItem
vTvItem(rItem
);
1128 DoGetItem(&vTvItem
);
1130 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
) != 0;
1131 } // end of wxTreeCtrl::IsSelected
1134 bool wxTreeCtrl::IsBold (
1135 const wxTreeItemId
& rItem
1139 } // end of wxTreeCtrl::IsBold
1141 // ----------------------------------------------------------------------------
1143 // ----------------------------------------------------------------------------
1145 wxTreeItemId
wxTreeCtrl::GetRootItem () const
1147 PMYRECORD pRecord
= NULL
;
1149 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1152 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1156 return wxTreeItemId(-1L);
1157 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1158 } // end of wxTreeCtrl::GetRootItem
1160 wxTreeItemId
wxTreeCtrl::GetSelection () const
1162 wxCHECK_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), (long)(WXHTREEITEM
)0,
1163 wxT("this only works with single selection controls") );
1165 PMYRECORD pRecord
= NULL
;
1167 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1168 ,CM_QUERYRECORDEMPHASIS
1170 ,MPARAM(CRA_SELECTED
)
1173 return wxTreeItemId(-1L);
1174 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1175 } // end of wxTreeCtrl::GetSelection
1177 wxTreeItemId
wxTreeCtrl::GetItemParent (
1178 const wxTreeItemId
& rItem
1181 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1186 return wxTreeItemId(-1L);
1187 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1190 ,MPFROM2SHORT(CMA_PARENT
, CMA_ITEMORDER
)
1193 return wxTreeItemId(-1L);
1194 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1195 } // end of wxTreeCtrl::GetItemParent
1197 wxTreeItemId
wxTreeCtrl::GetFirstChild (
1198 const wxTreeItemId
& rItem
1202 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1207 return wxTreeItemId(-1L);
1208 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1211 ,MPFROM2SHORT(CMA_FIRSTCHILD
, CMA_ITEMORDER
)
1214 return wxTreeItemId(-1L);
1216 // Remember the last child returned in 'cookie'
1218 rCookie
= (long)pRecord
->m_ulItemId
;
1219 return wxTreeItemId(rCookie
);
1220 } // end of wxTreeCtrl::GetFirstChild
1222 wxTreeItemId
wxTreeCtrl::GetNextChild (
1223 const wxTreeItemId
& WXUNUSED(rItem
)
1227 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1232 return wxTreeItemId(-1L);
1233 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1236 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1239 return wxTreeItemId(-1L);
1240 rCookie
= (long)pRecord
->m_ulItemId
;
1241 return wxTreeItemId(rCookie
);
1242 } // end of wxTreeCtrl::GetNextChild
1244 wxTreeItemId
wxTreeCtrl::GetLastChild (
1245 const wxTreeItemId
& rItem
1248 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1253 return wxTreeItemId(-1L);
1254 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1257 ,MPFROM2SHORT(CMA_LASTCHILD
, CMA_ITEMORDER
)
1260 return wxTreeItemId(-1L);
1261 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1262 } // end of wxTreeCtrl::GetLastChild
1264 wxTreeItemId
wxTreeCtrl::GetNextSibling (
1265 const wxTreeItemId
& rItem
1268 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1273 return wxTreeItemId(-1L);
1274 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1277 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1280 return wxTreeItemId(-1L);
1281 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1282 } // end of wxTreeCtrl::GetNextSibling
1284 wxTreeItemId
wxTreeCtrl::GetPrevSibling (
1285 const wxTreeItemId
& rItem
1288 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1293 return wxTreeItemId(-1L);
1294 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1297 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1300 return wxTreeItemId(-1L);
1301 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1302 } // end of wxTreeCtrl::GetPrevSibling
1304 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem () const
1306 PMYRECORD pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1309 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1312 return wxTreeItemId(-1L);
1314 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1315 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1318 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1321 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1324 return wxTreeItemId(-1L);
1325 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1326 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1328 return wxTreeItemId(-1L);
1329 } // end of wxTreeCtrl::GetFirstVisibleItem
1331 wxTreeItemId
wxTreeCtrl::GetNextVisible (
1332 const wxTreeItemId
& rItem
1335 wxASSERT_MSG(IsVisible(rItem
), wxT("The item you call GetNextVisible() for must be visible itself!"));
1337 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1342 return wxTreeItemId(-1L);
1345 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1348 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1351 return wxTreeItemId(-1L);
1352 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1353 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1355 return wxTreeItemId(-1L);
1356 } // end of wxTreeCtrl::GetNextVisible
1358 wxTreeItemId
wxTreeCtrl::GetPrevVisible (
1359 const wxTreeItemId
& rItem
1362 wxASSERT_MSG( IsVisible(rItem
), wxT("The item you call GetPrevVisible() for must be visible itself!"));
1364 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1369 return wxTreeItemId(-1L);
1372 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1375 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1378 return wxTreeItemId(-1L);
1379 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1380 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1382 return wxTreeItemId(-1L);
1383 } // end of wxTreeCtrl::GetPrevVisible
1385 // ----------------------------------------------------------------------------
1386 // multiple selections emulation -- under OS/2 checked tree items is not
1387 // supported, but multisel is. So we'll just check for selections here.
1388 // ----------------------------------------------------------------------------
1390 bool wxTreeCtrl::IsItemChecked (
1391 const wxTreeItemId
& rItem
1394 wxTreeViewItem
vTvItem(rItem
);
1396 DoGetItem(&vTvItem
);
1397 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
);
1398 } // end of wxTreeCtrl::IsItemChecked
1400 void wxTreeCtrl::SetItemCheck (
1401 const wxTreeItemId
& rItem
1405 wxTreeViewItem
vTvItem(rItem
);
1407 DoGetItem(&vTvItem
);
1408 ::WinSendMsg( GetHWND()
1409 ,CM_SETRECORDEMPHASIS
1411 ,MPFROM2SHORT(TRUE
, CRA_SELECTED
)
1413 DoSetItem(&vTvItem
);
1414 } // end of wxTreeCtrl::SetItemCheck
1416 size_t wxTreeCtrl::GetSelections (
1417 wxArrayTreeItemIds
& raSelections
1420 TraverseSelections
vSelector( this
1423 return vSelector
.GetCount();
1424 } // end of wxTreeCtrl::GetSelections
1426 // ----------------------------------------------------------------------------
1428 // ----------------------------------------------------------------------------
1430 wxTreeItemId
wxTreeCtrl::DoInsertItem (
1431 const wxTreeItemId
& rParent
1432 , wxTreeItemId vInsertAfter
1433 , const wxString
& rsText
1436 , wxTreeItemData
* pData
1439 PMYRECORD pRecordAfter
= FindOS2TreeRecordByID( GetHWND()
1440 ,vInsertAfter
.m_pItem
1443 PMYRECORD pRecordParent
= FindOS2TreeRecordByID( GetHWND()
1447 PMYRECORD pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1449 ,MPFROMLONG(sizeof(MYRECORD
) - sizeof(RECORDCORE
))
1452 RECORDINSERT vInsert
;
1454 vInsert
.cb
= sizeof(RECORDINSERT
);
1455 if (rParent
.m_pItem
== 0L)
1457 if (vInsertAfter
.m_pItem
== -1)
1458 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1460 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1461 vInsert
.pRecordParent
= NULL
;
1465 if (vInsertAfter
.m_pItem
== 0)
1466 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1467 else if (vInsertAfter
.m_pItem
== -1)
1468 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1470 vInsert
.pRecordOrder
= (PRECORDCORE
)pRecordAfter
;
1471 vInsert
.pRecordParent
= (PRECORDCORE
)pRecordParent
;
1473 vInsert
.fInvalidateRecord
= TRUE
;
1474 vInsert
.zOrder
= CMA_TOP
;
1475 vInsert
.cRecordsInsert
= 1;
1477 pRecord
->m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str();
1478 pRecord
->m_vRecord
.hbmBitmap
= nImage
;
1479 pRecord
->m_ulItemId
= pRecordAfter
->m_ulItemId
+ 1;
1482 pRecord
->m_ulUserData
= (ULONG
)pData
;
1484 ::WinSendMsg( GetHWND()
1491 // OS/2 must mannually bump the index's of following records
1493 BumpTreeRecordIds( GetHWND()
1499 // Associate the application tree item with PM tree item handle
1501 pData
->SetId((long)pRecord
->m_ulItemId
);
1503 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1506 #if WXWIN_COMPATIBILITY_2_4
1508 // for compatibility only
1509 wxTreeItemId
wxTreeCtrl::InsertItem (
1510 const wxTreeItemId
& rParent
1511 , const wxString
& rsText
1517 return DoInsertItem( rParent
1518 ,wxTreeItemId(lInsertAfter
)
1524 } // end of wxTreeCtrl::InsertItem
1526 #endif // WXWIN_COMPATIBILITY_2_4
1528 wxTreeItemId
wxTreeCtrl::AddRoot (
1529 const wxString
& rsText
1531 , int nSelectedImage
1532 , wxTreeItemData
* pData
)
1535 return DoInsertItem( wxTreeItemId((long)0)
1536 ,wxTreeItemId((long)-1)
1542 } // end of wxTreeCtrl::AddRoot
1544 wxTreeItemId
wxTreeCtrl::PrependItem (
1545 const wxTreeItemId
& rParent
1546 , const wxString
& rsText
1548 , int nSelectedImage
1549 , wxTreeItemData
* pData
1552 return DoInsertItem( rParent
1553 ,wxTreeItemId((long)0)
1559 } // end of wxTreeCtrl::PrependItem
1561 wxTreeItemId
wxTreeCtrl::InsertItem (
1562 const wxTreeItemId
& rParent
1563 , const wxTreeItemId
& rIdPrevious
1564 , const wxString
& rsText
1566 , int nSelectedImage
1567 , wxTreeItemData
* pData
1570 return DoInsertItem( rParent
1577 } // end of wxTreeCtrl::InsertItem
1579 wxTreeItemId
wxTreeCtrl::InsertItem (
1580 const wxTreeItemId
& rParent
1582 , const wxString
& rsText
1584 , int nSelectedImage
1585 , wxTreeItemData
* pData
1588 return DoInsertItem( rParent
1589 ,wxTreeItemId((long)nIndex
)
1595 } // end of wxTreeCtrl::InsertItem
1597 wxTreeItemId
wxTreeCtrl::AppendItem (
1598 const wxTreeItemId
& rParent
1599 , const wxString
& rsText
1601 , int nSelectedImage
1602 , wxTreeItemData
* pData
1605 return DoInsertItem( rParent
1606 ,wxTreeItemId((long)-1)
1612 } // end of wxTreeCtrl::AppendItem
1614 void wxTreeCtrl::Delete (
1615 const wxTreeItemId
& rItem
1619 // OS/2 does not generate DELETEITEM events so do it here
1621 wxEventType vEventType
= wxEVT_NULL
;
1622 wxTreeEvent
vEvent( wxEVT_NULL
1625 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1628 vEvent
.SetEventObject(this);
1629 ::WinSendMsg( GetHWND()
1632 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1634 vEvent
.m_item
= rItem
.m_pItem
;
1637 delete (wxTreeItemAttr
*)m_vAttrs
.Delete((long)rItem
.m_pItem
);
1639 vEvent
.SetEventType(vEventType
);
1640 GetEventHandler()->ProcessEvent(vEvent
);
1641 } // end of wxTreeCtrl::Delete
1643 // delete all children (but don't delete the item itself)
1644 void wxTreeCtrl::DeleteChildren (
1645 const wxTreeItemId
& rItem
1649 wxArrayLong aChildren
;
1650 wxTreeItemId vChild
= GetFirstChild( rItem
1654 while (vChild
.IsOk())
1656 aChildren
.Add((long)(WXHTREEITEM
)vChild
);
1657 vChild
= GetNextChild( rItem
1662 size_t nCount
= aChildren
.Count();
1664 for (size_t n
= 0; n
< nCount
; n
++)
1666 Delete(aChildren
[n
]);
1668 } // end of wxTreeCtrl::DeleteChildren
1670 void wxTreeCtrl::DeleteAllItems ()
1672 ::WinSendMsg( GetHWND()
1675 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1677 } // end of wxTreeCtrl::DeleteAllItems
1679 void wxTreeCtrl::DoExpand (
1680 const wxTreeItemId
& rItem
1684 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1689 case wxTREE_EXPAND_EXPAND
:
1690 ::WinSendMsg( GetHWND()
1697 case wxTREE_EXPAND_COLLAPSE
:
1698 ::WinSendMsg( GetHWND()
1705 case wxTREE_EXPAND_COLLAPSE_RESET
:
1706 ::WinSendMsg( GetHWND()
1711 DeleteChildren(rItem
);
1714 case wxTREE_EXPAND_TOGGLE
:
1715 if (pRecord
->m_vRecord
.flRecordAttr
& CRA_COLLAPSED
)
1716 ::WinSendMsg( GetHWND()
1721 else if (pRecord
->m_vRecord
.flRecordAttr
& CRA_EXPANDED
)
1722 ::WinSendMsg( GetHWND()
1730 } // end of wxTreeCtrl::DoExpand
1732 void wxTreeCtrl::Expand (
1733 const wxTreeItemId
& rItem
1737 ,wxTREE_EXPAND_EXPAND
1739 } // end of wxTreeCtrl::Expand
1741 void wxTreeCtrl::Collapse (
1742 const wxTreeItemId
& rItem
1746 ,wxTREE_EXPAND_COLLAPSE
1748 } // end of wxTreeCtrl::Collapse
1750 void wxTreeCtrl::CollapseAndReset (
1751 const wxTreeItemId
& rItem
1755 ,wxTREE_EXPAND_COLLAPSE_RESET
1757 } // end of wxTreeCtrl::CollapseAndReset
1759 void wxTreeCtrl::Toggle (
1760 const wxTreeItemId
& rItem
1764 ,wxTREE_EXPAND_TOGGLE
1766 } // end of wxTreeCtrl::Toggle
1768 #if WXWIN_COMPATIBILITY_2_4
1770 void wxTreeCtrl::ExpandItem (
1771 const wxTreeItemId
& rItem
1778 } // end of wxTreeCtrl::ExpandItem
1780 #endif // WXWIN_COMPATIBILITY_2_4
1782 void wxTreeCtrl::Unselect ()
1784 wxASSERT_MSG( !(m_windowStyle
& wxTR_MULTIPLE
),
1785 wxT("doesn't make sense, may be you want UnselectAll()?") );
1788 // Just remove the selection
1790 SelectItem(wxTreeItemId((long)0));
1791 } // end of wxTreeCtrl::Unselect
1793 void wxTreeCtrl::UnselectAll ()
1795 if (m_windowStyle
& wxTR_MULTIPLE
)
1797 wxArrayTreeItemIds aSelections
;
1798 size_t nCount
= GetSelections(aSelections
);
1800 for (size_t n
= 0; n
< nCount
; n
++)
1802 SetItemCheck( aSelections
[n
]
1810 // Just remove the selection
1814 } // end of wxTreeCtrl::UnselectAll
1816 void wxTreeCtrl::SelectItem (
1817 const wxTreeItemId
& rItem
1820 SetItemCheck(rItem
);
1821 } // end of wxTreeCtrl::SelectItem
1823 void wxTreeCtrl::EnsureVisible (
1824 const wxTreeItemId
& rItem
1827 wxTreeViewItem
vTvItem(rItem
);
1829 DoGetItem(&vTvItem
);
1830 if (!::WinSendMsg( GetHWND()
1831 ,CM_INVALIDATERECORD
1833 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1835 } // end of wxTreeCtrl::EnsureVisible
1837 void wxTreeCtrl::ScrollTo (
1838 const wxTreeItemId
& rItem
1841 wxTreeViewItem
vTvItem(rItem
);
1843 DoGetItem(&vTvItem
);
1844 if (!::WinSendMsg( GetHWND()
1845 ,CM_INVALIDATERECORD
1847 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1851 wxTextCtrl
* wxTreeCtrl::EditLabel (
1852 const wxTreeItemId
& rItem
1853 , wxClassInfo
* WXUNUSED(pTextControlClass
)
1857 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1861 vEdit
.cb
= sizeof(CNREDITDATA
);
1862 vEdit
.hwndCnr
= GetHWND();
1863 vEdit
.pRecord
= &pRecord
->m_vRecord
;
1864 vEdit
.pFieldInfo
= NULL
;
1865 vEdit
.ppszText
= NULL
;
1869 ::WinSendMsg( GetHWND()
1875 } // end of wxTreeCtrl::EditLabel
1877 // End label editing, optionally cancelling the edit
1878 void wxTreeCtrl::EndEditLabel (
1879 const wxTreeItemId
& WXUNUSED(rItem
)
1880 , bool WXUNUSED(bDiscardChanges
)
1883 ::WinSendMsg( GetHWND()
1888 } // end of wxTreeCtrl::EndEditLabel
1890 wxTreeItemId
wxTreeCtrl::HitTest (
1891 const wxPoint
& rPoint
1892 , int& WXUNUSED(rFlags
)
1895 PMYRECORD pRecord
= NULL
;
1896 QUERYRECFROMRECT vQueryRect
;
1901 // Get height for OS/2 point conversion
1903 ::WinSendMsg( GetHWND()
1904 ,CM_QUERYVIEWPORTRECT
1906 ,MPFROM2SHORT(CMA_WINDOW
, TRUE
)
1908 lHeight
= vRect
.yTop
- vRect
.yBottom
;
1911 // For now just try and get a record in the general vicinity and forget
1914 vRect
.xLeft
= rPoint
.x
- 2;
1915 vRect
.xRight
= rPoint
.x
+ 2;
1916 vRect
.yTop
= (lHeight
- rPoint
.y
) + 2;
1917 vRect
.yBottom
= (lHeight
- rPoint
.y
) - 2;
1919 vQueryRect
.cb
= sizeof(QUERYRECFROMRECT
);
1920 vQueryRect
.rect
= vRect
;
1921 vQueryRect
.fsSearch
= CMA_PARTIAL
;
1923 pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1924 ,CM_QUERYRECORDFROMRECT
1926 ,MPFROMP(&vQueryRect
)
1931 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1932 } // end of wxTreeCtrl::HitTest
1934 bool wxTreeCtrl::GetBoundingRect (
1935 const wxTreeItemId
& rItem
1941 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1944 QUERYRECORDRECT vQuery
;
1946 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1947 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1948 vQuery
.fRightSplitWindow
= FALSE
;
1950 vQuery
.fsExtent
= CMA_TEXT
;
1952 vQuery
.fsExtent
= CMA_TREEICON
| CMA_TEXT
;
1954 if (!::WinSendMsg( GetHWND()
1956 ,MPFROMP(&vRectRecord
)
1960 rRect
.SetLeft(vRectRecord
.xLeft
);
1961 rRect
.SetTop(vRectRecord
.yTop
);
1962 rRect
.SetRight(vRectRecord
.xRight
);
1963 rRect
.SetBottom(vRectRecord
.yBottom
);
1965 } // end of wxTreeCtrl::GetBoundingRect
1967 // ----------------------------------------------------------------------------
1969 // ----------------------------------------------------------------------------
1971 SHORT EXPENTRY
InternalDataCompareTreeFunc (
1977 wxCHECK_MSG( p1
&& p2
, 0,
1978 wxT("sorting tree without data doesn't make sense") );
1980 wxTreeCtrl
* pTree
= (wxTreeCtrl
*)pStorage
;
1982 return pTree
->OnCompareItems( p1
->m_ulItemId
1985 } // end of wxTreeSortHelper::Compare
1987 int wxTreeCtrl::OnCompareItems (
1988 const wxTreeItemId
& rItem1
1989 , const wxTreeItemId
& rItem2
1992 return wxStrcmp( GetItemText(rItem1
)
1993 ,GetItemText(rItem2
)
1995 } // end of wxTreeCtrl::OnCompareItems
1997 void wxTreeCtrl::SortChildren (
1998 const wxTreeItemId
& rItem
2001 ::WinSendMsg( GetHWND()
2003 ,(PFN
)InternalDataCompareTreeFunc
2006 } // end of wxTreeCtrl::SortChildren
2008 // ----------------------------------------------------------------------------
2010 // ----------------------------------------------------------------------------
2012 bool wxTreeCtrl::OS2Command (
2017 if (uCmd
== CN_ENDEDIT
)
2019 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
2023 vEvent
.SetEventObject( this );
2024 ProcessCommand(vEvent
);
2027 else if (uCmd
== CN_KILLFOCUS
)
2029 wxCommandEvent
vEvent( wxEVT_KILL_FOCUS
2032 vEvent
.SetEventObject( this );
2033 ProcessCommand(vEvent
);
2038 } // end of wxTreeCtrl::OS2Command
2041 // TODO: Fully implement direct manipulation when I figure it out
2043 MRESULT
wxTreeCtrl::OS2WindowProc (
2049 bool bProcessed
= false;
2051 wxTreeEvent
vEvent( wxEVT_NULL
2054 wxEventType vEventType
= wxEVT_NULL
;
2055 PCNRDRAGINIT pDragInit
= NULL
;
2056 PCNREDITDATA pEditData
= NULL
;
2057 PNOTIFYRECORDENTER pNotifyEnter
= NULL
;
2059 vEvent
.SetEventObject(this);
2063 switch(SHORT2FROMMP(wParam
))
2066 pDragInit
= (PCNRDRAGINIT
)lParam
;
2069 PMYRECORD pRecord
= (PMYRECORD
)pDragInit
->pRecord
;
2071 vEventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
2072 vEvent
.m_item
= pRecord
->m_ulItemId
;
2073 vEvent
.m_pointDrag
.x
= pDragInit
->x
;
2074 vEvent
.m_pointDrag
.y
= pDragInit
->y
;
2079 pEditData
= (PCNREDITDATA
)lParam
;
2082 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2084 vEventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
2085 vEvent
.m_item
= pRecord
->m_ulItemId
;
2086 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2087 vEvent
.m_editCancelled
= false;
2092 pEditData
= (PCNREDITDATA
)lParam
;
2095 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2097 vEventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
2098 vEvent
.m_item
= pRecord
->m_ulItemId
;
2099 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2100 if (pRecord
->m_vRecord
.pszTree
== NULL
)
2102 vEvent
.m_editCancelled
= true;
2106 vEvent
.m_editCancelled
= false;
2113 PMYRECORD pRecord
= (PMYRECORD
)lParam
;
2115 vEventType
= gs_expandEvents
[IDX_EXPAND
][IDX_DONE
];
2116 vEvent
.m_item
= pRecord
->m_ulItemId
;
2120 vEvent
.SetEventType(vEventType
);
2121 bProcessed
= GetEventHandler()->ProcessEvent(vEvent
);
2125 mRc
= wxControl::OS2WindowProc( uMsg
2130 } // end of wxTreeCtrl::OS2WindowProc
2132 #endif // wxUSE_TREECTRL