1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/textctrl.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/textctrl.h"
15 #include "wx/cocoa/string.h"
17 #include "wx/cocoa/autorelease.h"
19 #import <Foundation/NSString.h>
20 #import <AppKit/NSTextField.h>
22 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
23 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
25 WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
27 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
28 const wxString& value,
32 const wxValidator& validator,
35 wxAutoNSAutoreleasePool pool;
36 if(!CreateControl(parent,winid,pos,size,style,validator,name))
39 SetNSTextField([[NSTextField alloc] initWithFrame:NSMakeRect(0,0,30,30)]);
40 [m_cocoaNSView release];
41 [GetNSTextField() setStringValue:[NSString stringWithCString:value.c_str()]];
42 [GetNSControl() sizeToFit];
44 m_parent->CocoaAddChild(this);
48 wxTextCtrl::~wxTextCtrl()
50 DisassociateNSTextField(m_cocoaNSView);
53 void wxTextCtrl::Cocoa_didChangeText(void)
57 void wxTextCtrl::AppendText(wxString const&)
61 void wxTextCtrl::SetEditable(bool)
65 void wxTextCtrl::DiscardEdits()
69 void wxTextCtrl::SetSelection(long, long)
73 void wxTextCtrl::ShowPosition(long)
77 void wxTextCtrl::SetInsertionPoint(long)
81 void wxTextCtrl::SetInsertionPointEnd()
85 void wxTextCtrl::Cut()
89 void wxTextCtrl::Copy()
93 void wxTextCtrl::Redo()
97 void wxTextCtrl::Undo()
101 void wxTextCtrl::Clear()
105 void wxTextCtrl::Paste()
109 void wxTextCtrl::Remove(long, long)
113 void wxTextCtrl::Replace(long, long, wxString const&)
117 void wxTextCtrl::SetValue(wxString const& value)
119 wxAutoNSAutoreleasePool pool;
120 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
123 void wxTextCtrl::WriteText(wxString const&)
127 bool wxTextCtrl::IsEditable() const
132 bool wxTextCtrl::IsModified() const
137 wxString wxTextCtrl::GetLineText(long) const
139 return wxEmptyString;
142 void wxTextCtrl::GetSelection(long*, long*) const
146 bool wxTextCtrl::PositionToXY(long, long*, long*) const
151 long wxTextCtrl::XYToPosition(long, long) const
156 int wxTextCtrl::GetLineLength(long) const
161 long wxTextCtrl::GetLastPosition() const
166 int wxTextCtrl::GetNumberOfLines() const
171 long wxTextCtrl::GetInsertionPoint() const
176 bool wxTextCtrl::CanRedo() const
181 bool wxTextCtrl::CanUndo() const
186 wxString wxTextCtrl::GetValue() const
188 wxAutoNSAutoreleasePool pool;
189 return wxString([[GetNSTextField() stringValue] lossyCString]);