]>
Commit | Line | Data |
---|---|---|
fb896a32 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: cocoa/textctrl.mm | |
3 | // Purpose: wxTextCtrl | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2003/03/16 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) 2003 David Elliott | |
7d8268a1 | 9 | // Licence: wxWidgets licence |
fb896a32 DE |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
449c5673 DE |
12 | #include "wx/wxprec.h" |
13 | #ifndef WX_PRECOMP | |
14 | #include "wx/app.h" | |
15 | #include "wx/textctrl.h" | |
79e1f224 | 16 | #include "wx/log.h" |
449c5673 | 17 | #endif //WX_PRECOMP |
fb896a32 | 18 | |
7d27dcf9 DE |
19 | #include "wx/cocoa/string.h" |
20 | ||
7fc77f30 DE |
21 | #include "wx/cocoa/autorelease.h" |
22 | ||
fb896a32 DE |
23 | #import <Foundation/NSString.h> |
24 | #import <AppKit/NSTextField.h> | |
be134f05 | 25 | #import <AppKit/NSCell.h> |
fb896a32 | 26 | |
79e1f224 DE |
27 | #include <math.h> |
28 | ||
fb896a32 DE |
29 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) |
30 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) | |
31 | END_EVENT_TABLE() | |
32 | WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView) | |
33 | ||
34 | bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid, | |
35 | const wxString& value, | |
36 | const wxPoint& pos, | |
37 | const wxSize& size, | |
38 | long style, | |
39 | const wxValidator& validator, | |
40 | const wxString& name) | |
41 | { | |
7fc77f30 | 42 | wxAutoNSAutoreleasePool pool; |
fb896a32 DE |
43 | if(!CreateControl(parent,winid,pos,size,style,validator,name)) |
44 | return false; | |
45 | m_cocoaNSView = NULL; | |
9ba1d264 | 46 | SetNSTextField([[NSTextField alloc] initWithFrame:MakeDefaultNSRect(size)]); |
fb896a32 | 47 | [m_cocoaNSView release]; |
b0c0a393 DE |
48 | [GetNSTextField() setStringValue:wxNSStringWithWxString(value)]; |
49 | ||
fb896a32 | 50 | [GetNSControl() sizeToFit]; |
9ba1d264 DE |
51 | NSRect currentFrame = [m_cocoaNSView frame]; |
52 | if(currentFrame.size.width < 70) | |
53 | { | |
54 | currentFrame.size.width = 70; | |
55 | [m_cocoaNSView setFrame:currentFrame]; | |
56 | } | |
fb896a32 DE |
57 | if(m_parent) |
58 | m_parent->CocoaAddChild(this); | |
9ba1d264 | 59 | SetInitialFrameRect(pos,size); |
fb896a32 DE |
60 | return true; |
61 | } | |
62 | ||
63 | wxTextCtrl::~wxTextCtrl() | |
64 | { | |
911e17c6 | 65 | DisassociateNSTextField(GetNSTextField()); |
fb896a32 DE |
66 | } |
67 | ||
68 | void wxTextCtrl::Cocoa_didChangeText(void) | |
69 | { | |
70 | } | |
71 | ||
72 | void wxTextCtrl::AppendText(wxString const&) | |
73 | { | |
74 | } | |
75 | ||
76 | void wxTextCtrl::SetEditable(bool) | |
77 | { | |
78 | } | |
79 | ||
3a9fa0d6 VZ |
80 | void wxTextCtrl::MarkDirty() |
81 | { | |
82 | } | |
83 | ||
fb896a32 DE |
84 | void wxTextCtrl::DiscardEdits() |
85 | { | |
86 | } | |
87 | ||
88 | void wxTextCtrl::SetSelection(long, long) | |
89 | { | |
90 | } | |
91 | ||
92 | void wxTextCtrl::ShowPosition(long) | |
93 | { | |
94 | } | |
95 | ||
96 | void wxTextCtrl::SetInsertionPoint(long) | |
97 | { | |
98 | } | |
99 | ||
100 | void wxTextCtrl::SetInsertionPointEnd() | |
101 | { | |
102 | } | |
103 | ||
104 | void wxTextCtrl::Cut() | |
105 | { | |
106 | } | |
107 | ||
108 | void wxTextCtrl::Copy() | |
109 | { | |
110 | } | |
111 | ||
112 | void wxTextCtrl::Redo() | |
113 | { | |
114 | } | |
115 | ||
116 | void wxTextCtrl::Undo() | |
117 | { | |
118 | } | |
119 | ||
120 | void wxTextCtrl::Clear() | |
121 | { | |
122 | } | |
123 | ||
124 | void wxTextCtrl::Paste() | |
125 | { | |
126 | } | |
127 | ||
128 | void wxTextCtrl::Remove(long, long) | |
129 | { | |
130 | } | |
131 | ||
132 | void wxTextCtrl::Replace(long, long, wxString const&) | |
133 | { | |
134 | } | |
135 | ||
7d27dcf9 | 136 | void wxTextCtrl::SetValue(wxString const& value) |
fb896a32 | 137 | { |
7fc77f30 | 138 | wxAutoNSAutoreleasePool pool; |
7d27dcf9 | 139 | [GetNSTextField() setStringValue: wxNSStringWithWxString(value)]; |
fb896a32 DE |
140 | } |
141 | ||
142 | void wxTextCtrl::WriteText(wxString const&) | |
143 | { | |
144 | } | |
145 | ||
146 | bool wxTextCtrl::IsEditable() const | |
147 | { | |
148 | return true; | |
149 | } | |
150 | ||
151 | bool wxTextCtrl::IsModified() const | |
152 | { | |
153 | return false; | |
154 | } | |
155 | ||
156 | wxString wxTextCtrl::GetLineText(long) const | |
157 | { | |
158 | return wxEmptyString; | |
159 | } | |
160 | ||
161 | void wxTextCtrl::GetSelection(long*, long*) const | |
162 | { | |
163 | } | |
164 | ||
165 | bool wxTextCtrl::PositionToXY(long, long*, long*) const | |
166 | { | |
167 | return false; | |
168 | } | |
169 | ||
170 | long wxTextCtrl::XYToPosition(long, long) const | |
171 | { | |
172 | return 0; | |
173 | } | |
174 | ||
175 | int wxTextCtrl::GetLineLength(long) const | |
176 | { | |
177 | return 0; | |
178 | } | |
179 | ||
7d8268a1 | 180 | wxTextPos wxTextCtrl::GetLastPosition() const |
fb896a32 DE |
181 | { |
182 | return 0; | |
183 | } | |
184 | ||
185 | int wxTextCtrl::GetNumberOfLines() const | |
186 | { | |
187 | return 0; | |
188 | } | |
189 | ||
190 | long wxTextCtrl::GetInsertionPoint() const | |
191 | { | |
192 | return 0; | |
193 | } | |
194 | ||
195 | bool wxTextCtrl::CanRedo() const | |
196 | { | |
197 | return false; | |
198 | } | |
199 | ||
200 | bool wxTextCtrl::CanUndo() const | |
201 | { | |
202 | return false; | |
203 | } | |
204 | ||
205 | wxString wxTextCtrl::GetValue() const | |
206 | { | |
7fc77f30 | 207 | wxAutoNSAutoreleasePool pool; |
b0c0a393 | 208 | return wxStringWithNSString([GetNSTextField() stringValue]); |
fb896a32 DE |
209 | } |
210 | ||
79e1f224 DE |
211 | wxSize wxTextCtrl::DoGetBestSize() const |
212 | { | |
213 | wxAutoNSAutoreleasePool pool; | |
214 | wxASSERT(GetNSControl()); | |
215 | NSCell *cell = [GetNSControl() cell]; | |
216 | wxASSERT(cell); | |
217 | NSSize cellSize = [cell cellSize]; | |
c05c7cb5 | 218 | wxSize size(100,(int)ceil(cellSize.height)); |
79e1f224 DE |
219 | |
220 | wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y); | |
221 | return size; | |
222 | } | |
223 |