]> git.saurik.com Git - wxWidgets.git/blobdiff - src/mac/carbon/textctrl.cpp
moved fatal exception handling code to msw/main.cpp from common code
[wxWidgets.git] / src / mac / carbon / textctrl.cpp
index 9485a5b144c611f4ce7699c2afdb6f5283f9319c..d372d0a3b2a85b503ba2612e67bd38015e4c2e57 100644 (file)
@@ -199,7 +199,6 @@ public :
     virtual wxString GetStringValue() const ;
     virtual void SetStringValue( const wxString &str) ;
     
-    static int ConvertAttribute( const wxTextAttr& style , TXNTypeAttributes attr[] ) ;
     static TXNFrameOptions FrameOptionsFromWXStyle( long wxStyle ) ;
     void    AdjustCreationAttributes( const wxColour& background , bool visible ) ;
 
@@ -234,6 +233,7 @@ public :
     void SetTXNData( const wxString& st , TXNOffset start , TXNOffset end ) ;
 
 protected :
+    void TXNSetAttribute( const wxTextAttr& style , long from , long to ) ;
     TXNObject m_txn ;
 } ;
 
@@ -252,6 +252,7 @@ public :
                              const wxSize& size, long style ) ;
     virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
     virtual bool HasFocus() const ;
+    virtual bool NeedsFocusRect() const;
 protected :
     HIViewRef m_scrollView ;
     HIViewRef m_textView ;
@@ -433,6 +434,11 @@ void wxTextCtrl::SetValue(const wxString& str)
         return ;
 
     GetPeer()->SetStringValue(str) ;
+
+    wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
+    event.SetString( GetValue() ) ;
+    event.SetEventObject( this );
+    GetEventHandler()->ProcessEvent(event);
 }
 
 void wxTextCtrl::SetMaxLength(unsigned long len)
@@ -791,6 +797,16 @@ void wxTextCtrl::OnChar(wxKeyEvent& event)
         return ;
     }
 
+    // Check if we have reached the max # of chars, but still allow navigation and deletion
+    if ( !IsMultiLine() && GetValue().Length() >= m_maxLength &&
+        key != WXK_LEFT && key != WXK_RIGHT && key != WXK_TAB &&
+        key != WXK_BACK && !( key == WXK_RETURN && (m_windowStyle & wxPROCESS_ENTER) )
+       )
+    {
+        // eat it, we don't want to add more than allowed # of characters
+        return;
+    }
+
     // assume that any key not processed yet is going to modify the control
     m_dirty = true;
 
@@ -1493,8 +1509,9 @@ void wxMacMLTEControl::SetBackground( const wxBrush &brush )
     TXNSetBackground( m_txn , &tback);
 }
 
-int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttributes typeAttr[] )
+void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to)
 {
+       TXNTypeAttributes typeAttr[4] ;
     Str255 fontName = "\pMonaco" ;
     SInt16 fontSize = 12 ;
     Style fontStyle = normal ;
@@ -1511,7 +1528,7 @@ int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttribu
             fontStyle |= bold ;
         if ( font.GetStyle() == wxITALIC )
             fontStyle |= italic ;
-        
+
         typeAttr[attrCounter].tag = kTXNQDFontNameAttribute ;
         typeAttr[attrCounter].size = kTXNQDFontNameAttributeSize ;
         typeAttr[attrCounter].data.dataPtr = (void*) fontName ;
@@ -1531,29 +1548,21 @@ int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttribu
         color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ;
         attrCounter += 1 ;
     }
