MouseDown/Up events for a segmented control?

Does anyone have a trick for getting mouse up/down events on a segmented control? I can trap the mouse down event on the enclosing canvas only if the user presses the right mouse button. I’d rather not have to emulate the control using canvases since there’s tonnes of native look and feel that I’d have to reproduce…

Cheers.

-bill k

[quote=156293:@William Koperwhats]Does anyone have a trick for getting mouse up/down events on a segmented control? I can trap the mouse down event on the enclosing canvas only if the user presses the right mouse button. I’d rather not have to emulate the control using canvases since there’s tonnes of native look and feel that I’d have to reproduce…
[/quote]

The old trick Trick of putting a canvas sized to the control OVER it?

  • karen

Interesting. So then how does the segmented control get the mouse down event so that the segment changes appearance? I’m assuming I’d have to use the X, Y coordinates from the canvas event, determine which segment the mouse is over, and change selected property manually?

Thanks Karen.

[quote=156297:@William Koperwhats]Interesting. So then how does the segmented control get the mouse down event so that the segment changes appearance? I’m assuming I’d have to use the X, Y coordinates from the canvas event, determine which segment the mouse is over, and change selected property manually?
[/quote]

If You don’t return True in Canvas.MouseDown then the Segmented control will still receive the click and behave normally.

In Canvas.MouseDown you will have to determine which segment was clicked by X,y if you need that info at that point.

I think that I need to have the canvas handle the event since I’ll be starting a timer that will stop when the mouse is released. Unless the segment’s “Action” event can stop the timer. Hmm…

Neat trick!

That is an oldie but goodie!

That is something that used to be done a lot, until the framework added MoueDown events to more controls IIRC.

BTW IMO All RectControls SHOULD have a MouseDown event… So you might want to file a feature request for the SegmentedControl to add it.

  • karen

Just curious on WHY you need this.

Bob, I am using the segmented control to zoom and rotate real-time video (you can see the screenshot below). I needed to be able to catch the mouse-down event so that I could start a 20ms timer that would cause the respective values to increase/decrease while the user held down the mouse button. It’s not entirely in keeping with Apple HIG, but this is a cross-platform application and the result is completely intuitive.

Honestly, at that point I would create a custom canvas control to do that since the Segmented control doesn’t give it to you. But to each their own.

Use the action event as MouseDown, and to start a timer that monitors System.MouseDown until it becomes false or that the system.MouseX and system.MouseY get out of the segmentedControl area, and call a MyMouseUp method. You could subclass the SegmentedControl to implement custom events as well using that technique.

The issue with doing that is making it look OS and OS version appropriate, which he said was important to him upfront… This way Xojo Inc deals with that, and he only has to worry about the part that matters to him.

Right, but if the control doesn’t work they way he wants to use it…

Bob, Karen’s suggestion of putting a transparent canvas over the segmented control worked perfectly. The appearance looks “correct” across platforms and operating system versions, and the functionality is exactly what I needed.

Thanks again Karen.

As an aside, has anyone else noticed that a “Multiple” selection type segmented control doesn’t appear correctly in Mac OS X? The “Flip Horizontal/Vertical” segmented control in the above screen shot is used is just this way and never appears “selected” in Mac OS X (I’ve tried both Mavericks and Yosemite). It behaves correctly (i.e. the “Selected” property seems to change state), but the appearance never changes. In Windows everything looks just fine (now that’s a switch).

No need to reply, I created a feedback case: <https://xojo.com/issue/37677>