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
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
28 #include "wx/treectrl.h"
31 #include "wx/dynarray.h"
34 #include "wx/settings.h"
37 #include "wx/os2/private.h"
39 #include "wx/imaglist.h"
41 // a macro to hide the ugliness of nested casts
42 #define HITEM(item) (HTREEITEM)(WXHTREEITEM)(item)
44 // the native control doesn't support multiple selections under MSW and we
45 // have 2 ways to emulate them: either using TVS_CHECKBOXES style and let
46 // checkboxes be the selection status (checked == selected) or by really
47 // emulating everything, i.e. intercepting mouse and key events &c. The first
48 // approach is much easier but doesn't work with comctl32.dll < 4.71 and also
50 #define wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE 0
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 typedef struct _MYRECORD
65 } MYRECORD
, *PMYRECORD
;
67 struct wxTreeViewItem
: public MYRECORD
69 wxTreeViewItem(const wxTreeItemId
& rItem
)
71 m_ulItemId
= (ULONG
)rItem
.m_pItem
;
73 }; // end of STRUCT wxTreeViewItem
75 class wxTreeItemInternalData
79 wxTreeItemInternalData() {}
80 ~wxTreeItemInternalData()
85 wxTreeItemAttr
* m_pAttr
;
86 WXLPARAM m_lParam
; // user data
87 #if defined(C_CM_COS232)
88 PMYRECORD m_pMyRecord
; // so we can set the m_ulUserData to 0 when this is deleted
90 }; // end of CLASS wxTreeItemInternalData
92 void BumpTreeRecordIds (
99 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
102 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
105 pRecord
->m_ulItemId
++;
107 } // end of BumpTreeRecordIds
109 PMYRECORD
FindOS2TreeRecordByID (
114 PMYRECORD pRecord
= NULL
;
118 if (!::WinSendMsg( hWnd
121 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
124 for (i
= 0; i
< vCnrInfo
.cRecords
; i
++)
127 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
130 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
133 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( hWnd
136 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
140 if (pRecord
->m_ulItemId
== (ULONG
)lItemId
)
144 } // end of FindOS2ListRecordByID
148 class wxTreeTraversal
151 wxTreeTraversal(const wxTreeCtrl
* pTree
)
157 // Do traverse the tree: visit all items (recursively by default) under the
158 // given one; return true if all items were traversed or false if the
159 // traversal was aborted because OnVisit returned false
161 bool DoTraverse( const wxTreeItemId
& rRoot
162 ,bool bRecursively
= true
166 // Override this function to do whatever is needed for each item, return
167 // false to stop traversing
169 virtual bool OnVisit(const wxTreeItemId
& rItem
) = 0;
172 const wxTreeCtrl
* GetTree(void) const { return m_pTree
; }
175 bool Traverse( const wxTreeItemId
& rRoot
179 const wxTreeCtrl
* m_pTree
;
180 wxDECLARE_NO_COPY_CLASS(wxTreeTraversal
);
181 }; // end of CLASS wxTreeTraversal
184 // Internal class for getting the selected items
186 class TraverseSelections
: public wxTreeTraversal
189 TraverseSelections( const wxTreeCtrl
* pTree
190 ,wxArrayTreeItemIds
& raSelections
192 : wxTreeTraversal(pTree
)
193 , m_aSelections(raSelections
)
195 m_aSelections
.Empty();
196 DoTraverse(pTree
->GetRootItem());
199 virtual bool OnVisit(const wxTreeItemId
& rItem
)
202 // Can't visit a virtual node.
204 if ((GetTree()->GetRootItem() == rItem
) && (GetTree()->GetWindowStyle() & wxTR_HIDE_ROOT
))
208 PMYRECORD pRecord
= FindOS2TreeRecordByID( (HWND
)GetTree()->GetHWND()
211 if (pRecord
->m_vRecord
.flRecordAttr
& CRA_SELECTED
)
213 m_aSelections
.Add(rItem
);
218 size_t GetCount(void) const { return m_aSelections
.GetCount(); }
221 wxArrayTreeItemIds
& m_aSelections
;
222 }; // end of CLASS TraverseSelections
225 // Internal class for counting tree items
227 class TraverseCounter
: public wxTreeTraversal
230 TraverseCounter( const wxTreeCtrl
* pTree
231 ,const wxTreeItemId
& rRoot
234 : wxTreeTraversal(pTree
)
237 DoTraverse(rRoot
, bRecursively
);
240 virtual bool OnVisit(const wxTreeItemId
& WXUNUSED(rItem
))
246 size_t GetCount(void) const { return m_nCount
; }
250 }; // end of CLASS TraverseCounter
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
256 // ----------------------------------------------------------------------------
258 // ----------------------------------------------------------------------------
260 // indices in gs_expandEvents table below
275 // handy table for sending events - it has to be initialized during run-time
276 // now so can't be const any more
277 static /* const */ wxEventType gs_expandEvents
[IDX_WHAT_MAX
][IDX_HOW_MAX
];
280 but logically it's a const table with the following entries:
283 { wxEVT_TREE_ITEM_COLLAPSED, wxEVT_TREE_ITEM_COLLAPSING },
284 { wxEVT_TREE_ITEM_EXPANDED, wxEVT_TREE_ITEM_EXPANDING }
288 // ============================================================================
290 // ============================================================================
292 // ----------------------------------------------------------------------------
294 // ----------------------------------------------------------------------------
296 bool wxTreeTraversal::DoTraverse (
297 const wxTreeItemId
& rRoot
304 return Traverse( rRoot
307 } // end of wxTreeTraversal::DoTraverse
309 bool wxTreeTraversal::Traverse (
310 const wxTreeItemId
& rRoot
315 wxTreeItemId vChild
= m_pTree
->GetFirstChild( rRoot
318 while (vChild
.IsOk())
321 // Depth first traversal
323 if (bRecursively
&& !Traverse(vChild
, true))
325 if (!OnVisit(vChild
))
327 vChild
= m_pTree
->GetNextChild( rRoot
332 } // end of wxTreeTraversal::Traverse
334 // ----------------------------------------------------------------------------
335 // construction and destruction
336 // ----------------------------------------------------------------------------
338 void wxTreeCtrl::Init ()
340 m_pImageListNormal
= NULL
;
341 m_pImageListState
= NULL
;
342 m_bOwnsImageListNormal
= false;
343 m_bOwnsImageListState
= false;
344 m_bHasAnyAttr
= false;
348 // Initialize the global array of events now as it can't be done statically
349 // with the wxEVT_XXX values being allocated during run-time only
351 gs_expandEvents
[IDX_COLLAPSE
][IDX_DONE
] = wxEVT_TREE_ITEM_COLLAPSED
;
352 gs_expandEvents
[IDX_COLLAPSE
][IDX_DOING
] = wxEVT_TREE_ITEM_COLLAPSING
;
353 gs_expandEvents
[IDX_EXPAND
][IDX_DONE
] = wxEVT_TREE_ITEM_EXPANDED
;
354 gs_expandEvents
[IDX_EXPAND
][IDX_DOING
] = wxEVT_TREE_ITEM_EXPANDING
;
355 } // end of wxTreeCtrl::Init
357 bool wxTreeCtrl::Create (
360 , const wxPoint
& rPos
361 , const wxSize
& rSize
363 , const wxValidator
& rValidator
364 , const wxString
& rsName
370 if (!CreateControl( pParent
380 DWORD dwStyle
= WS_VISIBLE
| WS_TABSTOP
;
382 if (m_windowStyle
& wxCLIP_SIBLINGS
)
383 dwStyle
|= WS_CLIPSIBLINGS
;
385 // Create the tree control.
386 if (!OS2CreateControl( "CONTAINER"
392 // Now set the display attributes to show a TREE/ICON view of the
395 if (!::WinSendMsg( GetHWND()
398 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
401 vCnrInfo
.flWindowAttr
= CV_TREE
|CV_ICON
;
402 vCnrInfo
.flWindowAttr
|= CA_DRAWBITMAP
;
403 if (m_windowStyle
& wxTR_NO_LINES
)
404 vCnrInfo
.flWindowAttr
|= CA_TREELINE
;
406 ::WinSendMsg( GetHWND()
409 ,(MPARAM
)CMA_FLWINDOWATTR
412 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
413 SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
414 SetFont(*wxSMALL_FONT
);
423 } // end of wxTreeCtrl::Create
425 wxTreeCtrl::~wxTreeCtrl ()
428 // Delete any attributes
432 for (wxNode
* pNode
= m_vAttrs
.Next(); pNode
; pNode
= m_vAttrs
.Next())
434 delete (wxTreeItemAttr
*)pNode
->Data();
436 m_bHasAnyAttr
= false;
441 // Delete user data to prevent memory leaks
442 // also deletes hidden root node storage.
445 if (m_bOwnsImageListNormal
)
446 delete m_pImageListNormal
;
447 if (m_bOwnsImageListState
)
448 delete m_pImageListState
;
449 } // end of wxTreeCtrl::~wxTreeCtrl
451 // ----------------------------------------------------------------------------
453 // ----------------------------------------------------------------------------
456 // simple wrappers which add error checking in debug mode. These methods
457 // assume the items are properly filled out already. If not, you get errors
459 bool wxTreeCtrl::DoGetItem (
460 wxTreeViewItem
* pTvItem
463 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
469 wxLogLastError(wxT("Item not obtained"));
473 } // end of wxTreeCtrl::DoGetItem
475 void wxTreeCtrl::DoSetItem (
476 wxTreeViewItem
* pTvItem
480 // Just invalidate the record to redisplay it
482 if (!::WinSendMsg( GetHWND()
485 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
488 wxLogLastError(wxT("CM_INVALIDATERECORD"));
490 } // end of wxTreeCtrl::DoSetItem
492 unsigned int wxTreeCtrl::GetCount () const
496 ::WinSendMsg( GetHWND()
499 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
502 return (unsigned int)vCnrInfo
.cRecords
;
503 } // end of wxTreeCtrl::GetCount
505 unsigned int wxTreeCtrl::GetIndent () const
509 ::WinSendMsg( GetHWND()
512 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
514 return (unsigned int)vCnrInfo
.cxTreeIndent
;
515 } // end of wxTreeCtrl::GetIndent
517 void wxTreeCtrl::SetIndent (
523 ::WinSendMsg( GetHWND()
526 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
528 vCnrInfo
.cxTreeIndent
= (LONG
)uIndent
;
529 ::WinSendMsg( GetHWND()
532 ,(MPARAM
)CMA_CXTREEINDENT
534 } // end of wxTreeCtrl::SetIndent
536 wxImageList
* wxTreeCtrl::GetImageList () const
538 return m_pImageListNormal
;
539 } // end of wxTreeCtrl::GetImageList
541 wxImageList
* wxTreeCtrl::GetStateImageList () const
543 return m_pImageListNormal
;
544 } // end of wxTreeCtrl::GetStateImageList
547 // The SETS of imagelists really do nothing under OS2 as a RECORDCORE
548 // struct has the icon imbedded in it that it uses for the icon being
549 // displayed via the TREEITEMDESC member. Provided for interface
550 // compatibility only
552 void wxTreeCtrl::SetAnyImageList (
553 wxImageList
* WXUNUSED(pImageList
)
554 , int WXUNUSED(nWhich
)
557 } // end of wxTreeCtrl::SetAnyImageList
559 void wxTreeCtrl::SetImageList (
560 wxImageList
* WXUNUSED(pImageList
)
563 if (m_bOwnsImageListNormal
)
564 delete m_pImageListNormal
;
565 m_bOwnsImageListNormal
= false;
566 } // end of wxTreeCtrl::SetImageList
568 void wxTreeCtrl::SetStateImageList (
569 wxImageList
* WXUNUSED(pImageList
)
572 if (m_bOwnsImageListState
)
573 delete m_pImageListState
;
574 m_bOwnsImageListState
= false;
575 } // end of wxTreeCtrl::SetStateImageList
577 void wxTreeCtrl::AssignImageList (
578 wxImageList
* WXUNUSED(pImageList
)
581 m_bOwnsImageListNormal
= true;
582 } // end of wxTreeCtrl::AssignImageList
584 void wxTreeCtrl::AssignStateImageList (
585 wxImageList
* WXUNUSED(pImageList
)
588 m_bOwnsImageListState
= true;
589 } // end of wxTreeCtrl::AssignStateImageList
591 size_t wxTreeCtrl::GetChildrenCount (
592 const wxTreeItemId
& rItem
596 TraverseCounter
vCounter( this
600 return vCounter
.GetCount() - 1;
601 } // end of wxTreeCtrl::GetChildrenCount
603 // ----------------------------------------------------------------------------
605 // ----------------------------------------------------------------------------
607 bool wxTreeCtrl::SetBackgroundColour (
608 const wxColour
& rColour
611 ULONG ulColor
= wxColourToRGB(rColour
);
613 if ( !wxWindowBase::SetBackgroundColour(rColour
) )
615 ::WinSetPresParam( GetHWND()
621 } // end of wxTreeCtrl::SetBackgroundColour
623 bool wxTreeCtrl::SetForegroundColour (
624 const wxColour
& rColour
627 ULONG ulColor
= wxColourToRGB(rColour
);
629 if (!wxWindowBase::SetForegroundColour(rColour
))
631 ::WinSetPresParam( GetHWND()
637 } // end of wxTreeCtrl::SetForegroundColour
639 // ----------------------------------------------------------------------------
641 // ----------------------------------------------------------------------------
643 wxString
wxTreeCtrl::GetItemText (
644 const wxTreeItemId
& rItem
647 wxChar zBuf
[512]; // the size is arbitrary...
648 wxTreeViewItem
vTvItem(rItem
);
650 if (!DoGetItem(&vTvItem
))
653 // Don't return some garbage which was on stack, but an empty string
658 strcpy(zBuf
, vTvItem
.m_vRecord
.pszTree
);
659 return wxString(zBuf
);
660 } // end of wxTreeCtrl::GetItemText
662 void wxTreeCtrl::SetItemText (
663 const wxTreeItemId
& rItem
664 , const wxString
& rsText
667 wxTreeViewItem
vTvItem(rItem
);
669 vTvItem
.m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str(); // conversion is ok
671 } // end of wxTreeCtrl::SetItemText
674 // These functions under OS/2 PM are not needed. OS/2 containers in tree view
675 // provide for storing a custom expanded and collapsed icons and selected
676 // and non selected icons, natively. For instance, by default, a disk display
677 // will display a tree list of folder icons with "+" icons (collapsed) beside
678 // those folder which contain child members. Double clicking a folder changes
679 // the closed folder icon to an open folder icon with hatched selection
680 // highlighting indicating an ICON view container of the folder is open
681 // elsewhere on the desktop. So the below is not really needed, but we will
682 // simply return the appropriate icon requested out of OS/2's native PM
685 int wxTreeCtrl::DoGetItemImageFromData (
686 const wxTreeItemId
& WXUNUSED(rItem
)
687 , wxTreeItemIcon nWhich
691 // Image handles stored in CNRINFO.
695 ::WinSendMsg( GetHWND()
698 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
702 // We really only have two to chose from. If not custom (set in CNRINFO
703 // then return the handle to system bitmap). OS/2 automatically provides
704 // in_use and selected bitmaps/icons
708 case wxTreeItemIcon_Normal
:
709 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
710 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
711 return vCnrInfo
.hbmCollapsed
;
714 case wxTreeItemIcon_Expanded
:
715 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
716 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
717 return vCnrInfo
.hbmExpanded
;
720 return vCnrInfo
.hbmCollapsed
;
724 void wxTreeCtrl::DoSetItemImageFromData (
725 const wxTreeItemId
& WXUNUSED(rItem
)
727 , wxTreeItemIcon nWhich
731 // Image handles stored in CNRINFO.
735 ::WinSendMsg( GetHWND()
738 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
740 if (nWhich
== wxTreeItemIcon_Normal
)
741 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
742 if (nWhich
== wxTreeItemIcon_Expanded
)
743 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
744 ::WinSendMsg( GetHWND()
747 ,(MPARAM
)CMA_TREEBITMAP
749 } // end of wxTreeCtrl::DoSetItemImageFromData
752 void wxTreeCtrl::DoSetItemImages (
753 const wxTreeItemId
& rItem
758 } // end of wxTreeCtrl::DoSetItemImages
760 int wxTreeCtrl::GetItemImage (
761 const wxTreeItemId
& rItem
762 , wxTreeItemIcon nWhich
765 if (HasIndirectData(rItem
))
767 return DoGetItemImageFromData( rItem
774 ::WinSendMsg( GetHWND()
777 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
782 wxFAIL_MSG( wxT("unknown tree item image type") );
784 case wxTreeItemIcon_Normal
:
785 if (vCnrInfo
.hbmCollapsed
== NULLHANDLE
)
786 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEPLUS
);
787 return vCnrInfo
.hbmCollapsed
;
790 case wxTreeItemIcon_Expanded
:
791 if (vCnrInfo
.hbmExpanded
== NULLHANDLE
)
792 return (int)::WinGetSysBitmap(HWND_DESKTOP
, SBMP_TREEMINUS
);
793 return vCnrInfo
.hbmExpanded
;
795 case wxTreeItemIcon_Selected
:
796 case wxTreeItemIcon_SelectedExpanded
:
801 void wxTreeCtrl::SetItemImage (
802 const wxTreeItemId
& WXUNUSED(rItem
)
804 , wxTreeItemIcon nWhich
809 ::WinSendMsg( GetHWND()
812 ,(MPARAM
)(USHORT
)sizeof(CNRINFO
)
816 case wxTreeItemIcon_Normal
:
817 vCnrInfo
.hbmCollapsed
= (HBITMAP
)nImage
;
820 case wxTreeItemIcon_Expanded
:
821 vCnrInfo
.hbmExpanded
= (HBITMAP
)nImage
;
825 wxFAIL_MSG( wxT("unknown tree item image type") );
827 ::WinSendMsg( GetHWND()
830 ,(MPARAM
)CMA_TREEBITMAP
832 } // end of wxTreeCtrl::SetItemImage
834 wxTreeItemData
* wxTreeCtrl::GetItemData (
835 const wxTreeItemId
& rItem
838 wxTreeViewItem
vTvItem(rItem
);
840 if (!DoGetItem(&vTvItem
))
845 return (wxTreeItemData
*)vTvItem
.m_ulUserData
;
846 } // end of wxTreeCtrl::GetItemData
848 void wxTreeCtrl::SetItemData (
849 const wxTreeItemId
& rItem
850 , wxTreeItemData
* pData
854 // first, associate this piece of data with this item
860 wxTreeViewItem
vTvItem(rItem
);
862 vTvItem
.m_ulUserData
= (ULONG
)pData
;
864 } // end of wxTreeCtrl::SetItemData
866 // The following two do nothing under OS/2
867 void wxTreeCtrl::SetIndirectItemData (
868 const wxTreeItemId
& WXUNUSED(rItem
)
869 , wxTreeItemIndirectData
* WXUNUSED(pData
)
872 } // end of wxTreeCtrl::SetIndirectItemData
874 bool wxTreeCtrl::HasIndirectData (
875 const wxTreeItemId
& WXUNUSED(rItem
)
879 } // end of wxTreeCtrl::HasIndirectData
881 // Irreleveant under OS/2 --- item either has child records or it doesn't.
882 void wxTreeCtrl::SetItemHasChildren (
883 const wxTreeItemId
& WXUNUSED(rItem
)
884 , bool WXUNUSED(bHas
)
887 } // end of wxTreeCtrl::SetItemHasChildren
889 // Irreleveant under OS/2 --- function of the font in PM
890 void wxTreeCtrl::SetItemBold (
891 const wxTreeItemId
& WXUNUSED(rItem
)
892 , bool WXUNUSED(bBold
)
895 } // end of wxTreeCtrl::SetItemBold
897 void wxTreeCtrl::SetItemDropHighlight (
898 const wxTreeItemId
& rItem
902 wxTreeViewItem
vTvItem(rItem
);
904 ::WinSendMsg( GetHWND()
905 ,CM_SETRECORDEMPHASIS
907 ,MPFROM2SHORT(bHighlight
, CRA_SELECTED
)
910 } // end of wxTreeCtrl::SetItemDropHighlight
912 void wxTreeCtrl::RefreshItem (
913 const wxTreeItemId
& rItem
916 wxTreeViewItem
vTvItem(rItem
);
919 // This just does a record invalidate causing it to be re-displayed
922 } // end of wxTreeCtrl::RefreshItem
924 wxColour
wxTreeCtrl::GetItemTextColour (
925 const wxTreeItemId
& rItem
928 long lId
= (long)rItem
.m_pItem
;
929 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
935 return pAttr
->GetTextColour();
936 } // end of wxTreeCtrl::GetItemTextColour
938 wxColour
wxTreeCtrl::GetItemBackgroundColour (
939 const wxTreeItemId
& rItem
942 long lId
= (long)rItem
.m_pItem
;
943 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
949 return pAttr
->GetBackgroundColour();
950 } // end of wxTreeCtrl::GetItemBackgroundColour
952 wxFont
wxTreeCtrl::GetItemFont (
953 const wxTreeItemId
& rItem
956 long lId
= (long)rItem
.m_pItem
;
957 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
963 return pAttr
->GetFont();
964 } // end of wxTreeCtrl::GetItemFont
966 void wxTreeCtrl::SetItemTextColour (
967 const wxTreeItemId
& rItem
968 , const wxColour
& rCol
971 m_bHasAnyAttr
= true;
973 long lId
= (long)rItem
.m_pItem
;
974 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
978 pAttr
= new wxTreeItemAttr
;
979 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
981 pAttr
->SetTextColour(rCol
);
983 } // end of wxTreeCtrl::SetItemTextColour
985 void wxTreeCtrl::SetItemBackgroundColour (
986 const wxTreeItemId
& rItem
987 , const wxColour
& rCol
990 m_bHasAnyAttr
= true;
992 long lId
= (long)rItem
.m_pItem
;
993 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
997 pAttr
= new wxTreeItemAttr
;
998 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1000 pAttr
->SetBackgroundColour(rCol
);
1002 } // end of wxTreeCtrl::SetItemBackgroundColour
1004 void wxTreeCtrl::SetItemFont (
1005 const wxTreeItemId
& rItem
1006 , const wxFont
& rFont
1009 m_bHasAnyAttr
= true;
1011 long lId
= (long)rItem
.m_pItem
;
1012 wxTreeItemAttr
* pAttr
= (wxTreeItemAttr
*)m_vAttrs
.Get(lId
);
1016 pAttr
= new wxTreeItemAttr
;
1017 m_vAttrs
.Put(lId
, (wxObject
*)pAttr
);
1019 pAttr
->SetFont(rFont
);
1021 } // end of wxTreeCtrl::SetItemFont
1023 // ----------------------------------------------------------------------------
1025 // ----------------------------------------------------------------------------
1027 bool wxTreeCtrl::IsVisible (
1028 const wxTreeItemId
& rItem
1031 // Bug in Gnu-Win32 headers, so don't use the macro TreeView_GetItemRect
1033 RECTL vRectContainer
;
1034 wxRect vWxRectRecord
;
1035 wxRect vWxRectContainer
;
1036 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1039 QUERYRECORDRECT vQuery
;
1041 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1042 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1043 vQuery
.fRightSplitWindow
= FALSE
;
1044 vQuery
.fsExtent
= CMA_TREEICON
;
1046 ::WinSendMsg( GetHWND()
1047 ,CM_QUERYVIEWPORTRECT
1048 ,MPFROMP(&vRectContainer
)
1049 ,MPFROM2SHORT(CMA_WINDOW
, FALSE
)
1051 ::WinSendMsg( GetHWND()
1053 ,MPFROMP(&vRectRecord
)
1056 vWxRectRecord
.SetLeft(vRectRecord
.xLeft
);
1057 vWxRectRecord
.SetTop(vRectRecord
.yTop
);
1058 vWxRectRecord
.SetRight(vRectRecord
.xRight
);
1059 vWxRectRecord
.SetBottom(vRectRecord
.yBottom
);
1061 vWxRectContainer
.SetLeft(vRectContainer
.xLeft
);
1062 vWxRectContainer
.SetTop(vRectContainer
.yTop
);
1063 vWxRectContainer
.SetRight(vRectContainer
.xRight
);
1064 vWxRectContainer
.SetBottom(vRectContainer
.yBottom
);
1065 return (vWxRectContainer
.Contains(wxPoint(vWxRectRecord
.x
, vWxRectRecord
.y
)));
1066 } // end of wxTreeCtrl::IsVisible
1068 bool wxTreeCtrl::ItemHasChildren (
1069 const wxTreeItemId
& rItem
1072 wxTreeViewItem
vTvItem(rItem
);
1073 DoGetItem(&vTvItem
);
1076 // A tree record with children will have one of these attributes
1078 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
||
1079 vTvItem
.m_vRecord
.flRecordAttr
& CRA_COLLAPSED
) != 0;
1082 bool wxTreeCtrl::IsExpanded (
1083 const wxTreeItemId
& rItem
1086 wxTreeViewItem
vTvItem(rItem
);
1087 DoGetItem(&vTvItem
);
1089 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_EXPANDED
) != 0;
1090 } // end of wxTreeCtrl::IsExpanded
1092 bool wxTreeCtrl::IsSelected (
1093 const wxTreeItemId
& rItem
1096 wxTreeViewItem
vTvItem(rItem
);
1097 DoGetItem(&vTvItem
);
1099 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
) != 0;
1100 } // end of wxTreeCtrl::IsSelected
1103 bool wxTreeCtrl::IsBold (
1104 const wxTreeItemId
& rItem
1108 } // end of wxTreeCtrl::IsBold
1110 // ----------------------------------------------------------------------------
1112 // ----------------------------------------------------------------------------
1114 wxTreeItemId
wxTreeCtrl::GetRootItem () const
1116 PMYRECORD pRecord
= NULL
;
1118 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1121 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1125 return wxTreeItemId(-1L);
1126 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1127 } // end of wxTreeCtrl::GetRootItem
1129 wxTreeItemId
wxTreeCtrl::GetSelection () const
1131 wxCHECK_MSG( !(m_windowStyle
& wxTR_MULTIPLE
), (long)(WXHTREEITEM
)0,
1132 wxT("this only works with single selection controls") );
1134 PMYRECORD pRecord
= NULL
;
1136 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1137 ,CM_QUERYRECORDEMPHASIS
1139 ,MPARAM(CRA_SELECTED
)
1142 return wxTreeItemId(-1L);
1143 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1144 } // end of wxTreeCtrl::GetSelection
1146 wxTreeItemId
wxTreeCtrl::GetItemParent (
1147 const wxTreeItemId
& rItem
1150 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1155 return wxTreeItemId(-1L);
1156 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1159 ,MPFROM2SHORT(CMA_PARENT
, CMA_ITEMORDER
)
1162 return wxTreeItemId(-1L);
1163 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1164 } // end of wxTreeCtrl::GetItemParent
1166 wxTreeItemId
wxTreeCtrl::GetFirstChild (
1167 const wxTreeItemId
& rItem
1171 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1176 return wxTreeItemId(-1L);
1177 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1180 ,MPFROM2SHORT(CMA_FIRSTCHILD
, CMA_ITEMORDER
)
1183 return wxTreeItemId(-1L);
1185 // Remember the last child returned in 'cookie'
1187 rCookie
= (long)pRecord
->m_ulItemId
;
1188 return wxTreeItemId(rCookie
);
1189 } // end of wxTreeCtrl::GetFirstChild
1191 wxTreeItemId
wxTreeCtrl::GetNextChild (
1192 const wxTreeItemId
& WXUNUSED(rItem
)
1196 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1201 return wxTreeItemId(-1L);
1202 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1205 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1208 return wxTreeItemId(-1L);
1209 rCookie
= (long)pRecord
->m_ulItemId
;
1210 return wxTreeItemId(rCookie
);
1211 } // end of wxTreeCtrl::GetNextChild
1213 wxTreeItemId
wxTreeCtrl::GetLastChild (
1214 const wxTreeItemId
& rItem
1217 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1222 return wxTreeItemId(-1L);
1223 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1226 ,MPFROM2SHORT(CMA_LASTCHILD
, CMA_ITEMORDER
)
1229 return wxTreeItemId(-1L);
1230 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1231 } // end of wxTreeCtrl::GetLastChild
1233 wxTreeItemId
wxTreeCtrl::GetNextSibling (
1234 const wxTreeItemId
& rItem
1237 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1242 return wxTreeItemId(-1L);
1243 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1246 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1249 return wxTreeItemId(-1L);
1250 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1251 } // end of wxTreeCtrl::GetNextSibling
1253 wxTreeItemId
wxTreeCtrl::GetPrevSibling (
1254 const wxTreeItemId
& rItem
1257 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1262 return wxTreeItemId(-1L);
1263 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1266 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1269 return wxTreeItemId(-1L);
1270 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1271 } // end of wxTreeCtrl::GetPrevSibling
1273 wxTreeItemId
wxTreeCtrl::GetFirstVisibleItem () const
1275 PMYRECORD pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1278 ,MPFROM2SHORT(CMA_FIRST
, CMA_ITEMORDER
)
1281 return wxTreeItemId(-1L);
1283 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1284 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1287 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1290 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1293 return wxTreeItemId(-1L);
1294 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1295 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1297 return wxTreeItemId(-1L);
1298 } // end of wxTreeCtrl::GetFirstVisibleItem
1300 wxTreeItemId
wxTreeCtrl::GetNextVisible (
1301 const wxTreeItemId
& rItem
1304 wxASSERT_MSG(IsVisible(rItem
), wxT("The item you call GetNextVisible() for must be visible itself!"));
1306 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1311 return wxTreeItemId(-1L);
1314 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1317 ,MPFROM2SHORT(CMA_NEXT
, CMA_ITEMORDER
)
1320 return wxTreeItemId(-1L);
1321 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1322 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1324 return wxTreeItemId(-1L);
1325 } // end of wxTreeCtrl::GetNextVisible
1327 wxTreeItemId
wxTreeCtrl::GetPrevVisible (
1328 const wxTreeItemId
& rItem
1331 wxASSERT_MSG( IsVisible(rItem
), wxT("The item you call GetPrevVisible() for must be visible itself!"));
1333 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1338 return wxTreeItemId(-1L);
1341 pRecord
= (PMYRECORD
)PVOIDFROMMR(::WinSendMsg( GetHWND()
1344 ,MPFROM2SHORT(CMA_PREV
, CMA_ITEMORDER
)
1347 return wxTreeItemId(-1L);
1348 if (IsVisible(wxTreeItemId((long)pRecord
->m_ulItemId
)))
1349 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1351 return wxTreeItemId(-1L);
1352 } // end of wxTreeCtrl::GetPrevVisible
1354 // ----------------------------------------------------------------------------
1355 // multiple selections emulation -- under OS/2 checked tree items is not
1356 // supported, but multisel is. So we'll just check for selections here.
1357 // ----------------------------------------------------------------------------
1359 bool wxTreeCtrl::IsItemChecked (
1360 const wxTreeItemId
& rItem
1363 wxTreeViewItem
vTvItem(rItem
);
1365 DoGetItem(&vTvItem
);
1366 return (vTvItem
.m_vRecord
.flRecordAttr
& CRA_SELECTED
);
1367 } // end of wxTreeCtrl::IsItemChecked
1369 void wxTreeCtrl::SetItemCheck (
1370 const wxTreeItemId
& rItem
1374 wxTreeViewItem
vTvItem(rItem
);
1376 DoGetItem(&vTvItem
);
1377 ::WinSendMsg( GetHWND()
1378 ,CM_SETRECORDEMPHASIS
1380 ,MPFROM2SHORT(TRUE
, CRA_SELECTED
)
1382 DoSetItem(&vTvItem
);
1383 } // end of wxTreeCtrl::SetItemCheck
1385 size_t wxTreeCtrl::GetSelections (
1386 wxArrayTreeItemIds
& raSelections
1389 TraverseSelections
vSelector( this
1392 return vSelector
.GetCount();
1393 } // end of wxTreeCtrl::GetSelections
1395 // ----------------------------------------------------------------------------
1397 // ----------------------------------------------------------------------------
1399 wxTreeItemId
wxTreeCtrl::DoInsertItem (
1400 const wxTreeItemId
& rParent
1401 , wxTreeItemId vInsertAfter
1402 , const wxString
& rsText
1405 , wxTreeItemData
* pData
1408 PMYRECORD pRecordAfter
= FindOS2TreeRecordByID( GetHWND()
1409 ,vInsertAfter
.m_pItem
1412 PMYRECORD pRecordParent
= FindOS2TreeRecordByID( GetHWND()
1416 PMYRECORD pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1418 ,MPFROMLONG(sizeof(MYRECORD
) - sizeof(RECORDCORE
))
1421 RECORDINSERT vInsert
;
1423 vInsert
.cb
= sizeof(RECORDINSERT
);
1424 if (rParent
.m_pItem
== 0L)
1426 if (vInsertAfter
.m_pItem
== -1)
1427 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1429 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1430 vInsert
.pRecordParent
= NULL
;
1434 if (vInsertAfter
.m_pItem
== 0)
1435 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_FIRST
;
1436 else if (vInsertAfter
.m_pItem
== -1)
1437 vInsert
.pRecordOrder
= (PRECORDCORE
)CMA_END
;
1439 vInsert
.pRecordOrder
= (PRECORDCORE
)pRecordAfter
;
1440 vInsert
.pRecordParent
= (PRECORDCORE
)pRecordParent
;
1442 vInsert
.fInvalidateRecord
= TRUE
;
1443 vInsert
.zOrder
= CMA_TOP
;
1444 vInsert
.cRecordsInsert
= 1;
1446 pRecord
->m_vRecord
.pszTree
= (wxChar
*)rsText
.c_str();
1447 pRecord
->m_vRecord
.hbmBitmap
= nImage
;
1448 pRecord
->m_ulItemId
= pRecordAfter
->m_ulItemId
+ 1;
1451 pRecord
->m_ulUserData
= (ULONG
)pData
;
1453 ::WinSendMsg( GetHWND()
1460 // OS/2 must mannually bump the index's of following records
1462 BumpTreeRecordIds( GetHWND()
1468 // Associate the application tree item with PM tree item handle
1470 pData
->SetId((long)pRecord
->m_ulItemId
);
1472 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1475 wxTreeItemId
wxTreeCtrl::AddRoot (
1476 const wxString
& rsText
1478 , int nSelectedImage
1479 , wxTreeItemData
* pData
)
1482 return DoInsertItem( wxTreeItemId((long)0)
1483 ,wxTreeItemId((long)-1)
1489 } // end of wxTreeCtrl::AddRoot
1491 wxTreeItemId
wxTreeCtrl::PrependItem (
1492 const wxTreeItemId
& rParent
1493 , const wxString
& rsText
1495 , int nSelectedImage
1496 , wxTreeItemData
* pData
1499 return DoInsertItem( rParent
1500 ,wxTreeItemId((long)0)
1506 } // end of wxTreeCtrl::PrependItem
1508 wxTreeItemId
wxTreeCtrl::InsertItem (
1509 const wxTreeItemId
& rParent
1510 , const wxTreeItemId
& rIdPrevious
1511 , const wxString
& rsText
1513 , int nSelectedImage
1514 , wxTreeItemData
* pData
1517 return DoInsertItem( rParent
1524 } // end of wxTreeCtrl::InsertItem
1526 wxTreeItemId
wxTreeCtrl::InsertItem (
1527 const wxTreeItemId
& rParent
1529 , const wxString
& rsText
1531 , int nSelectedImage
1532 , wxTreeItemData
* pData
1535 return DoInsertItem( rParent
1536 ,wxTreeItemId((long)nIndex
)
1542 } // end of wxTreeCtrl::InsertItem
1544 wxTreeItemId
wxTreeCtrl::AppendItem (
1545 const wxTreeItemId
& rParent
1546 , const wxString
& rsText
1548 , int nSelectedImage
1549 , wxTreeItemData
* pData
1552 return DoInsertItem( rParent
1553 ,wxTreeItemId((long)-1)
1559 } // end of wxTreeCtrl::AppendItem
1561 void wxTreeCtrl::Delete (
1562 const wxTreeItemId
& rItem
1566 // OS/2 does not generate DELETEITEM events so do it here
1568 wxEventType vEventType
= wxEVT_NULL
;
1569 wxTreeEvent
vEvent( wxEVT_NULL
1572 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1575 vEvent
.SetEventObject(this);
1576 ::WinSendMsg( GetHWND()
1579 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1581 vEvent
.m_item
= rItem
.m_pItem
;
1584 delete (wxTreeItemAttr
*)m_vAttrs
.Delete((long)rItem
.m_pItem
);
1586 vEvent
.SetEventType(vEventType
);
1587 HandleWindowEvent(vEvent
);
1588 } // end of wxTreeCtrl::Delete
1590 // delete all children (but don't delete the item itself)
1591 void wxTreeCtrl::DeleteChildren (
1592 const wxTreeItemId
& rItem
1596 wxArrayLong aChildren
;
1597 wxTreeItemId vChild
= GetFirstChild( rItem
1601 while (vChild
.IsOk())
1603 aChildren
.Add((long)(WXHTREEITEM
)vChild
);
1604 vChild
= GetNextChild( rItem
1609 size_t nCount
= aChildren
.Count();
1611 for (size_t n
= 0; n
< nCount
; n
++)
1613 Delete(aChildren
[n
]);
1615 } // end of wxTreeCtrl::DeleteChildren
1617 void wxTreeCtrl::DeleteAllItems ()
1619 ::WinSendMsg( GetHWND()
1622 ,(MPARAM
)(CMA_FREE
| CMA_INVALIDATE
)
1624 } // end of wxTreeCtrl::DeleteAllItems
1626 void wxTreeCtrl::DoExpand (
1627 const wxTreeItemId
& rItem
1631 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1636 case wxTREE_EXPAND_EXPAND
:
1637 ::WinSendMsg( GetHWND()
1644 case wxTREE_EXPAND_COLLAPSE
:
1645 ::WinSendMsg( GetHWND()
1652 case wxTREE_EXPAND_COLLAPSE_RESET
:
1653 ::WinSendMsg( GetHWND()
1658 DeleteChildren(rItem
);
1661 case wxTREE_EXPAND_TOGGLE
:
1662 if (pRecord
->m_vRecord
.flRecordAttr
& CRA_COLLAPSED
)
1663 ::WinSendMsg( GetHWND()
1668 else if (pRecord
->m_vRecord
.flRecordAttr
& CRA_EXPANDED
)
1669 ::WinSendMsg( GetHWND()
1677 } // end of wxTreeCtrl::DoExpand
1679 void wxTreeCtrl::Expand (
1680 const wxTreeItemId
& rItem
1684 ,wxTREE_EXPAND_EXPAND
1686 } // end of wxTreeCtrl::Expand
1688 void wxTreeCtrl::Collapse (
1689 const wxTreeItemId
& rItem
1693 ,wxTREE_EXPAND_COLLAPSE
1695 } // end of wxTreeCtrl::Collapse
1697 void wxTreeCtrl::CollapseAndReset (
1698 const wxTreeItemId
& rItem
1702 ,wxTREE_EXPAND_COLLAPSE_RESET
1704 } // end of wxTreeCtrl::CollapseAndReset
1706 void wxTreeCtrl::Toggle (
1707 const wxTreeItemId
& rItem
1711 ,wxTREE_EXPAND_TOGGLE
1713 } // end of wxTreeCtrl::Toggle
1715 void wxTreeCtrl::Unselect ()
1717 wxASSERT_MSG( !(m_windowStyle
& wxTR_MULTIPLE
),
1718 wxT("doesn't make sense, may be you want UnselectAll()?") );
1721 // Just remove the selection
1723 SelectItem(wxTreeItemId((long)0));
1724 } // end of wxTreeCtrl::Unselect
1726 void wxTreeCtrl::UnselectAll ()
1728 if (m_windowStyle
& wxTR_MULTIPLE
)
1730 wxArrayTreeItemIds aSelections
;
1731 size_t nCount
= GetSelections(aSelections
);
1733 for (size_t n
= 0; n
< nCount
; n
++)
1735 SetItemCheck( aSelections
[n
]
1743 // Just remove the selection
1747 } // end of wxTreeCtrl::UnselectAll
1749 void wxTreeCtrl::SelectItem (
1750 const wxTreeItemId
& rItem
1753 SetItemCheck(rItem
);
1754 } // end of wxTreeCtrl::SelectItem
1756 void wxTreeCtrl::EnsureVisible (
1757 const wxTreeItemId
& rItem
1760 wxTreeViewItem
vTvItem(rItem
);
1762 DoGetItem(&vTvItem
);
1763 if (!::WinSendMsg( GetHWND()
1764 ,CM_INVALIDATERECORD
1766 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1768 } // end of wxTreeCtrl::EnsureVisible
1770 void wxTreeCtrl::ScrollTo (
1771 const wxTreeItemId
& rItem
1774 wxTreeViewItem
vTvItem(rItem
);
1776 DoGetItem(&vTvItem
);
1777 if (!::WinSendMsg( GetHWND()
1778 ,CM_INVALIDATERECORD
1780 ,MPFROM2SHORT(1, CMA_ERASE
| CMA_REPOSITION
| CMA_TEXTCHANGED
)
1784 wxTextCtrl
* wxTreeCtrl::EditLabel (
1785 const wxTreeItemId
& rItem
1786 , wxClassInfo
* WXUNUSED(pTextControlClass
)
1790 PMYRECORD pRecord
= FindOS2TreeRecordByID( GetHWND()
1794 vEdit
.cb
= sizeof(CNREDITDATA
);
1795 vEdit
.hwndCnr
= GetHWND();
1796 vEdit
.pRecord
= &pRecord
->m_vRecord
;
1797 vEdit
.pFieldInfo
= NULL
;
1798 vEdit
.ppszText
= NULL
;
1802 ::WinSendMsg( GetHWND()
1808 } // end of wxTreeCtrl::EditLabel
1810 // End label editing, optionally cancelling the edit
1811 void wxTreeCtrl::EndEditLabel (
1812 const wxTreeItemId
& WXUNUSED(rItem
)
1813 , bool WXUNUSED(bDiscardChanges
)
1816 ::WinSendMsg( GetHWND()
1821 } // end of wxTreeCtrl::EndEditLabel
1823 wxTreeItemId
wxTreeCtrl::HitTest (
1824 const wxPoint
& rPoint
1825 , int& WXUNUSED(rFlags
)
1828 PMYRECORD pRecord
= NULL
;
1829 QUERYRECFROMRECT vQueryRect
;
1834 // Get height for OS/2 point conversion
1836 ::WinSendMsg( GetHWND()
1837 ,CM_QUERYVIEWPORTRECT
1839 ,MPFROM2SHORT(CMA_WINDOW
, TRUE
)
1841 lHeight
= vRect
.yTop
- vRect
.yBottom
;
1844 // For now just try and get a record in the general vicinity and forget
1847 vRect
.xLeft
= rPoint
.x
- 2;
1848 vRect
.xRight
= rPoint
.x
+ 2;
1849 vRect
.yTop
= (lHeight
- rPoint
.y
) + 2;
1850 vRect
.yBottom
= (lHeight
- rPoint
.y
) - 2;
1852 vQueryRect
.cb
= sizeof(QUERYRECFROMRECT
);
1853 vQueryRect
.rect
= vRect
;
1854 vQueryRect
.fsSearch
= CMA_PARTIAL
;
1856 pRecord
= (PMYRECORD
)::WinSendMsg( GetHWND()
1857 ,CM_QUERYRECORDFROMRECT
1859 ,MPFROMP(&vQueryRect
)
1864 return wxTreeItemId((long)pRecord
->m_ulItemId
);
1865 } // end of wxTreeCtrl::HitTest
1867 bool wxTreeCtrl::GetBoundingRect (
1868 const wxTreeItemId
& rItem
1874 PMYRECORD pRecord
= FindOS2TreeRecordByID ( GetHWND()
1877 QUERYRECORDRECT vQuery
;
1879 vQuery
.cb
= sizeof(QUERYRECORDRECT
);
1880 vQuery
.pRecord
= (PRECORDCORE
)pRecord
;
1881 vQuery
.fRightSplitWindow
= FALSE
;
1883 vQuery
.fsExtent
= CMA_TEXT
;
1885 vQuery
.fsExtent
= CMA_TREEICON
| CMA_TEXT
;
1887 if (!::WinSendMsg( GetHWND()
1889 ,MPFROMP(&vRectRecord
)
1893 rRect
.SetLeft(vRectRecord
.xLeft
);
1894 rRect
.SetTop(vRectRecord
.yTop
);
1895 rRect
.SetRight(vRectRecord
.xRight
);
1896 rRect
.SetBottom(vRectRecord
.yBottom
);
1898 } // end of wxTreeCtrl::GetBoundingRect
1900 // ----------------------------------------------------------------------------
1902 // ----------------------------------------------------------------------------
1904 SHORT EXPENTRY
InternalDataCompareTreeFunc (
1910 wxCHECK_MSG( p1
&& p2
, 0,
1911 wxT("sorting tree without data doesn't make sense") );
1913 wxTreeCtrl
* pTree
= (wxTreeCtrl
*)pStorage
;
1915 return pTree
->OnCompareItems( p1
->m_ulItemId
1918 } // end of wxTreeSortHelper::Compare
1920 int wxTreeCtrl::OnCompareItems (
1921 const wxTreeItemId
& rItem1
1922 , const wxTreeItemId
& rItem2
1925 return wxStrcmp( GetItemText(rItem1
)
1926 ,GetItemText(rItem2
)
1928 } // end of wxTreeCtrl::OnCompareItems
1930 void wxTreeCtrl::SortChildren (
1931 const wxTreeItemId
& rItem
1934 ::WinSendMsg( GetHWND()
1936 ,(PFN
)InternalDataCompareTreeFunc
1939 } // end of wxTreeCtrl::SortChildren
1941 // ----------------------------------------------------------------------------
1943 // ----------------------------------------------------------------------------
1945 bool wxTreeCtrl::OS2Command (
1950 if (uCmd
== CN_ENDEDIT
)
1952 wxCommandEvent
vEvent( wxEVT_TEXT
1956 vEvent
.SetEventObject( this );
1957 ProcessCommand(vEvent
);
1960 else if (uCmd
== CN_KILLFOCUS
)
1962 wxCommandEvent
vEvent( wxEVT_KILL_FOCUS
1965 vEvent
.SetEventObject( this );
1966 ProcessCommand(vEvent
);
1971 } // end of wxTreeCtrl::OS2Command
1974 // TODO: Fully implement direct manipulation when I figure it out
1976 MRESULT
wxTreeCtrl::OS2WindowProc (
1982 bool bProcessed
= false;
1984 wxTreeEvent
vEvent( wxEVT_NULL
1987 wxEventType vEventType
= wxEVT_NULL
;
1988 PCNRDRAGINIT pDragInit
= NULL
;
1989 PCNREDITDATA pEditData
= NULL
;
1990 PNOTIFYRECORDENTER pNotifyEnter
= NULL
;
1992 vEvent
.SetEventObject(this);
1996 switch(SHORT2FROMMP(wParam
))
1999 pDragInit
= (PCNRDRAGINIT
)lParam
;
2002 PMYRECORD pRecord
= (PMYRECORD
)pDragInit
->pRecord
;
2004 vEventType
= wxEVT_TREE_BEGIN_DRAG
;
2005 vEvent
.m_item
= pRecord
->m_ulItemId
;
2006 vEvent
.m_pointDrag
.x
= pDragInit
->x
;
2007 vEvent
.m_pointDrag
.y
= pDragInit
->y
;
2012 pEditData
= (PCNREDITDATA
)lParam
;
2015 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2017 vEventType
= wxEVT_TREE_BEGIN_LABEL_EDIT
;
2018 vEvent
.m_item
= pRecord
->m_ulItemId
;
2019 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2020 vEvent
.m_editCancelled
= false;
2025 pEditData
= (PCNREDITDATA
)lParam
;
2028 PMYRECORD pRecord
= (PMYRECORD
)pEditData
->pRecord
;
2030 vEventType
= wxEVT_TREE_END_LABEL_EDIT
;
2031 vEvent
.m_item
= pRecord
->m_ulItemId
;
2032 vEvent
.m_label
= pRecord
->m_vRecord
.pszTree
;
2033 if (pRecord
->m_vRecord
.pszTree
== NULL
)
2035 vEvent
.m_editCancelled
= true;
2039 vEvent
.m_editCancelled
= false;
2046 PMYRECORD pRecord
= (PMYRECORD
)lParam
;
2048 vEventType
= gs_expandEvents
[IDX_EXPAND
][IDX_DONE
];
2049 vEvent
.m_item
= pRecord
->m_ulItemId
;
2053 vEvent
.SetEventType(vEventType
);
2054 bProcessed
= HandleWindowEvent(vEvent
);
2058 mRc
= wxControl::OS2WindowProc( uMsg
2063 } // end of wxTreeCtrl::OS2WindowProc
2065 #endif // wxUSE_TREECTRL