implemented SelectItem(item, bool); UnselectItem() and ToggleItemSelection()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@25716 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2004-02-10 19:14:41 +00:00
parent e55e94865f
commit 78f1210463
2 changed files with 42 additions and 13 deletions

View File

@@ -301,9 +301,18 @@ public:
// remove the selection from currently selected item (if any) // remove the selection from currently selected item (if any)
void Unselect(); void Unselect();
// or from the given one (multiselect mode only)
void UnselectItem(const wxTreeItemId& item) { SelectItem(item, false); }
// or from all
void UnselectAll(); void UnselectAll();
// select this item // select this item
void SelectItem(const wxTreeItemId& item, bool unselect_others=TRUE, bool extended_select=FALSE); void SelectItem(const wxTreeItemId& item, bool select = true);
// toggle the item selection
void ToggleItemSelection(const wxTreeItemId& item)
{
SelectItem(item, !IsSelected(item));
}
// make sure this item is visible (expanding the parent item and/or // make sure this item is visible (expanding the parent item and/or
// scrolling to this item if necessary) // scrolling to this item if necessary)
void EnsureVisible(const wxTreeItemId& item); void EnsureVisible(const wxTreeItemId& item);
@@ -432,6 +441,10 @@ protected:
void DrawLine(const wxTreeItemId& item, bool below); void DrawLine(const wxTreeItemId& item, bool below);
void DrawDropEffect(wxGenericTreeItem *item); void DrawDropEffect(wxGenericTreeItem *item);
void DoSelectItem(const wxTreeItemId& id,
bool unselect_others = TRUE,
bool extended_select = FALSE);
wxTreeItemId DoInsertItem(const wxTreeItemId& parent, wxTreeItemId DoInsertItem(const wxTreeItemId& parent,
size_t previous, size_t previous,
const wxString& text, const wxString& text,

View File

@@ -1726,9 +1726,9 @@ void wxGenericTreeCtrl::SelectItemRange(wxGenericTreeItem *item1, wxGenericTreeI
TagNextChildren(first,last,select); TagNextChildren(first,last,select);
} }
void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId, void wxGenericTreeCtrl::DoSelectItem(const wxTreeItemId& itemId,
bool unselect_others, bool unselect_others,
bool extended_select) bool extended_select)
{ {
wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") ); wxCHECK_RET( itemId.IsOk(), wxT("invalid tree item") );
@@ -1811,6 +1811,22 @@ void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId,
GetEventHandler()->ProcessEvent( event ); GetEventHandler()->ProcessEvent( event );
} }
void wxGenericTreeCtrl::SelectItem(const wxTreeItemId& itemId, bool select)
{
if ( select )
{
DoSelectItem(itemId);
}
else // deselect
{
wxGenericTreeItem *item = (wxGenericTreeItem*) itemId.m_pItem;
wxCHECK_RET( item, wxT("SelectItem(): invalid tree item") );
item->SetHilight(FALSE);
RefreshLine(item);
}
}
void wxGenericTreeCtrl::FillArray(wxGenericTreeItem *item, void wxGenericTreeCtrl::FillArray(wxGenericTreeItem *item,
wxArrayTreeItemIds &array) const wxArrayTreeItemIds &array) const
{ {
@@ -2579,7 +2595,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
if (current == GetFirstChild( prev, cookie )) if (current == GetFirstChild( prev, cookie ))
{ {
// otherwise we return to where we came from // otherwise we return to where we came from
SelectItem( prev, unselect_others, extended_select ); DoSelectItem( prev, unselect_others, extended_select );
m_key_current= (wxGenericTreeItem*) prev.m_pItem; m_key_current= (wxGenericTreeItem*) prev.m_pItem;
break; break;
} }
@@ -2596,7 +2612,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
} }
} }
SelectItem( prev, unselect_others, extended_select ); DoSelectItem( prev, unselect_others, extended_select );
m_key_current=(wxGenericTreeItem*) prev.m_pItem; m_key_current=(wxGenericTreeItem*) prev.m_pItem;
} }
} }
@@ -2613,7 +2629,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
} }
if (prev) if (prev)
{ {
SelectItem( prev, unselect_others, extended_select ); DoSelectItem( prev, unselect_others, extended_select );
} }
} }
break; break;
@@ -2630,7 +2646,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
{ {
wxTreeItemIdValue cookie; wxTreeItemIdValue cookie;
wxTreeItemId child = GetFirstChild( m_key_current, cookie ); wxTreeItemId child = GetFirstChild( m_key_current, cookie );
SelectItem( child, unselect_others, extended_select ); DoSelectItem( child, unselect_others, extended_select );
m_key_current=(wxGenericTreeItem*) child.m_pItem; m_key_current=(wxGenericTreeItem*) child.m_pItem;
} }
else else
@@ -2647,7 +2663,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
} }
if (next) if (next)
{ {
SelectItem( next, unselect_others, extended_select ); DoSelectItem( next, unselect_others, extended_select );
m_key_current=(wxGenericTreeItem*) next.m_pItem; m_key_current=(wxGenericTreeItem*) next.m_pItem;
} }
} }
@@ -2674,7 +2690,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
if ( last.IsOk() ) if ( last.IsOk() )
{ {
SelectItem( last, unselect_others, extended_select ); DoSelectItem( last, unselect_others, extended_select );
} }
} }
break; break;
@@ -2694,7 +2710,7 @@ void wxGenericTreeCtrl::OnChar( wxKeyEvent &event )
break; break;
} }
SelectItem( prev, unselect_others, extended_select ); DoSelectItem( prev, unselect_others, extended_select );
} }
break; break;
@@ -3019,7 +3035,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
!event.ControlDown() && !event.ControlDown() &&
!event.ShiftDown()) !event.ShiftDown())
{ {
SelectItem(item, true, false); DoSelectItem(item, true, false);
} }
} }
@@ -3080,7 +3096,7 @@ void wxGenericTreeCtrl::OnMouse( wxMouseEvent &event )
event.ControlDown(), event.ControlDown(),
is_multiple, extended_select, unselect_others); is_multiple, extended_select, unselect_others);
SelectItem(item, unselect_others, extended_select); DoSelectItem(item, unselect_others, extended_select);
} }