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