Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Multiline grid cell and VK_DELETE Collapse All
Subject Author Date
Suhai Gyorgy Jan 24, 2008 - 2:06 AM

Dear Support,

I found some problems in our multiline grid cell. It can be reproduced in your ProfUIS_Controls sample. Go to Grid page and then to Text column. Go into edit mode in one of the multiline cells and place the cursor to the very end of the first line. If you press Delete key here, you can see a square kind of character appearing between the texts "Cellx Line1" and "Cellx Line2". I think it is connected to how VK_DELETE is handled in the in-place editor’s message loop in CExtGridWnd::OnGbwBeginEdit.

Could you please check this issue?
Thank you!

Technical Support Jan 24, 2008 - 11:12 AM

Thank you for reporting this issue. Please update the source code for this method:

bool CExtGridWnd::OnGbwBeginEdit(
      LONG nVisibleColNo,
      LONG nVisibleRowNo,
      LONG nColNo,
      LONG nRowNo,
      INT nColType,
      INT nRowType,
      const RECT & rcCellExtra,
      const RECT & rcCell,
      const RECT & rcInplaceControl,
      bool bContinueMsgLoop,
      __EXT_MFC_SAFE_LPCTSTR strStartEditText
      )
{
      ASSERT_VALID( this );
      if(   CExtGridBaseWnd::OnGbwBeginEdit(
                  nVisibleColNo,
                  nVisibleRowNo,
                  nColNo,
                  nRowNo,
                  nColType,
                  nRowType,
                  rcCellExtra,
                  rcCell,
                  rcInplaceControl,
                  bContinueMsgLoop,
                  strStartEditText
                  )
            )
            return true;

      if(   CExtPopupMenuWnd::IsMenuTracking() )
            CExtPopupMenuWnd::CancelMenuTracking();
      CWnd::CancelToolTips();
DWORD dwBseStyle = BseGetStyle();
      if(               nColType < 0
            &&          (dwBseStyle&__EGWS_BSE_EDIT_CELLS_OUTER_L) == 0L
            )
            return false;
      else if(    nColType > 0
            &&          (dwBseStyle&__EGWS_BSE_EDIT_CELLS_OUTER_R) == 0L
            )
            return false;
      else if(    nRowType < 0
            &&          (dwBseStyle&__EGWS_BSE_EDIT_CELLS_OUTER_T) == 0L
            )
            return false;
      else if(    nRowType > 0
            &&          (dwBseStyle&__EGWS_BSE_EDIT_CELLS_OUTER_B) == 0L
            )
            return false;
      else if(    nColType == 0
            &&          nRowType == 0
            &&          (dwBseStyle&__EGWS_BSE_EDIT_CELLS_INNER) == 0L
            )
            return false;
static CExtGridCell * g_pEditCell = NULL;
bool bDoMsgLoop = true;
      if( m_hWndInplaceControl != NULL )
      {
            if( ! bContinueMsgLoop )
                  return false;
            HWND hWndInplaceControl = m_hWndInplaceControl;
            m_hWndInplaceControl = NULL;
            if( hWndInplaceControl != NULL )
            {
                  bDoMsgLoop = false;
                  if( ::IsWindow(hWndInplaceControl) )
                        ::DestroyWindow( hWndInplaceControl );
            }
      }
CRect rcActivate( rcInplaceControl );
      if(         rcActivate.left >= rcActivate.right
            ||    rcActivate.top >= rcActivate.bottom
            )
      {
            if(   ! GridCellRectsGet(
                        nColNo,
                        nRowNo,
                        nColType,
                        nRowType,
                        NULL,
                        NULL,
                        NULL,
                        &rcActivate
                        )
                  )
            {
                  g_pEditCell = NULL;
                  return false;
            }
            if( rcActivate.IsRectEmpty() )
            {
                  g_pEditCell = NULL;
                  return false;
            }
      }
CExtGridCell * pCellToEdit =
            GridCellGet(
                  nColNo,
                  nRowNo,
                  nColType,
                  nRowType
                  );
      if( pCellToEdit == NULL )
            return false;
      ASSERT_VALID( pCellToEdit );
      ASSERT( pCellToEdit->IsKindOf(RUNTIME_CLASS(CExtGridCell)) );
      ASSERT_VALID( pCellToEdit->DataProviderGet() );
      g_pEditCell = pCellToEdit;
      m_hWndInplaceControl =
            g_pEditCell->OnInplaceControlCreate(
                  *this,
                  nVisibleColNo,
                  nVisibleRowNo,
                  nColNo,
                  nRowNo,
                  nColType,
                  nRowType,
                  rcCellExtra,
                  rcCell,
                  rcActivate,
                  m_nHelperLastEditedColNo,
                  m_nHelperLastEditedRowNo
                  );
      if(         m_hWndInplaceControl == NULL
            ||    ( ! ::IsWindow( m_hWndInplaceControl ) )
            )
      {
            m_hWndInplaceControl = NULL;
            g_pEditCell = NULL;
            DWORD dwCellStyle = pCellToEdit->GetStyle();
            if( (dwCellStyle&__EGCS_CHK_MASK) == 0 )
            {
                  if( (dwCellStyle&__EGCS_BUTTON_DROPDOWN) != 0 )
                  {
                        bool bEnabled = false;
                        if( pCellToEdit->OnQueryButtonInfo(
                                    INT(CExtGridCell::__EBTT_DROPDOWN),
                                    &bEnabled
                                    )
                              )
                        {
                              if( bEnabled )
                              {
                                    pCellToEdit->OnButtonPressed(
                                          *this,
                                          INT(CExtGridCell::__EBTT_DROPDOWN),
                                          rcCellExtra,
                                          rcCell,
                                          nVisibleColNo,
                                          nVisibleRowNo,
                                          nColNo,
                                          nRowNo,
                                          nColType,
                                          nRowType
                                          );
                                    return true;
                              }
                        }
                  }
            }
            return false;
      }
      m_nHelperLastEditedColNo = nColNo;
      m_nHelperLastEditedRowNo = nRowNo;
      if( ! bDoMsgLoop )
            return true;
CWinThread * pThread = ::AfxGetThread();
      ASSERT_VALID( pThread );
      if( strStartEditText != NULL )
      {
            bool bSetText = true;
            TCHAR strClassName[512];
            ::GetClassName( m_hWndInplaceControl, strClassName, 512 );
            if( _tcslen( strClassName ) > 0 )
            {
                  __EXT_MFC_STRLWR( strClassName, 512 );
                  if(         _tcsstr( strClassName, _T("edit") ) != NULL
                        ||    _tcsstr( strClassName, _T("riched") ) != NULL
                        ||    _tcsstr( strClassName, _T("sysipaddress32") ) != NULL
                        )
                  {
                        bSetText = false;
                        HWND hWndInplaceControl = m_hWndInplaceControl;
                        if( _tcsstr( strClassName, _T("sysipaddress32") ) != NULL )
                        {
                              for(  HWND hWnd = ::GetWindow( m_hWndInplaceControl, GW_CHILD ); 
                                          hWnd != NULL; 
                                          hWnd = ::GetWindow( hWnd, GW_HWNDNEXT )
                                    )
                              {
                                    ASSERT( hWnd != NULL );
                                    ASSERT( ::IsWindow(hWnd) );
                                    if( ::GetFocus() == hWnd )
                                    {
                                          hWndInplaceControl = hWnd;
                                          break;
                                    }
                              }
                        }
                        ::SendMessage(
                              hWndInplaceControl,
                              EM_SETSEL,
                              WPARAM(0),
                              LPARAM(-1)
                              );
                        ::SendMessage(
                              hWndInplaceControl,
                              EM_REPLACESEL,
                              WPARAM(TRUE),
                              LPARAM(strStartEditText)
                              );
                  }
            }
            if( bSetText )
                  ::SetWindowText( m_hWndInplaceControl, strStartEditText );
      }
HWND hWndGrid = m_hWnd;
bool bStopFlag = false;
      for(  MSG msg;
                        m_hWndInplaceControl != NULL
                  &&    ::IsWindow( m_hWndInplaceControl )
                  &&    ::IsWindowVisible( m_hWndInplaceControl )
                  &&    ::IsWindow( hWndGrid )
                  &&    (!bStopFlag)
                  &&    (g_pEditCell != NULL)
                  ;
            )
      {
            if( ! ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )
            {
                  if(         m_hWndInplaceControl == NULL
                        ||    ( ! ::IsWindow( m_hWndInplaceControl ) )
                        ||    ( ! ::IsWindow( hWndGrid ) )
                        ||    bStopFlag
                        ||    g_pEditCell == NULL
                        )
                        break;
                  LONG nIdleCounter = 0L;
                  for(  nIdleCounter = 0L;
                              g_pEditCell->OnInplaceControlIdle(
                                    m_hWndInplaceControl,
                                    *this,
                                    nIdleCounter
                                    );
                              nIdleCounter ++
                              )
                  {
                        ASSERT_VALID( g_pEditCell );
                  }
                  if( CExtGridWnd::g_bEnableOnIdleCalls )
                  {
                        for(  nIdleCounter = 0L;
                                    pThread->OnIdle(nIdleCounter);
                                    nIdleCounter ++
                                    );
                  }
                  ::WaitMessage();
                  continue;
            }
            switch( msg.message )
            {
            case WM_KILLFOCUS:
                  if( msg.hwnd == m_hWndInplaceControl )
                        bStopFlag = true;
            break;
            case WM_CANCELMODE:
            case WM_ACTIVATEAPP:
            case WM_SYSCOMMAND:
            case WM_SETTINGCHANGE:
            case WM_SYSCOLORCHANGE:
                  bStopFlag = true;
            break;
            case WM_COMMAND:
                  if(         (HIWORD(msg.wParam)) == 0
                        ||    (HIWORD(msg.wParam)) == 1
                        )
                        bStopFlag = true;
            break;
            case WM_CAPTURECHANGED:
                  if( (HWND)msg.wParam != m_hWndInplaceControl )
                        bStopFlag = true;
            break;
            case WM_LBUTTONUP:
            case WM_LBUTTONDOWN:
            case WM_LBUTTONDBLCLK:
            case WM_RBUTTONUP:
            case WM_RBUTTONDOWN:
            case WM_RBUTTONDBLCLK:
            case WM_MBUTTONUP:
            case WM_MBUTTONDOWN:
            case WM_MBUTTONDBLCLK:
            case WM_NCLBUTTONUP:
            case WM_NCLBUTTONDOWN:
            case WM_NCLBUTTONDBLCLK:
            case WM_NCRBUTTONUP:
            case WM_NCRBUTTONDOWN:
            case WM_NCRBUTTONDBLCLK:
            case WM_NCMBUTTONUP:
            case WM_NCMBUTTONDOWN:
            case WM_NCMBUTTONDBLCLK:
            case WM_CONTEXTMENU:
                  if(         msg.hwnd != m_hWndInplaceControl
                        &&    (!::IsChild( m_hWndInplaceControl, msg.hwnd ))
                        )
                        bStopFlag = true;
            break;
            default:
                  if(         ( ! bStopFlag )
                        &&    WM_KEYFIRST <= msg.message
                        &&    msg.message <= WM_KEYLAST
                        &&    (     msg.hwnd != m_hWndInplaceControl 
                              ||    (!::IsChild( m_hWndInplaceControl, msg.hwnd )) 
                              )
                        )
                  {
                        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(msg.wParam) == VK_INSERT
                                          ||    int(msg.wParam) == int( _T(’C’) )
                                          )
                                    )
                              {
                                    LRESULT lResult = 0L;
                                    g_pEditCell->OnInplaceControlWindowProc(
                                          lResult,
                                          msg.message,
                                          msg.wParam,
                                          msg.lParam,
                                          msg.hwnd,
                                          *this,
                                          nVisibleColNo,
                                          nVisibleRowNo,
                                          nColNo,
                                          nRowNo,
                                          nColType,
                                          nRowType,
                                          rcCellExtra,
                                          rcCell,
                                          rcInplaceControl
                                          );
                                    ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                                    if( msg.message == WM_KEYDOWN )
                                          ::SendMessage( msg.hwnd, WM_COPY, 0, 0 );
                                    continue;
                              } 
                              if(         ( bCtrl && (!bShift) && int(msg.wParam) == int( _T(’V’) ) )
                                    ||    ( (!bCtrl) && bShift && int(msg.wParam) == VK_INSERT )
                                    )
                              {
                                    LRESULT lResult = 0L;
                                    g_pEditCell->OnInplaceControlWindowProc(
                                          lResult,
                                          msg.message,
                                          msg.wParam,
                                          msg.lParam,
                                          msg.hwnd,
                                          *this,
                                          nVisibleColNo,
                                          nVisibleRowNo,
                                          nColNo,
                                          nRowNo,
                                          nColType,
                                          nRowType,
                                          rcCellExtra,
                                          rcCell,
                                          rcInplaceControl
                                          );
                                    ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                                    if( msg.message == WM_KEYDOWN )
                                          ::SendMessage( msg.hwnd, WM_PASTE, 0, 0 );
                                    continue;
                              } 
                              if(         ( bCtrl && (!bShift) && int(msg.wParam) == int( _T(’X’) ) )
                                    ||    ( (!bCtrl) && bShift && int(msg.wParam) == VK_DELETE )
                                    )
                              {
                                    LRESULT lResult = 0L;
                                    g_pEditCell->OnInplaceControlWindowProc(
                                          lResult,
                                          msg.message,
                                          msg.wParam,
                                          msg.lParam,
                                          msg.hwnd,
                                          *this,
                                          nVisibleColNo,
                                          nVisibleRowNo,
                                          nColNo,
                                          nRowNo,
                                          nColType,
                                          nRowType,
                                          rcCellExtra,
                                          rcCell,
                                          rcInplaceControl
                                          );
                                    ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                                    if( msg.message == WM_KEYDOWN )
                                    {
                                          if( ( g_pEditCell->GetStyle() & __EGCS_READ_ONLY ) == 0 )
                                                ::SendMessage( msg.hwnd, WM_CUT, 0, 0 );
                                          else
                                                ::SendMessage( msg.hwnd, WM_COPY, 0, 0 );
                                    }
                                    continue;
                              } 
                              if(   bCtrl && (!bShift) && int(msg.wParam) == int( _T(’A’) ) ) 
                              {
                                    LRESULT lResult = 0L;
                                    g_pEditCell->OnInplaceControlWindowProc(
                                          lResult,
                                          msg.message,
                                          msg.wParam,
                                          msg.lParam,
                                          msg.hwnd,
                                          *this,
                                          nVisibleColNo,
                                          nVisibleRowNo,
                                          nColNo,
                                          nRowNo,
                                          nColType,
                                          nRowType,
                                          rcCellExtra,
                                          rcCell,
                                          rcInplaceControl
                                          );
                                    ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                                    if( msg.message == WM_KEYDOWN )

                                          ::SendMessage( msg.hwnd, EM_SETSEL, 0, -1 );
                                    continue;
                              }
                              if(   (!bCtrl) && (!bShift) && int(msg.wParam) == VK_DELETE )
                              {
                                    if( msg.message != WM_CHAR )
                                    {
                                          LRESULT lResult = 0L;
                                          g_pEditCell->OnInplaceControlWindowProc(
                                                lResult,
                                                msg.message,
                                                msg.wParam,
                                                msg.lParam,
                                                msg.hwnd,
                                                *this,
                                                nVisibleColNo,
                                                nVisibleRowNo,
                                                nColNo,
                                                nRowNo,
                                                nColType,
                                                nRowType,
                                                rcCellExtra,
                                                rcCell,
                                                rcInplaceControl
                                                );
                                          ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                                          if( msg.message == WM_KEYDOWN )
                                          {
                                                LPTSTR strEmpty = _T(""); 
                                                INT nSelStart = 0, nSelEnd = 0;
                                                ::SendMessage(
                                                      msg.hwnd,
                                                      EM_GETSEL,
                                                      reinterpret_cast < WPARAM > ( &nSelStart ),
                                                      reinterpret_cast < LPARAM > ( &nSelEnd )
                                                      );
                                                if( nSelStart == nSelEnd )
                                                {
                                                      INT nReplaceEnd = nSelStart + 1;
                                                      CString s;
                                                      CWnd::FromHandle( msg.hwnd )->GetWindowText( s );
                                                      TCHAR chr = s.GetAt( nSelStart );
                                                      if( chr == _T(’\r’) || chr == _T(’\n’) )
                                                            nReplaceEnd ++;
                                                      ::SendMessage(
                                                            msg.hwnd,
                                                            EM_SETSEL,
                                                            WPARAM( nSelStart ),
                                                            LPARAM( nReplaceEnd )
                                                            );
                                                }
                                                if( ( g_pEditCell->GetStyle() & __EGCS_READ_ONLY ) == 0 )
                                                      ::SendMessage(
                                                            msg.hwnd,
                                                            EM_REPLACESEL,
                                                            1,
                                                            reinterpret_cast < LPARAM > ( strEmpty )
                                                            );
                                          }
                                          continue;
                                    }
                              }
                        }
                        if(         ( (!bAlt) && bCtrl && (!bShift) && int(msg.wParam) == int( _T(’Z’) ) )
                              ||    ( bAlt && (!bCtrl) && (!bShift) && int(msg.wParam) == VK_BACK )
                              )
                        {
                              LRESULT lResult = 0L;
                              g_pEditCell->OnInplaceControlWindowProc(
                                    lResult,
                                    msg.message,
                                    msg.wParam,
                                    msg.lParam,
                                    msg.hwnd,
                                    *this,
                                    nVisibleColNo,
                                    nVisibleRowNo,
                                    nColNo,
                                    nRowNo,
                                    nColType,
                                    nRowType,
                                    rcCellExtra,
                                    rcCell,
                                    rcInplaceControl
                                    );
                              ::PeekMessage(&msg,NULL,msg.message,msg.message,PM_REMOVE);
                              if( msg.message == WM_KEYDOWN )
                                    ::SendMessage( msg.hwnd, WM_UNDO, 0, 0 );
                              continue;
                        } 
                  }
            break;
            }
            if( bStopFlag )
                  break;
            if( ! pThread->PumpMessage() )
                  break;
      }
      g_pEditCell = NULL;
      if( ! ::IsWindow( hWndGrid ) )
            return true;
      ASSERT( CWnd::FromHandlePermanent(hWndGrid) == this );
      ASSERT_VALID( this );
      m_nHelperLastEditedColNo = -1L;
      m_nHelperLastEditedRowNo = -1L;
      if( m_hWndInplaceControl != NULL )
      {
            if( ::IsWindow(m_hWndInplaceControl) )
            {
                  if( ::GetCapture() == m_hWndInplaceControl )
                        ::ReleaseCapture();
                  ::ShowWindow( m_hWndInplaceControl, SW_HIDE );
                  ::SetFocus( m_hWnd );
            }
            m_hWndInplaceControl = NULL;
      }
      return true;
}