Add support for wxTE_AUTO_URL to wxOSX

Recognize URLs by using native support for this available since OS X 10.5.

Closes #17137.
This commit is contained in:
Igor Korot
2016-02-01 02:12:10 +01:00
committed by Vadim Zeitlin
parent 33d8d4e57c
commit f5187859cc
3 changed files with 33 additions and 8 deletions

View File

@@ -412,6 +412,23 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
impl->DoNotifyFocusLost();
}
-(BOOL)textView:(NSTextView *)aTextView clickedOnLink:(id)link atIndex:(NSUInteger)charIndex
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( aTextView );
if ( impl )
{
wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
if ( wxpeer )
{
wxMouseEvent evtMouse( wxEVT_LEFT_DOWN );
wxTextUrlEvent event( wxpeer->GetId(), evtMouse, (long int)charIndex, (long int)charIndex );
event.SetEventObject( wxpeer );
wxpeer->HandleWindowEvent( event );
}
}
return NO;
}
@end
@implementation wxNSTextField
@@ -624,6 +641,11 @@ wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w, long s
[tv setRichText:NO];
}
if ( wxPeer->HasFlag(wxTE_AUTO_URL) )
{
[tv setAutomaticLinkDetectionEnabled:YES];
}
[m_scrollView setDocumentView: tv];
[tv setDelegate: tv];
@@ -671,7 +693,14 @@ void wxNSTextViewControl::SetStringValue( const wxString &str)
wxMacEditHelper helper(m_textView);
if (m_textView)
{
[m_textView setString: wxCFStringRef( st , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
if ( m_wxPeer->HasFlag(wxTE_AUTO_URL) )
{
// Make sure that any URLs in the new text are highlighted.
[m_textView checkTextInDocument:nil];
}
}
}
void wxNSTextViewControl::Copy()