KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_collapsible_pane.h
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 (C) 2020 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, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef KICAD_WX_COLLAPSIBLE_PANE_H
21#define KICAD_WX_COLLAPSIBLE_PANE_H
22
23#include <wx/control.h>
24#include <wx/containr.h>
25#include <wx/statbox.h> // needed to provide a hint that wx libraries instantiated wxNavigationEnabled<wxControl>
26
27
28wxDECLARE_EVENT( WX_COLLAPSIBLE_PANE_HEADER_CHANGED, wxCommandEvent );
29wxDECLARE_EVENT( WX_COLLAPSIBLE_PANE_CHANGED, wxCommandEvent );
30
36class WX_COLLAPSIBLE_PANE_HEADER : public wxControl
37{
38public:
40 {
41 init();
42 }
43
44 WX_COLLAPSIBLE_PANE_HEADER( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
45 const wxPoint& aPos = wxDefaultPosition,
46 const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
47 const wxValidator& aValidator = wxDefaultValidator,
48 const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) )
49 {
50 init();
51
52 Create( aParent, aId, aLabel, aPos, aSize, aStyle, aValidator, aName );
53 }
54
55 bool Create( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
56 const wxPoint& aPos = wxDefaultPosition,
57 const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
58 const wxValidator& aValidator = wxDefaultValidator,
59 const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) );
60
61 void SetCollapsed( bool aCollapsed = true );
62
63 bool IsCollapsed() const
64 {
65 return m_collapsed;
66 }
67
68protected:
69
70 wxSize DoGetBestClientSize() const override;
71
72private:
73 wxString m_label;
76
77 void init();
78
79 void onPaint( wxPaintEvent& aEvent );
80
81 void onFocus( wxFocusEvent& aEvent );
82
83 void onEnterWindow( wxMouseEvent& aEvent );
84
85 void onLeaveWindow( wxMouseEvent& aEvent );
86
87 void onLeftUp( wxMouseEvent& aEvent );
88
89 void onChar( wxKeyEvent& aEvent );
90
91 void doSetCollapsed( bool aCollapsed );
92
93 void drawArrow( wxDC& aDC, wxRect aRect, bool aIsActive );
94};
95
96
103class WX_COLLAPSIBLE_PANE : public wxNavigationEnabled<wxControl>
104{
105public:
107 {
108 init();
109 }
110
111 WX_COLLAPSIBLE_PANE( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
112 const wxPoint& aPos = wxDefaultPosition,
113 const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
114 const wxValidator& aValidator = wxDefaultValidator,
115 const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) )
116 {
117 init();
118
119 Create( aParent, aId, aLabel, aPos, aSize, aStyle, aValidator, aName );
120 }
121
123
124 bool Create( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
125 const wxPoint& aPos = wxDefaultPosition,
126 const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
127 const wxValidator& aValidator = wxDefaultValidator,
128 const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) );
129
130 void Collapse( bool aCollapse = true );
131
132 void Expand()
133 {
134 Collapse( false );
135 }
136
137 bool IsCollapsed() const;
138
139 bool IsExpanded() const { return !IsCollapsed(); }
140
141 wxWindow* GetPane()
142 {
143 return m_pane;
144 }
145
146 wxString GetLabel() const override
147 {
148 return m_header->GetLabel();
149 }
150
151 void SetLabel( const wxString& aLabel ) override;
152
153 bool SetBackgroundColour( const wxColour& aColor ) override;
154
155 bool InformFirstDirection( int aDirection, int aSize, int aAvailableOtherDir ) override;
156
157 wxSize DoGetBestClientSize() const override;
158
159 bool Layout() override;
160
161private:
162 wxWindow* m_pane;
163 wxSizer* m_sizer;
165
166 void init();
167
168 int getBorder() const;
169
170 void onSize( wxSizeEvent& aEvent );
171
172 void onHeaderClicked( wxCommandEvent& aEvent );
173};
174
175#endif // KICAD_WX_COLLAPSIBLE_PANE_H
A header control for WX_COLLAPSIBLE_PANE Looks like a static text with a unicode arrow prepended to s...
void drawArrow(wxDC &aDC, wxRect aRect, bool aIsActive)
void onLeaveWindow(wxMouseEvent &aEvent)
void onFocus(wxFocusEvent &aEvent)
void onChar(wxKeyEvent &aEvent)
void SetCollapsed(bool aCollapsed=true)
void onPaint(wxPaintEvent &aEvent)
wxSize DoGetBestClientSize() const override
WX_COLLAPSIBLE_PANE_HEADER(wxWindow *aParent, wxWindowID aId, const wxString &aLabel, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxBORDER_NONE, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxT("COLLAPSIBLE_PANE_HEADER"))
void doSetCollapsed(bool aCollapsed)
void onEnterWindow(wxMouseEvent &aEvent)
void onLeftUp(wxMouseEvent &aEvent)
bool Create(wxWindow *aParent, wxWindowID aId, const wxString &aLabel, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxBORDER_NONE, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxT("COLLAPSIBLE_PANE_HEADER"))
A better wxCollapsiblePane that.
wxSize DoGetBestClientSize() const override
void Collapse(bool aCollapse=true)
void onSize(wxSizeEvent &aEvent)
void onHeaderClicked(wxCommandEvent &aEvent)
WX_COLLAPSIBLE_PANE_HEADER * m_header
WX_COLLAPSIBLE_PANE(wxWindow *aParent, wxWindowID aId, const wxString &aLabel, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxBORDER_NONE, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxT("COLLAPSIBLE_PANE_HEADER"))
void SetLabel(const wxString &aLabel) override
bool InformFirstDirection(int aDirection, int aSize, int aAvailableOtherDir) override
wxString GetLabel() const override
bool Create(wxWindow *aParent, wxWindowID aId, const wxString &aLabel, const wxPoint &aPos=wxDefaultPosition, const wxSize &aSize=wxDefaultSize, long aStyle=wxBORDER_NONE, const wxValidator &aValidator=wxDefaultValidator, const wxString &aName=wxT("COLLAPSIBLE_PANE_HEADER"))
bool SetBackgroundColour(const wxColour &aColor) override
wxDECLARE_EVENT(WX_COLLAPSIBLE_PANE_HEADER_CHANGED, wxCommandEvent)