What is wrong with this event class? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

What is wrong with this event class?

Post by HeReSY » Tue Jul 24, 2007 8:50 am

I have a gouge, which should send an event when the user used the left mouse button and/or moves the mouse inside the gauge.
Here is my code how to process the event, but it never shows the messagebox (is only for testing).

Code: Select all

void wxSliderGauge::OnLeftDown(wxMouseEvent &event)
{
	int x,y;
	GetSize(&x, &y);
	int pos = ((float)GetRange() / x) * event.m_x;

	SetValue(pos);
	wxSliderGaugeEvent evt(wxEVT_SG_VALUE_CHANGED, GetId());
	if(this->ProcessEvent(evt)) wxMessageBox(_("That's it"));;
	//event.Skip();
}
My eventclass

Code: Select all

class wxSliderGaugeEvent : public wxNotifyEvent
{
		public:
			wxSliderGaugeEvent(wxEventType commandType = wxEVT_NULL, int id = 0)
			:wxNotifyEvent(commandType, id)
			{};

			wxSliderGaugeEvent(const wxSliderGaugeEvent &clone)
			:wxNotifyEvent(clone)
			{};

			virtual wxEvent* Clone() const
			{return new wxSliderGaugeEvent(*this);};
};

#define wxSG_VALUE_CHANGED	25000

DECLARE_EVENT_TYPE(wxEVT_SG_VALUE_CHANGED, 25000)

typedef void (wxEvtHandler::*wxSliderGaugeEventFunction)(wxSliderGaugeEvent&);


#define EVT_SG_VALUE_CHANGED(winid, func) \
		DECLARE_EVENT_TABLE_ENTRY(wxEVT_SG_VALUE_CHANGED, winid, wxID_ANY \
		(wxObjectEventFunction) (wxEventFunction) (wxSliderGaugeEventFunction) & func, (wxObject *) NULL ),
HeReSY

achim
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Sun Aug 29, 2004 5:20 pm
Location: Germany

Post by achim » Tue Jul 24, 2007 9:37 am

hi,

inside the posted code, I couldn't find something like:

Code: Select all

BEGIN_EVENT_TABLE(wxSliderGaugeEvent, wxNotifyEvent)
    EVT_SG_VALUE_CHANGED(winid, wxSliderGauge::OnLeftDown)
END_EVENT_TABLE()
(the classnames in BEGIN_EVENT_TABLE(..) may have diffent names), did you forget to map the event?

-achim

HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

Post by HeReSY » Tue Jul 24, 2007 9:41 am

This is in an other class.
I didn't post it, because the event is not processed.
So i cannot catch the event in another class.

HeReSY

achim
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Sun Aug 29, 2004 5:20 pm
Location: Germany

Post by achim » Tue Jul 24, 2007 9:51 am

non selfdefined events, you can, I don't know about selfdefined ones, guess it'll be worth to check it.

HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

Post by HeReSY » Tue Jul 24, 2007 10:50 am

I had a look in the wxAui source, and they check their events also with the return value from ProcessEvent(). So this should work in my case to.

HeReSY

achim
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Sun Aug 29, 2004 5:20 pm
Location: Germany

Post by achim » Tue Jul 24, 2007 11:52 am

ok, when I said: "worth to check it", I meant, worth to try:

Code: Select all

BEGIN_EVENT_TABLE(wxSliderGauge, wxSlider???)
    EVT_SG_VALUE_CHANGED(winid, wxSliderGauge::OnLeftDown)
END_EVENT_TABLE()
Looking to: http://www.wxwidgets.org/manuals/stable ... stomevents
Investigating the wxPlotEvent::wxPlotEvent( ... example, it' according to your code, but furthermore
the BEGIN_EVENT_TABLE macro is used.
Didn't see your other class, which catches the event, so I cannot tell anything about the way of the
event, and why it's not reaching the wxSliderGauge::OnLeftDown method?
Or just the if(this->ProcessEvent(evt)) isn't true?
Call another wxMessageBox at the beginning of wxSliderGauge::OnLeftDown to isolate the error.

-achim

HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

Post by HeReSY » Tue Jul 24, 2007 12:14 pm

Now i add some other wxMessageBox's to my code.
I can say, the app' tries to process the event, but it did not work.
ProcessEvent returns false, so i can't catch the event in any other class.

When I try to catch the event in the class where i want to use this control.

Code: Select all

BEGIN_EVENT_TABLE(TSManagementPane, tsBasePaneManagement)
	EVT_SG_VALUE_CHANGED(ID_TOLLE_SCHEIBE, TSManagementPane::OnChange)
END_EVENT_TABLE()
I get a compiler error:

Code: Select all

macro "DECLARE_EVENT_TABLE_ENTRY" requires 5 arguments, but only 4 given
error: `DECLARE_EVENT_TABLE_ENTRY' was not declared in this scope
So something should be wrong with my event.
Now I try to copy the wxPlotEvent

HeReSY

achim
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 205
Joined: Sun Aug 29, 2004 5:20 pm
Location: Germany

Post by achim » Tue Jul 24, 2007 12:42 pm

ok, when the first MessageBox appears, you do not need to change the event mapping.

Now looking to http://www.wxwidgets.org/manuals/stable ... ocessevent
Return value

true if a suitable event handler function was found and executed, and the function did not call wxEvent::Skip.
Well, which suitable event handler function should be found, what should be done?
Maybe the usage of if(this->ProcessEvent(evt)) is not the very best idea, but I don't know your goal.

Sorry, I didn't look very closly before...

-achim

Post Reply