Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / sidebar / Sidebar.cxx
blobccd2fbc589d2af55b92d63617af8ceee9e811d3c
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/Sidebar.hxx>
21 #include <sfx2/sidebar/SidebarController.hxx>
22 #include <sfx2/sidebar/ResourceManager.hxx>
23 #include <sidebar/PanelDescriptor.hxx>
24 #include <sidebar/Tools.hxx>
25 #include <sfx2/sidebar/FocusManager.hxx>
26 #include <sfx2/childwin.hxx>
27 #include <sfx2/sfxsids.hrc>
28 #include <com/sun/star/frame/XDispatch.hpp>
30 using namespace css;
32 namespace sfx2::sidebar {
34 void Sidebar::ToggleDeck(const OUString& rsDeckId, SfxViewFrame* pViewFrame)
36 if (!pViewFrame)
37 return;
39 SfxChildWindow* pSidebarChildWindow = pViewFrame->GetChildWindow(SID_SIDEBAR);
40 bool bInitiallyVisible = pSidebarChildWindow && pSidebarChildWindow->IsVisible();
41 if (!bInitiallyVisible)
42 pViewFrame->ShowChildWindow(SID_SIDEBAR);
44 if (SidebarController* pController =
45 SidebarController::GetSidebarControllerForFrame(pViewFrame->GetFrame().GetFrameInterface()))
47 if (bInitiallyVisible && pController->IsDeckVisible(rsDeckId))
49 // close the sidebar if it was already visible and showing this sidebar deck
50 const util::URL aURL(Tools::GetURL(".uno:Sidebar"));
51 css::uno::Reference<frame::XDispatch> xDispatch(Tools::GetDispatch(pViewFrame->GetFrame().GetFrameInterface(), aURL));
52 if (xDispatch.is())
53 xDispatch->dispatch(aURL, css::uno::Sequence<beans::PropertyValue>());
55 else
57 pController->OpenThenSwitchToDeck(rsDeckId);
58 pController->GetFocusManager().GrabFocusPanel();
63 void Sidebar::ShowPanel (
64 const OUString& rsPanelId,
65 const css::uno::Reference<frame::XFrame>& rxFrame, bool bFocus)
67 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
68 if (!pController)
69 return;
71 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
73 if (!xPanelDescriptor)
74 return;
76 // This should be a lot more sophisticated:
77 // - Make the deck switching asynchronous
78 // - Make sure to use a context that really shows the panel
80 // All that is not necessary for the current use cases so lets
81 // keep it simple for the time being.
82 pController->OpenThenSwitchToDeck(xPanelDescriptor->msDeckId);
84 if (bFocus)
85 pController->GetFocusManager().GrabFocusPanel();
88 void Sidebar::TogglePanel (
89 const OUString& rsPanelId,
90 const css::uno::Reference<frame::XFrame>& rxFrame)
92 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
93 if (!pController)
94 return;
96 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
98 if (!xPanelDescriptor)
99 return;
101 // This should be a lot more sophisticated:
102 // - Make the deck switching asynchronous
103 // - Make sure to use a context that really shows the panel
105 // All that is not necessary for the current use cases so lets
106 // keep it simple for the time being.
107 pController->OpenThenToggleDeck(xPanelDescriptor->msDeckId);
110 bool Sidebar::IsPanelVisible(
111 const OUString& rsPanelId,
112 const css::uno::Reference<frame::XFrame>& rxFrame)
114 SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
115 if (!pController)
116 return false;
118 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
119 if (!xPanelDescriptor)
120 return false;
122 return pController->IsDeckVisible(xPanelDescriptor->msDeckId);
125 } // end of namespace sfx2::sidebar
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */