Kaydet (Commit) 614e787c authored tarafından Frank Schoenheit [fs]'s avatar Frank Schoenheit [fs]

#i106671# retrieve the images from the document's/module's XImageManager, not…

#i106671# retrieve the images from the document's/module's XImageManager, not from some obscure SfxImageManager
üst 595e1c2e
/*************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2009 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
************************************************************************/
#include "commandimageprovider.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/ui/XImageManager.hpp>
#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/ui/ImageType.hpp>
/** === end UNO includes === **/
#include <comphelper/componentcontext.hxx>
#include <tools/diagnose_ex.h>
//........................................................................
namespace frm
{
//........................................................................
/** === begin UNO using === **/
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Type;
using ::com::sun::star::frame::XModel;
using ::com::sun::star::ui::XImageManager;
using ::com::sun::star::ui::XUIConfigurationManagerSupplier;
using ::com::sun::star::ui::XUIConfigurationManager;
using ::com::sun::star::ui::XModuleUIConfigurationManagerSupplier;
using ::com::sun::star::frame::XModuleManager;
using ::com::sun::star::graphic::XGraphic;
/** === end UNO using === **/
namespace ImageType = ::com::sun::star::ui::ImageType;
//====================================================================
//= DocumentCommandImageProvider
//====================================================================
class DocumentCommandImageProvider : public ICommandImageProvider
{
public:
DocumentCommandImageProvider( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
{
impl_init_nothrow( _rContext, _rxDocument );
}
virtual ~DocumentCommandImageProvider()
{
}
// ICommandImageProvider
virtual CommandImages getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge, const bool _bHiContrast ) const;
private:
void impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument );
private:
Reference< XImageManager > m_xDocumentImageManager;
Reference< XImageManager > m_xModuleImageManager;
};
//--------------------------------------------------------------------
void DocumentCommandImageProvider::impl_init_nothrow( const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
{
OSL_ENSURE( _rxDocument.is(), "DocumentCommandImageProvider::impl_init_nothrow: no document => no images!" );
if ( !_rxDocument.is() )
return;
// obtain the image manager of the document
try
{
Reference< XUIConfigurationManagerSupplier > xSuppUIConfig( _rxDocument, UNO_QUERY_THROW );
Reference< XUIConfigurationManager > xUIConfig( xSuppUIConfig->getUIConfigurationManager(), UNO_QUERY );
m_xDocumentImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
// obtain the image manager or the module
try
{
Reference< XModuleManager > xModuleManager( _rContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
::rtl::OUString sModuleID = xModuleManager->identify( _rxDocument );
Reference< XModuleUIConfigurationManagerSupplier > xSuppUIConfig(
_rContext.createComponent( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ), UNO_QUERY_THROW );
Reference< XUIConfigurationManager > xUIConfig(
xSuppUIConfig->getUIConfigurationManager( sModuleID ), UNO_SET_THROW );
m_xModuleImageManager.set( xUIConfig->getImageManager(), UNO_QUERY_THROW );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
//--------------------------------------------------------------------
CommandImages DocumentCommandImageProvider::getCommandImages( const CommandURLs& _rCommandURLs, const bool _bLarge, const bool _bHiContrast ) const
{
const size_t nCommandCount = _rCommandURLs.getLength();
CommandImages aImages( nCommandCount );
try
{
const sal_Int16 nImageType =
( _bLarge ? ImageType::SIZE_LARGE : ImageType::SIZE_DEFAULT )
+ ( _bHiContrast ? ImageType::COLOR_HIGHCONTRAST : ImageType::COLOR_NORMAL );
Sequence< Reference< XGraphic > > aDocImages( nCommandCount );
Sequence< Reference< XGraphic > > aModImages( nCommandCount );
// first try the document image manager
if ( m_xDocumentImageManager.is() )
aDocImages = m_xDocumentImageManager->getImages( nImageType, _rCommandURLs );
// then the module's image manager
if ( m_xModuleImageManager.is() )
aModImages = m_xModuleImageManager->getImages( nImageType, _rCommandURLs );
ENSURE_OR_THROW( aDocImages.getLength() == nCommandCount, "illegal array size returned by getImages (document image manager)" );
ENSURE_OR_THROW( aModImages.getLength() == nCommandCount, "illegal array size returned by getImages (module image manager)" );
for ( size_t i=0; i<nCommandCount; ++i )
{
if ( aDocImages[i].is() )
aImages[i] = Image( aDocImages[i] );
else
aImages[i] = Image( aModImages[i] );
}
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
return aImages;
}
//--------------------------------------------------------------------
::boost::shared_ptr< ICommandImageProvider > createDocumentCommandImageProvider(
const ::comphelper::ComponentContext& _rContext, const Reference< XModel >& _rxDocument )
{
::boost::shared_ptr< ICommandImageProvider > pImageProvider( new DocumentCommandImageProvider( _rContext, _rxDocument ) );
return pImageProvider;
}
//........................................................................
} // namespace frm
//........................................................................
...@@ -53,6 +53,7 @@ SLOFILES= $(SLO)$/formnavigation.obj \ ...@@ -53,6 +53,7 @@ SLOFILES= $(SLO)$/formnavigation.obj \
$(SLO)$/urltransformer.obj \ $(SLO)$/urltransformer.obj \
$(SLO)$/windowstateguard.obj \ $(SLO)$/windowstateguard.obj \
$(SLO)$/resettable.obj \ $(SLO)$/resettable.obj \
$(SLO)$/commandimageprovider.obj \
# --- Targets ---------------------------------- # --- Targets ----------------------------------
......
/*************************************************************************
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2009 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
************************************************************************/
#ifndef COMMANDIMAGEPROVIDER_HXX
#define COMMANDIMAGEPROVIDER_HXX
/** === begin UNO includes === **/
#include <com/sun/star/frame/XModel.hpp>
/** === end UNO includes === **/
#include <comphelper/componentcontext.hxx>
#include <vcl/image.hxx>
#include <boost/shared_ptr.hpp>
//........................................................................
namespace frm
{
//........................................................................
//=====================================================================
//= ICommandImageProvider
//=====================================================================
typedef ::rtl::OUString CommandURL;
typedef ::com::sun::star::uno::Sequence< CommandURL > CommandURLs;
typedef ::std::vector< Image > CommandImages;
class SAL_NO_VTABLE ICommandImageProvider
{
public:
virtual CommandImages getCommandImages(
const CommandURLs& _rCommandURLs,
const bool _bLarge,
const bool _bHiContrast
) const = 0;
virtual ~ICommandImageProvider() { }
};
//=====================================================================
//= factory
//=====================================================================
::boost::shared_ptr< ICommandImageProvider >
createDocumentCommandImageProvider(
const ::comphelper::ComponentContext& _rContext,
const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& _rxDocument
);
//........................................................................
} // namespace frm
//........................................................................
#endif // COMMANDIMAGEPROVIDER_HXX
...@@ -34,18 +34,21 @@ ...@@ -34,18 +34,21 @@
#include "navbarcontrol.hxx" #include "navbarcontrol.hxx"
#include "frm_strings.hxx" #include "frm_strings.hxx"
#include "frm_module.hxx" #include "frm_module.hxx"
#include "navtoolbar.hxx"
#include "FormComponent.hxx" #include "FormComponent.hxx"
#include "componenttools.hxx"
#include "navtoolbar.hxx"
/** === begin UNO includes === **/ /** === begin UNO includes === **/
#include <com/sun/star/awt/XView.hpp> #include <com/sun/star/awt/XView.hpp>
#include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/awt/PosSize.hpp>
#include <com/sun/star/form/runtime/FormFeature.hpp> #include <com/sun/star/form/runtime/FormFeature.hpp>
#include <com/sun/star/awt/XControlModel.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
/** === end UNO includes === **/ /** === end UNO includes === **/
#include <tools/debug.hxx> #include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <svx/svxids.hrc>
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
extern "C" void SAL_CALL createRegistryInfo_ONavigationBarControl() extern "C" void SAL_CALL createRegistryInfo_ONavigationBarControl()
...@@ -63,6 +66,7 @@ namespace frm ...@@ -63,6 +66,7 @@ namespace frm
using namespace ::com::sun::star::awt; using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame; using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::graphic;
namespace FormFeature = ::com::sun::star::form::runtime::FormFeature; namespace FormFeature = ::com::sun::star::form::runtime::FormFeature;
#define FORWARD_TO_PEER_1( unoInterface, method, param1 ) \ #define FORWARD_TO_PEER_1( unoInterface, method, param1 ) \
...@@ -131,7 +135,8 @@ namespace frm ...@@ -131,7 +135,8 @@ namespace frm
//------------------------------------------------------------------ //------------------------------------------------------------------
namespace namespace
{ {
static WinBits getWinBits( const Reference< XControlModel >& _rxModel ) //..............................................................
static WinBits lcl_getWinBits_nothrow( const Reference< XControlModel >& _rxModel )
{ {
WinBits nBits = 0; WinBits nBits = 0;
try try
...@@ -151,7 +156,7 @@ namespace frm ...@@ -151,7 +156,7 @@ namespace frm
} }
catch( const Exception& ) catch( const Exception& )
{ {
DBG_ERROR( "::getWinBits: caught an exception!" ); DBG_UNHANDLED_EXCEPTION();
} }
return nBits; return nBits;
} }
...@@ -177,7 +182,7 @@ namespace frm ...@@ -177,7 +182,7 @@ namespace frm
} }
// create the peer // create the peer
ONavigationBarPeer* pPeer = ONavigationBarPeer::Create( m_xORB, pParentWin, getWinBits( getModel() ) ); ONavigationBarPeer* pPeer = ONavigationBarPeer::Create( m_xORB, pParentWin, getModel() );
DBG_ASSERT( pPeer, "ONavigationBarControl::createPeer: invalid peer returned!" ); DBG_ASSERT( pPeer, "ONavigationBarControl::createPeer: invalid peer returned!" );
if ( pPeer ) if ( pPeer )
// by definition, the returned component is aquired once // by definition, the returned component is aquired once
...@@ -269,7 +274,7 @@ namespace frm ...@@ -269,7 +274,7 @@ namespace frm
DBG_NAME( ONavigationBarPeer ) DBG_NAME( ONavigationBarPeer )
//------------------------------------------------------------------ //------------------------------------------------------------------
ONavigationBarPeer* ONavigationBarPeer::Create( const Reference< XMultiServiceFactory >& _rxORB, ONavigationBarPeer* ONavigationBarPeer::Create( const Reference< XMultiServiceFactory >& _rxORB,
Window* _pParentWindow, WinBits _nStyle ) Window* _pParentWindow, const Reference< XControlModel >& _rxModel )
{ {
DBG_TESTSOLARMUTEX(); DBG_TESTSOLARMUTEX();
...@@ -278,7 +283,11 @@ namespace frm ...@@ -278,7 +283,11 @@ namespace frm
pPeer->acquire(); // by definition, the returned object is aquired once pPeer->acquire(); // by definition, the returned object is aquired once
// the VCL control for the peer // the VCL control for the peer
NavigationToolBar* pNavBar = new NavigationToolBar( _pParentWindow, _nStyle ); NavigationToolBar* pNavBar = new NavigationToolBar(
_pParentWindow,
lcl_getWinBits_nothrow( _rxModel ),
createDocumentCommandImageProvider( _rxORB, getXModel( _rxModel ) )
);
// some knittings // some knittings
pNavBar->setDispatcher( pPeer ); pNavBar->setDispatcher( pPeer );
......
...@@ -31,14 +31,17 @@ ...@@ -31,14 +31,17 @@
#ifndef FORMS_NAVBARCONTROL_HXX #ifndef FORMS_NAVBARCONTROL_HXX
#define FORMS_NAVBARCONTROL_HXX #define FORMS_NAVBARCONTROL_HXX
#include "formnavigation.hxx"
#include "commandimageprovider.hxx"
#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
#include <com/sun/star/frame/XStatusListener.hpp>
#include <toolkit/controls/unocontrol.hxx> #include <toolkit/controls/unocontrol.hxx>
#include <toolkit/awt/vclxwindow.hxx> #include <toolkit/awt/vclxwindow.hxx>
#include <comphelper/uno3.hxx> #include <comphelper/uno3.hxx>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <vcl/wintypes.hxx> #include <vcl/wintypes.hxx>
#include <com/sun/star/frame/XDispatchProviderInterception.hpp>
#include <com/sun/star/frame/XStatusListener.hpp>
#include "formnavigation.hxx"
//......................................................................... //.........................................................................
namespace frm namespace frm
...@@ -111,11 +114,13 @@ namespace frm ...@@ -111,11 +114,13 @@ namespace frm
static ONavigationBarPeer* Create( static ONavigationBarPeer* Create(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
Window* _pParentWindow, Window* _pParentWindow,
WinBits _nStyle const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& _rxModel
); );
protected: protected:
ONavigationBarPeer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB ); ONavigationBarPeer(
const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB
);
~ONavigationBarPeer(); ~ONavigationBarPeer();
public: public:
......
...@@ -34,14 +34,18 @@ ...@@ -34,14 +34,18 @@
#include <vcl/toolbox.hxx> #include <vcl/toolbox.hxx>
#include <vcl/field.hxx> #include <vcl/field.hxx>
#include <boost/shared_ptr.hpp>
//......................................................................... //.........................................................................
namespace frm namespace frm
{ {
//......................................................................... //.........................................................................
class IFeatureDispatcher; class IFeatureDispatcher;
class ICommandImageProvider;
class ImplNavToolBar; class ImplNavToolBar;
//===================================================================== //=====================================================================
//= NavigationToolBar //= NavigationToolBar
//===================================================================== //=====================================================================
...@@ -63,13 +67,15 @@ namespace frm ...@@ -63,13 +67,15 @@ namespace frm
}; };
private: private:
const IFeatureDispatcher* m_pDispatcher; const IFeatureDispatcher* m_pDispatcher;
ImageSize m_eImageSize; ::boost::shared_ptr< const ICommandImageProvider >
ImplNavToolBar* m_pToolbar; m_pImageProvider;
::std::vector< Window* > m_aChildWins; ImageSize m_eImageSize;
ImplNavToolBar* m_pToolbar;
::std::vector< Window* > m_aChildWins;
public: public:
NavigationToolBar( Window* _pParent, WinBits _nStyle ); NavigationToolBar( Window* _pParent, WinBits _nStyle, const ::boost::shared_ptr< const ICommandImageProvider >& _pImageProvider );
~NavigationToolBar( ); ~NavigationToolBar( );
/** sets the dispatcher which is to be used for the features /** sets the dispatcher which is to be used for the features
...@@ -82,19 +88,16 @@ namespace frm ...@@ -82,19 +88,16 @@ namespace frm
ensuring the life time of the object does exceed the life time ensuring the life time of the object does exceed the life time
of the tool bar instance. of the tool bar instance.
*/ */
void setDispatcher( const IFeatureDispatcher* _pDispatcher ); void setDispatcher( const IFeatureDispatcher* _pDispatcher );
/** enables or disables a given feature /// enables or disables a given feature
*/ void enableFeature( sal_Int16 _nFeatureId, bool _bEnabled );
void enableFeature( sal_Int16 _nFeatureId, bool _bEnabled );
/** checks or unchecks a given feature /// checks or unchecks a given feature
*/ void checkFeature( sal_Int16 _nFeatureId, bool _bEnabled );
void checkFeature( sal_Int16 _nFeatureId, bool _bEnabled );
/** sets the text of a given feature /// sets the text of a given feature
*/ void setFeatureText( sal_Int16 _nFeatureId, const ::rtl::OUString& _rText );
void setFeatureText( sal_Int16 _nFeatureId, const ::rtl::OUString& _rText );
/** retrieves the current image size /** retrieves the current image size
*/ */
...@@ -127,7 +130,10 @@ namespace frm ...@@ -127,7 +130,10 @@ namespace frm
void implInit( ); void implInit( );
/// impl version of SetImageSize /// impl version of SetImageSize
void implSetImageSize( ImageSize _eSize, bool _bForce = false ); void implSetImageSize( ImageSize _eSize );
/// updates the images of our items
void implUpdateImages();
/// enables or disables an item, plus possible dependent items /// enables or disables an item, plus possible dependent items
void implEnableItem( USHORT _nItemId, bool _bEnabled ); void implEnableItem( USHORT _nItemId, bool _bEnabled );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment