]>
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 | ||
9d112688 JS |
31 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) |
32 | BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) | |
fb896a32 DE |
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); |
715b3df0 DE |
62 | |
63 | [(NSTextField*)m_cocoaNSView setTarget: sm_cocoaTarget]; | |
64 | [(NSTextField*)m_cocoaNSView setAction:@selector(wxNSControlAction:)]; | |
65 | ||
fb896a32 DE |
66 | return true; |
67 | } | |
68 | ||
69 | wxTextCtrl::~wxTextCtrl() | |
70 | { | |
911e17c6 | 71 | DisassociateNSTextField(GetNSTextField()); |
fb896a32 DE |
72 | } |
73 | ||
74 | void wxTextCtrl::Cocoa_didChangeText(void) | |
75 | { | |
76 | } | |
77 | ||
715b3df0 DE |
78 | void wxTextCtrl::CocoaTarget_action(void) |
79 | { | |
80 | // NSTextField only sends the action message on enter key press and thus | |
81 | // we send the appropriate event type. | |
82 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, GetId()); | |
83 | ||
84 | // See wxTextCtrlBase::SendTextUpdatedEvent for why we don't set the string. | |
85 | //event.SetString(GetValue()); | |
86 | ||
87 | event.SetEventObject(this); | |
88 | GetEventHandler()->ProcessEvent(event); | |
89 | } | |
90 | ||
fb896a32 DE |
91 | void wxTextCtrl::AppendText(wxString const&) |
92 | { | |
93 | } | |
94 | ||
95 | void wxTextCtrl::SetEditable(bool) | |
96 | { | |
97 | } | |
98 | ||
3a9fa0d6 VZ |
99 | void wxTextCtrl::MarkDirty() |
100 | { | |
101 | } | |
102 | ||
fb896a32 DE |
103 | void wxTextCtrl::DiscardEdits() |
104 | { | |
105 | } | |
106 | ||
107 | void wxTextCtrl::SetSelection(long, long) | |
108 | { | |
109 | } | |
110 | ||
111 | void wxTextCtrl::ShowPosition(long) | |
112 | { | |
113 | } | |
114 | ||
115 | void wxTextCtrl::SetInsertionPoint(long) | |
116 | { | |
117 | } | |
118 | ||
119 | void wxTextCtrl::SetInsertionPointEnd() | |
120 | { | |
121 | } | |
122 | ||
123 | void wxTextCtrl::Cut() | |
124 | { | |
125 | } | |
126 | ||
127 | void wxTextCtrl::Copy() | |
128 | { | |
129 | } | |
130 | ||
131 | void wxTextCtrl::Redo() | |
132 | { | |
133 | } | |
134 | ||
135 | void wxTextCtrl::Undo() | |
136 | { | |
137 | } | |
138 | ||
139 | void wxTextCtrl::Clear() | |
140 | { | |
141 | } | |
142 | ||
143 | void wxTextCtrl::Paste() | |
144 | { | |
145 | } | |
146 | ||
147 | void wxTextCtrl::Remove(long, long) | |
148 | { | |
149 | } | |
150 | ||
151 | void wxTextCtrl::Replace(long, long, wxString const&) | |
152 | { | |
153 | } | |
154 | ||
ee2ec18e | 155 | void wxTextCtrl::DoSetValue(wxString const& value, int flags) |
fb896a32 | 156 | { |
7fc77f30 | 157 | wxAutoNSAutoreleasePool pool; |
7d27dcf9 | 158 | [GetNSTextField() setStringValue: wxNSStringWithWxString(value)]; |
ee2ec18e VZ |
159 | |
160 | if ( flags & SetValue_SendEvent ) | |
161 | SendTextUpdatedEvent(); | |
fb896a32 DE |
162 | } |
163 | ||
164 | void wxTextCtrl::WriteText(wxString const&) | |
165 | { | |
166 | } | |
167 | ||
168 | bool wxTextCtrl::IsEditable() const | |
169 | { | |
170 | return true; | |
171 | } | |
172 | ||
173 | bool wxTextCtrl::IsModified() const | |
174 | { | |
175 | return false; | |
176 | } | |
177 | ||
178 | wxString wxTextCtrl::GetLineText(long) const | |
179 | { | |
180 | return wxEmptyString; | |
181 | } | |
182 | ||
183 | void wxTextCtrl::GetSelection(long*, long*) const | |
184 | { | |
185 | } | |
186 | ||
187 | bool wxTextCtrl::PositionToXY(long, long*, long*) const | |
188 | { | |
189 | return false; | |
190 | } | |
191 | ||
192 | long wxTextCtrl::XYToPosition(long, long) const | |
193 | { | |
194 | return 0; | |
195 | } | |
196 | ||
197 | int wxTextCtrl::GetLineLength(long) const | |
198 | { | |
199 | return 0; | |
200 | } | |
201 | ||
7d8268a1 | 202 | wxTextPos wxTextCtrl::GetLastPosition() const |
fb896a32 DE |
203 | { |
204 | return 0; | |
205 | } | |
206 | ||
207 | int wxTextCtrl::GetNumberOfLines() const | |
208 | { | |
209 | return 0; | |
210 | } | |
211 | ||
212 | long wxTextCtrl::GetInsertionPoint() const | |
213 | { | |
214 | return 0; | |
215 | } | |
216 | ||
217 | bool wxTextCtrl::CanRedo() const | |
218 | { | |
219 | return false; | |
220 | } | |
221 | ||
222 | bool wxTextCtrl::CanUndo() const | |
223 | { | |
224 | return false; | |
225 | } | |
226 | ||
227 | wxString wxTextCtrl::GetValue() const | |
228 | { | |
7fc77f30 | 229 | wxAutoNSAutoreleasePool pool; |
b0c0a393 | 230 | return wxStringWithNSString([GetNSTextField() stringValue]); |
fb896a32 DE |
231 | } |
232 | ||
79e1f224 DE |
233 | wxSize wxTextCtrl::DoGetBestSize() const |
234 | { | |
235 | wxAutoNSAutoreleasePool pool; | |
236 | wxASSERT(GetNSControl()); | |
237 | NSCell *cell = [GetNSControl() cell]; | |
238 | wxASSERT(cell); | |
239 | NSSize cellSize = [cell cellSize]; | |
c05c7cb5 | 240 | wxSize size(100,(int)ceil(cellSize.height)); |
79e1f224 DE |
241 | |
242 | wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y); | |
243 | return size; | |
244 | } |