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::MarkDirty()
79 void wxTextCtrl::DiscardEdits()
83 void wxTextCtrl::SetSelection(long, long)
87 void wxTextCtrl::ShowPosition(long)
91 void wxTextCtrl::SetInsertionPoint(long)
95 void wxTextCtrl::SetInsertionPointEnd()
99 void wxTextCtrl::Cut()
103 void wxTextCtrl::Copy()
107 void wxTextCtrl::Redo()
111 void wxTextCtrl::Undo()
115 void wxTextCtrl::Clear()
119 void wxTextCtrl::Paste()
123 void wxTextCtrl::Remove(long, long)
127 void wxTextCtrl::Replace(long, long, wxString const&)
131 void wxTextCtrl::SetValue(wxString const& value)
133 wxAutoNSAutoreleasePool pool;
134 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
137 void wxTextCtrl::WriteText(wxString const&)
141 bool wxTextCtrl::IsEditable() const
146 bool wxTextCtrl::IsModified() const
151 wxString wxTextCtrl::GetLineText(long) const
153 return wxEmptyString;
156 void wxTextCtrl::GetSelection(long*, long*) const
160 bool wxTextCtrl::PositionToXY(long, long*, long*) const
165 long wxTextCtrl::XYToPosition(long, long) const
170 int wxTextCtrl::GetLineLength(long) const
175 long wxTextCtrl::GetLastPosition() const
180 int wxTextCtrl::GetNumberOfLines() const
185 long wxTextCtrl::GetInsertionPoint() const
190 bool wxTextCtrl::CanRedo() const
195 bool wxTextCtrl::CanUndo() const
200 wxString wxTextCtrl::GetValue() const
202 wxAutoNSAutoreleasePool pool;
203 return wxString([[GetNSTextField() stringValue] lossyCString]);