+ wxTreeEvent event(wxEVT_NULL, m_windowId);
+ wxEventType eventType = wxEVT_NULL;
+ NMHDR *hdr = (NMHDR *)lParam;
+
+ switch ( hdr->code )
+ {
+ case NM_RCLICK:
+ {
+ if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
+ return TRUE;
+
+ TV_HITTESTINFO tvhti;
+ ::GetCursorPos(&(tvhti.pt));
+ ::ScreenToClient(GetHwnd(),&(tvhti.pt));
+ if ( TreeView_HitTest(GetHwnd(),&tvhti) )
+ {
+ if( tvhti.flags & TVHT_ONITEM )
+ {
+ event.m_item = (WXHTREEITEM) tvhti.hItem;
+ eventType = wxEVT_COMMAND_TREE_ITEM_RIGHT_CLICK;
+ }
+ }
+ }
+ break;
+
+ case TVN_BEGINDRAG:
+ eventType = wxEVT_COMMAND_TREE_BEGIN_DRAG;
+ // fall through
+
+ case TVN_BEGINRDRAG:
+ {
+ if ( eventType == wxEVT_NULL )
+ eventType = wxEVT_COMMAND_TREE_BEGIN_RDRAG;
+ //else: left drag, already set above
+
+ NM_TREEVIEW *tv = (NM_TREEVIEW *)lParam;
+
+ event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
+ event.m_pointDrag = wxPoint(tv->ptDrag.x, tv->ptDrag.y);
+
+ // don't allow dragging by default: the user code must
+ // explicitly say that it wants to allow it to avoid breaking
+ // the old apps
+ event.Veto();
+ }
+ break;
+
+ case TVN_BEGINLABELEDIT:
+ {
+ eventType = wxEVT_COMMAND_TREE_BEGIN_LABEL_EDIT;
+ TV_DISPINFO *info = (TV_DISPINFO *)lParam;
+
+ event.m_item = (WXHTREEITEM) info->item.hItem;
+ event.m_label = info->item.pszText;
+ }
+ break;
+
+ case TVN_DELETEITEM:
+ {
+ eventType = wxEVT_COMMAND_TREE_DELETE_ITEM;
+ NM_TREEVIEW *tv = (NM_TREEVIEW *)lParam;
+
+ event.m_item = (WXHTREEITEM)tv->itemOld.hItem;
+
+ if ( m_hasAnyAttr )
+ {
+ delete (wxTreeItemAttr *)m_attrs.
+ Delete((long)tv->itemOld.hItem);
+ }
+ }
+ break;
+
+ case TVN_ENDLABELEDIT:
+ {
+ eventType = wxEVT_COMMAND_TREE_END_LABEL_EDIT;
+ TV_DISPINFO *info = (TV_DISPINFO *)lParam;
+
+ event.m_item = (WXHTREEITEM)info->item.hItem;
+ event.m_label = info->item.pszText;
+ if (info->item.pszText == NULL)
+ return FALSE;
+ break;
+ }
+
+ case TVN_GETDISPINFO:
+ eventType = wxEVT_COMMAND_TREE_GET_INFO;
+ // fall through
+
+ case TVN_SETDISPINFO:
+ {
+ if ( eventType == wxEVT_NULL )
+ eventType = wxEVT_COMMAND_TREE_SET_INFO;
+ //else: get, already set above
+
+ TV_DISPINFO *info = (TV_DISPINFO *)lParam;
+
+ event.m_item = (WXHTREEITEM) info->item.hItem;
+ break;
+ }
+
+ case TVN_ITEMEXPANDING:
+ event.m_code = FALSE;
+ // fall through
+
+ case TVN_ITEMEXPANDED:
+ {
+ NM_TREEVIEW* tv = (NM_TREEVIEW*)lParam;
+
+ bool expand = FALSE;
+ switch ( tv->action )
+ {
+ case TVE_EXPAND:
+ expand = TRUE;
+ break;
+
+ case TVE_COLLAPSE:
+ expand = FALSE;
+ break;
+
+ default:
+ wxLogDebug(wxT("unexpected code %d in TVN_ITEMEXPAND "
+ "message"), tv->action);
+ }
+
+ bool ing = ((int)hdr->code == TVN_ITEMEXPANDING);
+ eventType = g_events[expand][ing];
+
+ event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
+ }
+ break;
+
+ case TVN_KEYDOWN:
+ {
+ eventType = wxEVT_COMMAND_TREE_KEY_DOWN;
+ TV_KEYDOWN *info = (TV_KEYDOWN *)lParam;
+
+ event.m_code = wxCharCodeMSWToWX(info->wVKey);
+
+ // a separate event for this case
+ if ( info->wVKey == VK_SPACE || info->wVKey == VK_RETURN )
+ {
+ wxTreeEvent event2(wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
+ m_windowId);
+ event2.SetEventObject(this);
+
+ GetEventHandler()->ProcessEvent(event2);
+ }
+ }
+ break;
+
+ case TVN_SELCHANGED:
+ eventType = wxEVT_COMMAND_TREE_SEL_CHANGED;
+ // fall through
+
+ case TVN_SELCHANGING:
+ {
+ if ( eventType == wxEVT_NULL )
+ eventType = wxEVT_COMMAND_TREE_SEL_CHANGING;
+ //else: already set above
+
+ NM_TREEVIEW* tv = (NM_TREEVIEW *)lParam;
+
+ event.m_item = (WXHTREEITEM) tv->itemNew.hItem;
+ event.m_itemOld = (WXHTREEITEM) tv->itemOld.hItem;
+ }
+ break;
+
+#if defined(_WIN32_IE) && _WIN32_IE >= 0x300
+ case NM_CUSTOMDRAW:
+ {
+ LPNMTVCUSTOMDRAW lptvcd = (LPNMTVCUSTOMDRAW)lParam;
+ NMCUSTOMDRAW& nmcd = lptvcd->nmcd;
+ switch( nmcd.dwDrawStage )
+ {
+ case CDDS_PREPAINT:
+ // if we've got any items with non standard attributes,
+ // notify us before painting each item
+ *result = m_hasAnyAttr ? CDRF_NOTIFYITEMDRAW
+ : CDRF_DODEFAULT;
+ return TRUE;
+
+ case CDDS_ITEMPREPAINT:
+ {
+ wxTreeItemAttr *attr =
+ (wxTreeItemAttr *)m_attrs.Get(nmcd.dwItemSpec);
+
+ if ( !attr )
+ {
+ // nothing to do for this item
+ return CDRF_DODEFAULT;
+ }
+
+ HFONT hFont;
+ wxColour colText, colBack;
+ if ( attr->HasFont() )
+ {
+ wxFont font = attr->GetFont();
+ hFont = (HFONT)font.GetResourceHandle();
+ }
+ else
+ {
+ hFont = 0;
+ }
+
+ if ( attr->HasTextColour() )
+ {
+ colText = attr->GetTextColour();
+ }
+ else
+ {
+ colText = GetForegroundColour();
+ }
+
+ // selection colours should override ours
+ if ( nmcd.uItemState & CDIS_SELECTED )
+ {
+ DWORD clrBk = ::GetSysColor(COLOR_HIGHLIGHT);
+ lptvcd->clrTextBk = clrBk;
+
+ // try to make the text visible
+ lptvcd->clrText = wxColourToRGB(colText);
+ lptvcd->clrText |= ~clrBk;
+ lptvcd->clrText &= 0x00ffffff;
+ }
+ else
+ {
+ if ( attr->HasBackgroundColour() )
+ {
+ colBack = attr->GetBackgroundColour();
+ }
+ else
+ {
+ colBack = GetBackgroundColour();
+ }
+
+ lptvcd->clrText = wxColourToRGB(colText);
+ lptvcd->clrTextBk = wxColourToRGB(colBack);
+ }
+
+ // note that if we wanted to set colours for
+ // individual columns (subitems), we would have
+ // returned CDRF_NOTIFYSUBITEMREDRAW from here
+ if ( hFont )
+ {
+ ::SelectObject(nmcd.hdc, hFont);
+
+ *result = CDRF_NEWFONT;
+ }
+ else
+ {
+ *result = CDRF_DODEFAULT;
+ }
+
+ return TRUE;
+ }
+
+ default:
+ *result = CDRF_DODEFAULT;
+ return TRUE;
+ }
+ }
+ break;
+#endif // _WIN32_IE >= 0x300
+
+ default:
+ return wxControl::MSWOnNotify(idCtrl, lParam, result);
+ }