// 鼠标右键放开事件处理 BOOL CControlBase::OnRButtonUp(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = false; if(m_pControl != NULL) { // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if(SCROLL_V == uControlID) { point = oldPoint; } if(m_pControl->OnRButtonUp(nFlags, point)) { return true; } } else { // 发送鼠标右键放开DUI消息 if(m_bDuiMsgMouseRUp) { SendMessage(MSG_MOUSE_RUP, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlRButtonUp(nFlags, point); } return false; }
// 鼠标右键按下事件处理 BOOL CControlBase::OnRButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = false; if(m_pControl != NULL) { if(m_pControl->OnRButtonDown(nFlags, point)) { return true; } } else { // 发送鼠标右键按下DUI消息 if(m_bDuiMsgMouseRDown && m_rc.PtInRect(point)) { SendMessage(MSG_MOUSE_RDOWN, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlRButtonDown(nFlags, point); } return false; }
// 鼠标左键按下事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件(按照反向顺序查找,因为定义在后面的控件是优先级更高的) // 找到第一个符合条件的就结束查找 for (int i = m_vecControl.size()-1; i >= 0; i--) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; break; } } } if(m_pControl != NULL) { // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { point = oldPoint; } if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } // 发送鼠标左键按下DUI消息 if(m_bDuiMsgMouseLDown && m_rc.PtInRect(point)) { SendMessage(MSG_MOUSE_LDOWN, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlLButtonDown(nFlags, point); } return false; }
// 鼠标右键双击事件处理 BOOL CControlBase::OnRButtonDblClk(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = false; if(m_pControl != NULL) { // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { point = oldPoint; } if(m_pControl->OnRButtonDblClk(nFlags, point)) { return true; }else if(!m_pControl->GetDblClk()) { // 如果控件不允许双击,则调用单击处理函数 return m_pControl->OnRButtonDown(nFlags, point); } } else { if(!GetDblClk()) { // 如果控件不允许双击,则调用单击处理函数 return OnControlRButtonDown(nFlags, point); } // 发送鼠标右键双击DUI消息 if(m_bDuiMsgMouseRDblClk && m_rc.PtInRect(point)) { SendMessage(MSG_MOUSE_RDBLCLK, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlRButtonDblClk(nFlags, point); } return false; }
// 鼠标左键事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件 for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; } } } if(m_pControl != NULL) { if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } return OnControlLButtonDown(nFlags, point); } return false; }
// 鼠标左键事件处理 BOOL CControlBase::OnLButtonUp(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); m_bMouseDown = false; if(m_pControl != NULL) { if(m_pControl->OnLButtonUp(nFlags, point)) { return true; } } else { return OnControlLButtonUp(nFlags, point); } return false; }
// 鼠标移动事件处理 BOOL CControlBase::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); BOOL bRresponse = false; if(m_pControl) { if((m_pControl->PtInRect(point) && m_pControl->OnCheckMouseResponse(nFlags, point)) || m_bMouseDown) { if(m_pControl->OnMouseMove(nFlags, point)) { return true; } return false; } } CControlBase * pOldControl = m_pControl; m_pControl = NULL; if(!m_strTooltip.IsEmpty() && PtInRect(point) && OnCheckMouseResponse(nFlags, point)) { // 如果当前控件有Tooltip,则添加一个Tooltip CDlgBase* pDlg = GetParentDialog(); if(pDlg && (pDlg->GetTooltipCtrlID() != GetID())) { pDlg->SetTooltip(this, m_strTooltip, m_rc); pDlg->SetTooltipCtrlID(GetID()); } } bRresponse = OnControlMouseMove(nFlags, point); if(!m_bMouseDown) { for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { if(pControlBase->OnMouseMove(nFlags, point)) { if(pControlBase->PtInRect(point)) { m_pControl = pControlBase; } bRresponse = true; } } } if (pOldControl) { bRresponse = true; } if (m_pControl) { bRresponse = true; } } return bRresponse; }
// 鼠标移动事件处理 BOOL CControlBase::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); BOOL bRresponse = false; if(m_pControl) { CPoint pt = point; // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { pt = oldPoint; } if((m_pControl->PtInRect(pt) && m_pControl->OnCheckMouseResponse(nFlags, pt)) || m_bMouseDown) { if(m_pControl->OnMouseMove(nFlags, pt)) { return true; } return false; } } CControlBase * pOldControl = m_pControl; m_pControl = NULL; if(!m_strTooltip.IsEmpty() && PtInRect(point) && OnCheckMouseResponse(nFlags, point)) { // 如果当前控件有Tooltip,并且当前Tooltip设置的是其他控件,则设置Tooltip if(GetTooltipCtrlID() != GetID()) { SetTooltip(this, m_strTooltip, m_rc, FALSE, m_nTipWidth); SetTooltipCtrlID(GetID()); } } // 调用控件的设置鼠标光标函数 OnControlSetCursor(nFlags, point); // 调用控件的鼠标移动函数 bRresponse = OnControlMouseMove(nFlags, point); // 发送鼠标移动的DUI消息 if(m_bDuiMsgMouseMove) { if(PtInRect(point)) { // 发送鼠标在控件范围内移动的消息 SendMessage(MSG_MOUSE_MOVE, (WPARAM)nFlags, (LPARAM)(&point)); m_bMouseLeave = FALSE; }else { if(!m_bMouseLeave) { // 发送鼠标离开控件的消息(离开之后仅发送一次离开消息) SendMessage(MSG_MOUSE_LEAVE, (WPARAM)nFlags, (LPARAM)(&point)); m_bMouseLeave = TRUE; } } } if(!m_bMouseDown) { for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { CPoint pt = point; // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = pControlBase->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { pt = oldPoint; } if(pControlBase->OnMouseMove(nFlags, pt)) { if(pControlBase->PtInRect(pt)) { m_pControl = pControlBase; } bRresponse = true; } } } if (pOldControl) { bRresponse = true; } if (m_pControl) { bRresponse = true; } } return bRresponse; }