wxFLAGS_MEMBER(wxTR_HAS_VARIABLE_ROW_HEIGHT)
wxFLAGS_MEMBER(wxTR_SINGLE)
wxFLAGS_MEMBER(wxTR_MULTIPLE)
+#if WXWIN_COMPATIBILITY_2_8
wxFLAGS_MEMBER(wxTR_EXTENDED)
+#endif
wxFLAGS_MEMBER(wxTR_DEFAULT_STYLE)
wxEND_FLAGS( wxTreeCtrlStyle )
{
m_textCtrl = NULL;
m_hasAnyAttr = false;
+#if wxUSE_DRAGIMAGE
m_dragImage = NULL;
+#endif
m_pVirtualRoot = NULL;
// initialize the global array of events now as it can't be done statically
{
if ( item == m_idEdited )
{
- ::SetWindowText(hwndEdit, text);
+ ::SetWindowText(hwndEdit, text.wx_str());
}
}
}
wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, this, item);
if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
{
- if ( !::SelectItem(GetHwnd(), HITEM(item), select) )
+ if ( HasFlag(wxTR_MULTIPLE) )
{
- wxLogLastError(wxT("TreeView_SelectItem"));
+ if ( !::SelectItem(GetHwnd(), HITEM(item), select) )
+ {
+ wxLogLastError(wxT("TreeView_SelectItem"));
+ return;
+ }
}
- else // ok
+ else // single selection
{
- event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
- (void)GetEventHandler()->ProcessEvent(event);
+ // use TreeView_SelectItem() to deselect the previous selection
+ if ( !TreeView_SelectItem(GetHwnd(), HITEM(item)) )
+ {
+ wxLogLastError(wxT("TreeView_SelectItem"));
+ return;
+ }
}
+
+ event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
+ (void)GetEventHandler()->ProcessEvent(event);
}
//else: program vetoed the change
}
::SetFocus(GetHwnd(), htItem);
processed = true;
}
+ else // click on a single selected item
+ {
+ // don't interfere with the default processing in
+ // WM_MOUSEMOVE handler below as the default window
+ // proc will start the drag itself if we let have
+ // WM_LBUTTONDOWN
+ m_htClickedItem.Unset();
+ }
// reset on any click without Shift
m_htSelStart.Unset();
int cx = abs(m_ptClick.x - x);
int cy = abs(m_ptClick.y - y);
- if ( cx > GetSystemMetrics( SM_CXDRAG ) || cy > GetSystemMetrics( SM_CYDRAG ) )
+ if ( cx > ::GetSystemMetrics(SM_CXDRAG) ||
+ cy > ::GetSystemMetrics(SM_CYDRAG) )
{
- HWND pWnd = ::GetParent( GetHwnd() );
- if ( pWnd )
- {
- NM_TREEVIEW tv;
+ NM_TREEVIEW tv;
+ wxZeroMemory(tv);
- tv.hdr.hwndFrom = GetHwnd();
- tv.hdr.idFrom = ::GetWindowLong( GetHwnd(), GWL_ID );
- tv.hdr.code = TVN_BEGINDRAG;
+ tv.hdr.hwndFrom = GetHwnd();
+ tv.hdr.idFrom = ::GetWindowLong(GetHwnd(), GWL_ID);
+ tv.hdr.code = TVN_BEGINDRAG;
- tv.itemNew.hItem = HITEM(m_htClickedItem);
+ tv.itemNew.hItem = HITEM(m_htClickedItem);
- TVITEM tviAux;
- ZeroMemory(&tviAux, sizeof(tviAux));
- tviAux.hItem = HITEM(m_htClickedItem);
- tviAux.mask = TVIF_STATE | TVIF_PARAM;
- tviAux.stateMask = 0xffffffff;
- TreeView_GetItem( GetHwnd(), &tviAux );
- tv.itemNew.state = tviAux.state;
- tv.itemNew.lParam = tviAux.lParam;
+ TVITEM tviAux;
+ wxZeroMemory(tviAux);
- tv.ptDrag.x = x;
- tv.ptDrag.y = y;
+ tviAux.hItem = HITEM(m_htClickedItem);
+ tviAux.mask = TVIF_STATE | TVIF_PARAM;
+ tviAux.stateMask = 0xffffffff;
+ TreeView_GetItem(GetHwnd(), &tviAux);
- ::SendMessage( pWnd, WM_NOTIFY, tv.hdr.idFrom, (LPARAM)&tv );
- }
+ tv.itemNew.state = tviAux.state;
+ tv.itemNew.lParam = tviAux.lParam;
+
+ tv.ptDrag.x = x;
+ tv.ptDrag.y = y;
+
+ // do it before SendMessage() call below to avoid
+ // reentrancies here if there is another WM_MOUSEMOVE
+ // in the queue already
m_htClickedItem.Unset();
+
+ ::SendMessage(GetHwndOf(GetParent()), WM_NOTIFY,
+ tv.hdr.idFrom, (LPARAM)&tv );
+
+ // don't pass it to the default window proc, it would
+ // start dragging again
+ processed = true;
}
}
#endif // __WXWINCE__
+#if wxUSE_DRAGIMAGE
if ( m_dragImage )
{
m_dragImage->Move(wxPoint(x, y));
m_dragImage->Show();
}
}
+#endif // wxUSE_DRAGIMAGE
break;
case WM_LBUTTONUP:
// fall through
case WM_RBUTTONUP:
+#if wxUSE_DRAGIMAGE
if ( m_dragImage )
{
m_dragImage->EndDrag();
// are selected simultaneously which is quite weird
TreeView_SelectDropTarget(GetHwnd(), 0);
}
+#endif // wxUSE_DRAGIMAGE
break;
}
}
if ( wParam == VK_SPACE || wParam == VK_RETURN )
return 0;
}
+#if wxUSE_DRAGIMAGE
+ else if ( nMsg == WM_KEYDOWN )
+ {
+ if ( wParam == VK_ESCAPE )
+ {
+ if ( m_dragImage )
+ {
+ m_dragImage->EndDrag();
+ delete m_dragImage;
+ m_dragImage = NULL;
+
+ // if we don't do it, the tree seems to think that 2 items
+ // are selected simultaneously which is quite weird
+ TreeView_SelectDropTarget(GetHwnd(), 0);
+ }
+ }
+ }
+#endif // wxUSE_DRAGIMAGE
return wxControl::MSWDefWindowProc(nMsg, wParam, lParam);
}
case TVN_BEGINDRAG:
case TVN_BEGINRDRAG:
+#if wxUSE_DRAGIMAGE
if ( event.IsAllowed() )
{
// normally this is impossible because the m_dragImage is
m_dragImage->BeginDrag(wxPoint(0,0), this);
m_dragImage->Show();
}
+#endif // wxUSE_DRAGIMAGE
break;
case TVN_DELETEITEM: