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-08 11:22:34 +0200 |
commit | e40010a530778efde26ab20b2a2e8f9dbf7d55ee (patch) | |
tree | 83a2d12442678eb718729e47d50e875df796192e /svx | |
parent | ca435be45f316120b9df6c9d547b781ed975817d (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>
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 | 47 |
4 files changed, 49 insertions, 28 deletions
diff --git a/svx/source/inc/StylesPreviewToolBoxControl.hxx b/svx/source/inc/StylesPreviewToolBoxControl.hxx index c42c5ba09fd2..8de721ab0032 100644 --- a/svx/source/inc/StylesPreviewToolBoxControl.hxx +++ b/svx/source/inc/StylesPreviewToolBoxControl.hxx @@ -36,7 +36,7 @@ class SVX_DLLPUBLIC 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 0a95aa5397e5..9acf4a517194 100644 --- a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx +++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx @@ -80,7 +80,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&) { @@ -104,7 +107,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 4ff428a73e66..a200a8f906f9 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) { pPool->SetSearchMask(m_eStyleFamily); pStyle = pPool->First(); - while (pStyle && pStyle->GetName() != m_aStyleName) + while (pStyle && pStyle->GetName() != m_aStyleName.first + && pStyle->GetName() != m_aStyleName.second) pStyle = pPool->Next(); if (!pStyle) @@ -320,7 +321,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()); @@ -340,17 +341,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")) @@ -359,7 +360,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); @@ -391,10 +394,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,17 @@ void StylesPreviewWindow_Base::MakeCurrentStyleVisible() if (m_aAllStyles.size()) { unsigned nNewIterator = m_nStyleIterator; - auto aFound = std::find(m_aAllStyles.begin(), m_aAllStyles.end(), m_sSelectedStyle); + auto aIt = m_aAllStyles.begin(); + auto aFound = m_aAllStyles.end(); + while (aIt != m_aAllStyles.end()) + { + if (aIt->first == m_sSelectedStyle || aIt->second == m_sSelectedStyle) + { + aFound = aIt; + break; + } + aIt++; + } if (aFound != m_aAllStyles.end()) nNewIterator = aFound - m_aAllStyles.begin(); @@ -431,11 +444,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); @@ -461,7 +474,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(); } } @@ -484,7 +497,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())) |