Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / misc / imageprovider.cxx
blobfead8aa24c2a5090cf5be8a1cddfe68691b92834
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "imageprovider.hxx"
31 #include "dbu_resource.hrc"
32 #include "moduledbu.hxx"
33 #include "dbustrings.hrc"
35 /** === begin UNO includes === **/
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/graphic/XGraphic.hpp>
38 #include <com/sun/star/graphic/GraphicColorMode.hpp>
39 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
40 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
41 /** === end UNO includes === **/
43 #include <tools/diagnose_ex.h>
45 //........................................................................
46 namespace dbaui
48 //........................................................................
50 /** === begin UNO using === **/
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::sdbc::XConnection;
53 using ::com::sun::star::uno::Exception;
54 using ::com::sun::star::uno::UNO_QUERY_THROW;
55 using ::com::sun::star::container::XNameAccess;
56 using ::com::sun::star::beans::XPropertySet;
57 using ::com::sun::star::graphic::XGraphic;
58 using ::com::sun::star::sdb::application::XTableUIProvider;
59 using ::com::sun::star::uno::UNO_QUERY;
60 using ::com::sun::star::sdbcx::XViewsSupplier;
61 using ::com::sun::star::uno::UNO_SET_THROW;
62 /** === end UNO using === **/
63 namespace GraphicColorMode = ::com::sun::star::graphic::GraphicColorMode;
65 //====================================================================
66 //= ImageProvider_Data
67 //====================================================================
68 struct ImageProvider_Data
70 /// the connection we work with
71 Reference< XConnection > xConnection;
72 /// the views of the connection, if the DB supports views
73 Reference< XNameAccess > xViews;
74 /// interface for providing table's UI
75 Reference< XTableUIProvider > xTableUI;
78 //--------------------------------------------------------------------
79 namespace
81 //................................................................
82 static void lcl_getConnectionProvidedTableIcon_nothrow( const ImageProvider_Data& _rData,
83 const ::rtl::OUString& _rName, Reference< XGraphic >& _out_rxGraphic )
85 try
87 if ( _rData.xTableUI.is() )
88 _out_rxGraphic = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL );
90 catch( const Exception& )
92 DBG_UNHANDLED_EXCEPTION();
96 //................................................................
97 static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data& _rData, const ::rtl::OUString& _rName,
98 sal_uInt16& _out_rResourceID)
100 _out_rResourceID = 0;
103 bool bIsView = _rData.xViews.is() && _rData.xViews->hasByName( _rName );
104 if ( bIsView )
106 _out_rResourceID = VIEW_TREE_ICON;
108 else
110 _out_rResourceID = TABLE_TREE_ICON;
113 catch( const Exception& )
115 DBG_UNHANDLED_EXCEPTION();
119 //====================================================================
120 //= ImageProvider
121 //====================================================================
122 //--------------------------------------------------------------------
123 ImageProvider::ImageProvider()
124 :m_pData( new ImageProvider_Data )
128 //--------------------------------------------------------------------
129 ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection )
130 :m_pData( new ImageProvider_Data )
132 m_pData->xConnection = _rxConnection;
135 Reference< XViewsSupplier > xSuppViews( m_pData->xConnection, UNO_QUERY );
136 if ( xSuppViews.is() )
137 m_pData->xViews.set( xSuppViews->getViews(), UNO_SET_THROW );
139 m_pData->xTableUI.set( _rxConnection, UNO_QUERY );
141 catch( const Exception& )
143 DBG_UNHANDLED_EXCEPTION();
147 //--------------------------------------------------------------------
148 void ImageProvider::getImages( const String& _rName, const sal_Int32 _nDatabaseObjectType, Image& _out_rImage )
150 if ( _nDatabaseObjectType != DatabaseObject::TABLE )
152 // for types other than tables, the icon does not depend on the concrete object
153 _out_rImage = getDefaultImage( _nDatabaseObjectType );
155 else
157 // check whether the connection can give us an icon
158 Reference< XGraphic > xGraphic;
159 lcl_getConnectionProvidedTableIcon_nothrow( *m_pData, _rName, xGraphic );
160 if ( xGraphic.is() )
161 _out_rImage = Image( xGraphic );
163 if ( !_out_rImage )
165 // no -> determine by type
166 sal_uInt16 nImageResourceID = 0;
167 lcl_getTableImageResourceID_nothrow( *m_pData, _rName, nImageResourceID );
169 if ( nImageResourceID && !_out_rImage )
170 _out_rImage = Image( ModuleRes( nImageResourceID ) );
175 //--------------------------------------------------------------------
176 Image ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType )
178 Image aObjectImage;
179 sal_uInt16 nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType) );
180 if ( nImageResourceID )
181 aObjectImage = Image( ModuleRes( nImageResourceID ) );
182 return aObjectImage;
185 //--------------------------------------------------------------------
186 sal_uInt16 ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType)
188 sal_uInt16 nImageResourceID( 0 );
189 switch ( _nDatabaseObjectType )
191 case DatabaseObject::QUERY:
192 nImageResourceID = QUERY_TREE_ICON;
193 break;
194 case DatabaseObject::FORM:
195 nImageResourceID = FORM_TREE_ICON;
196 break;
197 case DatabaseObject::REPORT:
198 nImageResourceID = REPORT_TREE_ICON;
199 break;
200 case DatabaseObject::TABLE:
201 nImageResourceID = TABLE_TREE_ICON;
202 break;
203 default:
204 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
205 break;
207 return nImageResourceID;
210 //--------------------------------------------------------------------
211 Image ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType )
213 sal_uInt16 nImageResourceID( 0 );
214 switch ( _nDatabaseObjectType )
216 case DatabaseObject::QUERY:
217 nImageResourceID = QUERYFOLDER_TREE_ICON;
218 break;
219 case DatabaseObject::FORM:
220 nImageResourceID = FORMFOLDER_TREE_ICON;
221 break;
222 case DatabaseObject::REPORT:
223 nImageResourceID = REPORTFOLDER_TREE_ICON;
224 break;
225 case DatabaseObject::TABLE:
226 nImageResourceID = TABLEFOLDER_TREE_ICON;
227 break;
228 default:
229 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
230 break;
233 Image aFolderImage;
234 if ( nImageResourceID )
235 aFolderImage = Image( ModuleRes( nImageResourceID ) );
236 return aFolderImage;
239 //--------------------------------------------------------------------
240 Image ImageProvider::getDatabaseImage()
242 return Image( ModuleRes( DATABASE_TREE_ICON ) );
245 //........................................................................
246 } // namespace dbaui
247 //........................................................................
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */