Kaydet (Commit) 0342b099 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

sidebar: Make the color toolbox updater rendering more universal.

Render the color preview bigger if we have space for that.

Change-Id: I5bbe5edbb8e354fc3009935d3ed6090271b72bf7
üst 4f036439
......@@ -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;
......
......@@ -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 ) );
......
......@@ -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;
......
......@@ -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
......
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment