inherited wxPanel

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
chrisa
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Oct 11, 2012 8:48 pm

inherited wxPanel

Post by chrisa » Sat Oct 13, 2012 10:11 am

I am trying to create a custom wxPanel that has some standard controls, so I can re-use this as a base component to inherit from. I am using code::blocks.

I created a new wxPanel and called it xbasePanel. I added some controls (two buttons) to xbasePanel.

When I create a new panel (called NewPanel) which inherits from xbasePanel, I expected the controls I added to xbasePanel to appear by default in NewPanel, but they do not?

Can somebody explain why the base controls do not appear please?

thanks.

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: inherited wxPanel

Post by Auria » Sat Oct 13, 2012 9:18 pm

chrisa wrote:I am trying to create a custom wxPanel that has some standard controls, so I can re-use this as a base component to inherit from. I am using code::blocks.

I created a new wxPanel and called it xbasePanel. I added some controls (two buttons) to xbasePanel.

When I create a new panel (called NewPanel) which inherits from xbasePanel, I expected the controls I added to xbasePanel to appear by default in NewPanel, but they do not?

Can somebody explain why the base controls do not appear please?

thanks.
where do you add the controls in the base class? when you derive, do you call the constructor from the base class? etc.
"Keyboard not detected. Press F1 to continue"
-- Windows

chrisa
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Oct 11, 2012 8:48 pm

Re: inherited wxPanel

Post by chrisa » Sun Oct 14, 2012 10:40 am

I have included the code below from xbasePanel. I don't think the derived class is calling the right constructor to create the buttons, but can't work out why as both constructors call CreateControls().

Code: Select all

#include "wx_pch.h"
#include "xbasePanel.h"

#ifndef WX_PRECOMP
	//(*InternalHeadersPCH(xbasePanel)
	#include <wx/intl.h>
	#include <wx/string.h>
	//*)
#endif
//(*InternalHeaders(xbasePanel)
//*)

//(*IdInit(xbasePanel)
const long xbasePanel::ID_BUTTON1 = wxNewId();
const long xbasePanel::ID_BUTTON2 = wxNewId();
//*)

BEGIN_EVENT_TABLE(xbasePanel,wxPanel)
	//(*EventTable(xbasePanel)
	//*)
END_EVENT_TABLE()

xbasePanel::xbasePanel(wxWindow* parent,wxWindowID id,const wxPoint& pos,const wxSize& size)
{
	//(*Initialize(xbasePanel)
	Create(parent, id, wxDefaultPosition, wxSize(330,198), wxTAB_TRAVERSAL, _T("id"));
	CreateControls();
	//*)
}

xbasePanel::xbasePanel()
{
    Init();
    CreateControls();
}

void xbasePanel::CreateControls()
{

    Button1 = new wxButton(this, ID_BUTTON1, _("Label"), wxPoint(216,168), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(this, ID_BUTTON2, _("Label"), wxPoint(48,48), wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON2"));

}

xbasePanel::~xbasePanel()
{
	//(*Destroy(xbasePanel)
	//*)
}


Header:

Code: Select all

#ifndef XBASEPANEL_H
#define XBASEPANEL_H

#ifndef WX_PRECOMP
	//(*HeadersPCH(xbasePanel)
	#include <wx/panel.h>
	#include <wx/button.h>
	//*)
#endif
//(*Headers(xbasePanel)
//*)

class xbasePanel: public wxPanel
{
	public:
        xbasePanel();

		xbasePanel(wxWindow* parent,wxWindowID id=wxID_ANY,const wxPoint& pos=wxDefaultPosition,const wxSize& size=wxDefaultSize);
		virtual ~xbasePanel();

        void CreateControls();

		//(*Declarations(xbasePanel)
		wxButton* Button1;
		wxButton* Button2;
		//*)

	protected:

		//(*Identifiers(xbasePanel)
		static const long ID_BUTTON1;
		static const long ID_BUTTON2;
		//*)

 
	private:

		//(*Handlers(xbasePanel)
		//*)

		DECLARE_EVENT_TABLE()
};

#endif


chrisa
In need of some credit
In need of some credit
Posts: 3
Joined: Thu Oct 11, 2012 8:48 pm

Re: inherited wxPanel

Post by chrisa » Mon Oct 15, 2012 8:09 pm

I have found my problem. My problem seems to be with the wxsmith GUI; it does not add controls from an inherited base control. I had assumed, incorrectly, that the wxsmith GUI in code:blocks would add the base controls in the designer, but it does not.

I think I need to look at building a plug-in for code:blocks to make this work - not one for this forum though...

Post Reply