Copying to clipboard on macOS

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.
Post Reply
asztandi
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Mar 24, 2020 2:28 am

Copying to clipboard on macOS

Post by asztandi » Thu Apr 16, 2020 6:07 pm

Hello,

Placing data into the clipboard does not work for me. I am using version 3.1.3 on macOS (Catalina).
I tried out this function from the clipboard sample - with the small change that the event was generated by a button and not a menu item.

Code: Select all

void MyFrame::OnFlush(wxCommandEvent &WXUNUSED(event))
{
    wxClipboardLocker clipLock;

    if ( !clipLock )
    {
        m_textctrl->AppendText("Failed to lock clipboard.\n");
        return;
    }

    if ( !wxTheClipboard->AddData(new wxTextDataObject("Text from wx clipboard sample")) )
    {
        m_textctrl->AppendText("Failed to put text on clipboard.\n");
        return;
    }

    if ( !wxTheClipboard->Flush() )
    {
        m_textctrl->AppendText("Failed to flush clipboard.\n");
        return;
    }

    m_textctrl->AppendText("Clipboard flushed successfully, you should now "
                           "be able to paste text even after closing the sample.");
}
The AddData() function actually returns true but if I look inside the Mac's clipboard (Show clipboard from Finder) the text is not there. If I try to paste it into any text editor, the Paste menu item is always disabled. The same happens if I replace AddData() with SetData() function. The same functionality works well on Windows and on Linux and also, writing out the contents of the clipboard works well.
Any thoughts what I might be missing?

I also noticed the wxDF_TEXT is not supported any more on Mac, is that true? I mean

Code: Select all

wxTheClipboard->IsSupported(wxDF_TEXT) 
returns false even when the clipboard has text data. In order to return true, for the same text data, one needs to ask for wxDF_UNICODETEXT.

Thank you,
Any suggestion would be greatly appreciated!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2511
Joined: Sun Jan 03, 2010 5:45 pm

Re: Copying to clipboard on macOS

Post by PB » Thu Apr 16, 2020 7:22 pm

Perhaps you running into a bug fixed in the master
https://groups.google.com/d/topic/wx-de ... discussion

asztandi
In need of some credit
In need of some credit
Posts: 6
Joined: Tue Mar 24, 2020 2:28 am

Re: Copying to clipboard on macOS

Post by asztandi » Wed Apr 22, 2020 8:07 pm

Thank you so much for the link! It worked as expected.

Post Reply