LibreOffice Module svx (master) 1
StylesPreviewToolBoxControl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22#include <vcl/svapp.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>
27
29
31
32void SAL_CALL
33StylesPreviewToolBoxControl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
34{
36
37 if (m_xFrame.is())
38 {
39 InitializeStyles(m_xFrame->getController()->getModel());
40
41 m_xDispatchProvider = css::uno::Reference<css::frame::XDispatchProvider>(
42 m_xFrame->getController(), css::uno::UNO_QUERY);
43 }
44}
45
47{
49
50 SolarMutexGuard aSolarMutexGuard;
52 m_xWeldBox.reset();
53}
54
56 const css::uno::Reference<css::frame::XModel>& xModel)
57{
58 m_aDefaultStyles.clear();
59
60 //now convert the default style names to the localized names
61 try
62 {
63 css::uno::Reference<css::style::XStyleFamiliesSupplier> xStylesSupplier(
64 xModel, css::uno::UNO_QUERY_THROW);
65 css::uno::Reference<css::lang::XServiceInfo> xServices(xModel, css::uno::UNO_QUERY_THROW);
66 if (xServices->supportsService("com.sun.star.text.TextDocument"))
67 {
68 css::uno::Reference<css::container::XNameAccess> xParaStyles;
69 xStylesSupplier->getStyleFamilies()->getByName("ParagraphStyles") >>= xParaStyles;
70 static const std::vector<OUString> aWriterStyles
71 = { "Standard", "Text body", "Heading 1", "Heading 2", "Heading 3",
72 "Heading 4", "Title", "Subtitle", "Quotations", "Preformatted Text" };
73 for (const OUString& aStyle : aWriterStyles)
74 {
75 try
76 {
77 css::uno::Reference<css::beans::XPropertySet> xStyle;
78 xParaStyles->getByName(aStyle) >>= xStyle;
79 OUString sName;
80 xStyle->getPropertyValue("DisplayName") >>= sName;
81 if (!sName.isEmpty())
82 m_aDefaultStyles.push_back(std::pair<OUString, OUString>(aStyle, sName));
83 }
84 catch (const css::container::NoSuchElementException&)
85 {
86 }
87 catch (const css::uno::Exception&)
88 {
89 }
90 }
91 }
92 else if (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
93 {
94 static const char* aCalcStyles[] = { "Default", "Accent 1", "Accent 2", "Accent 3",
95 "Heading 1", "Heading 2", "Result" };
96 css::uno::Reference<css::container::XNameAccess> xCellStyles;
97 xStylesSupplier->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles;
98 for (const char* pCalcStyle : aCalcStyles)
99 {
100 try
101 {
102 const OUString sStyleName(OUString::createFromAscii(pCalcStyle));
103 if (xCellStyles->hasByName(sStyleName))
104 {
105 css::uno::Reference<css::beans::XPropertySet> xStyle(
106 xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY_THROW);
107 OUString sName;
108 xStyle->getPropertyValue("DisplayName") >>= sName;
109 if (!sName.isEmpty())
110 {
111 m_aDefaultStyles.push_back(
112 std::pair<OUString, OUString>(sStyleName, sName));
113 }
114 }
115 }
116 catch (const css::uno::Exception&)
117 {
118 }
119 }
120 }
121 }
122 catch (const css::uno::Exception&)
123 {
124 OSL_FAIL("error while initializing style names");
125 }
126}
127
129
130void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent& /*rEvent*/) {}
131
132css::uno::Reference<css::awt::XWindow>
133StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
134{
135 css::uno::Reference<css::awt::XWindow> xItemWindow;
136
137 /* TODO
138 if (m_pBuilder)
139 {
140 SolarMutexGuard aSolarMutexGuard;
141
142 std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
143
144 xItemWindow
145 = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
146
147 m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
148 m_pBox = m_xWeldBox.get();
149 }
150 else
151 */
152 {
154 if (pParent)
155 {
156 SolarMutexGuard aSolarMutexGuard;
157
159 pParent, std::vector(m_aDefaultStyles), m_xDispatchProvider);
161 }
162 }
163
164 return xItemWindow;
165}
166
168{
169 return "com.sun.star.comp.svx.StylesPreviewToolBoxControl";
170}
171
173{
174 return cppu::supportsService(this, rServiceName);
175}
176
178{
179 return { "com.sun.star.frame.ToolbarController" };
180}
181
182extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
184 css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
185{
186 return cppu::acquire(new StylesPreviewToolBoxControl());
187}
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
css::uno::Reference< css::lang::XComponent > m_xFrame
virtual OUString SAL_CALL getImplementationName() override
css::uno::Reference< css::frame::XDispatchProvider > m_xDispatchProvider
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
std::vector< std::pair< OUString, OUString > > m_aDefaultStyles
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow(const css::uno::Reference< css::awt::XWindow > &rParent) override
virtual sal_Bool SAL_CALL supportsService(const OUString &rServiceName) override
virtual void SAL_CALL update() override
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &rEvent) override
virtual void SAL_CALL dispose() override
void InitializeStyles(const css::uno::Reference< css::frame::XModel > &xModel)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
VclPtr< StylesPreviewWindow_Impl > m_xVclBox
std::unique_ptr< StylesPreviewWindow_Base > m_xWeldBox
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SAL_CALL dispose() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
OUString sName
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference< XModel > xModel
unsigned char sal_Bool