Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / StylesPreviewToolBoxControl.cxx
blob64e6ed7822fe3264f829015e0212b7c4a56ed998
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.
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() {}
32 void SAL_CALL
33 StylesPreviewToolBoxControl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
35 svt::ToolboxController::initialize(rArguments);
37 if (m_xFrame.is())
39 InitializeStyles(m_xFrame->getController()->getModel());
41 m_xDispatchProvider = css::uno::Reference<css::frame::XDispatchProvider>(
42 m_xFrame->getController(), css::uno::UNO_QUERY);
46 void SAL_CALL StylesPreviewToolBoxControl::dispose()
48 svt::ToolboxController::dispose();
50 SolarMutexGuard aSolarMutexGuard;
51 m_xVclBox.disposeAndClear();
52 m_xWeldBox.reset();
55 void StylesPreviewToolBoxControl::InitializeStyles(
56 const css::uno::Reference<css::frame::XModel>& xModel)
58 m_aDefaultStyles.clear();
60 //now convert the default style names to the localized names
61 try
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"))
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)
75 try
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));
84 catch (const css::container::NoSuchElementException&)
87 catch (const css::uno::Exception&)
92 else if (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument"))
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)
102 const OUString sStyleName(OUString::createFromAscii(pCalcStyle));
103 if (xCellStyles->hasByName(sStyleName))
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())
111 m_aDefaultStyles.push_back(
112 std::pair<OUString, OUString>(sStyleName, sName));
116 catch (const css::uno::Exception&)
122 catch (const css::uno::Exception&)
124 OSL_FAIL("error while initializing style names");
128 void SAL_CALL StylesPreviewToolBoxControl::update() {}
130 void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent& /*rEvent*/) {}
132 css::uno::Reference<css::awt::XWindow>
133 StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
135 css::uno::Reference<css::awt::XWindow> xItemWindow;
137 /* TODO
138 if (m_pBuilder)
140 SolarMutexGuard aSolarMutexGuard;
142 std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
144 xItemWindow
145 = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
147 m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
148 m_pBox = m_xWeldBox.get();
150 else
153 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
154 if (pParent)
156 SolarMutexGuard aSolarMutexGuard;
158 m_xVclBox = VclPtr<StylesPreviewWindow_Impl>::Create(
159 pParent, std::vector(m_aDefaultStyles), m_xDispatchProvider);
160 xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
164 return xItemWindow;
167 OUString StylesPreviewToolBoxControl::getImplementationName()
169 return "com.sun.star.comp.svx.StylesPreviewToolBoxControl";
172 sal_Bool StylesPreviewToolBoxControl::supportsService(const OUString& rServiceName)
174 return cppu::supportsService(this, rServiceName);
177 css::uno::Sequence<OUString> StylesPreviewToolBoxControl::getSupportedServiceNames()
179 return { "com.sun.star.frame.ToolbarController" };
182 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
183 com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation(
184 css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
186 return cppu::acquire(new StylesPreviewToolBoxControl());
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */