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