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/UnoDeck.hxx>
13 #include <sidebar/UnoPanels.hxx>
15 #include <sfx2/sidebar/ResourceManager.hxx>
16 #include <sfx2/sidebar/SidebarController.hxx>
17 #include <sidebar/DeckTitleBar.hxx>
18 #include <sfx2/sidebar/Deck.hxx>
19 #include <sidebar/DeckDescriptor.hxx>
22 #include <vcl/svapp.hxx>
25 using namespace ::sfx2::sidebar
;
27 SfxUnoDeck::SfxUnoDeck(uno::Reference
<frame::XFrame
> _xFrame
, OUString deckId
):
28 xFrame(std::move(_xFrame
)),
29 mDeckId(std::move(deckId
))
33 SidebarController
* SfxUnoDeck::getSidebarController()
35 return SidebarController::GetSidebarControllerForFrame(xFrame
);
38 OUString SAL_CALL
SfxUnoDeck::getId()
40 SolarMutexGuard aGuard
;
45 OUString SAL_CALL
SfxUnoDeck::getTitle()
47 SolarMutexGuard aGuard
;
49 SidebarController
* pSidebarController
= getSidebarController();
50 VclPtr
<Deck
> pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
54 pSidebarController
->CreateDeck(mDeckId
);
55 pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
58 DeckTitleBar
* pTitleBar
= pDeck
->GetTitleBar();
59 return pTitleBar
->GetTitle();
62 void SAL_CALL
SfxUnoDeck::setTitle( const OUString
& newTitle
)
64 SolarMutexGuard aGuard
;
66 SidebarController
* pSidebarController
= getSidebarController();
67 pSidebarController
->CreateDeck(mDeckId
);
69 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
73 Deck
* pDeck
= xDeckDescriptor
->mpDeck
;
74 DeckTitleBar
* pTitleBar
= pDeck
->GetTitleBar();
75 pTitleBar
->SetTitle(newTitle
);
77 xDeckDescriptor
->msTitle
= newTitle
;
78 xDeckDescriptor
->msHelpText
= newTitle
;
80 pSidebarController
->notifyDeckTitle(mDeckId
);
84 sal_Bool SAL_CALL
SfxUnoDeck::isActive()
86 SolarMutexGuard aGuard
;
88 SidebarController
* pSidebarController
= getSidebarController();
89 return pSidebarController
->IsDeckVisible(mDeckId
);
93 void SAL_CALL
SfxUnoDeck::activate( const sal_Bool bActivate
)
95 SolarMutexGuard aGuard
;
97 SidebarController
* pSidebarController
= getSidebarController();
99 // tdf#138160: OpenThenToggleDeck takes care of minimal width
101 pSidebarController
->OpenThenToggleDeck(mDeckId
);
104 pSidebarController
->SwitchToDefaultDeck();
105 // update the sidebar
106 pSidebarController
->NotifyResize();
111 uno::Reference
<ui::XPanels
> SAL_CALL
SfxUnoDeck::getPanels()
113 SolarMutexGuard aGuard
;
115 uno::Reference
<ui::XPanels
> panels
= new SfxUnoPanels(xFrame
, mDeckId
);
119 sal_Int32 SAL_CALL
SfxUnoDeck::getOrderIndex()
121 SolarMutexGuard aGuard
;
122 SidebarController
* pSidebarController
= getSidebarController();
124 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mnOrderIndex
;
128 void SAL_CALL
SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex
)
130 SolarMutexGuard aGuard
;
131 SidebarController
* pSidebarController
= getSidebarController();
133 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
137 xDeckDescriptor
->mnOrderIndex
= newOrderIndex
;
138 // update the sidebar
139 pSidebarController
->NotifyResize();
143 void SAL_CALL
SfxUnoDeck::moveFirst()
145 SolarMutexGuard aGuard
;
146 SidebarController
* pSidebarController
= getSidebarController();
148 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
150 sal_Int32 minIndex
= GetMinOrderIndex(aDecks
);
151 sal_Int32 curOrderIndex
= getOrderIndex();
153 if (curOrderIndex
!= minIndex
) // is deck already in place ?
156 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
159 xDeckDescriptor
->mnOrderIndex
= minIndex
;
160 // update the sidebar
161 pSidebarController
->NotifyResize();
166 void SAL_CALL
SfxUnoDeck::moveLast()
168 SolarMutexGuard aGuard
;
169 SidebarController
* pSidebarController
= getSidebarController();
171 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
173 sal_Int32 maxIndex
= GetMaxOrderIndex(aDecks
);
174 sal_Int32 curOrderIndex
= getOrderIndex();
176 if (curOrderIndex
!= maxIndex
) // is deck already in place ?
179 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
182 xDeckDescriptor
->mnOrderIndex
= maxIndex
;
183 // update the sidebar
184 pSidebarController
->NotifyResize();
189 void SAL_CALL
SfxUnoDeck::moveUp()
191 SolarMutexGuard aGuard
;
192 SidebarController
* pSidebarController
= getSidebarController();
194 // Search for previous deck OrderIndex
195 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
197 sal_Int32 curOrderIndex
= getOrderIndex();
198 sal_Int32 previousIndex
= GetMinOrderIndex(aDecks
);
200 for (auto const& deck
: aDecks
)
202 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
203 if( index
< curOrderIndex
&& index
> previousIndex
)
204 previousIndex
= index
;
207 if (curOrderIndex
!= previousIndex
) // is deck already in place ?
210 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
213 xDeckDescriptor
->mnOrderIndex
= previousIndex
;
214 // update the sidebar
215 pSidebarController
->NotifyResize();
220 void SAL_CALL
SfxUnoDeck::moveDown()
222 SolarMutexGuard aGuard
;
223 SidebarController
* pSidebarController
= getSidebarController();
225 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
227 // Search for next deck OrderIndex
228 sal_Int32 curOrderIndex
= getOrderIndex();
229 sal_Int32 nextIndex
= GetMaxOrderIndex(aDecks
);
231 for (auto const& deck
: aDecks
)
233 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
234 if( index
> curOrderIndex
&& index
< nextIndex
)
238 if (curOrderIndex
!= nextIndex
) // is deck already in place ?
241 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
244 xDeckDescriptor
->mnOrderIndex
= nextIndex
;
245 // update the sidebar
246 pSidebarController
->NotifyResize();
251 sal_Int32
SfxUnoDeck::GetMinOrderIndex(const ResourceManager::DeckContextDescriptorContainer
& rDecks
)
253 SidebarController
* pSidebarController
= getSidebarController();
255 ResourceManager::DeckContextDescriptorContainer::const_iterator iDeck
= rDecks
.begin();
256 sal_Int32 minIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(iDeck
->msId
)->mnOrderIndex
;
258 for (auto const& deck
: rDecks
)
260 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
267 sal_Int32
SfxUnoDeck::GetMaxOrderIndex(const ResourceManager::DeckContextDescriptorContainer
& rDecks
)
269 SidebarController
* pSidebarController
= getSidebarController();
271 sal_Int32 maxIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(rDecks
.begin()->msId
)->mnOrderIndex
;
273 for (auto const& deck
: rDecks
)
275 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */