X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9d46359178b28cd86e189e877015a8e69ff5bbaa..2078e2f129c323dd1b01aeef5061f787f8475386:/src/mac/carbon/textctrl.cpp diff --git a/src/mac/carbon/textctrl.cpp b/src/mac/carbon/textctrl.cpp index 341d97c5e9..7a3e1acb96 100644 --- a/src/mac/carbon/textctrl.cpp +++ b/src/mac/carbon/textctrl.cpp @@ -174,23 +174,14 @@ public : virtual bool HasOwnContextMenu() const { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - if ( UMAGetSystemVersion() >= 0x1040 ) - { - TXNCommandEventSupportOptions options ; - TXNGetCommandEventSupport( m_txn , & options ) ; - return options & kTXNSupportEditCommandProcessing ; - } -#endif - - return false ; + TXNCommandEventSupportOptions options ; + TXNGetCommandEventSupport( m_txn , & options ) ; + return options & kTXNSupportEditCommandProcessing ; } virtual void CheckSpelling(bool check) { -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - TXNSetSpellCheckAsYouType( m_txn, (Boolean) check ); -#endif + TXNSetSpellCheckAsYouType( m_txn, (Boolean) check ); } virtual void Clear() ; @@ -1028,52 +1019,6 @@ bool wxTextCtrl::MacSetupCursor( const wxPoint& pt ) return true ; } -#if !TARGET_API_MAC_OSX - -// user pane implementation - -void wxTextCtrl::MacControlUserPaneDrawProc(wxInt16 part) -{ - GetPeer()->MacControlUserPaneDrawProc( part ) ; -} - -wxInt16 wxTextCtrl::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) -{ - return GetPeer()->MacControlUserPaneHitTestProc( x , y ) ; -} - -wxInt16 wxTextCtrl::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) -{ - return GetPeer()->MacControlUserPaneTrackingProc( x , y , actionProc ) ; -} - -void wxTextCtrl::MacControlUserPaneIdleProc() -{ - GetPeer()->MacControlUserPaneIdleProc( ) ; -} - -wxInt16 wxTextCtrl::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) -{ - return GetPeer()->MacControlUserPaneKeyDownProc( keyCode , charCode , modifiers ) ; -} - -void wxTextCtrl::MacControlUserPaneActivateProc(bool activating) -{ - GetPeer()->MacControlUserPaneActivateProc( activating ) ; -} - -wxInt16 wxTextCtrl::MacControlUserPaneFocusProc(wxInt16 action) -{ - return GetPeer()->MacControlUserPaneFocusProc( action ) ; -} - -void wxTextCtrl::MacControlUserPaneBackgroundProc(void* info) -{ - GetPeer()->MacControlUserPaneBackgroundProc( info ) ; -} - -#endif - // ---------------------------------------------------------------------------- // implementation base class // ---------------------------------------------------------------------------- @@ -1251,8 +1196,6 @@ int wxMacTextControl::GetLineLength(long lineNo) const // standard unicode control implementation // ---------------------------------------------------------------------------- -#if TARGET_API_MAC_OSX - // the current unicode textcontrol implementation has a bug : only if the control // is currently having the focus, the selection can be retrieved by the corresponding // data tag. So we have a mirroring using a member variable @@ -1475,7 +1418,10 @@ void wxMacUnicodeTextControl::SetSelection( long from , long to ) else { from = wxMin(textLength,wxMax(from,0)) ; - to = wxMax(0,wxMin(textLength,to)) ; + if ( to == -1 ) + to = textLength; + else + to = wxMax(0,wxMin(textLength,to)) ; } sel.selStart = from ; @@ -1509,8 +1455,6 @@ void wxMacUnicodeTextControl::WriteText( const wxString& str ) } } -#endif - // ---------------------------------------------------------------------------- // MLTE control implementation (common part) // ---------------------------------------------------------------------------- @@ -1745,43 +1689,39 @@ void wxMacMLTEControl::AdjustCreationAttributes(const wxColour &background, TXNBackground tback; tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = MAC_WXCOLORREF( background.GetPixel() ); + background.GetRGBColor( &tback.bg.color ); TXNSetBackground( m_txn , &tback ); -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 - if ( UMAGetSystemVersion() >= 0x1040 ) + + TXNCommandEventSupportOptions options ; + if ( TXNGetCommandEventSupport( m_txn, &options ) == noErr ) { - TXNCommandEventSupportOptions options ; - if ( TXNGetCommandEventSupport( m_txn, &options ) == noErr ) - { - options |= - kTXNSupportEditCommandProcessing - | kTXNSupportEditCommandUpdating - | kTXNSupportFontCommandProcessing - | kTXNSupportFontCommandUpdating; - - // only spell check when not read-only - // use system options for the default - bool checkSpelling = false ; - if ( !(m_windowStyle & wxTE_READONLY) ) - { + options |= + kTXNSupportEditCommandProcessing + | kTXNSupportEditCommandUpdating + | kTXNSupportFontCommandProcessing + | kTXNSupportFontCommandUpdating; + + // only spell check when not read-only + // use system options for the default + bool checkSpelling = false ; + if ( !(m_windowStyle & wxTE_READONLY) ) + { #if wxUSE_SYSTEM_OPTIONS - if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) == 1) ) - { - checkSpelling = true ; - } -#endif + if ( wxSystemOptions::HasOption( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) && (wxSystemOptions::GetOptionInt( wxMAC_TEXTCONTROL_USE_SPELL_CHECKER ) == 1) ) + { + checkSpelling = true ; } - - if ( checkSpelling ) - options |= - kTXNSupportSpellCheckCommandProcessing - | kTXNSupportSpellCheckCommandUpdating; - - TXNSetCommandEventSupport( m_txn , options ) ; +#endif } + + if ( checkSpelling ) + options |= + kTXNSupportSpellCheckCommandProcessing + | kTXNSupportSpellCheckCommandUpdating; + + TXNSetCommandEventSupport( m_txn , options ) ; } -#endif } void wxMacMLTEControl::SetBackground( const wxBrush &brush ) @@ -1790,10 +1730,15 @@ void wxMacMLTEControl::SetBackground( const wxBrush &brush ) TXNBackground tback; tback.bgType = kTXNBackgroundTypeRGB; - tback.bg.color = MAC_WXCOLORREF( brush.GetColour().GetPixel() ); + brush.GetColour().GetRGBColor(&tback.bg.color); TXNSetBackground( m_txn , &tback ); } +static inline int wxConvertToTXN(int x) +{ + return wx_static_cast(int, x / 254.0 * 72 + 0.5); +} + void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , long to ) { TXNTypeAttributes typeAttr[4] ; @@ -1804,9 +1749,9 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo TXNControlTag controlTags[4]; TXNControlData controlData[4]; size_t controlAttrCount = 0; - + TXNTab* tabs = NULL; - + bool relayout = false; if ( style.HasFont() ) @@ -1822,19 +1767,18 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo if ( style.HasTextColour() ) { wxASSERT( typeAttrCount < WXSIZEOF(typeAttr) ); - color = MAC_WXCOLORREF(style.GetTextColour().GetPixel()) ; - + style.GetTextColour().GetRGBColor( &color ); typeAttr[typeAttrCount].tag = kTXNQDFontColorAttribute ; typeAttr[typeAttrCount].size = kTXNQDFontColorAttributeSize ; typeAttr[typeAttrCount].data.dataPtr = (void*) &color ; typeAttrCount++ ; } - + if ( style.HasAlignment() ) { wxASSERT( controlAttrCount < WXSIZEOF(controlTags) ); SInt32 align; - + switch ( style.GetAlignment() ) { case wxTEXT_ALIGNMENT_LEFT: @@ -1848,13 +1792,13 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo break; case wxTEXT_ALIGNMENT_JUSTIFIED: align = kTXNFullJust; - break; + break; default : case wxTEXT_ALIGNMENT_DEFAULT: align = kTXNFlushDefault; break; } - + controlTags[controlAttrCount] = kTXNJustificationTag ; controlData[controlAttrCount].sValue = align ; controlAttrCount++ ; @@ -1869,29 +1813,29 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo &controlTags[controlAttrCount], &controlData[controlAttrCount]) ); if ( style.HasLeftIndent() ) { - margins.leftMargin = style.GetLeftIndent() / 254.0 * 72 + 0.5; + margins.leftMargin = wxConvertToTXN(style.GetLeftIndent()); } if ( style.HasRightIndent() ) { - margins.rightMargin = style.GetRightIndent() / 254.0 * 72 + 0.5; + margins.rightMargin = wxConvertToTXN(style.GetRightIndent()); } controlAttrCount++ ; } - + if ( style.HasTabs() ) { const wxArrayInt& tabarray = style.GetTabs(); // unfortunately Mac only applies a tab distance, not individually different tabs controlTags[controlAttrCount] = kTXNTabSettingsTag; if ( tabarray.size() > 0 ) - controlData[controlAttrCount].tabValue.value = tabarray[0] / 254.0 * 72 + 0.5; + controlData[controlAttrCount].tabValue.value = wxConvertToTXN(tabarray[0]); else - controlData[controlAttrCount].tabValue.value = 72 ; + controlData[controlAttrCount].tabValue.value = 72 ; controlData[controlAttrCount].tabValue.tabType = kTXNLeftTab; controlAttrCount++ ; } - + // unfortunately the relayout is not automatic if ( controlAttrCount > 0 ) { @@ -1899,18 +1843,18 @@ void wxMacMLTEControl::TXNSetAttribute( const wxTextAttr& style , long from , lo controlTags, controlData) ); relayout = true; } - + if ( typeAttrCount > 0 ) { verify_noerr( TXNSetTypeAttributes( m_txn , typeAttrCount, typeAttr, from , to ) ); relayout = true; } - + if ( tabs != NULL ) { delete[] tabs; } - + if ( relayout ) { TXNRecalcTextLayout( m_txn ); @@ -1989,7 +1933,7 @@ void wxMacMLTEControl::Replace( long from , long to , const wxString &str ) wxMacWindowClipper c( m_peer ) ; #endif - TXNSetSelection( m_txn, from, to ) ; + TXNSetSelection( m_txn, from, to == -1 ? kTXNEndOffset : to ) ; TXNClear( m_txn ) ; SetTXNData( value, kTXNUseCurrentSelection, kTXNUseCurrentSelection ) ; } @@ -2022,7 +1966,7 @@ void wxMacMLTEControl::SetSelection( long from , long to ) if ((from == -1) && (to == -1)) TXNSelectAll( m_txn ); else - TXNSetSelection( m_txn, from, to ); + TXNSetSelection( m_txn, from, to == -1 ? kTXNEndOffset : to ); TXNShowSelection( m_txn, kTXNShowStart ); } @@ -2980,13 +2924,10 @@ static pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler { case kEventTextInputUnicodeForKeyEvent : { - if ( UMAGetSystemVersion() >= 0x1040 ) - { - TXNOffset from , to ; - TXNGetSelection( focus->GetTXNObject() , &from , &to ) ; - if ( from == to ) - TXNShowSelection( focus->GetTXNObject() , kTXNShowStart ); - } + TXNOffset from , to ; + TXNGetSelection( focus->GetTXNObject() , &from , &to ) ; + if ( from == to ) + TXNShowSelection( focus->GetTXNObject() , kTXNShowStart ); result = CallNextEventHandler(handler,event); break; } @@ -3095,7 +3036,7 @@ bool wxMacMLTEHIViewControl::HasFocus() const ControlRef control ; if ( GetUserFocusWindow() == NULL ) return false; - + GetKeyboardFocus( GetUserFocusWindow() , &control ) ; return control == m_textView ; } @@ -3106,7 +3047,8 @@ void wxMacMLTEHIViewControl::SetBackground( const wxBrush &brush ) #if 0 CGColorSpaceRef rgbSpace = CGColorSpaceCreateDeviceRGB(); - RGBColor col = MAC_WXCOLORREF(brush.GetColour().GetPixel()) ; + RGBColor col; + brush.GetColour().GetRGBColor(&col) ; float component[4] ; component[0] = col.red / 65536.0 ;