/src/libreoffice/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx
Line | Count | Source |
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 | | |
20 | | #include <StylesPreviewToolBoxControl.hxx> |
21 | | #include <comphelper/unique_unlock.hxx> |
22 | | #include <cppuhelper/supportsservice.hxx> |
23 | | #include <vcl/svapp.hxx> |
24 | | #include <toolkit/helper/vclunohelper.hxx> |
25 | | #include <com/sun/star/uno/Reference.hxx> |
26 | | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
27 | | #include <com/sun/star/beans/XPropertySet.hpp> |
28 | | |
29 | 0 | StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() {}Unexecuted instantiation: StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() Unexecuted instantiation: StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() |
30 | | |
31 | 0 | StylesPreviewToolBoxControl::~StylesPreviewToolBoxControl() {} |
32 | | |
33 | | void SAL_CALL |
34 | | StylesPreviewToolBoxControl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments) |
35 | 0 | { |
36 | 0 | svt::ToolboxController::initialize(rArguments); |
37 | |
|
38 | 0 | if (m_xFrame.is()) |
39 | 0 | InitializeStyles(m_xFrame->getController()->getModel()); |
40 | 0 | } |
41 | | |
42 | | void StylesPreviewToolBoxControl::disposing(std::unique_lock<std::mutex>& rGuard) |
43 | 0 | { |
44 | 0 | svt::ToolboxController::disposing(rGuard); |
45 | 0 | comphelper::unique_unlock aUnlock(rGuard); |
46 | 0 | SolarMutexGuard aSolarMutexGuard; |
47 | 0 | m_xVclBox.disposeAndClear(); |
48 | 0 | } |
49 | | |
50 | | void StylesPreviewToolBoxControl::InitializeStyles( |
51 | | const css::uno::Reference<css::frame::XModel>& xModel) |
52 | 0 | { |
53 | 0 | m_aDefaultStyles.clear(); |
54 | | |
55 | | //now convert the default style names to the localized names |
56 | 0 | try |
57 | 0 | { |
58 | 0 | css::uno::Reference<css::style::XStyleFamiliesSupplier> xStylesSupplier( |
59 | 0 | xModel, css::uno::UNO_QUERY_THROW); |
60 | 0 | css::uno::Reference<css::lang::XServiceInfo> xServices(xModel, css::uno::UNO_QUERY_THROW); |
61 | 0 | if (xServices->supportsService(u"com.sun.star.text.TextDocument"_ustr)) |
62 | 0 | { |
63 | 0 | css::uno::Reference<css::container::XNameAccess> xParaStyles; |
64 | 0 | xStylesSupplier->getStyleFamilies()->getByName(u"ParagraphStyles"_ustr) >>= xParaStyles; |
65 | 0 | static constexpr OUString aWriterStyles[]{ |
66 | 0 | u"Standard"_ustr, u"Text body"_ustr, u"Heading 1"_ustr, u"Heading 2"_ustr, |
67 | 0 | u"Heading 3"_ustr, u"Heading 4"_ustr, u"Title"_ustr, u"Subtitle"_ustr, |
68 | 0 | u"Quotations"_ustr, u"Preformatted Text"_ustr |
69 | 0 | }; |
70 | 0 | for (const OUString& rStyle : aWriterStyles) |
71 | 0 | { |
72 | 0 | try |
73 | 0 | { |
74 | 0 | css::uno::Reference<css::beans::XPropertySet> xStyle; |
75 | 0 | xParaStyles->getByName(rStyle) >>= xStyle; |
76 | 0 | OUString sTranslatedName; |
77 | 0 | xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sTranslatedName; |
78 | 0 | if (!sTranslatedName.isEmpty()) |
79 | 0 | m_aDefaultStyles.emplace_back<StylePreviewDescriptor>( |
80 | 0 | { rStyle, sTranslatedName }); |
81 | 0 | } |
82 | 0 | catch (const css::container::NoSuchElementException&) |
83 | 0 | { |
84 | 0 | } |
85 | 0 | catch (const css::uno::Exception&) |
86 | 0 | { |
87 | 0 | } |
88 | 0 | } |
89 | 0 | } |
90 | 0 | else if (xServices->supportsService(u"com.sun.star.sheet.SpreadsheetDocument"_ustr)) |
91 | 0 | { |
92 | 0 | static constexpr OUString aCalcStyles[]{ u"Default"_ustr, u"Accent 1"_ustr, |
93 | 0 | u"Accent 2"_ustr, u"Accent 3"_ustr, |
94 | 0 | u"Heading 1"_ustr, u"Heading 2"_ustr, |
95 | 0 | u"Result"_ustr }; |
96 | 0 | css::uno::Reference<css::container::XNameAccess> xCellStyles; |
97 | 0 | xStylesSupplier->getStyleFamilies()->getByName(u"CellStyles"_ustr) >>= xCellStyles; |
98 | 0 | for (const OUString& sStyleName : aCalcStyles) |
99 | 0 | { |
100 | 0 | try |
101 | 0 | { |
102 | 0 | if (xCellStyles->hasByName(sStyleName)) |
103 | 0 | { |
104 | 0 | css::uno::Reference<css::beans::XPropertySet> xStyle( |
105 | 0 | xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY); |
106 | 0 | if (xStyle) |
107 | 0 | { |
108 | 0 | OUString sTranslatedName; |
109 | 0 | xStyle->getPropertyValue(u"DisplayName"_ustr) >>= sTranslatedName; |
110 | 0 | if (!sTranslatedName.isEmpty()) |
111 | 0 | { |
112 | 0 | m_aDefaultStyles.emplace_back<StylePreviewDescriptor>( |
113 | 0 | { sStyleName, sTranslatedName }); |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | 0 | catch (const css::uno::Exception&) |
119 | 0 | { |
120 | 0 | } |
121 | 0 | } |
122 | 0 | } |
123 | 0 | } |
124 | 0 | catch (const css::uno::Exception&) |
125 | 0 | { |
126 | 0 | OSL_FAIL("error while initializing style names"); |
127 | 0 | } |
128 | 0 | } |
129 | | |
130 | 0 | void SAL_CALL StylesPreviewToolBoxControl::update() {} |
131 | | |
132 | 0 | void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent& /*rEvent*/) {} |
133 | | |
134 | | css::uno::Reference<css::awt::XWindow> |
135 | | StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) |
136 | 0 | { |
137 | 0 | css::uno::Reference<css::awt::XWindow> xItemWindow; |
138 | |
|
139 | 0 | VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent); |
140 | 0 | if (pParent) |
141 | 0 | { |
142 | 0 | SolarMutexGuard aSolarMutexGuard; |
143 | |
|
144 | 0 | m_xVclBox = VclPtr<StylesPreviewWindow_Impl>::Create(pParent, m_aDefaultStyles, m_xFrame); |
145 | 0 | xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox); |
146 | 0 | } |
147 | |
|
148 | 0 | return xItemWindow; |
149 | 0 | } |
150 | | |
151 | | OUString StylesPreviewToolBoxControl::getImplementationName() |
152 | 0 | { |
153 | 0 | return u"com.sun.star.comp.svx.StylesPreviewToolBoxControl"_ustr; |
154 | 0 | } |
155 | | |
156 | | sal_Bool StylesPreviewToolBoxControl::supportsService(const OUString& rServiceName) |
157 | 0 | { |
158 | 0 | return cppu::supportsService(this, rServiceName); |
159 | 0 | } |
160 | | |
161 | | css::uno::Sequence<OUString> StylesPreviewToolBoxControl::getSupportedServiceNames() |
162 | 0 | { |
163 | 0 | return { u"com.sun.star.frame.ToolbarController"_ustr }; |
164 | 0 | } |
165 | | |
166 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
167 | | com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation( |
168 | | css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&) |
169 | 0 | { |
170 | 0 | return cppu::acquire(new StylesPreviewToolBoxControl()); |
171 | 0 | } |
172 | | |
173 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |