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/Sidebar.hxx>
21 #include <sfx2/sidebar/SidebarController.hxx>
22 #include <sfx2/sidebar/ResourceManager.hxx>
23 #include <sfx2/sidebar/SidebarDockingWindow.hxx>
24 #include <sidebar/PanelDescriptor.hxx>
25 #include <sidebar/Tools.hxx>
26 #include <sfx2/sidebar/FocusManager.hxx>
27 #include <sfx2/childwin.hxx>
28 #include <sfx2/sfxsids.hrc>
29 #include <sfx2/viewsh.hxx>
30 #include <com/sun/star/frame/XDispatch.hpp>
34 namespace sfx2::sidebar
{
36 void Sidebar::ShowDeck(std::u16string_view rsDeckId
, SfxViewFrame
* pViewFrame
, bool bToggle
)
41 SfxChildWindow
* pSidebarChildWindow
= pViewFrame
->GetChildWindow(SID_SIDEBAR
);
42 bool bInitiallyVisible
= pSidebarChildWindow
&& pSidebarChildWindow
->IsVisible();
43 if (!bInitiallyVisible
)
44 pViewFrame
->ShowChildWindow(SID_SIDEBAR
);
46 SidebarController
* pController
=
47 SidebarController::GetSidebarControllerForFrame(pViewFrame
->GetFrame().GetFrameInterface());
51 if (bToggle
&& bInitiallyVisible
&& pController
->IsDeckVisible(rsDeckId
))
53 // close the sidebar if it was already visible and showing this sidebar deck
54 const util::URL
aURL(Tools::GetURL(u
".uno:Sidebar"_ustr
));
55 css::uno::Reference
<frame::XDispatch
> xDispatch(Tools::GetDispatch(pViewFrame
->GetFrame().GetFrameInterface(), aURL
));
57 xDispatch
->dispatch(aURL
, css::uno::Sequence
<beans::PropertyValue
>());
61 pController
->OpenThenSwitchToDeck(rsDeckId
);
62 pController
->GetFocusManager().GrabFocusPanel();
66 void Sidebar::ShowPanel (
67 std::u16string_view rsPanelId
,
68 const css::uno::Reference
<frame::XFrame
>& rxFrame
, bool bFocus
)
70 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
74 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
76 if (!xPanelDescriptor
)
79 // This should be a lot more sophisticated:
80 // - Make the deck switching asynchronous
81 // - Make sure to use a context that really shows the panel
83 // All that is not necessary for the current use cases so let's
84 // keep it simple for the time being.
85 pController
->OpenThenSwitchToDeck(xPanelDescriptor
->msDeckId
);
88 pController
->GetFocusManager().GrabFocusPanel();
91 void Sidebar::TogglePanel (
92 std::u16string_view rsPanelId
,
93 const css::uno::Reference
<frame::XFrame
>& rxFrame
)
95 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
99 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
101 if (!xPanelDescriptor
)
104 // This should be a lot more sophisticated:
105 // - Make the deck switching asynchronous
106 // - Make sure to use a context that really shows the panel
108 // All that is not necessary for the current use cases so let's
109 // keep it simple for the time being.
110 pController
->OpenThenToggleDeck(xPanelDescriptor
->msDeckId
);
113 bool Sidebar::IsPanelVisible(
114 std::u16string_view rsPanelId
,
115 const css::uno::Reference
<frame::XFrame
>& rxFrame
)
117 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
121 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
122 if (!xPanelDescriptor
)
125 return pController
->IsDeckVisible(xPanelDescriptor
->msDeckId
);
128 bool Sidebar::Setup(std::u16string_view sidebarDeckId
)
130 SfxViewShell
* pViewShell
= SfxViewShell::Current();
131 SfxViewFrame
* pViewFrame
= pViewShell
? &pViewShell
->GetViewFrame() : nullptr;
134 if (!pViewFrame
->GetChildWindow(SID_SIDEBAR
))
135 pViewFrame
->SetChildWindow(SID_SIDEBAR
, false /* create it */, true /* focus */);
137 pViewFrame
->ShowChildWindow(SID_SIDEBAR
, true);
139 // Force synchronous population of panels
140 SfxChildWindow
*pChild
= pViewFrame
->GetChildWindow(SID_SIDEBAR
);
144 auto pDockingWin
= dynamic_cast<sfx2::sidebar::SidebarDockingWindow
*>(pChild
->GetWindow());
148 pViewFrame
->ShowChildWindow( SID_SIDEBAR
);
150 const rtl::Reference
<sfx2::sidebar::SidebarController
>& xController
151 = pDockingWin
->GetOrCreateSidebarController();
153 xController
->FadeIn();
154 xController
->RequestOpenDeck();
156 if (!sidebarDeckId
.empty())
158 xController
->SwitchToDeck(sidebarDeckId
);
162 xController
->SwitchToDefaultDeck();
165 pDockingWin
->SyncUpdate();
172 } // end of namespace sfx2::sidebar
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */