LibreOffice Module forms (master) 1
commandimageprovider.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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20
22
23#include <com/sun/star/ui/XImageManager.hpp>
24#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
25#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp>
26#include <com/sun/star/frame/ModuleManager.hpp>
27#include <com/sun/star/ui/ImageType.hpp>
28
30
31
32namespace frm
33{
34
35
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::UNO_SET_THROW;
39 using ::com::sun::star::uno::Exception;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::XComponentContext;
42 using ::com::sun::star::frame::XModel;
43 using ::com::sun::star::ui::XUIConfigurationManagerSupplier;
44 using ::com::sun::star::ui::XUIConfigurationManager;
45 using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
46 using ::com::sun::star::ui::theModuleUIConfigurationManagerSupplier;
47 using ::com::sun::star::frame::ModuleManager;
48 using ::com::sun::star::frame::XModuleManager2;
49 using ::com::sun::star::graphic::XGraphic;
50
51 namespace ImageType = ::com::sun::star::ui::ImageType;
52
53 DocumentCommandImageProvider::DocumentCommandImageProvider( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
54 {
55 OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
56 if ( !_rxDocument.is() )
57 return;
58
59 // obtain the image manager of the document
60 try
61 {
62 Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
63 Reference< XUIConfigurationManager > xUIConfig = xSuppUIConfig->getUIConfigurationManager();
64 m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
65 }
66 catch( const Exception& )
67 {
68 DBG_UNHANDLED_EXCEPTION("forms.helper");
69 }
70
71 // obtain the image manager or the module
72 try
73 {
74 Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rContext) );
75 OUString sModuleID = xModuleManager->identify( _rxDocument );
76
77 Reference< XModuleUIConfigurationManagerSupplier > xSuppUIConfig(
78 theModuleUIConfigurationManagerSupplier::get(_rContext) );
79 Reference< XUIConfigurationManager > xUIConfig(
80 xSuppUIConfig->getUIConfigurationManager( sModuleID ), UNO_SET_THROW );
81 m_xModuleImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
82 }
83 catch( const Exception& )
84 {
85 DBG_UNHANDLED_EXCEPTION("forms.helper");
86 }
87 }
88
89
90 std::vector<Image> DocumentCommandImageProvider::getCommandImages( const css::uno::Sequence< OUString >& _rCommandURLs, const bool _bLarge ) const
91 {
92 const size_t nCommandCount = _rCommandURLs.getLength();
93 std::vector<Image> aImages( nCommandCount );
94 try
95 {
96 const sal_Int16 nImageType = ImageType::COLOR_NORMAL
97 + ( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT );
98
99 Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
100 Sequence< Reference< XGraphic > > aModImages( nCommandCount );
101
102 // first try the document image manager
103 if ( m_xDocumentImageManager.is() )
104 aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
105
106 // then the module's image manager
107 if ( m_xModuleImageManager.is() )
108 aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
109
110 ENSURE_OR_THROW( static_cast<size_t>(aDocImages.getLength()) == nCommandCount, "illegal array size returned by getImages (document image manager)" );
111 ENSURE_OR_THROW( static_cast<size_t>(aModImages.getLength()) == nCommandCount, "illegal array size returned by getImages (module image manager)" );
112
113 for ( size_t i=0; i<nCommandCount; ++i )
114 {
115 if ( aDocImages[i].is() )
116 aImages[i] = Image( aDocImages[i] );
117 else
118 aImages[i] = Image( aModImages[i] );
119 }
120 }
121 catch( const Exception& )
122 {
123 DBG_UNHANDLED_EXCEPTION("forms.helper");
124 }
125 return aImages;
126 }
127
128} // namespace frm
129
130
131/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< Image > getCommandImages(const css::uno::Sequence< OUString > &_rCommandURLs, bool _bLarge) const
DocumentCommandImageProvider(const css::uno::Reference< css::uno::XComponentContext > &_rContext, const css::uno::Reference< css::frame::XModel > &_rxDocument)
css::uno::Reference< css::ui::XImageManager > m_xDocumentImageManager
css::uno::Reference< css::ui::XImageManager > m_xModuleImageManager
#define ENSURE_OR_THROW(c, m)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
int i
ImageType