]>
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" |
88a7a4e1 | 27 | #endif |
5ca0d812 | 28 | |
f5c6eb5c | 29 | #ifdef __DARWIN__ |
88a7a4e1 WS |
30 | #include <sys/types.h> |
31 | #include <sys/stat.h> | |
e9576ca5 | 32 | #else |
88a7a4e1 | 33 | #include <stat.h> |
e9576ca5 | 34 | #endif |
2b5f62a0 VZ |
35 | |
36 | #if wxUSE_STD_IOSTREAM | |
37 | #if wxUSE_IOSTREAMH | |
38 | #include <fstream.h> | |
39 | #else | |
40 | #include <fstream> | |
41 | #endif | |
42 | #endif | |
e9576ca5 | 43 | |
422644a3 | 44 | #include "wx/toplevel.h" |
e9576ca5 | 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 | |
5ca0d812 | 121 | ~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 ) ; |
5ca0d812 | 180 | ~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 ) ; | |
09660720 | 308 | ~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 ) ; | |
329 | ~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 ) ; | |
365 | ~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 | |
5ca0d812 | 417 | IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) |
72055702 | 418 | |
5ca0d812 | 419 | BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) |
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 | { | |
965 | wxWindow *parent = GetParent(); | |
fef981b4 DS |
966 | while ( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) |
967 | { | |
968 | parent = parent->GetParent() ; | |
5ca0d812 | 969 | } |
fef981b4 | 970 | |
5ca0d812 SC |
971 | if ( parent && parent->GetDefaultItem() ) |
972 | { | |
fef981b4 | 973 | wxButton *def = wxDynamicCast(parent->GetDefaultItem(), wxButton); |
5ca0d812 SC |
974 | if ( def && def->IsEnabled() ) |
975 | { | |
976 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); | |
977 | event.SetEventObject(def); | |
978 | def->Command(event); | |
fef981b4 | 979 | |
5ca0d812 | 980 | return ; |
3dee36ae | 981 | } |
5ca0d812 SC |
982 | } |
983 | ||
984 | // this will make wxWidgets eat the ENTER key so that | |
0207e969 | 985 | // we actually prevent line wrapping in a single line text control |
7d8268a1 | 986 | eat_key = true; |
5ca0d812 | 987 | } |
5ca0d812 | 988 | break; |
facd6764 | 989 | |
5ca0d812 SC |
990 | case WXK_TAB: |
991 | if ( !(m_windowStyle & wxTE_PROCESS_TAB)) | |
992 | { | |
993 | int flags = 0; | |
994 | if (!event.ShiftDown()) | |
995 | flags |= wxNavigationKeyEvent::IsForward ; | |
996 | if (event.ControlDown()) | |
997 | flags |= wxNavigationKeyEvent::WinChange ; | |
998 | Navigate(flags); | |
fef981b4 | 999 | |
5ca0d812 SC |
1000 | return; |
1001 | } | |
1002 | else | |
1003 | { | |
fef981b4 DS |
1004 | // This is necessary (don't know why); |
1005 | // otherwise the tab will not be inserted. | |
5ca0d812 SC |
1006 | WriteText(wxT("\t")); |
1007 | } | |
a8d2fb31 | 1008 | break; |
7d8268a1 | 1009 | |
a8d2fb31 | 1010 | default: |
5ca0d812 SC |
1011 | break; |
1012 | } | |
facd6764 | 1013 | |
5ca0d812 | 1014 | if (!eat_key) |
7f1de2b2 | 1015 | { |
5ca0d812 | 1016 | // perform keystroke handling |
665b537f | 1017 | event.Skip(true) ; |
7f1de2b2 | 1018 | } |
a8d2fb31 | 1019 | |
5ca0d812 | 1020 | if ( ( key >= 0x20 && key < WXK_START ) || |
fce161de | 1021 | ( key >= WXK_NUMPAD0 && key <= WXK_DIVIDE ) || |
5ca0d812 SC |
1022 | key == WXK_RETURN || |
1023 | key == WXK_DELETE || | |
1024 | key == WXK_BACK) | |
7f1de2b2 | 1025 | { |
5ca0d812 | 1026 | wxCommandEvent event1(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); |
5ca0d812 | 1027 | event1.SetEventObject( this ); |
c88b7d28 | 1028 | wxPostEvent( GetEventHandler(), event1 ); |
7f1de2b2 | 1029 | } |
5ca0d812 | 1030 | } |
facd6764 | 1031 | |
5ca0d812 SC |
1032 | // ---------------------------------------------------------------------------- |
1033 | // standard handlers for standard edit menu events | |
1034 | // ---------------------------------------------------------------------------- | |
1035 | ||
1036 | void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event)) | |
1037 | { | |
1038 | Cut(); | |
72055702 SC |
1039 | } |
1040 | ||
5ca0d812 | 1041 | void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 1042 | { |
5ca0d812 SC |
1043 | Copy(); |
1044 | } | |
7f1de2b2 | 1045 | |
5ca0d812 SC |
1046 | void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event)) |
1047 | { | |
1048 | Paste(); | |
facd6764 SC |
1049 | } |
1050 | ||
5ca0d812 | 1051 | void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event)) |
facd6764 | 1052 | { |
5ca0d812 | 1053 | Undo(); |
facd6764 SC |
1054 | } |
1055 | ||
5ca0d812 SC |
1056 | void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event)) |
1057 | { | |
1058 | Redo(); | |
1059 | } | |
facd6764 | 1060 | |
24eef584 SC |
1061 | void wxTextCtrl::OnDelete(wxCommandEvent& WXUNUSED(event)) |
1062 | { | |
1063 | long from, to; | |
ffafe6ca | 1064 | |
c88b7d28 | 1065 | GetSelection( &from, &to ); |
24eef584 | 1066 | if (from != -1 && to != -1) |
c88b7d28 | 1067 | Remove( from, to ); |
24eef584 SC |
1068 | } |
1069 | ||
1070 | void wxTextCtrl::OnSelectAll(wxCommandEvent& WXUNUSED(event)) | |
1071 | { | |
1072 | SetSelection(-1, -1); | |
1073 | } | |
1074 | ||
5ca0d812 | 1075 | void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event) |
72055702 | 1076 | { |
5ca0d812 | 1077 | event.Enable( CanCut() ); |
72055702 SC |
1078 | } |
1079 | ||
5ca0d812 SC |
1080 | void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event) |
1081 | { | |
1082 | event.Enable( CanCopy() ); | |
72055702 SC |
1083 | } |
1084 | ||
5ca0d812 | 1085 | void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event) |
72055702 | 1086 | { |
5ca0d812 | 1087 | event.Enable( CanPaste() ); |
72055702 SC |
1088 | } |
1089 | ||
5ca0d812 | 1090 | void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event) |
29b30405 | 1091 | { |
5ca0d812 | 1092 | event.Enable( CanUndo() ); |
29b30405 SC |
1093 | } |
1094 | ||
5ca0d812 | 1095 | void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event) |
facd6764 | 1096 | { |
5ca0d812 | 1097 | event.Enable( CanRedo() ); |
facd6764 SC |
1098 | } |
1099 | ||
24eef584 SC |
1100 | void wxTextCtrl::OnUpdateDelete(wxUpdateUIEvent& event) |
1101 | { | |
1102 | long from, to; | |
ffafe6ca | 1103 | |
c88b7d28 | 1104 | GetSelection( &from, &to ); |
0207e969 | 1105 | event.Enable( from != -1 && to != -1 && from != to && IsEditable() ) ; |
24eef584 SC |
1106 | } |
1107 | ||
1108 | void wxTextCtrl::OnUpdateSelectAll(wxUpdateUIEvent& event) | |
1109 | { | |
1110 | event.Enable(GetLastPosition() > 0); | |
1111 | } | |
1112 | ||
a8d2fb31 | 1113 | // CS: Context Menus only work with MLTE implementations or non-multiline HIViews at the moment |
24eef584 SC |
1114 | |
1115 | void wxTextCtrl::OnContextMenu(wxContextMenuEvent& event) | |
1116 | { | |
64bd657c SC |
1117 | if ( GetPeer()->HasOwnContextMenu() ) |
1118 | { | |
1119 | event.Skip() ; | |
1120 | return ; | |
1121 | } | |
0207e969 | 1122 | |
24eef584 SC |
1123 | if (m_privateContextMenu == NULL) |
1124 | { | |
1125 | m_privateContextMenu = new wxMenu; | |
1126 | m_privateContextMenu->Append(wxID_UNDO, _("&Undo")); | |
1127 | m_privateContextMenu->Append(wxID_REDO, _("&Redo")); | |
1128 | m_privateContextMenu->AppendSeparator(); | |
1129 | m_privateContextMenu->Append(wxID_CUT, _("Cu&t")); | |
1130 | m_privateContextMenu->Append(wxID_COPY, _("&Copy")); | |
1131 | m_privateContextMenu->Append(wxID_PASTE, _("&Paste")); | |
1132 | m_privateContextMenu->Append(wxID_CLEAR, _("&Delete")); | |
1133 | m_privateContextMenu->AppendSeparator(); | |
1134 | m_privateContextMenu->Append(wxID_SELECTALL, _("Select &All")); | |
1135 | } | |
faa94f3e | 1136 | |
24eef584 SC |
1137 | if (m_privateContextMenu != NULL) |
1138 | PopupMenu(m_privateContextMenu); | |
1139 | } | |
1140 | ||
5ca0d812 | 1141 | bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) |
29b30405 | 1142 | { |
0207e969 | 1143 | if ( !GetPeer()->SetupCursor( pt ) ) |
f2c3f2a8 SC |
1144 | return wxWindow::MacSetupCursor( pt ) ; |
1145 | else | |
1146 | return true ; | |
5ca0d812 | 1147 | } |
a8d2fb31 | 1148 | |
20b69855 | 1149 | #if !TARGET_API_MAC_OSX |
24260aae | 1150 | |
5ca0d812 | 1151 | // user pane implementation |
ef4a634b | 1152 | |
7d8268a1 | 1153 | void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) |
5ca0d812 | 1154 | { |
24260aae | 1155 | GetPeer()->MacControlUserPaneDrawProc( part ) ; |
29b30405 SC |
1156 | } |
1157 | ||
7d8268a1 | 1158 | wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
29b30405 | 1159 | { |
24260aae | 1160 | return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ; |
29b30405 SC |
1161 | } |
1162 | ||
7d8268a1 | 1163 | wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) |
72055702 | 1164 | { |
24260aae | 1165 | return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ; |
72055702 SC |
1166 | } |
1167 | ||
7d8268a1 | 1168 | void wxTextCtrl::MacControlUserPaneIdleProc() |
72055702 | 1169 | { |
24260aae | 1170 | GetPeer()->MacControlUserPaneIdleProc( ) ; |
72055702 SC |
1171 | } |
1172 | ||
7d8268a1 | 1173 | wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
72055702 | 1174 | { |
24260aae | 1175 | return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ; |
72055702 SC |
1176 | } |
1177 | ||
7d8268a1 | 1178 | void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) |
72055702 | 1179 | { |
24260aae | 1180 | GetPeer()->MacControlUserPaneActivateProc( activating ) ; |
72055702 SC |
1181 | } |
1182 | ||
7d8268a1 | 1183 | wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) |
72055702 | 1184 | { |
24260aae | 1185 | return GetPeer()->MacControlUserPaneFocusProc( action ) ; |
72055702 SC |
1186 | } |
1187 | ||
7d8268a1 | 1188 | void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) |
72055702 | 1189 | { |
24260aae | 1190 | GetPeer()->MacControlUserPaneBackgroundProc( info ) ; |
5ca0d812 | 1191 | } |
24260aae | 1192 | |
20b69855 | 1193 | #endif |
a8d2fb31 | 1194 | |
5ca0d812 SC |
1195 | // ---------------------------------------------------------------------------- |
1196 | // implementation base class | |
1197 | // ---------------------------------------------------------------------------- | |
1198 | ||
0f7817ab SC |
1199 | wxMacTextControl::wxMacTextControl(wxTextCtrl* peer) : |
1200 | wxMacControl( peer ) | |
5ca0d812 | 1201 | { |
72055702 SC |
1202 | } |
1203 | ||
7d8268a1 | 1204 | wxMacTextControl::~wxMacTextControl() |
72055702 | 1205 | { |
72055702 SC |
1206 | } |
1207 | ||
7d8268a1 | 1208 | void wxMacTextControl::SetStyle(long start, long end, const wxTextAttr& style) |
72055702 | 1209 | { |
72055702 SC |
1210 | } |
1211 | ||
7d8268a1 | 1212 | void wxMacTextControl::Copy() |
72055702 | 1213 | { |
72055702 SC |
1214 | } |
1215 | ||
7d8268a1 | 1216 | void wxMacTextControl::Cut() |
72055702 | 1217 | { |
72055702 SC |
1218 | } |
1219 | ||
7d8268a1 | 1220 | void wxMacTextControl::Paste() |
72055702 | 1221 | { |
72055702 SC |
1222 | } |
1223 | ||
7d8268a1 WS |
1224 | bool wxMacTextControl::CanPaste() const |
1225 | { | |
5ca0d812 SC |
1226 | return false ; |
1227 | } | |
1228 | ||
7d8268a1 | 1229 | void wxMacTextControl::SetEditable(bool editable) |
72055702 | 1230 | { |
7d8268a1 | 1231 | } |
facd6764 | 1232 | |
7d8268a1 | 1233 | wxTextPos wxMacTextControl::GetLastPosition() const |
5ca0d812 | 1234 | { |
faa94f3e | 1235 | return GetStringValue().length() ; |
5ca0d812 | 1236 | } |
facd6764 | 1237 | |
44aa865d SC |
1238 | void wxMacTextControl::Replace( long from , long to , const wxString &val ) |
1239 | { | |
1240 | SetSelection( from , to ) ; | |
fef981b4 | 1241 | WriteText( val ) ; |
44aa865d SC |
1242 | } |
1243 | ||
1244 | void wxMacTextControl::Remove( long from , long to ) | |
5ca0d812 | 1245 | { |
44aa865d SC |
1246 | SetSelection( from , to ) ; |
1247 | WriteText( wxEmptyString) ; | |
72055702 SC |
1248 | } |
1249 | ||
7d8268a1 | 1250 | void wxMacTextControl::Clear() |
72055702 | 1251 | { |
5ca0d812 | 1252 | SetStringValue( wxEmptyString ) ; |
72055702 SC |
1253 | } |
1254 | ||
7d8268a1 | 1255 | bool wxMacTextControl::CanUndo() const |
72055702 | 1256 | { |
5ca0d812 SC |
1257 | return false ; |
1258 | } | |
587bc950 | 1259 | |
a8d2fb31 DS |
1260 | void wxMacTextControl::Undo() |
1261 | { | |
1262 | } | |
5ca0d812 SC |
1263 | |
1264 | bool wxMacTextControl::CanRedo() const | |
1265 | { | |
1266 | return false ; | |
7d8268a1 | 1267 | } |
5ca0d812 | 1268 | |
7d8268a1 | 1269 | void wxMacTextControl::Redo() |
5ca0d812 | 1270 | { |
72055702 SC |
1271 | } |
1272 | ||
5ca0d812 | 1273 | long wxMacTextControl::XYToPosition(long x, long y) const |
72055702 | 1274 | { |
5ca0d812 SC |
1275 | return 0 ; |
1276 | } | |
72055702 | 1277 | |
7d8268a1 | 1278 | bool wxMacTextControl::PositionToXY(long pos, long *x, long *y) const |
5ca0d812 SC |
1279 | { |
1280 | return false ; | |
72055702 SC |
1281 | } |
1282 | ||
7d8268a1 WS |
1283 | void wxMacTextControl::ShowPosition( long WXUNUSED(pos) ) |
1284 | { | |
1285 | } | |
5ca0d812 | 1286 | |
7d8268a1 | 1287 | int wxMacTextControl::GetNumberOfLines() const |
7548762c | 1288 | { |
5ca0d812 SC |
1289 | ItemCount lines = 0 ; |
1290 | wxString content = GetStringValue() ; | |
1291 | lines = 1; | |
fef981b4 | 1292 | |
faa94f3e | 1293 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1294 | { |
fef981b4 DS |
1295 | if (content[i] == '\r') |
1296 | lines++; | |
7548762c | 1297 | } |
a8d2fb31 | 1298 | |
5ca0d812 SC |
1299 | return lines ; |
1300 | } | |
7548762c | 1301 | |
5ca0d812 | 1302 | wxString wxMacTextControl::GetLineText(long lineNo) const |
7548762c | 1303 | { |
fef981b4 | 1304 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1305 | wxString content = GetStringValue() ; |
7d8268a1 | 1306 | |
5ca0d812 SC |
1307 | // Find line first |
1308 | int count = 0; | |
faa94f3e | 1309 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1310 | { |
5ca0d812 SC |
1311 | if (count == lineNo) |
1312 | { | |
1313 | // Add chars in line then | |
1314 | wxString tmp; | |
7d8268a1 | 1315 | |
faa94f3e | 1316 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1317 | { |
1318 | if (content[j] == '\n') | |
1319 | return tmp; | |
7d8268a1 | 1320 | |
5ca0d812 SC |
1321 | tmp += content[j]; |
1322 | } | |
7d8268a1 | 1323 | |
5ca0d812 SC |
1324 | return tmp; |
1325 | } | |
a8d2fb31 | 1326 | |
fef981b4 DS |
1327 | if (content[i] == '\n') |
1328 | count++; | |
7548762c | 1329 | } |
a8d2fb31 | 1330 | |
5ca0d812 SC |
1331 | return wxEmptyString ; |
1332 | } | |
7548762c | 1333 | |
a8d2fb31 | 1334 | int wxMacTextControl::GetLineLength(long lineNo) const |
5ca0d812 | 1335 | { |
fef981b4 | 1336 | // TODO: change this if possible to reflect real lines |
5ca0d812 | 1337 | wxString content = GetStringValue() ; |
7d8268a1 | 1338 | |
5ca0d812 SC |
1339 | // Find line first |
1340 | int count = 0; | |
faa94f3e | 1341 | for (size_t i = 0; i < content.length() ; i++) |
7548762c | 1342 | { |
5ca0d812 SC |
1343 | if (count == lineNo) |
1344 | { | |
1345 | // Count chars in line then | |
1346 | count = 0; | |
faa94f3e | 1347 | for (size_t j = i; j < content.length(); j++) |
5ca0d812 SC |
1348 | { |
1349 | count++; | |
a8d2fb31 DS |
1350 | if (content[j] == '\n') |
1351 | return count; | |
5ca0d812 | 1352 | } |
7d8268a1 | 1353 | |
5ca0d812 SC |
1354 | return count; |
1355 | } | |
a8d2fb31 | 1356 | |
fef981b4 DS |
1357 | if (content[i] == '\n') |
1358 | count++; | |
7548762c | 1359 | } |
a8d2fb31 | 1360 | |
5ca0d812 SC |
1361 | return 0 ; |
1362 | } | |
7548762c | 1363 | |
5ca0d812 SC |
1364 | // ---------------------------------------------------------------------------- |
1365 | // standard unicode control implementation | |
1366 | // ---------------------------------------------------------------------------- | |
1367 | ||
1368 | #if TARGET_API_MAC_OSX | |
1369 | ||
ad604d0f SC |
1370 | // the current unicode textcontrol implementation has a bug : only if the control |
1371 | // is currently having the focus, the selection can be retrieved by the corresponding | |
1372 | // data tag. So we have a mirroring using a member variable | |
1373 | // TODO : build event table using virtual member functions for wxMacControl | |
1374 | ||
1375 | static const EventTypeSpec unicodeTextControlEventList[] = | |
1376 | { | |
1377 | { kEventClassControl , kEventControlSetFocusPart } , | |
1378 | } ; | |
1379 | ||
1380 | static pascal OSStatus wxMacUnicodeTextControlControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1381 | { | |
1382 | OSStatus result = eventNotHandledErr ; | |
1383 | wxMacUnicodeTextControl* focus = (wxMacUnicodeTextControl*) data ; | |
1384 | wxMacCarbonEvent cEvent( event ) ; | |
9eddec69 | 1385 | |
ad604d0f SC |
1386 | switch ( GetEventKind( event ) ) |
1387 | { | |
1388 | case kEventControlSetFocusPart : | |
1389 | { | |
1390 | ControlPartCode controlPart = cEvent.GetParameter<ControlPartCode>(kEventParamControlPart , typeControlPartCode ); | |
1391 | if ( controlPart == kControlFocusNoPart ) | |
1392 | { | |
1393 | // about to loose focus -> store selection to field | |
1394 | focus->GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1395 | } | |
1396 | result = CallNextEventHandler(handler,event) ; | |
1397 | if ( controlPart != kControlFocusNoPart ) | |
1398 | { | |
1399 | // about to gain focus -> set selection from field | |
1400 | focus->SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &focus->m_selection ); | |
1401 | } | |
1402 | break; | |
1403 | } | |
1404 | default: | |
1405 | break ; | |
1406 | } | |
9eddec69 | 1407 | |
ad604d0f SC |
1408 | return result ; |
1409 | } | |
1410 | ||
1411 | static pascal OSStatus wxMacUnicodeTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
1412 | { | |
1413 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 1414 | |
ad604d0f SC |
1415 | switch ( GetEventClass( event ) ) |
1416 | { | |
1417 | case kEventClassControl : | |
1418 | result = wxMacUnicodeTextControlControlEventHandler( handler , event , data ) ; | |
1419 | break ; | |
9eddec69 | 1420 | |
ad604d0f SC |
1421 | default : |
1422 | break ; | |
1423 | } | |
1424 | return result ; | |
1425 | } | |
1426 | ||
1427 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacUnicodeTextControlEventHandler ) | |
1428 | ||
0f7817ab | 1429 | wxMacUnicodeTextControl::wxMacUnicodeTextControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
1430 | const wxString& str, |
1431 | const wxPoint& pos, | |
1432 | const wxSize& size, long style ) | |
1433 | : wxMacTextControl( wxPeer ) | |
5ca0d812 SC |
1434 | { |
1435 | m_font = wxPeer->GetFont() ; | |
1436 | m_windowStyle = style ; | |
7d8268a1 | 1437 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 1438 | wxString st = str ; |
395480fb | 1439 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
1440 | wxMacCFStringHolder cf(st , m_font.GetEncoding()) ; |
1441 | CFStringRef cfr = cf ; | |
1442 | Boolean isPassword = ( m_windowStyle & wxTE_PASSWORD ) != 0 ; | |
1443 | m_valueTag = isPassword ? kControlEditTextPasswordCFStringTag : kControlEditTextCFStringTag ; | |
ffafe6ca DS |
1444 | |
1445 | OSStatus err = CreateEditUnicodeTextControl( | |
fef981b4 DS |
1446 | MAC_WXHWND(wxPeer->MacGetTopLevelWindowRef()), &bounds , cfr , |
1447 | isPassword , NULL , &m_controlRef ) ; | |
ffafe6ca | 1448 | verify_noerr( err ); |
7d8268a1 | 1449 | |
5ca0d812 | 1450 | if ( !(m_windowStyle & wxTE_MULTILINE) ) |
5ca0d812 | 1451 | SetData<Boolean>( kControlEditTextPart , kControlEditTextSingleLineTag , true ) ; |
ad604d0f SC |
1452 | |
1453 | InstallControlEventHandler( m_controlRef , GetwxMacUnicodeTextControlEventHandlerUPP(), | |
1454 | GetEventTypeCount(unicodeTextControlEventList), unicodeTextControlEventList, this, | |
1455 | &m_focusHandlerRef); | |
5ca0d812 | 1456 | } |
7548762c | 1457 | |
5ca0d812 | 1458 | wxMacUnicodeTextControl::~wxMacUnicodeTextControl() |
7548762c | 1459 | { |
ad604d0f | 1460 | ::RemoveEventHandler( m_focusHandlerRef ); |
7548762c SC |
1461 | } |
1462 | ||
7d8268a1 | 1463 | void wxMacUnicodeTextControl::VisibilityChanged(bool shown) |
7548762c | 1464 | { |
5ca0d812 SC |
1465 | if ( !(m_windowStyle & wxTE_MULTILINE) && shown ) |
1466 | { | |
fef981b4 DS |
1467 | // work around a refresh issue insofar as not always the entire content is shown, |
1468 | // even if this would be possible | |
5ca0d812 SC |
1469 | ControlEditTextSelectionRec sel ; |
1470 | CFStringRef value = NULL ; | |
7548762c | 1471 | |
5ca0d812 | 1472 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); |
c88b7d28 | 1473 | verify_noerr( GetData<CFStringRef>( 0, m_valueTag, &value ) ); |
5ca0d812 SC |
1474 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag, &value ) ); |
1475 | verify_noerr( SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ); | |
7d8268a1 | 1476 | |
5ca0d812 SC |
1477 | CFRelease( value ) ; |
1478 | } | |
1479 | } | |
a8d2fb31 | 1480 | |
7d8268a1 | 1481 | wxString wxMacUnicodeTextControl::GetStringValue() const |
7548762c | 1482 | { |
5ca0d812 | 1483 | wxString result ; |
c88b7d28 | 1484 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; |
5ca0d812 SC |
1485 | if ( value ) |
1486 | { | |
1487 | wxMacCFStringHolder cf(value) ; | |
1488 | result = cf.AsString() ; | |
1489 | } | |
a8d2fb31 | 1490 | |
2e7573f7 | 1491 | #if '\n' == 10 |
395480fb SC |
1492 | wxMacConvertNewlines13To10( &result ) ; |
1493 | #else | |
5ca0d812 | 1494 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1495 | #endif |
a8d2fb31 | 1496 | |
7548762c SC |
1497 | return result ; |
1498 | } | |
a8d2fb31 | 1499 | |
c88b7d28 | 1500 | void wxMacUnicodeTextControl::SetStringValue( const wxString &str ) |
5ca0d812 SC |
1501 | { |
1502 | wxString st = str ; | |
395480fb | 1503 | wxMacConvertNewlines10To13( &st ) ; |
ffafe6ca | 1504 | wxMacCFStringHolder cf( st , m_font.GetEncoding() ) ; |
0207e969 | 1505 | verify_noerr( SetData<CFStringRef>( 0, m_valueTag , cf ) ) ; |
5ca0d812 | 1506 | } |
a8d2fb31 | 1507 | |
5ca0d812 SC |
1508 | void wxMacUnicodeTextControl::Copy() |
1509 | { | |
1510 | SendHICommand( kHICommandCopy ) ; | |
1511 | } | |
a8d2fb31 | 1512 | |
5ca0d812 SC |
1513 | void wxMacUnicodeTextControl::Cut() |
1514 | { | |
1515 | SendHICommand( kHICommandCut ) ; | |
1516 | } | |
a8d2fb31 | 1517 | |
5ca0d812 SC |
1518 | void wxMacUnicodeTextControl::Paste() |
1519 | { | |
1520 | SendHICommand( kHICommandPaste ) ; | |
1521 | } | |
a8d2fb31 | 1522 | |
5ca0d812 SC |
1523 | bool wxMacUnicodeTextControl::CanPaste() const |
1524 | { | |
1525 | return true ; | |
1526 | } | |
a8d2fb31 | 1527 | |
7d8268a1 | 1528 | void wxMacUnicodeTextControl::SetEditable(bool editable) |
5ca0d812 | 1529 | { |
35d9ac06 SC |
1530 | #if 0 // leads to problem because text cannot be selected anymore |
1531 | SetData<Boolean>( kControlEditTextPart , kControlEditTextLockedTag , (Boolean) !editable ) ; | |
1532 | #endif | |
5ca0d812 | 1533 | } |
7548762c | 1534 | |
0207e969 | 1535 | void wxMacUnicodeTextControl::GetSelection( long* from, long* to ) const |
7548762c | 1536 | { |
5ca0d812 | 1537 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1538 | if (HasFocus()) |
1539 | verify_noerr( GetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ) ; | |
1540 | else | |
1541 | sel = m_selection ; | |
9eddec69 | 1542 | |
0207e969 DS |
1543 | if ( from ) |
1544 | *from = sel.selStart ; | |
1545 | if ( to ) | |
1546 | *to = sel.selEnd ; | |
7548762c SC |
1547 | } |
1548 | ||
7d8268a1 | 1549 | void wxMacUnicodeTextControl::SetSelection( long from , long to ) |
ef4a634b | 1550 | { |
5ca0d812 | 1551 | ControlEditTextSelectionRec sel ; |
ad604d0f SC |
1552 | wxString result ; |
1553 | int textLength = 0 ; | |
1554 | CFStringRef value = GetData<CFStringRef>(0, m_valueTag) ; | |
1555 | if ( value ) | |
1556 | { | |
1557 | wxMacCFStringHolder cf(value) ; | |
1558 | textLength = cf.AsString().Length() ; | |
1559 | } | |
1560 | ||
1a535eb9 SC |
1561 | if ((from == -1) && (to == -1)) |
1562 | { | |
1563 | from = 0 ; | |
9eddec69 | 1564 | to = textLength ; |
ad604d0f SC |
1565 | } |
1566 | else | |
1567 | { | |
1568 | from = wxMin(textLength,wxMax(from,0)) ; | |
1569 | to = wxMax(0,wxMin(textLength,to)) ; | |
1a535eb9 | 1570 | } |
a8d2fb31 | 1571 | |
5ca0d812 SC |
1572 | sel.selStart = from ; |
1573 | sel.selEnd = to ; | |
ad604d0f SC |
1574 | if ( HasFocus() ) |
1575 | SetData<ControlEditTextSelectionRec>( 0, kControlEditTextSelectionTag, &sel ) ; | |
1576 | else | |
1577 | m_selection = sel; | |
5ca0d812 | 1578 | } |
facd6764 | 1579 | |
c88b7d28 | 1580 | void wxMacUnicodeTextControl::WriteText( const wxString& str ) |
5ca0d812 SC |
1581 | { |
1582 | wxString st = str ; | |
395480fb | 1583 | wxMacConvertNewlines10To13( &st ) ; |
0207e969 DS |
1584 | |
1585 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 | |
ad604d0f SC |
1586 | if ( HasFocus() ) |
1587 | { | |
7548762c SC |
1588 | wxMacCFStringHolder cf(st , m_font.GetEncoding() ) ; |
1589 | CFStringRef value = cf ; | |
5ca0d812 | 1590 | SetData<CFStringRef>( 0, kControlEditTextInsertCFStringRefTag, &value ); |
ad604d0f | 1591 | } |
df39467f | 1592 | else |
ad604d0f SC |
1593 | #endif |
1594 | { | |
5ca0d812 | 1595 | wxString val = GetStringValue() ; |
7548762c SC |
1596 | long start , end ; |
1597 | GetSelection( &start , &end ) ; | |
1598 | val.Remove( start , end - start ) ; | |
1599 | val.insert( start , str ) ; | |
5ca0d812 | 1600 | SetStringValue( val ) ; |
faa94f3e | 1601 | SetSelection( start + str.length() , start + str.length() ) ; |
ad604d0f | 1602 | } |
72055702 SC |
1603 | } |
1604 | ||
5ca0d812 | 1605 | #endif |
facd6764 | 1606 | |
5ca0d812 SC |
1607 | // ---------------------------------------------------------------------------- |
1608 | // MLTE control implementation (common part) | |
1609 | // ---------------------------------------------------------------------------- | |
facd6764 | 1610 | |
a8d2fb31 | 1611 | // if MTLE is read only, no changes at all are allowed, not even from |
5ca0d812 SC |
1612 | // procedural API, in order to allow changes via API all the same we must undo |
1613 | // the readonly status while we are executing, this class helps to do so | |
72055702 | 1614 | |
5de694f0 | 1615 | class wxMacEditHelper |
72055702 | 1616 | { |
5ca0d812 | 1617 | public : |
5de694f0 | 1618 | wxMacEditHelper( TXNObject txn ) |
5ca0d812 SC |
1619 | { |
1620 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1621 | m_txn = txn ; | |
1622 | TXNGetTXNObjectControls( m_txn , 1 , tag , m_data ) ; | |
1623 | if ( m_data[0].uValue == kTXNReadOnly ) | |
1624 | { | |
1625 | TXNControlData data[] = { { kTXNReadWrite } } ; | |
1626 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , data ) ; | |
1627 | } | |
1628 | } | |
a8d2fb31 | 1629 | |
5de694f0 | 1630 | ~wxMacEditHelper() |
5ca0d812 SC |
1631 | { |
1632 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; | |
1633 | if ( m_data[0].uValue == kTXNReadOnly ) | |
5ca0d812 | 1634 | TXNSetTXNObjectControls( m_txn , false , 1 , tag , m_data ) ; |
5ca0d812 | 1635 | } |
a8d2fb31 | 1636 | |
fef981b4 DS |
1637 | protected : |
1638 | TXNObject m_txn ; | |
1639 | TXNControlData m_data[1] ; | |
5ca0d812 | 1640 | } ; |
72055702 | 1641 | |
ffafe6ca DS |
1642 | wxMacMLTEControl::wxMacMLTEControl( wxTextCtrl *peer ) |
1643 | : wxMacTextControl( peer ) | |
789ae0cf | 1644 | { |
3dee36ae | 1645 | SetNeedsFocusRect( true ) ; |
789ae0cf SC |
1646 | } |
1647 | ||
7d8268a1 | 1648 | wxString wxMacMLTEControl::GetStringValue() const |
72055702 | 1649 | { |
5ca0d812 SC |
1650 | wxString result ; |
1651 | OSStatus err ; | |
1652 | Size actualSize = 0; | |
c88b7d28 | 1653 | |
5ca0d812 SC |
1654 | { |
1655 | #if wxUSE_UNICODE | |
1656 | Handle theText ; | |
c88b7d28 | 1657 | err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNUnicodeTextData ); |
fef981b4 | 1658 | |
5ca0d812 | 1659 | // all done |
fef981b4 | 1660 | if ( err != noErr ) |
5ca0d812 SC |
1661 | { |
1662 | actualSize = 0 ; | |
1663 | } | |
1664 | else | |
1665 | { | |
c88b7d28 | 1666 | actualSize = GetHandleSize( theText ) / sizeof(UniChar) ; |
5ca0d812 SC |
1667 | if ( actualSize > 0 ) |
1668 | { | |
1669 | wxChar *ptr = NULL ; | |
fef981b4 | 1670 | |
7d8268a1 | 1671 | #if SIZEOF_WCHAR_T == 2 |
c88b7d28 DS |
1672 | ptr = new wxChar[actualSize + 1] ; |
1673 | wxStrncpy( ptr , (wxChar*)(*theText) , actualSize ) ; | |
5ca0d812 | 1674 | #else |
c88b7d28 | 1675 | SetHandleSize( theText, (actualSize + 1) * sizeof(UniChar) ) ; |
5ca0d812 SC |
1676 | HLock( theText ) ; |
1677 | (((UniChar*)*theText)[actualSize]) = 0 ; | |
d9d488cf | 1678 | wxMBConvUTF16 converter ; |
5ca0d812 | 1679 | size_t noChars = converter.MB2WC( NULL , (const char*)*theText , 0 ) ; |
88a7a4e1 | 1680 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); |
5ca0d812 | 1681 | ptr = new wxChar[noChars + 1] ; |
7d8268a1 | 1682 | |
f3097709 | 1683 | noChars = converter.MB2WC( ptr , (const char*)*theText , noChars + 1 ) ; |
88a7a4e1 | 1684 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); |
5ca0d812 SC |
1685 | ptr[noChars] = 0 ; |
1686 | HUnlock( theText ) ; | |
1687 | #endif | |
fef981b4 | 1688 | |
5ca0d812 SC |
1689 | ptr[actualSize] = 0 ; |
1690 | result = wxString( ptr ) ; | |
c88b7d28 | 1691 | delete [] ptr ; |
5ca0d812 | 1692 | } |
a8d2fb31 | 1693 | |
5ca0d812 SC |
1694 | DisposeHandle( theText ) ; |
1695 | } | |
1696 | #else | |
1697 | Handle theText ; | |
c88b7d28 | 1698 | err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
0207e969 | 1699 | |
5ca0d812 | 1700 | // all done |
0207e969 | 1701 | if ( err != noErr ) |
5ca0d812 SC |
1702 | { |
1703 | actualSize = 0 ; | |
1704 | } | |
1705 | else | |
1706 | { | |
1707 | actualSize = GetHandleSize( theText ) ; | |
1708 | if ( actualSize > 0 ) | |
1709 | { | |
1710 | HLock( theText ) ; | |
1711 | result = wxString( *theText , wxConvLocal , actualSize ) ; | |
1712 | HUnlock( theText ) ; | |
1713 | } | |
a8d2fb31 | 1714 | |
5ca0d812 SC |
1715 | DisposeHandle( theText ) ; |
1716 | } | |
1717 | #endif | |
1718 | } | |
a8d2fb31 | 1719 | |
2e7573f7 | 1720 | #if '\n' == 10 |
395480fb SC |
1721 | wxMacConvertNewlines13To10( &result ) ; |
1722 | #else | |
5ca0d812 | 1723 | wxMacConvertNewlines10To13( &result ) ; |
395480fb | 1724 | #endif |
a8d2fb31 | 1725 | |
5ca0d812 | 1726 | return result ; |
72055702 SC |
1727 | } |
1728 | ||
0207e969 | 1729 | void wxMacMLTEControl::SetStringValue( const wxString &str ) |
72055702 | 1730 | { |
c88b7d28 DS |
1731 | wxString st = str; |
1732 | wxMacConvertNewlines10To13( &st ); | |
395480fb | 1733 | |
5de694f0 | 1734 | { |
c88b7d28 | 1735 | wxMacWindowClipper c( m_peer ); |
0207e969 | 1736 | |
5de694f0 | 1737 | { |
c88b7d28 DS |
1738 | wxMacEditHelper help( m_txn ); |
1739 | SetTXNData( st, kTXNStartOffset, kTXNEndOffset ); | |
5de694f0 | 1740 | } |
0207e969 | 1741 | |
fef981b4 DS |
1742 | TXNSetSelection( m_txn, 0, 0 ); |
1743 | TXNShowSelection( m_txn, kTXNShowStart ); | |
5de694f0 | 1744 | } |
5ca0d812 | 1745 | } |
facd6764 | 1746 | |
5ca0d812 SC |
1747 | TXNFrameOptions wxMacMLTEControl::FrameOptionsFromWXStyle( long wxStyle ) |
1748 | { | |
c88b7d28 DS |
1749 | TXNFrameOptions frameOptions = kTXNDontDrawCaretWhenInactiveMask; |
1750 | ||
b7e28620 | 1751 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 |
c88b7d28 | 1752 | frameOptions |= kTXNDoFontSubstitutionMask; |
b7e28620 | 1753 | #endif |
4d7528a1 | 1754 | |
c88b7d28 | 1755 | if ( ! (wxStyle & wxTE_NOHIDESEL) ) |
5ca0d812 SC |
1756 | frameOptions |= kTXNDontDrawSelectionWhenInactiveMask ; |
1757 | ||
c88b7d28 DS |
1758 | if ( wxStyle & (wxHSCROLL | wxTE_DONTWRAP) ) |
1759 | frameOptions |= kTXNWantHScrollBarMask ; | |
1760 | ||
5ca0d812 | 1761 | if ( wxStyle & wxTE_MULTILINE ) |
29e4a190 | 1762 | { |
c88b7d28 | 1763 | frameOptions |= kTXNAlwaysWrapAtViewEdgeMask ; |
72055702 | 1764 | |
c88b7d28 | 1765 | if ( !(wxStyle & wxTE_NO_VSCROLL) ) |
5de694f0 | 1766 | { |
5ca0d812 | 1767 | frameOptions |= kTXNWantVScrollBarMask ; |
c88b7d28 | 1768 | |
04c3457a DS |
1769 | // The following code causes drawing problems on 10.4. Perhaps it can be restored for |
1770 | // older versions of the OS, but I'm not sure it's appropriate to put a grow icon here | |
1771 | // anyways, as AFAIK users can't actually use it to resize the text ctrl. | |
1772 | // if ( frameOptions & kTXNWantHScrollBarMask ) | |
1773 | // frameOptions |= kTXNDrawGrowIconMask ; | |
5de694f0 | 1774 | } |
5ca0d812 SC |
1775 | } |
1776 | else | |
c88b7d28 | 1777 | { |
5ca0d812 | 1778 | frameOptions |= kTXNSingleLineOnlyMask ; |
c88b7d28 | 1779 | } |
7d8268a1 | 1780 | |
5ca0d812 SC |
1781 | return frameOptions ; |
1782 | } | |
cfeff6f7 | 1783 | |
5ca0d812 SC |
1784 | void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, bool visible ) |
1785 | { | |
3dee36ae WS |
1786 | TXNControlTag iControlTags[] = |
1787 | { | |
1788 | kTXNDoFontSubstitution, | |
5de694f0 SC |
1789 | kTXNWordWrapStateTag , |
1790 | }; | |
3dee36ae WS |
1791 | TXNControlData iControlData[] = |
1792 | { | |
c88b7d28 DS |
1793 | { true }, |
1794 | { kTXNNoAutoWrap }, | |
5de694f0 | 1795 | }; |
3dee36ae | 1796 | |
5de694f0 | 1797 | int toptag = WXSIZEOF( iControlTags ) ; |
7d8268a1 | 1798 | |
72055702 SC |
1799 | if ( m_windowStyle & wxTE_MULTILINE ) |
1800 | { | |
c88b7d28 DS |
1801 | iControlData[1].uValue = |
1802 | (m_windowStyle & wxTE_DONTWRAP) | |
1803 | ? kTXNNoAutoWrap | |
1804 | : kTXNAutoWrap; | |
72055702 | 1805 | } |
0207e969 | 1806 | |
ffafe6ca DS |
1807 | OSStatus err = TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ; |
1808 | verify_noerr( err ); | |
facd6764 | 1809 | |
fef981b4 | 1810 | // setting the default font: |
8e15e610 | 1811 | // under 10.2 this causes a visible caret, therefore we avoid it |
72055702 | 1812 | |
8e15e610 | 1813 | if ( UMAGetSystemVersion() >= 0x1030 ) |
72055702 | 1814 | { |
8e15e610 SC |
1815 | Str255 fontName ; |
1816 | SInt16 fontSize ; | |
1817 | Style fontStyle ; | |
5ca0d812 | 1818 | |
ffafe6ca | 1819 | GetThemeFont( kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ; |
5ca0d812 | 1820 | |
8e15e610 SC |
1821 | TXNTypeAttributes typeAttr[] = |
1822 | { | |
c88b7d28 DS |
1823 | { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } , |
1824 | { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } , | |
1825 | { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } , | |
8e15e610 SC |
1826 | } ; |
1827 | ||
ffafe6ca DS |
1828 | err = TXNSetTypeAttributes( |
1829 | m_txn, sizeof(typeAttr) / sizeof(TXNTypeAttributes), | |
1830 | typeAttr, kTXNStartOffset, kTXNEndOffset ); | |
1831 | verify_noerr( err ); | |
8e15e610 | 1832 | } |
3dee36ae | 1833 | |
5ca0d812 SC |
1834 | if ( m_windowStyle & wxTE_PASSWORD ) |
1835 | { | |
ffafe6ca DS |
1836 | UniChar c = 0x00A5 ; |
1837 | err = TXNEchoMode( m_txn , c , 0 , true ); | |
1838 | verify_noerr( err ); | |
72055702 | 1839 | } |
5ca0d812 SC |
1840 | |
1841 | TXNBackground tback; | |
1842 | tback.bgType = kTXNBackgroundTypeRGB; | |
1843 | tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); | |
0207e969 | 1844 | TXNSetBackground( m_txn , &tback ); |
a8d2fb31 | 1845 | |
64bd657c SC |
1846 | #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 |
1847 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
1848 | { | |
1849 | TXNCommandEventSupportOptions options ; | |
fef981b4 | 1850 | if ( TXNGetCommandEventSupport( m_txn, &options ) == noErr ) |
64bd657c | 1851 | { |
fef981b4 DS |
1852 | options |= |
1853 | kTXNSupportEditCommandProcessing | |
1854 | | kTXNSupportEditCommandUpdating | |
1855 | | kTXNSupportSpellCheckCommandProcessing | |
1856 | | kTXNSupportSpellCheckCommandUpdating | |
1857 | | kTXNSupportFontCommandProcessing | |
1858 | | kTXNSupportFontCommandUpdating; | |
9eddec69 | 1859 | |
64bd657c SC |
1860 | TXNSetCommandEventSupport( m_txn , options ) ; |
1861 | } | |
1862 | } | |
1863 | #endif | |
72055702 SC |
1864 | } |
1865 | ||
7d8268a1 | 1866 | void wxMacMLTEControl::SetBackground( const wxBrush &brush ) |
7ea087b7 SC |
1867 | { |
1868 | // currently only solid background are supported | |
1869 | TXNBackground tback; | |
0207e969 | 1870 | |
7ea087b7 SC |
1871 | tback.bgType = kTXNBackgroundTypeRGB; |
1872 | tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); | |
0207e969 | 1873 | TXNSetBackground( m_txn , &tback ); |
7ea087b7 SC |
1874 | } |
1875 | ||
0207e969 | 1876 | void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) |
72055702 | 1877 | { |
7d8268a1 | 1878 | TXNTypeAttributes typeAttr[4] ; |
5ca0d812 | 1879 | RGBColor color ; |
0207e969 | 1880 | int attrCount = 0 ; |
fef981b4 | 1881 | |
5ca0d812 | 1882 | if ( style.HasFont() ) |
72055702 | 1883 | { |
5ca0d812 | 1884 | const wxFont &font = style.GetFont() ; |
9eddec69 | 1885 | |
acead93d | 1886 | #if 0 // old version |
09660720 SC |
1887 | Str255 fontName = "\pMonaco" ; |
1888 | SInt16 fontSize = 12 ; | |
1889 | Style fontStyle = normal ; | |
5ca0d812 SC |
1890 | wxMacStringToPascal( font.GetFaceName() , fontName ) ; |
1891 | fontSize = font.GetPointSize() ; | |
1892 | if ( font.GetUnderlined() ) | |
1893 | fontStyle |= underline ; | |
1894 | if ( font.GetWeight() == wxBOLD ) | |
1895 | fontStyle |= bold ; | |
1896 | if ( font.GetStyle() == wxITALIC ) | |
1897 | fontStyle |= italic ; | |
eda3f2b4 | 1898 | |
0207e969 DS |
1899 | typeAttr[attrCount].tag = kTXNQDFontNameAttribute ; |
1900 | typeAttr[attrCount].size = kTXNQDFontNameAttributeSize ; | |
1901 | typeAttr[attrCount].data.dataPtr = (void*)fontName ; | |
1902 | attrCount++ ; | |
1903 | ||
1904 | typeAttr[attrCount].tag = kTXNQDFontSizeAttribute ; | |
1905 | typeAttr[attrCount].size = kTXNFontSizeAttributeSize ; | |
1906 | typeAttr[attrCount].data.dataValue = (fontSize << 16) ; | |
1907 | attrCount++ ; | |
1908 | ||
1909 | typeAttr[attrCount].tag = kTXNQDFontStyleAttribute ; | |
1910 | typeAttr[attrCount].size = kTXNQDFontStyleAttributeSize ; | |
1911 | typeAttr[attrCount].data.dataValue = fontStyle ; | |
1912 | attrCount++ ; | |
acead93d SC |
1913 | #else |
1914 | typeAttr[attrCount].tag = kTXNATSUIStyle ; | |
1915 | typeAttr[attrCount].size = kTXNATSUIStyleSize ; | |
1916 | typeAttr[attrCount].data.dataValue = (UInt32)font.MacGetATSUStyle() ; | |
1917 | attrCount++ ; | |
1918 | #endif | |
5ca0d812 | 1919 | } |
fef981b4 | 1920 | |
5ca0d812 SC |
1921 | if ( style.HasTextColour() ) |
1922 | { | |
5ca0d812 | 1923 | color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; |
0207e969 DS |
1924 | |
1925 | typeAttr[attrCount].tag = kTXNQDFontColorAttribute ; | |
1926 | typeAttr[attrCount].size = kTXNQDFontColorAttributeSize ; | |
1927 | typeAttr[attrCount].data.dataPtr = (void*) &color ; | |
1928 | attrCount++ ; | |
72055702 | 1929 | } |
fef981b4 | 1930 | |
0207e969 | 1931 | if ( attrCount > 0 ) |
8623a883 | 1932 | { |
0207e969 | 1933 | verify_noerr( TXNSetTypeAttributes( m_txn , attrCount , typeAttr, from , to ) ); |
09660720 SC |
1934 | // unfortunately the relayout is not automatic |
1935 | TXNRecalcTextLayout( m_txn ); | |
8623a883 | 1936 | } |
72055702 SC |
1937 | } |
1938 | ||
7d8268a1 | 1939 | void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
72055702 | 1940 | { |
0207e969 DS |
1941 | wxMacEditHelper help( m_txn ) ; |
1942 | TXNSetAttribute( wxTextAttr( foreground, wxNullColour, font ), kTXNStartOffset, kTXNEndOffset ) ; | |
72055702 | 1943 | } |
a8d2fb31 | 1944 | |
0207e969 | 1945 | void wxMacMLTEControl::SetStyle( long start, long end, const wxTextAttr& style ) |
7d8268a1 | 1946 | { |
0207e969 DS |
1947 | wxMacEditHelper help( m_txn ) ; |
1948 | TXNSetAttribute( style, start, end ) ; | |
7d8268a1 WS |
1949 | } |
1950 | ||
1951 | void wxMacMLTEControl::Copy() | |
5ca0d812 SC |
1952 | { |
1953 | ClearCurrentScrap(); | |
0207e969 | 1954 | TXNCopy( m_txn ); |
5ca0d812 | 1955 | TXNConvertToPublicScrap(); |
72055702 SC |
1956 | } |
1957 | ||
7d8268a1 | 1958 | void wxMacMLTEControl::Cut() |
3a9fa0d6 | 1959 | { |
5ca0d812 | 1960 | ClearCurrentScrap(); |
0207e969 | 1961 | TXNCut( m_txn ); |
5ca0d812 | 1962 | TXNConvertToPublicScrap(); |
3a9fa0d6 VZ |
1963 | } |
1964 | ||
7d8268a1 | 1965 | void wxMacMLTEControl::Paste() |
72055702 | 1966 | { |
5ca0d812 | 1967 | TXNConvertFromPublicScrap(); |
0207e969 | 1968 | TXNPaste( m_txn ); |
72055702 SC |
1969 | } |
1970 | ||
5ca0d812 | 1971 | bool wxMacMLTEControl::CanPaste() const |
72055702 | 1972 | { |
5ca0d812 | 1973 | return TXNIsScrapPastable() ; |
72055702 SC |
1974 | } |
1975 | ||
7d8268a1 | 1976 | void wxMacMLTEControl::SetEditable(bool editable) |
72055702 | 1977 | { |
5ca0d812 SC |
1978 | TXNControlTag tag[] = { kTXNIOPrivilegesTag } ; |
1979 | TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ; | |
c88b7d28 | 1980 | TXNSetTXNObjectControls( m_txn, false, WXSIZEOF(tag), tag, data ) ; |
5ca0d812 | 1981 | } |
bd3169a7 | 1982 | |
7d8268a1 | 1983 | wxTextPos wxMacMLTEControl::GetLastPosition() const |
5ca0d812 | 1984 | { |
7d8268a1 | 1985 | wxTextPos actualsize = 0 ; |
5ca0d812 SC |
1986 | |
1987 | Handle theText ; | |
0207e969 | 1988 | OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText, kTXNTextData ); |
fef981b4 DS |
1989 | |
1990 | // all done | |
1991 | if ( err == noErr ) | |
5ca0d812 | 1992 | { |
fef981b4 DS |
1993 | actualsize = GetHandleSize( theText ) ; |
1994 | DisposeHandle( theText ) ; | |
5ca0d812 SC |
1995 | } |
1996 | else | |
1997 | { | |
fef981b4 | 1998 | actualsize = 0 ; |
5ca0d812 SC |
1999 | } |
2000 | ||
2001 | return actualsize ; | |
2002 | } | |
2003 | ||
44aa865d | 2004 | void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) |
5ca0d812 SC |
2005 | { |
2006 | wxString value = str ; | |
395480fb | 2007 | wxMacConvertNewlines10To13( &value ) ; |
5ca0d812 | 2008 | |
5de694f0 | 2009 | wxMacEditHelper help( m_txn ) ; |
0f7817ab | 2010 | wxMacWindowClipper c( m_peer ) ; |
5ca0d812 | 2011 | |
0207e969 | 2012 | TXNSetSelection( m_txn, from, to ) ; |
5ca0d812 | 2013 | TXNClear( m_txn ) ; |
0207e969 | 2014 | SetTXNData( value, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5ca0d812 SC |
2015 | } |
2016 | ||
2017 | void wxMacMLTEControl::Remove( long from , long to ) | |
2018 | { | |
0f7817ab | 2019 | wxMacWindowClipper c( m_peer ) ; |
5de694f0 | 2020 | wxMacEditHelper help( m_txn ) ; |
0207e969 | 2021 | TXNSetSelection( m_txn , from , to ) ; |
5ca0d812 SC |
2022 | TXNClear( m_txn ) ; |
2023 | } | |
2024 | ||
2025 | void wxMacMLTEControl::GetSelection( long* from, long* to) const | |
2026 | { | |
2027 | TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ; | |
2028 | } | |
2029 | ||
7d8268a1 | 2030 | void wxMacMLTEControl::SetSelection( long from , long to ) |
5ca0d812 | 2031 | { |
0f7817ab | 2032 | wxMacWindowClipper c( m_peer ) ; |
fef981b4 DS |
2033 | |
2034 | // change the selection | |
5ca0d812 | 2035 | if ((from == -1) && (to == -1)) |
0207e969 | 2036 | TXNSelectAll( m_txn ); |
5ca0d812 | 2037 | else |
fef981b4 | 2038 | TXNSetSelection( m_txn, from, to ); |
0207e969 | 2039 | |
fef981b4 | 2040 | TXNShowSelection( m_txn, kTXNShowStart ); |
5ca0d812 SC |
2041 | } |
2042 | ||
c88b7d28 | 2043 | void wxMacMLTEControl::WriteText( const wxString& str ) |
5ca0d812 | 2044 | { |
5ca0d812 | 2045 | wxString st = str ; |
395480fb | 2046 | wxMacConvertNewlines10To13( &st ) ; |
5ca0d812 SC |
2047 | |
2048 | long start , end , dummy ; | |
0207e969 | 2049 | |
5ca0d812 | 2050 | GetSelection( &start , &dummy ) ; |
5de694f0 | 2051 | wxMacWindowClipper c( m_peer ) ; |
0207e969 | 2052 | |
5de694f0 SC |
2053 | { |
2054 | wxMacEditHelper helper( m_txn ) ; | |
c88b7d28 | 2055 | SetTXNData( st, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; |
5de694f0 | 2056 | } |
a8d2fb31 | 2057 | |
c88b7d28 | 2058 | GetSelection( &dummy, &end ) ; |
fef981b4 DS |
2059 | |
2060 | // TODO: SetStyle( start , end , GetDefaultStyle() ) ; | |
5ca0d812 SC |
2061 | } |
2062 | ||
7d8268a1 | 2063 | void wxMacMLTEControl::Clear() |
5ca0d812 | 2064 | { |
0f7817ab | 2065 | wxMacWindowClipper c( m_peer ) ; |
0207e969 | 2066 | wxMacEditHelper st( m_txn ) ; |
5ca0d812 | 2067 | TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ; |
c88b7d28 | 2068 | TXNClear( m_txn ) ; |
5ca0d812 SC |
2069 | } |
2070 | ||
7d8268a1 | 2071 | bool wxMacMLTEControl::CanUndo() const |
5ca0d812 SC |
2072 | { |
2073 | return TXNCanUndo( m_txn , NULL ) ; | |
2074 | } | |
2075 | ||
7d8268a1 | 2076 | void wxMacMLTEControl::Undo() |
5ca0d812 | 2077 | { |
7d8268a1 WS |
2078 | TXNUndo( m_txn ) ; |
2079 | } | |
5ca0d812 | 2080 | |
fef981b4 | 2081 | bool wxMacMLTEControl::CanRedo() const |
5ca0d812 SC |
2082 | { |
2083 | return TXNCanRedo( m_txn , NULL ) ; | |
7d8268a1 | 2084 | } |
5ca0d812 | 2085 | |
7d8268a1 WS |
2086 | void wxMacMLTEControl::Redo() |
2087 | { | |
5ca0d812 SC |
2088 | TXNRedo( m_txn ) ; |
2089 | } | |
2090 | ||
7d8268a1 | 2091 | int wxMacMLTEControl::GetNumberOfLines() const |
5ca0d812 SC |
2092 | { |
2093 | ItemCount lines = 0 ; | |
fef981b4 DS |
2094 | TXNGetLineCount( m_txn, &lines ) ; |
2095 | ||
5ca0d812 SC |
2096 | return lines ; |
2097 | } | |
2098 | ||
2099 | long wxMacMLTEControl::XYToPosition(long x, long y) const | |
2100 | { | |
2101 | Point curpt ; | |
fef981b4 | 2102 | wxTextPos lastpos ; |
7d8268a1 | 2103 | |
fef981b4 | 2104 | // TODO: find a better implementation : while we can get the |
5ca0d812 SC |
2105 | // line metrics of a certain line, we don't get its starting |
2106 | // position, so it would probably be rather a binary search | |
2107 | // for the start position | |
c88b7d28 | 2108 | long xpos = 0, ypos = 0 ; |
5ca0d812 | 2109 | int lastHeight = 0 ; |
5ca0d812 | 2110 | ItemCount n ; |
fef981b4 DS |
2111 | |
2112 | lastpos = GetLastPosition() ; | |
ebe86b1e | 2113 | for ( n = 0 ; n <= (ItemCount) lastpos ; ++n ) |
bd3169a7 SC |
2114 | { |
2115 | if ( y == ypos && x == xpos ) | |
2116 | return n ; | |
7d8268a1 | 2117 | |
ffafe6ca | 2118 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2119 | |
2120 | if ( curpt.v > lastHeight ) | |
2121 | { | |
2122 | xpos = 0 ; | |
2123 | if ( n > 0 ) | |
2124 | ++ypos ; | |
0207e969 | 2125 | |
bd3169a7 SC |
2126 | lastHeight = curpt.v ; |
2127 | } | |
2128 | else | |
2129 | ++xpos ; | |
2130 | } | |
a8d2fb31 | 2131 | |
5ca0d812 | 2132 | return 0 ; |
72055702 SC |
2133 | } |
2134 | ||
c88b7d28 | 2135 | bool wxMacMLTEControl::PositionToXY( long pos, long *x, long *y ) const |
72055702 | 2136 | { |
bd3169a7 | 2137 | Point curpt ; |
fef981b4 | 2138 | wxTextPos lastpos ; |
7d8268a1 | 2139 | |
fef981b4 DS |
2140 | if ( y ) |
2141 | *y = 0 ; | |
2142 | if ( x ) | |
2143 | *x = 0 ; | |
7d8268a1 | 2144 | |
fef981b4 | 2145 | lastpos = GetLastPosition() ; |
bd3169a7 SC |
2146 | if ( pos <= lastpos ) |
2147 | { | |
c88b7d28 | 2148 | // TODO: find a better implementation - while we can get the |
bd3169a7 SC |
2149 | // line metrics of a certain line, we don't get its starting |
2150 | // position, so it would probably be rather a binary search | |
2151 | // for the start position | |
0207e969 | 2152 | long xpos = 0, ypos = 0 ; |
bd3169a7 | 2153 | int lastHeight = 0 ; |
bd3169a7 | 2154 | ItemCount n ; |
0207e969 | 2155 | |
ebe86b1e | 2156 | for ( n = 0 ; n <= (ItemCount) pos ; ++n ) |
bd3169a7 | 2157 | { |
ffafe6ca | 2158 | TXNOffsetToPoint( m_txn, n, &curpt ) ; |
bd3169a7 SC |
2159 | |
2160 | if ( curpt.v > lastHeight ) | |
2161 | { | |
2162 | xpos = 0 ; | |
2163 | if ( n > 0 ) | |
2164 | ++ypos ; | |
0207e969 | 2165 | |
bd3169a7 SC |
2166 | lastHeight = curpt.v ; |
2167 | } | |
2168 | else | |
2169 | ++xpos ; | |
2170 | } | |
a8d2fb31 | 2171 | |
fef981b4 DS |
2172 | if ( y ) |
2173 | *y = ypos ; | |
2174 | if ( x ) | |
2175 | *x = xpos ; | |
bd3169a7 | 2176 | } |
5ca0d812 | 2177 | |
7d8268a1 | 2178 | return false ; |
72055702 SC |
2179 | } |
2180 | ||
7d8268a1 | 2181 | void wxMacMLTEControl::ShowPosition( long pos ) |
72055702 | 2182 | { |
3a05d58d | 2183 | #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER) |
3a05d58d | 2184 | { |
fef981b4 DS |
2185 | Point current, desired ; |
2186 | TXNOffset selstart, selend; | |
2187 | ||
2188 | TXNGetSelection( m_txn, &selstart, &selend ); | |
2189 | TXNOffsetToPoint( m_txn, selstart, ¤t ); | |
2190 | TXNOffsetToPoint( m_txn, pos, &desired ); | |
2191 | ||
2192 | // TODO: use HIPoints for 10.3 and above | |
2193 | if ( (UInt32)TXNScroll != (UInt32)kUnresolvedCFragSymbolAddress ) | |
f8e089e0 SC |
2194 | { |
2195 | OSErr theErr = noErr; | |
c88b7d28 DS |
2196 | SInt32 dv = desired.v - current.v; |
2197 | SInt32 dh = desired.h - current.h; | |
ffafe6ca | 2198 | TXNShowSelection( m_txn, kTXNShowStart ) ; // NB: should this be kTXNShowStart or kTXNShowEnd ?? |
c88b7d28 | 2199 | theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, &dv, &dh ); |
fef981b4 DS |
2200 | |
2201 | // there will be an error returned for classic MLTE implementation when the control is | |
4d7528a1 SC |
2202 | // invisible, but HITextView works correctly, so we don't assert that one |
2203 | // wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") ); | |
f8e089e0 | 2204 | } |
3a05d58d SC |
2205 | } |
2206 | #endif | |
5ca0d812 SC |
2207 | } |
2208 | ||
fef981b4 | 2209 | void wxMacMLTEControl::SetTXNData( const wxString& st, TXNOffset start, TXNOffset end ) |
5ca0d812 SC |
2210 | { |
2211 | #if wxUSE_UNICODE | |
2212 | #if SIZEOF_WCHAR_T == 2 | |
7d8268a1 | 2213 | size_t len = st.Len() ; |
fef981b4 | 2214 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)st.wc_str(), len * 2, start, end ); |
5ca0d812 | 2215 | #else |
d9d488cf | 2216 | wxMBConvUTF16 converter ; |
c88b7d28 DS |
2217 | ByteCount byteBufferLen = converter.WC2MB( NULL, st.wc_str(), 0 ) ; |
2218 | UniChar *unibuf = (UniChar*)malloc( byteBufferLen ) ; | |
fef981b4 DS |
2219 | converter.WC2MB( (char*)unibuf, st.wc_str(), byteBufferLen ) ; |
2220 | TXNSetData( m_txn, kTXNUnicodeTextData, (void*)unibuf, byteBufferLen, start, end ) ; | |
7d8268a1 | 2221 | free( unibuf ) ; |
587bc950 | 2222 | #endif |
5ca0d812 | 2223 | #else |
c88b7d28 | 2224 | wxCharBuffer text = st.mb_str( wxConvLocal ) ; |
fef981b4 | 2225 | TXNSetData( m_txn, kTXNTextData, (void*)text.data(), strlen( text ), start, end ) ; |
7d8268a1 | 2226 | #endif |
72055702 SC |
2227 | } |
2228 | ||
5ca0d812 | 2229 | wxString wxMacMLTEControl::GetLineText(long lineNo) const |
72055702 | 2230 | { |
5ca0d812 | 2231 | wxString line ; |
5ca0d812 | 2232 | |
bd3169a7 | 2233 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2234 | { |
fef981b4 DS |
2235 | Point firstPoint; |
2236 | Fixed lineWidth, lineHeight, currentHeight; | |
2237 | long ypos ; | |
7d8268a1 | 2238 | |
ae25e5cc | 2239 | // get the first possible position in the control |
ae25e5cc | 2240 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2241 | |
ae25e5cc RN |
2242 | // Iterate through the lines until we reach the one we want, |
2243 | // adding to our current y pixel point position | |
fef981b4 DS |
2244 | ypos = 0 ; |
2245 | currentHeight = 0; | |
ae25e5cc | 2246 | while (ypos < lineNo) |
32b5be3d | 2247 | { |
ae25e5cc RN |
2248 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2249 | currentHeight += lineHeight; | |
2250 | } | |
7d8268a1 | 2251 | |
eab19a7c | 2252 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2253 | TXNOffset theOffset; |
2254 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2255 | |
ae25e5cc RN |
2256 | wxString content = GetStringValue() ; |
2257 | Point currentPoint = thePoint; | |
fef981b4 | 2258 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2259 | { |
2260 | line += content[theOffset]; | |
2261 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
21fd5529 | 2262 | } |
21fd5529 | 2263 | } |
fef981b4 | 2264 | |
5ca0d812 | 2265 | return line ; |
72055702 SC |
2266 | } |
2267 | ||
ffafe6ca | 2268 | int wxMacMLTEControl::GetLineLength(long lineNo) const |
72055702 | 2269 | { |
ae25e5cc RN |
2270 | int theLength = 0; |
2271 | ||
bd3169a7 | 2272 | if ( lineNo < GetNumberOfLines() ) |
32b5be3d | 2273 | { |
fef981b4 DS |
2274 | Point firstPoint; |
2275 | Fixed lineWidth, lineHeight, currentHeight; | |
ffafe6ca | 2276 | long ypos; |
7d8268a1 | 2277 | |
ae25e5cc | 2278 | // get the first possible position in the control |
ae25e5cc | 2279 | TXNOffsetToPoint(m_txn, 0, &firstPoint); |
7d8268a1 | 2280 | |
ae25e5cc RN |
2281 | // Iterate through the lines until we reach the one we want, |
2282 | // adding to our current y pixel point position | |
fef981b4 DS |
2283 | ypos = 0; |
2284 | currentHeight = 0; | |
ae25e5cc | 2285 | while (ypos < lineNo) |
32b5be3d | 2286 | { |
ae25e5cc RN |
2287 | TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight); |
2288 | currentHeight += lineHeight; | |
2289 | } | |
7d8268a1 | 2290 | |
eab19a7c | 2291 | Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) }; |
ae25e5cc RN |
2292 | TXNOffset theOffset; |
2293 | TXNPointToOffset(m_txn, thePoint, &theOffset); | |
7d8268a1 | 2294 | |
ae25e5cc RN |
2295 | wxString content = GetStringValue() ; |
2296 | Point currentPoint = thePoint; | |
fef981b4 | 2297 | while (thePoint.v == currentPoint.v && theOffset < content.length()) |
ae25e5cc RN |
2298 | { |
2299 | ++theLength; | |
2300 | TXNOffsetToPoint(m_txn, ++theOffset, ¤tPoint); | |
29e4a190 | 2301 | } |
29e4a190 | 2302 | } |
fef981b4 | 2303 | |
ae25e5cc | 2304 | return theLength ; |
5ca0d812 | 2305 | } |
21fd5529 | 2306 | |
5ca0d812 SC |
2307 | // ---------------------------------------------------------------------------- |
2308 | // MLTE control implementation (classic part) | |
2309 | // ---------------------------------------------------------------------------- | |
21fd5529 | 2310 | |
5de694f0 SC |
2311 | // OS X Notes : We still don't have a full replacement for MLTE, so this implementation |
2312 | // has to live on. We have different problems coming from outdated implementations on the | |
2313 | // various OS X versions. Most deal with the scrollbars: they are not correctly embedded | |
2314 | // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is | |
2315 | // no way out, therefore we are using our own implementation and our own scrollbars .... | |
5ca0d812 | 2316 | |
5de694f0 | 2317 | #ifdef __WXMAC_OSX__ |
0f7817ab | 2318 | |
5de694f0 SC |
2319 | TXNScrollInfoUPP gTXNScrollInfoProc = NULL ; |
2320 | ControlActionUPP gTXNScrollActionProc = NULL ; | |
0f7817ab | 2321 | |
fef981b4 DS |
2322 | pascal void wxMacMLTEClassicControl::TXNScrollInfoProc( |
2323 | SInt32 iValue, SInt32 iMaximumValue, | |
0207e969 | 2324 | TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon ) |
0f7817ab | 2325 | { |
5de694f0 SC |
2326 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ; |
2327 | SInt32 value = wxMax( iValue , 0 ) ; | |
2328 | SInt32 maximum = wxMax( iMaximumValue , 0 ) ; | |
3dee36ae | 2329 | |
5de694f0 SC |
2330 | if ( iScrollBarOrientation == kTXNHorizontal ) |
2331 | { | |
2332 | if ( mlte->m_sbHorizontal ) | |
2333 | { | |
2334 | SetControl32BitValue( mlte->m_sbHorizontal , value ) ; | |
2335 | SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ; | |
2336 | mlte->m_lastHorizontalValue = value ; | |
2337 | } | |
2338 | } | |
2339 | else if ( iScrollBarOrientation == kTXNVertical ) | |
5ca0d812 | 2340 | { |
5de694f0 SC |
2341 | if ( mlte->m_sbVertical ) |
2342 | { | |
2343 | SetControl32BitValue( mlte->m_sbVertical , value ) ; | |
2344 | SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ; | |
2345 | mlte->m_lastVerticalValue = value ; | |
2346 | } | |
72055702 SC |
2347 | } |
2348 | } | |
2349 | ||
5de694f0 | 2350 | pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode ) |
72055702 | 2351 | { |
5de694f0 SC |
2352 | wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ; |
2353 | if ( mlte == NULL ) | |
2354 | return ; | |
3dee36ae | 2355 | |
5de694f0 | 2356 | if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal ) |
3dee36ae WS |
2357 | return ; |
2358 | ||
fef981b4 | 2359 | OSStatus err ; |
3dee36ae WS |
2360 | bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ; |
2361 | ||
5de694f0 SC |
2362 | SInt32 minimum = 0 ; |
2363 | SInt32 maximum = GetControl32BitMaximum( controlRef ) ; | |
2364 | SInt32 value = GetControl32BitValue( controlRef ) ; | |
2365 | SInt32 delta = 0; | |
fef981b4 | 2366 | |
5de694f0 SC |
2367 | switch ( partCode ) |
2368 | { | |
2369 | case kControlDownButtonPart : | |
2370 | delta = 10 ; | |
2371 | break ; | |
fef981b4 | 2372 | |
5de694f0 SC |
2373 | case kControlUpButtonPart : |
2374 | delta = -10 ; | |
2375 | break ; | |
fef981b4 | 2376 | |
5de694f0 SC |
2377 | case kControlPageDownPart : |
2378 | delta = GetControlViewSize( controlRef ) ; | |
2379 | break ; | |
fef981b4 | 2380 | |
5de694f0 | 2381 | case kControlPageUpPart : |
fef981b4 | 2382 | delta = -GetControlViewSize( controlRef ) ; |
5de694f0 | 2383 | break ; |
fef981b4 | 2384 | |
5de694f0 | 2385 | case kControlIndicatorPart : |
c88b7d28 | 2386 | delta = value - (isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue) ; |
5de694f0 | 2387 | break ; |
fef981b4 | 2388 | |
5de694f0 SC |
2389 | default : |
2390 | break ; | |
2391 | } | |
fef981b4 | 2392 | |
5de694f0 | 2393 | if ( delta != 0 ) |
e600c175 | 2394 | { |
5de694f0 | 2395 | SInt32 newValue = value ; |
3dee36ae | 2396 | |
5de694f0 SC |
2397 | if ( partCode != kControlIndicatorPart ) |
2398 | { | |
fef981b4 | 2399 | if ( value + delta < minimum ) |
5de694f0 SC |
2400 | delta = minimum - value ; |
2401 | if ( value + delta > maximum ) | |
2402 | delta = maximum - value ; | |
2403 | ||
2404 | SetControl32BitValue( controlRef , value + delta ) ; | |
2405 | newValue = value + delta ; | |
2406 | } | |
3dee36ae | 2407 | |
5de694f0 SC |
2408 | SInt32 verticalDelta = isHorizontal ? 0 : delta ; |
2409 | SInt32 horizontalDelta = isHorizontal ? delta : 0 ; | |
3dee36ae | 2410 | |
0207e969 DS |
2411 | err = TXNScroll( |
2412 | mlte->m_txn, kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels, | |
2413 | &verticalDelta, &horizontalDelta ); | |
ffafe6ca | 2414 | verify_noerr( err ); |
3dee36ae | 2415 | |
5de694f0 SC |
2416 | if ( isHorizontal ) |
2417 | mlte->m_lastHorizontalValue = newValue ; | |
2418 | else | |
2419 | mlte->m_lastVerticalValue = newValue ; | |
5ca0d812 | 2420 | } |
5ca0d812 | 2421 | } |
5de694f0 | 2422 | #endif |
7d8268a1 | 2423 | |
0f7817ab | 2424 | // make correct activations |
fef981b4 | 2425 | void wxMacMLTEClassicControl::MacActivatePaneText(bool setActive) |
0f7817ab SC |
2426 | { |
2427 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef); | |
ef4a634b | 2428 | |
5de694f0 | 2429 | wxMacWindowClipper clipper( textctrl ) ; |
c88b7d28 | 2430 | TXNActivate( m_txn, m_txnFrameID, setActive ); |
0f7817ab | 2431 | |
5de694f0 SC |
2432 | ControlRef controlFocus = 0 ; |
2433 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
2434 | if ( controlFocus == m_controlRef ) | |
fef981b4 | 2435 | TXNFocus( m_txn, setActive ); |
5de694f0 SC |
2436 | } |
2437 | ||
fef981b4 | 2438 | void wxMacMLTEClassicControl::MacFocusPaneText(bool setFocus) |
5de694f0 | 2439 | { |
0207e969 | 2440 | TXNFocus( m_txn, setFocus ); |
5ca0d812 | 2441 | } |
1fa29bdc | 2442 | |
3dee36ae | 2443 | // guards against inappropriate redraw (hidden objects drawing onto window) |
0f7817ab | 2444 | |
fef981b4 | 2445 | void wxMacMLTEClassicControl::MacSetObjectVisibility(bool vis) |
0f7817ab | 2446 | { |
789ae0cf SC |
2447 | ControlRef controlFocus = 0 ; |
2448 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; | |
3dee36ae | 2449 | |
fef981b4 | 2450 | if ( !vis && (controlFocus == m_controlRef ) ) |
789ae0cf | 2451 | SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ; |
3dee36ae | 2452 | |
4611a719 | 2453 | TXNControlTag iControlTags[1] = { kTXNVisibilityTag }; |
c88b7d28 | 2454 | TXNControlData iControlData[1] = { { (UInt32)false } }; |
bd2213c2 | 2455 | |
fef981b4 | 2456 | verify_noerr( TXNGetTXNObjectControls( m_txn , 1, iControlTags, iControlData ) ) ; |
3dee36ae | 2457 | |
bd2213c2 SC |
2458 | if ( iControlData[0].uValue != vis ) |
2459 | { | |
2460 | iControlData[0].uValue = vis ; | |
0207e969 | 2461 | verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1, iControlTags, iControlData ) ) ; |
bd2213c2 | 2462 | } |
fef981b4 | 2463 | |
0207e969 DS |
2464 | // currently, we always clip as partial visibility (overlapped) visibility is also a problem, |
2465 | // if we run into further problems we might set the FrameBounds to an empty rect here | |
5ca0d812 | 2466 | } |
1fa29bdc | 2467 | |
0f7817ab | 2468 | // make sure that the TXNObject is at the right position |
5de694f0 | 2469 | |
3dee36ae | 2470 | void wxMacMLTEClassicControl::MacUpdatePosition() |
0f7817ab | 2471 | { |
c88b7d28 | 2472 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
0f7817ab SC |
2473 | if ( textctrl == NULL ) |
2474 | return ; | |
7d8268a1 | 2475 | |
0f7817ab | 2476 | Rect bounds ; |
c88b7d28 | 2477 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2478 | |
ba75e603 SC |
2479 | wxRect visRect = textctrl->MacGetClippedClientRect() ; |
2480 | Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ; | |
2481 | int x , y ; | |
2482 | x = y = 0 ; | |
2483 | textctrl->MacWindowToRootWindow( &x , &y ) ; | |
2484 | OffsetRect( &visBounds , x , y ) ; | |
3dee36ae | 2485 | |
c88b7d28 | 2486 | if ( !EqualRect( &bounds, &m_txnControlBounds ) || !EqualRect( &visBounds, &m_txnVisBounds ) ) |
0f7817ab | 2487 | { |
0f7817ab | 2488 | m_txnControlBounds = bounds ; |
ba75e603 | 2489 | m_txnVisBounds = visBounds ; |
c88b7d28 | 2490 | wxMacWindowClipper cl( textctrl ) ; |
5de694f0 | 2491 | |
4e477040 | 2492 | #ifdef __WXMAC_OSX__ |
789ae0cf | 2493 | bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ; |
4e477040 SC |
2494 | if ( m_sbHorizontal || m_sbVertical ) |
2495 | { | |
5de694f0 SC |
2496 | int w = bounds.right - bounds.left ; |
2497 | int h = bounds.bottom - bounds.top ; | |
4e477040 SC |
2498 | |
2499 | if ( m_sbHorizontal ) | |
2500 | { | |
2501 | Rect sbBounds ; | |
5de694f0 | 2502 | |
4e477040 | 2503 | sbBounds.left = -1 ; |
5de694f0 SC |
2504 | sbBounds.top = h - 14 ; |
2505 | sbBounds.right = w + 1 ; | |
2506 | sbBounds.bottom = h + 1 ; | |
3dee36ae | 2507 | |
789ae0cf SC |
2508 | if ( !isCompositing ) |
2509 | OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; | |
3dee36ae | 2510 | |
4e477040 | 2511 | SetControlBounds( m_sbHorizontal , &sbBounds ) ; |
5de694f0 | 2512 | SetControlViewSize( m_sbHorizontal , w ) ; |
4e477040 | 2513 | } |
0207e969 | 2514 | |
4e477040 SC |
2515 | if ( m_sbVertical ) |
2516 | { | |
2517 | Rect sbBounds ; | |
5de694f0 SC |
2518 | |
2519 | sbBounds.left = w - 14 ; | |
4e477040 | 2520 | sbBounds.top = -1 ; |
5de694f0 | 2521 | sbBounds.right = w + 1 ; |
fef981b4 | 2522 | sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ; |
3dee36ae | 2523 | |
789ae0cf SC |
2524 | if ( !isCompositing ) |
2525 | OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ; | |
2526 | ||
4e477040 | 2527 | SetControlBounds( m_sbVertical , &sbBounds ) ; |
5de694f0 | 2528 | SetControlViewSize( m_sbVertical , h ) ; |
4e477040 SC |
2529 | } |
2530 | } | |
3dee36ae | 2531 | |
c447d5a9 SC |
2532 | Rect oldviewRect ; |
2533 | TXNLongRect olddestRect ; | |
2534 | TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ; | |
3dee36ae | 2535 | |
c447d5a9 | 2536 | Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2537 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2538 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
c447d5a9 | 2539 | TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left, |
fef981b4 DS |
2540 | m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , |
2541 | m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ; | |
3dee36ae | 2542 | |
c447d5a9 SC |
2543 | if ( olddestRect.right >= 10000 ) |
2544 | destRect.right = destRect.left + 32000 ; | |
3dee36ae | 2545 | |
c447d5a9 SC |
2546 | if ( olddestRect.bottom >= 0x20000000 ) |
2547 | destRect.bottom = destRect.top + 0x40000000 ; | |
3dee36ae WS |
2548 | |
2549 | SectRect( &viewRect , &visBounds , &viewRect ) ; | |
823c4e96 | 2550 | TXNSetRectBounds( m_txn , &viewRect , &destRect , true ) ; |
fef981b4 DS |
2551 | |
2552 | #if 0 | |
2553 | TXNSetFrameBounds( | |
2554 | m_txn, | |
2555 | m_txnControlBounds.top, | |
2556 | m_txnControlBounds.left, | |
2557 | m_txnControlBounds.bottom - (m_sbHorizontal ? 14 : 0), | |
2558 | m_txnControlBounds.right - (m_sbVertical ? 14 : 0), | |
2559 | m_txnFrameID ); | |
2560 | #endif | |
5de694f0 | 2561 | #else |
3dee36ae | 2562 | |
c88b7d28 DS |
2563 | TXNSetFrameBounds( |
2564 | m_txn, m_txnControlBounds.top, m_txnControlBounds.left, | |
2565 | wxMax( m_txnControlBounds.bottom, m_txnControlBounds.top ), | |
2566 | wxMax( m_txnControlBounds.right, m_txnControlBounds.left ), m_txnFrameID ); | |
24eef584 | 2567 | #endif |
c88b7d28 DS |
2568 | |
2569 | // the SetFrameBounds method under Classic sometimes does not correctly scroll a selection into sight after a | |
5de694f0 SC |
2570 | // movement, therefore we have to force it |
2571 | ||
fef981b4 | 2572 | // this problem has been reported in OSX as well, so we use this here once again |
0207e969 | 2573 | |
5de694f0 | 2574 | TXNLongRect textRect ; |
3dee36ae | 2575 | TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ; |
5de694f0 | 2576 | if ( textRect.left < m_txnControlBounds.left ) |
fef981b4 | 2577 | TXNShowSelection( m_txn , kTXNShowStart ) ; |
e600c175 | 2578 | } |
5ca0d812 SC |
2579 | } |
2580 | ||
3dee36ae | 2581 | void wxMacMLTEClassicControl::SetRect( Rect *r ) |
0f7817ab SC |
2582 | { |
2583 | wxMacControl::SetRect( r ) ; | |
2584 | MacUpdatePosition() ; | |
2585 | } | |
2586 | ||
3dee36ae | 2587 | void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart) |
24260aae | 2588 | { |
c88b7d28 | 2589 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2590 | if ( textctrl == NULL ) |
e600c175 | 2591 | return ; |
7d8268a1 | 2592 | |
5ca0d812 SC |
2593 | if ( textctrl->MacIsReallyShown() ) |
2594 | { | |
2595 | wxMacWindowClipper clipper( textctrl ) ; | |
0f7817ab | 2596 | TXNDraw( m_txn , NULL ) ; |
e600c175 | 2597 | } |
5ca0d812 SC |
2598 | } |
2599 | ||
3dee36ae | 2600 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) |
24260aae SC |
2601 | { |
2602 | Point where = { y , x } ; | |
a8d2fb31 | 2603 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2604 | |
0207e969 | 2605 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2606 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
72055702 | 2607 | { |
fef981b4 DS |
2608 | if (PtInRect( where, &m_txnControlBounds )) |
2609 | { | |
5de694f0 | 2610 | result = kControlEditTextPart ; |
fef981b4 | 2611 | } |
7d8268a1 | 2612 | else |
3556e470 SC |
2613 | { |
2614 | // sometimes we get the coords also in control local coordinates, therefore test again | |
2615 | if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) | |
2616 | { | |
2617 | int x = 0 , y = 0 ; | |
2618 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2619 | where.h += x ; | |
2620 | where.v += y ; | |
2621 | } | |
fef981b4 | 2622 | |
0207e969 | 2623 | if (PtInRect( where, &m_txnControlBounds )) |
5de694f0 | 2624 | result = kControlEditTextPart ; |
3556e470 | 2625 | } |
5ca0d812 | 2626 | } |
a8d2fb31 | 2627 | |
5ca0d812 SC |
2628 | return result; |
2629 | } | |
2630 | ||
3dee36ae | 2631 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc ) |
24260aae | 2632 | { |
a8d2fb31 | 2633 | ControlPartCode result = kControlNoPart; |
5de694f0 | 2634 | |
0207e969 | 2635 | wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference( m_controlRef ); |
a8d2fb31 | 2636 | if ( (textctrl != NULL) && textctrl->MacIsReallyShown() ) |
7d8268a1 | 2637 | { |
a8d2fb31 | 2638 | Point startPt = { y , x } ; |
5ca0d812 SC |
2639 | // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them |
2640 | if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) | |
2641 | { | |
2642 | int x = 0 , y = 0 ; | |
2643 | textctrl->MacClientToRootWindow( &x , &y ) ; | |
2644 | startPt.h += x ; | |
2645 | startPt.v += y ; | |
2646 | } | |
7d8268a1 | 2647 | |
24260aae | 2648 | switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v )) |
5ca0d812 | 2649 | { |
5de694f0 | 2650 | case kControlEditTextPart : |
7d8268a1 WS |
2651 | { |
2652 | wxMacWindowClipper clipper( textctrl ) ; | |
7d8268a1 | 2653 | EventRecord rec ; |
c88b7d28 | 2654 | |
7d8268a1 | 2655 | ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ; |
24260aae | 2656 | TXNClick( m_txn, &rec ); |
7d8268a1 | 2657 | } |
fef981b4 | 2658 | break; |
a8d2fb31 | 2659 | |
fef981b4 DS |
2660 | default : |
2661 | break; | |
5ca0d812 SC |
2662 | } |
2663 | } | |
a8d2fb31 DS |
2664 | |
2665 | return result; | |
5ca0d812 SC |
2666 | } |
2667 | ||
3dee36ae | 2668 | void wxMacMLTEClassicControl::MacControlUserPaneIdleProc() |
24260aae | 2669 | { |
c88b7d28 | 2670 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 SC |
2671 | if ( textctrl == NULL ) |
2672 | return ; | |
24260aae | 2673 | |
3dee36ae | 2674 | if (textctrl->MacIsReallyShown()) |
24260aae | 2675 | { |
3dee36ae | 2676 | if (IsControlActive(m_controlRef)) |
24260aae | 2677 | { |
5ca0d812 | 2678 | Point mousep; |
7d8268a1 | 2679 | |
5ca0d812 SC |
2680 | wxMacWindowClipper clipper( textctrl ) ; |
2681 | GetMouse(&mousep); | |
5de694f0 SC |
2682 | |
2683 | TXNIdle(m_txn); | |
2684 | ||
3dee36ae | 2685 | if (PtInRect(mousep, &m_txnControlBounds)) |
24260aae | 2686 | { |
fef981b4 DS |
2687 | RgnHandle theRgn = NewRgn(); |
2688 | RectRgn(theRgn, &m_txnControlBounds); | |
5de694f0 SC |
2689 | TXNAdjustCursor(m_txn, theRgn); |
2690 | DisposeRgn(theRgn); | |
72055702 | 2691 | } |
5ca0d812 SC |
2692 | } |
2693 | } | |
2694 | } | |
72055702 | 2695 | |
3dee36ae | 2696 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) |
24260aae | 2697 | { |
c88b7d28 | 2698 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2699 | if ( textctrl == NULL ) |
a8d2fb31 | 2700 | return kControlNoPart; |
7d8268a1 | 2701 | |
5de694f0 | 2702 | wxMacWindowClipper clipper( textctrl ) ; |
ef4a634b | 2703 | |
5de694f0 SC |
2704 | EventRecord ev ; |
2705 | memset( &ev , 0 , sizeof( ev ) ) ; | |
2706 | ev.what = keyDown ; | |
2707 | ev.modifiers = modifiers ; | |
fef981b4 DS |
2708 | ev.message = ((keyCode << 8) & keyCodeMask) | (charCode & charCodeMask); |
2709 | TXNKeyDown( m_txn , &ev ); | |
3dee36ae | 2710 | |
5de694f0 SC |
2711 | return kControlEntireControl; |
2712 | } | |
24260aae | 2713 | |
c88b7d28 | 2714 | void wxMacMLTEClassicControl::MacControlUserPaneActivateProc(bool activating) |
24260aae | 2715 | { |
5de694f0 | 2716 | MacActivatePaneText( activating ); |
72055702 SC |
2717 | } |
2718 | ||
3dee36ae | 2719 | wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action) |
24260aae | 2720 | { |
c88b7d28 | 2721 | ControlPartCode focusResult = kControlFocusNoPart; |
7d8268a1 | 2722 | |
c88b7d28 | 2723 | wxTextCtrl* textctrl = (wxTextCtrl*)GetControlReference( m_controlRef ); |
5ca0d812 | 2724 | if ( textctrl == NULL ) |
c88b7d28 | 2725 | return focusResult; |
0f7817ab SC |
2726 | |
2727 | wxMacWindowClipper clipper( textctrl ) ; | |
3dee36ae | 2728 | |
a8d2fb31 | 2729 | ControlRef controlFocus = NULL ; |
5de694f0 SC |
2730 | GetKeyboardFocus( m_txnWindow , &controlFocus ) ; |
2731 | bool wasFocused = ( controlFocus == m_controlRef ) ; | |
2732 | ||
3dee36ae | 2733 | switch (action) |
24260aae | 2734 | { |
5de694f0 SC |
2735 | case kControlFocusPrevPart: |
2736 | case kControlFocusNextPart: | |
0207e969 DS |
2737 | MacFocusPaneText( !wasFocused ); |
2738 | focusResult = (!wasFocused ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart); | |
5de694f0 | 2739 | break; |
3dee36ae | 2740 | |
5ca0d812 | 2741 | case kControlFocusNoPart: |
5de694f0 | 2742 | default: |
a8d2fb31 | 2743 | MacFocusPaneText( false ); |
5ca0d812 SC |
2744 | focusResult = kControlFocusNoPart; |
2745 | break; | |
5ca0d812 | 2746 | } |
0f7817ab | 2747 | |
5ca0d812 | 2748 | return focusResult; |
72055702 SC |
2749 | } |
2750 | ||
24260aae SC |
2751 | void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info ) |
2752 | { | |
2753 | } | |
2754 | ||
0f7817ab | 2755 | wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
2756 | const wxString& str, |
2757 | const wxPoint& pos, | |
2758 | const wxSize& size, long style ) | |
2759 | : wxMacMLTEControl( wxPeer ) | |
72055702 | 2760 | { |
5ca0d812 SC |
2761 | m_font = wxPeer->GetFont() ; |
2762 | m_windowStyle = style ; | |
7d8268a1 | 2763 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
72055702 | 2764 | |
c88b7d28 | 2765 | short featureSet = |
0207e969 DS |
2766 | kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle |
2767 | | kControlWantsActivate | kControlHandlesTracking | |
2768 | // | kControlHasSpecialBackground | |
2769 | | kControlGetsFocusOnClick | kControlSupportsLiveFeedback; | |
72055702 | 2770 | |
ffafe6ca DS |
2771 | OSStatus err = ::CreateUserPaneControl( |
2772 | MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), | |
2773 | &bounds, featureSet, &m_controlRef ); | |
2774 | verify_noerr( err ); | |
7d8268a1 | 2775 | |
0f7817ab | 2776 | DoCreate(); |
7d8268a1 | 2777 | |
a8d2fb31 | 2778 | AdjustCreationAttributes( *wxWHITE , true ) ; |
5ca0d812 | 2779 | |
bd2213c2 SC |
2780 | MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ; |
2781 | ||
24eef584 SC |
2782 | { |
2783 | wxString st = str ; | |
2784 | wxMacConvertNewlines10To13( &st ) ; | |
2785 | wxMacWindowClipper clipper( m_peer ) ; | |
2786 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; | |
0207e969 | 2787 | TXNSetSelection( m_txn, 0, 0 ) ; |
24eef584 | 2788 | } |
72055702 SC |
2789 | } |
2790 | ||
5ca0d812 | 2791 | wxMacMLTEClassicControl::~wxMacMLTEClassicControl() |
72055702 | 2792 | { |
0207e969 | 2793 | TXNDeleteObject( m_txn ); |
5de694f0 | 2794 | m_txn = NULL ; |
72055702 SC |
2795 | } |
2796 | ||
7d8268a1 | 2797 | void wxMacMLTEClassicControl::VisibilityChanged(bool shown) |
72055702 | 2798 | { |
0f7817ab | 2799 | MacSetObjectVisibility( shown ) ; |
4e477040 SC |
2800 | wxMacControl::VisibilityChanged( shown ) ; |
2801 | } | |
2802 | ||
2803 | void wxMacMLTEClassicControl::SuperChangedPosition() | |
2804 | { | |
2805 | MacUpdatePosition() ; | |
2806 | wxMacControl::SuperChangedPosition() ; | |
72055702 SC |
2807 | } |
2808 | ||
24260aae SC |
2809 | #ifdef __WXMAC_OSX__ |
2810 | ||
5de694f0 SC |
2811 | ControlUserPaneDrawUPP gTPDrawProc = NULL; |
2812 | ControlUserPaneHitTestUPP gTPHitProc = NULL; | |
2813 | ControlUserPaneTrackingUPP gTPTrackProc = NULL; | |
2814 | ControlUserPaneIdleUPP gTPIdleProc = NULL; | |
2815 | ControlUserPaneKeyDownUPP gTPKeyProc = NULL; | |
2816 | ControlUserPaneActivateUPP gTPActivateProc = NULL; | |
2817 | ControlUserPaneFocusUPP gTPFocusProc = NULL; | |
2818 | ||
24260aae SC |
2819 | static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) |
2820 | { | |
2821 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2822 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2823 | if ( win ) |
ffafe6ca | 2824 | win->MacControlUserPaneDrawProc( part ) ; |
24260aae SC |
2825 | } |
2826 | ||
c7fe80e2 | 2827 | static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) |
24260aae SC |
2828 | { |
2829 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2830 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2831 | if ( win ) |
ffafe6ca | 2832 | return win->MacControlUserPaneHitTestProc( where.h , where.v ) ; |
24260aae SC |
2833 | else |
2834 | return kControlNoPart ; | |
2835 | } | |
2836 | ||
c7fe80e2 | 2837 | static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) |
24260aae SC |
2838 | { |
2839 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2840 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2841 | if ( win ) |
ffafe6ca | 2842 | return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc ) ; |
24260aae SC |
2843 | else |
2844 | return kControlNoPart ; | |
2845 | } | |
2846 | ||
2847 | static pascal void wxMacControlUserPaneIdleProc(ControlRef control) | |
2848 | { | |
2849 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2850 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2851 | if ( win ) |
2852 | win->MacControlUserPaneIdleProc() ; | |
2853 | } | |
2854 | ||
2855 | static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) | |
2856 | { | |
2857 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2858 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2859 | if ( win ) |
ffafe6ca | 2860 | return win->MacControlUserPaneKeyDownProc( keyCode, charCode, modifiers ) ; |
24260aae SC |
2861 | else |
2862 | return kControlNoPart ; | |
2863 | } | |
2864 | ||
2865 | static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) | |
2866 | { | |
2867 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2868 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2869 | if ( win ) |
ffafe6ca | 2870 | win->MacControlUserPaneActivateProc( activating ) ; |
24260aae SC |
2871 | } |
2872 | ||
2873 | static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) | |
2874 | { | |
2875 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2876 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae | 2877 | if ( win ) |
ffafe6ca | 2878 | return win->MacControlUserPaneFocusProc( action ) ; |
24260aae SC |
2879 | else |
2880 | return kControlNoPart ; | |
2881 | } | |
2882 | ||
fef981b4 | 2883 | #if 0 |
24260aae SC |
2884 | static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) |
2885 | { | |
2886 | wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ; | |
bc8f7aee | 2887 | wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ; |
24260aae SC |
2888 | if ( win ) |
2889 | win->MacControlUserPaneBackgroundProc(info) ; | |
2890 | } | |
2891 | #endif | |
2892 | ||
fef981b4 DS |
2893 | #endif // __WXMAC_OSX__ |
2894 | ||
5de694f0 SC |
2895 | // TXNRegisterScrollInfoProc |
2896 | ||
5ca0d812 | 2897 | OSStatus wxMacMLTEClassicControl::DoCreate() |
2b5f62a0 | 2898 | { |
5ca0d812 | 2899 | Rect bounds; |
5ca0d812 | 2900 | OSStatus err = noErr ; |
7d8268a1 | 2901 | |
fef981b4 | 2902 | // set up our globals |
24260aae SC |
2903 | #ifdef __WXMAC_OSX__ |
2904 | if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc); | |
2905 | if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc); | |
2906 | if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc); | |
2907 | if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc); | |
2908 | if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc); | |
2909 | if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc); | |
2910 | if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc); | |
5de694f0 SC |
2911 | |
2912 | if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ; | |
2913 | if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ; | |
24260aae | 2914 | #endif |
7d8268a1 | 2915 | |
fef981b4 | 2916 | // set the initial settings for our private data |
7d8268a1 | 2917 | |
a8d2fb31 | 2918 | m_txnWindow = GetControlOwner(m_controlRef); |
5de694f0 | 2919 | m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow); |
7d8268a1 | 2920 | |
24260aae | 2921 | #ifdef __WXMAC_OSX__ |
fef981b4 | 2922 | // set up the user pane procedures |
5ca0d812 SC |
2923 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc); |
2924 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc); | |
2925 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc); | |
2926 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc); | |
2927 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc); | |
2928 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc); | |
2929 | SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc); | |
24260aae | 2930 | #endif |
c88b7d28 | 2931 | |
fef981b4 | 2932 | // calculate the rectangles used by the control |
c88b7d28 | 2933 | UMAGetControlBoundsInWindowCoords( m_controlRef, &bounds ); |
3dee36ae | 2934 | |
0f7817ab | 2935 | m_txnControlBounds = bounds ; |
ba75e603 | 2936 | m_txnVisBounds = bounds ; |
3dee36ae | 2937 | |
fef981b4 DS |
2938 | CGrafPtr origPort ; |
2939 | GDHandle origDev ; | |
7d8268a1 | 2940 | |
c88b7d28 | 2941 | GetGWorld( &origPort, &origDev ) ; |
fef981b4 | 2942 | SetPort( m_txnPort ); |
7d8268a1 | 2943 | |
fef981b4 | 2944 | // create the new edit field |
c88b7d28 | 2945 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ); |
7d8268a1 | 2946 | |
4e477040 | 2947 | #ifdef __WXMAC_OSX__ |
fef981b4 DS |
2948 | // the scrollbars are not correctly embedded but are inserted at the root: |
2949 | // this gives us problems as we have erratic redraws even over the structure area | |
4e477040 | 2950 | |
5de694f0 SC |
2951 | m_sbHorizontal = 0 ; |
2952 | m_sbVertical = 0 ; | |
2953 | m_lastHorizontalValue = 0 ; | |
2954 | m_lastVerticalValue = 0 ; | |
3dee36ae | 2955 | |
5de694f0 SC |
2956 | Rect sb = { 0 , 0 , 0 , 0 } ; |
2957 | if ( frameOptions & kTXNWantVScrollBarMask ) | |
2958 | { | |
c88b7d28 DS |
2959 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbVertical ); |
2960 | SetControlReference( m_sbVertical, (SInt32)this ); | |
5de694f0 | 2961 | SetControlAction( m_sbVertical, gTXNScrollActionProc ); |
c88b7d28 DS |
2962 | ShowControl( m_sbVertical ); |
2963 | EmbedControl( m_sbVertical , m_controlRef ); | |
2964 | frameOptions &= ~kTXNWantVScrollBarMask; | |
5de694f0 | 2965 | } |
fef981b4 | 2966 | |
5de694f0 SC |
2967 | if ( frameOptions & kTXNWantHScrollBarMask ) |
2968 | { | |
c88b7d28 DS |
2969 | CreateScrollBarControl( m_txnWindow, &sb, 0, 0, 100, 1, true, gTXNScrollActionProc, &m_sbHorizontal ); |
2970 | SetControlReference( m_sbHorizontal, (SInt32)this ); | |
5de694f0 | 2971 | SetControlAction( m_sbHorizontal, gTXNScrollActionProc ); |
c88b7d28 DS |
2972 | ShowControl( m_sbHorizontal ); |
2973 | EmbedControl( m_sbHorizontal, m_controlRef ); | |
5de694f0 SC |
2974 | frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask); |
2975 | } | |
4e477040 SC |
2976 | |
2977 | #endif | |
2978 | ||
ffafe6ca DS |
2979 | err = TXNNewObject( |
2980 | NULL, m_txnWindow, &bounds, frameOptions, | |
2981 | kTXNTextEditStyleFrameType, kTXNTextensionFile, kTXNSystemDefaultEncoding, | |
2982 | &m_txn, &m_txnFrameID, NULL ); | |
2983 | verify_noerr( err ); | |
3dee36ae | 2984 | |
fef981b4 DS |
2985 | #if 0 |
2986 | TXNControlTag iControlTags[] = { kTXNUseCarbonEvents }; | |
c88b7d28 | 2987 | TXNControlData iControlData[] = { { (UInt32)&cInfo } }; |
fef981b4 DS |
2988 | int toptag = WXSIZEOF( iControlTags ) ; |
2989 | TXNCarbonEventInfo cInfo ; | |
55d0b180 SC |
2990 | cInfo.useCarbonEvents = false ; |
2991 | cInfo.filler = 0 ; | |
2992 | cInfo.flags = 0 ; | |
2993 | cInfo.fDictionary = NULL ; | |
2994 | ||
c88b7d28 | 2995 | verify_noerr( TXNSetTXNObjectControls( m_txn, false, toptag, iControlTags, iControlData ) ); |
fef981b4 | 2996 | #endif |
55d0b180 | 2997 | |
4e477040 | 2998 | #ifdef __WXMAC_OSX__ |
c88b7d28 | 2999 | TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32)this ); |
4e477040 SC |
3000 | #endif |
3001 | ||
0f7817ab | 3002 | SetGWorld( origPort , origDev ) ; |
ffafe6ca | 3003 | |
5ca0d812 | 3004 | return err; |
facd6764 SC |
3005 | } |
3006 | ||
5ca0d812 SC |
3007 | // ---------------------------------------------------------------------------- |
3008 | // MLTE control implementation (OSX part) | |
3009 | // ---------------------------------------------------------------------------- | |
facd6764 | 3010 | |
5ca0d812 | 3011 | #if TARGET_API_MAC_OSX |
facd6764 | 3012 | |
3b92f0e0 SC |
3013 | #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
3014 | ||
09660720 | 3015 | // tiger multi-line textcontrols with no CR in the entire content |
9eddec69 | 3016 | // don't scroll automatically, so we need a hack. |
09660720 SC |
3017 | // This attempt only works 'before' the key (ie before CallNextEventHandler) |
3018 | // is processed, thus the scrolling always occurs one character too late, but | |
3019 | // better than nothing ... | |
3020 | ||
3021 | static const EventTypeSpec eventList[] = | |
3022 | { | |
3023 | { kEventClassTextInput, kEventTextInputUnicodeForKeyEvent } , | |
3024 | } ; | |
9eddec69 | 3025 | |
09660720 SC |
3026 | static pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) |
3027 | { | |
3028 | OSStatus result = eventNotHandledErr ; | |
3029 | wxMacMLTEHIViewControl* focus = (wxMacMLTEHIViewControl*) data ; | |
9eddec69 | 3030 | |
09660720 SC |
3031 | switch ( GetEventKind( event ) ) |
3032 | { | |
3033 | case kEventTextInputUnicodeForKeyEvent : | |
3034 | { | |
3035 | if ( UMAGetSystemVersion() >= 0x1040 ) | |
3036 | { | |
3037 | TXNOffset from , to ; | |
3038 | TXNGetSelection( focus->GetTXNObject() , &from , &to ) ; | |
3039 | if ( from == to ) | |
3040 | TXNShowSelection( focus->GetTXNObject() , kTXNShowStart ); | |
3041 | } | |
3042 | result = CallNextEventHandler(handler,event); | |
3043 | break; | |
3044 | } | |
3045 | default: | |
3046 | break ; | |
3047 | } | |
9eddec69 | 3048 | |
09660720 SC |
3049 | return result ; |
3050 | } | |
3051 | ||
3052 | static pascal OSStatus wxMacTextControlEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) | |
3053 | { | |
3054 | OSStatus result = eventNotHandledErr ; | |
9eddec69 | 3055 | |
09660720 SC |
3056 | switch ( GetEventClass( event ) ) |
3057 | { | |
3058 | case kEventClassTextInput : | |
3059 | result = wxMacUnicodeTextEventHandler( handler , event , data ) ; | |
3060 | break ; | |
9eddec69 | 3061 | |
09660720 SC |
3062 | default : |
3063 | break ; | |
3064 | } | |
3065 | return result ; | |
3066 | } | |
3067 | ||
3068 | DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacTextControlEventHandler ) | |
3069 | ||
0f7817ab | 3070 | wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer, |
ffafe6ca DS |
3071 | const wxString& str, |
3072 | const wxPoint& pos, | |
3073 | const wxSize& size, long style ) : wxMacMLTEControl( wxPeer ) | |
facd6764 | 3074 | { |
5ca0d812 SC |
3075 | m_font = wxPeer->GetFont() ; |
3076 | m_windowStyle = style ; | |
7d8268a1 | 3077 | Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ; |
5ca0d812 | 3078 | wxString st = str ; |
395480fb | 3079 | wxMacConvertNewlines10To13( &st ) ; |
7d8268a1 | 3080 | |
ffafe6ca DS |
3081 | HIRect hr = { |
3082 | { bounds.left , bounds.top }, | |
3083 | { bounds.right - bounds.left, bounds.bottom - bounds.top } } ; | |
facd6764 | 3084 | |
5ca0d812 SC |
3085 | m_scrollView = NULL ; |
3086 | TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ; | |
0207e969 | 3087 | if ( frameOptions & (kTXNWantVScrollBarMask | kTXNWantHScrollBarMask) ) |
5ca0d812 | 3088 | { |
0207e969 DS |
3089 | HIScrollViewCreate( |
3090 | (frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) | |
3091 | | (frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll : 0) , | |
3092 | &m_scrollView ) ; | |
7d8268a1 WS |
3093 | |
3094 | HIViewSetFrame( m_scrollView, &hr ); | |
3095 | HIViewSetVisible( m_scrollView, true ); | |
5ca0d812 | 3096 | } |
7d8268a1 | 3097 | |
5ca0d812 SC |
3098 | m_textView = NULL ; |
3099 | HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ; | |
0207e969 | 3100 | m_txn = HITextViewGetTXNObject( m_textView ) ; |
5ca0d812 SC |
3101 | HIViewSetVisible( m_textView , true ) ; |
3102 | if ( m_scrollView ) | |
3103 | { | |
3104 | HIViewAddSubview( m_scrollView , m_textView ) ; | |
3105 | m_controlRef = m_scrollView ; | |
0207e969 | 3106 | wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ; |
5ca0d812 SC |
3107 | } |
3108 | else | |
3109 | { | |
7d8268a1 | 3110 | HIViewSetFrame( m_textView, &hr ); |
5ca0d812 SC |
3111 | m_controlRef = m_textView ; |
3112 | } | |
7d8268a1 | 3113 | |
0f7817ab SC |
3114 | AdjustCreationAttributes( *wxWHITE , true ) ; |
3115 | ||
3116 | wxMacWindowClipper c( m_peer ) ; | |
5ca0d812 SC |
3117 | SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ; |
3118 | ||
fef981b4 DS |
3119 | TXNSetSelection( m_txn, 0, 0 ); |
3120 | TXNShowSelection( m_txn, kTXNShowStart ); | |
09660720 SC |
3121 | |
3122 | InstallControlEventHandler( m_textView , GetwxMacTextControlEventHandlerUPP(), | |
3123 | GetEventTypeCount(eventList), eventList, this, | |
3124 | &m_textEventHandlerRef); | |
3125 | } | |
3126 | ||
3127 | wxMacMLTEHIViewControl::~wxMacMLTEHIViewControl() | |
3128 | { | |
3129 | ::RemoveEventHandler( m_textEventHandlerRef ) ; | |
facd6764 SC |
3130 | } |
3131 | ||
7d8268a1 | 3132 | OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart ) |
facd6764 | 3133 | { |
fef981b4 | 3134 | return SetKeyboardFocus( GetControlOwner( m_textView ), m_textView, focusPart ) ; |
facd6764 SC |
3135 | } |
3136 | ||
7d8268a1 | 3137 | bool wxMacMLTEHIViewControl::HasFocus() const |
facd6764 | 3138 | { |
5ca0d812 SC |
3139 | ControlRef control ; |
3140 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
3141 | return control == m_textView ; | |
facd6764 SC |
3142 | } |
3143 | ||
44aa865d SC |
3144 | void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) |
3145 | { | |
3146 | wxMacMLTEControl::SetBackground( brush ) ; | |
fef981b4 DS |
3147 | |
3148 | #if 0 | |
44aa865d SC |
3149 | CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); |
3150 | RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; | |
3151 | ||
3152 | float component[4] ; | |
3153 | component[0] = col.red / 65536.0 ; | |
3154 | component[1] = col.green / 65536.0 ; | |
3155 | component[2] = col.blue / 65536.0 ; | |
3156 | component[3] = 1.0 ; // alpha | |
0207e969 | 3157 | |
ffafe6ca DS |
3158 | CGColorRef color = CGColorCreate( rgbSpace , component ); |
3159 | HITextViewSetBackgroundColor( m_textView , color ); | |
44aa865d | 3160 | CGColorSpaceRelease( rgbSpace ); |
fef981b4 | 3161 | #endif |
44aa865d SC |
3162 | } |
3163 | ||
3b92f0e0 SC |
3164 | #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 |
3165 | ||
3166 | ||
fedad417 | 3167 | #endif |
5ca0d812 SC |
3168 | |
3169 | #endif // wxUSE_TEXTCTRL |