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/.
11 #include <sidebar/UnoPanel.hxx>
13 #include <sfx2/sidebar/ResourceManager.hxx>
14 #include <sfx2/sidebar/SidebarController.hxx>
16 #include <sidebar/PanelDescriptor.hxx>
17 #include <sidebar/PanelTitleBar.hxx>
18 #include <sfx2/sidebar/Panel.hxx>
19 #include <sfx2/sidebar/Deck.hxx>
20 #include <sidebar/DeckDescriptor.hxx>
23 #include <vcl/svapp.hxx>
26 using namespace ::sfx2::sidebar
;
28 SfxUnoPanel::SfxUnoPanel(uno::Reference
<frame::XFrame
> _xFrame
, OUString panelId
, OUString deckId
):
29 xFrame(std::move(_xFrame
)),
30 mPanelId(std::move(panelId
)),
31 mDeckId(std::move(deckId
))
33 SidebarController
* pSidebarController
= getSidebarController();
35 pSidebarController
->CreateDeck(mDeckId
); // creates deck object is not already
36 mpDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
37 mxPanel
= mpDeck
->GetPanel(mPanelId
);
40 SidebarController
* SfxUnoPanel::getSidebarController()
42 return SidebarController::GetSidebarControllerForFrame(xFrame
);
45 OUString SAL_CALL
SfxUnoPanel::getId()
47 SolarMutexGuard aGuard
;
52 OUString SAL_CALL
SfxUnoPanel::getTitle()
54 SolarMutexGuard aGuard
;
56 auto xPanel
= mxPanel
.lock();
57 PanelTitleBar
* pTitleBar
= xPanel
? xPanel
->GetTitleBar() : nullptr;
59 return pTitleBar
->GetTitle();
64 void SAL_CALL
SfxUnoPanel::setTitle( const OUString
& newTitle
)
66 SolarMutexGuard aGuard
;
68 SidebarController
* pSidebarController
= getSidebarController();
69 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
73 xPanelDescriptor
->msTitle
= newTitle
;
74 auto xPanel
= mxPanel
.lock();
75 PanelTitleBar
* pTitleBar
= xPanel
? xPanel
->GetTitleBar() : nullptr;
77 pTitleBar
->SetTitle(newTitle
);
81 sal_Bool SAL_CALL
SfxUnoPanel::isExpanded()
83 SolarMutexGuard aGuard
;
85 auto xPanel
= mxPanel
.lock();
86 return xPanel
&& xPanel
->IsExpanded();
90 void SAL_CALL
SfxUnoPanel::expand( const sal_Bool bCollapseOther
)
93 SolarMutexGuard aGuard
;
95 auto xPanel
= mxPanel
.lock();
97 xPanel
->SetExpanded(true);
101 SharedPanelContainer aPanels
= mpDeck
->GetPanels();
102 for (auto const& panel
: aPanels
)
104 if (! panel
->HasIdPredicate(mPanelId
))
105 panel
->SetExpanded(false);
109 SidebarController
* pSidebarController
= getSidebarController();
110 pSidebarController
->NotifyResize();
114 void SAL_CALL
SfxUnoPanel::collapse()
116 SolarMutexGuard aGuard
;
118 auto xPanel
= mxPanel
.lock();
120 xPanel
->SetExpanded(false);
121 SidebarController
* pSidebarController
= getSidebarController();
122 pSidebarController
->NotifyResize();
125 uno::Reference
<awt::XWindow
> SAL_CALL
SfxUnoPanel::getDialog()
127 SolarMutexGuard aGuard
;
129 auto xPanel
= mxPanel
.lock();
130 return xPanel
? xPanel
->GetElementWindow() : nullptr;
133 sal_Int32 SAL_CALL
SfxUnoPanel::getOrderIndex()
135 SolarMutexGuard aGuard
;
136 SidebarController
* pSidebarController
= getSidebarController();
138 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
)->mnOrderIndex
;
142 void SAL_CALL
SfxUnoPanel::setOrderIndex( const sal_Int32 newOrderIndex
)
144 SolarMutexGuard aGuard
;
145 SidebarController
* pSidebarController
= getSidebarController();
147 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
149 if (xPanelDescriptor
)
151 xPanelDescriptor
->mnOrderIndex
= newOrderIndex
;
152 // update the sidebar
153 pSidebarController
->NotifyResize();
157 void SAL_CALL
SfxUnoPanel::moveFirst()
159 SolarMutexGuard aGuard
;
160 SidebarController
* pSidebarController
= getSidebarController();
162 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
164 sal_Int32 curOrderIndex
= getOrderIndex();
165 sal_Int32 minIndex
= GetMinOrderIndex(aPanels
);
167 if (curOrderIndex
!= minIndex
) // is current panel already in place ?
170 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
171 if (xPanelDescriptor
)
173 xPanelDescriptor
->mnOrderIndex
= minIndex
;
174 // update the sidebar
175 pSidebarController
->NotifyResize();
180 void SAL_CALL
SfxUnoPanel::moveLast()
182 SolarMutexGuard aGuard
;
183 SidebarController
* pSidebarController
= getSidebarController();
185 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
187 sal_Int32 curOrderIndex
= getOrderIndex();
188 sal_Int32 maxIndex
= GetMaxOrderIndex(aPanels
);
190 if (curOrderIndex
!= maxIndex
) // is current panel already in place ?
193 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
194 if (xPanelDescriptor
)
196 xPanelDescriptor
->mnOrderIndex
= maxIndex
;
197 // update the sidebar
198 pSidebarController
->NotifyResize();
203 void SAL_CALL
SfxUnoPanel::moveUp()
205 SolarMutexGuard aGuard
;
206 SidebarController
* pSidebarController
= getSidebarController();
208 // Search for previous panel OrderIndex
209 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
211 sal_Int32 curOrderIndex
= getOrderIndex();
212 sal_Int32 previousIndex
= GetMinOrderIndex(aPanels
);
214 for (auto const& panel
: aPanels
)
216 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
217 if( index
< curOrderIndex
&& index
> previousIndex
)
218 previousIndex
= index
;
221 if (curOrderIndex
!= previousIndex
) // is current panel already in place ?
224 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
225 if (xPanelDescriptor
)
227 xPanelDescriptor
->mnOrderIndex
= previousIndex
;
228 // update the sidebar
229 pSidebarController
->NotifyResize();
234 void SAL_CALL
SfxUnoPanel::moveDown()
236 SolarMutexGuard aGuard
;
237 SidebarController
* pSidebarController
= getSidebarController();
239 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
241 // Search for next panel OrderIndex
242 sal_Int32 curOrderIndex
= getOrderIndex();
243 sal_Int32 nextIndex
= GetMaxOrderIndex(aPanels
);
245 for (auto const& panel
: aPanels
)
247 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
248 if( index
> curOrderIndex
&& index
< nextIndex
)
252 if (curOrderIndex
!= nextIndex
) // is current panel already in place ?
255 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
256 if (xPanelDescriptor
)
258 xPanelDescriptor
->mnOrderIndex
= nextIndex
;
259 // update the sidebar
260 pSidebarController
->NotifyResize();
265 sal_Int32
SfxUnoPanel::GetMinOrderIndex(const ResourceManager::PanelContextDescriptorContainer
& rPanels
)
267 SidebarController
* pSidebarController
= getSidebarController();
269 sal_Int32 minIndex
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(rPanels
.begin()->msId
)->mnOrderIndex
;
271 for (auto const& panel
: rPanels
)
273 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
280 sal_Int32
SfxUnoPanel::GetMaxOrderIndex(const ResourceManager::PanelContextDescriptorContainer
& rPanels
)
282 SidebarController
* pSidebarController
= getSidebarController();
284 sal_Int32 maxIndex
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(rPanels
.begin()->msId
)->mnOrderIndex
;
286 for (auto const& panel
: rPanels
)
288 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */