ExtEdit.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:204k
- // This is part of the Professional User Interface Suite library.
- // Copyright (C) 2001-2009 FOSS Software, Inc.
- // All rights reserved.
- //
- // http://www.prof-uis.com
- // mailto:support@prof-uis.com
- //
- // This source code can be used, modified and redistributed
- // under the terms of the license agreement that is included
- // in the Professional User Interface Suite package.
- //
- // Warranties and Disclaimers:
- // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND
- // INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- // IN NO EVENT WILL FOSS SOFTWARE INC. BE LIABLE FOR ANY DIRECT,
- // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES,
- // INCLUDING DAMAGES FOR LOSS OF PROFITS, LOSS OR INACCURACY OF DATA,
- // INCURRED BY ANY PERSON FROM SUCH PERSON'S USAGE OF THIS SOFTWARE
- // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- #include "stdafx.h"
- #if (!defined __EXT_EDIT_H)
- #include <ExtEdit.h>
- #endif
- #if (!defined __EXT_MEMORY_DC_H)
- #include <../Src/ExtMemoryDC.h>
- #endif
- #if (!defined __EXT_POPUP_MENU_WND_H)
- #include <ExtPopupMenuWnd.h>
- #endif
- #if (!defined __EXT_TOOLCONTROLBAR_H)
- #include <ExtToolControlBar.h>
- #endif
- #if (!defined __EXT_PAINT_MANAGER_H)
- #include <ExtPaintManager.h>
- #endif
- #if (!defined __ExtCmdManager_H)
- #include <ExtCmdManager.h>
- #endif
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditBase
- IMPLEMENT_DYNCREATE( CExtEditBase, CEdit );
- IMPLEMENT_CExtPmBridge_MEMBERS( CExtEditBase );
- HWND CExtEditBase::g_hWndEditInAltKeyCodeMode = NULL;
- CExtEditBase::CExtEditBase()
- : m_bHandleCtxMenus( true )
- , m_clrBack( COLORREF(-1L) )
- , m_clrBackPrev( COLORREF(-1L) )
- , m_clrText( COLORREF(-1L) )
- , m_bRichMode( false )
- , m_bHandleAltKeyCodes( true )
- , m_bAltKeyCodeMode( false )
- , m_nTrackedAltKeyCode( 0L )
- {
- EnableToolTips();
- PmBridge_Install();
- }
- CExtEditBase::~CExtEditBase()
- {
- PmBridge_Uninstall();
- if( m_brBack.GetSafeHandle() != NULL )
- m_brBack.DeleteObject();
- }
- BEGIN_MESSAGE_MAP( CExtEditBase, CEdit )
- //{{AFX_MSG_MAP(CExtEditBase)
- ON_WM_PAINT()
- ON_WM_CONTEXTMENU()
- ON_WM_CTLCOLOR_REFLECT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- DWORD CALLBACK CExtEditBase::stat_Rich_CallBack_StreamIn( __EXT_MFC_DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb )
- {
- ASSERT( pcb != NULL );
- CExtSafeString * pStr = (CExtSafeString*)dwCookie;
- ASSERT( pStr != NULL );
- LONG nLength = pStr->GetLength();
- // if( nLength < cb )
- // {
- // (*pcb) = nLength;
- // ::memcpy( pbBuff, (LPCTSTR)*pStr, (*pcb)*sizeof(TCHAR) );
- // pStr->Empty();
- // }
- // else
- // {
- // (*pcb) = cb;
- // ::memcpy( pbBuff, (LPCTSTR)*pStr, (*pcb)*sizeof(TCHAR) );
- // *pStr = pStr->Right( nLength - cb );
- // }
- USES_CONVERSION;
- if( nLength < cb )
- {
- LPCSTR strA = T2CA( LPCTSTR(*pStr) );
- (*pcb) = nLength;
- ::memcpy( pbBuff, LPVOID(strA), (*pcb)*sizeof(CHAR) );
- pStr->Empty();
- }
- else
- {
- CExtSafeString strPart = pStr->Left( cb );
- LPCSTR strA = T2CA( LPCTSTR(strPart) );
- (*pcb) = cb;
- ::memcpy( pbBuff, LPVOID(strA), (*pcb) * sizeof(CHAR) );
- *pStr = pStr->Right( nLength - cb );
- }
- return 0;
- }
- DWORD CALLBACK CExtEditBase::stat_Rich_CallBack_StreamOut( __EXT_MFC_DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG * pcb )
- {
- pcb;
- CExtSafeString * pStr = (CExtSafeString*) dwCookie;
- //CExtSafeString strTmp = _T("");
- // ASSERT( pStr != NULL );
- // strTmp = (CExtSafeString)pbBuff;
- // (*pStr) += strTmp.Left( cb );
- if( cb <= 0 )
- return 0;
- CHAR * pLocalBuffer = (CHAR *) ::malloc( cb + 1 );
- if( pLocalBuffer == NULL )
- return 0;
- pLocalBuffer[ cb ] = CHAR(0);
- ::memcpy( pLocalBuffer, pbBuff, cb * sizeof(CHAR) );
- USES_CONVERSION;
- LPCTSTR strT = A2CT(pLocalBuffer);
- (*pStr) += strT;
- ::free( pLocalBuffer );
- return 0;
- }
- void CExtEditBase::OnPaint()
- {
- // Let base class do it's thing
- CEdit::OnPaint();
- // Now we can do our painting for cue banner stuff
- if( GetWindowTextLength() > 0 || ::GetFocus() == m_hWnd )
- return;
- CExtSafeString strCueBanner = GetCueBanner();
- if( strCueBanner.IsEmpty() )
- return;
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- LOGFONT _lf;
- ::memset( &_lf, 0 , sizeof(LOGFONT) );
- if( ! pPM->m_FontNormal.GetLogFont( &_lf ) )
- return;
- CFont _font;
- _lf.lfItalic = TRUE;
- if( ! _font.CreateFontIndirect( &_lf ) )
- return;
- CRect rcClient;
- GetClientRect( &rcClient );
- CRect rcCueBanner = rcClient;
- rcCueBanner.DeflateRect( 3, 1 );
- CClientDC dc( this );
- CFont * pOldFont = dc.SelectObject( &_font );
- COLORREF clrOldText = dc.SetTextColor( pPM->GetColor( COLOR_GRAYTEXT ) );
- INT nOldBkMode = dc.SetBkMode( TRANSPARENT );
- dc.DrawText( LPCTSTR(strCueBanner), strCueBanner.GetLength(), &rcCueBanner, DT_LEFT|DT_VCENTER|DT_END_ELLIPSIS );
- dc.SetBkMode( nOldBkMode );
- dc.SetTextColor( clrOldText );
- dc.SelectObject( pOldFont );
- }
- bool CExtEditBase::SetCueBanner( __EXT_MFC_SAFE_LPCTSTR lpcText )
- {
- ASSERT_VALID( this );
- if( lpcText == NULL )
- m_strCueBanner.Empty();
- else
- m_strCueBanner = lpcText;
- if( GetSafeHwnd() != NULL && GetWindowTextLength() > 0 && ::GetFocus() != m_hWnd )
- Invalidate();
- return true;
- }
- bool CExtEditBase::GetCueBanner( __EXT_MFC_SAFE_LPTSTR lpText, int cchText ) const
- {
- ASSERT_VALID( this );
- if( lpText == NULL )
- return false;
- __EXT_MFC_STRNCPY( lpText, cchText, LPCTSTR(m_strCueBanner), m_strCueBanner.GetLength() );
- return true;
- }
- CExtSafeString CExtEditBase::GetCueBanner() const
- {
- ASSERT_VALID( this );
- return m_strCueBanner;
- }
- void CExtEditBase::OnContextMenu(CWnd* pWnd,CPoint pos )
- {
- if( ! m_bHandleCtxMenus )
- {
- CEdit::OnContextMenu( pWnd, pos );
- return;
- } // if( ! m_bHandleCtxMenus )
- LPCTSTR strProfileName =
- g_CmdManager->ProfileNameFromWnd( GetSafeHwnd() );
- if( strProfileName == NULL )
- {
- CEdit::OnContextMenu( pWnd, pos );
- return;
- }
- CExtPopupMenuWnd * pPopup =
- CExtPopupMenuWnd::InstantiatePopupMenu(
- GetParent()->GetSafeHwnd(),
- RUNTIME_CLASS(CExtPopupMenuWnd),
- this
- );
- if( ! pPopup->CreatePopupMenu( GetSafeHwnd() ) )
- {
- ASSERT( FALSE );
- delete pPopup;
- CEdit::OnContextMenu( pWnd, pos );
- return;
- }
- static struct
- {
- UINT m_nCmdID;
- LPCTSTR m_sMenuText;
- } arrCmds[] =
- {
- { ID_EDIT_UNDO, _T("&Undo") },
- // { ID_EDIT_REDO, _T("&Redo") },
- { ID_SEPARATOR, NULL },
- { ID_EDIT_CUT, _T("Cu&t") },
- { ID_EDIT_COPY, _T("&Copy") },
- { ID_EDIT_PASTE, _T("&Paste") },
- { ID_EDIT_CLEAR, _T("Cl&ear") },
- { ID_SEPARATOR, NULL },
- { ID_EDIT_SELECT_ALL, _T("Select &All") },
- };
- for( int i = 0; i < sizeof(arrCmds)/sizeof(arrCmds[0]); i++ )
- {
- if( arrCmds[i].m_nCmdID == ID_SEPARATOR )
- {
- VERIFY( pPopup->ItemInsert( ID_SEPARATOR ) );
- continue;
- } // if( arrCmds[i].m_nCmdID == ID_SEPARATOR )
- CExtCmdItem * pCmdItem = g_CmdManager->CmdGetPtr( strProfileName, arrCmds[i].m_nCmdID );
- if( pCmdItem == NULL )
- pCmdItem = g_CmdManager->CmdAllocPtr( strProfileName, arrCmds[i].m_nCmdID );
- ASSERT( pCmdItem != NULL );
- if( pCmdItem == NULL )
- continue;
- if( pCmdItem->m_sMenuText.IsEmpty() )
- {
- CExtSafeString sText;
- if( g_ResourceManager->LoadString( sText, arrCmds[i].m_nCmdID ) )
- {
- sText.Replace( _T("t"), _T(" ") );
- sText.Replace( _T("r"), _T("") );
- sText.TrimLeft();
- sText.TrimRight();
- if( ! sText.IsEmpty() )
- {
- INT nSep = INT( sText.ReverseFind('n') );
- if( nSep < 0 )
- {
- pCmdItem->m_sMenuText = sText;
- } // if( nSep < 0 )
- else
- {
- int nLen = sText.GetLength();
- pCmdItem->m_sMenuText = sText.Right( nLen - nSep );
- pCmdItem->m_sMenuText.TrimLeft();
- pCmdItem->m_sMenuText.TrimRight();
- } // else from if( nSep < 0 )
- } // if( ! sText.IsEmpty() )
- }
- if( pCmdItem->m_sMenuText.IsEmpty() )
- pCmdItem->m_sMenuText = arrCmds[i].m_sMenuText;
- } // if( pCmdItem->m_sMenuText.IsEmpty() )
- pCmdItem->StateSetBasic();
- VERIFY( pPopup->ItemInsert( arrCmds[i].m_nCmdID ) );
- } // for( int i = 0; i < sizeof(arrCmds)/sizeof(arrCmds[0]); i++ )
- CRect rcClient;
- GetClientRect( &rcClient );
- ClientToScreen( &rcClient );
- if( !rcClient.PtInRect( pos ) )
- pos = rcClient.CenterPoint();
- SetFocus();
-
- HWND hWndOwn = m_hWnd;
- if( ! pPopup->TrackPopupMenu( TPMX_OWNERDRAW_FIXED|TPMX_DO_MESSAGE_LOOP, pos.x, pos.y, NULL, this, NULL, NULL, true ) )
- {
- //ASSERT( FALSE );
- //delete pPopup;
- if( ! ::IsWindow( hWndOwn ) )
- return;
- CEdit::OnContextMenu( pWnd, pos );
- return;
- }
- else
- {
- if( ! ::IsWindow( hWndOwn ) )
- return;
- VERIFY( RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW|RDW_FRAME|RDW_ALLCHILDREN ) );
- }
- }
- __EXT_MFC_INT_PTR CExtEditBase::OnToolHitTest( CPoint point, TOOLINFO * pTI ) const
- {
- __PROF_UIS_MANAGE_STATE;
- __EXT_MFC_IMPLEMENT_TT_REDIR_OnToolHitTest( CExtEditBase, CExtToolControlBar );
- return CEdit::OnToolHitTest( point, pTI );
- }
- COLORREF CExtEditBase::OnQueryBackColor() const
- {
- ASSERT_VALID( this );
- return m_clrBack;
- }
- COLORREF CExtEditBase::OnQueryTextColor() const
- {
- ASSERT_VALID( this );
- return m_clrText;
- }
- void CExtEditBase::InitToolTip()
- {
- if( m_wndToolTip.m_hWnd == NULL )
- {
- m_wndToolTip.Create( this );
- m_wndToolTip.Activate( FALSE );
- }
- }
- int CExtEditBase::OnQueryMaxTipWidth( __EXT_MFC_SAFE_LPCTSTR lpszText )
- {
- lpszText;
- return 250;
- }
- void CExtEditBase::ActivateTooltip(BOOL bActivate)
- {
- if( m_wndToolTip.GetToolCount() == 0 )
- return;
- m_wndToolTip.Activate( bActivate );
- }
- void CExtEditBase::SetTooltipText(
- CExtSafeString * spText,
- BOOL bActivate // = TRUE
- )
- {
- if( spText == NULL )
- return;
- InitToolTip();
- if( m_wndToolTip.GetToolCount() == 0 )
- {
- CRect rectBtn;
- GetClientRect( rectBtn );
- m_wndToolTip.AddTool( this, *spText, rectBtn, 1 );
- }
- CWnd::CancelToolTips();
- m_wndToolTip.UpdateTipText( *spText, this, 1 );
- m_wndToolTip.SetMaxTipWidth( -1 );
- if( spText->Find( _T("r") ) >= 0 )
- m_wndToolTip.SetMaxTipWidth( OnQueryMaxTipWidth( *spText ) );
- m_wndToolTip.Activate( bActivate );
- }
- void CExtEditBase::SetTooltipText(
- CExtSafeString & sText,
- BOOL bActivate // = TRUE
- )
- {
- if( sText.IsEmpty() )
- return;
- InitToolTip();
- if( m_wndToolTip.GetToolCount() == 0 )
- {
- CRect rectBtn;
- GetClientRect(rectBtn);
- m_wndToolTip.AddTool( this, sText, rectBtn, 1 );
- }
- CWnd::CancelToolTips();
- m_wndToolTip.UpdateTipText( sText, this, 1 );
- m_wndToolTip.SetMaxTipWidth( -1 );
- if( sText.Find( _T("r") ) >= 0 )
- m_wndToolTip.SetMaxTipWidth( OnQueryMaxTipWidth( sText ) );
- m_wndToolTip.Activate( bActivate );
- }
- void CExtEditBase::SetTooltipText(
- __EXT_MFC_SAFE_LPCTSTR sText,
- BOOL bActivate // = TRUE
- )
- {
- if( sText == NULL
- || _tcslen( sText ) == 0
- )
- return;
- InitToolTip();
- if( m_wndToolTip.GetToolCount() == 0 )
- {
- CRect rectBtn;
- GetClientRect(rectBtn);
- m_wndToolTip.AddTool(this,sText,rectBtn,1);
- }
- CWnd::CancelToolTips();
- m_wndToolTip.UpdateTipText(sText,this,1);
- m_wndToolTip.SetMaxTipWidth( -1 );
- CExtSafeString strText( sText );
- if( strText.Find( _T("r") ) >= 0 )
- m_wndToolTip.SetMaxTipWidth( OnQueryMaxTipWidth( LPCTSTR(sText) ) );
- m_wndToolTip.Activate(bActivate);
- }
- void CExtEditBase::SetTooltipText(
- int nId,
- BOOL bActivate // = TRUE
- )
- {
- CExtSafeString sText;
- g_ResourceManager->LoadString( sText, nId );
- if( ! sText.IsEmpty() )
- SetTooltipText( &sText, bActivate );
- }
- void CExtEditBase::SetBkColor( COLORREF clrBk )
- {
- ASSERT_VALID( this );
- m_clrBack = clrBk;
- if( GetSafeHwnd() != NULL )
- RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW|RDW_FRAME |RDW_FRAME|RDW_ALLCHILDREN );
- }
- COLORREF CExtEditBase::GetBkColor() const
- {
- ASSERT_VALID( this );
- return OnQueryBackColor();
- }
- void CExtEditBase::SetTextColor( COLORREF clrText )
- {
- ASSERT_VALID( this );
- m_clrText = clrText;
- if( GetSafeHwnd() != NULL )
- Invalidate();
- }
- COLORREF CExtEditBase::GetTextColor() const
- {
- ASSERT_VALID( this );
- return OnQueryTextColor();
- }
- LRESULT CExtEditBase::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch( message )
- {
- case WM_KEYDOWN:
- case WM_KEYUP:
- case WM_SYSKEYDOWN:
- case WM_SYSKEYUP:
- { // block - clipboard commands
- bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
- bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
- bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
- if( ! bAlt )
- {
- if( bCtrl && ! bShift
- && ( INT(wParam) == VK_INSERT
- || INT(wParam) == INT( _T('C') )
- )
- )
- {
- if( message == WM_KEYDOWN )
- SendMessage( WM_COPY, 0, 0 );
- return 0L;
- }
-
- if( ( bCtrl && (!bShift) && int(wParam) == int( _T('V') ) )
- || ( (!bCtrl) && bShift && int(wParam) == VK_INSERT )
- )
- {
- if( message == WM_KEYDOWN && ( GetStyle() & ES_READONLY ) == 0 )
- {
- //SendMessage( WM_PASTE, 0, 0 );
- Default();
- }
- return 0L;
- }
- if( ( bCtrl && (!bShift) && int(wParam) == int( _T('X') ) )
- || ( (!bCtrl) && bShift && int(wParam) == VK_DELETE )
- )
- {
- if( message == WM_KEYDOWN )
- SendMessage( ( ( GetStyle() & ES_READONLY ) == 0 ) ? WM_CUT : WM_COPY, 0, 0 );
- return 0L;
- }
- }
- } // block - clipboard commands
- // if( ( GetStyle() & ES_READONLY ) != 0 )
- // {
- // bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
- // if( ! bAlt )
- // {
- // bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
- // bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
- // if( ( bCtrl
- // && ( wParam == WPARAM('X')
- // || wParam == WPARAM('x')
- // || wParam == WPARAM('V')
- // || wParam == WPARAM('v')
- // || wParam == WPARAM('Z')
- // || wParam == WPARAM('z')
- // )
- // )
- // || ( bShift
- // && ( wParam == VK_INSERT
- // || wParam == VK_DELETE
- // )
- // )
- // || ( ( ! ( bCtrl || bShift ) )
- // && ( wParam == VK_DELETE || wParam == VK_BACK )
- // )
- // )
- // return 0L;
- // }
- // else
- // {
- // if( wParam == VK_BACK )
- // return 0L;
- // }
- // }
- if( m_bHandleAltKeyCodes )
- {
- bool bKeyDown = ( message == WM_KEYDOWN || message == WM_SYSKEYDOWN ) ? true : false;
- switch( wParam )
- {
- case VK_MENU:
- if( bKeyDown )
- {
- if( ( GetStyle() & ES_READONLY ) != 0 )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- }
- m_bAltKeyCodeMode = true;
- g_hWndEditInAltKeyCodeMode = m_hWnd;
- m_nTrackedAltKeyCode = 0L;
- return 0L;
- } // if( bKeyDown )
- else if( m_bAltKeyCodeMode )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- if( m_nTrackedAltKeyCode > 0L )
- {
- USES_CONVERSION;
- WCHAR wstr[2] = { WCHAR(m_nTrackedAltKeyCode), L' ' };
- LPCTSTR str = W2CT( wstr );
- //ReplaceSel( str );
- m_nTrackedAltKeyCode = 0L;
- for( MSG _msg; ::PeekMessage( &_msg, m_hWnd, WM_CHAR, WM_CHAR, PM_REMOVE ); );
- SendMessage( WM_CHAR, WPARAM(str[0]), 1L );
- }
- return 0L;
- } // else if( m_bAltKeyCodeMode )
- break;
- case VK_INSERT:
- case VK_END:
- case VK_DOWN:
- case VK_NEXT:
- case VK_LEFT:
- case 0x0C: // VK_CLEAR
- case VK_RIGHT:
- case VK_HOME:
- case VK_UP:
- case VK_PRIOR:
- if( m_bAltKeyCodeMode )
- {
- if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- }
- if( bKeyDown )
- {
- LONG nAdd = -1L;
- bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
- if( bIsExtendedKey )
- {
- switch( wParam )
- {
- case VK_INSERT: nAdd = 0L; break;
- case VK_END: nAdd = 1L; break;
- case VK_DOWN: nAdd = 2L; break;
- case VK_NEXT: nAdd = 3L; break;
- case VK_LEFT: nAdd = 4L; break;
- case 0x0C: nAdd = 5L; break; // VK_CLEAR
- case VK_RIGHT: nAdd = 6L; break;
- case VK_HOME: nAdd = 7L; break;
- case VK_UP: nAdd = 8L; break;
- case VK_PRIOR: nAdd = 9L; break;
- } // switch( wParam )
- } // if( bIsExtendedKey )
- if( nAdd >= 0L )
- {
- m_nTrackedAltKeyCode *= 10;
- ASSERT( 0L <= nAdd && nAdd <= 9L );
- m_nTrackedAltKeyCode += nAdd;
- }
- } // if( message == WM_KEYDOWN )
- return 0L;
- } // if( m_bAltKeyCodeMode )
- break;
- case VK_NUMPAD0:
- case VK_NUMPAD1:
- case VK_NUMPAD2:
- case VK_NUMPAD3:
- case VK_NUMPAD4:
- case VK_NUMPAD5:
- case VK_NUMPAD6:
- case VK_NUMPAD7:
- case VK_NUMPAD8:
- case VK_NUMPAD9:
- if( m_bAltKeyCodeMode )
- {
- if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- }
- if( bKeyDown )
- {
- bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
- if( bIsExtendedKey )
- {
- m_nTrackedAltKeyCode *= 10;
- LONG nAdd = LONG(wParam) - LONG(VK_NUMPAD0);
- ASSERT( 0L <= nAdd && nAdd <= 9L );
- m_nTrackedAltKeyCode += nAdd;
- } // if( bIsExtendedKey )
- } // if( message == WM_KEYDOWN )
- return 0L;
- } // if( m_bAltKeyCodeMode )
- break;
- case WPARAM('0'):
- case WPARAM('1'):
- case WPARAM('2'):
- case WPARAM('3'):
- case WPARAM('4'):
- case WPARAM('5'):
- case WPARAM('6'):
- case WPARAM('7'):
- case WPARAM('8'):
- case WPARAM('9'):
- if( m_bAltKeyCodeMode )
- {
- if( ! CExtPopupMenuWnd::IsKeyPressed( VK_MENU ) )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- }
- if( bKeyDown )
- {
- bool bIsExtendedKey = ( ( lParam & (1L<<24L) ) == 0 ) ? true : false;
- if( bIsExtendedKey )
- {
- m_nTrackedAltKeyCode *= 10;
- LONG nAdd = LONG(wParam) - LONG('0');
- ASSERT( 0L <= nAdd && nAdd <= 9L );
- m_nTrackedAltKeyCode += nAdd;
- } // if( bIsExtendedKey )
- } // if( message == WM_KEYDOWN )
- return 0L;
- } // if( m_bAltKeyCodeMode )
- break;
- default:
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- } // switch( wParam )
- } // if( m_bHandleAltKeyCodes )
- else
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- } // else from if( m_bHandleAltKeyCodes )
- break;
- case WM_CANCELMODE:
- case WM_ACTIVATE:
- case WM_ACTIVATEAPP:
- case WM_KILLFOCUS:
- case WM_DESTROY:
- case WM_SETTINGCHANGE:
- case WM_DISPLAYCHANGE:
- case WM_SHOWWINDOW:
- case WM_SIZE:
- case WM_WINDOWPOSCHANGING:
- case WM_WINDOWPOSCHANGED:
- case EM_SETSEL:
- case EM_REPLACESEL:
- case EM_UNDO:
- case EM_REDO:
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- case WM_STYLECHANGED:
- if( ( GetStyle() & ES_READONLY ) != 0 )
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- break;
- }
- break;
- case WM_SYSCHAR:
- case WM_CHAR:
- if( ( GetStyle() & ES_READONLY ) != 0
- && (! CExtPopupMenuWnd::IsKeyPressed( VK_CONTROL ) )
- )
- return 0L;
- break;
- case WM_PASTE:
- {
- m_bAltKeyCodeMode = false;
- if( g_hWndEditInAltKeyCodeMode == m_hWnd )
- g_hWndEditInAltKeyCodeMode = NULL;
- m_nTrackedAltKeyCode = 0L;
- }
- break;
- } // switch( message )
- if( message == WM_NOTIFY
- && m_wndToolTip.GetSafeHwnd() != NULL
- && IsWindow( m_wndToolTip.GetSafeHwnd() )
- && ((LPNMHDR)lParam) != NULL
- && ((LPNMHDR)lParam)->hwndFrom == m_wndToolTip.GetSafeHwnd()
- && ((LPNMHDR)lParam)->code == TTN_SHOW
- )
- ::SetWindowPos(
- m_wndToolTip.GetSafeHwnd(),
- HWND_TOP,
- 0,0,0,0,
- SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE
- );
- LRESULT lResult = CEdit::WindowProc( message, wParam, lParam );
- return lResult;
- }
- BOOL CExtEditBase::PreTranslateMessage( MSG * pMsg )
- {
- if( ! CExtPopupMenuWnd::IsMenuTracking() )
- {
- InitToolTip();
- m_wndToolTip.RelayEvent(pMsg);
- }
- return CEdit::PreTranslateMessage( pMsg );
- }
- BOOL CExtEditBase::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
- {
- if( m_bHandleCtxMenus
- && ( nCode == CN_UPDATE_COMMAND_UI
- || nCode == CN_COMMAND
- )
- )
- {
- bool bReadOnly = ( ( GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- DWORD nSelection = GetSel();
- if( nID == ID_EDIT_UNDO )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
- pCmdUI->Enable( ( CanUndo() && (! bReadOnly ) ) ? TRUE : FALSE );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- Undo();
- return TRUE;
- } // if( nID == ID_EDIT_UNDO )
- // if( nID == ID_EDIT_REDO )
- // {
- // if( nCode == CN_UPDATE_COMMAND_UI )
- // {
- // CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- // ASSERT( pCmdUI != NULL );
- // pCmdUI->Enable(
- // (BOOL) ( SendMessage( EM_CANREDO ) && (! bReadOnly )
- // );
- // } // if( nCode == CN_UPDATE_COMMAND_UI )
- // else
- // SendMessage( EM_REDO );
- // return TRUE;
- // } // if( nID == ID_EDIT_REDO )
- if( nID == ID_EDIT_CUT )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
- pCmdUI->Enable( (LOWORD(nSelection)) != (HIWORD(nSelection)) && (! bReadOnly ) );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- SendMessage( WM_CUT );
- return TRUE;
- } // if( nID == ID_EDIT_CUT )
- if( nID == ID_EDIT_COPY )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
- pCmdUI->Enable( (LOWORD(nSelection)) != (HIWORD(nSelection)) );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- SendMessage( WM_COPY );
- return TRUE;
- } // if( nID == ID_EDIT_COPY )
- if( nID == ID_EDIT_PASTE )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
- pCmdUI->Enable(
- ( ::IsClipboardFormatAvailable( CF_TEXT )
- || ( g_PaintManager.m_bIsWinNT4orLater && ::IsClipboardFormatAvailable( CF_UNICODETEXT ) )
- )
- && (! bReadOnly )
- );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- SendMessage( WM_PASTE );
- return TRUE;
- } // if( nID == ID_EDIT_PASTE )
- if( nID == ID_EDIT_CLEAR )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
- pCmdUI->Enable( (LOWORD(nSelection)) != (HIWORD(nSelection)) && (! bReadOnly ) );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- SendMessage( WM_CLEAR );
- return TRUE;
- } // if( nID == ID_EDIT_CLEAR )
- if( nID == ID_EDIT_SELECT_ALL )
- {
- if( nCode == CN_UPDATE_COMMAND_UI )
- {
- CCmdUI * pCmdUI = (CCmdUI *)pExtra;
- ASSERT( pCmdUI != NULL );
-
- int nLength = GetWindowTextLength();
- pCmdUI->Enable(
- nLength > 0
- && (!( (LOWORD(nSelection)) == 0
- && (HIWORD(nSelection)) == nLength
- ))
- );
- } // if( nCode == CN_UPDATE_COMMAND_UI )
- else
- SetSel( 0, -1 );
- return TRUE;
- } // if( nID == ID_EDIT_SELECT_ALL )
- } // if( m_bHandleCtxMenus ...
- return CEdit::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
- }
- HBRUSH CExtEditBase::CtlColor( CDC* pDC, UINT nCtlColor )
- {
- ASSERT_VALID( this );
- if( nCtlColor == CTLCOLOR_EDIT
- || nCtlColor == CTLCOLOR_MSGBOX
- || nCtlColor == CTLCOLOR_STATIC
- )
- {
- CExtPaintManager * pPM = PmBridge_GetPM();
- ASSERT_VALID( pPM );
- bool bReadOnly = ( GetStyle() & ES_READONLY ) != 0;
- bool bDisabled = OnQueryWindowEnabledState() ? false : true;
- COLORREF clrText = GetTextColor();
- if( clrText == COLORREF(-1L) )
- clrText = pPM->GetColor( bDisabled ? CExtPaintManager::CLR_TEXT_DISABLED : COLOR_WINDOWTEXT, this );
- COLORREF clrBk = GetBkColor();
- if( clrBk == COLORREF(-1L) )
- clrBk = pPM->GetColor( ( bReadOnly || bDisabled ) ? CExtPaintManager::CLR_3DFACE_OUT : COLOR_WINDOW, this );
- pDC->SetBkColor( clrBk );
- pDC->SetTextColor( clrText );
- if( m_clrBackPrev != clrBk )
- {
- if( m_brBack.GetSafeHandle() != NULL )
- m_brBack.DeleteObject();
- m_brBack.CreateSolidBrush( clrBk );
- m_clrBackPrev = clrBk;
- }
- return m_brBack;
- }
- else
- return (HBRUSH)Default();
- }
- void CExtEditBase::stat_DoPaintNc(
- bool bEnabled,
- bool bMouseOver,
- CWnd * pWnd,
- CExtPmBridge * pPmBridge,
- CDC * pDC
- )
- {
- ASSERT_VALID( pWnd );
- ASSERT( pWnd->GetSafeHwnd() != NULL );
- ASSERT( pPmBridge != NULL );
- ASSERT_VALID( pDC );
- ASSERT( pDC->GetSafeHdc() != NULL );
- CRect rcInBarWnd, rcInBarClient;
- pWnd->GetWindowRect( &rcInBarWnd );
- pWnd->GetClientRect( &rcInBarClient );
- pWnd->ClientToScreen( &rcInBarClient );
- if( rcInBarWnd == rcInBarClient )
- return;
- CPoint ptDevOffset = -rcInBarWnd.TopLeft();
- rcInBarWnd.OffsetRect( ptDevOffset );
- rcInBarClient.OffsetRect( ptDevOffset );
- const INT cx = ::GetSystemMetrics( SM_CXVSCROLL );
- const INT cy = ::GetSystemMetrics( SM_CYHSCROLL );
- DWORD dwStyle = pWnd->GetStyle();
- bool bHasVerticalSB = ( (dwStyle&WS_VSCROLL) != 0 ) ? true : false;
- bool bHasHorizontalSB = ( (dwStyle&WS_HSCROLL) != 0 ) ? true : false;
- if( bHasVerticalSB && bHasHorizontalSB )
- {
- INT nNcX = rcInBarWnd.right - rcInBarClient.right - cx;
- INT nNcY = rcInBarWnd.bottom - rcInBarClient.bottom - cy;
- pDC->FillSolidRect(
- rcInBarWnd.right - cx - nNcX, rcInBarWnd.bottom - cy - nNcY, cx, cy,
- pPmBridge->PmBridge_GetPM()->GetColor( COLOR_WINDOW, pWnd )
- );
- }
- CRect rcExclude( rcInBarClient );
- if( bHasVerticalSB )
- rcExclude.right += cx;
- if( bHasHorizontalSB )
- rcExclude.bottom += cy;
- #ifndef __EXT_MFC_NO_SPINWND
- CWnd * pWndParent = pWnd->GetParent();
- ASSERT_VALID( pWndParent );
- bool bBuddyWithSpin = false;
- bool bSpinAlignRight = false;
- bool bSpinAlignLeft = false;
- CWnd * pWndTest = pWnd->GetWindow( GW_HWNDNEXT );
- if( pWndTest->GetSafeHwnd() != NULL )
- {
- ASSERT_VALID( pWndTest );
- static const TCHAR szSpin[] = UPDOWN_CLASS;
- TCHAR szCompare[ sizeof(szSpin)/sizeof(szSpin[0]) + 1 ] = _T("");
- ::GetClassName( pWndTest->GetSafeHwnd(), szCompare, sizeof(szCompare)/sizeof(szCompare[0]) );
- if( ! lstrcmpi( szCompare, szSpin ) )
- {
- DWORD dwStyle = pWndTest->GetStyle();
- bSpinAlignRight = ( ( dwStyle & UDS_ALIGNRIGHT ) != 0 ) ? true : false;
- bSpinAlignLeft = ( ( dwStyle & UDS_ALIGNLEFT ) != 0 ) ? true : false;
- bBuddyWithSpin = ( ( dwStyle & UDS_AUTOBUDDY ) != 0 && ( bSpinAlignRight || bSpinAlignLeft ) ) ? true : false;
- }
- }
- if( bBuddyWithSpin )
- {
- CRect rcSpin;
- pWndTest->GetClientRect( &rcSpin );
- if( bSpinAlignRight )
- {
- rcInBarWnd.right += rcSpin.Width();
- rcExclude.right += rcSpin.Width();
- }
- else if( bSpinAlignLeft )
- {
- rcInBarWnd.left -= rcSpin.Width();
- rcExclude.left -= rcSpin.Width();
- }
- }
- #endif // __EXT_MFC_NO_SPINWND
- pDC->ExcludeClipRect( &rcExclude );
- if( bHasVerticalSB || bHasHorizontalSB )
- {
- struct default_friendly_t : public CWnd
- {
- friend void CExtEditBase::stat_DoPaintNc( bool bEnabled, bool bMouseOver, CWnd * pWnd, CExtPmBridge * pPmBridge, CDC * pDC );
- };
- ((default_friendly_t*)pWnd)->Default();
- }
- bool bReadOnly = ( ( pWnd->GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- COLORREF clrSysBk = pPmBridge->PmBridge_GetPM()->GetColor( ( bReadOnly || (!bEnabled) ) ? CExtPaintManager::CLR_3DFACE_OUT : COLOR_WINDOW, pWnd );
- CExtEditBase::stat_DrawEditImpl( bEnabled, bMouseOver, pWnd, pPmBridge, rcInBarWnd, pDC );
- pDC->SelectClipRgn( NULL );
- #ifndef __EXT_MFC_NO_SPINWND
- if( bBuddyWithSpin )
- {
- CRect rcSpinWnd, rcSpinClient;
- pWndTest->GetWindowRect( &rcSpinWnd );
- pWndTest->GetClientRect( &rcSpinClient );
- pWndTest->ClientToScreen( &rcSpinClient );
- CPoint ptDevOffset = -rcSpinWnd.TopLeft();
- rcSpinWnd.OffsetRect( ptDevOffset );
- rcSpinClient.OffsetRect( ptDevOffset );
- __EXT_MFC_LONG_PTR dwExStyle = ::__EXT_MFC_GetWindowLong( pWndTest->GetSafeHwnd(), GWL_EXSTYLE );
- bool bRTL = ( (dwExStyle & WS_EX_LAYOUTRTL) != 0 ) ? true : false;
- if( bRTL )
- rcSpinClient.OffsetRect( -3, 0 );
- CWindowDC dcSpin( pWndTest );
- dcSpin.ExcludeClipRect( &rcSpinClient );
- dcSpin.FillSolidRect( &rcSpinWnd, clrSysBk );
- if( bSpinAlignRight )
- rcSpinWnd.left -= rcInBarClient.Width();
- else if( bSpinAlignLeft )
- rcSpinWnd.right += rcInBarClient.Width();
- CExtEditBase::stat_DrawEditImpl( bEnabled, bMouseOver, pWnd, pPmBridge, rcSpinWnd, &dcSpin );
- dcSpin.SelectClipRgn( NULL );
- }
- #endif // __EXT_MFC_NO_SPINWND
- }
- void CExtEditBase::stat_DrawEditImpl(
- bool bEnabled,
- bool bMouseOver,
- CWnd * pWnd,
- CExtPmBridge * pPmBridge,
- CRect rectClient,
- CDC * pDC
- )
- {
- ASSERT_VALID( pWnd );
- ASSERT( pWnd->GetSafeHwnd() != NULL );
- ASSERT( pPmBridge != NULL );
- ASSERT_VALID( pDC );
- ASSERT( pDC->GetSafeHdc() != NULL );
- bool bNeedReleaseDC = false;
- if( pDC == NULL )
- {
- pDC = pWnd->GetDC();
- bNeedReleaseDC = true;
- }
- ASSERT_VALID( pDC );
- bool bFocus = false;
- if( ::GetFocus() == pWnd->m_hWnd && (! CExtPopupMenuWnd::IsMenuTracking() ) )
- bFocus = true;
- bool bReadOnly = ( ( pWnd->GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- CExtPaintManager::PAINTCONTROLFRAMEDATA _pcfd( pWnd, rectClient, true, bMouseOver, bEnabled, bFocus, bReadOnly );
- pPmBridge->PmBridge_GetPM()->PaintControlFrame( *pDC, _pcfd );
- if( bNeedReleaseDC )
- pWnd->ReleaseDC(pDC);
- }
- void CExtEditBase::stat_PrintClient(
- bool bEnabled,
- bool bMouseOver,
- UINT message,
- LPARAM lParam,
- CWnd * pWnd,
- CExtPmBridge * pPmBridge,
- CDC * pDC
- )
- {
- ASSERT_VALID( pWnd );
- ASSERT( pWnd->GetSafeHwnd() != NULL );
- ASSERT( pPmBridge != NULL );
- ASSERT_VALID( pDC );
- ASSERT( pDC->GetSafeHdc() != NULL );
- CRect rcWnd;
- pWnd->GetWindowRect( &rcWnd );
- rcWnd.OffsetRect( -rcWnd.TopLeft() );
- CExtMemoryDC dc( pDC, &rcWnd, CExtMemoryDC::MDCOPT_TO_MEMORY|CExtMemoryDC::MDCOPT_FILL_BITS|CExtMemoryDC::MDCOPT_RTL_COMPATIBILITY );
- if( (lParam&PRF_NONCLIENT) != 0 )
- CExtEditBase::stat_DoPaintNc( bEnabled, bMouseOver, pWnd, pPmBridge, pDC );
- if( (lParam&PRF_CHILDREN) != 0 )
- CExtPaintManager::stat_PrintChildren( pWnd->m_hWnd, message, dc.GetSafeHdc(), lParam, false );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEdit
- IMPLEMENT_DYNCREATE( CExtEdit, CExtEditBase );
- CExtEdit::CExtEdit()
- {
- }
- CExtEdit::~CExtEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CExtEdit, CExtED < CExtEditBase >)
- //{{AFX_MSG_MAP(CExtEdit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExtIPAddressCtrl
- CTypedPtrList < CPtrList, CExtIPAddressCtrl * > CExtIPAddressCtrl::g_listTargets;
- IMPLEMENT_DYNCREATE( CExtIPAddressCtrl, CIPAddressCtrl );
- IMPLEMENT_CExtPmBridge_MEMBERS( CExtIPAddressCtrl );
- CExtIPAddressCtrl::CExtIPAddressCtrl()
- : m_bDirectCreateCall( false )
- , m_bInitialized( false )
- , m_bMouseOver( false )
- {
- for( INT nIndex = 0; nIndex < 4; nIndex++ )
- {
- m_pWNDPROC[nIndex] = NULL;
- m_hWndHooked[nIndex] = NULL;
- }
- PmBridge_Install();
- }
- CExtIPAddressCtrl::~CExtIPAddressCtrl()
- {
- PmBridge_Uninstall();
- }
- BEGIN_MESSAGE_MAP(CExtIPAddressCtrl, CIPAddressCtrl)
- //{{AFX_MSG_MAP(CExtIPAddressCtrl)
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_WM_SETFOCUS()
- ON_WM_KILLFOCUS()
- ON_WM_NCPAINT()
- ON_WM_SETCURSOR()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CExtIPAddressCtrl message handlers
- BOOL CExtIPAddressCtrl::OnSetCursor( CWnd * pWnd, UINT nHitTest, UINT message )
- {
- if( message == WM_MOUSEMOVE )
- {
- CRect rcWnd;
- GetWindowRect( &rcWnd );
- if( rcWnd.PtInRect( GetCurrentMessage()->pt ) )
- {
- SetTimer( __EXT_EDIT_UPDATE_TIMER, __EXT_EDIT_UPDATE_TIMER_PERIOD, NULL );
- SendMessage( WM_TIMER, __EXT_EDIT_UPDATE_TIMER, 0L );
- }
- }
- return CIPAddressCtrl::OnSetCursor(pWnd, nHitTest, message);
- }
- void CExtIPAddressCtrl::OnTimer( __EXT_MFC_UINT_PTR nIDEvent )
- {
- if( nIDEvent != __EXT_EDIT_UPDATE_TIMER )
- {
- CIPAddressCtrl::OnTimer( nIDEvent );
- return;
- }
- POINT pt;
- if( ! ::GetCursorPos(&pt) )
- return;
- if( IsWindowVisible() )
- {
- bool bOldMouseOver = m_bMouseOver;
- CRect rectItem;
- GetWindowRect( &rectItem );
- if( !rectItem.PtInRect(pt) )
- {
- KillTimer( __EXT_EDIT_UPDATE_TIMER );
- m_bMouseOver = false;
- }
- else
- {
- HWND hWndFromPoint = ::WindowFromPoint( pt );
- if( hWndFromPoint == m_hWnd )
- m_bMouseOver = true;
- else
- {
- for( HWND hWnd = ::GetWindow( m_hWnd, GW_CHILD ); hWnd != NULL; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ) )
- {
- if( hWnd != NULL && ::IsWindow( hWnd ) )
- {
- if( hWnd == hWndFromPoint )
- {
- m_bMouseOver = true;
- break;
- }
- }
- }
- }
- }
- if( bOldMouseOver != m_bMouseOver )
- _PostRedraw();
- } // if( IsWindowVisible() )
- }
- void CExtIPAddressCtrl::_PostRedraw()
- {
- VERIFY(
- RedrawWindow(
- NULL,
- NULL,
- RDW_INVALIDATE | RDW_UPDATENOW
- | RDW_ERASE | RDW_ERASENOW
- | RDW_FRAME | RDW_ALLCHILDREN
- )
- );
- }
- void CExtIPAddressCtrl::_DrawEditImpl(
- CRect rectClient,
- CDC * pDC // = NULL
- )
- {
- bool bNeedReleaseDC = false;
- if( pDC == NULL )
- {
- pDC = GetDC();
- bNeedReleaseDC = true;
- }
- ASSERT_VALID( pDC );
- bool bFocus = false;
- if( ! CExtPopupMenuWnd::IsMenuTracking() )
- {
- HWND hWndFocused = GetFocus()->GetSafeHwnd();
- if( hWndFocused == m_hWnd )
- bFocus = true;
- else
- {
- for( HWND hWnd = ::GetWindow( m_hWnd, GW_CHILD ); hWnd != NULL; hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ) )
- {
- if( hWnd != NULL && ::IsWindow( hWnd ) )
- {
- if( hWnd == hWndFocused )
- {
- bFocus = true;
- break;
- }
- }
- }
- }
- }
- rectClient.InflateRect( 3, 3 );
- bool bEnabled = IsWindowEnabled() ? true : false;
- bool bReadOnly = ( ( GetStyle() & ES_READONLY ) != 0 ) ? true : false;
- CExtPaintManager::PAINTCONTROLFRAMEDATA _pcfd( this, rectClient, true, m_bMouseOver, bEnabled, bFocus, bReadOnly );
- PmBridge_GetPM()->PaintControlFrame( *pDC, _pcfd );
- if( bNeedReleaseDC )
- ReleaseDC(pDC);
- }
- void CExtIPAddressCtrl::OnSetFocus(CWnd* pOldWnd)
- {
- CIPAddressCtrl::OnSetFocus(pOldWnd);
- _PostRedraw();
- }
- void CExtIPAddressCtrl::OnKillFocus(CWnd* pNewWnd)
- {
- CIPAddressCtrl::OnKillFocus(pNewWnd);
- _PostRedraw();
- }
- void CExtIPAddressCtrl::OnNcPaint()
- {
- ASSERT_VALID( this );
- CWindowDC dc( this );
- _DoPaintNC( &dc );
- }
- void CExtIPAddressCtrl::_DoPaintNC( CDC * pDC )
- {
- ASSERT_VALID( this );
- ASSERT_VALID( pDC );
- ASSERT( pDC->GetSafeHdc() != NULL );
- if( ! m_bInitialized )
- return;
- CRect rcInBarWnd, rcInBarClient;
- GetWindowRect( &rcInBarWnd );
- GetClientRect( &rcInBarClient );
- ClientToScreen( &rcInBarClient );
- if( rcInBarWnd == rcInBarClient )
- return;
- CPoint ptDevOffset = -rcInBarWnd.TopLeft();
- rcInBarWnd.OffsetRect( ptDevOffset );
- rcInBarClient.OffsetRect( ptDevOffset );
- const INT cx = ::GetSystemMetrics( SM_CXVSCROLL );
- const INT cy = ::GetSystemMetrics( SM_CYHSCROLL );
- DWORD dwStyle = GetStyle();
- bool bHasVerticalSB = ( ( dwStyle & WS_VSCROLL ) != 0 ) ? true : false;
- bool bHasHorizontalSB = ( ( dwStyle & WS_HSCROLL ) != 0 ) ? true : false;
- if( bHasVerticalSB && bHasHorizontalSB )
- {
- INT nNcX = rcInBarWnd.right - rcInBarClient.right - cx;
- INT nNcY = rcInBarWnd.bottom - rcInBarClient.bottom - cy;
- pDC->FillSolidRect(
- rcInBarWnd.right - cx - nNcX, rcInBarWnd.bottom - cy - nNcY, cx, cy,
- PmBridge_GetPM()->GetColor( COLOR_WINDOW, this )
- );
- }
- CRect rcExclude( rcInBarClient );
- if( bHasVerticalSB )
- rcExclude.right += cx;
- if( bHasHorizontalSB )
- rcExclude.bottom += cy;
- pDC->ExcludeClipRect( &rcExclude );
- if( bHasVerticalSB || bHasHorizontalSB )
- Default();
- rcInBarWnd.DeflateRect( 3, 3 );
- _DrawEditImpl( rcInBarWnd, pDC );
- pDC->SelectClipRgn( NULL );
- }
- LRESULT CExtIPAddressCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- if( message == WM_PRINT
- || message == WM_PRINTCLIENT
- )
- {
- CDC * pDC = CDC::FromHandle( (HDC) wParam );
- CRect rcWnd;
- GetWindowRect( &rcWnd );
- rcWnd.OffsetRect( -rcWnd.TopLeft() );
- CExtMemoryDC dc( pDC, &rcWnd );
- if( ( lParam & PRF_NONCLIENT ) != 0 )
- _DoPaintNC( &dc );
- if( ( lParam & PRF_CHILDREN ) != 0 )
- CExtPaintManager::stat_PrintChildren( m_hWnd, message, dc.GetSafeHdc(), lParam, false );
- return (!0);
- }
- return CIPAddressCtrl::WindowProc(message, wParam, lParam);
- }
- void CExtIPAddressCtrl::OnDestroy()
- {
- POSITION pos = g_listTargets.Find( this );
- if( pos == NULL )
- return;
- g_listTargets.RemoveAt( pos );
- for( INT nIndexWnd = 0; nIndexWnd < 4; nIndexWnd++ )
- {
- if( m_hWndHooked[ nIndexWnd ] != NULL
- && ::IsWindow(m_hWndHooked[ nIndexWnd ])
- && m_pWNDPROC[ nIndexWnd ] != NULL
- )
- {
- ::__EXT_MFC_SetWindowLong(
- m_hWndHooked[ nIndexWnd ],
- __EXT_MFC_GWL_WNDPROC,
- #if defined(_WIN64)
- (__EXT_MFC_LONG_PTR)
- #else
- (LONG)(__EXT_MFC_LONG_PTR)
- #endif
- m_pWNDPROC[ nIndexWnd ]
- );
- }
- }
- CIPAddressCtrl::OnDestroy();
- }
- LRESULT CALLBACK CExtIPAddressCtrl::g_HookWndProc( HWND hWnd, UINT nMessage, WPARAM wParam, LPARAM lParam )
- {
- for( POSITION pos = g_listTargets.GetHeadPosition(); pos != NULL; )
- {
- CExtIPAddressCtrl * pWndTarget = g_listTargets.GetNext( pos );
- if( pWndTarget != NULL && pWndTarget->GetSafeHwnd() != NULL )
- {
- if( nMessage == WM_SETCURSOR )
- ::SendMessage( pWndTarget->m_hWnd, nMessage, wParam, lParam );
- else if( nMessage == WM_SETFOCUS || nMessage == WM_KILLFOCUS )
- pWndTarget->RedrawWindow( NULL, NULL, RDW_INVALIDATE|RDW_UPDATENOW|RDW_ERASE|RDW_ERASENOW|RDW_FRAME|RDW_ALLCHILDREN );
- for( INT nIndexWnd = 0; nIndexWnd < 4; nIndexWnd++ )
- {
- HWND hWndHooked = pWndTarget->m_hWndHooked[ nIndexWnd ];
- WNDPROC pWNDPROC = pWndTarget->m_pWNDPROC[ nIndexWnd ];
- if( hWndHooked != NULL && ::IsWindow(hWndHooked) && hWndHooked == hWnd )
- {
- ASSERT( pWNDPROC != NULL );
- return ::CallWindowProc( pWNDPROC, hWnd, nMessage, wParam, lParam );
- }
- }
- }
- } // for( POSITION pos = g_listTargets.GetHeadPosition(); pos != NULL; )
- return 0L;
- }
- void CExtIPAddressCtrl::PreSubclassWindow()
- {
- CIPAddressCtrl::PreSubclassWindow();
- if( m_bDirectCreateCall )
- return;
- if( ! _CreateHelper() )
- {
- ASSERT( FALSE );
- return;
- }
- m_bInitialized = true;
- }
- BOOL CExtIPAddressCtrl::Create(
- DWORD dwStyle,
- const RECT & rect,
- CWnd * pParentWnd,
- UINT nID
- )
- {
- if( ! CIPAddressCtrl::Create( dwStyle, rect, pParentWnd, nID ) )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- return TRUE;
- }
- BOOL CExtIPAddressCtrl::Create(
- LPCTSTR lpszClassName,
- LPCTSTR lpszWindowName,
- DWORD dwStyle,
- const RECT & rect,
- CWnd * pParentWnd,
- UINT nID, CCreateContext * pContext
- )
- {
- ASSERT_VALID( this );
- m_bDirectCreateCall = true;
- if( ! CWnd::Create( lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext ) )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- if( ! _CreateHelper() )
- {
- ASSERT( FALSE );
- return FALSE;
- }
- m_bInitialized = true;
- return TRUE;
- }
- bool CExtIPAddressCtrl::_CreateHelper()
- {
- ASSERT_VALID( this );
- if( m_bInitialized )
- return true;
- if( m_hWnd == NULL || ( !::IsWindow( m_hWnd ) ) )
- return false;
- // hook all the child edit controls
- POSITION pos = g_listTargets.Find( this );
- if( pos == NULL )
- g_listTargets.AddHead( this );
- bool bInit = false;
- INT nIndexWnd = 0;
- for( HWND hWnd = ::GetWindow( m_hWnd, GW_CHILD ); ((hWnd != NULL) && (nIndexWnd < 4)); hWnd = ::GetWindow( hWnd, GW_HWNDNEXT ), nIndexWnd++ )
- {
- m_hWndHooked[ nIndexWnd ] = hWnd;
- if( m_hWndHooked[ nIndexWnd ] == NULL || (!::IsWindow(m_hWndHooked[ nIndexWnd ])) )
- {
- ASSERT( FALSE );
- bInit = false;
- break;
- }
- bInit = true;
- m_pWNDPROC[ nIndexWnd ] = (WNDPROC)(__EXT_MFC_LONG_PTR)
- ::__EXT_MFC_SetWindowLong(
- m_hWndHooked[ nIndexWnd ],
- __EXT_MFC_GWL_WNDPROC,
- #if defined(_WIN64)
- (__EXT_MFC_LONG_PTR)
- #else
- (LONG)(__EXT_MFC_LONG_PTR)
- #endif
- g_HookWndProc
- );
- ASSERT( m_pWNDPROC[ nIndexWnd ] != NULL );
- }
- if( ! bInit )
- return false;
- return true;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditHotKeyBase window
- IMPLEMENT_DYNCREATE( CExtEditHotKeyBase, CExtEditBase );
- CExtEditHotKeyBase::CExtEditHotKeyBase()
- : m_bAllowTabKeyInput( false )
- , m_nSimpleKeyModifiers( (BYTE)0 )
- {
- ::memset( &m_dataAccel, 0, sizeof(ACCEL) );
- }
- CExtEditHotKeyBase::~CExtEditHotKeyBase()
- {
- }
- BEGIN_MESSAGE_MAP( CExtEditHotKeyBase, CExtEditBase )
- //{{AFX_MSG_MAP(CExtEditHotKeyBase)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- CExtSafeString CExtEditHotKeyBase::stat_GetSingleKeyName(
- HKL hKeyboardLayout,
- WORD nKey,
- __EXT_MFC_SAFE_LPCTSTR strAppendIfNonEmpty, // = NULL
- bool bMakeOnlyFirstLettersUpper // = true
- )
- {
- UINT nScan = ::MapVirtualKeyEx( (UINT)nKey, 0, hKeyboardLayout );
- nScan &= 0x0FFFF;
- switch( nKey )
- {
- case VK_INSERT:
- case VK_DELETE:
- case VK_PRIOR:
- case VK_NEXT:
- case VK_END:
- case VK_HOME:
- case VK_LEFT:
- case VK_UP:
- case VK_RIGHT:
- case VK_DOWN:
- case VK_SELECT:
- case VK_PRINT:
- case VK_EXECUTE:
- case VK_SNAPSHOT:
- case VK_HELP:
- nScan |= 0x0300;
- break;
- } // switch( nKey )
- LPARAM lParam = MAKELPARAM( 1, nScan );
- const int nMaxKeyName = 256;
- CExtSafeString strKeyText;
- LPTSTR pBuffer = strKeyText.GetBuffer(nMaxKeyName);
- ASSERT( pBuffer != NULL );
- ::memset( pBuffer, 0, nMaxKeyName*sizeof(TCHAR) );
- ::GetKeyNameText( (LONG)lParam, pBuffer, nMaxKeyName );
- strKeyText.ReleaseBuffer();
- if( strKeyText.IsEmpty())
- return strKeyText;
- if( ! bMakeOnlyFirstLettersUpper )
- {
- if( strAppendIfNonEmpty != NULL )
- strKeyText += strAppendIfNonEmpty;
- return strKeyText;
- }
- strKeyText.MakeLower();
- bool bPrevSpace = true;
- for( int i = 0; i < strKeyText.GetLength(); i++ )
- {
- TCHAR chr = strKeyText[i];
- if( _istspace(chr) )
- {
- bPrevSpace = true;
- continue;
- } // if( _istspace(chr) )
- if( _istalpha(chr) && bPrevSpace )
- {
- chr = (TCHAR)_totupper( chr );
- strKeyText.SetAt( i, chr );
- } // if( _istalpha(chr) && bPrevSpace )
- bPrevSpace = false;
- } // for( int i = 0; i < strKeyText.GetLength(); i++ )
- if( strAppendIfNonEmpty != NULL )
- strKeyText += strAppendIfNonEmpty;
- return strKeyText;
- }
- CExtSafeString CExtEditHotKeyBase::stat_FormatAccelText( const ACCEL & _dataAccel )
- {
- HKL hKeyboardLayout = ::GetKeyboardLayout( ( ::AfxGetThread() ) -> m_nThreadID );
- static TCHAR strTextBetweenKeys[] = _T("+");
- CExtSafeString strAccelText;
- if( _dataAccel.fVirt & FCONTROL )
- strAccelText += CExtEditHotKeyBase::stat_GetSingleKeyName( hKeyboardLayout, VK_CONTROL, strTextBetweenKeys );
- if( _dataAccel.fVirt & FSHIFT )
- strAccelText += CExtEditHotKeyBase::stat_GetSingleKeyName( hKeyboardLayout, VK_SHIFT, strTextBetweenKeys );
- if( _dataAccel.fVirt & FALT )
- strAccelText += CExtEditHotKeyBase::stat_GetSingleKeyName( hKeyboardLayout, VK_MENU, strTextBetweenKeys );
- if( _dataAccel.key == 0 )
- return strAccelText;
- if( _dataAccel.fVirt & FVIRTKEY )
- strAccelText += CExtEditHotKeyBase::stat_GetSingleKeyName( hKeyboardLayout, _dataAccel.key );
- else
- strAccelText += (TCHAR)_dataAccel.key;
- return strAccelText;
- }
- void CExtEditHotKeyBase::_SyncEditText()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL || ( ! ::IsWindow(GetSafeHwnd()) ) )
- return;
- CExtSafeString strText = OnGetAccelText();
- SetRedraw( FALSE );
- CExtEditBase::SetSel( 0, -1 );
- CExtEditBase::ReplaceSel( strText );
- CExtEditBase::SetSel( -1, -1 );
- SetRedraw( TRUE );
- Invalidate();
- }
- bool CExtEditHotKeyBase::IsAccelDefined() const
- {
- if( KeyGet() != 0 )
- return true;
- return false;
- }
- bool CExtEditHotKeyBase::IsEmpty() const
- {
- ASSERT_VALID( this );
- if( KeyGet() == 0 && ModifiersGet() == 0 )
- return true;
- return false;
- }
- void CExtEditHotKeyBase::Empty()
- {
- _Empty();
- _SyncEditText();
- }
- void CExtEditHotKeyBase::_Empty()
- {
- ASSERT_VALID( this );
- ::memset( &m_dataAccel, 0, sizeof(ACCEL) );
- }
- const ACCEL & CExtEditHotKeyBase::AccelGet() const
- {
- ASSERT_VALID( this );
- return m_dataAccel;
- }
- void CExtEditHotKeyBase::AccelSet( const ACCEL & _dataAccel )
- {
- ASSERT_VALID( this );
- __EXT_MFC_MEMCPY( &m_dataAccel, sizeof(ACCEL), &_dataAccel, sizeof(ACCEL) );
- _SyncEditText();
- }
- WORD CExtEditHotKeyBase::KeyGet() const
- {
- ASSERT_VALID( this );
- return m_dataAccel.key;
- }
- void CExtEditHotKeyBase::KeySet( WORD nKey )
- {
- ASSERT_VALID( this );
- if( m_dataAccel.key == nKey )
- return;
- m_dataAccel.key = nKey;
- _SyncEditText();
- OnAccelChanged();
- if( IsAccelDefined() )
- OnAccelDefined();
- }
- BYTE CExtEditHotKeyBase::ModifiersGet() const
- {
- ASSERT_VALID( this );
- return m_dataAccel.fVirt;
- }
- void CExtEditHotKeyBase::ModifiersSet( BYTE nModifiers )
- {
- ASSERT_VALID( this );
- if( m_dataAccel.fVirt == nModifiers )
- return;
- m_dataAccel.fVirt = nModifiers;
- _SyncEditText();
- OnAccelChanged();
- if( IsAccelDefined() )
- OnAccelDefined();
- }
- BYTE CExtEditHotKeyBase::SimpleKeyModifiersGet() const
- {
- ASSERT_VALID( this );
- return m_nSimpleKeyModifiers;
- }
- void CExtEditHotKeyBase::SimpleKeyModifiersSet(
- BYTE nModifiers
- )
- {
- ASSERT_VALID( this );
- m_nSimpleKeyModifiers = nModifiers;
- m_nSimpleKeyModifiers &= FCONTROL|FALT|FSHIFT;
- }
- bool CExtEditHotKeyBase::AllowTabKeyInputGet() const
- {
- ASSERT_VALID( this );
- return m_bAllowTabKeyInput;
- }
- void CExtEditHotKeyBase::AllowTabKeyInputSet(
- bool bAllowTabKeyInput
- )
- {
- ASSERT_VALID( this );
- m_bAllowTabKeyInput = bAllowTabKeyInput;
- }
- CExtSafeString CExtEditHotKeyBase::OnGetEmptyText()
- {
- ASSERT_VALID( this );
- return CExtSafeString( _T("") );
- }
- CExtSafeString CExtEditHotKeyBase::OnGetAccelText()
- {
- ASSERT_VALID( this );
- if( IsEmpty() )
- return OnGetEmptyText();
- CExtSafeString strText = stat_FormatAccelText( m_dataAccel );
- return strText;
- }
- bool CExtEditHotKeyBase::OnTestEraseAccel(
- const ACCEL & _dataAccel
- )
- {
- ASSERT_VALID( this );
- if( ( _dataAccel.key == VK_BACK
- || _dataAccel.key == VK_DELETE
- || _dataAccel.key == VK_ESCAPE
- )
- && ( _dataAccel.fVirt&(FCONTROL|FALT|FSHIFT) ) == 0
- )
- return true;
- return false;
- }
- bool CExtEditHotKeyBase::OnAccelChanging( const ACCEL & _dataAccelOld, const ACCEL & _dataAccelNew )
- {
- ASSERT_VALID( this );
- _dataAccelOld;
- _dataAccelNew;
- return true; // allow any changes
- }
- void CExtEditHotKeyBase::OnAccelChanged()
- {
- ASSERT_VALID( this );
- }
- void CExtEditHotKeyBase::OnAccelDefined()
- {
- ASSERT_VALID( this );
- }
- bool CExtEditHotKeyBase::OnTestSimpleKey( WORD nKey )
- {
- ASSERT_VALID( this );
- if( ( 0x30 <= nKey && nKey <= 0x39 ) // Numbers
- || ( 0x41 <= nKey && nKey <= 0x5A ) // Letters
- || nKey == VK_SPACE
- || nKey == 0xC0 // '`'
- || nKey == 0xBD // '-'
- || nKey == 0xBB // '='
- || nKey == 0xDC // '\'
- || nKey == 0xDB // '['
- || nKey == 0xDD // ']'
- || nKey == 0xBA // ';'
- || nKey == 0xDE // '''
- || nKey == 0xBC // ','
- || nKey == 0xBE // '.'
- || nKey == 0xBF // '/'
- || nKey == VK_LEFT
- || nKey == VK_RIGHT
- || nKey == VK_UP
- || nKey == VK_DOWN
- || nKey == VK_INSERT
- || nKey == VK_DELETE
- || nKey == VK_HOME
- || nKey == VK_END
- || nKey == VK_PRIOR
- || nKey == VK_NEXT
- )
- return true;
- return false;
- }
- bool CExtEditHotKeyBase::OnTestDisabledKey( WORD nKey )
- {
- ASSERT_VALID( this );
- if( nKey == VK_NUMLOCK
- || nKey == VK_PRINT
- || nKey == VK_PAUSE
- )
- return true;
- return false;
- }
- BOOL CExtEditHotKeyBase::PreTranslateMessage( MSG * pMsg )
- {
- ASSERT_VALID( this );
- if( pMsg->message != WM_KEYDOWN
- && pMsg->message != WM_KEYUP
- && pMsg->message != WM_SYSKEYDOWN
- && pMsg->message != WM_SYSKEYUP
- )
- return CExtEditBase::PreTranslateMessage( pMsg );
- if( OnTestDisabledKey( (WORD)pMsg->wParam ) )
- return TRUE;
- HWND hWndFocus = ::GetFocus();
- if( hWndFocus == NULL || hWndFocus != m_hWnd )
- return CExtEditBase::PreTranslateMessage( pMsg );
- bool bDown = ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN ) ? true : false;
- if( ! bDown )
- return TRUE;
- bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
- bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
- bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
- if( pMsg->wParam == VK_TAB && (!AllowTabKeyInputGet()) )
- {
- if( bAlt || bCtrl )
- return TRUE;
- ::SendMessage( ::GetParent(m_hWnd), WM_NEXTDLGCTL, bShift ? 1 : 0, 0 );
- return TRUE;
- } // if( pMsg->wParam == VK_TAB && (!AllowTabKeyInputGet()) )
- ACCEL _dataAccelSave;
- __EXT_MFC_MEMCPY(
- &_dataAccelSave,
- sizeof(ACCEL),
- &m_dataAccel,
- sizeof(ACCEL)
- );
- _Empty();
- m_dataAccel.fVirt &= ~(FCONTROL|FALT|FSHIFT);
- if( pMsg->wParam != VK_CONTROL
- && pMsg->wParam != VK_MENU
- && pMsg->wParam != VK_SHIFT
- )
- {
- m_dataAccel.fVirt |= FVIRTKEY;
- m_dataAccel.key = (WORD)pMsg->wParam;
- }
- else
- m_dataAccel.key = 0;
- if( bCtrl )
- m_dataAccel.fVirt |= FCONTROL;
- if( bAlt )
- m_dataAccel.fVirt |= FALT;
- if( bShift )
- m_dataAccel.fVirt |= FSHIFT;
- if( ( m_dataAccel.fVirt&(FCONTROL|FALT|FSHIFT) ) == 0
- && SimpleKeyModifiersGet() != 0
- && OnTestSimpleKey( m_dataAccel.key )
- )
- m_dataAccel.fVirt |= SimpleKeyModifiersGet();
- if( OnTestEraseAccel(m_dataAccel) )
- _Empty();
- if( ::memcmp( &_dataAccelSave, &m_dataAccel, sizeof(ACCEL) ) == 0 )
- return TRUE;
- if( ! OnAccelChanging( _dataAccelSave, m_dataAccel ) )
- {
- __EXT_MFC_MEMCPY( &m_dataAccel, sizeof(ACCEL), &_dataAccelSave, sizeof(ACCEL) );
- return TRUE;
- }
- _SyncEditText();
- OnAccelChanged();
- if( IsAccelDefined() )
- OnAccelDefined();
- return TRUE;
- }
- LRESULT CExtEditHotKeyBase::WindowProc(
- UINT message,
- WPARAM wParam,
- LPARAM lParam
- )
- {
- if( WM_KEYFIRST <= message && message <= WM_KEYLAST )
- return 0;
- if( message == WM_COPY
- || message == WM_CUT
- || message == WM_PASTE
- || message == WM_CLEAR
- || message == EM_UNDO
- )
- return 0;
- if( message == WM_RBUTTONUP
- || message == WM_RBUTTONDOWN
- || message == WM_RBUTTONDBLCLK
- )
- {
- if( ::GetFocus() != m_hWnd )
- SetFocus();
- return 0;
- }
- return CExtEditBase::WindowProc( message, wParam, lParam );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditHotKey
- IMPLEMENT_DYNCREATE( CExtEditHotKey, CExtEditHotKeyBase );
- CExtEditHotKey::CExtEditHotKey()
- {
- }
- CExtEditHotKey::~CExtEditHotKey()
- {
- }
- BEGIN_MESSAGE_MAP(CExtEditHotKey, CExtED < CExtEditHotKeyBase >)
- //{{AFX_MSG_MAP(CExtEditHotKey)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- void AFXAPI __EXT_MFC_DDX_HotKey( CDataExchange * pDX, INT nIDC, ACCEL & value )
- {
- HWND hWndCtrl = pDX->PrepareCtrl( nIDC );
- ASSERT( hWndCtrl != NULL );
- ASSERT( ::IsWindow( hWndCtrl ) );
- CExtEditHotKey * pWnd =
- DYNAMIC_DOWNCAST( CExtEditHotKey, CWnd::FromHandle( hWndCtrl ) );
- if( pWnd != NULL )
- {
- ASSERT_VALID( pWnd );
- if( pDX->m_bSaveAndValidate )
- value = pWnd->AccelGet();
- else
- pWnd->AccelSet( value );
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditWithBehavior
- IMPLEMENT_DYNAMIC( CExtEditWithBehavior, CExtEdit );
- CExtEditWithBehavior::CExtEditWithBehavior()
- : m_nInternalFlags( __EISF_CLEAN )
- , m_bRichPainting( false )
- , m_clrRichTextNormal( COLORREF(-1L) )
- , m_clrRichTextReadOnly( COLORREF(-1L) )
- , m_clrRichTextDisabled( COLORREF(-1L) )
- , m_clrRichBackNormal( COLORREF(-1L) )
- , m_clrRichBackReadOnly( COLORREF(-1L) )
- , m_clrRichBackDisabled( COLORREF(-1L) )
- {
- }
- CExtEditWithBehavior::~CExtEditWithBehavior()
- {
- }
- BEGIN_MESSAGE_MAP( CExtEditWithBehavior, CExtEdit )
- //{{AFX_MSG_MAP(CExtEditWithBehavior)
- ON_WM_KEYDOWN()
- // ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
- // ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
- //}}AFX_MSG_MAP
- ON_MESSAGE( WM_CUT, OnCut )
- ON_MESSAGE( WM_PASTE, OnPaste )
- ON_MESSAGE( WM_CLEAR, OnClear )
- ON_MESSAGE( WM_SETTEXT, OnSetText )
- ON_NOTIFY_REFLECT( EN_PROTECTED, OnProtected )
- END_MESSAGE_MAP()
- void CExtEditWithBehavior::PreSubclassWindow()
- {
- CExtEdit::PreSubclassWindow();
- m_bRichMode = false;
- CExtSafeString sClassName;
- ::GetClassName( m_hWnd, LPTSTR( sClassName.GetBuffer( _MAX_PATH+1 ) ), _MAX_PATH );
- sClassName.ReleaseBuffer();
- sClassName.MakeLower();
- if( sClassName.Find( _T("rich") ) >= 0 )
- {
- m_bRichMode = true;
- m_bRichPainting = true;
- ::SendMessage( m_hWnd, EM_SETEVENTMASK, 0, ENM_CHANGE|ENM_SELCHANGE|ENM_PROTECTED );
- ::SendMessage( m_hWnd, EM_SETOPTIONS, WPARAM(ECOOP_AND), LPARAM(ECO_AUTOWORDSELECTION|ECO_AUTOHSCROLL /*|ECO_NOHIDESEL*/ ) );
- static CExtNotImplRichEditOleCallBack g_stat_cb_not_impl;
- ::SendMessage( m_hWnd, EM_SETOLECALLBACK, 0, (LPARAM)(&g_stat_cb_not_impl) );
- CHARFORMAT cfDefault;
- ::memset( &cfDefault, 0, sizeof(CHARFORMAT) );
- cfDefault.cbSize = 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 );
- cfDefault.bCharSet = DEFAULT_CHARSET;
- 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) )
- cfDefault.crTextColor = ::GetSysColor( bEnabled ? ( bReadOnly ? COLOR_3DSHADOW : COLOR_WINDOWTEXT ) : COLOR_GRAYTEXT );
- }
- COLORREF clrBack = OnQueryBackColor();
- if( clrBack == COLORREF(-1L) )
- {
- clrBack = bEnabled ? ( bReadOnly ? m_clrRichBackReadOnly : m_clrRichBackNormal ) : m_clrRichBackDisabled;
- if( clrBack == COLORREF(-1L) )
- clrBack = ::GetSysColor( bEnabled ? ( bReadOnly ? COLOR_3DFACE : COLOR_WINDOW ) : 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 );
- Rich_SetSel( crRestore );
- Rich_HideSelection( false, false );
- m_bRichPainting = false;
- }
- }
- LRESULT CExtEditWithBehavior::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // if( WM_KEYFIRST <= message && message <= WM_KEYLAST )
- // {
- // bool bAlt = ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 ) ? true : false;
- // bool bCtrl = ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 ) ? true : false;
- // bool bShift = ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 ) ? true : false;
- // if( ! bAlt )
- // {
- // if( bCtrl && ! bShift
- // && ( INT(wParam) == VK_INSERT
- // || INT(wParam) == INT( _T('C') )
- // )
- // )
- // {
- // if( message == WM_KEYDOWN )
- // SendMessage( WM_COPY, 0, 0 );
- // return 0L;
- // }
- //
- // if( ( bCtrl && (!bShift) && int(wParam) == int( _T('V') ) )
- // || ( (!bCtrl) && bShift && int(wParam) == VK_INSERT )
- // )
- // {
- // if( message == WM_KEYDOWN && ( GetStyle() & ES_READONLY ) == 0 )
- // SendMessage( WM_PASTE, 0, 0 );
- // return 0L;
- // }
- // if( ( bCtrl && (!bShift) && int(wParam) == int( _T('X') ) )
- // || ( (!bCtrl) && bShift && int(wParam) == VK_DELETE )
- // )
- // {
- // if( message == WM_KEYDOWN )
- // SendMessage( ( ( GetStyle() & ES_READONLY ) == 0 ) ? WM_CUT : WM_COPY, 0, 0 );
- // return 0L;
- // }
- // }
- // }
- return CExtEdit::WindowProc( message, wParam, lParam );
- }
- void CExtEditWithBehavior::OnProtected( NMHDR * pNMHDR, LRESULT * pResult )
- {
- ASSERT_VALID( this );
- if( ! m_bRichMode )
- return;
- ENPROTECTED * pEP = (ENPROTECTED*)pNMHDR;
- (*pResult) = _Rich_OnProtected( pEP );
- }
- BOOL CExtEditWithBehavior::_Rich_OnProtected( ENPROTECTED * pEP )
- {
- ASSERT_VALID( this );
- if( pEP->msg != EM_SETCHARFORMAT )
- {
- _Rich_OnDraw();
- //HWND hWndParent = ::GetParent( m_hWnd );
- //::SendMessage( hWndParent, WM_COMMAND, MAKEWPARAM( GetDlgCtrlID(), EN_CHANGE ), LPARAM(m_hWnd) );
- }
- return FALSE;
- }
- CExtSafeString CExtEditWithBehavior::TextGet() const
- {
- ASSERT_VALID( this );
- CExtSafeString strRetVal( _T("") );
- if( GetSafeHwnd() == NULL )
- return strRetVal;
- if( m_bRichMode )
- strRetVal = Rich_PlainText_Get();
- else
- {
- CString strText;
- GetWindowText( strText );
- strRetVal = LPCTSTR(strText);
- }
- return strRetVal;
- }
- CExtSafeString CExtEditWithBehavior::TextGetTrimmed() const
- {
- ASSERT_VALID( this );
- CExtSafeString strText = TextGet();
- strText.TrimLeft();
- strText.TrimRight();
- return CExtSafeString( strText );
- }
- void CExtEditWithBehavior::TextSet( __EXT_MFC_SAFE_LPCTSTR strText )
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- LPCTSTR strTextToSet = (LPCTSTR(strText) != NULL) ? LPCTSTR(strText) : _T("");
- if( m_bRichMode )
- {
- ASSERT( ! m_bRichPainting );
- Rich_PlainText_Set( strTextToSet );
- _Rich_OnDraw();
- }
- else
- SetWindowText( strTextToSet );
- }
- void CExtEditWithBehavior::_Rich_OnDraw()
- {
- ASSERT_VALID( this );
- // if( ! m_bRichMode )
- // return;
- // if( GetSafeHwnd() == NULL )
- // return;
- // if( m_bRichPainting )
- // return;
- // m_bRichPainting = true;
- // . . .
- // m_bRichPainting = false;
- }
- CExtSafeString CExtEditWithBehavior::TextGetValid() const
- {
- ASSERT_VALID( this );
- return TextGet();
- }
- void CExtEditWithBehavior::_UpdateContent()
- {
- ASSERT_VALID( this );
- if( GetSafeHwnd() == NULL )
- return;
- CExtSafeString strTextValid = TextGetValid();
- CExtSafeString strTextCurrent = TextGet();
- if( strTextValid != strTextCurrent )
- {
- //SetWindowText( LPCTSTR(strTextValid) );
- LPCTSTR strTextToSet = (LPCTSTR(strTextValid) != NULL) ? LPCTSTR(strTextValid) : _T("");
- if( m_bRichMode )
- {
- ASSERT( ! m_bRichPainting );
- Rich_PlainText_Set( strTextToSet );
- _Rich_OnDraw();
- }
- else
- SetWindowText( strTextToSet );
- }
- }
- bool CExtEditWithBehavior::Behavior_OnQueryCharEnabledTyping( __EXT_MFC_SAFE_TCHAR _tchr ) const
- {
- ASSERT_VALID( this );
- _tchr;
- return true;
- }
- LRESULT CExtEditWithBehavior::OnCut( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- int nStart, nEnd;
- GetSel( nStart, nEnd );
- if( nStart < nEnd )
- {
- SendMessage( WM_COPY );
- SendMessage( WM_KEYDOWN, VK_DELETE );
- }
- return 0;
- }
-
- LRESULT CExtEditWithBehavior::OnClear( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- lParam;
- int nStart, nEnd;
- GetSel(nStart, nEnd);
- if( nStart < nEnd )
- SendMessage( WM_KEYDOWN, VK_DELETE );
- return 0;
- }
- LRESULT CExtEditWithBehavior::OnPaste( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- if( ( GetStyle() & ES_READONLY ) != 0 )
- return 0;
- wParam;
- lParam;
- int nStart, nEnd;
- GetSel(nStart, nEnd);
- Default();
- CExtSafeString strTextValid = TextGetValid();
- CExtSafeString strTextCurrent = TextGet();
- if( strTextValid != strTextCurrent )
- {
- //SetWindowText( LPCTSTR(strTextValid) );
- LPCTSTR strTextToSet = (LPCTSTR(strTextValid) != NULL) ? LPCTSTR(strTextValid) : _T("");
- if( m_bRichMode )
- {
- ASSERT( ! m_bRichPainting );
- Rich_PlainText_Set( strTextToSet );
- _Rich_OnDraw();
- }
- else
- SetWindowText( strTextToSet );
- SetSel( nStart, nEnd );
- }
- return 0;
- }
- LRESULT CExtEditWithBehavior::OnSetText( WPARAM wParam, LPARAM lParam )
- {
- ASSERT_VALID( this );
- wParam;
- LRESULT nResult = Default();
- CExtSafeString strText = TextGetValid();
- if( strText != LPCTSTR(lParam) )
- {
- //SetWindowText( strText );
- LPCTSTR strTextToSet = (LPCTSTR(strText) != NULL) ? LPCTSTR(strText) : _T("");
- if( m_bRichMode )
- {
- ASSERT( ! m_bRichPainting );
- Rich_PlainText_Set( strTextToSet );
- _Rich_OnDraw();
- }
- else
- SetWindowText( strTextToSet );
- }
- else if( m_bRichMode )
- {
- _Rich_OnDraw();
- }
- if( IsWindowVisible() )
- Invalidate();
- return nResult;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditWithBehavior::CBehaviorBase
- CExtEditWithBehavior::CBehaviorBase::CBehaviorBase()
- : m_pEditWithBehaviorWnd( NULL )
- , m_nBehaviorFlags( 0 )
- {
- }
- CExtEditWithBehavior::CBehaviorBase::~CBehaviorBase()
- {
- }
- bool CExtEditWithBehavior::CBehaviorBase::_FlagsModify( UINT nAdd, UINT nRemove )
- {
- UINT nFlags = ( m_nBehaviorFlags & (~nRemove) ) | nAdd;
- if( m_nBehaviorFlags == nFlags )
- return false;
- m_nBehaviorFlags = nFlags;
- _Redraw();
- return true;
- }
- UINT CExtEditWithBehavior::CBehaviorBase::_FlagsGet() const
- {
- return m_nBehaviorFlags;
- }
- void CExtEditWithBehavior::CBehaviorBase::Behavior_OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- m_pEditWithBehaviorWnd->OnChar( uChar, nRepCnt, nFlags );
- m_pEditWithBehaviorWnd->_Rich_OnDraw();
- }
- void CExtEditWithBehavior::CBehaviorBase::Behavior_OnKeyDown( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- m_pEditWithBehaviorWnd->OnKeyDown( uChar, nRepCnt, nFlags );
- // if( uChar == VK_DELETE || uChar == VK_BACK )
- // m_pEditWithBehaviorWnd->_Rich_OnDraw();
- }
- void CExtEditWithBehavior::CBehaviorBase::Behavior_OnKillFocus( CWnd * pNewWnd )
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- m_pEditWithBehaviorWnd->OnKillFocus( pNewWnd );
- }
- LRESULT CExtEditWithBehavior::CBehaviorBase::Behavior_OnPaste( WPARAM wParam, LPARAM lParam )
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return 0L;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- if( ( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY ) != 0 )
- return 0;
- LRESULT nRetVal = m_pEditWithBehaviorWnd->OnPaste( wParam, lParam );
- // m_pEditWithBehaviorWnd->_Rich_OnDraw();
- return nRetVal;
- }
- LRESULT CExtEditWithBehavior::CBehaviorBase::_Default()
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return 0L;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- return m_pEditWithBehaviorWnd->Default();
- }
- void CExtEditWithBehavior::CBehaviorBase::_Redraw()
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- m_pEditWithBehaviorWnd->_UpdateContent();
- }
- bool CExtEditWithBehavior::CBehaviorBase::Behavior_OnQueryCharEnabledTyping( __EXT_MFC_SAFE_TCHAR _tchr ) const
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return true;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- return m_pEditWithBehaviorWnd->Behavior_OnQueryCharEnabledTyping( _tchr );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditWithBehavior::CBehaviorMasked
- CExtEditWithBehavior::CBehaviorMasked::CBehaviorMasked(
- __EXT_MFC_SAFE_LPCTSTR strMask // = _T("")
- )
- : m_strMask( strMask )
- , m_bInsertMode( false )
- , m_bNullableMode( true )
- , m_bFieldSelectionMode( true )
- , m_bBack( false )
- , m_tchrNullChar( _T('_') )
- {
- // default mask symbol number
- CharRule _rule1( __EXT_MFC_SAFE_TCHAR( _T('#') ), (CharRule::ValidationFunction)_istdigit );
- m_arrRules.Add( _rule1 );
- // default mask symbol letter
- CharRule _rule2( __EXT_MFC_SAFE_TCHAR( _T('@') ), (CharRule::ValidationFunction)_istalpha );
- m_arrRules.Add( _rule2 );
- // default mask symbol number and letter
- CharRule _rule3( __EXT_MFC_SAFE_TCHAR( _T('$') ), (CharRule::ValidationFunction)_istalnum );
- m_arrRules.Add( _rule3 );
- }
- __EXT_MFC_SAFE_LPCTSTR CExtEditWithBehavior::CBehaviorMasked::MaskGet() const
- {
- return __EXT_MFC_SAFE_LPCTSTR(LPCTSTR(m_strMask));
- }
- void CExtEditWithBehavior::CBehaviorMasked::MaskSet( __EXT_MFC_SAFE_LPCTSTR strMask )
- {
- if( m_strMask == LPCTSTR(strMask) )
- return;
- m_strMask = LPCTSTR(strMask);
- _ShowNullableMask();
- _Redraw();
- }
- CExtSafeString CExtEditWithBehavior::CBehaviorMasked::_GetNumericText() const
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- CExtSafeString strResult;
- INT nIndex, nCount = INT(strText.GetLength());
- for( nIndex = 0; nIndex < nCount; nIndex++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchr = strText[ nIndex ];
- if(_istdigit( _tchr ) )
- {
- TCHAR _tstr[2] = { _tchr, TCHAR(0) };
- strResult += _tstr;
- }
- }
- return strResult;
- }
- CExtSafeString CExtEditWithBehavior::CBehaviorMasked::Behavior_GetValidText(
- bool bSetSel // = false
- ) const
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- bSetSel;
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- INT nMaskLen = INT( m_strMask.GetLength() );
- if( nMaskLen == 0 )
- return strText;
- CExtSafeString strNewText;
- bool bNullableMode = NullableModeGet();
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- INT nLength = INT(strText.GetLength()), nPos, nMaskPos;
- for( nPos = 0, nMaskPos = 0; nPos < nLength; nPos++, nMaskPos++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchr = strText[nPos];
- __EXT_MFC_SAFE_TCHAR _tchrMask = static_cast < __EXT_MFC_SAFE_TCHAR > ( nMaskPos < nMaskLen ? m_strMask[ nMaskPos ] : 0 );
- if( ! TCHAR(_tchrMask) )
- break;
- INT nSymbolIndex, nSymbolCount = INT(m_arrRules.GetSize());
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule & symbol = m_arrRules[ nSymbolIndex ];
- if( _tchrMask != symbol || ! symbol.Validate(_tchr) )
- continue;
- for( ; nMaskPos < nMaskLen; nMaskPos++ )
- {
- _tchrMask = m_strMask[ nMaskPos ];
- if( _tchrMask == symbol )
- {
- TCHAR _tstr[2] = { symbol.Convert(_tchr), TCHAR(0) };
- strNewText += _tstr;
- break;
- }
- else
- {
- int iSymbol2 = 0;
- for( iSymbol2 = 0; iSymbol2 < nSymbolCount; iSymbol2++ )
- {
- if( _tchrMask == m_arrRules[ iSymbol2 ] )
- {
- TCHAR _tstr[2] = { symbol.Convert(_tchr), TCHAR(0) };
- strNewText += _tstr;
- break;
- }
- }
- if( iSymbol2 < nSymbolCount )
- break;
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strNewText += _tstr;
- }
- }
- break;
- }
- if( nSymbolIndex == nSymbolCount )
- {
- if( _tchr == _tchrMask )
- {
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- if( _tchrMask == m_arrRules[nSymbolIndex] )
- break;
- }
- if (nSymbolIndex == nSymbolCount)
- {
- TCHAR _tstr[2] = { TCHAR(_tchr), TCHAR(0) };
- strNewText += _tstr;
- continue;
- }
- }
- if( bNullableMode && _tchr == _tchrNullChar)
- {
- TCHAR _tstr[2] = { TCHAR(_tchr), TCHAR(0) };
- strNewText += _tstr;
- continue;
- }
- break;
- }
- }
- return strNewText;
- }
- void CExtEditWithBehavior::CBehaviorMasked::Behavior_OnChar( UINT uChar, UINT nRepCnt, UINT nFlags )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- if( m_strMask.IsEmpty() )
- {
- CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- return;
- }
- if( ( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY ) != 0 )
- return;
- if( uChar == VK_BACK )
- return;
- __EXT_MFC_SAFE_TCHAR _tchr = static_cast < TCHAR > ( uChar );
- INT nMaskLen = INT(m_strMask.GetLength());
- if( nMaskLen == 0 )
- {
- if( Behavior_OnQueryCharEnabledTyping( _tchr ) )
- CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- return;
- }
- int nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- INT nLength = INT(strText.GetLength());
- INT _posNullChar = -1;
- bool _nullCharBeforePos = _NullCharBefore( nStart );
- bool bInsertMode = InsertModeGet();
- bool bNullableMode = NullableModeGet();
- bool _nullCharIs = _IsNullChar( _posNullChar );
- if( nLength == nMaskLen
- && ( ( bInsertMode && ( bNullableMode && ! _nullCharIs ) )
- || ( bInsertMode && ! bNullableMode )
- )
- && nStart == nEnd
- )
- {
- OnCheckText( true );
- return;
- }
- if( ! ( _istprint( _tchr ) || IsCharAlphaNumeric( _tchr ) ) )
- {
- if( Behavior_OnQueryCharEnabledTyping( _tchr ) )
- CBehaviorBase::Behavior_OnChar( uChar, nRepCnt, nFlags );
- return;
- }
- else
- {
- if( nStart >= m_strMask.GetLength() )
- return;
- }
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask[nStart];
- __EXT_MFC_SAFE_TCHAR chTextCurrentSymbols = _T(' ');
- if( /*( ! strText.IsEmpty() )*/ nStart < strText.GetLength() && bNullableMode )
- chTextCurrentSymbols = strText.GetAt( nStart );
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- INT nSymbolIndex, nSymbolCount = INT(m_arrRules.GetSize());
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule & symbol = m_arrRules[nSymbolIndex];
- if( _tchrMask == symbol )
- {
- if( symbol.Validate(_tchr) && Behavior_OnQueryCharEnabledTyping(_tchr) )
- {
- if( ( ! bInsertMode || ( bNullableMode && ( chTextCurrentSymbols == _tchrNullChar ) ) )
- && nStart == nEnd
- )
- nEnd = ( nEnd == nLength ? nEnd : ( nStart + 1 ) );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- _SymbolInsert( CExtSafeString( TCHAR(symbol.Convert(_tchr)) ) );
- m_pEditWithBehaviorWnd->SetSel( nStart + 1, nStart + 1 );
- bool _inserMaskSymbol = _AddSymbolMaskToEnd();
- if( ( _posNullChar != -1 ) && ( _posNullChar < nStart )
- && bInsertMode
- && ( chTextCurrentSymbols != _tchrNullChar )
- && ! _nullCharBeforePos
- )
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- if( ( bInsertMode && ! bNullableMode )
- || bNullableMode
- )
- OnCheckText( true );
- if( ! _inserMaskSymbol )
- _GetFieldSelection( nStart );
- }
- return;
- }
- }
- if( _tchrMask == _tchr && Behavior_OnQueryCharEnabledTyping(_tchr) )
- {
- if( ! bInsertMode || ( bNullableMode && ( chTextCurrentSymbols == _tchrNullChar ) ) )
- nEnd = ( nEnd == nLength ? nEnd : ( nStart + 1 ) );
- m_pEditWithBehaviorWnd->SetSel( nStart, nEnd );
- _SymbolInsert( CExtSafeString( TCHAR(_tchr) ) );
- m_pEditWithBehaviorWnd->SetSel( nStart + 1, nStart + 1 );
- if( ( _posNullChar != -1 ) && ( _posNullChar < nStart )
- && bInsertMode
- && ( chTextCurrentSymbols != _tchrNullChar )
- && ! _nullCharBeforePos
- )
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- if( ( bInsertMode && ! bNullableMode )
- || bNullableMode
- )
- OnCheckText( true );
- _GetFieldSelection( nStart );
- return;
- }
- CExtSafeString strSymbols;
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- strSymbols += TCHAR(__EXT_MFC_SAFE_TCHAR(m_arrRules[nSymbolIndex]));
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule & symbol = m_arrRules[nSymbolIndex];
- if( ! symbol.Validate( _tchr ) )
- continue;
- CExtSafeString strMaskPortion = m_strMask.Mid( nStart );
- INT nMaskPos = INT( strMaskPortion.FindOneOf( strSymbols ) );
- if( nMaskPos >= 0 && TCHAR(strMaskPortion[nMaskPos]) == TCHAR(__EXT_MFC_SAFE_TCHAR(symbol)) && Behavior_OnQueryCharEnabledTyping(_tchr) )
- {
- if( nStart != nEnd )
- {
- _SymbolInsert( CExtSafeString( TCHAR(symbol.Convert(_tchr)) ) );
- m_pEditWithBehaviorWnd->SetSel( nStart + nMaskPos + 1, nStart + nMaskPos + 1 );
- if( bNullableMode )
- OnCheckText( true );
- return;
- }
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart + nMaskPos );
- m_pEditWithBehaviorWnd->ReplaceSel( strMaskPortion.Left( nMaskPos ), TRUE );
- Behavior_OnChar( uChar, nRepCnt, nFlags );
- return;
- }
- }
- }
- bool CExtEditWithBehavior::CBehaviorMasked::_AddSymbolMaskToEnd()
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- INT nMaskSymbolCount = _GetCountMaskSymbolsFromEnd();
- if( nMaskSymbolCount == 0 )
- return false;
- int _nStart, _nEnd;
- m_pEditWithBehaviorWnd->GetSel( _nStart, _nEnd );
- ASSERT( _nStart == _nEnd );
- CExtSafeString _str = m_pEditWithBehaviorWnd->TextGet();
- INT nMaskLen = INT( m_strMask.GetLength() );
- if( ( nMaskLen - _nStart ) != nMaskSymbolCount )
- return false;
- for( INT i = _nStart; i < nMaskLen; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- _str += _tstr;
- }
- m_pEditWithBehaviorWnd->TextSet( _str );
- m_pEditWithBehaviorWnd->SetSel( _nStart, _nEnd );
- return true;
- }
- INT CExtEditWithBehavior::CBehaviorMasked::_GetCountMaskSymbolsFromEnd()
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- INT nMaskLen = INT( m_strMask.GetLength() );
- INT nMaskSymbolCount = 0;
- if( nMaskLen == 0 )
- return nMaskSymbolCount;
- INT i = nMaskLen - 1;
- for( ; i >= 0; i-- )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- if( m_arrRules.FindPos( _tchrMask ) < 0 )
- nMaskSymbolCount ++;
- else
- break;
- }
- return nMaskSymbolCount;
- }
- void CExtEditWithBehavior::CBehaviorMasked::Behavior_OnKeyDown(UINT uChar, UINT nRepCnt, UINT nFlags)
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- if( m_strMask.IsEmpty() )
- {
- CBehaviorBase::Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- return;
- }
- switch( uChar )
- {
- case VK_BACK:
- {
- if( ( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY ) != 0 )
- return;
- m_bBack = true;
- int nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString str = m_pEditWithBehaviorWnd->TextGet();
- INT nLength = INT(str.GetLength());
- if( nStart != nEnd )
- m_pEditWithBehaviorWnd->SendMessage( WM_KEYDOWN, VK_DELETE );
- else if( nEnd != 0 )
- {
- nEnd --;
- bool bJumpMode = false;
- INT nMaskLen = INT( m_strMask.GetLength() );
- if( nEnd < nMaskLen )
- {
- for( ; nEnd >= 0 ; )
- {
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- __EXT_MFC_SAFE_TCHAR tchrMask = m_strMask[ nEnd ];
- __EXT_MFC_SAFE_TCHAR tchrSymbol = str.GetAt( nEnd );
- if( ( nEnd == ( nMaskLen - 1 ) )
- && tchrMask == tchrSymbol
- )
- return;
- bool bSymbolFind = false;
- for( INT nSymbolIndex = 0, nSymbolCount = INT(m_arrRules.GetSize()); nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule & symbol = m_arrRules[nSymbolIndex];
- if( tchrMask == symbol )
- {
- bSymbolFind = true;
- break;
- }
- }
- if( bSymbolFind )
- {
- if( ! bJumpMode )
- m_pEditWithBehaviorWnd->SendMessage( WM_KEYDOWN, VK_DELETE );
- break;
- }
- else
- {
- if( ( nEnd + 1 ) == nLength )
- {
- m_pEditWithBehaviorWnd->SendMessage( WM_KEYDOWN, VK_DELETE );
- break;
- }
- bJumpMode = true;
- nEnd --;
- continue;
- }
- } // for( ; nEnd > 0 ; )
- if( bJumpMode )
- {
- nEnd ++;
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- }
- } // if( nEnd < nMaskLen )
- } // else if( nEnd != 0 )
- }
- return;
- case VK_DELETE:
- {
- if( ( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY ) != 0 )
- return;
- int nStart, nEnd;
- bool bNullableMode = NullableModeGet();
- CExtSafeString str = m_pEditWithBehaviorWnd->TextGet();
- INT nLength = INT(str.GetLength());
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- if( nStart == nEnd )
- {
- bool bJumpMode = false;
- INT nMaskLen = INT( m_strMask.GetLength() );
- for( ; true ; )
- {
- if( nEnd < nMaskLen )
- {
- __EXT_MFC_SAFE_TCHAR tchrMask = m_strMask[ nEnd ];
- __EXT_MFC_SAFE_TCHAR tchrSymbol = str.GetAt( nEnd );
- if( ( nEnd == ( nMaskLen - 1 ) )
- && tchrMask == tchrSymbol
- )
- return;
- bool bSymbolFind = false;
- for( INT nSymbolIndex = 0, nSymbolCount = INT(m_arrRules.GetSize()); nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule& symbol = m_arrRules[nSymbolIndex];
- if( tchrMask == symbol )
- {
- bSymbolFind = true;
- break;
- }
- }
- if( ! bSymbolFind && nLength == ( nEnd + 1 ) )
- break;
- if( ! bSymbolFind )
- {
- nEnd ++;
- m_pEditWithBehaviorWnd->SendMessage( WM_KEYDOWN, VK_RIGHT );
- bJumpMode = true;
- continue;
- }
- else
- break;
- }
- else
- break;
- } // for( ; true ; )
- if( bJumpMode )
- return;
- if( (! m_bBack) && bNullableMode )
- {
- if( nEnd == nMaskLen )
- return;
- __EXT_MFC_SAFE_TCHAR tchrNullChar = NullCharGet();
- CExtSafeString strText = TCHAR(tchrNullChar);
- m_pEditWithBehaviorWnd->SetSel( nEnd, ( nEnd + 1 ) );
- m_pEditWithBehaviorWnd->ReplaceSel( strText, TRUE );
- m_pEditWithBehaviorWnd->SetSel( ( nEnd + 1 ), ( nEnd + 1 ) );
- return;
- }
- else if( m_bBack && bNullableMode )
- {
- __EXT_MFC_SAFE_TCHAR tchrNullChar = NullCharGet();
- CExtSafeString strText = TCHAR(tchrNullChar);
- m_pEditWithBehaviorWnd->SetSel( nEnd, ( nEnd + 1 ) );
- m_pEditWithBehaviorWnd->ReplaceSel( strText, TRUE );
- m_pEditWithBehaviorWnd->SetSel( nEnd, nEnd );
- m_bBack = false;
- return;
- }
- m_bBack = false;
- } // if( nStart == nEnd )
- }
- break;
- } // switch( uChar )
- switch( uChar )
- {
- case VK_BACK:
- case VK_DELETE:
- {
- if( ( m_pEditWithBehaviorWnd->GetStyle() & ES_READONLY ) != 0 )
- return;
- int _nStart, _nEnd;
- int nStart, nEnd;
- bool bNullableMode = NullableModeGet();
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- _DefineNewPosition( _nStart, _nEnd );
- if( nStart != nEnd && _nStart == _nEnd )
- {
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- return;
- }
- CExtSafeString _strNew;
- _MaskSymbolDelete( _strNew );
- //m_pEditWithBehaviorWnd->TextSet( _strNew );
- if( _nStart == _nEnd )
- _strNew.Delete( _nStart, 1 );
- else
- _strNew.Delete( _nStart, ( _nEnd - _nStart ) );
- if( bNullableMode && m_strMask.GetLength() > 0 )
- {
- if( _nStart == _nEnd )
- _strNew.Insert( _nStart, _tchrNullChar );
- else
- for( int i = 0; i < ( _nEnd - _nStart ); i++ )
- _strNew.Insert( _nStart, _tchrNullChar );
- }
- _MaskSymbolInsert( _strNew );
- if( bNullableMode )
- OnCheckText( false );
- m_pEditWithBehaviorWnd->SetSel( nStart, nStart );
- }
- break;
- default:
- CBehaviorBase::Behavior_OnKeyDown( uChar, nRepCnt, nFlags );
- break;
- } // switch( uChar )
- }
- void CExtEditWithBehavior::CBehaviorMasked::_GetMaskBasedGroupArrays(
- CExtSafeStringArray & arrMaskGroups,
- CExtSafeStringArray * p_arrEnteredValues, // = NULL
- bool bJoinSimilarRules, // = true
- bool bJoinDifferentRules, // = false
- bool bPutNullableCharIntoValueArray // = false
- )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- arrMaskGroups.RemoveAll();
- if( p_arrEnteredValues != NULL )
- p_arrEnteredValues->RemoveAll();
- // (###) ###-#### x####
- //-------------------------- with bJoinSimilarRules == true
- // 0 1 2 3
- // ### ### #### #### ---> save into arrMaskGroups
- //-------------------------- with bJoinSimilarRules == false
- // 0 1 2 3 4 5 6 7 ....
- // # # # # # # # # # # # # # # ---> save into arrMaskGroups
- //
- //==================================================================
- // sample with different rules # and $, #-digit, $-alpha
- // #$-##-$$
- //-------------------------- with bJoinSimilarRules == true and bJoinDifferentRules == true
- // #$-##-$$
- // 0 1 2
- // #$ ## $$
- //-------------------------- with bJoinSimilarRules == true and bJoinDifferentRules == false
- // #$-##-$$
- // 0 1 2 3
- // # $ ## $$
- //-------------------------- with bJoinSimilarRules == false and bJoinDifferentRules == true
- // #$-##-$$
- // 0 1 2 3 4
- // #$ # # $ $
- //-------------------------- with bJoinSimilarRules == false and bJoinDifferentRules == false
- // #$-##-$$
- // 0 1 2 3 4 5
- // # $ # # $ $
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- INT nLenText = INT( strText.GetLength() );
- INT nLenMask = INT( m_strMask.GetLength() );
- INT i;
- CExtSafeString strAsmMask, strAsmVal;
- for( i = 0; i < nLenMask; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt(i);
- __EXT_MFC_SAFE_TCHAR _tchrText = ( p_arrEnteredValues != NULL && i < nLenText ) ? __EXT_MFC_SAFE_TCHAR(strText.GetAt(0)) : __EXT_MFC_SAFE_TCHAR(0);
- if( m_arrRules.FindPos( _tchrMask ) < 0 )
- continue;
- bool bAppendToCurrentAsm = false;
- if( bJoinDifferentRules )
- bAppendToCurrentAsm = true;
- else if( strAsmMask.IsEmpty() )
- bAppendToCurrentAsm = true;
- else if(
- bJoinSimilarRules
- && TCHAR( strAsmMask.GetAt( strAsmMask.GetLength() - 1 ) ) == TCHAR(_tchrMask)
- )
- bAppendToCurrentAsm = true;
- if( bAppendToCurrentAsm )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strAsmMask += _tstr;
- if( _tchrText != 0 )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrText), TCHAR(0) };
- strAsmVal += _tstr;
- }
- }
- else
- {
- ASSERT( ! strAsmMask.IsEmpty() );
- arrMaskGroups.Add( strAsmMask );
- strAsmMask.Empty();
- if( p_arrEnteredValues != NULL )
- {
- p_arrEnteredValues->Add( strAsmVal );
- strAsmVal.Empty();
- }
- }
- } // for( i = 0; i < nLenMask; i++ )
- if( ! strAsmMask.IsEmpty() )
- {
- arrMaskGroups.Add( strAsmMask );
- strAsmMask.Empty();
- if( p_arrEnteredValues != NULL )
- {
- p_arrEnteredValues->Add( strAsmVal );
- strAsmVal.Empty();
- }
- } // if( ! strAsmMask.IsEmpty() )
- if( (!bPutNullableCharIntoValueArray) && p_arrEnteredValues != NULL )
- {
- __EXT_MFC_SAFE_TCHAR strWithNullableChar[ 2 ] = { NullCharGet(), _T(' ') };
- INT nCount = INT( p_arrEnteredValues->GetSize() );
- for( i = 0; i < nCount; i++ )
- p_arrEnteredValues->ElementAt( i ).Replace( LPCTSTR(strWithNullableChar), _T("") );
- } // if( (!bPutNullableCharIntoValueArray) && p_arrEnteredValues != NULL )
- }
- void CExtEditWithBehavior::CBehaviorMasked::OnCheckText(
- bool bAppendEndChars
- )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- ASSERT( m_pEditWithBehaviorWnd->GetSafeHwnd() != NULL );
- int nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel(nStart, nEnd);
- INT nLenMask = INT( m_strMask.GetLength() );
- CExtSafeString strTextInitial = m_pEditWithBehaviorWnd->TextGet();
- INT nLenInitial = INT( strTextInitial.GetLength() );
- CExtSafeString strText = strTextInitial;
- CExtSafeString strEnd;
- INT i = 0;
- bool bNullableMode = NullableModeGet();
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- __EXT_MFC_SAFE_TCHAR _tchrText, _tchrMask;
- if( ( nLenInitial > nLenMask ) && bNullableMode )
- {
- for( i = 0; i < (nLenInitial - 1); i++ )
- {
- _tchrText = strText.GetAt(i);
- if( _tchrText == _tchrNullChar )
- {
- strText.Delete(i);
- break;
- }
- }
- i = 0;
- }
- for( ; ! strText.IsEmpty(); )
- {
- if( bNullableMode && nLenMask <= i )
- {
- _tchrText = strText.GetAt(0);
- ASSERT( _tchrText == _tchrNullChar );
- break;
- }
- _tchrText = strText.GetAt(0);
- _tchrMask = m_strMask.GetAt(i);
- bool bRuleWasFound = false;
- if( ( bNullableMode
- && _tchrText == _tchrNullChar
- && m_arrRules.FindPos( _tchrMask ) >= 0
- )
- || m_arrRules.CheckRule( _tchrMask, _tchrText, &bRuleWasFound )
- )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrText), TCHAR(0) };
- strEnd += _tstr;
- strText.Delete(0);
- i++;
- continue;
- }
- if( bRuleWasFound )
- {
- strText.Delete(0);
- }
- else
- {
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strEnd += _tstr;
- i++;
- }
- }
- INT nResetSelPos = min( nStart, nEnd );
- INT nLenComposed = INT( strEnd.GetLength() );
- ASSERT( nLenComposed <= nLenMask );
- if( bAppendEndChars )
- {
- if( nLenComposed < nLenMask )
- {
- bool bMoveSelToAppended = ( nEnd == nLenComposed ) ? true : false;
- for( i = nLenComposed; i < nLenMask; i ++ )
- {
- _tchrMask = m_strMask.GetAt(i);
- if( m_arrRules.FindPos( _tchrMask ) < 0 )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strEnd += _tstr;
- nLenComposed ++;
- }
- else
- break;
- }
- if( bMoveSelToAppended )
- nResetSelPos = i;
- }
- }
- INT strLen = INT(strEnd.GetLength());
- if( bNullableMode )
- {
- if( strLen < nLenMask )
- {
- nEnd = strLen;
- for( ; strLen < nLenMask; strLen ++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( strLen );
- if( m_arrRules.FindPos( _tchrMask ) >= 0 )
- _tchrMask = _tchrNullChar;
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strEnd += _tstr;
- }
- }
- }
- if( strEnd == strTextInitial )
- return;
- OnInputChar( strEnd );
- if( strEnd == strTextInitial )
- return;
- m_pEditWithBehaviorWnd->TextSet( strEnd );
- m_pEditWithBehaviorWnd->SetSel( nResetSelPos, nResetSelPos );
- }
- void CExtEditWithBehavior::CBehaviorMasked::OnInputChar( CExtSafeString & str )
- {
- str;
- }
- void CExtEditWithBehavior::CBehaviorMasked::_DefineNewPosition( int & _nStart, int & _nEnd )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- int nStart, nEnd;
- m_pEditWithBehaviorWnd->GetSel( nStart, nEnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- if( strText.IsEmpty() )
- return;
- INT nMaskCountAfterStartPos = 0, nMaskCountBetweenStartPosEndPos = 0, i;
- for( i = 0; i < nStart; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = strText.GetAt( i );
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- if( _tchrSymbol == _tchrMask )
- nMaskCountAfterStartPos ++;
- }
- _nStart = nStart - nMaskCountAfterStartPos;
- _nEnd = _nStart;
- INT nTextLen = (INT)strText.GetLength();
- //INT nMaskLen = (INT)m_strMask.GetLength();
- nStart = min( nStart, nTextLen );
- nEnd = min( nEnd, nTextLen );
- if( nStart != nEnd )
- {
- if( ! m_strMask.IsEmpty() )
- {
- for( i = nStart; i < nEnd; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = strText.GetAt( i );
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- if( _tchrSymbol == _tchrMask )
- nMaskCountBetweenStartPosEndPos ++;
- }
- }
- _nEnd = nEnd - nMaskCountBetweenStartPosEndPos - nMaskCountAfterStartPos;
- }
- }
- void CExtEditWithBehavior::CBehaviorMasked::_MaskSymbolDelete( CExtSafeString & _str )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- if( strText.IsEmpty() )
- return;
- INT nLenStr = INT(strText.GetLength()), nLenMask = INT(m_strMask.GetLength()), i;
- _str = _T("");
- if( nLenMask < nLenStr )
- return;
- for( i = 0; i < nLenStr; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = strText.GetAt( i );
- if( _tchrSymbol != _tchrMask )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrSymbol), TCHAR(0) };
- _str += _tstr;
- }
- }
- }
- void CExtEditWithBehavior::CBehaviorMasked::_MaskSymbolInsert( CExtSafeString _str )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- if( _str.IsEmpty() )
- {
- m_pEditWithBehaviorWnd->TextSet( _str );
- return;
- }
- INT nMaskLen = INT( m_strMask.GetLength() );
- CExtSafeString strText = _T("");
- INT i = 0;
- if( nMaskLen > 0 )
- {
- for( ; ! _str.IsEmpty(); )
- {
- __EXT_MFC_SAFE_TCHAR _tchrMask = m_strMask.GetAt( i );
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = _str.GetAt( 0 );
- if( m_arrRules.FindPos( _tchrMask ) >= 0 )
- {
- TCHAR _tstr[2] = { TCHAR(_tchrSymbol), TCHAR(0) };
- strText += _tstr;
- _str.Delete( 0 );
- }
- else
- {
- TCHAR _tstr[2] = { TCHAR(_tchrMask), TCHAR(0) };
- strText += _tstr;
- }
- i ++;
- if( i >= nMaskLen )
- break;
- }
- }
- m_pEditWithBehaviorWnd->TextSet( strText );
- }
- void CExtEditWithBehavior::CBehaviorMasked::_SymbolInsert( CExtSafeString _str )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- bool bNullableMode = NullableModeGet();
- bool bInsertMode = InsertModeGet();
- int _nStart, _nEnd;
- _DefineNewPosition( _nStart, _nEnd );
- CExtSafeString _strNew;
- _MaskSymbolDelete( _strNew );
- INT nLenStr = INT(_strNew.GetLength());
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- INT nPosNullChar = -1;
- bool bNullChar = _IsNullChar( nPosNullChar );
- bool bDeleteNullCharSymbolAfterPos = false;
- if( bNullableMode && bInsertMode
- && TCHAR(_strNew.GetAt( _nStart )) != TCHAR(_tchrNullChar)
- && bNullChar
- && _nEnd == _nStart
- )
- {
- INT i;
- for( i = _nStart; i < nLenStr; i++ )
- {
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = _strNew.GetAt( i );
- if( _tchrSymbol == _tchrNullChar )
- {
- _strNew.Delete( i );
- bDeleteNullCharSymbolAfterPos = true;
- break;
- }
- }
- if( ! bDeleteNullCharSymbolAfterPos )
- {
- for( i = _nStart; i >= 0; i-- )
- {
- __EXT_MFC_SAFE_TCHAR _tchrSymbol = _strNew.GetAt( i );
- if( _tchrSymbol == _tchrNullChar )
- {
- _strNew.Delete( i );
- break;
- }
- }
- }
- }
- if( _nStart == _nEnd )
- {
- if( bDeleteNullCharSymbolAfterPos || ! bNullableMode )
- _strNew.Insert( _nStart, _str );
- else
- _strNew.Insert( _nStart - 1, _str );
- }
- else
- {
- _strNew.Delete( _nStart, ( _nEnd - _nStart ) );
- _strNew.Insert( _nStart, _str );
- }
- _MaskSymbolInsert( _strNew );
- }
- bool CExtEditWithBehavior::CBehaviorMasked::_NullCharBefore( int _nPos )
- {
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- INT nLenStr = INT(strText.GetLength()), i;
- __EXT_MFC_SAFE_TCHAR _tchrNullChar = NullCharGet();
- __EXT_MFC_SAFE_TCHAR _tchrSymbol;
- for( i = _nPos; i < nLenStr; i++ )
- {
- _tchrSymbol = strText.GetAt( i );
- if( _tchrSymbol == _tchrNullChar )
- return true;
- }
- return false;
- }
- CExtEditWithBehavior::CBehaviorMasked::CharRuleArray & CExtEditWithBehavior::CBehaviorMasked::GetSymbolArray()
- {
- return m_arrRules;
- }
- void CExtEditWithBehavior::CBehaviorMasked::InsertModeSet( bool bInsertMode )
- {
- m_bInsertMode = bInsertMode;
- }
- bool CExtEditWithBehavior::CBehaviorMasked::InsertModeGet() const
- {
- return m_bInsertMode;
- }
- void CExtEditWithBehavior::CBehaviorMasked::NullableModeSet( bool bNullableMode )
- {
- m_bNullableMode = bNullableMode;
- }
- bool CExtEditWithBehavior::CBehaviorMasked::NullableModeGet() const
- {
- return m_bNullableMode;
- }
- void CExtEditWithBehavior::CBehaviorMasked::NullCharSet( __EXT_MFC_SAFE_TCHAR _tchrNullChar )
- {
- m_tchrNullChar = _tchrNullChar;
- _Redraw();
- }
- void CExtEditWithBehavior::CBehaviorMasked::FieldSelectionModeSet( bool bFieldSelectionMode )
- {
- m_bFieldSelectionMode = bFieldSelectionMode;
- }
- bool CExtEditWithBehavior::CBehaviorMasked::FieldSelectionModeGet() const
- {
- return m_bFieldSelectionMode;
- }
- __EXT_MFC_SAFE_TCHAR CExtEditWithBehavior::CBehaviorMasked::NullCharGet() const
- {
- return m_tchrNullChar;
- }
- bool CExtEditWithBehavior::CBehaviorMasked::_IsNullChar( int & _pos ) const
- {
- // ASSERT_VALID( m_pEditWithBehaviorWnd );
- CExtSafeString strTextInitial = m_pEditWithBehaviorWnd->TextGet();
- INT nLength = INT(strTextInitial.GetLength()), i;
- TCHAR tchrText;
- TCHAR _tchrNullChar = TCHAR( NullCharGet() );
- for( i = 0; i < nLength; i++ )
- {
- tchrText = strTextInitial.GetAt( i );
- if( tchrText == _tchrNullChar )
- {
- _pos = i;
- return true;
- }
- }
- return false;
- }
- bool CExtEditWithBehavior::CBehaviorMasked::_GetFieldSelection( int _currentPosition )
- {
- bool bFieldSelectionMode = FieldSelectionModeGet();
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return bFieldSelectionMode;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- if( ! bFieldSelectionMode )
- return false;
- CExtSafeString strText = m_pEditWithBehaviorWnd->TextGet();
- if( strText.IsEmpty() )
- return false;
- INT nLength = INT( strText.GetLength() );
- bool bNullableMode = NullableModeGet();
- TCHAR _tchrNullChar = TCHAR( NullCharGet() );
- TCHAR _tchrMask = m_strMask.GetAt(_currentPosition);
- CExtSafeString strSymbols;
- INT nSymbolIndex, nSymbolCount = INT(m_arrRules.GetSize());
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- strSymbols += TCHAR(__EXT_MFC_SAFE_TCHAR(m_arrRules[nSymbolIndex]));
- if( strSymbols.FindOneOf( & _tchrMask ) < 0 )
- return false;
- INT _maskLen = m_strMask.GetLength();
- if( _maskLen == _currentPosition + 1 )
- return false;
- _tchrMask = m_strMask.GetAt(_currentPosition + 1);
- if( strSymbols.FindOneOf( & _tchrMask ) >= 0 )
- return false;
- INT _startPosition = -1;
- INT _endPosition = -1;
- INT i = _currentPosition + 1;
- for( ; i < nLength; i++ )
- {
- _tchrMask = m_strMask.GetAt(i);
- if( strSymbols.FindOneOf( & _tchrMask ) >= 0 )
- {
- _startPosition = i;
- break;
- }
- }
- if( _startPosition < 0 )
- return false;
- for( i = _startPosition; i < nLength; i++ )
- {
- _tchrMask = m_strMask.GetAt(i);
- if( strSymbols.FindOneOf( & _tchrMask ) < 0 )
- {
- _endPosition = i;
- break;
- }
- }
- if( _endPosition < 0 )
- _endPosition = nLength;
- m_pEditWithBehaviorWnd->SetSel( _startPosition, _endPosition );
- CExtSafeString strIns;
- for( i = _startPosition; i < _endPosition; i ++ )
- strIns += _tchrNullChar;
- if( ! strIns.IsEmpty() && bNullableMode )
- {
- m_pEditWithBehaviorWnd->ReplaceSel( strIns, TRUE );
- m_pEditWithBehaviorWnd->SetSel( _startPosition, _endPosition );
- }
- return true;
- }
- void CExtEditWithBehavior::CBehaviorMasked::_ShowNullableMask()
- {
- if( m_pEditWithBehaviorWnd->GetSafeHwnd() == NULL )
- return;
- ASSERT_VALID( m_pEditWithBehaviorWnd );
- bool bNullableMode = NullableModeGet();
- if( ! bNullableMode || m_pEditWithBehaviorWnd == NULL )
- return;
- INT nMaskLength = INT( m_strMask.GetLength() );
- TCHAR _tchrNullChar = TCHAR(NullCharGet());
- CExtSafeString strText;
- for( INT i = 0; i < nMaskLength; i ++ )
- {
- TCHAR _tchrMask = m_strMask.GetAt( i );
- INT nSymbolIndex, nSymbolCount = INT(m_arrRules.GetSize());
- for( nSymbolIndex = 0; nSymbolIndex < nSymbolCount; nSymbolIndex++ )
- {
- const CharRule & symbol = m_arrRules[nSymbolIndex];
- if( _tchrMask == TCHAR(__EXT_MFC_SAFE_TCHAR(symbol)) )
- _tchrMask = _tchrNullChar;
- }
- strText += _tchrMask;
- }
- m_pEditWithBehaviorWnd->TextSet( strText );
- }
- /////////////////////////////////////////////////////////////////////////////
- // CExtEditWithBehavior::CBehaviorMasked::CharRule
- CExtEditWithBehavior::CBehaviorMasked::CharRule::CharRule()
- : m_cSymbol( __EXT_MFC_SAFE_TCHAR(TCHAR(0)) )
- , m_fnValidation( NULL )
- , m_fnConversion( NULL )
- , m_clrSymbol( COLORREF(-1L) )
- {
- }
- CExtEditWithBehavior::CBehaviorMasked::CharRule::CharRule( __EXT_MFC_SAFE_TCHAR cSymbol, ValidationFunction fnValidation, ConversionFunction fnConversion /*= NULL*/ )
- : m_cSymbol( cSymbol )