make wxTreeCtrl::SelectItem(false) work in single selection controls under MSW (fixing the recently added unit test); also set the previously selected item in the selection changing/changed messages

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60921 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-06-06 22:56:57 +00:00
parent d121598c37
commit 8664669368

View File

@ -1878,8 +1878,9 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
{
wxCHECK_RET( !IsHiddenRoot(item), _T("can't select hidden root item") );
if ( IsSelected(item) == select )
if ( select == IsSelected(item) )
{
// nothing to do, the item is already in the requested state
return;
}
@ -1902,20 +1903,31 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
(void)HandleTreeEvent(changedEvent);
}
}
else
else // single selection
{
wxASSERT_MSG( select,
_T("SelectItem(false) works only for multiselect") );
wxTreeItemId itemOld, itemNew;
if ( select )
{
itemOld = GetSelection();
itemNew = item;
}
else // deselecting the currently selected item
{
itemOld = item;
// leave itemNew invalid
}
// in spite 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 changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this, item);
wxTreeEvent
changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this, itemNew);
changingEvent.SetOldItem(itemOld);
if ( IsTreeEventAllowed(changingEvent) )
{
if ( !TreeView_SelectItem(GetHwnd(), HITEM(item)) )
if ( !TreeView_SelectItem(GetHwnd(), HITEM(itemNew)) )
{
wxLogLastError(wxT("TreeView_SelectItem"));
}
@ -1924,7 +1936,8 @@ void wxTreeCtrl::SelectItem(const wxTreeItemId& item, bool select)
SetFocusedItem(item);
wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED,
this, item);
this, itemNew);
changedEvent.SetOldItem(itemOld);
(void)HandleTreeEvent(changedEvent);
}
}