+ return true;
+}
+
+// we hook into WndProc to process WM_MOUSEMOVE/WM_BUTTONUP messages - as we
+// only do it during dragging, minimize wxWin overhead (this is important for
+// WM_MOUSEMOVE as they're a lot of them) by catching Windows messages directly
+// instead of passing by wxWin events
+WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
+{
+ bool processed = false;
+ WXLRESULT rc = 0;
+ bool isMultiple = (GetWindowStyle() & wxTR_MULTIPLE) != 0;
+
+ if ( (nMsg >= WM_MOUSEFIRST) && (nMsg <= WM_MOUSELAST) )
+ {
+ // we only process mouse messages here and these parameters have the
+ // same meaning for all of them
+ int x = GET_X_LPARAM(lParam),
+ y = GET_Y_LPARAM(lParam);
+ HTREEITEM htItem = GetItemFromPoint(GetHwnd(), x, y);
+
+ switch ( nMsg )
+ {
+ case WM_RBUTTONDOWN:
+ // if the item we are about to right click on is not already
+ // selected or if we click outside of any item, remove the
+ // entire previous selection
+ if ( !htItem || !::IsItemSelected(GetHwnd(), htItem) )
+ {
+ UnselectAll();
+ }
+
+ // select item and set the focus to the
+ // newly selected item
+ ::SelectItem(GetHwnd(), htItem);
+ ::SetFocus(GetHwnd(), htItem);
+ break;
+
+#if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+ case WM_LBUTTONDOWN:
+ if ( htItem && isMultiple )
+ {
+ if ( wParam & MK_CONTROL )
+ {
+ SetFocus();
+
+ // toggle selected state
+ ::ToggleItemSelection(GetHwnd(), htItem);
+
+ ::SetFocus(GetHwnd(), htItem);
+
+ // reset on any click without Shift
+ m_htSelStart.Unset();
+
+ processed = true;
+ }
+ else if ( wParam & MK_SHIFT )
+ {
+ // this selects all items between the starting one and
+ // the current
+
+ if ( !m_htSelStart )
+ {
+ // take the focused item
+ m_htSelStart = TreeView_GetSelection(GetHwnd());
+ }
+
+ SelectRange(GetHwnd(), HITEM(m_htSelStart), htItem,
+ !(wParam & MK_CONTROL));
+
+ ::SetFocus(GetHwnd(), htItem);
+
+ processed = true;
+ }
+ else // normal click
+ {
+ // avoid doing anything if we click on the only
+ // currently selected item
+
+ wxArrayTreeItemIds selections;
+ size_t count = GetSelections(selections);
+ if ( count == 0 ||
+ count > 1 ||
+ HITEM_PTR(selections[0]) != htItem )
+ {
+ // 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 (IsItemSelected(GetHwnd(), htItem))
+ {
+ ::SetFocus(GetHwnd(), htItem);
+ }
+ else
+ {
+ UnselectAll();
+
+ // prevent the click from starting in-place editing
+ // which should only happen if we click on the
+ // already selected item (and nothing else is
+ // selected)
+
+ TreeView_SelectItem(GetHwnd(), 0);
+ ::SelectItem(GetHwnd(), htItem);
+ }
+ }
+
+ // reset on any click without Shift
+ m_htSelStart.Unset();
+ }
+ }
+ break;
+#endif // wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+
+ case WM_MOUSEMOVE:
+ if ( m_dragImage )
+ {
+ m_dragImage->Move(wxPoint(x, y));
+ if ( htItem )
+ {
+ // highlight the item as target (hiding drag image is
+ // necessary - otherwise the display will be corrupted)
+ m_dragImage->Hide();
+ TreeView_SelectDropTarget(GetHwnd(), htItem);
+ m_dragImage->Show();
+ }
+ }
+ break;
+
+ 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:
+ if ( m_dragImage )
+ {
+ m_dragImage->EndDrag();
+ delete m_dragImage;
+ m_dragImage = NULL;
+
+ // generate the drag end event
+ wxTreeEvent event(wxEVT_COMMAND_TREE_END_DRAG, m_windowId);
+
+ event.m_item = htItem;
+ event.m_pointDrag = wxPoint(x, y);
+ event.SetEventObject(this);
+
+ (void)GetEventHandler()->ProcessEvent(event);
+
+ // 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);
+ }
+ break;
+ }
+ }
+#if !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+ else if ( (nMsg == WM_SETFOCUS || nMsg == WM_KILLFOCUS) && isMultiple )
+ {
+ // the tree control greys out the selected item when it loses focus and
+ // paints it as selected again when it regains it, but it won't do it
+ // for the other items itself - help it
+ wxArrayTreeItemIds selections;
+ size_t count = GetSelections(selections);
+ RECT rect;
+ for ( size_t n = 0; n < count; n++ )
+ {
+ // TreeView_GetItemRect() will return false if item is not visible,
+ // which may happen perfectly well
+ if ( TreeView_GetItemRect(GetHwnd(), HITEM_PTR(selections[n]),
+ &rect, true) )
+ {
+ ::InvalidateRect(GetHwnd(), &rect, false);
+ }
+ }
+ }
+ else if ( nMsg == WM_KEYDOWN && isMultiple )
+ {
+ bool bCtrl = wxIsCtrlDown(),
+ bShift = wxIsShiftDown();
+
+ // we handle.arrows and space, but not page up/down and home/end: the
+ // latter should be easy, but not the former
+
+ HTREEITEM htSel = (HTREEITEM)TreeView_GetSelection(GetHwnd());
+ if ( !m_htSelStart )
+ {
+ m_htSelStart = htSel;
+ }
+
+ if ( wParam == VK_SPACE )
+ {
+ if ( bCtrl )
+ {
+ ::ToggleItemSelection(GetHwnd(), htSel);
+ }
+ else
+ {
+ UnselectAll();
+
+ ::SelectItem(GetHwnd(), htSel);
+ }
+
+ processed = true;
+ }
+ else if ( wParam == VK_UP || wParam == VK_DOWN )
+ {
+ if ( !bCtrl && !bShift )
+ {
+ // no modifiers, just clear selection and then let the default
+ // processing to take place
+ UnselectAll();
+ }
+ else if ( htSel )
+ {
+ (void)wxControl::MSWWindowProc(nMsg, wParam, lParam);
+
+ HTREEITEM htNext = (HTREEITEM)(wParam == VK_UP
+ ? TreeView_GetPrevVisible(GetHwnd(), htSel)
+ : TreeView_GetNextVisible(GetHwnd(), htSel));
+
+ if ( !htNext )
+ {
+ // at the top/bottom
+ htNext = htSel;
+ }
+
+ if ( bShift )
+ {
+ SelectRange(GetHwnd(), HITEM(m_htSelStart), htNext);
+ }
+ else // bCtrl
+ {
+ // without changing selection
+ ::SetFocus(GetHwnd(), htNext);
+ }
+
+ processed = true;
+ }
+ }
+ }
+#endif // !wxUSE_CHECKBOXES_IN_MULTI_SEL_TREE
+ else if ( nMsg == WM_CHAR )
+ {
+ // don't let the control process Space and Return keys because it
+ // doesn't do anything useful with them anyhow but always beeps
+ // annoyingly when it receives them and there is no way to turn it off
+ // simply if you just process TREEITEM_ACTIVATED event to which Space
+ // and Enter presses are mapped in your code
+ if ( wParam == VK_SPACE || wParam == VK_RETURN )
+ {
+ processed = true;
+ }
+ }
+
+ if ( !processed )
+ rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
+
+ return rc;