(Part 4 Connect)cont’d Todo’s seeing what happens if you duplicate an event specifier

This morning was correcting some typo’s in my previous post and ran past the todo’s I gave myself. One of them was to see what happens when I duplicate an event specifier.

My strategy is to play around with buttons working having the same event specifiers in the same panel and see what happens.

Btw… I just ran across something in code::blocks that I should have been aware of.
Apparently, if you setfocus with the mouse going over class’s or constants a tooltip pops up. Right clicking at this point will give you menu for all kinds of interesting information information.
For example, when I swept over WXID_EXIT and right clicked on “Find declaration of: ‘wxID_EXIT'” it automatically opened defs.h This gave access to this:

/* Standard button and menu IDs */
wxID_OK = 5100,
wxID_CANCEL,
wxID_APPLY,
wxID_YES,
wxID_NO,
wxID_STATIC,
wxID_FORWARD,
wxID_BACKWARD,
wxID_DEFAULT,
wxID_MORE,
wxID_SETUP,
wxID_RESET,
wxID_CONTEXT_HELP,
wxID_YESTOALL,
wxID_NOTOALL,
wxID_ABORT,
wxID_RETRY,
wxID_IGNORE,
wxID_ADD,
wxID_REMOVE,

wxID_UP,
wxID_DOWN,
wxID_HOME,
wxID_REFRESH,
wxID_STOP,
wxID_INDEX,

wxID_BOLD,
wxID_ITALIC,
wxID_JUSTIFY_CENTER,
wxID_JUSTIFY_FILL,
wxID_JUSTIFY_RIGHT,
wxID_JUSTIFY_LEFT,
wxID_UNDERLINE,
wxID_INDENT,
wxID_UNINDENT,
wxID_ZOOM_100,
wxID_ZOOM_FIT,
wxID_ZOOM_IN,
wxID_ZOOM_OUT,
wxID_UNDELETE,
wxID_REVERT_TO_SAVED,

Experiment #1
Anyway… my first test was to add the following code in bold to button.cpp

#include “button.h”

Button::Button(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(270, 150))
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxButton *button = new wxButton(panel, wxID_EXIT, wxT(“Quit”),
wxPoint(60, 40));

wxButton *button1 = new wxButton(panel, wxID_EXIT, wxT(“Quit”),
wxPoint(60, 100));
Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Button::OnQuit));
button->SetFocus();
Centre();
}
void Button::OnQuit(wxCommandEvent & WXUNUSED(event))
{
Close(true);
}

This ran, showed two buttons and have the following compiler warning:

/home/jonas/projects/zedcode_tutorials/SimpleButton/button.cpp||In constructor ‘Button::Button(const wxString&)’:|
/home/jonas/projects/zedcode_tutorials/SimpleButton/button.cpp|11|warning: unused variable ‘button1’|
||=== Build finished: 0 errors, 1 warnings ===|

This works for me.  Btw… Either button responded to OnQuit, which seems reasonable.

Experiment #2

This time I want to setup setup two seperate event specifiers, get them working and the change them to the same event specifier to see what happens.
Ok… this works.

#include “button.h”

Button::Button(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(270, 150))
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxButton *button = new wxButton(panel, wxID_EXIT, wxT(“Quit”),
wxPoint(60, 40));

wxButton *button1 = new wxButton(panel, wxID_OK, wxT(“OK”),
wxPoint(60, 100));

Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Button::OnQuit));
button->SetFocus();

Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Button::OnOk));
button1->SetFocus();

Centre();
}

void Button::OnQuit(wxCommandEvent & WXUNUSED(event))
{
Close(true);
}
void Button::OnOk(wxCommandEvent & WXUNUSED(event))
{

Close(true);
}

Yikes…. this works also with no complaints from the compiler.

#include “button.h”

Button::Button(const wxString& title)
: wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(270, 150))
{
wxPanel *panel = new wxPanel(this, wxID_ANY);
wxButton *button = new wxButton(panel, wxID_EXIT, wxT(“Quit”),
wxPoint(60, 40));

wxButton *button1 = new wxButton(panel, wxID_EXIT, wxT(“OK”),
wxPoint(60, 100));

Connect(wxID_EXIT, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Button::OnQuit));
button->SetFocus();

Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(Button::OnOk));
button1->SetFocus();
Centre();
}

void Button::OnQuit(wxCommandEvent & WXUNUSED(event))
{
Close(true);
}
void Button::OnOk(wxCommandEvent & WXUNUSED(event))
{

Close(true);
}

This I guess this is good to know. I was getting confused because I was trying to frame this within a vb6 context. You know if duplicated a name in a control it would squawk about that and ask you meant to set up a control array.
This is very different. Oddly enough, I’m feeling less confused which is good.
The other items of my things to play around was to have a simple button and have it connected to mouse movements, etc… I think I’m going to hold off on that one for now.. Till I get a little further along in the tutorial..

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

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