1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/textctrl.mm
4 // Author: Stefan Csomor
5 // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
7 // RCS-ID: $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/textctrl.h"
23 #include "wx/button.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
31 #include <sys/types.h>
37 #if wxUSE_STD_IOSTREAM
45 #include "wx/filefn.h"
46 #include "wx/sysopt.h"
47 #include "wx/thread.h"
49 #include "wx/osx/private.h"
50 #include "wx/osx/carbon/private/mactext.h"
53 @implementation wxNSTextField
55 - (void)setImplementation: (wxWidgetImpl *) theImplementation
57 impl = theImplementation;
60 - (wxWidgetImpl*) implementation
70 // use our common calls
71 - (void) setTitle:(NSString *) title
73 [self setStringValue: title];
78 class wxNSTextFieldControl : public wxMacTextControl
81 wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxMacTextControl(wxPeer, w)
84 virtual ~wxNSTextFieldControl()
88 virtual void VisibilityChanged(bool shown){}
89 virtual wxString GetStringValue() const
91 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
92 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
94 virtual void SetStringValue( const wxString &str)
96 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
98 virtual void Copy() {}
100 virtual void Paste() {}
101 virtual bool CanPaste() const { return false;}
102 virtual void SetEditable(bool editable) {}
103 virtual void GetSelection( long* from, long* to) const {}
104 virtual void SetSelection( long from , long to ){}
105 virtual void WriteText(const wxString& str)
107 // temp hack to get logging working early
108 wxString former = GetStringValue();
109 SetStringValue( former + str );
113 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
122 NSView* sv = (wxpeer->GetParent()->GetHandle() );
124 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
125 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
129 //[v setEditable:NO];
130 //[v setDrawsBackground:NO];
132 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
133 [v setImplementation:c];
138 #endif // wxUSE_TEXTCTRL