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/cocoa/private/textimpl.h"
52 @implementation wxNSTextField
56 static BOOL initialized = NO;
60 wxOSXCocoaClassAddWXMethods( self );
64 - (id)initWithFrame:(NSRect)frame
66 [super initWithFrame:frame];
67 [self setDelegate: self];
68 [self setTarget: self];
69 // [self setAction: @selector(enterAction:)];
73 // use our common calls
74 - (void) setTitle:(NSString *) title
76 [self setStringValue: title];
79 - (void)controlTextDidChange:(NSNotification *)aNotification
83 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
85 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
86 event.SetEventObject( wxpeer );
87 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
88 wxpeer->HandleWindowEvent( event );
93 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
97 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
99 wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId());
100 event.SetEventObject( wxpeer );
101 event.SetWindow( wxpeer );
102 wxpeer->HandleWindowEvent( event );
107 - (void) enterAction: (id) sender
111 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
112 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) {
113 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
114 event.SetEventObject( wxpeer );
115 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
116 wxpeer->HandleWindowEvent( event );
123 wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
127 wxNSTextFieldControl::~wxNSTextFieldControl()
131 wxString wxNSTextFieldControl::GetStringValue() const
133 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
134 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
136 void wxNSTextFieldControl::SetStringValue( const wxString &str)
138 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
140 void wxNSTextFieldControl::Copy()
144 void wxNSTextFieldControl::Cut()
148 void wxNSTextFieldControl::Paste()
152 bool wxNSTextFieldControl::CanPaste() const
157 void wxNSTextFieldControl::SetEditable(bool editable)
159 [(wxNSTextField*) m_osxView setEditable:editable];
162 void wxNSTextFieldControl::GetSelection( long* from, long* to) const
166 void wxNSTextFieldControl::SetSelection( long from , long to )
170 void wxNSTextFieldControl::WriteText(const wxString& str)
172 // temp hack to get logging working early
173 wxString former = GetStringValue();
174 SetStringValue( former + str );
177 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
186 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
187 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
189 if ( style & wxNO_BORDER )
196 //[v setEditable:NO];
197 //[v setDrawsBackground:NO];
199 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
204 #endif // wxUSE_TEXTCTRL