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