1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "treectrl.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
29 #if defined(__WIN95__)
31 #include "wx/treectrl.h"
32 #include "wx/msw/private.h"
38 // Bug in headers, sometimes
40 #define TVIS_FOCUSED 0x0001
43 static void wxConvertToMSWTreeItem(wxTreeItem
& info
, TV_ITEM
& tvItem
);
44 static void wxConvertFromMSWTreeItem(wxTreeItem
& info
, TV_ITEM
& tvItem
, HWND getFullInfo
= 0);
46 #if !USE_SHARED_LIBRARY
47 IMPLEMENT_DYNAMIC_CLASS(wxTreeCtrl
, wxControl
)
48 IMPLEMENT_DYNAMIC_CLASS(wxTreeItem
, wxObject
)
52 wxTreeCtrl::wxTreeCtrl(void)
54 m_imageListNormal
= NULL
;
55 m_imageListState
= NULL
;
59 bool wxTreeCtrl::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
60 long style
, const wxValidator
& validator
, const wxString
& name
)
62 wxSystemSettings settings
;
63 SetBackgroundColour(settings
.GetSystemColour(wxSYS_COLOUR_WINDOW
));
64 SetForegroundColour(parent
->GetDefaultForegroundColour());
67 SetValidator(validator
);
69 m_imageListNormal
= NULL
;
70 m_imageListState
= NULL
;
78 m_windowStyle
= style
;
80 // SetFont(wxTheFontList->FindOrCreateFont(11, wxSWISS, wxNORMAL, wxNORMAL));
93 m_windowId
= (id
== -1) ? NewControlId() : id
;
95 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| TVS_HASLINES
;
98 WXDWORD exStyle
= Determine3DEffects(WS_EX_CLIENTEDGE
, &want3D
) ;
100 // Even with extended styles, need to combine with WS_BORDER
101 // for them to look right.
102 if (want3D
|| (m_windowStyle
& wxSIMPLE_BORDER
) || (m_windowStyle
& wxRAISED_BORDER
) ||
103 (m_windowStyle
& wxSUNKEN_BORDER
) || (m_windowStyle
& wxDOUBLE_BORDER
))
106 if ( m_windowStyle
& wxTR_HAS_BUTTONS
)
107 wstyle
|= TVS_HASBUTTONS
;
109 if ( m_windowStyle
& wxTR_EDIT_LABELS
)
110 wstyle
|= TVS_EDITLABELS
;
112 if ( m_windowStyle
& wxTR_LINES_AT_ROOT
)
113 wstyle
|= TVS_LINESATROOT
;
115 // Create the toolbar control.
116 HWND hWndTreeControl
= CreateWindowEx(exStyle
,
121 (HWND
) parent
->GetHWND(),
126 m_hWnd
= (WXHWND
) hWndTreeControl
;
127 if (parent
) parent
->AddChild(this);
129 SubclassWin((WXHWND
) m_hWnd
);
134 wxTreeCtrl::~wxTreeCtrl(void)
138 m_textCtrl
->UnsubclassWin();
139 m_textCtrl
->SetHWND((WXHWND
) 0);
145 int wxTreeCtrl::GetCount(void) const
147 return (int) TreeView_GetCount((HWND
) GetHWND());
150 int wxTreeCtrl::GetIndent(void) const
152 return (int) TreeView_GetIndent((HWND
) GetHWND());
155 void wxTreeCtrl::SetIndent(int indent
)
157 TreeView_SetIndent((HWND
) GetHWND(), indent
);
160 wxImageList
*wxTreeCtrl::GetImageList(int which
) const
162 if ( which
== wxIMAGE_LIST_NORMAL
)
164 return m_imageListNormal
;
166 else if ( which
== wxIMAGE_LIST_STATE
)
168 return m_imageListState
;
173 void wxTreeCtrl::SetImageList(wxImageList
*imageList
, int which
)
176 if ( which
== wxIMAGE_LIST_NORMAL
)
178 flags
= TVSIL_NORMAL
;
179 m_imageListNormal
= imageList
;
181 else if ( which
== wxIMAGE_LIST_STATE
)
184 m_imageListState
= imageList
;
186 TreeView_SetImageList((HWND
) GetHWND(), (HIMAGELIST
) imageList
? imageList
->GetHIMAGELIST() : 0, flags
);
189 long wxTreeCtrl::GetNextItem(long item
, int code
) const
194 case wxTREE_NEXT_CARET
:
197 case wxTREE_NEXT_CHILD
:
200 case wxTREE_NEXT_DROPHILITE
:
201 flag
= TVGN_DROPHILITE
;
203 case wxTREE_NEXT_FIRSTVISIBLE
:
204 flag
= TVGN_FIRSTVISIBLE
;
206 case wxTREE_NEXT_NEXT
:
209 case wxTREE_NEXT_NEXTVISIBLE
:
210 flag
= TVGN_NEXTVISIBLE
;
212 case wxTREE_NEXT_PARENT
:
215 case wxTREE_NEXT_PREVIOUS
:
216 flag
= TVGN_PREVIOUS
;
218 case wxTREE_NEXT_PREVIOUSVISIBLE
:
219 flag
= TVGN_PREVIOUSVISIBLE
;
221 case wxTREE_NEXT_ROOT
:
228 return (long) TreeView_GetNextItem( (HWND
) GetHWND(), (HTREEITEM
) item
, flag
);
231 bool wxTreeCtrl::ItemHasChildren(long item
) const
234 item2
.hItem
= (HTREEITEM
) item
;
235 item2
.mask
= TVIF_CHILDREN
;
236 TreeView_GetItem((HWND
) GetHWND(), &item2
);
237 return (item2
.cChildren
!= 0);
240 long wxTreeCtrl::GetChild(long item
) const
242 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_CHILD
, (LPARAM
)item
);
245 long wxTreeCtrl::GetParent(long item
) const
247 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_PARENT
, (LPARAM
)item
);
250 long wxTreeCtrl::GetFirstVisibleItem(void) const
252 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_FIRSTVISIBLE
, 0);
255 long wxTreeCtrl::GetNextVisibleItem(long item
) const
257 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_NEXTVISIBLE
, (LPARAM
)item
);
260 long wxTreeCtrl::GetSelection(void) const
262 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_CARET
, 0);
265 long wxTreeCtrl::GetRootItem(void) const
267 return (long) ::SendMessage((HWND
) GetHWND(), TVM_GETNEXTITEM
, TVGN_ROOT
, 0);
270 bool wxTreeCtrl::GetItem(wxTreeItem
& info
) const
273 tvItem
.hItem
= (HTREEITEM
)info
.m_itemId
;
274 tvItem
.pszText
= NULL
;
276 tvItem
.stateMask
= 0;
278 // TODO: convert other bits in the mask
279 if ( info
.m_mask
& wxTREE_MASK_TEXT
)
281 tvItem
.mask
|= TVIF_TEXT
;
282 tvItem
.pszText
= new char[513];
283 tvItem
.cchTextMax
= 512;
285 if ( info
.m_mask
& wxTREE_MASK_DATA
)
286 tvItem
.mask
|= TVIF_PARAM
;
287 if ( info
.m_stateMask
& wxTREE_STATE_EXPANDED
) {
288 tvItem
.mask
|= TVIF_STATE
;
289 tvItem
.stateMask
|= TVIS_EXPANDED
;
292 bool success
= TreeView_GetItem((HWND
)GetHWND(), &tvItem
) != 0;
296 wxLogSysError("TreeView_GetItem failed");
299 delete[] tvItem
.pszText
;
304 wxConvertFromMSWTreeItem(info
, tvItem
);
307 delete[] tvItem
.pszText
;
312 bool wxTreeCtrl::SetItem(wxTreeItem
& info
)
315 wxConvertToMSWTreeItem(info
, item
);
316 return (::SendMessage((HWND
) GetHWND(), TVM_SETITEM
, 0, (LPARAM
)&item
) != 0);
319 int wxTreeCtrl::GetItemState(long item
, long stateMask
) const
323 info
.m_mask
= wxTREE_MASK_STATE
;
324 info
.m_stateMask
= stateMask
;
325 info
.m_itemId
= item
;
333 bool wxTreeCtrl::SetItemState(long item
, long state
, long stateMask
)
337 info
.m_mask
= wxTREE_MASK_STATE
;
338 info
.m_state
= state
;
339 info
.m_stateMask
= stateMask
;
340 info
.m_itemId
= item
;
342 return SetItem(info
);
345 bool wxTreeCtrl::SetItemImage(long item
, int image
, int selImage
)
349 info
.m_mask
= wxTREE_MASK_IMAGE
;
350 info
.m_image
= image
;
353 info
.m_selectedImage
= selImage
;
354 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
356 info
.m_itemId
= item
;
358 return SetItem(info
);
361 wxString
wxTreeCtrl::GetItemText(long item
) const
365 info
.m_mask
= wxTREE_MASK_TEXT
;
366 info
.m_itemId
= item
;
373 void wxTreeCtrl::SetItemText(long item
, const wxString
& str
)
377 info
.m_mask
= wxTREE_MASK_TEXT
;
378 info
.m_itemId
= item
;
384 long wxTreeCtrl::GetItemData(long item
) const
388 info
.m_mask
= wxTREE_MASK_DATA
;
389 info
.m_itemId
= item
;
396 bool wxTreeCtrl::SetItemData(long item
, long data
)
400 info
.m_mask
= wxTREE_MASK_DATA
;
401 info
.m_itemId
= item
;
404 return SetItem(info
);
407 bool wxTreeCtrl::GetItemRect(long item
, wxRectangle
& rect
, bool textOnly
) const
411 *(HTREEITEM
*)& rect2
= (HTREEITEM
) item
;
412 bool success
= (::SendMessage((HWND
) GetHWND(), TVM_GETITEMRECT
, (WPARAM
)textOnly
,
413 (LPARAM
)&rect2
) != 0);
417 rect
.width
= rect2
.right
- rect2
.left
;
418 rect
.height
= rect2
.bottom
- rect2
.left
;
422 wxTextCtrl
* wxTreeCtrl::GetEditControl(void) const
428 bool wxTreeCtrl::DeleteItem(long item
)
430 return (TreeView_DeleteItem((HWND
) GetHWND(), (HTREEITEM
) item
) != 0);
433 bool wxTreeCtrl::ExpandItem(long item
, int action
)
435 UINT mswAction
= TVE_EXPAND
;
438 case wxTREE_EXPAND_EXPAND
:
439 mswAction
= TVE_EXPAND
;
442 case wxTREE_EXPAND_COLLAPSE
:
443 mswAction
= TVE_COLLAPSE
;
446 case wxTREE_EXPAND_COLLAPSE_RESET
:
447 // @@@ it should also delete all the items! currently, if you do use this
448 // code your program will probaly crash. Feel free to remove this if
450 wxFAIL_MSG("wxTREE_EXPAND_COLLAPSE_RESET probably doesn't work.");
451 mswAction
= TVE_COLLAPSERESET
;
454 case wxTREE_EXPAND_TOGGLE
:
455 mswAction
= TVE_TOGGLE
;
459 wxFAIL_MSG("unknown action in wxTreeCtrl::ExpandItem");
462 bool bOk
= TreeView_Expand((HWND
)GetHWND(), (HTREEITEM
)item
, mswAction
) != 0;
464 // TreeView_Expand doesn't send TVN_EXPAND(ING) messages, so emulate them
466 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
467 event
.m_item
.m_itemId
= item
;
468 event
.m_item
.m_mask
=
469 event
.m_item
.m_stateMask
= 0xffff; // get all
470 GetItem(event
.m_item
);
472 bool bIsExpanded
= (event
.m_item
.m_state
& wxTREE_STATE_EXPANDED
) != 0;
474 event
.m_code
= action
;
475 event
.SetEventObject(this);
477 // @@@ return values of {EXPAND|COLLAPS}ING event handler is discarded
478 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDING
479 : wxEVT_COMMAND_TREE_ITEM_COLLAPSING
);
480 GetEventHandler()->ProcessEvent(event
);
482 event
.SetEventType(bIsExpanded
? wxEVT_COMMAND_TREE_ITEM_EXPANDED
483 : wxEVT_COMMAND_TREE_ITEM_COLLAPSED
);
484 GetEventHandler()->ProcessEvent(event
);
490 long wxTreeCtrl::InsertItem(long parent
, wxTreeItem
& info
, long insertAfter
)
492 TV_INSERTSTRUCT tvInsertStruct
;
493 tvInsertStruct
.hParent
= (HTREEITEM
) parent
;
494 tvInsertStruct
.hInsertAfter
= (HTREEITEM
) insertAfter
;
496 wxConvertToMSWTreeItem(info
, tvInsertStruct
.item
);
498 return (long) TreeView_InsertItem((HWND
) GetHWND(), & tvInsertStruct
);
501 long wxTreeCtrl::InsertItem(long parent
, const wxString
& label
, int image
, int selImage
,
506 info
.m_mask
= wxTREE_MASK_TEXT
;
509 info
.m_mask
|= wxTREE_MASK_IMAGE
| wxTREE_MASK_SELECTED_IMAGE
;
510 info
.m_image
= image
;
511 if ( selImage
== -1 )
512 info
.m_selectedImage
= image
;
514 info
.m_selectedImage
= selImage
;
517 return InsertItem(parent
, info
, insertAfter
);
520 bool wxTreeCtrl::SelectItem(long item
)
522 return (TreeView_SelectItem((HWND
) GetHWND(), (HTREEITEM
) item
) != 0);
525 bool wxTreeCtrl::ScrollTo(long item
)
527 return (TreeView_SelectSetFirstVisible((HWND
) GetHWND(), (HTREEITEM
) item
) != 0);
530 bool wxTreeCtrl::DeleteAllItems(void)
532 return (TreeView_DeleteAllItems((HWND
) GetHWND()) != 0);
535 wxTextCtrl
* wxTreeCtrl::EditLabel(long item
, wxClassInfo
* textControlClass
)
537 wxASSERT( (textControlClass
->IsKindOf(CLASSINFO(wxTextCtrl
))) );
539 HWND hWnd
= (HWND
) TreeView_EditLabel((HWND
) GetHWND(), item
);
543 m_textCtrl
->UnsubclassWin();
544 m_textCtrl
->SetHWND(0);
549 m_textCtrl
= (wxTextCtrl
*) textControlClass
->CreateObject();
550 m_textCtrl
->SetHWND((WXHWND
) hWnd
);
551 m_textCtrl
->SubclassWin((WXHWND
) hWnd
);
556 // End label editing, optionally cancelling the edit
557 bool wxTreeCtrl::EndEditLabel(bool cancel
)
559 bool success
= (TreeView_EndEditLabelNow((HWND
) GetHWND(), cancel
) != 0);
563 m_textCtrl
->UnsubclassWin();
564 m_textCtrl
->SetHWND(0);
571 long wxTreeCtrl::HitTest(const wxPoint
& point
, int& flags
)
573 TV_HITTESTINFO hitTestInfo
;
574 hitTestInfo
.pt
.x
= (int) point
.x
;
575 hitTestInfo
.pt
.y
= (int) point
.y
;
577 TreeView_HitTest((HWND
) GetHWND(), & hitTestInfo
);
580 if ( hitTestInfo
.flags
& TVHT_ABOVE
)
581 flags
|= wxTREE_HITTEST_ABOVE
;
582 if ( hitTestInfo
.flags
& TVHT_BELOW
)
583 flags
|= wxTREE_HITTEST_BELOW
;
584 if ( hitTestInfo
.flags
& TVHT_NOWHERE
)
585 flags
|= wxTREE_HITTEST_NOWHERE
;
586 if ( hitTestInfo
.flags
& TVHT_ONITEMBUTTON
)
587 flags
|= wxTREE_HITTEST_ONITEMBUTTON
;
588 if ( hitTestInfo
.flags
& TVHT_ONITEMICON
)
589 flags
|= wxTREE_HITTEST_ONITEMICON
;
590 if ( hitTestInfo
.flags
& TVHT_ONITEMINDENT
)
591 flags
|= wxTREE_HITTEST_ONITEMINDENT
;
592 if ( hitTestInfo
.flags
& TVHT_ONITEMLABEL
)
593 flags
|= wxTREE_HITTEST_ONITEMLABEL
;
594 if ( hitTestInfo
.flags
& TVHT_ONITEMRIGHT
)
595 flags
|= wxTREE_HITTEST_ONITEMRIGHT
;
596 if ( hitTestInfo
.flags
& TVHT_ONITEMSTATEICON
)
597 flags
|= wxTREE_HITTEST_ONITEMSTATEICON
;
598 if ( hitTestInfo
.flags
& TVHT_TOLEFT
)
599 flags
|= wxTREE_HITTEST_TOLEFT
;
600 if ( hitTestInfo
.flags
& TVHT_TORIGHT
)
601 flags
|= wxTREE_HITTEST_TORIGHT
;
603 return (long) hitTestInfo
.hItem
;
607 wxImageList *wxTreeCtrl::CreateDragImage(long item)
612 bool wxTreeCtrl::SortChildren(long item
)
614 return (TreeView_SortChildren((HWND
) GetHWND(), (HTREEITEM
) item
, 0) != 0);
617 bool wxTreeCtrl::EnsureVisible(long item
)
619 return (TreeView_EnsureVisible((HWND
) GetHWND(), (HTREEITEM
) item
) != 0);
622 bool wxTreeCtrl::MSWCommand(WXUINT cmd
, WXWORD id
)
624 if (cmd
== EN_UPDATE
)
626 wxCommandEvent
event(wxEVT_COMMAND_TEXT_UPDATED
, id
);
627 event
.SetEventObject( this );
628 ProcessCommand(event
);
631 else if (cmd
== EN_KILLFOCUS
)
633 wxCommandEvent
event(wxEVT_KILL_FOCUS
, id
);
634 event
.SetEventObject( this );
635 ProcessCommand(event
);
641 bool wxTreeCtrl::MSWNotify(WXWPARAM wParam
, WXLPARAM lParam
)
643 wxTreeEvent
event(wxEVT_NULL
, m_windowId
);
644 wxEventType eventType
= wxEVT_NULL
;
645 NMHDR
* hdr1
= (NMHDR
*) lParam
;
646 switch ( hdr1
->code
)
650 eventType
= wxEVT_COMMAND_TREE_BEGIN_DRAG
;
651 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
652 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
653 event
.m_pointDrag
.x
= hdr
->ptDrag
.x
;
654 event
.m_pointDrag
.y
= hdr
->ptDrag
.y
;
657 case TVN_BEGINLABELEDIT
:
659 eventType
= wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT
;
660 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
661 wxConvertFromMSWTreeItem(event
.m_item
, info
->item
, (HWND
) GetHWND());
666 eventType
= wxEVT_COMMAND_TREE_BEGIN_RDRAG
;
667 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
668 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
669 event
.m_pointDrag
.x
= hdr
->ptDrag
.x
;
670 event
.m_pointDrag
.y
= hdr
->ptDrag
.y
;
675 eventType
= wxEVT_COMMAND_TREE_DELETE_ITEM
;
676 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
677 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemOld
, (HWND
) GetHWND());
678 event
.m_pointDrag
.x
= hdr
->ptDrag
.x
;
679 event
.m_pointDrag
.y
= hdr
->ptDrag
.y
;
682 case TVN_ENDLABELEDIT
:
684 eventType
= wxEVT_COMMAND_TREE_END_LABEL_EDIT
;
685 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
686 wxConvertFromMSWTreeItem(event
.m_item
, info
->item
, (HWND
) GetHWND());
689 case TVN_GETDISPINFO
:
691 eventType
= wxEVT_COMMAND_TREE_GET_INFO
;
692 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
693 wxConvertFromMSWTreeItem(event
.m_item
, info
->item
, (HWND
) GetHWND());
696 case TVN_ITEMEXPANDING
:
698 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
699 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
701 switch ( hdr
->action
)
704 eventType
= wxEVT_COMMAND_TREE_ITEM_EXPANDING
;
708 eventType
= wxEVT_COMMAND_TREE_ITEM_COLLAPSING
;
711 case TVE_COLLAPSERESET
:
713 wxLogDebug("unexpected code in TVN_ITEMEXPANDING message");
719 case TVN_ITEMEXPANDED
:
721 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
722 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
723 switch ( hdr
->action
)
726 eventType
= wxEVT_COMMAND_TREE_ITEM_EXPANDED
;
730 eventType
= wxEVT_COMMAND_TREE_ITEM_COLLAPSED
;
733 case TVE_COLLAPSERESET
:
735 wxLogDebug("unexpected code in TVN_ITEMEXPANDED message");
742 eventType
= wxEVT_COMMAND_TREE_KEY_DOWN
;
743 TV_KEYDOWN
*info
= (TV_KEYDOWN
*)lParam
;
744 event
.m_code
= wxCharCodeMSWToWX(info
->wVKey
);
749 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGED
;
750 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
751 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
752 event
.m_oldItem
= (long) hdr
->itemNew
.hItem
;
756 case TVN_SELCHANGING
:
758 eventType
= wxEVT_COMMAND_TREE_SEL_CHANGING
;
759 NM_TREEVIEW
* hdr
= (NM_TREEVIEW
*)lParam
;
760 wxConvertFromMSWTreeItem(event
.m_item
, hdr
->itemNew
, (HWND
) GetHWND());
761 event
.m_oldItem
= (long) hdr
->itemNew
.hItem
;
764 case TVN_SETDISPINFO
:
766 eventType
= wxEVT_COMMAND_TREE_SET_INFO
;
767 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
768 wxConvertFromMSWTreeItem(event
.m_item
, info
->item
, (HWND
) GetHWND());
773 return wxControl::MSWNotify(wParam
, lParam
);
777 event
.SetEventObject(this);
778 event
.SetEventType(eventType
);
780 if ( !GetEventHandler()->ProcessEvent(event
) )
783 if (hdr1
->code
== TVN_GETDISPINFO
)
785 TV_DISPINFO
*info
= (TV_DISPINFO
*)lParam
;
786 wxConvertToMSWTreeItem(event
.m_item
, info
->item
);
792 // Tree item structure
793 wxTreeItem::wxTreeItem(void)
800 m_selectedImage
= -1;
805 // If getFullInfo is TRUE, we explicitly query for more info if we haven't got it all.
806 static void wxConvertFromMSWTreeItem(wxTreeItem
& info
, TV_ITEM
& tvItem
, HWND getFullInfo
)
808 info
.m_data
= tvItem
.lParam
;
811 info
.m_stateMask
= 0;
813 long oldMask
= tvItem
.mask
;
815 bool needText
= FALSE
;
816 if (getFullInfo
!= 0)
818 if ( tvItem
.mask
& TVIF_TEXT
)
825 tvItem
.pszText
= new char[513];
826 tvItem
.cchTextMax
= 512;
828 tvItem
.mask
|= TVIF_HANDLE
| TVIF_STATE
| TVIF_TEXT
| TVIF_IMAGE
| TVIF_SELECTEDIMAGE
| TVIF_CHILDREN
| TVIF_PARAM
;
829 ::SendMessage(getFullInfo
, TVM_GETITEM
, 0, (LPARAM
)& tvItem
) ;
832 if ( tvItem
.mask
& TVIF_HANDLE
)
834 info
.m_mask
|= wxTREE_MASK_HANDLE
;
835 info
.m_itemId
= (long) tvItem
.hItem
;
837 if ( tvItem
.mask
& TVIF_STATE
)
839 info
.m_mask
|= wxTREE_MASK_STATE
;
840 if ( tvItem
.stateMask
& TVIS_BOLD
)
842 info
.m_stateMask
|= wxTREE_STATE_BOLD
;
843 if ( tvItem
.state
& TVIS_BOLD
)
844 info
.m_state
|= wxTREE_STATE_BOLD
;
847 if ( tvItem
.stateMask
& TVIS_CUT
)
849 info
.m_stateMask
|= wxTREE_STATE_CUT
;
850 if ( tvItem
.state
& TVIS_CUT
)
851 info
.m_state
|= wxTREE_STATE_CUT
;
854 if ( tvItem
.stateMask
& TVIS_DROPHILITED
)
856 info
.m_stateMask
|= wxTREE_STATE_DROPHILITED
;
857 if ( tvItem
.state
& TVIS_DROPHILITED
)
858 info
.m_state
|= wxTREE_STATE_DROPHILITED
;
860 if ( tvItem
.stateMask
& TVIS_EXPANDED
)
862 info
.m_stateMask
|= wxTREE_STATE_EXPANDED
;
863 if ( tvItem
.state
& TVIS_EXPANDED
)
864 info
.m_state
|= wxTREE_STATE_EXPANDED
;
866 if ( tvItem
.stateMask
& TVIS_EXPANDEDONCE
)
868 info
.m_stateMask
|= wxTREE_STATE_EXPANDEDONCE
;
869 if ( tvItem
.state
& TVIS_EXPANDEDONCE
)
870 info
.m_state
|= wxTREE_STATE_EXPANDEDONCE
;
872 if ( tvItem
.stateMask
& TVIS_FOCUSED
)
874 info
.m_stateMask
|= wxTREE_STATE_FOCUSED
;
875 if ( tvItem
.state
& TVIS_FOCUSED
)
876 info
.m_state
|= wxTREE_STATE_FOCUSED
;
878 if ( tvItem
.stateMask
& TVIS_SELECTED
)
880 info
.m_stateMask
|= wxTREE_STATE_SELECTED
;
881 if ( tvItem
.state
& TVIS_SELECTED
)
882 info
.m_state
|= wxTREE_STATE_SELECTED
;
886 if ( tvItem
.mask
& TVIF_TEXT
)
888 info
.m_mask
|= wxTREE_MASK_TEXT
;
889 info
.m_text
= tvItem
.pszText
;
891 if ( tvItem
.mask
& TVIF_IMAGE
)
893 info
.m_mask
|= wxTREE_MASK_IMAGE
;
894 info
.m_image
= tvItem
.iImage
;
896 if ( tvItem
.mask
& TVIF_SELECTEDIMAGE
)
898 info
.m_mask
|= wxTREE_MASK_SELECTED_IMAGE
;
899 info
.m_selectedImage
= tvItem
.iSelectedImage
;
901 if ( tvItem
.mask
& TVIF_CHILDREN
)
903 info
.m_mask
|= wxTREE_MASK_CHILDREN
;
904 info
.m_children
= tvItem
.cChildren
;
906 if ( tvItem
.mask
& TVIF_PARAM
)
907 info
.m_mask
|= wxTREE_MASK_DATA
;
912 delete[] tvItem
.pszText
;
914 tvItem
.mask
= oldMask
;
917 static void wxConvertToMSWTreeItem(wxTreeItem
& info
, TV_ITEM
& tvItem
)
919 tvItem
.hItem
= (HTREEITEM
) info
.m_itemId
;
921 tvItem
.iImage
= info
.m_image
;
922 tvItem
.iSelectedImage
= info
.m_selectedImage
;
923 tvItem
.cChildren
= info
.m_children
;
924 tvItem
.lParam
= info
.m_data
;
926 tvItem
.stateMask
= 0;
929 if (info
.m_mask
& wxTREE_MASK_HANDLE
)
930 tvItem
.mask
|= TVIF_HANDLE
;
931 if (info
.m_mask
& wxTREE_MASK_STATE
)
932 tvItem
.mask
|= TVIF_STATE
;
933 if (info
.m_mask
& wxTREE_MASK_TEXT
)
935 tvItem
.mask
|= TVIF_TEXT
;
936 tvItem
.pszText
= (char *) (const char *)info
.m_text
;
937 if ( tvItem
.pszText
)
938 tvItem
.cchTextMax
= info
.m_text
.Length();
940 tvItem
.cchTextMax
= 0;
942 if (info
.m_mask
& wxTREE_MASK_IMAGE
)
943 tvItem
.mask
|= TVIF_IMAGE
;
944 if (info
.m_mask
& wxTREE_MASK_SELECTED_IMAGE
)
945 tvItem
.mask
|= TVIF_SELECTEDIMAGE
;
946 if (info
.m_mask
& wxTREE_MASK_CHILDREN
)
947 tvItem
.mask
|= TVIF_CHILDREN
;
948 if (info
.m_mask
& wxTREE_MASK_DATA
)
949 tvItem
.mask
|= TVIF_PARAM
;
951 if (info
.m_stateMask
& wxTREE_STATE_BOLD
)
953 tvItem
.stateMask
|= TVIS_BOLD
;
954 tvItem
.state
|= TVIS_BOLD
;
956 if (info
.m_stateMask
& wxTREE_STATE_CUT
)
958 tvItem
.stateMask
|= TVIS_CUT
;
959 if ( info
.m_state
& wxTREE_STATE_CUT
)
960 tvItem
.state
|= TVIS_CUT
;
962 if (info
.m_stateMask
& wxTREE_STATE_DROPHILITED
)
964 tvItem
.stateMask
|= TVIS_DROPHILITED
;
965 if ( info
.m_state
& wxTREE_STATE_DROPHILITED
)
966 tvItem
.state
|= TVIS_DROPHILITED
;
968 if (info
.m_stateMask
& wxTREE_STATE_EXPANDED
)
970 tvItem
.stateMask
|= TVIS_EXPANDED
;
971 if ( info
.m_state
& wxTREE_STATE_EXPANDED
)
972 tvItem
.state
|= TVIS_EXPANDED
;
974 if (info
.m_stateMask
& wxTREE_STATE_EXPANDEDONCE
)
976 tvItem
.stateMask
|= TVIS_EXPANDEDONCE
;
977 if ( info
.m_state
& wxTREE_STATE_EXPANDEDONCE
)
978 tvItem
.state
|= TVIS_EXPANDEDONCE
;
980 if (info
.m_stateMask
& wxTREE_STATE_FOCUSED
)
982 tvItem
.stateMask
|= TVIS_FOCUSED
;
983 if ( info
.m_state
& wxTREE_STATE_FOCUSED
)
984 tvItem
.state
|= TVIS_FOCUSED
;
986 if (info
.m_stateMask
& wxTREE_STATE_SELECTED
)
988 tvItem
.stateMask
|= TVIS_SELECTED
;
989 if ( info
.m_state
& wxTREE_STATE_SELECTED
)
990 tvItem
.state
|= TVIS_SELECTED
;
995 IMPLEMENT_DYNAMIC_CLASS(wxTreeEvent
, wxCommandEvent
)
997 wxTreeEvent::wxTreeEvent(wxEventType commandType
, int id
):
998 wxCommandEvent(commandType
, id
)