+ if ((m_windowStyle & wxTR_NO_LINES) == 0)
+ wstyle |= TVS_HASLINES;
+ if ( m_windowStyle & wxTR_HAS_BUTTONS )
+ wstyle |= TVS_HASBUTTONS;
+
+ if ( m_windowStyle & wxTR_EDIT_LABELS )
+ wstyle |= TVS_EDITLABELS;
+
+ if ( m_windowStyle & wxTR_LINES_AT_ROOT )
+ wstyle |= TVS_LINESATROOT;
+
+ if ( m_windowStyle & wxTR_FULL_ROW_HIGHLIGHT )
+ {
+ if ( wxTheApp->GetComCtl32Version() >= 471 )
+ wstyle |= TVS_FULLROWSELECT;
+ }
+
+ // using TVS_CHECKBOXES for emulation of a multiselection tree control
+ // doesn't work without the new enough headers
+#if wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE && \
+ !defined( __GNUWIN32_OLD__ ) && \
+ !defined( __BORLANDC__ ) && \
+ !defined( __WATCOMC__ ) && \
+ (!defined(__VISUALC__) || (__VISUALC__ > 1010))
+
+ // we emulate the multiple selection tree controls by using checkboxes: set
+ // up the image list we need for this if we do have multiple selections
+ if ( m_windowStyle & wxTR_MULTIPLE )
+ wstyle |= TVS_CHECKBOXES;
+#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+
+ // Create the tree control.
+ if ( !MSWCreateControl(WC_TREEVIEW, wstyle) )
+ return false;
+
+#if wxUSE_COMCTL32_SAFELY
+ wxWindow::SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+ wxWindow::SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
+#elif 1
+ SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+ SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
+#else
+ // This works around a bug in the Windows tree control whereby for some versions
+ // of comctrl32, setting any colour actually draws the background in black.
+ // This will initialise the background to the system colour.
+ // THIS FIX NOW REVERTED since it caused problems on _other_ systems.
+ // Assume the user has an updated comctl32.dll.
+ ::SendMessage(GetHwnd(), TVM_SETBKCOLOR, 0,-1);
+ wxWindow::SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+ SetForegroundColour(wxWindow::GetParent()->GetForegroundColour());
+#endif
+
+
+ // VZ: this is some experimental code which may be used to get the
+ // TVS_CHECKBOXES style functionality for comctl32.dll < 4.71.
+ // AFAIK, the standard DLL does about the same thing anyhow.
+#if 0
+ if ( m_windowStyle & wxTR_MULTIPLE )
+ {
+ wxBitmap bmp;
+
+ // create the DC compatible with the current screen
+ HDC hdcMem = CreateCompatibleDC(NULL);
+
+ // create a mono bitmap of the standard size
+ int x = GetSystemMetrics(SM_CXMENUCHECK);
+ int y = GetSystemMetrics(SM_CYMENUCHECK);
+ wxImageList imagelistCheckboxes(x, y, false, 2);
+ HBITMAP hbmpCheck = CreateBitmap(x, y, // bitmap size
+ 1, // # of color planes
+ 1, // # bits needed for one pixel
+ 0); // array containing colour data
+ SelectObject(hdcMem, hbmpCheck);
+
+ // then draw a check mark into it
+ RECT rect = { 0, 0, x, y };
+ if ( !::DrawFrameControl(hdcMem, &rect,
+ DFC_BUTTON,
+ DFCS_BUTTONCHECK | DFCS_CHECKED) )
+ {
+ wxLogLastError(wxT("DrawFrameControl(check)"));
+ }
+
+ bmp.SetHBITMAP((WXHBITMAP)hbmpCheck);
+ imagelistCheckboxes.Add(bmp);
+
+ if ( !::DrawFrameControl(hdcMem, &rect,
+ DFC_BUTTON,
+ DFCS_BUTTONCHECK) )
+ {
+ wxLogLastError(wxT("DrawFrameControl(uncheck)"));
+ }
+
+ bmp.SetHBITMAP((WXHBITMAP)hbmpCheck);
+ imagelistCheckboxes.Add(bmp);
+
+ // clean up
+ ::DeleteDC(hdcMem);
+
+ // set the imagelist
+ SetStateImageList(&imagelistCheckboxes);
+ }
+#endif // 0
+
+ SetSize(pos.x, pos.y, size.x, size.y);
+
+ return true;
+}
+
+wxTreeCtrl::~wxTreeCtrl()
+{
+ // delete any attributes
+ if ( m_hasAnyAttr )
+ {
+ WX_CLEAR_HASH_MAP(wxMapTreeAttr, m_attrs);
+
+ // prevent TVN_DELETEITEM handler from deleting the attributes again!
+ m_hasAnyAttr = false;
+ }
+
+ DeleteTextCtrl();
+
+ // delete user data to prevent memory leaks
+ // also deletes hidden root node storage.
+ DeleteAllItems();
+
+ if (m_ownsImageListNormal) delete m_imageListNormal;
+ if (m_ownsImageListState) delete m_imageListState;
+}
+
+// ----------------------------------------------------------------------------
+// accessors
+// ----------------------------------------------------------------------------
+
+// simple wrappers which add error checking in debug mode
+
+bool wxTreeCtrl::DoGetItem(wxTreeViewItem* tvItem) const
+{
+ wxCHECK_MSG( tvItem->hItem != TVI_ROOT, false,
+ _T("can't retrieve virtual root item") );
+
+ if ( !TreeView_GetItem(GetHwnd(), tvItem) )
+ {
+ wxLogLastError(wxT("TreeView_GetItem"));
+
+ return false;
+ }
+
+ return true;
+}
+
+void wxTreeCtrl::DoSetItem(wxTreeViewItem* tvItem)
+{
+ if ( TreeView_SetItem(GetHwnd(), tvItem) == -1 )
+ {
+ wxLogLastError(wxT("TreeView_SetItem"));
+ }
+}
+
+size_t wxTreeCtrl::GetCount() const
+{
+ return (size_t)TreeView_GetCount(GetHwnd());
+}
+
+unsigned int wxTreeCtrl::GetIndent() const
+{
+ return TreeView_GetIndent(GetHwnd());
+}
+
+void wxTreeCtrl::SetIndent(unsigned int indent)
+{
+ TreeView_SetIndent(GetHwnd(), indent);
+}
+
+wxImageList *wxTreeCtrl::GetImageList() const
+{
+ return m_imageListNormal;
+}
+
+wxImageList *wxTreeCtrl::GetStateImageList() const
+{
+ return m_imageListState;
+}
+
+void wxTreeCtrl::SetAnyImageList(wxImageList *imageList, int which)
+{
+ // no error return
+ TreeView_SetImageList(GetHwnd(),
+ imageList ? imageList->GetHIMAGELIST() : 0,
+ which);
+}
+
+void wxTreeCtrl::SetImageList(wxImageList *imageList)
+{
+ if (m_ownsImageListNormal)
+ delete m_imageListNormal;
+
+ SetAnyImageList(m_imageListNormal = imageList, TVSIL_NORMAL);
+ m_ownsImageListNormal = false;
+}
+
+void wxTreeCtrl::SetStateImageList(wxImageList *imageList)
+{
+ if (m_ownsImageListState) delete m_imageListState;
+ SetAnyImageList(m_imageListState = imageList, TVSIL_STATE);
+ m_ownsImageListState = false;
+}
+
+void wxTreeCtrl::AssignImageList(wxImageList *imageList)
+{
+ SetImageList(imageList);
+ m_ownsImageListNormal = true;
+}
+
+void wxTreeCtrl::AssignStateImageList(wxImageList *imageList)
+{
+ SetStateImageList(imageList);
+ m_ownsImageListState = true;
+}
+
+size_t wxTreeCtrl::GetChildrenCount(const wxTreeItemId& item,
+ bool recursively) const
+{
+ TraverseCounter counter(this, item, recursively);
+
+ return counter.GetCount() - 1;
+}
+
+// ----------------------------------------------------------------------------
+// control colours
+// ----------------------------------------------------------------------------