1 /************************************************************************* 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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_dbaccess.hxx" 30 31 #include "imageprovider.hxx" 32 #include "dbu_resource.hrc" 33 #include "moduledbu.hxx" 34 #include "dbustrings.hrc" 35 36 /** === begin UNO includes === **/ 37 #include <com/sun/star/beans/XPropertySet.hpp> 38 #include <com/sun/star/graphic/XGraphic.hpp> 39 #include <com/sun/star/graphic/GraphicColorMode.hpp> 40 #include <com/sun/star/sdb/application/XTableUIProvider.hpp> 41 #include <com/sun/star/sdbcx/XViewsSupplier.hpp> 42 /** === end UNO includes === **/ 43 44 #include <tools/diagnose_ex.h> 45 46 //........................................................................ 47 namespace dbaui 48 { 49 //........................................................................ 50 51 /** === begin UNO using === **/ 52 using ::com::sun::star::uno::Reference; 53 using ::com::sun::star::sdbc::XConnection; 54 using ::com::sun::star::uno::Exception; 55 using ::com::sun::star::uno::UNO_QUERY_THROW; 56 using ::com::sun::star::container::XNameAccess; 57 using ::com::sun::star::beans::XPropertySet; 58 using ::com::sun::star::graphic::XGraphic; 59 using ::com::sun::star::sdb::application::XTableUIProvider; 60 using ::com::sun::star::uno::UNO_QUERY; 61 using ::com::sun::star::sdbcx::XViewsSupplier; 62 using ::com::sun::star::uno::UNO_SET_THROW; 63 /** === end UNO using === **/ 64 namespace GraphicColorMode = ::com::sun::star::graphic::GraphicColorMode; 65 66 //==================================================================== 67 //= ImageProvider_Data 68 //==================================================================== 69 struct ImageProvider_Data 70 { 71 /// the connection we work with 72 Reference< XConnection > xConnection; 73 /// the views of the connection, if the DB supports views 74 Reference< XNameAccess > xViews; 75 /// interface for providing table's UI 76 Reference< XTableUIProvider > xTableUI; 77 }; 78 79 //-------------------------------------------------------------------- 80 namespace 81 { 82 //................................................................ 83 static void lcl_getConnectionProvidedTableIcon_nothrow( const ImageProvider_Data& _rData, 84 const ::rtl::OUString& _rName, Reference< XGraphic >& _out_rxGraphic, Reference< XGraphic >& _out_rxGraphicHC ) 85 { 86 try 87 { 88 if ( _rData.xTableUI.is() ) 89 { 90 _out_rxGraphic = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL ); 91 _out_rxGraphicHC = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::HIGH_CONTRAST ); 92 } 93 } 94 catch( const Exception& ) 95 { 96 DBG_UNHANDLED_EXCEPTION(); 97 } 98 } 99 100 //................................................................ 101 static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data& _rData, const ::rtl::OUString& _rName, 102 sal_uInt16& _out_rResourceID, sal_uInt16& _out_rResourceID_HC ) 103 { 104 _out_rResourceID = _out_rResourceID_HC = 0; 105 try 106 { 107 bool bIsView = _rData.xViews.is() && _rData.xViews->hasByName( _rName ); 108 if ( bIsView ) 109 { 110 _out_rResourceID = VIEW_TREE_ICON; 111 _out_rResourceID_HC = VIEW_TREE_ICON_SCH; 112 } 113 else 114 { 115 _out_rResourceID = TABLE_TREE_ICON; 116 _out_rResourceID_HC = TABLE_TREE_ICON_SCH; 117 } 118 } 119 catch( const Exception& ) 120 { 121 DBG_UNHANDLED_EXCEPTION(); 122 } 123 } 124 } 125 //==================================================================== 126 //= ImageProvider 127 //==================================================================== 128 //-------------------------------------------------------------------- 129 ImageProvider::ImageProvider() 130 :m_pData( new ImageProvider_Data ) 131 { 132 } 133 134 //-------------------------------------------------------------------- 135 ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection ) 136 :m_pData( new ImageProvider_Data ) 137 { 138 m_pData->xConnection = _rxConnection; 139 try 140 { 141 Reference< XViewsSupplier > xSuppViews( m_pData->xConnection, UNO_QUERY ); 142 if ( xSuppViews.is() ) 143 m_pData->xViews.set( xSuppViews->getViews(), UNO_SET_THROW ); 144 145 m_pData->xTableUI.set( _rxConnection, UNO_QUERY ); 146 } 147 catch( const Exception& ) 148 { 149 DBG_UNHANDLED_EXCEPTION(); 150 } 151 } 152 153 //-------------------------------------------------------------------- 154 void ImageProvider::getImages( const String& _rName, const sal_Int32 _nDatabaseObjectType, Image& _out_rImage, Image& _out_rImageHC ) 155 { 156 if ( _nDatabaseObjectType != DatabaseObject::TABLE ) 157 { 158 // for types other than tables, the icon does not depend on the concrete object 159 _out_rImage = getDefaultImage( _nDatabaseObjectType, false ); 160 _out_rImageHC = getDefaultImage( _nDatabaseObjectType, true ); 161 } 162 else 163 { 164 // check whether the connection can give us an icon 165 Reference< XGraphic > xGraphic; 166 Reference< XGraphic > xGraphicHC; 167 lcl_getConnectionProvidedTableIcon_nothrow( *m_pData, _rName, xGraphic, xGraphicHC ); 168 if ( xGraphic.is() ) 169 _out_rImage = Image( xGraphic ); 170 if ( xGraphicHC.is() ) 171 _out_rImageHC = Image( xGraphicHC ); 172 173 if ( !_out_rImage || !_out_rImageHC ) 174 { 175 // no -> determine by type 176 sal_uInt16 nImageResourceID = 0; 177 sal_uInt16 nImageResourceID_HC = 0; 178 lcl_getTableImageResourceID_nothrow( *m_pData, _rName, nImageResourceID, nImageResourceID_HC ); 179 180 if ( nImageResourceID && !_out_rImage ) 181 _out_rImage = Image( ModuleRes( nImageResourceID ) ); 182 if ( nImageResourceID_HC && !_out_rImageHC ) 183 _out_rImageHC = Image( ModuleRes( nImageResourceID_HC ) ); 184 } 185 } 186 } 187 188 //-------------------------------------------------------------------- 189 Image ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 190 { 191 Image aObjectImage; 192 sal_uInt16 nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType, _bHighContrast ) ); 193 if ( nImageResourceID ) 194 aObjectImage = Image( ModuleRes( nImageResourceID ) ); 195 return aObjectImage; 196 } 197 198 //-------------------------------------------------------------------- 199 sal_uInt16 ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 200 { 201 sal_uInt16 nImageResourceID( 0 ); 202 switch ( _nDatabaseObjectType ) 203 { 204 case DatabaseObject::QUERY: 205 nImageResourceID = _bHighContrast ? QUERY_TREE_ICON_SCH : QUERY_TREE_ICON; 206 break; 207 case DatabaseObject::FORM: 208 nImageResourceID = _bHighContrast ? FORM_TREE_ICON_SCH : FORM_TREE_ICON; 209 break; 210 case DatabaseObject::REPORT: 211 nImageResourceID = _bHighContrast ? REPORT_TREE_ICON_SCH : REPORT_TREE_ICON; 212 break; 213 case DatabaseObject::TABLE: 214 nImageResourceID = _bHighContrast ? TABLE_TREE_ICON_SCH : TABLE_TREE_ICON; 215 break; 216 default: 217 OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" ); 218 break; 219 } 220 return nImageResourceID; 221 } 222 223 //-------------------------------------------------------------------- 224 Image ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 225 { 226 sal_uInt16 nImageResourceID( 0 ); 227 switch ( _nDatabaseObjectType ) 228 { 229 case DatabaseObject::QUERY: 230 nImageResourceID = _bHighContrast ? QUERYFOLDER_TREE_ICON_SCH : QUERYFOLDER_TREE_ICON; 231 break; 232 case DatabaseObject::FORM: 233 nImageResourceID = _bHighContrast ? FORMFOLDER_TREE_ICON_SCH : FORMFOLDER_TREE_ICON; 234 break; 235 case DatabaseObject::REPORT: 236 nImageResourceID = _bHighContrast ? REPORTFOLDER_TREE_ICON_SCH : REPORTFOLDER_TREE_ICON; 237 break; 238 case DatabaseObject::TABLE: 239 nImageResourceID = _bHighContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON; 240 break; 241 default: 242 OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" ); 243 break; 244 } 245 246 Image aFolderImage; 247 if ( nImageResourceID ) 248 aFolderImage = Image( ModuleRes( nImageResourceID ) ); 249 return aFolderImage; 250 } 251 252 //-------------------------------------------------------------------- 253 Image ImageProvider::getDatabaseImage( bool _bHighContrast ) 254 { 255 return Image( ModuleRes( _bHighContrast ? DATABASE_TREE_ICON_SCH : DATABASE_TREE_ICON ) ); 256 } 257 258 //........................................................................ 259 } // namespace dbaui 260 //........................................................................ 261 262