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.
wxStyledTextCtrl Cut/Copy/Paste not working Topic is solved
-
- Super wx Problem Solver
- Posts: 469
- Joined: Tue Jun 20, 2006 6:47 pm
- Contact:
Re: wxStyledTextCtrl Cut/Copy/Paste not working
Well the cut method is defined in the Scintilla source as:
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:
where CopyToClipboard is:
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.
Code: Select all
void Editor::Cut() {
pdoc->CheckReadOnly();
if (!pdoc->IsReadOnly() && !SelectionContainsProtected()) {
Copy();
ClearSelection();
}
}
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);
}
}
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
}
Re: wxStyledTextCtrl Cut/Copy/Paste not working
wxClipBoard requires wxDataObject. Did you disable that by any chance?
Check if you can use wxClipBoard in your code or if you get a compile error.
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 */
Use the source, Luke!
Re: wxStyledTextCtrl Cut/Copy/Paste not working
Hi,
You can also check the config.log file if the required constants are enabled or disabled.
Thank you.
You can also check the config.log file if the required constants are enabled or disabled.
Thank you.
Re: wxStyledTextCtrl Cut/Copy/Paste not working
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?
@doublemax: Where is your code snippet from? Can I enforce "configure" to stop on such inconsistencies, too?
Re: wxStyledTextCtrl Cut/Copy/Paste not working
It's from <wxdir>/include/chkconf.h@doublemax: Where is your code snippet from? Can I enforce "configure" to stop on such inconsistencies, too?
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!