diff options
author | Jan Holesovsky <kendy@collabora.com> | 2014-01-04 12:59:04 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2014-01-04 13:02:27 +0100 |
commit | 0459682b4186b7522783e33cca3791420559817a (patch) | |
tree | 998ceed34d7cae96ef3868c840c61867686f2cc4 | |
parent | ae37972cd25117d467d34ee8591c21dcbb5a0fec (diff) |
hidpi: Blind fix - avoid double scaling by updating GetItemImage().
I guess some code uses GetItemImage(), and then SetItemImage() again. To make
it work, scale the image down in the hidpi mode.
Change-Id: I1ce9fdb28564b829253d7a9c7eabb46019e68876
-rw-r--r-- | vcl/source/window/toolbox2.cxx | 55 |
1 files changed, 39 insertions, 16 deletions
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 1f9021971c8b..0294e3deb6eb 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -622,9 +622,17 @@ void ToolBox::InsertItem( sal_uInt16 nItemId, const Image& rImage, DBG_ASSERT( GetItemPos( nItemId ) == TOOLBOX_ITEM_NOTFOUND, "ToolBox::InsertItem(): ItemId already exists" ); - // Item anlegen und in die Liste einfuegen - mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), ImplToolItem( nItemId, rImage, nBits ) ); - SetItemImage(nItemId, rImage); + Image aImage(rImage); + if (GetDPIScaleFactor() > 1) + { + BitmapEx aBitmap(aImage.GetBitmapEx()); + aBitmap.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BMP_SCALE_FAST); + aImage = Image(aBitmap); + } + + mpData->m_aItems.insert((nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), + ImplToolItem(nItemId, aImage, nBits)); + mpData->ImplClearLayoutData(); ImplInvalidate( sal_True ); @@ -644,9 +652,17 @@ void ToolBox::InsertItem( sal_uInt16 nItemId, const Image& rImage, DBG_ASSERT( GetItemPos( nItemId ) == TOOLBOX_ITEM_NOTFOUND, "ToolBox::InsertItem(): ItemId already exists" ); - // Item anlegen und in die Liste einfuegen - mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), ImplToolItem( nItemId, rImage, ImplConvertMenuString( rText ), nBits ) ); - SetItemImage(nItemId, rImage); + Image aImage(rImage); + if (GetDPIScaleFactor() > 1) + { + BitmapEx aBitmap(aImage.GetBitmapEx()); + aBitmap.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BMP_SCALE_FAST); + aImage = Image(aBitmap); + } + + mpData->m_aItems.insert((nPos < mpData->m_aItems.size()) ? mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(), + ImplToolItem(nItemId, aImage, ImplConvertMenuString(rText), nBits)); + mpData->ImplClearLayoutData(); ImplInvalidate( sal_True ); @@ -1353,17 +1369,11 @@ void ToolBox::SetItemImage( sal_uInt16 nItemId, const Image& rImage ) { Image aImage(rImage); - if ( GetDPIScaleFactor() > 1) + if (GetDPIScaleFactor() > 1) { BitmapEx aBitmap(aImage.GetBitmapEx()); - - // Some code calls this twice, so add a sanity check - // FIXME find out what that code is & fix accordingly - if (aBitmap.GetSizePixel().Width() < 32) - { - aBitmap.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BMP_SCALE_FAST); - aImage = Image(aBitmap); - } + aBitmap.Scale(GetDPIScaleFactor(), GetDPIScaleFactor(), BMP_SCALE_FAST); + aImage = Image(aBitmap); } ImplToolItem* pItem = &mpData->m_aItems[nPos]; @@ -1487,7 +1497,20 @@ Image ToolBox::GetItemImage( sal_uInt16 nItemId ) const ImplToolItem* pItem = ImplGetItem( nItemId ); if ( pItem ) - return pItem->maImage; + { + Image aImage(pItem->maImage); + + if (GetDPIScaleFactor() > 1) + { + // we have scaled everything we have inserted, so scale it back to + // the original size + BitmapEx aBitmap(aImage.GetBitmapEx()); + aBitmap.Scale(1.0/GetDPIScaleFactor(), 1.0/GetDPIScaleFactor(), BMP_SCALE_FAST); + aImage = Image(aBitmap); + } + + return aImage; + } else return Image(); } |