Ticket #11620: tree-selectall.patch

File tree-selectall.patch, 8.3 KB (added by TNikolay, 8 years ago)
  • include/wx/generic/treectlg.h

     
    155155    virtual void Unselect();
    156156    virtual void UnselectAll();
    157157    virtual void SelectItem(const wxTreeItemId& item, bool select = true);
     158    virtual void SelectAll(const wxTreeItemId& parent);
    158159
    159160    virtual void EnsureVisible(const wxTreeItemId& item);
    160161    virtual void ScrollTo(const wxTreeItemId& item);
  • include/wx/msw/treectrl.h

     
    128128    virtual wxTreeItemId GetSelection() const;
    129129    virtual size_t GetSelections(wxArrayTreeItemIds& selections) const;
    130130    virtual wxTreeItemId GetFocusedItem() const;
    131 
     131   
    132132    virtual wxTreeItemId GetItemParent(const wxTreeItemId& item) const;
    133133    virtual wxTreeItemId GetFirstChild(const wxTreeItemId& item,
    134134                                       wxTreeItemIdValue& cookie) const;
     
    162162    virtual void Unselect();
    163163    virtual void UnselectAll();
    164164    virtual void SelectItem(const wxTreeItemId& item, bool select = true);
     165    virtual void SelectAll(const wxTreeItemId& parent);
    165166
    166167    virtual void EnsureVisible(const wxTreeItemId& item);
    167168    virtual void ScrollTo(const wxTreeItemId& item);
     
    276277    void DoToggleItemSelection(const wxTreeItemId& item);
    277278
    278279    void DoUnselectAll();
     280    void DoSelectAll(const wxTreeItemId& parent);
    279281
    280282    void DeleteTextCtrl();
    281283
  • include/wx/treectrl.h

     
    324324    virtual void UnselectAll() = 0;
    325325        // select this item
    326326    virtual void SelectItem(const wxTreeItemId& item, bool select = true) = 0;
     327        // Selects all first-level children for given parent. This works in
     328        //multiselection controls only.
     329    virtual void SelectAll(const wxTreeItemId& parent) = 0;
    327330        // unselect this item
    328331    void UnselectItem(const wxTreeItemId& item) { SelectItem(item, false); }
    329332        // toggle item selection
     
    400403protected:
    401404    virtual wxSize DoGetBestSize() const;
    402405
    403     // comon part of Get/SetItemState()
     406    // common part of Get/SetItemState()
    404407    virtual int DoGetItemState(const wxTreeItemId& item) const = 0;
    405408    virtual void DoSetItemState(const wxTreeItemId& item, int state) = 0;
    406409
  • interface/wx/treectrl.h

     
    954954        Unselects the given item. This works in multiselection controls only.
    955955    */
    956956    void UnselectItem(const wxTreeItemId& item);
     957
     958    /**
     959    Selects all first-level children for given parent. This works in multiselection
     960    controls only.
     961    */
     962    virtual void SelectAll(const wxTreeItemId& parent);
    957963};
    958964
    959965
  • samples/treectrl/treetest.cpp

     
    9898    MENU_LINK(Select)
    9999    MENU_LINK(Unselect)
    100100    MENU_LINK(ToggleSel)
     101    MENU_LINK(SelectAllItems)
    101102#endif // NO_MULTIPLE_SELECTION
    102103    MENU_LINK(Rename)
    103104    MENU_LINK(Count)
     
    262263    tree_menu->Append(TreeTest_DeleteChildren, wxT("Delete &children"));
    263264    tree_menu->Append(TreeTest_DeleteAll, wxT("Delete &all items"));
    264265    tree_menu->Append(TreeTest_SelectRoot, wxT("Select root item"));
     266   
    265267    tree_menu->AppendSeparator();
    266268    tree_menu->Append(TreeTest_Count, wxT("Count children of current item"));
    267269    tree_menu->Append(TreeTest_CountRec, wxT("Recursively count children of current item"));
     
    307309    item_menu->Append(TreeTest_DumpSelected, wxT("Dump selected items\tAlt-D"));
    308310    item_menu->Append(TreeTest_Select, wxT("Select current item\tAlt-S"));
    309311    item_menu->Append(TreeTest_Unselect, wxT("Unselect everything\tAlt-U"));
     312    item_menu->Append(TreeTest_SelectAllItems, wxT("Select all items\tCtrl-A"));
    310313#endif // NO_MULTIPLE_SELECTION
    311314
    312315    wxMenuBar *menu_bar = new wxMenuBar;
     
    594597    m_treeCtrl->UnselectAll();
    595598}
    596599
     600
     601void MyFrame::OnSelectAllItems(wxCommandEvent& WXUNUSED(event))
     602{
     603    wxTreeItemId item = m_treeCtrl->GetFocusedItem();
     604    if ( !item.IsOk() )
     605        item = m_treeCtrl->GetRootItem();
     606   
     607    if ( item != m_treeCtrl->GetRootItem() )
     608        item = m_treeCtrl->GetItemParent(item);
     609    m_treeCtrl->SelectAll(item);
     610}
     611
    597612#endif // NO_MULTIPLE_SELECTION
    598613
    599614void MyFrame::DoSetBold(bool bold)
  • samples/treectrl/treetest.h

     
    209209    void OnSelect(wxCommandEvent& event);
    210210    void OnUnselect(wxCommandEvent& event);
    211211    void OnToggleSel(wxCommandEvent& event);
     212    void OnSelectAllItems(wxCommandEvent& event);
    212213#endif // NO_MULTIPLE_SELECTION
    213214    void OnSelectRoot(wxCommandEvent& event);
    214215    void OnDelete(wxCommandEvent& event);
     
    354355    TreeTest_Select,
    355356    TreeTest_Unselect,
    356357    TreeTest_SelectRoot,
     358    TreeTest_SelectAllItems,
    357359    TreeTest_ShowFirstVisible,
    358360    TreeTest_ShowLastVisible,
    359361    TreeTest_ShowNextVisible,
  • src/generic/treectlg.cpp

     
    19831983    }
    19841984}
    19851985
     1986
     1987void wxGenericTreeCtrl::SelectAll(const wxTreeItemId& parent)
     1988{
     1989    wxCHECK_RET( HasFlag(wxTR_MULTIPLE), wxT("this only works with multiple selection controls") );
     1990
     1991    UnselectAll();
     1992
     1993    if ( !HasChildren(parent) )
     1994        return;
     1995 
     1996
     1997    wxArrayGenericTreeItems& children = ((wxGenericTreeItem*) parent.m_pItem)->GetChildren();
     1998    size_t count = children.GetCount();
     1999
     2000    wxGenericTreeItem *_item = (wxGenericTreeItem*) ((wxTreeItemId)children[0]).m_pItem;
     2001    wxTreeEvent event(wxEVT_COMMAND_TREE_SEL_CHANGING, this, (wxGenericTreeItem*) _item);
     2002    event.m_itemOld = m_current;
     2003
     2004    if ( GetEventHandler()->ProcessEvent( event ) && !event.IsAllowed() )
     2005        return;
     2006
     2007    for ( size_t n = 0; n < count; ++n )
     2008    {
     2009        m_current = m_key_current = children[n];
     2010        m_current->SetHilight(true);
     2011        RefreshSelected();
     2012    }
     2013
     2014   
     2015    event.SetEventType(wxEVT_COMMAND_TREE_SEL_CHANGED);
     2016    GetEventHandler()->ProcessEvent( event );
     2017}
     2018
     2019
    19862020// Recursive function !
    19872021// To stop we must have crt_item<last_item
    19882022// Algorithm :
  • src/msw/treectrl.cpp

     
    18831883    }
    18841884}
    18851885
     1886void wxTreeCtrl::DoSelectAll(const wxTreeItemId& parent)
     1887{
     1888    DoUnselectAll();
     1889   
     1890    wxTreeItemIdValue cookie;
     1891    wxTreeItemId child = GetFirstChild(parent, cookie);
     1892    while ( child.IsOk() )
     1893    {
     1894        DoSelectItem(child, true);
     1895        child = GetNextChild(child, cookie);
     1896    }
     1897}
     1898
     1899void wxTreeCtrl::SelectAll(const wxTreeItemId& parent)
     1900{
     1901    wxCHECK_RET( HasFlag(wxTR_MULTIPLE), wxT("this only works with multiple selection controls") );
     1902
     1903    HTREEITEM htFocus = (HTREEITEM)TreeView_GetSelection(GetHwnd());
     1904
     1905    wxTreeEvent changingEvent(wxEVT_COMMAND_TREE_SEL_CHANGING, this);
     1906    changingEvent.m_itemOld = htFocus;
     1907
     1908    if ( IsTreeEventAllowed(changingEvent) )
     1909    {
     1910        DoSelectAll(parent);
     1911
     1912        wxTreeEvent changedEvent(wxEVT_COMMAND_TREE_SEL_CHANGED, this);
     1913        changedEvent.m_itemOld = htFocus;
     1914        (void)HandleTreeEvent(changedEvent);
     1915    }
     1916}
     1917
     1918
    18861919void wxTreeCtrl::DoSelectItem(const wxTreeItemId& item, bool select)
    18871920{
    18881921    TempSetter set(m_changingSelection);
     
    31843217                    // unprocessed
    31853218                    MSWHandleSelectionKey(wParam);
    31863219                }
    3187 
     3220               
    31883221                // pretend that we did process it in any case as we already
    31893222                // generated an event for it
    31903223                processed = true;