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