-    return attrCounter ;
+    if ( attrCounter > 0 )
+    {
+        verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, from , to) );
+    }
 }
 
 void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) 
 {
     EditHelper help(m_txn) ;
-    wxTextAttr style(foreground,wxNullColour,font) ;
-    TXNTypeAttributes typeAttr[4] ;
-    int attrCounter = ConvertAttribute( style , typeAttr ) ;
-    if ( attrCounter > 0 )
-    {
-        verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, kTXNStartOffset,kTXNEndOffset) );
-    }
+    TXNSetAttribute( wxTextAttr(foreground,wxNullColour,font) , kTXNStartOffset,kTXNEndOffset ) ;
 }
 void wxMacMLTEControl::SetStyle(long start, long end, const wxTextAttr& style) 
 { 
     EditHelper help(m_txn) ;
-    TXNTypeAttributes typeAttr[4] ;
-    int attrCounter = ConvertAttribute( style , typeAttr ) ;
-    if ( attrCounter > 0 )
-    {
-        verify_noerr( TXNSetTypeAttributes ( m_txn , attrCounter , typeAttr, start,end) );
-    }
+    TXNSetAttribute( style , start,end ) ;
 }   
  
 void wxMacMLTEControl::Copy() 
@@ -1987,21 +1996,36 @@ static void TPCalculateBounds(STPTextPaneVars *varsp, const Rect& bounds)
 OSStatus MLTESetObjectVisibility( STPTextPaneVars *varsp, Boolean vis , long wxStyle)
 {
     OSStatus err = noErr ;
-#if TARGET_API_MAC_OSX
-    TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
-    TXNControlData iControlData[1] = {{ vis }};
-    err = ::TXNSetTXNObjectControls( varsp->fTXNRec, false, 1, iControlTags, iControlData );
-#endif
     wxTextCtrl* textctrl = (wxTextCtrl*) GetControlReference(varsp->fUserPaneRec);
-    if ( vis && textctrl )
+    if ( textctrl )
     {
+#if TARGET_API_MAC_OSX
+       TXNControlTag iControlTags[1] = { kTXNVisibilityTag };
+       TXNControlData iControlData[1] = {{ vis }};
+       err = ::TXNSetTXNObjectControls( varsp->fTXNRec, false, 1, iControlTags, iControlData );
+#endif
         Rect bounds ;
         UMAGetControlBoundsInWindowCoords( varsp->fUserPaneRec, &bounds);
         TPCalculateBounds( varsp , bounds ) ;
-        wxMacWindowClipper cl(textctrl) ;
-        TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left,
-                           varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame);
-        TXNShowSelection( varsp->fTXNRec, kTXNShowStart);
+           if ( vis )
+           {
+                       wxMacWindowClipper cl(textctrl) ;
+               TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top, varsp->fRTextArea.left,
+                                  varsp->fRTextArea.bottom, varsp->fRTextArea.right, varsp->fTXNFrame);
+               TXNShowSelection( varsp->fTXNRec, kTXNShowStart);
+           }
+           else
+           {
+#if TARGET_API_MAC_OSX
+                       // in 10.2 the scrollbars are still actively redrawn when using only the code above
+                       if ( UMAGetSystemVersion() < 0x1030 )
+                       {
+                       TXNSetFrameBounds( varsp->fTXNRec, varsp->fRTextArea.top + 20000 , varsp->fRTextArea.left + 20000 ,
+                               varsp->fRTextArea.bottom + 20000 , varsp->fRTextArea.right + 20000 , varsp->fTXNFrame);
+                               
+                       }
+#endif
+           }
     }
     return err ;
 }
@@ -2059,7 +2083,7 @@ static void TPRedrawFocusOutline(STPTextPaneVars *varsp) {
        if (varsp->fFocusDrawState != (varsp->fIsActive && varsp->fInFocus)) 
        { 
                varsp->fFocusDrawState = (varsp->fIsActive && varsp->fInFocus);
-               DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState);
+               // DrawThemeFocusRect(&varsp->fRFocusOutline, varsp->fFocusDrawState);
        }
 }
 
@@ -2403,6 +2427,11 @@ void wxMacMLTEClassicControl::VisibilityChanged(bool shown)
         InvalWindowRect( GetControlOwner( m_controlRef ) , &((STPTextPaneVars *)m_macTXNvars)->fRBounds ) ;
 }
 
+bool wxMacMLTEClassicControl::NeedsFocusRect() const 
+{
+    return true;
+}
+
 OSStatus wxMacMLTEClassicControl::DoCreate()
 {
     Rect bounds;