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