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