KiCad PCB EDA Suite
WX_COLLAPSIBLE_PANE Class Reference

A better wxCollapsiblePane that. More...

#include <collapsible_pane.h>

Inheritance diagram for WX_COLLAPSIBLE_PANE:

Public Member Functions

 WX_COLLAPSIBLE_PANE ()
 
 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"))
 
 ~WX_COLLAPSIBLE_PANE ()
 
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 Collapse (bool aCollapse=true)
 
void Expand ()
 
bool IsCollapsed () const
 
bool IsExpanded () const
 
wxWindow * GetPane ()
 
wxString GetLabel () const override
 
void SetLabel (const wxString &aLabel) override
 
bool SetBackgroundColour (const wxColour &aColor) override
 
bool InformFirstDirection (int aDirection, int aSize, int aAvailableOtherDir) override
 
wxSize DoGetBestClientSize () const override
 
bool Layout () override
 

Private Member Functions

void init ()
 
int getBorder () const
 
void onSize (wxSizeEvent &aEvent)
 
void onHeaderClicked (wxCommandEvent &aEvent)
 

Private Attributes

wxWindow * m_pane
 
wxSizer * m_sizer
 
WX_COLLAPSIBLE_PANE_HEADERm_header
 

Detailed Description

A better wxCollapsiblePane that.

  • Looks the same on all platforms
  • Doesn't have the same sizer bugs
  • Uses proper window colors

Definition at line 101 of file collapsible_pane.h.

Constructor & Destructor Documentation

◆ WX_COLLAPSIBLE_PANE() [1/2]

WX_COLLAPSIBLE_PANE::WX_COLLAPSIBLE_PANE ( )
inline

Definition at line 104 of file collapsible_pane.h.

105  {
106  init();
107  }

References init().

◆ WX_COLLAPSIBLE_PANE() [2/2]

WX_COLLAPSIBLE_PANE::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" ) 
)
inline

Definition at line 109 of file collapsible_pane.h.

114  {
115  init();
116 
117  Create( aParent, aId, aLabel, aPos, aSize, aStyle, aValidator, aName );
118  }
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"))

References Create(), and init().

◆ ~WX_COLLAPSIBLE_PANE()

WX_COLLAPSIBLE_PANE::~WX_COLLAPSIBLE_PANE ( )

Definition at line 67 of file collapsible_pane.cpp.

68 {
69  if( m_sizer )
70  m_sizer->SetContainingWindow( nullptr );
71 
72  // Not owned by wxWindow
73  delete m_sizer;
74 }

References m_sizer.

Member Function Documentation

◆ Collapse()

void WX_COLLAPSIBLE_PANE::Collapse ( bool  aCollapse = true)

Definition at line 77 of file collapsible_pane.cpp.

78 {
79  if( IsCollapsed() == aCollapse )
80  return;
81 
82  InvalidateBestSize();
83 
84  m_pane->Show( !aCollapse );
85  m_header->SetCollapsed( aCollapse );
86 
87  SetSize( GetBestSize() );
88 }
void SetCollapsed(bool aCollapsed=true)
WX_COLLAPSIBLE_PANE_HEADER * m_header

References IsCollapsed(), m_header, m_pane, and WX_COLLAPSIBLE_PANE_HEADER::SetCollapsed().

Referenced by APPEARANCE_CONTROLS::createControls(), Expand(), and onHeaderClicked().

◆ Create()

bool WX_COLLAPSIBLE_PANE::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" ) 
)

Definition at line 33 of file collapsible_pane.cpp.

