diff --git a/docs/changes.txt b/docs/changes.txt index 750de9d7a2..abfd5af375 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -201,8 +201,8 @@ wxOSX/Cocoa: - Implement wxWindow::Disable() for non-native controls too (Steve Browne). - Implement wxTopLevelWindow::EnableCloseButton() (John Roberts). - Fix wxEVT_CHAR for non-BMP Unicode characters (ARATA Mizuki). -- Add support for wxEVT_COMBOBOX_DROPDOWN and wxEVT_COMBOBOX_CLOSEUP - events (Igor Korot). +- Add wxTE_AUTO_URL support to wxTextCtrl (Igor Korot). +- Add support for wxEVT_COMBOBOX_{DROPDOWN, CLOSEUP} events (Igor Korot). - Implement strike-through support in wxFont (Igor Korot). - Provide native implementation of wxStandardPaths (Tobias Taschner). - Add wxTE_{RIGHT,CENTER} support for multiline wxTextCtrl (Andreas Falkenhahn). diff --git a/interface/wx/textctrl.h b/interface/wx/textctrl.h index cf1cf2b14c..85a4fefc17 100644 --- a/interface/wx/textctrl.h +++ b/interface/wx/textctrl.h @@ -29,8 +29,6 @@ // automatically detect the URLs and generate the events when mouse is // moved/clicked over an URL -// -// this is for Win32 richedit and wxGTK2 multiline controls only so far #define wxTE_AUTO_URL 0x1000 // by default, the Windows text control doesn't show the selection when it @@ -967,8 +965,7 @@ public: ignored under other platforms @style{wxTE_AUTO_URL} Highlight the URLs and generate the wxTextUrlEvents when mouse - events occur over them. This style is only supported for wxTE_RICH - Win32 and multi-line wxGTK2 text controls. + events occur over them. @style{wxTE_NOHIDESEL} By default, the Windows text control doesn't show the selection when it doesn't have focus - use this style to force it to always @@ -1148,8 +1145,7 @@ public: pressed in a text control which must have wxTE_PROCESS_ENTER style for this event to be generated. @event{EVT_TEXT_URL(id, func)} - A mouse event occurred over an URL in the text control (wxMSW and - wxGTK2 only currently). + A mouse event occurred over an URL in the text control. @event{EVT_TEXT_MAXLEN(id, func)} This event is generated when the user tries to enter more text into the control than the limit set by wxTextCtrl::SetMaxLength(), see its description. diff --git a/src/osx/cocoa/textctrl.mm b/src/osx/cocoa/textctrl.mm index 0605e8fb3f..132dab3ea6 100644 --- a/src/osx/cocoa/textctrl.mm +++ b/src/osx/cocoa/textctrl.mm @@ -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()