(Part 2) Exploring wxwidgets using zetcode’s tutorial “Widgets communicate” and Code::blocks

Ok.. Part 1 was me playing around… Now I’m need to figure out the meat and potatoes of this particular tutorial..
Looking at the header files
communicate.h

#include “Panels.h”
#include <wx/wxprec.h>

class Communicate : public wxFrame
{
public:
Communicate(const wxString& title);

LeftPanel *m_lp;
RightPanel *m_rp;
wxPanel *m_parent;

};

Panels.h

#include <wx/wx.h>
#include <wx/panel.h>
#include <wx/wx.h>
#include <wx/panel.h>

class LeftPanel : public wxPanel
{
public:
LeftPanel(wxPanel *parent);

void OnPlus(wxCommandEvent & event);
void OnMinus(wxCommandEvent & event);

wxButton *m_plus;
wxButton *m_minus;
wxPanel *m_parent;
int count;

};

class RightPanel : public wxPanel
{
public:
RightPanel(wxPanel *parent);

void OnSetText(wxCommandEvent & event);

wxStaticText *m_text;

};

const int ID_PLUS = 101;
const int ID_MINUS = 102;

class LeftPanel : public wxPanel
{
public:
LeftPanel(wxPanel *parent);

void OnPlus(wxCommandEvent & event);
void OnMinus(wxCommandEvent & event);

wxButton *m_plus;
wxButton *m_minus;
wxPanel *m_parent;
int count;

};

class RightPanel : public wxPanel
{
public:
RightPanel(wxPanel *parent);

void OnSetText(wxCommandEvent & event);

wxStaticText *m_text;

};

Ok.. Now the click + event calls the following code :

void LeftPanel::OnPlus(wxCommandEvent & WXUNUSED(event))
{
count++;

communicate *comm = (Communicate *) m_parent->GetParent();

comm->m_rp->m_text->SetLabel(wxString::Format(wxT(“%d”), count));

}

Ok… I”m going to need to digest this one..  I think there is some sort of type casting going one here.  Communicate inherited wxframe which inherited wxwindows so that where the GetParent() came from.
Todo.. Need to get better understanding and elaborate.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *