static void restore_bk_color (ANIMATIONINFO* anim_info, ANIMATIONFRAME* frame) { SetBrushColor (anim_info->mem_dc, GetBkColor(anim_info->mem_dc)); FillBox (anim_info->mem_dc, frame->off_x, frame->off_y, frame->width, frame->height); }
/* ** This is cribbed from FX/fxwgl.c, and seems to implement support ** for bitmap fonts where the wglUseFontBitmapsA() code implements ** support for outline fonts. In combination they hopefully give ** fairly generic support for fonts. */ static BOOL wglUseFontBitmaps_FX(HDC fontDevice, DWORD firstChar, DWORD numChars, DWORD listBase) { #define VERIFY(a) a TEXTMETRIC metric; BITMAPINFO *dibInfo; HDC bitDevice; COLORREF tempColor; int i; VERIFY(GetTextMetrics(fontDevice, &metric)); dibInfo = (BITMAPINFO *) calloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD), 1); dibInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); dibInfo->bmiHeader.biPlanes = 1; dibInfo->bmiHeader.biBitCount = 1; dibInfo->bmiHeader.biCompression = BI_RGB; bitDevice = CreateCompatibleDC(fontDevice); // Swap fore and back colors so the bitmap has the right polarity tempColor = GetBkColor(bitDevice); SetBkColor(bitDevice, GetTextColor(bitDevice)); SetTextColor(bitDevice, tempColor); // Place chars based on base line VERIFY(SetTextAlign(bitDevice, TA_BASELINE) != GDI_ERROR ? 1 : 0); for(i = 0; i < (int)numChars; i++) { SIZE size; char curChar; int charWidth,charHeight,bmapWidth,bmapHeight,numBytes,res; HBITMAP bitObject; HGDIOBJ origBmap; unsigned char *bmap; curChar = (char)(i + firstChar); // Find how high/wide this character is VERIFY(GetTextExtentPoint32(bitDevice, &curChar, 1, &size)); // Create the output bitmap charWidth = size.cx; charHeight = size.cy; // Round up to the next multiple of 32 bits bmapWidth = ((charWidth + 31) / 32) * 32; bmapHeight = charHeight; bitObject = CreateCompatibleBitmap(bitDevice, bmapWidth, bmapHeight); //VERIFY(bitObject); // Assign the output bitmap to the device origBmap = SelectObject(bitDevice, bitObject); (void) VERIFY(origBmap); VERIFY( PatBlt( bitDevice, 0, 0, bmapWidth, bmapHeight,BLACKNESS ) ); // Use our source font on the device VERIFY(SelectObject(bitDevice, GetCurrentObject(fontDevice,OBJ_FONT))); // Draw the character VERIFY(TextOut(bitDevice, 0, metric.tmAscent, &curChar, 1)); // Unselect our bmap object VERIFY(SelectObject(bitDevice, origBmap)); // Convert the display dependant representation to a 1 bit deep DIB numBytes = (bmapWidth * bmapHeight) / 8; bmap = malloc(numBytes); dibInfo->bmiHeader.biWidth = bmapWidth; dibInfo->bmiHeader.biHeight = bmapHeight; res = GetDIBits(bitDevice, bitObject, 0, bmapHeight, bmap, dibInfo, DIB_RGB_COLORS); //VERIFY(res); // Create the GL object glNewList(i + listBase, GL_COMPILE); glBitmap(bmapWidth, bmapHeight, 0.0, (GLfloat)metric.tmDescent, (GLfloat)charWidth, 0.0, bmap); glEndList(); // CheckGL(); // Destroy the bmap object DeleteObject(bitObject); // Deallocate the bitmap data free(bmap); } // Destroy the DC VERIFY(DeleteDC(bitDevice)); free(dibInfo); return TRUE; #undef VERIFY }
void CSchemaCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if ( lpDrawItemStruct->itemID == (UINT)-1 ) return; if ( ( lpDrawItemStruct->itemAction & ODA_SELECT ) == 0 && ( lpDrawItemStruct->itemAction & ODA_DRAWENTIRE ) == 0 ) return; CRect rcItem( &lpDrawItemStruct->rcItem ); CPoint pt( rcItem.left + 1, rcItem.top + 1 ); CDC dc; dc.Attach( lpDrawItemStruct->hDC ); if ( Settings.General.LanguageRTL ) SetLayout( dc.m_hDC, LAYOUT_RTL ); dc.SetTextColor( ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? CoolInterface.m_crHiText : CoolInterface.m_crDropdownText ); CSchemaPtr pSchema = (CSchemaPtr)lpDrawItemStruct->itemData; if ( pSchema != NULL ) { /*dc.FillSolidRect( &rcItem, GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );*/ if ( IsWindowEnabled() ) { if ( lpDrawItemStruct->itemState & ODS_SELECTED ) dc.FillSolidRect( &rcItem, CoolInterface.m_crHighlight ); else dc.FillSolidRect( &rcItem, CoolInterface.m_crDropdownBox ); } else dc.FillSolidRect( &rcItem, GetBkColor(lpDrawItemStruct->hDC) ); dc.SetBkMode( TRANSPARENT ); ShellIcons.Draw( &dc, pSchema->m_nIcon16, 16, pt.x, pt.y, CLR_NONE, ( lpDrawItemStruct->itemState & ODS_SELECTED ) ); rcItem.left += 20; rcItem.right -= 2; CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFont ); CString strURI = pSchema->GetURI(); if ( dc.GetTextExtent( pSchema->m_sTitle + strURI ).cx > rcItem.Width() - 20 && strURI.GetLength() > 8 ) { LPCTSTR pszLeft = _tcschr( (LPCTSTR)strURI + 7, '/' ); int nRight = strURI.ReverseFind( '/' ); if ( pszLeft && nRight >= 0 ) { int nLeft = static_cast< int >( pszLeft - (LPCTSTR)strURI ); // !!! (TODO) strURI = strURI.Left( nLeft ) + _T("/\x2026") + strURI.Mid( nRight ); } } if ( dc.GetTextExtent( pSchema->m_sTitle + strURI ).cx <= rcItem.Width() - 20 ) { // COLORREF crBackup = dc.SetTextColor( GetSysColor( COLOR_GRAYTEXT ) ); dc.DrawText( strURI, &rcItem, DT_SINGLELINE|DT_RIGHT|DT_VCENTER|DT_NOPREFIX ); // dc.SetTextColor( crBackup ); } dc.SelectObject( &theApp.m_gdiFontBold ); dc.DrawText( pSchema->m_sTitle, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX ); dc.SelectObject( pOldFont ); } else if ( lpDrawItemStruct->itemID == 0 ) { /*dc.FillSolidRect( &rcItem, GetSysColor( ( lpDrawItemStruct->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHT : COLOR_WINDOW ) );*/ if ( IsWindowEnabled() ) { if ( lpDrawItemStruct->itemState & ODS_SELECTED ) dc.FillSolidRect( &rcItem, CoolInterface.m_crHighlight ); else dc.FillSolidRect( &rcItem, CoolInterface.m_crDropdownBox ); } else dc.FillSolidRect( &rcItem, GetBkColor(lpDrawItemStruct->hDC) ); dc.SetBkMode( TRANSPARENT ); CoolInterface.Draw( &dc, IDR_SEARCHFRAME, 16, pt.x, pt.y, CLR_NONE, ( lpDrawItemStruct->itemState & ODS_SELECTED ) ); rcItem.left += 20; rcItem.right -= 2; CFont* pOldFont = (CFont*)dc.SelectObject( &theApp.m_gdiFontBold ); dc.DrawText( m_sNoSchemaText, &rcItem, DT_SINGLELINE|DT_LEFT|DT_VCENTER|DT_NOPREFIX ); dc.SelectObject( pOldFont ); } else { dc.Draw3dRect( &rcItem, CoolInterface.m_crDropdownBox , CoolInterface.m_crDropdownBox ); rcItem.DeflateRect( 1, 1 ); if ( lpDrawItemStruct->itemState & ODS_SELECTED ) { dc.Draw3dRect( &rcItem, CoolInterface.m_crBorder, CoolInterface.m_crBorder ); rcItem.DeflateRect( 1, 1 ); dc.FillSolidRect( &rcItem, CoolInterface.m_crBackSel ); } else { dc.FillSolidRect( &rcItem, GetSysColor( COLOR_WINDOW /* COLOR_BTNFACE */ ) ); } dc.SetBkMode( TRANSPARENT ); pt = rcItem.CenterPoint(); pt.x -= 8; pt.y -= 8; CoolInterface.Draw( &dc, IDI_CHEVRON, 16, pt.x, pt.y ); } dc.Detach(); }
void CtrlMemView::onPaint(WPARAM wParam, LPARAM lParam) { // draw to a bitmap for double buffering PAINTSTRUCT ps; HDC actualHdc = BeginPaint(wnd, &ps); HDC hdc = CreateCompatibleDC(actualHdc); HBITMAP hBM = CreateCompatibleBitmap(actualHdc, rect.right-rect.left, rect.bottom-rect.top); SelectObject(hdc, hBM); SetBkMode(hdc,OPAQUE); HPEN standardPen = CreatePen(0,0,0xFFFFFF); HBRUSH standardBrush = CreateSolidBrush(0xFFFFFF); HPEN oldPen = (HPEN) SelectObject(hdc,standardPen); HBRUSH oldBrush = (HBRUSH) SelectObject(hdc,standardBrush); HFONT oldFont = (HFONT) SelectObject(hdc,(HGDIOBJ)font); // white background SelectObject(hdc,standardPen); SelectObject(hdc,standardBrush); Rectangle(hdc,0,0,rect.right,rect.bottom); // draw one extra row that may be partially visible for (int i = 0; i < visibleRows+1; i++) { char temp[32]; unsigned int address=windowStart + i*rowSize; int rowY = rowHeight*i; sprintf(temp,"%08X",address); SetTextColor(hdc,0x600000); TextOutA(hdc,addressStart,rowY,temp,(int)strlen(temp)); SetTextColor(hdc,0x000000); u32 memory[4]; bool valid = debugger != NULL && debugger->isAlive() && Memory::IsValidAddress(address); if (valid) { memory[0] = debugger->readMemory(address); memory[1] = debugger->readMemory(address+4); memory[2] = debugger->readMemory(address+8); memory[3] = debugger->readMemory(address+12); } u8* m = (u8*) memory; for (int j = 0; j < rowSize; j++) { if (valid) sprintf(temp,"%02X",m[j]); else strcpy(temp,"??"); unsigned char c = m[j]; if (c < 32 || c >= 128 || valid == false) c = '.'; if (address+j == curAddress && searching == false) { COLORREF oldBkColor = GetBkColor(hdc); COLORREF oldTextColor = GetTextColor(hdc); if (hasFocus && !asciiSelected) { SetTextColor(hdc,0xFFFFFF); SetBkColor(hdc,0xFF9933); if (selectedNibble == 0) SelectObject(hdc,(HGDIOBJ)underlineFont); } else { SetTextColor(hdc,0); SetBkColor(hdc,0xC0C0C0); } TextOutA(hdc,hexStart+j*3*charWidth,rowY,&temp[0],1); if (hasFocus && !asciiSelected) { if (selectedNibble == 1) SelectObject(hdc,(HGDIOBJ)underlineFont); else SelectObject(hdc,(HGDIOBJ)font); } TextOutA(hdc,hexStart+j*3*charWidth+charWidth,rowY,&temp[1],1); if (hasFocus && asciiSelected) { SetTextColor(hdc,0xFFFFFF); SetBkColor(hdc,0xFF9933); } else { SetTextColor(hdc,0); SetBkColor(hdc,0xC0C0C0); SelectObject(hdc,(HGDIOBJ)font); } TextOutA(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); SetTextColor(hdc,oldTextColor); SetBkColor(hdc,oldBkColor); } else { TextOutA(hdc,hexStart+j*3*charWidth,rowY,temp,2); TextOutA(hdc,asciiStart+j*(charWidth+2),rowY,(char*)&c,1); } } } SelectObject(hdc,oldFont); SelectObject(hdc,oldPen); SelectObject(hdc,oldBrush); // copy bitmap to the actual hdc BitBlt(actualHdc,0,0,rect.right,rect.bottom,hdc,0,0,SRCCOPY); DeleteObject(hBM); DeleteDC(hdc); DeleteObject(standardPen); DeleteObject(standardBrush); EndPaint(wnd, &ps); }
void CClientListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (!theApp.emuledlg->IsRunning()) return; if (!lpDrawItemStruct->itemData) return; CDC* odc = CDC::FromHandle(lpDrawItemStruct->hDC); BOOL bCtrlFocused = ((GetFocus() == this) || (GetStyle() & LVS_SHOWSELALWAYS)); if (lpDrawItemStruct->itemState & ODS_SELECTED) { if (bCtrlFocused) odc->SetBkColor(m_crHighlight); else odc->SetBkColor(m_crNoHighlight); } else odc->SetBkColor(GetBkColor()); const CUpDownClient* client = (CUpDownClient*)lpDrawItemStruct->itemData; CMemDC dc(odc, &lpDrawItemStruct->rcItem); CFont* pOldFont = dc.SelectObject(GetFont()); CRect cur_rec(lpDrawItemStruct->rcItem); COLORREF crOldTextColor = dc.SetTextColor((lpDrawItemStruct->itemState & ODS_SELECTED) ? m_crHighlightText : m_crWindowText); int iOldBkMode; if (m_crWindowTextBk == CLR_NONE){ DefWindowProc(WM_ERASEBKGND, (WPARAM)(HDC)dc, 0); iOldBkMode = dc.SetBkMode(TRANSPARENT); } else iOldBkMode = OPAQUE; CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl(); int iCount = pHeaderCtrl->GetItemCount(); cur_rec.right = cur_rec.left - 8; cur_rec.left += 4; CString Sbuffer; for(int iCurrent = 0; iCurrent < iCount; iCurrent++){ int iColumn = pHeaderCtrl->OrderToIndex(iCurrent); if( !IsColumnHidden(iColumn) ){ cur_rec.right += GetColumnWidth(iColumn); switch(iColumn){ case 0:{ uint8 image; if (client->IsFriend()) image = 2; else if (client->GetClientSoft() == SO_EDONKEYHYBRID) image = 4; else if (client->GetClientSoft() == SO_MLDONKEY) image = 3; else if (client->GetClientSoft() == SO_SHAREAZA) image = 5; else if (client->GetClientSoft() == SO_URL) image = 6; else if (client->GetClientSoft() == SO_AMULE) image = 7; else if (client->GetClientSoft() == SO_LPHANT) image = 8; else if (client->ExtProtocolAvailable()) image = 1; else image = 0; uint32 nOverlayImage = 0; if ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED)) nOverlayImage |= 1; if (client->IsObfuscatedConnectionEstablished()) nOverlayImage |= 2; POINT point = {cur_rec.left, cur_rec.top+1}; imagelist.Draw(dc,image, point, ILD_NORMAL | ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED) ? INDEXTOOVERLAYMASK(1) : 0)); if (client->GetUserName()==NULL) Sbuffer.Format(_T("(%s)"), GetResString(IDS_UNKNOWN)); else Sbuffer = client->GetUserName(); //EastShare Start - added by AndCycle, IP to Country CString tempStr; tempStr.Format(_T("%s%s"), client->GetCountryName(), Sbuffer); Sbuffer = tempStr; if(CGlobalVariable::ip2country->ShowCountryFlag()){ cur_rec.left+=20; POINT point2= {cur_rec.left,cur_rec.top+1}; CGlobalVariable::ip2country->GetFlagImageList()->DrawIndirect(dc, client->GetCountryFlagIndex(), point2, CSize(18,16), CPoint(0,0), ILD_NORMAL); } //EastShare End - added by AndCycle, IP to Country cur_rec.left +=20; dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left -=20; //EastShare Start - added by AndCycle, IP to Country if(CGlobalVariable::ip2country->ShowCountryFlag()){ cur_rec.left-=20; } //EastShare End - added by AndCycle, IP to Country break; } case 1:{ Sbuffer = client->GetUploadStateDisplayString(); break; } case 2:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetUploadedTotal(), false, false); else Sbuffer.Empty(); break; } case 3:{ Sbuffer = client->GetDownloadStateDisplayString(); break; } case 4:{ if(client->credits) Sbuffer = CastItoXBytes(client->credits->GetDownloadedTotal(), false, false); else Sbuffer.Empty(); break; } case 5:{ Sbuffer = client->GetClientSoftVer(); if (Sbuffer.IsEmpty()) Sbuffer = GetResString(IDS_UNKNOWN); break; } case 6:{ if(client->socket){ if(client->socket->IsConnected()){ Sbuffer = GetResString(IDS_YES); break; } } Sbuffer = GetResString(IDS_NO); break; } case 7: Sbuffer = md4str(client->GetUserHash()); break; } if( iColumn != 0) dc.DrawText(Sbuffer,Sbuffer.GetLength(),&cur_rec,DLC_DT_TEXT); cur_rec.left += GetColumnWidth(iColumn); } } // draw rectangle around selected item(s) if (lpDrawItemStruct->itemState & ODS_SELECTED) { RECT outline_rec = lpDrawItemStruct->rcItem; outline_rec.top--; outline_rec.bottom++; dc.FrameRect(&outline_rec, &CBrush(GetBkColor())); outline_rec.top++; outline_rec.bottom--; outline_rec.left++; outline_rec.right--; if(bCtrlFocused) dc.FrameRect(&outline_rec, &CBrush(m_crFocusLine)); else dc.FrameRect(&outline_rec, &CBrush(m_crNoFocusLine)); } if (m_crWindowTextBk == CLR_NONE) dc.SetBkMode(iOldBkMode); dc.SelectObject(pOldFont); dc.SetTextColor(crOldTextColor); }
void CUploadListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (!theApp.emuledlg->IsRunning()) return; if (!lpDrawItemStruct->itemData) return; CMemDC dc(CDC::FromHandle(lpDrawItemStruct->hDC), &lpDrawItemStruct->rcItem); BOOL bCtrlFocused; InitItemMemDC(dc, lpDrawItemStruct, bCtrlFocused); CRect cur_rec(lpDrawItemStruct->rcItem); CRect rcClient; GetClientRect(&rcClient); const CUpDownClient* client = (CUpDownClient*)lpDrawItemStruct->itemData; COLORREF crOldBackColor = dc->GetBkColor(); //Xman PowerRelease CKnownFile* file = CGlobalVariable::sharedfiles->GetFileByID(client->GetUploadFileID()); CHeaderCtrl *pHeaderCtrl = GetHeaderCtrl(); int iCount = pHeaderCtrl->GetItemCount(); cur_rec.right = cur_rec.left - 8; cur_rec.left += 4; CString Sbuffer; for (int iCurrent = 0; iCurrent < iCount; iCurrent++) { int iColumn = pHeaderCtrl->OrderToIndex(iCurrent); if (!IsColumnHidden(iColumn)) { cur_rec.right += GetColumnWidth(iColumn); switch (iColumn) { case 0: { uint8 image; if (client->IsFriend()) image = 4; else if (client->GetClientSoft() == SO_EDONKEYHYBRID) { if (client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 8; else image = 7; } else if (client->GetClientSoft() == SO_MLDONKEY) { if (client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 6; else image = 5; } else if (client->GetClientSoft() == SO_SHAREAZA) { if(client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 10; else image = 9; } else if (client->GetClientSoft() == SO_AMULE) { if(client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 12; else image = 11; } else if (client->GetClientSoft() == SO_LPHANT) { if(client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 14; else image = 13; } else if (client->ExtProtocolAvailable()) { if(client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 3; else image = 1; } else { if (client->credits && client->credits->GetScoreRatio(client->GetIP()) > 1) image = 2; else image = 0; } uint32 nOverlayImage = 0; if ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED)) nOverlayImage |= 1; if (client->IsObfuscatedConnectionEstablished()) nOverlayImage |= 2; POINT point = {cur_rec.left, cur_rec.top+1}; imagelist.Draw(dc,image, point, ILD_NORMAL | ((client->Credits() && client->Credits()->GetCurrentIdentState(client->GetIP()) == IS_IDENTIFIED) ? INDEXTOOVERLAYMASK(1) : 0)); Sbuffer = client->GetUserName(); //EastShare Start - added by AndCycle, IP to Country CString tempStr; tempStr.Format(_T("%s%s"), client->GetCountryName(), Sbuffer); Sbuffer = tempStr; if(CGlobalVariable::ip2country->ShowCountryFlag()) { cur_rec.left += 20; POINT point2= {cur_rec.left,cur_rec.top+1}; CGlobalVariable::ip2country->GetFlagImageList()->DrawIndirect(dc, client->GetCountryFlagIndex(), point2, CSize(18,16), CPoint(0,0), ILD_NORMAL); } //EastShare End - added by AndCycle, IP to Country cur_rec.left += 20; dc.DrawText(Sbuffer, Sbuffer.GetLength(), &cur_rec, DLC_DT_TEXT); cur_rec.left -= 20; //EastShare Start - added by AndCycle, IP to Country if(CGlobalVariable::ip2country->ShowCountryFlag()) { cur_rec.left-=20; } //EastShare End - added by AndCycle, IP to Country break; } case 1: if (file) Sbuffer = file->GetFileName(); else Sbuffer = _T("?"); if(file && file->GetUpPriority()==PR_POWER) ///PowerRelease dc->SetBkColor(RGB(255,225,225)); break; case 2: Sbuffer = CastItoXBytes(client->GetDatarate(), false, true); break; case 3: // NOTE: If you change (add/remove) anything which is displayed here, update also the sorting part.. if (thePrefs.m_bExtControls) Sbuffer.Format( _T("%s (%s)"), CastItoXBytes(client->GetSessionUp(), false, false), CastItoXBytes(client->GetQueueSessionPayloadUp(), false, false)); else Sbuffer = CastItoXBytes(client->GetSessionUp(), false, false); break; case 4: if (client->HasLowID()) Sbuffer.Format(_T("%s (%s)"), CastSecondsToHM(client->GetWaitTime()/1000), GetResString(IDS_IDLOW)); else Sbuffer = CastSecondsToHM(client->GetWaitTime()/1000); break; case 5: Sbuffer = CastSecondsToHM(client->GetUpStartTimeDelay()/1000); break; case 6: Sbuffer = client->GetUploadStateDisplayString(); break; case 7: cur_rec.bottom--; cur_rec.top++; client->DrawUpStatusBar(dc, &cur_rec, false, thePrefs.UseFlatBar()); cur_rec.bottom++; cur_rec.top--; break; } if (iColumn != 7 && iColumn != 0) dc.DrawText(Sbuffer, Sbuffer.GetLength(), &cur_rec, DLC_DT_TEXT); dc->SetBkColor( crOldBackColor ); cur_rec.left += GetColumnWidth(iColumn); } } //draw rectangle around selected item(s) if (lpDrawItemStruct->itemState & ODS_SELECTED) { RECT outline_rec = lpDrawItemStruct->rcItem; outline_rec.top--; outline_rec.bottom++; dc.FrameRect(&outline_rec, &CBrush(GetBkColor())); outline_rec.top++; outline_rec.bottom--; outline_rec.left++; outline_rec.right--; if (bCtrlFocused) dc.FrameRect(&outline_rec, &CBrush(m_crFocusLine)); else dc.FrameRect(&outline_rec, &CBrush(m_crNoFocusLine)); } /* if (m_crWindowTextBk == CLR_NONE) dc.SetBkMode(iOldBkMode); dc.SelectObject(pOldFont); dc.SetTextColor(crOldTextColor);*/ }
void KGTreeCtrl::OnTimer(UINT nIDEvent) { if (nIDEvent == m_nHoverTimerID) { KillTimer(m_nHoverTimerID); m_nHoverTimerID = 0; HTREEITEM trItem = 0; UINT uFlag = 0; trItem = HitTest(m_HoverPoint, &uFlag); if (trItem && m_bDragging) { //SelectItem(trItem); Expand(trItem, TVE_EXPAND); Invalidate(); CRect rect; GetItemRect(trItem, &rect, true); rect.left -= 35; m_curPointLeft.x = rect.left; m_curPointLeft.y = rect.bottom; m_curPointRigh.x = rect.right; m_curPointRigh.y = rect.bottom; } } else if(nIDEvent == m_nScrollTimerID) { m_TimerTicks++; CPoint pt; GetCursorPos(&pt); CRect rect; GetClientRect(&rect); ClientToScreen(&rect); HTREEITEM hItem = GetFirstVisibleItem(); if ( pt.y < rect.top +10) { int slowscroll = 6 - (rect.top + 10 - pt.y )/20; if( 0 == (m_TimerTicks % ((slowscroll > 0) ? slowscroll : 1)) ) { CImageList::DragShowNolock ( false ); SendMessage( WM_VSCROLL,SB_LINEUP ); SelectDropTarget( hItem ); m_hItemDragD = hItem; CImageList::DragShowNolock ( true ); } } else if( pt.y > rect.bottom - 10 ) { int slowscroll = 6 - (pt.y - rect.bottom + 10)/20; if( 0 == (m_TimerTicks % ((slowscroll > 0) ? slowscroll : 1)) ) { CImageList::DragShowNolock ( false ); SendMessage( WM_VSCROLL,SB_LINEDOWN ); int nCount = GetVisibleCount(); for( int i=0 ; i<nCount-1 ; i++ ) hItem = GetNextVisibleItem( hItem ); if( hItem ) SelectDropTarget( hItem ); m_hItemDragD = hItem; CImageList::DragShowNolock ( true ); } } } else if (nIDEvent == m_nDrawLineTimerID) { CClientDC dc(this); CPen penP(PS_SOLID, 2, GetBkColor()); dc.SelectObject(&penP); dc.MoveTo(m_pointLeft); dc.LineTo(m_pointRigh); dc.MoveTo(m_pointLeft.x, m_pointLeft.y - 5); dc.LineTo(m_pointLeft.x, m_pointLeft.y + 5); CPen penN(PS_SOLID, 2, RGB(122, 178, 255)); dc.SelectObject(&penN); dc.MoveTo(m_curPointLeft); dc.LineTo(m_curPointRigh); dc.MoveTo(m_curPointLeft.x, m_curPointLeft.y - 5); dc.LineTo(m_curPointLeft.x, m_curPointLeft.y + 5); m_pointLeft.x = m_curPointLeft.x; m_pointLeft.y = m_curPointLeft.y; m_pointRigh.x = m_curPointRigh.x; m_pointRigh.y = m_curPointRigh.y; } else CTreeCtrl::OnTimer(nIDEvent); }
INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush ) { DWORD size; METARECORD *mr; LOGBRUSH logbrush; METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev; BOOL r; if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return -1; switch(logbrush.lbStyle) { case BS_SOLID: case BS_NULL: case BS_HATCHED: { LOGBRUSH16 lb16; lb16.lbStyle = logbrush.lbStyle; lb16.lbColor = logbrush.lbColor; lb16.lbHatch = logbrush.lbHatch; size = sizeof(METARECORD) + sizeof(LOGBRUSH16) - 2; mr = HeapAlloc( GetProcessHeap(), 0, size ); mr->rdSize = size / 2; mr->rdFunction = META_CREATEBRUSHINDIRECT; memcpy( mr->rdParm, &lb16, sizeof(LOGBRUSH16)); break; } case BS_PATTERN: { BITMAP bm; BITMAPINFO *info; DWORD bmSize; COLORREF cref; GetObjectA((HANDLE)logbrush.lbHatch, sizeof(bm), &bm); if(bm.bmBitsPixel != 1 || bm.bmPlanes != 1) { FIXME("Trying to store a colour pattern brush\n"); goto done; } bmSize = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, DIB_PAL_COLORS); size = sizeof(METARECORD) + sizeof(WORD) + sizeof(BITMAPINFO) + sizeof(RGBQUAD) + bmSize; mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); if(!mr) goto done; mr->rdFunction = META_DIBCREATEPATTERNBRUSH; mr->rdSize = size / 2; mr->rdParm[0] = BS_PATTERN; mr->rdParm[1] = DIB_RGB_COLORS; info = (BITMAPINFO *)(mr->rdParm + 2); info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); info->bmiHeader.biWidth = bm.bmWidth; info->bmiHeader.biHeight = bm.bmHeight; info->bmiHeader.biPlanes = 1; info->bmiHeader.biBitCount = 1; info->bmiHeader.biSizeImage = bmSize; GetBitmapBits((HANDLE)logbrush.lbHatch, bm.bmHeight * BITMAP_GetWidthBytes (bm.bmWidth, bm.bmBitsPixel), (LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD)); /* Change the padding to be DIB compatible if needed */ if(bm.bmWidth & 31) MFDRV_PadTo32((LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD), bm.bmWidth, bm.bmHeight); /* BMP and DIB have opposite row order conventions */ MFDRV_Reverse((LPBYTE)info + sizeof(BITMAPINFO) + sizeof(RGBQUAD), bm.bmWidth, bm.bmHeight); cref = GetTextColor(physDev->hdc); info->bmiColors[0].rgbRed = GetRValue(cref); info->bmiColors[0].rgbGreen = GetGValue(cref); info->bmiColors[0].rgbBlue = GetBValue(cref); info->bmiColors[0].rgbReserved = 0; cref = GetBkColor(physDev->hdc); info->bmiColors[1].rgbRed = GetRValue(cref); info->bmiColors[1].rgbGreen = GetGValue(cref); info->bmiColors[1].rgbBlue = GetBValue(cref); info->bmiColors[1].rgbReserved = 0; break; } case BS_DIBPATTERN: { BITMAPINFO *info; DWORD bmSize, biSize; info = GlobalLock16((HGLOBAL16)logbrush.lbHatch); if (info->bmiHeader.biCompression) bmSize = info->bmiHeader.biSizeImage; else bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth, info->bmiHeader.biHeight, info->bmiHeader.biBitCount); biSize = bitmap_info_size(info, LOWORD(logbrush.lbColor)); size = sizeof(METARECORD) + biSize + bmSize + 2; mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size); if(!mr) goto done; mr->rdFunction = META_DIBCREATEPATTERNBRUSH; mr->rdSize = size / 2; *(mr->rdParm) = logbrush.lbStyle; *(mr->rdParm + 1) = LOWORD(logbrush.lbColor); memcpy(mr->rdParm + 2, info, biSize + bmSize); break; } default: FIXME("Unkonwn brush style %x\n", logbrush.lbStyle); return 0; } r = MFDRV_WriteRecord( dev, mr, mr->rdSize * 2); HeapFree(GetProcessHeap(), 0, mr); if( !r ) return -1; done: return MFDRV_AddHandle( dev, hBrush ); }
void SmartListCtrl::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; if ( !eventHandler_ ) return; LPNMLISTVIEW info = (LPNMLISTVIEW)pNMHDR; std::string text; int image; getData( info->iItem, text, image ); POINT pt; GetCursorPos( &pt ); if ( dragImgList_ ) { delete dragImgList_; dragImgList_ = 0; } int pos = GetNextItem( -1, LVNI_SELECTED ); bool isFirst = true; int xoff = 0; int yoff = 0; int xstep = 0; int ystep = 0; IMAGEINFO imf; int maxDragWidth = 400; int maxDragHeight = 350; while ( pos != -1 ) { if ( isFirst ) { dragImgList_ = CreateDragImage( pos, &pt ); dragImgList_->GetImageInfo( 0, &imf ); xstep = imf.rcImage.right - imf.rcImage.left; ystep = imf.rcImage.bottom - imf.rcImage.top; yoff = imf.rcImage.bottom; isFirst = false; } else { if ( yoff + ystep > maxDragHeight && xoff + xstep > maxDragWidth ) generateDragListEndItem_ = true; // reached the max, so generate a 'more...' item in GetData CImageList* oneImgList = CreateDragImage( pos, &pt ); generateDragListEndItem_ = false; CImageList* tempImgList = new CImageList(); tempImgList->Attach( ImageList_Merge( dragImgList_->GetSafeHandle(), 0, oneImgList->GetSafeHandle(), 0, xoff, yoff ) ); delete dragImgList_; delete oneImgList; dragImgList_ = tempImgList; dragImgList_->GetImageInfo( 0, &imf ); yoff += ystep; if ( yoff > maxDragHeight ) { xoff += xstep; if ( xoff > maxDragWidth ) break; yoff = 0; } } pos = GetNextItem( pos, LVNI_SELECTED ); } if ( dragImgList_ ) { CPoint offset( thumbWidthCur_ + 16 , max( 16, thumbHeightCur_ - 14 ) ); dragImgList_->SetBkColor( GetBkColor() ); dragImgList_->SetDragCursorImage( 0, offset ); dragImgList_->BeginDrag( 0, offset ); dragImgList_->DragEnter( 0, pt ); } if ( delayedSelectionPending_ ) { // if a selection timer is pending, force it delayedSelectionNotify(); } dragging_ = true; eventHandler_->listStartDrag( info->iItem ); }
void SmartListCtrl::setStyle( ViewStyle style ) { style_ = style; static CImageList dummyImgList; static const int IMGLIST_FORMAT = ILC_COLOR24|ILC_MASK; thumbnailManager_->resetPendingRequests( this ); if ( !dummyImgList.GetSafeHandle() ) { dummyImgList.Create( 1, 1, IMGLIST_FORMAT, 0, 0 ); dummyImgList.SetBkColor( GetBkColor() ); } // delete previous image list SetImageList( &dummyImgList, LVSIL_NORMAL ); SetImageList( &dummyImgList, LVSIL_SMALL ); SetImageList( &dummyImgList, LVSIL_STATE ); CImageList* imgListPtr = 0; // set thumbnail size according to list style DWORD wstyle = GetWindowLong( GetSafeHwnd(), GWL_STYLE ); // hack: have to force change the list view style so tooltip cache resets. SetWindowLong( GetSafeHwnd(), GWL_STYLE, (wstyle & ~LVS_TYPEMASK) | LVS_REPORT ); wstyle = GetWindowLong( GetSafeHwnd(), GWL_STYLE ); if ( style_ == BIGICONS ) { SetWindowLong( GetSafeHwnd(), GWL_STYLE, (wstyle & ~LVS_TYPEMASK) | LVS_ICON ); listViewIcons_ = true; thumbWidthCur_ = thumbWidth_; thumbHeightCur_ = thumbHeight_; listCache_ = &listCacheBig_; listCache_->setMaxItems( maxItems_ ); imgListPtr = &imgListBig_; } else if ( style_ == SMALLICONS ) { SetWindowLong( GetSafeHwnd(), GWL_STYLE, (wstyle & ~LVS_TYPEMASK) | LVS_LIST ); listViewIcons_ = true; thumbWidthCur_ = thumbWidthSmall_; thumbHeightCur_ = thumbHeightSmall_; // Since small icons take less space, up the max cache items (by 16 if // big thumbs are 64x64 and small thumbs are 16x16, for example) to // take advantage of the same memory space. int memoryMultiplier = ( thumbWidth_ * thumbHeight_ ) / ( thumbWidthSmall_ * thumbHeightSmall_ ); listCache_ = &listCacheSmall_; listCache_->setMaxItems( maxItems_ * memoryMultiplier ); imgListPtr = &imgListSmall_; } else { SetWindowLong( GetSafeHwnd(), GWL_STYLE, (wstyle & ~LVS_TYPEMASK) | LVS_LIST ); listViewIcons_ = false; thumbWidthCur_ = 0; thumbHeightCur_ = 0; imgListPtr = &dummyImgList; } // create image list if the style requires it if ( style_ != LIST ) { if ( !imgListPtr->GetSafeHandle() ) { imgListPtr->Create( thumbWidthCur_, thumbHeightCur_, IMGLIST_FORMAT, 0, 32 ); imgListPtr->SetBkColor( GetBkColor() ); imgListPtr->Add( AfxGetApp()->LoadIcon( IDI_UALFILE ) ); // clear cache listCache_->init( imgListPtr, 1 ); } } // set the image list if ( style_ == BIGICONS ) SetImageList( imgListPtr, LVSIL_NORMAL ); else if ( style_ == SMALLICONS ) SetImageList( imgListPtr, LVSIL_SMALL ); // clear and start SetItemCount( 0 ); if ( provider_ ) SetTimer( SMARTLIST_LOADTIMER_ID, SMARTLIST_LOADTIMER_MSEC, 0 ); }
LRESULT onDrawItem(HWND hWnd, WPARAM wParam, LPARAM lParam) { LPDRAWITEMSTRUCT lpdis; PNHMenuItem item; PNHMenuWindow data; TEXTMETRIC tm; HGDIOBJ saveFont; HDC tileDC; short ntile; int t_x, t_y; int x, y; TCHAR wbuf[BUFSZ]; RECT drawRect; COLORREF OldBg, OldFg, NewBg; char *p, *p1; int column; lpdis = (LPDRAWITEMSTRUCT) lParam; /* If there are no list box items, skip this message. */ if (lpdis->itemID == -1) return FALSE; data = (PNHMenuWindow)GetWindowLong(hWnd, GWL_USERDATA); item = &data->menu.items[lpdis->itemID]; tileDC = CreateCompatibleDC(lpdis->hDC); saveFont = SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, item->attr, lpdis->hDC, FALSE)); NewBg = mswin_get_color(NHW_MENU, MSWIN_COLOR_BG); OldBg = SetBkColor(lpdis->hDC, NewBg); OldFg = SetTextColor(lpdis->hDC, mswin_get_color(NHW_MENU, MSWIN_COLOR_FG)); GetTextMetrics(lpdis->hDC, &tm); x = lpdis->rcItem.left + 1; /* print check mark if it is a "selectable" menu */ if( data->how!=PICK_NONE ) { if( NHMENU_IS_SELECTABLE(*item) ) { HGDIOBJ saveBrush; HBRUSH hbrCheckMark; char buf[2]; switch(item->count) { case -1: hbrCheckMark = CreatePatternBrush(data->bmpChecked); break; case 0: hbrCheckMark = CreatePatternBrush(data->bmpNotChecked); break; default: hbrCheckMark = CreatePatternBrush(data->bmpCheckedCount); break; } y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; SetBrushOrgEx(lpdis->hDC, x, y, NULL); saveBrush = SelectObject(lpdis->hDC, hbrCheckMark); PatBlt(lpdis->hDC, x, y, TILE_X, TILE_Y, PATCOPY); SelectObject(lpdis->hDC, saveBrush); DeleteObject(hbrCheckMark); x += TILE_X + 5; if(item->accelerator!=0) { buf[0] = item->accelerator; buf[1] = '\x0'; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), 1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); */ DrawText(lpdis->hDC, NH_A2W(buf, wbuf, 2), -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX); } x += tm.tmAveCharWidth + tm.tmOverhang + 5; } else { x += TILE_X + tm.tmAveCharWidth + tm.tmOverhang + 10; } } /* print glyph if present */ if( item->glyph != NO_GLYPH ) { HGDIOBJ saveBmp; saveBmp = SelectObject(tileDC, GetNHApp()->bmpTiles); ntile = glyph2tile[ item->glyph ]; t_x = (ntile % TILES_PER_LINE)*TILE_X; t_y = (ntile / TILES_PER_LINE)*TILE_Y; y = (lpdis->rcItem.bottom + lpdis->rcItem.top - TILE_Y) / 2; nhapply_image_transparent( lpdis->hDC, x, y, TILE_X, TILE_Y, tileDC, t_x, t_y, TILE_X, TILE_Y, TILE_BK_COLOR ); SelectObject(tileDC, saveBmp); } x += TILE_X + 5; /* draw item text */ if( item->has_tab ) { p1 = item->str; p = strchr(item->str, '\t'); column = 0; SetRect( &drawRect, x, lpdis->rcItem.top, min(x + data->menu.tab_stop_size[0], lpdis->rcItem.right), lpdis->rcItem.bottom ); for (;;) { TCHAR wbuf[BUFSZ]; if (p != NULL) *p = '\0'; /* for time being, view tab field as zstring */ DrawText(lpdis->hDC, NH_A2W(p1, wbuf, BUFSZ), /*JP strlen(p1), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); if (p != NULL) *p = '\t'; else /* last string so, */ break; p1 = p + 1; p = strchr(p1, '\t'); drawRect.left = drawRect.right + TAB_SEPARATION; ++column; drawRect.right = min (drawRect.left + data->menu.tab_stop_size[column], lpdis->rcItem.right); } } else { TCHAR wbuf[BUFSZ]; SetRect( &drawRect, x, lpdis->rcItem.top, lpdis->rcItem.right, lpdis->rcItem.bottom); DrawText(lpdis->hDC, NH_A2W(item->str, wbuf, BUFSZ), /*JP strlen(item->str), */ -1, &drawRect, DT_LEFT | DT_VCENTER | DT_SINGLELINE ); } /* draw focused item */ if( item->has_focus ) { RECT client_rt; HBRUSH bkBrush; GetClientRect(lpdis->hwndItem, &client_rt); if( NHMENU_IS_SELECTABLE(*item) && data->menu.items[lpdis->itemID].count>0 && item->glyph != NO_GLYPH ) { if( data->menu.items[lpdis->itemID].count==-1 ) { _stprintf(wbuf, TEXT("Count: All") ); } else { _stprintf(wbuf, TEXT("Count: %d"), data->menu.items[lpdis->itemID].count ); } SelectObject(lpdis->hDC, mswin_get_font(NHW_MENU, ATR_BLINK, lpdis->hDC, FALSE)); /* calculate text rectangle */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_CALCRECT | DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); /* erase text rectangle */ drawRect.left = max(client_rt.left+1, client_rt.right - (drawRect.right - drawRect.left) - 10); drawRect.right = client_rt.right-1; drawRect.top = lpdis->rcItem.top; drawRect.bottom = lpdis->rcItem.bottom; bkBrush = CreateSolidBrush( GetBkColor(lpdis->hDC) ); FillRect(lpdis->hDC, &drawRect, bkBrush ); DeleteObject( bkBrush ); /* draw text */ /*JP DrawText(lpdis->hDC, wbuf, _tcslen(wbuf), &drawRect, */ DrawText(lpdis->hDC, wbuf, -1, &drawRect, DT_RIGHT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX ); } /* draw focus rect */ SetRect( &drawRect, client_rt.left, lpdis->rcItem.top, client_rt.right, lpdis->rcItem.bottom ); DrawFocusRect(lpdis->hDC, &drawRect); } SetTextColor (lpdis->hDC, OldFg); SetBkColor (lpdis->hDC, OldBg); SelectObject(lpdis->hDC, saveFont); DeleteDC(tileDC); return TRUE; }