void CSkinHorizontalScrollbar::OnLButtonDown(UINT nFlags, CPoint point) { pList->Invalidate(FALSE); SetCapture(); CRect clientRect; GetClientRect(&clientRect); int nWidth = clientRect.Width()-26; CRect rectLeftArrow(0,0,26,20); CRect rectRightArrow(nWidth,0,nWidth+26,20); CRect rectThumb(nThumbLeft,0,nThumbLeft+26,20); if(rectThumb.PtInRect(point)) { bMouseDown = true; } if(rectRightArrow.PtInRect(point)) { bMouseDownArrowRight = true; SetTimer(2,250,NULL); } if(rectLeftArrow.PtInRect(point)) { bMouseDownArrowLeft = true; SetTimer(2,250,NULL); } CStatic::OnLButtonDown(nFlags, point); }
void CSkinHorizontalScrollbar::OnLButtonUp(UINT nFlags, CPoint point) { UpdateThumbPosition(); KillTimer(1); ReleaseCapture(); bool bInChannel = true; CRect clientRect; GetClientRect(&clientRect); int nWidth = clientRect.Width()-26; CRect rectLeftArrow(0,0,26,20); CRect rectThumb(nThumbLeft,0,nThumbLeft+26,20); if(rectLeftArrow.PtInRect(point)) { ScrollLeft(); bInChannel = false; } CRect rectRightArrow(nWidth,0,nWidth+26,20); if(rectRightArrow.PtInRect(point)) { ScrollRight(); bInChannel = false; } if(rectThumb.PtInRect(point)) { bInChannel = false; } if(bInChannel == true && !bMouseDown) { if(point.x > nThumbLeft) { PageRight(); } else { PageLeft(); } } //reset all variables bMouseDown = false; bDragging = false; bMouseDownArrowLeft = false; bMouseDownArrowRight = false; CStatic::OnLButtonUp(nFlags, point); }
/////////////////////////////////////////////////////////////////////////////// // OnLButtonUp void CXScrollBar::OnLButtonUp(UINT nFlags, CPoint point) { UpdateThumbPosition(); KillTimer(1); ReleaseCapture(); if (m_bHorizontal) { CRect rectLeftArrow(0, 0, m_nBitmapWidth, m_rectClient.Height()); CRect rectRightArrow(m_rectClient.Width() - m_nBitmapWidth, 0, m_rectClient.Width(), m_rectClient.Height()); CRect rectThumb(m_nThumbLeft, 0, m_nThumbLeft + m_nBitmapWidth, m_rectClient.Height()); if (rectLeftArrow.PtInRect(point)) { ScrollLeft(); } else if (rectRightArrow.PtInRect(point)) { ScrollRight(); } else if (rectThumb.PtInRect(point)) { m_bThumbHover = TRUE; Invalidate(); SetTimer(TIMER_MOUSE_OVER_THUMB, 50, NULL); } m_bMouseDownArrowLeft = FALSE; m_bMouseDownArrowRight = FALSE; } else { CRect rectUpArrow(0, 0, m_rectClient.Width(), m_nBitmapHeight); CRect rectDownArrow(0, m_rectClient.Height() - m_nBitmapHeight, m_rectClient.Width(), m_rectClient.Height()); CRect rectThumb(0, m_nThumbTop, m_rectClient.Width(), m_nThumbTop + m_nBitmapHeight); if (rectUpArrow.PtInRect(point)) { ScrollUp(); } else if (rectDownArrow.PtInRect(point)) { ScrollDown(); } else if (rectThumb.PtInRect(point)) { m_bThumbHover = TRUE; Invalidate(); SetTimer(TIMER_MOUSE_OVER_THUMB, 50, NULL); } m_bMouseDownArrowUp = FALSE; m_bMouseDownArrowDown = FALSE; } m_bMouseDown = FALSE; m_bDragging = FALSE; CStatic::OnLButtonUp(nFlags, point); }
/////////////////////////////////////////////////////////////////////////////// // OnLButtonDown void CXScrollBar::OnLButtonDown(UINT nFlags, CPoint point) { SetCapture(); if (m_bHorizontal) { CRect rectLeftArrow(0, 0, m_nBitmapWidth, m_rectClient.Height()); CRect rectRightArrow(m_rectClient.Width() - m_nBitmapWidth, 0, m_rectClient.Width(), m_rectClient.Height()); CRect rectThumb(m_nThumbLeft, 0, m_nThumbLeft + m_nBitmapWidth, m_rectClient.Height()); if (rectThumb.PtInRect(point)) { m_bMouseDown = TRUE; } else if (rectRightArrow.PtInRect(point)) { m_bMouseDownArrowRight = TRUE; SetTimer(TIMER_LBUTTON_PRESSED, 150, NULL); } else if (rectLeftArrow.PtInRect(point)) { m_bMouseDownArrowLeft = TRUE; SetTimer(TIMER_LBUTTON_PRESSED, 150, NULL); } else // button down in channel { m_nThumbLeft = point.x - m_nBitmapWidth / 2; SetPositionFromThumb(); Draw(); if (m_pParent && ::IsWindow(m_pParent->m_hWnd)) { m_pParent->SendMessage(WM_HSCROLL, MAKELONG(SB_THUMBTRACK, m_nPos), (LPARAM)m_hWnd); } } } else { CRect rectUpArrow(0, 0, m_rectClient.Width(), m_nBitmapHeight); CRect rectDownArrow(0, m_rectClient.Height() - m_nBitmapHeight, m_rectClient.Width(), m_rectClient.Height()); CRect rectThumb(0, m_nThumbTop, m_rectClient.Width(), m_nThumbTop + m_nBitmapHeight); if (rectThumb.PtInRect(point)) { m_bMouseDown = TRUE; } else if (rectDownArrow.PtInRect(point)) { m_bMouseDownArrowDown = TRUE; SetTimer(TIMER_LBUTTON_PRESSED, 150, NULL); } else if (rectUpArrow.PtInRect(point)) { m_bMouseDownArrowUp = TRUE; SetTimer(TIMER_LBUTTON_PRESSED, 150, NULL); } else // button down in channel { m_nThumbTop = point.y - m_nBitmapHeight / 2; SetPositionFromThumb(); Draw(); if (m_pParent && ::IsWindow(m_pParent->m_hWnd)) { m_pParent->SendMessage(WM_VSCROLL, MAKELONG(SB_THUMBTRACK, m_nPos), (LPARAM)m_hWnd); } } } CStatic::OnLButtonDown(nFlags, point); }
/////////////////////////////////////////////////////////////////////////////// // DrawHorizontal void CXScrollBar::DrawHorizontal() { TRACE(_T("in CXScrollBar::DrawHorizontal\n")); CClientDC dc(this); CMemDC memDC(&dc, &m_rectClient); CBrush brushFrame(FRAME_COLOR); CDC bitmapDC; bitmapDC.CreateCompatibleDC(&dc); CBitmap bitmap; // ===== draw left arrow ===== VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_LEFTARROW)); CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap); // NOTE: thumb and arrow bitmaps are assumed to be same width and height CRect rectLeftArrow(m_rectClient.left, m_rectClient.top, m_rectClient.left + m_nBitmapWidth, m_rectClient.bottom); memDC.StretchBlt(rectLeftArrow.left, rectLeftArrow.top+1, rectLeftArrow.Width(), rectLeftArrow.Height()-1, &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectLeftArrow, &brushFrame); int nChannelStart = m_rectClient.left + m_nBitmapWidth; int nChannelWidth = m_rectClient.Width() - 2*m_nBitmapWidth; if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // ===== draw channel ===== // save new thumb position TRACE(_T("m_nThumbLeft=%d\n"), m_nThumbLeft); m_rectThumb.left = m_rectClient.left + m_nThumbLeft; m_rectThumb.right = m_rectThumb.left + m_nBitmapWidth; m_rectThumb.top = m_rectClient.top; m_rectThumb.bottom = m_rectThumb.top + m_rectClient.Height(); VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_CHANNEL)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectChannelRight(m_rectThumb.left + m_nBitmapWidth/2, m_rectClient.top, nChannelStart + nChannelWidth, m_rectClient.bottom); memDC.StretchBlt(rectChannelRight.left, rectChannelRight.top+1, rectChannelRight.Width(), rectChannelRight.Height()-1, &bitmapDC, 0, 0, 1, m_nBitmapHeight, SRCCOPY); if (m_bChannelColor && m_bThumbColor) { // thumb has a color, so use same (lightened) color for channel CColor color; color.SetRGB(GetRValue(m_ThumbColor), GetGValue(m_ThumbColor), GetBValue(m_ThumbColor)); color.ToHLS(); float fLuminance = color.GetLuminance(); // use 80% L, 150% S for main color fLuminance = .80f; float fSaturation = color.GetSaturation(); fSaturation = 0.5f * fSaturation; float fHue = color.GetHue(); color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb3 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .87 L for second highlight color fLuminance = .87f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb2 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); // use .92 L for first highlight color fLuminance = .92f; color.SetHLS(fHue, fLuminance, fSaturation); color.ToRGB(); COLORREF rgb1 = RGB(color.GetRed(), color.GetGreen(), color.GetBlue()); BITMAP bm; bitmap.GetBitmap(&bm); // set highlight colors bitmapDC.SetPixel(0, 0, rgb1); bitmapDC.SetPixel(0, 1, rgb2); // set main color for (int y = 2; y < (bm.bmHeight); y++) { bitmapDC.SetPixel(0, y, rgb3); } } CRect rectChannelLeft(nChannelStart, m_rectClient.top, m_rectThumb.left + m_nBitmapWidth/2, m_rectClient.bottom); memDC.StretchBlt(rectChannelLeft.left, rectChannelLeft.top+1, rectChannelLeft.Width(), rectChannelLeft.Height()-1, &bitmapDC, 0, 0, 1, m_nBitmapHeight, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // ===== draw right arrow ===== VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_RIGHTARROW)); pOldBitmap = bitmapDC.SelectObject(&bitmap); CRect rectRightArrow(m_rectClient.right - m_nBitmapWidth, m_rectClient.top, m_rectClient.right, m_rectClient.bottom); memDC.StretchBlt(rectRightArrow.left, rectRightArrow.top+1, rectRightArrow.Width(), rectRightArrow.Height()-1, &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); memDC.FrameRect(&rectRightArrow, &brushFrame); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; // If there is nothing to scroll then don't show the thumb if (m_nRange) { // ===== draw thumb ===== if (m_bThumbColor) { VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_THUMB)); } else { VERIFY(bitmap.LoadBitmap(IDB_HORIZONTAL_SCROLLBAR_THUMB_NO_COLOR)); } pOldBitmap = bitmapDC.SelectObject(&bitmap); COLORREF rgbThumb = m_ThumbColor; if (m_bThumbHover) { rgbThumb = m_ThumbHoverColor; } COLORREF rgbPrev = 0; // add desired color to thumb for (int x = 0; x < m_nBitmapWidth; x++) { for (int y = 0; y < m_nBitmapHeight; y++) { COLORREF rgb = bitmapDC.GetPixel(x, y); if (m_bThumbColor && (rgb == THUMB_MASK_COLOR)) { bitmapDC.SetPixel(x, y, rgbThumb); } else if (rgb == THUMB_GRIPPER_MASK_COLOR) { if (m_bThumbGripper) { bitmapDC.SetPixel(x, y, THUMB_GRIPPER_COLOR); } else { bitmapDC.SetPixel(x, y, rgbPrev); } } else if (rgb == THUMB_LEFT_TRANSPARENT_MASK_COLOR) { COLORREF rgbLeftChannel = memDC.GetPixel(nChannelStart, y); bitmapDC.SetPixel(x, y, rgbLeftChannel); } else if (rgb == THUMB_RIGHT_TRANSPARENT_MASK_COLOR) { COLORREF rgbRightChannel = memDC.GetPixel(nChannelStart+nChannelWidth-1, y); bitmapDC.SetPixel(x, y, rgbRightChannel); } rgbPrev = rgb; } } memDC.StretchBlt(m_rectThumb.left, m_rectThumb.top, m_rectThumb.Width(), m_rectThumb.Height(), &bitmapDC, 0, 0, m_nBitmapWidth, m_nBitmapHeight, SRCCOPY); if (pOldBitmap) { bitmapDC.SelectObject(pOldBitmap); } if (bitmap.GetSafeHandle()) { bitmap.DeleteObject(); } pOldBitmap = NULL; } else { m_rectThumb = CRect(-1,-1,-1,-1); } memDC.FrameRect(&m_rectClient, &brushFrame); }