void CUploadsCtrl::PaintQueue(CDC& dc, const CRect& rcRow, CUploadQueue* pQueue, BOOL bFocus) { ASSUME_LOCK( UploadQueues.m_pSection ); COLORREF crNatural = CoolInterface.m_crWindow; COLORREF crBack = pQueue->m_bSelected ? CoolInterface.m_crHighlight : crNatural; COLORREF crLeftAligned = crBack ; dc.SetBkColor( crBack ); dc.SetBkMode( OPAQUE ); if ( pQueue->m_bSelected ) dc.SetTextColor( CoolInterface.m_crHiText ); else dc.SetTextColor( CoolInterface.m_crText ); int nTextLeft = rcRow.right, nTextRight = rcRow.left; HDITEM pColumn = {}; pColumn.mask = HDI_FORMAT | HDI_LPARAM; dc.SelectObject( &CoolInterface.m_fntBold ); for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn++ ) { CString strText; CRect rcCell; m_wndHeader.GetItemRect( nColumn, &rcCell ); rcCell.left += rcRow.left; rcCell.right += rcRow.left; rcCell.top = rcRow.top; rcCell.bottom = rcRow.bottom; crLeftAligned = ( rcRow.left == rcCell.left ? crNatural : crBack ) ; POINT ptHover; RECT rcTick = { rcCell.left+2, rcCell.top+2, rcCell.left+14, rcCell.bottom-2 }; GetCursorPos(&ptHover); ScreenToClient(&ptHover); switch ( pColumn.lParam ) { case UPLOAD_COLUMN_TITLE: dc.FillSolidRect( rcCell.left, rcCell.bottom - 1, 32, 1, crLeftAligned ); if ( pQueue->m_bExpanded ) { CoolInterface.Draw( &dc, PtInRect(&rcTick,ptHover) ? IDI_MINUS_HOVER : IDI_MINUS, 16, rcCell.left, rcCell.top, crLeftAligned ); } else { CoolInterface.Draw( &dc, PtInRect(&rcTick,ptHover) ? IDI_PLUS_HOVER : IDI_PLUS, 16, rcCell.left, rcCell.top, crLeftAligned ); } rcCell.left += 16; if ( pQueue == UploadQueues.m_pTorrentQueue ) { ImageList_DrawEx( m_gdiProtocols, PROTOCOL_BT, dc.GetSafeHdc(), rcCell.left, rcCell.top, 16, 16, crLeftAligned, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL ); } else if ( pQueue->m_nProtocols == ( 1 << PROTOCOL_HTTP ) ) { ImageList_DrawEx( m_gdiProtocols, PROTOCOL_HTTP, dc.GetSafeHdc(), rcCell.left, rcCell.top, 16, 16, crLeftAligned, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL ); } else if ( pQueue->m_nProtocols == ( 1 << PROTOCOL_ED2K ) ) { ImageList_DrawEx( m_gdiProtocols, PROTOCOL_ED2K, dc.GetSafeHdc(), rcCell.left, rcCell.top, 16, 16, crLeftAligned, CLR_DEFAULT, pQueue->m_bSelected ? ILD_SELECTED : ILD_NORMAL ); } else { CoolInterface.Draw( &dc, pQueue->m_bExpanded ? IDI_FOLDER_OPEN : IDI_FOLDER_CLOSED, 16, rcCell.left, rcCell.top, crLeftAligned, pQueue->m_bSelected ); } rcCell.left += 16; dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crLeftAligned ); rcCell.left += 1; strText = pQueue->m_sName; break; case UPLOAD_COLUMN_SIZE: if ( pQueue == UploadQueues.m_pTorrentQueue ) strText.Format( _T("%u/%u"), pQueue->m_nMinTransfers, pQueue->m_nMaxTransfers ); //No. Clients was loaded into these variables else if ( pQueue != UploadQueues.m_pHistoryQueue ) strText.Format( _T("%u/%u"), pQueue->GetTransferCount(), pQueue->GetQueuedCount() ); break; case UPLOAD_COLUMN_SPEED: if ( pQueue != UploadQueues.m_pHistoryQueue ) strText = Settings.SmartSpeed( pQueue->GetMeasuredSpeed() ); break; } nTextLeft = min( nTextLeft, (int)rcCell.left ); nTextRight = max( nTextRight, (int)rcCell.right ); if ( rcCell.Width() < 8 ) strText.Empty(); if ( dc.GetTextExtent( strText ).cx > rcCell.Width() - 8 ) { while ( dc.GetTextExtent( strText + _T('\x2026') ).cx > ( rcCell.Width() - 8 ) && strText.GetLength() > 0 ) { strText.Truncate( strText.GetLength() - 1 ); } if ( strText.GetLength() > 0 ) strText += _T('\x2026'); } int nWidth = dc.GetTextExtent( strText ).cx; int nPosition = 0; switch ( pColumn.fmt & LVCFMT_JUSTIFYMASK ) { default: nPosition = ( rcCell.left + 4 ); break; case LVCFMT_CENTER: nPosition = ( ( rcCell.left + rcCell.right ) / 2 ) - ( nWidth / 2 ); break; case LVCFMT_RIGHT: nPosition = ( rcCell.right - 4 - nWidth ); break; } dc.SetBkColor( crBack ); dc.ExtTextOut( nPosition, rcCell.top + 2, ETO_CLIPPED|ETO_OPAQUE, &rcCell, strText, NULL ); } if ( nTextRight < rcRow.right ) { CRect rcBlank( nTextRight, rcRow.top, rcRow.right, rcRow.bottom ); dc.FillSolidRect( &rcBlank, crBack ); } dc.SelectObject( &CoolInterface.m_fntNormal ); if ( bFocus ) { CRect rcFocus( nTextLeft, rcRow.top, max( (int)rcRow.right, nTextRight ), rcRow.bottom ); dc.Draw3dRect( &rcFocus, CoolInterface.m_crHiBorder, CoolInterface.m_crHiBorder ); } }
void CUploadsCtrl::PaintFile(CDC& dc, const CRect& rcRow, CUploadQueue* /*pQueue*/, CUploadFile* pFile, int nPosition, BOOL bFocus) { ASSUME_LOCK( Transfers.m_pSection ); CUploadTransfer* pTransfer = pFile->GetActive(); int nFlagImage = Flags.GetFlagIndex( pTransfer->m_sCountry ); COLORREF crNatural = CoolInterface.m_crWindow; COLORREF crBack = pFile->m_bSelected ? CoolInterface.m_crHighlight : crNatural; COLORREF crLeftAligned = crBack; COLORREF crBorder = pFile->m_bSelected ? CoolInterface.m_crFragmentBorderSelected : CoolInterface.m_crFragmentBorder; dc.SetBkColor( crBack ); dc.SetBkMode( OPAQUE ); if ( pFile->m_bSelected ) dc.SetTextColor( CoolInterface.m_crHiText ); else if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) dc.SetTextColor( CoolInterface.m_crDisabled ); else dc.SetTextColor( CoolInterface.m_crText ); int nTextLeft = rcRow.right, nTextRight = rcRow.left; HDITEM pColumn = {}; pColumn.mask = HDI_FORMAT | HDI_LPARAM; for ( int nColumn = 0 ; m_wndHeader.GetItem( nColumn, &pColumn ) ; nColumn++ ) { CString strText; CRect rcCell; m_wndHeader.GetItemRect( nColumn, &rcCell ); rcCell.left += rcRow.left; rcCell.right += rcRow.left; rcCell.top = rcRow.top; rcCell.bottom = rcRow.bottom; crLeftAligned = ( rcRow.left == rcCell.left ? crNatural : crBack ) ; switch ( pColumn.lParam ) { case UPLOAD_COLUMN_TITLE: dc.FillSolidRect( rcCell.left, rcCell.top, 24, rcCell.Height(), crLeftAligned ); rcCell.left += 24; dc.FillSolidRect( rcCell.left, rcCell.bottom - 1, 16, 1, crLeftAligned ); ShellIcons.Draw( &dc, ShellIcons.Get( ( lstrcmpi( PathFindExtension( pFile->m_sPath ), _T(".partial") ) ? pFile->m_sPath : pFile->m_sName ), 16 ), 16, rcCell.left, rcCell.top, crBack, pFile->m_bSelected ); rcCell.left += 16; dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crLeftAligned ); rcCell.left += 1; strText = pFile->m_sName; break; case UPLOAD_COLUMN_USER: if ( pTransfer == NULL ) strText.Empty(); else if ( pTransfer->m_sRemoteNick.IsEmpty() ) strText = pTransfer->m_sAddress; else strText = pTransfer->m_sRemoteNick + _T(" (") + pTransfer->m_sAddress + _T(")"); break; case UPLOAD_COLUMN_SIZE: strText = Settings.SmartVolume( pFile->m_nSize ); break; case UPLOAD_COLUMN_PROGRESS: dc.Draw3dRect( &rcCell, crBack, crBack ); rcCell.DeflateRect( 1, 1 ); dc.Draw3dRect( &rcCell, crBack, crBack ); rcCell.DeflateRect( 0, 1 ); dc.Draw3dRect( &rcCell, crBorder, crBorder ); rcCell.DeflateRect( 1, 1 ); CFragmentBar::DrawUpload( &dc, &rcCell, pFile, crNatural ); break; case UPLOAD_COLUMN_SPEED: if ( pTransfer == NULL || pTransfer->m_nState == upsNull ) LoadString( strText, IDS_STATUS_COMPLETED ); else if ( pTransfer->m_nProtocol == PROTOCOL_BT ) { CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer; if ( ! pBT->m_bInterested ) LoadString( strText, IDS_STATUS_UNINTERESTED ); else if ( pBT->m_bChoked ) LoadString( strText, IDS_STATUS_CHOKED ); else { DWORD nSpeed = pTransfer->GetMeasuredSpeed(); if ( nSpeed ) strText = Settings.SmartSpeed( nSpeed ); } } else if ( nPosition > 0 ) { CString strQ; LoadString( strQ, IDS_STATUS_Q ); strText.Format( _T("%s %i"), (LPCTSTR)strQ, nPosition ); } else { DWORD nSpeed = pTransfer->GetMeasuredSpeed(); if ( nSpeed ) strText = Settings.SmartSpeed( nSpeed ); else LoadString( strText, IDS_STATUS_NEXT ); } break; case UPLOAD_COLUMN_CLIENT: if ( pTransfer != NULL ) strText = pTransfer->m_sUserAgent; break; case UPLOAD_COLUMN_RATING: strText.Format(_T("%u"), pTransfer->m_nUserRating ); break; case UPLOAD_COLUMN_COUNTRY: dc.FillSolidRect( rcCell.left, rcCell.top, 20, rcCell.Height(), crBack ); rcCell.left += 2; if ( nFlagImage >= 0 ) Flags.Draw( nFlagImage, dc.GetSafeHdc(), rcCell.left, rcCell.top + 2, CLR_NONE, CLR_DEFAULT, pFile->m_bSelected ? ILD_SELECTED : ILD_NORMAL ); rcCell.left += 16; dc.FillSolidRect( rcCell.left, rcCell.top, 1, rcCell.Height(), crNatural ); strText = pTransfer->m_sCountry; break; } nTextLeft = min( (LONG)nTextLeft, rcCell.left ); nTextRight = max( (LONG)nTextRight, rcCell.right ); if ( pColumn.lParam == UPLOAD_COLUMN_PROGRESS ) continue; if ( rcCell.Width() < 8 ) strText.Empty(); if ( dc.GetTextExtent( strText ).cx > rcCell.Width() - 8 ) { while ( dc.GetTextExtent( strText + _T('\x2026') ).cx > ( rcCell.Width() - 8 ) && strText.GetLength() > 0 ) { strText.Truncate( strText.GetLength() - 1 ); } if ( strText.GetLength() > 0 ) strText += _T('\x2026'); } int nWidth = dc.GetTextExtent( strText ).cx; int nPos = 0; switch ( pColumn.fmt & LVCFMT_JUSTIFYMASK ) { default: nPos = ( rcCell.left + 4 ); break; case LVCFMT_CENTER: nPos = ( ( rcCell.left + rcCell.right ) / 2 ) - ( nWidth / 2 ); break; case LVCFMT_RIGHT: nPos = ( rcCell.right - 4 - nWidth ); break; } dc.SetBkColor( crBack ); dc.ExtTextOut( nPos, rcCell.top + 2, ETO_CLIPPED|ETO_OPAQUE, &rcCell, strText, NULL ); } if ( nTextRight < rcRow.right ) { CRect rcBlank( nTextRight, rcRow.top, rcRow.right, rcRow.bottom ); dc.FillSolidRect( &rcBlank, crBack ); } if ( bFocus ) { CRect rcFocus( nTextLeft, rcRow.top, max( (int)rcRow.right, nTextRight ), rcRow.bottom ); dc.Draw3dRect( &rcFocus, CoolInterface.m_crHiBorder, CoolInterface.m_crHiBorder ); } }
int CXTPTabPaintManager::DrawSingleButtonIconAndText(CDC* pDC, CXTPTabManagerItem* pItem, CRect rcItem, BOOL bDraw) { CXTPTabManager* pManager = pItem->GetTabManager(); XTPTabLayoutStyle layout = pManager->GetLayout(); BOOL bVertical = !pManager->IsHorizontalPosition(); if (layout == xtpTabLayoutRotated) bVertical = !bVertical; CString strItem = pItem->GetCaption(); CFont* pFont = m_bBoldSelected && pItem->IsSelected() && pManager->IsActive() ? GetBoldFont(bVertical) : GetFont(bVertical); CXTPFontDC fnt(pDC, pFont); CSize szIcon(m_szIcon); BOOL bDrawIcon = pManager->DrawIcon(pDC, 0, pItem, FALSE, szIcon); BOOL bDrawText = layout != xtpTabLayoutCompressed || pItem->IsSelected(); int nNavigateButtonsLength = 0; if (bDrawText && pItem->GetNavigateButtons()->GetSize() > 0) { nNavigateButtonsLength = 0; for (int i = 0; i < (int)pItem->GetNavigateButtons()->GetSize(); i++) { CXTPTabManagerNavigateButton* pButton = pItem->GetNavigateButtons()->GetAt(i); if (pManager->IsNavigateButtonVisible(pButton)) { CSize sz = pButton->GetSize(); nNavigateButtonsLength += bVertical ? sz.cy : sz.cx; } } if (nNavigateButtonsLength > 0) nNavigateButtonsLength += 3; } if (bDraw) { if (nNavigateButtonsLength > 0) { m_pColorSet->SetTextColor(pDC, pItem); if (bVertical) rcItem.bottom -= 3; else rcItem.right -= 3; for (int i = (int)pItem->GetNavigateButtons()->GetSize() - 1; i >= 0; i--) { CXTPTabManagerNavigateButton* pButton = pItem->GetNavigateButtons()->GetAt(i); if (pManager->IsNavigateButtonVisible(pButton)) { CSize szButton = pButton->GetSize(); if (!bVertical) { pButton->SetRect(CRect(rcItem.right - szButton.cx, rcItem.CenterPoint().y + szButton.cy / 2 - szButton.cy, rcItem.right, rcItem.CenterPoint().y + szButton.cy / 2)); rcItem.right -= szButton.cx; } else { pButton->SetRect(CRect(rcItem.CenterPoint().x - szButton.cx / 2, rcItem.bottom - szButton.cy, rcItem.CenterPoint().x - szButton.cx / 2 + szButton.cx, rcItem.bottom)); rcItem.bottom -= szButton.cy; } pItem->GetNavigateButtons()->GetAt(i)->Draw(pDC); } } } m_pColorSet->SetTextColor(pDC, pItem); CRect rcFocus(rcItem); if (bVertical) { int nAvailLength = pItem->GetButtonLength() - pItem->GetContentLength(); if (nAvailLength > 0) { rcItem.DeflateRect(0, nAvailLength / 2); } rcItem.top += m_rcButtonTextPadding.left + m_rcButtonMargin.left; if (pManager->GetPosition() == xtpTabPositionRight) rcItem.DeflateRect(m_rcButtonMargin.bottom, 0, m_rcButtonMargin.top, 0); else rcItem.DeflateRect(m_rcButtonMargin.top, 0, m_rcButtonMargin.bottom, 0); if (bDrawIcon) { CPoint pt(rcItem.CenterPoint().x - szIcon.cx/2, rcItem.top - 1); if (rcItem.Height() > szIcon.cy) pManager->DrawIcon(pDC, pt, pItem, TRUE, szIcon); rcItem.top += szIcon.cy + 2; } if (bDrawText && rcItem.bottom > rcItem.top + 8) { CSize szText = pDC->GetTextExtent(strItem); rcItem.left = rcItem.right - (rcItem.Width() - szText.cy - (pManager->GetPosition() == xtpTabPositionRight ? 1 : 0)) / 2; rcItem.right = rcItem.left + rcItem.Height(); rcItem.bottom -= m_rcButtonMargin.right + max(0, m_rcButtonTextPadding.right - 4); if (!m_bDrawTextNoPrefix) StripMnemonics(strItem); if (m_bDrawTextPathEllipsis) { DrawTextPathEllipsis(pDC, pManager, strItem, rcItem, DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX); } else { m_pAppearanceSet->DrawText(pDC, pManager, strItem, &rcItem, DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX | (m_bDrawTextEndEllipsis ? DT_END_ELLIPSIS : 0)); } } } else { int nAvailLength = pItem->GetButtonLength() - pItem->GetContentLength(); if (nAvailLength > 0) { rcItem.DeflateRect(nAvailLength / 2, 0); } rcItem.left += m_rcButtonTextPadding.left + m_rcButtonMargin.left; if (pManager->GetPosition() == xtpTabPositionBottom) rcItem.DeflateRect(0, m_rcButtonMargin.bottom, 0, m_rcButtonMargin.top); else rcItem.DeflateRect(0, m_rcButtonMargin.top, 0, m_rcButtonMargin.bottom); if (bDrawIcon) { CPoint pt(rcItem.left - 1, rcItem.CenterPoint().y - szIcon.cy/2); if (rcItem.Width() > szIcon.cx) pManager->DrawIcon(pDC, pt, pItem, TRUE, szIcon); rcItem.left += szIcon.cx + 2; } if (bDrawText && rcItem.right > rcItem.left) { rcItem.right -= m_rcButtonTextPadding.right + m_rcButtonMargin.right - (bDrawIcon ? 2 : 0); if (pItem->GetMarkupUIElement()) { XTPMarkupSetDefaultFont(pItem->GetTabManager()->GetMarkupContext(), (HFONT)pFont->GetSafeHandle(), pDC->GetTextColor()); CRect rcText(rcItem); if (m_nDrawTextFormat & DT_VCENTER) { CSize szText = XTPMarkupMeasureElement(pItem->GetMarkupUIElement()); rcText.top = (rcText.top + rcText.bottom - szText.cy) / 2; rcText.bottom = rcText.top + szText.cy; } XTPMarkupRenderElement(pItem->GetMarkupUIElement(), pDC->GetSafeHdc(), rcText); } else if (m_bDrawTextPathEllipsis) { DrawTextPathEllipsis(pDC, pManager, strItem, rcItem, DT_SINGLELINE | m_nDrawTextFormat | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0)); } else { if (m_bDrawTextHidePrefix) StripMnemonics(strItem); m_pAppearanceSet->DrawText(pDC, pManager, strItem, rcItem, DT_SINGLELINE | m_nDrawTextFormat | (m_bDrawTextHidePrefix || m_bDrawTextNoPrefix ? DT_NOPREFIX : 0) | (m_bDrawTextEndEllipsis ? DT_END_ELLIPSIS : 0)); } } } if (pItem->IsFocused()) { DrawFocusRect(pDC, pItem, rcFocus); } return 0; } else { if (layout == xtpTabLayoutFixed) { return _GetButtonLength(m_nFixedTabWidth, m_nMinTabWidth, m_nMaxTabWidth); } if (layout == xtpTabLayoutCompressed) { if (!bDrawText) return _GetButtonLength(8 + (bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth) ; CXTPFontDC fntItems(pDC, m_bBoldSelected && pManager->IsActive() ? GetBoldFont(bVertical) : GetFont(bVertical)); int nLength = 0; for (int i = 0; i < pManager->GetItemCount(); i++) { CRect rcItemText(0, 0, 0, 0); m_pAppearanceSet->DrawText(pDC, pManager, pManager->GetItem(i)->GetCaption(), rcItemText, DT_SINGLELINE | DT_CALCRECT | DT_NOCLIP | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0)); nLength = max(nLength, rcItemText.Width()); } return _GetButtonLength(nNavigateButtonsLength + nLength + m_rcButtonTextPadding.left + m_rcButtonTextPadding.right + (!bDrawIcon ? 0: bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth); } CSize szText(0); if (pItem->GetMarkupUIElement()) { XTPMarkupSetDefaultFont(pManager->GetMarkupContext(), (HFONT)pFont->GetSafeHandle(), pDC->GetTextColor()); szText = XTPMarkupMeasureElement(pItem->GetMarkupUIElement()); } else { m_pAppearanceSet->DrawText(pDC, pManager, strItem, rcItem, DT_SINGLELINE | DT_CALCRECT | DT_NOCLIP | (m_bDrawTextNoPrefix ? DT_NOPREFIX : 0)); szText = rcItem.Size(); } return _GetButtonLength(nNavigateButtonsLength + szText.cx + m_rcButtonTextPadding.left + m_rcButtonTextPadding.right + (!bDrawIcon ? 0: bVertical ? szIcon.cy : szIcon.cx), m_nMinTabWidth, m_nMaxTabWidth); } }