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:[NSString stringWithCString:value.c_str()]];
45 [GetNSControl() sizeToFit];
46 NSRect currentFrame = [m_cocoaNSView frame];
47 if(currentFrame.size.width < 70)
49 currentFrame.size.width = 70;
50 [m_cocoaNSView setFrame:currentFrame];
53 m_parent->CocoaAddChild(this);
54 SetInitialFrameRect(pos,size);
58 wxTextCtrl::~wxTextCtrl()
60 DisassociateNSTextField(GetNSTextField());
63 void wxTextCtrl::Cocoa_didChangeText(void)
67 void wxTextCtrl::AppendText(wxString const&)
71 void wxTextCtrl::SetEditable(bool)
75 void wxTextCtrl::DiscardEdits()
79 void wxTextCtrl::SetSelection(long, long)
83 void wxTextCtrl::ShowPosition(long)
87 void wxTextCtrl::SetInsertionPoint(long)
91 void wxTextCtrl::SetInsertionPointEnd()
95 void wxTextCtrl::Cut()
99 void wxTextCtrl::Copy()
103 void wxTextCtrl::Redo()
107 void wxTextCtrl::Undo()
111 void wxTextCtrl::Clear()
115 void wxTextCtrl::Paste()
119 void wxTextCtrl::Remove(long, long)
123 void wxTextCtrl::Replace(long, long, wxString const&)
127 void wxTextCtrl::SetValue(wxString const& value)
129 wxAutoNSAutoreleasePool pool;
130 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
133 void wxTextCtrl::WriteText(wxString const&)
137 bool wxTextCtrl::IsEditable() const
142 bool wxTextCtrl::IsModified() const
147 wxString wxTextCtrl::GetLineText(long) const
149 return wxEmptyString;
152 void wxTextCtrl::GetSelection(long*, long*) const
156 bool wxTextCtrl::PositionToXY(long, long*, long*) const
161 long wxTextCtrl::XYToPosition(long, long) const
166 int wxTextCtrl::GetLineLength(long) const
171 long wxTextCtrl::GetLastPosition() const
176 int wxTextCtrl::GetNumberOfLines() const
181 long wxTextCtrl::GetInsertionPoint() const
186 bool wxTextCtrl::CanRedo() const
191 bool wxTextCtrl::CanUndo() const
196 wxString wxTextCtrl::GetValue() const
198 wxAutoNSAutoreleasePool pool;
199 return wxString([[GetNSTextField() stringValue] lossyCString]);