📄 gridctrl.cpp
字号:
int nFixedRowHeight = GetFixedRowHeight();
int nFixedColWidth = GetFixedColumnWidth();
pt = origPt;
if (pt.y > rect.bottom)
{
//SendMessage(WM_VSCROLL, SB_LINEDOWN, 0);
SendMessage(WM_KEYDOWN, VK_DOWN, 0);
if (pt.x < rect.left)
pt.x = rect.left;
if (pt.x > rect.right)
pt.x = rect.right;
pt.y = rect.bottom;
OnSelecting(GetCellFromPt(pt));
}
else if (pt.y < nFixedRowHeight)
{
//SendMessage(WM_VSCROLL, SB_LINEUP, 0);
SendMessage(WM_KEYDOWN, VK_UP, 0);
if (pt.x < rect.left)
pt.x = rect.left;
if (pt.x > rect.right)
pt.x = rect.right;
pt.y = nFixedRowHeight + 1;
OnSelecting(GetCellFromPt(pt));
}
pt = origPt;
if (pt.x > rect.right)
{
// SendMessage(WM_HSCROLL, SB_LINERIGHT, 0);
SendMessage(WM_KEYDOWN, VK_RIGHT, 0);
if (pt.y < rect.top)
pt.y = rect.top;
if (pt.y > rect.bottom)
pt.y = rect.bottom;
pt.x = rect.right;
OnSelecting(GetCellFromPt(pt));
}
else if (pt.x < nFixedColWidth)
{
//SendMessage(WM_HSCROLL, SB_LINELEFT, 0);
SendMessage(WM_KEYDOWN, VK_LEFT, 0);
if (pt.y < rect.top)
pt.y = rect.top;
if (pt.y > rect.bottom)
pt.y = rect.bottom;
pt.x = nFixedColWidth + 1;
OnSelecting(GetCellFromPt(pt));
}
}
// move about with keyboard
void CGridCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (!IsValid(m_idCurrentCell))
{
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
return;
}
CCellID next = m_idCurrentCell;
BOOL bChangeLine = FALSE;
BOOL bHorzScrollAction = FALSE;
BOOL bVertScrollAction = FALSE;
if (IsCTRLpressed())
{
switch (nChar)
{
case 'A':
OnEditSelectAll();
break;
#ifndef GRIDCONTROL_NO_CLIPBOARD
case 'X':
OnEditCut();
break;
case VK_INSERT:
case 'C':
OnEditCopy();
break;
case 'V':
OnEditPaste();
break;
#endif
}
}
#ifndef GRIDCONTROL_NO_CLIPBOARD
if (IsSHIFTpressed() &&(nChar == VK_INSERT))
OnEditPaste();
#endif
BOOL bFoundVisible;
int iOrig;
if (nChar == VK_DELETE)
{
CutSelectedText();
}
else if (nChar == VK_DOWN)
{
// don't let user go to a hidden row
bFoundVisible = FALSE;
iOrig = next.row;
next.row++;
while( next.row < GetRowCount())
{
if( GetRowHeight( next.row) > 0)
{
bFoundVisible = TRUE;
break;
}
next.row++;
}
if( !bFoundVisible)
next.row = iOrig;
}
else if (nChar == VK_UP)
{
// don't let user go to a hidden row
bFoundVisible = FALSE;
iOrig = next.row;
next.row--;
while( next.row >= m_nFixedRows)
{
if( GetRowHeight( next.row) > 0)
{
bFoundVisible = TRUE;
break;
}
next.row--;
}
if( !bFoundVisible)
next.row = iOrig;
}
else if (nChar == VK_RIGHT || (nChar == VK_TAB && !IsSHIFTpressed()) )
{
// don't let user go to a hidden column
bFoundVisible = FALSE;
iOrig = next.col;
next.col++;
if (nChar == VK_TAB)
{
// If we're at the end of a row, go down a row till we find a non-hidden row
if (next.col == (GetColumnCount()) && next.row < (GetRowCount() - 1))
{
next.row++;
while( next.row < GetRowCount())
{
if( GetRowHeight(next.row) > 0)
{
bFoundVisible = TRUE;
break;
}
next.row++;
}
next.col = m_nFixedCols; // Place focus on first non-fixed column
bChangeLine = TRUE;
}
else
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
// We're on a non-hidden row, so look across for the next non-hidden column
while( next.col < GetColumnCount())
{
if( GetColumnWidth( next.col) > 0)
{
bFoundVisible = TRUE;
break;
}
next.col++;
}
// If nothing worked then don't bother
if( !bFoundVisible)
next.col = iOrig;
}
else if (nChar == VK_LEFT || (nChar == VK_TAB && IsSHIFTpressed()) )
{
// don't let user go to a hidden column
bFoundVisible = FALSE;
iOrig = next.col;
next.col--;
if (nChar == VK_TAB)
{
if (next.col == (GetFixedColumnCount()-1) && next.row > GetFixedRowCount())
{
next.row--;
while( next.row > GetFixedRowCount())
{
if( GetRowHeight(next.row) > 0)
{
bFoundVisible = TRUE;
break;
}
next.row--;
}
next.col = GetColumnCount() - 1;
bChangeLine = TRUE;
}
else
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
}
while( next.col >= m_nFixedCols)
{
if( GetColumnWidth( next.col) > 0)
{
bFoundVisible = TRUE;
break;
}
next.col--;
}
if( !bFoundVisible)
next.col = iOrig;
}
else if (nChar == VK_NEXT)
{
CCellID idOldTopLeft = GetTopleftNonFixedCell();
SendMessage(WM_VSCROLL, SB_PAGEDOWN, 0);
bVertScrollAction = TRUE;
CCellID idNewTopLeft = GetTopleftNonFixedCell();
int increment = idNewTopLeft.row - idOldTopLeft.row;
if (increment)
{
next.row += increment;
if (next.row >(GetRowCount() - 1))
next.row = GetRowCount() - 1;
}
else
next.row = GetRowCount() - 1;
}
else if (nChar == VK_PRIOR)
{
CCellID idOldTopLeft = GetTopleftNonFixedCell();
SendMessage(WM_VSCROLL, SB_PAGEUP, 0);
bVertScrollAction = TRUE;
CCellID idNewTopLeft = GetTopleftNonFixedCell();
int increment = idNewTopLeft.row - idOldTopLeft.row;
if (increment)
{
next.row += increment;
if (next.row < m_nFixedRows)
next.row = m_nFixedRows;
}
else
next.row = m_nFixedRows;
}
else if (nChar == VK_HOME)
{
// Home and Ctrl-Home work more like Excel
// and don't let user go to a hidden cell
if (IsCTRLpressed())
{
SendMessage(WM_VSCROLL, SB_TOP, 0);
SendMessage(WM_HSCROLL, SB_LEFT, 0);
bVertScrollAction = TRUE;
bHorzScrollAction = TRUE;
next.row = m_nFixedRows;
next.col = m_nFixedCols;
}
else
{
SendMessage(WM_HSCROLL, SB_LEFT, 0);
bHorzScrollAction = TRUE;
next.col = m_nFixedCols;
}
// adjust column to avoid hidden columns and rows
while( next.col < GetColumnCount() - 1)
{
if( GetColumnWidth( next.col) > 0)
break;
next.col++;
}
while( next.row < GetRowCount() - 1)
{
if( GetRowHeight( next.row) > 0)
break;
next.row++;
}
}
else if (nChar == VK_END)
{
// End and Ctrl-End work more like Excel
// and don't let user go to a hidden cell
if (IsCTRLpressed())
{
SendMessage(WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(WM_HSCROLL, SB_RIGHT, 0);
bHorzScrollAction = TRUE;
bVertScrollAction = TRUE;
next.row = GetRowCount() - 1;
next.col = GetColumnCount() - 1;
}
else
{
SendMessage(WM_HSCROLL, SB_RIGHT, 0);
bHorzScrollAction = TRUE;
next.col = GetColumnCount() - 1;
}
// adjust column to avoid hidden columns and rows
while( next.col > m_nFixedCols + 1)
{
if( GetColumnWidth( next.col) > 0)
break;
next.col--;
}
while( next.row > m_nFixedRows + 1)
{
if( GetRowHeight( next.row) > 0)
break;
next.row--;
}
}
else if (nChar == VK_F2)
{
OnEditCell(m_idCurrentCell.row, m_idCurrentCell.col, CPoint( -1, -1), VK_LBUTTON);
}
else
{
CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
return;
}
if (next != m_idCurrentCell)
{
// While moving with the Cursorkeys the current ROW/CELL will get selected
// OR Selection will get expanded when SHIFT is pressed
// Cut n paste from OnLButtonDown - Franco Bez
// Added check for NULL mouse mode - Chris Maunder.
if (m_MouseMode == MOUSE_NOTHING)
{
m_PrevSelectedCellMap.RemoveAll();
m_MouseMode = m_bListMode? MOUSE_SELECT_ROW : MOUSE_SELECT_CELLS;
if (!IsSHIFTpressed() || nChar == VK_TAB)
m_SelectionStartCell = next;
// Notify parent that selection is changing - Arthur Westerman/Scot Brennecke
SendMessageToParent(next.row, next.col, GVN_SELCHANGING);
OnSelecting(next);
SendMessageToParent(next.row, next.col, GVN_SELCHANGED);
m_MouseMode = MOUSE_NOTHING;
}
SetFocusCell(next);
if (!IsCellVisible(next))
{
switch (nChar)
{
case VK_RIGHT:
SendMessage(WM_HSCROLL, SB_LINERIGHT, 0);
bHorzScrollAction = TRUE;
break;
case VK_LEFT:
SendMessage(WM_HSCROLL, SB_LINELEFT, 0);
bHorzScrollAction = TRUE;
break;
case VK_DOWN:
SendMessage(WM_VSCROLL, SB_LINEDOWN, 0);
bVertScrollAction = TRUE;
break;
case VK_UP:
SendMessage(WM_VSCROLL, SB_LINEUP, 0);
bVertScrollAction = TRUE;
break;
case VK_TAB:
if (IsSHIFTpressed())
{
if (bChangeLine)
{
SendMessage(WM_VSCROLL, SB_LINEUP, 0);
bVertScrollAction = TRUE;
SetScrollPos32(SB_HORZ, m_nHScrollMax);
break;
}
else
{
SendMessage(WM_HSCROLL, SB_LINELEFT, 0);
bHorzScrollAction = TRUE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -