Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 : : *
5 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
6 : : *
7 : : * OpenOffice.org - a multi-platform office productivity suite
8 : : *
9 : : * This file is part of OpenOffice.org.
10 : : *
11 : : * OpenOffice.org is free software: you can redistribute it and/or modify
12 : : * it under the terms of the GNU Lesser General Public License version 3
13 : : * only, as published by the Free Software Foundation.
14 : : *
15 : : * OpenOffice.org is distributed in the hope that it will be useful,
16 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : : * GNU Lesser General Public License version 3 for more details
19 : : * (a copy is included in the LICENSE file that accompanied this code).
20 : : *
21 : : * You should have received a copy of the GNU Lesser General Public License
22 : : * version 3 along with OpenOffice.org. If not, see
23 : : * <http://www.openoffice.org/license.html>
24 : : * for a copy of the LGPLv3 License.
25 : : *
26 : : ************************************************************************/
27 : :
28 : :
29 : : #include "commandimageprovider.hxx"
30 : :
31 : : #include <com/sun/star/ui/XImageManager.hpp>
32 : : #include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
33 : : #include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
34 : : #include <com/sun/star/frame/XModuleManager.hpp>
35 : : #include <com/sun/star/ui/ImageType.hpp>
36 : :
37 : : #include <tools/diagnose_ex.h>
38 : :
39 : : //........................................................................
40 : : namespace frm
41 : : {
42 : : //........................................................................
43 : :
44 : : /** === begin UNO using === **/
45 : : using ::com::sun::star::uno::Reference;
46 : : using ::com::sun::star::uno::XInterface;
47 : : using ::com::sun::star::uno::UNO_QUERY;
48 : : using ::com::sun::star::uno::UNO_QUERY_THROW;
49 : : using ::com::sun::star::uno::UNO_SET_THROW;
50 : : using ::com::sun::star::uno::Exception;
51 : : using ::com::sun::star::uno::RuntimeException;
52 : : using ::com::sun::star::uno::Any;
53 : : using ::com::sun::star::uno::makeAny;
54 : : using ::com::sun::star::uno::Sequence;
55 : : using ::com::sun::star::uno::Type;
56 : : using ::com::sun::star::frame::XModel;
57 : : using ::com::sun::star::ui::XImageManager;
58 : : using ::com::sun::star::ui::XUIConfigurationManagerSupplier;
59 : : using ::com::sun::star::ui::XUIConfigurationManager;
60 : : using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
61 : : using ::com::sun::star::frame::XModuleManager;
62 : : using ::com::sun::star::graphic::XGraphic;
63 : : /** === end UNO using === **/
64 : : namespace ImageType = ::com::sun::star::ui::ImageType;
65 : :
66 : : //====================================================================
67 : : //= DocumentCommandImageProvider
68 : : //====================================================================
69 : : class DocumentCommandImageProvider : public ICommandImageProvider
70 : : {
71 : : public:
72 : 36 : DocumentCommandImageProvider( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
73 : 36 : {
74 [ + - ]: 36 : impl_init_nothrow( _rContext, _rxDocument );
75 : 36 : }
76 : 72 : virtual ~DocumentCommandImageProvider()
77 : 36 : {
78 [ - + ]: 72 : }
79 : :
80 : : // ICommandImageProvider
81 : : virtual CommandImages getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge ) const;
82 : :
83 : : private:
84 : : void impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument );
85 : :
86 : : private:
87 : : Reference< XImageManager > m_xDocumentImageManager;
88 : : Reference< XImageManager > m_xModuleImageManager;
89 : : };
90 : :
91 : : //--------------------------------------------------------------------
92 : 36 : void DocumentCommandImageProvider::impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
93 : : {
94 : : OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
95 [ - + ]: 36 : if ( !_rxDocument.is() )
96 : 36 : return;
97 : :
98 : : // obtain the image manager of the document
99 : : try
100 : : {
101 [ + - ]: 36 : Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
102 [ + - ][ + - ]: 36 : Reference< XUIConfigurationManager > xUIConfig( xSuppUIConfig->getUIConfigurationManager(), UNO_QUERY );
[ + - ]
103 [ + - ][ + - ]: 36 : m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
[ # # ][ + - ]
104 : : }
105 : 0 : catch( const Exception& )
106 : : {
107 : : DBG_UNHANDLED_EXCEPTION();
108 : : }
109 : :
110 : : // obtain the image manager or the module
111 : : try
112 : : {
113 [ + - ][ + - ]: 36 : Reference< XModuleManager > xModuleManager( _rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
114 [ + - ][ + - ]: 36 : ::rtl::OUString sModuleID = xModuleManager->identify( _rxDocument );
115 : :
116 : : Reference< XModuleUIConfigurationManagerSupplier > xSuppUIConfig(
117 [ + - ][ + - ]: 36 : _rContext.createComponent( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ), UNO_QUERY_THROW );
118 : : Reference< XUIConfigurationManager > xUIConfig(
119 [ + - ][ + - ]: 36 : xSuppUIConfig->getUIConfigurationManager( sModuleID ), UNO_SET_THROW );
[ + - ]
120 [ + - ][ + - ]: 36 : m_xModuleImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
[ # # ][ + - ]
121 : : }
122 : 0 : catch( const Exception& )
123 : : {
124 : : DBG_UNHANDLED_EXCEPTION();
125 : : }
126 : : }
127 : :
128 : : //--------------------------------------------------------------------
129 : 90 : CommandImages DocumentCommandImageProvider::getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge ) const
130 : : {
131 : 90 : const size_t nCommandCount = _rCommandURLs.getLength();
132 : 90 : CommandImages aImages( nCommandCount );
133 : : try
134 : : {
135 : : const sal_Int16 nImageType = ImageType::COLOR_NORMAL
136 [ + + ]: 90 : + ( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT );
137 : :
138 [ + - ]: 90 : Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
139 [ + - ]: 90 : Sequence< Reference< XGraphic > > aModImages( nCommandCount );
140 : :
141 : : // first try the document image manager
142 [ + - ]: 90 : if ( m_xDocumentImageManager.is() )
143 [ + - ][ + - ]: 90 : aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
[ + - ][ + - ]
144 : :
145 : : // then the module's image manager
146 [ + - ]: 90 : if ( m_xModuleImageManager.is() )
147 [ + - ][ + - ]: 90 : aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
[ + - ][ + - ]
148 : :
149 [ - + ][ # # ]: 90 : ENSURE_OR_THROW( (size_t)aDocImages.getLength() == nCommandCount, "illegal array size returned by getImages (document image manager)" );
[ # # ][ # # ]
150 [ - + ][ # # ]: 90 : ENSURE_OR_THROW( (size_t)aModImages.getLength() == nCommandCount, "illegal array size returned by getImages (module image manager)" );
[ # # ][ # # ]
151 : :
152 [ + + ]: 1800 : for ( size_t i=0; i<nCommandCount; ++i )
153 : : {
154 [ + - ][ - + ]: 1710 : if ( aDocImages[i].is() )
155 [ # # ][ # # ]: 0 : aImages[i] = Image( aDocImages[i] );
[ # # ][ # # ]
[ # # ]
156 : : else
157 [ + - ][ + - ]: 1710 : aImages[i] = Image( aModImages[i] );
[ + - ][ + - ]
[ + - ]
158 [ + - ][ + - ]: 90 : }
[ # # ]
159 : : }
160 [ # # ]: 0 : catch( const Exception& )
161 : : {
162 : : DBG_UNHANDLED_EXCEPTION();
163 : : }
164 : 90 : return aImages;
165 : : }
166 : :
167 : : //--------------------------------------------------------------------
168 : 36 : PCommandImageProvider createDocumentCommandImageProvider(
169 : : const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
170 : : {
171 [ + - ][ + - ]: 36 : PCommandImageProvider pImageProvider( new DocumentCommandImageProvider( _rContext, _rxDocument ) );
172 : 36 : return pImageProvider;
173 : : }
174 : :
175 : : //........................................................................
176 : : } // namespace frm
177 : : //........................................................................
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|