]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/textctrl.cpp
Use the current font for the DoGetBestSize calculation
[wxWidgets.git] / src / mac / carbon / textctrl.cpp
index 59acc5cc7519102baf47853075e256b68afd64a7..100f1d69892cb90210b70ca1959c1f9380886502 100644 (file)
@@ -196,6 +196,7 @@ public :
     virtual void ShowPosition( long WXUNUSED(pos) ) ;
     virtual int GetLineLength(long lineNo) const ;
     virtual wxString GetLineText(long lineNo) const ;
+    virtual bool SetupCursor( const wxPoint& pt ) { return false ; }
 
 #ifndef __WXMAC_OSX__
     virtual void            MacControlUserPaneDrawProc(wxInt16 part) = 0 ;
@@ -327,6 +328,8 @@ public :
     virtual wxInt16         MacControlUserPaneFocusProc(wxInt16 action) ;
     virtual void            MacControlUserPaneBackgroundProc(void* info) ;
 
+    virtual bool            SetupCursor( const wxPoint& WXUNUSED(pt) ) { MacControlUserPaneIdleProc() ; return true ;}
+
     virtual void            SetRect( Rect *r ) ;
 
 protected :
@@ -343,7 +346,7 @@ private :
     WindowRef               m_txnWindow ;
     // bounds of the control as we last did set the txn frames
     Rect                    m_txnControlBounds ;
-
+    Rect                    m_txnVisBounds ;
 #ifdef __WXMAC_OSX__
     static pascal void      TXNScrollInfoProc (SInt32 iValue, SInt32 iMaximumValue, 
                                 TXNScrollBarOrientation iScrollBarOrientation, SInt32 iRefCon) ;
@@ -442,6 +445,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id,
     {
         SetEditable( false ) ;
     }
+    
+    SetCursor( wxCursor( wxCURSOR_IBEAM ) ) ;
 
     return true;
 }
@@ -1010,7 +1015,10 @@ void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
 
 bool wxTextCtrl::MacSetupCursor( const wxPoint& pt )
 {
-    return true ;
+    if ( !GetPeer()->SetupCursor(pt) )
+        return wxWindow::MacSetupCursor( pt ) ;
+    else
+        return true ;
 }
 #if !TARGET_API_MAC_OSX
 
@@ -1524,24 +1532,28 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo
                                         iControlTags, iControlData )) ;
 
     // setting the default font
+    // under 10.2 this causes a visible caret, therefore we avoid it
 
-    Str255 fontName ;
-    SInt16 fontSize ;
-    Style fontStyle ;
-
-    GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
-
-    TXNTypeAttributes typeAttr[] =
+    if ( UMAGetSystemVersion() >= 0x1030 )
     {
-        {   kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } ,
-        {   kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } ,
-        {   kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , {  (void*) normal } } ,
-    } ;
+        Str255 fontName ;
+        SInt16 fontSize ;
+        Style fontStyle ;
+
+        GetThemeFont(kThemeSystemFont , GetApplicationScript() , fontName , &fontSize , &fontStyle ) ;
 
-    verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr,
-          kTXNStartOffset,
-          kTXNEndOffset) );
+        TXNTypeAttributes typeAttr[] =
+        {
+            {   kTXNQDFontNameAttribute , kTXNQDFontNameAttributeSize , { (void*) fontName } } ,
+            {   kTXNQDFontSizeAttribute , kTXNFontSizeAttributeSize , { (void*) (fontSize << 16) } } ,
+            {   kTXNQDFontStyleAttribute , kTXNQDFontStyleAttributeSize , {  (void*) normal } } ,
+        } ;
 
+        verify_noerr( TXNSetTypeAttributes (m_txn, sizeof( typeAttr ) / sizeof(TXNTypeAttributes) , typeAttr,
+              kTXNStartOffset,
+              kTXNEndOffset) );
+    }
+    
     if ( m_windowStyle & wxTE_PASSWORD )
     {
         UniChar c = 0xA5 ;
@@ -2100,6 +2112,19 @@ void wxMacMLTEClassicControl::MacSetObjectVisibility(Boolean vis)
     {
         SetKeyboardFocus( m_txnWindow , m_controlRef , kControlFocusNoPart ) ;
     }
+    
+    TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
+    TXNControlData iControlData[1] = { {(UInt32) false } };
+
+    verify_noerr( TXNGetTXNObjectControls( m_txn , 1,
+                                        iControlTags, iControlData ) ) ;
+                                        
+    if ( iControlData[0].uValue != vis )
+    {
+        iControlData[0].uValue = vis ;
+        verify_noerr( TXNSetTXNObjectControls( m_txn, false , 1,
+                                        iControlTags, iControlData )) ;
+    }
     // we right now are always clipping as partial visibility (overlapped) visibility
     // is also a problem, if we run into further problems we might set the FrameBounds to an empty
     // rect here
@@ -2116,11 +2141,17 @@ void wxMacMLTEClassicControl::MacUpdatePosition()
     Rect bounds ;
     UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
     
-    if ( !EqualRect( &bounds , &m_txnControlBounds ) )
+    wxRect visRect = textctrl->MacGetClippedClientRect() ;
+    Rect visBounds = { visRect.y , visRect.x , visRect.y + visRect.height , visRect.x + visRect.width } ;
+    int x , y ;
+    x = y = 0 ;
+    textctrl->MacWindowToRootWindow( &x , &y ) ;
+    OffsetRect( &visBounds , x , y ) ;
+    
+    if ( !EqualRect( &bounds , &m_txnControlBounds ) || !EqualRect( &visBounds , &m_txnVisBounds) )
     {
-        // old position
-        Rect oldBounds = m_txnControlBounds ;
         m_txnControlBounds = bounds ;
+        m_txnVisBounds = visBounds ;
         wxMacWindowClipper cl(textctrl) ;
 
 #ifdef __WXMAC_OSX__
@@ -2161,8 +2192,28 @@ void wxMacMLTEClassicControl::MacUpdatePosition()
                 SetControlViewSize( m_sbVertical , h ) ;
             }
         }
+        
+        Rect oldviewRect ;
+        TXNLongRect olddestRect ;
+        TXNGetRectBounds( m_txn , &oldviewRect , &olddestRect , NULL ) ;
+        
+        Rect viewRect = { m_txnControlBounds.top, m_txnControlBounds.left,
+            m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ;
+        TXNLongRect destRect = { m_txnControlBounds.top, m_txnControlBounds.left,
+            m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ) } ;
+            
+        if ( olddestRect.right >= 10000 )
+            destRect.right = destRect.left + 32000 ;
+            
+        if ( olddestRect.bottom >= 0x20000000 )
+            destRect.bottom = destRect.top + 0x40000000 ;
+            
+        SectRect( &viewRect , &visBounds , &viewRect ) ; 
+        TXNSetRectBounds( m_txn , &viewRect , &destRect , false ) ;
+/*
         TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
             m_txnControlBounds.bottom - ( m_sbHorizontal ? 14 : 0 ) , m_txnControlBounds.right - ( m_sbVertical ? 14 : 0 ), m_txnFrameID);
+*/
 #else
         
         TXNSetFrameBounds( m_txn, m_txnControlBounds.top, m_txnControlBounds.left,
@@ -2313,7 +2364,7 @@ wxInt16 wxMacMLTEClassicControl::MacControlUserPaneKeyDownProc (wxInt16 keyCode,
     ev.modifiers = modifiers ;
     ev.message = (( keyCode << 8 ) & keyCodeMask ) + ( charCode & charCodeMask ) ;
     TXNKeyDown( m_txn , &ev);
-
+    
     return kControlEntireControl;
 }
 
@@ -2380,10 +2431,10 @@ wxMacMLTEClassicControl::wxMacMLTEClassicControl( wxTextCtrl *wxPeer,
 
     DoCreate();
 
-    MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ;
-
     AdjustCreationAttributes( *wxWHITE , true) ;
 
+    MacSetObjectVisibility( wxPeer->MacIsReallyShown() ) ;
+
     wxMacWindowClipper clipper( m_peer ) ;
     SetTXNData( st , kTXNStartOffset, kTXNEndOffset ) ;
     TXNSetSelection( m_txn, 0, 0);
@@ -2533,6 +2584,7 @@ OSStatus wxMacMLTEClassicControl::DoCreate()
     UMAGetControlBoundsInWindowCoords(m_controlRef, &bounds);
  
     m_txnControlBounds = bounds ;
+    m_txnVisBounds = bounds ;
     
     CGrafPtr        origPort = NULL ;
     GDHandle        origDev = NULL ;
@@ -2582,7 +2634,29 @@ OSStatus wxMacMLTEClassicControl::DoCreate()
                               kTXNTextensionFile,
                               kTXNSystemDefaultEncoding,
                               &m_txn, &m_txnFrameID, NULL ) );
+/*
+    TXNCarbonEventInfo cInfo ;
+    
+    cInfo.useCarbonEvents = false ;
+    cInfo.filler = 0 ;
+    cInfo.flags = 0 ;
+    cInfo.fDictionary = NULL ;
+
+    TXNControlTag iControlTags[] = 
+        { 
+            kTXNUseCarbonEvents ,
+        };
+    TXNControlData iControlData[] = 
+        { 
+            {(UInt32) &cInfo },
+        };
+        
+    int toptag = WXSIZEOF( iControlTags ) ;
 
+    verify_noerr( TXNSetTXNObjectControls( m_txn, false , toptag,
+                                        iControlTags, iControlData )) ;
+
+*/
 #ifdef __WXMAC_OSX__
     TXNRegisterScrollInfoProc( m_txn, gTXNScrollInfoProc, (SInt32) this);
 #endif