ExtEdit.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:204k
- , m_fnValidation( fnValidation )
- , m_fnConversion( fnConversion )
- , m_clrSymbol( COLORREF(-1L) )
- {
- }
- CExtEditWithBehavior::CBehaviorMasked::CharRule::CharRule( COLORREF clrSymbol, __EXT_MFC_SAFE_TCHAR cSymbol, ValidationFunction fnValidation, ConversionFunction fnConversion /*= NULL*/ )
- : m_cSymbol( cSymbol )
- , m_fnValidation( fnValidation )
- , m_fnConversion( fnConversion )
- , m_clrSymbol( clrSymbol )
- {
- }
- CExtEditWithBehavior::CBehaviorMasked::CharRule::~CharRule()
- {
- }
- bool CExtEditWithBehavior::CBehaviorMasked::CharRule::Validate( __EXT_MFC_SAFE_TCHAR _tchr ) const
- {
- if( m_fnValidation != NULL )
- return ( m_fnValidation( _tchr ) != 0 ) ? true : false;
- return true;
- }
- __EXT_MFC_SAFE_TCHAR CExtEditWithBehavior::CBehaviorMasked::CharRule::Convert( __EXT_MFC_SAFE_TCHAR _tchr ) const
- {
- if( m_fnConversion != NULL )
- return (TCHAR)m_fnConversion( _tchr );
- return _tchr;
- }
- void CExtEditWithBehavior::CBehaviorMasked::CharRule::Set(__EXT_MFC_SAFE_TCHAR cSymbol)
- {
- m_cSymbol = cSymbol;
- }
- __EXT_MFC_SAFE_TCHAR CExtEditWithBehavior::CBehaviorMasked::CharRule::Get() const
- {
- return m_cSymbol;
- }
- CExtEditWithBehavior::CBehaviorMasked::CharRule::operator __EXT_MFC_SAFE_TCHAR() const
- {
- return m_cSymbol;
- }
- //void CExtEditWithBehavior::OnChange()
- //{
- //}
- //
- //void CExtEditWithBehavior::OnUpdate()
- //{
- //}
- void CExtEditWithBehavior::CBehaviorMasked::CharRule::Serialize( CArchive & ar )
- {
- if( ar.IsStoring() )
- {
- ar << DWORD(TCHAR(__EXT_MFC_SAFE_TCHAR(m_cSymbol)));
- ar << DWORD(m_clrSymbol);
- }
- else
- {
- DWORD dwTmp;
- ar >> dwTmp;
- m_cSymbol = (__EXT_MFC_SAFE_TCHAR)(TCHAR)(dwTmp);
- ar >> dwTmp;
- m_clrSymbol = (COLORREF)dwTmp;
- }
- }
- void CExtEditWithBehavior::CBehaviorMasked::CharRuleArray::Serialize( CArchive & ar )
- {
- DWORD dwIndex, dwCount;
- if( ar.IsStoring() )
- {
- dwCount = DWORD( GetSize() );
- ar << dwCount;
- }
- else
- {
- RemoveAll();
- ar >> dwCount;
- SetSize( INT(dwCount) );
- }
- for( dwIndex = 0; dwIndex < dwCount; dwIndex ++ )
- {
- CharRule & _cr = ElementAt( INT(dwIndex) );
- _cr.Serialize( ar );
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditMasked
- IMPLEMENT_DYNCREATE( CExtEditMasked, CExtEditWithBehavior );
- CExtEditMasked::CExtEditMasked(
- __EXT_MFC_SAFE_LPCTSTR strMask // = _T("")
- )
- : CBehaviorMasked( strMask )
- , m_clrDefault( COLORREF(-1L) )
- {
- m_pEditWithBehaviorWnd = this;
- }
- BEGIN_MESSAGE_MAP( CExtEditMasked, CExtEditWithBehavior )
- //{{AFX_MSG_MAP(CExtEditMasked)
- ON_WM_CHAR()
- ON_WM_KEYDOWN()
- ON_WM_KILLFOCUS()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void CExtEditMasked::_Rich_OnDraw()
- {
- ASSERT_VALID( this );
- if( ! m_bRichMode )
- return;
- if( GetSafeHwnd() == NULL )
- return;
- if( m_bRichPainting )
- return;
- m_bRichPainting = true;
- CExtSafeString strText = TextGet();
- CExtSafeString strMask = MaskGet();
- INT nTextLen = INT( strText.GetLength() );
- INT nMaskLen = INT( strMask.GetLength() );
- INT nWalkLen = min( nTextLen, nMaskLen );
- if( nWalkLen > 0 )
- {
- COLORREF clrDefault = m_clrDefault;
- if( clrDefault == COLORREF(-1L) )
- {
- if( IsWindowEnabled() && ( GetStyle() & ES_READONLY ) == 0 )
- clrDefault = ::GetSysColor( COLOR_WINDOWTEXT );
- else
- clrDefault = ::GetSysColor( COLOR_3DSHADOW );
- }
- CHARFORMAT cfDefault;
- ::memset( &cfDefault, 0, sizeof(CHARFORMAT) );
- cfDefault.dwMask = CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_PROTECTED|CFM_COLOR;
- cfDefault.dwEffects = CFE_PROTECTED;
- CFont * pFont = GetFont();
- if( pFont->GetSafeHandle() == NULL )
- {
- CWnd * pWndParent = GetParent();
- if( pWndParent->GetSafeHwnd() != NULL )
- pFont = pWndParent->GetFont();
- if( pFont->GetSafeHandle() == NULL )
- pFont = &(PmBridge_GetPM()->m_FontNormal);
- }
- LOGFONT _lf; ::memset( &_lf, 0, sizeof(LOGFONT) );
- pFont->GetLogFont( &_lf );
- #if (! defined _RICHEDIT_VER )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- #if ( _RICHEDIT_VER < 0x0200 )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- __EXT_MFC_STRCPY( cfDefault.szFaceName, sizeof(cfDefault.szFaceName)/sizeof(cfDefault.szFaceName[0]), _lf.lfFaceName );
- #endif
- #endif
- CWindowDC dcDesktop( NULL );
- cfDefault.yHeight = ::MulDiv( _lf.lfHeight, 72 * 20, dcDesktop.GetDeviceCaps( LOGPIXELSY ) );
- cfDefault.yHeight = abs( cfDefault.yHeight );
- bool bEnabled = IsWindowEnabled() ? true : false, bReadOnly = ( ( GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- cfDefault.crTextColor = bEnabled ? ( bReadOnly ? m_clrRichTextReadOnly : m_clrRichTextNormal ) : m_clrRichTextDisabled;
- if( cfDefault.crTextColor == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- cfDefault.crTextColor = ::GetSysColor( COLOR_3DSHADOW );
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
- }
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_GRAYTEXT );
- }
- COLORREF clrBack = OnQueryBackColor();
- if( clrBack == COLORREF(-1L) )
- {
- clrBack = bEnabled ? ( bReadOnly ? m_clrRichBackReadOnly : m_clrRichBackNormal ) : m_clrRichBackDisabled;
- if( clrBack == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- clrBack = ::GetSysColor( COLOR_3DFACE );
- else
- clrBack = ::GetSysColor( COLOR_WINDOW );
- }
- else
- clrBack = ::GetSysColor( COLOR_3DFACE );
- }
- }
- Rich_SetBackgroundColor( FALSE, clrBack );
- Rich_HideSelection( true, false );
- CHARRANGE crRestore;
- Rich_GetSel( crRestore );
- Rich_SetSel( 0, -1 );
- SendMessage( EM_SETCHARFORMAT, SCF_DEFAULT, LPARAM(&cfDefault) );
- SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(&cfDefault) );
- Rich_SetSelectionColor( cfDefault.crTextColor );
- CharRuleArray & arrCharRules = GetSymbolArray();
- INT nWalkIndex;
- for( nWalkIndex = 0; nWalkIndex < nWalkLen; nWalkIndex ++ )
- {
- TCHAR tchrMask = strMask[ nWalkIndex ];
- INT nRuleNo = arrCharRules.FindPos( tchrMask );
- if( nRuleNo < 0 )
- continue;
- CharRule & theCharRule = arrCharRules.ElementAt( nRuleNo );
- if( theCharRule.m_clrSymbol == COLORREF(-1L) )
- continue;
- Rich_SetSel( nWalkIndex, ( nWalkIndex + 1 ) );
- Rich_SetSelectionColor( theCharRule.m_clrSymbol );
- }
- Rich_SetSel( crRestore );
- Rich_HideSelection( false, false );
- } // if( nWalkLen > 0 )
- m_bRichPainting = false;
- }
- CExtSafeString CExtEditMasked::TextGetValid() const
- {
- ASSERT_VALID( this );
- return Behavior_GetValidText();
- }
- #ifndef _UNICODE
- int CExtEditMasked::stat_IsCharDigit( UINT c ) { return _istdigit( (TCHAR)c ); } // similar to _istdigit()
- int CExtEditMasked::stat_IsCharAlpha( UINT c ) { return IsCharAlpha( (TCHAR)c ); } // similar to _istalpha()
- int CExtEditMasked::stat_IsCharAlphaOrDigit( UINT c ) { return IsCharAlphaNumeric( (TCHAR)c ); } // similar to _istalnum()
- #else
- int CExtEditMasked::stat_IsCharDigit( __EXT_MFC_SAFE_TCHAR c ) { return _istdigit( (TCHAR)c ); } // similar to _istdigit()
- int CExtEditMasked::stat_IsCharAlpha( __EXT_MFC_SAFE_TCHAR c ) { return IsCharAlpha( (TCHAR)c ); } // similar to _istalpha()
- int CExtEditMasked::stat_IsCharAlphaOrDigit( __EXT_MFC_SAFE_TCHAR c ) { return IsCharAlphaNumeric( (TCHAR)c ); } // similar to _istalnum()
- #endif
- void CExtEditMasked::OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- Behavior_OnChar( uChar, nRepCnt, nFlags );
- // _Rich_OnDraw();
- }
- void CExtEditMasked::OnKeyDown( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- }
- void CExtEditMasked::OnKillFocus( CWnd * pNewWnd )
- {
- ASSERT_VALID( this );
- Behavior_OnKillFocus( pNewWnd );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditSystemNumberCurrencyBase window
- IMPLEMENT_DYNAMIC( CExtEditSystemNumberCurrencyBase, CExtEditWithBehavior );
- CExtEditSystemNumberCurrencyBase::CExtEditSystemNumberCurrencyBase(
- INT nMaxWholeDigits, // = __EXT_MFC_DEFAULT_MAX_WHOLE_DIGITS
- INT nMaxFractionDigits // = __EXT_MFC_DEFAULT_FRACTION_WHOLE_DIGITS
- )
- : m_nMaxWholeDigits( nMaxWholeDigits >= 0 ? nMaxWholeDigits : (-nMaxWholeDigits) )
- , m_nMaxFractionDigits( nMaxFractionDigits )
- , m_nNegSignMatch( 0 )
- , m_strNegativeSign( _T("-") )
- , m_strDecimalPoint( _T('.') )
- , m_strGroupSeparator( _T(',') )
- , m_nNegativeFormatIndex( 0 )
- , m_nPositiveFormatIndex( 0 )
- , m_lfMin( __EXT_MFC_SYSTEM_NUMBER_MIN )
- , m_lfMax( __EXT_MFC_SYSTEM_NUMBER_MAX )
- , m_bAdjustingSeparators( false )
- , m_bBackspace( false )
- , m_nStartSel( -1 )
- , m_nEndSel( -1 )
- , m_clrNumber( COLORREF(-1L) )
- , m_clrFraction( COLORREF(-1L) )
- , m_clrGroupSeparator( COLORREF(-1L) )
- , m_clrDecimalSeparator( COLORREF(-1L) )
- , m_clrSign( COLORREF(-1L) )
- , m_clrBrackets( COLORREF(-1L) )
- , m_strCurrencySymbol( _T("$") )
- {
- ASSERT( m_nMaxWholeDigits > 0 ); // must have at least 1 digit to the left of the decimal
- ASSERT( m_nMaxFractionDigits >= 0 ); // decimal places must be positive
- m_pEditWithBehaviorWnd = this;
- if( nMaxWholeDigits < 0 )
- CBehaviorBase::m_nBehaviorFlags |= __ESE_DISABLE_NEGATIVE;
- }
- CExtEditSystemNumberCurrencyBase::~CExtEditSystemNumberCurrencyBase()
- {
- }
- BEGIN_MESSAGE_MAP( CExtEditSystemNumberCurrencyBase, CExtEditWithBehavior )
- //{{AFX_MSG_MAP(CExtEditWithBehavior)
- ON_WM_CHAR()
- ON_WM_KEYDOWN()
- ON_WM_KILLFOCUS()
- ON_MESSAGE( WM_PASTE, OnPaste )
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void CExtEditSystemNumberCurrencyBase::CurrencySet( const CURRENCY & _cy )
- {
- ASSERT_VALID( this );
- long double lfVal = ((long double)_cy.int64) / ((long double)10000.0);
- LongDoubleSet( lfVal );
- }
- COleCurrency CExtEditSystemNumberCurrencyBase::CurrencyGet() const
- {
- ASSERT_VALID( this );
- long double lfVal = LongDoubleGet() * ((long double)10000.0);
- COleCurrency _oleCurrency;
- _oleCurrency.m_cur.int64 = (LONGLONG)lfVal;
- return _oleCurrency;
- }
- void CExtEditSystemNumberCurrencyBase::LongDoubleSet( long double lfValue, bool bTrimTrailingZeros /*= true*/ )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- m_pEditWithBehaviorWnd->SetWindowText( _GetDoubleText( lfValue, bTrimTrailingZeros ) );
- }
- void CExtEditSystemNumberCurrencyBase::MaxWholeDigitsSet( INT nMaxWholeDigits )
- {
- ASSERT_VALID( this );
- ASSERT( nMaxWholeDigits );
- bool bAllowNegative = (nMaxWholeDigits >= 0);
- if( nMaxWholeDigits < 0 )
- nMaxWholeDigits = -nMaxWholeDigits;
- if( m_nMaxWholeDigits == nMaxWholeDigits && AllowNegativeGet() == bAllowNegative )
- return;
- m_nMaxWholeDigits = nMaxWholeDigits;
- if( ! _FlagsModify( bAllowNegative ? 0 : __ESE_DISABLE_NEGATIVE, bAllowNegative ? __ESE_DISABLE_NEGATIVE : 0 ) )
- _Redraw();
- }
- INT CExtEditSystemNumberCurrencyBase::MaxWholeDigitsGet() const
- {
- ASSERT_VALID( this );
- return m_nMaxWholeDigits;
- }
- void CExtEditSystemNumberCurrencyBase::MaxFractionDigitsSet( INT nMaxFractionDigits )
- {
- ASSERT_VALID( this );
- ASSERT( nMaxFractionDigits >= 0 );
- if( m_nMaxFractionDigits == nMaxFractionDigits )
- return;
- m_nMaxFractionDigits = nMaxFractionDigits;
- _Redraw();
- }
- INT CExtEditSystemNumberCurrencyBase::MaxFractionDigitsGet() const
- {
- ASSERT_VALID( this );
- return m_nMaxFractionDigits;
- }
- void CExtEditSystemNumberCurrencyBase::AllowNegativeSet( bool bAllowNegative /*= true*/ )
- {
- ASSERT_VALID( this );
- _FlagsModify( bAllowNegative ? 0 : __ESE_DISABLE_NEGATIVE, bAllowNegative ? __ESE_DISABLE_NEGATIVE : 0 );
- }
- bool CExtEditSystemNumberCurrencyBase::AllowNegativeGet() const
- {
- ASSERT_VALID( this );
- bool bAllowNegative = ( ( CBehaviorBase::m_nBehaviorFlags & __ESE_DISABLE_NEGATIVE ) != 0 ) ? false : true;
- return bAllowNegative;
- }
- void CExtEditSystemNumberCurrencyBase::RangeSet( long double lfMin, long double lfMax )
- {
- ASSERT_VALID( this );
- ASSERT( lfMin <= lfMax );
- m_lfMin = lfMin;
- m_lfMax = lfMax;
- _AdjustWithinRange();
- _Redraw();
- }
- void CExtEditSystemNumberCurrencyBase::RangeGet( long double * p_lfMin, long double * p_lfMax ) const
- {
- ASSERT_VALID( this );
- if( p_lfMin != NULL )
- (*p_lfMin) = m_lfMin;
- if( p_lfMax != NULL )
- (*p_lfMax) = m_lfMax;
- }
- void CExtEditSystemNumberCurrencyBase::NumberColorSet( COLORREF clrNumber /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrNumber == clrNumber )
- return;
- m_clrNumber = clrNumber;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::NumberColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrNumber;
- }
- void CExtEditSystemNumberCurrencyBase::FractionColorSet( COLORREF clrFraction /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrFraction == clrFraction )
- return;
- m_clrFraction = clrFraction;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::FractionColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrFraction;
- }
- void CExtEditSystemNumberCurrencyBase::GroupSeparatorColorSet( COLORREF clrGroupSeparator /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrGroupSeparator == clrGroupSeparator )
- return;
- m_clrGroupSeparator = clrGroupSeparator;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::GroupSeparatorColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrGroupSeparator;
- }
- void CExtEditSystemNumberCurrencyBase::DecimalSeparatorColorSet( COLORREF clrDecimalSeparator /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrDecimalSeparator == clrDecimalSeparator )
- return;
- m_clrDecimalSeparator = clrDecimalSeparator;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::DecimalSeparatorColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrDecimalSeparator;
- }
- void CExtEditSystemNumberCurrencyBase::SignColorSet( COLORREF clrSign /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrSign == clrSign )
- return;
- m_clrSign = clrSign;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::SignColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrSign;
- }
- void CExtEditSystemNumberCurrencyBase::BracketsColorSet( COLORREF clrBrackets /* = COLORREF(-1L) */ )
- {
- ASSERT_VALID( this );
- if( m_clrBrackets == clrBrackets )
- return;
- m_clrBrackets = clrBrackets;
- _Rich_OnDraw();
- }
- COLORREF CExtEditSystemNumberCurrencyBase::BracketsColorGet() const
- {
- ASSERT_VALID( this );
- return m_clrBrackets;
- }
- bool CExtEditSystemNumberCurrencyBase::_IsValid() const
- {
- ASSERT_VALID( this );
- long double lfValue = LongDoubleGet();
- bool bRetVal = ( m_lfMin <= lfValue && lfValue <= m_lfMax ) ? true : false;
- return bRetVal;
- }
- INT CExtEditSystemNumberCurrencyBase::_GetGroupSeparatorCount( const CExtSafeString & strText ) const
- {
- ASSERT_VALID( this );
- INT nPos = 0, nSepCount = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- nSepCount ++;
- nPos ++;
- }
- return nSepCount;
- }
- void CExtEditSystemNumberCurrencyBase::_AdjustSeparators(
- INT nCurrentSeparatorCount,
- bool bDecimalPoint // = false
- )
- {
- ASSERT_VALID( this );
- nCurrentSeparatorCount;
- bDecimalPoint;
- m_bAdjustingSeparators = true;
- CExtSafeString strText = Behavior_GetValidText( true );
- m_bAdjustingSeparators = false;
- }
- void CExtEditSystemNumberCurrencyBase::stat_InsertZeros( CExtSafeString * pStrText, INT nPos, INT nCount )
- {
- ASSERT( pStrText != NULL );
- if( nPos < 0 && nCount > 0 )
- nPos = INT( pStrText->GetLength() );
- for( INT iZero = 0; iZero < nCount; iZero++ )
- pStrText->Insert( nPos, _T('0') );
- }
- CExtSafeString CExtEditSystemNumberCurrencyBase::TextGetValid() const
- {
- ASSERT_VALID( this );
- return Behavior_GetValidText();
- }
- void CExtEditSystemNumberCurrencyBase::OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- Behavior_OnChar( uChar, nRepCnt, nFlags );
- // _Rich_OnDraw();
- }
- void CExtEditSystemNumberCurrencyBase::OnKeyDown( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- }
- void CExtEditSystemNumberCurrencyBase::OnKillFocus( CWnd * pNewWnd )
- {
- ASSERT_VALID( this );
- Behavior_OnKillFocus( pNewWnd );
- }
- LRESULT CExtEditSystemNumberCurrencyBase::OnPaste( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- if( ( GetStyle() & ES_READONLY ) != 0 )
- return 0;
- LRESULT lResult = Behavior_OnPaste( wParam, lParam );
- return lResult;
- }
- void CExtEditSystemNumberCurrencyBase::_CheckFlags()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- // test whether value is empty
- CExtSafeString strOriginalText = _GetNumericText( m_pEditWithBehaviorWnd->TextGet() );
- CExtSafeString strText = strOriginalText;
- INT nLen = INT( strText.GetLength() );
- // optionally remove any extra leading zeros but always leave one in front of the decimal point
- if( ( CBehaviorBase::m_nBehaviorFlags & __ESE_KF_REMOVE_EXTRA_LEADING_ZEROS ) != 0 && nLen > 0 )
- {
- bool bIsNegative = _IsNegative( strText );
- INT _nStart = 0, _nEnd = 0;
- _GetTextWithoutMarks( strText, _nStart, _nEnd );
- strText.TrimLeft( _T('0') );
- INT nDecimalSignPos = (INT)strText.Find( m_strDecimalPoint );
- if( strText.IsEmpty() || nDecimalSignPos == 0 )
- strText.Insert( 0, _T('0') );
- _GetTextWithMarks( strText, _nStart, _nEnd, bIsNegative );
- }
- else if( nLen == 0 && ( CBehaviorBase::m_nBehaviorFlags & __ESE_KF_DONT_PAD_WITH_ZEROS_IF_EMPTY ) != 0 )
- return;
- // test whether we need to pad the number with zeros after decimal point
- if( ( CBehaviorBase::m_nBehaviorFlags & __ESE_KF_PAD_WITH_ZEROS_AFTER_DECIMAL ) != 0 && m_nMaxFractionDigits > 0 )
- {
- bool bIsNegative = _IsNegative( strText );
- INT _nStart = 0, _nEnd = 0;
- _GetTextWithoutMarks( strText, _nStart, _nEnd );
- INT nDecimalSignPos = (INT)strText.Find( m_strDecimalPoint );
- INT nLen = INT( strText.GetLength() );
- if( nDecimalSignPos < 0 )
- {
- if( nLen == 0 )
- {
- strText = _T('0');
- nLen = (INT)strText.GetLength();
- }
- strText += m_strDecimalPoint;
- nDecimalSignPos = (INT)strText.Find( m_strDecimalPoint );
- }
- INT _nRightPartLen = (INT)strText.Mid( nDecimalSignPos + (INT)m_strDecimalPoint.GetLength() ).GetLength();
- if( _nRightPartLen > m_nMaxFractionDigits )
- strText.Delete( nDecimalSignPos + m_nMaxFractionDigits + m_strDecimalPoint.GetLength() );
- stat_InsertZeros( &strText, -1, m_nMaxFractionDigits - _nRightPartLen );
- _GetTextWithoutMarks( strText, _nStart, _nEnd );
- _GetTextWithMarks( strText, _nStart, _nEnd, bIsNegative );
- }
- // test whether we need to pad the number with zeros before the decimal point
- if( ( CBehaviorBase::m_nBehaviorFlags & __ESE_KF_PAD_WITH_ZEROS_BEFORE_DECIMAL ) != 0 && m_nMaxWholeDigits > 0 )
- {
- bool bIsNegative = _IsNegative( strText );
- INT _nStart = 0, _nEnd = 0;
- _GetTextWithoutMarks( strText, _nStart, _nEnd );
- INT nDecimalSignPos = (INT)strText.Find( m_strDecimalPoint );
- INT nLen = INT( strText.GetLength() );
- INT nZeroCount = 0, nZeroPos = -1;
- if( nDecimalSignPos < 0 )
- {
- nZeroCount = m_nMaxWholeDigits - nLen;
- nZeroPos = nLen;
- }
- else
- {
- nZeroCount = m_nMaxWholeDigits - nDecimalSignPos;
- nZeroPos = nDecimalSignPos;
- }
- stat_InsertZeros( &strText, nZeroPos, nZeroCount );
- _GetTextWithoutMarks( strText, _nStart, _nEnd );
- _GetTextWithMarks( strText, _nStart, _nEnd, bIsNegative );
- }
- if( strText != strOriginalText )
- m_pEditWithBehaviorWnd->SetWindowText( strText );
- }
- void CExtEditSystemNumberCurrencyBase::Behavior_OnKeyDown( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- switch( uChar )
- {
- case VK_DELETE:
- {
- if( ( GetStyle() & ES_READONLY ) != 0 )
- return;
- INT nStart = 0, nEnd = 0;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- if( _DeleteSymbols( strText, nStart, nEnd ) )
- {
- m_pEditWithBehaviorWnd->SetWindowText( strText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- else
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- // _Rich_OnDraw();
- return;
- }
- case VK_BACK:
- {
- if( ( GetStyle() & ES_READONLY ) != 0 )
- return;
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- if( strText.IsEmpty() )
- return;
- INT nStart = 0, nEnd = 0;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- if( _DeleteSymbols( strText, nStart, nEnd, true ) )
- m_pEditWithBehaviorWnd->SetWindowText( strText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- // _Rich_OnDraw();
- return;
- }
- }
- //CExtEditWithBehavior::CBehaviorBase::Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- CBehaviorBase::Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- }
- void CExtEditSystemNumberCurrencyBase::Behavior_OnKillFocus( CWnd * pNewWnd )
- {
- ASSERT_VALID( this );
- //CExtEditWithBehavior::CBehaviorBase::Behavior_OnKillFocus( pNewWnd );
- CBehaviorBase::Behavior_OnKillFocus( pNewWnd );
- _CheckFlags();
- }
- LRESULT CExtEditSystemNumberCurrencyBase::Behavior_OnPaste( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- if( ( GetStyle() & ES_READONLY ) != 0 )
- return 0;
- INT nStart = 0, nEnd = 0;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- // paste from clipboard
- if( OpenClipboard() )
- {
- CExtSafeString strClipboardText;
- bool bHaveClipboardText = false;
- if( g_PaintManager.m_bIsWinNT4orLater && ::IsClipboardFormatAvailable( CF_UNICODETEXT ) )
- {
- HGLOBAL h = ::GetClipboardData( CF_UNICODETEXT );
- if( h != NULL )
- {
- LPWSTR strUnicodeBuffer = (LPWSTR) ::GlobalLock( h );
- if( strUnicodeBuffer != NULL )
- {
- bHaveClipboardText = true;
- USES_CONVERSION;
- LPCTSTR strBuffer = W2CT(strUnicodeBuffer);
- strClipboardText = strBuffer;
- ::GlobalUnlock( h );
- }
- }
- } // if( g_PaintManager.m_bIsWinNT4orLater && ::IsClipboardFormatAvailable( CF_UNICODETEXT ) )
- if( ( ! bHaveClipboardText ) && ::IsClipboardFormatAvailable( CF_TEXT ) )
- {
- HGLOBAL h = ::GetClipboardData( CF_TEXT );
- if( h != NULL )
- {
- LPSTR strBuffer = (LPSTR) ::GlobalLock( h );
- if( strBuffer != NULL )
- {
- bHaveClipboardText = true;
- strClipboardText = LPCTSTR(strBuffer);
- ::GlobalUnlock( h );
- } // if( strBuffer != NULL )
- }
- } // if( ( ! bHaveClipboardText ) && ::IsClipboardFormatAvailable( CF_TEXT ) )
- if( bHaveClipboardText )
- {
- bool bNegative = _IsNegative( strText );
- _GetTextWithoutMarks( strText, nStart, nEnd );
- INT _nStart = 0, _nEnd = 0;
- INT nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nDecimalPointLen = INT( m_strDecimalPoint.GetLength() );
- if( nDecimalPointPos != -1 )
- _GetTextWithoutMarks( strClipboardText, _nStart, _nEnd, true );
- else
- _GetTextWithoutMarks( strClipboardText, _nStart, _nEnd );
- if( strText.IsEmpty() )
- _GetTextWithoutMarks( strClipboardText, _nStart, _nEnd, true );
- INT nClipboardTextLen = INT( strClipboardText.GetLength() );
- if( ( nEnd - nStart ) > 0 )
- strText.Delete( nStart, ( nEnd - nStart ) );
- nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- bool bStartInFrontOfDecimalPoint = ( nStart <= nDecimalPointPos );
- strText.Insert( nStart, strClipboardText );
- nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- if( nDecimalPointPos > m_nMaxWholeDigits )
- {
- strText.Delete( nDecimalPointPos, nDecimalPointLen );
- strText.Insert( m_nMaxWholeDigits, m_strDecimalPoint );
- nDecimalPointPos = m_nMaxWholeDigits;
- }
- if( nDecimalPointPos != -1 )
- nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nMaxLen = m_nMaxWholeDigits + m_nMaxFractionDigits + ( ( nDecimalPointPos != -1 ) ? nDecimalPointLen : 0 );
- nEnd = nStart + nClipboardTextLen;
- if( bStartInFrontOfDecimalPoint
- && nEnd > nDecimalPointPos
- )
- nEnd += nDecimalPointLen;
- if( nMaxLen < strText.GetLength() )
- {
- strText.Delete( nMaxLen, ( strText.GetLength() - nMaxLen ) );
- if( nDecimalPointPos != -1 )
- {
- nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- // check if DecimalPoint deleted
- if( nDecimalPointPos == -1 )
- {
- nMaxLen -= nDecimalPointLen;
- strText.Delete( nMaxLen, nDecimalPointLen );
- }
- }
- if( nDecimalPointPos != -1 && nDecimalPointPos > m_nMaxWholeDigits )
- {
- strText.Delete( nDecimalPointPos, nDecimalPointLen );
- strText.Insert( m_nMaxWholeDigits, m_strDecimalPoint );
- if( nEnd >= m_nMaxWholeDigits )
- nEnd += nDecimalPointLen;
- }
- }
- _GetTextWithMarks( strText, nStart, nEnd, bNegative );
- m_pEditWithBehaviorWnd->TextSet( strText );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- } // if( bHaveClipboardText )
- ::CloseClipboard();
- } // if( OpenClipboard() )
- // _Rich_OnDraw();
- return 0;
- }
- BOOL CExtEditSystemNumberCurrencyBase::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
- {
- ASSERT_VALID( this );
- if( message == WM_COMMAND )
- {
- INT nCode = HIWORD(wParam);
- switch( nCode )
- {
- case EN_CHANGE:
- _AdjustWithinRange();
- break;
- }
- }
- return CExtEditWithBehavior::OnChildNotify(message, wParam, lParam, pLResult);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditSystemNumber window
- IMPLEMENT_DYNCREATE( CExtEditSystemNumber, CExtEditSystemNumberCurrencyBase );
- CExtEditSystemNumber::CExtEditSystemNumber(
- INT nMaxWholeDigits, // = __EXT_MFC_DEFAULT_MAX_WHOLE_DIGITS,
- INT nMaxFractionDigits // = __EXT_MFC_DEFAULT_FRACTION_WHOLE_DIGITS
- )
- : CExtEditSystemNumberCurrencyBase( nMaxWholeDigits, nMaxFractionDigits )
- {
- _Init();
- }
- CExtEditSystemNumber::~CExtEditSystemNumber()
- {
- }
- BEGIN_MESSAGE_MAP( CExtEditSystemNumber, CExtEditSystemNumberCurrencyBase )
- //{{AFX_MSG_MAP(CExtEditSystemNumberCurrencyBase)
- //}}AFX_MSG_MAP
- __EXT_MFC_SAFE_ON_WM_SETTINGCHANGE()
- END_MESSAGE_MAP()
- void CExtEditSystemNumber::_Init()
- {
- ASSERT_VALID( this );
- // negative sign
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, m_strNegativeSign.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strNegativeSign.ReleaseBuffer();
- }
- // decimal point
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SDECIMAL, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_SDECIMAL, m_strDecimalPoint.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strDecimalPoint.ReleaseBuffer();
- // group separator
- if( g_ResourceManager->GetLocaleInfo( LOCALE_STHOUSAND, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_STHOUSAND, m_strGroupSeparator.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strGroupSeparator.ReleaseBuffer();
- TCHAR cNegNumFormatIndex = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_INEGNUMBER, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_INEGNUMBER, &cNegNumFormatIndex, sizeof( cNegNumFormatIndex ) / sizeof(TCHAR) );
- m_nNegativeFormatIndex = _ttoi( & cNegNumFormatIndex );
- CExtSafeString strDigitGrouping = _T("0");
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, strDigitGrouping.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- strDigitGrouping.ReleaseBuffer();
- INT nStrLen = INT( strDigitGrouping.GetLength() );
- CExtSafeString _strGroup = _T("");
- INT nGroup = 0;
- if( m_listDigitGrouping.GetCount() > 0 )
- m_listDigitGrouping.RemoveAll();
- for( INT i = 0; i < nStrLen; i++ )
- {
- TCHAR ch = strDigitGrouping[i];
- if( ch == _T(';') )
- {
- nGroup = _ttoi( _strGroup );
- m_listDigitGrouping.AddTail( nGroup );
- _strGroup = _T("");
- nGroup = 0;
- }
- else
- _strGroup = _strGroup + ch;
- }
- nGroup = _ttoi( _strGroup );
- m_listDigitGrouping.AddTail( nGroup );
- }
- TCHAR cNoOfDigitsAfterDecimal = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_IDIGITS, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_IDIGITS, &cNoOfDigitsAfterDecimal, sizeof( cNoOfDigitsAfterDecimal ) / sizeof(TCHAR) );
- m_nMaxFractionDigits = _ttoi( & cNoOfDigitsAfterDecimal );
- TCHAR cDisplayLeadingZeros = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_ILZERO, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_ILZERO, &cDisplayLeadingZeros, sizeof( cDisplayLeadingZeros ) / sizeof(TCHAR) );
- m_nDisplayLeadingZeros = _ttoi( & cDisplayLeadingZeros );
- TCHAR cDigitGrouping[20] = _T("");
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, cDigitGrouping, sizeof( cDigitGrouping ) / sizeof( cDigitGrouping[0] ) );
- // ensure the separators are not the same
- if( m_strDecimalPoint == m_strGroupSeparator
- && ( m_strDecimalPoint == _T(".")
- || m_strDecimalPoint == _T(",")
- )
- )
- m_strGroupSeparator = ( m_strDecimalPoint == _T(",") ? _T(".") : _T(",") );
- if( m_strDecimalPoint == m_strGroupSeparator
- && ( m_strDecimalPoint != _T(".")
- && m_strDecimalPoint != _T(",")
- )
- )
- m_strDecimalPoint == _T(".");
- }
- void CExtEditSystemNumber::OnSettingChange(UINT uFlags, __EXT_MFC_SAFE_LPCTSTR lpszSection)
- {
- ASSERT_VALID( this );
- CExtEditSystemNumberCurrencyBase::OnSettingChange( uFlags, lpszSection );
- if( _tcscmp( lpszSection, _T("intl") ) == 0 )
- {
- long double lfSaved = LongDoubleGet();
- _Init();
- LongDoubleSet( lfSaved );
- SetSel( -1, -1 );
- }
- }
- CExtSafeString CExtEditSystemNumber::_GetNumericText(
- const CExtSafeString & strText,
- bool bUseMathSymbols // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strNewText;
- bool bIsNegative = _IsNegative(strText); // false;
- bool bHasDecimalPoint = false;
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSignPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nPos, nLen;
- for( nPos = 0, nLen = INT( strText.GetLength() ); nPos < nLen; nPos++ )
- {
- TCHAR c = strText[nPos];
- if( _istdigit(c) )
- strNewText += c;
- else if( nPos == nDecimalSignPos && !bHasDecimalPoint )
- {
- bHasDecimalPoint = true;
- strNewText += ( bUseMathSymbols ? _T(".") : m_strDecimalPoint );
- nPos += nDecimalSignLen - 1;
- }
- }
- // add negative sign to the front of the number
- if( bIsNegative )
- {
- CExtSafeString strNegativeSign;
- if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 3 )
- strNegativeSign = m_strNegativeSign;
- if( m_nNegativeFormatIndex == 2 )
- strNegativeSign = m_strNegativeSign + _T(" ");
- if( m_nNegativeFormatIndex == 4 )
- strNegativeSign = _T(" ") + m_strNegativeSign;
- if( bUseMathSymbols )
- {
- strNewText.Insert( 0, _T('-') );
- }
- else
- {
- INT nIndex = ( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 ) ? 0 : strNewText.GetLength();
- if( m_nNegativeFormatIndex != 0 )
- strNewText.Insert( nIndex, bUseMathSymbols ? _T("-") : strNegativeSign );
- else
- {
- strNewText.Insert( strNewText.GetLength(), _T(')') );
- strNewText.Insert( 0, _T('(') );
- }
- }
- }
- return strNewText;
- }
- CExtSafeString CExtEditSystemNumber::_GetDoubleText( long double lfValue, bool bTrimTrailingZeros /*= true*/ ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strText;
- strText.Format( _T("%lf"), lfValue );
- if( m_strDecimalPoint != _T(".") )
- strText.Replace( _T("."), m_strDecimalPoint );
- if( bTrimTrailingZeros )
- {
- strText.TrimRight( _T('0') );
- strText.TrimRight( m_strDecimalPoint );
- }
- bool bNegative = ( strText.Find( _T("-") ) == 0 ) ? true : false;
- if( bNegative )
- {
- strText.Delete( 0 );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- _strBefore = _T("(");
- _strAfter = _T(")");
- break;
- case 1:
- _strBefore = m_strNegativeSign;
- break;
- case 2:
- _strBefore = m_strNegativeSign + _T(" ");
- break;
- case 3:
- _strAfter = m_strNegativeSign;
- break;
- case 4:
- _strAfter = _T(" ") + m_strNegativeSign;
- break;
- }
- INT nLen = INT( strText.GetLength() );
- if( ! _strAfter.IsEmpty() )
- strText.Insert( nLen, _strAfter );
- if( ! _strBefore.IsEmpty() )
- strText.Insert( 0, _strBefore );
- }
- return strText;
- }
- void CExtEditSystemNumber::IntSet( INT nVal )
- {
- ASSERT_VALID( this );
- CExtSafeString strText;
- strText.Format( _T("%d"), nVal );
- bool bNegative = ( strText.Find( _T("-") ) == 0 ) ? true : false;
- if( bNegative )
- {
- strText.Delete( 0 );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- _strBefore = _T("(");
- _strAfter = _T(")");
- break;
- case 1:
- _strBefore = m_strNegativeSign;
- break;
- case 2:
- _strBefore = m_strNegativeSign + _T(" ");
- break;
- case 3:
- _strAfter = m_strNegativeSign;
- break;
- case 4:
- _strAfter = _T(" ") + m_strNegativeSign;
- break;
- }
- INT nLen = INT( strText.GetLength() );
- if( ! _strAfter.IsEmpty() )
- strText.Insert( nLen, _strAfter );
- if( ! _strBefore.IsEmpty() )
- strText.Insert( 0, _strBefore );
- }
- m_pEditWithBehaviorWnd->SetWindowText(strText);
- }
- long double CExtEditSystemNumber::LongDoubleGet() const
- {
- ASSERT_VALID( this );
- // return _tcstod( _GetNumericText( m_pEditWithBehaviorWnd->TextGet(), true ), NULL );
- CExtSafeString str = _GetNumericText( m_pEditWithBehaviorWnd->TextGet() ); //, true
- if( str.IsEmpty()
- || str == _T(".")
- || str == LPCTSTR(m_strDecimalPoint)
- || ( str.GetLength() == 1 && m_strDecimalPoint.GetLength() > 0 && str[0] == m_strDecimalPoint[0] )
- )
- return 0.0;
- LCID _LCID = LANG_USER_DEFAULT;
- if( g_ResourceManager->IsCustomLangAllowed() )
- _LCID = g_ResourceManager->GetLangIdDesired();
- DOUBLE lfTmp = 0.0;
- USES_CONVERSION;
- HRESULT hr = ::VarR8FromStr( (LPOLESTR) T2COLE( LPCTSTR(str) ), _LCID, 0, &lfTmp );
- ASSERT( SUCCEEDED( hr ) );
- hr;
- long double lfVal = (long double)lfTmp;
- return lfVal;
- }
- INT CExtEditSystemNumber::IntGet() const
- {
- ASSERT_VALID( this );
- // return (INT)_ttoi( _GetNumericText( m_pEditWithBehaviorWnd->TextGet(), true ) );
- CExtSafeString str = _GetNumericText( m_pEditWithBehaviorWnd->TextGet() ); //, true
- if( str.IsEmpty() )
- return 0;
- LCID _LCID = LANG_USER_DEFAULT;
- if( g_ResourceManager->IsCustomLangAllowed() )
- _LCID = g_ResourceManager->GetLangIdDesired();
- LONG nTmp = 0L;
- USES_CONVERSION;
- HRESULT hr = ::VarI4FromStr( (LPOLESTR) T2COLE( LPCTSTR(str) ), _LCID, 0, &nTmp );
- ASSERT( SUCCEEDED( hr ) );
- hr;
- return INT(nTmp);
- }
- CExtSafeString CExtEditSystemNumber::Behavior_GetValidText(
- bool bSetSel // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString strNewText = strText;
- bool bIsNegative = _IsNegative( strText );
- INT nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- _GetTextWithoutMarks( strNewText, nStart, nEnd );
- _GetTextWithMarks( strNewText, nStart, nEnd );
- // insert the negative sign if it is not present
- if( bIsNegative && AllowNegativeGet() )
- {
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() ) + ( ( m_nNegativeFormatIndex == 2 || m_nNegativeFormatIndex == 4 ) ? 1: 0 );
- if( m_nNegativeFormatIndex == 0 )
- nNegSignLen = 1;
- CExtSafeString _strNegativeSign = ( (m_nNegativeFormatIndex == 4) ? _T(" "): _T("") ) + m_strNegativeSign + ( (m_nNegativeFormatIndex == 2) ? _T(" "): _T("") );
- if( m_nNegativeFormatIndex == 0 )
- {
- strNewText.Insert( strNewText.GetLength(), _T(")") );
- strNewText.Insert( 0, _T("(") );
- nStart += 1;
- nEnd += 1;
- }
- if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 )
- strNewText.Insert( 0, _strNegativeSign );
- if( m_nNegativeFormatIndex == 3 || m_nNegativeFormatIndex == 4 )
- strNewText.Insert( strNewText.GetLength(), _strNegativeSign );
- if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 )
- {
- nStart += nNegSignLen;
- nEnd += nNegSignLen;
- }
- }
- if( bSetSel && ( ! m_bRichPainting ) )
- {
- CExtSafeString strCurrentText = m_pEditWithBehaviorWnd->TextGet();
- if( strNewText != strCurrentText )
- m_pEditWithBehaviorWnd->SetWindowText( strNewText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- return strNewText;
- }
- void CExtEditSystemNumber::Behavior_OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- if( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY )
- return;
- TCHAR c = static_cast<TCHAR>( uChar );
- INT nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString strNumericText = _GetNumericText( strText );
- INT nDecimalPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nNumericDecimalPos = INT( strNumericText.Find( m_strDecimalPoint ) );
- INT nLen = INT( strText.GetLength() );
- INT nNumericLen = INT( strNumericText.GetLength() );
- INT nSepCount = _GetGroupSeparatorCount( strText );
- bool bNeedAdjustment = false;
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() );
- bool bIsNegative = false;
- bool bIsDecimalPoint = false;
- if( ( c == m_strNegativeSign[0/*nNegSignMatch*/] )
- || ( m_nNegativeFormatIndex == 0
- && c == _T('(')
- )
- || ( c == _T('-') )
- )
- bIsNegative = true;
- // check if it's a negative sign
- if( bIsNegative && AllowNegativeGet() )
- {
- bool bNegative = _IsNegative( strText );
- CExtSafeString _strBefore = _T(""), _strAfter = _T("");
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- _strBefore = _T("(");
- _strAfter = _T(")");
- break;
- case 1:
- _strBefore = m_strNegativeSign;
- break;
- case 2:
- _strBefore = m_strNegativeSign + _T(" ");
- break;
- case 3:
- _strAfter = m_strNegativeSign;
- break;
- case 4:
- _strAfter = _T(" ") + m_strNegativeSign;
- break;
- }
- INT nBeforLen = INT( _strBefore.GetLength() );
- INT nAfterLen = INT( _strAfter.GetLength() );
- CExtSafeString strNewText = strText;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- if( bNegative )
- {
- if( nStart < nBeforLen )
- nStart = nBeforLen;
- if( nEnd > ( nLen - nAfterLen ) )
- nEnd = ( nLen - nAfterLen );
- }
- _GetTextWithoutMarks( strNewText, nStart, nEnd );
- _GetTextWithMarks( strNewText, nStart, nEnd, ! bNegative );
- CExtSafeString strCurrentText = m_pEditWithBehaviorWnd->TextGet();
- if( strNewText != strCurrentText )
- m_pEditWithBehaviorWnd->SetWindowText( strNewText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- return;
- }
- // test whether it is decimal point (only one is enabled)
- else if( c == m_strDecimalPoint[0] && m_nMaxFractionDigits > 0 )
- {
- if( nDecimalPos >= 0 )
- {
- // test decimal point replacement
- if( nDecimalPos >= nStart && nDecimalPos < nEnd )
- {
- bNeedAdjustment = true;
- bIsDecimalPoint = true;
- }
- else
- { // else set caret
- m_pEditWithBehaviorWnd->SetSel( nDecimalPos + m_strDecimalPoint.GetLength(), nDecimalPos + m_strDecimalPoint.GetLength() );
- return;
- }
- }
- else
- {
- bNeedAdjustment = true;
- bIsDecimalPoint = true;
- }
- }
- else if( _istdigit(c) )
- {
- // test we're on the right of the decimal point.
- if( nDecimalPos >= 0 && nDecimalPos < nStart )
- {
- bool bIsNegative = ( ! strNumericText.IsEmpty() && ( strNumericText.Find( m_strNegativeSign ) >= 0 ) && ( m_nNegativeFormatIndex == 3 || m_nNegativeFormatIndex == 4 ) );
- if( ! bIsNegative )
- bIsNegative = ( ! strNumericText.IsEmpty() && ( strNumericText.Find( _T('(') ) >= 0 ) && m_nNegativeFormatIndex == 0 );
- INT nNegLength = 0;
- if( m_nNegativeFormatIndex != 0 )
- nNegLength = nNegSignLen + ( ( m_nNegativeFormatIndex == 4 ) ? 1 : 0 );
- else
- nNegLength = 1;
- if( bIsNegative )
- {
- INT nNegSignPos = -1;
- if( m_nNegativeFormatIndex == 3 )
- nNegSignPos = INT( strText.Find( m_strNegativeSign ) );
- if( m_nNegativeFormatIndex == 4 )
- nNegSignPos = INT( strText.Find( _T(' ') + m_strNegativeSign ) );
- if( m_nNegativeFormatIndex == 0 )
- nNegSignPos = INT( strText.Find( _T(')') ) );
- if( ( nStart > nNegSignPos ) && ( nStart <= nLen ) && nNegSignPos != -1 )
- {
- nStart = nNegSignPos;
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- }
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- if( nDecimalPos <= nStart && nStart < ( nDecimalPos + nDecimalSeparatorLen ) )
- {
- INT nPrevStart = nStart;
- nStart = ( nDecimalPos + nDecimalSeparatorLen );
- if( nEnd == nPrevStart
- || nEnd < nPrevStart
- || ( nEnd > nPrevStart
- && nEnd < nStart
- )
- )
- nEnd = nStart;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- if( strNumericText.Mid( /*nDecimalPos */ nNumericDecimalPos + nDecimalSeparatorLen ).GetLength() == ( m_nMaxFractionDigits + ( bIsNegative ? nNegLength : 0 ) ) )
- {
- if( nStart <= ( nDecimalPos + m_nMaxFractionDigits + nDecimalSeparatorLen - 1 ) )
- {
- nEnd = ( ( ( nEnd == nLen ) || ( nEnd > ( nStart + 1 ) ) ) ? nEnd : (nStart + 1) );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( CExtSafeString(c), TRUE );
- CExtSafeString strReplaceText = Behavior_GetValidText();
- }
- return;
- }
- else if( strNumericText.Mid( /*nDecimalPos */ nNumericDecimalPos + nDecimalSeparatorLen ).GetLength() > ( m_nMaxFractionDigits + ( bIsNegative ? nNegLength : 0 ) ) )
- {
- ASSERT(false);
- return;
- }
- }
- // we're on the left side of the decimal point
- else
- {
- bool bIsNegative = ( ! strNumericText.IsEmpty() && ( strNumericText.Find( m_strNegativeSign ) >= 0 ) && ( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 ) );
- if( ! bIsNegative )
- bIsNegative = ( ! strNumericText.IsEmpty() && ( strNumericText.Find( _T('(') ) >= 0 ) && m_nNegativeFormatIndex == 0 );
- bool bIsNegativeRight = ( ! strNumericText.IsEmpty() && ( strNumericText.Find( m_strNegativeSign ) >= 0 ) && ( m_nNegativeFormatIndex == 3 || m_nNegativeFormatIndex == 4 ) );
- INT nNegLength = 0;
- nNegLength
- = nNegSignLen
- + (
- ( m_nNegativeFormatIndex == 2
- || m_nNegativeFormatIndex == 4
- ) ? 1 : 0
- );
- if( m_nNegativeFormatIndex == 0 )
- nNegLength = 1;
- if( bIsNegative )
- {
- if( ( nStart >= 0 ) && ( nStart < nNegLength ) )
- {
- nStart = nNegLength;
- if( nStart > nEnd )
- nEnd = nStart;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- }
- if( bIsNegativeRight || ( bIsNegative && m_nNegativeFormatIndex == 0 ) )
- {
- if( ( nEnd >= ( nLen - nNegLength ) ) && ( nEnd <= nLen ) )
- {
- nEnd = nLen - nNegLength;
- if( nStart > nEnd )
- nStart = nEnd;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- if( ( nStart >= ( nLen - nNegLength ) ) && ( nStart <= nLen ) )
- {
- nStart = nLen - nNegLength;
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- }
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- // ensure we can still enter digits.
- INT nDecPos = m_nMaxWholeDigits + ( bIsNegative ? nNegLength : 0 ) + ( nSepCount * nGroupSeparatorLen );
- if( nStart == nDecPos )
- {
- UINT nFlags = CBehaviorBase::m_nBehaviorFlags;
- if( ( nFlags & __ESE_ADD_DECIMAL_AFTER_MAX_WHOLE_DIGITS ) != 0 && m_nMaxFractionDigits > 0 )
- {
- nEnd = ( ( ( nEnd == nLen ) || ( ( nEnd > nStart ) && ( ( nEnd - nStart ) > 1 ) ) ) ? nEnd : ( nStart + nDecimalSignLen + 1 ) );
- if( bIsNegativeRight || ( bIsNegative && m_nNegativeFormatIndex == 0 ) )
- {
- m_pEditWithBehaviorWnd->SetSel( nStart, strText.GetLength() );
- m_pEditWithBehaviorWnd->ReplaceSel( _T(""), TRUE );
- }
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( m_strDecimalPoint + c, TRUE );
- if( bIsNegativeRight || ( bIsNegative && m_nNegativeFormatIndex == 0 ) )
- {
- CExtSafeString strChangedText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString _strNegativeSign = ( m_nNegativeFormatIndex == 4 ? _T(" "): _T("") ) + m_strNegativeSign;
- nEnd = INT( strChangedText.GetLength() );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- if( m_nNegativeFormatIndex != 0 )
- m_pEditWithBehaviorWnd->ReplaceSel( _strNegativeSign, TRUE );
- else
- m_pEditWithBehaviorWnd->ReplaceSel( _T(")"), TRUE );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- }
- CExtSafeString strReplaceText = Behavior_GetValidText(true);
- }
- return;
- }
- if( strNumericText.Mid(
- 0,
- ( ( nNumericDecimalPos >= 0 )
- ? nNumericDecimalPos
- : nNumericLen
- )
- ).GetLength()
- == ( m_nMaxWholeDigits + ( bIsNegative ? nNegLength : 0 ) ) // + ( ( nNumericDecimalPos >= 0 ) ? ( m_strDecimalPoint.GetLength() ) : 0 )
- )
- {
- {
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos <= nStart && nStart < ( nPos + nGroupSeparatorLen ) )
- {
- nStart = nPos + nGroupSeparatorLen;
- break;
- }
- nPos ++;
- }
- INT _nNegativeSignLen = INT( m_strNegativeSign.GetLength() ) + ( (m_nNegativeFormatIndex == 2 || m_nNegativeFormatIndex == 4) ? 1: 0 );
- if( m_nNegativeFormatIndex == 0 )
- _nNegativeSignLen = 1;
- if( nStart < _nNegativeSignLen && bIsNegative )
- nStart = _nNegativeSignLen;
- nEnd = ( ( ( nEnd == nLen ) || ( nEnd > ( nStart + 1 ) ) ) ? nEnd : ( nStart + 1 ) );
- if( bIsNegativeRight )
- {
- INT nNegSignPos = INT( strText.Find( m_strNegativeSign ) );
- if( nEnd > nNegSignPos )
- nEnd = nNegSignPos;
- }
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( CExtSafeString(c), TRUE );
- CExtSafeString strReplaceText = Behavior_GetValidText(true);
- }
- return;
- }
- bNeedAdjustment = true;
- }
- }
- // test whether it is a non-printable character (i.e. backspace, ctrl+c )
- else if( ! ( _istprint( c ) || IsCharAlphaNumeric( c ) ) )
- bNeedAdjustment = true;
- else
- return;
- if( ! m_bBackspace )
- {
- //CExtEditSystemNumberCurrencyBase::CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- // if the decimal point was added/removed or a separator needs adding/removing, adjust the text
- if( bNeedAdjustment )
- _AdjustSeparators( nSepCount, bIsDecimalPoint );
- }
- else
- m_bBackspace = false;
- }
- bool CExtEditSystemNumber::_DeleteSymbols(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bBackspace // = false
- )
- {
- ASSERT_VALID( this );
- ASSERT( ! m_bRichPainting );
- INT nLen = INT( strText.GetLength() );
- bool bNegative = _IsNegative( strText );
- CExtSafeString strTextLen = strText;
- INT nStLen = 0, nEndLen = 0;
- _GetTextWithoutMarks( strTextLen, nStLen, nEndLen );
- INT nTextLen = INT( strTextLen.GetLength() );
- INT nDecSepPosLen = INT( strTextLen.Find( m_strDecimalPoint ) );
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSeparatorPos = INT( strText.Find( m_strDecimalPoint ) );
- INT _nPos = 0, _nGroupSignBeforeStart = 0, _nGroupSignCount = (INT)_GetGroupSeparatorCount( strText );
- for( ; true; )
- {
- _nPos = (INT)strText.Find( m_strGroupSeparator, _nPos );
- if( _nPos < 0 )
- break;
- if( _nPos < nStart )
- _nGroupSignBeforeStart ++;
- _nPos ++;
- }
- _nGroupSignBeforeStart = _nGroupSignCount - _nGroupSignBeforeStart;
- if( bBackspace )
- {
- if( nStart == 0 && nStart == nEnd )
- return false;
- INT nPos = 0;
- if( nStart >= 0 )
- {
- if( ( nDecimalSeparatorPos < nStart
- || ( nDecimalSeparatorPos == nStart
- && nStart != nEnd
- )
- )
- && nStart <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nDecSepPosLen == m_nMaxWholeDigits
- && ( nTextLen > ( nDecSepPosLen + nDecimalSeparatorLen )
- && nDecSepPosLen != -1
- )
- )
- {
- nStart = nDecimalSeparatorPos;
- nEnd = nDecimalSeparatorPos;
- m_bBackspace = true;
- return false;
- }
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( ( nPos < nStart
- || ( nPos == nStart
- && nStart != nEnd
- )
- )
- && nStart <= ( nPos + nGroupSeparatorLen )
- && nEnd <= ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos;
- nEnd = nPos;
- m_bBackspace = true;
- return false;
- }
- nPos ++;
- }
- }
- }
- else
- {
- if( nStart == nLen )
- return false;
- INT nPos = 0;
- if( nStart < nLen )
- {
- if( nDecimalSeparatorPos <= nStart
- && nStart < ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nDecSepPosLen == m_nMaxWholeDigits
- && ( nTextLen > ( nDecSepPosLen + nDecimalSeparatorLen )
- && nDecSepPosLen != -1
- )
- )
- {
- nStart = nDecimalSeparatorPos + nDecimalSeparatorLen;
- nEnd = nDecimalSeparatorPos + nDecimalSeparatorLen;
- return false;
- }
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos <= nStart
- && nStart < ( nPos + nGroupSeparatorLen )
- && nEnd <= ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos + nGroupSeparatorLen;
- nEnd = nPos + nGroupSeparatorLen;
- return false;
- }
- nPos ++;
- }
- }
- }
- if( nStart != nEnd )
- {
- if( nDecimalSeparatorPos < nStart
- && nStart < ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- )
- {
- nStart = nDecimalSeparatorPos + nDecimalSeparatorLen;
- if( nStart > nEnd )
- nEnd = nStart;
- }
- if( nDecimalSeparatorPos < nEnd
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- )
- nEnd = nDecimalSeparatorPos;
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos < nStart
- && nStart < ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos + nGroupSeparatorLen;
- if( nStart >= nEnd )
- {
- nEnd = nStart;
- break;
- }
- }
- if( nPos < nEnd
- && nEnd < ( nPos + nGroupSeparatorLen )
- )
- {
- nEnd = nPos;
- if( nEnd < nStart )
- nStart = nEnd;
- if( nEnd >= nStart )
- break;
- }
- nPos ++;
- }
- }
- {
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() ) + ( ( m_nNegativeFormatIndex == 2 || m_nNegativeFormatIndex == 4 ) ? 1 : 0 );
- if( m_nNegativeFormatIndex == 0 )
- nNegSignLen = 1;
- bool bNegDel = false;
- if( bNegative )
- {
- if( ( nStart < nNegSignLen || ( nStart == nNegSignLen && nStart == nEnd && bBackspace ) )
- && ( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 || m_nNegativeFormatIndex == 0 )
- )
- {
- bNegative = false;
- bNegDel = true;
- }
- if( ( ( nStart >= ( nLen - nNegSignLen )
- && ! bBackspace
- )
- || nEnd > ( nLen - nNegSignLen )
- || ( nStart > ( nLen - nNegSignLen )
- && bBackspace
- )
- || ( nStart == nLen
- && nStart == nEnd
- && bBackspace
- )
- )
- && ( m_nNegativeFormatIndex == 3
- || m_nNegativeFormatIndex == 4
- || m_nNegativeFormatIndex == 0
- )
- )
- {
- bNegative = false;
- bNegDel = true;
- }
- }
- _GetTextWithoutMarks( strText, nStart, nEnd );
- if( bBackspace )
- {
- bool bSelect = ( nStart != nEnd ) ? true : false;
- strText.Delete( ( nStart != nEnd ) ? nStart : ( nStart - 1 ), ( nStart != nEnd ) ? ( nEnd - nStart ) : ( bNegDel ? 0 : 1 ) );
- if( ! bSelect && ! bNegDel )
- nStart --;
- m_bBackspace = true;
- }
- else
- {
- INT _nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- if( _nDecimalPointPos != -1 )
- {
- if( nStart > _nDecimalPointPos
- && nStart < ( _nDecimalPointPos + nDecimalSeparatorLen )
- )
- nStart = _nDecimalPointPos;
- if( nEnd > _nDecimalPointPos
- && nEnd < ( _nDecimalPointPos + nDecimalSeparatorLen )
- )
- nEnd = _nDecimalPointPos + nDecimalSeparatorLen;
- }
- strText.Delete( nStart, ( nStart != nEnd ) ? ( nEnd - nStart ) : ( bNegDel ? 0 : 1 ) );
- }
- _GetTextWithoutMarks( strText, nStart, nEnd );
- _GetTextWithMarks( strText, nStart, nEnd, bNegative );
- if( m_bBackspace && ( nStart - nGroupSeparatorLen ) >= 0 )
- {
- INT nGroupSepPos = (INT)strText.Find( m_strGroupSeparator, ( nStart - nGroupSeparatorLen ) );
- if( nGroupSepPos >= 0 )
- {
- INT _nPos = 0, _nGroupSignBeforeStartAfterDelete = 0;
- bool _bChangePos = false;
- INT _nGroupSignCountAfterDelete = (INT)_GetGroupSeparatorCount( strText );
- for( ; true; )
- {
- _nPos = (INT)strText.Find( m_strGroupSeparator, _nPos );
- if( _nPos == -1 )
- break;
- if( _nPos < nStart )
- _nGroupSignBeforeStartAfterDelete ++;
- _nPos ++;
- }
- _nGroupSignBeforeStartAfterDelete = _nGroupSignCountAfterDelete - _nGroupSignBeforeStartAfterDelete;
- if( ( _nGroupSignBeforeStart - 1 ) == _nGroupSignBeforeStartAfterDelete )
- _bChangePos = true;
- if( nGroupSepPos == ( nStart - nGroupSeparatorLen ) && _bChangePos )
- nStart = nGroupSepPos;
- }
- }
- }
- return true;
- }
- void CExtEditSystemNumber::_GetTextWithoutMarks(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bCutDecimalPoint // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strCurrentText;
- INT nStartPos = nStart, nEndPos = nEnd;
- INT nSignCountBeforeStartPos ,nSignCountBeforeEndPos ,nSignCount;
- INT nStrLen = INT( strText.GetLength() );
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSeparatorPos = INT( strText.Find( m_strDecimalPoint ) );
- nSignCount = 0;
- if( nEndPos > strText.GetLength() )
- nEndPos = INT( strText.GetLength() );
- nSignCountBeforeStartPos = nSignCountBeforeEndPos = nSignCount = 0;
- for( INT i = 0; i < nStrLen; i++ )
- {
- TCHAR _tchr = strText[i];
- bool bUseSymbol = false;
- if( _T('0') <= _tchr && _tchr <= _T('9') ) // || ( _tchr == m_strDecimalPoint && ! bCutDecimalPoint )
- {
- strCurrentText += _tchr;
- bUseSymbol = true;
- }
- if( i >= nDecimalSeparatorPos && i < ( nDecimalSeparatorPos + nDecimalSeparatorLen ) && ! bCutDecimalPoint && nDecimalSeparatorPos != -1 )
- {
- strCurrentText += _tchr;
- bUseSymbol = true;
- }
- if( ! bUseSymbol )
- nSignCount++;
- if( i == ( nStartPos - 1 ) )
- nSignCountBeforeStartPos = nSignCount;
- else if( i == ( nEndPos - 1 ) )
- nSignCountBeforeEndPos = nSignCount;
- }
- nStartPos -= nSignCountBeforeStartPos;
- nEndPos -= nSignCountBeforeEndPos;
- if( nStartPos < 0 )
- nStartPos = 0;
- if( nEndPos < 0 )
- nEndPos = 0;
- strText = strCurrentText;
- if( nStart != nEnd )
- {
- nStart = nStartPos;
- nEnd = nEndPos;
- }
- else
- nStart = nEnd = nStartPos;
- }
- void CExtEditSystemNumber::_GetTextWithMarks(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bInsertNegSign // = false
- ) const
- {
- ASSERT_VALID( this );
- if( strText.IsEmpty() )
- return;
- INT nTextLen = INT( strText.GetLength() );
- CExtSafeString strTextChange;
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nPositionDecimalPoint = INT( strText.Find( m_strDecimalPoint ) );
- INT nMaxLen = m_nMaxWholeDigits + m_nMaxFractionDigits + ( ( nPositionDecimalPoint >= 0 ) ? nDecimalSeparatorLen : 0 );
- if( nTextLen > nMaxLen )
- {
- if( nPositionDecimalPoint >= 0 )
- {
- CExtSafeString _strDecimalPoint = _T("");
- _strDecimalPoint = m_strDecimalPoint;
- strText.Replace( _strDecimalPoint, _T("") );
- if( nPositionDecimalPoint > m_nMaxWholeDigits )
- strText.Insert( m_nMaxWholeDigits, m_strDecimalPoint );
- else
- strText.Insert( nPositionDecimalPoint, m_strDecimalPoint );
- }
- nTextLen = INT( strText.GetLength() );
- }
- INT nWholeNumber = ( ( nPositionDecimalPoint >= 0 ) ? ( ( nPositionDecimalPoint < m_nMaxWholeDigits ) ? nPositionDecimalPoint : m_nMaxWholeDigits ) : ( ( m_nMaxWholeDigits >= nTextLen ) ? nTextLen : m_nMaxWholeDigits ) );
- INT nDecimalPointLen = nDecimalSeparatorLen; // 1
- INT nCorectTextLen = nWholeNumber + nDecimalPointLen + m_nMaxFractionDigits;
- nCorectTextLen = ( nCorectTextLen > nTextLen ) ? nTextLen : nCorectTextLen;
- INT nCountDigitGroups = INT( m_listDigitGrouping.GetCount() );
- CList < INT, INT > _listPos;
- bool bLastZiro = ( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex( nCountDigitGroups - 1 ) ) == 0 ) ? true : false;
- ASSERT( nWholeNumber <= m_nMaxWholeDigits );
- INT nPos = nWholeNumber;
- INT i = 0;
- INT nPreviousCount = -1;
- for( ; true; )
- {
- INT nCount = INT( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex(i) ) );
- if( nCount == 0 && i < ( nCountDigitGroups - 1 ) )
- break;
- if( nCount == 0 && i == ( nCountDigitGroups - 1 ) )
- {
- ASSERT( nPreviousCount != -1 );
- nCount = nPreviousCount;
- }
- nPos -= nCount;
- if( nPos > 0 )
- _listPos.AddHead( nPos - 1 );
- else
- break;
- if( i == ( nCountDigitGroups - 1 ) && ! bLastZiro )
- break;
- if( i < ( nCountDigitGroups - 1 ) )
- i ++;
- nPreviousCount = nCount;
- }
- INT nSignCountBeforeStart = 0;
- INT nSignCountBeforeEnd = 0;
- bool bInsertedDecimalSignBeforeStart = false;
- bool bInsertedDecimalSignBeforeEnd = false;
- INT nCurDigitPos = 0;
- INT nPosCount = INT( _listPos.GetCount() );
- bool bCanPastGroupSep = ( nPosCount > 0 );
- for( i = 0; i < nCorectTextLen; i++ )
- {
- TCHAR _tchr = strText[i];
- strTextChange += _tchr;
- bool bInsertSign = false;
- INT nPosCur = 0;
- if( bCanPastGroupSep )
- nPosCur = _listPos.GetAt( _listPos.FindIndex( nCurDigitPos ) );
- if( ( i <= nWholeNumber )
- && ( i != ( nCorectTextLen - 1 ) )
- && ( i == nPosCur )
- && bCanPastGroupSep
- )
- {
- strTextChange += m_strGroupSeparator;
- bInsertSign = true;
- if( nCurDigitPos < ( nPosCount - 1 ) )
- nCurDigitPos ++;
- else
- bCanPastGroupSep = false;
- }
- if( i == ( nWholeNumber - 1 ) && ( nPositionDecimalPoint == -1 ) && ( i != nCorectTextLen - 1 ) )
- {
- strTextChange += m_strDecimalPoint;
- if( i < ( nStart - 1 ) )
- bInsertedDecimalSignBeforeStart = true;
- if( i < ( nEnd - 1 ) )
- bInsertedDecimalSignBeforeEnd = true;
- }
- if( bInsertSign )
- {
- if( i < nStart )
- nSignCountBeforeStart ++;
- if( i < nEnd )
- nSignCountBeforeEnd ++;
- }
- }
- if( bInsertNegSign && AllowNegativeGet() )
- {
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() ) + ( ( m_nNegativeFormatIndex == 2 || m_nNegativeFormatIndex == 4 ) ? 1: 0 );
- CExtSafeString _strNegativeSign = ( (m_nNegativeFormatIndex == 4) ? _T(" "): _T("") ) + m_strNegativeSign + ( (m_nNegativeFormatIndex == 2) ? _T(" "): _T("") );
- if( m_nNegativeFormatIndex == 0 )
- {
- strTextChange.Insert( strTextChange.GetLength(), _T(")") );
- strTextChange.Insert( 0, _T("(") );
- nStart += 1;
- nEnd += 1;
- }
- if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 )
- strTextChange.Insert( 0, _strNegativeSign );
- if( m_nNegativeFormatIndex == 3 || m_nNegativeFormatIndex == 4 )
- strTextChange.Insert( strTextChange.GetLength(), _strNegativeSign );
- if( m_nNegativeFormatIndex == 1 || m_nNegativeFormatIndex == 2 )
- {
- nStart += nNegSignLen;
- nEnd += nNegSignLen;
- }
- }
- strText = strTextChange;
- nStart += nGroupSeparatorLen * nSignCountBeforeStart + ( bInsertedDecimalSignBeforeStart ? nDecimalSeparatorLen : 0 );
- nEnd += nGroupSeparatorLen * nSignCountBeforeEnd + ( bInsertedDecimalSignBeforeEnd ? nDecimalSeparatorLen : 0 );
- }
- bool CExtEditSystemNumber::_IsNegative( __EXT_MFC_SAFE_LPCTSTR strText ) const
- {
- ASSERT_VALID( this );
- CExtSafeString _strText = strText;
- bool bRetVal = ( ( _strText.Find( m_strNegativeSign ) >= 0 ) ? true: false );
- if( m_nNegativeFormatIndex == 0 )
- bRetVal = ( ( _strText.Find( _T('(') ) >= 0 ) ? true: false );
- return bRetVal;
- }
- void CExtEditSystemNumber::_AdjustWithinRange()
- {
- ASSERT_VALID( this );
- if( m_bRichPainting )
- return;
- if( _IsValid() )
- return;
- if( TextGet().IsEmpty() )
- SetWindowText( _T(" ") );
- else
- _Redraw();
- long double dValue = LongDoubleGet();
- if( dValue < m_lfMin )
- LongDoubleSet( m_lfMin );
- else if( dValue > m_lfMax )
- LongDoubleSet( m_lfMax );
- CExtSafeString _strText = TextGet();
- bool bNegative = _IsNegative( _strText );
- INT nNegSignPos = -1;
- INT nLen = INT( _strText.GetLength() );
- if( bNegative )
- {
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- nNegSignPos = INT( _strText.Find( _T(")") ) );
- break;
- case 3:
- nNegSignPos = INT( _strText.Find( m_strNegativeSign ) );
- break;
- case 4:
- nNegSignPos = INT( _strText.Find( _T(" ") + m_strNegativeSign ) );
- break;
- }
- }
- _Rich_OnDraw();
- if( ! m_bRichPainting )
- {
- if( nNegSignPos >= 0 )
- SetSel( nNegSignPos, nNegSignPos );
- else
- SetSel( nLen, nLen );
- }
- }
- void CExtEditSystemNumber::_Rich_OnDraw()
- {
- ASSERT_VALID( this );
- if( ! m_bRichMode )
- return;
- if( GetSafeHwnd() == NULL )
- return;
- if( m_bRichPainting )
- return;
- m_bRichPainting = true;
- CHARRANGE crRestore;
- Rich_GetSel( crRestore );
- CHARFORMAT cfDefault;
- ::memset( &cfDefault, 0, sizeof(CHARFORMAT) );
- cfDefault.dwMask = CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_PROTECTED|CFM_COLOR;
- cfDefault.dwEffects = CFE_PROTECTED;
- //cfDefault.yHeight = 180;
- //cfDefault.crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
- CFont * pFont = GetFont();
- if( pFont->GetSafeHandle() == NULL )
- {
- CWnd * pWndParent = GetParent();
- if( pWndParent->GetSafeHwnd() != NULL )
- pFont = pWndParent->GetFont();
- if( pFont->GetSafeHandle() == NULL )
- pFont = &(PmBridge_GetPM()->m_FontNormal);
- }
- LOGFONT _lf; ::memset( &_lf, 0, sizeof(LOGFONT) );
- pFont->GetLogFont( &_lf );
- #if (! defined _RICHEDIT_VER )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- #if ( _RICHEDIT_VER < 0x0200 )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- __EXT_MFC_STRCPY( cfDefault.szFaceName, sizeof(cfDefault.szFaceName)/sizeof(cfDefault.szFaceName[0]), _lf.lfFaceName );
- #endif
- #endif
- CWindowDC dcDesktop( NULL );
- cfDefault.yHeight = ::MulDiv( _lf.lfHeight, 72 * 20, dcDesktop.GetDeviceCaps( LOGPIXELSY ) );
- cfDefault.yHeight = abs( cfDefault.yHeight );
- bool bEnabled = IsWindowEnabled() ? true : false, bReadOnly = ( ( GetStyle() & ES_READONLY ) != 0 );
- cfDefault.crTextColor = OnQueryTextColor();
- if( cfDefault.crTextColor == COLORREF(-1L) )
- {
- cfDefault.crTextColor = bEnabled ? ( bReadOnly ? m_clrRichTextReadOnly : m_clrRichTextNormal ) : m_clrRichTextDisabled;
- if( cfDefault.crTextColor == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- cfDefault.crTextColor = ::GetSysColor( COLOR_3DSHADOW );
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
- }
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_GRAYTEXT );
- }
- }
- COLORREF clrBack = OnQueryBackColor();
- if( clrBack == COLORREF(-1L) )
- {
- clrBack = bEnabled ? ( bReadOnly ? m_clrRichBackReadOnly : m_clrRichBackNormal ) : m_clrRichBackDisabled;
- if( clrBack == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- clrBack = ::GetSysColor( COLOR_3DFACE );
- else
- clrBack = ::GetSysColor( COLOR_WINDOW );
- }
- else
- clrBack = ::GetSysColor( COLOR_3DFACE );
- }
- }
- Rich_SetBackgroundColor( FALSE, clrBack );
- Rich_HideSelection( true, false );
- Rich_SetSel( 0, -1 );
- SendMessage( EM_SETCHARFORMAT, SCF_DEFAULT, LPARAM(&cfDefault) );
- SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(&cfDefault) );
- Rich_SetSelectionColor( cfDefault.crTextColor );
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- COLORREF clrSign = m_clrSign;
- if( clrSign == COLORREF(-1L) )
- clrSign = cfDefault.crTextColor;
- if( m_clrNumber != COLORREF(-1L)
- || m_clrFraction != COLORREF(-1L)
- || m_clrGroupSeparator != COLORREF(-1L)
- || m_clrDecimalSeparator != COLORREF(-1L)
- || m_clrBrackets != COLORREF(-1L)
- || clrSign != COLORREF(-1L)
- )
- {
- CExtSafeString strText = TextGet();
- INT nTextLen = INT( strText.GetLength() );
- if( nTextLen > 0 )
- {
- bool bNegative = _IsNegative( strText );
- INT nPositionDecimalPoint = INT( strText.Find( m_strDecimalPoint ) );
- CExtSafeString _strBefore = _T(""), _strAfter = _T("");
- if( bNegative )
- {
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- _strBefore = _T("(");
- _strAfter = _T(")");
- break;
- case 1:
- _strBefore = m_strNegativeSign;
- break;
- case 2:
- _strBefore = m_strNegativeSign + _T(" ");
- break;
- case 3:
- _strAfter = m_strNegativeSign;
- break;
- case 4:
- _strAfter = _T(" ") + m_strNegativeSign;
- break;
- }
- }
- INT nBeforLen = _strBefore.GetLength();
- INT nAfterLen = _strAfter.GetLength();
- // Whole number
- if( m_clrNumber != COLORREF(-1L) )
- {
- Rich_SetSel( nBeforLen, ( nPositionDecimalPoint != -1 ) ? nPositionDecimalPoint : ( nTextLen - nAfterLen ) );
- Rich_SetSelectionColor( m_clrNumber );
- }
- if( nPositionDecimalPoint != -1 )
- {
- if( m_clrDecimalSeparator != COLORREF(-1L) )
- {
- Rich_SetSel( nPositionDecimalPoint, ( nPositionDecimalPoint + nDecimalSignLen ) );
- Rich_SetSelectionColor( m_clrDecimalSeparator );
- }
- if( m_clrFraction != COLORREF(-1L) )
- {
- Rich_SetSel( nPositionDecimalPoint + nDecimalSignLen, nTextLen - nAfterLen );
- Rich_SetSelectionColor( m_clrFraction );
- }
- }
- if( m_clrGroupSeparator != COLORREF(-1L) )
- {
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- Rich_SetSel( nPos, ( nPos + nGroupSeparatorLen ) );
- Rich_SetSelectionColor( m_clrGroupSeparator );
- nPos ++;
- }
- }
- if( bNegative && clrSign != COLORREF(-1L) )
- {
- if( ( _strAfter.IsEmpty() || _strBefore.IsEmpty() )
- && ( ! _strAfter.IsEmpty() || !_strBefore.IsEmpty() )
- )
- {
- INT nNegSignPos = INT( strText.Find( m_strNegativeSign ) );
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() );
- if( clrSign != COLORREF(-1L) )
- {
- Rich_SetSel( nNegSignPos, ( nNegSignPos + nNegSignLen ) );
- Rich_SetSelectionColor( clrSign );
- }
- }
- if( ! _strAfter.IsEmpty() && ! _strBefore.IsEmpty() )
- {
- if( m_clrBrackets != COLORREF(-1L) )
- {
- INT i, nPos = 0;
- CString _strBrackets = _T("()[]{}");
- INT nBrackLen = _strBrackets.GetLength();
- for( i = 0; i < nBrackLen; i++ )
- {
- nPos = 0;
- for( ; true; )
- {
- nPos = strText.Find( _strBrackets[i], nPos );
- if( nPos == -1 )
- break;
- Rich_SetSel( nPos, ( nPos + 1 ) );
- Rich_SetSelectionColor( m_clrBrackets );
- nPos ++;
- }
- }
- }
- }
- }
- } // if( nTextLen > 0 )
- }
- Rich_SetSel( crRestore );
- Rich_HideSelection( false, false );
- m_bRichPainting = false;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditSystemCurrency window
- IMPLEMENT_DYNCREATE( CExtEditSystemCurrency, CExtEditSystemNumberCurrencyBase );
- CExtEditSystemCurrency::CExtEditSystemCurrency(
- INT nMaxWholeDigits, // = __EXT_MFC_DEFAULT_MAX_WHOLE_DIGITS
- INT nMaxFractionDigits // = __EXT_MFC_DEFAULT_FRACTION_WHOLE_DIGITS
- )
- : CExtEditSystemNumberCurrencyBase( nMaxWholeDigits, nMaxFractionDigits )
- {
- _Init();
- }
- CExtEditSystemCurrency::~CExtEditSystemCurrency()
- {
- }
- BEGIN_MESSAGE_MAP( CExtEditSystemCurrency, CExtEditSystemNumberCurrencyBase )
- //{{AFX_MSG_MAP(CExtEditSystemNumberCurrencyBase)
- //}}AFX_MSG_MAP
- __EXT_MFC_SAFE_ON_WM_SETTINGCHANGE()
- END_MESSAGE_MAP()
- void CExtEditSystemCurrency::_Init()
- {
- ASSERT_VALID( this );
- // negative sign
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SNEGATIVESIGN, m_strNegativeSign.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strNegativeSign.ReleaseBuffer();
- }
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SCURRENCY, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SCURRENCY, m_strCurrencySymbol.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strCurrencySymbol.ReleaseBuffer();
- }
- // decimal point
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONDECIMALSEP, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SMONDECIMALSEP, m_strDecimalPoint.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strDecimalPoint.ReleaseBuffer();
- }
- // group separator
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONTHOUSANDSEP, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SMONTHOUSANDSEP, m_strGroupSeparator.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- m_strGroupSeparator.ReleaseBuffer();
- }
- TCHAR cPosCurFormatIndex = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_ICURRENCY, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_ICURRENCY, &cPosCurFormatIndex, sizeof( cPosCurFormatIndex ) / sizeof(TCHAR) );
- m_nPositiveFormatIndex = _ttoi( & cPosCurFormatIndex );
- CExtSafeString strNegCurFormatIndex = _T("0");
- if( g_ResourceManager->GetLocaleInfo( LOCALE_INEGCURR, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_INEGCURR, strNegCurFormatIndex.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- strNegCurFormatIndex.ReleaseBuffer();
- }
- CExtSafeString strDigitGrouping = _T("0");
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SMONGROUPING, NULL, 0 ) )
- {
- g_ResourceManager->GetLocaleInfo( LOCALE_SMONGROUPING, strDigitGrouping.GetBuffer( _MAX_PATH + 1 ), _MAX_PATH );
- strDigitGrouping.ReleaseBuffer();
- INT nStrLen = INT( strDigitGrouping.GetLength() );
- CExtSafeString _strGroup = _T("");
- INT nGroup = 0;
- if( m_listDigitGrouping.GetCount() > 0 )
- m_listDigitGrouping.RemoveAll();
- for( INT i = 0; i < nStrLen; i++ )
- {
- TCHAR ch = strDigitGrouping[i];
- if( ch == _T(';') )
- {
- nGroup = _ttoi( _strGroup );
- m_listDigitGrouping.AddTail( nGroup );
- _strGroup = _T("");
- nGroup = 0;
- }
- else
- _strGroup = _strGroup + ch;
- }
- nGroup = _ttoi( _strGroup );
- m_listDigitGrouping.AddTail( nGroup );
- }
- m_nNegativeFormatIndex = _ttoi( strNegCurFormatIndex );
- TCHAR cNoOfDigitsAfterDecimal = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_ICURRDIGITS, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_ICURRDIGITS, &cNoOfDigitsAfterDecimal, sizeof( cNoOfDigitsAfterDecimal ) / sizeof(TCHAR) );
- m_nMaxFractionDigits = _ttoi( & cNoOfDigitsAfterDecimal );
- TCHAR cDisplayLeadingZeros = _T('0');
- if( g_ResourceManager->GetLocaleInfo( LOCALE_ILZERO, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_ILZERO, &cDisplayLeadingZeros, sizeof( cDisplayLeadingZeros ) / sizeof(TCHAR) );
- m_nDisplayLeadingZeros = _ttoi( & cDisplayLeadingZeros );
- TCHAR cDigitGrouping[20] = _T("");
- if( g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, NULL, 0 ) )
- g_ResourceManager->GetLocaleInfo( LOCALE_SGROUPING, cDigitGrouping, sizeof( cDigitGrouping ) / sizeof( cDigitGrouping[0] ) );
- // ensure the separators are not the same
- if( m_strDecimalPoint == m_strGroupSeparator )
- m_strGroupSeparator = ( m_strDecimalPoint == _T(",") ? _T(".") : _T(",") );
- }
- void CExtEditSystemCurrency::OnSettingChange( UINT uFlags, __EXT_MFC_SAFE_LPCTSTR lpszSection )
- {
- ASSERT_VALID( this );
- CExtEditSystemNumberCurrencyBase::OnSettingChange( uFlags, lpszSection );
- if( _tcscmp( lpszSection, _T("intl") ) == 0 )
- {
- long double lfSaved = LongDoubleGet();
- _Init();
- LongDoubleSet( lfSaved );
- SetSel( -1, -1 );
- }
- }
- CExtSafeString CExtEditSystemCurrency::_GetNumericText(
- const CExtSafeString & strText,
- bool bUseMathSymbols // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strNewText;
- bool bIsNegative = _IsNegative( strText );
- bool bHasDecimalPoint = false;
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSignPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nPos, nLen;
- for( nPos = 0, nLen = INT( strText.GetLength() ); nPos < nLen; nPos++ )
- {
- TCHAR c = strText[nPos];
- if( _istdigit(c) )
- strNewText += c;
- else if( nPos == nDecimalSignPos && !bHasDecimalPoint )
- {
- bHasDecimalPoint = true;
- strNewText += ( bUseMathSymbols ? _T(".") : m_strDecimalPoint );
- nPos += nDecimalSignLen - 1;
- }
- }
- if( bUseMathSymbols )
- {
- if( bIsNegative )
- strNewText.Insert( 0, _T("-") );
- }
- else
- {
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bIsNegative && AllowNegativeGet() );
- if( ! _strAfter.IsEmpty() )
- strNewText.Insert( strNewText.GetLength(), _strAfter );
- if( ! _strBefore.IsEmpty() )
- strNewText.Insert( 0, _strBefore );
- }
- return strNewText;
- }
- CExtSafeString CExtEditSystemCurrency::_GetDoubleText( long double lfValue, bool bTrimTrailingZeros /*= true*/ ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strText;
- strText.Format( _T("%lf"), lfValue );
- if( m_strDecimalPoint != _T(".") )
- strText.Replace( _T("."), m_strDecimalPoint );
- if( bTrimTrailingZeros )
- {
- strText.TrimRight( _T("0") );
- strText.TrimRight( m_strDecimalPoint );
- }
- bool bNegative = ( strText.Find( _T("-") ) == 0 ) ? true : false;
- if( bNegative )
- strText.Delete( 0 );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative && AllowNegativeGet() );
- INT nLen = INT( strText.GetLength() );
- if( ! _strAfter.IsEmpty() )
- strText.Insert( nLen, _strAfter );
- if( ! _strBefore.IsEmpty() )
- strText.Insert( 0, _strBefore );
- return strText;
- }
- void CExtEditSystemCurrency::IntSet( INT nVal )
- {
- ASSERT_VALID( this );
- CExtSafeString strText;
- strText.Format( _T("%d"), nVal );
- bool bNegative = ( strText.Find( _T("-") ) == 0 ) ? true : false;
- strText.Delete( 0 );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative && AllowNegativeGet() );
- INT nLen = INT( strText.GetLength() );
- if( ! _strAfter.IsEmpty() )
- strText.Insert( nLen, _strAfter );
- if( ! _strBefore.IsEmpty() )
- strText.Insert( 0, _strBefore );
- m_pEditWithBehaviorWnd->SetWindowText(strText);
- }
- long double CExtEditSystemCurrency::LongDoubleGet() const
- {
- ASSERT_VALID( this );
- // return _tcstod( _GetNumericText( m_pEditWithBehaviorWnd->TextGet(), true ), NULL );
- CExtSafeString str = _GetNumericText( m_pEditWithBehaviorWnd->TextGet(), true );
- if( str.IsEmpty()
- || str == _T(".")
- || str == LPCTSTR(m_strDecimalPoint)
- || ( str.GetLength() == 1 && m_strDecimalPoint.GetLength() > 0 && str[0] == m_strDecimalPoint[0] )
- )
- return 0.0;
- LCID _LCID = LANG_USER_DEFAULT;
- if( g_ResourceManager->IsCustomLangAllowed() )
- _LCID = g_ResourceManager->GetLangIdDesired();
- COleCurrency _oleCurrency;
- VERIFY( _oleCurrency.ParseCurrency( LPCTSTR(str), 0, _LCID ) );
- long double lfVal = ((long double)_oleCurrency.m_cur.int64) / ((long double)10000.0);
- return lfVal;
- }
- INT CExtEditSystemCurrency::IntGet() const
- {
- ASSERT_VALID( this );
- // return (INT)_ttoi( _GetNumericText( m_pEditWithBehaviorWnd->TextGet() ) );
- CExtSafeString str = _GetNumericText( m_pEditWithBehaviorWnd->TextGet(), true );
- if( str.IsEmpty() )
- return 0;
- LCID _LCID = LANG_USER_DEFAULT;
- if( g_ResourceManager->IsCustomLangAllowed() )
- _LCID = g_ResourceManager->GetLangIdDesired();
- COleCurrency _oleCurrency;
- VERIFY( _oleCurrency.ParseCurrency( LPCTSTR(str), 0, _LCID ) );
- __int64 nVal = ((__int64)_oleCurrency.m_cur.int64) / ((__int64)10000);
- return INT(nVal);
- }
- CExtSafeString CExtEditSystemCurrency::Behavior_GetValidText(
- bool bSetSel // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString strNewText = strText;
- bool bIsNegative = _IsNegative( strText );
- INT nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- _GetTextWithoutMarks( strNewText, nStart, nEnd );
- _GetTextWithMarks( strNewText, nStart, nEnd, ( bIsNegative && AllowNegativeGet() ) );
- if( bSetSel && ( ! m_bRichPainting ) )
- {
- CExtSafeString strCurrentText = m_pEditWithBehaviorWnd->TextGet();
- if( strNewText != strCurrentText )
- m_pEditWithBehaviorWnd->SetWindowText( strNewText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- return strNewText;
- }
- void CExtEditSystemCurrency::Behavior_OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( this );
- if( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY )
- return;
- TCHAR c = static_cast<TCHAR>( uChar );
- INT nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString strNumericText = _GetNumericText( strText );
- INT nDecimalPos = INT( strText.Find( m_strDecimalPoint ) );
- INT nNumericDecimalPos = INT( strNumericText.Find( m_strDecimalPoint ) );
- INT nLen = INT( strText.GetLength() );
- INT nNumericLen = INT( strNumericText.GetLength() );
- INT nSepCount = _GetGroupSeparatorCount( strText );
- bool bNeedAdjustment = false;
- bool bIsNegative = false;
- bool bIsDecimalPoint = false;
- if( ( c == m_strNegativeSign[0] )
- || ( ( m_nNegativeFormatIndex == 0
- || m_nNegativeFormatIndex == 4
- || m_nNegativeFormatIndex == 14
- || m_nNegativeFormatIndex == 15
- )
- && c == _T('(')
- )
- || ( c == _T('-') )
- )
- {
- bIsNegative = true;
- }
- // test whether it is a negative sign
- if( bIsNegative && AllowNegativeGet() )
- {
- bool bNegative = _IsNegative( strText );
- CExtSafeString _strBefore = _T(""), _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative );
- INT nBeforLen = INT( _strBefore.GetLength() );
- INT nAfterLen = INT( _strAfter.GetLength() );
- CExtSafeString strNewText = strText;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- if( nStart < nBeforLen )
- nStart = nBeforLen;
- if( nEnd > ( nLen - nAfterLen ) )
- nEnd = ( nLen - nAfterLen );
- _GetTextWithoutMarks( strNewText, nStart, nEnd );
- _GetTextWithMarks( strNewText, nStart, nEnd, ! bNegative );
- CExtSafeString strCurrentText = m_pEditWithBehaviorWnd->TextGet();
- if( strNewText != strCurrentText )
- m_pEditWithBehaviorWnd->SetWindowText( strNewText );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- return;
- }
- // test whether it is a decimal point (only one is enabled)
- else if( c == m_strDecimalPoint[0] && m_nMaxFractionDigits > 0 )
- {
- if( nDecimalPos >= 0 )
- {
- // test decimal point replacement
- if( nDecimalPos >= nStart && nDecimalPos < nEnd )
- {
- bNeedAdjustment = true;
- bIsDecimalPoint = true;
- }
- else
- { // else set caret
- m_pEditWithBehaviorWnd->SetSel( nDecimalPos + m_strDecimalPoint.GetLength(), nDecimalPos + m_strDecimalPoint.GetLength() );
- //m_pEditWithBehaviorWnd->SetSel( nDecimalPos + 1, nDecimalPos + 1 );
- return;
- }
- }
- else
- {
- bNeedAdjustment = true;
- bIsDecimalPoint = true;
- }
- }
- // test if it's a digit
- else if( _istdigit(c) )
- {
- // test whether we're on the right of the decimal point
- if( nDecimalPos >= 0 && nDecimalPos < nStart )
- {
- bool bIsNegative = _IsNegative( strNumericText );
- CExtSafeString _strBeforeCurrency = _T("");
- CExtSafeString _strAfterCurrency = _T("");
- _GetSignStrings( _strBeforeCurrency, _strAfterCurrency, bIsNegative && AllowNegativeGet() );
- INT nNegLength = INT( _strAfterCurrency.GetLength() );
- if( ! _strAfterCurrency.IsEmpty() )
- {
- INT nNegSignPos = -1;
- if( ! _strAfterCurrency.IsEmpty() )
- nNegSignPos = INT( strText.Find( _strAfterCurrency ) );
- if( ( nStart > nNegSignPos ) && ( nStart <= nLen ) && nNegSignPos != -1 )
- {
- nStart = nNegSignPos;
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- }
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- if( nDecimalPos <= nStart && nStart < ( nDecimalPos + nDecimalSeparatorLen ) )
- {
- INT nPrevStart = nStart;
- nStart = ( nDecimalPos + nDecimalSeparatorLen );
- if( nEnd == nPrevStart
- || nEnd < nPrevStart
- || ( nEnd > nPrevStart
- && nEnd < nStart
- )
- )
- nEnd = nStart;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- if( strNumericText.Mid( /*nDecimalPos */nNumericDecimalPos + nDecimalSeparatorLen ).GetLength() == ( m_nMaxFractionDigits + nNegLength ) )
- {
- if( nStart <= ( nDecimalPos + m_nMaxFractionDigits + nDecimalSeparatorLen - 1 ) )
- {
- //nEnd = ( ( ( nEnd == nLen ) || ( nEnd > nStart ) ) ? nEnd : (nStart + 1) );
- nEnd = ( ( ( nEnd == nLen ) || ( nEnd > ( nStart + 1 ) ) ) ? nEnd : (nStart + 1) );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( CExtSafeString(c), TRUE );
- }
- return;
- }
- else if( strNumericText.Mid( nNumericDecimalPos + nDecimalSeparatorLen ).GetLength() > ( m_nMaxFractionDigits + nNegLength ) )
- {
- ASSERT(false);
- return;
- }
- }
- // we're on the left side of the decimal point
- else
- {
- bool bIsNegative = _IsNegative( strNumericText );
- CExtSafeString _strBeforeCurrency = _T("");
- CExtSafeString _strAfterCurrency = _T("");
- _GetSignStrings( _strBeforeCurrency, _strAfterCurrency, bIsNegative && AllowNegativeGet() );
- INT nNegLength = INT( _strBeforeCurrency.GetLength() );
- INT nAfterSignsLength = INT( _strAfterCurrency.GetLength() );
- if( nNegLength > 0 )
- {
- if( ( nStart >= 0 ) && ( nStart < nNegLength ) )
- {
- nStart = nNegLength;
- if( nStart > nEnd )
- nEnd = nStart;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- }
- if( nAfterSignsLength > 0 )
- {
- if( ( nEnd >= ( nLen - nAfterSignsLength ) ) && ( nEnd <= nLen ) )
- {
- nEnd = nLen - nAfterSignsLength;
- if( nStart > nEnd )
- nStart = nEnd;
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- }
- if( ( nStart >= ( nLen - nAfterSignsLength ) ) && ( nStart <= nLen ) )
- {
- nStart = nLen - nAfterSignsLength;
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- }
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- // ensure we can still enter digits
- INT nDecPos = m_nMaxWholeDigits + nNegLength + ( nSepCount * nGroupSeparatorLen );
- if( nStart == nDecPos )
- {
- UINT nFlags = CBehaviorBase::m_nBehaviorFlags;
- if( nFlags & __ESE_ADD_DECIMAL_AFTER_MAX_WHOLE_DIGITS && m_nMaxFractionDigits > 0 )
- {
- nEnd = ( ( ( nEnd == nLen ) || ( ( nEnd > nStart ) && ( ( nEnd - nStart ) > 1 ) ) ) ? nEnd : ( nStart + nDecimalSignLen + 1 ) );
-
- if( _strAfterCurrency.GetLength() > 0 )
- {
- m_pEditWithBehaviorWnd->SetSel( nStart, strText.GetLength() );
- m_pEditWithBehaviorWnd->ReplaceSel( _T(""), TRUE );
- }
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( m_strDecimalPoint + c, TRUE );
- if( _strAfterCurrency.GetLength() > 0 )
- {
- CExtSafeString strChangedText = m_pEditWithBehaviorWnd->TextGet();
- INT nEnd = INT( strChangedText.GetLength() );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( _strAfterCurrency, TRUE );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- }
- CExtSafeString strReplaceText = Behavior_GetValidText( true );
- }
- return;
- }
- if( strNumericText.Mid(
- 0,
- ( ( nNumericDecimalPos >= 0 )
- ? nNumericDecimalPos
- : nNumericLen
- )
- ).GetLength()
- == ( m_nMaxWholeDigits + nNegLength )
- )
- {
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos <= nStart && nStart < ( nPos + nGroupSeparatorLen ) )
- {
- nStart = nPos + nGroupSeparatorLen;
- break;
- }
- nPos ++;
- }
- INT _nNegativeSignLen = nNegLength;
- if( nStart < _nNegativeSignLen )
- nStart = _nNegativeSignLen;
- nEnd = ( ( ( nEnd == nLen ) || ( nEnd > nStart ) ) ? nEnd : ( nStart + 1 ) );
- if( _strAfterCurrency.GetLength() > 0 )
- {
- INT nNegSignPos = INT( strText.Find( _strAfterCurrency ) );
- if( nEnd > nNegSignPos )
- nEnd = nNegSignPos;
- }
- if( ! m_bRichPainting )
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- m_pEditWithBehaviorWnd->ReplaceSel( CExtSafeString(c), TRUE );
- CExtSafeString strReplaceText = Behavior_GetValidText(true);
- return;
- }
- bNeedAdjustment = true;
- }
- }
- // test whether it is a non-printable character (i.e. backspace, ctrl+c )
- else if( ! ( _istprint( c ) || IsCharAlphaNumeric( c ) ) )
- bNeedAdjustment = true;
- else
- return;
- if( ! m_bBackspace )
- {
- //CExtEditSystemNumberCurrencyBase::CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- // if the decimal point was added/removed or a separator needs adding/removing, adjust the text
- if( bNeedAdjustment )
- _AdjustSeparators( nSepCount, bIsDecimalPoint );
- }
- else
- m_bBackspace = false;
- }
- bool CExtEditSystemCurrency::_DeleteSymbols(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bBackspace // = false
- )
- {
- ASSERT_VALID( this );
- ASSERT( ! m_bRichPainting );
- INT nLen = INT( strText.GetLength() );
- bool bNegative = _IsNegative( strText );
- CExtSafeString strTextLen = strText;
- INT nStLen = 0, nEndLen = 0;
- _GetTextWithoutMarks( strTextLen, nStLen, nEndLen );
- INT nTextLen = INT( strTextLen.GetLength() );
- INT nDecSepPosLen = INT( strTextLen.Find( m_strDecimalPoint ) );
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSeparatorPos = INT( strText.Find( m_strDecimalPoint ) );
- INT _nPos = 0, _nGroupSignBeforeStart = 0, _nGroupSignCount = (INT)_GetGroupSeparatorCount( strText );
- for( ; true; )
- {
- _nPos = (INT)strText.Find( m_strGroupSeparator, _nPos );
- if( _nPos < 0 )
- break;
- if( _nPos < nStart )
- _nGroupSignBeforeStart ++;
- _nPos ++;
- }
- _nGroupSignBeforeStart = _nGroupSignCount - _nGroupSignBeforeStart;
- if( bBackspace )
- {
- if( nStart == 0 && nStart == nEnd )
- return false;
- INT nPos = 0;
- if( nStart >= 0 )
- {
- if( ( nDecimalSeparatorPos < nStart
- || ( nDecimalSeparatorPos == nStart
- && nStart != nEnd
- )
- )
- && nStart <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nDecSepPosLen == m_nMaxWholeDigits
- && ( nTextLen > ( nDecSepPosLen + nDecimalSeparatorLen )
- && nDecSepPosLen != -1
- )
- )
- {
- nStart = nDecimalSeparatorPos;
- nEnd = nDecimalSeparatorPos;
- m_bBackspace = true;
- return false;
- }
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( ( nPos < nStart
- || ( nPos == nStart
- && nStart != nEnd
- )
- )
- && nStart <= ( nPos + nGroupSeparatorLen )
- && nEnd <= ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos;
- nEnd = nPos;
- m_bBackspace = true;
- return false;
- }
- nPos ++;
- }
- }
- }
- else
- {
- if( nStart == nLen )
- return false;
- INT nPos = 0;
- if( nStart < nLen )
- {
- if( nDecimalSeparatorPos <= nStart
- && nStart < ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- && nDecSepPosLen == m_nMaxWholeDigits
- && ( nTextLen > ( nDecSepPosLen + nDecimalSeparatorLen )
- && nDecSepPosLen != -1
- )
- )
- {
- nStart = nDecimalSeparatorPos + nDecimalSeparatorLen;
- nEnd = nDecimalSeparatorPos + nDecimalSeparatorLen;
- return false;
- }
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos <= nStart
- && nStart < ( nPos + nGroupSeparatorLen )
- && nEnd <= ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos + nGroupSeparatorLen;
- nEnd = nPos + nGroupSeparatorLen;
- return false;
- }
- nPos ++;
- }
- }
- }
- if( nStart != nEnd )
- {
- if( nDecimalSeparatorPos < nStart
- && nStart < ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- )
- {
- nStart = nDecimalSeparatorPos + nDecimalSeparatorLen;
- if( nStart > nEnd )
- nEnd = nStart;
- }
- if( nDecimalSeparatorPos < nEnd
- && nEnd <= ( nDecimalSeparatorPos + nDecimalSeparatorLen )
- )
- nEnd = nDecimalSeparatorPos;
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- if( nPos < nStart
- && nStart < ( nPos + nGroupSeparatorLen )
- )
- {
- nStart = nPos + nGroupSeparatorLen;
- if( nStart >= nEnd )
- {
- nEnd = nStart;
- break;
- }
- }
- if( nPos < nEnd
- && nEnd < ( nPos + nGroupSeparatorLen )
- )
- {
- nEnd = nPos;
- if( nEnd < nStart )
- nStart = nEnd;
- if( nEnd >= nStart )
- break;
- }
- nPos ++;
- }
- }
- {
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative && AllowNegativeGet() );
- INT nBeforeLen = INT( _strBefore.GetLength() );
- INT nAfterLen = INT( _strAfter.GetLength() );
- bool bNegDel = false;
- if( bNegative )
- {
- if( ( nStart < nBeforeLen
- || ( nStart == nBeforeLen
- && nStart == nEnd
- && bBackspace
- )
- )
- && nBeforeLen > 0
- )
- {
- bNegative = false;
- bNegDel = true;
- }
- if( ( ( nStart >= ( nLen - nAfterLen ) && ! bBackspace )
- || ( nStart > ( nLen - nAfterLen ) && bBackspace )
- || ( nStart == nLen && nStart == nEnd && bBackspace )
- || nEnd > ( nLen - nAfterLen )
- )
- && nAfterLen > 0
- )
- {
- bNegative = false;
- bNegDel = true;
- }
- }
- else
- {
- if( ( ( nStart < nBeforeLen
- && nEnd <= nBeforeLen
- )
- || ( nStart == nBeforeLen
- && nStart == nEnd
- && bBackspace
- )
- )
- && nBeforeLen > 0
- )
- {
- nStart = nBeforeLen;
- return true;
- }
- if( ( ( nStart >= ( nLen - nAfterLen ) && ! bBackspace )
- || ( nStart > ( nLen - nAfterLen ) && bBackspace )
- || ( nStart == nLen && nStart == nEnd && bBackspace )
- )
- && nAfterLen > 0
- )
- {
- nStart = nLen - nAfterLen;
- return true;
- }
- if( nEnd > ( nLen - nAfterLen )
- && nAfterLen > 0
- )
- nEnd = nLen - nAfterLen;
- }
- _GetTextWithoutMarks( strText, nStart, nEnd );
- if( bBackspace )
- {
- bool bSelect = ( nStart != nEnd ) ? true : false;
- strText.Delete( ( nStart != nEnd ) ? nStart : ( nStart - 1 ), ( nStart != nEnd ) ? ( nEnd - nStart ) : ( bNegDel ? 0 : 1 ) );
- if( ! bSelect && ! bNegDel )
- nStart --;
- m_bBackspace = true;
- }
- else
- {
- INT _nDecimalPointPos = INT( strText.Find( m_strDecimalPoint ) );
- if( _nDecimalPointPos != -1 )
- {
- if( nStart > _nDecimalPointPos
- && nStart < ( _nDecimalPointPos + nDecimalSeparatorLen )
- )
- nStart = _nDecimalPointPos;
- if( nEnd > _nDecimalPointPos
- && nEnd < ( _nDecimalPointPos + nDecimalSeparatorLen )
- )
- nEnd = _nDecimalPointPos + nDecimalSeparatorLen;
- }
- strText.Delete( nStart, ( nStart != nEnd ) ? ( nEnd - nStart ) : ( bNegDel ? 0 : 1 ) );
- }
- _GetTextWithoutMarks( strText, nStart, nEnd );
- _GetTextWithMarks( strText, nStart, nEnd, bNegative );
- if( m_bBackspace && ( nStart - nGroupSeparatorLen ) >= 0 )
- {
- INT nGroupSepPos = (INT)strText.Find( m_strGroupSeparator, ( nStart - nGroupSeparatorLen ) );
- if( nGroupSepPos >= 0 )
- {
- INT _nPos = 0;
- INT _nGroupSignBeforeStartAfterDelete = 0;
- bool _bChangePos = false;
- INT _nGroupSignCountAfterDelete = (INT)_GetGroupSeparatorCount( strText );
- for( ; true; )
- {
- _nPos = (INT)strText.Find( m_strGroupSeparator, _nPos );
- if( _nPos < 0 )
- break;
- if( _nPos < nStart )
- _nGroupSignBeforeStartAfterDelete ++;
- _nPos ++;
- }
- _nGroupSignBeforeStartAfterDelete = _nGroupSignCountAfterDelete - _nGroupSignBeforeStartAfterDelete;
- if( ( _nGroupSignBeforeStart - 1 ) == _nGroupSignBeforeStartAfterDelete )
- _bChangePos = true;
- if( nGroupSepPos == ( nStart - nGroupSeparatorLen ) && _bChangePos )
- nStart = nGroupSepPos;
- }
- }
- }
- return true;
- }
- INT CExtEditSystemCurrency::_GetSignLengthBeforeCurrency(
- bool bNegative // = false
- ) const
- {
- ASSERT_VALID( this );
- INT nCurSignLength = INT( m_strCurrencySymbol.GetLength() );
- INT nNegSignLenBeforeCur = 0;
- INT nPosSignLenBeforeCur = 0;
- INT nSpecificSymbLength = 1; // Bracket or Space
- if( bNegative )
- {
- CExtSafeString strBefore = _T("");
- CExtSafeString strAfter = _T("");
- _GetSignStrings( strBefore, strAfter );
- nNegSignLenBeforeCur = INT( strBefore.GetLength() );
- }
- switch( m_nPositiveFormatIndex )
- {
- case 0:
- nPosSignLenBeforeCur = nCurSignLength;
- break;
- case 2:
- nPosSignLenBeforeCur = nCurSignLength + nSpecificSymbLength;
- break;
- }
- return bNegative ? nNegSignLenBeforeCur : nPosSignLenBeforeCur;
- }
- void CExtEditSystemCurrency::_GetSignStrings(
- CExtSafeString & strBeforeCurrency,
- CExtSafeString & strAfterCurrency,
- bool bNegative // = true
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strBefore = _T("");
- CExtSafeString strAfter = _T("");
- if( bNegative )
- {
- switch( m_nNegativeFormatIndex )
- {
- case 0:
- strBefore = _T("(") + m_strCurrencySymbol;
- strAfter = _T(")");
- break;
- case 1:
- strBefore = m_strNegativeSign + m_strCurrencySymbol;
- break;
- case 2:
- strBefore = m_strCurrencySymbol + m_strNegativeSign;
- break;
- case 3:
- strBefore = m_strCurrencySymbol;
- strAfter = m_strNegativeSign;
- break;
- case 4:
- strBefore = _T("(");
- strAfter = m_strCurrencySymbol + _T(")");
- break;
- case 5:
- strBefore = m_strNegativeSign;
- strAfter = m_strCurrencySymbol;
- break;
- case 6:
- strAfter = m_strNegativeSign + m_strCurrencySymbol;
- break;
- case 7:
- strAfter = m_strCurrencySymbol + m_strNegativeSign;
- break;
- case 8:
- strBefore = m_strNegativeSign;
- strAfter = _T(" ") + m_strCurrencySymbol;
- break;
- case 9:
- strBefore = m_strNegativeSign + m_strCurrencySymbol + _T(" ");
- break;
- case 10:
- strAfter = _T(" ") + m_strCurrencySymbol + m_strNegativeSign;
- break;
- case 11:
- strBefore = m_strCurrencySymbol + _T(" ");
- strAfter = m_strNegativeSign;
- break;
- case 12:
- strBefore = m_strCurrencySymbol + _T(" ") + m_strNegativeSign;
- break;
- case 13:
- strAfter = m_strNegativeSign + _T(" ") + m_strCurrencySymbol;
- break;
- case 14:
- strBefore = _T("(") + m_strCurrencySymbol + _T(" ");
- strAfter = _T(")");
- break;
- case 15:
- strBefore = _T("(");
- strAfter = _T(" ") + m_strCurrencySymbol + _T(")");
- break;
- }
- }
- else
- {
- switch( m_nPositiveFormatIndex )
- {
- case 0:
- strBefore = m_strCurrencySymbol;
- break;
- case 1:
- strAfter = m_strCurrencySymbol;
- break;
- case 2:
- strBefore = m_strCurrencySymbol + _T(" ");
- break;
- case 3:
- strAfter = _T(" ") + m_strCurrencySymbol;
- break;
- }
- }
- strBeforeCurrency = strBefore;
- strAfterCurrency = strAfter;
- }
- void CExtEditSystemCurrency::_GetTextWithoutMarks(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bCutDecimalPoint // = false
- ) const
- {
- ASSERT_VALID( this );
- CExtSafeString strCurrentText;
- INT nStartPos = nStart, nEndPos = nEnd;
- INT nSignCountBeforeStartPos ,nSignCountBeforeEndPos ,nSignCount;
- bool bIsNegative = _IsNegative(strText);
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nDecimalSeparatorPos = INT( strText.Find( m_strDecimalPoint ) );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bIsNegative );
- INT nStrLen = INT( strText.GetLength() );
- if( nEndPos > INT( strText.GetLength() ) )
- nEndPos = INT( strText.GetLength() );
- nSignCountBeforeStartPos = nSignCountBeforeEndPos = nSignCount = 0;
- for( INT i = 0; i < nStrLen; i++ )
- {
- TCHAR _tchr = strText[i];
- bool bUseSymbol = false;
- if( _T('0') <= _tchr && _tchr <= _T('9') )
- {
- strCurrentText += _tchr;
- bUseSymbol = true;
- }
- if( i >= nDecimalSeparatorPos && i < ( nDecimalSeparatorPos + nDecimalSeparatorLen ) && ! bCutDecimalPoint && nDecimalSeparatorPos != -1 )
- {
- strCurrentText += _tchr;
- bUseSymbol = true;
- }
- if( ! bUseSymbol )
- nSignCount++;
- if( i == ( nStartPos - 1 ) )
- nSignCountBeforeStartPos = nSignCount;
- else if( i == ( nEndPos - 1 ) )
- nSignCountBeforeEndPos = nSignCount;
- }
- nStartPos -= nSignCountBeforeStartPos;
- nEndPos -= nSignCountBeforeEndPos;
- if( nStartPos < 0 )
- nStartPos = 0;
- if( nEndPos < 0 )
- nEndPos = 0;
- strText = strCurrentText;
- if( nStart != nEnd )
- {
- nStart = nStartPos;
- nEnd = nEndPos;
- }
- else
- nStart = nEnd = nStartPos;
- }
- void CExtEditSystemCurrency::_GetTextWithMarks(
- CExtSafeString & strText,
- INT & nStart,
- INT & nEnd,
- bool bInsertNegSign // = false
- ) const
- {
- ASSERT_VALID( this );
- if( strText.IsEmpty() )
- return;
- INT nTextLen = INT( strText.GetLength() );
- CExtSafeString strTextChange;
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSeparatorLen = INT( m_strDecimalPoint.GetLength() );
- INT nPositionDecimalPoint = INT( strText.Find( m_strDecimalPoint ) );
- INT nMaxLen = m_nMaxWholeDigits + m_nMaxFractionDigits + ( ( nPositionDecimalPoint >= 0 ) ? nDecimalSeparatorLen : 0 );
- bool bStartBehindEnd = ( nStart > INT( strText.GetLength() ) );
- bool bEndBehindEnd = ( nEnd > INT( strText.GetLength() ) );
- if( nTextLen > nMaxLen )
- {
- if( nPositionDecimalPoint >= 0 )
- {
- CExtSafeString _strDecimalPoint = _T("");
- _strDecimalPoint = m_strDecimalPoint;
- strText.Replace( _strDecimalPoint, _T("") );
- if( nPositionDecimalPoint > m_nMaxWholeDigits )
- {
- strText.Insert( m_nMaxWholeDigits, m_strDecimalPoint );
- }
- else
- strText.Insert( nPositionDecimalPoint, m_strDecimalPoint );
- }
- nTextLen = INT( strText.GetLength() );
- }
- INT nWholeNumber = ( ( nPositionDecimalPoint >= 0 ) ? ( ( nPositionDecimalPoint < m_nMaxWholeDigits ) ? nPositionDecimalPoint : m_nMaxWholeDigits ) : ( ( m_nMaxWholeDigits >= nTextLen ) ? nTextLen : m_nMaxWholeDigits ) );
- INT nDecimalPointLen = nDecimalSeparatorLen; // 1
- INT nCorectTextLen = nWholeNumber + nDecimalPointLen + m_nMaxFractionDigits;
- nCorectTextLen = ( nCorectTextLen > nTextLen ) ? nTextLen : nCorectTextLen;
- INT nCountDigitGroups = INT( m_listDigitGrouping.GetCount() );
- CList < INT, INT > _listPos;
- bool bLastZiro = ( m_listDigitGrouping.GetAt( m_listDigitGrouping.FindIndex( nCountDigitGroups - 1 ) ) == 0 ) ? true : false;
- ASSERT( nWholeNumber <= m_nMaxWholeDigits );
- INT nPos = nWholeNumber;
- INT i = 0;
- INT nPreviousCount = -1;
- for( ; true; )
- {
- INT nCount = m_listDigitGrouping.GetAt(m_listDigitGrouping.FindIndex(i));
- if( nCount == 0 && i < ( nCountDigitGroups - 1 ) )
- break;
- if( nCount == 0 && i == ( nCountDigitGroups - 1 ) )
- {
- ASSERT( nPreviousCount != -1 );
- nCount = nPreviousCount;
- }
- nPos -= nCount;
- if( nPos > 0 )
- _listPos.AddHead( nPos - 1 );
- else
- break;
- if( i == ( nCountDigitGroups - 1 ) && ! bLastZiro )
- break;
- if( i < ( nCountDigitGroups - 1 ) )
- i ++;
- nPreviousCount = nCount;
- }
- INT nSignCountBeforeStart = 0;
- INT nSignCountBeforeEnd = 0;
- bool bInsertedDecimalSignBeforeStart = false;
- bool bInsertedDecimalSignBeforeEnd = false;
- INT nCurDigitPos = 0;
- INT nPosCount = INT( _listPos.GetCount() );
- bool bCanPastGroupSep = ( nPosCount > 0 );
- for( i = 0; i < nCorectTextLen; i++ )
- {
- TCHAR _tchr = strText[i];
- strTextChange += _tchr;
- bool bInsertSign = false;
- INT nPosCur = 0;
- if( bCanPastGroupSep )
- nPosCur = _listPos.GetAt( _listPos.FindIndex( nCurDigitPos ) );
- if( ( i <= nWholeNumber )
- && ( i != ( nCorectTextLen - 1 ) )
- && ( i == nPosCur )
- && bCanPastGroupSep
- )
- {
- strTextChange += m_strGroupSeparator;
- bInsertSign = true;
- if( nCurDigitPos < ( nPosCount - 1 ) )
- nCurDigitPos ++;
- else
- bCanPastGroupSep = false;
- }
- if( i == ( nWholeNumber - 1 ) && ( nPositionDecimalPoint == -1 ) && ( i != nCorectTextLen - 1 ) )
- {
- strTextChange += m_strDecimalPoint;
- if( i < ( nStart - 1 ) )
- bInsertedDecimalSignBeforeStart = true;
- if( i < ( nEnd - 1 ) )
- bInsertedDecimalSignBeforeEnd = true;
- }
- if( bInsertSign )
- {
- if( i < nStart )
- nSignCountBeforeStart ++;
- if( i < nEnd )
- nSignCountBeforeEnd ++;
- }
- }
- CExtSafeString _strSignBefore = _T("");
- CExtSafeString _strSignAfter = _T("");
- _GetSignStrings( _strSignBefore, _strSignAfter, bInsertNegSign && AllowNegativeGet() );
- if( _strSignAfter.GetLength() > 0 )
- {
- strTextChange.Insert( strTextChange.GetLength(), _strSignAfter );
- if( bStartBehindEnd )
- nStart += INT( _strSignAfter.GetLength() );
- if( bEndBehindEnd )
- nEnd += INT( _strSignAfter.GetLength() );
- }
- if( _strSignBefore.GetLength() > 0 )
- {
- strTextChange.Insert( 0, _strSignBefore );
- nStart += INT( _strSignBefore.GetLength() );
- nEnd += INT( _strSignBefore.GetLength() );
- }
- strText = strTextChange;
- nStart += nGroupSeparatorLen * nSignCountBeforeStart + ( bInsertedDecimalSignBeforeStart ? nDecimalSeparatorLen : 0 );
- nEnd += nGroupSeparatorLen * nSignCountBeforeEnd + ( bInsertedDecimalSignBeforeEnd ? nDecimalSeparatorLen : 0 );
- }
- bool CExtEditSystemCurrency::_IsNegative( __EXT_MFC_SAFE_LPCTSTR strText ) const
- {
- ASSERT_VALID( this );
- CExtSafeString _strText = strText;
- bool bRetVal = ( ( _strText.Find( m_strNegativeSign ) >= 0 ) ? true: false );
- if( m_nNegativeFormatIndex == 0
- || m_nNegativeFormatIndex == 4
- || m_nNegativeFormatIndex == 14
- || m_nNegativeFormatIndex == 15
- )
- bRetVal = ( ( _strText.Find( _T('(') ) >= 0 ) ? true: false );
- return bRetVal;
- }
- void CExtEditSystemCurrency::_AdjustWithinRange()
- {
- ASSERT_VALID( this );
- if( _IsValid() )
- return;
- if( m_pEditWithBehaviorWnd->TextGet().IsEmpty() )
- m_pEditWithBehaviorWnd->SetWindowText( _T(" ") );
- else
- _Redraw();
- long double dValue = LongDoubleGet();
- if( dValue < m_lfMin )
- LongDoubleSet( m_lfMin );
- else if( dValue > m_lfMax )
- LongDoubleSet( m_lfMax );
- CExtSafeString _strText = m_pEditWithBehaviorWnd->TextGet();
- bool bNegative = _IsNegative( _strText );
- CExtSafeString _strBefore = _T("");
- CExtSafeString _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative );
- INT nNegSignPos = -1;
- INT nLen = INT( _strText.GetLength() );
- if( ! _strAfter.IsEmpty() )
- nNegSignPos = INT( _strText.Find( _strAfter ) );
- if( ! m_bRichPainting )
- {
- if( nNegSignPos >= 0 )
- m_pEditWithBehaviorWnd->SetSel( nNegSignPos, nNegSignPos );
- else
- m_pEditWithBehaviorWnd->SetSel( nLen, nLen );
- }
- }
- void CExtEditSystemCurrency::_Rich_OnDraw()
- {
- if( ! m_bRichMode )
- return;
- if( GetSafeHwnd() == NULL )
- return;
- if( m_bRichPainting )
- return;
- m_bRichPainting = true;
- CHARRANGE crRestore;
- Rich_GetSel( crRestore );
- CHARFORMAT cfDefault;
- ::memset( &cfDefault, 0, sizeof(CHARFORMAT) );
- cfDefault.dwMask = CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_FACE|CFM_SIZE|CFM_CHARSET|CFM_PROTECTED|CFM_COLOR;
- cfDefault.dwEffects = CFE_PROTECTED;
- //cfDefault.yHeight = 180;
- //cfDefault.crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
- CFont * pFont = GetFont();
- if( pFont->GetSafeHandle() == NULL )
- {
- CWnd * pWndParent = GetParent();
- if( pWndParent->GetSafeHwnd() != NULL )
- pFont = pWndParent->GetFont();
- if( pFont->GetSafeHandle() == NULL )
- pFont = &(PmBridge_GetPM()->m_FontNormal);
- }
- LOGFONT _lf; ::memset( &_lf, 0, sizeof(LOGFONT) );
- pFont->GetLogFont( &_lf );
- #if (! defined _RICHEDIT_VER )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- #if ( _RICHEDIT_VER < 0x0200 )
- USES_CONVERSION;
- strcpy( cfDefault.szFaceName, T2CA(_lf.lfFaceName) );
- #else
- __EXT_MFC_STRCPY( cfDefault.szFaceName, sizeof(cfDefault.szFaceName)/sizeof(cfDefault.szFaceName[0]), _lf.lfFaceName );
- #endif
- #endif
- CWindowDC dcDesktop( NULL );
- cfDefault.yHeight = ::MulDiv( _lf.lfHeight, 72 * 20, dcDesktop.GetDeviceCaps( LOGPIXELSY ) );
- cfDefault.yHeight = abs( cfDefault.yHeight );
- bool bEnabled = IsWindowEnabled() ? true : false, bReadOnly = ( ( GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- cfDefault.crTextColor = OnQueryTextColor();
- if( cfDefault.crTextColor == COLORREF(-1L) )
- {
- cfDefault.crTextColor = bEnabled ? ( bReadOnly ? m_clrRichTextReadOnly : m_clrRichTextNormal ) : m_clrRichTextDisabled;
- if( cfDefault.crTextColor == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- cfDefault.crTextColor = ::GetSysColor( COLOR_3DSHADOW );
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_WINDOWTEXT );
- }
- else
- cfDefault.crTextColor = ::GetSysColor( COLOR_GRAYTEXT );
- }
- }
- COLORREF clrBack = OnQueryBackColor();
- if( clrBack == COLORREF(-1L) )
- {
- clrBack = bEnabled ? ( bReadOnly ? m_clrRichBackReadOnly : m_clrRichBackNormal ) : m_clrRichBackDisabled;
- if( clrBack == COLORREF(-1L) )
- {
- if( bEnabled )
- {
- if( bReadOnly )
- clrBack = ::GetSysColor( COLOR_3DFACE );
- else
- clrBack = ::GetSysColor( COLOR_WINDOW );
- }
- else
- clrBack = ::GetSysColor( COLOR_3DFACE );
- }
- }
- Rich_SetBackgroundColor( FALSE, clrBack );
- Rich_HideSelection( true, false );
- Rich_SetSel( 0, -1 );
- SendMessage( EM_SETCHARFORMAT, SCF_DEFAULT, LPARAM(&cfDefault) );
- SendMessage( EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(&cfDefault) );
- Rich_SetSelectionColor( cfDefault.crTextColor );
- COLORREF clrSign = m_clrSign;
- if( clrSign == COLORREF(-1L) )
- clrSign = cfDefault.crTextColor;
- COLORREF clrBrackets = m_clrBrackets;
- if( clrSign == COLORREF(-1L) )
- clrBrackets = cfDefault.crTextColor;
- INT nGroupSeparatorLen = INT( m_strGroupSeparator.GetLength() );
- INT nDecimalSignLen = INT( m_strDecimalPoint.GetLength() );
- if( m_clrNumber != COLORREF(-1L)
- || m_clrFraction != COLORREF(-1L)
- || m_clrGroupSeparator != COLORREF(-1L)
- || m_clrDecimalSeparator != COLORREF(-1L)
- || m_clrSign != COLORREF(-1L)
- || m_clrBrackets != COLORREF(-1L)
- )
- {
- CExtSafeString strText = TextGet();
- INT nTextLen = INT( strText.GetLength() );
- if( nTextLen > 0 )
- {
- bool bNegative = _IsNegative( strText );
- INT nPositionDecimalPoint = INT( strText.Find( m_strDecimalPoint ) );
- CExtSafeString _strBefore = _T(""), _strAfter = _T("");
- _GetSignStrings( _strBefore, _strAfter, bNegative );
- INT nBeforLen = _strBefore.GetLength();
- INT nAfterLen = _strAfter.GetLength();
- // whole number
- if( m_clrNumber != COLORREF(-1L) )
- {
- Rich_SetSel( nBeforLen, ( nPositionDecimalPoint != -1 ) ? nPositionDecimalPoint : ( nTextLen - nAfterLen ) );
- Rich_SetSelectionColor( m_clrNumber );
- }
- if( nPositionDecimalPoint != -1 )
- {
- if( m_clrDecimalSeparator != COLORREF(-1L) )
- {
- Rich_SetSel( nPositionDecimalPoint, ( nPositionDecimalPoint + nDecimalSignLen ) );
- Rich_SetSelectionColor( m_clrDecimalSeparator );
- }
- if( m_clrFraction != COLORREF(-1L) )
- {
- Rich_SetSel( nPositionDecimalPoint + nDecimalSignLen, nTextLen - nAfterLen );
- Rich_SetSelectionColor( m_clrFraction );
- }
- }
- if( m_clrGroupSeparator != COLORREF(-1L) )
- {
- INT nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( m_strGroupSeparator, nPos ) );
- if( nPos == -1 )
- break;
- Rich_SetSel( nPos, ( nPos + nGroupSeparatorLen ) );
- Rich_SetSelectionColor( m_clrGroupSeparator );
- nPos ++;
- }
- }
- INT nNegSignPos = INT( strText.Find( m_strNegativeSign ) );
- INT nNegSignLen = INT( m_strNegativeSign.GetLength() );
- if( nNegSignPos >= 0 )
- {
- if( m_clrSign != COLORREF(-1L) )
- {
- Rich_SetSel( nNegSignPos, nNegSignPos + nNegSignLen );
- Rich_SetSelectionColor( m_clrSign );
- }
- }
- if( m_clrBrackets != COLORREF(-1L) )
- {
- INT nPos = 0;
- CExtSafeString _strBrackets = _T("()[]{}");
- INT nBrackLen = INT( _strBrackets.GetLength() );
- for( INT i = 0; i < nBrackLen; i++ )
- {
- nPos = 0;
- for( ; true; )
- {
- nPos = INT( strText.Find( _strBrackets[i], nPos ) );
- if( nPos == -1 )
- break;
- Rich_SetSel( nPos, ( nPos + 1 ) );
- Rich_SetSelectionColor( m_clrBrackets );
- nPos ++;
- }
- }
- }
- } // if( nTextLen > 0 )
- }
- Rich_SetSel( crRestore );
- Rich_HideSelection( false, false );
- m_bRichPainting = false;
- }