X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1e2081a1b9962f3d58afce7b45845ba7956d3c20..99bdcd556e57cf263fbfcc0f65cdd8ebd5f1c211:/src/msw/dc.cpp?ds=sidebyside diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index f4aeebe02b..e533015783 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -137,7 +137,8 @@ private: wxColourChanger::wxColourChanger(wxDC& dc) : m_dc(dc) { - if ( dc.GetBrush().GetStyle() == wxSTIPPLE_MASK_OPAQUE ) + const wxBrush& brush = dc.GetBrush(); + if ( brush.Ok() && brush.GetStyle() == wxSTIPPLE_MASK_OPAQUE ) { HDC hdc = GetHdcOf(dc); m_colFgOld = ::GetTextColor(hdc); @@ -467,16 +468,17 @@ void wxDC::Clear() ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } -void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) +bool wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) { #ifdef __WXMICROWIN__ - if (!GetHDC()) return; + if (!GetHDC()) return FALSE; #endif - if ( !::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), + bool success = (0 != ::ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), col.GetPixel(), style == wxFLOOD_SURFACE ? FLOODFILLSURFACE - : FLOODFILLBORDER) ) + : FLOODFILLBORDER) ) ; + if (!success) { // quoting from the MSDN docs: // @@ -494,6 +496,8 @@ void wxDC::DoFloodFill(wxCoord x, wxCoord y, const wxColour& col, int style) } CalcBoundingBox(x, y); + + return success; } bool wxDC::DoGetPixel(wxCoord x, wxCoord y, wxColour *col) const @@ -939,7 +943,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxPalette *pal = bmp.GetPalette(); if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) { - oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(pal), FALSE); + oldPal = ::SelectPalette(hdcMem, GetHpaletteOf(*pal), FALSE); ::RealizePalette(hdcMem); } #endif // wxUSE_PALETTE @@ -994,7 +998,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask wxPalette *pal = bmp.GetPalette(); if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 ) { - oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE); + oldPal = ::SelectPalette(memdc, GetHpaletteOf(*pal), FALSE); ::RealizePalette(memdc); } #endif // wxUSE_PALETTE @@ -1125,13 +1129,13 @@ void wxDC::DoDrawRotatedText(const wxString& text, // "upper left" and "upper right" CalcBoundingBox(x, y); - CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); + CalcBoundingBox(x + wxCoord(w*cos(rad)), y - wxCoord(h*sin(rad))); // "bottom left" and "bottom right" x += (wxCoord)(h*sin(rad)); y += (wxCoord)(h*cos(rad)); CalcBoundingBox(x, y); - CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); + CalcBoundingBox(x + wxCoord(h*sin(rad)), y + wxCoord(h*cos(rad))); } #endif } @@ -1142,7 +1146,7 @@ void wxDC::DoDrawRotatedText(const wxString& text, #if wxUSE_PALETTE -void wxDC::SetPalette(const wxPalette& palette) +void wxDC::DoSelectPalette(bool realize) { #ifdef __WXMICROWIN__ if (!GetHDC()) return; @@ -1156,28 +1160,44 @@ void wxDC::SetPalette(const wxPalette& palette) m_oldPalette = 0; } - m_palette = palette; - - if (!m_palette.Ok()) + if ( m_palette.Ok() ) { - // Setting a NULL colourmap is a way of restoring - // the original colourmap - if (m_oldPalette) - { - ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, FALSE); - m_oldPalette = 0; - } + HPALETTE oldPal = ::SelectPalette(GetHdc(), + GetHpaletteOf(m_palette), + FALSE); + if (!m_oldPalette) + m_oldPalette = (WXHPALETTE) oldPal; - return; + if (realize) + ::RealizePalette(GetHdc()); } +} - if (m_palette.Ok() && m_palette.GetHPALETTE()) +void wxDC::SetPalette(const wxPalette& palette) +{ + if ( palette.Ok() ) { - HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), FALSE); - if (!m_oldPalette) - m_oldPalette = (WXHPALETTE) oldPal; + m_palette = palette; + DoSelectPalette(TRUE); + } +} - ::RealizePalette(GetHdc()); +void wxDC::InitializePalette() +{ + if ( wxDisplayDepth() <= 8 ) + { + // look for any window or parent that has a custom palette. If any has + // one then we need to use it in drawing operations + wxWindow *win = m_canvas->GetAncestorWithCustomPalette(); + + m_hasCustomPalette = win && win->HasCustomPalette(); + if ( m_hasCustomPalette ) + { + m_palette = win->GetPalette(); + + // turn on MSW translation for this palette + DoSelectPalette(); + } } } @@ -1906,8 +1926,30 @@ void wxDC::DoGetSizeMM(int *w, int *h) const if (!GetHDC()) return; #endif - if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); - if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); + // if we implement it in terms of DoGetSize() instead of directly using the + // results returned by GetDeviceCaps(HORZ/VERTSIZE) as was done before, it + // will also work for wxWindowDC and wxClientDC even though their size is + // not the same as the total size of the screen + int wPixels, hPixels; + DoGetSize(&wPixels, &hPixels); + + if ( w ) + { + int wTotal = ::GetDeviceCaps(GetHdc(), HORZRES); + + wxCHECK_RET( wTotal, _T("0 width device?") ); + + *w = (wPixels * ::GetDeviceCaps(GetHdc(), HORZSIZE)) / wTotal; + } + + if ( h ) + { + int hTotal = ::GetDeviceCaps(GetHdc(), VERTRES); + + wxCHECK_RET( hTotal, _T("0 height device?") ); + + *h = (hPixels * ::GetDeviceCaps(GetHdc(), VERTSIZE)) / hTotal; + } } wxSize wxDC::GetPPI() const