⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gridctrl.cpp

📁 超市管理系统超市管理系统超市管理系统超市管理系统超市管理系统超市管理系统
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    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;

    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;

    switch (nChar)
    {
    case VK_DELETE: 
        if (IsCellEditable(m_idCurrentCell.row, m_idCurrentCell.col))
        {
            SendMessageToParent(m_idCurrentCell.row, m_idCurrentCell.col, GVN_BEGINLABELEDIT);
            SetItemText(m_idCurrentCell.row, m_idCurrentCell.col, _T(""));
            SetModified(TRUE, m_idCurrentCell.row, m_idCurrentCell.col);
            SendMessageToParent(m_idCurrentCell.row, m_idCurrentCell.col, GVN_ENDLABELEDIT);
            RedrawCell(m_idCurrentCell);
        }
        break;
        
    case VK_TAB:    
        if (IsSHIFTpressed())
        {
            if (next.col > m_nFixedCols) 
                next.col--;
            else if (next.col == m_nFixedCols && next.row > m_nFixedRows) 
            {
                next.row--; 
                next.col = GetColumnCount() - 1; 
                bChangeLine = TRUE;
            }
            else
                CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
        }
        else
        {
            if (next.col <(GetColumnCount() - 1)) 
                next.col++;
            else if (next.col == (GetColumnCount() - 1) && 
                next.row <(GetRowCount() - 1))
            {
                next.row++; 
                next.col = m_nFixedCols; 
                bChangeLine = TRUE;
            }
            else
                CWnd::OnKeyDown(nChar, nRepCnt, nFlags);
        } 
        break;
        
    case 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;

            break;
        
    case 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;

            break;
        
    case VK_RIGHT:  
            // don't let user go to a hidden column
            bFoundVisible = FALSE;
            iOrig = next.col;
            next.col++;
            while( next.col < GetColumnCount())
            {
                if( GetColumnWidth( next.col) > 0)
                {
                    bFoundVisible = TRUE;
                    break;
                }
                next.col++;
            }
            if( !bFoundVisible)
                next.col = iOrig;

            break;
        
    case VK_LEFT:   
            // don't let user go to a hidden column
            bFoundVisible = FALSE;
            iOrig = next.col;
            next.col--;
            while( next.col >= m_nFixedCols)
            {
                if( GetColumnWidth( next.col) > 0)
                {
                    bFoundVisible = TRUE;
                    break;
                }
                next.col--;
            }
            if( !bFoundVisible)
                next.col = iOrig;

            break;
        
    case VK_NEXT:   
        {
            CCellID idOldTopLeft = GetTopleftNonFixedCell();
            SendMessage(WM_VSCROLL, SB_PAGEDOWN, 0);
            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;
            break;
        }

    case VK_PRIOR:  
        {
            CCellID idOldTopLeft = GetTopleftNonFixedCell();
            SendMessage(WM_VSCROLL, SB_PAGEUP, 0);
            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;
            break;
        }
        
    case 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);
                next.row = m_nFixedRows;
                next.col = m_nFixedCols;
            }
            else
            {
                SendMessage(WM_HSCROLL, SB_LEFT, 0);
                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++;
            }
            break;
        
    case 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);
            next.row = GetRowCount() - 1;
            next.col = GetColumnCount() - 1;
        }
        else
        {
            SendMessage(WM_HSCROLL, SB_RIGHT, 0);
            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--;
        }

        break;
        
    case VK_F2:
        OnEditCell(m_idCurrentCell.row, m_idCurrentCell.col, CPoint( -1, -1), VK_LBUTTON);
        break;

    default:
        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;
            OnSelecting(next);
            m_MouseMode = MOUSE_NOTHING;
        }

        SetFocusCell(next);

        if (!IsCellVisible(next))
        {

            switch (nChar)
            {
            case VK_RIGHT:  
                SendMessage(WM_HSCROLL, SB_LINERIGHT, 0); 
                break;
                

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -