void CEasySkinSliderCtrl::SetPos( int nPos ) { int nMin,nMax; GetRange(nMin,nMax); //重新定位,防止超出客户区 if( nPos <= nMin ) nPos = nMin; if ( nPos >= nMax ) nPos = nMax; __super::SetPos(nPos); int nPosNew = 0; if ( GetStyle() & TBS_VERT ) nPosNew = m_rcChannelRect.Height()*nPos/(nMax-nMin); else nPosNew = m_rcChannelRect.Width()*nPos/(nMax-nMin); if( nPosNew<0 ) nPosNew = 0; SetThumbRect(nPosNew); RedrawWindow(NULL,NULL,RDW_FRAME|RDW_INVALIDATE|RDW_ERASE|RDW_ERASENOW); }
BOOL CEasySkinSliderCtrl::SetThumImage( LPCTSTR lpszFileName ) { UIRenderEngine->RemoveImage(m_pThumImg); m_pThumImg = UIRenderEngine->GetImage(lpszFileName); if (NULL == m_pThumImg) return FALSE; else { m_szThum.SetSize(m_pThumImg->GetWidth(),m_pThumImg->GetHeight()); m_rcThumRect.SetRect(0,0,m_szThum.cx,m_szThum.cy); SetThumbRect(); SetChannelRect(); return TRUE; } }
//***************************************************************************** void CBCGPRibbonSlider::SetPos (int nPos, BOOL bRedraw) { ASSERT_VALID (this); m_nPos = min (max (m_nMin, nPos), m_nMax); SetThumbRect (); if (!m_bDontNotify) { CBCGPRibbonBar* pRibbonBar = GetTopLevelRibbonBar (); if (pRibbonBar != NULL) { ASSERT_VALID (pRibbonBar); CArray<CBCGPBaseRibbonElement*, CBCGPBaseRibbonElement*> arButtons; pRibbonBar->GetElementsByID (m_nID, arButtons); for (int i = 0; i < arButtons.GetSize (); i++) { CBCGPRibbonSlider* pOther = DYNAMIC_DOWNCAST (CBCGPRibbonSlider, arButtons [i]); if (pOther != NULL && pOther != this) { ASSERT_VALID (pOther); pOther->m_bDontNotify = TRUE; pOther->SetPos (nPos); pOther->m_bDontNotify = FALSE; } } } } if (bRedraw) { Redraw (); } }
//***************************************************************************** void CBCGPRibbonSlider::OnAfterChangeRect (CDC* pDC) { ASSERT_VALID (this); CBCGPBaseRibbonElement::OnAfterChangeRect (pDC); m_rectZoomOut.SetRectEmpty (); m_rectZoomIn.SetRectEmpty (); m_rectThumb.SetRectEmpty (); m_rectLabel.SetRectEmpty (); m_rectSlider = m_rect; if (m_rect.IsRectEmpty ()) { return; } if (IsVert () && !m_strText.IsEmpty ()) { m_rectLabel = m_rectSlider; m_rectSlider.bottom -= globalData.GetTextHeight (); m_rectLabel.top = m_rectSlider.bottom; } double dblScale = globalData.GetRibbonImageScale (); if (m_bZoomButtons) { m_rectZoomOut = m_rectSlider; if (IsVert ()) { m_rectZoomOut.bottom = m_rectZoomOut.top + (int)(.5 + cySliderHeight * dblScale); } else { m_rectZoomOut.right = m_rectZoomOut.left + m_rectZoomOut.Height (); } m_rectZoomIn = m_rectSlider; if (IsVert ()) { m_rectZoomIn.top = m_rectZoomIn.bottom - (int)(.5 + cySliderHeight * dblScale); m_rectSlider.top = m_rectZoomOut.bottom; m_rectSlider.bottom = m_rectZoomIn.top; } else { m_rectZoomIn.left = m_rectZoomIn.right - m_rectZoomIn.Height (); m_rectSlider.left = m_rectZoomOut.right; m_rectSlider.right = m_rectZoomIn.left; } } int nThumbSize = IsVert () ? cyThumbHeight : cxThumbWidth; if (dblScale > 1.) { nThumbSize = (int)(.5 + dblScale * nThumbSize); } if (IsVert ()) { m_rectSlider.DeflateRect (0, nThumbSize / 2); } else { m_rectSlider.DeflateRect (nThumbSize / 2, 0); } SetThumbRect (); }