Start on implementation for wxTE_MULTILINE / wxTE_RICH* support using NSTextView/NSScrollView.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58897 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
		@@ -38,4 +38,26 @@ protected :
 | 
				
			|||||||
    NSTextField* m_textField;
 | 
					    NSTextField* m_textField;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class wxNSTextViewControl : public wxWidgetCocoaImpl, public wxTextWidgetImpl
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					public:
 | 
				
			||||||
 | 
					    wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w );
 | 
				
			||||||
 | 
					    virtual ~wxNSTextViewControl();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    virtual wxString GetStringValue() const ;
 | 
				
			||||||
 | 
					    virtual void SetStringValue( const wxString &str) ;
 | 
				
			||||||
 | 
					    virtual void Copy() ;
 | 
				
			||||||
 | 
					    virtual void Cut() ;
 | 
				
			||||||
 | 
					    virtual void Paste() ;
 | 
				
			||||||
 | 
					    virtual bool CanPaste() const ;
 | 
				
			||||||
 | 
					    virtual void SetEditable(bool editable) ;
 | 
				
			||||||
 | 
					    virtual void GetSelection( long* from, long* to) const ;
 | 
				
			||||||
 | 
					    virtual void SetSelection( long from , long to );
 | 
				
			||||||
 | 
					    virtual void WriteText(const wxString& str) ;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					protected:
 | 
				
			||||||
 | 
					    NSScrollView* m_scrollView;
 | 
				
			||||||
 | 
					    NSTextView* m_textView;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
 | 
					#endif // _WX_OSX_COCOA_PRIVATE_TEXTIMPL_H_
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -67,6 +67,24 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@end
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@interface wxNSTextView : NSScrollView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@implementation wxNSTextView
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					+ (void)initialize
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    static BOOL initialized = NO;
 | 
				
			||||||
 | 
					    if (!initialized) 
 | 
				
			||||||
 | 
					    {    
 | 
				
			||||||
 | 
					        initialized = YES;
 | 
				
			||||||
 | 
					        wxOSXCocoaClassAddWXMethods( self );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@implementation wxNSTextField
 | 
					@implementation wxNSTextField
 | 
				
			||||||
 | 
					
 | 
				
			||||||
+ (void)initialize
 | 
					+ (void)initialize
 | 
				
			||||||
@@ -110,6 +128,102 @@
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
@end
 | 
					@end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// wxNSTextViewControl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					wxNSTextViewControl::wxNSTextViewControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    m_scrollView = (NSScrollView*) w;
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    [m_scrollView setHasVerticalScroller:YES];
 | 
				
			||||||
 | 
					    [m_scrollView setHasHorizontalScroller:NO];
 | 
				
			||||||
 | 
					    [m_scrollView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
 | 
				
			||||||
 | 
					    NSSize contentSize = [m_scrollView contentSize];
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    m_textView = [[NSTextView alloc] initWithFrame: NSMakeRect(0, 0,
 | 
				
			||||||
 | 
					            contentSize.width, contentSize.height)];
 | 
				
			||||||
 | 
					    [m_textView setVerticallyResizable:YES];
 | 
				
			||||||
 | 
					    [m_textView setHorizontallyResizable:NO];
 | 
				
			||||||
 | 
					    [m_textView setAutoresizingMask:NSViewWidthSizable];
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    [m_scrollView setDocumentView: m_textView];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [m_textView setDelegate: w];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					wxNSTextViewControl::~wxNSTextViewControl()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView setDelegate: nil];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					wxString wxNSTextViewControl::GetStringValue() const 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView) 
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        wxCFStringRef cf( (CFStringRef) [[m_textView string] retain] );
 | 
				
			||||||
 | 
					        return cf.AsString(m_wxPeer->GetFont().GetEncoding());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return wxEmptyString;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void wxNSTextViewControl::SetStringValue( const wxString &str) 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView setString: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					void wxNSTextViewControl::Copy() 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView copy:nil];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::Cut() 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView cut:nil];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::Paste() 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView paste:nil];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool wxNSTextViewControl::CanPaste() const 
 | 
				
			||||||
 | 
					{ 
 | 
				
			||||||
 | 
					    return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::SetEditable(bool editable) 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					        [m_textView setEditable: editable];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::GetSelection( long* from, long* to) const 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textView)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        NSRange range = [m_textView selectedRange];
 | 
				
			||||||
 | 
					        *from = range.location;
 | 
				
			||||||
 | 
					        *to = range.location + range.length;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::SetSelection( long from , long to )
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    [m_textView setSelectedRange:NSMakeRange(from, to-from)];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void wxNSTextViewControl::WriteText(const wxString& str) 
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    // temp hack to get logging working early
 | 
				
			||||||
 | 
					    wxString former = GetStringValue();
 | 
				
			||||||
 | 
					    SetStringValue( former + str );
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// wxNSTextFieldControl
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 | 
					wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    m_textField = (NSTextField*) w;
 | 
					    m_textField = (NSTextField*) w;
 | 
				
			||||||
