]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/textctrl.mm
Remove duplicate IMPLEMENT_XXX_CLASS macros from wxUniv code.
[wxWidgets.git] / src / cocoa / textctrl.mm
CommitLineData
fb896a32 1/////////////////////////////////////////////////////////////////////////////
fec9cc08 2// Name: src/cocoa/textctrl.mm
fb896a32
DE
3// Purpose: wxTextCtrl
4// Author: David Elliott
da19c58b 5// Modified by: Mark Oxenham
fb896a32 6// Created: 2003/03/16
fec9cc08 7// RCS-ID: $Id$
fb896a32 8// Copyright: (c) 2003 David Elliott
526954c5 9// Licence: wxWindows licence
fb896a32
DE
10/////////////////////////////////////////////////////////////////////////////
11
449c5673 12#include "wx/wxprec.h"
fec9cc08
WS
13
14#include "wx/textctrl.h"
15
449c5673
DE
16#ifndef WX_PRECOMP
17 #include "wx/app.h"
79e1f224 18 #include "wx/log.h"
449c5673 19#endif //WX_PRECOMP
fb896a32 20
7d27dcf9
DE
21#include "wx/cocoa/string.h"
22
7fc77f30
DE
23#include "wx/cocoa/autorelease.h"
24
fb896a32
DE
25#import <Foundation/NSString.h>
26#import <AppKit/NSTextField.h>
f513aa78 27#import <AppKit/NSSecureTextField.h>
be134f05 28#import <AppKit/NSCell.h>
fb896a32 29
79e1f224
DE
30#include <math.h>
31
9d112688 32BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
fb896a32
DE
33END_EVENT_TABLE()
34WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
35
36bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
37 const wxString& value,
38 const wxPoint& pos,
39 const wxSize& size,
40 long style,
41 const wxValidator& validator,
42 const wxString& name)
43{
7fc77f30 44 wxAutoNSAutoreleasePool pool;
fb896a32
DE
45 if(!CreateControl(parent,winid,pos,size,style,validator,name))
46 return false;
47 m_cocoaNSView = NULL;
f513aa78 48 SetNSTextField([(style & wxTE_PASSWORD)?[NSSecureTextField alloc]:[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]);
fb896a32 49 [m_cocoaNSView release];
b0c0a393
DE
50 [GetNSTextField() setStringValue:wxNSStringWithWxString(value)];
51
fb896a32 52 [GetNSControl() sizeToFit];
9ba1d264
DE
53 NSRect currentFrame = [m_cocoaNSView frame];
54 if(currentFrame.size.width < 70)
55 {
56 currentFrame.size.width = 70;
57 [m_cocoaNSView setFrame:currentFrame];
58 }
fb896a32
DE
59 if(m_parent)
60 m_parent->CocoaAddChild(this);
9ba1d264 61 SetInitialFrameRect(pos,size);
715b3df0
DE
62
63 [(NSTextField*)m_cocoaNSView setTarget: sm_cocoaTarget];
64 [(NSTextField*)m_cocoaNSView setAction:@selector(wxNSControlAction:)];
da19c58b
DE
65
66 // set the text alignment option
67 NSTextAlignment alignStyle;
68 if (style & wxTE_RIGHT)
69 alignStyle = NSRightTextAlignment;
70 else if (style & wxTE_CENTRE)
71 alignStyle = NSCenterTextAlignment;
72 else // default to wxTE_LEFT because it is 0 and can't be tested
73 alignStyle = NSLeftTextAlignment;
74 [GetNSControl() setAlignment:alignStyle];
75
76 // if Read-only then set as such, this flag is overwritable by wxTextCtrl::SetEditable(TRUE)
77 if (style & wxTE_READONLY)
78 {
79 SetEditable(FALSE);
80 }
81
fb896a32
DE
82 return true;
83}
84
85wxTextCtrl::~wxTextCtrl()
86{
911e17c6 87 DisassociateNSTextField(GetNSTextField());
fb896a32
DE
88}
89
90void wxTextCtrl::Cocoa_didChangeText(void)
91{
92}
93
715b3df0
DE
94void wxTextCtrl::CocoaTarget_action(void)
95{
50135807 96 SendTextUpdatedEvent();
715b3df0
DE
97}
98
fb896a32
DE
99void wxTextCtrl::AppendText(wxString const&)
100{
101}
102
da19c58b 103void wxTextCtrl::SetEditable(bool editable)
fb896a32 104{
da19c58b
DE
105 // first ensure that the current value is stored (in case the user had not finished editing
106 // before SetEditable(FALSE) was called)
107 DoSetValue(GetValue(),1);
108
109 [GetNSTextField() setEditable: editable];
110
111 // forces the focus on the textctrl to be lost - while focus is still maintained
112 // after SetEditable(FALSE) the user may still edit the control
113 // (might not the best way to do this..)
114 [GetNSTextField() abortEditing];
fb896a32
DE
115}
116
3a9fa0d6
VZ
117void wxTextCtrl::MarkDirty()
118{
119}
120
fb896a32
DE
121void wxTextCtrl::DiscardEdits()
122{
123}
124
125void wxTextCtrl::SetSelection(long, long)
126{
127}
128
129void wxTextCtrl::ShowPosition(long)
130{
131}
132
133void wxTextCtrl::SetInsertionPoint(long)
134{
135}
136
137void wxTextCtrl::SetInsertionPointEnd()
138{
139}
140
141void wxTextCtrl::Cut()
142{
143}
144
145void wxTextCtrl::Copy()
146{
147}
148
149void wxTextCtrl::Redo()
150{
151}
152
153void wxTextCtrl::Undo()
154{
155}
156
157void wxTextCtrl::Clear()
158{
159}
160
161void wxTextCtrl::Paste()
162{
163}
164
165void wxTextCtrl::Remove(long, long)
166{
167}
168
169void wxTextCtrl::Replace(long, long, wxString const&)
170{
171}
172
ee2ec18e 173void wxTextCtrl::DoSetValue(wxString const& value, int flags)
fb896a32 174{
7fc77f30 175 wxAutoNSAutoreleasePool pool;
7d27dcf9 176 [GetNSTextField() setStringValue: wxNSStringWithWxString(value)];
ee2ec18e
VZ
177
178 if ( flags & SetValue_SendEvent )
179 SendTextUpdatedEvent();
fb896a32
DE
180}
181
182void wxTextCtrl::WriteText(wxString const&)
183{
184}
185
186bool wxTextCtrl::IsEditable() const
187{
da19c58b 188 return [GetNSTextField() isEditable];
fb896a32
DE
189}
190
191bool wxTextCtrl::IsModified() const
192{
193 return false;
194}
195
196wxString wxTextCtrl::GetLineText(long) const
197{
198 return wxEmptyString;
199}
200
201void wxTextCtrl::GetSelection(long*, long*) const
202{
203}
204
205bool wxTextCtrl::PositionToXY(long, long*, long*) const
206{
207 return false;
208}
209
210long wxTextCtrl::XYToPosition(long, long) const
211{
212 return 0;
213}
214
215int wxTextCtrl::GetLineLength(long) const
216{
217 return 0;
218}
219
7d8268a1 220wxTextPos wxTextCtrl::GetLastPosition() const
fb896a32 221{
da19c58b
DE
222 // working - returns the size of the wxString
223 return (long)(GetValue().Len());
fb896a32
DE
224}
225
226int wxTextCtrl::GetNumberOfLines() const
227{
228 return 0;
229}
230
231long wxTextCtrl::GetInsertionPoint() const
232{
233 return 0;
234}
235
236bool wxTextCtrl::CanRedo() const
237{
238 return false;
239}
240
241bool wxTextCtrl::CanUndo() const
242{
243 return false;
244}
245
246wxString wxTextCtrl::GetValue() const
247{
7fc77f30 248 wxAutoNSAutoreleasePool pool;
b0c0a393 249 return wxStringWithNSString([GetNSTextField() stringValue]);
fb896a32
DE
250}
251
79e1f224
DE
252wxSize wxTextCtrl::DoGetBestSize() const
253{
254 wxAutoNSAutoreleasePool pool;
255 wxASSERT(GetNSControl());
256 NSCell *cell = [GetNSControl() cell];
257 wxASSERT(cell);
258 NSSize cellSize = [cell cellSize];
c05c7cb5 259 wxSize size(100,(int)ceil(cellSize.height));
79e1f224
DE
260
261 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);
262 return size;
263}