merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / misc / imageprovider.cxx
blob02cb496f515a7cf5a2b1153c0fa11fa0fafb0934
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: imageprovider.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "imageprovider.hxx"
35 #include "dbu_resource.hrc"
36 #include "moduledbu.hxx"
37 #include "dbustrings.hrc"
39 /** === begin UNO includes === **/
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/graphic/XGraphic.hpp>
42 #include <com/sun/star/graphic/GraphicColorMode.hpp>
43 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
44 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
45 /** === end UNO includes === **/
47 #include <tools/diagnose_ex.h>
49 //........................................................................
50 namespace dbaui
52 //........................................................................
54 /** === begin UNO using === **/
55 using ::com::sun::star::uno::Reference;
56 using ::com::sun::star::sdbc::XConnection;
57 using ::com::sun::star::uno::Exception;
58 using ::com::sun::star::uno::UNO_QUERY_THROW;
59 using ::com::sun::star::container::XNameAccess;
60 using ::com::sun::star::beans::XPropertySet;
61 using ::com::sun::star::graphic::XGraphic;
62 using ::com::sun::star::sdb::application::XTableUIProvider;
63 using ::com::sun::star::uno::UNO_QUERY;
64 using ::com::sun::star::sdbcx::XViewsSupplier;
65 using ::com::sun::star::uno::UNO_SET_THROW;
66 /** === end UNO using === **/
67 namespace GraphicColorMode = ::com::sun::star::graphic::GraphicColorMode;
69 //====================================================================
70 //= ImageProvider_Data
71 //====================================================================
72 struct ImageProvider_Data
74 /// the connection we work with
75 Reference< XConnection > xConnection;
76 /// the views of the connection, if the DB supports views
77 Reference< XNameAccess > xViews;
78 /// interface for providing table's UI
79 Reference< XTableUIProvider > xTableUI;
82 //--------------------------------------------------------------------
83 namespace
85 //................................................................
86 static void lcl_getConnectionProvidedTableIcon_nothrow( const ImageProvider_Data& _rData,
87 const ::rtl::OUString& _rName, Reference< XGraphic >& _out_rxGraphic, Reference< XGraphic >& _out_rxGraphicHC )
89 try
91 if ( _rData.xTableUI.is() )
93 _out_rxGraphic = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL );
94 _out_rxGraphicHC = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::HIGH_CONTRAST );
97 catch( const Exception& )
99 DBG_UNHANDLED_EXCEPTION();
103 //................................................................
104 static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data& _rData, const ::rtl::OUString& _rName,
105 USHORT& _out_rResourceID, USHORT& _out_rResourceID_HC )
107 _out_rResourceID = _out_rResourceID_HC = 0;
110 bool bIsView = _rData.xViews.is() && _rData.xViews->hasByName( _rName );
111 if ( bIsView )
113 _out_rResourceID = VIEW_TREE_ICON;
114 _out_rResourceID_HC = VIEW_TREE_ICON_SCH;
116 else
118 _out_rResourceID = TABLE_TREE_ICON;
119 _out_rResourceID_HC = TABLE_TREE_ICON_SCH;
122 catch( const Exception& )
124 DBG_UNHANDLED_EXCEPTION();
128 //====================================================================
129 //= ImageProvider
130 //====================================================================
131 //--------------------------------------------------------------------
132 ImageProvider::ImageProvider()
133 :m_pData( new ImageProvider_Data )
137 //--------------------------------------------------------------------
138 ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection )
139 :m_pData( new ImageProvider_Data )
141 m_pData->xConnection = _rxConnection;
144 Reference< XViewsSupplier > xSuppViews( m_pData->xConnection, UNO_QUERY );
145 if ( xSuppViews.is() )
146 m_pData->xViews.set( xSuppViews->getViews(), UNO_SET_THROW );
148 m_pData->xTableUI.set( _rxConnection, UNO_QUERY );
150 catch( const Exception& )
152 DBG_UNHANDLED_EXCEPTION();
156 //--------------------------------------------------------------------
157 void ImageProvider::getImages( const String& _rName, const sal_Int32 _nDatabaseObjectType, Image& _out_rImage, Image& _out_rImageHC )
159 if ( _nDatabaseObjectType != DatabaseObject::TABLE )
161 // for types other than tables, the icon does not depend on the concrete object
162 _out_rImage = getDefaultImage( _nDatabaseObjectType, false );
163 _out_rImageHC = getDefaultImage( _nDatabaseObjectType, true );
165 else
167 // check whether the connection can give us an icon
168 Reference< XGraphic > xGraphic;
169 Reference< XGraphic > xGraphicHC;
170 lcl_getConnectionProvidedTableIcon_nothrow( *m_pData, _rName, xGraphic, xGraphicHC );
171 if ( xGraphic.is() )
172 _out_rImage = Image( xGraphic );
173 if ( xGraphicHC.is() )
174 _out_rImageHC = Image( xGraphicHC );
176 if ( !_out_rImage || !_out_rImageHC )
178 // no -> determine by type
179 USHORT nImageResourceID = 0;
180 USHORT nImageResourceID_HC = 0;
181 lcl_getTableImageResourceID_nothrow( *m_pData, _rName, nImageResourceID, nImageResourceID_HC );
183 if ( nImageResourceID && !_out_rImage )
184 _out_rImage = Image( ModuleRes( nImageResourceID ) );
185 if ( nImageResourceID_HC && !_out_rImageHC )
186 _out_rImageHC = Image( ModuleRes( nImageResourceID_HC ) );
191 //--------------------------------------------------------------------
192 Image ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast )
194 Image aObjectImage;
195 USHORT nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType, _bHighContrast ) );
196 if ( nImageResourceID )
197 aObjectImage = Image( ModuleRes( nImageResourceID ) );
198 return aObjectImage;
201 //--------------------------------------------------------------------
202 USHORT ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType, bool _bHighContrast )
204 USHORT nImageResourceID( 0 );
205 switch ( _nDatabaseObjectType )
207 case DatabaseObject::QUERY:
208 nImageResourceID = _bHighContrast ? QUERY_TREE_ICON_SCH : QUERY_TREE_ICON;
209 break;
210 case DatabaseObject::FORM:
211 nImageResourceID = _bHighContrast ? FORM_TREE_ICON_SCH : FORM_TREE_ICON;
212 break;
213 case DatabaseObject::REPORT:
214 nImageResourceID = _bHighContrast ? REPORT_TREE_ICON_SCH : REPORT_TREE_ICON;
215 break;
216 case DatabaseObject::TABLE:
217 nImageResourceID = _bHighContrast ? TABLE_TREE_ICON_SCH : TABLE_TREE_ICON;
218 break;
219 default:
220 OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" );
221 break;
223 return nImageResourceID;
226 //--------------------------------------------------------------------
227 Image ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast )
229 USHORT nImageResourceID( 0 );
230 switch ( _nDatabaseObjectType )
232 case DatabaseObject::QUERY:
233 nImageResourceID = _bHighContrast ? QUERYFOLDER_TREE_ICON_SCH : QUERYFOLDER_TREE_ICON;
234 break;
235 case DatabaseObject::FORM:
236 nImageResourceID = _bHighContrast ? FORMFOLDER_TREE_ICON_SCH : FORMFOLDER_TREE_ICON;
237 break;
238 case DatabaseObject::REPORT:
239 nImageResourceID = _bHighContrast ? REPORTFOLDER_TREE_ICON_SCH : REPORTFOLDER_TREE_ICON;
240 break;
241 case DatabaseObject::TABLE:
242 nImageResourceID = _bHighContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON;
243 break;
244 default:
245 OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" );
246 break;
249 Image aFolderImage;
250 if ( nImageResourceID )
251 aFolderImage = Image( ModuleRes( nImageResourceID ) );
252 return aFolderImage;
255 //--------------------------------------------------------------------
256 Image ImageProvider::getDatabaseImage( bool _bHighContrast )
258 return Image( ModuleRes( _bHighContrast ? DATABASE_TREE_ICON_SCH : DATABASE_TREE_ICON ) );
261 //........................................................................
262 } // namespace dbaui
263 //........................................................................