KiCad PCB EDA Suite
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_COLLAPSIBLE_PANE_H
21 #define KICAD_COLLAPSIBLE_PANE_H
22 
23 #include <wx/wx.h>
24 
25 
26 wxDECLARE_EVENT( WX_COLLAPSIBLE_PANE_HEADER_CHANGED, wxCommandEvent );
27 wxDECLARE_EVENT( WX_COLLAPSIBLE_PANE_CHANGED, wxCommandEvent );
28 
34 class WX_COLLAPSIBLE_PANE_HEADER : public wxControl
35 {
36 public:
38  {
39  init();
40  }
41 
42  WX_COLLAPSIBLE_PANE_HEADER( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
43  const wxPoint& aPos = wxDefaultPosition,
44  const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
45  const wxValidator& aValidator = wxDefaultValidator,
46  const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) )
47  {
48  init();
49 
50  Create( aParent, aId, aLabel, aPos, aSize, aStyle, aValidator, aName );
51  }
52 
53  bool Create( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
54  const wxPoint& aPos = wxDefaultPosition,
55  const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
56  const wxValidator& aValidator = wxDefaultValidator,
57  const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) );
58 
59  void SetCollapsed( bool aCollapsed = true );
60 
61  bool IsCollapsed() const
62  {
63  return m_collapsed;
64  }
65 
66 protected:
67 
68  wxSize DoGetBestClientSize() const override;
69 
70 private:
71  wxString m_label;
73  bool m_inWindow;
74  wxBitmap m_iconRight;
75  wxBitmap m_iconDown;
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 
94 
101 class WX_COLLAPSIBLE_PANE : public wxNavigationEnabled<wxControl>
102 {
103 public:
105  {
106  init();
107  }
108 
109  WX_COLLAPSIBLE_PANE( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
110  const wxPoint& aPos = wxDefaultPosition,
111  const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
112  const wxValidator& aValidator = wxDefaultValidator,
113  const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) )
114  {
115  init();
116 
117  Create( aParent, aId, aLabel, aPos, aSize, aStyle, aValidator, aName );
118  }
119 
121 
122  bool Create( wxWindow* aParent, wxWindowID aId, const wxString& aLabel,
123  const wxPoint& aPos = wxDefaultPosition,
124  const wxSize& aSize = wxDefaultSize, long aStyle = wxBORDER_NONE,
125  const wxValidator& aValidator = wxDefaultValidator,
126  const wxString& aName = wxT( "COLLAPSIBLE_PANE_HEADER" ) );
127 
128  void Collapse( bool aCollapse = true );
129 
130  void Expand()
131  {
132  Collapse( false );
133  }
134 
135  bool IsCollapsed() const;
136 
137  bool IsExpanded() const { return !IsCollapsed(); }
138 
139  wxWindow* GetPane()
140  {
141  return m_pane;
142  }
143 
144  wxString GetLabel() const override
145  {
146  return m_header->GetLabel();
147  }
148 
149  void SetLabel( const wxString& aLabel ) override;
150 
151  bool SetBackgroundColour( const wxColour& aColor ) override;
152 
153  bool InformFirstDirection( int aDirection, int aSize, int aAvailableOtherDir ) override;
154 
155  wxSize DoGetBestClientSize() const override;
156 
157  bool Layout() override;
158 
159 private:
160  wxWindow* m_pane;
161  wxSizer* m_sizer;
163 
164  void init();
165 
166  int getBorder() const;
167 
168  void onSize( wxSizeEvent& aEvent );
169 
170  void onHeaderClicked( wxCommandEvent& aEvent );
171 };
172 
173 #endif // KICAD_COLLAPSIBLE_PANE_H
bool SetBackgroundColour(const wxColour &aColor) 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"))
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 onFocus(wxFocusEvent &aEvent)
A header control for WX_COLLAPSIBLE_PANE Looks like a static text with a unicode arrow prepended to s...
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"))
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"))
void doSetCollapsed(bool aCollapsed)
bool InformFirstDirection(int aDirection, int aSize, int aAvailableOtherDir) override
void onEnterWindow(wxMouseEvent &aEvent)
void onHeaderClicked(wxCommandEvent &aEvent)
void SetCollapsed(bool aCollapsed=true)
WX_COLLAPSIBLE_PANE_HEADER * m_header
wxDECLARE_EVENT(WX_COLLAPSIBLE_PANE_HEADER_CHANGED, wxCommandEvent)
void onPaint(wxPaintEvent &aEvent)
wxSize DoGetBestClientSize() const override
bool Layout() override
void onLeaveWindow(wxMouseEvent &aEvent)
void onChar(wxKeyEvent &aEvent)
wxString GetLabel() const override
void onSize(wxSizeEvent &aEvent)
void SetLabel(const wxString &aLabel) override
void Collapse(bool aCollapse=true)
A better wxCollapsiblePane that.
void onLeftUp(wxMouseEvent &aEvent)
wxSize DoGetBestClientSize() const override