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"
19 #include "wx/cocoa/string.h"
21 #include "wx/cocoa/autorelease.h"
23 #import <Foundation/NSString.h>
24 #import <AppKit/NSTextField.h>
28 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
29 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
31 WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
33 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
34 const wxString& value,
38 const wxValidator& validator,
41 wxAutoNSAutoreleasePool pool;
42 if(!CreateControl(parent,winid,pos,size,style,validator,name))
45 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
46 [m_cocoaNSView release];
47 [GetNSTextField() setStringValue:wxNSStringWithWxString(value)];
49 [GetNSControl() sizeToFit];
50 NSRect currentFrame = [m_cocoaNSView frame];
51 if(currentFrame.size.width < 70)
53 currentFrame.size.width = 70;
54 [m_cocoaNSView setFrame:currentFrame];
57 m_parent->CocoaAddChild(this);
58 SetInitialFrameRect(pos,size);
62 wxTextCtrl::~wxTextCtrl()
64 DisassociateNSTextField(GetNSTextField());
67 void wxTextCtrl::Cocoa_didChangeText(void)
71 void wxTextCtrl::AppendText(wxString const&)
75 void wxTextCtrl::SetEditable(bool)
79 void wxTextCtrl::MarkDirty()
83 void wxTextCtrl::DiscardEdits()
87 void wxTextCtrl::SetSelection(long, long)
91 void wxTextCtrl::ShowPosition(long)
95 void wxTextCtrl::SetInsertionPoint(long)
99 void wxTextCtrl::SetInsertionPointEnd()
103 void wxTextCtrl::Cut()
107 void wxTextCtrl::Copy()
111 void wxTextCtrl::Redo()
115 void wxTextCtrl::Undo()
119 void wxTextCtrl::Clear()
123 void wxTextCtrl::Paste()
127 void wxTextCtrl::Remove(long, long)
131 void wxTextCtrl::Replace(long, long, wxString const&)
135 void wxTextCtrl::SetValue(wxString const& value)
137 wxAutoNSAutoreleasePool pool;
138 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
141 void wxTextCtrl::WriteText(wxString const&)
145 bool wxTextCtrl::IsEditable() const
150 bool wxTextCtrl::IsModified() const
155 wxString wxTextCtrl::GetLineText(long) const
157 return wxEmptyString;
160 void wxTextCtrl::GetSelection(long*, long*) const
164 bool wxTextCtrl::PositionToXY(long, long*, long*) const
169 long wxTextCtrl::XYToPosition(long, long) const
174 int wxTextCtrl::GetLineLength(long) const
179 long wxTextCtrl::GetLastPosition() const
184 int wxTextCtrl::GetNumberOfLines() const
189 long wxTextCtrl::GetInsertionPoint() const
194 bool wxTextCtrl::CanRedo() const
199 bool wxTextCtrl::CanUndo() const
204 wxString wxTextCtrl::GetValue() const
206 wxAutoNSAutoreleasePool pool;
207 return wxStringWithNSString([GetNSTextField() stringValue]);
210 wxSize wxTextCtrl::DoGetBestSize() const
212 wxAutoNSAutoreleasePool pool;
213 wxASSERT(GetNSControl());
214 NSCell *cell = [GetNSControl() cell];
216 NSSize cellSize = [cell cellSize];
217 wxSize size(100,(int)ceilf(cellSize.height));
219 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);