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