How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

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
Gabriele Giuseppini
Experienced Solver
Experienced Solver
Posts: 56
Joined: Fri Oct 12, 2018 6:12 pm
Location: Amsterdam, the Netherlands

How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by Gabriele Giuseppini »

Dear all,

I have a wxPanel that contains a few child controls, like a static bitmap and a static label. I would like to register a wxEVT_LEFT_DCLICK on the panel to be notified when the user double-clicks *anywhere* in that panel, but apparently wxPanel fires wxEVT_LEFT_DCLICK only when it's empty. When it contains child controls, it looks like I have to register a handler for each control separately, and what's worse, some control types don't even fire the event (like the static label).

Is there a way to be notified of a double-click anywhere in a wxPanel, regardless of the child controls it contains?
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by Manolo »

A button and other controls fire an event of type wxCommandEvent. If that event is not handled (you don't have a handler for it, or your handler calls event.Skip()) then it's propagated to the parent of the button.

You may think that having a handler in the panel it will called for any action on its children. But that's not true. Only events of type wxCommandEvent are propagated. This is not the case for wxKeyEvent.

You can simply use a key-event handle for every child of the panel.
some control types don't even fire the event (like the static label)
Strange. I remember an old bug for this case, which was fixed some time ago. Do you use a recent wx version?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by ONEEYEMAN »

Manolo,
Its not a key event - its a mouse event.
To OP;
As Manolo said, only command events are propagated upwards and mouse events are not command ones.
You can register the mouse events for every single control on the panel and call event.Skip(), but if you have many controls, which have their own mouse handling it will be a disaster.

What is the idea behind this functionality?

Thank you.
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by Manolo »

Its not a key event - its a mouse event.
Ooops! You're right.
Gabriele Giuseppini
Experienced Solver
Experienced Solver
Posts: 56
Joined: Fri Oct 12, 2018 6:12 pm
Location: Amsterdam, the Netherlands

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by Gabriele Giuseppini »

Manolo, you are absolutely right - my mistake, the static label does indeed fire wxEVT_LEFT_DCLICK, so I can definitely register for the event on both controls.

ONEEYEMAN, I'm writing a dialog showing a sort of preview or thumbnail for a number of files (of a custom type) in a directory, somewhat similar to MSW's explorer window in grid mode. Previews for each file are laid out in a grid-like fashion, and each tile consists of a few items like an image and one or more labels. The user may double-click on an individual tile to communicate that they want to load that file.

You are right, having to register for each control is a bit cumbersome, but I can't think of another way. I had a look at wxGrid but it seems to me I can only customize the content of each tile by going down the raw DC paint route, and that seems a bit overkill for my purpose. Any better ideas?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by doublemax »

The only other solution i could think of would be to render everything (bitmap and labels / description) into one bitmap and then display only one wxStaticBitmap.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7479
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by ONEEYEMAN »

Hi,
Or maybe use wxBitmapButton, which can be easier to manage.

Thank you.
Gabriele Giuseppini
Experienced Solver
Experienced Solver
Posts: 56
Joined: Fri Oct 12, 2018 6:12 pm
Location: Amsterdam, the Netherlands

Re: How can I catch wxEVT_LEFT_DCLICK on a wxPanel?

Post by Gabriele Giuseppini »

Yeah exactly, rendering everything to a bitmap is what I was trying to avoid, but may be if I can use it in a BitmapButton it's not that bad...thanks.
Post Reply