]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
faa94f3e | 2 | // Name: src/mac/carbon/textctrl.cpp |
e9576ca5 | 3 | // Purpose: wxTextCtrl |
a31a5f85 | 4 | // Author: Stefan Csomor |
6af16761 | 5 | // Modified by: Ryan Norton (MLTE GetLineLength and GetLineText) |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #include "wx/wxprec.h" |
fedad417 GD |
13 | |
14 | #if wxUSE_TEXTCTRL | |
15 | ||
88a7a4e1 WS |
16 | #include "wx/textctrl.h" |
17 | ||
18 | #ifndef WX_PRECOMP | |
19 | #include "wx/intl.h" | |
670f9935 | 20 | #include "wx/app.h" |
de6185e2 | 21 | #include "wx/utils.h" |
da80ae71 | 22 | #include "wx/dc.h" |
f1e01716 | 23 | #include "wx/button.h" |
3b3dc801 | 24 | #include "wx/menu.h" |
9eddec69 | 25 | #include "wx/settings.h" |
246c5004 | 26 | #include "wx/msgdlg.h" |
1832043f | 27 | #include "wx/toplevel.h" |
88a7a4e1 | 28 | #endif |
5ca0d812 | 29 | |
f5c6eb5c | 30 | #ifdef __DARWIN__ |
88a7a4e1 WS |
31 | #include <sys/types.h> |
32 | #include <sys/stat.h> | |
e9576ca5 | 33 | #else |
88a7a4e1 | 34 | #include <stat.h> |
e9576ca5 | 35 | #endif |
2b5f62a0 VZ |
36 | |
37 | #if wxUSE_STD_IOSTREAM | |
38 | #if wxUSE_IOSTREAMH | |
39 | #include <fstream.h> | |
40 | #else | |
41 | #include <fstream> | |
42 | #endif | |
43 | #endif | |
e9576ca5 | 44 | |
e9576ca5 | 45 | #include "wx/filefn.h" |
823c4e96 | 46 | #include "wx/sysopt.h" |
e9576ca5 SC |
47 | |
48 | #if defined(__BORLANDC__) && !defined(__WIN32__) | |
670f9935 | 49 | #include <alloc.h> |
f5c6eb5c | 50 | #elif !defined(__MWERKS__) && !defined(__GNUWIN32) && !defined(__DARWIN__) |
670f9935 | 51 | #include <malloc.h> |
e9576ca5 SC |
52 | #endif |
53 | ||
66a09d47 SC |
54 | #ifndef __DARWIN__ |
55 | #include <Scrap.h> | |
1b2b1638 | 56 | #endif |
3556e470 | 57 | |
fef981b4 DS |
58 | #ifndef __DARWIN__ |
59 | #include <MacTextEditor.h> | |
60 | #include <ATSUnicode.h> | |
61 | #include <TextCommon.h> | |
62 | #include <TextEncodingConverter.h> | |
63 | #endif | |
64 | ||
65 | #include "wx/mac/uma.h" | |
66 | ||
0f7817ab | 67 | #ifndef __WXMAC_OSX__ |
3dee36ae | 68 | enum |
0f7817ab | 69 | { |
c88b7d28 | 70 | kTXNVisibilityTag = 'visb' // set the visibility state of the object |
0f7817ab SC |
71 | }; |
72 | #endif | |
73 | ||
72055702 | 74 | |
5ca0d812 | 75 | class wxMacFunctor |
587bc950 | 76 | { |
7d8268a1 | 77 | public : |
a8d2fb31 | 78 | wxMacFunctor() {} |
5ca0d812 | 79 | virtual ~wxMacFunctor() {} |
fef981b4 | 80 | |
5ca0d812 | 81 | virtual void* operator()() = 0 ; |
fef981b4 | 82 | |
c88b7d28 | 83 | static void* CallBackProc( void *param ) |
587bc950 | 84 | { |
5ca0d812 SC |
85 | wxMacFunctor* f = (wxMacFunctor*) param ; |
86 | void *result = (*f)() ; | |
87 | return result ; | |
587bc950 | 88 | } |
5ca0d812 | 89 | } ; |
587bc950 | 90 | |
fef981b4 DS |
91 | template<typename classtype, typename param1type> |
92 | ||
5ca0d812 | 93 | class wxMacObjectFunctor1 : public wxMacFunctor |
587bc950 | 94 | { |
5ca0d812 SC |
95 | typedef void (classtype::*function)( param1type p1 ) ; |
96 | typedef void (classtype::*ref_function)( const param1type& p1 ) ; | |
7d8268a1 | 97 | public : |
5ca0d812 | 98 | wxMacObjectFunctor1( classtype *obj , function f , param1type p1 ) : |
fef981b4 | 99 | wxMacFunctor() |
587bc950 | 100 | { |
5ca0d812 SC |
101 | m_object = obj ; |
102 | m_function = f ; | |
103 | m_param1 = p1 ; | |
587bc950 | 104 | } |
587bc950 | 105 | |
5ca0d812 | 106 | wxMacObjectFunctor1( classtype *obj , ref_function f , param1type p1 ) : |
fef981b4 | 107 | wxMacFunctor() |
5ca0d812 SC |
108 | { |
109 | m_object = obj ; | |
110 | m_refFunction = f ; | |
111 | m_param1 = p1 ; | |
112 | } | |
587bc950 | 113 | |
d3c7fc99 | 114 | virtual ~wxMacObjectFunctor1() {} |
7d8268a1 WS |
115 | |
116 | virtual void* operator()() | |
587bc950 | 117 | { |
c88b7d28 | 118 | (m_object->*m_function)( m_param1 ) ; |
5ca0d812 SC |
119 | return NULL ; |
120 | } | |
a8d2fb31 | 121 | |
5ca0d812 SC |
122 | private : |
123 | classtype* m_object ; | |
124 | param1type m_param1 ; | |
125 | union | |
126 | { | |
fef981b4 DS |
127 | function m_function ; |
128 | ref_function m_refFunction ; | |
587bc950 | 129 | } ; |
5ca0d812 | 130 | } ; |
587bc950 | 131 | |
7d8268a1 | 132 | template<typename classtype, typename param1type> |
5ca0d812 SC |
133 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
134 | { | |
fef981b4 | 135 | wxMacObjectFunctor1<classtype, param1type> params(object, function, p1) ; |
7d8268a1 | 136 | void *result = |
fef981b4 | 137 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
5ca0d812 SC |
138 | return result ; |
139 | } | |
587bc950 | 140 | |
7d8268a1 | 141 | template<typename classtype, typename param1type> |
5ca0d812 SC |
142 | void* wxMacMPRemoteCall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
143 | { | |
fef981b4 | 144 | wxMacObjectFunctor1<classtype,param1type> params(object, function, p1) ; |
7d8268a1 | 145 | void *result = |
fef981b4 | 146 | MPRemoteCall( wxMacFunctor::CallBackProc , ¶ms , kMPOwningProcessRemoteContext ) ; |
5ca0d812 | 147 | return result ; |
587bc950 SC |
148 | } |
149 | ||
7d8268a1 | 150 | template<typename classtype, typename param1type> |
5ca0d812 SC |
151 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( param1type p1 ) , param1type p1 ) |
152 | { | |
153 | wxMutexGuiLeave() ; | |
154 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
155 | wxMutexGuiEnter() ; | |
156 | return result ; | |
157 | } | |
29b30405 | 158 | |
7d8268a1 | 159 | template<typename classtype, typename param1type> |
5ca0d812 SC |
160 | void* wxMacMPRemoteGUICall( classtype *object , void (classtype::*function)( const param1type& p1 ) , param1type p1 ) |
161 | { | |
162 | wxMutexGuiLeave() ; | |
163 | void *result = wxMacMPRemoteCall( object , function , p1 ) ; | |
164 | wxMutexGuiEnter() ; | |
165 | return result ; | |
166 | } | |
a8d2fb31 | 167 | |
5ca0d812 SC |
168 | // common interface for all implementations |
169 | class wxMacTextControl : public wxMacControl | |
170 | { | |
171 | public : | |
0f7817ab | 172 | wxMacTextControl( wxTextCtrl *peer ) ; |
d3c7fc99 | 173 | virtual ~wxMacTextControl() ; |
7d8268a1 | 174 | |
5ca0d812 SC |
175 | virtual wxString GetStringValue() const = 0 ; |
176 | virtual void SetStringValue( const wxString &val ) = 0 ; | |
c88b7d28 DS |
177 | virtual void SetSelection( long from, long to ) = 0 ; |
178 | virtual void GetSelection( long* from, long* to ) const = 0 ; | |
179 | virtual void WriteText( const wxString& str ) = 0 ; | |
180 | ||
181 | virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; | |
5ca0d812 SC |
182 | virtual void Copy() ; |
183 | virtual void Cut() ; | |
184 | virtual void Paste() ; | |
185 | virtual bool CanPaste() const ; | |
c88b7d28 | 186 | virtual void SetEditable( bool editable ) ; |
7d8268a1 | 187 | virtual wxTextPos GetLastPosition() const ; |
c88b7d28 DS |
188 | virtual void Replace( long from, long to, const wxString &str ) ; |
189 | virtual void Remove( long from, long to ) ; | |
190 | ||
fef981b4 DS |
191 | |
192 | virtual bool HasOwnContextMenu() const | |
193 | { return false ; } | |
194 | ||
195 | virtual bool SetupCursor( const wxPoint& pt ) | |
196 | { return false ; } | |
9eddec69 | 197 | |
5ca0d812 SC |
198 | virtual void Clear() ; |
199 | virtual bool CanUndo() const; | |
7d8268a1 | 200 | virtual void Undo() ; |
5ca0d812 SC |
201 | virtual bool CanRedo() const; |
202 | virtual void Redo() ; | |
203 | virtual int GetNumberOfLines() const ; | |
204 | virtual long XYToPosition(long x, long y) const; | |
205 | virtual bool PositionToXY(long pos, long *x, long *y) const ; | |
c88b7d28 | 206 | virtual void ShowPosition(long WXUNUSED(pos)) ; |
5ca0d812 SC |
207 | virtual int GetLineLength(long lineNo) const ; |
208 | virtual wxString GetLineText(long lineNo) const ; | |
24260aae SC |
209 | |
210 | #ifndef __WXMAC_OSX__ | |
211 | virtual void MacControlUserPaneDrawProc(wxInt16 part) = 0 ; | |
212 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) = 0 ; | |
213 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) = 0 ; | |
214 | virtual void MacControlUserPaneIdleProc() = 0 ; | |
215 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) = 0 ; | |
216 | virtual void MacControlUserPaneActivateProc(bool activating) = 0 ; | |
217 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) = 0 ; | |
218 | virtual void MacControlUserPaneBackgroundProc(void* info) = 0 ; | |
219 | #endif | |
5ca0d812 | 220 | } ; |
72055702 | 221 | |
5ca0d812 | 222 | // common parts for implementations based on MLTE |
72055702 | 223 | |
5ca0d812 SC |
224 | class wxMacMLTEControl : public wxMacTextControl |
225 | { | |
226 | public : | |
789ae0cf | 227 | wxMacMLTEControl( wxTextCtrl *peer ) ; |
c88b7d28 | 228 | |
5ca0d812 | 229 | virtual wxString GetStringValue() const ; |
c88b7d28 | 230 | virtual void SetStringValue( const wxString &str ) ; |
7d8268a1 | 231 | |
5ca0d812 | 232 | static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ; |
fef981b4 | 233 | |
c88b7d28 | 234 | void AdjustCreationAttributes( const wxColour& background, bool visible ) ; |
5ca0d812 | 235 | |
c88b7d28 DS |
236 | virtual void SetFont( const wxFont & font, const wxColour& foreground, long windowStyle ) ; |
237 | virtual void SetBackground( const wxBrush &brush ) ; | |
238 | virtual void SetStyle( long start, long end, const wxTextAttr& style ) ; | |
5ca0d812 SC |
239 | virtual void Copy() ; |
240 | virtual void Cut() ; | |
241 | virtual void Paste() ; | |
242 | virtual bool CanPaste() const ; | |
c88b7d28 | 243 | virtual void SetEditable( bool editable ) ; |
7d8268a1 | 244 | virtual wxTextPos GetLastPosition() const ; |
c88b7d28 DS |
245 | virtual void Replace( long from, long to, const wxString &str ) ; |
246 | virtual void Remove( long from, long to ) ; | |
247 | virtual void GetSelection( long* from, long* to ) const ; | |
248 | virtual void SetSelection( long from, long to ) ; | |
7d8268a1 | 249 | |
c88b7d28 | 250 | virtual void WriteText( const wxString& str ) ; |
fef981b4 | 251 | |
0207e969 DS |
252 | virtual bool HasOwnContextMenu() const |
253 | { | |
64bd657c SC |
254 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
255 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
256 | { | |
257 | TXNCommandEventSupportOptions options ; | |
258 | TXNGetCommandEventSupport( m_txn , & options ) ; | |
259 | return options & kTXNSupportEditCommandProcessing ; | |
260 | } | |
261 | #endif | |
fef981b4 | 262 | |
64bd657c SC |
263 | return false ; |
264 | } | |
265 | ||
5ca0d812 SC |
266 | virtual void Clear() ; |
267 | ||
268 | virtual bool CanUndo() const ; | |
269 | virtual void Undo() ; | |
270 | virtual bool CanRedo() const; | |
271 | virtual void Redo() ; | |
272 | virtual int GetNumberOfLines() const ; | |
273 | virtual long XYToPosition(long x, long y) const ; | |
274 | virtual bool PositionToXY(long pos, long *x, long *y) const ; | |
275 | virtual void ShowPosition( long pos ) ; | |
276 | virtual int GetLineLength(long lineNo) const ; | |
277 | virtual wxString GetLineText(long lineNo) const ; | |
278 | ||
279 | void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ; | |
09660720 | 280 | TXNObject GetTXNObject() { return m_txn ; } |
5ca0d812 SC |
281 | |
282 | protected : | |
8623a883 | 283 | void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ; |
fef981b4 | 284 | |
5ca0d812 SC |
285 | TXNObject m_txn ; |
286 | } ; | |
72055702 | 287 | |
5ca0d812 | 288 | #if TARGET_API_MAC_OSX |
72055702 | 289 | |
5ca0d812 SC |
290 | // implementation available under OSX |
291 | ||
788e118f SC |
292 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
293 | ||
7d8268a1 | 294 | class wxMacMLTEHIViewControl : public wxMacMLTEControl |
5ca0d812 SC |
295 | { |
296 | public : | |
0f7817ab | 297 | wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
298 | const wxString& str, |
299 | const wxPoint& pos, | |
300 | const wxSize& size, long style ) ; | |
d3c7fc99 | 301 | virtual ~wxMacMLTEHIViewControl() ; |
9eddec69 | 302 | |
5ca0d812 SC |
303 | virtual OSStatus SetFocus( ControlFocusPart focusPart ) ; |
304 | virtual bool HasFocus() const ; | |
44aa865d | 305 | virtual void SetBackground( const wxBrush &brush) ; |
a8d2fb31 | 306 | |
5ca0d812 SC |
307 | protected : |
308 | HIViewRef m_scrollView ; | |
309 | HIViewRef m_textView ; | |
09660720 | 310 | EventHandlerRef m_textEventHandlerRef ; |
fef981b4 | 311 | }; |
ef4a634b | 312 | |
788e118f SC |
313 | #endif |
314 | ||
5ca0d812 SC |
315 | class wxMacUnicodeTextControl : public wxMacTextControl |
316 | { | |
317 | public : | |
0f7817ab | 318 | wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
319 | const wxString& str, |
320 | const wxPoint& pos, | |
321 | const wxSize& size, long style ) ; | |
d3c7fc99 | 322 | virtual ~wxMacUnicodeTextControl(); |
fef981b4 | 323 | |
5ca0d812 SC |
324 | virtual void VisibilityChanged(bool shown); |
325 | virtual wxString GetStringValue() const ; | |
326 | virtual void SetStringValue( const wxString &str) ; | |
327 | virtual void Copy(); | |
328 | virtual void Cut(); | |
329 | virtual void Paste(); | |
330 | virtual bool CanPaste() const; | |
331 | virtual void SetEditable(bool editable) ; | |
5ca0d812 SC |
332 | virtual void GetSelection( long* from, long* to) const ; |
333 | virtual void SetSelection( long from , long to ) ; | |
334 | virtual void WriteText(const wxString& str) ; | |
a8d2fb31 | 335 | |
5ca0d812 SC |
336 | protected : |
337 | // contains the tag for the content (is different for password and non-password controls) | |
338 | OSType m_valueTag ; | |
ad604d0f SC |
339 | |
340 | // as the selection tag only works correctly when the control has the focus we have to mirror the | |
341 | // intended value | |
342 | EventHandlerRef m_focusHandlerRef ; | |
343 | public : | |
344 | ControlEditTextSelectionRec m_selection ; | |
fef981b4 | 345 | }; |
72055702 | 346 | |
3556e470 | 347 | #endif |
72055702 | 348 | |
24260aae | 349 | // 'classic' MLTE implementation |
72055702 | 350 | |
5ca0d812 SC |
351 | class wxMacMLTEClassicControl : public wxMacMLTEControl |
352 | { | |
353 | public : | |
0f7817ab | 354 | wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
5ca0d812 SC |
355 | const wxString& str, |
356 | const wxPoint& pos, | |
357 | const wxSize& size, long style ) ; | |
d3c7fc99 | 358 | virtual ~wxMacMLTEClassicControl() ; |
ffafe6ca | 359 | |
5ca0d812 | 360 | virtual void VisibilityChanged(bool shown) ; |
4e477040 | 361 | virtual void SuperChangedPosition() ; |
24260aae SC |
362 | |
363 | virtual void MacControlUserPaneDrawProc(wxInt16 part) ; | |
364 | virtual wxInt16 MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) ; | |
365 | virtual wxInt16 MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) ; | |
366 | virtual void MacControlUserPaneIdleProc() ; | |
367 | virtual wxInt16 MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) ; | |
368 | virtual void MacControlUserPaneActivateProc(bool activating) ; | |
369 | virtual wxInt16 MacControlUserPaneFocusProc(wxInt16 action) ; | |
370 | virtual void MacControlUserPaneBackgroundProc(void* info) ; | |
371 | ||
ffafe6ca DS |
372 | virtual bool SetupCursor( const wxPoint& WXUNUSED(pt) ) |
373 | { | |
374 | MacControlUserPaneIdleProc(); | |
375 | return true; | |
376 | } | |
f2c3f2a8 | 377 | |
0f7817ab SC |
378 | virtual void SetRect( Rect *r ) ; |
379 | ||
5ca0d812 SC |
380 | protected : |
381 | OSStatus DoCreate(); | |
3dee36ae | 382 | |
0f7817ab | 383 | void MacUpdatePosition() ; |
fef981b4 DS |
384 | void MacActivatePaneText(bool setActive) ; |
385 | void MacFocusPaneText(bool setFocus) ; | |
386 | void MacSetObjectVisibility(bool vis) ; | |
a8d2fb31 | 387 | |
0f7817ab SC |
388 | private : |
389 | TXNFrameID m_txnFrameID ; | |
390 | GrafPtr m_txnPort ; | |
5de694f0 | 391 | WindowRef m_txnWindow ; |
0f7817ab SC |
392 | // bounds of the control as we last did set the txn frames |
393 | Rect m_txnControlBounds ; | |
ba75e603 | 394 | Rect m_txnVisBounds ; |
fef981b4 | 395 | |
4e477040 | 396 | #ifdef __WXMAC_OSX__ |
fef981b4 DS |
397 | static pascal void TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) ; |
398 | static pascal void TXNScrollInfoProc( | |
399 | SInt32 iValue, SInt32 iMaximumValue, | |
400 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) ; | |
401 | ||
4e477040 | 402 | ControlRef m_sbHorizontal ; |
5de694f0 | 403 | SInt32 m_lastHorizontalValue ; |
4e477040 | 404 | ControlRef m_sbVertical ; |
5de694f0 | 405 | SInt32 m_lastVerticalValue ; |
4e477040 | 406 | #endif |
fef981b4 | 407 | }; |
facd6764 | 408 | |
fef981b4 | 409 | |
9d112688 | 410 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) |
72055702 | 411 | |
9d112688 | 412 | BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) |
7ea087b7 | 413 | EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground ) |
5ca0d812 SC |
414 | EVT_DROP_FILES(wxTextCtrl::OnDropFiles) |
415 | EVT_CHAR(wxTextCtrl::OnChar) | |
416 | EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) | |
417 | EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy) | |
418 | EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste) | |
419 | EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo) | |
420 | EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo) | |
24eef584 SC |
421 | EVT_MENU(wxID_CLEAR, wxTextCtrl::OnDelete) |
422 | EVT_MENU(wxID_SELECTALL, wxTextCtrl::OnSelectAll) | |
423 | ||
424 | EVT_CONTEXT_MENU(wxTextCtrl::OnContextMenu) | |
5ca0d812 SC |
425 | |
426 | EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut) | |
427 | EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy) | |
428 | EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste) | |
429 | EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo) | |
430 | EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo) | |
24eef584 SC |
431 | EVT_UPDATE_UI(wxID_CLEAR, wxTextCtrl::OnUpdateDelete) |
432 | EVT_UPDATE_UI(wxID_SELECTALL, wxTextCtrl::OnUpdateSelectAll) | |
5ca0d812 | 433 | END_EVENT_TABLE() |
5ca0d812 | 434 | |
fef981b4 | 435 | |
a8d2fb31 | 436 | void wxTextCtrl::Init() |
facd6764 | 437 | { |
24eef584 SC |
438 | m_editable = true ; |
439 | m_dirty = false; | |
5ca0d812 | 440 | |
b9bae707 | 441 | m_maxLength = 0; |
c88b7d28 | 442 | m_privateContextMenu = NULL; |
51478cd6 | 443 | m_triggerOnSetValue = true ; |
facd6764 SC |
444 | } |
445 | ||
5ca0d812 | 446 | wxTextCtrl::~wxTextCtrl() |
facd6764 | 447 | { |
24eef584 | 448 | delete m_privateContextMenu; |
facd6764 SC |
449 | } |
450 | ||
ffafe6ca | 451 | bool wxTextCtrl::Create( wxWindow *parent, |
c88b7d28 DS |
452 | wxWindowID id, |
453 | const wxString& str, | |
454 | const wxPoint& pos, | |
455 | const wxSize& size, | |
456 | long style, | |
457 | const wxValidator& validator, | |
ffafe6ca | 458 | const wxString& name ) |
5ca0d812 | 459 | { |
7d8268a1 | 460 | m_macIsUserPane = false ; |
5ca0d812 SC |
461 | m_editable = true ; |
462 | ||
c88b7d28 DS |
463 | if ( ! (style & wxNO_BORDER) ) |
464 | style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; | |
7d8268a1 | 465 | |
ffafe6ca | 466 | if ( !wxTextCtrlBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) |
7d8268a1 | 467 | return false; |
ef4a634b | 468 | |
5ca0d812 | 469 | if ( m_windowStyle & wxTE_MULTILINE ) |
facd6764 | 470 | { |
9e15c718 | 471 | // always turn on this style for multi-line controls |
5ca0d812 SC |
472 | m_windowStyle |= wxTE_PROCESS_ENTER; |
473 | style |= wxTE_PROCESS_ENTER ; | |
ed8c2780 | 474 | } |
3556e470 | 475 | |
4d7528a1 | 476 | bool forceMLTE = false ; |
fef981b4 | 477 | |
823c4e96 | 478 | #if wxUSE_SYSTEM_OPTIONS |
ffafe6ca | 479 | if (wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_MLTE ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_MLTE ) == 1)) |
823c4e96 | 480 | { |
4d7528a1 | 481 | forceMLTE = true ; |
823c4e96 SC |
482 | } |
483 | #endif | |
4f74e0d1 SC |
484 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 |
485 | forceMLTE = false; | |
486 | #endif | |
4d7528a1 SC |
487 | |
488 | #ifdef __WXMAC_OSX__ | |
489 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
c88b7d28 | 490 | if ( UMAGetSystemVersion() >= 0x1030 && !forceMLTE ) |
788e118f | 491 | { |
4d7528a1 SC |
492 | if ( m_windowStyle & wxTE_MULTILINE ) |
493 | m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; | |
788e118f | 494 | } |
788e118f | 495 | #endif |
fef981b4 | 496 | |
3556e470 | 497 | if ( !m_peer ) |
7d8268a1 | 498 | { |
4f74e0d1 | 499 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 |
c88b7d28 | 500 | if ( !(m_windowStyle & wxTE_MULTILINE) && !forceMLTE ) |
4f74e0d1 SC |
501 | #endif |
502 | { | |
4d7528a1 | 503 | m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; |
4f74e0d1 | 504 | } |
788e118f | 505 | } |
3556e470 | 506 | #endif |
fef981b4 | 507 | |
4f74e0d1 SC |
508 | // the horizontal single line scrolling bug that made us keep |
509 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 | |
3556e470 | 510 | if ( !m_peer ) |
3556e470 | 511 | m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; |
4f74e0d1 | 512 | #endif |
788e118f | 513 | |
c88b7d28 | 514 | MacPostControlCreate(pos, size) ; |
72055702 | 515 | |
807c0706 SC |
516 | // only now the embedding is correct and we can do a positioning update |
517 | ||
518 | MacSuperChangedPosition() ; | |
519 | ||
5ca0d812 | 520 | if ( m_windowStyle & wxTE_READONLY) |
5ca0d812 | 521 | SetEditable( false ) ; |
3dee36ae | 522 | |
f2c3f2a8 | 523 | SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ; |
72055702 | 524 | |
7d8268a1 | 525 | return true; |
facd6764 SC |
526 | } |
527 | ||
3dee36ae | 528 | void wxTextCtrl::MacSuperChangedPosition() |
4e477040 SC |
529 | { |
530 | wxWindow::MacSuperChangedPosition() ; | |
531 | GetPeer()->SuperChangedPosition() ; | |
532 | } | |
533 | ||
7d8268a1 | 534 | void wxTextCtrl::MacVisibilityChanged() |
5ca0d812 SC |
535 | { |
536 | GetPeer()->VisibilityChanged( MacIsReallyShown() ) ; | |
537 | } | |
facd6764 | 538 | |
7d8268a1 | 539 | void wxTextCtrl::MacEnabledStateChanged() |
5ca0d812 | 540 | { |
72055702 SC |
541 | } |
542 | ||
5ca0d812 SC |
543 | wxString wxTextCtrl::GetValue() const |
544 | { | |
545 | return GetPeer()->GetStringValue() ; | |
546 | } | |
ef4a634b | 547 | |
5ca0d812 | 548 | void wxTextCtrl::GetSelection(long* from, long* to) const |
7d8268a1 | 549 | { |
5ca0d812 SC |
550 | GetPeer()->GetSelection( from , to ) ; |
551 | } | |
552 | ||
ee2ec18e | 553 | void wxTextCtrl::DoSetValue(const wxString& str, int flags) |
5ca0d812 SC |
554 | { |
555 | // optimize redraws | |
556 | if ( GetValue() == str ) | |
ee2ec18e | 557 | return; |
facd6764 | 558 | |
c88b7d28 | 559 | GetPeer()->SetStringValue( str ) ; |
e8b4fd4b | 560 | |
ee2ec18e | 561 | if ( (flags & SetValue_SendEvent) && m_triggerOnSetValue ) |
51478cd6 | 562 | { |
ee2ec18e | 563 | SendTextUpdatedEvent(); |
51478cd6 | 564 | } |
72055702 SC |
565 | } |
566 | ||
5ca0d812 SC |
567 | void wxTextCtrl::SetMaxLength(unsigned long len) |
568 | { | |
569 | m_maxLength = len ; | |
570 | } | |
72055702 | 571 | |
5ca0d812 SC |
572 | bool wxTextCtrl::SetFont( const wxFont& font ) |
573 | { | |
574 | if ( !wxTextCtrlBase::SetFont( font ) ) | |
7d8268a1 WS |
575 | return false ; |
576 | ||
5ca0d812 | 577 | GetPeer()->SetFont( font , GetForegroundColour() , GetWindowStyle() ) ; |
fef981b4 | 578 | |
5ca0d812 SC |
579 | return true ; |
580 | } | |
581 | ||
582 | bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style) | |
583 | { | |
584 | GetPeer()->SetStyle( start , end , style ) ; | |
fef981b4 | 585 | |
5ca0d812 SC |
586 | return true ; |
587 | } | |
588 | ||
589 | bool wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) | |
590 | { | |
591 | wxTextCtrlBase::SetDefaultStyle( style ) ; | |
592 | SetStyle( kTXNUseCurrentSelection , kTXNUseCurrentSelection , GetDefaultStyle() ) ; | |
fef981b4 | 593 | |
7d8268a1 | 594 | return true ; |
5ca0d812 SC |
595 | } |
596 | ||
597 | // Clipboard operations | |
fef981b4 | 598 | |
5ca0d812 SC |
599 | void wxTextCtrl::Copy() |
600 | { | |
601 | if (CanCopy()) | |
7d8268a1 | 602 | GetPeer()->Copy() ; |
72055702 SC |
603 | } |
604 | ||
5ca0d812 SC |
605 | void wxTextCtrl::Cut() |
606 | { | |
607 | if (CanCut()) | |
608 | { | |
7d8268a1 | 609 | GetPeer()->Cut() ; |
72055702 | 610 | |
c88b7d28 | 611 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); |
5ca0d812 | 612 | event.SetEventObject( this ); |
c88b7d28 | 613 | GetEventHandler()->ProcessEvent( event ); |
5ca0d812 SC |
614 | } |
615 | } | |
72055702 | 616 | |
5ca0d812 SC |
617 | void wxTextCtrl::Paste() |
618 | { | |
619 | if (CanPaste()) | |
620 | { | |
7d8268a1 | 621 | GetPeer()->Paste() ; |
fef981b4 DS |
622 | |
623 | // TODO: eventually we should add setting the default style again | |
72055702 | 624 | |
c88b7d28 | 625 | wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, m_windowId ); |
5ca0d812 | 626 | event.SetEventObject( this ); |
c88b7d28 | 627 | GetEventHandler()->ProcessEvent( event ); |
5ca0d812 SC |
628 | } |
629 | } | |
72055702 | 630 | |
5ca0d812 SC |
631 | bool wxTextCtrl::CanCopy() const |
632 | { | |
633 | // Can copy if there's a selection | |
634 | long from, to; | |
c88b7d28 | 635 | GetSelection( &from, &to ); |
ffafe6ca | 636 | |
5ca0d812 SC |
637 | return (from != to); |
638 | } | |
ef4a634b | 639 | |
5ca0d812 SC |
640 | bool wxTextCtrl::CanCut() const |
641 | { | |
642 | if ( !IsEditable() ) | |
c88b7d28 | 643 | return false; |
a8d2fb31 | 644 | |
5ca0d812 SC |
645 | // Can cut if there's a selection |
646 | long from, to; | |
c88b7d28 | 647 | GetSelection( &from, &to ); |
ffafe6ca | 648 | |
5ca0d812 | 649 | return (from != to); |
72055702 SC |
650 | } |
651 | ||
5ca0d812 SC |
652 | bool wxTextCtrl::CanPaste() const |
653 | { | |
654 | if (!IsEditable()) | |
7d8268a1 | 655 | return false; |
72055702 | 656 | |
5ca0d812 SC |
657 | return GetPeer()->CanPaste() ; |
658 | } | |
facd6764 | 659 | |
5ca0d812 SC |
660 | void wxTextCtrl::SetEditable(bool editable) |
661 | { | |
662 | if ( editable != m_editable ) | |
663 | { | |
664 | m_editable = editable ; | |
665 | GetPeer()->SetEditable( editable ) ; | |
ed8c2780 | 666 | } |
72055702 SC |
667 | } |
668 | ||
5ca0d812 SC |
669 | void wxTextCtrl::SetInsertionPoint(long pos) |
670 | { | |
671 | SetSelection( pos , pos ) ; | |
672 | } | |
72055702 | 673 | |
5ca0d812 SC |
674 | void wxTextCtrl::SetInsertionPointEnd() |
675 | { | |
7d8268a1 | 676 | wxTextPos pos = GetLastPosition(); |
ffafe6ca | 677 | SetInsertionPoint( pos ); |
5ca0d812 | 678 | } |
facd6764 | 679 | |
5ca0d812 SC |
680 | long wxTextCtrl::GetInsertionPoint() const |
681 | { | |
ffafe6ca | 682 | long begin, end ; |
5ca0d812 | 683 | GetSelection( &begin , &end ) ; |
ffafe6ca | 684 | |
5ca0d812 SC |
685 | return begin ; |
686 | } | |
facd6764 | 687 | |
7d8268a1 | 688 | wxTextPos wxTextCtrl::GetLastPosition() const |
5ca0d812 | 689 | { |
c88b7d28 | 690 | return GetPeer()->GetLastPosition() ; |
72055702 SC |
691 | } |
692 | ||
5ca0d812 SC |
693 | void wxTextCtrl::Replace(long from, long to, const wxString& str) |
694 | { | |
ffafe6ca | 695 | GetPeer()->Replace( from , to , str ) ; |
5ca0d812 | 696 | } |
72055702 | 697 | |
5ca0d812 SC |
698 | void wxTextCtrl::Remove(long from, long to) |
699 | { | |
700 | GetPeer()->Remove( from , to ) ; | |
701 | } | |
facd6764 | 702 | |
5ca0d812 SC |
703 | void wxTextCtrl::SetSelection(long from, long to) |
704 | { | |
705 | GetPeer()->SetSelection( from , to ) ; | |
706 | } | |
707 | ||
5ca0d812 SC |
708 | void wxTextCtrl::WriteText(const wxString& str) |
709 | { | |
fef981b4 | 710 | // TODO: this MPRemoting will be moved into a remoting peer proxy for any command |
5ca0d812 SC |
711 | if ( !wxIsMainThread() ) |
712 | { | |
fef981b4 DS |
713 | // unfortunately CW 8 is not able to correctly deduce the template types, |
714 | // so we have to instantiate explicitly | |
5ca0d812 | 715 | wxMacMPRemoteGUICall<wxTextCtrl,wxString>( this , &wxTextCtrl::WriteText , str ) ; |
ffafe6ca | 716 | |
5ca0d812 SC |
717 | return ; |
718 | } | |
ffafe6ca DS |
719 | |
720 | GetPeer()->WriteText( str ) ; | |
5ca0d812 | 721 | } |
72055702 | 722 | |
5ca0d812 SC |
723 | void wxTextCtrl::AppendText(const wxString& text) |
724 | { | |
725 | SetInsertionPointEnd(); | |
ffafe6ca | 726 | WriteText( text ); |
5ca0d812 | 727 | } |
facd6764 | 728 | |
5ca0d812 SC |
729 | void wxTextCtrl::Clear() |
730 | { | |
731 | GetPeer()->Clear() ; | |
732 | } | |
facd6764 | 733 | |
5ca0d812 SC |
734 | bool wxTextCtrl::IsModified() const |
735 | { | |
736 | return m_dirty; | |
737 | } | |
facd6764 | 738 | |
5ca0d812 SC |
739 | bool wxTextCtrl::IsEditable() const |
740 | { | |
741 | return IsEnabled() && m_editable ; | |
72055702 SC |
742 | } |
743 | ||
5ca0d812 SC |
744 | bool wxTextCtrl::AcceptsFocus() const |
745 | { | |
746 | // we don't want focus if we can't be edited | |
747 | return /*IsEditable() && */ wxControl::AcceptsFocus(); | |
748 | } | |
72055702 | 749 | |
5ca0d812 | 750 | wxSize wxTextCtrl::DoGetBestSize() const |
1b2b1638 | 751 | { |
c88b7d28 | 752 | int wText, hText; |
ef4a634b | 753 | |
a8d2fb31 DS |
754 | // these are the numbers from the HIG: |
755 | // we reduce them by the borders first | |
c88b7d28 | 756 | wText = 100 ; |
72463754 | 757 | |
fef981b4 | 758 | switch ( m_windowVariant ) |
5ca0d812 SC |
759 | { |
760 | case wxWINDOW_VARIANT_NORMAL : | |
72463754 | 761 | hText = 22 - 6 ; |
5ca0d812 | 762 | break ; |
a8d2fb31 | 763 | |
5ca0d812 | 764 | case wxWINDOW_VARIANT_SMALL : |
72463754 | 765 | hText = 19 - 6 ; |
5ca0d812 | 766 | break ; |
a8d2fb31 | 767 | |
5ca0d812 | 768 | case wxWINDOW_VARIANT_MINI : |
c88b7d28 | 769 | hText = 15 - 6 ; |
5ca0d812 | 770 | break ; |
a8d2fb31 | 771 | |
5ca0d812 | 772 | default : |
72463754 | 773 | hText = 22 - 6; |
7d8268a1 | 774 | break ; |
5ca0d812 | 775 | } |
72055702 | 776 | |
72463754 SC |
777 | // as the above numbers have some free space around the text |
778 | // we get 5 lines like this anyway | |
5ca0d812 | 779 | if ( m_windowStyle & wxTE_MULTILINE ) |
5ca0d812 | 780 | hText *= 5 ; |
ef4a634b | 781 | |
72463754 SC |
782 | if ( !HasFlag(wxNO_BORDER) ) |
783 | hText += 6 ; | |
784 | ||
5ca0d812 SC |
785 | return wxSize(wText, hText); |
786 | } | |
ef4a634b | 787 | |
5ca0d812 SC |
788 | // ---------------------------------------------------------------------------- |
789 | // Undo/redo | |
790 | // ---------------------------------------------------------------------------- | |
facd6764 | 791 | |
5ca0d812 SC |
792 | void wxTextCtrl::Undo() |
793 | { | |
794 | if (CanUndo()) | |
5ca0d812 | 795 | GetPeer()->Undo() ; |
72055702 SC |
796 | } |
797 | ||
5ca0d812 | 798 | void wxTextCtrl::Redo() |
587bc950 | 799 | { |
5ca0d812 | 800 | if (CanRedo()) |
5ca0d812 | 801 | GetPeer()->Redo() ; |
5ca0d812 | 802 | } |
1b2b1638 | 803 | |
5ca0d812 SC |
804 | bool wxTextCtrl::CanUndo() const |
805 | { | |
7d8268a1 | 806 | if ( !IsEditable() ) |
7d8268a1 | 807 | return false ; |
a8d2fb31 | 808 | |
5ca0d812 SC |
809 | return GetPeer()->CanUndo() ; |
810 | } | |
72055702 | 811 | |
5ca0d812 | 812 | bool wxTextCtrl::CanRedo() const |
6bdd4f5d | 813 | { |
7d8268a1 | 814 | if ( !IsEditable() ) |
7d8268a1 | 815 | return false ; |
a8d2fb31 | 816 | |
5ca0d812 | 817 | return GetPeer()->CanRedo() ; |
6bdd4f5d SC |
818 | } |
819 | ||
5ca0d812 SC |
820 | void wxTextCtrl::MarkDirty() |
821 | { | |
822 | m_dirty = true; | |
823 | } | |
587bc950 | 824 | |
5ca0d812 SC |
825 | void wxTextCtrl::DiscardEdits() |
826 | { | |
827 | m_dirty = false; | |
828 | } | |
587bc950 | 829 | |
5ca0d812 SC |
830 | int wxTextCtrl::GetNumberOfLines() const |
831 | { | |
832 | return GetPeer()->GetNumberOfLines() ; | |
833 | } | |
587bc950 | 834 | |
5ca0d812 SC |
835 | long wxTextCtrl::XYToPosition(long x, long y) const |
836 | { | |
837 | return GetPeer()->XYToPosition( x , y ) ; | |
838 | } | |
587bc950 | 839 | |
5ca0d812 | 840 | bool wxTextCtrl::PositionToXY(long pos, long *x, long *y) const |
72055702 | 841 | { |
ffafe6ca | 842 | return GetPeer()->PositionToXY( pos , x , y ) ; |
5ca0d812 | 843 | } |
1fa29bdc | 844 | |
5ca0d812 SC |
845 | void wxTextCtrl::ShowPosition(long pos) |
846 | { | |
847 | return GetPeer()->ShowPosition(pos) ; | |
848 | } | |
1fa29bdc | 849 | |
5ca0d812 SC |
850 | int wxTextCtrl::GetLineLength(long lineNo) const |
851 | { | |
852 | return GetPeer()->GetLineLength(lineNo) ; | |
1b2b1638 SC |
853 | } |
854 | ||
5ca0d812 | 855 | wxString wxTextCtrl::GetLineText(long lineNo) const |
1b2b1638 | 856 | { |
5ca0d812 | 857 | return GetPeer()->GetLineText(lineNo) ; |
72055702 SC |
858 | } |
859 | ||
5ca0d812 | 860 | void wxTextCtrl::Command(wxCommandEvent & event) |
72055702 | 861 | { |
c88b7d28 DS |
862 | SetValue(event.GetString()); |
863 | ProcessCommand(event); | |
5ca0d812 | 864 | } |
72055702 | 865 | |
5ca0d812 SC |
866 | void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) |
867 | { | |
868 | // By default, load the first file into the text window. | |
869 | if (event.GetNumberOfFiles() > 0) | |
ffafe6ca | 870 | LoadFile( event.GetFiles()[0] ); |
5ca0d812 | 871 | } |
ef4a634b | 872 | |
7ea087b7 SC |
873 | void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) |
874 | { | |
875 | // all erasing should be done by the real mac control implementation | |
876 | // while this is true for MLTE under classic, the HITextView is somehow | |
877 | // transparent but background erase is not working correctly, so intercept | |
878 | // things while we can... | |
395480fb | 879 | event.Skip() ; |
7ea087b7 SC |
880 | } |
881 | ||
5ca0d812 SC |
882 | void wxTextCtrl::OnChar(wxKeyEvent& event) |
883 | { | |
884 | int key = event.GetKeyCode() ; | |
885 | bool eat_key = false ; | |
72055702 | 886 | |
c4d9fc39 SC |
887 | if ( key == 'a' && event.MetaDown() ) |
888 | { | |
88a7a4e1 WS |
889 | SelectAll() ; |
890 | ||
c4d9fc39 SC |
891 | return ; |
892 | } | |
893 | ||
5ca0d812 | 894 | if ( key == 'c' && event.MetaDown() ) |
72055702 | 895 | { |
5ca0d812 SC |
896 | if ( CanCopy() ) |
897 | Copy() ; | |
fef981b4 | 898 | |
5ca0d812 | 899 | return ; |
72055702 SC |
900 | } |
901 | ||
5ca0d812 | 902 | if ( !IsEditable() && key != WXK_LEFT && key != WXK_RIGHT && key != WXK_DOWN && key != WXK_UP && key != WXK_TAB && |
8e13c1ec | 903 | !( key == WXK_RETURN && ( (m_windowStyle & wxTE_PROCESS_ENTER) || (m_windowStyle & wxTE_MULTILINE) ) ) |
faa94f3e | 904 | // && key != WXK_PAGEUP && key != WXK_PAGEDOWN && key != WXK_HOME && key != WXK_END |
5ca0d812 | 905 | ) |
29e4a190 | 906 | { |
5ca0d812 SC |
907 | // eat it |
908 | return ; | |
909 | } | |
d3016f30 | 910 | |
b9bae707 VZ |
911 | // Check if we have reached the max # of chars (if it is set), but still |
912 | // allow navigation and deletion | |
faa94f3e | 913 | if ( !IsMultiLine() && m_maxLength && GetValue().length() >= m_maxLength && |
bdf0c19c | 914 | key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB && |
8e13c1ec | 915 | key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxTE_PROCESS_ENTER) ) |
bdf0c19c KH |
916 | ) |
917 | { | |
918 | // eat it, we don't want to add more than allowed # of characters | |
b9bae707 VZ |
919 | |
920 | // TODO: generate EVT_TEXT_MAXLEN() | |
bdf0c19c KH |
921 | return; |
922 | } | |
923 | ||
5ca0d812 SC |
924 | // assume that any key not processed yet is going to modify the control |
925 | m_dirty = true; | |
587bc950 | 926 | |
5ca0d812 SC |
927 | if ( key == 'v' && event.MetaDown() ) |
928 | { | |
929 | if ( CanPaste() ) | |
930 | Paste() ; | |
0207e969 | 931 | |
5ca0d812 | 932 | return ; |
29e4a190 | 933 | } |
fef981b4 | 934 | |
5ca0d812 | 935 | if ( key == 'x' && event.MetaDown() ) |
ed8c2780 | 936 | { |
5ca0d812 SC |
937 | if ( CanCut() ) |
938 | Cut() ; | |
fef981b4 | 939 | |
5ca0d812 | 940 | return ; |
1b2b1638 | 941 | } |
a8d2fb31 | 942 | |
5ca0d812 SC |
943 | switch ( key ) |
944 | { | |
945 | case WXK_RETURN: | |
8e13c1ec | 946 | if (m_windowStyle & wxTE_PROCESS_ENTER) |
5ca0d812 SC |
947 | { |
948 | wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); | |
949 | event.SetEventObject( this ); | |
950 | event.SetString( GetValue() ); | |
951 | if ( GetEventHandler()->ProcessEvent(event) ) | |
952 | return; | |
953 | } | |
fef981b4 | 954 | |
5ca0d812 SC |
955 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
956 | { | |
6c20e8f8 VZ |
957 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); |
958 | if ( tlw && tlw->GetDefaultItem() ) | |
fef981b4 | 959 | { |
6c20e8f8 | 960 | wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); |
5ca0d812 SC |
961 | if ( def && def->IsEnabled() ) |
962 | { | |
963 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
964 | event.SetEventObject(def); | |
965 | def->Command(event); | |
fef981b4 | 966 | |
5ca0d812 | 967 | return ; |
3dee36ae | 968 | } |
5ca0d812 SC |
969 | } |
970 | ||
971 | // this will make wxWidgets eat the ENTER key so that | |
0207e969 | 972 | // we actually prevent line wrapping in a single line text control |
7d8268a1 | 973 | eat_key = true; |
5ca0d812 | 974 | } |
5ca0d812 | 975 | break; |
facd6764 | 976 | |
5ca0d812 SC |
977 | case WXK_TAB: |
978 | if ( !(m_windowStyle & wxTE_PROCESS_TAB)) | |
979 | { | |
980 | int flags = 0; | |
981 | if (!event.ShiftDown()) | |
982 | flags |= wxNavigationKeyEvent::IsForward ; | |
983 | if (event.ControlDown()) | |
984 | flags |= wxNavigationKeyEvent::WinChange ; | |
985 | Navigate(flags); | |
fef981b4 | 986 | |
5ca0d812 SC |
987 | return; |
988 | } | |
989 | else | |
990 | { | |
fef981b4 DS |
991 | // This is necessary (don't know why); |
992 | // otherwise the tab will not be inserted. | |
5ca0d812 | 993 | WriteText(wxT("\t")); |
4e6cc020 | 994 | eat_key = true; |
5ca0d812 | 995 | } |
a8d2fb31 | 996 | break; |
7d8268a1 | 997 | |
a8d2fb31 | 998 | default: |
5ca0d812 SC |
999 | break; |
1000 | } | |
facd6764 | 1001 | |
5ca0d812 | 1002 | if (!eat_key) |
7f1de2b2 | 1003 | { |
5ca0d812 | 1004 | // perform keystroke handling |
665b537f | 1005 | event.Skip(true) ; |
7f1de2b2 | 1006 | } |
a8d2fb31 | 1007 | |
5ca0d812 | 1008 | if ( ( key >= 0x20 && key < WXK_START ) || |
fce161de | 1009 | ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || |
5ca0d812 SC |
1010 | key == WXK_RETURN || |
1011 | key == WXK_DELETE || | |
1012 | key == WXK_BACK) | |
7f1de2b2 | 1013 | { |
5ca0d812 | 1014 | wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 | 1015 | event1.SetEventObject( this ); |
c88b7d28 | 1016 | wxPostEvent( GetEventHandler(), event1 ); |
7f1de2b2 | 1017 | } |
5ca0d812 | 1018 | } |
facd6764 | 1019 | |
5ca0d812 SC |
1020 | // ---------------------------------------------------------------------------- |
1021 | // standard handlers for standard edit menu events | |
1022 | // ---------------------------------------------------------------------------- | |
1023 | ||
1024 | void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) | |
1025 | { | |
1026 | Cut(); | |
72055702 SC |
1027 | } |
1028 | ||
5ca0d812 | 1029 | void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 1030 | { |
5ca0d812 SC |
1031 | Copy(); |
1032 | } | |
7f1de2b2 | 1033 | |
5ca0d812 SC |
1034 | void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) |
1035 | { | |
1036 | Paste(); | |
facd6764 SC |
1037 | } |
1038 | ||
5ca0d812 | 1039 | void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 1040 | { |
5ca0d812 | 1041 | Undo(); |
facd6764 SC |
1042 | } |
1043 | ||
5ca0d812 SC |
1044 | void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) |
1045 | { | |
1046 | Redo(); | |
1047 | } | |
facd6764 | 1048 | |
24eef584 SC |
1049 | void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) |
1050 | { | |
1051 | long from, to; | |
ffafe6ca | 1052 | |
c88b7d28 | 1053 | GetSelection( &from, &to ); |
24eef584 | 1054 | if (from != -1 && to != -1) |
c88b7d28 | 1055 | Remove( from, to ); |
24eef584 SC |
1056 | } |
1057 | ||
1058 | void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
1059 | { | |
1060 | SetSelection(-1, -1); | |
1061 | } | |
1062 | ||
5ca0d812 | 1063 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
72055702 | 1064 | { |
5ca0d812 | 1065 | event.Enable( CanCut() ); |
72055702 SC |
1066 | } |
1067 | ||
5ca0d812 SC |
1068 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) |
1069 | { | |
1070 | event.Enable( CanCopy() ); | |
72055702 SC |
1071 | } |
1072 | ||
5ca0d812 | 1073 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) |
72055702 | 1074 | { |
5ca0d812 | 1075 | event.Enable( CanPaste() ); |
72055702 SC |
1076 | } |
1077 | ||
5ca0d812 | 1078 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) |
29b30405 | 1079 | { |
5ca0d812 | 1080 | event.Enable( CanUndo() ); |
29b30405 SC |
1081 | } |
1082 | ||
5ca0d812 | 1083 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) |
facd6764 | 1084 | { |
5ca0d812 | 1085 | event.Enable( CanRedo() ); |
facd6764 SC |
1086 | } |
1087 | ||
24eef584 SC |
1088 | void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) |
1089 | { | |
1090 | long from, to; | |
ffafe6ca | 1091 | |
c88b7d28 | 1092 | GetSelection( &from, &to ); |
0207e969 | 1093 | event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; |
24eef584 SC |
1094 | } |
1095 | ||
1096 | void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
1097 | { | |
1098 | event.Enable(GetLastPosition() > 0); | |
1099 | } | |
1100 | ||
a8d2fb31 | 1101 | // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment |
24eef584 SC |
1102 | |
1103 | void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) | |
1104 | { | |
64bd657c SC |
1105 | if ( GetPeer()->HasOwnContextMenu() ) |
1106 | { | |
1107 | event.Skip() ; | |
1108 | return ; | |
1109 | } | |
0207e969 | 1110 | |
24eef584 SC |
1111 | if (m_privateContextMenu == NULL) |
1112 | { | |
1113 | m_privateContextMenu = new wxMenu; | |
1114 | m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); | |
1115 | m_privateContextMenu->Append(wxID_REDO, _("&Redo")); | |
1116 | m_privateContextMenu->AppendSeparator(); | |
1117 | m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); | |
1118 | m_privateContextMenu->Append(wxID_COPY, _("&Copy")); | |
1119 | m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); | |
1120 | m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); | |
1121 | m_privateContextMenu->AppendSeparator(); | |
1122 | m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); | |
1123 | } | |
faa94f3e | 1124 | |
24eef584 SC |
1125 | if (m_privateContextMenu != NULL) |
1126 | PopupMenu(m_privateContextMenu); | |
1127 | } | |
1128 | ||
5ca0d812 | 1129 | bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) |
29b30405 | 1130 | { |
0207e969 | 1131 | if ( !GetPeer()->SetupCursor( pt ) ) |
f2c3f2a8 SC |
1132 | return wxWindow::MacSetupCursor( pt ) ; |
1133 | else | |
1134 | return true ; | |
5ca0d812 | 1135 | } |
a8d2fb31 | 1136 | |
20b69855 | 1137 | #if !TARGET_API_MAC_OSX |
24260aae | 1138 | |
5ca0d812 | 1139 | // user pane implementation |
ef4a634b | 1140 | |
7d8268a1 | 1141 | void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) |
5ca0d812 | 1142 | { |
24260aae | 1143 | GetPeer()->MacControlUserPaneDrawProc( part ) ; |
29b30405 SC |
1144 | } |
1145 | ||
7d8268a1 | 1146 | wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
29b30405 | 1147 | { |
24260aae | 1148 | return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ; |
29b30405 SC |
1149 | } |
1150 | ||
7d8268a1 | 1151 | wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
72055702 | 1152 | { |
24260aae | 1153 | return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ; |
72055702 SC |
1154 | } |
1155 | ||
7d8268a1 | 1156 | void wxTextCtrl::MacControlUserPaneIdleProc() |
72055702 | 1157 | { |
24260aae | 1158 | GetPeer()->MacControlUserPaneIdleProc( ) ; |
72055702 SC |
1159 | } |
1160 | ||
7d8268a1 | 1161 | wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
72055702 | 1162 | { |
24260aae | 1163 | return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ; |
72055702 SC |
1164 | } |
1165 | ||
7d8268a1 | 1166 | void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) |
72055702 | 1167 | { |
24260aae | 1168 | GetPeer()->MacControlUserPaneActivateProc( activating ) ; |
72055702 SC |
1169 | } |
1170 | ||
7d8268a1 | 1171 | wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) |
72055702 | 1172 | { |
24260aae | 1173 | return GetPeer()->MacControlUserPaneFocusProc( action ) ; |
72055702 SC |
1174 | } |
1175 | ||
7d8268a1 | 1176 | void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) |
72055702 | 1177 | { |
24260aae | 1178 | GetPeer()->MacControlUserPaneBackgroundProc( info ) ; |
5ca0d812 | 1179 | } |
24260aae | 1180 | |
20b69855 | 1181 | #endif |
a8d2fb31 | 1182 | |
5ca0d812 SC |
1183 | // ---------------------------------------------------------------------------- |
1184 | // implementation base class | |
1185 | // ---------------------------------------------------------------------------- | |
1186 | ||
0f7817ab SC |
1187 | wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : |
1188 | wxMacControl( peer ) | |
5ca0d812 | 1189 | { |
72055702 SC |
1190 | } |
1191 | ||
7d8268a1 | 1192 | wxMacTextControl::~wxMacTextControl() |
72055702 | 1193 | { |
72055702 SC |
1194 | } |
1195 | ||
7d8268a1 | 1196 | void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style) |
72055702 | 1197 | { |
72055702 SC |
1198 | } |
1199 | ||
7d8268a1 | 1200 | void wxMacTextControl::Copy() |
72055702 | 1201 | { |
72055702 SC |
1202 | } |
1203 | ||
7d8268a1 | 1204 | void wxMacTextControl::Cut() |
72055702 | 1205 | { |
72055702 SC |
1206 | } |
1207 | ||
7d8268a1 | 1208 | void wxMacTextControl::Paste() |
72055702 | 1209 | { |
72055702 SC |
1210 | } |
1211 | ||
7d8268a1 WS |
1212 | bool wxMacTextControl::CanPaste() const |
1213 | { | |
5ca0d812 SC |
1214 | return false ; |
1215 | } | |
1216 | ||
7d8268a1 | 1217 | void wxMacTextControl::SetEditable(bool editable) |
72055702 | 1218 | { |
7d8268a1 | 1219 | } |
facd6764 | 1220 | |
7d8268a1 | 1221 | wxTextPos wxMacTextControl::GetLastPosition() const |
5ca0d812 | 1222 | { |
faa94f3e | 1223 | return GetStringValue().length() ; |
5ca0d812 | 1224 | } |
facd6764 | 1225 | |
44aa865d SC |
1226 | void wxMacTextControl::Replace( long from , long to , const wxString &val ) |
1227 | { | |
1228 | SetSelection( from , to ) ; | |
fef981b4 | 1229 | WriteText( val ) ; |
44aa865d SC |
1230 | } |
1231 | ||
1232 | void wxMacTextControl::Remove( long from , long to ) | |
5ca0d812 | 1233 | { |
44aa865d SC |
1234 | SetSelection( from , to ) ; |
1235 | WriteText( wxEmptyString) ; | |
72055702 SC |
1236 | } |
1237 | ||
7d8268a1 | 1238 | void wxMacTextControl::Clear() |
72055702 | 1239 | { |
5ca0d812 | 1240 | SetStringValue( wxEmptyString ) ; |
72055702 SC |
1241 | } |
1242 | ||
7d8268a1 | 1243 | bool wxMacTextControl::CanUndo() const |
72055702 | 1244 | { |
5ca0d812 SC |
1245 | return false ; |
1246 | } | |
587bc950 | 1247 | |
a8d2fb31 DS |
1248 | void wxMacTextControl::Undo() |
1249 | { | |
1250 | } | |
5ca0d812 SC |
1251 | |
1252 | bool wxMacTextControl::CanRedo() const | |
1253 | { | |
1254 | return false ; | |
7d8268a1 | 1255 | } |
5ca0d812 | 1256 | |
7d8268a1 | 1257 | void wxMacTextControl::Redo() |
5ca0d812 | 1258 | { |
72055702 SC |
1259 | } |
1260 | ||
5ca0d812 | 1261 | long wxMacTextControl::XYToPosition(long x, long y) const |
72055702 | 1262 | { |
5ca0d812 SC |
1263 | return 0 ; |
1264 | } | |
72055702 | 1265 | |
7d8268a1 | 1266 | bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const |
5ca0d812 SC |
1267 | { |
1268 | return false ; | |
72055702 SC |
1269 | } |
1270 | ||
7d8268a1 WS |
1271 | void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) |
1272 | { | |
1273 | } | |
5ca0d812 | 1274 | |
7d8268a1 | 1275 | int wxMacTextControl::GetNumberOfLines() const |
7548762c | 1276 | { |
5ca0d812 SC |
1277 | ItemCount lines = 0 ; |
1278 | wxString content = GetStringValue() ; | |
1279 | lines = 1; | |
fef981b4 | 1280 | |
faa94f3e | 1281 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1282 | { |
fef981b4 DS |
1283 | if (content[i] == '\r') |
1284 | lines++; | |
7548762c | 1285 | } |
a8d2fb31 | 1286 | |
5ca0d812 SC |
1287 | return lines ; |
1288 | } | |
7548762c | 1289 | |
5ca0d812 | 1290 | wxString wxMacTextControl::GetLineText(long lineNo) const |
7548762c | 1291 | { |
fef981b4 | 1292 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1293 | wxString content = GetStringValue() ; |
7d8268a1 | 1294 | |
5ca0d812 SC |
1295 | // Find line first |
1296 | int count = 0; | |
faa94f3e | 1297 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1298 | { |
5ca0d812 SC |
1299 | if (count == lineNo) |
1300 | { | |
1301 | // Add chars in line then | |
1302 | wxString tmp; | |
7d8268a1 | 1303 | |
faa94f3e | 1304 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1305 | { |
1306 | if (content[j] == '\n') | |
1307 | return tmp; | |
7d8268a1 | 1308 | |
5ca0d812 SC |
1309 | tmp += content[j]; |
1310 | } | |
7d8268a1 | 1311 | |
5ca0d812 SC |
1312 | return tmp; |
1313 | } | |
a8d2fb31 | 1314 | |
fef981b4 DS |
1315 | if (content[i] == '\n') |
1316 | count++; | |
7548762c | 1317 | } |
a8d2fb31 | 1318 | |
5ca0d812 SC |
1319 | return wxEmptyString ; |
1320 | } | |
7548762c | 1321 | |
a8d2fb31 | 1322 | int wxMacTextControl::GetLineLength(long lineNo) const |
5ca0d812 | 1323 | { |
fef981b4 | 1324 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1325 | wxString content = GetStringValue() ; |
7d8268a1 | 1326 | |
5ca0d812 SC |
1327 | // Find line first |
1328 | int count = 0; | |
faa94f3e | 1329 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1330 | { |
5ca0d812 SC |
1331 | if (count == lineNo) |
1332 | { | |
1333 | // Count chars in line then | |
1334 | count = 0; | |
faa94f3e | 1335 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1336 | { |
1337 | count++; | |
a8d2fb31 DS |
1338 | if (content[j] == '\n') |
1339 | return count; | |
5ca0d812 | 1340 | } |
7d8268a1 | 1341 | |
5ca0d812 SC |
1342 | return count; |
1343 | } | |
a8d2fb31 | 1344 | |
fef981b4 DS |
1345 | if (content[i] == '\n') |
1346 | count++; | |
7548762c | 1347 | } |
a8d2fb31 | 1348 | |
5ca0d812 SC |
1349 | return 0 ; |
1350 | } | |
7548762c | 1351 | |
5ca0d812 SC |
1352 | // ---------------------------------------------------------------------------- |
1353 | // standard unicode control implementation | |
1354 | // ---------------------------------------------------------------------------- | |
1355 | ||
1356 | #if TARGET_API_MAC_OSX | |
1357 | ||
ad604d0f SC |
1358 | // the current unicode textcontrol implementation has a bug : only if the control |
1359 | // is currently having the focus, the selection can be retrieved by the corresponding | |
1360 | // data tag. So we have a mirroring using a member variable | |
1361 | // TODO : build event table using virtual member functions for wxMacControl | |
1362 | ||
1363 | static const EventTypeSpec unicodeTextControlEventList[] = | |
1364 | { | |
1365 | { kEventClassControl , kEventControlSetFocusPart } , | |
1366 | } ; | |
1367 | ||
1368 | static pascal OSStatus wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1369 | { | |
1370 | OSStatus result = eventNotHandledErr ; | |
1371 | wxMacUnicodeTextControl* focus = (wxMacUnicodeTextControl*) data ; | |
1372 | wxMacCarbonEvent cEvent( event ) ; | |
9eddec69 | 1373 | |
ad604d0f SC |
1374 | switch ( GetEventKind( event ) ) |
1375 | { | |
1376 | case kEventControlSetFocusPart : | |
1377 | { | |
1378 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
1379 | if ( controlPart == kControlFocusNoPart ) | |
1380 | { | |
1381 | // about to loose focus -> store selection to field | |
1382 | focus->GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1383 | } | |
1384 | result = CallNextEventHandler(handler,event) ; | |
1385 | if ( controlPart != kControlFocusNoPart ) | |
1386 | { | |
1387 | // about to gain focus -> set selection from field | |
1388 | focus->SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1389 | } | |
1390 | break; | |
1391 | } | |
1392 | default: | |
1393 | break ; | |
1394 | } | |
9eddec69 | 1395 | |
ad604d0f SC |
1396 | return result ; |
1397 | } | |
1398 | ||
1399 | static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1400 | { | |
1401 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 1402 | |
ad604d0f SC |
1403 | switch ( GetEventClass( event ) ) |
1404 | { | |
1405 | case kEventClassControl : | |
1406 | result = wxMacUnicodeTextControlControlEventHandler( handler , event , data ) ; | |
1407 | break ; | |
9eddec69 | 1408 | |
ad604d0f SC |
1409 | default : |
1410 | break ; | |
1411 | } | |
1412 | return result ; | |
1413 | } | |
1414 | ||
1415 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) | |
1416 | ||
0f7817ab | 1417 | wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
1418 | const wxString& str, |
1419 | const wxPoint& pos, | |
1420 | const wxSize& size, long style ) | |
1421 | : wxMacTextControl( wxPeer ) | |
5ca0d812 SC |
1422 | { |
1423 | m_font = wxPeer->GetFont() ; | |
1424 | m_windowStyle = style ; | |
7d8268a1 | 1425 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 1426 | wxString st = str ; |
395480fb | 1427 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1428 | wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; |
1429 | CFStringRef cfr = cf ; | |
1430 | Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; | |
1431 | m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ; | |
ffafe6ca DS |
1432 | |
1433 | OSStatus err = CreateEditUnicodeTextControl( | |
fef981b4 DS |
1434 | MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , |
1435 | isPassword , NULL , &m_controlRef ) ; | |
ffafe6ca | 1436 | verify_noerr( err ); |
7d8268a1 | 1437 | |
5ca0d812 | 1438 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
5ca0d812 | 1439 | SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; |
ad604d0f SC |
1440 | |
1441 | InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), | |
1442 | GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, | |
1443 | &m_focusHandlerRef); | |
5ca0d812 | 1444 | } |
7548762c | 1445 | |
5ca0d812 | 1446 | wxMacUnicodeTextControl::~wxMacUnicodeTextControl() |
7548762c | 1447 | { |
ad604d0f | 1448 | ::RemoveEventHandler( m_focusHandlerRef ); |
7548762c SC |
1449 | } |
1450 | ||
7d8268a1 | 1451 | void wxMacUnicodeTextControl::VisibilityChanged(bool shown) |
7548762c | 1452 | { |
5ca0d812 SC |
1453 | if ( !(m_windowStyle & wxTE_MULTILINE) && shown ) |
1454 | { | |
fef981b4 DS |
1455 | // work around a refresh issue insofar as not always the entire content is shown, |
1456 | // even if this would be possible | |
5ca0d812 SC |
1457 | ControlEditTextSelectionRec sel ; |
1458 | CFStringRef value = NULL ; | |
7548762c | 1459 | |
5ca0d812 | 1460 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); |
c88b7d28 | 1461 | verify_noerr( GetData<CFStringRef>( 0, m_valueTag, &value ) ); |
5ca0d812 SC |
1462 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag, &value ) ); |
1463 | verify_noerr( SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); | |
7d8268a1 | 1464 | |
5ca0d812 SC |
1465 | CFRelease( value ) ; |
1466 | } | |
1467 | } | |
a8d2fb31 | 1468 | |
7d8268a1 | 1469 | wxString wxMacUnicodeTextControl::GetStringValue() const |
7548762c | 1470 | { |
5ca0d812 | 1471 | wxString result ; |
c88b7d28 | 1472 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; |
5ca0d812 SC |
1473 | if ( value ) |
1474 | { | |
1475 | wxMacCFStringHolder cf(value) ; | |
1476 | result = cf.AsString() ; | |
1477 | } | |
a8d2fb31 | 1478 | |
2e7573f7 | 1479 | #if '\n' == 10 |
395480fb SC |
1480 | wxMacConvertNewlines13To10( &result ) ; |
1481 | #else | |
5ca0d812 | 1482 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1483 | #endif |
a8d2fb31 | 1484 | |
7548762c SC |
1485 | return result ; |
1486 | } | |
a8d2fb31 | 1487 | |
c88b7d28 | 1488 | void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) |
5ca0d812 SC |
1489 | { |
1490 | wxString st = str ; | |
395480fb | 1491 | wxMacConvertNewlines10To13( &st ) ; |
ffafe6ca | 1492 | wxMacCFStringHolder cf( st , m_font.GetEncoding() ) ; |
0207e969 | 1493 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag , cf ) ) ; |
5ca0d812 | 1494 | } |
a8d2fb31 | 1495 | |
5ca0d812 SC |
1496 | void wxMacUnicodeTextControl::Copy() |
1497 | { | |
1498 | SendHICommand( kHICommandCopy ) ; | |
1499 | } | |
a8d2fb31 | 1500 | |
5ca0d812 SC |
1501 | void wxMacUnicodeTextControl::Cut() |
1502 | { | |
1503 | SendHICommand( kHICommandCut ) ; | |
1504 | } | |
a8d2fb31 | 1505 | |
5ca0d812 SC |
1506 | void wxMacUnicodeTextControl::Paste() |
1507 | { | |
1508 | SendHICommand( kHICommandPaste ) ; | |
1509 | } | |
a8d2fb31 | 1510 | |
5ca0d812 SC |
1511 | bool wxMacUnicodeTextControl::CanPaste() const |
1512 | { | |
1513 | return true ; | |
1514 | } | |
a8d2fb31 | 1515 | |
7d8268a1 | 1516 | void wxMacUnicodeTextControl::SetEditable(bool editable) |
5ca0d812 | 1517 | { |
35d9ac06 SC |
1518 | #if 0 // leads to problem because text cannot be selected anymore |
1519 | SetData<Boolean>( kControlEditTextPart , kControlEditTextLockedTag , (Boolean) !editable ) ; | |
1520 | #endif | |
5ca0d812 | 1521 | } |
7548762c | 1522 | |
0207e969 | 1523 | void wxMacUnicodeTextControl::GetSelection( long* from, long* to ) const |
7548762c | 1524 | { |
5ca0d812 | 1525 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1526 | if (HasFocus()) |
1527 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ) ; | |
1528 | else | |
1529 | sel = m_selection ; | |
9eddec69 | 1530 | |
0207e969 DS |
1531 | if ( from ) |
1532 | *from = sel.selStart ; | |
1533 | if ( to ) | |
1534 | *to = sel.selEnd ; | |
7548762c SC |
1535 | } |
1536 | ||
7d8268a1 | 1537 | void wxMacUnicodeTextControl::SetSelection( long from , long to ) |
ef4a634b | 1538 | { |
5ca0d812 | 1539 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1540 | wxString result ; |
1541 | int textLength = 0 ; | |
1542 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; | |
1543 | if ( value ) | |
1544 | { | |
1545 | wxMacCFStringHolder cf(value) ; | |
1832043f | 1546 | textLength = cf.AsString().length() ; |
ad604d0f SC |
1547 | } |
1548 | ||
1a535eb9 SC |
1549 | if ((from == -1) && (to == -1)) |
1550 | { | |
1551 | from = 0 ; | |
9eddec69 | 1552 | to = textLength ; |
ad604d0f SC |
1553 | } |
1554 | else | |
1555 | { | |
1556 | from = wxMin(textLength,wxMax(from,0)) ; | |
1557 | to = wxMax(0,wxMin(textLength,to)) ; | |
1a535eb9 | 1558 | } |
a8d2fb31 | 1559 | |
5ca0d812 SC |
1560 | sel.selStart = from ; |
1561 | sel.selEnd = to ; | |
ad604d0f SC |
1562 | if ( HasFocus() ) |
1563 | SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ; | |
1564 | else | |
1565 | m_selection = sel; | |
5ca0d812 | 1566 | } |
facd6764 | 1567 | |
c88b7d28 | 1568 | void wxMacUnicodeTextControl::WriteText( const wxString& str ) |
5ca0d812 SC |
1569 | { |
1570 | wxString st = str ; | |
395480fb | 1571 | wxMacConvertNewlines10To13( &st ) ; |
0207e969 DS |
1572 | |
1573 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
ad604d0f SC |
1574 | if ( HasFocus() ) |
1575 | { | |
7548762c SC |
1576 | wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; |
1577 | CFStringRef value = cf ; | |
5ca0d812 | 1578 | SetData<CFStringRef>( 0, kControlEditTextInsertCFStringRefTag, &value ); |
ad604d0f | 1579 | } |
df39467f | 1580 | else |
ad604d0f SC |
1581 | #endif |
1582 | { | |
5ca0d812 | 1583 | wxString val = GetStringValue() ; |
7548762c SC |
1584 | long start , end ; |
1585 | GetSelection( &start , &end ) ; | |
1586 | val.Remove( start , end - start ) ; | |
1587 | val.insert( start , str ) ; | |
5ca0d812 | 1588 | SetStringValue( val ) ; |
faa94f3e | 1589 | SetSelection( start + str.length() , start + str.length() ) ; |
ad604d0f | 1590 | } |
72055702 SC |
1591 | } |
1592 | ||
5ca0d812 | 1593 | #endif |
facd6764 | 1594 | |
5ca0d812 SC |
1595 | // ---------------------------------------------------------------------------- |
1596 | // MLTE control implementation (common part) | |
1597 | // ---------------------------------------------------------------------------- | |
facd6764 | 1598 | |
a8d2fb31 | 1599 | // if MTLE is read only, no changes at all are allowed, not even from |
5ca0d812 SC |
1600 | // procedural API, in order to allow changes via API all the same we must undo |
1601 | // the readonly status while we are executing, this class helps to do so | |
72055702 | 1602 | |
5de694f0 | 1603 | class wxMacEditHelper |
72055702 | 1604 | { |
5ca0d812 | 1605 | public : |
5de694f0 | 1606 | wxMacEditHelper( TXNObject txn ) |
5ca0d812 SC |
1607 | { |
1608 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1609 | m_txn = txn ; | |
1610 | TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ; | |
1611 | if ( m_data[0].uValue == kTXNReadOnly ) | |
1612 | { | |
1613 | TXNControlData data[] = { { kTXNReadWrite } } ; | |
1614 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; | |
1615 | } | |
1616 | } | |
a8d2fb31 | 1617 | |
5de694f0 | 1618 | ~wxMacEditHelper() |
5ca0d812 SC |
1619 | { |
1620 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1621 | if ( m_data[0].uValue == kTXNReadOnly ) | |
5ca0d812 | 1622 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; |
5ca0d812 | 1623 | } |
a8d2fb31 | 1624 | |
fef981b4 DS |
1625 | protected : |
1626 | TXNObject m_txn ; | |
1627 | TXNControlData m_data[1] ; | |
5ca0d812 | 1628 | } ; |
72055702 | 1629 | |
ffafe6ca DS |
1630 | wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) |
1631 | : wxMacTextControl( peer ) | |
789ae0cf | 1632 | { |
3dee36ae | 1633 | SetNeedsFocusRect( true ) ; |
789ae0cf SC |
1634 | } |
1635 | ||
7d8268a1 | 1636 | wxString wxMacMLTEControl::GetStringValue() const |
72055702 | 1637 | { |
5ca0d812 SC |
1638 | wxString result ; |
1639 | OSStatus err ; | |
1640 | Size actualSize = 0; | |
c88b7d28 | 1641 | |
5ca0d812 SC |
1642 | { |
1643 | #if wxUSE_UNICODE | |
1644 | Handle theText ; | |
c88b7d28 | 1645 | err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNUnicodeTextData ); |
fef981b4 | 1646 | |
5ca0d812 | 1647 | // all done |
fef981b4 | 1648 | if ( err != noErr ) |
5ca0d812 SC |
1649 | { |
1650 | actualSize = 0 ; | |
1651 | } | |
1652 | else | |
1653 | { | |
c88b7d28 | 1654 | actualSize = GetHandleSize( theText ) / sizeof(UniChar) ; |
5ca0d812 SC |
1655 | if ( actualSize > 0 ) |
1656 | { | |
1657 | wxChar *ptr = NULL ; | |
fef981b4 | 1658 | |
7d8268a1 | 1659 | #if SIZEOF_WCHAR_T == 2 |
c88b7d28 DS |
1660 | ptr = new wxChar[actualSize + 1] ; |
1661 | wxStrncpy( ptr , (wxChar*)(*theText) , actualSize ) ; | |
5ca0d812 | 1662 | #else |
c88b7d28 | 1663 | SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ; |
5ca0d812 SC |
1664 | HLock( theText ) ; |
1665 | (((UniChar*)*theText)[actualSize]) = 0 ; | |
d9d488cf | 1666 | wxMBConvUTF16 converter ; |
5ca0d812 | 1667 | size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; |
88a7a4e1 | 1668 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); |
5ca0d812 | 1669 | ptr = new wxChar[noChars + 1] ; |
7d8268a1 | 1670 | |
f3097709 | 1671 | noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; |
88a7a4e1 | 1672 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); |
5ca0d812 SC |
1673 | ptr[noChars] = 0 ; |
1674 | HUnlock( theText ) ; | |
1675 | #endif | |
fef981b4 | 1676 | |
5ca0d812 SC |
1677 | ptr[actualSize] = 0 ; |
1678 | result = wxString( ptr ) ; | |
c88b7d28 | 1679 | delete [] ptr ; |
5ca0d812 | 1680 | } |
a8d2fb31 | 1681 | |
5ca0d812 SC |
1682 | DisposeHandle( theText ) ; |
1683 | } | |
1684 | #else | |
1685 | Handle theText ; | |
c88b7d28 | 1686 | err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
0207e969 | 1687 | |
5ca0d812 | 1688 | // all done |
0207e969 | 1689 | if ( err != noErr ) |
5ca0d812 SC |
1690 | { |
1691 | actualSize = 0 ; | |
1692 | } | |
1693 | else | |
1694 | { | |
1695 | actualSize = GetHandleSize( theText ) ; | |
1696 | if ( actualSize > 0 ) | |
1697 | { | |
1698 | HLock( theText ) ; | |
1699 | result = wxString( *theText , wxConvLocal , actualSize ) ; | |
1700 | HUnlock( theText ) ; | |
1701 | } | |
a8d2fb31 | 1702 | |
5ca0d812 SC |
1703 | DisposeHandle( theText ) ; |
1704 | } | |
1705 | #endif | |
1706 | } | |
a8d2fb31 | 1707 | |
2e7573f7 | 1708 | #if '\n' == 10 |
395480fb SC |
1709 | wxMacConvertNewlines13To10( &result ) ; |
1710 | #else | |
5ca0d812 | 1711 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1712 | #endif |
a8d2fb31 | 1713 | |
5ca0d812 | 1714 | return result ; |
72055702 SC |
1715 | } |
1716 | ||
0207e969 | 1717 | void wxMacMLTEControl::SetStringValue( const wxString &str ) |
72055702 | 1718 | { |
c88b7d28 DS |
1719 | wxString st = str; |
1720 | wxMacConvertNewlines10To13( &st ); | |
395480fb | 1721 | |
5de694f0 | 1722 | { |
4f74e0d1 SC |
1723 | #ifndef __LP64__ |
1724 | wxMacWindowClipper c( m_peer ) ; | |
1725 | #endif | |
0207e969 | 1726 | |
5de694f0 | 1727 | { |
c88b7d28 DS |
1728 | wxMacEditHelper help( m_txn ); |
1729 | SetTXNData( st, kTXNStartOffset, kTXNEndOffset ); | |
5de694f0 | 1730 | } |
0207e969 | 1731 | |
fef981b4 DS |
1732 | TXNSetSelection( m_txn, 0, 0 ); |
1733 | TXNShowSelection( m_txn, kTXNShowStart ); | |
5de694f0 | 1734 | } |
5ca0d812 | 1735 | } |
facd6764 | 1736 | |
5ca0d812 SC |
1737 | TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) |
1738 | { | |
c88b7d28 DS |
1739 | TXNFrameOptions frameOptions = kTXNDontDrawCaretWhenInactiveMask; |
1740 | ||
b7e28620 | 1741 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
c88b7d28 | 1742 | frameOptions |= kTXNDoFontSubstitutionMask; |
b7e28620 | 1743 | #endif |
4d7528a1 | 1744 | |
c88b7d28 | 1745 | if ( ! (wxStyle & wxTE_NOHIDESEL) ) |
5ca0d812 SC |
1746 | frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; |
1747 | ||
c88b7d28 DS |
1748 | if ( wxStyle & (wxHSCROLL | wxTE_DONTWRAP) ) |
1749 | frameOptions |= kTXNWantHScrollBarMask ; | |
1750 | ||
5ca0d812 | 1751 | if ( wxStyle & wxTE_MULTILINE ) |
29e4a190 | 1752 | { |
c88b7d28 | 1753 | frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; |
72055702 | 1754 | |
c88b7d28 | 1755 | if ( !(wxStyle & wxTE_NO_VSCROLL) ) |
5de694f0 | 1756 | { |
5ca0d812 | 1757 | frameOptions |= kTXNWantVScrollBarMask ; |
c88b7d28 | 1758 | |
04c3457a DS |
1759 | // The following code causes drawing problems on 10.4. Perhaps it can be restored for |
1760 | // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here | |
1761 | // anyways, as AFAIK users can't actually use it to resize the text ctrl. | |
1762 | // if ( frameOptions & kTXNWantHScrollBarMask ) | |
1763 | // frameOptions |= kTXNDrawGrowIconMask ; | |
5de694f0 | 1764 | } |
5ca0d812 SC |
1765 | } |
1766 | else | |
c88b7d28 | 1767 | { |
5ca0d812 | 1768 | frameOptions |= kTXNSingleLineOnlyMask ; |
c88b7d28 | 1769 | } |
7d8268a1 | 1770 | |
5ca0d812 SC |
1771 | return frameOptions ; |
1772 | } | |
cfeff6f7 | 1773 | |
5ca0d812 SC |
1774 | void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible ) |
1775 | { | |
3dee36ae WS |
1776 | TXNControlTag iControlTags[] = |
1777 | { | |
1778 | kTXNDoFontSubstitution, | |
5de694f0 SC |
1779 | kTXNWordWrapStateTag , |
1780 | }; | |
3dee36ae WS |
1781 | TXNControlData iControlData[] = |
1782 | { | |
c88b7d28 DS |
1783 | { true }, |
1784 | { kTXNNoAutoWrap }, | |
5de694f0 | 1785 | }; |
3dee36ae | 1786 | |
5de694f0 | 1787 | int toptag = WXSIZEOF( iControlTags ) ; |
7d8268a1 | 1788 | |
72055702 SC |
1789 | if ( m_windowStyle & wxTE_MULTILINE ) |
1790 | { | |
c88b7d28 DS |
1791 | iControlData[1].uValue = |
1792 | (m_windowStyle & wxTE_DONTWRAP) | |
1793 | ? kTXNNoAutoWrap | |
1794 | : kTXNAutoWrap; | |
72055702 | 1795 | } |
0207e969 | 1796 | |
ffafe6ca DS |
1797 | OSStatus err = TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ; |
1798 | verify_noerr( err ); | |
facd6764 | 1799 | |
fef981b4 | 1800 | // setting the default font: |
8e15e610 | 1801 | // under 10.2 this causes a visible caret, therefore we avoid it |
72055702 | 1802 | |
8e15e610 | 1803 | if ( UMAGetSystemVersion() >= 0x1030 ) |
72055702 | 1804 | { |
8e15e610 SC |
1805 | Str255 fontName ; |
1806 | SInt16 fontSize ; | |
1807 | Style fontStyle ; | |
5ca0d812 | 1808 | |
ffafe6ca | 1809 | GetThemeFont( kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
5ca0d812 | 1810 | |
8e15e610 SC |
1811 | TXNTypeAttributes typeAttr[] = |
1812 | { | |
c88b7d28 DS |
1813 | { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , |
1814 | { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , | |
1815 | { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , | |
8e15e610 SC |
1816 | } ; |
1817 | ||
ffafe6ca DS |
1818 | err = TXNSetTypeAttributes( |
1819 | m_txn, sizeof(typeAttr) / sizeof(TXNTypeAttributes), | |
1820 | typeAttr, kTXNStartOffset, kTXNEndOffset ); | |
1821 | verify_noerr( err ); | |
8e15e610 | 1822 | } |
3dee36ae | 1823 | |
5ca0d812 SC |
1824 | if ( m_windowStyle & wxTE_PASSWORD ) |
1825 | { | |
ffafe6ca DS |
1826 | UniChar c = 0x00A5 ; |
1827 | err = TXNEchoMode( m_txn , c , 0 , true ); | |
1828 | verify_noerr( err ); | |
72055702 | 1829 | } |
5ca0d812 SC |
1830 | |
1831 | TXNBackground tback; | |
1832 | tback.bgType = kTXNBackgroundTypeRGB; | |
1833 | tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); | |
0207e969 | 1834 | TXNSetBackground( m_txn , &tback ); |
a8d2fb31 | 1835 | |
64bd657c SC |
1836 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
1837 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
1838 | { | |
1839 | TXNCommandEventSupportOptions options ; | |
fef981b4 | 1840 | if ( TXNGetCommandEventSupport( m_txn, &options ) == noErr ) |
64bd657c | 1841 | { |
fef981b4 DS |
1842 | options |= |
1843 | kTXNSupportEditCommandProcessing | |
1844 | | kTXNSupportEditCommandUpdating | |
1845 | | kTXNSupportSpellCheckCommandProcessing | |
1846 | | kTXNSupportSpellCheckCommandUpdating | |
1847 | | kTXNSupportFontCommandProcessing | |
1848 | | kTXNSupportFontCommandUpdating; | |
9eddec69 | 1849 | |
64bd657c SC |
1850 | TXNSetCommandEventSupport( m_txn , options ) ; |
1851 | } | |
1852 | } | |
1853 | #endif | |
72055702 SC |
1854 | } |
1855 | ||
7d8268a1 | 1856 | void wxMacMLTEControl::SetBackground( const wxBrush &brush ) |
7ea087b7 SC |
1857 | { |
1858 | // currently only solid background are supported | |
1859 | TXNBackground tback; | |
0207e969 | 1860 | |
7ea087b7 SC |
1861 | tback.bgType = kTXNBackgroundTypeRGB; |
1862 | tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); | |
0207e969 | 1863 | TXNSetBackground( m_txn , &tback ); |
7ea087b7 SC |
1864 | } |
1865 | ||
0207e969 | 1866 | void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) |
72055702 | 1867 | { |
7d8268a1 | 1868 | TXNTypeAttributes typeAttr[4] ; |
5ca0d812 | 1869 | RGBColor color ; |
0207e969 | 1870 | int attrCount = 0 ; |
fef981b4 | 1871 | |
5ca0d812 | 1872 | if ( style.HasFont() ) |
72055702 | 1873 | { |
5ca0d812 | 1874 | const wxFont &font = style.GetFont() ; |
9eddec69 | 1875 | |
acead93d | 1876 | #if 0 // old version |
09660720 SC |
1877 | Str255 fontName = "\pMonaco" ; |
1878 | SInt16 fontSize = 12 ; | |
1879 | Style fontStyle = normal ; | |
5ca0d812 SC |
1880 | wxMacStringToPascal( font.GetFaceName() , fontName ) ; |
1881 | fontSize = font.GetPointSize() ; | |
1882 | if ( font.GetUnderlined() ) | |
1883 | fontStyle |= underline ; | |
1884 | if ( font.GetWeight() == wxBOLD ) | |
1885 | fontStyle |= bold ; | |
1886 | if ( font.GetStyle() == wxITALIC ) | |
1887 | fontStyle |= italic ; | |
eda3f2b4 | 1888 | |
0207e969 DS |
1889 | typeAttr[attrCount].tag = kTXNQDFontNameAttribute ; |
1890 | typeAttr[attrCount].size = kTXNQDFontNameAttributeSize ; | |
1891 | typeAttr[attrCount].data.dataPtr = (void*)fontName ; | |
1892 | attrCount++ ; | |
1893 | ||
1894 | typeAttr[attrCount].tag = kTXNQDFontSizeAttribute ; | |
1895 | typeAttr[attrCount].size = kTXNFontSizeAttributeSize ; | |
1896 | typeAttr[attrCount].data.dataValue = (fontSize << 16) ; | |
1897 | attrCount++ ; | |
1898 | ||
1899 | typeAttr[attrCount].tag = kTXNQDFontStyleAttribute ; | |
1900 | typeAttr[attrCount].size = kTXNQDFontStyleAttributeSize ; | |
1901 | typeAttr[attrCount].data.dataValue = fontStyle ; | |
1902 | attrCount++ ; | |
acead93d SC |
1903 | #else |
1904 | typeAttr[attrCount].tag = kTXNATSUIStyle ; | |
1905 | typeAttr[attrCount].size = kTXNATSUIStyleSize ; | |
4f74e0d1 | 1906 | typeAttr[attrCount].data.dataPtr = font.MacGetATSUStyle() ; |
acead93d SC |
1907 | attrCount++ ; |
1908 | #endif | |
5ca0d812 | 1909 | } |
fef981b4 | 1910 | |
5ca0d812 SC |
1911 | if ( style.HasTextColour() ) |
1912 | { | |
5ca0d812 | 1913 | color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; |
0207e969 DS |
1914 | |
1915 | typeAttr[attrCount].tag = kTXNQDFontColorAttribute ; | |
1916 | typeAttr[attrCount].size = kTXNQDFontColorAttributeSize ; | |
1917 | typeAttr[attrCount].data.dataPtr = (void*) &color ; | |
1918 | attrCount++ ; | |
72055702 | 1919 | } |
fef981b4 | 1920 | |
0207e969 | 1921 | if ( attrCount > 0 ) |
8623a883 | 1922 | { |
0207e969 | 1923 | verify_noerr( TXNSetTypeAttributes( m_txn , attrCount , typeAttr, from , to ) ); |
09660720 SC |
1924 | // unfortunately the relayout is not automatic |
1925 | TXNRecalcTextLayout( m_txn ); | |
8623a883 | 1926 | } |
72055702 SC |
1927 | } |
1928 | ||
7d8268a1 | 1929 | void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
72055702 | 1930 | { |
0207e969 DS |
1931 | wxMacEditHelper help( m_txn ) ; |
1932 | TXNSetAttribute( wxTextAttr( foreground, wxNullColour, font ), kTXNStartOffset, kTXNEndOffset ) ; | |
72055702 | 1933 | } |
a8d2fb31 | 1934 | |
0207e969 | 1935 | void wxMacMLTEControl::SetStyle( long start, long end, const wxTextAttr& style ) |
7d8268a1 | 1936 | { |
0207e969 DS |
1937 | wxMacEditHelper help( m_txn ) ; |
1938 | TXNSetAttribute( style, start, end ) ; | |
7d8268a1 WS |
1939 | } |
1940 | ||
1941 | void wxMacMLTEControl::Copy() | |
5ca0d812 SC |
1942 | { |
1943 | ClearCurrentScrap(); | |
0207e969 | 1944 | TXNCopy( m_txn ); |
5ca0d812 | 1945 | TXNConvertToPublicScrap(); |
72055702 SC |
1946 | } |
1947 | ||
7d8268a1 | 1948 | void wxMacMLTEControl::Cut() |
3a9fa0d6 | 1949 | { |
5ca0d812 | 1950 | ClearCurrentScrap(); |
0207e969 | 1951 | TXNCut( m_txn ); |
5ca0d812 | 1952 | TXNConvertToPublicScrap(); |
3a9fa0d6 VZ |
1953 | } |
1954 | ||
7d8268a1 | 1955 | void wxMacMLTEControl::Paste() |
72055702 | 1956 | { |
5ca0d812 | 1957 | TXNConvertFromPublicScrap(); |
0207e969 | 1958 | TXNPaste( m_txn ); |
72055702 SC |
1959 | } |
1960 | ||
5ca0d812 | 1961 | bool wxMacMLTEControl::CanPaste() const |
72055702 | 1962 | { |
5ca0d812 | 1963 | return TXNIsScrapPastable() ; |
72055702 SC |
1964 | } |
1965 | ||
7d8268a1 | 1966 | void wxMacMLTEControl::SetEditable(bool editable) |
72055702 | 1967 | { |
5ca0d812 SC |
1968 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; |
1969 | TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; | |
c88b7d28 | 1970 | TXNSetTXNObjectControls( m_txn, false, WXSIZEOF(tag), tag, data ) ; |
5ca0d812 | 1971 | } |
bd3169a7 | 1972 | |
7d8268a1 | 1973 | wxTextPos wxMacMLTEControl::GetLastPosition() const |
5ca0d812 | 1974 | { |
7d8268a1 | 1975 | wxTextPos actualsize = 0 ; |
5ca0d812 SC |
1976 | |
1977 | Handle theText ; | |
0207e969 | 1978 | OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
fef981b4 DS |
1979 | |
1980 | // all done | |
1981 | if ( err == noErr ) | |
5ca0d812 | 1982 | { |
fef981b4 DS |
1983 | actualsize = GetHandleSize( theText ) ; |
1984 | DisposeHandle( theText ) ; | |
5ca0d812 SC |
1985 | } |
1986 | else | |
1987 | { | |
fef981b4 | 1988 | actualsize = 0 ; |
5ca0d812 SC |
1989 | } |
1990 | ||
1991 | return actualsize ; | |
1992 | } | |
1993 | ||
44aa865d | 1994 | void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) |
5ca0d812 SC |
1995 | { |
1996 | wxString value = str ; | |
395480fb | 1997 | wxMacConvertNewlines10To13( &value ) ; |
5ca0d812 | 1998 | |
5de694f0 | 1999 | wxMacEditHelper help( m_txn ) ; |
4f74e0d1 | 2000 | #ifndef __LP64__ |
0f7817ab | 2001 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 2002 | #endif |
5ca0d812 | 2003 | |
0207e969 | 2004 | TXNSetSelection( m_txn, from, to ) ; |
5ca0d812 | 2005 | TXNClear( m_txn ) ; |
0207e969 | 2006 | SetTXNData( value, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5ca0d812 SC |
2007 | } |
2008 | ||
2009 | void wxMacMLTEControl::Remove( long from , long to ) | |
2010 | { | |
4f74e0d1 | 2011 | #ifndef __LP64__ |
0f7817ab | 2012 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 2013 | #endif |
5de694f0 | 2014 | wxMacEditHelper help( m_txn ) ; |
0207e969 | 2015 | TXNSetSelection( m_txn , from , to ) ; |
5ca0d812 SC |
2016 | TXNClear( m_txn ) ; |
2017 | } | |
2018 | ||
2019 | void wxMacMLTEControl::GetSelection( long* from, long* to) const | |
2020 | { | |
2021 | TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ; | |
2022 | } | |
2023 | ||
7d8268a1 | 2024 | void wxMacMLTEControl::SetSelection( long from , long to ) |
5ca0d812 | 2025 | { |
4f74e0d1 | 2026 | #ifndef __LP64__ |
0f7817ab | 2027 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 2028 | #endif |
fef981b4 DS |
2029 | |
2030 | // change the selection | |
5ca0d812 | 2031 | if ((from == -1) && (to == -1)) |
0207e969 | 2032 | TXNSelectAll( m_txn ); |
5ca0d812 | 2033 | else |
fef981b4 | 2034 | TXNSetSelection( m_txn, from, to ); |
0207e969 | 2035 | |
fef981b4 | 2036 | TXNShowSelection( m_txn, kTXNShowStart ); |
5ca0d812 SC |
2037 | } |
2038 | ||
c88b7d28 | 2039 | void wxMacMLTEControl::WriteText( const wxString& str ) |
5ca0d812 | 2040 | { |
5ca0d812 | 2041 | wxString st = str ; |
395480fb | 2042 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
2043 | |
2044 | long start , end , dummy ; | |
0207e969 | 2045 | |
5ca0d812 | 2046 | GetSelection( &start , &dummy ) ; |
4f74e0d1 | 2047 | #ifndef __LP64__ |
5de694f0 | 2048 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 2049 | #endif |
0207e969 | 2050 | |
5de694f0 SC |
2051 | { |
2052 | wxMacEditHelper helper( m_txn ) ; | |
c88b7d28 | 2053 | SetTXNData( st, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5de694f0 | 2054 | } |
a8d2fb31 | 2055 | |
c88b7d28 | 2056 | GetSelection( &dummy, &end ) ; |
fef981b4 DS |
2057 | |
2058 | // TODO: SetStyle( start , end , GetDefaultStyle() ) ; | |
5ca0d812 SC |
2059 | } |
2060 | ||
7d8268a1 | 2061 | void wxMacMLTEControl::Clear() |
5ca0d812 | 2062 | { |
4f74e0d1 | 2063 | #ifndef __LP64__ |
0f7817ab | 2064 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 2065 | #endif |
0207e969 | 2066 | wxMacEditHelper st( m_txn ) ; |
5ca0d812 | 2067 | TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; |
c88b7d28 | 2068 | TXNClear( m_txn ) ; |
5ca0d812 SC |
2069 | } |
2070 | ||
7d8268a1 | 2071 | bool wxMacMLTEControl::CanUndo() const |
5ca0d812 SC |
2072 | { |
2073 | return TXNCanUndo( m_txn , NULL ) ; | |
2074 | } | |
2075 | ||
7d8268a1 | 2076 | void wxMacMLTEControl::Undo() |
5ca0d812 | 2077 | { |
7d8268a1 WS |
2078 | TXNUndo( m_txn ) ; |
2079 | } | |
5ca0d812 | 2080 | |
fef981b4 | 2081 | bool wxMacMLTEControl::CanRedo() const |
5ca0d812 SC |
2082 | { |
2083 | return TXNCanRedo( m_txn , NULL ) ; | |
7d8268a1 | 2084 | } |
5ca0d812 | 2085 | |
7d8268a1 WS |
2086 | void wxMacMLTEControl::Redo() |
2087 | { | |
5ca0d812 SC |
2088 | TXNRedo( m_txn ) ; |
2089 | } | |
2090 | ||
7d8268a1 | 2091 | int wxMacMLTEControl::GetNumberOfLines() const |
5ca0d812 SC |
2092 | { |
2093 | ItemCount lines = 0 ; | |
fef981b4 DS |
2094 | TXNGetLineCount( m_txn, &lines ) ; |
2095 | ||
5ca0d812 SC |
2096 | return lines ; |
2097 | } | |
2098 | ||
2099 | long wxMacMLTEControl::XYToPosition(long x, long y) const | |
2100 | { | |
2101 | Point curpt ; | |
fef981b4 | 2102 | wxTextPos lastpos ; |
7d8268a1 | 2103 | |
fef981b4 | 2104 | // TODO: find a better implementation : while we can get the |
5ca0d812 SC |
2105 | // line metrics of a certain line, we don't get its starting |
2106 | // position, so it would probably be rather a binary search | |
2107 | // for the start position | |
c88b7d28 | 2108 | long xpos = 0, ypos = 0 ; |
5ca0d812 | 2109 | int lastHeight = 0 ; |
5ca0d812 | 2110 | ItemCount n ; |
fef981b4 DS |
2111 | |
2112 | lastpos = GetLastPosition() ; | |
ebe86b1e | 2113 | for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) |
bd3169a7 SC |
2114 | { |
2115 | if ( y == ypos && x == xpos ) | |
2116 | return n ; | |
7d8268a1 | 2117 | |
ffafe6ca | 2118 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2119 | |
2120 | if ( curpt.v > lastHeight ) | |
2121 | { | |
2122 | xpos = 0 ; | |
2123 | if ( n > 0 ) | |
2124 | ++ypos ; | |
0207e969 | 2125 | |
bd3169a7 SC |
2126 | lastHeight = curpt.v ; |
2127 | } | |
2128 | else | |
2129 | ++xpos ; | |
2130 | } | |
a8d2fb31 | 2131 | |
5ca0d812 | 2132 | return 0 ; |
72055702 SC |
2133 | } |
2134 | ||
c88b7d28 | 2135 | bool wxMacMLTEControl::PositionToXY( long pos, long *x, long *y ) const |
72055702 | 2136 | { |
bd3169a7 | 2137 | Point curpt ; |
fef981b4 | 2138 | wxTextPos lastpos ; |
7d8268a1 | 2139 | |
fef981b4 DS |
2140 | if ( y ) |
2141 | *y = 0 ; | |
2142 | if ( x ) | |
2143 | *x = 0 ; | |
7d8268a1 | 2144 | |
fef981b4 | 2145 | lastpos = GetLastPosition() ; |
bd3169a7 SC |
2146 | if ( pos <= lastpos ) |
2147 | { | |
c88b7d28 | 2148 | // TODO: find a better implementation - while we can get the |
bd3169a7 SC |
2149 | // line metrics of a certain line, we don't get its starting |
2150 | // position, so it would probably be rather a binary search | |
2151 | // for the start position | |
0207e969 | 2152 | long xpos = 0, ypos = 0 ; |
bd3169a7 | 2153 | int lastHeight = 0 ; |
bd3169a7 | 2154 | ItemCount n ; |
0207e969 | 2155 | |
ebe86b1e | 2156 | for ( n = 0 ; n <= (ItemCount) pos ; ++n ) |
bd3169a7 | 2157 | { |
ffafe6ca | 2158 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2159 | |
2160 | if ( curpt.v > lastHeight ) | |
2161 | { | |
2162 | xpos = 0 ; | |
2163 | if ( n > 0 ) | |
2164 | ++ypos ; | |
0207e969 | 2165 | |
bd3169a7 SC |
2166 | lastHeight = curpt.v ; |
2167 | } | |
2168 | else | |
2169 | ++xpos ; | |
2170 | } | |
a8d2fb31 | 2171 | |
fef981b4 DS |
2172 | if ( y ) |
2173 | *y = ypos ; | |
2174 | if ( x ) | |
2175 | *x = xpos ; | |
bd3169a7 | 2176 | } |
5ca0d812 | 2177 | |
7d8268a1 | 2178 | return false ; |
72055702 SC |
2179 | } |
2180 | ||
7d8268a1 | 2181 | void wxMacMLTEControl::ShowPosition( long pos ) |
72055702 | 2182 | { |
4f74e0d1 SC |
2183 | Point current, desired ; |
2184 | TXNOffset selstart, selend; | |
fef981b4 | 2185 | |
4f74e0d1 SC |
2186 | TXNGetSelection( m_txn, &selstart, &selend ); |
2187 | TXNOffsetToPoint( m_txn, selstart, ¤t ); | |
2188 | TXNOffsetToPoint( m_txn, pos, &desired ); | |
fef981b4 | 2189 | |
4f74e0d1 SC |
2190 | // TODO: use HIPoints for 10.3 and above |
2191 | ||
2192 | OSErr theErr = noErr; | |
2193 | long dv = desired.v - current.v; | |
2194 | long dh = desired.h - current.h; | |
2195 | TXNShowSelection( m_txn, kTXNShowStart ) ; // NB: should this be kTXNShowStart or kTXNShowEnd ?? | |
2196 | theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, &dv, &dh ); | |
2197 | ||
2198 | // there will be an error returned for classic MLTE implementation when the control is | |
2199 | // invisible, but HITextView works correctly, so we don't assert that one | |
2200 | // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); | |
5ca0d812 SC |
2201 | } |
2202 | ||
fef981b4 | 2203 | void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) |
5ca0d812 SC |
2204 | { |
2205 | #if wxUSE_UNICODE | |
2206 | #if SIZEOF_WCHAR_T == 2 | |
1832043f | 2207 | size_t len = st.length() ; |
fef981b4 | 2208 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end ); |
5ca0d812 | 2209 | #else |
d9d488cf | 2210 | wxMBConvUTF16 converter ; |
c88b7d28 DS |
2211 | ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; |
2212 | UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ; | |
fef981b4 DS |
2213 | converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ; |
2214 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; | |
7d8268a1 | 2215 | free( unibuf ) ; |
587bc950 | 2216 | #endif |
5ca0d812 | 2217 | #else |
c88b7d28 | 2218 | wxCharBuffer text = st.mb_str( wxConvLocal ) ; |
fef981b4 | 2219 | TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; |
7d8268a1 | 2220 | #endif |
72055702 SC |
2221 | } |
2222 | ||
5ca0d812 | 2223 | wxString wxMacMLTEControl::GetLineText(long lineNo) const |
72055702 | 2224 | { |
5ca0d812 | 2225 | wxString line ; |
5ca0d812 | 2226 | |
bd3169a7 | 2227 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2228 | { |
fef981b4 DS |
2229 | Point firstPoint; |
2230 | Fixed lineWidth, lineHeight, currentHeight; | |
2231 | long ypos ; | |
7d8268a1 | 2232 | |
ae25e5cc | 2233 | // get the first possible position in the control |
ae25e5cc | 2234 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2235 | |
ae25e5cc RN |
2236 | // Iterate through the lines until we reach the one we want, |
2237 | // adding to our current y pixel point position | |
fef981b4 DS |
2238 | ypos = 0 ; |
2239 | currentHeight = 0; | |
ae25e5cc | 2240 | while (ypos < lineNo) |
32b5be3d | 2241 | { |
ae25e5cc RN |
2242 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2243 | currentHeight += lineHeight; | |
2244 | } | |
7d8268a1 | 2245 | |
eab19a7c | 2246 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2247 | TXNOffset theOffset; |
2248 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2249 | |
ae25e5cc RN |
2250 | wxString content = GetStringValue() ; |
2251 | Point currentPoint = thePoint; | |
fef981b4 | 2252 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2253 | { |
2254 | line += content[theOffset]; | |
2255 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
21fd5529 | 2256 | } |
21fd5529 | 2257 | } |
fef981b4 | 2258 | |
5ca0d812 | 2259 | return line ; |
72055702 SC |
2260 | } |
2261 | ||
ffafe6ca | 2262 | int wxMacMLTEControl::GetLineLength(long lineNo) const |
72055702 | 2263 | { |
ae25e5cc RN |
2264 | int theLength = 0; |
2265 | ||
bd3169a7 | 2266 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2267 | { |
fef981b4 DS |
2268 | Point firstPoint; |
2269 | Fixed lineWidth, lineHeight, currentHeight; | |
ffafe6ca | 2270 | long ypos; |
7d8268a1 | 2271 | |
ae25e5cc | 2272 | // get the first possible position in the control |
ae25e5cc | 2273 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2274 | |
ae25e5cc RN |
2275 | // Iterate through the lines until we reach the one we want, |
2276 | // adding to our current y pixel point position | |
fef981b4 DS |
2277 | ypos = 0; |
2278 | currentHeight = 0; | |
ae25e5cc | 2279 | while (ypos < lineNo) |
32b5be3d | 2280 | { |
ae25e5cc RN |
2281 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2282 | currentHeight += lineHeight; | |
2283 | } | |
7d8268a1 | 2284 | |
eab19a7c | 2285 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2286 | TXNOffset theOffset; |
2287 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2288 | |
ae25e5cc RN |
2289 | wxString content = GetStringValue() ; |
2290 | Point currentPoint = thePoint; | |
fef981b4 | 2291 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2292 | { |
2293 | ++theLength; | |
2294 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
29e4a190 | 2295 | } |
29e4a190 | 2296 | } |
fef981b4 | 2297 | |
ae25e5cc | 2298 | return theLength ; |
5ca0d812 | 2299 | } |
21fd5529 | 2300 | |
4f74e0d1 SC |
2301 | #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5 |
2302 | ||
5ca0d812 SC |
2303 | // ---------------------------------------------------------------------------- |
2304 | // MLTE control implementation (classic part) | |
2305 | // ---------------------------------------------------------------------------- | |
21fd5529 | 2306 | |
5de694f0 SC |
2307 | // OS X Notes : We still don't have a full replacement for MLTE, so this implementation |
2308 | // has to live on. We have different problems coming from outdated implementations on the | |
2309 | // various OS X versions. Most deal with the scrollbars: they are not correctly embedded | |
2310 | // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is | |
2311 | // no way out, therefore we are using our own implementation and our own scrollbars .... | |
5ca0d812 | 2312 | |
5de694f0 | 2313 | #ifdef __WXMAC_OSX__ |
0f7817ab | 2314 | |
5de694f0 SC |
2315 | TXNScrollInfoUPP gTXNScrollInfoProc = NULL ; |
2316 | ControlActionUPP gTXNScrollActionProc = NULL ; | |
0f7817ab | 2317 | |
fef981b4 DS |
2318 | pascal void wxMacMLTEClassicControl::TXNScrollInfoProc( |
2319 | SInt32 iValue, SInt32 iMaximumValue, | |
0207e969 | 2320 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) |
0f7817ab | 2321 | { |
5de694f0 SC |
2322 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ; |
2323 | SInt32 value = wxMax( iValue , 0 ) ; | |
2324 | SInt32 maximum = wxMax( iMaximumValue , 0 ) ; | |
3dee36ae | 2325 | |
5de694f0 SC |
2326 | if ( iScrollBarOrientation == kTXNHorizontal ) |
2327 | { | |
2328 | if ( mlte->m_sbHorizontal ) | |
2329 | { | |
2330 | SetControl32BitValue( mlte->m_sbHorizontal , value ) ; | |
2331 | SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ; | |
2332 | mlte->m_lastHorizontalValue = value ; | |
2333 | } | |
2334 | } | |
2335 | else if ( iScrollBarOrientation == kTXNVertical ) | |
5ca0d812 | 2336 | { |
5de694f0 SC |
2337 | if ( mlte->m_sbVertical ) |
2338 | { | |
2339 | SetControl32BitValue( mlte->m_sbVertical , value ) ; | |
2340 | SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ; | |
2341 | mlte->m_lastVerticalValue = value ; | |
2342 | } | |
72055702 SC |
2343 | } |
2344 | } | |
2345 | ||
5de694f0 | 2346 | pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) |
72055702 | 2347 | { |
5de694f0 SC |
2348 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ; |
2349 | if ( mlte == NULL ) | |
2350 | return ; | |
3dee36ae | 2351 | |
5de694f0 | 2352 | if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal ) |
3dee36ae WS |
2353 | return ; |
2354 | ||
fef981b4 | 2355 | OSStatus err ; |
3dee36ae WS |
2356 | bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; |
2357 | ||
5de694f0 SC |
2358 | SInt32 minimum = 0 ; |
2359 | SInt32 maximum = GetControl32BitMaximum( controlRef ) ; | |
2360 | SInt32 value = GetControl32BitValue( controlRef ) ; | |
2361 | SInt32 delta = 0; | |
fef981b4 | 2362 | |
5de694f0 SC |
2363 | switch ( partCode ) |
2364 | { | |
2365 | case kControlDownButtonPart : | |
2366 | delta = 10 ; | |
2367 | break ; | |
fef981b4 | 2368 | |
5de694f0 SC |
2369 | case kControlUpButtonPart : |
2370 | delta = -10 ; | |
2371 | break ; | |
fef981b4 | 2372 | |
5de694f0 SC |
2373 | case kControlPageDownPart : |
2374 | delta = GetControlViewSize( controlRef ) ; | |
2375 | break ; | |
fef981b4 | 2376 | |
5de694f0 | 2377 | case kControlPageUpPart : |
fef981b4 | 2378 | delta = -GetControlViewSize( controlRef ) ; |
5de694f0 | 2379 | break ; |
fef981b4 | 2380 | |
5de694f0 | 2381 | case kControlIndicatorPart : |
c88b7d28 | 2382 | delta = value - (isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue) ; |
5de694f0 | 2383 | break ; |
fef981b4 | 2384 | |
5de694f0 SC |
2385 | default : |
2386 | break ; | |
2387 | } | |
fef981b4 | 2388 | |
5de694f0 | 2389 | if ( delta != 0 ) |
e600c175 | 2390 | { |
5de694f0 | 2391 | SInt32 newValue = value ; |
3dee36ae | 2392 | |
5de694f0 SC |
2393 | if ( partCode != kControlIndicatorPart ) |
2394 | { | |
fef981b4 | 2395 | if ( value + delta < minimum ) |
5de694f0 SC |
2396 | delta = minimum - value ; |
2397 | if ( value + delta > maximum ) | |
2398 | delta = maximum - value ; | |
2399 | ||
2400 | SetControl32BitValue( controlRef , value + delta ) ; | |
2401 | newValue = value + delta ; | |
2402 | } | |
3dee36ae | 2403 | |
5de694f0 SC |
2404 | SInt32 verticalDelta = isHorizontal ? 0 : delta ; |
2405 | SInt32 horizontalDelta = isHorizontal ? delta : 0 ; | |
3dee36ae | 2406 | |
0207e969 DS |
2407 | err = TXNScroll( |
2408 | mlte->m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, | |
2409 | &verticalDelta, &horizontalDelta ); | |
ffafe6ca | 2410 | verify_noerr( err ); |
3dee36ae | 2411 | |
5de694f0 SC |
2412 | if ( isHorizontal ) |
2413 | mlte->m_lastHorizontalValue = newValue ; | |
2414 | else | |
2415 | mlte->m_lastVerticalValue = newValue ; | |
5ca0d812 | 2416 | } |
5ca0d812 | 2417 | } |
5de694f0 | 2418 | #endif |
7d8268a1 | 2419 | |
0f7817ab | 2420 | // make correct activations |
fef981b4 | 2421 | void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive) |
0f7817ab SC |
2422 | { |
2423 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
ef4a634b | 2424 | |
5de694f0 | 2425 | wxMacWindowClipper clipper( textctrl ) ; |
c88b7d28 | 2426 | TXNActivate( m_txn, m_txnFrameID, setActive ); |
0f7817ab | 2427 | |
5de694f0 SC |
2428 | ControlRef controlFocus = 0 ; |
2429 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2430 | if ( controlFocus == m_controlRef ) | |
fef981b4 | 2431 | TXNFocus( m_txn, setActive ); |
5de694f0 SC |
2432 | } |
2433 | ||
fef981b4 | 2434 | void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus) |
5de694f0 | 2435 | { |
0207e969 | 2436 | TXNFocus( m_txn, setFocus ); |
5ca0d812 | 2437 | } |
1fa29bdc | 2438 | |
3dee36ae | 2439 | // guards against inappropriate redraw (hidden objects drawing onto window) |
0f7817ab | 2440 | |
fef981b4 | 2441 | void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis) |
0f7817ab | 2442 | { |
789ae0cf SC |
2443 | ControlRef controlFocus = 0 ; |
2444 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
3dee36ae | 2445 | |
fef981b4 | 2446 | if ( !vis && (controlFocus == m_controlRef ) ) |
789ae0cf | 2447 | SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; |
3dee36ae | 2448 | |
4611a719 | 2449 | TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; |
c88b7d28 | 2450 | TXNControlData iControlData[1] = { { (UInt32)false } }; |
bd2213c2 | 2451 | |
fef981b4 | 2452 | verify_noerr( TXNGetTXNObjectControls( m_txn , 1, iControlTags, iControlData ) ) ; |
3dee36ae | 2453 | |
bd2213c2 SC |
2454 | if ( iControlData[0].uValue != vis ) |
2455 | { | |
2456 | iControlData[0].uValue = vis ; | |
0207e969 | 2457 | verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1, iControlTags, iControlData ) ) ; |
bd2213c2 | 2458 | } |
fef981b4 | 2459 | |
0207e969 DS |
2460 | // currently, we always clip as partial visibility (overlapped) visibility is also a problem, |
2461 | // if we run into further problems we might set the FrameBounds to an empty rect here | |
5ca0d812 | 2462 | } |
1fa29bdc | 2463 | |
0f7817ab | 2464 | // make sure that the TXNObject is at the right position |
5de694f0 | 2465 | |
3dee36ae | 2466 | void wxMacMLTEClassicControl::MacUpdatePosition() |
0f7817ab | 2467 | { |
c88b7d28 | 2468 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
0f7817ab SC |
2469 | if ( textctrl == NULL ) |
2470 | return ; | |
7d8268a1 | 2471 | |
0f7817ab | 2472 | Rect bounds ; |
c88b7d28 | 2473 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2474 | |
ba75e603 SC |
2475 | wxRect visRect = textctrl->MacGetClippedClientRect() ; |
2476 | Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; | |
2477 | int x , y ; | |
2478 | x = y = 0 ; | |
2479 | textctrl->MacWindowToRootWindow( &x , &y ) ; | |
2480 | OffsetRect( &visBounds , x , y ) ; | |
3dee36ae | 2481 | |
c88b7d28 | 2482 | if ( !EqualRect( &bounds, &m_txnControlBounds ) || !EqualRect( &visBounds, &m_txnVisBounds ) ) |
0f7817ab | 2483 | { |
0f7817ab | 2484 | m_txnControlBounds = bounds ; |
ba75e603 | 2485 | m_txnVisBounds = visBounds ; |
c88b7d28 | 2486 | wxMacWindowClipper cl( textctrl ) ; |
5de694f0 | 2487 | |
4e477040 SC |
2488 | #ifdef __WXMAC_OSX__ |
2489 | if ( m_sbHorizontal || m_sbVertical ) | |
2490 | { | |
5de694f0 SC |
2491 | int w = bounds.right - bounds.left ; |
2492 | int h = bounds.bottom - bounds.top ; | |
4e477040 SC |
2493 | |
2494 | if ( m_sbHorizontal ) | |
2495 | { | |
2496 | Rect sbBounds ; | |
5de694f0 | 2497 | |
4e477040 | 2498 | sbBounds.left = -1 ; |
5de694f0 SC |
2499 | sbBounds.top = h - 14 ; |
2500 | sbBounds.right = w + 1 ; | |
2501 | sbBounds.bottom = h + 1 ; | |
3dee36ae | 2502 | |
4e477040 | 2503 | SetControlBounds( m_sbHorizontal , &sbBounds ) ; |
5de694f0 | 2504 | SetControlViewSize( m_sbHorizontal , w ) ; |
4e477040 | 2505 | } |
0207e969 | 2506 | |
4e477040 SC |
2507 | if ( m_sbVertical ) |
2508 | { | |
2509 | Rect sbBounds ; | |
5de694f0 SC |
2510 | |
2511 | sbBounds.left = w - 14 ; | |
4e477040 | 2512 | sbBounds.top = -1 ; |
5de694f0 | 2513 | sbBounds.right = w + 1 ; |
fef981b4 | 2514 | sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; |
3dee36ae | 2515 | |
4e477040 | 2516 | SetControlBounds( m_sbVertical , &sbBounds ) ; |
5de694f0 | 2517 | SetControlViewSize( m_sbVertical , h ) ; |
4e477040 SC |
2518 | } |
2519 | } | |
3dee36ae | 2520 | |
c447d5a9 SC |
2521 | Rect oldviewRect ; |
2522 | TXNLongRect olddestRect ; | |
2523 | TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ; | |
3dee36ae | 2524 | |
c447d5a9 | 2525 | Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2526 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2527 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
c447d5a9 | 2528 | TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2529 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2530 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
3dee36ae | 2531 | |
c447d5a9 SC |
2532 | if ( olddestRect.right >= 10000 ) |
2533 | destRect.right = destRect.left + 32000 ; | |
3dee36ae | 2534 | |
c447d5a9 SC |
2535 | if ( olddestRect.bottom >= 0x20000000 ) |
2536 | destRect.bottom = destRect.top + 0x40000000 ; | |
3dee36ae WS |
2537 | |
2538 | SectRect( &viewRect , &visBounds , &viewRect ) ; | |
823c4e96 | 2539 | TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ; |
fef981b4 DS |
2540 | |
2541 | #if 0 | |
2542 | TXNSetFrameBounds( | |
2543 | m_txn, | |
2544 | m_txnControlBounds.top, | |
2545 | m_txnControlBounds.left, | |
2546 | m_txnControlBounds.bottom - (m_sbHorizontal ? 14 : 0), | |
2547 | m_txnControlBounds.right - (m_sbVertical ? 14 : 0), | |
2548 | m_txnFrameID ); | |
2549 | #endif | |
5de694f0 | 2550 | #else |
3dee36ae | 2551 | |
c88b7d28 DS |
2552 | TXNSetFrameBounds( |
2553 | m_txn, m_txnControlBounds.top, m_txnControlBounds.left, | |
2554 | wxMax( m_txnControlBounds.bottom, m_txnControlBounds.top ), | |
2555 | wxMax( m_txnControlBounds.right, m_txnControlBounds.left ), m_txnFrameID ); | |
24eef584 | 2556 | #endif |
c88b7d28 DS |
2557 | |
2558 | // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a | |
5de694f0 SC |
2559 | // movement, therefore we have to force it |
2560 | ||
fef981b4 | 2561 | // this problem has been reported in OSX as well, so we use this here once again |
0207e969 | 2562 | |
5de694f0 | 2563 | TXNLongRect textRect ; |
3dee36ae | 2564 | TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; |
5de694f0 | 2565 | if ( textRect.left < m_txnControlBounds.left ) |
fef981b4 | 2566 | TXNShowSelection( m_txn , kTXNShowStart ) ; |
e600c175 | 2567 | } |
5ca0d812 SC |
2568 | } |
2569 | ||
3dee36ae | 2570 | void wxMacMLTEClassicControl::SetRect( Rect *r ) |
0f7817ab SC |
2571 | { |
2572 | wxMacControl::SetRect( r ) ; | |
2573 | MacUpdatePosition() ; | |
2574 | } | |
2575 | ||
3dee36ae | 2576 | void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) |
24260aae | 2577 | { |
c88b7d28 | 2578 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2579 | if ( textctrl == NULL ) |
e600c175 | 2580 | return ; |
7d8268a1 | 2581 | |
5ca0d812 SC |
2582 | if ( textctrl->MacIsReallyShown() ) |
2583 | { | |
2584 | wxMacWindowClipper clipper( textctrl ) ; | |
0f7817ab | 2585 | TXNDraw( m_txn , NULL ) ; |
e600c175 | 2586 | } |
5ca0d812 SC |
2587 | } |
2588 | ||
3dee36ae | 2589 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
24260aae SC |
2590 | { |
2591 | Point where = { y , x } ; | |
a8d2fb31 | 2592 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2593 | |
0207e969 | 2594 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2595 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
72055702 | 2596 | { |
fef981b4 DS |
2597 | if (PtInRect( where, &m_txnControlBounds )) |
2598 | { | |
5de694f0 | 2599 | result = kControlEditTextPart ; |
fef981b4 | 2600 | } |
7d8268a1 | 2601 | else |
3556e470 SC |
2602 | { |
2603 | // sometimes we get the coords also in control local coordinates, therefore test again | |
ab346e1c VZ |
2604 | int x = 0 , y = 0 ; |
2605 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2606 | where.h += x ; | |
2607 | where.v += y ; | |
fef981b4 | 2608 | |
0207e969 | 2609 | if (PtInRect( where, &m_txnControlBounds )) |
5de694f0 | 2610 | result = kControlEditTextPart ; |
3556e470 | 2611 | } |
5ca0d812 | 2612 | } |
a8d2fb31 | 2613 | |
5ca0d812 SC |
2614 | return result; |
2615 | } | |
2616 | ||
3dee36ae | 2617 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc ) |
24260aae | 2618 | { |
a8d2fb31 | 2619 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2620 | |
0207e969 | 2621 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2622 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
7d8268a1 | 2623 | { |
a8d2fb31 | 2624 | Point startPt = { y , x } ; |
ab346e1c | 2625 | |
5ca0d812 | 2626 | // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them |
ab346e1c VZ |
2627 | int x = 0 , y = 0 ; |
2628 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2629 | startPt.h += x ; | |
2630 | startPt.v += y ; | |
7d8268a1 | 2631 | |
24260aae | 2632 | switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v )) |
5ca0d812 | 2633 | { |
5de694f0 | 2634 | case kControlEditTextPart : |
7d8268a1 WS |
2635 | { |
2636 | wxMacWindowClipper clipper( textctrl ) ; | |
7d8268a1 | 2637 | EventRecord rec ; |
c88b7d28 | 2638 | |
7d8268a1 | 2639 | ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; |
24260aae | 2640 | TXNClick( m_txn, &rec ); |
7d8268a1 | 2641 | } |
fef981b4 | 2642 | break; |
a8d2fb31 | 2643 | |
fef981b4 DS |
2644 | default : |
2645 | break; | |
5ca0d812 SC |
2646 | } |
2647 | } | |
a8d2fb31 DS |
2648 | |
2649 | return result; | |
5ca0d812 SC |
2650 | } |
2651 | ||
3dee36ae | 2652 | void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() |
24260aae | 2653 | { |
c88b7d28 | 2654 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 SC |
2655 | if ( textctrl == NULL ) |
2656 | return ; | |
24260aae | 2657 | |
3dee36ae | 2658 | if (textctrl->MacIsReallyShown()) |
24260aae | 2659 | { |
3dee36ae | 2660 | if (IsControlActive(m_controlRef)) |
24260aae | 2661 | { |
5ca0d812 | 2662 | Point mousep; |
7d8268a1 | 2663 | |
5ca0d812 SC |
2664 | wxMacWindowClipper clipper( textctrl ) ; |
2665 | GetMouse(&mousep); | |
5de694f0 SC |
2666 | |
2667 | TXNIdle(m_txn); | |
2668 | ||
3dee36ae | 2669 | if (PtInRect(mousep, &m_txnControlBounds)) |
24260aae | 2670 | { |
fef981b4 DS |
2671 | RgnHandle theRgn = NewRgn(); |
2672 | RectRgn(theRgn, &m_txnControlBounds); | |
5de694f0 SC |
2673 | TXNAdjustCursor(m_txn, theRgn); |
2674 | DisposeRgn(theRgn); | |
72055702 | 2675 | } |
5ca0d812 SC |
2676 | } |
2677 | } | |
2678 | } | |
72055702 | 2679 | |
3dee36ae | 2680 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
24260aae | 2681 | { |
c88b7d28 | 2682 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2683 | if ( textctrl == NULL ) |
a8d2fb31 | 2684 | return kControlNoPart; |
7d8268a1 | 2685 | |
5de694f0 | 2686 | wxMacWindowClipper clipper( textctrl ) ; |
ef4a634b | 2687 | |
5de694f0 SC |
2688 | EventRecord ev ; |
2689 | memset( &ev , 0 , sizeof( ev ) ) ; | |
2690 | ev.what = keyDown ; | |
2691 | ev.modifiers = modifiers ; | |
fef981b4 DS |
2692 | ev.message = ((keyCode << 8) & keyCodeMask) | (charCode & charCodeMask); |
2693 | TXNKeyDown( m_txn , &ev ); | |
3dee36ae | 2694 | |
5de694f0 SC |
2695 | return kControlEntireControl; |
2696 | } | |
24260aae | 2697 | |
c88b7d28 | 2698 | void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating) |
24260aae | 2699 | { |
5de694f0 | 2700 | MacActivatePaneText( activating ); |
72055702 SC |
2701 | } |
2702 | ||
3dee36ae | 2703 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) |
24260aae | 2704 | { |
c88b7d28 | 2705 | ControlPartCode focusResult = kControlFocusNoPart; |
7d8268a1 | 2706 | |
c88b7d28 | 2707 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2708 | if ( textctrl == NULL ) |
c88b7d28 | 2709 | return focusResult; |
0f7817ab SC |
2710 | |
2711 | wxMacWindowClipper clipper( textctrl ) ; | |
3dee36ae | 2712 | |
a8d2fb31 | 2713 | ControlRef controlFocus = NULL ; |
5de694f0 SC |
2714 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; |
2715 | bool wasFocused = ( controlFocus == m_controlRef ) ; | |
2716 | ||
3dee36ae | 2717 | switch (action) |
24260aae | 2718 | { |
5de694f0 SC |
2719 | case kControlFocusPrevPart: |
2720 | case kControlFocusNextPart: | |
0207e969 DS |
2721 | MacFocusPaneText( !wasFocused ); |
2722 | focusResult = (!wasFocused ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart); | |
5de694f0 | 2723 | break; |
3dee36ae | 2724 | |
5ca0d812 | 2725 | case kControlFocusNoPart: |
5de694f0 | 2726 | default: |
a8d2fb31 | 2727 | MacFocusPaneText( false ); |
5ca0d812 SC |
2728 | focusResult = kControlFocusNoPart; |
2729 | break; | |
5ca0d812 | 2730 | } |
0f7817ab | 2731 | |
5ca0d812 | 2732 | return focusResult; |
72055702 SC |
2733 | } |
2734 | ||
24260aae SC |
2735 | void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info ) |
2736 | { | |
2737 | } | |
2738 | ||
0f7817ab | 2739 | wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
2740 | const wxString& str, |
2741 | const wxPoint& pos, | |
2742 | const wxSize& size, long style ) | |
2743 | : wxMacMLTEControl( wxPeer ) | |
72055702 | 2744 | { |
5ca0d812 SC |
2745 | m_font = wxPeer->GetFont() ; |
2746 | m_windowStyle = style ; | |
7d8268a1 | 2747 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
72055702 | 2748 | |
c88b7d28 | 2749 | short featureSet = |
0207e969 DS |
2750 | kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle |
2751 | | kControlWantsActivate | kControlHandlesTracking | |
2752 | // | kControlHasSpecialBackground | |
2753 | | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; | |
72055702 | 2754 | |
ffafe6ca DS |
2755 | OSStatus err = ::CreateUserPaneControl( |
2756 | MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), | |
2757 | &bounds, featureSet, &m_controlRef ); | |
2758 | verify_noerr( err ); | |
7d8268a1 | 2759 | |
0f7817ab | 2760 | DoCreate(); |
7d8268a1 | 2761 | |
a8d2fb31 | 2762 | AdjustCreationAttributes( *wxWHITE , true ) ; |
5ca0d812 | 2763 | |
bd2213c2 SC |
2764 | MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; |
2765 | ||
24eef584 SC |
2766 | { |
2767 | wxString st = str ; | |
2768 | wxMacConvertNewlines10To13( &st ) ; | |
2769 | wxMacWindowClipper clipper( m_peer ) ; | |
2770 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; | |
0207e969 | 2771 | TXNSetSelection( m_txn, 0, 0 ) ; |
24eef584 | 2772 | } |
72055702 SC |
2773 | } |
2774 | ||
5ca0d812 | 2775 | wxMacMLTEClassicControl::~wxMacMLTEClassicControl() |
72055702 | 2776 | { |
0207e969 | 2777 | TXNDeleteObject( m_txn ); |
5de694f0 | 2778 | m_txn = NULL ; |
72055702 SC |
2779 | } |
2780 | ||
7d8268a1 | 2781 | void wxMacMLTEClassicControl::VisibilityChanged(bool shown) |
72055702 | 2782 | { |
0f7817ab | 2783 | MacSetObjectVisibility( shown ) ; |
4e477040 SC |
2784 | wxMacControl::VisibilityChanged( shown ) ; |
2785 | } | |
2786 | ||
2787 | void wxMacMLTEClassicControl::SuperChangedPosition() | |
2788 | { | |
2789 | MacUpdatePosition() ; | |
2790 | wxMacControl::SuperChangedPosition() ; | |
72055702 SC |
2791 | } |
2792 | ||
24260aae SC |
2793 | #ifdef __WXMAC_OSX__ |
2794 | ||
5de694f0 SC |
2795 | ControlUserPaneDrawUPP gTPDrawProc = NULL; |
2796 | ControlUserPaneHitTestUPP gTPHitProc = NULL; | |
2797 | ControlUserPaneTrackingUPP gTPTrackProc = NULL; | |
2798 | ControlUserPaneIdleUPP gTPIdleProc = NULL; | |
2799 | ControlUserPaneKeyDownUPP gTPKeyProc = NULL; | |
2800 | ControlUserPaneActivateUPP gTPActivateProc = NULL; | |
2801 | ControlUserPaneFocusUPP gTPFocusProc = NULL; | |
2802 | ||
24260aae SC |
2803 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
2804 | { | |
2805 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2806 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2807 | if ( win ) |
ffafe6ca | 2808 | win->MacControlUserPaneDrawProc( part ) ; |
24260aae SC |
2809 | } |
2810 | ||
c7fe80e2 | 2811 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) |
24260aae SC |
2812 | { |
2813 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2814 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2815 | if ( win ) |
ffafe6ca | 2816 | return win->MacControlUserPaneHitTestProc( where.h , where.v ) ; |
24260aae SC |
2817 | else |
2818 | return kControlNoPart ; | |
2819 | } | |
2820 | ||
c7fe80e2 | 2821 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) |
24260aae SC |
2822 | { |
2823 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2824 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2825 | if ( win ) |
ffafe6ca | 2826 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc ) ; |
24260aae SC |
2827 | else |
2828 | return kControlNoPart ; | |
2829 | } | |
2830 | ||
2831 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
2832 | { | |
2833 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2834 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2835 | if ( win ) |
2836 | win->MacControlUserPaneIdleProc() ; | |
2837 | } | |
2838 | ||
2839 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
2840 | { | |
2841 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2842 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2843 | if ( win ) |
ffafe6ca | 2844 | return win->MacControlUserPaneKeyDownProc( keyCode, charCode, modifiers ) ; |
24260aae SC |
2845 | else |
2846 | return kControlNoPart ; | |
2847 | } | |
2848 | ||
2849 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
2850 | { | |
2851 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2852 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2853 | if ( win ) |
ffafe6ca | 2854 | win->MacControlUserPaneActivateProc( activating ) ; |
24260aae SC |
2855 | } |
2856 | ||
2857 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
2858 | { | |
2859 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2860 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2861 | if ( win ) |
ffafe6ca | 2862 | return win->MacControlUserPaneFocusProc( action ) ; |
24260aae SC |
2863 | else |
2864 | return kControlNoPart ; | |
2865 | } | |
2866 | ||
fef981b4 | 2867 | #if 0 |
24260aae SC |
2868 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) |
2869 | { | |
2870 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2871 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2872 | if ( win ) |
2873 | win->MacControlUserPaneBackgroundProc(info) ; | |
2874 | } | |
2875 | #endif | |
2876 | ||
fef981b4 DS |
2877 | #endif // __WXMAC_OSX__ |
2878 | ||
5de694f0 SC |
2879 | // TXNRegisterScrollInfoProc |
2880 | ||
5ca0d812 | 2881 | OSStatus wxMacMLTEClassicControl::DoCreate() |
2b5f62a0 | 2882 | { |
5ca0d812 | 2883 | Rect bounds; |
5ca0d812 | 2884 | OSStatus err = noErr ; |
7d8268a1 | 2885 | |
fef981b4 | 2886 | // set up our globals |
24260aae SC |
2887 | #ifdef __WXMAC_OSX__ |
2888 | if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc); | |
2889 | if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc); | |
2890 | if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc); | |
2891 | if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc); | |
2892 | if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc); | |
2893 | if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc); | |
2894 | if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc); | |
5de694f0 SC |
2895 | |
2896 | if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ; | |
2897 | if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ; | |
24260aae | 2898 | #endif |
7d8268a1 | 2899 | |
fef981b4 | 2900 | // set the initial settings for our private data |
7d8268a1 | 2901 | |
a8d2fb31 | 2902 | m_txnWindow = GetControlOwner(m_controlRef); |
5de694f0 | 2903 | m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow); |
7d8268a1 | 2904 | |
24260aae | 2905 | #ifdef __WXMAC_OSX__ |
fef981b4 | 2906 | // set up the user pane procedures |
5ca0d812 SC |
2907 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); |
2908 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); | |
2909 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); | |
2910 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); | |
2911 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); | |
2912 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); | |
2913 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); | |
24260aae | 2914 | #endif |
c88b7d28 | 2915 | |
fef981b4 | 2916 | // calculate the rectangles used by the control |
c88b7d28 | 2917 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2918 | |
0f7817ab | 2919 | m_txnControlBounds = bounds ; |
ba75e603 | 2920 | m_txnVisBounds = bounds ; |
3dee36ae | 2921 | |
fef981b4 DS |
2922 | CGrafPtr origPort ; |
2923 | GDHandle origDev ; | |
7d8268a1 | 2924 | |
c88b7d28 | 2925 | GetGWorld( &origPort, &origDev ) ; |
fef981b4 | 2926 | SetPort( m_txnPort ); |
7d8268a1 | 2927 | |
fef981b4 | 2928 | // create the new edit field |
c88b7d28 | 2929 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ); |
7d8268a1 | 2930 | |
4e477040 | 2931 | #ifdef __WXMAC_OSX__ |
fef981b4 DS |
2932 | // the scrollbars are not correctly embedded but are inserted at the root: |
2933 | // this gives us problems as we have erratic redraws even over the structure area | |
4e477040 | 2934 | |
5de694f0 SC |
2935 | m_sbHorizontal = 0 ; |
2936 | m_sbVertical = 0 ; | |
2937 | m_lastHorizontalValue = 0 ; | |
2938 | m_lastVerticalValue = 0 ; | |
3dee36ae | 2939 | |
5de694f0 SC |
2940 | Rect sb = { 0 , 0 , 0 , 0 } ; |
2941 | if ( frameOptions & kTXNWantVScrollBarMask ) | |
2942 | { | |
c88b7d28 DS |
2943 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbVertical ); |
2944 | SetControlReference( m_sbVertical, (SInt32)this ); | |
5de694f0 | 2945 | SetControlAction( m_sbVertical, gTXNScrollActionProc ); |
c88b7d28 DS |
2946 | ShowControl( m_sbVertical ); |
2947 | EmbedControl( m_sbVertical , m_controlRef ); | |
2948 | frameOptions &= ~kTXNWantVScrollBarMask; | |
5de694f0 | 2949 | } |
fef981b4 | 2950 | |
5de694f0 SC |
2951 | if ( frameOptions & kTXNWantHScrollBarMask ) |
2952 | { | |
c88b7d28 DS |
2953 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbHorizontal ); |
2954 | SetControlReference( m_sbHorizontal, (SInt32)this ); | |
5de694f0 | 2955 | SetControlAction( m_sbHorizontal, gTXNScrollActionProc ); |
c88b7d28 DS |
2956 | ShowControl( m_sbHorizontal ); |
2957 | EmbedControl( m_sbHorizontal, m_controlRef ); | |
5de694f0 SC |
2958 | frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask); |
2959 | } | |
4e477040 SC |
2960 | |
2961 | #endif | |
2962 | ||
ffafe6ca DS |
2963 | err = TXNNewObject( |
2964 | NULL, m_txnWindow, &bounds, frameOptions, | |
2965 | kTXNTextEditStyleFrameType, kTXNTextensionFile, kTXNSystemDefaultEncoding, | |
2966 | &m_txn, &m_txnFrameID, NULL ); | |
2967 | verify_noerr( err ); | |
3dee36ae | 2968 | |
fef981b4 DS |
2969 | #if 0 |
2970 | TXNControlTag iControlTags[] = { kTXNUseCarbonEvents }; | |
c88b7d28 | 2971 | TXNControlData iControlData[] = { { (UInt32)&cInfo } }; |
fef981b4 DS |
2972 | int toptag = WXSIZEOF( iControlTags ) ; |
2973 | TXNCarbonEventInfo cInfo ; | |
55d0b180 SC |
2974 | cInfo.useCarbonEvents = false ; |
2975 | cInfo.filler = 0 ; | |
2976 | cInfo.flags = 0 ; | |
2977 | cInfo.fDictionary = NULL ; | |
2978 | ||
c88b7d28 | 2979 | verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ); |
fef981b4 | 2980 | #endif |
55d0b180 | 2981 | |
4e477040 | 2982 | #ifdef __WXMAC_OSX__ |
c88b7d28 | 2983 | TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32)this ); |
4e477040 SC |
2984 | #endif |
2985 | ||
0f7817ab | 2986 | SetGWorld( origPort , origDev ) ; |
ffafe6ca | 2987 | |
5ca0d812 | 2988 | return err; |
facd6764 | 2989 | } |
4f74e0d1 | 2990 | #endif |
facd6764 | 2991 | |
5ca0d812 SC |
2992 | // ---------------------------------------------------------------------------- |
2993 | // MLTE control implementation (OSX part) | |
2994 | // ---------------------------------------------------------------------------- | |
facd6764 | 2995 | |
5ca0d812 | 2996 | #if TARGET_API_MAC_OSX |
facd6764 | 2997 | |
3b92f0e0 SC |
2998 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
2999 | ||
09660720 | 3000 | // tiger multi-line textcontrols with no CR in the entire content |
9eddec69 | 3001 | // don't scroll automatically, so we need a hack. |
09660720 SC |
3002 | // This attempt only works 'before' the key (ie before CallNextEventHandler) |
3003 | // is processed, thus the scrolling always occurs one character too late, but | |
3004 | // better than nothing ... | |
3005 | ||
3006 | static const EventTypeSpec eventList[] = | |
3007 | { | |
3008 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
3009 | } ; | |
9eddec69 | 3010 | |
09660720 SC |
3011 | static pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
3012 | { | |
3013 | OSStatus result = eventNotHandledErr ; | |
3014 | wxMacMLTEHIViewControl* focus = (wxMacMLTEHIViewControl*) data ; | |
9eddec69 | 3015 | |
09660720 SC |
3016 | switch ( GetEventKind( event ) ) |
3017 | { | |
3018 | case kEventTextInputUnicodeForKeyEvent : | |
3019 | { | |
3020 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
3021 | { | |
3022 | TXNOffset from , to ; | |
3023 | TXNGetSelection( focus->GetTXNObject() , &from , &to ) ; | |
3024 | if ( from == to ) | |
3025 | TXNShowSelection( focus->GetTXNObject() , kTXNShowStart ); | |
3026 | } | |
3027 | result = CallNextEventHandler(handler,event); | |
3028 | break; | |
3029 | } | |
3030 | default: | |
3031 | break ; | |
3032 | } | |
9eddec69 | 3033 | |
09660720 SC |
3034 | return result ; |
3035 | } | |
3036 | ||
3037 | static pascal OSStatus wxMacTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
3038 | { | |
3039 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 3040 | |
09660720 SC |
3041 | switch ( GetEventClass( event ) ) |
3042 | { | |
3043 | case kEventClassTextInput : | |
3044 | result = wxMacUnicodeTextEventHandler( handler , event , data ) ; | |
3045 | break ; | |
9eddec69 | 3046 | |
09660720 SC |
3047 | default : |
3048 | break ; | |
3049 | } | |
3050 | return result ; | |
3051 | } | |
3052 | ||
3053 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler ) | |
3054 | ||
0f7817ab | 3055 | wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
3056 | const wxString& str, |
3057 | const wxPoint& pos, | |
3058 | const wxSize& size, long style ) : wxMacMLTEControl( wxPeer ) | |
facd6764 | 3059 | { |
5ca0d812 SC |
3060 | m_font = wxPeer->GetFont() ; |
3061 | m_windowStyle = style ; | |
7d8268a1 | 3062 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 3063 | wxString st = str ; |
395480fb | 3064 | wxMacConvertNewlines10To13( &st ) ; |
7d8268a1 | 3065 | |
ffafe6ca DS |
3066 | HIRect hr = { |
3067 | { bounds.left , bounds.top }, | |
3068 | { bounds.right - bounds.left, bounds.bottom - bounds.top } } ; | |
facd6764 | 3069 | |
5ca0d812 SC |
3070 | m_scrollView = NULL ; |
3071 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; | |
0207e969 | 3072 | if ( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask) ) |
5ca0d812 | 3073 | { |
0207e969 DS |
3074 | HIScrollViewCreate( |
3075 | (frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | |
3076 | | (frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll : 0) , | |
3077 | &m_scrollView ) ; | |
7d8268a1 WS |
3078 | |
3079 | HIViewSetFrame( m_scrollView, &hr ); | |
3080 | HIViewSetVisible( m_scrollView, true ); | |
5ca0d812 | 3081 | } |
7d8268a1 | 3082 | |
5ca0d812 SC |
3083 | m_textView = NULL ; |
3084 | HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ; | |
0207e969 | 3085 | m_txn = HITextViewGetTXNObject( m_textView ) ; |
5ca0d812 SC |
3086 | HIViewSetVisible( m_textView , true ) ; |
3087 | if ( m_scrollView ) | |
3088 | { | |
3089 | HIViewAddSubview( m_scrollView , m_textView ) ; | |
3090 | m_controlRef = m_scrollView ; | |
0207e969 | 3091 | wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; |
5ca0d812 SC |
3092 | } |
3093 | else | |
3094 | { | |
7d8268a1 | 3095 | HIViewSetFrame( m_textView, &hr ); |
5ca0d812 SC |
3096 | m_controlRef = m_textView ; |
3097 | } | |
7d8268a1 | 3098 | |
0f7817ab | 3099 | AdjustCreationAttributes( *wxWHITE , true ) ; |
4f74e0d1 | 3100 | #ifndef __LP64__ |
0f7817ab | 3101 | wxMacWindowClipper c( m_peer ) ; |
4f74e0d1 | 3102 | #endif |
5ca0d812 SC |
3103 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; |
3104 | ||
fef981b4 DS |
3105 | TXNSetSelection( m_txn, 0, 0 ); |
3106 | TXNShowSelection( m_txn, kTXNShowStart ); | |
09660720 SC |
3107 | |
3108 | InstallControlEventHandler( m_textView , GetwxMacTextControlEventHandlerUPP(), | |
3109 | GetEventTypeCount(eventList), eventList, this, | |
3110 | &m_textEventHandlerRef); | |
3111 | } | |
3112 | ||
3113 | wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() | |
3114 | { | |
3115 | ::RemoveEventHandler( m_textEventHandlerRef ) ; | |
facd6764 SC |
3116 | } |
3117 | ||
7d8268a1 | 3118 | OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) |
facd6764 | 3119 | { |
fef981b4 | 3120 | return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, focusPart ) ; |
facd6764 SC |
3121 | } |
3122 | ||
7d8268a1 | 3123 | bool wxMacMLTEHIViewControl::HasFocus() const |
facd6764 | 3124 | { |
5ca0d812 SC |
3125 | ControlRef control ; |
3126 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
3127 | return control == m_textView ; | |
facd6764 SC |
3128 | } |
3129 | ||
44aa865d SC |
3130 | void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) |
3131 | { | |
3132 | wxMacMLTEControl::SetBackground( brush ) ; | |
fef981b4 DS |
3133 | |
3134 | #if 0 | |
44aa865d SC |
3135 | CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); |
3136 | RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; | |
3137 | ||
3138 | float component[4] ; | |
3139 | component[0] = col.red / 65536.0 ; | |
3140 | component[1] = col.green / 65536.0 ; | |
3141 | component[2] = col.blue / 65536.0 ; | |
3142 | component[3] = 1.0 ; // alpha | |
0207e969 | 3143 | |
ffafe6ca DS |
3144 | CGColorRef color = CGColorCreate( rgbSpace , component ); |
3145 | HITextViewSetBackgroundColor( m_textView , color ); | |
44aa865d | 3146 | CGColorSpaceRelease( rgbSpace ); |
fef981b4 | 3147 | #endif |
44aa865d SC |
3148 | } |
3149 | ||
3b92f0e0 SC |
3150 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
3151 | ||
3152 | ||
fedad417 | 3153 | #endif |
5ca0d812 SC |
3154 | |
3155 | #endif // wxUSE_TEXTCTRL |