Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/framework/source/uielement/addonstoolbarwrapper.cxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <uielement/addonstoolbarwrapper.hxx>
21
#include <uielement/toolbarmanager.hxx>
22
23
#include <com/sun/star/lang/DisposedException.hpp>
24
#include <com/sun/star/ui/UIElementType.hpp>
25
26
#include <toolkit/helper/vclunohelper.hxx>
27
28
#include <vcl/svapp.hxx>
29
#include <vcl/toolbox.hxx>
30
#include <vcl/wintypes.hxx>
31
32
using namespace com::sun::star::uno;
33
using namespace com::sun::star::beans;
34
using namespace com::sun::star::frame;
35
using namespace com::sun::star::lang;
36
using namespace com::sun::star::container;
37
using namespace com::sun::star::awt;
38
using namespace ::com::sun::star::ui;
39
40
namespace framework
41
{
42
43
AddonsToolBarWrapper::AddonsToolBarWrapper( const Reference< XComponentContext >& xContext ) :
44
0
    UIElementWrapperBase( UIElementType::TOOLBAR ),
45
0
    m_xContext( xContext ),
46
0
    m_bCreatedImages( false )
47
0
{
48
0
}
49
50
AddonsToolBarWrapper::~AddonsToolBarWrapper()
51
0
{
52
0
}
53
54
// XComponent
55
void SAL_CALL AddonsToolBarWrapper::dispose()
56
0
{
57
0
    Reference< XComponent > xThis(this);
58
59
0
    css::lang::EventObject aEvent( xThis );
60
0
    m_aListenerContainer.disposeAndClear( aEvent );
61
62
0
    SolarMutexGuard g;
63
64
0
    if ( m_xToolBarManager.is() )
65
0
        m_xToolBarManager->dispose();
66
0
    m_xToolBarManager.clear();
67
68
0
    m_bDisposed = true;
69
0
}
70
71
// XInitialization
72
void SAL_CALL AddonsToolBarWrapper::initialize( const Sequence< Any >& aArguments )
73
0
{
74
0
    SolarMutexGuard g;
75
76
0
    if ( m_bDisposed )
77
0
        throw DisposedException();
78
79
0
    if ( m_bInitialized )
80
0
        return;
81
82
0
    UIElementWrapperBase::initialize( aArguments );
83
84
0
    for ( const Any& rArg : aArguments )
85
0
    {
86
0
        PropertyValue aPropValue;
87
0
        if ( rArg >>= aPropValue )
88
0
        {
89
0
            if ( aPropValue.Name == "ConfigurationData" )
90
0
                aPropValue.Value >>= m_aConfigData;
91
0
        }
92
0
    }
93
94
0
    Reference< XFrame > xFrame( m_xWeakFrame );
95
0
    if ( !(xFrame.is() && m_aConfigData.hasElements()) )
96
0
        return;
97
98
    // Create VCL based toolbar which will be filled with settings data
99
0
    VclPtr<ToolBox> pToolBar;
100
0
    rtl::Reference<ToolBarManager> pToolBarManager;
101
0
    {
102
0
        SolarMutexGuard aSolarMutexGuard;
103
0
        VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
104
0
        if ( pWindow )
105
0
        {
106
0
            WinBits nStyles = WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
107
108
0
            pToolBar = VclPtr<ToolBox>::Create( pWindow, nStyles );
109
0
            pToolBar->SetLineSpacing(true);
110
0
            pToolBarManager = new ToolBarManager( m_xContext, xFrame, m_aResourceURL, pToolBar );
111
0
            m_xToolBarManager = pToolBarManager;
112
0
        }
113
0
    }
114
115
0
    try
116
0
    {
117
0
        if ( m_aConfigData.hasElements() && pToolBar && pToolBarManager )
118
0
        {
119
            // Fill toolbar with container contents
120
0
            pToolBarManager->FillAddonToolbar( m_aConfigData );
121
0
            pToolBar->EnableCustomize();
122
0
            ::Size aActSize( pToolBar->GetSizePixel() );
123
0
            ::Size aSize( pToolBar->CalcWindowSizePixel() );
124
0
            aSize.setWidth( aActSize.Width() );
125
0
            pToolBar->SetSizePixel( aSize );
126
0
        }
127
0
    }
128
0
    catch ( const NoSuchElementException& )
129
0
    {
130
0
    }
131
0
}
132
133
// XUIElement interface
134
Reference< XInterface > SAL_CALL AddonsToolBarWrapper::getRealInterface()
135
0
{
136
0
    SolarMutexGuard g;
137
138
0
    if ( m_xToolBarManager )
139
0
    {
140
0
        vcl::Window* pWindow = m_xToolBarManager->GetToolBar();
141
0
        return Reference< XInterface >( VCLUnoHelper::GetInterface( pWindow ), UNO_QUERY );
142
0
    }
143
144
0
    return Reference< XInterface >();
145
0
}
146
147
// allow late population of images for add-on toolbars
148
void AddonsToolBarWrapper::populateImages()
149
0
{
150
0
    SolarMutexGuard g;
151
152
0
    if (m_bCreatedImages)
153
0
        return;
154
155
0
    if (m_xToolBarManager)
156
0
    {
157
0
        m_xToolBarManager->RequestImages();
158
0
        m_bCreatedImages = true;
159
0
    }
160
0
}
161
162
} // namespace framework
163
164
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */