Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / Panel.cxx
blobc45a1e5efd421d8929aaf0ab5a546493f5dd39c5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #ifdef DEBUG
31 #include <sfx2/sidebar/Tools.hxx>
32 #include <sfx2/sidebar/Deck.hxx>
33 #endif
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>
40 using namespace css;
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)
55 , mxElement()
56 , mxPanelComponent()
57 , mbIsExpanded(bIsInitiallyExpanded)
58 , mbLurking(false)
59 , maDeckLayoutTrigger(rDeckLayoutTrigger)
60 , maContextAccess(rContextAccess)
61 , mxFrame(rxFrame)
62 , mpTitleBar(VclPtr<PanelTitleBar>::Create(rPanelDescriptor.msTitle, pParentWindow, this))
64 SetText(rPanelDescriptor.msTitle);
67 Panel::~Panel()
69 disposeOnce();
70 assert(!mpTitleBar);
73 void Panel::SetLurkMode(bool bLurk)
75 // cf. DeckLayouter
76 mbLurking = bLurk;
79 void Panel::ApplySettings(vcl::RenderContext& rRenderContext)
81 rRenderContext.SetBackground(Theme::GetColor(Theme::Color_PanelBackground));
84 void Panel::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
86 if (!IsLurking())
88 vcl::Window::DumpAsPropertyTree(rJsonWriter);
89 rJsonWriter.put("type", "panel");
93 void Panel::dispose()
95 mxPanelComponent = nullptr;
98 Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
99 mxElement = nullptr;
100 if (xComponent.is())
101 xComponent->dispose();
105 Reference<lang::XComponent> xComponent = GetElementWindow();
106 if (xComponent.is())
107 xComponent->dispose();
110 mpTitleBar.disposeAndClear();
112 vcl::Window::dispose();
115 VclPtr<PanelTitleBar> const & Panel::GetTitleBar() const
117 return mpTitleBar;
120 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
122 mxElement = rxElement;
123 if (mxElement.is())
125 mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
129 void Panel::SetExpanded (const bool bIsExpanded)
131 SidebarController* pSidebarController = SidebarController::GetSidebarControllerForFrame(mxFrame);
133 if (mbIsExpanded == bIsExpanded)
134 return;
136 mbIsExpanded = bIsExpanded;
137 mpTitleBar->UpdateExpandedState();
138 maDeckLayoutTrigger();
140 if (maContextAccess && pSidebarController)
142 pSidebarController->GetResourceManager()->StorePanelExpansionState(
143 msPanelId,
144 bIsExpanded,
145 maContextAccess());
149 bool Panel::HasIdPredicate (const OUString& rsId) const
151 return msPanelId == rsId;
154 void Panel::Resize()
156 Window::Resize();
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&)
170 Invalidate();
173 Reference<awt::XWindow> Panel::GetElementWindow()
175 if (mxElement.is())
177 Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
178 if (xToolPanel.is())
179 return xToolPanel->getWindow();
182 return nullptr;
185 } // end of namespace sfx2::sidebar
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */