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 <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>
32 namespace sfx2::sidebar
{
34 void Sidebar::ToggleDeck(std::u16string_view rsDeckId
, SfxViewFrame
* pViewFrame
)
39 SfxChildWindow
* pSidebarChildWindow
= pViewFrame
->GetChildWindow(SID_SIDEBAR
);
40 bool bInitiallyVisible
= pSidebarChildWindow
&& pSidebarChildWindow
->IsVisible();
41 if (!bInitiallyVisible
)
42 pViewFrame
->ShowChildWindow(SID_SIDEBAR
);
44 SidebarController
* pController
=
45 SidebarController::GetSidebarControllerForFrame(pViewFrame
->GetFrame().GetFrameInterface());
49 if (bInitiallyVisible
&& pController
->IsDeckVisible(rsDeckId
))
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
));
55 xDispatch
->dispatch(aURL
, css::uno::Sequence
<beans::PropertyValue
>());
59 pController
->OpenThenSwitchToDeck(rsDeckId
);
60 pController
->GetFocusManager().GrabFocusPanel();
64 void Sidebar::ShowPanel (
65 std::u16string_view rsPanelId
,
66 const css::uno::Reference
<frame::XFrame
>& rxFrame
, bool bFocus
)
68 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
72 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
74 if (!xPanelDescriptor
)
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
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
);
86 pController
->GetFocusManager().GrabFocusPanel();
89 void Sidebar::TogglePanel (
90 std::u16string_view rsPanelId
,
91 const css::uno::Reference
<frame::XFrame
>& rxFrame
)
93 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
97 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
99 if (!xPanelDescriptor
)
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
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
);
111 bool Sidebar::IsPanelVisible(
112 std::u16string_view rsPanelId
,
113 const css::uno::Reference
<frame::XFrame
>& rxFrame
)
115 SidebarController
* pController
= SidebarController::GetSidebarControllerForFrame(rxFrame
);
119 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pController
->GetResourceManager()->GetPanelDescriptor(rsPanelId
);
120 if (!xPanelDescriptor
)
123 return pController
->IsDeckVisible(xPanelDescriptor
->msDeckId
);
126 } // end of namespace sfx2::sidebar
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */