INT_PTR TdlgPropsEdit::msgProc(UINT uMsg,WPARAM wParam,LPARAM lParam) { switch (uMsg) { case WM_INITDIALOG: { hlv=GetDlgItem(m_hwnd,IDC_LV_PROPS); int ncol=0; ListView_AddCol(hlv,ncol,300,_l("Original:/Translation"),false); ListView_SetItemCount(hlv,props.size()*2); ListView_SetExtendedListViewStyleEx(hlv,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES,LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); return TRUE; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case IDCANCEL: if (HWND(lParam)==GetDlgItem(m_hwnd,IDOK) || HWND(lParam)==GetDlgItem(m_hwnd,IDCANCEL)) { EndDialog(m_hwnd,LOWORD(wParam)); return TRUE; } break; }; break; case WM_NOTIFY: { NMHDR *nmhdr=LPNMHDR(lParam); if (nmhdr->idFrom==IDC_LV_PROPS) switch (nmhdr->code) { case LVN_GETDISPINFO: { NMLVDISPINFO *nmdi=(NMLVDISPINFO*)lParam; int i=nmdi->item.iItem; if (i==-1) { break; } if (nmdi->item.mask&LVIF_TEXT) switch (nmdi->item.iSubItem) { case 0: { //strcpy(nmdi->item.pszText,((i&1)==0)?props[i/2].first.c_str():props[i/2].second.c_str()); nmdi->item.pszText=(LPTSTR)((i&1)==0?props[i/2].first.c_str():props[i/2].second.c_str()); break; } } return TRUE; } case NM_CUSTOMDRAW: { NMLVCUSTOMDRAW *lvcd=LPNMLVCUSTOMDRAW(lParam); if (lvcd->nmcd.dwDrawStage==CDDS_PREPAINT) { setDlgResult(CDRF_NOTIFYITEMDRAW); return TRUE; } if (lvcd->nmcd.dwDrawStage==CDDS_ITEMPREPAINT) { if (!italicFont) { LOGFONT oldFont; HFONT hf=(HFONT)GetCurrentObject(lvcd->nmcd.hdc,OBJ_FONT); GetObject(hf,sizeof(LOGFONT),&oldFont); oldFont.lfItalic=TRUE; italicFont=CreateFontIndirect(&oldFont); } if ((lvcd->nmcd.dwItemSpec&1)==0) { SelectObject(lvcd->nmcd.hdc,italicFont); } setDlgResult(CDRF_NEWFONT); return TRUE; } return TRUE; } case LVN_BEGINLABELEDIT: { NMLVDISPINFO *nmdi=(NMLVDISPINFO*)lParam; if ((nmdi->item.iItem&1)==0) { setDlgResult(TRUE); return TRUE; } break; } case LVN_ENDLABELEDIT: { NMLVDISPINFO *nmdi=(NMLVDISPINFO*)lParam; if (nmdi->item.pszText) { props[nmdi->item.iItem/2].second=nmdi->item.pszText; setDlgResult(TRUE); return TRUE; } break; } case LVN_KEYDOWN: { NMLVKEYDOWN *nmkd=(NMLVKEYDOWN*)lParam; if (nmkd->wVKey==VK_F2) { ListView_EditLabel(hlv,ListView_GetNextItem(hlv,-1,LVNI_SELECTED)); return TRUE; } break; } } break; } } return Twindow::msgProc(uMsg,wParam,lParam); }
void DrawPolyPolyPolygon(Draw& draw, const Point *vertices, int vertex_count, const int *subpolygon_counts, int subpolygon_count_count, const int *disjunct_polygon_counts, int disjunct_polygon_count_count, Color color, int width, Color outline, uint64 pattern, Color doxor) { if(vertex_count == 0) return; #ifdef PLATFORM_WIN32_ //!!TODO if(PdfDraw *pdf = dynamic_cast<PdfDraw *>(&draw)) { pdf->DrawPolyPolyPolygon(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, disjunct_polygon_counts, disjunct_polygon_count_count, color, width, outline, pattern, doxor); return; } #endif // LOG("DrawPolyPolyPolygon: drawing = " << (draw.IsDrawing() ? "yes" : "no") // << ", backdraw = " << (draw.IsBack() ? "yes" : "no") // << ", " << (draw.Dots() ? "dots" : "pixels") // << ", printer = " << (draw.IsPrinter() ? "yes" : "no")); // LOG("#vertices = " << vertex_count << ", #subpolygons = " << subpolygon_count_count // << ", #disjunct polygons = " << disjunct_polygon_count_count); // LOG("color = " << Dump(color) << ", width = " << width << ", outline = " << Dump(outline) // << ", pattern = " << Dump(pattern) << ", doxor = " << doxor); #ifdef _DEBUG // for(int v = 0; v < vertex_count; v++) // if(abs2(vertices[v] - vertices[(v ? v : vertex_count) - 1]) >= 500 * 500) // NEVER(); #endif if(!dynamic_cast<SystemDraw *>(&draw)) { draw.DrawPolyPolyPolygon(vertices, vertex_count, subpolygon_counts, subpolygon_count_count, disjunct_polygon_counts, disjunct_polygon_count_count, color, width, outline, pattern, doxor); return; } // TIMING("DrawPolyPolygon/hdc"); bool is_xor = !IsNull(doxor); #ifdef PLATFORM_X11 unsigned xor_pixel = (is_xor ? GetXPixel(doxor) : 0); XGCValues gcv; gcv.function = is_xor ? X11_ROP2_XOR : X11_ROP2_COPY; GC fill_gc = NULL; Image pattern_image; if(!IsNull(color)) { gcv.foreground = GetXPixel(color) ^ xor_pixel; int fmask = GCForeground | GCFunction; if(pattern) { pattern_image = GetPatternImage(pattern); gcv.stipple = pattern_image.GetMaskPixmap(); gcv.fill_style = FillStippled; fmask |= GCStipple | GCFillStyle; } fill_gc = XCreateGC(Xdisplay, draw.GetDrawable(), fmask, &gcv); } GC line_gc = NULL; if(!IsNull(outline)) { gcv.foreground = GetXPixel(outline) ^ xor_pixel; gcv.line_width = width; line_gc = XCreateGC(Xdisplay, draw.GetDrawable(), GCForeground | GCFunction | GCLineWidth, &gcv); Point offset = draw.GetOffset(); } #endif for(int i = 0; i < disjunct_polygon_count_count; i++, disjunct_polygon_counts++) { int poly = *disjunct_polygon_counts; int sub = 1; if(*subpolygon_counts < poly) if(disjunct_polygon_count_count > 1) { const int *se = subpolygon_counts; int total = 0; while(total < poly) total += *se++; sub = se - subpolygon_counts; } else sub = subpolygon_count_count; if(sub > poly) { vertices += poly; subpolygon_counts += sub; continue; } #if defined(PLATFORM_WIN32) #ifdef SYSTEMDRAW SystemDraw *w = dynamic_cast<SystemDraw *>(&draw); if(w) { SystemDraw& draw = *w; #endif if(pattern) { int old_rop = GetROP2(draw); HGDIOBJ old_brush = GetCurrentObject(draw, OBJ_BRUSH); word wpat[8] = { (byte)(pattern >> 56), (byte)(pattern >> 48), (byte)(pattern >> 40), (byte)(pattern >> 32), (byte)(pattern >> 24), (byte)(pattern >> 16), (byte)(pattern >> 8), (byte)(pattern >> 0), }; HBITMAP bitmap = CreateBitmap(8, 8, 1, 1, wpat); HBRUSH brush = ::CreatePatternBrush(bitmap); COLORREF old_bk = GetBkColor(draw); COLORREF old_fg = GetTextColor(draw); if(!is_xor) { SetROP2(draw, R2_MASKPEN); SelectObject(draw, brush); SetTextColor(draw, Black()); SetBkColor(draw, White()); DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, true, PEN_NULL, Null); SetROP2(draw, R2_MERGEPEN); SetTextColor(draw, color); SetBkColor(draw, Black()); } else { // xor fill with pattern data SetROP2(draw, R2_XORPEN); SelectObject(draw, brush); } DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, true, PEN_NULL, Null); SelectObject(draw, old_brush); SetTextColor(draw, old_fg); SetBkColor(draw, old_bk); SetROP2(draw, old_rop); DeleteObject(brush); DeleteObject(bitmap); if(!IsNull(outline)) { draw.SetColor(Null); draw.SetDrawPen(width, outline); ASSERT(sizeof(POINT) == sizeof(Point)); PolyPolygon(draw, (const POINT *)vertices, subpolygon_counts, sub); } } else { // simple fill // RTIMING("AreaTool::Fill(solid color)"); int out_wd = (IsNull(width) || IsNull(outline) ? PEN_NULL : width); Color out_co = Nvl(outline, Black); draw.SetDrawPen(out_wd, out_co); if(is_xor) { color = Color(color.GetR() ^ doxor.GetR(), color.GetG() ^ doxor.GetG(), color.GetB() ^ doxor.GetB()); SetROP2(draw, R2_XORPEN); } HGDIOBJ old_brush = 0; if(IsNull(color)) { static HGDIOBJ null_brush = GetStockObject(NULL_BRUSH); old_brush = SelectObject(draw, null_brush); } else draw.SetColor(color); DrawPolyPolygonRaw(draw, vertices, poly, subpolygon_counts, sub, !IsNull(color), out_wd, out_co); if(old_brush) SelectObject(draw, old_brush); if(is_xor) SetROP2(draw, R2_COPYPEN); } #ifdef SYSTEMDRAW } #endif #elif defined(PLATFORM_X11) if(fill_gc) FillPolyPolygonRaw(fill_gc, draw.GetDrawable(), draw.GetClip(), draw.GetOffset(), vertices, poly, subpolygon_counts, sub); if(line_gc) DrawPolyPolygonRaw(line_gc, draw.GetDrawable(), draw.GetOffset(), vertices, poly, subpolygon_counts, sub); #else #error #endif vertices += poly; subpolygon_counts += sub; }
HIMAGELIST SdkCreateGrayImageList( IN HIMAGELIST himlNormal ) { int Count, i; int Width, Height; HIMAGELIST himlGray; HDC hdcDesktop; HDC hdcMem; RECT rc; COLORREF crMask; HPALETTE hpal; UINT index; HGDIOBJ hbm; HGDIOBJ hbmOld; COLORREF rgb; BYTE gray; HWND hWnd; int x, y; Count = ImageList_GetImageCount(himlNormal); if (Count == 0) { return NULL; } ImageList_GetIconSize(himlNormal, &Width, &Height); himlGray = ImageList_Create(Width, Height, ILC_COLOR24 | ILC_MASK, Count, 0); hdcDesktop = GetDC(NULL); hdcMem = CreateCompatibleDC(NULL); rc.top = rc.left = 0; rc.bottom = Height; rc.right = Width; crMask = RGB(200, 199, 200); if (GetDeviceCaps(hdcDesktop, BITSPIXEL) < 24) { hpal = (HPALETTE)GetCurrentObject(hdcDesktop, OBJ_PAL); index = GetNearestPaletteIndex(hpal, crMask); if (index != CLR_INVALID) { crMask = PALETTEINDEX(index); } } for (i = 0 ; i < Count; ++i) { hbm = CreateCompatibleBitmap(hdcDesktop, Width, Height); hbmOld = SelectObject(hdcMem, hbm); SdkFillSolidRect(hdcMem, crMask, &rc); ImageList_SetBkColor(himlNormal, crMask); ImageList_Draw(himlNormal, i, hdcMem, 0, 0, ILD_NORMAL); for (x = 0 ; x < Width; ++x) { for (y = 0; y < Height; ++y) { rgb = GetPixel(hdcMem, x, y); if (rgb != crMask) { gray = (BYTE) (95 + (GetRValue(rgb) * 3 + GetGValue(rgb) * 6 + GetBValue(rgb)) / 20); SetPixel(hdcMem, x, y, RGB(gray, gray, gray)); } } } hbm = SelectObject(hdcMem, hbmOld); ImageList_AddMasked(himlGray, (HBITMAP)hbm, crMask); DeleteObject(hbm); } DeleteDC(hdcMem); hWnd = WindowFromDC(hdcDesktop); ReleaseDC(hWnd, hdcDesktop); return himlGray; }
PassRefPtr<SimpleFontData> FontCache::systemFallbackForCharacters(const FontDescription& description, const SimpleFontData* originalFontData, bool, const UChar* characters, int length) { String familyName; WCHAR name[LF_FACESIZE]; UChar character = characters[0]; const FontPlatformData& origFont = originalFontData->platformData(); unsigned unicodeRange = findCharUnicodeRange(character); if (IMLangFontLinkType* langFontLink = getFontLinkInterface()) { HGDIOBJ oldFont = GetCurrentObject(g_screenDC, OBJ_FONT); HFONT hfont = 0; DWORD codePages = 0; UINT codePage = 0; // Try MLang font linking first. langFontLink->GetCharCodePages(character, &codePages); if (codePages && unicodeRange == cRangeSetCJK) { // The CJK character may belong to multiple code pages. We want to // do font linking against a single one of them, preferring the default // code page for the user's locale. const Vector<DWORD, 4>& CJKCodePageMasks = getCJKCodePageMasks(); unsigned numCodePages = CJKCodePageMasks.size(); for (unsigned i = 0; i < numCodePages; ++i) { hfont = createMLangFont(langFontLink, g_screenDC, origFont, CJKCodePageMasks[i]); if (!hfont) continue; SelectObject(g_screenDC, hfont); GetTextFace(g_screenDC, LF_FACESIZE, name); if (hfont && !(codePages & CJKCodePageMasks[i])) { // We asked about a code page that is not one of the code pages // returned by MLang, so the font might not contain the character. if (!currentFontContainsCharacter(langFontLink, g_screenDC, hfont, character, name)) { SelectObject(g_screenDC, oldFont); langFontLink->ReleaseFont(hfont); hfont = 0; continue; } } break; } } else { hfont = createMLangFont(langFontLink, g_screenDC, origFont, codePages, character); SelectObject(g_screenDC, hfont); GetTextFace(g_screenDC, LF_FACESIZE, name); } SelectObject(g_screenDC, oldFont); if (hfont) { familyName = name; langFontLink->ReleaseFont(hfont); } else FontPlatformData::mapKnownFont(codePages, familyName); } if (familyName.isEmpty()) familyName = FontPlatformData::defaultFontFamily(); if (!familyName.isEmpty()) { // FIXME: temporary workaround for Thai font problem FontDescription fontDescription(description); if (unicodeRange == cRangeThai && fontDescription.weight() > FontWeightNormal) fontDescription.setWeight(FontWeightNormal); FontPlatformData* result = getCachedFontPlatformData(fontDescription, familyName); if (result && result->hash() != origFont.hash()) { if (RefPtr<SimpleFontData> fontData = getCachedFontData(result, DoNotRetain)) return fontData.release(); } } return 0; }
BOOL EMFDRV_StretchBlt( PHYSDEV devDst, struct bitblt_coords *dst, PHYSDEV devSrc, struct bitblt_coords *src, DWORD rop ) { BOOL ret; PEMRBITBLT pEMR; UINT emrSize; UINT bmiSize; UINT bitsSize; UINT size; BITMAP BM; WORD nBPP = 0; LPBITMAPINFOHEADER lpBmiH; HBITMAP hBitmap = NULL; DWORD emrType; if (devSrc->funcs == devDst->funcs) return FALSE; /* can't use a metafile DC as source */ if (src->log_width == dst->log_width && src->log_height == dst->log_height) { emrType = EMR_BITBLT; emrSize = sizeof(EMRBITBLT); } else { emrType = EMR_STRETCHBLT; emrSize = sizeof(EMRSTRETCHBLT); } hBitmap = GetCurrentObject(devSrc->hdc, OBJ_BITMAP); if(sizeof(BITMAP) != GetObjectW(hBitmap, sizeof(BITMAP), &BM)) return FALSE; nBPP = BM.bmPlanes * BM.bmBitsPixel; if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */ bitsSize = get_dib_stride( BM.bmWidth, nBPP ) * BM.bmHeight; bmiSize = sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP : 0) * sizeof(RGBQUAD); size = emrSize + bmiSize + bitsSize; pEMR = HeapAlloc(GetProcessHeap(), 0, size); if (!pEMR) return FALSE; /* Initialize EMR */ pEMR->emr.iType = emrType; pEMR->emr.nSize = size; pEMR->rclBounds.left = dst->log_x; pEMR->rclBounds.top = dst->log_y; pEMR->rclBounds.right = dst->log_x + dst->log_width - 1; pEMR->rclBounds.bottom = dst->log_y + dst->log_height - 1; pEMR->xDest = dst->log_x; pEMR->yDest = dst->log_y; pEMR->cxDest = dst->log_width; pEMR->cyDest = dst->log_height; pEMR->dwRop = rop; pEMR->xSrc = src->log_x; pEMR->ySrc = src->log_y; GetWorldTransform(devSrc->hdc, &pEMR->xformSrc); pEMR->crBkColorSrc = GetBkColor(devSrc->hdc); pEMR->iUsageSrc = DIB_RGB_COLORS; pEMR->offBmiSrc = emrSize; pEMR->offBitsSrc = emrSize + bmiSize; pEMR->cbBmiSrc = bmiSize; pEMR->cbBitsSrc = bitsSize; if (emrType == EMR_STRETCHBLT) { PEMRSTRETCHBLT pEMRStretch = (PEMRSTRETCHBLT)pEMR; pEMRStretch->cxSrc = src->log_width; pEMRStretch->cySrc = src->log_height; } /* Initialize BITMAPINFO structure */ lpBmiH = (LPBITMAPINFOHEADER)((BYTE*)pEMR + pEMR->offBmiSrc); lpBmiH->biSize = sizeof(BITMAPINFOHEADER); lpBmiH->biWidth = BM.bmWidth; lpBmiH->biHeight = BM.bmHeight; lpBmiH->biPlanes = BM.bmPlanes; lpBmiH->biBitCount = nBPP; /* Assume the bitmap isn't compressed and set the BI_RGB flag. */ lpBmiH->biCompression = BI_RGB; lpBmiH->biSizeImage = bitsSize; lpBmiH->biYPelsPerMeter = 0; lpBmiH->biXPelsPerMeter = 0; lpBmiH->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0; /* Set biClrImportant to 0, indicating that all of the device colors are important. */ lpBmiH->biClrImportant = 0; /* Initialize bitmap bits */ if (GetDIBits(devSrc->hdc, hBitmap, 0, (UINT)lpBmiH->biHeight, (BYTE*)pEMR + pEMR->offBitsSrc, (LPBITMAPINFO)lpBmiH, DIB_RGB_COLORS)) { ret = EMFDRV_WriteRecord(devDst, (EMR*)pEMR); if (ret) EMFDRV_UpdateBBox(devDst, &(pEMR->rclBounds)); } else ret = FALSE; HeapFree( GetProcessHeap(), 0, pEMR); return ret; }
static BOOL EMFDRV_BitBlockTransfer( PHYSDEV devDst, INT xDst, INT yDst, INT widthDst, INT heightDst, PHYSDEV devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc, DWORD rop, DWORD emrType) { BOOL ret; PEMRBITBLT pEMR; UINT emrSize; UINT bmiSize; UINT bitsSize; UINT size; BITMAP BM; WORD nBPP; LPBITMAPINFOHEADER lpBmiH; EMFDRV_PDEVICE* physDevSrc = (EMFDRV_PDEVICE*)devSrc; HBITMAP hBitmap = GetCurrentObject(physDevSrc->hdc, OBJ_BITMAP); if (emrType == EMR_BITBLT) emrSize = sizeof(EMRBITBLT); else if (emrType == EMR_STRETCHBLT) emrSize = sizeof(EMRSTRETCHBLT); else return FALSE; if(sizeof(BITMAP) != GetObjectW(hBitmap, sizeof(BITMAP), &BM)) return FALSE; nBPP = BM.bmPlanes * BM.bmBitsPixel; if(nBPP > 8) nBPP = 24; /* FIXME Can't get 16bpp to work for some reason */ bitsSize = DIB_GetDIBWidthBytes(BM.bmWidth, nBPP) * BM.bmHeight; bmiSize = sizeof(BITMAPINFOHEADER) + (nBPP <= 8 ? 1 << nBPP : 0) * sizeof(RGBQUAD); size = emrSize + bmiSize + bitsSize; pEMR = HeapAlloc(GetProcessHeap(), 0, size); if (!pEMR) return FALSE; /* Initialize EMR */ pEMR->emr.iType = emrType; pEMR->emr.nSize = size; pEMR->rclBounds.left = xDst; pEMR->rclBounds.top = yDst; pEMR->rclBounds.right = xDst + widthDst - 1; pEMR->rclBounds.bottom = yDst + heightDst - 1; pEMR->xDest = xDst; pEMR->yDest = yDst; pEMR->cxDest = widthDst; pEMR->cyDest = heightDst; pEMR->dwRop = rop; pEMR->xSrc = xSrc; pEMR->ySrc = ySrc; pEMR->xformSrc.eM11 = 1.0; /** FIXME: */ pEMR->xformSrc.eM12 = 0.0; /** Setting default */ pEMR->xformSrc.eM21 = 0.0; /** value. */ pEMR->xformSrc.eM22 = 1.0; /** Where should we */ pEMR->xformSrc.eDx = 0.0; /** get that info */ pEMR->xformSrc.eDy = 0.0; /** ???? */ pEMR->crBkColorSrc = GetBkColor(physDevSrc->hdc); pEMR->iUsageSrc = DIB_RGB_COLORS; pEMR->offBmiSrc = emrSize; pEMR->cbBmiSrc = bmiSize; pEMR->offBitsSrc = emrSize + bmiSize; pEMR->cbBitsSrc = bitsSize; if (emrType == EMR_STRETCHBLT) { PEMRSTRETCHBLT pEMRStretch = (PEMRSTRETCHBLT)pEMR; pEMRStretch->cxSrc = widthSrc; pEMRStretch->cySrc = heightSrc; } /* Initialize BITMAPINFO structure */ lpBmiH = (LPBITMAPINFOHEADER)((BYTE*)pEMR + pEMR->offBmiSrc); lpBmiH->biSize = sizeof(BITMAPINFOHEADER); lpBmiH->biWidth = BM.bmWidth; lpBmiH->biHeight = BM.bmHeight; lpBmiH->biPlanes = BM.bmPlanes; lpBmiH->biBitCount = nBPP; /* Assume the bitmap isn't compressed and set the BI_RGB flag. */ lpBmiH->biCompression = BI_RGB; lpBmiH->biSizeImage = bitsSize; lpBmiH->biYPelsPerMeter = /* 1 meter = 39.37 inch */ MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSX),3937,100); lpBmiH->biXPelsPerMeter = MulDiv(GetDeviceCaps(physDevSrc->hdc,LOGPIXELSY),3937,100); lpBmiH->biClrUsed = nBPP <= 8 ? 1 << nBPP : 0; /* Set biClrImportant to 0, indicating that all of the device colors are important. */ lpBmiH->biClrImportant = 0; /* Initialize bitmap bits */ if (GetDIBits(physDevSrc->hdc, hBitmap, 0, (UINT)lpBmiH->biHeight, (BYTE*)pEMR + pEMR->offBitsSrc, (LPBITMAPINFO)lpBmiH, DIB_RGB_COLORS)) { ret = EMFDRV_WriteRecord(devDst, (EMR*)pEMR); if (ret) EMFDRV_UpdateBBox(devDst, &(pEMR->rclBounds)); } else ret = FALSE; HeapFree( GetProcessHeap(), 0, pEMR); return ret; }
void DWriteRenderer::SubpixelZoom() { bool bgr = renderingParams_->GetPixelGeometry() == DWRITE_PIXEL_GEOMETRY_BGR; // Get the DIB selection selected into each IDWriteBitmapRenderTarget's memory DC. DIBSECTION srcDib; if (GetObject(GetCurrentObject(magnifierTarget_->GetMemoryDC(), OBJ_BITMAP), sizeof(srcDib), &srcDib) != sizeof(srcDib)) return; DIBSECTION dstDib; if (GetObject(GetCurrentObject(renderTarget_->GetMemoryDC(), OBJ_BITMAP), sizeof(dstDib), &dstDib) != sizeof(dstDib)) return; // Point to the pixels. Each DIB section is a 32-bit per pixel top-down DIB. int const srcWidth = srcDib.dsBm.bmWidth; int const srcHeight = srcDib.dsBm.bmHeight; UINT32 const* const srcBits = static_cast<UINT32*>(srcDib.dsBm.bmBits); int const dstWidth = dstDib.dsBm.bmWidth; int const dstHeight = dstDib.dsBm.bmHeight; UINT32* const dstBits = static_cast<UINT32*>(dstDib.dsBm.bmBits); // Number of target pixels per source pixel and source subpixel. int const scale = magnifier_.scale; int const subpixelScale = scale / 3; int const pixelGap = scale % 3; // Mask of colors for left, center, and right subpixels. UINT32 const maskL = bgr ? 0x0000FF : 0xFF0000; UINT32 const maskC = 0x00FF00; UINT32 const maskR = bgr ? 0xFF0000 : 0x0000FF; // Iterate over all the source scan lines. for (int y = 0; y < srcHeight; ++y) { UINT32 const* srcRow = srcBits + (y * srcWidth); // Determine the corresponding range of Y values in the destination bitmap. int minDstY = (y * scale) + magnifier_.magnifierPos.y; int limDstY = minDstY + scale; // Consrain the destination Y values to fit in the destination bitmap. if (minDstY < 0) minDstY = 0; if (limDstY > dstHeight) limDstY = dstHeight; // Are any of the destination scan lines visible? if (minDstY < limDstY) { UINT32* const firstDstRow = dstBits + (minDstY * dstWidth); int dstX = magnifier_.magnifierPos.x; // Iterate over all the pixels in the source scan line. for (int x = 0; x < srcWidth; ++x) { UINT32 const color = srcRow[x]; // Fill in the destination pixels for the left, center, // and right color stripes. for (int i = 0; i < subpixelScale; ++i, ++dstX) { if (dstX >= 0 && dstX < dstWidth) firstDstRow[dstX] = color & maskL; } for (int i = 0; i < subpixelScale; ++i, ++dstX) { if (dstX >= 0 && dstX < dstWidth) firstDstRow[dstX] = color & maskC; } for (int i = 0; i < subpixelScale; ++i, ++dstX) { if (dstX >= 0 && dstX < dstWidth) firstDstRow[dstX] = color & maskR; } // If the scale is not a multiple if three, we'll have a black // gap between the pixels. for (int i = 0; i < pixelGap; ++i, ++dstX) { if (dstX >= 0 && dstX < dstWidth) firstDstRow[dstX] = 0; } } // Copy the destination row we just initialized to the remaining // destination rows for this scan line. UINT32* dstRow = firstDstRow + dstWidth; for (int y2 = minDstY + 1; y2 < limDstY; ++y2, dstRow += dstWidth) { memcpy( dstRow + magnifier_.magnifierPos.x, firstDstRow + magnifier_.magnifierPos.x, (dstX - magnifier_.magnifierPos.x) * sizeof(UINT32) ); } } } }
/********************************************************************** * * PSDRV_Brush * */ BOOL PSDRV_Brush(PHYSDEV dev, BOOL EO) { PSDRV_PDEVICE *physDev = get_psdrv_dev( dev ); LOGBRUSH logbrush; BOOL ret = TRUE; if(physDev->pathdepth) return FALSE; if (!GetObjectA( GetCurrentObject(dev->hdc,OBJ_BRUSH), sizeof(logbrush), &logbrush )) { ERR("Can't get BRUSHOBJ\n"); return FALSE; } switch (logbrush.lbStyle) { case BS_SOLID: PSDRV_WriteGSave(dev); PSDRV_SetBrush(dev); PSDRV_Fill(dev, EO); PSDRV_WriteGRestore(dev); break; case BS_HATCHED: PSDRV_WriteGSave(dev); PSDRV_SetBrush(dev); switch(logbrush.lbHatch) { case HS_VERTICAL: case HS_CROSS: PSDRV_WriteGSave(dev); PSDRV_Clip(dev, EO); PSDRV_WriteHatch(dev); PSDRV_WriteStroke(dev); PSDRV_WriteGRestore(dev); if(logbrush.lbHatch == HS_VERTICAL) break; /* else fallthrough for HS_CROSS */ case HS_HORIZONTAL: PSDRV_WriteGSave(dev); PSDRV_Clip(dev, EO); PSDRV_WriteRotate(dev, 90.0); PSDRV_WriteHatch(dev); PSDRV_WriteStroke(dev); PSDRV_WriteGRestore(dev); break; case HS_FDIAGONAL: case HS_DIAGCROSS: PSDRV_WriteGSave(dev); PSDRV_Clip(dev, EO); PSDRV_WriteRotate(dev, -45.0); PSDRV_WriteHatch(dev); PSDRV_WriteStroke(dev); PSDRV_WriteGRestore(dev); if(logbrush.lbHatch == HS_FDIAGONAL) break; /* else fallthrough for HS_DIAGCROSS */ case HS_BDIAGONAL: PSDRV_WriteGSave(dev); PSDRV_Clip(dev, EO); PSDRV_WriteRotate(dev, 45.0); PSDRV_WriteHatch(dev); PSDRV_WriteStroke(dev); PSDRV_WriteGRestore(dev); break; default: ERR("Unknown hatch style\n"); ret = FALSE; break; } PSDRV_WriteGRestore(dev); break; case BS_NULL: break; case BS_PATTERN: { BITMAP bm; BYTE *bits; GetObjectA( (HBITMAP)logbrush.lbHatch, sizeof(BITMAP), &bm); TRACE("BS_PATTERN %dx%d %d bpp\n", bm.bmWidth, bm.bmHeight, bm.bmBitsPixel); bits = HeapAlloc(PSDRV_Heap, 0, bm.bmWidthBytes * bm.bmHeight); GetBitmapBits( (HBITMAP)logbrush.lbHatch, bm.bmWidthBytes * bm.bmHeight, bits); if(physDev->pi->ppd->LanguageLevel > 1) { PSDRV_WriteGSave(dev); PSDRV_WritePatternDict(dev, &bm, bits); PSDRV_Fill(dev, EO); PSDRV_WriteGRestore(dev); } else { FIXME("Trying to set a pattern brush on a level 1 printer\n"); ret = FALSE; } HeapFree(PSDRV_Heap, 0, bits); } break; case BS_DIBPATTERN: { BITMAPINFO *bmi = (BITMAPINFO *)logbrush.lbHatch; UINT usage = logbrush.lbColor; TRACE("size %dx%dx%d\n", bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight, bmi->bmiHeader.biBitCount); if(physDev->pi->ppd->LanguageLevel > 1) { PSDRV_WriteGSave(dev); ret = PSDRV_WriteDIBPatternDict(dev, bmi, usage); PSDRV_Fill(dev, EO); PSDRV_WriteGRestore(dev); } else { FIXME("Trying to set a pattern brush on a level 1 printer\n"); ret = FALSE; } } break; default: ret = FALSE; break; } return ret; }
// Add image to the list (return the index of the image or -1 on error) // If pos == -1, add to the end of the list int ImageArray_AddImage(IMAGE_ARRAY_DATA *iad, HBITMAP hBmp, int pos) { BITMAP bm; int new_width, new_height; HBITMAP hNewBmp, old_bmp; HDC hdc_old; BOOL last_one; int i; if (hBmp == NULL) return -1; EnterCriticalSection(&iad->cs); if (pos < 0) pos = iad->nodes_size; // Add to end? if (pos >= iad->nodes_size) { pos = iad->nodes_size; last_one = TRUE; } else { last_one = FALSE; } // Get bounds if (!GetObject(hBmp, sizeof(BITMAP), &bm)) { LeaveCriticalSection(&iad->cs); return -1; } if (iad->width_based) { new_width = max(bm.bmWidth, iad->width); new_height = iad->height + bm.bmHeight; } else { new_width = bm.bmWidth + iad->width; new_height = max(iad->height, bm.bmHeight); } // Alloc image hNewBmp = ImageArray_CreateBitmapPoint(new_width, new_height, &(iad->lpBits)); if (hNewBmp == NULL) { LeaveCriticalSection(&iad->cs); return -1; } // Alloc array if (!ImageArray_Alloc(iad, iad->nodes_size + 1)) { DeleteObject(hNewBmp); LeaveCriticalSection(&iad->cs); return -1; } // Move image... // Set some draw states SelectObject(iad->hdc, hNewBmp); hdc_old = CreateCompatibleDC(iad->hdc); old_bmp = (HBITMAP)GetCurrentObject(hdc_old, OBJ_BITMAP); SetBkMode(iad->hdc, TRANSPARENT); { POINT org; GetBrushOrgEx(iad->hdc, &org); SetStretchBltMode(iad->hdc, HALFTONE); SetBrushOrgEx(iad->hdc, org.x, org.y, NULL); } { int x = 0, y = 0, w = 0, h = 0; // 1- old data if (pos > 0) { SelectObject(hdc_old, iad->img); if (iad->width_based) { w = iad->width; h = 0; for (i = 0; i < pos; i++) { h += iad->nodes[i].height; } } else { h = iad->height; w = 0; for (i = 0; i < pos; i++) { w += iad->nodes[i].width; } } BitBlt(iad->hdc, 0, 0, w, h, hdc_old, 0, 0, SRCCOPY); } // 2- new image if (iad->width_based) { x = 0; y = h; } else { x = w; y = 0; } SelectObject(hdc_old, hBmp); BitBlt(iad->hdc, x, y, bm.bmWidth, bm.bmHeight, hdc_old, 0, 0, SRCCOPY); // 3- old data if (!last_one) { int ox, oy; SelectObject(hdc_old, iad->img); if (iad->width_based) { ox = 0; oy = y; x = 0; y += bm.bmHeight; w = iad->width; h = iad->height - h; } else { ox = x; oy = 0; x += bm.bmWidth; y = 0; w = iad->width - w; h = iad->height; } BitBlt(iad->hdc, x, y, w, h, hdc_old, ox, oy, SRCCOPY); } } // restore things SelectObject(hdc_old, old_bmp); DeleteDC(hdc_old); if (iad->img != NULL) DeleteObject(iad->img); iad->img = hNewBmp; // Move array if (!last_one && iad->nodes_size > 1) { memmove(&iad->nodes[pos + 1], &iad->nodes[pos], (iad->nodes_size - pos) * sizeof(IMAGE_ARRAY_DATA_NODE)); } iad->nodes[pos].width = bm.bmWidth; iad->nodes[pos].height = bm.bmHeight; iad->width = new_width; iad->height = new_height; // Finished it! LeaveCriticalSection(&iad->cs); return pos; }
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (songlist.quit) return; UINT n = lpDrawItemStruct->itemID; HDC* mdc = &lpDrawItemStruct->hDC; HWND* hWnd = &songlist.hWnd; HDC* bdc = &songlist.bdc; IMGINFO* imgplay = &songlist.imgplay; IMGINFO* imgpause = &songlist.imgpause; PLAYERINFO* playerinfo = GetPlayerInfo(n); if (playerinfo == NULL) return; HFONT font = (HFONT)GetCurrentObject(*mdc, OBJ_FONT); SelectObject(*bdc, font); RECT r = {0}; LONG x = lpDrawItemStruct->rcItem.left; LONG y = lpDrawItemStruct->rcItem.top; LONG w = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left; LONG h = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top; r.left = lpDrawItemStruct->rcItem.left; r.right = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left; r.top = 0; r.bottom = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top; COLORREF color = RGB(0, 0, 0); if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { SetTextColor(*bdc, RGB(0, 0, 0)); color = RGB(192, 192, 192); } else SetTextColor(*bdc, RGB(255, 255, 255)); SetBkColor(*bdc, color); HBRUSH brush = CreateSolidBrush(color); ExtTextOut(*bdc, 0, 0, ETO_OPAQUE, &r, NULL, 0, NULL); DeleteObject(brush); RECT rect = {0}; if (playerinfo != NULL) { Gdiplus::Graphics graphics(*bdc); ListView_GetSubItemRect(*hWnd, n, 0, LVIR_LABEL, &rect); Gdiplus::PointF point; if (playerinfo->playing) { point.X = (Gdiplus::REAL)(rect.right - rect.left - imgplay->image->GetWidth()) / 2.0F; point.Y = (Gdiplus::REAL)(rect.bottom - rect.top - imgplay->image->GetHeight()) / 2.0F; Gdiplus::Status s = graphics.DrawImage(imgplay->image, point); } if (playerinfo->pause) { point.X = (Gdiplus::REAL)(rect.right - rect.left - imgpause->image->GetWidth()) / 2.0F; point.Y = (Gdiplus::REAL)(rect.bottom - rect.top - imgpause->image->GetHeight()) / 2.0F; Gdiplus::Status s = graphics.DrawImage(imgpause->image, point); } } for (int i = 1;i < 4;i++) { wchar_t text[256] = {0}; ListView_GetItemText(*hWnd, n, i, text, sizeof(text) / sizeof(wchar_t)); ListView_GetSubItemRect(*hWnd, n, i, LVIR_LABEL, &rect); r.left = rect.left; r.right = rect.right; r.top = 0; r.bottom = rect.bottom - rect.top; DrawText(*bdc, text, wcslen(text), &r, DT_LEFT | DT_SINGLELINE | DT_VCENTER); } BitBlt(*mdc, x, y, w, h, *bdc, 0, 0, SRCCOPY); }
void Cache_GetAvatar(struct ClcData *dat, struct ClcContact *contact) { int old_pos=contact->avatar_pos; if (g_CluiData.bSTATE!=STATE_NORMAL || (dat->use_avatar_service && !ServiceExists(MS_AV_GETAVATARBITMAP)) ) // workaround for avatar service and other wich destroys service on OK_TOEXIT { contact->avatar_pos = AVATAR_POS_DONT_HAVE; contact->avatar_data = NULL; return; } if (dat->use_avatar_service && ServiceExists(MS_AV_GETAVATARBITMAP)) { if (dat->avatars_show && !ModernGetSettingByte(contact->hContact, "CList", "HideContactAvatar", 0)) { contact->avatar_data = (struct avatarCacheEntry *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)contact->hContact, 0); if (contact->avatar_data == NULL || contact->avatar_data->cbSize != sizeof(struct avatarCacheEntry) || contact->avatar_data->dwFlags == AVS_BITMAP_EXPIRED) { contact->avatar_data = NULL; } if (contact->avatar_data != NULL) { contact->avatar_data->t_lastAccess = (DWORD)time(NULL); } } else { contact->avatar_data = NULL; } Cache_ProceedAvatarInList(dat, contact); } else { contact->avatar_pos = AVATAR_POS_DONT_HAVE; if (dat->avatars_show && !ModernGetSettingByte(contact->hContact, "CList", "HideContactAvatar", 0)) { DBVARIANT dbv; if (!ModernGetSettingTString(contact->hContact, "ContactPhoto", "File", &dbv)) { HBITMAP hBmp = (HBITMAP) CallService(MS_UTILS_LOADBITMAPT, 0, (LPARAM)dbv.ptszVal); if (hBmp != NULL) { // Make bounds BITMAP bm; if (GetObject(hBmp,sizeof(BITMAP),&bm)) { // Create data... HDC hdc; HBITMAP hDrawBmp,oldBmp; // Make bounds -> keep aspect radio LONG width_clip; LONG height_clip; RECT rc = {0}; // Clipping width and height width_clip = dat->avatars_maxheight_size; height_clip = dat->avatars_maxheight_size; if (height_clip * bm.bmWidth / bm.bmHeight <= width_clip) { width_clip = height_clip * bm.bmWidth / bm.bmHeight; } else { height_clip = width_clip * bm.bmHeight / bm.bmWidth; } // Create objs hdc = CreateCompatibleDC(dat->avatar_cache.hdc); hDrawBmp = ske_CreateDIB32(width_clip, height_clip); oldBmp=(HBITMAP)SelectObject(hdc, hDrawBmp); SetBkMode(hdc,TRANSPARENT); { POINT org; GetBrushOrgEx(hdc, &org); SetStretchBltMode(hdc, HALFTONE); SetBrushOrgEx(hdc, org.x, org.y, NULL); } rc.right = width_clip - 1; rc.bottom = height_clip - 1; // Draw bitmap 8//8 { HDC dcMem = CreateCompatibleDC(hdc); HBITMAP obmp=(HBITMAP)SelectObject(dcMem, hBmp); StretchBlt(hdc, 0, 0, width_clip, height_clip,dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); SelectObject(dcMem,obmp); mod_DeleteDC(dcMem); } { RECT rtr={0}; rtr.right=width_clip+1; rtr.bottom=height_clip+1; ske_SetRectOpaque(hdc,&rtr); } hDrawBmp = (HBITMAP)GetCurrentObject(hdc, OBJ_BITMAP); SelectObject(hdc,oldBmp); mod_DeleteDC(hdc); // Add to list if (old_pos >= 0) { ImageArray_ChangeImage(&dat->avatar_cache, hDrawBmp, old_pos); contact->avatar_pos = old_pos; } else { contact->avatar_pos = ImageArray_AddImage(&dat->avatar_cache, hDrawBmp, -1); } DeleteObject(hDrawBmp); } // if (GetObject(hBmp,sizeof(BITMAP),&bm)) DeleteObject(hBmp); } //if (hBmp != NULL) } ModernDBFreeVariant(&dbv); } // Remove avatar if needed if (old_pos >= 0 && contact->avatar_pos == AVATAR_POS_DONT_HAVE) { ImageArray_RemoveImage(&dat->avatar_cache, old_pos); // Update all items ExecuteOnAllContacts(dat, ReduceAvatarPosition, (void *)&old_pos); } if (old_pos==AVATAR_POS_ANIMATED && contact->avatar_pos != AVATAR_POS_ANIMATED) { AniAva_RemoveAvatar( contact->hContact ); } } }
static void PaintWorker(MButtonCtrl *ctl, HDC hdcPaint) { if (hdcPaint) { HDC hdcMem; HBITMAP hbmMem; HDC hOld; RECT rcClient; GetClientRect(ctl->hwnd, &rcClient); hdcMem = CreateCompatibleDC(hdcPaint); hbmMem = CreateCompatibleBitmap(hdcPaint, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top); hOld = ( HDC )SelectObject(hdcMem, hbmMem); // If its a push button, check to see if it should stay pressed if (ctl->pushBtn && ctl->pbState) ctl->stateId = PBS_PRESSED; // Draw the flat button if (ctl->flatBtn) { if (ctl->hThemeToolbar) { int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId==PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED; if (isThemeBackgroundPartiallyTransparent(ctl->hThemeToolbar, TP_BUTTON, TBStateConvert2Flat(state))) { drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient); } drawThemeBackground(ctl->hThemeToolbar, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), &rcClient, &rcClient); } else { HBRUSH hbr; if (ctl->stateId==PBS_PRESSED||ctl->stateId==PBS_HOT) hbr = GetSysColorBrush(COLOR_3DLIGHT); else { HWND hwndParent = GetParent(ctl->hwnd); HDC dc = GetDC(hwndParent); HBRUSH oldBrush = (HBRUSH)GetCurrentObject( dc, OBJ_BRUSH ); hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)dc, (LPARAM)hwndParent); SelectObject(dc,oldBrush); ReleaseDC(hwndParent,dc); } if (hbr) { FillRect(hdcMem, &rcClient, hbr); DeleteObject(hbr); } if (ctl->stateId==PBS_HOT||ctl->focus) { if (ctl->pbState) DrawEdge(hdcMem,&rcClient, EDGE_ETCHED,BF_RECT|BF_SOFT); else DrawEdge(hdcMem,&rcClient, BDR_RAISEDOUTER,BF_RECT|BF_SOFT|BF_FLAT); } else if (ctl->stateId==PBS_PRESSED) DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER,BF_RECT|BF_SOFT); } } else { // Draw background/border if (ctl->hThemeButton) { int state = IsWindowEnabled(ctl->hwnd)?(ctl->stateId==PBS_NORMAL&&ctl->defbutton?PBS_DEFAULTED:ctl->stateId):PBS_DISABLED; if (isThemeBackgroundPartiallyTransparent(ctl->hThemeButton, BP_PUSHBUTTON, state)) { drawThemeParentBackground(ctl->hwnd, hdcMem, &rcClient); } drawThemeBackground(ctl->hThemeButton, hdcMem, BP_PUSHBUTTON, state, &rcClient, &rcClient); } else { UINT uState = DFCS_BUTTONPUSH|((ctl->stateId==PBS_HOT)?DFCS_HOT:0)|((ctl->stateId == PBS_PRESSED)?DFCS_PUSHED:0); if (ctl->defbutton&&ctl->stateId==PBS_NORMAL) uState |= DLGC_DEFPUSHBUTTON; DrawFrameControl(hdcMem, &rcClient, DFC_BUTTON, uState); } // Draw focus rectangle if button has focus if (ctl->focus) { RECT focusRect = rcClient; InflateRect(&focusRect, -3, -3); DrawFocusRect(hdcMem, &focusRect); } } // If we have an icon or a bitmap, ignore text and only draw the image on the button if (ctl->hIcon) { int ix = (rcClient.right-rcClient.left)/2 - (GetSystemMetrics(SM_CXSMICON)/2); int iy = (rcClient.bottom-rcClient.top)/2 - (GetSystemMetrics(SM_CYSMICON)/2); if (ctl->stateId == PBS_PRESSED) { ix++; iy++; } { HIMAGELIST hImageList; HICON hIconNew; hImageList = ImageList_Create(GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON), IsWinVerXPPlus()? ILC_COLOR32 | ILC_MASK : ILC_COLOR16 | ILC_MASK, 1, 0); ImageList_AddIcon(hImageList, ctl->hIcon); hIconNew = ImageList_GetIcon(hImageList, 0, ILD_NORMAL); DrawState(hdcMem,NULL,NULL,(LPARAM)hIconNew,0,ix,iy,GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON|DSS_NORMAL:DST_ICON|DSS_DISABLED); ImageList_RemoveAll(hImageList); ImageList_Destroy(hImageList); DestroyIcon(hIconNew); } } else if (ctl->hBitmap) { BITMAP bminfo; int ix,iy; GetObject(ctl->hBitmap, sizeof(bminfo), &bminfo); ix = (rcClient.right-rcClient.left)/2 - (bminfo.bmWidth/2); iy = (rcClient.bottom-rcClient.top)/2 - (bminfo.bmHeight/2); if (ctl->stateId == PBS_PRESSED) { ix++; iy++; } DrawState(hdcMem,NULL,NULL,(LPARAM)ctl->hBitmap,0,ix,iy,bminfo.bmWidth,bminfo.bmHeight,IsWindowEnabled(ctl->hwnd)?DST_BITMAP:DST_BITMAP|DSS_DISABLED); } else if (GetWindowTextLength(ctl->hwnd)) { // Draw the text and optinally the arrow TCHAR szText[MAX_PATH]; SIZE sz; RECT rcText; HFONT hOldFont; CopyRect(&rcText, &rcClient); GetWindowText(ctl->hwnd, szText, SIZEOF(szText)); SetBkMode(hdcMem, TRANSPARENT); hOldFont = (HFONT)SelectObject(hdcMem, ctl->hFont); // XP w/themes doesn't used the glossy disabled text. Is it always using COLOR_GRAYTEXT? Seems so. SetTextColor(hdcMem, IsWindowEnabled(ctl->hwnd)||!ctl->hThemeButton?GetSysColor(COLOR_BTNTEXT):GetSysColor(COLOR_GRAYTEXT)); GetTextExtentPoint32(hdcMem, szText, lstrlen(szText), &sz); if (ctl->cHot) { SIZE szHot; GetTextExtentPoint32 (hdcMem, _T("&"), 1, &szHot); sz.cx -= szHot.cx; } if (ctl->arrow) { DrawState(hdcMem,NULL,NULL,(LPARAM)ctl->arrow,0,rcClient.right-rcClient.left-5-GetSystemMetrics(SM_CXSMICON)+(!ctl->hThemeButton&&ctl->stateId==PBS_PRESSED?1:0),(rcClient.bottom-rcClient.top)/2-GetSystemMetrics(SM_CYSMICON)/2+(!ctl->hThemeButton&&ctl->stateId==PBS_PRESSED?1:0),GetSystemMetrics(SM_CXSMICON),GetSystemMetrics(SM_CYSMICON),IsWindowEnabled(ctl->hwnd)?DST_ICON:DST_ICON|DSS_DISABLED); } SelectObject(hdcMem, ctl->hFont); DrawState(hdcMem,NULL,NULL,(LPARAM)szText,0,(rcText.right-rcText.left-sz.cx)/2+(!ctl->hThemeButton&&ctl->stateId==PBS_PRESSED?1:0),ctl->hThemeButton?(rcText.bottom-rcText.top-sz.cy)/2:(rcText.bottom-rcText.top-sz.cy)/2-(ctl->stateId==PBS_PRESSED?0:1),sz.cx,sz.cy,IsWindowEnabled(ctl->hwnd)||ctl->hThemeButton?DST_PREFIXTEXT|DSS_NORMAL:DST_PREFIXTEXT|DSS_DISABLED); SelectObject(hdcMem, hOldFont); } BitBlt(hdcPaint, 0, 0, rcClient.right-rcClient.left, rcClient.bottom-rcClient.top, hdcMem, 0, 0, SRCCOPY); SelectObject(hdcMem, hOld); DeleteObject(hbmMem); DeleteDC(hdcMem); } }
UINT CEGetDIBColorTable(HDC hdc, UINT uStartIndex, UINT cEntries, RGBQUAD *pColors) { if (pColors == NULL) return 0; // No place to put them, fail // Get a description of the DIB Section HBITMAP hDIBSection = (HBITMAP) GetCurrentObject( hdc, OBJ_BITMAP ); DIBSECTION ds; DWORD dwSize = GetObject( hDIBSection, sizeof(DIBSECTION), &ds ); if (dwSize != sizeof(DIBSECTION)) return 0; // Must not be a DIBSection, fail if (ds.dsBmih.biBitCount > 8) return 0; // Not Palettized, fail // get the number of colors to return per BITMAPINFOHEADER docs UINT cColors; if (ds.dsBmih.biClrUsed) cColors = ds.dsBmih.biClrUsed; else cColors = 1 << (ds.dsBmih.biBitCount * ds.dsBmih.biPlanes); // Create a mask for the palette index bits for 1, 2, 4, and 8 bpp WORD wIndexMask = (0xFF << (8 - ds.dsBmih.biBitCount)) & 0x00FF; // Get the pointer to the image bits LPBYTE pBits = (LPBYTE) ds.dsBm.bmBits; // Initialize the loop variables cColors = min( cColors, cEntries ); BYTE OldPalIndex = *pBits; UINT TestPixelY; if (ds.dsBmih.biHeight > 0 ) // If button up DIB, pBits points to last row TestPixelY = ds.dsBm.bmHeight-1; else // If top down DIB, pBits points to first row TestPixelY = 0; for (UINT iColor = uStartIndex; iColor < cColors; iColor++) { COLORREF rgbColor; // Set the palette index for the test pixel, // modifying only the bits for one pixel *pBits = (iColor << (8 - ds.dsBmih.biBitCount)) | (*pBits & ~wIndexMask); // now get the resulting color rgbColor = GetPixel( hdc, 0, TestPixelY ); pColors[iColor - uStartIndex].rgbReserved = 0; pColors[iColor - uStartIndex].rgbBlue = GetBValue(rgbColor); pColors[iColor - uStartIndex].rgbRed = GetRValue(rgbColor); pColors[iColor - uStartIndex].rgbGreen = GetGValue(rgbColor); } // Restore the test pixel *pBits = OldPalIndex; return cColors; }
void map_font() { HDC hDC = GetDC( NULL ); //errno_t err ; //err = _wfopen_s(&out, L"font_dump.txt", L"w, ccs=UNICODE" ) ; //LOGFONT lf = { 0, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, //0, NULL }; //EnumFontFamiliesEx( hDC, &lf, (FONTENUMPROC)EnumFontFamiliesExProc, 0, 0 ); //fclose( out ); HFONT hfont; TEXTMETRIC tm; LOGFONTA lf; TCHAR szFaceName[LF_FACESIZE]; CHOOSEFONTA choose_font; LPCTSTR lpszFilename = "c:\\Code39Barcode.ttf"; int err; bool success; // load font err = AddFontResourceA(lpszFilename); SendMessageA(HWND_BROADCAST,WM_FONTCHANGE,0,0); choose_font.lStructSize = sizeof(CHOOSEFONT); choose_font.hwndOwner = NULL; choose_font.lpLogFont = &lf; choose_font.Flags = CF_SCREENFONTS; success = ChooseFontA( &choose_font ); /* for( indx=0; indx<num_fonts; indx++) { hfont = CreateFontA(0,0,0,0,0,0,0,0,DEFAULT_CHARSET, 0,0,0,0, font_table[indx]); SelectObject(hDC, hfont); GetObjectA( GetCurrentObject( hdc, OBJ_FONT ), sizeof(lf), (LPVOID) &lf ); // Get the info for the currently realized font. //GetTextMetrics( hdc, &tm ); GetTextFace( hdc, sizeof(szFaceName), szFaceName ); cout << "Font: " << font_table[indx] << " Mapping: " << szFaceName << endl; */ /* // get logical font information hfont = CreateFontA(0,0,0,0,0,0,0,0,DEFAULT_CHARSET, 0,0,0,0, "Code39Barcode"); SelectObject(hDC, hfont); GetObjectA( GetCurrentObject( hDC, OBJ_FONT ), sizeof(lf), (LPVOID) &lf ); GetTextFace( hDC, sizeof(szFaceName), szFaceName ); */ // unload font err = RemoveFontResourceA(lpszFilename); SendMessageA(HWND_BROADCAST,WM_FONTCHANGE,0,0); hfont = CreateFontIndirectA(&lf); SelectObject(hDC, hfont); GetObjectA( GetCurrentObject( hDC, OBJ_FONT ), sizeof(lf), (LPVOID) &lf ); GetTextFace( hDC, sizeof(szFaceName), szFaceName ); GetTextMetrics( hDC, &tm ); //cout << "Font: " << "Arial" << " Mapping: " << szFaceName << endl; ReleaseDC( NULL, hDC ); return; }
BOOL CALLBACK cfgDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { HANDLE_MSG(hwndDlg, WM_COMMAND, WMCommandProc); case WM_DRAWITEM: { DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam; int nIdx = FindControlIdx(lpdis->CtlID); #ifdef IO_LINK_UNDERLINED HFONT OldFont; LOGFONT lf; #endif if (nIdx < 0) break; FieldType *pField = pFields + nIdx; #ifdef IO_LINK_UNDERLINED GetObject(GetCurrentObject(lpdis->hDC, OBJ_FONT), sizeof(lf), &lf); lf.lfUnderline = TRUE; OldFont = (HFONT)SelectObject(lpdis->hDC, CreateFontIndirect(&lf)); #endif // We need lpdis->rcItem later RECT rc = lpdis->rcItem; // Calculate needed size of the control DrawText(lpdis->hDC, pField->pszText, -1, &rc, DT_VCENTER | DT_SINGLELINE | DT_CALCRECT); // Make some more room so the focus rect won't cut letters off rc.right = min(rc.right + 2, lpdis->rcItem.right); // Move rect to right if in RTL mode if (bRTL) { rc.left += lpdis->rcItem.right - rc.right; rc.right += lpdis->rcItem.right - rc.right; } if (lpdis->itemAction & ODA_DRAWENTIRE) { // Get TxtColor unless the user has set another using SetCtlColors if (!GetWindowLong(lpdis->hwndItem, GWL_USERDATA)) SetTextColor(lpdis->hDC, (COLORREF) pField->hImage); // Draw the text DrawText(lpdis->hDC, pField->pszText, -1, &rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE | (bRTL ? DT_RTLREADING : 0)); } // Draw the focus rect if needed if (((lpdis->itemState & ODS_FOCUS) && (lpdis->itemAction & ODA_DRAWENTIRE)) || (lpdis->itemAction & ODA_FOCUS)) { // NB: when not in DRAWENTIRE mode, this will actually toggle the focus // rectangle since it's drawn in a XOR way DrawFocusRect(lpdis->hDC, &rc); } pField->rect = rc; #ifdef IO_LINK_UNDERLINED DeleteObject(SelectObject(lpdis->hDC, OldFont)); #endif break; } case WM_CTLCOLORSTATIC: case WM_CTLCOLOREDIT: case WM_CTLCOLORDLG: case WM_CTLCOLORBTN: case WM_CTLCOLORLISTBOX: // let the NSIS window handle colors, it knows best return mySendMessage(hMainWindow, uMsg, wParam, lParam); } return 0; }
/*********************************************************************** * dibdrv_SelectBrush */ HBRUSH CDECL dibdrv_SelectBrush( PHYSDEV dev, HBRUSH hbrush ) { PHYSDEV next = GET_NEXT_PHYSDEV( dev, pSelectBrush ); dibdrv_physdev *pdev = get_dibdrv_pdev(dev); LOGBRUSH logbrush; TRACE("(%p, %p)\n", dev, hbrush); if (!GetObjectW( hbrush, sizeof(logbrush), &logbrush )) return 0; if (hbrush == GetStockObject( DC_BRUSH )) logbrush.lbColor = GetDCBrushColor( dev->hdc ); pdev->brush_style = logbrush.lbStyle; pdev->defer |= DEFER_BRUSH; free_pattern_brush( pdev ); switch(logbrush.lbStyle) { case BS_SOLID: pdev->brush_colorref = logbrush.lbColor; pdev->brush_color = get_fg_color( pdev, pdev->brush_colorref ); calc_and_xor_masks(GetROP2(dev->hdc), pdev->brush_color, &pdev->brush_and, &pdev->brush_xor); pdev->brush_rects = solid_brush; pdev->defer &= ~DEFER_BRUSH; break; case BS_NULL: pdev->brush_rects = null_brush; pdev->defer &= ~DEFER_BRUSH; break; case BS_DIBPATTERN: { BITMAPINFOHEADER *bi = GlobalLock((HGLOBAL)logbrush.lbHatch); dib_info orig_dib; WORD usage = LOWORD(logbrush.lbColor); HPALETTE pal = (usage == DIB_PAL_COLORS) ? GetCurrentObject(dev->hdc, OBJ_PAL) : NULL; if(!bi) return NULL; if(init_dib_info_from_packed(&orig_dib, bi, usage, pal)) { copy_dib_color_info(&pdev->brush_dib, &pdev->dib); if(convert_dib(&pdev->brush_dib, &orig_dib)) { pdev->brush_rects = pattern_brush; pdev->defer &= ~DEFER_BRUSH; } free_dib_info(&orig_dib, FALSE); } GlobalUnlock((HGLOBAL)logbrush.lbHatch); break; } case BS_HATCHED: { if(logbrush.lbHatch > HS_DIAGCROSS) return 0; pdev->brush_hatch = logbrush.lbHatch; pdev->brush_colorref = logbrush.lbColor; pdev->brush_color = get_fg_color( pdev, pdev->brush_colorref ); calc_and_xor_masks(GetROP2(dev->hdc), pdev->brush_color, &pdev->brush_and, &pdev->brush_xor); pdev->brush_rects = pattern_brush; pdev->defer &= ~DEFER_BRUSH; break; } default: break; } return next->funcs->pSelectBrush( next, hbrush ); }
/****************************************************************************** * CreateCompatibleBitmap [GDI32.@] * * Creates a bitmap compatible with the DC. * * PARAMS * hdc [I] Handle to device context * width [I] Width of bitmap * height [I] Height of bitmap * * RETURNS * Success: Handle to bitmap * Failure: 0 */ HBITMAP WINAPI CreateCompatibleBitmap( HDC hdc, INT width, INT height) { HBITMAP hbmpRet = 0; TRACE("(%p,%d,%d) =\n", hdc, width, height); if (GetObjectType( hdc ) != OBJ_MEMDC) { hbmpRet = CreateBitmap(width, height, GetDeviceCaps(hdc, PLANES), GetDeviceCaps(hdc, BITSPIXEL), NULL); } else /* Memory DC */ { DIBSECTION dib; HBITMAP bitmap = GetCurrentObject( hdc, OBJ_BITMAP ); INT size = GetObjectW( bitmap, sizeof(dib), &dib ); if (!size) return 0; if (size == sizeof(BITMAP)) { /* A device-dependent bitmap is selected in the DC */ hbmpRet = CreateBitmap(width, height, dib.dsBm.bmPlanes, dib.dsBm.bmBitsPixel, NULL); } else { /* A DIB section is selected in the DC */ BITMAPINFO *bi; void *bits; /* Allocate memory for a BITMAPINFOHEADER structure and a color table. The maximum number of colors in a color table is 256 which corresponds to a bitmap with depth 8. Bitmaps with higher depths don't have color tables. */ bi = HeapAlloc(GetProcessHeap(), 0, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD)); if (bi) { bi->bmiHeader.biSize = sizeof(bi->bmiHeader); bi->bmiHeader.biWidth = width; bi->bmiHeader.biHeight = height; bi->bmiHeader.biPlanes = dib.dsBmih.biPlanes; bi->bmiHeader.biBitCount = dib.dsBmih.biBitCount; bi->bmiHeader.biCompression = dib.dsBmih.biCompression; bi->bmiHeader.biSizeImage = 0; bi->bmiHeader.biXPelsPerMeter = dib.dsBmih.biXPelsPerMeter; bi->bmiHeader.biYPelsPerMeter = dib.dsBmih.biYPelsPerMeter; bi->bmiHeader.biClrUsed = dib.dsBmih.biClrUsed; bi->bmiHeader.biClrImportant = dib.dsBmih.biClrImportant; if (bi->bmiHeader.biCompression == BI_BITFIELDS) { /* Copy the color masks */ CopyMemory(bi->bmiColors, dib.dsBitfields, 3 * sizeof(DWORD)); } else if (bi->bmiHeader.biBitCount <= 8) { /* Copy the color table */ GetDIBColorTable(hdc, 0, 256, bi->bmiColors); } hbmpRet = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0); HeapFree(GetProcessHeap(), 0, bi); } } } TRACE("\t\t%p\n", hbmpRet); return hbmpRet; }
static void test_GetCurrentObject(void) { DWORD type; HPEN hpen; HBRUSH hbrush; HPALETTE hpal; HFONT hfont; HBITMAP hbmp; HRGN hrgn; HDC hdc; HCOLORSPACE hcs; HGDIOBJ hobj; LOGBRUSH lb; LOGCOLORSPACEA lcs; hdc = CreateCompatibleDC(0); assert(hdc != 0); type = GetObjectType(hdc); ok(type == OBJ_MEMDC, "GetObjectType returned %u\n", type); hpen = CreatePen(PS_SOLID, 10, RGB(10, 20, 30)); assert(hpen != 0); SelectObject(hdc, hpen); hobj = GetCurrentObject(hdc, OBJ_PEN); ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj); hobj = GetCurrentObject(hdc, OBJ_EXTPEN); ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj); hbrush = CreateSolidBrush(RGB(10, 20, 30)); assert(hbrush != 0); SelectObject(hdc, hbrush); hobj = GetCurrentObject(hdc, OBJ_BRUSH); ok(hobj == hbrush, "OBJ_BRUSH is wrong: %p\n", hobj); hpal = CreateHalftonePalette(hdc); assert(hpal != 0); SelectPalette(hdc, hpal, FALSE); hobj = GetCurrentObject(hdc, OBJ_PAL); ok(hobj == hpal, "OBJ_PAL is wrong: %p\n", hobj); hfont = CreateFontA(10, 5, 0, 0, FW_DONTCARE, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "MS Sans Serif"); assert(hfont != 0); SelectObject(hdc, hfont); hobj = GetCurrentObject(hdc, OBJ_FONT); ok(hobj == hfont, "OBJ_FONT is wrong: %p\n", hobj); hbmp = CreateBitmap(100, 100, 1, 1, NULL); assert(hbmp != 0); SelectObject(hdc, hbmp); hobj = GetCurrentObject(hdc, OBJ_BITMAP); ok(hobj == hbmp, "OBJ_BITMAP is wrong: %p\n", hobj); assert(GetObjectA(hbrush, sizeof(lb), &lb) == sizeof(lb)); hpen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_SQUARE | PS_JOIN_BEVEL, 10, &lb, 0, NULL); assert(hpen != 0); SelectObject(hdc, hpen); hobj = GetCurrentObject(hdc, OBJ_PEN); ok(hobj == hpen, "OBJ_PEN is wrong: %p\n", hobj); hobj = GetCurrentObject(hdc, OBJ_EXTPEN); ok(hobj == hpen, "OBJ_EXTPEN is wrong: %p\n", hobj); hcs = GetColorSpace(hdc); if (hcs) { trace("current color space is not NULL\n"); ok(GetLogColorSpaceA(hcs, &lcs, sizeof(lcs)), "GetLogColorSpace failed\n"); hcs = CreateColorSpaceA(&lcs); ok(hcs != 0, "CreateColorSpace failed\n"); SelectObject(hdc, hcs); hobj = GetCurrentObject(hdc, OBJ_COLORSPACE); ok(hobj == hcs, "OBJ_COLORSPACE is wrong: %p\n", hobj); } hrgn = CreateRectRgn(1, 1, 100, 100); assert(hrgn != 0); SelectObject(hdc, hrgn); hobj = GetCurrentObject(hdc, OBJ_REGION); ok(!hobj, "OBJ_REGION is wrong: %p\n", hobj); DeleteDC(hdc); }
void p_text(p_win *w, int x0, int y0, const char *text, int n) { HDC dc = w_getdc(w, 1); if (dc) { int i; if (n <= 0) n = 16350; for (i=0 ; i<n ; i++) if (!text[i]) break; n = i; if (!w->orient) { TextOut(dc, x0, y0, text, n); } else { /* only do this with opaque background, * since only 8x8 patterned brushes supported under Win95 * (could read screen, rotate, TextOut, rotate back) */ TEXTMETRIC tm; SIZE sz; if (n>0 && GetTextMetrics(dc, &tm) && GetTextExtentPoint32(dc, text, n, &sz) && sz.cx>0) { int width = sz.cx; int height = tm.tmHeight + 1; int base = tm.tmAscent; int scandx = ((width-1)/(8*sizeof(DWORD)) + 1)*(8*sizeof(DWORD)); int scandy = ((height-1)/(8*sizeof(DWORD)) + 1)*(8*sizeof(DWORD)); HDC offdc = CreateCompatibleDC(dc); HBITMAP offbm = CreateCompatibleBitmap(dc, scandx, scandy); HFONT font = GetCurrentObject(dc, OBJ_FONT); void *monodat = p_malloc(scandx*scandy/4); void *monorot = (char *)monodat + (scandx*scandy/8); struct { BITMAPINFOHEADER bmiHeader; DWORD bmiColors[2]; } mono; mono.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); mono.bmiHeader.biWidth = scandx; mono.bmiHeader.biHeight = -scandy; mono.bmiHeader.biPlanes = 1; mono.bmiHeader.biBitCount = 1; mono.bmiHeader.biCompression = BI_RGB; mono.bmiHeader.biSizeImage = 0; mono.bmiHeader.biXPelsPerMeter = 0; mono.bmiHeader.biYPelsPerMeter = 0; mono.bmiHeader.biClrUsed = 0; mono.bmiHeader.biClrImportant = 0; /* apparently, bmiColors ignored on read * -white bits are set, black bits reset no matter what */ mono.bmiColors[0] = RGB(0,0,0); mono.bmiColors[1] = RGB(255,255,255); if (offdc && offbm && font && monodat) { RECT r; SelectObject(offdc, offbm); SelectObject(offdc, font); SetBkMode(offdc, TRANSPARENT); SetTextColor(offdc, RGB(255,255,255)); SetTextAlign(offdc, TA_LEFT | TA_BASELINE | TA_NOUPDATECP); r.left = r.top = 0; r.right = scandx; r.bottom = scandy; FillRect(offdc, &r, GetStockObject(BLACK_BRUSH)); if (w->orient == 2) { TextOut(offdc, scandx-width, base, text, n); } else if (w->orient == 1) { TextOut(offdc, scandx-width, base, text, n); } else { TextOut(offdc, 0, scandy-height+base, text, n); } GetDIBits(offdc, offbm, 0, scandy, monodat, (BITMAPINFO *)&mono, DIB_RGB_COLORS); } if (offdc) DeleteDC(offdc); if (offbm) DeleteObject(offbm); if (monodat) { COLORREF bg = w_color(w,w->bg); COLORREF fg = w_color(w,w->color); if (w->orient == 2) { p_mrot180(monodat, monorot, scandx, height); x0 -= width-1; y0 -= (height-base)-1; scandx = width, width = height, height = scandx; } else if (w->orient == 1) { p_mrot090(monodat, monorot, scandx, scandy); x0 -= base; y0 -= width-1; } else { p_mrot270(monodat, monorot, scandx, scandy); x0 -= (height-base)-1; } mono.bmiColors[0] = W_SWAPRGB(bg); mono.bmiColors[1] = W_SWAPRGB(fg); mono.bmiHeader.biWidth = height; mono.bmiHeader.biHeight = -width; /* prefer this to SetDIBitsToDevice? */ StretchDIBits(dc, x0, y0, height, width, 0, 0, height, width, monorot, (BITMAPINFO *)&mono, DIB_RGB_COLORS, SRCCOPY); p_free(monodat); } } } } }
static void test_gdi_objects(void) { BYTE buff[256]; HDC hdc = GetDC(NULL); HPEN hp; int i; BOOL ret; /* SelectObject() with a NULL DC returns 0 and sets ERROR_INVALID_HANDLE. * Note: Under XP at least invalid ptrs can also be passed, not just NULL; * Don't test that here in case it crashes earlier win versions. */ SetLastError(0); hp = SelectObject(NULL, GetStockObject(BLACK_PEN)); ok(!hp && (GetLastError() == ERROR_INVALID_HANDLE || broken(!GetLastError())), "SelectObject(NULL DC) expected 0, ERROR_INVALID_HANDLE, got %p, %u\n", hp, GetLastError()); /* With a valid DC and a NULL object, the call returns 0 but does not SetLastError() */ SetLastError(0); hp = SelectObject(hdc, NULL); ok(!hp && !GetLastError(), "SelectObject(NULL obj) expected 0, NO_ERROR, got %p, %u\n", hp, GetLastError()); /* The DC is unaffected by the NULL SelectObject */ SetLastError(0); hp = SelectObject(hdc, GetStockObject(BLACK_PEN)); ok(hp && !GetLastError(), "SelectObject(post NULL) expected non-null, NO_ERROR, got %p, %u\n", hp, GetLastError()); /* GetCurrentObject does not SetLastError() on a null object */ SetLastError(0); hp = GetCurrentObject(NULL, OBJ_PEN); ok(!hp && !GetLastError(), "GetCurrentObject(NULL DC) expected 0, NO_ERROR, got %p, %u\n", hp, GetLastError()); /* DeleteObject does not SetLastError() on a null object */ ret = DeleteObject(NULL); ok( !ret && !GetLastError(), "DeleteObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n", ret, GetLastError()); /* GetObject does not SetLastError() on a null object */ SetLastError(0); i = GetObjectA(NULL, sizeof(buff), buff); ok (!i && (GetLastError() == 0 || GetLastError() == ERROR_INVALID_PARAMETER), "GetObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n", i, GetLastError()); /* GetObject expects ERROR_NOACCESS when passed an invalid buffer */ hp = SelectObject(hdc, GetStockObject(BLACK_PEN)); SetLastError(0); i = GetObjectA(hp, (INT_PTR)buff, (LPVOID)sizeof(buff)); ok (!i && (GetLastError() == 0 || GetLastError() == ERROR_NOACCESS), "GetObject(invalid buff), expected 0, ERROR_NOACCESS, got %d, %u\n", i, GetLastError()); /* GetObjectType does SetLastError() on a null object */ SetLastError(0); i = GetObjectType(NULL); ok (!i && GetLastError() == ERROR_INVALID_HANDLE, "GetObjectType(NULL obj), expected 0, ERROR_INVALID_HANDLE, got %d, %u\n", i, GetLastError()); /* UnrealizeObject does not SetLastError() on a null object */ SetLastError(0); i = UnrealizeObject(NULL); ok (!i && !GetLastError(), "UnrealizeObject(NULL obj), expected 0, NO_ERROR, got %d, %u\n", i, GetLastError()); ReleaseDC(NULL, hdc); }
static void PaintWorker(TBBUTTONDATA *bct, HDC hdcPaint, POINT *pOffset) { if (!hdcPaint) return; //early exit POINT offset; if (pOffset) offset = *pOffset; else offset.x = offset.y = 0; RECT rcClient; GetClientRect(bct->hwnd, &rcClient); int width = rcClient.right - rcClient.left; int height = rcClient.bottom - rcClient.top; HBITMAP hbmMem = NULL; HBITMAP hbmOld = NULL; HDC hdcMem = pOffset ? hdcPaint : CreateCompatibleDC(hdcPaint); HFONT hOldFont = (HFONT)SelectObject(hdcMem, bct->hFont); if (!pOffset) { hbmMem = ske_CreateDIB32(width, height); hbmOld = (HBITMAP)SelectObject(hdcMem, hbmMem); } else OffsetRect(&rcClient, offset.x, offset.y); if (!g_CluiData.fDisableSkinEngine) { char szRequest[128]; /* painting */ mir_snprintf(szRequest, "Button,ID=%s,Hovered=%s,Pressed=%s,Focused=%s", bct->szButtonID, // ID b2str(bct->stateId == PBS_HOT), // Hovered b2str(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE), // Pressed b2str(bct->bFocused)); // Focused SkinDrawGlyph(hdcMem, &rcClient, &rcClient, szRequest); } else if (xpt_IsThemed(bct->hThemeToolbar)) { RECT *rc = &rcClient; int state = IsWindowEnabled(bct->hwnd) ? /*(bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE) ? PBS_PRESSED :*/ (bct->stateId == PBS_NORMAL && bct->bIsDefault ? PBS_DEFAULTED : bct->stateId) : PBS_DISABLED; xpt_DrawTheme(bct->hThemeToolbar, bct->hwnd, hdcMem, TP_BUTTON, TBStateConvert2Flat(state), rc, rc); } else { HBRUSH hbr = NULL; if (bct->stateId == PBS_PRESSED || bct->stateId == PBS_HOT) hbr = GetSysColorBrush(COLOR_3DLIGHT); else { RECT btnRect; POINT pt = { 0 }; int ret; HWND hwndParent = GetParent(bct->hwnd); HDC dc = CreateCompatibleDC(NULL); HBITMAP memBM, oldBM; GetWindowRect(hwndParent, &btnRect); memBM = ske_CreateDIB32(btnRect.right - btnRect.left, btnRect.bottom - btnRect.top); oldBM = (HBITMAP)SelectObject(dc, memBM); ret = SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM)dc, 0); GetWindowRect(bct->hwnd, &btnRect); ClientToScreen(hwndParent, &pt); OffsetRect(&btnRect, -pt.x, -pt.y); if (ret) BitBlt(hdcMem, 0, 0, btnRect.right - btnRect.left, btnRect.bottom - btnRect.top, dc, btnRect.left, btnRect.top, SRCCOPY); oldBM = (HBITMAP)SelectObject(dc, oldBM); DeleteObject(memBM); DeleteDC(dc); if (!ret) { //WM_ERASEBKG return false need to paint HDC pdc = GetDC(hwndParent); HBRUSH oldBrush = (HBRUSH)GetCurrentObject(pdc, OBJ_BRUSH); hbr = (HBRUSH)SendMessage(hwndParent, WM_CTLCOLORDLG, (WPARAM)pdc, (LPARAM)hwndParent); SelectObject(pdc, oldBrush); ReleaseDC(hwndParent, pdc); } } if (hbr) { FillRect(hdcMem, &rcClient, hbr); DeleteObject(hbr); } if (bct->stateId == PBS_HOT || bct->bFocused) { if (bct->bIsPushed) DrawEdge(hdcMem, &rcClient, EDGE_ETCHED, BF_RECT | BF_SOFT); else DrawEdge(hdcMem, &rcClient, BDR_RAISEDOUTER, BF_RECT | BF_SOFT | BF_FLAT); } else if (bct->stateId == PBS_PRESSED) DrawEdge(hdcMem, &rcClient, BDR_SUNKENOUTER, BF_RECT | BF_SOFT); } RECT rcTemp = rcClient; //content rect bool bPressed = (bct->stateId == PBS_PRESSED || bct->bIsPushed == TRUE); bool bHasText = (bct->szText[0] != '\0'); /* formatter */ if (!g_CluiData.fDisableSkinEngine) { /* correct rect according to rcMargins */ rcTemp.left += bct->rcMargins.left; rcTemp.top += bct->rcMargins.top; rcTemp.bottom -= bct->rcMargins.bottom; rcTemp.right -= bct->rcMargins.right; } /* reposition button items */ RECT rcIcon = rcTemp, rcText = rcTemp; if (bct->hIcon) { if (bHasText) { rcIcon.right = rcIcon.left + 16; /* CXSM_ICON */ rcText.left = rcIcon.right + 2; } else { rcIcon.left += (rcIcon.right - rcIcon.left) / 2 - 8; rcIcon.right = rcIcon.left + 16; } } /* Check sizes*/ if (bct->hIcon && (rcIcon.right > rcTemp.right || rcIcon.bottom > rcTemp.bottom || rcIcon.left < rcTemp.left || rcIcon.top < rcTemp.top)) bct->hIcon = NULL; if (bHasText && (rcText.right > rcTemp.right || rcText.bottom > rcTemp.bottom || rcText.left < rcTemp.left || rcText.top < rcTemp.top)) bHasText = FALSE; if (bct->hIcon) { /* center icon vertically */ rcIcon.top += (rcClient.bottom - rcClient.top) / 2 - 8; /* CYSM_ICON/2 */ rcIcon.bottom = rcIcon.top + 16; /* CYSM_ICON */ /* draw it */ ske_DrawIconEx(hdcMem, rcIcon.left + bPressed, rcIcon.top + bPressed, bct->hIcon, 16, 16, 0, NULL, DI_NORMAL); } if (bHasText) { BOOL bCentered = TRUE; SetBkMode(hdcMem, TRANSPARENT); if (bct->nFontID >= 0) g_clcPainter.ChangeToFont(hdcMem, NULL, bct->nFontID, NULL); RECT TextRequiredRect = rcText; ske_DrawText(hdcMem, bct->szText, -1, &TextRequiredRect, DT_CENTER | DT_VCENTER | DT_CALCRECT | DT_SINGLELINE); if (TextRequiredRect.right - TextRequiredRect.left > rcText.right - rcText.left) bCentered = FALSE; ske_DrawText(hdcMem, bct->szText, -1, &rcText, (bCentered ? DT_CENTER : 0) | DT_VCENTER | DT_SINGLELINE); ske_ResetTextEffect(hdcMem); } if (!pOffset) BitBlt(hdcPaint, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); // better to use try/finally but looks like last one is Microsoft specific SelectObject(hdcMem, hOldFont); if (!pOffset) { SelectObject(hdcMem, hbmOld); DeleteObject(hbmMem); DeleteDC(hdcMem); } }
BOOL sw_SetContext(struct wgl_dc_data* dc_data, DHGLRC dhglrc) { struct sw_context* sw_ctx = (struct sw_context*)dhglrc; struct sw_framebuffer* fb = dc_data->sw_data; UINT width, height; /* Update state */ sw_update_state(&sw_ctx->mesa, 0); /* Get framebuffer size */ if(dc_data->flags & WGL_DC_OBJ_DC) { HWND hwnd = dc_data->owner.hwnd; RECT client_rect; if(!hwnd) { ERR("Physical DC without a window!\n"); return FALSE; } if(!GetClientRect(hwnd, &client_rect)) { ERR("GetClientRect failed!\n"); return FALSE; } /* This is a physical DC. Setup the hook */ sw_ctx->hook = SetWindowsHookEx(WH_CALLWNDPROC, sw_call_window_proc, NULL, GetCurrentThreadId()); /* Calculate width & height */ width = client_rect.right - client_rect.left; height = client_rect.bottom - client_rect.top; } else /* OBJ_MEMDC */ { BITMAP bm; HBITMAP hbmp; HDC hdc = dc_data->owner.hdc; if(fb->flags & SW_FB_DOUBLEBUFFERED) { ERR("Memory DC called with a double buffered format.\n"); return FALSE; } hbmp = GetCurrentObject( hdc, OBJ_BITMAP ); if(!hbmp) { ERR("No Bitmap!\n"); return FALSE; } if(GetObject(hbmp, sizeof(bm), &bm) == 0) { ERR("GetObject failed!\n"); return FALSE; } width = bm.bmWidth; height = bm.bmHeight; } if(!width) width = 1; if(!height) height = 1; fb->bmi.bmiHeader.biWidth = width; fb->bmi.bmiHeader.biHeight = height; /* Also make the mesa context current to mesa */ if(!_mesa_make_current(&sw_ctx->mesa, fb->gl_buffer, fb->gl_buffer)) { ERR("_mesa_make_current filaed!\n"); return FALSE; } /* Set the viewport if this is the first time we initialize this context */ if(sw_ctx->mesa.Viewport.X == 0 && sw_ctx->mesa.Viewport.Y == 0 && sw_ctx->mesa.Viewport.Width == 0 && sw_ctx->mesa.Viewport.Height == 0) { _mesa_set_viewport(&sw_ctx->mesa, 0, 0, width, height); } /* update the framebuffer size */ _mesa_resize_framebuffer(&sw_ctx->mesa, fb->gl_buffer, width, height); /* We're good */ return TRUE; }
/* ** 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 OBS::DrawStatusBar(DRAWITEMSTRUCT &dis) { if(!App->bRunning) return; HDC hdcTemp = CreateCompatibleDC(dis.hDC); HBITMAP hbmpTemp = CreateCompatibleBitmap(dis.hDC, dis.rcItem.right-dis.rcItem.left, dis.rcItem.bottom-dis.rcItem.top); SelectObject(hdcTemp, hbmpTemp); SelectObject(hdcTemp, GetCurrentObject(dis.hDC, OBJ_FONT)); //HBRUSH hColorBrush = CreateSolidBrush((green<<8)|red); RECT rc; mcpy(&rc, &dis.rcItem, sizeof(rc)); rc.left -= dis.rcItem.left; rc.right -= dis.rcItem.left; rc.top -= dis.rcItem.top; rc.bottom -= dis.rcItem.top; FillRect(hdcTemp, &rc, (HBRUSH)(COLOR_BTNFACE+1)); //DeleteObject(hColorBrush); //-------------------------------- if(dis.itemID == 4) { DWORD green = 0xFF, red = 0xFF; statusBarData.bytesPerSec = App->bytesPerSec; statusBarData.strain = App->curStrain; //statusBarData.strain = rand()%101; if(statusBarData.strain > 50.0) green = DWORD(((50.0-(statusBarData.strain-50.0))/50.0)*255.0); double redStrain = statusBarData.strain/50.0; if(redStrain > 1.0) redStrain = 1.0; red = DWORD(redStrain*255.0); //-------------------------------- HBRUSH hColorBrush = CreateSolidBrush((green<<8)|red); RECT rcBox = {0, 0, 20, 20}; /*rc.left += dis.rcItem.left; rc.right += dis.rcItem.left; rc.top += dis.rcItem.top; rc.bottom += dis.rcItem.top;*/ FillRect(hdcTemp, &rcBox, hColorBrush); DeleteObject(hColorBrush); //-------------------------------- SetBkMode(hdcTemp, TRANSPARENT); rc.left += 22; String strKBPS; strKBPS << IntString((statusBarData.bytesPerSec*8) / 1000) << TEXT("kb/s"); //strKBPS << IntString(rand()) << TEXT("kb/s"); DrawText(hdcTemp, strKBPS, strKBPS.Length(), &rc, DT_VCENTER|DT_SINGLELINE|DT_LEFT); } else { String strOutString; switch(dis.itemID) { case 0: strOutString << App->GetMostImportantInfo(); break; case 1: { DWORD streamTimeSecondsTotal = App->totalStreamTime/1000; DWORD streamTimeMinutesTotal = streamTimeSecondsTotal/60; DWORD streamTimeSeconds = streamTimeSecondsTotal%60; DWORD streamTimeHours = streamTimeMinutesTotal/60; DWORD streamTimeMinutes = streamTimeMinutesTotal%60; strOutString = FormattedString(TEXT("%u:%02u:%02u"), streamTimeHours, streamTimeMinutes, streamTimeSeconds); } break; case 2: { double percentageDropped = 0.0; if (OSTryEnterMutex(App->hStartupShutdownMutex)) { if(App->network) { UINT numTotalFrames = App->network->NumTotalVideoFrames(); if(numTotalFrames) percentageDropped = (double(App->network->NumDroppedFrames())/double(numTotalFrames))*100.0; } OSLeaveMutex(App->hStartupShutdownMutex); } strOutString << Str("MainWindow.DroppedFrames") << FormattedString(TEXT(" %u (%0.2f%%)"), App->curFramesDropped, percentageDropped); } break; case 3: strOutString << TEXT("FPS: ") << IntString(App->captureFPS); break; } if(strOutString.IsValid()) { SetBkMode(hdcTemp, TRANSPARENT); DrawText(hdcTemp, strOutString, strOutString.Length(), &rc, DT_VCENTER|DT_SINGLELINE|DT_LEFT); } } //-------------------------------- BitBlt(dis.hDC, dis.rcItem.left, dis.rcItem.top, dis.rcItem.right-dis.rcItem.left, dis.rcItem.bottom-dis.rcItem.top, hdcTemp, 0, 0, SRCCOPY); DeleteObject(hdcTemp); DeleteObject(hbmpTemp); }
Bool window_subsystem_init( char * error_buf) { WNDCLASSW wc; HDC dc; HBITMAP hbm; OSVERSIONINFO os = { sizeof( OSVERSIONINFO)}; guts. version = GetVersion(); GetVersionEx( &os); guts. alloc_utf8_to_wchar_visual = (( os.dwMajorVersion > 5) || (os.dwMajorVersion == 5 && os.dwMinorVersion > 1)) ? alloc_utf8_to_wchar_visual : alloc_utf8_to_wchar; guts. mainThreadId = GetCurrentThreadId(); guts. errorMode = SetErrorMode( SEM_FAILCRITICALERRORS); guts. desktopWindow = GetDesktopWindow(); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_app_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"GenericApp"; RegisterClassW( &wc); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_frame_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"GenericFrame"; RegisterClassW( &wc); memset( &wc, 0, sizeof( wc)); wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wc.lpfnWndProc = ( WNDPROC) generic_view_handler; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = guts. instance; wc.hIcon = LoadIcon( guts. instance, IDI_APPLICATION); wc.hCursor = NULL; // LoadCursor( NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)NULL; wc.lpszClassName = L"Generic"; RegisterClassW( &wc); stylusMan = hash_create(); fontMan = hash_create(); patMan = hash_create(); menuMan = hash_create(); imageMan = hash_create(); regnodeMan = hash_create(); create_font_hash(); { LOGBRUSH b = { BS_HOLLOW, 0, 0}; Font f; hPenHollow = CreatePen( PS_NULL, 0, 0); hBrushHollow = CreateBrushIndirect( &b); hPatHollow. dotsCount = 0; hPatHollow. dotsPtr = nil; FONTSTRUCSIZE = (char *)(&(f. name)) - (char *)(&f); } if (!( dc = dc_alloc())) return false; guts. displayResolution. x = GetDeviceCaps( dc, LOGPIXELSX); guts. displayResolution. y = GetDeviceCaps( dc, LOGPIXELSY); { LOGFONT lf; HFONT sfont; // getting most common font name memset( &lf, 0, sizeof( lf)); lf. lfCharSet = OEM_CHARSET; lf. lfOutPrecision = OUT_DEFAULT_PRECIS; lf. lfClipPrecision = CLIP_DEFAULT_PRECIS; lf. lfQuality = PROOF_QUALITY; lf. lfPitchAndFamily = DEFAULT_PITCH; sfont = SelectObject( dc, CreateFontIndirect( &lf)); GetTextFace( dc, 256, guts. defaultSystemFont); // getting common fixed font name lf. lfHeight = 320; lf. lfPitchAndFamily = FIXED_PITCH; DeleteObject( SelectObject( dc, CreateFontIndirect( &lf))); GetTextFace( dc, 256, guts. defaultFixedFont); // getting common variable font name lf. lfPitchAndFamily = VARIABLE_PITCH; DeleteObject( SelectObject( dc, CreateFontIndirect( &lf))); GetTextFace( dc, 256, guts. defaultVariableFont); DeleteObject( SelectObject( dc, sfont)); // getting system font presets memset( &guts. windowFont, 0, sizeof( Font)); strcpy( guts. windowFont. name, DEFAULT_WIDGET_FONT); guts. windowFont. size = DEFAULT_WIDGET_FONT_SIZE; guts. windowFont. width = guts. windowFont. height = C_NUMERIC_UNDEF; #ifdef FONT_CHECK guts. windowFont. size = 12; #endif apc_font_pick( nilHandle, &guts. windowFont, &guts. windowFont); guts. ncmData. cbSize = sizeof( NONCLIENTMETRICS); SystemParametersInfo( SPI_GETNONCLIENTMETRICS, sizeof( NONCLIENTMETRICS), ( PVOID) &guts. ncmData, 0); font_logfont2font( &guts. ncmData. lfMenuFont, &guts. menuFont, &guts. displayResolution); font_logfont2font( &guts. ncmData. lfMessageFont, &guts. msgFont, &guts. displayResolution); font_logfont2font( &guts. ncmData. lfCaptionFont, &guts. capFont, &guts. displayResolution); } memset( &guts. displayBMInfo, 0, sizeof( guts. displayBMInfo)); guts. displayBMInfo. bmiHeader. biSize = sizeof( BITMAPINFO); if ( !( hbm = GetCurrentObject( dc, OBJ_BITMAP))) { apiErr; dc_free(); return false; } if ( !GetDIBits( dc, hbm, 0, 0, NULL, &guts. displayBMInfo, DIB_PAL_COLORS)) { guts. displayBMInfo. bmiHeader. biBitCount = GetDeviceCaps( dc, BITSPIXEL); guts. displayBMInfo. bmiHeader. biPlanes = GetDeviceCaps( dc, PLANES); } dc_free(); guts. insertMode = true; guts. iconSizeSmall. x = GetSystemMetrics( SM_CXSMICON); guts. iconSizeSmall. y = GetSystemMetrics( SM_CYSMICON); guts. iconSizeLarge. x = GetSystemMetrics( SM_CXICON); guts. iconSizeLarge. y = GetSystemMetrics( SM_CYICON); guts. pointerSize. x = GetSystemMetrics( SM_CXCURSOR); guts. pointerSize. y = GetSystemMetrics( SM_CYCURSOR); list_create( &guts. transp, 8, 8); list_create( &guts. files, 8, 8); list_create( &guts. sockets, 8, 8); // selecting locale layout, more or less latin-like { char buf[ KL_NAMELENGTH * 2] = ""; HKL current = GetKeyboardLayout( 0); int i, j, size = GetKeyboardLayoutList( 0, nil); HKL * kl = ( HKL *) malloc( sizeof( HKL) * size); guts. keyLayout = nil; if ( !GetKeyboardLayoutName( buf)) apiErr; for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) { if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) { guts. keyLayout = current; goto found_1; } } if ( kl) { GetKeyboardLayoutList( size, kl); for ( i = 0; i < size; i++) { ActivateKeyboardLayout( kl[ i], 0); if ( !GetKeyboardLayoutName( buf)) apiErr; for ( j = 0; j < ( sizeof( keyLayouts) / sizeof( char*)); j++) { if ( strncmp( buf + 4, keyLayouts[ j], 4) == 0) { guts. keyLayout = kl[ i]; goto found_2; } } } found_2:; ActivateKeyboardLayout( current, 0); } found_1:; free( kl); } guts. currentKeyState = guts. keyState; memset( guts. emptyKeyState, 0, sizeof( guts. emptyKeyState)); guts. smDblClk. x = GetSystemMetrics( SM_CXDOUBLECLK); guts. smDblClk. y = GetSystemMetrics( SM_CYDOUBLECLK); return true; }
INT Test_NtGdiSaveDC(PTESTINFO pti) { HDC hdc, hdc2; HWND hwnd; HBITMAP hbmp1, hbmp2, hOldBmp; /* Test 0 hdc */ TEST(NtGdiSaveDC(0) == 0); /* Test info dc */ hdc = CreateICW(L"DISPLAY",NULL,NULL,NULL); TEST(hdc); TEST(NtGdiSaveDC(hdc) == 1); TEST(NtGdiSaveDC(hdc) == 2); DeleteDC(hdc); /* Test display dc */ hdc = GetDC(0); TEST(hdc); TEST(NtGdiSaveDC(hdc) == 1); TEST(NtGdiSaveDC(hdc) == 2); ReleaseDC(0, hdc); /* Test a mem DC */ hdc = CreateCompatibleDC(0); TEST(hdc); TEST(NtGdiSaveDC(hdc) == 1); TEST(NtGdiSaveDC(hdc) == 2); DeleteDC(hdc); /* Create a window */ hwnd = CreateWindowW(L"BUTTON", L"TestWindow", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 10, 10, 100, 100, NULL, NULL, g_hInstance, 0); hdc = GetDC(hwnd); TEST(hdc); TEST(NtGdiSaveDC(hdc) == 1); NtGdiRestoreDC(hdc, 1); ReleaseDC(hwnd, hdc); DestroyWindow(hwnd); /* test behaviour when a bitmap is selected */ hbmp1 = CreateBitmap(2, 2, 1, 1, NULL); TEST(hbmp1); hbmp2 = CreateBitmap(2, 2, 1, 1, NULL); TEST(hbmp2); hdc = CreateCompatibleDC(0); TEST(hdc); hdc2 = CreateCompatibleDC(0); TEST(hdc2); hOldBmp = SelectObject(hdc, hbmp1); TEST(hOldBmp); TEST(NtGdiSaveDC(hdc) == 1); TEST(SelectObject(hdc, hbmp2) == hbmp1); TEST(SelectObject(hdc2, hbmp1) == NULL); SelectObject(hdc, hOldBmp); NtGdiRestoreDC(hdc, 1); TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1); /* Again, just to be sure */ TEST(NtGdiSaveDC(hdc) == 1); TEST(NtGdiSaveDC(hdc) == 2); TEST(SelectObject(hdc, hbmp2) == hbmp1); TEST(SelectObject(hdc2, hbmp1) == NULL); SelectObject(hdc, hOldBmp); NtGdiRestoreDC(hdc, 2); TEST(GetCurrentObject(hdc, OBJ_BITMAP) == hbmp1); /*Cleanup */ SelectObject(hdc, hOldBmp); DeleteDC(hdc); DeleteDC(hdc2); DeleteObject(hbmp1); DeleteObject(hbmp2); return APISTATUS_NORMAL; }
static void test_CreateBitmapRenderTarget(void) { IDWriteBitmapRenderTarget *target, *target2; IDWriteGdiInterop *interop; DIBSECTION ds; HBITMAP hbm; HRESULT hr; SIZE size; HDC hdc; int ret; hr = IDWriteFactory_GetGdiInterop(factory, &interop); EXPECT_HR(hr, S_OK); target = NULL; hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target); EXPECT_HR(hr, S_OK); if (0) /* crashes on native */ hr = IDWriteBitmapRenderTarget_GetSize(target, NULL); size.cx = size.cy = -1; hr = IDWriteBitmapRenderTarget_GetSize(target, &size); EXPECT_HR(hr, S_OK); ok(size.cx == 0, "got %d\n", size.cx); ok(size.cy == 0, "got %d\n", size.cy); target2 = NULL; hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 0, 0, &target2); EXPECT_HR(hr, S_OK); ok(target != target2, "got %p, %p\n", target2, target); IDWriteBitmapRenderTarget_Release(target2); hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target); ok(hdc != NULL, "got %p\n", hdc); hbm = GetCurrentObject(hdc, OBJ_BITMAP); ok(hbm != NULL, "got %p\n", hbm); /* check DIB properties */ ret = GetObjectW(hbm, sizeof(ds), &ds); ok(ret == sizeof(BITMAP), "got %d\n", ret); ok(ds.dsBm.bmWidth == 1, "got %d\n", ds.dsBm.bmWidth); ok(ds.dsBm.bmHeight == 1, "got %d\n", ds.dsBm.bmHeight); ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes); ok(ds.dsBm.bmBitsPixel == 1, "got %d\n", ds.dsBm.bmBitsPixel); ok(!ds.dsBm.bmBits, "got %p\n", ds.dsBm.bmBits); IDWriteBitmapRenderTarget_Release(target); hbm = GetCurrentObject(hdc, OBJ_BITMAP); ok(!hbm, "got %p\n", hbm); target = NULL; hr = IDWriteGdiInterop_CreateBitmapRenderTarget(interop, NULL, 10, 5, &target); EXPECT_HR(hr, S_OK); hdc = IDWriteBitmapRenderTarget_GetMemoryDC(target); ok(hdc != NULL, "got %p\n", hdc); hbm = GetCurrentObject(hdc, OBJ_BITMAP); ok(hbm != NULL, "got %p\n", hbm); /* check DIB properties */ ret = GetObjectW(hbm, sizeof(ds), &ds); ok(ret == sizeof(ds), "got %d\n", ret); ok(ds.dsBm.bmWidth == 10, "got %d\n", ds.dsBm.bmWidth); ok(ds.dsBm.bmHeight == 5, "got %d\n", ds.dsBm.bmHeight); ok(ds.dsBm.bmPlanes == 1, "got %d\n", ds.dsBm.bmPlanes); ok(ds.dsBm.bmBitsPixel == 32, "got %d\n", ds.dsBm.bmBitsPixel); ok(ds.dsBm.bmBits != NULL, "got %p\n", ds.dsBm.bmBits); size.cx = size.cy = -1; hr = IDWriteBitmapRenderTarget_GetSize(target, &size); EXPECT_HR(hr, S_OK); ok(size.cx == 10, "got %d\n", size.cx); ok(size.cy == 5, "got %d\n", size.cy); IDWriteBitmapRenderTarget_Release(target); IDWriteGdiInterop_Release(interop); }
/**************************************************************************** * PSDRV_WriteSetDownloadFont * * Write setfont for download font. * */ BOOL PSDRV_WriteSetDownloadFont(PHYSDEV dev) { PSDRV_PDEVICE *physDev = get_psdrv_dev( dev ); char *ps_name; LPOUTLINETEXTMETRICA potm; DWORD len = GetOutlineTextMetricsA(dev->hdc, 0, NULL); DOWNLOAD *pdl; LOGFONTW lf; UINT ppem; XFORM xform; assert(physDev->font.fontloc == Download); potm = HeapAlloc(GetProcessHeap(), 0, len); GetOutlineTextMetricsA(dev->hdc, len, potm); get_download_name(dev, potm, &ps_name); physDev->font.fontinfo.Download = is_font_downloaded(physDev, ps_name); if (!GetObjectW( GetCurrentObject(dev->hdc, OBJ_FONT), sizeof(lf), &lf )) return FALSE; ppem = calc_ppem_for_height(dev->hdc, lf.lfHeight); /* Retrieve the world -> device transform */ GetTransform(dev->hdc, 0x204, &xform); if(GetGraphicsMode(dev->hdc) == GM_COMPATIBLE) { xform.eM11 = xform.eM22 = fabs(xform.eM22); xform.eM21 = xform.eM12 = 0; } physDev->font.size.xx = ps_round(ppem * xform.eM11); physDev->font.size.xy = ps_round(ppem * xform.eM12); physDev->font.size.yx = -ps_round(ppem * xform.eM21); physDev->font.size.yy = -ps_round(ppem * xform.eM22); physDev->font.underlineThickness = potm->otmsUnderscoreSize; physDev->font.underlinePosition = potm->otmsUnderscorePosition; physDev->font.strikeoutThickness = potm->otmsStrikeoutSize; physDev->font.strikeoutPosition = potm->otmsStrikeoutPosition; if(physDev->font.fontinfo.Download == NULL) { RECT bbox; UINT emsize; if (!get_bbox(dev->hdc, &bbox, &emsize)) { HeapFree(GetProcessHeap(), 0, potm); return FALSE; } if(!is_room_for_font(physDev)) PSDRV_EmptyDownloadList(dev, TRUE); pdl = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pdl)); pdl->ps_name = HeapAlloc(GetProcessHeap(), 0, strlen(ps_name)+1); strcpy(pdl->ps_name, ps_name); pdl->next = NULL; if(physDev->pi->ppd->TTRasterizer == RO_Type42) { pdl->typeinfo.Type42 = T42_download_header(dev, ps_name, &bbox, emsize); pdl->type = Type42; } if(pdl->typeinfo.Type42 == NULL) { pdl->typeinfo.Type1 = T1_download_header(dev, ps_name, &bbox, emsize); pdl->type = Type1; } pdl->next = physDev->downloaded_fonts; physDev->downloaded_fonts = pdl; physDev->font.fontinfo.Download = pdl; if(pdl->type == Type42) { char g_name[MAX_G_NAME + 1]; get_glyph_name(dev->hdc, 0, g_name); T42_download_glyph(dev, pdl, 0, g_name); } } PSDRV_WriteSetFont(dev, ps_name, physDev->font.size, physDev->font.escapement); HeapFree(GetProcessHeap(), 0, ps_name); HeapFree(GetProcessHeap(), 0, potm); return TRUE; }
/*********************************************************************** * wglUseFontOutlines_common */ static BOOL wglUseFontOutlines_common(HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf, BOOL unicode) { UINT glyph; const MAT2 identity = {{0,1},{0,0},{0,0},{0,1}}; GLUtesselator *tess; LOGFONTW lf; HFONT old_font, unscaled_font; UINT em_size = 1024; RECT rc; TRACE("(%p, %d, %d, %d, %f, %f, %d, %p, %s)\n", hdc, first, count, listBase, deviation, extrusion, format, lpgmf, unicode ? "W" : "A"); if (!load_libglu()) { ERR("libGLU is required for this function but isn't loaded\n"); return FALSE; } ENTER_GL(); tess = pgluNewTess(); if(tess) { pgluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr)tess_callback_vertex); pgluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr)tess_callback_begin); pgluTessCallback(tess, GLU_TESS_END, tess_callback_end); } LEAVE_GL(); if(!tess) return FALSE; GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf); rc.left = rc.right = rc.bottom = 0; rc.top = em_size; DPtoLP(hdc, (POINT*)&rc, 2); lf.lfHeight = -abs(rc.top - rc.bottom); lf.lfOrientation = lf.lfEscapement = 0; unscaled_font = CreateFontIndirectW(&lf); old_font = SelectObject(hdc, unscaled_font); for (glyph = first; glyph < first + count; glyph++) { DWORD needed; GLYPHMETRICS gm; BYTE *buf; TTPOLYGONHEADER *pph; TTPOLYCURVE *ppc; GLdouble *vertices; if(unicode) needed = GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity); else needed = GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, 0, NULL, &identity); if(needed == GDI_ERROR) goto error; buf = HeapAlloc(GetProcessHeap(), 0, needed); vertices = HeapAlloc(GetProcessHeap(), 0, needed / sizeof(POINTFX) * 3 * sizeof(GLdouble)); if(unicode) GetGlyphOutlineW(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity); else GetGlyphOutlineA(hdc, glyph, GGO_NATIVE, &gm, needed, buf, &identity); TRACE("glyph %d\n", glyph); if(lpgmf) { lpgmf->gmfBlackBoxX = (float)gm.gmBlackBoxX / em_size; lpgmf->gmfBlackBoxY = (float)gm.gmBlackBoxY / em_size; lpgmf->gmfptGlyphOrigin.x = (float)gm.gmptGlyphOrigin.x / em_size; lpgmf->gmfptGlyphOrigin.y = (float)gm.gmptGlyphOrigin.y / em_size; lpgmf->gmfCellIncX = (float)gm.gmCellIncX / em_size; lpgmf->gmfCellIncY = (float)gm.gmCellIncY / em_size; TRACE("%fx%f at %f,%f inc %f,%f\n", lpgmf->gmfBlackBoxX, lpgmf->gmfBlackBoxY, lpgmf->gmfptGlyphOrigin.x, lpgmf->gmfptGlyphOrigin.y, lpgmf->gmfCellIncX, lpgmf->gmfCellIncY); lpgmf++; } ENTER_GL(); glNewList(listBase++, GL_COMPILE); pgluTessBeginPolygon(tess, NULL); pph = (TTPOLYGONHEADER*)buf; while((BYTE*)pph < buf + needed) { TRACE("\tstart %d, %d\n", pph->pfxStart.x.value, pph->pfxStart.y.value); pgluTessBeginContour(tess); fixed_to_double(pph->pfxStart, em_size, vertices); pgluTessVertex(tess, vertices, vertices); vertices += 3; ppc = (TTPOLYCURVE*)((char*)pph + sizeof(*pph)); while((char*)ppc < (char*)pph + pph->cb) { int i; switch(ppc->wType) { case TT_PRIM_LINE: for(i = 0; i < ppc->cpfx; i++) { TRACE("\t\tline to %d, %d\n", ppc->apfx[i].x.value, ppc->apfx[i].y.value); fixed_to_double(ppc->apfx[i], em_size, vertices); pgluTessVertex(tess, vertices, vertices); vertices += 3; } break; case TT_PRIM_QSPLINE: for(i = 0; i < ppc->cpfx/2; i++) { /* FIXME just connecting the control points for now */ TRACE("\t\tcurve %d,%d %d,%d\n", ppc->apfx[i * 2].x.value, ppc->apfx[i * 3].y.value, ppc->apfx[i * 2 + 1].x.value, ppc->apfx[i * 3 + 1].y.value); fixed_to_double(ppc->apfx[i * 2], em_size, vertices); pgluTessVertex(tess, vertices, vertices); vertices += 3; fixed_to_double(ppc->apfx[i * 2 + 1], em_size, vertices); pgluTessVertex(tess, vertices, vertices); vertices += 3; } break; default: ERR("\t\tcurve type = %d\n", ppc->wType); pgluTessEndContour(tess); goto error_in_list; } ppc = (TTPOLYCURVE*)((char*)ppc + sizeof(*ppc) + (ppc->cpfx - 1) * sizeof(POINTFX)); } pgluTessEndContour(tess); pph = (TTPOLYGONHEADER*)((char*)pph + pph->cb); } error_in_list: pgluTessEndPolygon(tess); glTranslated((GLdouble)gm.gmCellIncX / em_size, (GLdouble)gm.gmCellIncY / em_size, 0.0); glEndList(); LEAVE_GL(); HeapFree(GetProcessHeap(), 0, buf); HeapFree(GetProcessHeap(), 0, vertices); } error: DeleteObject(SelectObject(hdc, old_font)); pgluDeleteTess(tess); return TRUE; }
HFONT _GetDcFont(HDC hdc) { return (HFONT)GetCurrentObject(hdc, OBJ_FONT); }