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, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "dialog_items_list.h"
21#include <wx/sizer.h>
22#include <wx/button.h>
23
24DIALOG_ITEMS_LIST::DIALOG_ITEMS_LIST( wxWindow* aParent, const wxString& aTitle,
25 const wxString& aMessage, const wxString& aDetailsLabel ) :
26 DIALOG_SHIM( aParent, wxID_ANY, aTitle, wxDefaultPosition, wxDefaultSize,
27 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
28{
29 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
30
31 m_message = new wxStaticText( this, wxID_ANY, aMessage );
32 mainSizer->Add( m_message, 0, wxALL | wxEXPAND, 10 );
33
34 m_collapsiblePane = new wxCollapsiblePane( this, wxID_ANY, aDetailsLabel );
35 mainSizer->Add( m_collapsiblePane, 1, wxALL | wxEXPAND, 10 );
36
37 wxWindow* pane = m_collapsiblePane->GetPane();
38 wxBoxSizer* paneSizer = new wxBoxSizer( wxVERTICAL );
39
40 m_listCtrl = new wxListCtrl( pane, wxID_ANY, wxDefaultPosition, wxSize( 400, 200 ),
41 wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL );
42 m_listCtrl->InsertColumn( 0, wxEmptyString );
43
44 paneSizer->Add( m_listCtrl, 1, wxEXPAND | wxALL, 5 );
45 pane->SetSizer( paneSizer );
46
47 m_collapsiblePane->Bind( wxEVT_COLLAPSIBLEPANE_CHANGED, &DIALOG_ITEMS_LIST::onCollapse, this );
48 m_listCtrl->Bind( wxEVT_LIST_ITEM_SELECTED, &DIALOG_ITEMS_LIST::onSelectionChanged, this );
49
50 wxSizer* buttonsSizer = CreateSeparatedButtonSizer( wxOK | wxCANCEL );
51 mainSizer->Add( buttonsSizer, 0, wxEXPAND | wxALL, 10 );
52
53 SetSizer( mainSizer );
54 Layout();
55 GetSizer()->Fit( this );
56 Center();
57}
58
62
63void DIALOG_ITEMS_LIST::AddItems( const std::vector<wxString>& aItems )
64{
65 for( const wxString& item : aItems )
66 m_listCtrl->InsertItem( m_listCtrl->GetItemCount(), item );
67
68 m_listCtrl->SetColumnWidth( 0, wxLIST_AUTOSIZE_USEHEADER );
69}
70
71void DIALOG_ITEMS_LIST::SetSelectionCallback( std::function<void(int)> aCallback )
72{
73 m_callback = aCallback;
74}
75
76void DIALOG_ITEMS_LIST::onSelectionChanged( wxListEvent& aEvent )
77{
78 if( m_callback )
79 m_callback( aEvent.GetIndex() );
80}
81
82void DIALOG_ITEMS_LIST::onCollapse( wxCollapsiblePaneEvent& aEvent )
83{
84 Layout();
85 GetSizer()->Fit( this );
86}
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)