// 鼠标右键按下事件处理 BOOL CDuiGridCtrl::OnControlRButtonDown(UINT nFlags, CPoint point) { if(m_vecRowInfo.size() == 0) { return false; } // 设置窗口焦点,否则可能无法进行滚动事件的处理 SetWindowFocus(); if((m_nHoverRow >= 0) && (m_nHoverRow < (int)m_vecRowInfo.size())) { GridRowInfo &rowInfo = m_vecRowInfo.at(m_nHoverRow); if(PtInRow(point, rowInfo) && !PtInRowCheck(point, rowInfo)) // 检查框事件只在鼠标放开时候触发 { rowInfo.nHoverItem = PtInRowItem(point, rowInfo); if(m_nDownRow != m_nHoverRow) { if(m_bEnableDownRow) { m_nDownRow = m_nHoverRow; m_nHoverRow = -1; } SendMessage(MSG_MOUSE_RDOWN, m_bEnableDownRow ? m_nDownRow : m_nHoverRow, rowInfo.nHoverItem); UpdateControl(TRUE); return true; } } } else if((m_nDownRow >= 0) && (m_nDownRow < (int)m_vecRowInfo.size())) { // 如果点击的还是之前点击的行,也同样会发送鼠标点击事件 GridRowInfo &rowInfo = m_vecRowInfo.at(m_nDownRow); if(PtInRow(point, rowInfo)&& !PtInRowCheck(point, rowInfo)) // 检查框事件只在鼠标放开时候触发 { rowInfo.nHoverItem = PtInRowItem(point, rowInfo); SendMessage(MSG_MOUSE_RDOWN, m_nDownRow, rowInfo.nHoverItem); return true; } } return false; }
// 鼠标右键放开事件处理 BOOL CDuiGridCtrl::OnControlRButtonUp(UINT nFlags, CPoint point) { if(m_vecRowInfo.size() == 0) { return false; } if((m_nHoverRow >= 0) && (m_nHoverRow < (int)m_vecRowInfo.size())) { GridRowInfo &rowInfo = m_vecRowInfo.at(m_nHoverRow); if(PtInRow(point, rowInfo)) { //取反,否则消息不能发送 if(!PtInRowCheck(point, rowInfo)) // 检查框状态改变 { rowInfo.nCheck = ((rowInfo.nCheck == 1) ? 0 : 1); SendMessage(MSG_MOUSE_RUP, m_nHoverRow, rowInfo.nCheck); UpdateControl(TRUE); return true; } } }else if((m_nDownRow >= 0) && (m_nDownRow < (int)m_vecRowInfo.size())) { // 如果点击的还是之前点击的行,也同样会发送鼠标点击事件 GridRowInfo &rowInfo = m_vecRowInfo.at(m_nDownRow); if(PtInRow(point, rowInfo)) { if(PtInRowCheck(point, rowInfo)) // 检查框状态改变 { rowInfo.nCheck = ((rowInfo.nCheck == 1) ? 0 : 1); SendMessage(MSG_MOUSE_RUP, m_nDownRow, rowInfo.nCheck); UpdateControl(TRUE); return true; } } } return false; }
// 鼠标左键双击事件处理 BOOL CDuiGridCtrl::OnControlLButtonDblClk(UINT nFlags, CPoint point) { if(m_vecRowInfo.size() == 0) { return false; } if(m_rc.PtInRect(point)) { for(size_t i = 0; i < m_vecRowInfo.size(); i++) { GridRowInfo &rowInfo = m_vecRowInfo.at(i); if(PtInRow(point, rowInfo) && !PtInRowCheck(point, rowInfo)) { int nClickItem = PtInRowItem(point, rowInfo); SendMessage(MSG_BUTTON_DBLCLK, i, nClickItem); return true; } } } return false; }
// 鼠标移动事件处理 BOOL CDuiGridCtrl::OnControlMouseMove(UINT nFlags, CPoint point) { if(m_vecRowInfo.size() == 0) { return false; } int nOldHoverRow = m_nHoverRow; BOOL bHoverItemChange = FALSE; int nOldHoverItem = -1; if(m_rc.PtInRect(point)) { if((m_nHoverRow >= 0) && (m_nHoverRow < (int)m_vecRowInfo.size())) { GridRowInfo &rowInfo = m_vecRowInfo.at(m_nHoverRow); nOldHoverItem = rowInfo.nHoverItem; if(PtInRow(point, rowInfo)) { rowInfo.nHoverItem = PtInRowItem(point, rowInfo); if(nOldHoverItem != rowInfo.nHoverItem) { bHoverItemChange = TRUE; UpdateControl(TRUE); } if(m_bGridTooltip) // 设置单元格Tooltip { GridItemInfo* pGridInfo = GetItemInfo(m_nHoverRow, rowInfo.nHoverItem); if(pGridInfo && pGridInfo->bNeedTitleTip) { SetGridTooltip(m_nHoverRow, rowInfo.nHoverItem, pGridInfo->strTitle); }else if(pGridInfo && pGridInfo->bNeedContentTip) { SetGridTooltip(m_nHoverRow, rowInfo.nHoverItem, pGridInfo->strContent); }else { ClearGridTooltip(); } } return false; } m_nHoverRow = -1; } BOOL bMousenDown = false; if((m_nDownRow >= 0) && (m_nDownRow < (int)m_vecRowInfo.size())) { GridRowInfo &rowInfo = m_vecRowInfo.at(m_nDownRow); nOldHoverItem = rowInfo.nHoverItem; if(PtInRow(point, rowInfo)) { rowInfo.nHoverItem = PtInRowItem(point, rowInfo); bMousenDown = true; m_nHoverRow = -1; if(nOldHoverItem != rowInfo.nHoverItem) { bHoverItemChange = TRUE; } if(m_bGridTooltip) // 设置单元格Tooltip { GridItemInfo* pGridInfo = GetItemInfo(m_nDownRow, rowInfo.nHoverItem); if(pGridInfo && pGridInfo->bNeedTitleTip) { SetGridTooltip(m_nDownRow, rowInfo.nHoverItem, pGridInfo->strTitle); }else if(pGridInfo && pGridInfo->bNeedContentTip) { SetGridTooltip(m_nDownRow, rowInfo.nHoverItem, pGridInfo->strContent); }else { ClearGridTooltip(); } } } } if(!bMousenDown) { for(size_t i = 0; i < m_vecRowInfo.size(); i++) { GridRowInfo &rowInfo = m_vecRowInfo.at(i); nOldHoverItem = rowInfo.nHoverItem; if(PtInRow(point, rowInfo)) { rowInfo.nHoverItem = PtInRowItem(point, rowInfo); m_nHoverRow = i; if(nOldHoverItem != rowInfo.nHoverItem) { bHoverItemChange = TRUE; } break; } } } } else { m_nHoverRow = -1; } if((nOldHoverRow != m_nHoverRow) || bHoverItemChange) { UpdateControl(TRUE); return true; } return false; }
BOOL CDuiListCtrl::OnControlMouseMove(UINT nFlags, CPoint point) { if(m_vecRowInfo.size() == 0) { return false; } int nOldHoverRow = m_nHoverRow; BOOL bHoverLinkChange = FALSE; int nOldHoverLink = -1; if(m_rc.PtInRect(point)) { // 如果鼠标在热点行,判断鼠标是否在某个链接位置 if((m_nHoverRow >= 0) && (m_nHoverRow < (int)m_vecRowInfo.size())) { ListRowInfo &rowInfo = m_vecRowInfo.at(m_nHoverRow); nOldHoverLink = rowInfo.nHoverLink; if(PtInRow(point, rowInfo)) { if(m_bRowTooltip) { if(rowInfo.bNeedTitleTip) { SetRowTooltip(m_nHoverRow, rowInfo.strTitle); }else if(rowInfo.bNeedContentTip) { SetRowTooltip(m_nHoverRow, rowInfo.strContent); }else { ClearRowTooltip(); } } rowInfo.nHoverLink = PtInRowLink(point, rowInfo); if(nOldHoverLink != rowInfo.nHoverLink) { bHoverLinkChange = TRUE; UpdateControl(TRUE); } return false; } m_nHoverRow = -1; } // 如果鼠标在当前行,判断鼠标是否在某个链接位置 BOOL bMousenDown = false; if((m_nDownRow >= 0) && (m_nDownRow < (int)m_vecRowInfo.size())) { ListRowInfo &rowInfo = m_vecRowInfo.at(m_nDownRow); nOldHoverLink = rowInfo.nHoverLink; if(PtInRow(point, rowInfo)) { if(m_bRowTooltip) { if(rowInfo.bNeedTitleTip) { SetRowTooltip(m_nDownRow, rowInfo.strTitle); }else if(rowInfo.bNeedContentTip) { SetRowTooltip(m_nDownRow, rowInfo.strContent); }else { ClearRowTooltip(); } } rowInfo.nHoverLink = PtInRowLink(point, rowInfo); bMousenDown = true; m_nHoverRow = -1; if(nOldHoverLink != rowInfo.nHoverLink) { bHoverLinkChange = TRUE; } } } // 计算热点行和热点链接 if(!bMousenDown) { for(size_t i = 0; i < m_vecRowInfo.size(); i++) { ListRowInfo &rowInfo = m_vecRowInfo.at(i); nOldHoverLink = rowInfo.nHoverLink; if(PtInRow(point, rowInfo)) { rowInfo.nHoverLink = PtInRowLink(point, rowInfo); m_nHoverRow = i; if(nOldHoverLink != rowInfo.nHoverLink) { bHoverLinkChange = TRUE; } break; } } } } else { m_nHoverRow = -1; } if((nOldHoverRow != m_nHoverRow) || bHoverLinkChange) { UpdateControl(TRUE); return true; } return false; }