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 InitializeStyles(m_xFrame->getController()->getModel());
39}
40
42{
44
45 SolarMutexGuard aSolarMutexGuard;
47 m_xWeldBox.reset();
48}
49
51 const css::uno::Reference<css::frame::XModel>& xModel)
52{
53 m_aDefaultStyles.clear();
54
55 //now convert the default style names to the localized names
56 try
57 {
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"))
62 {
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)
69 {
70 try
71 {
72 css::uno::Reference<css::beans::XPropertySet> xStyle;
73 xParaStyles->getByName(aStyle) >>= xStyle;
74 OUString sName;
75 xStyle->getPropertyValue("DisplayName") >>= sName;
76 if (!sName.isEmpty())
77 m_aDefaultStyles.push_back(std::pair<OUString, OUString>(aStyle, sName));
78 }
79 catch (const css::container::NoSuchElementException&)
80 {
81 }
82 catch (const css::uno::Exception&)
83 {
84 }
85 }
86 }
87 else if (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
88 {
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)
94 {
95 try
96 {
97 const OUString sStyleName(OUString::createFromAscii(pCalcStyle));
98 if (xCellStyles->hasByName(sStyleName))
99 {
100 css::uno::Reference<css::beans::XPropertySet> xStyle(
101 xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY_THROW);
102 OUString sName;
103 xStyle->getPropertyValue("DisplayName") >>= sName;
104 if (!sName.isEmpty())
105 {
106 m_aDefaultStyles.push_back(
107 std::pair<OUString, OUString>(sStyleName, sName));
108 }
109 }
110 }
111 catch (const css::uno::Exception&)
112 {
113 }
114 }
115 }
116 }
117 catch (const css::uno::Exception&)
118 {
119 OSL_FAIL("error while initializing style names");
120 }
121}
122
124
125void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent& /*rEvent*/) {}
126
127css::uno::Reference<css::awt::XWindow>
128StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
129{
130 css::uno::Reference<css::awt::XWindow> xItemWindow;
131
132 /* TODO
133 if (m_pBuilder)
134 {
135 SolarMutexGuard aSolarMutexGuard;
136
137 std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
138
139 xItemWindow
140 = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
141
142 m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
143 m_pBox = m_xWeldBox.get();
144 }
145 else
146 */
147 {
149 if (pParent)
150 {
151 SolarMutexGuard aSolarMutexGuard;
152
154 pParent, std::vector(m_aDefaultStyles), m_xFrame);
156 }
157 }
158
159 return xItemWindow;
160}
161
163{
164 return "com.sun.star.comp.svx.StylesPreviewToolBoxControl";
165}
166
168{
169 return cppu::supportsService(this, rServiceName);
170}
171
173{
174 return { "com.sun.star.frame.ToolbarController" };
175}
176
177extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
179 css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
180{
181 return cppu::acquire(new StylesPreviewToolBoxControl());
182}
183
184/* 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
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