1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/textctrl.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/textctrl.h"
21 #include "wx/cocoa/string.h"
23 #include "wx/cocoa/autorelease.h"
25 #import <Foundation/NSString.h>
26 #import <AppKit/NSTextField.h>
27 #import <AppKit/NSCell.h>
31 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
32 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
34 WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
36 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
37 const wxString& value,
41 const wxValidator& validator,
44 wxAutoNSAutoreleasePool pool;
45 if(!CreateControl(parent,winid,pos,size,style,validator,name))
48 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
49 [m_cocoaNSView release];
50 [GetNSTextField() setStringValue:wxNSStringWithWxString(value)];
52 [GetNSControl() sizeToFit];
53 NSRect currentFrame = [m_cocoaNSView frame];
54 if(currentFrame.size.width < 70)
56 currentFrame.size.width = 70;
57 [m_cocoaNSView setFrame:currentFrame];
60 m_parent->CocoaAddChild(this);
61 SetInitialFrameRect(pos,size);
65 wxTextCtrl::~wxTextCtrl()
67 DisassociateNSTextField(GetNSTextField());
70 void wxTextCtrl::Cocoa_didChangeText(void)
74 void wxTextCtrl::AppendText(wxString const&)
78 void wxTextCtrl::SetEditable(bool)
82 void wxTextCtrl::MarkDirty()
86 void wxTextCtrl::DiscardEdits()
90 void wxTextCtrl::SetSelection(long, long)
94 void wxTextCtrl::ShowPosition(long)
98 void wxTextCtrl::SetInsertionPoint(long)
102 void wxTextCtrl::SetInsertionPointEnd()
106 void wxTextCtrl::Cut()
110 void wxTextCtrl::Copy()
114 void wxTextCtrl::Redo()
118 void wxTextCtrl::Undo()
122 void wxTextCtrl::Clear()
126 void wxTextCtrl::Paste()
130 void wxTextCtrl::Remove(long, long)
134 void wxTextCtrl::Replace(long, long, wxString const&)
138 void wxTextCtrl::SetValue(wxString const& value)
140 wxAutoNSAutoreleasePool pool;
141 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
144 void wxTextCtrl::WriteText(wxString const&)
148 bool wxTextCtrl::IsEditable() const
153 bool wxTextCtrl::IsModified() const
158 wxString wxTextCtrl::GetLineText(long) const
160 return wxEmptyString;
163 void wxTextCtrl::GetSelection(long*, long*) const
167 bool wxTextCtrl::PositionToXY(long, long*, long*) const
172 long wxTextCtrl::XYToPosition(long, long) const
177 int wxTextCtrl::GetLineLength(long) const
182 wxTextPos wxTextCtrl::GetLastPosition() const
187 int wxTextCtrl::GetNumberOfLines() const
192 long wxTextCtrl::GetInsertionPoint() const
197 bool wxTextCtrl::CanRedo() const
202 bool wxTextCtrl::CanUndo() const
207 wxString wxTextCtrl::GetValue() const
209 wxAutoNSAutoreleasePool pool;
210 return wxStringWithNSString([GetNSTextField() stringValue]);
213 wxSize wxTextCtrl::DoGetBestSize() const
215 wxAutoNSAutoreleasePool pool;
216 wxASSERT(GetNSControl());
217 NSCell *cell = [GetNSControl() cell];
219 NSSize cellSize = [cell cellSize];
220 wxSize size(100,(int)ceil(cellSize.height));
222 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);