36 {
37  if( !wxControl::Create( aParent, aId, aPos, aSize, aStyle, aValidator, aName ) )
38  return false;
39 
40  m_sizer = new wxBoxSizer( wxVERTICAL );
41 
42  m_header = new WX_COLLAPSIBLE_PANE_HEADER( this, wxID_ANY, aLabel, wxPoint( 0, 0 ),
43  wxDefaultSize );
44 
45  m_sizer->Add( m_header, wxSizerFlags().Border( wxBOTTOM, getBorder() ) );
46 
47  m_pane = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
48  wxTAB_TRAVERSAL | wxNO_BORDER, wxT( "COLLAPSIBLE_PANE_PANE" ) );
49 
50  m_pane->Hide();
51 
52  Bind( wxEVT_SIZE, &WX_COLLAPSIBLE_PANE::onSize, this );
53  Bind( WX_COLLAPSIBLE_PANE_HEADER_CHANGED, &WX_COLLAPSIBLE_PANE::onHeaderClicked, this );
54 
55  return true;
56 }
A header control for WX_COLLAPSIBLE_PANE Looks like a static text with a unicode arrow prepended to s...
void onHeaderClicked(wxCommandEvent &aEvent)
WX_COLLAPSIBLE_PANE_HEADER * m_header
void onSize(wxSizeEvent &aEvent)

References getBorder(), m_header, m_pane, m_sizer, onHeaderClicked(), and onSize().

Referenced by WX_COLLAPSIBLE_PANE().

◆ DoGetBestClientSize()

wxSize WX_COLLAPSIBLE_PANE::DoGetBestClientSize ( ) const
override

Definition at line 129 of file collapsible_pane.cpp.

130 {
131  wxSize size = m_sizer->GetMinSize();
132 
133  if( IsExpanded() )
134  {
135  wxSize paneSize = m_pane->GetBestSize();
136 
137  size.SetWidth( std::max( size.GetWidth(), paneSize.x ) );
138  size.SetHeight( size.y + getBorder() + paneSize.y );
139  }
140 
141  return size;
142 }

References getBorder(), IsExpanded(), m_pane, and m_sizer.

◆ Expand()

void WX_COLLAPSIBLE_PANE::Expand ( )
inline

Definition at line 130 of file collapsible_pane.h.

131  {
132  Collapse( false );
133  }
void Collapse(bool aCollapse=true)

References Collapse().

◆ getBorder()

int WX_COLLAPSIBLE_PANE::getBorder ( ) const
private

Definition at line 166 of file collapsible_pane.cpp.

167 {
168 #if defined( __WXMSW__ )
169  wxASSERT( m_header );
170  return m_header->ConvertDialogToPixels( wxSize( 2, 0 ) ).x;
171 #else
172  return 3;
173 #endif
174 }
WX_COLLAPSIBLE_PANE_HEADER * m_header

References m_header.

Referenced by Create(), DoGetBestClientSize(), and Layout().

◆ GetLabel()

wxString WX_COLLAPSIBLE_PANE::GetLabel ( ) const
inlineoverride

Definition at line 144 of file collapsible_pane.h.

145  {
146  return m_header->GetLabel();
147  }
WX_COLLAPSIBLE_PANE_HEADER * m_header

References m_header.

◆ GetPane()

wxWindow* WX_COLLAPSIBLE_PANE::GetPane ( )
inline

Definition at line 139 of file collapsible_pane.h.

140  {
141  return m_pane;
142  }

References m_pane.

Referenced by APPEARANCE_CONTROLS::createControls(), and InformFirstDirection().

◆ InformFirstDirection()

bool WX_COLLAPSIBLE_PANE::InformFirstDirection ( int  aDirection,
int  aSize,
int  aAvailableOtherDir 
)
override

Definition at line 113 of file collapsible_pane.cpp.

114 {
115  wxWindow* const pane = GetPane();
116 
117  if( !pane )
118  return false;
119 
120  if( !pane->InformFirstDirection( aDirection, aSize, aAvailableOtherDir ) )
121  return false;
122 
123  InvalidateBestSize();
124 
125  return true;
126 }

References GetPane().

◆ init()

void WX_COLLAPSIBLE_PANE::init ( )
private

Definition at line 59 of file collapsible_pane.cpp.

60 {
61  m_pane = nullptr;
62  m_sizer = nullptr;
63  m_header = nullptr;
64 }
WX_COLLAPSIBLE_PANE_HEADER * m_header

References m_header, m_pane, and m_sizer.

Referenced by WX_COLLAPSIBLE_PANE().

◆ IsCollapsed()

