1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <StylesPreviewToolBoxControl.hxx>
21 #include <cppuhelper/supportsservice.hxx>
22 #include <vcl/svapp.hxx>
23 #include <toolkit/helper/vclunohelper.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
26 #include <com/sun/star/beans/XPropertySet.hpp>
28 StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() {}
30 StylesPreviewToolBoxControl::~StylesPreviewToolBoxControl() {}
33 StylesPreviewToolBoxControl::initialize(const css::uno::Sequence
<css::uno::Any
>& rArguments
)
35 svt::ToolboxController::initialize(rArguments
);
38 InitializeStyles(m_xFrame
->getController()->getModel());
41 void SAL_CALL
StylesPreviewToolBoxControl::dispose()
43 svt::ToolboxController::dispose();
45 SolarMutexGuard aSolarMutexGuard
;
46 m_xVclBox
.disposeAndClear();
50 void StylesPreviewToolBoxControl::InitializeStyles(
51 const css::uno::Reference
<css::frame::XModel
>& xModel
)
53 m_aDefaultStyles
.clear();
55 //now convert the default style names to the localized names
58 css::uno::Reference
<css::style::XStyleFamiliesSupplier
> xStylesSupplier(
59 xModel
, css::uno::UNO_QUERY_THROW
);
60 css::uno::Reference
<css::lang::XServiceInfo
> xServices(xModel
, css::uno::UNO_QUERY_THROW
);
61 if (xServices
->supportsService(u
"com.sun.star.text.TextDocument"_ustr
))
63 css::uno::Reference
<css::container::XNameAccess
> xParaStyles
;
64 xStylesSupplier
->getStyleFamilies()->getByName(u
"ParagraphStyles"_ustr
) >>= xParaStyles
;
65 static constexpr OUString aWriterStyles
[]{
66 u
"Standard"_ustr
, u
"Text body"_ustr
, u
"Heading 1"_ustr
, u
"Heading 2"_ustr
,
67 u
"Heading 3"_ustr
, u
"Heading 4"_ustr
, u
"Title"_ustr
, u
"Subtitle"_ustr
,
68 u
"Quotations"_ustr
, u
"Preformatted Text"_ustr
70 for (const OUString
& aStyle
: aWriterStyles
)
74 css::uno::Reference
<css::beans::XPropertySet
> xStyle
;
75 xParaStyles
->getByName(aStyle
) >>= xStyle
;
77 xStyle
->getPropertyValue(u
"DisplayName"_ustr
) >>= sName
;
79 m_aDefaultStyles
.push_back(std::pair
<OUString
, OUString
>(aStyle
, sName
));
81 catch (const css::container::NoSuchElementException
&)
84 catch (const css::uno::Exception
&)
89 else if (xServices
->supportsService(u
"com.sun.star.sheet.SpreadsheetDocument"_ustr
))
91 static constexpr OUString aCalcStyles
[]{ u
"Default"_ustr
, u
"Accent 1"_ustr
,
92 u
"Accent 2"_ustr
, u
"Accent 3"_ustr
,
93 u
"Heading 1"_ustr
, u
"Heading 2"_ustr
,
95 css::uno::Reference
<css::container::XNameAccess
> xCellStyles
;
96 xStylesSupplier
->getStyleFamilies()->getByName(u
"CellStyles"_ustr
) >>= xCellStyles
;
97 for (const OUString
& sStyleName
: aCalcStyles
)
101 if (xCellStyles
->hasByName(sStyleName
))
103 css::uno::Reference
<css::beans::XPropertySet
> xStyle(
104 xCellStyles
->getByName(sStyleName
), css::uno::UNO_QUERY
);
108 xStyle
->getPropertyValue(u
"DisplayName"_ustr
) >>= sName
;
109 if (!sName
.isEmpty())
111 m_aDefaultStyles
.push_back(
112 std::pair
<OUString
, OUString
>(sStyleName
, sName
));
117 catch (const css::uno::Exception
&)
123 catch (const css::uno::Exception
&)
125 OSL_FAIL("error while initializing style names");
129 void SAL_CALL
StylesPreviewToolBoxControl::update() {}
131 void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent
& /*rEvent*/) {}
133 css::uno::Reference
<css::awt::XWindow
>
134 StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference
<css::awt::XWindow
>& rParent
)
136 css::uno::Reference
<css::awt::XWindow
> xItemWindow
;
141 SolarMutexGuard aSolarMutexGuard;
143 std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
146 = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
148 m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
149 m_pBox = m_xWeldBox.get();
154 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow(rParent
);
157 SolarMutexGuard aSolarMutexGuard
;
159 m_xVclBox
= VclPtr
<StylesPreviewWindow_Impl
>::Create(
160 pParent
, std::vector(m_aDefaultStyles
), m_xFrame
);
161 xItemWindow
= VCLUnoHelper::GetInterface(m_xVclBox
);
168 OUString
StylesPreviewToolBoxControl::getImplementationName()
170 return u
"com.sun.star.comp.svx.StylesPreviewToolBoxControl"_ustr
;
173 sal_Bool
StylesPreviewToolBoxControl::supportsService(const OUString
& rServiceName
)
175 return cppu::supportsService(this, rServiceName
);
178 css::uno::Sequence
<OUString
> StylesPreviewToolBoxControl::getSupportedServiceNames()
180 return { u
"com.sun.star.frame.ToolbarController"_ustr
};
183 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
184 com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation(
185 css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const&)
187 return cppu::acquire(new StylesPreviewToolBoxControl());
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */