1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
19 #include <sfx2/sidebar/SidebarPanelBase.hxx>
20 #include <sfx2/sidebar/Theme.hxx>
21 #include <sfx2/sidebar/ILayoutableWindow.hxx>
22 #include <sfx2/sidebar/IContextChangeReceiver.hxx>
23 #include <sfx2/imagemgr.hxx>
24 #include <vcl/ctrl.hxx>
25 #include <vcl/layout.hxx>
26 #include <comphelper/processfactory.hxx>
28 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
29 #include <com/sun/star/ui/UIElementType.hpp>
32 using namespace css::uno
;
34 namespace sfx2
{ namespace sidebar
{
36 Reference
<ui::XUIElement
> SidebarPanelBase::Create (
37 const ::rtl::OUString
& rsResourceURL
,
38 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
40 const css::ui::LayoutSize
& rLayoutSize
)
42 Reference
<ui::XUIElement
> xUIElement (
51 SidebarPanelBase::SidebarPanelBase (
52 const ::rtl::OUString
& rsResourceURL
,
53 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
,
55 const css::ui::LayoutSize
& rLayoutSize
)
56 : SidebarPanelBaseInterfaceBase(m_aMutex
),
59 msResourceURL(rsResourceURL
),
60 maLayoutSize(rLayoutSize
)
64 css::uno::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
65 css::ui::ContextChangeEventMultiplexer::get(
66 ::comphelper::getProcessComponentContext()));
67 if (xMultiplexer
.is())
68 xMultiplexer
->addContextChangeEventListener(this, mxFrame
->getController());
70 if (mpControl
!= nullptr)
72 mpControl
->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground
));
77 SidebarPanelBase::~SidebarPanelBase()
81 void SAL_CALL
SidebarPanelBase::disposing()
82 throw (css::uno::RuntimeException
)
84 mpControl
.disposeAndClear();
88 css::uno::Reference
<css::ui::XContextChangeEventMultiplexer
> xMultiplexer (
89 css::ui::ContextChangeEventMultiplexer::get(
90 ::comphelper::getProcessComponentContext()));
91 if (xMultiplexer
.is())
92 xMultiplexer
->removeAllContextChangeEventListeners(this);
97 // XContextChangeEventListener
98 void SAL_CALL
SidebarPanelBase::notifyContextChangeEvent (
99 const ui::ContextChangeEventObject
& rEvent
)
100 throw (css::uno::RuntimeException
, std::exception
)
102 IContextChangeReceiver
* pContextChangeReceiver
103 = dynamic_cast<IContextChangeReceiver
*>(mpControl
.get());
104 if (pContextChangeReceiver
!= NULL
)
106 const EnumContext
aContext(
107 EnumContext::GetApplicationEnum(rEvent
.ApplicationName
),
108 EnumContext::GetContextEnum(rEvent
.ContextName
));
109 pContextChangeReceiver
->HandleContextChange(aContext
);
113 void SAL_CALL
SidebarPanelBase::disposing (
114 const css::lang::EventObject
& rEvent
)
115 throw (css::uno::RuntimeException
, std::exception
)
123 css::uno::Reference
<css::frame::XFrame
> SAL_CALL
SidebarPanelBase::getFrame()
124 throw(css::uno::RuntimeException
, std::exception
)
129 ::rtl::OUString SAL_CALL
SidebarPanelBase::getResourceURL()
130 throw(css::uno::RuntimeException
, std::exception
)
132 return msResourceURL
;
135 sal_Int16 SAL_CALL
SidebarPanelBase::getType()
136 throw(css::uno::RuntimeException
, std::exception
)
138 return ui::UIElementType::TOOLPANEL
;
141 Reference
<XInterface
> SAL_CALL
SidebarPanelBase::getRealInterface()
142 throw(css::uno::RuntimeException
, std::exception
)
144 return Reference
<XInterface
>(static_cast<XWeak
*>(this));
147 Reference
<accessibility::XAccessible
> SAL_CALL
SidebarPanelBase::createAccessible (
148 const Reference
<accessibility::XAccessible
>& rxParentAccessible
)
149 throw(css::uno::RuntimeException
, std::exception
)
151 (void)rxParentAccessible
;
153 // Not yet implemented.
157 Reference
<awt::XWindow
> SAL_CALL
SidebarPanelBase::getWindow()
158 throw(css::uno::RuntimeException
, std::exception
)
160 if (mpControl
!= nullptr)
161 return Reference
<awt::XWindow
>(
162 mpControl
->GetComponentInterface(),
168 ui::LayoutSize SAL_CALL
SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth
)
169 throw(css::uno::RuntimeException
, std::exception
)
171 if (maLayoutSize
.Minimum
>= 0)
175 ILayoutableWindow
* pLayoutableWindow
= dynamic_cast<ILayoutableWindow
*>(mpControl
.get());
177 if (isLayoutEnabled(mpControl
))
179 // widget layout-based sidebar
180 Size
aSize(mpControl
->get_preferred_size());
181 return ui::LayoutSize(aSize
.Height(), aSize
.Height(), aSize
.Height());
183 else if (pLayoutableWindow
!= NULL
)
184 return pLayoutableWindow
->GetHeightForWidth(nWidth
);
185 else if (mpControl
!= nullptr)
187 const sal_Int32
nHeight (mpControl
->GetSizePixel().Height());
188 return ui::LayoutSize(nHeight
,nHeight
,nHeight
);
192 return ui::LayoutSize(0,0,0);
195 sal_Int32 SAL_CALL
SidebarPanelBase::getMinimalWidth () throw(css::uno::RuntimeException
, std::exception
)
197 if (isLayoutEnabled(mpControl
))
199 // widget layout-based sidebar
200 Size
aSize(mpControl
->get_preferred_size());
201 return aSize
.Width();
206 } } // end of namespace sfx2::sidebar
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */