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