📄 gridctrl.cpp
字号:
CWnd::OnSettingChange(uFlags, lpszSection);
if (GetDefaultCell(FALSE, FALSE)->GetTextClr() == m_crWindowText) // Still using system colours
GetDefaultCell(FALSE, FALSE)->SetTextClr(::GetSysColor(COLOR_WINDOWTEXT)); // set to new system colour
if (GetDefaultCell(FALSE, FALSE)->GetBackClr() == m_crWindowColour)
GetDefaultCell(FALSE, FALSE)->SetBackClr(::GetSysColor(COLOR_WINDOW));
if (GetDefaultCell(TRUE, FALSE)->GetTextClr() == m_crWindowText) // Still using system colours
GetDefaultCell(TRUE, FALSE)->SetTextClr(::GetSysColor(COLOR_WINDOWTEXT)); // set to new system colour
if (GetDefaultCell(TRUE, FALSE)->GetBackClr() == m_crWindowColour)
GetDefaultCell(TRUE, FALSE)->SetBackClr(::GetSysColor(COLOR_WINDOW));
if (GetDefaultCell(FALSE, TRUE)->GetTextClr() == m_crWindowText) // Still using system colours
GetDefaultCell(FALSE, TRUE)->SetTextClr(::GetSysColor(COLOR_WINDOWTEXT)); // set to new system colour
if (GetDefaultCell(FALSE, TRUE)->GetBackClr() == m_crWindowColour)
GetDefaultCell(FALSE, TRUE)->SetBackClr(::GetSysColor(COLOR_WINDOW));
if (GetDefaultCell(TRUE, TRUE)->GetTextClr() == m_crWindowText) // Still using system colours
GetDefaultCell(TRUE, TRUE)->SetTextClr(::GetSysColor(COLOR_WINDOWTEXT)); // set to new system colour
if (GetDefaultCell(TRUE, TRUE)->GetBackClr() == m_crWindowColour)
GetDefaultCell(TRUE, TRUE)->SetBackClr(::GetSysColor(COLOR_WINDOW));
if (GetGridBkColor() == m_crShadow)
SetGridBkColor(::GetSysColor(COLOR_3DSHADOW));
m_crWindowText = ::GetSysColor(COLOR_WINDOWTEXT);
m_crWindowColour = ::GetSysColor(COLOR_WINDOW);
m_cr3DFace = ::GetSysColor(COLOR_3DFACE);
m_crShadow = ::GetSysColor(COLOR_3DSHADOW);
m_nRowsPerWheelNotch = GetMouseScrollLines(); // Get the number of lines
}
#endif
// For drag-selection. Scrolls hidden cells into view
// TODO: decrease timer interval over time to speed up selection over time
void CGridCtrl::OnTimer(UINT nIDEvent)
{
ASSERT(nIDEvent == WM_LBUTTONDOWN);
if (nIDEvent != WM_LBUTTONDOWN)
return;
CPoint pt, origPt;
#ifdef _WIN32_WCE
if (m_MouseMode == MOUSE_NOTHING)
return;
origPt = GetMessagePos();
#else
if (!GetCursorPos(&origPt))
return;
#endif
ScreenToClient(&origPt);
CRect rect;
GetClientRect(rect);
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;
case 'k': // This is ctrl+ on french keyboard, may need to be better processed for other locales
AutoSizeColumns();
Invalidate();
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()) )
{
if( (nChar == VK_TAB) && m_QuitFocusOnTab )
{
CDialog* p= (CDialog*) GetParent();
if(p) p->NextDlgCtrl();
return;
}
// 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)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -