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