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("com.sun.star.text.TextDocument"))
63 css::uno::Reference
<css::container::XNameAccess
> xParaStyles
;
64 xStylesSupplier
->getStyleFamilies()->getByName("ParagraphStyles") >>= xParaStyles
;
65 static const std::vector
<OUString
> aWriterStyles
66 = { "Standard", "Text body", "Heading 1", "Heading 2", "Heading 3",
67 "Heading 4", "Title", "Subtitle", "Quotations", "Preformatted Text" };
68 for (const OUString
& aStyle
: aWriterStyles
)
72 css::uno::Reference
<css::beans::XPropertySet
> xStyle
;
73 xParaStyles
->getByName(aStyle
) >>= xStyle
;
75 xStyle
->getPropertyValue("DisplayName") >>= sName
;
77 m_aDefaultStyles
.push_back(std::pair
<OUString
, OUString
>(aStyle
, sName
));
79 catch (const css::container::NoSuchElementException
&)
82 catch (const css::uno::Exception
&)
87 else if (xServices
->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
89 static const char* aCalcStyles
[] = { "Default", "Accent 1", "Accent 2", "Accent 3",
90 "Heading 1", "Heading 2", "Result" };
91 css::uno::Reference
<css::container::XNameAccess
> xCellStyles
;
92 xStylesSupplier
->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles
;
93 for (const char* pCalcStyle
: aCalcStyles
)
97 const OUString
sStyleName(OUString::createFromAscii(pCalcStyle
));
98 if (xCellStyles
->hasByName(sStyleName
))
100 css::uno::Reference
<css::beans::XPropertySet
> xStyle(
101 xCellStyles
->getByName(sStyleName
), css::uno::UNO_QUERY_THROW
);
103 xStyle
->getPropertyValue("DisplayName") >>= sName
;
104 if (!sName
.isEmpty())
106 m_aDefaultStyles
.push_back(
107 std::pair
<OUString
, OUString
>(sStyleName
, sName
));
111 catch (const css::uno::Exception
&)
117 catch (const css::uno::Exception
&)
119 OSL_FAIL("error while initializing style names");
123 void SAL_CALL
StylesPreviewToolBoxControl::update() {}
125 void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent
& /*rEvent*/) {}
127 css::uno::Reference
<css::awt::XWindow
>
128 StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference
<css::awt::XWindow
>& rParent
)
130 css::uno::Reference
<css::awt::XWindow
> xItemWindow
;
135 SolarMutexGuard aSolarMutexGuard;
137 std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
140 = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
142 m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
143 m_pBox = m_xWeldBox.get();
148 VclPtr
<vcl::Window
> pParent
= VCLUnoHelper::GetWindow(rParent
);
151 SolarMutexGuard aSolarMutexGuard
;
153 m_xVclBox
= VclPtr
<StylesPreviewWindow_Impl
>::Create(
154 pParent
, std::vector(m_aDefaultStyles
), m_xFrame
);
155 xItemWindow
= VCLUnoHelper::GetInterface(m_xVclBox
);
162 OUString
StylesPreviewToolBoxControl::getImplementationName()
164 return "com.sun.star.comp.svx.StylesPreviewToolBoxControl";
167 sal_Bool
StylesPreviewToolBoxControl::supportsService(const OUString
& rServiceName
)
169 return cppu::supportsService(this, rServiceName
);
172 css::uno::Sequence
<OUString
> StylesPreviewToolBoxControl::getSupportedServiceNames()
174 return { "com.sun.star.frame.ToolbarController" };
177 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
178 com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation(
179 css::uno::XComponentContext
*, css::uno::Sequence
<css::uno::Any
> const&)
181 return cppu::acquire(new StylesPreviewToolBoxControl());
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */