summaryrefslogtreecommitdiff
path: root/vcl/win/gdi
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2021-09-15 17:32:49 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2021-09-25 17:44:33 +0200
commit398ae49ba337a2d2c32611f371132c978cf4db64 (patch)
treeb9f1a73f53049ba9c10e0e68c1482f27929b9f86 /vcl/win/gdi
parent3d897530d4cd24e2739c81a39984015b192d110e (diff)
WIN handle graphics palette with deinit
Manually setting the default palette of the graphics DC seems to be a bad idea. And I think this fixes a real bug in ImplHandlePalette, because that would set the graphics DC palette but didn't set the default palette using setDefPal. Change-Id: Ic3b176645c68fa33a020791d5b64b04c3cbaacee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122158 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/win/gdi')
-rw-r--r--vcl/win/gdi/salgdi.cxx25
-rw-r--r--vcl/win/gdi/salvd.cxx4
2 files changed, 24 insertions, 5 deletions
diff --git a/vcl/win/gdi/salgdi.cxx b/vcl/win/gdi/salgdi.cxx
index 43536de1fb01..6bd510b6effa 100644
--- a/vcl/win/gdi/salgdi.cxx
+++ b/vcl/win/gdi/salgdi.cxx
@@ -495,6 +495,7 @@ void WinSalGraphics::DeInitGraphics()
SelectFont( getHDC(), mhDefFont );
mhDefFont = nullptr;
}
+ setPalette(nullptr);
mpImpl->DeInit();
}
@@ -700,12 +701,32 @@ void WinSalGraphics::setHWND(HWND hWnd)
HPALETTE WinSalGraphics::getDefPal() const
{
+ assert(getHDC() || !mhDefPal);
return mhDefPal;
}
-void WinSalGraphics::setDefPal(HPALETTE hDefPal)
+void WinSalGraphics::setPalette(HPALETTE hNewPal, BOOL bForceBkgd)
{
- mhDefPal = hDefPal;
+ if (!getHDC())
+ {
+ assert(!mhDefPal);
+ return;
+ }
+
+ if (hNewPal)
+ {
+ HPALETTE hOldPal = SelectPalette(getHDC(), hNewPal, bForceBkgd);
+ if (!mhDefPal)
+ mhDefPal = hOldPal;
+ }
+ else
+ {
+ if (mhDefPal)
+ {
+ SelectPalette(getHDC(), mhDefPal, bForceBkgd);
+ mhDefPal = nullptr;
+ }
+ }
}
HRGN WinSalGraphics::getRegion() const
diff --git a/vcl/win/gdi/salvd.cxx b/vcl/win/gdi/salvd.cxx
index 679a32a576cd..7b3e7e11fc5c 100644
--- a/vcl/win/gdi/salvd.cxx
+++ b/vcl/win/gdi/salvd.cxx
@@ -129,7 +129,7 @@ std::unique_ptr<SalVirtualDevice> WinSalInstance::CreateVirtualDevice( SalGraphi
if ( pSalData->mhDitherPal && pVirGraphics->isScreen() )
{
- pVirGraphics->setDefPal(SelectPalette( hDC, pSalData->mhDitherPal, TRUE ));
+ pVirGraphics->setPalette(pSalData->mhDitherPal);
RealizePalette( hDC );
}
@@ -172,8 +172,6 @@ WinSalVirtualDevice::~WinSalVirtualDevice()
// restore the mpGraphics' original HDC values, so the HDC can be deleted in the !mbForeignDC case
mpGraphics->setHDC(nullptr);
- if( mpGraphics->getDefPal() )
- SelectPalette(hDC, mpGraphics->getDefPal(), TRUE);
if( mhDefBmp )
SelectBitmap(hDC, mhDefBmp);
if( !mbForeignDC )