bool WX_COLLAPSIBLE_PANE::IsCollapsed ( ) const

Definition at line 91 of file collapsible_pane.cpp.

92 {
93  return !m_pane || !m_pane->IsShown();
94 }

References m_pane.

Referenced by Collapse(), IsExpanded(), and onHeaderClicked().

◆ IsExpanded()

bool WX_COLLAPSIBLE_PANE::IsExpanded ( ) const
inline

Definition at line 137 of file collapsible_pane.h.

137 { return !IsCollapsed(); }

References IsCollapsed().

Referenced by DoGetBestClientSize(), and Layout().

◆ Layout()

bool WX_COLLAPSIBLE_PANE::Layout ( )
override

Definition at line 145 of file collapsible_pane.cpp.

146 {
147  if( !m_sizer || !m_pane || !m_header )
148  return false;
149 
150  wxSize size( GetSize() );
151 
152  m_sizer->SetDimension( 0, 0, size.x, m_sizer->GetMinSize().y );
153  m_sizer->Layout();
154 
155  if( IsExpanded() )
156  {
157  int yoffset = m_sizer->GetSize().y + getBorder();
158  m_pane->SetSize( 0, yoffset, size.x, size.y - yoffset );
159  m_pane->Layout();
160  }
161 
162  return true;
163 }
WX_COLLAPSIBLE_PANE_HEADER * m_header

References getBorder(), IsExpanded(), m_header, m_pane, and m_sizer.

Referenced by onSize(), and SetLabel().

◆ onHeaderClicked()

void WX_COLLAPSIBLE_PANE::onHeaderClicked ( wxCommandEvent &  aEvent)
private

Definition at line 184 of file collapsible_pane.cpp.

185 {
186  if( aEvent.GetEventObject() != m_header )
187  {
188  aEvent.Skip();
189  return;
190  }
191 
192  Collapse( !IsCollapsed() );
193 
194  wxCommandEvent evt( WX_COLLAPSIBLE_PANE_CHANGED, GetId() );
195  evt.SetEventObject( this );
196  ProcessEvent( evt );
197 }
WX_COLLAPSIBLE_PANE_HEADER * m_header
void Collapse(bool aCollapse=true)

References Collapse(), IsCollapsed(), and m_header.

Referenced by Create().

◆ onSize()

void WX_COLLAPSIBLE_PANE::onSize ( wxSizeEvent &  aEvent)
private

Definition at line 177 of file collapsible_pane.cpp.

178 {
179  Layout();
180  aEvent.Skip();
181 }
bool Layout() override

References Layout().

Referenced by Create().

◆ SetBackgroundColour()

bool WX_COLLAPSIBLE_PANE::SetBackgroundColour ( const wxColour &  aColor)
override

Definition at line 106 of file collapsible_pane.cpp.

107 {
108  m_header->SetBackgroundColour( aColor );
109  return wxWindow::SetBackgroundColour( aColor );
110 }
WX_COLLAPSIBLE_PANE_HEADER * m_header

References m_header.

Referenced by APPEARANCE_CONTROLS::createControls().

◆ SetLabel()

void WX_COLLAPSIBLE_PANE::SetLabel ( const wxString &  aLabel)
override

Definition at line 97 of file collapsible_pane.cpp.

98 {
99  m_header->SetLabel( aLabel );
100  m_header->SetInitialSize();
101 
102  Layout();
103 }
WX_COLLAPSIBLE_PANE_HEADER * m_header
bool Layout() override

References Layout(), and m_header.

Member Data Documentation

◆ m_header

WX_COLLAPSIBLE_PANE_HEADER* WX_COLLAPSIBLE_PANE::m_header
private

◆ m_pane

wxWindow* WX_COLLAPSIBLE_PANE::m_pane
private

◆ m_sizer

wxSizer* WX_COLLAPSIBLE_PANE::m_sizer
private

Definition at line 161 of file collapsible_pane.h.

Referenced by Create(), DoGetBestClientSize(), init(), Layout(), and ~WX_COLLAPSIBLE_PANE().


The documentation for this class was generated from the following files: