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()
43 OUString SAL_CALL
SfxUnoDeck::getTitle()
45 SolarMutexGuard aGuard
;
47 SidebarController
* pSidebarController
= getSidebarController();
48 VclPtr
<Deck
> pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
52 pSidebarController
->CreateDeck(mDeckId
);
53 pDeck
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mpDeck
;
56 DeckTitleBar
* pTitleBar
= pDeck
->GetTitleBar();
57 return pTitleBar
->GetTitle();
60 void SAL_CALL
SfxUnoDeck::setTitle( const OUString
& newTitle
)
62 SolarMutexGuard aGuard
;
64 SidebarController
* pSidebarController
= getSidebarController();
65 pSidebarController
->CreateDeck(mDeckId
);
67 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
71 Deck
* pDeck
= xDeckDescriptor
->mpDeck
;
72 DeckTitleBar
* pTitleBar
= pDeck
->GetTitleBar();
73 pTitleBar
->SetTitle(newTitle
);
75 xDeckDescriptor
->msTitle
= newTitle
;
76 xDeckDescriptor
->msHelpText
= newTitle
;
78 pSidebarController
->notifyDeckTitle(mDeckId
);
82 sal_Bool SAL_CALL
SfxUnoDeck::isActive()
84 SolarMutexGuard aGuard
;
86 SidebarController
* pSidebarController
= getSidebarController();
87 return pSidebarController
->IsDeckVisible(mDeckId
);
91 void SAL_CALL
SfxUnoDeck::activate( const sal_Bool bActivate
)
93 SolarMutexGuard aGuard
;
95 SidebarController
* pSidebarController
= getSidebarController();
97 // tdf#138160: OpenThenToggleDeck takes care of minimal width
99 pSidebarController
->OpenThenToggleDeck(mDeckId
);
102 pSidebarController
->SwitchToDefaultDeck();
103 // update the sidebar
104 pSidebarController
->NotifyResize();
109 uno::Reference
<ui::XPanels
> SAL_CALL
SfxUnoDeck::getPanels()
111 SolarMutexGuard aGuard
;
113 uno::Reference
<ui::XPanels
> panels
= new SfxUnoPanels(xFrame
, mDeckId
);
117 sal_Int32 SAL_CALL
SfxUnoDeck::getOrderIndex()
119 SolarMutexGuard aGuard
;
120 SidebarController
* pSidebarController
= getSidebarController();
122 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
)->mnOrderIndex
;
126 void SAL_CALL
SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex
)
128 SolarMutexGuard aGuard
;
129 SidebarController
* pSidebarController
= getSidebarController();
131 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
135 xDeckDescriptor
->mnOrderIndex
= newOrderIndex
;
136 // update the sidebar
137 pSidebarController
->NotifyResize();
141 void SAL_CALL
SfxUnoDeck::moveFirst()
143 SolarMutexGuard aGuard
;
144 SidebarController
* pSidebarController
= getSidebarController();
146 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
148 sal_Int32 minIndex
= GetMinOrderIndex(aDecks
);
149 sal_Int32 curOrderIndex
= getOrderIndex();
151 if (curOrderIndex
!= minIndex
) // is deck already in place ?
154 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
157 xDeckDescriptor
->mnOrderIndex
= minIndex
;
158 // update the sidebar
159 pSidebarController
->NotifyResize();
164 void SAL_CALL
SfxUnoDeck::moveLast()
166 SolarMutexGuard aGuard
;
167 SidebarController
* pSidebarController
= getSidebarController();
169 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
171 sal_Int32 maxIndex
= GetMaxOrderIndex(aDecks
);
172 sal_Int32 curOrderIndex
= getOrderIndex();
174 if (curOrderIndex
!= maxIndex
) // is deck already in place ?
177 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
180 xDeckDescriptor
->mnOrderIndex
= maxIndex
;
181 // update the sidebar
182 pSidebarController
->NotifyResize();
187 void SAL_CALL
SfxUnoDeck::moveUp()
189 SolarMutexGuard aGuard
;
190 SidebarController
* pSidebarController
= getSidebarController();
192 // Search for previous deck OrderIndex
193 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
195 sal_Int32 curOrderIndex
= getOrderIndex();
196 sal_Int32 previousIndex
= GetMinOrderIndex(aDecks
);
198 for (auto const& deck
: aDecks
)
200 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
201 if( index
< curOrderIndex
&& index
> previousIndex
)
202 previousIndex
= index
;
205 if (curOrderIndex
!= previousIndex
) // is deck already in place ?
208 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
211 xDeckDescriptor
->mnOrderIndex
= previousIndex
;
212 // update the sidebar
213 pSidebarController
->NotifyResize();
218 void SAL_CALL
SfxUnoDeck::moveDown()
220 SolarMutexGuard aGuard
;
221 SidebarController
* pSidebarController
= getSidebarController();
223 ResourceManager::DeckContextDescriptorContainer aDecks
= pSidebarController
->GetMatchingDecks();
225 // Search for next deck OrderIndex
226 sal_Int32 curOrderIndex
= getOrderIndex();
227 sal_Int32 nextIndex
= GetMaxOrderIndex(aDecks
);
229 for (auto const& deck
: aDecks
)
231 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
232 if( index
> curOrderIndex
&& index
< nextIndex
)
236 if (curOrderIndex
!= nextIndex
) // is deck already in place ?
239 std::shared_ptr
<DeckDescriptor
> xDeckDescriptor
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(mDeckId
);
242 xDeckDescriptor
->mnOrderIndex
= nextIndex
;
243 // update the sidebar
244 pSidebarController
->NotifyResize();
249 sal_Int32
SfxUnoDeck::GetMinOrderIndex(const ResourceManager::DeckContextDescriptorContainer
& rDecks
)
251 SidebarController
* pSidebarController
= getSidebarController();
253 ResourceManager::DeckContextDescriptorContainer::const_iterator iDeck
= rDecks
.begin();
254 sal_Int32 minIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(iDeck
->msId
)->mnOrderIndex
;
256 for (auto const& deck
: rDecks
)
258 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
265 sal_Int32
SfxUnoDeck::GetMaxOrderIndex(const ResourceManager::DeckContextDescriptorContainer
& rDecks
)
267 SidebarController
* pSidebarController
= getSidebarController();
269 sal_Int32 maxIndex
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(rDecks
.begin()->msId
)->mnOrderIndex
;
271 for (auto const& deck
: rDecks
)
273 sal_Int32 index
= pSidebarController
->GetResourceManager()->GetDeckDescriptor(deck
.msId
)->mnOrderIndex
;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */