Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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 <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>
27
28
0
StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() {}
29
30
0
StylesPreviewToolBoxControl::~StylesPreviewToolBoxControl() {}
31
32
void SAL_CALL
33
StylesPreviewToolBoxControl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments)
34
0
{
35
0
    svt::ToolboxController::initialize(rArguments);
36
37
0
    if (m_xFrame.is())
38
0
        InitializeStyles(m_xFrame->getController()->getModel());
39
0
}
40
41
void SAL_CALL StylesPreviewToolBoxControl::dispose()
42
0
{
43
0
    svt::ToolboxController::dispose();
44
45
0
    SolarMutexGuard aSolarMutexGuard;
46
0
    m_xVclBox.disposeAndClear();
47
0
    m_xWeldBox.reset();
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
    /* TODO
140
    if (m_pBuilder)
141
    {
142
        SolarMutexGuard aSolarMutexGuard;
143
144
        std::unique_ptr<weld::Container> xWidget(*m_pBuilder);
145
146
        xItemWindow
147
            = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
148
149
        m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget)));
150
        m_pBox = m_xWeldBox.get();
151
    }
152
    else
153
    */
154
0
    {
155
0
        VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
156
0
        if (pParent)
157
0
        {
158
0
            SolarMutexGuard aSolarMutexGuard;
159
160
0
            m_xVclBox
161
0
                = VclPtr<StylesPreviewWindow_Impl>::Create(pParent, m_aDefaultStyles, m_xFrame);
162
0
            xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox);
163
0
        }
164
0
    }
165
166
0
    return xItemWindow;
167
0
}
168
169
OUString StylesPreviewToolBoxControl::getImplementationName()
170
0
{
171
0
    return u"com.sun.star.comp.svx.StylesPreviewToolBoxControl"_ustr;
172
0
}
173
174
sal_Bool StylesPreviewToolBoxControl::supportsService(const OUString& rServiceName)
175
0
{
176
0
    return cppu::supportsService(this, rServiceName);
177
0
}
178
179
css::uno::Sequence<OUString> StylesPreviewToolBoxControl::getSupportedServiceNames()
180
0
{
181
0
    return { u"com.sun.star.frame.ToolbarController"_ustr };
182
0
}
183
184
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
185
com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation(
186
    css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
187
0
{
188
0
    return cppu::acquire(new StylesPreviewToolBoxControl());
189
0
}
190
191
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */