From 7e862a2dff0941678cc57b9fe796803874096ba0 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Sat, 24 Nov 2012 00:43:23 +0100 Subject: Apply Style: Preview styles directly in the Apply Style combo box. Change-Id: I5042b5bc61da65dc85cb406e5137e0395b699fbf --- svx/source/tbxctrls/tbcontrl.cxx | 106 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index 7639bfe82887..08a7edb68d8a 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -66,13 +67,15 @@ #include "helpid.hrc" #include "svx/htmlmode.hxx" #include -#include "editeng/fontitem.hxx" +#include #include #include #include #include -#include "editeng/flstitem.hxx" -#include "editeng/bolnitem.hxx" +#include +#include +#include +#include #include "svx/drawitem.hxx" #include #include "svx/dlgutil.hxx" @@ -140,6 +143,8 @@ public: virtual void DataChanged( const DataChangedEvent& rDCEvt ); virtual void StateChanged( StateChangedType nStateChange ); + virtual void UserDraw( const UserDrawEvent& rUDEvt ); + inline void SetVisibilityListener( const Link& aVisListener ) { aVisibilityListener = aVisListener; } inline void RemoveVisibilityListener() { aVisibilityListener = Link(); } @@ -339,6 +344,8 @@ SvxStyleBox_Impl::SvxStyleBox_Impl( { aLogicalSize = PixelToLogic( GetSizePixel(), MAP_APPFONT ); EnableAutocomplete( sal_True ); + EnableUserDraw( true ); + SetUserItemSize( Size( 0, 30 ) ); } SvxStyleBox_Impl::~SvxStyleBox_Impl() @@ -516,6 +523,99 @@ void SvxStyleBox_Impl::StateChanged( StateChangedType nStateChange ) } } +void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt ) +{ + sal_uInt16 nItem = rUDEvt.GetItemId(); + + if ( nItem == 0 || nItem == GetEntryCount() - 1 ) + { + // draw the non-style entries, ie. "Clear Formatting" or "More..." + DrawEntry( rUDEvt, true, true ); + } + else + { + SfxObjectShell *pShell = SfxObjectShell::Current(); + SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool(); + SfxStyleSheetBase* pStyle = NULL; + + OUString aStyleName( GetEntry( nItem ) ); + + if ( pPool ) + { + pPool->SetSearchMask( eStyleFamily, SFXSTYLEBIT_ALL ); + + pStyle = pPool->First(); + while ( pStyle && OUString( pStyle->GetName() ) != aStyleName ) + pStyle = pPool->Next(); + } + + if ( !pStyle ) + { + // cannot find the style for whatever reason + DrawEntry( rUDEvt, true, true ); + } + else + { + const SfxItemSet& aItemSet = pStyle->GetItemSet(); + + // all the font properties + //const SvxColorItem *pColorItem = static_cast< const SvxColorItem* >( aItemSet.GetItem( SID_ATTR_CHAR_COLOR ) ); + + const SvxFontItem *pFontItem = static_cast< const SvxFontItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONT ) ); + const SvxFontHeightItem *pFontHeightItem = static_cast< const SvxFontHeightItem* >( aItemSet.GetItem( SID_ATTR_CHAR_FONTHEIGHT ) ); + + if ( pFontItem && pFontHeightItem ) + { + OutputDevice *pDevice = rUDEvt.GetDevice(); + + Size aFontSize( pFontHeightItem->GetHeight(), pFontHeightItem->GetHeight() ); + Size aPixelSize( pDevice->LogicToPixel( aFontSize, pShell->GetMapUnit() ) ); + + // setup the font properties + Font aFont( pFontItem->GetFamilyName(), pFontItem->GetStyleName(), aPixelSize ); + + const SfxPoolItem *pItem = aItemSet.GetItem( SID_ATTR_CHAR_POSTURE ); + if ( pItem ) + aFont.SetItalic( static_cast< const SvxPostureItem* >( pItem )->GetPosture() ); + + pItem = aItemSet.GetItem( SID_ATTR_CHAR_WEIGHT ); + if ( pItem ) + aFont.SetWeight( static_cast< const SvxWeightItem* >( pItem )->GetWeight() ); + // TODO more properties + + // setup the device & draw + Font aOldFont( pDevice->GetFont() ); + //Color aOldColor( pDevice->GetTextColor() ); + + pDevice->SetFont( aFont ); + //pDevice->SetTextColor( pColorItem->GetValue() ); + + // IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as + // nBorder, and we are adding 1 in order to look better when + // italics is present + const int nLeftDistance = 8; + + Rectangle aTextRect; + pDevice->GetTextBoundRect( aTextRect, aStyleName ); + + Point aPos( rUDEvt.GetRect().TopLeft() ); + aPos.X() += nLeftDistance; + aPos.Y() += std::max( 0L, ( rUDEvt.GetRect().GetHeight() - aTextRect.Bottom() ) / 2 ); + + pDevice->DrawText( aPos, aStyleName ); + + //pDevice->SetTextColor( aOldColor ); + pDevice->SetFont( aOldFont ); + + // draw separator, if present + DrawEntry( rUDEvt, false, false ); + } + else + DrawEntry( rUDEvt, true, true ); + } + } +} + //-------------------------------------------------------------------- IMPL_STATIC_LINK( SvxStyleBox_Impl, FocusHdl_Impl, Control*, _pCtrl ) -- cgit v1.2.3