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
54 WXCOCOAIMPL_COMMON_IMPLEMENTATION
56 - (id)initWithFrame:(NSRect)frame
58 [super initWithFrame:frame];
60 [self setDelegate: self];
61 [self setTarget: self];
62 // [self setAction: @selector(enterAction:)];
66 // use our common calls
67 - (void) setTitle:(NSString *) title
69 [self setStringValue: title];
72 - (void)controlTextDidChange:(NSNotification *)aNotification
76 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
78 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
79 event.SetEventObject( wxpeer );
80 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
81 wxpeer->HandleWindowEvent( event );
86 - (void)controlTextDidEndEditing:(NSNotification *)aNotification
90 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
92 wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId());
93 event.SetEventObject( wxpeer );
94 event.SetWindow( wxpeer );
95 wxpeer->HandleWindowEvent( event );
100 - (void) enterAction: (id) sender
104 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
105 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) {
106 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
107 event.SetEventObject( wxpeer );
108 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
109 wxpeer->HandleWindowEvent( event );
116 wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
120 wxNSTextFieldControl::~wxNSTextFieldControl()
124 wxString wxNSTextFieldControl::GetStringValue() const
126 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
127 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
129 void wxNSTextFieldControl::SetStringValue( const wxString &str)
131 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
133 void wxNSTextFieldControl::Copy()
137 void wxNSTextFieldControl::Cut()
141 void wxNSTextFieldControl::Paste()
145 bool wxNSTextFieldControl::CanPaste() const
150 void wxNSTextFieldControl::SetEditable(bool editable)
152 [(wxNSTextField*) m_osxView setEditable:editable];
155 void wxNSTextFieldControl::GetSelection( long* from, long* to) const
159 void wxNSTextFieldControl::SetSelection( long from , long to )
163 void wxNSTextFieldControl::WriteText(const wxString& str)
165 // temp hack to get logging working early
166 wxString former = GetStringValue();
167 SetStringValue( former + str );
170 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
179 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
180 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
182 if ( style & wxNO_BORDER )
189 //[v setEditable:NO];
190 //[v setDrawsBackground:NO];
192 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
193 [v setImplementation:c];
198 #endif // wxUSE_TEXTCTRL