LibreOffice Module sfx2 (master) 1
SidebarPanelBase.cxx
Go to the documentation of this file.
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 */
24#include <utility>
25#include <vcl/EnumContext.hxx>
26#include <vcl/svapp.hxx>
28#include <com/sun/star/awt/XWindowPeer.hpp>
29#include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
30#include <com/sun/star/ui/UIElementType.hpp>
31
32using namespace css;
33using namespace css::uno;
34
35namespace sfx2::sidebar {
36
37Reference<ui::XUIElement> SidebarPanelBase::Create (
38 const OUString& rsResourceURL,
39 const css::uno::Reference<css::frame::XFrame>& rxFrame,
40 std::unique_ptr<PanelLayout> xControl,
41 const css::ui::LayoutSize& rLayoutSize)
42{
43 Reference<ui::XUIElement> xUIElement (
45 rsResourceURL,
46 rxFrame,
47 std::move(xControl),
48 rLayoutSize));
49 return xUIElement;
50}
51
53 OUString sResourceURL,
54 css::uno::Reference<css::frame::XFrame> xFrame,
55 std::unique_ptr<PanelLayout> xControl,
56 const css::ui::LayoutSize& rLayoutSize)
57 : mxFrame(std::move(xFrame)),
58 mxControl(std::move(xControl)),
59 msResourceURL(std::move(sResourceURL)),
60 maLayoutSize(rLayoutSize)
61{
62 if (mxFrame.is())
63 {
64 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
65 css::ui::ContextChangeEventMultiplexer::get(
66 ::comphelper::getProcessComponentContext()));
67 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
68 }
69}
70
72{
73}
74
76{
77 if (!mxControl)
78 return;
79 mxControl->SetPanel(pPanel);
80}
81
82void SidebarPanelBase::disposing(std::unique_lock<std::mutex>&)
83{
84 SolarMutexGuard aGuard;
85
86 mxControl.reset();
87
88 if (mxFrame.is())
89 {
90 css::uno::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
91 css::ui::ContextChangeEventMultiplexer::get(
92 ::comphelper::getProcessComponentContext()));
93 xMultiplexer->removeAllContextChangeEventListeners(this);
94 mxFrame = nullptr;
95 }
96}
97
98// XContextChangeEventListener
100 const ui::ContextChangeEventObject& rEvent)
101{
102 SolarMutexGuard aGuard;
103
104 IContextChangeReceiver* pContextChangeReceiver
105 = dynamic_cast<IContextChangeReceiver*>(mxControl.get());
106 if (pContextChangeReceiver != nullptr)
107 {
108 const vcl::EnumContext aContext(
109 vcl::EnumContext::GetApplicationEnum(rEvent.ApplicationName),
110 vcl::EnumContext::GetContextEnum(rEvent.ContextName));
111 pContextChangeReceiver->HandleContextChange(aContext);
112 }
113}
114
116 const css::lang::EventObject&)
117{
118 SolarMutexGuard aGuard;
119
120 mxFrame = nullptr;
121 mxControl.reset();
122}
123
124css::uno::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame()
125{
126 return mxFrame;
127}
128
130{
131 return msResourceURL;
132}
133
134sal_Int16 SAL_CALL SidebarPanelBase::getType()
135{
136 return ui::UIElementType::TOOLPANEL;
137}
138
139Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface()
140{
141 return getXWeak();
142}
143
144Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
145 const Reference<accessibility::XAccessible>&)
146{
147 // Not implemented.
148 return nullptr;
149}
150
151Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow()
152{
153 // Not implemented
154 return nullptr;
155}
156
157ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
158{
159 SolarMutexGuard aGuard;
160
161 if (maLayoutSize.Minimum >= 0)
162 return maLayoutSize;
163
164 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mxControl.get());
165 if (pLayoutableWindow)
166 return pLayoutableWindow->GetHeightForWidth(nWidth);
167 else
168 {
169 // widget layout-based sidebar
170 mxControl->queue_resize();
171 Size aSize(mxControl->get_preferred_size());
172 return ui::LayoutSize(aSize.Height(), aSize.Height(), aSize.Height());
173 }
174}
175
177{
178 SolarMutexGuard aGuard;
179
180 // widget layout-based sidebar
181 Size aSize(mxControl->get_preferred_size());
182 return aSize.Width();
183}
184
185void SAL_CALL SidebarPanelBase::updateModel(const css::uno::Reference<css::frame::XModel>& xModel)
186{
187 SolarMutexGuard aGuard;
188
189 SidebarModelUpdate* pModelUpdate = dynamic_cast<SidebarModelUpdate*>(mxControl.get());
190 if (!pModelUpdate)
191 return;
192
193 pModelUpdate->updateModel(xModel);
194}
195
196} // end of namespace sfx2::sidebar
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::ui::LayoutSize maLayoutSize
constexpr tools::Long Height() const
constexpr tools::Long Width() const
Multiple panels form a single deck.
Definition: Panel.hxx:54
virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override
virtual OUString SAL_CALL getResourceURL() override
virtual void SAL_CALL disposing(const css::lang::EventObject &rEvent) override
virtual css::ui::LayoutSize SAL_CALL getHeightForWidth(sal_Int32 nWidth) override
virtual sal_Int32 SAL_CALL getMinimalWidth() override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRealInterface() override
SidebarPanelBase(OUString sResourceURL, css::uno::Reference< css::frame::XFrame > xFrame, std::unique_ptr< PanelLayout > xControl, const css::ui::LayoutSize &rLayoutSize)
const css::ui::LayoutSize maLayoutSize
css::uno::Reference< css::frame::XFrame > mxFrame
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL createAccessible(const css::uno::Reference< css::accessibility::XAccessible > &rxParentAccessible) override
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getWindow() override
static css::uno::Reference< css::ui::XUIElement > Create(const OUString &rsResourceURL, const css::uno::Reference< css::frame::XFrame > &rxFrame, std::unique_ptr< PanelLayout > xControl, const css::ui::LayoutSize &rLayoutSize)
std::unique_ptr< PanelLayout > mxControl
void SetParentPanel(sfx2::sidebar::Panel *pPanel)
virtual void SAL_CALL notifyContextChangeEvent(const css::ui::ContextChangeEventObject &rEvent) override
virtual void SAL_CALL updateModel(const css::uno::Reference< css::frame::XModel > &xModel) override
virtual sal_Int16 SAL_CALL getType() override
static Application GetApplicationEnum(const OUString &rsApplicationName)
static Context GetContextEnum(const OUString &rsContextName)
Reference< XFrame > xFrame
Reference< XModel > xModel