propagating visibility states into MLTE (otherwise it is 'stealing' events at the...
[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
1536 Str255 fontName ;
1537 SInt16 fontSize ;
1538 Style fontStyle ;
1539
1540 GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
1541
1542 TXNTypeAttributes typeAttr[] =
1543 {
1544 { kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } ,
1545 { kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } ,
1546 { kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , { (void*) normal } } ,
1547 } ;
1548
1549 verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr,
1550 kTXNStartOffset,
1551 kTXNEndOffset) );
1552
1553 if ( m_windowStyle & wxTE_PASSWORD )
1554 {
1555 UniChar c = 0xA5 ;
1556 verify_noerr(TXNEchoMode( m_txn , c , 0 , true )) ;
1557 }
1558
1559 TXNBackground tback;
1560 tback.bgType = kTXNBackgroundTypeRGB;
1561 tback.bg.color = MAC_WXCOLORREF( background.GetPixel() );
1562 TXNSetBackground( m_txn , &tback);
1563 }
1564
1565 void wxMacMLTEControl::SetBackground( const wxBrush &brush )
1566 {
1567 // currently only solid background are supported
1568 TXNBackground tback;
1569 tback.bgType = kTXNBackgroundTypeRGB;
1570 tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() );
1571 TXNSetBackground( m_txn , &tback);
1572 }
1573
1574 void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to)
1575 {
1576 TXNTypeAttributes typeAttr[4] ;
1577 Str255 fontName = "\pMonaco" ;
1578 SInt16 fontSize = 12 ;
1579 Style fontStyle = normal ;
1580 RGBColor color ;
1581 int attrCounter = 0 ;
1582 if ( style.HasFont() )
1583 {
1584 const wxFont &font = style.GetFont() ;
1585 wxMacStringToPascal( font.GetFaceName() , fontName ) ;
1586 fontSize = font.GetPointSize() ;
1587 if ( font.GetUnderlined() )
1588 fontStyle |= underline ;
1589 if ( font.GetWeight() == wxBOLD )
1590 fontStyle |= bold ;
1591 if ( font.GetStyle() == wxITALIC )
1592 fontStyle |= italic ;
1593
1594 typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ;
1595 typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ;
1596 typeAttr[attrCounter].data.dataPtr = (void*) fontName ;
1597 typeAttr[attrCounter+1].tag = kTXNQDFontSizeAttribute ;
1598 typeAttr[attrCounter+1].size = kTXNFontSizeAttributeSize ;
1599 typeAttr[attrCounter+1].data.dataValue = (fontSize << 16) ;
1600 typeAttr[attrCounter+2].tag = kTXNQDFontStyleAttribute ;
1601 typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ;
1602 typeAttr[attrCounter+2].data.dataValue = fontStyle ;
1603 attrCounter += 3 ;
1604 }
1605 if ( style.HasTextColour() )
1606 {
1607 typeAttr[attrCounter].tag = kTXNQDFontColorAttribute ;
1608 typeAttr[attrCounter].size = kTXNQDFontColorAttributeSize ;
1609 typeAttr[attrCounter].data.dataPtr = (void*) &color ;
1610 color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ;
1611 attrCounter += 1 ;
1612 }
1613 if ( attrCounter > 0 )
1614 {
1615 verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, from , to) );
1616 }
1617 }
1618
1619 void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
1620 {
1621 wxMacEditHelper help(m_txn) ;
1622 TXNSetAttribute( wxTextAttr(foreground,wxNullColour,font) , kTXNStartOffset,kTXNEndOffset ) ;
1623 }
1624 void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style)
1625 {
1626 wxMacEditHelper help(m_txn) ;
1627 TXNSetAttribute( style , start,end ) ;
1628 }
1629
1630 void wxMacMLTEControl::Copy()
1631 {
1632 ClearCurrentScrap();
1633 TXNCopy(m_txn);
1634 TXNConvertToPublicScrap();
1635 }
1636
1637 void wxMacMLTEControl::Cut()
1638 {
1639 ClearCurrentScrap();
1640 TXNCut(m_txn);
1641 TXNConvertToPublicScrap();
1642 }
1643
1644 void wxMacMLTEControl::Paste()
1645 {
1646 TXNConvertFromPublicScrap();
1647 TXNPaste(m_txn);
1648 }
1649
1650 bool wxMacMLTEControl::CanPaste() const
1651 {
1652 return TXNIsScrapPastable() ;
1653 }
1654
1655 void wxMacMLTEControl::SetEditable(bool editable)
1656 {
1657 TXNControlTag tag[] = { kTXNIOPrivilegesTag } ;
1658 TXNControlData data[] = { { editable ? kTXNReadWrite : kTXNReadOnly } } ;
1659 TXNSetTXNObjectControls( m_txn , false , WXSIZEOF(tag) , tag , data ) ;
1660 }
1661
1662 wxTextPos wxMacMLTEControl::GetLastPosition() const
1663 {
1664 wxTextPos actualsize = 0 ;
1665
1666 Handle theText ;
1667 OSErr err = TXNGetDataEncoded( m_txn, kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData );
1668 /* all done */
1669 if ( err )
1670 {
1671 actualsize = 0 ;
1672 }
1673 else
1674 {
1675 actualsize = GetHandleSize( theText ) ;
1676 DisposeHandle( theText ) ;
1677 }
1678
1679 return actualsize ;
1680 }
1681
1682 void wxMacMLTEControl::Replace( long from , long to , const wxString str )
1683 {
1684 wxString value = str ;
1685 wxMacConvertNewlines10To13( &value ) ;
1686
1687 wxMacEditHelper help( m_txn ) ;
1688 wxMacWindowClipper c( m_peer ) ;
1689
1690 TXNSetSelection(m_txn , from , to ) ;
1691 TXNClear( m_txn ) ;
1692 SetTXNData( value , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
1693 }
1694
1695 void wxMacMLTEControl::Remove( long from , long to )
1696 {
1697 wxMacWindowClipper c( m_peer ) ;
1698 wxMacEditHelper help( m_txn ) ;
1699 TXNSetSelection(m_txn , from , to ) ;
1700 TXNClear( m_txn ) ;
1701 }
1702
1703 void wxMacMLTEControl::GetSelection( long* from, long* to) const
1704 {
1705 TXNGetSelection( m_txn , (TXNOffset*) from , (TXNOffset*) to ) ;
1706 }
1707
1708 void wxMacMLTEControl::SetSelection( long from , long to )
1709 {
1710 wxMacWindowClipper c( m_peer ) ;
1711 /* change the selection */
1712 if ((from == -1) && (to == -1))
1713 TXNSelectAll(m_txn);
1714 else
1715 TXNSetSelection( m_txn, from, to);
1716 TXNShowSelection( m_txn, kTXNShowStart);
1717 }
1718
1719 void wxMacMLTEControl::WriteText(const wxString& str)
1720 {
1721 wxString st = str ;
1722 wxMacConvertNewlines10To13( &st ) ;
1723
1724 long start , end , dummy ;
1725 GetSelection( &start , &dummy ) ;
1726 wxMacWindowClipper c( m_peer ) ;
1727 {
1728 wxMacEditHelper helper( m_txn ) ;
1729 SetTXNData( st , kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ;
1730 }
1731 GetSelection( &dummy , &end ) ;
1732 // TODO SetStyle( start , end , GetDefaultStyle() ) ;
1733 }
1734
1735 void wxMacMLTEControl::Clear()
1736 {
1737 wxMacWindowClipper c( m_peer ) ;
1738 wxMacEditHelper st(m_txn) ;
1739 TXNSetSelection( m_txn , kTXNStartOffset , kTXNEndOffset ) ;
1740 TXNClear(m_txn);
1741 }
1742
1743 bool wxMacMLTEControl::CanUndo() const
1744 {
1745 return TXNCanUndo( m_txn , NULL ) ;
1746 }
1747
1748 void wxMacMLTEControl::Undo()
1749 {
1750 TXNUndo( m_txn ) ;
1751 }
1752
1753 bool wxMacMLTEControl::CanRedo() const
1754 {
1755 return TXNCanRedo( m_txn , NULL ) ;
1756 }
1757
1758 void wxMacMLTEControl::Redo()
1759 {
1760 TXNRedo( m_txn ) ;
1761 }
1762
1763 int wxMacMLTEControl::GetNumberOfLines() const
1764 {
1765 ItemCount lines = 0 ;
1766 TXNGetLineCount(m_txn, &lines ) ;
1767 return lines ;
1768 }
1769
1770 long wxMacMLTEControl::XYToPosition(long x, long y) const
1771 {
1772 Point curpt ;
1773
1774 wxTextPos lastpos = GetLastPosition() ;
1775
1776 // TODO find a better implementation : while we can get the
1777 // line metrics of a certain line, we don't get its starting
1778 // position, so it would probably be rather a binary search
1779 // for the start position
1780 long xpos = 0 ;
1781 long ypos = 0 ;
1782 int lastHeight = 0 ;
1783
1784 ItemCount n ;
1785 for ( n = 0 ; n <= (ItemCount) lastpos ; ++n )
1786 {
1787 if ( y == ypos && x == xpos )
1788 return n ;
1789
1790 TXNOffsetToPoint( m_txn , n , &curpt);
1791
1792 if ( curpt.v > lastHeight )
1793 {
1794 xpos = 0 ;
1795 if ( n > 0 )
1796 ++ypos ;
1797 lastHeight = curpt.v ;
1798 }
1799 else
1800 ++xpos ;
1801 }
1802 return 0 ;
1803 }
1804
1805 bool wxMacMLTEControl::PositionToXY(long pos, long *x, long *y) const
1806 {
1807 Point curpt ;
1808
1809 wxTextPos lastpos = GetLastPosition() ;
1810
1811 if ( y ) *y = 0 ;
1812 if ( x ) *x = 0 ;
1813
1814 if ( pos <= lastpos )
1815 {
1816 // TODO find a better implementation : while we can get the
1817 // line metrics of a certain line, we don't get its starting
1818 // position, so it would probably be rather a binary search
1819 // for the start position
1820 long xpos = 0 ;
1821 long ypos = 0 ;
1822 int lastHeight = 0 ;
1823
1824 ItemCount n ;
1825 for ( n = 0 ; n <= (ItemCount) pos ; ++n )
1826 {
1827 TXNOffsetToPoint(m_txn , n , &curpt);
1828
1829 if ( curpt.v > lastHeight )
1830 {
1831 xpos = 0 ;
1832 if ( n > 0 )
1833 ++ypos ;
1834 lastHeight = curpt.v ;
1835 }
1836 else
1837 ++xpos ;
1838 }
1839 if ( y ) *y = ypos ;
1840 if ( x ) *x = xpos ;
1841 }
1842
1843 return false ;
1844 }
1845
1846 void wxMacMLTEControl::ShowPosition( long pos )
1847 {
1848 #if TARGET_RT_MAC_MACHO && defined(AVAILABLE_MAC_OS_X_VERSION_10_2_AND_LATER)
1849 {
1850 Point current ;
1851 Point desired ;
1852 TXNOffset selstart , selend ;
1853 TXNGetSelection( m_txn , &selstart , &selend) ;
1854 TXNOffsetToPoint( m_txn, selstart , &current);
1855 TXNOffsetToPoint( m_txn, pos , &desired);
1856 //TODO use HIPoints for 10.3 and above
1857 if ( (UInt32) TXNScroll != (UInt32) kUnresolvedCFragSymbolAddress )
1858 {
1859 OSErr theErr = noErr;
1860 SInt32 dv = desired.v - current.v ;
1861 SInt32 dh = desired.h - current.h ;
1862 TXNShowSelection( m_txn , true ) ;
1863 theErr = TXNScroll( m_txn, kTXNScrollUnitsInPixels , kTXNScrollUnitsInPixels , &dv , &dh );
1864 wxASSERT_MSG( theErr == noErr, _T("TXNScroll returned an error!") );
1865 }
1866 }
1867 #endif
1868 }
1869
1870 void wxMacMLTEControl::SetTXNData( const wxString& st , TXNOffset start , TXNOffset end )
1871 {
1872 #if wxUSE_UNICODE
1873 #if SIZEOF_WCHAR_T == 2
1874 size_t len = st.Len() ;
1875 TXNSetData( m_txn , kTXNUnicodeTextData, (void*)st.wc_str(), len * 2,
1876 start, end);
1877 #else
1878 wxMBConvUTF16BE converter ;
1879 ByteCount byteBufferLen = converter.WC2MB( NULL , st.wc_str() , 0 ) ;
1880 UniChar *unibuf = (UniChar*) malloc(byteBufferLen) ;
1881 converter.WC2MB( (char*) unibuf , st.wc_str() , byteBufferLen ) ;
1882 TXNSetData( m_txn , kTXNUnicodeTextData, (void*)unibuf, byteBufferLen ,
1883 start, end);
1884 free( unibuf ) ;
1885 #endif
1886 #else
1887 wxCharBuffer text = st.mb_str(wxConvLocal) ;
1888 TXNSetData( m_txn , kTXNTextData, (void*)text.data(), strlen( text ) ,
1889 start, end);
1890 #endif
1891 }
1892
1893
1894 wxString wxMacMLTEControl::GetLineText(long lineNo) const
1895 {
1896 wxString line ;
1897
1898 if ( lineNo < GetNumberOfLines() )
1899 {
1900 long ypos = 0 ;
1901
1902 Fixed lineWidth,
1903 lineHeight,
1904 currentHeight = 0;
1905
1906 // get the first possible position in the control
1907 Point firstPoint;
1908 TXNOffsetToPoint(m_txn, 0, &firstPoint);
1909
1910 // Iterate through the lines until we reach the one we want,
1911 // adding to our current y pixel point position
1912 while (ypos < lineNo)
1913 {
1914 TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
1915 currentHeight += lineHeight;
1916 }
1917
1918 Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
1919 TXNOffset theOffset;
1920 TXNPointToOffset(m_txn, thePoint, &theOffset);
1921
1922 wxString content = GetStringValue() ;
1923 Point currentPoint = thePoint;
1924 while(thePoint.v == currentPoint.v && theOffset < content.length())
1925 {
1926 line += content[theOffset];
1927 TXNOffsetToPoint(m_txn, ++theOffset, &currentPoint);
1928 }
1929 }
1930 return line ;
1931 }
1932
1933 int wxMacMLTEControl::GetLineLength(long lineNo) const
1934 {
1935 int theLength = 0;
1936
1937 if ( lineNo < GetNumberOfLines() )
1938 {
1939 long ypos = 0 ;
1940
1941 Fixed lineWidth,
1942 lineHeight,
1943 currentHeight = 0;
1944
1945 // get the first possible position in the control
1946 Point firstPoint;
1947 TXNOffsetToPoint(m_txn, 0, &firstPoint);
1948
1949 // Iterate through the lines until we reach the one we want,
1950 // adding to our current y pixel point position
1951 while (ypos < lineNo)
1952 {
1953 TXNGetLineMetrics(m_txn, ypos++, &lineWidth, &lineHeight);
1954 currentHeight += lineHeight;
1955 }
1956
1957 Point thePoint = { firstPoint.v + (currentHeight >> 16), firstPoint.h + (0) };
1958 TXNOffset theOffset;
1959 TXNPointToOffset(m_txn, thePoint, &theOffset);
1960
1961 wxString content = GetStringValue() ;
1962 Point currentPoint = thePoint;
1963 while(thePoint.v == currentPoint.v && theOffset < content.length())
1964 {
1965 ++theLength;
1966 TXNOffsetToPoint(m_txn, ++theOffset, &currentPoint);
1967 }
1968 }
1969 return theLength ;
1970 }
1971
1972
1973 // ----------------------------------------------------------------------------
1974 // MLTE control implementation (classic part)
1975 // ----------------------------------------------------------------------------
1976
1977 // OS X Notes : We still don't have a full replacement for MLTE, so this implementation
1978 // has to live on. We have different problems coming from outdated implementations on the
1979 // various OS X versions. Most deal with the scrollbars: they are not correctly embedded
1980 // while this can be solved on 10.3 by reassigning them the correct place, on 10.2 there is
1981 // no way out, therefore we are using our own implementation and our own scrollbars ....
1982
1983 #ifdef __WXMAC_OSX__
1984
1985 TXNScrollInfoUPP gTXNScrollInfoProc = NULL ;
1986 ControlActionUPP gTXNScrollActionProc = NULL ;
1987
1988 pascal void wxMacMLTEClassicControl::TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, TXNScrollBarOrientation
1989 iScrollBarOrientation, SInt32 iRefCon)
1990 {
1991 wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) iRefCon ;
1992 SInt32 value = wxMax( iValue , 0 ) ;
1993 SInt32 maximum = wxMax( iMaximumValue , 0 ) ;
1994
1995 if ( iScrollBarOrientation == kTXNHorizontal )
1996 {
1997 if ( mlte->m_sbHorizontal )
1998 {
1999 SetControl32BitValue( mlte->m_sbHorizontal , value ) ;
2000 SetControl32BitMaximum( mlte->m_sbHorizontal , maximum ) ;
2001 mlte->m_lastHorizontalValue = value ;
2002 }
2003 }
2004 else if ( iScrollBarOrientation == kTXNVertical )
2005 {
2006 if ( mlte->m_sbVertical )
2007 {
2008 SetControl32BitValue( mlte->m_sbVertical , value ) ;
2009 SetControl32BitMaximum( mlte->m_sbVertical , maximum ) ;
2010 mlte->m_lastVerticalValue = value ;
2011 }
2012 }
2013 }
2014
2015 pascal void wxMacMLTEClassicControl::TXNScrollActionProc( ControlRef controlRef , ControlPartCode partCode )
2016 {
2017 OSStatus err ;
2018 wxMacMLTEClassicControl* mlte = (wxMacMLTEClassicControl*) GetControlReference( controlRef ) ;
2019 if ( mlte == NULL )
2020 return ;
2021
2022 if ( controlRef != mlte->m_sbVertical && controlRef != mlte->m_sbHorizontal )
2023 return ;
2024
2025 bool isHorizontal = ( controlRef == mlte->m_sbHorizontal ) ;
2026
2027 SInt32 minimum = 0 ;
2028 SInt32 maximum = GetControl32BitMaximum( controlRef ) ;
2029 SInt32 value = GetControl32BitValue( controlRef ) ;
2030 SInt32 delta = 0;
2031 switch ( partCode )
2032 {
2033 case kControlDownButtonPart :
2034 delta = 10 ;
2035 break ;
2036 case kControlUpButtonPart :
2037 delta = -10 ;
2038 break ;
2039 case kControlPageDownPart :
2040 delta = GetControlViewSize( controlRef ) ;
2041 break ;
2042 case kControlPageUpPart :
2043 delta = -GetControlViewSize( controlRef ) ;
2044 break ;
2045 case kControlIndicatorPart :
2046 delta = value -
2047 ( isHorizontal ? mlte->m_lastHorizontalValue : mlte->m_lastVerticalValue ) ;
2048 break ;
2049 default :
2050 break ;
2051 }
2052 if ( delta != 0 )
2053 {
2054 SInt32 newValue = value ;
2055
2056 if ( partCode != kControlIndicatorPart )
2057 {
2058 if( value + delta < minimum )
2059 delta = minimum - value ;
2060 if ( value + delta > maximum )
2061 delta = maximum - value ;
2062
2063 SetControl32BitValue( controlRef , value + delta ) ;
2064 newValue = value + delta ;
2065 }
2066
2067 SInt32 verticalDelta = isHorizontal ? 0 : delta ;
2068 SInt32 horizontalDelta = isHorizontal ? delta : 0 ;
2069
2070 err = TXNScroll( mlte->m_txn , kTXNScrollUnitsInPixels, kTXNScrollUnitsInPixels,
2071 &verticalDelta , &horizontalDelta );
2072
2073 if ( isHorizontal )
2074 mlte->m_lastHorizontalValue = newValue ;
2075 else
2076 mlte->m_lastVerticalValue = newValue ;
2077 }
2078 }
2079 #endif
2080
2081 // make correct activations
2082 void wxMacMLTEClassicControl::MacActivatePaneText(Boolean setActive)
2083 {
2084 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2085
2086 wxMacWindowClipper clipper( textctrl ) ;
2087 TXNActivate(m_txn, m_txnFrameID, setActive);
2088
2089 ControlRef controlFocus = 0 ;
2090 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2091 if ( controlFocus == m_controlRef )
2092 TXNFocus( m_txn, setActive);
2093 }
2094
2095 void wxMacMLTEClassicControl::MacFocusPaneText(Boolean setFocus)
2096 {
2097 TXNFocus( m_txn, setFocus);
2098 }
2099
2100 // guards against inappropriate redraw (hidden objects drawing onto window)
2101
2102 void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis)
2103 {
2104 ControlRef controlFocus = 0 ;
2105 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2106
2107 if ( controlFocus == m_controlRef && vis == false )
2108 {
2109 SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ;
2110 }
2111
2112 TXNControlTag iControlTags[] =
2113 {
2114 kTXNVisibilityTag ,
2115 };
2116 TXNControlData iControlData[] =
2117 {
2118 {(UInt32) false },
2119 };
2120
2121 int toptag = WXSIZEOF( iControlTags ) ;
2122
2123 verify_noerr( TXNGetTXNObjectControls( m_txn , toptag,
2124 iControlTags, iControlData ) ) ;
2125
2126 if ( iControlData[0].uValue != vis )
2127 {
2128 iControlData[0].uValue = vis ;
2129 verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
2130 iControlTags, iControlData )) ;
2131 }
2132 // we right now are always clipping as partial visibility (overlapped) visibility
2133 // is also a problem, if we run into further problems we might set the FrameBounds to an empty
2134 // rect here
2135 }
2136
2137 // make sure that the TXNObject is at the right position
2138
2139 void wxMacMLTEClassicControl::MacUpdatePosition()
2140 {
2141 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2142 if ( textctrl == NULL )
2143 return ;
2144
2145 Rect bounds ;
2146 UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
2147
2148 if ( !EqualRect( &bounds , &m_txnControlBounds ) )
2149 {
2150 // old position
2151 Rect oldBounds = m_txnControlBounds ;
2152 m_txnControlBounds = bounds ;
2153 wxMacWindowClipper cl(textctrl) ;
2154
2155 #ifdef __WXMAC_OSX__
2156 bool isCompositing = textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ;
2157 if ( m_sbHorizontal || m_sbVertical )
2158 {
2159 int w = bounds.right - bounds.left ;
2160 int h = bounds.bottom - bounds.top ;
2161
2162 if ( m_sbHorizontal )
2163 {
2164 Rect sbBounds ;
2165
2166 sbBounds.left = -1 ;
2167 sbBounds.top = h - 14 ;
2168 sbBounds.right = w + 1 ;
2169 sbBounds.bottom = h + 1 ;
2170
2171 if ( !isCompositing )
2172 OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ;
2173
2174 SetControlBounds( m_sbHorizontal , &sbBounds ) ;
2175 SetControlViewSize( m_sbHorizontal , w ) ;
2176 }
2177 if ( m_sbVertical )
2178 {
2179 Rect sbBounds ;
2180
2181 sbBounds.left = w - 14 ;
2182 sbBounds.top = -1 ;
2183 sbBounds.right = w + 1 ;
2184 sbBounds.bottom = m_sbHorizontal ? h - 14 : h + 1 ;
2185
2186 if ( !isCompositing )
2187 OffsetRect( &sbBounds , m_txnControlBounds.left , m_txnControlBounds.top ) ;
2188
2189 SetControlBounds( m_sbVertical , &sbBounds ) ;
2190 SetControlViewSize( m_sbVertical , h ) ;
2191 }
2192 }
2193 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2194 m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
2195 #else
2196
2197 TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
2198 wxMax( m_txnControlBounds.bottom , m_txnControlBounds.top ) ,
2199 wxMax( m_txnControlBounds.right , m_txnControlBounds.left ) , m_txnFrameID);
2200
2201 // the SetFrameBounds method unter classic sometimes does not correctly scroll a selection into sight after a
2202 // movement, therefore we have to force it
2203
2204 TXNLongRect textRect ;
2205 TXNGetRectBounds( m_txn , NULL , NULL , &textRect ) ;
2206 if ( textRect.left < m_txnControlBounds.left )
2207 {
2208 TXNShowSelection( m_txn , false ) ;
2209 }
2210 #endif
2211 }
2212 }
2213
2214 void wxMacMLTEClassicControl::SetRect( Rect *r )
2215 {
2216 wxMacControl::SetRect( r ) ;
2217 MacUpdatePosition() ;
2218 }
2219
2220 void wxMacMLTEClassicControl::MacControlUserPaneDrawProc(wxInt16 thePart)
2221 {
2222 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2223 if ( textctrl == NULL )
2224 return ;
2225
2226 if ( textctrl->MacIsReallyShown() )
2227 {
2228 wxMacWindowClipper clipper( textctrl ) ;
2229 TXNDraw( m_txn , NULL ) ;
2230 }
2231 }
2232
2233 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y)
2234 {
2235 Point where = { y , x } ;
2236 ControlPartCode result;
2237
2238 result = 0;
2239 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2240 if ( textctrl == NULL )
2241 return 0 ;
2242
2243 if (textctrl->MacIsReallyShown() )
2244 {
2245 if (PtInRect(where, &m_txnControlBounds))
2246 result = kControlEditTextPart ;
2247 else
2248 {
2249 // sometimes we get the coords also in control local coordinates, therefore test again
2250 if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() )
2251 {
2252 int x = 0 , y = 0 ;
2253 textctrl->MacClientToRootWindow( &x , &y ) ;
2254 where.h += x ;
2255 where.v += y ;
2256 }
2257 if (PtInRect(where, &m_txnControlBounds))
2258 result = kControlEditTextPart ;
2259 else
2260 result = 0;
2261 }
2262 }
2263 return result;
2264 }
2265
2266 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneTrackingProc( wxInt16 x, wxInt16 y, void* actionProc )
2267 {
2268 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2269 if ( textctrl == NULL )
2270 return 0;
2271
2272 ControlPartCode partCodeResult = 0;
2273
2274 if (textctrl->MacIsReallyShown() )
2275 {
2276 Point startPt = { y ,x } ;
2277 // for compositing, we must convert these into toplevel window coordinates, because hittesting expects them
2278 if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() )
2279 {
2280 int x = 0 , y = 0 ;
2281 textctrl->MacClientToRootWindow( &x , &y ) ;
2282 startPt.h += x ;
2283 startPt.v += y ;
2284 }
2285
2286 switch (MacControlUserPaneHitTestProc( startPt.h , startPt.v ))
2287 {
2288 case kControlEditTextPart :
2289 {
2290 wxMacWindowClipper clipper( textctrl ) ;
2291
2292 EventRecord rec ;
2293 ConvertEventRefToEventRecord( (EventRef) wxTheApp->MacGetCurrentEvent() , &rec ) ;
2294 TXNClick( m_txn, &rec );
2295
2296 }
2297 break;
2298 }
2299 }
2300 return partCodeResult;
2301 }
2302
2303 void wxMacMLTEClassicControl::MacControlUserPaneIdleProc()
2304 {
2305 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2306 if ( textctrl == NULL )
2307 return ;
2308
2309 if (textctrl->MacIsReallyShown())
2310 {
2311 if (IsControlActive(m_controlRef))
2312 {
2313 Point mousep;
2314
2315 wxMacWindowClipper clipper( textctrl ) ;
2316 GetMouse(&mousep);
2317
2318 TXNIdle(m_txn);
2319
2320 if (PtInRect(mousep, &m_txnControlBounds))
2321 {
2322 RgnHandle theRgn;
2323 RectRgn((theRgn = NewRgn()), &m_txnControlBounds);
2324 TXNAdjustCursor(m_txn, theRgn);
2325 DisposeRgn(theRgn);
2326 }
2327 }
2328 }
2329 }
2330
2331 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
2332 {
2333 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2334 if ( textctrl == NULL )
2335 return 0;
2336
2337 wxMacWindowClipper clipper( textctrl ) ;
2338
2339 EventRecord ev ;
2340 memset( &ev , 0 , sizeof( ev ) ) ;
2341 ev.what = keyDown ;
2342 ev.modifiers = modifiers ;
2343 ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ;
2344 TXNKeyDown( m_txn , &ev);
2345
2346 return kControlEntireControl;
2347 }
2348
2349 void wxMacMLTEClassicControl::MacControlUserPaneActivateProc( bool activating)
2350 {
2351 MacActivatePaneText( activating );
2352 }
2353
2354 wxInt16 wxMacMLTEClassicControl::MacControlUserPaneFocusProc(wxInt16 action)
2355 {
2356 ControlPartCode focusResult;
2357
2358 focusResult = kControlFocusNoPart;
2359 wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(m_controlRef);
2360 if ( textctrl == NULL )
2361 return 0;
2362
2363 wxMacWindowClipper clipper( textctrl ) ;
2364
2365 ControlRef controlFocus = 0 ;
2366 GetKeyboardFocus( m_txnWindow , &controlFocus ) ;
2367 bool wasFocused = ( controlFocus == m_controlRef ) ;
2368
2369 switch (action)
2370 {
2371 case kControlFocusPrevPart:
2372 case kControlFocusNextPart:
2373 MacFocusPaneText( ( !wasFocused));
2374 focusResult = (!wasFocused) ? (ControlPartCode) kControlEditTextPart : (ControlPartCode) kControlFocusNoPart;
2375 break;
2376
2377 case kControlFocusNoPart:
2378 default:
2379 MacFocusPaneText( false);
2380 focusResult = kControlFocusNoPart;
2381 break;
2382 }
2383
2384 return focusResult;
2385 }
2386
2387 void wxMacMLTEClassicControl::MacControlUserPaneBackgroundProc( void *info )
2388 {
2389 }
2390
2391 wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
2392 const wxString& str,
2393 const wxPoint& pos,
2394 const wxSize& size, long style ) : wxMacMLTEControl( wxPeer )
2395 {
2396 m_font = wxPeer->GetFont() ;
2397 m_windowStyle = style ;
2398 Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
2399 wxString st = str ;
2400 wxMacConvertNewlines10To13( &st ) ;
2401
2402 short featurSet;
2403
2404 featurSet = kControlSupportsEmbedding | kControlSupportsFocus | kControlWantsIdle
2405 | kControlWantsActivate | kControlHandlesTracking // | kControlHasSpecialBackground
2406 | kControlGetsFocusOnClick | kControlSupportsLiveFeedback;
2407
2408 verify_noerr( ::CreateUserPaneControl( MAC_WXHWND(wxPeer->GetParent()->MacGetTopLevelWindowRef()), &bounds, featurSet, &m_controlRef ) );
2409
2410 DoCreate();
2411
2412 AdjustCreationAttributes( *wxWHITE , true) ;
2413
2414 MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ;
2415
2416 wxMacWindowClipper clipper( m_peer ) ;
2417 SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
2418 TXNSetSelection( m_txn, 0, 0);
2419 }
2420
2421 wxMacMLTEClassicControl::~wxMacMLTEClassicControl()
2422 {
2423 TXNDeleteObject(m_txn);
2424 m_txn = NULL ;
2425 }
2426
2427 void wxMacMLTEClassicControl::VisibilityChanged(bool shown)
2428 {
2429 MacSetObjectVisibility( shown ) ;
2430 wxMacControl::VisibilityChanged( shown ) ;
2431 }
2432
2433 void wxMacMLTEClassicControl::SuperChangedPosition()
2434 {
2435 MacUpdatePosition() ;
2436 wxMacControl::SuperChangedPosition() ;
2437 }
2438
2439 #ifdef __WXMAC_OSX__
2440
2441 ControlUserPaneDrawUPP gTPDrawProc = NULL;
2442 ControlUserPaneHitTestUPP gTPHitProc = NULL;
2443 ControlUserPaneTrackingUPP gTPTrackProc = NULL;
2444 ControlUserPaneIdleUPP gTPIdleProc = NULL;
2445 ControlUserPaneKeyDownUPP gTPKeyProc = NULL;
2446 ControlUserPaneActivateUPP gTPActivateProc = NULL;
2447 ControlUserPaneFocusUPP gTPFocusProc = NULL;
2448
2449 static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part)
2450 {
2451 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2452 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2453 if ( win )
2454 win->MacControlUserPaneDrawProc(part) ;
2455 }
2456
2457 static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where)
2458 {
2459 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2460 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2461 if ( win )
2462 return win->MacControlUserPaneHitTestProc(where.h , where.v) ;
2463 else
2464 return kControlNoPart ;
2465 }
2466
2467 static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc)
2468 {
2469 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2470 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2471 if ( win )
2472 return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ;
2473 else
2474 return kControlNoPart ;
2475 }
2476
2477 static pascal void wxMacControlUserPaneIdleProc(ControlRef control)
2478 {
2479 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2480 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2481 if ( win )
2482 win->MacControlUserPaneIdleProc() ;
2483 }
2484
2485 static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers)
2486 {
2487 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2488 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2489 if ( win )
2490 return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ;
2491 else
2492 return kControlNoPart ;
2493 }
2494
2495 static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating)
2496 {
2497 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2498 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2499 if ( win )
2500 win->MacControlUserPaneActivateProc(activating) ;
2501 }
2502
2503 static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action)
2504 {
2505 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2506 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2507 if ( win )
2508 return win->MacControlUserPaneFocusProc(action) ;
2509 else
2510 return kControlNoPart ;
2511 }
2512
2513 /*
2514 static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info)
2515 {
2516 wxTextCtrl *textCtrl = wxDynamicCast( wxFindControlFromMacControl(control) , wxTextCtrl ) ;
2517 wxMacMLTEClassicControl * win = textCtrl ? (wxMacMLTEClassicControl*)(textCtrl->GetPeer()) : NULL ;
2518 if ( win )
2519 win->MacControlUserPaneBackgroundProc(info) ;
2520 }
2521 */
2522 #endif
2523
2524 // TXNRegisterScrollInfoProc
2525
2526 OSStatus wxMacMLTEClassicControl::DoCreate()
2527 {
2528 Rect bounds;
2529
2530 OSStatus err = noErr ;
2531
2532 /* set up our globals */
2533 #ifdef __WXMAC_OSX__
2534 if (gTPDrawProc == NULL) gTPDrawProc = NewControlUserPaneDrawUPP(wxMacControlUserPaneDrawProc);
2535 if (gTPHitProc == NULL) gTPHitProc = NewControlUserPaneHitTestUPP(wxMacControlUserPaneHitTestProc);
2536 if (gTPTrackProc == NULL) gTPTrackProc = NewControlUserPaneTrackingUPP(wxMacControlUserPaneTrackingProc);
2537 if (gTPIdleProc == NULL) gTPIdleProc = NewControlUserPaneIdleUPP(wxMacControlUserPaneIdleProc);
2538 if (gTPKeyProc == NULL) gTPKeyProc = NewControlUserPaneKeyDownUPP(wxMacControlUserPaneKeyDownProc);
2539 if (gTPActivateProc == NULL) gTPActivateProc = NewControlUserPaneActivateUPP(wxMacControlUserPaneActivateProc);
2540 if (gTPFocusProc == NULL) gTPFocusProc = NewControlUserPaneFocusUPP(wxMacControlUserPaneFocusProc);
2541
2542 if (gTXNScrollInfoProc == NULL ) gTXNScrollInfoProc = NewTXNScrollInfoUPP(TXNScrollInfoProc) ;
2543 if (gTXNScrollActionProc == NULL ) gTXNScrollActionProc = NewControlActionUPP(TXNScrollActionProc) ;
2544 #endif
2545
2546 /* set the initial settings for our private data */
2547
2548 m_txnWindow =GetControlOwner(m_controlRef);
2549 m_txnPort = (GrafPtr) GetWindowPort(m_txnWindow);
2550
2551 #ifdef __WXMAC_OSX__
2552 /* set up the user pane procedures */
2553 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneDrawProcTag, sizeof(gTPDrawProc), &gTPDrawProc);
2554 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneHitTestProcTag, sizeof(gTPHitProc), &gTPHitProc);
2555 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneTrackingProcTag, sizeof(gTPTrackProc), &gTPTrackProc);
2556 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneIdleProcTag, sizeof(gTPIdleProc), &gTPIdleProc);
2557 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneKeyDownProcTag, sizeof(gTPKeyProc), &gTPKeyProc);
2558 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneActivateProcTag, sizeof(gTPActivateProc), &gTPActivateProc);
2559 SetControlData(m_controlRef, kControlEntireControl, kControlUserPaneFocusProcTag, sizeof(gTPFocusProc), &gTPFocusProc);
2560 #endif
2561 /* calculate the rectangles used by the control */
2562 UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
2563
2564 m_txnControlBounds = bounds ;
2565
2566 CGrafPtr origPort = NULL ;
2567 GDHandle origDev = NULL ;
2568 GetGWorld( &origPort , &origDev ) ;
2569 SetPort(m_txnPort);
2570
2571 /* create the new edit field */
2572
2573 TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( m_windowStyle ) ;
2574
2575 #ifdef __WXMAC_OSX__
2576
2577 // the scrollbars are not correctly embedded but are inserted at the root
2578 // this gives us problems as we have erratic redraws even over the structure
2579 // area
2580
2581 m_sbHorizontal = 0 ;
2582 m_sbVertical = 0 ;
2583 m_lastHorizontalValue = 0 ;
2584 m_lastVerticalValue = 0 ;
2585
2586 Rect sb = { 0 , 0 , 0 , 0 } ;
2587 if ( frameOptions & kTXNWantVScrollBarMask )
2588 {
2589 CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbVertical ) ;
2590 SetControlReference( m_sbVertical , (SInt32) this ) ;
2591 SetControlAction( m_sbVertical, gTXNScrollActionProc );
2592 ShowControl( m_sbVertical ) ;
2593 EmbedControl( m_sbVertical , m_controlRef ) ;
2594 frameOptions &= ~kTXNWantVScrollBarMask ;
2595 }
2596 if ( frameOptions & kTXNWantHScrollBarMask )
2597 {
2598 CreateScrollBarControl( m_txnWindow , &sb , 0 , 0 , 100 , 1 , true , gTXNScrollActionProc , &m_sbHorizontal ) ;
2599 SetControlReference( m_sbHorizontal , (SInt32) this ) ;
2600 SetControlAction( m_sbHorizontal, gTXNScrollActionProc );
2601 ShowControl( m_sbHorizontal ) ;
2602 EmbedControl( m_sbHorizontal , m_controlRef ) ;
2603 frameOptions &= ~(kTXNWantHScrollBarMask | kTXNDrawGrowIconMask);
2604 }
2605
2606 #endif
2607
2608 verify_noerr(TXNNewObject(NULL, m_txnWindow , &bounds,
2609 frameOptions ,
2610 kTXNTextEditStyleFrameType,
2611 kTXNTextensionFile,
2612 kTXNSystemDefaultEncoding,
2613 &m_txn, &m_txnFrameID, NULL ) );
2614
2615 #ifdef __WXMAC_OSX__
2616 TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this);
2617 #endif
2618
2619 SetGWorld( origPort , origDev ) ;
2620 return err;
2621 }
2622
2623 // ----------------------------------------------------------------------------
2624 // MLTE control implementation (OSX part)
2625 // ----------------------------------------------------------------------------
2626
2627 #if TARGET_API_MAC_OSX
2628
2629 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2630
2631 wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxTextCtrl *wxPeer,
2632 const wxString& str,
2633 const wxPoint& pos,
2634 const wxSize& size, long style ) : wxMacMLTEControl( wxPeer )
2635 {
2636 m_font = wxPeer->GetFont() ;
2637 m_windowStyle = style ;
2638 Rect bounds = wxMacGetBoundsForControl( wxPeer , pos , size ) ;
2639 wxString st = str ;
2640 wxMacConvertNewlines10To13( &st ) ;
2641
2642 HIRect hr = { bounds.left , bounds.top , bounds.right - bounds.left , bounds.bottom- bounds.top } ;
2643
2644 m_scrollView = NULL ;
2645 TXNFrameOptions frameOptions = FrameOptionsFromWXStyle( style ) ;
2646 if ( frameOptions & (kTXNWantVScrollBarMask|kTXNWantHScrollBarMask) )
2647 {
2648 HIScrollViewCreate(( frameOptions & kTXNWantHScrollBarMask ? kHIScrollViewOptionsHorizScroll : 0) |
2649 ( frameOptions & kTXNWantVScrollBarMask ? kHIScrollViewOptionsVertScroll: 0 ) , &m_scrollView ) ;
2650
2651 HIViewSetFrame( m_scrollView, &hr );
2652 HIViewSetVisible( m_scrollView, true );
2653 }
2654
2655 m_textView = NULL ;
2656 HITextViewCreate( NULL , 0, frameOptions , &m_textView ) ;
2657 m_txn = HITextViewGetTXNObject( m_textView) ;
2658 HIViewSetVisible( m_textView , true ) ;
2659 if ( m_scrollView )
2660 {
2661 HIViewAddSubview( m_scrollView , m_textView ) ;
2662 m_controlRef = m_scrollView ;
2663 wxPeer->MacInstallEventHandler( (WXWidget) m_textView ) ;
2664 }
2665 else
2666 {
2667 HIViewSetFrame( m_textView, &hr );
2668 m_controlRef = m_textView ;
2669 }
2670
2671 AdjustCreationAttributes( *wxWHITE , true ) ;
2672
2673 wxMacWindowClipper c( m_peer ) ;
2674 SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
2675
2676 TXNSetSelection( m_txn, 0, 0);
2677 TXNShowSelection( m_txn, kTXNShowStart);
2678
2679 }
2680
2681 OSStatus wxMacMLTEHIViewControl::SetFocus( ControlFocusPart focusPart )
2682 {
2683 return SetKeyboardFocus( GetControlOwner( m_textView ) ,
2684 m_textView , focusPart ) ;
2685 }
2686
2687 bool wxMacMLTEHIViewControl::HasFocus() const
2688 {
2689 ControlRef control ;
2690 GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2691 return control == m_textView ;
2692 }
2693
2694 #endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
2695
2696
2697 #endif
2698
2699 #endif // wxUSE_TEXTCTRL