diff options
-rw-r--r-- | include/svtools/valueset.hxx | 10 | ||||
-rw-r--r-- | sd/source/ui/animations/SlideTransitionPane.cxx | 17 | ||||
-rw-r--r-- | svtools/source/control/valueimp.hxx | 1 | ||||
-rw-r--r-- | svtools/source/control/valueset.cxx | 81 |
4 files changed, 88 insertions, 21 deletions
diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx index b51587b442a1..d63146cdd13c 100644 --- a/include/svtools/valueset.hxx +++ b/include/svtools/valueset.hxx @@ -307,12 +307,17 @@ public: void DoubleClick(); virtual void UserDraw( const UserDrawEvent& rUDEvt ); + /// Insert @rImage item. void InsertItem(sal_uInt16 nItemId, const Image& rImage, size_t nPos = VALUESET_APPEND); + /// Insert @rImage item with @rStr as either a legend or tooltip depending on @bShowLegend. void InsertItem(sal_uInt16 nItemId, const Image& rImage, - const OUString& rStr, size_t nPos = VALUESET_APPEND); + const OUString& rStr, size_t nPos = VALUESET_APPEND, bool bShowLegend = false); + /// Insert an @rColor item with @rStr tooltip. void InsertItem(sal_uInt16 nItemId, const Color& rColor, const OUString& rStr, size_t nPos = VALUESET_APPEND); + /// Insert an User Drawn item. void InsertItem(sal_uInt16 nItemId, size_t nPos = VALUESET_APPEND); + /// Insert an User Drawn item with @rStr tooltip. void InsertItem(sal_uInt16 nItemId, const OUString& rStr, size_t nPos = VALUESET_APPEND); void RemoveItem(sal_uInt16 nItemId); @@ -336,8 +341,9 @@ public: return mnUserVisLines; } void SetItemWidth( long nItemWidth = 0 ); - void SetItemHeight( long nLineHeight = 0 ); + Size GetLargestItemSize(); + void RecalculateItemSizes(); void SelectItem( sal_uInt16 nItemId ); sal_uInt16 GetSelectItemId() const diff --git a/sd/source/ui/animations/SlideTransitionPane.cxx b/sd/source/ui/animations/SlideTransitionPane.cxx index dc16de9c2a5b..e223d116d6c6 100644 --- a/sd/source/ui/animations/SlideTransitionPane.cxx +++ b/sd/source/ui/animations/SlideTransitionPane.cxx @@ -52,9 +52,6 @@ #include <algorithm> -#define TRANSITION_THUMB_WIDTH 64 -#define TRANSITION_THUMB_HEIGHT 40 - using namespace ::com::sun::star; using ::com::sun::star::uno::Reference; @@ -389,8 +386,6 @@ public: set_hexpand( true ); set_vexpand( true ); SetExtraSpacing( 2 ); - SetItemWidth( TRANSITION_THUMB_WIDTH ); - SetItemHeight( TRANSITION_THUMB_HEIGHT ); } virtual ~TransitionPane() { disposeOnce(); } @@ -444,8 +439,11 @@ SlideTransitionPane::SlideTransitionPane( mxView.set( mxModel->getCurrentController(), uno::UNO_QUERY ); // dummy list box of slide transitions for startup. - mpVS_TRANSITION_ICONS->InsertItem( 0, Image( BitmapEx( "sd/cmd/transition-none.png" ) ), - SD_RESSTR( STR_SLIDETRANSITION_NONE ) ); + mpVS_TRANSITION_ICONS->InsertItem( + 0, Image( BitmapEx( "sd/cmd/transition-none.png" ) ), + SD_RESSTR( STR_SLIDETRANSITION_NONE ), + VALUESET_APPEND, /* show legend */ true ); + mpVS_TRANSITION_ICONS->RecalculateItemSizes(); // set defaults mpCB_AUTO_PREVIEW->Check(); // automatic preview on @@ -1123,7 +1121,9 @@ IMPL_LINK_NOARG_TYPED(SlideTransitionPane, LateInitCallback, Timer *, void) if ( aIcon.IsEmpty() ) // need a fallback aIcon = BitmapEx( "sd/cmd/transition-none.png" ); - mpVS_TRANSITION_ICONS->InsertItem( nPresetOffset + 1, Image( aIcon ), sLabel ); + mpVS_TRANSITION_ICONS->InsertItem( + nPresetOffset + 1, Image( aIcon ), sLabel, + VALUESET_APPEND, /* show legend */ true ); m_aNumVariants[ pPreset->getSetId() ] = 1; } @@ -1134,6 +1134,7 @@ IMPL_LINK_NOARG_TYPED(SlideTransitionPane, LateInitCallback, Timer *, void) } nPresetOffset++; } + mpVS_TRANSITION_ICONS->RecalculateItemSizes(); SAL_INFO( "sd.transitions", "Item transition offsets in ValueSet:"); for( size_t i = 0; i < mpVS_TRANSITION_ICONS->GetItemCount(); ++i ) diff --git a/svtools/source/control/valueimp.hxx b/svtools/source/control/valueimp.hxx index eef2fcf41f8b..93c1ae4e9069 100644 --- a/svtools/source/control/valueimp.hxx +++ b/svtools/source/control/valueimp.hxx @@ -42,6 +42,7 @@ enum ValueSetItemType { VALUESETITEM_NONE, VALUESETITEM_IMAGE, + VALUESETITEM_IMAGE_AND_TEXT, VALUESETITEM_COLOR, VALUESETITEM_USERDRAW }; diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx index 5696b8ac4a41..b62d6ce68ada 100644 --- a/svtools/source/control/valueset.cxx +++ b/svtools/source/control/valueset.cxx @@ -308,7 +308,9 @@ void ValueSet::ImplFormatItem(vcl::RenderContext& rRenderContext, ValueSetItem* Size aRectSize = aRect.GetSize(); Point aPos(aRect.Left(), aRect.Top()); aPos.X() += (aRectSize.Width() - aImageSize.Width()) / 2; - aPos.Y() += (aRectSize.Height() - aImageSize.Height()) / 2; + + if (pItem->meType != VALUESETITEM_IMAGE_AND_TEXT) + aPos.Y() += (aRectSize.Height() - aImageSize.Height()) / 2; DrawImageFlags nImageStyle = DrawImageFlags::NONE; if (!IsEnabled()) @@ -323,6 +325,26 @@ void ValueSet::ImplFormatItem(vcl::RenderContext& rRenderContext, ValueSetItem* } else maVirDev->DrawImage(aPos, pItem->maImage, nImageStyle); + + if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT) + { + maVirDev->SetFont(rRenderContext.GetFont()); + maVirDev->SetTextColor((nStyle & WB_MENUSTYLEVALUESET) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor()); + maVirDev->SetTextFillColor(); + + long nTxtWidth = maVirDev->GetTextWidth(pItem->maText); + + if (nTxtWidth > aRect.GetWidth()) + maVirDev->SetClipRegion(vcl::Region(aRect)); + + maVirDev->DrawText(Point(aRect.Left() + + (aRect.GetWidth() - nTxtWidth) / 2, + aRect.Bottom() - maVirDev->GetTextHeight()), + pItem->maText); + + if (nTxtWidth > aRect.GetWidth()) + maVirDev->SetClipRegion(); + } } } @@ -1584,11 +1606,12 @@ void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, size_t nPos } void ValueSet::InsertItem( sal_uInt16 nItemId, const Image& rImage, - const OUString& rText, size_t nPos ) + const OUString& rText, size_t nPos, + bool bShowLegend ) { ValueSetItem* pItem = new ValueSetItem( *this ); pItem->mnId = nItemId; - pItem->meType = VALUESETITEM_IMAGE; + pItem->meType = bShowLegend ? VALUESETITEM_IMAGE_AND_TEXT : VALUESETITEM_IMAGE; pItem->maImage = rImage; pItem->maText = rText; ImplInsertItem( pItem, nPos ); @@ -1805,6 +1828,27 @@ void ValueSet::SetItemHeight( long nNewItemHeight ) } } +/** + * An inelegant method; sets the item width & height such that + * all of the included items and their labels fit; if we can + * calculate that. + */ +void ValueSet::RecalculateItemSizes() +{ + Size aLargestItem = GetLargestItemSize(); + + if ( mnUserItemWidth != aLargestItem.Width() || + mnUserItemHeight != aLargestItem.Height() ) + { + mnUserItemWidth = aLargestItem.Width(); + mnUserItemHeight = aLargestItem.Height(); + mbFormat = true; + queue_resize(); + if ( IsReallyVisible() && IsUpdateMode() ) + Invalidate(); + } +} + void ValueSet::SelectItem( sal_uInt16 nItemId ) { size_t nItemPos = 0; @@ -2286,9 +2330,9 @@ void ValueSet::SetHighlightHdl( const Link<ValueSet*,void>& rLink ) maHighlightHdl = rLink; } -Size ValueSet::GetOptimalSize() const +Size ValueSet::GetLargestItemSize() { - Size aLargestItemSize; + Size aLargestItem; for (size_t i = 0, n = mItemList.size(); i < n; ++i) { @@ -2296,18 +2340,33 @@ Size ValueSet::GetOptimalSize() const if (!pItem->mbVisible) continue; - if (pItem->meType != VALUESETITEM_IMAGE) + if (pItem->meType != VALUESETITEM_IMAGE && + pItem->meType != VALUESETITEM_IMAGE_AND_TEXT) { - //handle determining an optimal size for this case + // handle determining an optimal size for this case continue; } - Size aImageSize = pItem->maImage.GetSizePixel(); - aLargestItemSize.Width() = std::max(aLargestItemSize.Width(), aImageSize.Width()); - aLargestItemSize.Height() = std::max(aLargestItemSize.Height(), aImageSize.Height()); + Size aSize = pItem->maImage.GetSizePixel(); + if (pItem->meType == VALUESETITEM_IMAGE_AND_TEXT) + { + aSize.Height() += 3 * NAME_LINE_HEIGHT + + maVirDev->GetTextHeight(); + aSize.Width() = std::max(aSize.Width(), + maVirDev->GetTextWidth(pItem->maText) + NAME_OFFSET); + } + + aLargestItem.Width() = std::max(aLargestItem.Width(), aSize.Width()); + aLargestItem.Height() = std::max(aLargestItem.Height(), aSize.Height()); } - return CalcWindowSizePixel(aLargestItemSize); + return aLargestItem; +} + +Size ValueSet::GetOptimalSize() const +{ + return CalcWindowSizePixel( + const_cast<ValueSet *>(this)->GetLargestItemSize()); } void ValueSet::SetEdgeBlending(bool bNew) |