/src/libreoffice/sfx2/source/sidebar/Sidebar.cxx
Line | Count | Source |
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 | | |
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> |
31 | | |
32 | | using namespace css; |
33 | | |
34 | | namespace sfx2::sidebar { |
35 | | |
36 | | void Sidebar::ShowDeck(std::u16string_view rsDeckId, SfxViewFrame* pViewFrame, bool bToggle) |
37 | 0 | { |
38 | 0 | if (!pViewFrame) |
39 | 0 | return; |
40 | | |
41 | 0 | SfxChildWindow* pSidebarChildWindow = pViewFrame->GetChildWindow(SID_SIDEBAR); |
42 | 0 | bool bInitiallyVisible = pSidebarChildWindow && pSidebarChildWindow->IsVisible(); |
43 | 0 | if (!bInitiallyVisible) |
44 | 0 | pViewFrame->ShowChildWindow(SID_SIDEBAR); |
45 | |
|
46 | 0 | SidebarController* pController = |
47 | 0 | SidebarController::GetSidebarControllerForFrame(pViewFrame->GetFrame().GetFrameInterface()); |
48 | 0 | if (!pController) |
49 | 0 | return; |
50 | | |
51 | 0 | if (bToggle && bInitiallyVisible && pController->IsDeckVisible(rsDeckId)) |
52 | 0 | { |
53 | | // close the sidebar if it was already visible and showing this sidebar deck |
54 | 0 | const util::URL aURL(Tools::GetURL(u".uno:Sidebar"_ustr)); |
55 | 0 | css::uno::Reference<frame::XDispatch> xDispatch(Tools::GetDispatch(pViewFrame->GetFrame().GetFrameInterface(), aURL)); |
56 | 0 | if (xDispatch.is()) |
57 | 0 | xDispatch->dispatch(aURL, css::uno::Sequence<beans::PropertyValue>()); |
58 | 0 | } |
59 | 0 | else |
60 | 0 | { |
61 | 0 | pController->OpenThenSwitchToDeck(rsDeckId); |
62 | 0 | pController->GetFocusManager().GrabFocusPanel(); |
63 | 0 | } |
64 | 0 | } |
65 | | |
66 | | void Sidebar::ShowPanel ( |
67 | | std::u16string_view rsPanelId, |
68 | | const css::uno::Reference<frame::XFrame>& rxFrame, bool bFocus) |
69 | 0 | { |
70 | 0 | SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame); |
71 | 0 | if (!pController) |
72 | 0 | return; |
73 | | |
74 | 0 | std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId); |
75 | |
|
76 | 0 | if (!xPanelDescriptor) |
77 | 0 | return; |
78 | | |
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 |
82 | | |
83 | | // All that is not necessary for the current use cases so let's |
84 | | // keep it simple for the time being. |
85 | 0 | pController->OpenThenSwitchToDeck(xPanelDescriptor->msDeckId); |
86 | |
|
87 | 0 | if (bFocus) |
88 | 0 | pController->GetFocusManager().GrabFocusPanel(); |
89 | 0 | } |
90 | | |
91 | | void Sidebar::TogglePanel ( |
92 | | std::u16string_view rsPanelId, |
93 | | const css::uno::Reference<frame::XFrame>& rxFrame) |
94 | 0 | { |
95 | 0 | SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame); |
96 | 0 | if (!pController) |
97 | 0 | return; |
98 | | |
99 | 0 | std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId); |
100 | |
|
101 | 0 | if (!xPanelDescriptor) |
102 | 0 | return; |
103 | | |
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 |
107 | | |
108 | | // All that is not necessary for the current use cases so let's |
109 | | // keep it simple for the time being. |
110 | 0 | pController->OpenThenToggleDeck(xPanelDescriptor->msDeckId); |
111 | 0 | } |
112 | | |
113 | | bool Sidebar::IsPanelVisible( |
114 | | std::u16string_view rsPanelId, |
115 | | const css::uno::Reference<frame::XFrame>& rxFrame) |
116 | 0 | { |
117 | 0 | SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame); |
118 | 0 | if (!pController) |
119 | 0 | return false; |
120 | | |
121 | 0 | std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId); |
122 | 0 | if (!xPanelDescriptor) |
123 | 0 | return false; |
124 | | |
125 | 0 | return pController->IsDeckVisible(xPanelDescriptor->msDeckId); |
126 | 0 | } |
127 | | |
128 | | bool Sidebar::Setup(std::u16string_view sidebarDeckId) |
129 | 0 | { |
130 | 0 | SfxViewShell* pViewShell = SfxViewShell::Current(); |
131 | 0 | SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr; |
132 | 0 | if (pViewFrame) |
133 | 0 | { |
134 | 0 | if (!pViewFrame->GetChildWindow(SID_SIDEBAR)) |
135 | 0 | pViewFrame->SetChildWindow(SID_SIDEBAR, false /* create it */, true /* focus */); |
136 | |
|
137 | 0 | pViewFrame->ShowChildWindow(SID_SIDEBAR, true); |
138 | | |
139 | | // Force synchronous population of panels |
140 | 0 | SfxChildWindow *pChild = pViewFrame->GetChildWindow(SID_SIDEBAR); |
141 | 0 | if (!pChild) |
142 | 0 | return false; |
143 | | |
144 | 0 | auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pChild->GetWindow()); |
145 | 0 | if (!pDockingWin) |
146 | 0 | return false; |
147 | | |
148 | 0 | pViewFrame->ShowChildWindow( SID_SIDEBAR ); |
149 | |
|
150 | 0 | const rtl::Reference<sfx2::sidebar::SidebarController>& xController |
151 | 0 | = pDockingWin->GetOrCreateSidebarController(); |
152 | |
|
153 | 0 | xController->FadeIn(); |
154 | 0 | xController->RequestOpenDeck(); |
155 | |
|
156 | 0 | if (!sidebarDeckId.empty()) |
157 | 0 | { |
158 | 0 | xController->SwitchToDeck(sidebarDeckId); |
159 | 0 | } |
160 | 0 | else |
161 | 0 | { |
162 | 0 | xController->SwitchToDefaultDeck(); |
163 | 0 | } |
164 | |
|
165 | 0 | pDockingWin->SyncUpdate(); |
166 | 0 | return true; |
167 | 0 | } |
168 | 0 | else |
169 | 0 | return false; |
170 | 0 | } |
171 | | |
172 | | } // end of namespace sfx2::sidebar |
173 | | |
174 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |