LibreOffice Module sfx2 (master) 1
UnoPanel.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 */
10
11#include <sidebar/UnoPanel.hxx>
12
15
19#include <sfx2/sidebar/Deck.hxx>
21
22#include <utility>
23#include <vcl/svapp.hxx>
24
25using namespace css;
26using namespace ::sfx2::sidebar;
27
28SfxUnoPanel::SfxUnoPanel(uno::Reference<frame::XFrame> _xFrame, OUString panelId, OUString deckId):
29xFrame(std::move(_xFrame)),
30mPanelId(std::move(panelId)),
31mDeckId(std::move(deckId))
32{
33 SidebarController* pSidebarController = getSidebarController();
34
35 pSidebarController->CreateDeck(mDeckId); // creates deck object is not already
36 mpDeck = pSidebarController->GetResourceManager()->GetDeckDescriptor(mDeckId)->mpDeck;
37 mxPanel = mpDeck->GetPanel(mPanelId);
38}
39
41{
42 return SidebarController::GetSidebarControllerForFrame(xFrame);
43}
44
45OUString SAL_CALL SfxUnoPanel::getId()
46{
47 SolarMutexGuard aGuard;
48
49 return mPanelId;
50}
51
52OUString SAL_CALL SfxUnoPanel::getTitle()
53{
54 SolarMutexGuard aGuard;
55
56 auto xPanel = mxPanel.lock();
57 PanelTitleBar* pTitleBar = xPanel ? xPanel->GetTitleBar() : nullptr;
58 if (pTitleBar)
59 return pTitleBar->GetTitle();
60 else
61 return OUString();
62}
63
64void SAL_CALL SfxUnoPanel::setTitle( const OUString& newTitle )
65{
66 SolarMutexGuard aGuard;
67
68 SidebarController* pSidebarController = getSidebarController();
69 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
70
71 if (xPanelDescriptor)
72 {
73 xPanelDescriptor->msTitle = newTitle;
74 auto xPanel = mxPanel.lock();
75 PanelTitleBar* pTitleBar = xPanel ? xPanel->GetTitleBar() : nullptr;
76 if (pTitleBar)
77 pTitleBar->SetTitle(newTitle);
78 }
79}
80
82{
83 SolarMutexGuard aGuard;
84
85 auto xPanel = mxPanel.lock();
86 return xPanel && xPanel->IsExpanded();
87}
88
89
90void SAL_CALL SfxUnoPanel::expand( const sal_Bool bCollapseOther )
91{
92
93 SolarMutexGuard aGuard;
94
95 auto xPanel = mxPanel.lock();
96 if (xPanel)
97 xPanel->SetExpanded(true);
98
99 if (bCollapseOther)
100 {
101 SharedPanelContainer aPanels = mpDeck->GetPanels();
102 for (auto const& panel : aPanels)
103 {
104 if (! panel->HasIdPredicate(mPanelId))
105 panel->SetExpanded(false);
106 }
107 }
108
109 SidebarController* pSidebarController = getSidebarController();
110 pSidebarController->NotifyResize();
111
112}
113
115{
116 SolarMutexGuard aGuard;
117
118 auto xPanel = mxPanel.lock();
119 if (xPanel)
120 xPanel->SetExpanded(false);
121 SidebarController* pSidebarController = getSidebarController();
122 pSidebarController->NotifyResize();
123}
124
125uno::Reference<awt::XWindow> SAL_CALL SfxUnoPanel::getDialog()
126{
127 SolarMutexGuard aGuard;
128
129 auto xPanel = mxPanel.lock();
130 return xPanel ? xPanel->GetElementWindow() : nullptr;
131}
132
133sal_Int32 SAL_CALL SfxUnoPanel::getOrderIndex()
134{
135 SolarMutexGuard aGuard;
136 SidebarController* pSidebarController = getSidebarController();
137
138 sal_Int32 index = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId)->mnOrderIndex;
139 return index;
140}
141
142void SAL_CALL SfxUnoPanel::setOrderIndex( const sal_Int32 newOrderIndex )
143{
144 SolarMutexGuard aGuard;
145 SidebarController* pSidebarController = getSidebarController();
146
147 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
148
149 if (xPanelDescriptor)
150 {
151 xPanelDescriptor->mnOrderIndex = newOrderIndex;
152 // update the sidebar
153 pSidebarController->NotifyResize();
154 }
155}
156
158{
159 SolarMutexGuard aGuard;
160 SidebarController* pSidebarController = getSidebarController();
161
162 ResourceManager::PanelContextDescriptorContainer aPanels = pSidebarController->GetMatchingPanels(mDeckId);
163
164 sal_Int32 curOrderIndex = getOrderIndex();
165 sal_Int32 minIndex = GetMinOrderIndex(aPanels);
166
167 if (curOrderIndex != minIndex) // is current panel already in place ?
168 {
169 minIndex -= 1;
170 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
171 if (xPanelDescriptor)
172 {
173 xPanelDescriptor->mnOrderIndex = minIndex;
174 // update the sidebar
175 pSidebarController->NotifyResize();
176 }
177 }
178}
179
181{
182 SolarMutexGuard aGuard;
183 SidebarController* pSidebarController = getSidebarController();
184
185 ResourceManager::PanelContextDescriptorContainer aPanels = pSidebarController->GetMatchingPanels(mDeckId);
186
187 sal_Int32 curOrderIndex = getOrderIndex();
188 sal_Int32 maxIndex = GetMaxOrderIndex(aPanels);
189
190 if (curOrderIndex != maxIndex) // is current panel already in place ?
191 {
192 maxIndex += 1;
193 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
194 if (xPanelDescriptor)
195 {
196 xPanelDescriptor->mnOrderIndex = maxIndex;
197 // update the sidebar
198 pSidebarController->NotifyResize();
199 }
200 }
201}
202
203void SAL_CALL SfxUnoPanel::moveUp()
204{
205 SolarMutexGuard aGuard;
206 SidebarController* pSidebarController = getSidebarController();
207
208 // Search for previous panel OrderIndex
209 ResourceManager::PanelContextDescriptorContainer aPanels = pSidebarController->GetMatchingPanels(mDeckId);
210
211 sal_Int32 curOrderIndex = getOrderIndex();
212 sal_Int32 previousIndex = GetMinOrderIndex(aPanels);
213
214 for (auto const& panel : aPanels)
215 {
216 sal_Int32 index = pSidebarController->GetResourceManager()->GetPanelDescriptor(panel.msId)->mnOrderIndex;
217 if( index < curOrderIndex && index > previousIndex)
218 previousIndex = index;
219 }
220
221 if (curOrderIndex != previousIndex) // is current panel already in place ?
222 {
223 previousIndex -= 1;
224 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
225 if (xPanelDescriptor)
226 {
227 xPanelDescriptor->mnOrderIndex = previousIndex;
228 // update the sidebar
229 pSidebarController->NotifyResize();
230 }
231 }
232}
233
235{
236 SolarMutexGuard aGuard;
237 SidebarController* pSidebarController = getSidebarController();
238
239 ResourceManager::PanelContextDescriptorContainer aPanels = pSidebarController->GetMatchingPanels(mDeckId);
240
241 // Search for next panel OrderIndex
242 sal_Int32 curOrderIndex = getOrderIndex();
243 sal_Int32 nextIndex = GetMaxOrderIndex(aPanels);
244
245 for (auto const& panel : aPanels)
246 {
247 sal_Int32 index = pSidebarController->GetResourceManager()->GetPanelDescriptor(panel.msId)->mnOrderIndex;
248 if( index > curOrderIndex && index < nextIndex)
249 nextIndex = index;
250 }
251
252 if (curOrderIndex != nextIndex) // is current panel already in place ?
253 {
254 nextIndex += 1;
255 std::shared_ptr<PanelDescriptor> xPanelDescriptor = pSidebarController->GetResourceManager()->GetPanelDescriptor(mPanelId);
256 if (xPanelDescriptor)
257 {
258 xPanelDescriptor->mnOrderIndex = nextIndex;
259 // update the sidebar
260 pSidebarController->NotifyResize();
261 }
262 }
263}
264
265sal_Int32 SfxUnoPanel::GetMinOrderIndex(const ResourceManager::PanelContextDescriptorContainer& rPanels)
266{
267 SidebarController* pSidebarController = getSidebarController();
268
269 sal_Int32 minIndex = pSidebarController->GetResourceManager()->GetPanelDescriptor(rPanels.begin()->msId)->mnOrderIndex;
270
271 for (auto const& panel : rPanels)
272 {
273 sal_Int32 index = pSidebarController->GetResourceManager()->GetPanelDescriptor(panel.msId)->mnOrderIndex;
274 if(minIndex > index)
275 minIndex = index;
276 }
277 return minIndex;
278}
279
280sal_Int32 SfxUnoPanel::GetMaxOrderIndex(const ResourceManager::PanelContextDescriptorContainer& rPanels)
281{
282 SidebarController* pSidebarController = getSidebarController();
283
284 sal_Int32 maxIndex = pSidebarController->GetResourceManager()->GetPanelDescriptor(rPanels.begin()->msId)->mnOrderIndex;
285
286 for (auto const& panel : rPanels)
287 {
288 sal_Int32 index = pSidebarController->GetResourceManager()->GetPanelDescriptor(panel.msId)->mnOrderIndex;
289 if(maxIndex < index)
290 maxIndex = index;
291 }
292 return maxIndex;
293}
294
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclPtr< sfx2::sidebar::Deck > mpDeck
Definition: UnoPanel.hxx:62
virtual void SAL_CALL collapse() override
Definition: UnoPanel.cxx:114
virtual sal_Int32 SAL_CALL getOrderIndex() override
Definition: UnoPanel.cxx:133
virtual sal_Bool SAL_CALL isExpanded() override
Definition: UnoPanel.cxx:81
virtual void SAL_CALL expand(const sal_Bool bCollapseOther) override
Definition: UnoPanel.cxx:90
sfx2::sidebar::SidebarController * getSidebarController()
Definition: UnoPanel.cxx:40
virtual void SAL_CALL moveDown() override
Definition: UnoPanel.cxx:234
virtual void SAL_CALL setOrderIndex(const sal_Int32 newOrderIndex) override
Definition: UnoPanel.cxx:142
virtual OUString SAL_CALL getId() override
Definition: UnoPanel.cxx:45
const OUString mDeckId
Definition: UnoPanel.hxx:60
const OUString mPanelId
Definition: UnoPanel.hxx:59
SfxUnoPanel(css::uno::Reference< css::frame::XFrame >, OUString, OUString)
Definition: UnoPanel.cxx:28
std::weak_ptr< sfx2::sidebar::Panel > mxPanel
Definition: UnoPanel.hxx:63
virtual void SAL_CALL moveUp() override
Definition: UnoPanel.cxx:203
virtual void SAL_CALL moveFirst() override
Definition: UnoPanel.cxx:157
const css::uno::Reference< css::frame::XFrame > xFrame
Definition: UnoPanel.hxx:56
virtual OUString SAL_CALL getTitle() override
Definition: UnoPanel.cxx:52
sal_Int32 GetMaxOrderIndex(const sfx2::sidebar::ResourceManager::PanelContextDescriptorContainer &rPanels)
Definition: UnoPanel.cxx:280
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getDialog() override
Definition: UnoPanel.cxx:125
virtual void SAL_CALL moveLast() override
Definition: UnoPanel.cxx:180
virtual void SAL_CALL setTitle(const OUString &newTitle) override
Definition: UnoPanel.cxx:64
sal_Int32 GetMinOrderIndex(const sfx2::sidebar::ResourceManager::PanelContextDescriptorContainer &rPanels)
Definition: UnoPanel.cxx:265
index
std::vector< std::shared_ptr< Panel > > SharedPanelContainer
Definition: Panel.hxx:118
Reference< XFrame > xFrame
unsigned char sal_Bool