Subclass wxDataViewCtrl to include our helpers
It is cleaner to just extend the class with these functions rather than having the separate functions.
This commit is contained in:
parent
5fcc1135a8
commit
07d613d0d2
|
@ -206,6 +206,7 @@ set( COMMON_WIDGET_SRCS
|
|||
widgets/wx_busy_indicator.cpp
|
||||
widgets/wx_collapsible_pane.cpp
|
||||
widgets/wx_combobox.cpp
|
||||
widgets/wx_dataviewctrl.cpp
|
||||
widgets/wx_ellipsized_static_text.cpp
|
||||
widgets/wx_grid.cpp
|
||||
widgets/wx_html_report_box.cpp
|
||||
|
@ -387,7 +388,6 @@ set( COMMON_SRCS
|
|||
validators.cpp
|
||||
wildcards_and_files_ext.cpp
|
||||
drawing_sheet/ds_painter.cpp
|
||||
wxdataviewctrl_helpers.cpp
|
||||
wx_stl_compat.cpp
|
||||
wx_filename.cpp
|
||||
xnode.cpp
|
||||
|
|
|
@ -25,15 +25,15 @@
|
|||
#include <widgets/lib_tree.h>
|
||||
#include <core/kicad_algo.h>
|
||||
#include <macros.h>
|
||||
#include <wxdataviewctrl_helpers.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <dialogs/eda_reorderable_list_dialog.h>
|
||||
#include <tool/tool_interactive.h>
|
||||
#include <tool/tool_manager.h>
|
||||
#include <tool/action_manager.h>
|
||||
#include <tool/actions.h>
|
||||
#include <wx/srchctrl.h>
|
||||
#include <widgets/wx_dataviewctrl.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/srchctrl.h>
|
||||
#include <wx/timer.h>
|
||||
|
||||
constexpr int RECENT_SEARCHES_MAX = 10;
|
||||
|
@ -106,7 +106,7 @@ LIB_TREE::LIB_TREE( wxWindow* aParent, const wxString& aRecentSearchesKey, LIB_T
|
|||
|
||||
// Tree control
|
||||
int dvFlags = ( aFlags & MULTISELECT ) ? wxDV_MULTIPLE : wxDV_SINGLE;
|
||||
m_tree_ctrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dvFlags );
|
||||
m_tree_ctrl = new WX_DATAVIEWCTRL( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, dvFlags );
|
||||
m_adapter->AttachTo( m_tree_ctrl );
|
||||
|
||||
if( aFlags & DETAILS )
|
||||
|
@ -488,12 +488,12 @@ void LIB_TREE::onQueryCharHook( wxKeyEvent& aKeyStroke )
|
|||
{
|
||||
case WXK_UP:
|
||||
updateRecentSearchMenu();
|
||||
selectIfValid( GetPrevItem( *m_tree_ctrl, sel ) );
|
||||
selectIfValid( m_tree_ctrl->GetPrevItem( sel ) );
|
||||
break;
|
||||
|
||||
case WXK_DOWN:
|
||||
updateRecentSearchMenu();
|
||||
selectIfValid( GetNextItem( *m_tree_ctrl, sel ) );
|
||||
selectIfValid( m_tree_ctrl->GetNextItem( sel ) );
|
||||
break;
|
||||
|
||||
case WXK_ADD:
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
|
@ -17,21 +17,21 @@
|
|||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <widgets/wx_dataviewctrl.h>
|
||||
#include <wx/dataview.h>
|
||||
#include <wxdataviewctrl_helpers.h>
|
||||
|
||||
wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
|
||||
wxDataViewItem WX_DATAVIEWCTRL::GetPrevItem( wxDataViewItem const& aItem )
|
||||
{
|
||||
wxDataViewItem prevItem = GetPrevSibling( aView, aItem );
|
||||
wxDataViewItem prevItem = GetPrevSibling( aItem );
|
||||
|
||||
if( !prevItem.IsOk() )
|
||||
{
|
||||
prevItem = aView.GetModel()->GetParent( aItem );
|
||||
prevItem = GetModel()->GetParent( aItem );
|
||||
}
|
||||
else if( aView.IsExpanded( prevItem ) )
|
||||
else if( IsExpanded( prevItem ) )
|
||||
{
|
||||
wxDataViewItemArray children;
|
||||
aView.GetModel()->GetChildren( prevItem, children );
|
||||
GetModel()->GetChildren( prevItem, children );
|
||||
prevItem = children[children.size() - 1];
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
|
|||
}
|
||||
|
||||
|
||||
wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
|
||||
wxDataViewItem WX_DATAVIEWCTRL::GetNextItem( wxDataViewItem const& aItem )
|
||||
{
|
||||
wxDataViewItem nextItem;
|
||||
wxDataViewItem invalid;
|
||||
|
@ -48,7 +48,7 @@ wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
|
|||
{
|
||||
// No selection. Select the first.
|
||||
wxDataViewItemArray children;
|
||||
aView.GetModel()->GetChildren( aItem, children );
|
||||
GetModel()->GetChildren( aItem, children );
|
||||
|
||||
if( children.size() )
|
||||
return children[0];
|
||||
|
@ -56,10 +56,10 @@ wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
|
|||
return invalid;
|
||||
}
|
||||
|
||||
if( aView.IsExpanded( aItem ) )
|
||||
if( IsExpanded( aItem ) )
|
||||
{
|
||||
wxDataViewItemArray children;
|
||||
aView.GetModel()->GetChildren( aItem, children );
|
||||
GetModel()->GetChildren( aItem, children );
|
||||
|
||||
if( children.size() )
|
||||
return children[0];
|
||||
|
@ -69,9 +69,9 @@ wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
|
|||
else
|
||||
{
|
||||
// Walk up levels until we find one that has a next sibling.
|
||||
for( wxDataViewItem walk = aItem; walk.IsOk(); walk = aView.GetModel()->GetParent( walk ) )
|
||||
for( wxDataViewItem walk = aItem; walk.IsOk(); walk = GetModel()->GetParent( walk ) )
|
||||
{
|
||||
nextItem = GetNextSibling( aView, walk );
|
||||
nextItem = GetNextSibling( walk );
|
||||
|
||||
if( nextItem.IsOk() )
|
||||
break;
|
||||
|
@ -82,13 +82,13 @@ wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& a
|
|||
}
|
||||
|
||||
|
||||
wxDataViewItem GetPrevSibling( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
|
||||
wxDataViewItem WX_DATAVIEWCTRL::GetPrevSibling( wxDataViewItem const& aItem )
|
||||
{
|
||||
wxDataViewItemArray siblings;
|
||||
wxDataViewItem invalid;
|
||||
wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
|
||||
wxDataViewItem parent = GetModel()->GetParent( aItem );
|
||||
|
||||
aView.GetModel()->GetChildren( parent, siblings );
|
||||
GetModel()->GetChildren( parent, siblings );
|
||||
|
||||
for( size_t i = 0; i < siblings.size(); ++i )
|
||||
{
|
||||
|
@ -105,13 +105,13 @@ wxDataViewItem GetPrevSibling( wxDataViewCtrl const& aView, wxDataViewItem const
|
|||
}
|
||||
|
||||
|
||||
wxDataViewItem GetNextSibling( wxDataViewCtrl const& aView, wxDataViewItem const& aItem )
|
||||
wxDataViewItem WX_DATAVIEWCTRL::GetNextSibling( wxDataViewItem const& aItem )
|
||||
{
|
||||
wxDataViewItemArray siblings;
|
||||
wxDataViewItem invalid;
|
||||
wxDataViewItem parent = aView.GetModel()->GetParent( aItem );
|
||||
wxDataViewItem parent = GetModel()->GetParent( aItem );
|
||||
|
||||
aView.GetModel()->GetChildren( parent, siblings );
|
||||
GetModel()->GetChildren( parent, siblings );
|
||||
|
||||
for( size_t i = 0; i < siblings.size(); ++i )
|
||||
{
|
|
@ -28,8 +28,8 @@
|
|||
#include <wx/panel.h>
|
||||
#include <lib_tree_model_adapter.h>
|
||||
#include <html_window.h>
|
||||
#include <widgets/wx_dataviewctrl.h>
|
||||
|
||||
class wxDataViewCtrl;
|
||||
class wxTextCtrl;
|
||||
class wxHtmlLinkEvent;
|
||||
class wxSearchCtrl;
|
||||
|
@ -216,16 +216,16 @@ protected:
|
|||
|
||||
wxObjectDataPtr<LIB_TREE_MODEL_ADAPTER> m_adapter;
|
||||
|
||||
wxSearchCtrl* m_query_ctrl;
|
||||
wxDataViewCtrl* m_tree_ctrl;
|
||||
HTML_WINDOW* m_details_ctrl;
|
||||
wxTimer* m_debounceTimer;
|
||||
bool m_inTimerEvent;
|
||||
wxSearchCtrl* m_query_ctrl;
|
||||
WX_DATAVIEWCTRL* m_tree_ctrl;
|
||||
HTML_WINDOW* m_details_ctrl;
|
||||
wxTimer* m_debounceTimer;
|
||||
bool m_inTimerEvent;
|
||||
|
||||
LIB_ID m_last_libid;
|
||||
wxString m_recentSearchesKey;
|
||||
LIB_ID m_last_libid;
|
||||
wxString m_recentSearchesKey;
|
||||
|
||||
bool m_skipNextRightClick;
|
||||
bool m_skipNextRightClick;
|
||||
};
|
||||
|
||||
///< Custom event sent when a new symbol is preselected
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef WX_DATAVIEWCTRL_H_
|
||||
#define WX_DATAVIEWCTRL_H_
|
||||
|
||||
#include <wx/dataview.h>
|
||||
|
||||
/**
|
||||
* Extension of the wxDataViewCtrl to include some helper functions for working with items.
|
||||
* These should probably be sent upstream, since they may be useful to others, but for now
|
||||
* just extend the class with them ourselves.
|
||||
*/
|
||||
class WX_DATAVIEWCTRL : public wxDataViewCtrl
|
||||
{
|
||||
public:
|
||||
// Just take all constructors
|
||||
using wxDataViewCtrl::wxDataViewCtrl;
|
||||
|
||||
/**
|
||||
* Get the previous item in list order.
|
||||
*
|
||||
* @param aItem a valid item in the control's model
|
||||
* @return the item before aItem, or an invalid item if aItem is at the top.
|
||||
*/
|
||||
wxDataViewItem GetPrevItem( wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the next item in list order.
|
||||
*
|
||||
* @param aItem a valid item in the control's model
|
||||
* @return the item after aItem, or an invalid item if aItem is at the bottom.
|
||||
*/
|
||||
wxDataViewItem GetNextItem( wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the previous sibling of an item.
|
||||
*
|
||||
* @param aItem a valid item in the control's model
|
||||
* @return the sibling before aItem, or an invalid item if aItem has no siblings before it.
|
||||
*/
|
||||
wxDataViewItem GetPrevSibling( wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the next sibling of an item.
|
||||
*
|
||||
* @param aItem a valid item in the control's model
|
||||
* @return the sibling after aItem, or an invalid item if aItem has no siblings after it.
|
||||
*/
|
||||
wxDataViewItem GetNextSibling( wxDataViewItem const& aItem );
|
||||
|
||||
};
|
||||
|
||||
#endif // WX_DATAVIEWCTRL_H_
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2017 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* wxDataViewCtrl helper functions. These are functions that should be methods
|
||||
* of wxDataViewCtrl, but aren't.
|
||||
*/
|
||||
|
||||
#ifndef WXDATAVIEWCTRL_HELPERS_H
|
||||
#define WXDATAVIEWCTRL_HELPERS_H
|
||||
|
||||
#include <wx/dataview.h>
|
||||
|
||||
/**
|
||||
* Get the previous item in list order.
|
||||
*
|
||||
* @param aView - a wxDataViewCtrl with valid model
|
||||
* @param aItem - a valid item in the model
|
||||
* @return the item before aItem, or an invalid item if aItem is at the top.
|
||||
*/
|
||||
wxDataViewItem GetPrevItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the next item in list order.
|
||||
*
|
||||
* @param aView - a wxDataViewCtrl with valid model
|
||||
* @param aItem - a valid item in the model
|
||||
* @return the item after aItem, or an invalid item if aItem is at the bottom.
|
||||
*/
|
||||
wxDataViewItem GetNextItem( wxDataViewCtrl const& aView, wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the previous sibling of an item.
|
||||
*
|
||||
* @param aView - awxDataViewCtrl with valid model
|
||||
* @param aItem - a valid item in the model
|
||||
* @return the sibling before aItem, or an invalid item if aItem has no siblings before it.
|
||||
*/
|
||||
wxDataViewItem GetPrevSibling( wxDataViewCtrl const& aView, wxDataViewItem const& aItem );
|
||||
|
||||
/**
|
||||
* Get the next sibling of an item.
|
||||
*
|
||||
* @param aView - awxDataViewCtrl with valid model
|
||||
* @param aItem - a valid item in the model
|
||||
* @return the sibling after aItem, or an invalid item if aItem has no siblings after it.
|
||||
*/
|
||||
wxDataViewItem GetNextSibling( wxDataViewCtrl const& aView, wxDataViewItem const& aItem );
|
||||
|
||||
#endif // WXDATAVIEWCTRL_HELPERS_H
|
Loading…
Reference in New Issue