+ SelectRange(GetHwnd(),
+ HITEM(m_htSelStart), HITEM(next),
+ SR_UNSELECT_OTHERS);
+ SetFocusedItem(next);
+
+ wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED,
+ this, next);
+ changedEvent.m_itemOld = htSel;
+ (void)HandleTreeEvent(changedEvent);
+ }
+ }
+ }
+ else // no Shift
+ {
+ wxTreeEvent changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING,
+ this, next);
+ changingEvent.m_itemOld = htSel;
+
+ if ( IsTreeEventAllowed(changingEvent) )
+ {
+ DoUnselectAll();
+ DoSelectItem(next);
+ SetFocusedItem(next);
+
+ wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED,
+ this, next);
+ changedEvent.m_itemOld = htSel;
+ (void)HandleTreeEvent(changedEvent);
+ }
+ }
+ }
+ break;
+
+ case VK_PRIOR:
+ case VK_NEXT:
+ if ( bCtrl )
+ {
+ wxTreeItemId firstVisible = GetFirstVisibleItem();
+ size_t visibleCount = TreeView_GetVisibleCount(GetHwnd());
+ wxTreeItemId nextAdjacent = (vkey == VK_PRIOR) ?
+ TreeView_GetPrevVisible(GetHwnd(), HITEM(firstVisible)) :
+ TreeView_GetNextVisible(GetHwnd(), HITEM(firstVisible));
+
+ if ( !nextAdjacent )
+ {
+ break;
+ }
+
+ wxTreeItemId nextStart = firstVisible;
+
+ for ( size_t n = 1; n < visibleCount; n++ )
+ {
+ wxTreeItemId nextTemp = (vkey == VK_PRIOR) ?
+ TreeView_GetPrevVisible(GetHwnd(), HITEM(nextStart)) :
+ TreeView_GetNextVisible(GetHwnd(), HITEM(nextStart));
+
+ if ( nextTemp.IsOk() )
+ {
+ nextStart = nextTemp;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ EnsureVisible(nextStart);
+
+ if ( vkey == VK_NEXT )
+ {
+ wxTreeItemId nextEnd = nextStart;
+
+ for ( size_t n = 1; n < visibleCount; n++ )
+ {
+ wxTreeItemId nextTemp =
+ TreeView_GetNextVisible(GetHwnd(), HITEM(nextEnd));
+
+ if ( nextTemp.IsOk() )
+ {
+ nextEnd = nextTemp;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ EnsureVisible(nextEnd);
+ }
+ }
+ else // no Ctrl
+ {
+ size_t visibleCount = TreeView_GetVisibleCount(GetHwnd());
+ wxTreeItemId nextAdjacent = (vkey == VK_PRIOR) ?
+ TreeView_GetPrevVisible(GetHwnd(), htSel) :
+ TreeView_GetNextVisible(GetHwnd(), htSel);
+
+ if ( !nextAdjacent )
+ {
+ break;
+ }
+
+ wxTreeItemId next(htSel);
+
+ for ( size_t n = 1; n < visibleCount; n++ )
+ {
+ wxTreeItemId nextTemp = vkey == VK_PRIOR ?
+ TreeView_GetPrevVisible(GetHwnd(), HITEM(next)) :
+ TreeView_GetNextVisible(GetHwnd(), HITEM(next));
+
+ if ( !nextTemp.IsOk() )
+ break;
+
+ next = nextTemp;
+ }
+
+ wxTreeEvent changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING,
+ this, next);
+ changingEvent.m_itemOld = htSel;
+
+ if ( IsTreeEventAllowed(changingEvent) )
+ {
+ DoUnselectAll();
+ m_htSelStart.Unset();
+ DoSelectItem(next);
+ SetFocusedItem(next);
+
+ wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED,
+ this, next);
+ changedEvent.m_itemOld = htSel;
+ (void)HandleTreeEvent(changedEvent);
+ }
+ }
+ break;
+
+ default:
+ return false;
+ }
+
+ return true;
+}
+
+bool wxTreeCtrl::MSWHandleTreeKeyDownEvent(WXWPARAM wParam, WXLPARAM lParam)
+{
+ wxTreeEvent keyEvent(wxEVT_COMMAND_TREE_KEY_DOWN, this);
+
+ int keyCode = wxCharCodeMSWToWX(wParam);
+
+ if ( !keyCode )
+ {
+ // wxCharCodeMSWToWX() returns 0 to indicate that this is a
+ // simple ASCII key
+ keyCode = wParam;
+ }
+
+ keyEvent.m_evtKey = CreateKeyEvent(wxEVT_KEY_DOWN, keyCode,
+ lParam, wParam);
+
+ bool processed = HandleTreeEvent(keyEvent);
+
+ // generate a separate event for Space/Return
+ if ( !wxIsCtrlDown() && !wxIsShiftDown() && !wxIsAltDown() &&
+ ((wParam == VK_SPACE) || (wParam == VK_RETURN)) )
+ {
+ const HTREEITEM htSel = (HTREEITEM)TreeView_GetSelection(GetHwnd());
+ if ( htSel )
+ {
+ wxTreeEvent activatedEvent(wxEVT_COMMAND_TREE_ITEM_ACTIVATED,
+ this, htSel);
+ (void)HandleTreeEvent(activatedEvent);
+ }
+ }