196de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 396de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 496de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 596de5490SAndrew Rist * distributed with this work for additional information 696de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 796de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 896de5490SAndrew Rist * "License"); you may not use this file except in compliance 996de5490SAndrew Rist * with the License. You may obtain a copy of the License at 1096de5490SAndrew Rist * 1196de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 1296de5490SAndrew Rist * 1396de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 1496de5490SAndrew Rist * software distributed under the License is distributed on an 1596de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1696de5490SAndrew Rist * KIND, either express or implied. See the License for the 1796de5490SAndrew Rist * specific language governing permissions and limitations 1896de5490SAndrew Rist * under the License. 1996de5490SAndrew Rist * 2096de5490SAndrew Rist *************************************************************/ 2196de5490SAndrew Rist 2296de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25*b63233d8Sdamjan #include "precompiled_dbui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "imageprovider.hxx" 28cdf0e10cSrcweir #include "dbu_resource.hrc" 29cdf0e10cSrcweir #include "moduledbu.hxx" 30cdf0e10cSrcweir #include "dbustrings.hrc" 31cdf0e10cSrcweir 32cdf0e10cSrcweir /** === begin UNO includes === **/ 33cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp> 35cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicColorMode.hpp> 36cdf0e10cSrcweir #include <com/sun/star/sdb/application/XTableUIProvider.hpp> 37cdf0e10cSrcweir #include <com/sun/star/sdbcx/XViewsSupplier.hpp> 38cdf0e10cSrcweir /** === end UNO includes === **/ 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <tools/diagnose_ex.h> 41cdf0e10cSrcweir 42cdf0e10cSrcweir //........................................................................ 43cdf0e10cSrcweir namespace dbaui 44cdf0e10cSrcweir { 45cdf0e10cSrcweir //........................................................................ 46cdf0e10cSrcweir 47cdf0e10cSrcweir /** === begin UNO using === **/ 48cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 49cdf0e10cSrcweir using ::com::sun::star::sdbc::XConnection; 50cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 51cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 52cdf0e10cSrcweir using ::com::sun::star::container::XNameAccess; 53cdf0e10cSrcweir using ::com::sun::star::beans::XPropertySet; 54cdf0e10cSrcweir using ::com::sun::star::graphic::XGraphic; 55cdf0e10cSrcweir using ::com::sun::star::sdb::application::XTableUIProvider; 56cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 57cdf0e10cSrcweir using ::com::sun::star::sdbcx::XViewsSupplier; 58cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 59cdf0e10cSrcweir /** === end UNO using === **/ 60cdf0e10cSrcweir namespace GraphicColorMode = ::com::sun::star::graphic::GraphicColorMode; 61cdf0e10cSrcweir 62cdf0e10cSrcweir //==================================================================== 63cdf0e10cSrcweir //= ImageProvider_Data 64cdf0e10cSrcweir //==================================================================== 65cdf0e10cSrcweir struct ImageProvider_Data 66cdf0e10cSrcweir { 67cdf0e10cSrcweir /// the connection we work with 68cdf0e10cSrcweir Reference< XConnection > xConnection; 69cdf0e10cSrcweir /// the views of the connection, if the DB supports views 70cdf0e10cSrcweir Reference< XNameAccess > xViews; 71cdf0e10cSrcweir /// interface for providing table's UI 72cdf0e10cSrcweir Reference< XTableUIProvider > xTableUI; 73cdf0e10cSrcweir }; 74cdf0e10cSrcweir 75cdf0e10cSrcweir //-------------------------------------------------------------------- 76cdf0e10cSrcweir namespace 77cdf0e10cSrcweir { 78cdf0e10cSrcweir //................................................................ lcl_getConnectionProvidedTableIcon_nothrow(const ImageProvider_Data & _rData,const::rtl::OUString & _rName,Reference<XGraphic> & _out_rxGraphic,Reference<XGraphic> & _out_rxGraphicHC)79cdf0e10cSrcweir static void lcl_getConnectionProvidedTableIcon_nothrow( const ImageProvider_Data& _rData, 80cdf0e10cSrcweir const ::rtl::OUString& _rName, Reference< XGraphic >& _out_rxGraphic, Reference< XGraphic >& _out_rxGraphicHC ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir try 83cdf0e10cSrcweir { 84cdf0e10cSrcweir if ( _rData.xTableUI.is() ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir _out_rxGraphic = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::NORMAL ); 87cdf0e10cSrcweir _out_rxGraphicHC = _rData.xTableUI->getTableIcon( _rName, GraphicColorMode::HIGH_CONTRAST ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir } 90cdf0e10cSrcweir catch( const Exception& ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir //................................................................ lcl_getTableImageResourceID_nothrow(const ImageProvider_Data & _rData,const::rtl::OUString & _rName,sal_uInt16 & _out_rResourceID,sal_uInt16 & _out_rResourceID_HC)97cdf0e10cSrcweir static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data& _rData, const ::rtl::OUString& _rName, 98cdf0e10cSrcweir sal_uInt16& _out_rResourceID, sal_uInt16& _out_rResourceID_HC ) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir _out_rResourceID = _out_rResourceID_HC = 0; 101cdf0e10cSrcweir try 102cdf0e10cSrcweir { 103cdf0e10cSrcweir bool bIsView = _rData.xViews.is() && _rData.xViews->hasByName( _rName ); 104cdf0e10cSrcweir if ( bIsView ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir _out_rResourceID = VIEW_TREE_ICON; 107cdf0e10cSrcweir _out_rResourceID_HC = VIEW_TREE_ICON_SCH; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir else 110cdf0e10cSrcweir { 111cdf0e10cSrcweir _out_rResourceID = TABLE_TREE_ICON; 112cdf0e10cSrcweir _out_rResourceID_HC = TABLE_TREE_ICON_SCH; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir } 115cdf0e10cSrcweir catch( const Exception& ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir } 120cdf0e10cSrcweir } 121cdf0e10cSrcweir //==================================================================== 122cdf0e10cSrcweir //= ImageProvider 123cdf0e10cSrcweir //==================================================================== 124cdf0e10cSrcweir //-------------------------------------------------------------------- ImageProvider()125cdf0e10cSrcweir ImageProvider::ImageProvider() 126cdf0e10cSrcweir :m_pData( new ImageProvider_Data ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir //-------------------------------------------------------------------- ImageProvider(const Reference<XConnection> & _rxConnection)131cdf0e10cSrcweir ImageProvider::ImageProvider( const Reference< XConnection >& _rxConnection ) 132cdf0e10cSrcweir :m_pData( new ImageProvider_Data ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir m_pData->xConnection = _rxConnection; 135cdf0e10cSrcweir try 136cdf0e10cSrcweir { 137cdf0e10cSrcweir Reference< XViewsSupplier > xSuppViews( m_pData->xConnection, UNO_QUERY ); 138cdf0e10cSrcweir if ( xSuppViews.is() ) 139cdf0e10cSrcweir m_pData->xViews.set( xSuppViews->getViews(), UNO_SET_THROW ); 140cdf0e10cSrcweir 141cdf0e10cSrcweir m_pData->xTableUI.set( _rxConnection, UNO_QUERY ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir catch( const Exception& ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 146cdf0e10cSrcweir } 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir //-------------------------------------------------------------------- getImages(const String & _rName,const sal_Int32 _nDatabaseObjectType,Image & _out_rImage,Image & _out_rImageHC)150cdf0e10cSrcweir void ImageProvider::getImages( const String& _rName, const sal_Int32 _nDatabaseObjectType, Image& _out_rImage, Image& _out_rImageHC ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir if ( _nDatabaseObjectType != DatabaseObject::TABLE ) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir // for types other than tables, the icon does not depend on the concrete object 155cdf0e10cSrcweir _out_rImage = getDefaultImage( _nDatabaseObjectType, false ); 156cdf0e10cSrcweir _out_rImageHC = getDefaultImage( _nDatabaseObjectType, true ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir else 159cdf0e10cSrcweir { 160cdf0e10cSrcweir // check whether the connection can give us an icon 161cdf0e10cSrcweir Reference< XGraphic > xGraphic; 162cdf0e10cSrcweir Reference< XGraphic > xGraphicHC; 163cdf0e10cSrcweir lcl_getConnectionProvidedTableIcon_nothrow( *m_pData, _rName, xGraphic, xGraphicHC ); 164cdf0e10cSrcweir if ( xGraphic.is() ) 165cdf0e10cSrcweir _out_rImage = Image( xGraphic ); 166cdf0e10cSrcweir if ( xGraphicHC.is() ) 167cdf0e10cSrcweir _out_rImageHC = Image( xGraphicHC ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir if ( !_out_rImage || !_out_rImageHC ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir // no -> determine by type 172cdf0e10cSrcweir sal_uInt16 nImageResourceID = 0; 173cdf0e10cSrcweir sal_uInt16 nImageResourceID_HC = 0; 174cdf0e10cSrcweir lcl_getTableImageResourceID_nothrow( *m_pData, _rName, nImageResourceID, nImageResourceID_HC ); 175cdf0e10cSrcweir 176cdf0e10cSrcweir if ( nImageResourceID && !_out_rImage ) 177cdf0e10cSrcweir _out_rImage = Image( ModuleRes( nImageResourceID ) ); 178cdf0e10cSrcweir if ( nImageResourceID_HC && !_out_rImageHC ) 179cdf0e10cSrcweir _out_rImageHC = Image( ModuleRes( nImageResourceID_HC ) ); 180cdf0e10cSrcweir } 181cdf0e10cSrcweir } 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir //-------------------------------------------------------------------- getDefaultImage(sal_Int32 _nDatabaseObjectType,bool _bHighContrast)185cdf0e10cSrcweir Image ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir Image aObjectImage; 188cdf0e10cSrcweir sal_uInt16 nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType, _bHighContrast ) ); 189cdf0e10cSrcweir if ( nImageResourceID ) 190cdf0e10cSrcweir aObjectImage = Image( ModuleRes( nImageResourceID ) ); 191cdf0e10cSrcweir return aObjectImage; 192cdf0e10cSrcweir } 193cdf0e10cSrcweir 194cdf0e10cSrcweir //-------------------------------------------------------------------- getDefaultImageResourceID(sal_Int32 _nDatabaseObjectType,bool _bHighContrast)195cdf0e10cSrcweir sal_uInt16 ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir sal_uInt16 nImageResourceID( 0 ); 198cdf0e10cSrcweir switch ( _nDatabaseObjectType ) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir case DatabaseObject::QUERY: 201cdf0e10cSrcweir nImageResourceID = _bHighContrast ? QUERY_TREE_ICON_SCH : QUERY_TREE_ICON; 202cdf0e10cSrcweir break; 203cdf0e10cSrcweir case DatabaseObject::FORM: 204cdf0e10cSrcweir nImageResourceID = _bHighContrast ? FORM_TREE_ICON_SCH : FORM_TREE_ICON; 205cdf0e10cSrcweir break; 206cdf0e10cSrcweir case DatabaseObject::REPORT: 207cdf0e10cSrcweir nImageResourceID = _bHighContrast ? REPORT_TREE_ICON_SCH : REPORT_TREE_ICON; 208cdf0e10cSrcweir break; 209cdf0e10cSrcweir case DatabaseObject::TABLE: 210cdf0e10cSrcweir nImageResourceID = _bHighContrast ? TABLE_TREE_ICON_SCH : TABLE_TREE_ICON; 211cdf0e10cSrcweir break; 212cdf0e10cSrcweir default: 213cdf0e10cSrcweir OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" ); 214cdf0e10cSrcweir break; 215cdf0e10cSrcweir } 216cdf0e10cSrcweir return nImageResourceID; 217cdf0e10cSrcweir } 218cdf0e10cSrcweir 219cdf0e10cSrcweir //-------------------------------------------------------------------- getFolderImage(sal_Int32 _nDatabaseObjectType,bool _bHighContrast)220cdf0e10cSrcweir Image ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType, bool _bHighContrast ) 221cdf0e10cSrcweir { 222cdf0e10cSrcweir sal_uInt16 nImageResourceID( 0 ); 223cdf0e10cSrcweir switch ( _nDatabaseObjectType ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir case DatabaseObject::QUERY: 226cdf0e10cSrcweir nImageResourceID = _bHighContrast ? QUERYFOLDER_TREE_ICON_SCH : QUERYFOLDER_TREE_ICON; 227cdf0e10cSrcweir break; 228cdf0e10cSrcweir case DatabaseObject::FORM: 229cdf0e10cSrcweir nImageResourceID = _bHighContrast ? FORMFOLDER_TREE_ICON_SCH : FORMFOLDER_TREE_ICON; 230cdf0e10cSrcweir break; 231cdf0e10cSrcweir case DatabaseObject::REPORT: 232cdf0e10cSrcweir nImageResourceID = _bHighContrast ? REPORTFOLDER_TREE_ICON_SCH : REPORTFOLDER_TREE_ICON; 233cdf0e10cSrcweir break; 234cdf0e10cSrcweir case DatabaseObject::TABLE: 235cdf0e10cSrcweir nImageResourceID = _bHighContrast ? TABLEFOLDER_TREE_ICON_SCH : TABLEFOLDER_TREE_ICON; 236cdf0e10cSrcweir break; 237cdf0e10cSrcweir default: 238cdf0e10cSrcweir OSL_ENSURE( false, "ImageProvider::getDefaultImage: invalid database object type!" ); 239cdf0e10cSrcweir break; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir Image aFolderImage; 243cdf0e10cSrcweir if ( nImageResourceID ) 244cdf0e10cSrcweir aFolderImage = Image( ModuleRes( nImageResourceID ) ); 245cdf0e10cSrcweir return aFolderImage; 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir //-------------------------------------------------------------------- getDatabaseImage(bool _bHighContrast)249cdf0e10cSrcweir Image ImageProvider::getDatabaseImage( bool _bHighContrast ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir return Image( ModuleRes( _bHighContrast ? DATABASE_TREE_ICON_SCH : DATABASE_TREE_ICON ) ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir //........................................................................ 255cdf0e10cSrcweir } // namespace dbaui 256cdf0e10cSrcweir //........................................................................ 257cdf0e10cSrcweir 258