diff options
-rw-r--r-- | include/vcl/toolbox.hxx | 3 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbxcolorupdate.cxx | 22 | ||||
-rw-r--r-- | vcl/inc/toolbox.h | 4 | ||||
-rw-r--r-- | vcl/source/window/toolbox.cxx | 21 | ||||
-rw-r--r-- | vcl/source/window/toolbox2.cxx | 14 |
5 files changed, 57 insertions, 7 deletions
diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx index 9c619ea35afd..e3e2ff866350 100644 --- a/include/vcl/toolbox.hxx +++ b/include/vcl/toolbox.hxx @@ -400,6 +400,9 @@ public: Rectangle GetItemRect( sal_uInt16 nItemId ) const; Rectangle GetItemPosRect( sal_uInt16 nPos ) const; + /// Returns size of the bitmap / text that is inside this toolbox item. + Size GetItemContentSize( sal_uInt16 nItemId ) const; + /// Retrieves the optimal position to place a popup window for this item (subtoolbar or dropdown) Point GetItemPopupPosition( sal_uInt16 nItemId, const Size& rSize ) const; diff --git a/svx/source/tbxctrls/tbxcolorupdate.cxx b/svx/source/tbxctrls/tbxcolorupdate.cxx index 5a9273233b99..85f580fe38ff 100644 --- a/svx/source/tbxctrls/tbxcolorupdate.cxx +++ b/svx/source/tbxctrls/tbxcolorupdate.cxx @@ -86,7 +86,9 @@ namespace svx void ToolboxButtonColorUpdater::Update( const Color& rColor ) { Image aImage( mpTbx->GetItemImage( mnBtnId ) ); - const bool bSizeChanged = ( maBmpSize != aImage.GetSizePixel() ); + Size aItemSize( mpTbx->GetItemContentSize( mnBtnId ) ); + + const bool bSizeChanged = ( maBmpSize != aItemSize ); const bool bDisplayModeChanged = ( mbWasHiContrastMode != mpTbx->GetSettings().GetStyleSettings().GetHighContrastMode() ); Color aColor( rColor ); @@ -96,7 +98,15 @@ namespace svx if( ( maCurColor != aColor ) || bSizeChanged || bDisplayModeChanged ) { - BitmapEx aBmpEx( aImage.GetBitmapEx() ); + // create an empty bitmap, and copy the original bitmap inside + // (so that it grows in case the original bitmap was smaller) + sal_uInt8 nAlpha = 255; + BitmapEx aBmpEx( Bitmap( aItemSize, 24 ), AlphaMask( aItemSize, &nAlpha ) ); + BitmapEx aSource( aImage.GetBitmapEx() ); + Rectangle aRect( Point( 0, 0 ), + Size( std::min( aItemSize.Width(), aSource.GetSizePixel().Width() ), std::min( aItemSize.Height(), aSource.GetSizePixel().Height() ) ) ); + aBmpEx.CopyPixel( aRect, aRect, &aSource ); + Bitmap aBmp( aBmpEx.GetBitmap() ); BitmapWriteAccess* pBmpAcc = aBmp.IsEmpty() ? NULL : aBmp.AcquireWriteAccess(); @@ -136,12 +146,12 @@ namespace svx maUpdRect.Right() = 73; maUpdRect.Bottom() = 9; } - else if(30 == maBmpSize.Width() && 16 == maBmpSize.Height()) + else if(maBmpSize.Width() >= (2 * maBmpSize.Height() - 2) && maBmpSize.Height() >= 16) { - maUpdRect.Left() = 17; + maUpdRect.Left() = maBmpSize.Height() + 2; maUpdRect.Top() = 2; - maUpdRect.Right() = 27; - maUpdRect.Bottom() = 13; + maUpdRect.Right() = maBmpSize.Width() - 3; + maUpdRect.Bottom() = maBmpSize.Height() - 3; } else maUpdRect = Rectangle( Point( 1, maBmpSize.Height() - 7 ), Size( maBmpSize.Width() - 2 ,6 ) ); diff --git a/vcl/inc/toolbox.h b/vcl/inc/toolbox.h index 8670aeeb101b..db9370912e2a 100644 --- a/vcl/inc/toolbox.h +++ b/vcl/inc/toolbox.h @@ -63,12 +63,14 @@ struct ImplToolItem OString maHelpId; Rectangle maRect; Rectangle maCalcRect; - /// Widget layout may request size; set it as the minimal size. + /// Widget layout may request size; set it as the minimal size (like, the item will always have at least this size). Size maMinimalItemSize; /// The overall horizontal item size, including one or more of [image size + textlength + dropdown arrow] Size maItemSize; long mnSepSize; long mnDropDownArrowWidth; + /// Size of the content (bitmap or text, without dropdown) that we have in the item. + Size maContentSize; ToolBoxItemType meType; ToolBoxItemBits mnBits; TriState meState; diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index 6f8b72a8075c..1a9d585ccf8c 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -1899,6 +1899,9 @@ sal_Bool ToolBox::ImplCalcItem() it->mbEmptyBtn = sal_True; } + // save the content size + it->maContentSize = it->maItemSize; + // if required, take window height into consideration if ( it->mpWindow ) { @@ -1921,11 +1924,16 @@ sal_Bool ToolBox::ImplCalcItem() long tmp = it->maItemSize.Width(); it->maItemSize.Width() = it->maItemSize.Height(); it->maItemSize.Height() = tmp; + + tmp = it->maContentSize.Width(); + it->maContentSize.Width() = it->maContentSize.Height(); + it->maContentSize.Height() = tmp; } } else if ( it->meType == TOOLBOXITEM_SPACE ) { it->maItemSize = Size( nDefWidth, nDefHeight ); + it->maContentSize = it->maItemSize; } if ( it->meType == TOOLBOXITEM_BUTTON || it->meType == TOOLBOXITEM_SPACE ) @@ -1938,10 +1946,23 @@ sal_Bool ToolBox::ImplCalcItem() long nMinW = std::max(nMinWidth, it->maMinimalItemSize.Width()); long nMinH = std::max(nMinHeight, it->maMinimalItemSize.Height()); + long nGrowContentWidth = 0; + long nGrowContentHeight = 0; + if( it->maItemSize.Width() < nMinW ) + { + nGrowContentWidth = nMinW - it->maItemSize.Width(); it->maItemSize.Width() = nMinW; + } if( it->maItemSize.Height() < nMinH ) + { + nGrowContentHeight = nMinH - it->maItemSize.Height(); it->maItemSize.Height() = nMinH; + } + + // grow the content size by the additional available space + it->maContentSize.Width() += nGrowContentWidth; + it->maContentSize.Height() += nGrowContentHeight; } // keep track of max item size diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx index 69ee1252db7f..412fe331897a 100644 --- a/vcl/source/window/toolbox2.cxx +++ b/vcl/source/window/toolbox2.cxx @@ -170,6 +170,7 @@ ImplToolItem::ImplToolItem( const ImplToolItem& rItem ) : maItemSize ( rItem.maItemSize ), mnSepSize ( rItem.mnSepSize ), mnDropDownArrowWidth ( rItem.mnDropDownArrowWidth ), + maContentSize ( rItem.maContentSize ), meType ( rItem.meType ), mnBits ( rItem.mnBits ), meState ( rItem.meState ), @@ -208,6 +209,7 @@ ImplToolItem& ImplToolItem::operator=( const ImplToolItem& rItem ) maCalcRect = rItem.maCalcRect; mnSepSize = rItem.mnSepSize; mnDropDownArrowWidth = rItem.mnDropDownArrowWidth; + maContentSize = rItem.maContentSize; maMinimalItemSize = rItem.maMinimalItemSize; maItemSize = rItem.maItemSize; mbVisibleText = rItem.mbVisibleText; @@ -1239,6 +1241,18 @@ Rectangle ToolBox::GetItemPosRect( sal_uInt16 nPos ) const return Rectangle(); } +Size ToolBox::GetItemContentSize( sal_uInt16 nItemId ) const +{ + if ( mbCalc || mbFormat ) + ((ToolBox*)this)->ImplFormat(); + + sal_uInt16 nPos = GetItemPos( nItemId ); + if ( nPos < mpData->m_aItems.size() ) + return mpData->m_aItems[nPos].maContentSize; + else + return Size(); +} + // ----------------------------------------------------------------------- sal_Bool ToolBox::ImplHasExternalMenubutton() |