send selection events when Ctrl-clicking an item repeeatedly in a multiselection tree

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45392 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-04-10 23:56:20 +00:00
parent f87a111f9e
commit cc87a04c9d

View File

@@ -95,11 +95,6 @@ static inline void UnselectItem(HWND hwndTV, HTREEITEM htItem)
SelectItem(hwndTV, htItem, false);
}
static inline void ToggleItemSelection(HWND hwndTV, HTREEITEM htItem)
{
SelectItem(hwndTV, htItem, !IsItemSelected(hwndTV, htItem));
}
// helper function which selects all items in a range and, optionally,
// unselects all others
static void SelectRange(HWND hwndTV,
@@ -168,15 +163,18 @@ static void SelectRange(HWND hwndTV,
// helper function which tricks the standard control into changing the focused
// item without changing anything else (if someone knows why Microsoft doesn't
// allow to do it by just setting TVIS_FOCUSED flag, please tell me!)
static void SetFocus(HWND hwndTV, HTREEITEM htItem)
//
// returns true if the focus was changed, false if the given item was already
// the focused one
static bool SetFocus(HWND hwndTV, HTREEITEM htItem)
{
// the current focus
HTREEITEM htFocus = (HTREEITEM)TreeView_GetSelection(hwndTV);
if ( htItem == htFocus )
return false;
if ( htItem )
{
// set the focus
if ( htItem != htFocus )
{
// remember the selection state of the item
bool wasSelected = IsItemSelected(hwndTV, htItem);
@@ -200,11 +198,7 @@ static void SetFocus(HWND hwndTV, HTREEITEM htItem)
}
//else: was selected, still selected - ok
}
//else: nothing to do, focus already there
}
else
{
if ( htFocus )
else // reset focus
{
bool wasFocusSelected = IsItemSelected(hwndTV, htFocus);
@@ -217,8 +211,8 @@ static void SetFocus(HWND hwndTV, HTREEITEM htItem)
SelectItem(hwndTV, htFocus);
}
}
//else: nothing to do, no focus already
}
return true;
}
// ----------------------------------------------------------------------------
@@ -1669,23 +1663,13 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
{
wxCHECK_RET( !IsHiddenRoot(item), _T("can't select hidden root item") );
if ( m_windowStyle & wxTR_MULTIPLE )
{
::SelectItem(GetHwnd(), HITEM(item), select);
}
else
{
wxASSERT_MSG( select,
wxASSERT_MSG( select || HasFlag(wxTR_MULTIPLE),
_T("SelectItem(false) works only for multiselect") );
// inspite of the docs (MSDN Jan 99 edition), we don't seem to receive
// the notification from the control (i.e. TVN_SELCHANG{ED|ING}), so
// send them ourselves
wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, this, item);
if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() )
{
if ( !TreeView_SelectItem(GetHwnd(), HITEM(item)) )
if ( !::SelectItem(GetHwnd(), HITEM(item), select) )
{
wxLogLastError(wxT("TreeView_SelectItem"));
}
@@ -1696,7 +1680,6 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
}
}
//else: program vetoed the change
}
}
void wxTreeCtrl::EnsureVisible(const wxTreeItemId& item)
@@ -2013,7 +1996,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
SetFocus();
// toggle selected state
::ToggleItemSelection(GetHwnd(), htItem);
ToggleItemSelection(htItem);
::SetFocus(GetHwnd(), htItem);
@@ -2209,7 +2192,7 @@ WXLRESULT wxTreeCtrl::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lPara
case VK_SPACE:
if ( bCtrl )
{
::ToggleItemSelection(GetHwnd(), htSel);
ToggleItemSelection(htSel);
}
else
{