Since mouse and keyboard events for MyGLCanvas are NOT delegated to the parent
class or to the parent Frame (specified in the first argument of the constructor
of GLCanvas). But I want that some events like Mouse events and key events
should be delegated to the top level Frame class, in case MyGLCanvas does not
want to handle them.
Can somebody help me figure out how can I send these events to the top level
Frame class?
Thanks,
Divick
--On 07 July 2006 17:56 +0530 Divick Kishore <div...@darshansolutions.com>
wrote:
On the event handler for MyGLCanvas, just do something like:
GetParent()->GetEventHandler()->ProcessEvent(event);
where event was what you were passed. Obviously if your MyGLCanvas is
not an immediate child of your wxFrame, you will have to do something
a bit cleverer to find it, such as:
wxWindow * pParent = this;
while (pParent && !pParent->IsKindOf(CLASSINFO(wxFrame)))
{
pParent=pParent->GetParent();
}
if (pParent)
pParent->GetEventHandler()->ProcessEvent(event);
Alex
--On 07 July 2006 18:55 +0530 Divick Kishore <divick....@gmail.com>
wrote:
> What if I I don't have an event handler set using PushEventHandler method
> ?
The GetEventHandler() will return the wxFrame itself. If you don't use
PushEventHandler or Connect then the GetEventHandler is redunandant but
it will be harmless. Beware, you might not /know/ you are using
PushEventHandler (for instance if you use wxAUI on the frame).
> I tried as you suggested above but the events are not being delegated
> to the function defined in the parent using the STATIC event tables. Is
> there something wrong with my approach ?
Well it works for me. I use this to propagate mouse events upwards from
controls to dialogs. Is your parent window handler expecting that
the event object may be different?
Alex
Thanks,
Divick
My MyGLCanvas class's constructor looks like this:
MyGLCanvas ::MyGLCanvas (wxWindow *
parentWindow):wxGLCanvas(parentWindow, wxID_ANY, wxDefaultPosition,
wxDefaultSize, wxSUNKEN_BORDER)
and above is being called from the a class derived from wxFrame and with
this (MyFrame) passed in the constructor of MyGLCanvas. Does this mean
MyFrame is parent of MyGLCanvas?
To be more precise My GLCanvas is embeded inside a sizer added to the
frame. ( Does adding a widget/control to a sizer/panel make the widget /
control a child of size in which it is added ?)
Here is what it looks like in short:
wxFrame <-- MyFrame
wxGLCanvas <-- MyGLCanvas
MyFrame contains a wxSizer. wxSizer contains MyGLCanvas created with
MyFrame as the 'parent' argument in the constructor.
So if I write code something like as shown below it does not work.
wxWindow * pParent = this;
while (pParent && !pParent->IsKindOf(CLASSINFO(wxFrame)))
{
pParent=pParent->GetParent();
}
if (pParent)
pParent->GetEventHandler()->ProcessEvent(event);
while if I write something like this (as shown below ), then it works:
wxWindow * pParent = this;
while (pParent && !pParent->IsKindOf(CLASSINFO(MyFrame)))
{
pParent=pParent->GetParent();
}
MyFrame * frame = dynamic_cast<MyFrame *>(pParent);
if (frame)
frame->OnKeyF1(keyEvent); //This function handles
the event for some key
Is there something wrong with the above code or is it the right way of
doing things?
Thanks,
Divick
> So if I write code something like as shown below it does not work.
>
> wxWindow * pParent = this;
> while (pParent && !pParent->IsKindOf(CLASSINFO(wxFrame)))
> {
> pParent=pParent->GetParent();
> }
> if (pParent)
> pParent->GetEventHandler()->ProcessEvent(event);
>
> while if I write something like this (as shown below ), then it works:
>
> wxWindow * pParent = this;
> while (pParent && !pParent->IsKindOf(CLASSINFO(MyFrame)))
> {
> pParent=pParent->GetParent();
> }
> MyFrame * frame = dynamic_cast<MyFrame *>(pParent);
> if (frame)
> frame->OnKeyF1(keyEvent); //This function handles the
> event for some key
>
> Is there something wrong with the above code or is it the right way of
> doing things?
I would have thought the first code set should work too. It possibly
does not because the default event table expects the window of
the event concerned to be equal to the window handling it. I didn't
think it did that, and is more likely to check the window ID which
you can circumvent by using wxID_ANY. In my test case I'm actually
passing it to a PushEventHandler'd event handler rather than the
static table.
If the latter works for you, then I'd just carry on using it. What
I was trying to give you was a more generic way of passing the
event up to the parent.
Alex