wxColourDialog on Mac: how to use?

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
perazz
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri Jul 08, 2022 4:29 pm

wxColourDialog on Mac: how to use?

Post by perazz »

I'm trying to implement a very basic color picker but I have issues on OS X.

My understanding is the native (Cocoa) Mac color picker is "dynamic" by nature, i.e., no OK/Cancel buttons,
see for example at https://www.youtube.com/watch?v=MQqntlvhGLg.

So I'm trying to to catch wxEVT_COLOUR_CHANGED events, to dynamically update the color while the color picking window
is open, but no events are ever returned:

Code: Select all

    // Color picker
    m_contextMenu.Bind(wxEVT_MENU,
                       [this](wxCommandEvent &)
    {
        // Get initial color
        wxColourData new_color;
        new_color.SetColour(GetActiveLineColor());

        // Open dialog and keep returning an updated color whenever selected
        wxColourDialog dlg(this, &new_color);
        dlg.Bind(wxEVT_COLOUR_CHANGED, [this](wxColourDialogEvent& event) {
                 SetActiveLineColor(event.GetColour());
                 wxLogMessage("new color selected");
                 Update();
                 });

        if ( dlg.ShowModal() == wxID_OK ) {
            // Colour did change.
        } else {
            // Colour didn't change.
        }

    }, wxID_SELECT_COLOR );
It seems like the colour event is only available for Windows so far? https://docs.wxwidgets.org/latest/class ... ialog.html
If so, what should I do then, just get the final color returned by the window whatever flag ShowModal returns with?

Thank you in advance,
Federico
User avatar
doublemax
Moderator
Moderator
Posts: 19164
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxColourDialog on Mac: how to use?

Post by doublemax »

perazz wrote: Sun Nov 20, 2022 9:12 am If so, what should I do then, just get the final color returned by the window whatever flag ShowModal returns with?
Yes
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7481
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxColourDialog on Mac: how to use?

Post by ONEEYEMAN »

Hi,
Unless you want to improve this and make it work.

Thank you.
perazz
Knows some wx things
Knows some wx things
Posts: 32
Joined: Fri Jul 08, 2022 4:29 pm

Re: wxColourDialog on Mac: how to use?

Post by perazz »

Thank you,

yes I definitely want to help out on this. I'll start studying the native OS X API and enable this event in wx in the same way it's done for Windows,

Federico