X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5ca0d8122ab2ecbce178aa9f21f13270c4ffaca0..a2fe01c96d43777db58041ec470e8aaa27f1e3b2:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 0f5950f8e8..8f28ec3dcc 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -55,6 +55,13 @@ #ifndef __DARWIN__ #include #endif + +// if this is set to 1 then under OSX 10.2 the 'classic' MLTE implementation will be used +// if set to 0 then the unicode textctrl will be used +#ifndef wxMAC_AWAYS_USE_MLTE +#define wxMAC_AWAYS_USE_MLTE 1 +#endif + #include #include #include @@ -197,6 +204,7 @@ public : void AdjustCreationAttributes( const wxColour& background , bool visible ) ; virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ; + virtual void SetBackground( const wxBrush &brush) ; virtual void SetStyle(long start, long end, const wxTextAttr& style) ; virtual void Copy() ; virtual void Cut() ; @@ -233,6 +241,8 @@ protected : // implementation available under OSX +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + class wxMacMLTEHIViewControl : public wxMacMLTEControl { public : @@ -248,6 +258,8 @@ protected : HIViewRef m_textView ; } ; +#endif + class wxMacUnicodeTextControl : public wxMacTextControl { public : @@ -273,7 +285,7 @@ protected : OSType m_valueTag ; } ; -#else +#endif // implementation available under classic @@ -295,28 +307,13 @@ public : STPTextPaneVars* m_macTXNvars ; } ; -#endif -// built-in TextCtrl - - #define TE_UNLIMITED_LENGTH 0xFFFFFFFFUL -#if TARGET_API_MAC_OSX - #define wxMAC_USE_MLTE 1 - #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 - #define wxMAC_USE_MLTE_HIVIEW 1 - #else - #define wxMAC_USE_MLTE_HIVIEW 0 - #endif -#else - // there is no unicodetextctrl on classic, and hopefully MLTE works better there - #define wxMAC_USE_MLTE 1 - #define wxMAC_USE_MLTE_HIVIEW 0 -#endif #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxControl) BEGIN_EVENT_TABLE(wxTextCtrl, wxControl) + EVT_ERASE_BACKGROUND( wxTextCtrl::OnEraseBackground ) EVT_DROP_FILES(wxTextCtrl::OnDropFiles) EVT_CHAR(wxTextCtrl::OnChar) EVT_MENU(wxID_CUT, wxTextCtrl::OnCut) @@ -357,19 +354,8 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, m_macIsUserPane = FALSE ; m_editable = true ; - // base initialization - - if ( !HasFlag(wxNO_BORDER) ) - { -#if wxMAC_USE_MLTE -#if wxMAC_USE_MLTE_HIVIEW - style |= wxSUNKEN_BORDER ; -#endif -#endif - } - else - { - } + if ( ! ( style & wxNO_BORDER) ) + style = ( style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; if ( !wxTextCtrlBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) ) return FALSE; @@ -386,15 +372,29 @@ bool wxTextCtrl::Create(wxWindow *parent, wxWindowID id, m_windowStyle |= wxTE_PROCESS_ENTER; style |= wxTE_PROCESS_ENTER ; } -#if wxMAC_USE_MLTE -#if wxMAC_USE_MLTE_HIVIEW - m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; -#else - m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; -#endif -#else // wxMAC_USE_MLTE - m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; + +#if TARGET_API_MAC_OSX +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + if ( UMAGetSystemVersion() >= 0x1030 ) + { + m_peer = new wxMacMLTEHIViewControl( this , str , pos , size , style ) ; + } +#endif +#if !wxMAC_AWAYS_USE_MLTE + if ( !m_peer ) + { + m_peer = new wxMacUnicodeTextControl( this , str , pos , size , style ) ; + } +#endif #endif + if ( !m_peer ) + { + // this control draws the border itself + if ( !HasFlag(wxNO_BORDER) ) + m_windowStyle &= ~wxSUNKEN_BORDER ; + m_peer = new wxMacMLTEClassicControl( this , str , pos , size , style ) ; + } + MacPostControlCreate(pos,size) ; if ( m_windowStyle & wxTE_READONLY) @@ -631,34 +631,35 @@ wxSize wxTextCtrl::DoGetBestSize() const int hText; + // these are the numbers from the HIG, we reduce them by the borders + // first + switch( m_windowVariant ) { case wxWINDOW_VARIANT_NORMAL : - hText = 22 ; + hText = 22 - 6 ; break ; case wxWINDOW_VARIANT_SMALL : - hText = 19 ; + hText = 19 - 6 ; break ; case wxWINDOW_VARIANT_MINI : - hText= 15 ; + hText= 15 - 6 ; break ; default : - hText = 22 ; + hText = 22 - 6; break ; } -#if !wxMAC_USE_MLTE - // unicode text control is using client size, ie 3 pixels on every side - // TODO make this fit into normal window size concept, probably having - // to reintroduce the margin vars - hText -= 6 ; -#endif - + // as the above numbers have some free space around the text + // we get 5 lines like this anyway if ( m_windowStyle & wxTE_MULTILINE ) { hText *= 5 ; } + if ( !HasFlag(wxNO_BORDER) ) + hText += 6 ; + return wxSize(wText, hText); } @@ -759,6 +760,14 @@ void wxTextCtrl::OnDropFiles(wxDropFilesEvent& event) } } +void wxTextCtrl::OnEraseBackground(wxEraseEvent& event) +{ + // all erasing should be done by the real mac control implementation + // while this is true for MLTE under classic, the HITextView is somehow + // transparent but background erase is not working correctly, so intercept + // things while we can... +} + void wxTextCtrl::OnChar(wxKeyEvent& event) { int key = event.GetKeyCode() ; @@ -1253,7 +1262,7 @@ void wxMacUnicodeTextControl::WriteText(const wxString& str) val.Remove( start , end - start ) ; val.insert( start , str ) ; SetStringValue( val ) ; - SetInsertionPoint( start + str.Length() ) ; + SetSelection( start + str.Length() , start + str.Length() ) ; #endif } @@ -1343,7 +1352,7 @@ wxString wxMacMLTEControl::GetStringValue() const } #else Handle theText ; - err = TXNGetDataEncoded( ((TXNObject) m_macTXN), kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); + err = TXNGetDataEncoded( m_txn , kTXNStartOffset, kTXNEndOffset, &theText , kTXNTextData ); // all done if ( err ) { @@ -1464,6 +1473,15 @@ void wxMacMLTEControl::AdjustCreationAttributes( const wxColour &background, boo TXNSetBackground( m_txn , &tback); } +void wxMacMLTEControl::SetBackground( const wxBrush &brush ) +{ + // currently only solid background are supported + TXNBackground tback; + tback.bgType = kTXNBackgroundTypeRGB; + tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); + TXNSetBackground( m_txn , &tback); +} + int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttributes typeAttr[] ) { Str255 fontName = "\pMonaco" ; @@ -1493,7 +1511,6 @@ int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttribu typeAttr[attrCounter+2].size = kTXNQDFontStyleAttributeSize ; typeAttr[attrCounter+2].data.dataValue = fontStyle ; attrCounter += 3 ; - } if ( style.HasTextColour() ) { @@ -1509,7 +1526,7 @@ int wxMacMLTEControl::ConvertAttribute( const wxTextAttr& style , TXNTypeAttribu void wxMacMLTEControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) { EditHelper help(m_txn) ; - wxTextAttr style(wxNullColour,wxNullColour,font) ; + wxTextAttr style(foreground,wxNullColour,font) ; TXNTypeAttributes typeAttr[4] ; int attrCounter = ConvertAttribute( style , typeAttr ) ; if ( attrCounter > 0 ) @@ -1870,8 +1887,6 @@ int wxMacMLTEControl::GetLineLength(long lineNo) const // MLTE control implementation (classic part) // ---------------------------------------------------------------------------- -#if !TARGET_API_MAC_OSX - // CS:TODO we still have a problem getting properly at the text events of a control because under Carbon // the MLTE engine registers itself for the key events thus the normal flow never occurs, the only measure for the // moment is to avoid setting the true focus on the control, the proper solution at the end would be to have @@ -2088,7 +2103,20 @@ static pascal ControlPartCode TPPaneHitTestProc(ControlRef theControl, Point whe if (PtInRect(where, &varsp->fRBounds)) result = kmUPTextPart; else - result = 0; + { + // sometimes we get the coords also in control local coordinates, therefore test again + if ( textctrl->MacGetTopLevelWindow()->MacUsesCompositing() ) + { + int x = 0 , y = 0 ; + textctrl->MacClientToRootWindow( &x , &y ) ; + where.h += x ; + where.v += y ; + } + if (PtInRect(where, &varsp->fRBounds)) + result = kmUPTextPart; + else + result = 0; + } } return result; } @@ -2436,15 +2464,14 @@ OSStatus wxMacMLTEClassicControl::DoCreate() return err; } - -#endif - // ---------------------------------------------------------------------------- // MLTE control implementation (OSX part) // ---------------------------------------------------------------------------- #if TARGET_API_MAC_OSX +#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + wxMacMLTEHIViewControl::wxMacMLTEHIViewControl( wxWindow *wxPeer, const wxString& str, const wxPoint& pos, @@ -2509,9 +2536,12 @@ bool wxMacMLTEHIViewControl::HasFocus() const bool wxMacMLTEHIViewControl::NeedsFocusRect() const { - return true ; + return m_windowStyle & wxNO_BORDER ? false : true; } +#endif // MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 + + #endif #endif // wxUSE_TEXTCTRL