LibreOffice Module sfx2 (master) 1
Panel.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 */
19
26#include <sfx2/viewsh.hxx>
27#include <tools/json_writer.hxx>
28
29
30#ifdef DEBUG
31#include <sfx2/sidebar/Tools.hxx>
32#include <sfx2/sidebar/Deck.hxx>
33#endif
34
35#include <com/sun/star/ui/XToolPanel.hpp>
36#include <com/sun/star/ui/XSidebarPanel.hpp>
37#include <com/sun/star/ui/XUIElement.hpp>
38
39#include <utility>
40#include <vcl/weldutils.hxx>
41
42using namespace css;
43using namespace css::uno;
44
45namespace sfx2::sidebar {
46
47Panel::Panel(const PanelDescriptor& rPanelDescriptor,
48 weld::Widget* pParentWindow,
49 const bool bIsInitiallyExpanded,
50 Deck* pDeck,
51 std::function<Context()> aContextAccess,
52 const css::uno::Reference<css::frame::XFrame>& rxFrame)
53 : mxBuilder(Application::CreateBuilder(pParentWindow, "sfx/ui/panel.ui", false, reinterpret_cast<sal_uInt64>(SfxViewShell::Current())))
54 , msPanelId(rPanelDescriptor.msId)
55 , msTitle(rPanelDescriptor.msTitle)
56 , mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional)
57 , mbWantsAWT(rPanelDescriptor.mbWantsAWT)
58 , mbIsExpanded(bIsInitiallyExpanded)
59 , mbLurking(false)
60 , maContextAccess(std::move(aContextAccess))
61 , mxFrame(rxFrame)
62 , mpParentWindow(pParentWindow)
63 , mxDeck(pDeck)
64 , mxContainer(mxBuilder->weld_box("Panel"))
65 , mxTitleBar(new PanelTitleBar(rPanelDescriptor.msTitle, *mxBuilder, this))
66 , mxContents(mxBuilder->weld_box("contents"))
67{
68 mxContents->set_visible(mbIsExpanded);
69 mxContainer->connect_get_property_tree(LINK(this, Panel, DumpAsPropertyTreeHdl));
70}
71
73{
74 // Get vertical extent of the panel.
75 int x, y, width, height;
76 if (mxContainer->get_extents_relative_to(*mpParentWindow, x, y, width, height))
77 {
78 rExtents = tools::Rectangle(Point(x, y), Size(width, height));
79 return true;
80 }
81 return false;
82}
83
84void Panel::SetHeightPixel(int nHeight)
85{
86 mxContainer->set_size_request(-1, nHeight);
87}
88
89void Panel::set_margin_top(int nMargin)
90{
91 mxContainer->set_margin_top(nMargin);
92}
93
94void Panel::set_margin_bottom(int nMargin)
95{
96 mxContainer->set_margin_bottom(nMargin);
97}
98
99void Panel::set_vexpand(bool bExpand)
100{
101 mxContainer->set_vexpand(bExpand);
102}
103
104void Panel::SetLurkMode(bool bLurk)
105{
106 // cf. DeckLayouter
107 mbLurking = bLurk;
108}
109
110IMPL_LINK(Panel, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void)
111{
112 if (!IsLurking())
113 rJsonWriter.put("type", "panel");
114}
115
117{
118 mxPanelComponent = nullptr;
119
120 {
121 Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
122 mxElement = nullptr;
123 if (xComponent.is())
124 xComponent->dispose();
125 }
126
127 {
128 Reference<lang::XComponent> xComponent = GetElementWindow();
129 if (xComponent.is())
130 xComponent->dispose();
131 }
132
133 mxTitleBar.reset();
134
135 if (mxXWindow)
136 {
137 mxXWindow->dispose();
138 mxXWindow.clear();
139 }
140 mxContents.reset();
141
142 assert(!mxTitleBar);
143}
144
146{
147 return mxTitleBar.get();
148}
149
151{
152 return mxContents.get();
153}
154
155void Panel::Show(bool bShow)
156{
157 mxContainer->set_visible(bShow);
158}
159
160void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
161{
162 mxElement = rxElement;
163 if (!mxElement.is())
164 return;
165 mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
166 if (mbWantsAWT)
167 return;
169 assert(pPanelBase && "internal panels are all expected to inherit from SidebarPanelBase");
170 pPanelBase->SetParentPanel(this);
171}
172
174{
175 mxDeck->RequestLayout();
176}
177
179{
180 return mxDeck->GetFrameWeld();
181}
182
183void Panel::SetExpanded (const bool bIsExpanded)
184{
186
187 if (mbIsExpanded == bIsExpanded)
188 return;
189
190 mbIsExpanded = bIsExpanded;
191 mxTitleBar->UpdateExpandedState();
193
194 if (maContextAccess && pSidebarController)
195 {
196 pSidebarController->GetResourceManager()->StorePanelExpansionState(
197 msPanelId,
198 bIsExpanded,
200 }
201
202 mxContents->set_visible(mbIsExpanded);
203}
204
205bool Panel::HasIdPredicate (std::u16string_view rsId) const
206{
207 return msPanelId == rsId;
208}
209
211{
212 mxTitleBar->DataChanged();
213}
214
215Reference<awt::XWindow> Panel::GetElementWindow()
216{
217 if (mxElement.is())
218 {
219 Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
220 if (xToolPanel.is())
221 return xToolPanel->getWindow();
222 }
223
224 return nullptr;
225}
226
227const Reference<awt::XWindow>& Panel::GetElementParentWindow()
228{
229 if (!mxXWindow)
230 {
231 if (mbWantsAWT)
232 mxXWindow = mxContents->CreateChildFrame();
233 else
234 mxXWindow = Reference<awt::XWindow>(new weld::TransportAsXWindow(mxContents.get()));
235 }
236 return mxXWindow;
237}
238
239} // end of namespace sfx2::sidebar
240
241/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< container::XNameAccess > mxContainer
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
This is the parent window of the panels.
Definition: Deck.hxx:38
Multiple panels form a single deck.
Definition: Panel.hxx:54
css::uno::Reference< css::awt::XWindow > GetElementWindow()
Definition: Panel.cxx:215
const css::uno::Reference< css::awt::XWindow > & GetElementParentWindow()
Definition: Panel.cxx:227
void Show(bool bShow)
Definition: Panel.cxx:155
const std::function< Context()> maContextAccess
Definition: Panel.hxx:106
void SetUIElement(const css::uno::Reference< css::ui::XUIElement > &rxElement)
Definition: Panel.cxx:160
weld::Widget * mpParentWindow
Definition: Panel.hxx:108
void TriggerDeckLayouting()
Definition: Panel.cxx:173
std::unique_ptr< weld::Box > mxContents
Definition: Panel.hxx:112
void set_margin_bottom(int nMargin)
Definition: Panel.cxx:94
std::unique_ptr< weld::Box > mxContainer
Definition: Panel.hxx:110
css::uno::Reference< css::awt::XWindow > mxXWindow
Definition: Panel.hxx:113
void SetHeightPixel(int nHeight)
Definition: Panel.cxx:84
VclPtr< Deck > mxDeck
Definition: Panel.hxx:109
const css::uno::Reference< css::frame::XFrame > & mxFrame
Definition: Panel.hxx:107
css::uno::Reference< css::ui::XSidebarPanel > mxPanelComponent
Definition: Panel.hxx:103
void SetExpanded(const bool bIsExpanded)
Definition: Panel.cxx:183
void set_margin_top(int nMargin)
Definition: Panel.cxx:89
void SetLurkMode(bool bLurk)
Set whether a panel should be present but invisible / inactive.
Definition: Panel.cxx:104
weld::Box * GetContents() const
Definition: Panel.cxx:150
weld::Window * GetFrameWeld()
Definition: Panel.cxx:178
bool HasIdPredicate(std::u16string_view rsId) const
Definition: Panel.cxx:205
Panel(const PanelDescriptor &rPanelDescriptor, weld::Widget *pParentWindow, const bool bIsInitiallyExpanded, Deck *pDeck, std::function< Context()> aContextAccess, const css::uno::Reference< css::frame::XFrame > &rxFrame)
Definition: Panel.cxx:47
PanelTitleBar * GetTitleBar() const
Definition: Panel.cxx:145
void set_vexpand(bool bExpand)
Definition: Panel.cxx:99
const bool mbWantsAWT
Definition: Panel.hxx:101
const OUString msPanelId
Definition: Panel.hxx:98
bool get_extents(tools::Rectangle &rExtents) const
Definition: Panel.cxx:72
std::unique_ptr< PanelTitleBar > mxTitleBar
Definition: Panel.hxx:111
css::uno::Reference< css::ui::XUIElement > mxElement
Definition: Panel.hxx:102
void StorePanelExpansionState(std::u16string_view rsPanelId, const bool bExpansionState, const Context &rContext)
Remember the expansions state per panel and context.
static SidebarController * GetSidebarControllerForFrame(const css::uno::Reference< css::frame::XFrame > &rxFrame)
Return the SidebarController object that is associated with the given XFrame.
Base class for sidebar panels that provides some convenience functionality.
void SetParentPanel(sfx2::sidebar::Panel *pPanel)
float y
float x
IMPL_LINK(FocusManager, KeyInputHdl, const KeyEvent &, rKeyEvent, bool)