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>
22 #include <vcl/svapp.hxx>
25 using namespace ::sfx2::sidebar
;
27 SfxUnoPanel::SfxUnoPanel(const uno::Reference
<frame::XFrame
>& rFrame
, const OUString
& panelId
, const OUString
& deckId
):
34 SidebarController
* pSidebarController
= getSidebarController();
36 pSidebarController
->CreateDeck(mDeckId
); // creates deck object is not already
37 mpDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
38 mpPanel
= mpDeck
->GetPanel(mPanelId
);
41 SidebarController
* SfxUnoPanel::getSidebarController()
43 return SidebarController::GetSidebarControllerForFrame(xFrame
);
46 OUString SAL_CALL
SfxUnoPanel::getId()
48 SolarMutexGuard aGuard
;
53 OUString SAL_CALL
SfxUnoPanel::getTitle()
55 SolarMutexGuard aGuard
;
57 VclPtr
<PanelTitleBar
> pTitleBar
= mpPanel
->GetTitleBar();
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 VclPtr
<PanelTitleBar
> pTitleBar
= mpPanel
->GetTitleBar();
76 pTitleBar
->SetTitle(newTitle
);
80 sal_Bool SAL_CALL
SfxUnoPanel::isExpanded()
82 SolarMutexGuard aGuard
;
84 return mpPanel
->IsExpanded();
88 void SAL_CALL
SfxUnoPanel::expand( const sal_Bool bCollapseOther
)
91 SolarMutexGuard aGuard
;
93 mpPanel
->SetExpanded(true);
97 SharedPanelContainer aPanels
= mpDeck
->GetPanels();
98 for (auto const& panel
: aPanels
)
100 if (! panel
->HasIdPredicate(mPanelId
))
101 panel
->SetExpanded(false);
105 SidebarController
* pSidebarController
= getSidebarController();
106 pSidebarController
->NotifyResize();
110 void SAL_CALL
SfxUnoPanel::collapse()
112 SolarMutexGuard aGuard
;
114 mpPanel
->SetExpanded(false);
115 SidebarController
* pSidebarController
= getSidebarController();
116 pSidebarController
->NotifyResize();
119 uno::Reference
<awt::XWindow
> SAL_CALL
SfxUnoPanel::getDialog()
121 SolarMutexGuard aGuard
;
123 return mpPanel
->GetElementWindow();
127 sal_Int32 SAL_CALL
SfxUnoPanel::getOrderIndex()
129 SolarMutexGuard aGuard
;
130 SidebarController
* pSidebarController
= getSidebarController();
132 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
)->mnOrderIndex
;
136 void SAL_CALL
SfxUnoPanel::setOrderIndex( const sal_Int32 newOrderIndex
)
138 SolarMutexGuard aGuard
;
139 SidebarController
* pSidebarController
= getSidebarController();
141 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
143 if (xPanelDescriptor
)
145 xPanelDescriptor
->mnOrderIndex
= newOrderIndex
;
146 // update the sidebar
147 pSidebarController
->NotifyResize();
151 void SAL_CALL
SfxUnoPanel::moveFirst()
153 SolarMutexGuard aGuard
;
154 SidebarController
* pSidebarController
= getSidebarController();
156 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
158 sal_Int32 curOrderIndex
= getOrderIndex();
159 sal_Int32 minIndex
= GetMinOrderIndex(aPanels
);
161 if (curOrderIndex
!= minIndex
) // is current panel already in place ?
164 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
165 if (xPanelDescriptor
)
167 xPanelDescriptor
->mnOrderIndex
= minIndex
;
168 // update the sidebar
169 pSidebarController
->NotifyResize();
174 void SAL_CALL
SfxUnoPanel::moveLast()
176 SolarMutexGuard aGuard
;
177 SidebarController
* pSidebarController
= getSidebarController();
179 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
181 sal_Int32 curOrderIndex
= getOrderIndex();
182 sal_Int32 maxIndex
= GetMaxOrderIndex(aPanels
);
184 if (curOrderIndex
!= maxIndex
) // is current panel already in place ?
187 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
188 if (xPanelDescriptor
)
190 xPanelDescriptor
->mnOrderIndex
= maxIndex
;
191 // update the sidebar
192 pSidebarController
->NotifyResize();
197 void SAL_CALL
SfxUnoPanel::moveUp()
199 SolarMutexGuard aGuard
;
200 SidebarController
* pSidebarController
= getSidebarController();
202 // Search for previous panel OrderIndex
203 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
205 sal_Int32 curOrderIndex
= getOrderIndex();
206 sal_Int32 previousIndex
= GetMinOrderIndex(aPanels
);
208 for (auto const& panel
: aPanels
)
210 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
211 if( index
< curOrderIndex
&& index
> previousIndex
)
212 previousIndex
= index
;
215 if (curOrderIndex
!= previousIndex
) // is current panel already in place ?
218 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
219 if (xPanelDescriptor
)
221 xPanelDescriptor
->mnOrderIndex
= previousIndex
;
222 // update the sidebar
223 pSidebarController
->NotifyResize();
228 void SAL_CALL
SfxUnoPanel::moveDown()
230 SolarMutexGuard aGuard
;
231 SidebarController
* pSidebarController
= getSidebarController();
233 ResourceManager::PanelContextDescriptorContainer aPanels
= pSidebarController
->GetMatchingPanels(mDeckId
);
235 // Search for next panel OrderIndex
236 sal_Int32 curOrderIndex
= getOrderIndex();
237 sal_Int32 nextIndex
= GetMaxOrderIndex(aPanels
);
239 for (auto const& panel
: aPanels
)
241 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
242 if( index
> curOrderIndex
&& index
< nextIndex
)
246 if (curOrderIndex
!= nextIndex
) // is current panel already in place ?
249 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(mPanelId
);
250 if (xPanelDescriptor
)
252 xPanelDescriptor
->mnOrderIndex
= nextIndex
;
253 // update the sidebar
254 pSidebarController
->NotifyResize();
259 sal_Int32
SfxUnoPanel::GetMinOrderIndex(ResourceManager::PanelContextDescriptorContainer aPanels
)
261 SidebarController
* pSidebarController
= getSidebarController();
263 sal_Int32 minIndex
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(aPanels
.begin()->msId
)->mnOrderIndex
;
265 for (auto const& panel
: aPanels
)
267 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
274 sal_Int32
SfxUnoPanel::GetMaxOrderIndex(ResourceManager::PanelContextDescriptorContainer aPanels
)
276 SidebarController
* pSidebarController
= getSidebarController();
278 sal_Int32 maxIndex
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(aPanels
.begin()->msId
)->mnOrderIndex
;
280 for (auto const& panel
: aPanels
)
282 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetPanelDescriptor(panel
.msId
)->mnOrderIndex
;
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */