1. We don't need GetTopLevelParent() here, we already have wxGetTopLevelParent()
2. Don't hardcode button id in the generic version 3. Don't include unneeded headers from the header git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42263 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -16,9 +16,22 @@
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/button.h"
|
||||
#endif // !WX_PRECOMP
|
||||
|
||||
#include "wx/collpane.h"
|
||||
#include "wx/statline.h"
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// constants
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// the number of pixels to leave between the button and the static line and
|
||||
// between the button and the pane
|
||||
#define wxCP_MARGIN 10
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@@ -34,18 +47,19 @@ IMPLEMENT_DYNAMIC_CLASS(wxGenericCollapsiblePane, wxControl)
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCollapsiblePaneEvent, wxCommandEvent)
|
||||
|
||||
BEGIN_EVENT_TABLE(wxGenericCollapsiblePane, wxControl)
|
||||
EVT_BUTTON(wxCP_BUTTON_ID, wxGenericCollapsiblePane::OnButton)
|
||||
EVT_BUTTON(wxID_ANY, wxGenericCollapsiblePane::OnButton)
|
||||
EVT_SIZE(wxGenericCollapsiblePane::OnSize)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
|
||||
bool wxGenericCollapsiblePane::Create( wxWindow *parent, wxWindowID id,
|
||||
const wxString& label,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& val,
|
||||
const wxString& name)
|
||||
bool wxGenericCollapsiblePane::Create(wxWindow *parent,
|
||||
wxWindowID id,
|
||||
const wxString& label,
|
||||
const wxPoint& pos,
|
||||
const wxSize& size,
|
||||
long style,
|
||||
const wxValidator& val,
|
||||
const wxString& name)
|
||||
{
|
||||
if ( !wxControl::Create(parent, id, pos, size, style, val, name) )
|
||||
return false;
|
||||
@@ -53,7 +67,7 @@ bool wxGenericCollapsiblePane::Create( wxWindow *parent, wxWindowID id,
|
||||
m_strLabel = label;
|
||||
|
||||
// create children; their size & position is set in OnSize()
|
||||
m_pButton = new wxButton(this, wxCP_BUTTON_ID, GetBtnLabel(), wxPoint(0, 0),
|
||||
m_pButton = new wxButton(this, wxID_ANY, GetBtnLabel(), wxPoint(0, 0),
|
||||
wxDefaultSize, wxBU_EXACTFIT);
|
||||
m_pStatLine = new wxStaticLine(this, wxID_ANY);
|
||||
m_pPane = new wxWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
||||
@@ -106,7 +120,7 @@ void wxGenericCollapsiblePane::Collapse(bool collapse)
|
||||
SetMinSize(sz);
|
||||
SetSize(sz);
|
||||
|
||||
wxWindow *top = GetTopLevelParent();
|
||||
wxWindow *top = wxGetTopLevelParent(this);
|
||||
if (top)
|
||||
{
|
||||
// we've changed our size, thus our top level parent needs to relayout
|
||||
@@ -143,15 +157,6 @@ void wxGenericCollapsiblePane::Collapse(bool collapse)
|
||||
}
|
||||
}
|
||||
|
||||
wxWindow *wxGenericCollapsiblePane::GetTopLevelParent()
|
||||
{
|
||||
wxWindow *parent = GetParent();
|
||||
while (parent && !parent->IsTopLevel())
|
||||
parent = parent->GetParent();
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
void wxGenericCollapsiblePane::SetLabel(const wxString &label)
|
||||
{
|
||||
m_strLabel = label;
|
||||
@@ -183,8 +188,14 @@ void wxGenericCollapsiblePane::LayoutChildren()
|
||||
// wxGenericCollapsiblePane - event handlers
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void wxGenericCollapsiblePane::OnButton(wxCommandEvent &WXUNUSED(event))
|
||||
void wxGenericCollapsiblePane::OnButton(wxCommandEvent& event)
|
||||
{
|
||||
if ( event.GetEventObject() != m_pButton )
|
||||
{
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
Collapse(!IsCollapsed());
|
||||
|
||||
// this change was generated by the user - send the event
|
||||
|
Reference in New Issue
Block a user