1 /////////////////////////////////////////////////////////////////////////////
2 // Name: cocoa/textctrl.mm
4 // Author: David Elliott
8 // Copyright: (c) 2003 David Elliott
9 // Licence: wxWidgets licence
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>
25 #import <AppKit/NSCell.h>
29 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl)
30 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
32 WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
34 bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
35 const wxString& value,
39 const wxValidator& validator,
42 wxAutoNSAutoreleasePool pool;
43 if(!CreateControl(parent,winid,pos,size,style,validator,name))
46 SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
47 [m_cocoaNSView release];
48 [GetNSTextField() setStringValue:wxNSStringWithWxString(value)];
50 [GetNSControl() sizeToFit];
51 NSRect currentFrame = [m_cocoaNSView frame];
52 if(currentFrame.size.width < 70)
54 currentFrame.size.width = 70;
55 [m_cocoaNSView setFrame:currentFrame];
58 m_parent->CocoaAddChild(this);
59 SetInitialFrameRect(pos,size);
63 wxTextCtrl::~wxTextCtrl()
65 DisassociateNSTextField(GetNSTextField());
68 void wxTextCtrl::Cocoa_didChangeText(void)
72 void wxTextCtrl::AppendText(wxString const&)
76 void wxTextCtrl::SetEditable(bool)
80 void wxTextCtrl::MarkDirty()
84 void wxTextCtrl::DiscardEdits()
88 void wxTextCtrl::SetSelection(long, long)
92 void wxTextCtrl::ShowPosition(long)
96 void wxTextCtrl::SetInsertionPoint(long)
100 void wxTextCtrl::SetInsertionPointEnd()
104 void wxTextCtrl::Cut()
108 void wxTextCtrl::Copy()
112 void wxTextCtrl::Redo()
116 void wxTextCtrl::Undo()
120 void wxTextCtrl::Clear()
124 void wxTextCtrl::Paste()
128 void wxTextCtrl::Remove(long, long)
132 void wxTextCtrl::Replace(long, long, wxString const&)
136 void wxTextCtrl::SetValue(wxString const& value)
138 wxAutoNSAutoreleasePool pool;
139 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
142 void wxTextCtrl::WriteText(wxString const&)
146 bool wxTextCtrl::IsEditable() const
151 bool wxTextCtrl::IsModified() const
156 wxString wxTextCtrl::GetLineText(long) const
158 return wxEmptyString;
161 void wxTextCtrl::GetSelection(long*, long*) const
165 bool wxTextCtrl::PositionToXY(long, long*, long*) const
170 long wxTextCtrl::XYToPosition(long, long) const
175 int wxTextCtrl::GetLineLength(long) const
180 long wxTextCtrl::GetLastPosition() const
185 int wxTextCtrl::GetNumberOfLines() const
190 long wxTextCtrl::GetInsertionPoint() const
195 bool wxTextCtrl::CanRedo() const
200 bool wxTextCtrl::CanUndo() const
205 wxString wxTextCtrl::GetValue() const
207 wxAutoNSAutoreleasePool pool;
208 return wxStringWithNSString([GetNSTextField() stringValue]);
211 wxSize wxTextCtrl::DoGetBestSize() const
213 wxAutoNSAutoreleasePool pool;
214 wxASSERT(GetNSControl());
215 NSCell *cell = [GetNSControl() cell];
217 NSSize cellSize = [cell cellSize];
218 wxSize size(100,(int)ceilf(cellSize.height));
220 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);