1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "imageprovider.hxx"
21 #include "dbu_resource.hrc"
22 #include "moduledbu.hxx"
23 #include "dbustrings.hrc"
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/graphic/XGraphic.hpp>
27 #include <com/sun/star/graphic/GraphicColorMode.hpp>
28 #include <com/sun/star/sdb/application/XTableUIProvider.hpp>
29 #include <com/sun/star/sdbcx/XViewsSupplier.hpp>
31 #include <tools/diagnose_ex.h>
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::sdbc::XConnection
;
38 using ::com::sun::star::uno::Exception
;
39 using ::com::sun::star::uno::UNO_QUERY_THROW
;
40 using ::com::sun::star::container::XNameAccess
;
41 using ::com::sun::star::beans::XPropertySet
;
42 using ::com::sun::star::graphic::XGraphic
;
43 using ::com::sun::star::sdb::application::XTableUIProvider
;
44 using ::com::sun::star::uno::UNO_QUERY
;
45 using ::com::sun::star::sdbcx::XViewsSupplier
;
46 using ::com::sun::star::uno::UNO_SET_THROW
;
48 namespace GraphicColorMode
= css::graphic::GraphicColorMode
;
49 namespace DatabaseObject
= css::sdb::application::DatabaseObject
;
52 struct ImageProvider_Data
54 /// the connection we work with
55 Reference
< XConnection
> xConnection
;
56 /// the views of the connection, if the DB supports views
57 Reference
< XNameAccess
> xViews
;
58 /// interface for providing table's UI
59 Reference
< XTableUIProvider
> xTableUI
;
64 static void lcl_getConnectionProvidedTableIcon_nothrow( const ImageProvider_Data
& _rData
,
65 const OUString
& _rName
, Reference
< XGraphic
>& _out_rxGraphic
)
69 if ( _rData
.xTableUI
.is() )
70 _out_rxGraphic
= _rData
.xTableUI
->getTableIcon( _rName
, GraphicColorMode::NORMAL
);
72 catch( const Exception
& )
74 DBG_UNHANDLED_EXCEPTION();
78 static void lcl_getTableImageResourceID_nothrow( const ImageProvider_Data
& _rData
, const OUString
& _rName
,
79 sal_uInt16
& _out_rResourceID
)
84 bool bIsView
= _rData
.xViews
.is() && _rData
.xViews
->hasByName( _rName
);
87 _out_rResourceID
= VIEW_TREE_ICON
;
91 _out_rResourceID
= TABLE_TREE_ICON
;
94 catch( const Exception
& )
96 DBG_UNHANDLED_EXCEPTION();
101 ImageProvider::ImageProvider()
102 :m_pData( new ImageProvider_Data
)
106 ImageProvider::ImageProvider( const Reference
< XConnection
>& _rxConnection
)
107 :m_pData( new ImageProvider_Data
)
109 m_pData
->xConnection
= _rxConnection
;
112 Reference
< XViewsSupplier
> xSuppViews( m_pData
->xConnection
, UNO_QUERY
);
113 if ( xSuppViews
.is() )
114 m_pData
->xViews
.set( xSuppViews
->getViews(), UNO_SET_THROW
);
116 m_pData
->xTableUI
.set( _rxConnection
, UNO_QUERY
);
118 catch( const Exception
& )
120 DBG_UNHANDLED_EXCEPTION();
124 void ImageProvider::getImages( const OUString
& _rName
, const sal_Int32 _nDatabaseObjectType
, Image
& _out_rImage
)
126 if ( _nDatabaseObjectType
!= DatabaseObject::TABLE
)
128 // for types other than tables, the icon does not depend on the concrete object
129 _out_rImage
= getDefaultImage( _nDatabaseObjectType
);
133 // check whether the connection can give us an icon
134 Reference
< XGraphic
> xGraphic
;
135 lcl_getConnectionProvidedTableIcon_nothrow( *m_pData
, _rName
, xGraphic
);
137 _out_rImage
= Image( xGraphic
);
141 // no -> determine by type
142 sal_uInt16 nImageResourceID
= 0;
143 lcl_getTableImageResourceID_nothrow( *m_pData
, _rName
, nImageResourceID
);
145 if ( nImageResourceID
&& !_out_rImage
)
146 _out_rImage
= Image( ModuleRes( nImageResourceID
) );
151 Image
ImageProvider::getDefaultImage( sal_Int32 _nDatabaseObjectType
)
154 sal_uInt16
nImageResourceID( getDefaultImageResourceID( _nDatabaseObjectType
) );
155 if ( nImageResourceID
)
156 aObjectImage
= Image( ModuleRes( nImageResourceID
) );
160 sal_uInt16
ImageProvider::getDefaultImageResourceID( sal_Int32 _nDatabaseObjectType
)
162 sal_uInt16
nImageResourceID( 0 );
163 switch ( _nDatabaseObjectType
)
165 case DatabaseObject::QUERY
:
166 nImageResourceID
= QUERY_TREE_ICON
;
168 case DatabaseObject::FORM
:
169 nImageResourceID
= FORM_TREE_ICON
;
171 case DatabaseObject::REPORT
:
172 nImageResourceID
= REPORT_TREE_ICON
;
174 case DatabaseObject::TABLE
:
175 nImageResourceID
= TABLE_TREE_ICON
;
178 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
181 return nImageResourceID
;
184 Image
ImageProvider::getFolderImage( sal_Int32 _nDatabaseObjectType
)
186 sal_uInt16
nImageResourceID( 0 );
187 switch ( _nDatabaseObjectType
)
189 case DatabaseObject::QUERY
:
190 nImageResourceID
= QUERYFOLDER_TREE_ICON
;
192 case DatabaseObject::FORM
:
193 nImageResourceID
= FORMFOLDER_TREE_ICON
;
195 case DatabaseObject::REPORT
:
196 nImageResourceID
= REPORTFOLDER_TREE_ICON
;
198 case DatabaseObject::TABLE
:
199 nImageResourceID
= TABLEFOLDER_TREE_ICON
;
202 OSL_FAIL( "ImageProvider::getDefaultImage: invalid database object type!" );
207 if ( nImageResourceID
)
208 aFolderImage
= Image( ModuleRes( nImageResourceID
) );
212 Image
ImageProvider::getDatabaseImage()
214 return Image( ModuleRes( DATABASE_TREE_ICON
) );
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */