tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / forms / source / helper / commandimageprovider.cxx
blobdce1f50e24bcec5277e8366a33648cb65e47e2ff
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 <comphelper/diagnose_ex.hxx>
32 namespace frm
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;
51 namespace ImageType = ::com::sun::star::ui::ImageType;
53 DocumentCommandImageProvider::DocumentCommandImageProvider( const Reference<XComponentContext>& _rContext, const Reference< XModel >& _rxDocument )
55 OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
56 if ( !_rxDocument.is() )
57 return;
59 // obtain the image manager of the document
60 try
62 Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
63 Reference< XUIConfigurationManager > xUIConfig = xSuppUIConfig->getUIConfigurationManager();
64 m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
66 catch( const Exception& )
68 DBG_UNHANDLED_EXCEPTION("forms.helper");
71 // obtain the image manager or the module
72 try
74 Reference< XModuleManager2 > xModuleManager( ModuleManager::create(_rContext) );
75 OUString sModuleID = xModuleManager->identify( _rxDocument );
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 );
83 catch( const Exception& )
85 DBG_UNHANDLED_EXCEPTION("forms.helper");
90 std::vector<Image> DocumentCommandImageProvider::getCommandImages( const css::uno::Sequence< OUString >& _rCommandURLs, const bool _bLarge ) const
92 const size_t nCommandCount = _rCommandURLs.getLength();
93 std::vector<Image> aImages( nCommandCount );
94 try
96 const sal_Int16 nImageType = ImageType::COLOR_NORMAL
97 + ( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT );
99 Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
100 Sequence< Reference< XGraphic > > aModImages( nCommandCount );
102 // first try the document image manager
103 if ( m_xDocumentImageManager.is() )
104 aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
106 // then the module's image manager
107 if ( m_xModuleImageManager.is() )
108 aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
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)" );
113 for ( size_t i=0; i<nCommandCount; ++i )
115 if ( aDocImages[i].is() )
116 aImages[i] = Image( aDocImages[i] );
117 else
118 aImages[i] = Image( aModImages[i] );
121 catch( const Exception& )
123 DBG_UNHANDLED_EXCEPTION("forms.helper");
125 return aImages;
128 } // namespace frm
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */