KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_items_list.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "dialog_items_list.h"
25#include <wx/sizer.h>
26#include <wx/button.h>
27
28DIALOG_ITEMS_LIST::DIALOG_ITEMS_LIST( wxWindow* aParent, const wxString& aTitle,
29 const wxString& aMessage, const wxString& aDetailsLabel ) :
30 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
31 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
32{
33 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
34
35 m_message = new wxStaticText( this, wxID_ANY, aMessage );
36 mainSizer->Add( m_message, 0, wxALL | wxEXPAND, 10 );
37
38 m_collapsiblePane = new wxCollapsiblePane( this, wxID_ANY, aDetailsLabel );
39 mainSizer->Add( m_collapsiblePane, 1, wxALL | wxEXPAND, 10 );
40
41 wxWindow* pane = m_collapsiblePane->GetPane();
42 wxBoxSizer* paneSizer = new wxBoxSizer( wxVERTICAL );
43
44 m_listCtrl = new wxListCtrl( pane, wxID_ANY, wxDefaultPosition, wxSize( 400, 200 ),
45 wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL );
46 m_listCtrl->InsertColumn( 0, wxEmptyString );
47
48 paneSizer->Add( m_listCtrl, 1, wxEXPAND | wxALL, 5 );
49 pane->SetSizer( paneSizer );
50
51 m_collapsiblePane->Bind( wxEVT_COLLAPSIBLEPANE_CHANGED, &DIALOG_ITEMS_LIST::onCollapse, this );
52 m_listCtrl->Bind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_ITEMS_LIST::onSelectionChanged, this );
53
54 wxSizer* buttonsSizer = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
55 mainSizer->Add( buttonsSizer, 0, wxEXPAND | wxALL, 10 );
56
57 SetSizer( mainSizer );
58 Layout();
59 GetSizer()->Fit( this );
60 Center();
61}
62
66
67void DIALOG_ITEMS_LIST::AddItems( const std::vector<wxString>& aItems )
68{
69 for( const wxString& item : aItems )
70 m_listCtrl->InsertItem( m_listCtrl->GetItemCount(), item );
71
72 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE_USEHEADER );
73}
74
75void DIALOG_ITEMS_LIST::SetSelectionCallback( std::function<void(int)> aCallback )
76{
77 m_callback = aCallback;
78}
79
80void DIALOG_ITEMS_LIST::onSelectionChanged( wxListEvent& aEvent )
81{
82 if( m_callback )
83 m_callback( aEvent.GetIndex() );
84}
85
86void DIALOG_ITEMS_LIST::onCollapse( wxCollapsiblePaneEvent& aEvent )
87{
88 Layout();
89 GetSizer()->Fit( this );
90}
std::function< void(int)> m_callback
wxStaticText * m_message
void onCollapse(wxCollapsiblePaneEvent &aEvent)
void SetSelectionCallback(std::function< void(int)> aCallback)
void AddItems(const std::vector< wxString > &aItems)
wxCollapsiblePane * m_collapsiblePane
void onSelectionChanged(wxListEvent &aEvent)
wxListCtrl * m_listCtrl
DIALOG_ITEMS_LIST(wxWindow *aParent, const wxString &aTitle, const wxString &aMessage, const wxString &aDetailsLabel)
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)