1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/textctrl.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/textctrl.h"
18 #include "wx/cocoa/string.h"
20 #include "wx/cocoa/autorelease.h"
22 #import <Foundation/NSString.h>
23 #import <AppKit/NSTextField.h>
25 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
26 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
28 WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
30 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
31 const wxString& value,
35 const wxValidator& validator,
38 wxAutoNSAutoreleasePool pool;
39 if(!CreateControl(parent,winid,pos,size,style,validator,name))
42 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
43 [m_cocoaNSView release];
44 [GetNSTextField() setStringValue:wxNSStringWithWxString(value)];
46 [GetNSControl() sizeToFit];
47 NSRect currentFrame = [m_cocoaNSView frame];
48 if(currentFrame.size.width < 70)
50 currentFrame.size.width = 70;
51 [m_cocoaNSView setFrame:currentFrame];
54 m_parent->CocoaAddChild(this);
55 SetInitialFrameRect(pos,size);
59 wxTextCtrl::~wxTextCtrl()
61 DisassociateNSTextField(GetNSTextField());
64 void wxTextCtrl::Cocoa_didChangeText(void)
68 void wxTextCtrl::AppendText(wxString const&)
72 void wxTextCtrl::SetEditable(bool)
76 void wxTextCtrl::MarkDirty()
80 void wxTextCtrl::DiscardEdits()
84 void wxTextCtrl::SetSelection(long, long)
88 void wxTextCtrl::ShowPosition(long)
92 void wxTextCtrl::SetInsertionPoint(long)
96 void wxTextCtrl::SetInsertionPointEnd()
100 void wxTextCtrl::Cut()
104 void wxTextCtrl::Copy()
108 void wxTextCtrl::Redo()
112 void wxTextCtrl::Undo()
116 void wxTextCtrl::Clear()
120 void wxTextCtrl::Paste()
124 void wxTextCtrl::Remove(long, long)
128 void wxTextCtrl::Replace(long, long, wxString const&)
132 void wxTextCtrl::SetValue(wxString const& value)
134 wxAutoNSAutoreleasePool pool;
135 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
138 void wxTextCtrl::WriteText(wxString const&)
142 bool wxTextCtrl::IsEditable() const
147 bool wxTextCtrl::IsModified() const
152 wxString wxTextCtrl::GetLineText(long) const
154 return wxEmptyString;
157 void wxTextCtrl::GetSelection(long*, long*) const
161 bool wxTextCtrl::PositionToXY(long, long*, long*) const
166 long wxTextCtrl::XYToPosition(long, long) const
171 int wxTextCtrl::GetLineLength(long) const
176 long wxTextCtrl::GetLastPosition() const
181 int wxTextCtrl::GetNumberOfLines() const
186 long wxTextCtrl::GetInsertionPoint() const
191 bool wxTextCtrl::CanRedo() const
196 bool wxTextCtrl::CanUndo() const
201 wxString wxTextCtrl::GetValue() const
203 wxAutoNSAutoreleasePool pool;
204 return wxStringWithNSString([GetNSTextField() stringValue]);