/src/libreoffice/sfx2/source/sidebar/UnoDecks.cxx
Line | Count | Source |
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 <sal/config.h> |
12 | | |
13 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
14 | | #include <sidebar/UnoDecks.hxx> |
15 | | #include <sidebar/UnoDeck.hxx> |
16 | | |
17 | | #include <sfx2/sidebar/ResourceManager.hxx> |
18 | | #include <sfx2/sidebar/SidebarController.hxx> |
19 | | |
20 | | #include <utility> |
21 | | #include <vcl/svapp.hxx> |
22 | | |
23 | | #include <algorithm> |
24 | | |
25 | | using namespace css; |
26 | | using namespace ::sfx2::sidebar; |
27 | | |
28 | | SfxUnoDecks::SfxUnoDecks(uno::Reference<frame::XFrame> _xFrame): |
29 | 0 | xFrame(std::move(_xFrame)) |
30 | 0 | { |
31 | 0 | } |
32 | | |
33 | | SidebarController* SfxUnoDecks::getSidebarController() |
34 | 0 | { |
35 | 0 | return SidebarController::GetSidebarControllerForFrame(xFrame); |
36 | 0 | } |
37 | | |
38 | | // XNameAccess |
39 | | |
40 | | uno::Any SAL_CALL SfxUnoDecks::getByName( const OUString& aName ) |
41 | 0 | { |
42 | 0 | SolarMutexGuard aGuard; |
43 | |
|
44 | 0 | if (!hasByName(aName)) |
45 | 0 | throw container::NoSuchElementException(); |
46 | | |
47 | 0 | uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, aName); |
48 | 0 | return uno::Any(xDeck); |
49 | 0 | } |
50 | | |
51 | | |
52 | | uno::Sequence< OUString > SAL_CALL SfxUnoDecks::getElementNames() |
53 | 0 | { |
54 | 0 | SolarMutexGuard aGuard; |
55 | |
|
56 | 0 | SidebarController* pSidebarController = getSidebarController(); |
57 | |
|
58 | 0 | ResourceManager::DeckContextDescriptorContainer aDecks; |
59 | 0 | css::uno::Sequence< OUString > deckList(aDecks.size()); |
60 | |
|
61 | 0 | if (pSidebarController) |
62 | 0 | { |
63 | 0 | pSidebarController->GetResourceManager()->GetMatchingDecks ( |
64 | 0 | aDecks, |
65 | 0 | pSidebarController->GetCurrentContext(), |
66 | 0 | pSidebarController->IsDocumentReadOnly(), |
67 | 0 | xFrame->getController()); |
68 | |
|
69 | 0 | deckList.realloc(aDecks.size()); |
70 | 0 | std::transform(aDecks.begin(), aDecks.end(), deckList.getArray(), |
71 | 0 | [](const auto& rDeck) { return rDeck.msId; }); |
72 | 0 | } |
73 | |
|
74 | 0 | return deckList; |
75 | |
|
76 | 0 | } |
77 | | |
78 | | sal_Bool SAL_CALL SfxUnoDecks::hasByName( const OUString& aName ) |
79 | 0 | { |
80 | 0 | SolarMutexGuard aGuard; |
81 | |
|
82 | 0 | SidebarController* pSidebarController = getSidebarController(); |
83 | |
|
84 | 0 | bool bFound = false; |
85 | |
|
86 | 0 | if (pSidebarController) |
87 | 0 | { |
88 | 0 | ResourceManager::DeckContextDescriptorContainer aDecks; |
89 | |
|
90 | 0 | pSidebarController->GetResourceManager()->GetMatchingDecks ( |
91 | 0 | aDecks, |
92 | 0 | pSidebarController->GetCurrentContext(), |
93 | 0 | pSidebarController->IsDocumentReadOnly(), |
94 | 0 | xFrame->getController()); |
95 | |
|
96 | 0 | bFound = std::any_of(aDecks.begin(), aDecks.end(), |
97 | 0 | [&aName](const ResourceManager::DeckContextDescriptor& rDeck) { return rDeck.msId == aName; }); |
98 | 0 | } |
99 | |
|
100 | 0 | return bFound; |
101 | |
|
102 | 0 | } |
103 | | |
104 | | // XIndexAccess |
105 | | |
106 | | sal_Int32 SAL_CALL SfxUnoDecks::getCount() |
107 | 0 | { |
108 | 0 | SolarMutexGuard aGuard; |
109 | |
|
110 | 0 | uno::Sequence< OUString > decks = getElementNames(); |
111 | 0 | return decks.getLength(); |
112 | 0 | } |
113 | | |
114 | | uno::Any SAL_CALL SfxUnoDecks::getByIndex( sal_Int32 Index ) |
115 | 0 | { |
116 | 0 | SolarMutexGuard aGuard; |
117 | 0 | uno::Any aRet; |
118 | |
|
119 | 0 | uno::Sequence< OUString > decks = getElementNames(); |
120 | |
|
121 | 0 | if (Index > decks.getLength()-1 || Index < 0) |
122 | 0 | throw lang::IndexOutOfBoundsException(); |
123 | | |
124 | 0 | uno::Reference<ui::XDeck> xDeck = new SfxUnoDeck(xFrame, decks[Index]); |
125 | 0 | aRet <<= xDeck; |
126 | 0 | return aRet; |
127 | |
|
128 | 0 | } |
129 | | |
130 | | // XElementAccess |
131 | | uno::Type SAL_CALL SfxUnoDecks::getElementType() |
132 | 0 | { |
133 | 0 | return uno::Type(); |
134 | 0 | } |
135 | | |
136 | | sal_Bool SAL_CALL SfxUnoDecks::hasElements() |
137 | 0 | { |
138 | 0 | SolarMutexGuard aGuard; |
139 | |
|
140 | 0 | uno::Sequence< OUString > decks = getElementNames(); |
141 | 0 | return decks.hasElements(); |
142 | 0 | } |
143 | | |
144 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |