]>
Commit | Line | Data |
---|---|---|
fb896a32 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fec9cc08 | 2 | // Name: src/cocoa/textctrl.mm |
fb896a32 DE |
3 | // Purpose: wxTextCtrl |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2003/03/16 | |
fec9cc08 | 7 | // RCS-ID: $Id$ |
fb896a32 | 8 | // Copyright: (c) 2003 David Elliott |
7d8268a1 | 9 | // Licence: wxWidgets 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> | |
be134f05 | 27 | #import <AppKit/NSCell.h> |
fb896a32 | 28 | |
79e1f224 DE |
29 | #include <math.h> |
30 | ||
fb896a32 DE |
31 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) |
32 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) | |
33 | END_EVENT_TABLE() | |
34 | WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView) | |
35 | ||
36 | bool 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; | |
9ba1d264 | 48 | SetNSTextField([[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); |
fb896a32 DE |
62 | return true; |
63 | } | |
64 | ||
65 | wxTextCtrl::~wxTextCtrl() | |
66 | { | |
911e17c6 | 67 | DisassociateNSTextField(GetNSTextField()); |
fb896a32 DE |
68 | } |
69 | ||
70 | void wxTextCtrl::Cocoa_didChangeText(void) | |
71 | { | |
72 | } | |
73 | ||
74 | void wxTextCtrl::AppendText(wxString const&) | |
75 | { | |
76 | } | |
77 | ||
78 | void wxTextCtrl::SetEditable(bool) | |
79 | { | |
80 | } | |
81 | ||
3a9fa0d6 VZ |
82 | void wxTextCtrl::MarkDirty() |
83 | { | |
84 | } | |
85 | ||
fb896a32 DE |
86 | void wxTextCtrl::DiscardEdits() |
87 | { | |
88 | } | |
89 | ||
90 | void wxTextCtrl::SetSelection(long, long) | |
91 | { | |
92 | } | |
93 | ||
94 | void wxTextCtrl::ShowPosition(long) | |
95 | { | |
96 | } | |
97 | ||
98 | void wxTextCtrl::SetInsertionPoint(long) | |
99 | { | |
100 | } | |
101 | ||
102 | void wxTextCtrl::SetInsertionPointEnd() | |
103 | { | |
104 | } | |
105 | ||
106 | void wxTextCtrl::Cut() | |
107 | { | |
108 | } | |
109 | ||
110 | void wxTextCtrl::Copy() | |
111 | { | |
112 | } | |
113 | ||
114 | void wxTextCtrl::Redo() | |
115 | { | |
116 | } | |
117 | ||
118 | void wxTextCtrl::Undo() | |
119 | { | |
120 | } | |
121 | ||
122 | void wxTextCtrl::Clear() | |
123 | { | |
124 | } | |
125 | ||
126 | void wxTextCtrl::Paste() | |
127 | { | |
128 | } | |
129 | ||
130 | void wxTextCtrl::Remove(long, long) | |
131 | { | |
132 | } | |
133 | ||
134 | void wxTextCtrl::Replace(long, long, wxString const&) | |
135 | { | |
136 | } | |
137 | ||
7d27dcf9 | 138 | void wxTextCtrl::SetValue(wxString const& value) |
fb896a32 | 139 | { |
7fc77f30 | 140 | wxAutoNSAutoreleasePool pool; |
7d27dcf9 | 141 | [GetNSTextField() setStringValue: wxNSStringWithWxString(value)]; |
fb896a32 DE |
142 | } |
143 | ||
144 | void wxTextCtrl::WriteText(wxString const&) | |
145 | { | |
146 | } | |
147 | ||
148 | bool wxTextCtrl::IsEditable() const | |
149 | { | |
150 | return true; | |
151 | } | |
152 | ||
153 | bool wxTextCtrl::IsModified() const | |
154 | { | |
155 | return false; | |
156 | } | |
157 | ||
158 | wxString wxTextCtrl::GetLineText(long) const | |
159 | { | |
160 | return wxEmptyString; | |
161 | } | |
162 | ||
163 | void wxTextCtrl::GetSelection(long*, long*) const | |
164 | { | |
165 | } | |
166 | ||
167 | bool wxTextCtrl::PositionToXY(long, long*, long*) const | |
168 | { | |
169 | return false; | |
170 | } | |
171 | ||
172 | long wxTextCtrl::XYToPosition(long, long) const | |
173 | { | |
174 | return 0; | |
175 | } | |
176 | ||
177 | int wxTextCtrl::GetLineLength(long) const | |
178 | { | |
179 | return 0; | |
180 | } | |
181 | ||
7d8268a1 | 182 | wxTextPos wxTextCtrl::GetLastPosition() const |
fb896a32 DE |
183 | { |
184 | return 0; | |
185 | } | |
186 | ||
187 | int wxTextCtrl::GetNumberOfLines() const | |
188 | { | |
189 | return 0; | |
190 | } | |
191 | ||
192 | long wxTextCtrl::GetInsertionPoint() const | |
193 | { | |
194 | return 0; | |
195 | } | |
196 | ||
197 | bool wxTextCtrl::CanRedo() const | |
198 | { | |
199 | return false; | |
200 | } | |
201 | ||
202 | bool wxTextCtrl::CanUndo() const | |
203 | { | |
204 | return false; | |
205 | } | |
206 | ||
207 | wxString wxTextCtrl::GetValue() const | |
208 | { | |
7fc77f30 | 209 | wxAutoNSAutoreleasePool pool; |
b0c0a393 | 210 | return wxStringWithNSString([GetNSTextField() stringValue]); |
fb896a32 DE |
211 | } |
212 | ||
79e1f224 DE |
213 | wxSize wxTextCtrl::DoGetBestSize() const |
214 | { | |
215 | wxAutoNSAutoreleasePool pool; | |
216 | wxASSERT(GetNSControl()); | |
217 | NSCell *cell = [GetNSControl() cell]; | |
218 | wxASSERT(cell); | |
219 | NSSize cellSize = [cell cellSize]; | |
c05c7cb5 | 220 | wxSize size(100,(int)ceil(cellSize.height)); |
79e1f224 DE |
221 | |
222 | wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y); | |
223 | return size; | |
224 | } |