fixes to allow dragging in multiselection tree ctrl (patch 759421)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21865 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2003-07-10 13:03:30 +00:00
parent ae8c4b33a3
commit 35cf1ec63c
2 changed files with 73 additions and 16 deletions

View File

@@ -3076,6 +3076,21 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
} }
else if ( event.LeftUp() ) else if ( event.LeftUp() )
{ {
// this facilitates multiple-item drag-and-drop
if (item && HasFlag(wxTR_MULTIPLE))
{
wxArrayTreeItemIds selections;
size_t count = GetSelections(selections);
if (count > 1 &&
!event.ControlDown() &&
!event.ShiftDown())
{
SelectItem(item, true, false);
}
}
if ( m_lastOnSame ) if ( m_lastOnSame )
{ {
if ( (item == m_current) && if ( (item == m_current) &&
@@ -3118,14 +3133,24 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
return; return;
} }
// how should the selection work for this event?
bool is_multiple, extended_select, unselect_others;
EventFlagsToSelType(GetWindowStyleFlag(),
event.ShiftDown(),
event.ControlDown(),
is_multiple, extended_select, unselect_others);
SelectItem(item, unselect_others, extended_select); // clear the previously selected items, if the
// user clicked outside of the present selection.
// otherwise, perform the deselection on mouse-up.
// this allows multiple drag and drop to work.
if (!IsSelected(item))
{
// how should the selection work for this event?
bool is_multiple, extended_select, unselect_others;
EventFlagsToSelType(GetWindowStyleFlag(),
event.ShiftDown(),
event.ControlDown(),
is_multiple, extended_select, unselect_others);
SelectItem(item, unselect_others, extended_select);
}
// For some reason, Windows isn't recognizing a left double-click, // For some reason, Windows isn't recognizing a left double-click,
// so we need to simulate it here. Allow 200 milliseconds for now. // so we need to simulate it here. Allow 200 milliseconds for now.

View File

@@ -2121,20 +2121,34 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{ {
// avoid doing anything if we click on the only // avoid doing anything if we click on the only
// currently selected item // currently selected item
wxArrayTreeItemIds selections; wxArrayTreeItemIds selections;
size_t count = GetSelections(selections); size_t count = GetSelections(selections);
if ( count == 0 || if ( count == 0 ||
count > 1 || count > 1 ||
HITEM(selections[0]) != htItem ) HITEM(selections[0]) != htItem )
{ {
// clear the previously selected items // clear the previously selected items, if the
UnselectAll(); // user clicked outside of the present selection.
// otherwise, perform the deselection on mouse-up.
// this allows multiple drag and drop to work.
if (IsItemSelected(GetHwnd(), htItem))
{
::SetFocus(GetHwnd(), htItem);
}
else
{
UnselectAll();
// prevent the click from starting in-place editing // prevent the click from starting in-place editing
// which should only happen if we click on the // which should only happen if we click on the
// already selected item (and nothing else is // already selected item (and nothing else is
// selected) // selected)
TreeView_SelectItem(GetHwnd(), 0);
TreeView_SelectItem(GetHwnd(), 0);
::SelectItem(GetHwnd(), htItem);
}
} }
// reset on any click without Shift // reset on any click without Shift
@@ -2160,6 +2174,24 @@ long wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
break; break;
case WM_LBUTTONUP: case WM_LBUTTONUP:
// facilitates multiple drag-and-drop
if (htItem && isMultiple)
{
wxArrayTreeItemIds selections;
size_t count = GetSelections(selections);
if (count > 1 &&
!(wParam & MK_CONTROL) &&
!(wParam & MK_SHIFT))
{
UnselectAll();
TreeView_SelectItem(GetHwnd(), htItem);
}
}
// fall through
case WM_RBUTTONUP: case WM_RBUTTONUP:
if ( m_dragImage ) if ( m_dragImage )
{ {