LibreOffice Module sfx2 (master) 1
Sidebar.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
24#include <sidebar/Tools.hxx>
26#include <sfx2/childwin.hxx>
27#include <sfx2/sfxsids.hrc>
28#include <com/sun/star/frame/XDispatch.hpp>
29
30using namespace css;
31
32namespace sfx2::sidebar {
33
34void Sidebar::ShowDeck(std::u16string_view rsDeckId, SfxViewFrame* pViewFrame, bool bToggle)
35{
36 if (!pViewFrame)
37 return;
38
39 SfxChildWindow* pSidebarChildWindow = pViewFrame->GetChildWindow(SID_SIDEBAR);
40 bool bInitiallyVisible = pSidebarChildWindow && pSidebarChildWindow->IsVisible();
41 if (!bInitiallyVisible)
42 pViewFrame->ShowChildWindow(SID_SIDEBAR);
43
44 SidebarController* pController =
46 if (!pController)
47 return;
48
49 if (bToggle && bInitiallyVisible && pController->IsDeckVisible(rsDeckId))
50 {
51 // close the sidebar if it was already visible and showing this sidebar deck
52 const util::URL aURL(Tools::GetURL(".uno:Sidebar"));
53 css::uno::Reference<frame::XDispatch> xDispatch(Tools::GetDispatch(pViewFrame->GetFrame().GetFrameInterface(), aURL));
54 if (xDispatch.is())
55 xDispatch->dispatch(aURL, css::uno::Sequence<beans::PropertyValue>());
56 }
57 else
58 {
59 pController->OpenThenSwitchToDeck(rsDeckId);
60 pController->GetFocusManager().GrabFocusPanel();
61 }
62}
63
65 std::u16string_view rsPanelId,
66 const css::uno::Reference<frame::XFrame>& rxFrame, bool bFocus)
67{
69 if (!pController)
70 return;
71
72 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
73
74 if (!xPanelDescriptor)
75 return;
76
77 // This should be a lot more sophisticated:
78 // - Make the deck switching asynchronous
79 // - Make sure to use a context that really shows the panel
80
81 // All that is not necessary for the current use cases so lets
82 // keep it simple for the time being.
83 pController->OpenThenSwitchToDeck(xPanelDescriptor->msDeckId);
84
85 if (bFocus)
86 pController->GetFocusManager().GrabFocusPanel();
87}
88
90 std::u16string_view rsPanelId,
91 const css::uno::Reference<frame::XFrame>& rxFrame)
92{
94 if (!pController)
95 return;
96
97 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
98
99 if (!xPanelDescriptor)
100 return;
101
102 // This should be a lot more sophisticated:
103 // - Make the deck switching asynchronous
104 // - Make sure to use a context that really shows the panel
105
106 // All that is not necessary for the current use cases so lets
107 // keep it simple for the time being.
108 pController->OpenThenToggleDeck(xPanelDescriptor->msDeckId);
109}
110
112 std::u16string_view rsPanelId,
113 const css::uno::Reference<frame::XFrame>& rxFrame)
114{
116 if (!pController)
117 return false;
118
119 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
120 if (!xPanelDescriptor)
121 return false;
122
123 return pController->IsDeckVisible(xPanelDescriptor->msDeckId);
124}
125
126} // end of namespace sfx2::sidebar
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsVisible() const
Definition: childwin.cxx:501
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
Definition: frame.cxx:515
SfxChildWindow * GetChildWindow(sal_uInt16)
Definition: viewfrm.cxx:3567
SfxFrame & GetFrame() const
Definition: viewfrm.cxx:2782
void ShowChildWindow(sal_uInt16, bool bVisible=true)
Definition: viewfrm.cxx:3557
std::shared_ptr< PanelDescriptor > GetPanelDescriptor(std::u16string_view rsPanelId) const
static SidebarController * GetSidebarControllerForFrame(const css::uno::Reference< css::frame::XFrame > &rxFrame)
Return the SidebarController object that is associated with the given XFrame.
void OpenThenToggleDeck(const OUString &rsDeckId)
void OpenThenSwitchToDeck(std::u16string_view rsDeckId)
bool IsDeckVisible(std::u16string_view rsDeckId)
Returns true when the given deck is the currently visible deck.
static void ShowPanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame, bool bFocus=false)
Switch to the deck that contains the specified panel and make sure that the panel is visible (expande...
Definition: Sidebar.cxx:64
static bool IsPanelVisible(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame)
Definition: Sidebar.cxx:111
static void TogglePanel(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame)
Switch to the deck that contains the specified panel and toggle the visibility of the panel (expanded...
Definition: Sidebar.cxx:89
static void ShowDeck(std::u16string_view rsDeckId, SfxViewFrame *pViewFrame, bool bToggle)
Definition: Sidebar.cxx:34
static css::uno::Reference< css::frame::XDispatch > GetDispatch(const css::uno::Reference< css::frame::XFrame > &rxFrame, const css::util::URL &rURL)
Definition: Tools.cxx:83
static css::util::URL GetURL(const OUString &rsCommand)
Definition: Tools.cxx:71
Reference< XDispatch > xDispatch
URL aURL