@@ -118,6 +232,8 @@ wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : w
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
wxNSTextFieldControl::~wxNSTextFieldControl()
 | 
					wxNSTextFieldControl::~wxNSTextFieldControl()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    if (m_textField)
 | 
				
			||||||
 | 
					        [m_textField setDelegate: nil];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
wxString wxNSTextFieldControl::GetStringValue() const 
 | 
					wxString wxNSTextFieldControl::GetStringValue() const 
 | 
				
			||||||
@@ -220,25 +336,34 @@ wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
					    NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
 | 
				
			||||||
    NSTextField* v = nil;
 | 
					    NSTextField* v = nil;
 | 
				
			||||||
 | 
					    wxWidgetCocoaImpl* c = NULL;
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    if ( style & wxTE_PASSWORD )
 | 
					    if ( style & wxTE_MULTILINE || style & wxTE_RICH || style & wxTE_RICH2 )
 | 
				
			||||||
        v =[[wxNSSecureTextField alloc] initWithFrame:r];    
 | 
					 | 
				
			||||||
    else
 | 
					 | 
				
			||||||
        v= [[wxNSTextField alloc] initWithFrame:r];
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    if ( style & wxNO_BORDER )
 | 
					 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        v = [[wxNSTextView alloc] initWithFrame:r];
 | 
				
			||||||
 | 
					        c = new wxNSTextViewControl( wxpeer, v );
 | 
				
			||||||
 | 
					        static_cast<wxNSTextViewControl*>(c)->SetStringValue(str);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    else 
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        if ( style & wxTE_PASSWORD )
 | 
				
			||||||
 | 
					            v = [[wxNSSecureTextField alloc] initWithFrame:r];
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					            v = [[wxNSTextField alloc] initWithFrame:r];
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        if ( style & wxNO_BORDER )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // FIXME: How can we remove the native control's border?
 | 
				
			||||||
 | 
					            // setBordered is separate from the text ctrl's border.
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
        [v setBezeled:NO];
 | 
					        [v setBezeled:NO];
 | 
				
			||||||
        [v setBordered:NO];
 | 
					        [v setBordered:NO];
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        c = new wxNSTextFieldControl( wxpeer, v );
 | 
				
			||||||
 | 
					        static_cast<wxNSTextFieldControl*>(c)->SetStringValue(str);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    [v setBezeled:NO];
 | 
					 | 
				
			||||||
    [v setBordered:NO];
 | 
					 | 
				
			||||||
    //[v setBezeled:NO];
 | 
					 | 
				
			||||||
    //[v setEditable:NO];
 | 
					 | 
				
			||||||
    //[v setDrawsBackground:NO];
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
 | 
					 | 
				
			||||||
    return c;
 | 
					    return c;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user