wxStyledTextCtrl Cut/Copy/Paste not working Topic is solved

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
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

wxStyledTextCtrl Cut/Copy/Paste not working

Post by walderich »

I compiled wxWidgets under OS X High Sierra as static build with some configuration options disabled for size optimization. I now have the issue that the wxStyledTextCtrl component doesn't work correctly:

1. "Cut" does eventually remove the selected text, but it is not copied to the clipboard i.e. it is not accessible anywhere.
2. "Copy" does not work. Neither by shortcut nor by (context) menu (which is enabled).
3. "Paste" does not work. Context menu is disabled.

Both issues also apply to the sample stctest application. But normal wxTextCtrl components work correctly. Is it possible, that I disabled a required configuration setting (--enable-clipboard is set)? Or do I need to enable these separately?

My application already worked, when I was compiling it on OS X Yosemite, but that was already two years ago.
New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 466
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

Re: wxStyledTextCtrl Cut/Copy/Paste not working

Post by New Pagodi »

Well the cut method is defined in the Scintilla source as:

Code: Select all

void Editor::Cut() {
	pdoc->CheckReadOnly();
	if (!pdoc->IsReadOnly() && !SelectionContainsProtected()) {
		Copy();
		ClearSelection();
	}
}
So if you're saying copy isn't working, and cut deletes the text but doesn't place it on the clipboard, I guess that makes sense since cut is literally defined to be copy (which is broken) and then delete the text.


The copy method is implemented in the wxSTC source in the ScintillaWX class (a class derived from the Scintilla editor class) as follows:

Code: Select all

void ScintillaWX::Copy() {
    if (!sel.Empty()) {
        SelectionText st;
        CopySelectionRange(&st);
        CopyToClipboard(st);
    }
}
where CopyToClipboard is:

Code: Select all

void ScintillaWX::CopyToClipboard(const SelectionText& st) {
#if wxUSE_CLIPBOARD
    if ( !st.LengthWithTerminator() )
        return;

    // Send an event to allow the copied text to be changed
    wxStyledTextEvent evt(wxEVT_STC_CLIPBOARD_COPY, stc->GetId());
    evt.SetEventObject(stc);
    evt.SetString(wxTextBuffer::Translate(stc2wx(st.Data(), st.Length())));
    stc->GetEventHandler()->ProcessEvent(evt);

    wxTheClipboard->UsePrimarySelection(false);
    if (wxTheClipboard->Open()) {
        wxString text = evt.GetString();

#ifdef wxHAVE_STC_RECT_FORMAT
        if (st.rectangular)
        {
            // when copying the text to the clipboard, add extra meta-data that
            // tells the Paste() method that the user copied a rectangular
            // block of text, as opposed to a stream of text.
            wxDataObjectComposite* composite = new wxDataObjectComposite();
            composite->Add(new wxTextDataObject(text), true);
            composite->Add(new wxCustomDataObject(m_clipRectTextFormat));
            wxTheClipboard->SetData(composite);
        }
        else
#endif // wxHAVE_STC_RECT_FORMAT
            wxTheClipboard->SetData(new wxTextDataObject(text));
        wxTheClipboard->Close();
    }
#else
    wxUnusedVar(st);
#endif // wxUSE_CLIPBOARD
}
Unless I'm missing something the only way this can break down is if wxUSE_CLIPBOARD=0. Maybe some of your other configuration settings caused that to happen? Unfortunately, I don't have any mac hardware, so I can't be of much other help here.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStyledTextCtrl Cut/Copy/Paste not working

Post by doublemax »

wxClipBoard requires wxDataObject. Did you disable that by any chance?

Code: Select all

#if wxUSE_CLIPBOARD && !wxUSE_DATAOBJ
#   ifdef wxABORT_ON_CONFIG_ERROR
#       error "wxClipboard requires wxDataObject"
#   else
#       undef wxUSE_DATAOBJ
#       define wxUSE_DATAOBJ 1
#   endif
#endif /* wxUSE_CLIPBOARD */
Check if you can use wxClipBoard in your code or if you get a compile error.
Use the source, Luke!
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxStyledTextCtrl Cut/Copy/Paste not working

Post by ONEEYEMAN »

Hi,
You can also check the config.log file if the required constants are enabled or disabled.

Thank you.
walderich
Earned a small fee
Earned a small fee
Posts: 24
Joined: Sat Sep 17, 2011 6:09 pm

Re: wxStyledTextCtrl Cut/Copy/Paste not working

Post by walderich »

Thank you all for your quick replies! I indeed disabled wxDataObject, which prevented the clipboard to work. After recompiling wxWidgets I got my application to work. Thanks again!

@doublemax: Where is your code snippet from? Can I enforce "configure" to stop on such inconsistencies, too?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxStyledTextCtrl Cut/Copy/Paste not working

Post by doublemax »

@doublemax: Where is your code snippet from? Can I enforce "configure" to stop on such inconsistencies, too?
It's from <wxdir>/include/chkconf.h
In the second half you there are a few more of dependencies.

You would have gotten an error if you explicitly enabled clipboard support. Without, it will just silently be ignored.
Use the source, Luke!
Post Reply