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:MakeDefaultNSRect(size)]);
40 [m_cocoaNSView release];
41 [GetNSTextField() setStringValue:[NSString stringWithCString:value.c_str()]];
42 [GetNSControl() sizeToFit];
43 NSRect currentFrame = [m_cocoaNSView frame];
44 if(currentFrame.size.width < 70)
46 currentFrame.size.width = 70;
47 [m_cocoaNSView setFrame:currentFrame];
50 m_parent->CocoaAddChild(this);
51 SetInitialFrameRect(pos,size);
55 wxTextCtrl::~wxTextCtrl()
57 DisassociateNSTextField(m_cocoaNSView);
60 void wxTextCtrl::Cocoa_didChangeText(void)
64 void wxTextCtrl::AppendText(wxString const&)
68 void wxTextCtrl::SetEditable(bool)
72 void wxTextCtrl::DiscardEdits()
76 void wxTextCtrl::SetSelection(long, long)
80 void wxTextCtrl::ShowPosition(long)
84 void wxTextCtrl::SetInsertionPoint(long)
88 void wxTextCtrl::SetInsertionPointEnd()
92 void wxTextCtrl::Cut()
96 void wxTextCtrl::Copy()
100 void wxTextCtrl::Redo()
104 void wxTextCtrl::Undo()
108 void wxTextCtrl::Clear()
112 void wxTextCtrl::Paste()
116 void wxTextCtrl::Remove(long, long)
120 void wxTextCtrl::Replace(long, long, wxString const&)
124 void wxTextCtrl::SetValue(wxString const& value)
126 wxAutoNSAutoreleasePool pool;
127 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
130 void wxTextCtrl::WriteText(wxString const&)
134 bool wxTextCtrl::IsEditable() const
139 bool wxTextCtrl::IsModified() const
144 wxString wxTextCtrl::GetLineText(long) const
146 return wxEmptyString;
149 void wxTextCtrl::GetSelection(long*, long*) const
153 bool wxTextCtrl::PositionToXY(long, long*, long*) const
158 long wxTextCtrl::XYToPosition(long, long) const
163 int wxTextCtrl::GetLineLength(long) const
168 long wxTextCtrl::GetLastPosition() const
173 int wxTextCtrl::GetNumberOfLines() const
178 long wxTextCtrl::GetInsertionPoint() const
183 bool wxTextCtrl::CanRedo() const
188 bool wxTextCtrl::CanUndo() const
193 wxString wxTextCtrl::GetValue() const
195 wxAutoNSAutoreleasePool pool;
196 return wxString([[GetNSTextField() stringValue] lossyCString]);