diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2020-08-31 13:05:31 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2020-09-18 13:30:17 +0200 |
commit | 10aac52bafc8a0430d1da3fe8f45832c64d6bf34 (patch) | |
tree | b492fc98563f66686d405db5cee1d8f390da96bf /svx | |
parent | e046042865cd269b901fdf95c861f66b31fb4b0a (diff) |
Styles preview widget language independent
Use both english / universal and translated names
to identify a style.
Change-Id: Ibd8b23e678e8bea5773d1da97adf5201377b4453
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101832
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Tested-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102963
Tested-by: Jenkins
Diffstat (limited to 'svx')
-rw-r--r-- | svx/source/inc/StylesPreviewToolBoxControl.hxx | 2 | ||||
-rw-r--r-- | svx/source/inc/StylesPreviewWindow.hxx | 18 | ||||
-rw-r--r-- | svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx | 10 | ||||
-rw-r--r-- | svx/source/tbxctrls/StylesPreviewWindow.cxx | 39 |
4 files changed, 41 insertions, 28 deletions
diff --git a/svx/source/inc/StylesPreviewToolBoxControl.hxx b/svx/source/inc/StylesPreviewToolBoxControl.hxx index 7e2bd85da67e..c7ac3f9953b6 100644 --- a/svx/source/inc/StylesPreviewToolBoxControl.hxx +++ b/svx/source/inc/StylesPreviewToolBoxControl.hxx @@ -35,7 +35,7 @@ class StylesPreviewToolBoxControl final css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider; - std::vector<OUString> m_aDefaultStyles; + std::vector<std::pair<OUString, OUString>> m_aDefaultStyles; public: StylesPreviewToolBoxControl(); diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx index 5ae857210c6f..26ba93d7be79 100644 --- a/svx/source/inc/StylesPreviewWindow.hxx +++ b/svx/source/inc/StylesPreviewWindow.hxx @@ -44,19 +44,19 @@ class StyleItemController : public weld::CustomWidgetController static constexpr unsigned LEFT_MARGIN = 8; SfxStyleFamily m_eStyleFamily; - OUString m_aStyleName; + std::pair<OUString, OUString> m_aStyleName; bool m_bSelected; css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider; public: - StyleItemController(const OUString& aStyleName, + StyleItemController(const std::pair<OUString, OUString>& aStyleName, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; bool MouseButtonDown(const MouseEvent&) override; - void SetStyle(const OUString& sStyleName); + void SetStyle(const std::pair<OUString, OUString>& sStyleName); void Select(bool bSelect); @@ -83,8 +83,8 @@ protected: std::unique_ptr<weld::Toolbar> m_xUp; std::unique_ptr<weld::Toolbar> m_xDown; - std::vector<OUString> m_aDefaultStyles; - std::vector<OUString> m_aAllStyles; + std::vector<std::pair<OUString, OUString>> m_aDefaultStyles; + std::vector<std::pair<OUString, OUString>> m_aAllStyles; unsigned m_nStyleIterator; OUString m_sSelectedStyle; @@ -93,7 +93,8 @@ protected: DECL_LINK(GoDown, const OString&, void); public: - StylesPreviewWindow_Base(weld::Builder& xBuilder, std::vector<OUString>& aDefaultStyles, + StylesPreviewWindow_Base(weld::Builder& xBuilder, + std::vector<std::pair<OUString, OUString>>& aDefaultStyles, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); ~StylesPreviewWindow_Base(); @@ -103,13 +104,14 @@ private: void Update(); void UpdateStylesList(); void MakeCurrentStyleVisible(); - OUString GetVisibleStyle(unsigned nPosition); + std::pair<OUString, OUString> GetVisibleStyle(unsigned nPosition); }; class StylesPreviewWindow_Impl : public InterimItemWindow, public StylesPreviewWindow_Base { public: - StylesPreviewWindow_Impl(vcl::Window* pParent, std::vector<OUString>& aDefaultStyles, + StylesPreviewWindow_Impl(vcl::Window* pParent, + std::vector<std::pair<OUString, OUString>>& aDefaultStyles, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); ~StylesPreviewWindow_Impl(); diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx index 7e4a0167b908..9b78a0e7aaf0 100644 --- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx +++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx @@ -79,7 +79,10 @@ void StylesPreviewToolBoxControl::InitializeStyles( OUString sName; xStyle->getPropertyValue("DisplayName") >>= sName; if (!sName.isEmpty()) - m_aDefaultStyles.push_back(sName); + m_aDefaultStyles.push_back(std::pair<OUString, OUString>(aStyle, sName)); + } + catch (const css::container::NoSuchElementException&) + { } catch (const css::uno::Exception&) { @@ -103,7 +106,10 @@ void StylesPreviewToolBoxControl::InitializeStyles( OUString sName; xStyle->getPropertyValue("DisplayName") >>= sName; if (!sName.isEmpty()) - m_aDefaultStyles.push_back(sName); + { + m_aDefaultStyles.push_back( + std::pair<OUString, OUString>(sStyleName, sName)); + } } } catch (const css::uno::Exception&) diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx index 992c601601a4..6bd4f54ecba8 100644 --- a/svx/source/tbxctrls/StylesPreviewWindow.cxx +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -71,7 +71,7 @@ void StyleStatusListener::StateChanged(SfxItemState /*eState*/, const SfxPoolIte } StyleItemController::StyleItemController( - const OUString& aStyleName, + const std::pair<OUString, OUString>& aStyleName, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) : m_eStyleFamily(SfxStyleFamily::Para) , m_aStyleName(aStyleName) @@ -90,7 +90,7 @@ void StyleItemController::Paint(vcl::RenderContext& rRenderContext, rRenderContext.Pop(); } -void StyleItemController::SetStyle(const OUString& sStyleName) +void StyleItemController::SetStyle(const std::pair<OUString, OUString>& sStyleName) { m_aStyleName = sStyleName; Invalidate(); @@ -105,7 +105,7 @@ void StyleItemController::Select(bool bSelect) bool StyleItemController::MouseButtonDown(const MouseEvent&) { css::uno::Sequence<css::beans::PropertyValue> aArgs(2); - aArgs[0].Value <<= m_aStyleName; + aArgs[0].Value <<= m_aStyleName.second; aArgs[1].Name = "Family"; aArgs[1].Value <<= sal_Int16(m_eStyleFamily); @@ -217,7 +217,8 @@ void StyleItemController::DrawEntry(vcl::RenderContext& rRenderContext) return; pStyle = pPool->First(m_eStyleFamily); - while (pStyle && pStyle->GetName() != m_aStyleName) + while (pStyle && pStyle->GetName() != m_aStyleName.first + && pStyle->GetName() != m_aStyleName.second) pStyle = pPool->Next(); if (!pStyle) @@ -319,7 +320,7 @@ void StyleItemController::DrawSelection(vcl::RenderContext& rRenderContext) void StyleItemController::DrawHighlight(vcl::RenderContext& rRenderContext, Color aFontBack) { tools::Rectangle aTextRect; - rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName); + rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.second); Size aSize = aTextRect.GetSize(); aSize.AdjustHeight(aSize.getHeight()); @@ -339,17 +340,17 @@ void StyleItemController::DrawHighlight(vcl::RenderContext& rRenderContext, Colo void StyleItemController::DrawText(vcl::RenderContext& rRenderContext) { tools::Rectangle aTextRect; - rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName); + rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName.second); Point aPos(0, 0); aPos.AdjustX(LEFT_MARGIN); aPos.AdjustY((rRenderContext.GetOutputHeightPixel() - aTextRect.Bottom()) / 2); - rRenderContext.DrawText(aPos, m_aStyleName); + rRenderContext.DrawText(aPos, m_aStyleName.second); } StylesPreviewWindow_Base::StylesPreviewWindow_Base( - weld::Builder& xBuilder, std::vector<OUString>& aDefaultStyles, + weld::Builder& xBuilder, std::vector<std::pair<OUString, OUString>>& aDefaultStyles, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) : m_xUp(xBuilder.weld_toolbar("uptoolbar")) , m_xDown(xBuilder.weld_toolbar("downtoolbar")) @@ -358,7 +359,9 @@ StylesPreviewWindow_Base::StylesPreviewWindow_Base( { for (unsigned int i = 0; i < STYLES_COUNT; i++) { - m_xStyleControllers[i].reset(new StyleItemController(aDefaultStyles[i], xDispatchProvider)); + auto aStyle + = i < aDefaultStyles.size() ? aDefaultStyles[i] : std::pair<OUString, OUString>("", ""); + m_xStyleControllers[i].reset(new StyleItemController(aStyle, xDispatchProvider)); OUString sIdOUString = "style" + OUString::number(i + 1); OString sId = OUStringToOString(sIdOUString, RTL_TEXTENCODING_ASCII_US); @@ -390,10 +393,10 @@ StylesPreviewWindow_Base::~StylesPreviewWindow_Base() m_pStatusListener = nullptr; } -OUString StylesPreviewWindow_Base::GetVisibleStyle(unsigned nPosition) +std::pair<OUString, OUString> StylesPreviewWindow_Base::GetVisibleStyle(unsigned nPosition) { if (nPosition >= STYLES_COUNT || !m_aAllStyles.size()) - return ""; + return std::make_pair<OUString, OUString>("", ""); return m_aAllStyles[(m_nStyleIterator + nPosition) % m_aAllStyles.size()]; } @@ -413,7 +416,9 @@ void StylesPreviewWindow_Base::MakeCurrentStyleVisible() return; unsigned nNewIterator = m_nStyleIterator; - auto aFound = std::find(m_aAllStyles.begin(), m_aAllStyles.end(), m_sSelectedStyle); + auto aFound = std::find_if(m_aAllStyles.begin(), m_aAllStyles.end(), [this](auto it) { + return it.first == m_sSelectedStyle || it.second == m_sSelectedStyle; + }); if (aFound != m_aAllStyles.end()) nNewIterator = aFound - m_aAllStyles.begin(); @@ -430,11 +435,11 @@ void StylesPreviewWindow_Base::Update() for (unsigned int i = 0; i < STYLES_COUNT; i++) { - OUString sStyleName = GetVisibleStyle(i); + std::pair<OUString, OUString> sStyleName = GetVisibleStyle(i); m_xStyleControllers[i]->SetStyle(sStyleName); - m_xStyleControllersWeld[i]->set_tooltip_text(sStyleName); + m_xStyleControllersWeld[i]->set_tooltip_text(sStyleName.second); - if (sStyleName == m_sSelectedStyle) + if (sStyleName.first == m_sSelectedStyle || sStyleName.second == m_sSelectedStyle) m_xStyleControllers[i]->Select(true); else m_xStyleControllers[i]->Select(false); @@ -460,7 +465,7 @@ void StylesPreviewWindow_Base::UpdateStylesList() while (pStyle) { - m_aAllStyles.push_back(pStyle->GetName()); + m_aAllStyles.push_back(std::pair<OUString, OUString>("", pStyle->GetName())); pStyle = xIter->Next(); } } @@ -483,7 +488,7 @@ IMPL_LINK(StylesPreviewWindow_Base, GoDown, const OString&, /*rItem*/, void) } StylesPreviewWindow_Impl::StylesPreviewWindow_Impl( - vcl::Window* pParent, std::vector<OUString>& aDefaultStyles, + vcl::Window* pParent, std::vector<std::pair<OUString, OUString>>& aDefaultStyles, css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) : InterimItemWindow(pParent, "svx/ui/stylespreview.ui", "ApplyStyleBox", reinterpret_cast<sal_uInt64>(SfxViewShell::Current())) |