nss: upgrade to release 3.73
[LibreOffice.git] / forms / source / helper / commandimageprovider.cxx
blobca2d7052567fa01d191412bbcfd7b882cb9b23d0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <commandimageprovider.hxx>
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>
29 #include <tools/diagnose_ex.h>
32 namespace frm
36 using ::com::sun::star::uno::Reference;
37 using ::com::sun::star::uno::UNO_QUERY;
38 using ::com::sun::star::uno::UNO_QUERY_THROW;
39 using ::com::sun::star::uno::UNO_SET_THROW;
40 using ::com::sun::star::uno::Exception;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::uno::XComponentContext;
43 using ::com::sun::star::frame::XModel;
44 using ::com::sun::star::ui::XImageManager;
45 using ::com::sun::star::ui::XUIConfigurationManagerSupplier;
46 using ::com::sun::star::ui::XUIConfigurationManager;
47 using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
48 using ::com::sun::star::ui::theModuleUIConfigurationManagerSupplier;
49 using ::com::sun::star::frame::ModuleManager;
50 using ::com::sun::star::frame::XModuleManager2;
51 using ::com::sun::star::graphic::XGraphic;
53 namespace ImageType = ::com::sun::star::ui::ImageType;
55 DocumentCommandImageProvider::DocumentCommandImageProvider( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
57 OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
58 if ( !_rxDocument.is() )
59 return;
61 // obtain the image manager of the document
62 try
64 Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
65 Reference< XUIConfigurationManager > xUIConfig = xSuppUIConfig->getUIConfigurationManager();
66 m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
68 catch( const Exception& )
70 DBG_UNHANDLED_EXCEPTION("forms.helper");
73 // obtain the image manager or the module
74 try
76 Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rContext) );
77 OUString sModuleID = xModuleManager->identify( _rxDocument );
79 Reference< XModuleUIConfigurationManagerSupplier > xSuppUIConfig(
80 theModuleUIConfigurationManagerSupplier::get(_rContext) );
81 Reference< XUIConfigurationManager > xUIConfig(
82 xSuppUIConfig->getUIConfigurationManager( sModuleID ), UNO_SET_THROW );
83 m_xModuleImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
85 catch( const Exception& )
87 DBG_UNHANDLED_EXCEPTION("forms.helper");
92 std::vector<Image> DocumentCommandImageProvider::getCommandImages( const css::uno::Sequence< OUString >& _rCommandURLs, const bool _bLarge ) const
94 const size_t nCommandCount = _rCommandURLs.getLength();
95 std::vector<Image> aImages( nCommandCount );
96 try
98 const sal_Int16 nImageType = ImageType::COLOR_NORMAL
99 + ( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT );
101 Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
102 Sequence< Reference< XGraphic > > aModImages( nCommandCount );
104 // first try the document image manager
105 if ( m_xDocumentImageManager.is() )
106 aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
108 // then the module's image manager
109 if ( m_xModuleImageManager.is() )
110 aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
112 ENSURE_OR_THROW( static_cast<size_t>(aDocImages.getLength()) == nCommandCount, "illegal array size returned by getImages (document image manager)" );
113 ENSURE_OR_THROW( static_cast<size_t>(aModImages.getLength()) == nCommandCount, "illegal array size returned by getImages (module image manager)" );
115 for ( size_t i=0; i<nCommandCount; ++i )
117 if ( aDocImages[i].is() )
118 aImages[i] = Image( aDocImages[i] );
119 else
120 aImages[i] = Image( aModImages[i] );
123 catch( const Exception& )
125 DBG_UNHANDLED_EXCEPTION("forms.helper");
127 return aImages;
130 } // namespace frm
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */