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 .
20 #include <sfx2/sidebar/Panel.hxx>
21 #include <sidebar/PanelTitleBar.hxx>
22 #include <sidebar/PanelDescriptor.hxx>
23 #include <sfx2/sidebar/Theme.hxx>
24 #include <sfx2/sidebar/ResourceManager.hxx>
26 #include <sfx2/sidebar/SidebarController.hxx>
27 #include <tools/json_writer.hxx>
31 #include <sfx2/sidebar/Tools.hxx>
32 #include <sfx2/sidebar/Deck.hxx>
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <com/sun/star/ui/XToolPanel.hpp>
37 #include <com/sun/star/ui/XSidebarPanel.hpp>
38 #include <com/sun/star/ui/XUIElement.hpp>
41 using namespace css::uno
;
43 namespace sfx2::sidebar
{
45 Panel::Panel(const PanelDescriptor
& rPanelDescriptor
,
46 vcl::Window
* pParentWindow
,
47 const bool bIsInitiallyExpanded
,
48 const std::function
<void()>& rDeckLayoutTrigger
,
49 const std::function
<Context()>& rContextAccess
,
50 const css::uno::Reference
<css::frame::XFrame
>& rxFrame
52 : Window(pParentWindow
)
53 , msPanelId(rPanelDescriptor
.msId
)
54 , mbIsTitleBarOptional(rPanelDescriptor
.mbIsTitleBarOptional
)
57 , mbIsExpanded(bIsInitiallyExpanded
)
59 , maDeckLayoutTrigger(rDeckLayoutTrigger
)
60 , maContextAccess(rContextAccess
)
62 , mpTitleBar(VclPtr
<PanelTitleBar
>::Create(rPanelDescriptor
.msTitle
, pParentWindow
, this))
64 SetText(rPanelDescriptor
.msTitle
);
73 void Panel::SetLurkMode(bool bLurk
)
79 void Panel::ApplySettings(vcl::RenderContext
& rRenderContext
)
81 rRenderContext
.SetBackground(Theme::GetColor(Theme::Color_PanelBackground
));
84 void Panel::DumpAsPropertyTree(tools::JsonWriter
& rJsonWriter
)
88 vcl::Window::DumpAsPropertyTree(rJsonWriter
);
89 rJsonWriter
.put("type", "panel");
95 mxPanelComponent
= nullptr;
98 Reference
<lang::XComponent
> xComponent (mxElement
, UNO_QUERY
);
101 xComponent
->dispose();
105 Reference
<lang::XComponent
> xComponent
= GetElementWindow();
107 xComponent
->dispose();
110 mpTitleBar
.disposeAndClear();
112 vcl::Window::dispose();
115 VclPtr
<PanelTitleBar
> const & Panel::GetTitleBar() const
120 void Panel::SetUIElement (const Reference
<ui::XUIElement
>& rxElement
)
122 mxElement
= rxElement
;
125 mxPanelComponent
.set(mxElement
->getRealInterface(), UNO_QUERY
);
129 void Panel::SetExpanded (const bool bIsExpanded
)
131 SidebarController
* pSidebarController
= SidebarController::GetSidebarControllerForFrame(mxFrame
);
133 if (mbIsExpanded
== bIsExpanded
)
136 mbIsExpanded
= bIsExpanded
;
137 mpTitleBar
->UpdateExpandedState();
138 maDeckLayoutTrigger();
140 if (maContextAccess
&& pSidebarController
)
142 pSidebarController
->GetResourceManager()->StorePanelExpansionState(
149 bool Panel::HasIdPredicate (const OUString
& rsId
) const
151 return msPanelId
== rsId
;
158 // Forward new size to window of XUIElement.
159 Reference
<awt::XWindow
> xElementWindow (GetElementWindow());
160 if(xElementWindow
.is())
162 const Size
aSize(GetSizePixel());
163 xElementWindow
->setPosSize(0, 0, aSize
.Width(), aSize
.Height(),
164 awt::PosSize::POSSIZE
);
168 void Panel::DataChanged (const DataChangedEvent
&)
173 Reference
<awt::XWindow
> Panel::GetElementWindow()
177 Reference
<ui::XToolPanel
> xToolPanel(mxElement
->getRealInterface(), UNO_QUERY
);
179 return xToolPanel
->getWindow();
185 } // end of namespace sfx2::sidebar
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */