summaryrefslogtreecommitdiff
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
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>
-rw-r--r--vcl/inc/win/salgdi.h2
-rw-r--r--vcl/win/gdi/salgdi.cxx25
-rw-r--r--vcl/win/gdi/salvd.cxx4
-rw-r--r--vcl/win/window/salframe.cxx47
4 files changed, 44 insertions, 34 deletions
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index f43224a861a4..0f5b700cff26 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -177,7 +177,7 @@ public:
void setHDC(HDC aNew);
HPALETTE getDefPal() const;
- void setDefPal(HPALETTE hDefPal);
+ void setPalette(HPALETTE, BOOL bForceBkgd = TRUE);
HRGN getRegion() const;
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 )
diff --git a/vcl/win/window/salframe.cxx b/vcl/win/window/salframe.cxx
index d38b0296f3e3..e995cae356d4 100644
--- a/vcl/win/window/salframe.cxx
+++ b/vcl/win/window/salframe.cxx
@@ -913,8 +913,6 @@ bool WinSalFrame::ReleaseFrameGraphicsDC( WinSalGraphics* pGraphics )
HDC hDC = pGraphics->getHDC();
if ( !hDC )
return false;
- if ( pGraphics->getDefPal() )
- SelectPalette( hDC, pGraphics->getDefPal(), TRUE );
pGraphics->setHDC(nullptr);
SendMessageW( pSalData->mpInstance->mhComWnd, SAL_MSG_RELEASEDC,
reinterpret_cast<WPARAM>(mhWnd), reinterpret_cast<LPARAM>(hDC) );
@@ -995,7 +993,7 @@ bool WinSalFrame::InitFrameGraphicsDC( WinSalGraphics *pGraphics, HDC hDC, HWND
if ( pSalData->mhDitherPal )
{
- pGraphics->setDefPal(SelectPalette( hDC, pSalData->mhDitherPal, TRUE ));
+ pGraphics->setPalette(pSalData->mhDitherPal);
RealizePalette( hDC );
}
@@ -4155,7 +4153,7 @@ static void ImplHandleForcePalette( HWND hWnd )
WinSalGraphics* pGraphics = pFrame->mpLocalGraphics;
if (pGraphics->getDefPal())
{
- SelectPalette( pGraphics->getHDC(), hPal, FALSE );
+ pGraphics->setPalette(hPal, FALSE);
if ( RealizePalette( pGraphics->getHDC() ) )
{
InvalidateRect( hWnd, nullptr, FALSE );
@@ -4210,9 +4208,8 @@ static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
WinSalFrame* pTempFrame;
WinSalGraphics* pGraphics;
HDC hDC;
- HPALETTE hOldPal;
+ HPALETTE hOldPal = nullptr;
UINT nCols;
- bool bStdDC;
bool bUpdate;
pSalData->mbInPalChange = true;
@@ -4222,24 +4219,14 @@ static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
while ( pTempVD )
{
pGraphics = pTempVD->getGraphics();
- if ( pGraphics->getDefPal() )
- {
- SelectPalette( pGraphics->getHDC(),
- pGraphics->getDefPal(),
- TRUE );
- }
+ pGraphics->setPalette(nullptr);
pTempVD = pTempVD->getNext();
}
pTempFrame = pSalData->mpFirstFrame;
while ( pTempFrame )
{
pGraphics = pTempFrame->mpLocalGraphics;
- if ( pGraphics && pGraphics->getHDC() && pGraphics->getDefPal() )
- {
- SelectPalette( pGraphics->getHDC(),
- pGraphics->getDefPal(),
- TRUE );
- }
+ pGraphics->setPalette(nullptr);
pTempFrame = pTempFrame->mpNextFrame;
}
@@ -4247,23 +4234,27 @@ static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
WinSalFrame* pFrame = nullptr;
if ( bFrame )
pFrame = GetWindowPtr( hWnd );
- if ( pFrame && pFrame->mpLocalGraphics && pFrame->mpLocalGraphics->getHDC() )
+
+ UnrealizeObject(hPal);
+ const bool bStdDC = pFrame && pFrame->mpLocalGraphics && pFrame->mpLocalGraphics->getHDC();
+ if (!bStdDC)
{
- hDC = pFrame->mpLocalGraphics->getHDC();
- bStdDC = true;
+ hDC = GetDC(hWnd);
+ hOldPal = SelectPalette(hDC, hPal, TRUE);
}
else
{
- hDC = GetDC( hWnd );
- bStdDC = false;
+ hDC = pFrame->mpLocalGraphics->getHDC();
+ pFrame->mpLocalGraphics->setPalette(hPal);
}
- UnrealizeObject( hPal );
- hOldPal = SelectPalette( hDC, hPal, TRUE );
+
nCols = RealizePalette( hDC );
bUpdate = nCols != 0;
+
if ( !bStdDC )
{
- SelectPalette( hDC, hOldPal, TRUE );
+ if (hOldPal)
+ SelectPalette(hDC, hOldPal, TRUE);
ReleaseDC( hWnd, hDC );
}
@@ -4274,7 +4265,7 @@ static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
pGraphics = pTempVD->getGraphics();
if ( pGraphics->getDefPal() )
{
- SelectPalette( pGraphics->getHDC(), hPal, TRUE );
+ pGraphics->setPalette(hPal);
RealizePalette( pGraphics->getHDC() );
}
pTempVD = pTempVD->getNext();
@@ -4287,7 +4278,7 @@ static LRESULT ImplHandlePalette( bool bFrame, HWND hWnd, UINT nMsg,
pGraphics = pTempFrame->mpLocalGraphics;
if ( pGraphics && pGraphics->getHDC() && pGraphics->getDefPal() )
{
- SelectPalette( pGraphics->getHDC(), hPal, TRUE );
+ pGraphics->setPalette(hPal);
if ( RealizePalette( pGraphics->getHDC() ) )
bUpdate = true;
}