Applied patch [ 1212208 ] Fix a bug in wxTreeCtrl with wxTR_MULTIPLE

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34677 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2005-06-16 17:01:19 +00:00
parent 8af56e0827
commit e3ad57026a
2 changed files with 64 additions and 8 deletions

View File

@@ -498,7 +498,8 @@ private:
void* m_pVirtualRoot; void* m_pVirtualRoot;
// the starting item for selection with Shift // the starting item for selection with Shift
wxTreeItemId m_htSelStart; wxTreeItemId m_htSelStart, m_htClickedItem;
wxPoint m_ptClick;
friend class wxTreeItemIndirectData; friend class wxTreeItemIndirectData;
friend class wxTreeSortHelper; friend class wxTreeSortHelper;

View File

@@ -2290,6 +2290,12 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
y = GET_Y_LPARAM(lParam); y = GET_Y_LPARAM(lParam);
HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y); HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y);
TV_HITTESTINFO tvht;
tvht.pt.x = x;
tvht.pt.y = y;
TreeView_HitTest(GetHwnd(), &tvht);
switch ( nMsg ) switch ( nMsg )
{ {
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
@@ -2309,8 +2315,11 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
#if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE #if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
if ( htItem && isMultiple ) if ( htItem && isMultiple && (tvht.flags & TVHT_ONITEM) != 0 )
{ {
m_htClickedItem = (WXHTREEITEM) htItem;
m_ptClick = wxPoint(x, y);
if ( wParam & MK_CONTROL ) if ( wParam & MK_CONTROL )
{ {
SetFocus(); SetFocus();
@@ -2336,8 +2345,11 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
m_htSelStart = TreeView_GetSelection(GetHwnd()); m_htSelStart = TreeView_GetSelection(GetHwnd());
} }
if ( m_htSelStart )
SelectRange(GetHwnd(), HITEM(m_htSelStart), htItem, SelectRange(GetHwnd(), HITEM(m_htSelStart), htItem,
!(wParam & MK_CONTROL)); !(wParam & MK_CONTROL));
else
::SelectItem(GetHwnd(), htItem);
::SetFocus(GetHwnd(), htItem); ::SetFocus(GetHwnd(), htItem);
@@ -2348,6 +2360,8 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
// avoid doing anything if we click on the only // avoid doing anything if we click on the only
// currently selected item // currently selected item
SetFocus();
wxArrayTreeItemIds selections; wxArrayTreeItemIds selections;
size_t count = GetSelections(selections); size_t count = GetSelections(selections);
if ( count == 0 || if ( count == 0 ||
@@ -2359,11 +2373,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
// otherwise, perform the deselection on mouse-up. // otherwise, perform the deselection on mouse-up.
// this allows multiple drag and drop to work. // this allows multiple drag and drop to work.
if (IsItemSelected(GetHwnd(), htItem)) if (!IsItemSelected(GetHwnd(), htItem))
{
::SetFocus(GetHwnd(), htItem);
}
else
{ {
UnselectAll(); UnselectAll();
@@ -2375,6 +2385,8 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
TreeView_SelectItem(GetHwnd(), 0); TreeView_SelectItem(GetHwnd(), 0);
::SelectItem(GetHwnd(), htItem); ::SelectItem(GetHwnd(), htItem);
} }
::SetFocus(GetHwnd(), htItem);
processed = true;
} }
// reset on any click without Shift // reset on any click without Shift
@@ -2385,6 +2397,46 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE #endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
if ( m_htClickedItem )
{
int cx = abs(m_ptClick.x - x);
int cy = abs(m_ptClick.y - y);
if ( cx > GetSystemMetrics( SM_CXDRAG ) || cy > GetSystemMetrics( SM_CYDRAG ) )
{
HWND pWnd = ::GetParent( GetHwnd() );
if ( pWnd )
{
NM_TREEVIEW tv;
tv.hdr.hwndFrom = GetHwnd();
tv.hdr.idFrom = ::GetWindowLong( GetHwnd(), GWL_ID );
tv.hdr.code = TVN_BEGINDRAG;
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;
tv.ptDrag.x = x;
tv.ptDrag.y = y;
::SendMessage( pWnd, WM_NOTIFY, tv.hdr.idFrom, (LPARAM)&tv );
}
m_htClickedItem.Unset();
}
}
if ( m_dragImage ) if ( m_dragImage )
{ {
m_dragImage->Move(wxPoint(x, y)); m_dragImage->Move(wxPoint(x, y));
@@ -2413,7 +2465,10 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
{ {
UnselectAll(); UnselectAll();
TreeView_SelectItem(GetHwnd(), htItem); TreeView_SelectItem(GetHwnd(), htItem);
::SelectItem(GetHwnd(), htItem);
::SetFocus(GetHwnd(), htItem);
} }
m_htClickedItem.Unset();
} }
// fall through // fall through