diff options
author | Ariel Constenla-Haile <arielch@apache.org> | 2013-05-25 22:11:58 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-06-24 11:25:34 +0100 |
commit | a1748501d81425d26d09509eec2fd141f2f28f05 (patch) | |
tree | ef1f7e42eb8d8afd660741229d6d628c7127667a /sfx2 | |
parent | a089ed2bf90fdb293c8502e4ab47cbbe027234f8 (diff) |
Kill SfxAppToolBoxControl_Impl
(cherry picked from commit 273121f8d7e277e35c8e5a8aad46ef0c103ebc03)
Conflicts:
sfx2/inc/sfx2/mnuitem.hxx
sfx2/inc/sfx2/tbxctrl.hxx
sfx2/source/appl/appreg.cxx
sfx2/source/menu/mnuitem.cxx
sfx2/source/toolbox/tbxitem.cxx
Change-Id: I6d0750d89ad009f82c5552d971537b78e45426f2
Silence warning C4706
(cherry picked from commit 0b373b3e4c45d09c40a8949e9366adb9b991de4b)
Change-Id: Id497469eba8288565145c47c84b7938a1316c21a
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/appreg.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/menu/mnuitem.cxx | 149 | ||||
-rw-r--r-- | sfx2/source/toolbox/tbxitem.cxx | 357 |
3 files changed, 147 insertions, 361 deletions
diff --git a/sfx2/source/appl/appreg.cxx b/sfx2/source/appl/appreg.cxx index f3e736566aaf..9e0dcecd0926 100644 --- a/sfx2/source/appl/appreg.cxx +++ b/sfx2/source/appl/appreg.cxx @@ -62,8 +62,6 @@ void SfxApplication::Registrations_Impl() // Controller SfxToolBoxControl::RegisterControl(SID_REPEAT); SfxURLToolBoxControl_Impl::RegisterControl(SID_OPENURL); - SfxAppToolBoxControl_Impl::RegisterControl( SID_NEWDOCDIRECT ); - SfxAppToolBoxControl_Impl::RegisterControl( SID_AUTOPILOTMENU ); SfxRecentFilesToolBoxControl::RegisterControl( SID_OPENDOC ); }; diff --git a/sfx2/source/menu/mnuitem.cxx b/sfx2/source/menu/mnuitem.cxx index 1a48896a350b..6530c88bebbf 100644 --- a/sfx2/source/menu/mnuitem.cxx +++ b/sfx2/source/menu/mnuitem.cxx @@ -24,13 +24,15 @@ #include <string> #include <com/sun/star/uno/Reference.h> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/frame/Desktop.hpp> #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/util/URL.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <comphelper/processfactory.hxx> +#include <com/sun/star/util/URLTransformer.hpp> #include <com/sun/star/util/XURLTransformer.hpp> +#include <comphelper/processfactory.hxx> #include <tools/urlobj.hxx> #include <svl/eitem.hxx> #include <svl/stritem.hxx> @@ -291,6 +293,99 @@ PopupMenu* SfxMenuControl::GetPopup () const return 0; } +long Select_Impl( void* pHdl, void* pVoid ); + +SFX_IMPL_MENU_CONTROL( SfxAppMenuControl_Impl, SfxStringItem ); + +SfxAppMenuControl_Impl::SfxAppMenuControl_Impl( + sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings ) + : SfxMenuControl( nPos, rBindings ), pMenu(0) +{ + String aText = rMenu.GetItemText( nPos ); + + // Determine the current background color setting for menus + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + m_nSymbolsStyle = rSettings.GetSymbolsStyle(); + m_bShowMenuImages = rSettings.GetUseImagesInMenus(); + + ::framework::MenuConfiguration aConf( ::comphelper::getProcessComponentContext() ); + Reference<com::sun::star::frame::XFrame> aXFrame( GetBindings().GetDispatcher_Impl()->GetFrame()->GetFrame().GetFrameInterface() ); + pMenu = aConf.CreateBookmarkMenu( aXFrame, GetId() == SID_NEWDOCDIRECT ? BOOKMARK_NEWMENU : BOOKMARK_WIZARDMENU ); + if( pMenu ) + { + pMenu->SetSelectHdl( Link( &(this->GetBindings()), Select_Impl ) ); + pMenu->SetActivateHdl( LINK(this, SfxAppMenuControl_Impl, Activate) ); + rMenu.SetPopupMenu( nPos, pMenu ); + } +} + +SfxAppMenuControl_Impl::~SfxAppMenuControl_Impl() +{ + delete pMenu; +} + +IMPL_LINK( SfxAppMenuControl_Impl, Activate, Menu *, pActMenu ) +{ + if ( pActMenu ) + { + const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); + sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle(); + sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus(); + + if (( nSymbolsStyle != m_nSymbolsStyle ) || + ( bShowMenuImages != m_bShowMenuImages )) + { + m_nSymbolsStyle = nSymbolsStyle; + m_bShowMenuImages = bShowMenuImages; + + sal_uInt16 nCount = pActMenu->GetItemCount(); + for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ ) + { + sal_uInt16 nItemId = pActMenu->GetItemId( nSVPos ); + if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR ) + { + if ( bShowMenuImages ) + { + sal_Bool bImageSet = sal_False; + ::rtl::OUString aImageId; + ::framework::MenuConfiguration::Attributes* pMenuAttributes = + (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nItemId ); + + if ( pMenuAttributes ) + aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes + + if ( aImageId.getLength() > 0 ) + { + Reference< ::com::sun::star::frame::XFrame > xFrame; + Image aImage = GetImage( xFrame, aImageId, sal_False ); + if ( !!aImage ) + { + bImageSet = sal_True; + pActMenu->SetItemImage( nItemId, aImage ); + } + } + + String aCmd( pActMenu->GetItemCommand( nItemId ) ); + if ( !bImageSet && aCmd.Len() ) + { + Image aImage = SvFileInformationManager::GetImage( + INetURLObject(aCmd), sal_False ); + if ( !!aImage ) + pActMenu->SetItemImage( nItemId, aImage ); + } + } + else + pActMenu->SetItemImage( nItemId, Image() ); + } + } + } + + return sal_True; + } + + return sal_False; +} + SfxUnoMenuControl* SfxMenuControl::CreateControl( const String& rCmd, sal_uInt16 nId, Menu& rMenu, const String& sItemText, SfxBindings& rBindings, SfxVirtualMenu* pVirt) @@ -317,4 +412,54 @@ SfxUnoMenuControl::~SfxUnoMenuControl() pUnoCtrl->release(); } +long Select_Impl( void* /*pHdl*/, void* pVoid ) +{ + Menu* pMenu = (Menu*)pVoid; + String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) ); + + if( !aURL.Len() ) + return 0; + + Reference < ::com::sun::star::frame::XDesktop2 > xDesktop = + ::com::sun::star::frame::Desktop::create( ::comphelper::getProcessComponentContext() ); + + URL aTargetURL; + aTargetURL.Complete = aURL; + Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) ); + xTrans->parseStrict( aTargetURL ); + + Reference < XDispatch > xDisp; + if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL ) + xDisp = xDesktop->queryDispatch( aTargetURL, OUString(), 0 ); + else + { + OUString aTargetFrame( OUString("_blank") ); + ::framework::MenuConfiguration::Attributes* pMenuAttributes = + (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() ); + + if ( pMenuAttributes ) + aTargetFrame = pMenuAttributes->aTargetFrame; + + xDisp = xDesktop->queryDispatch( aTargetURL, aTargetFrame , 0 ); + } + + if ( xDisp.is() ) + { + SfxAppMenuControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppMenuControl_Impl::ExecuteInfo; + pExecuteInfo->xDispatch = xDisp; + pExecuteInfo->aTargetURL = aTargetURL; + pExecuteInfo->aArgs = Sequence< PropertyValue >(); + Application::PostUserEvent( STATIC_LINK( 0, SfxAppMenuControl_Impl, ExecuteHdl_Impl), pExecuteInfo ); + } + + return sal_True; +} + +IMPL_STATIC_LINK_NOINSTANCE( SfxAppMenuControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) +{ + pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); + delete pExecuteInfo; + return 0; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx index b8913eb5e597..e5b188b3c592 100644 --- a/sfx2/source/toolbox/tbxitem.cxx +++ b/sfx2/source/toolbox/tbxitem.cxx @@ -108,7 +108,6 @@ using namespace ::com::sun::star::ui; //==================================================================== SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True); -SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem); SFX_IMPL_TOOLBOX_CONTROL(SfxRecentFilesToolBoxControl, SfxStringItem); static Window* GetTopMostParentSystemWindow( Window* pWindow ) @@ -1392,362 +1391,6 @@ void SfxPopupWindow::Delete() //-------------------------------------------------------------------- -SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) - : SfxToolBoxControl( nSlotId, nId, rBox ) - , pMenu( 0 ) -{ - rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW ); - rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN); - - // Determine the current background color of the menus - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); - m_nSymbolsStyle = rSettings.GetSymbolsStyle(); - m_bShowMenuImages = rSettings.GetUseImagesInMenus(); - - SetImage( String() ); -} - -SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl() -{ - delete pMenu; -} - -//_____________________________________________________ -/* - it return the existing state of the given URL in the popupmenu of this toolbox control. - - If the given URL can be located as an action command of one menu item of the - popup menu of this control, we return sal_True. Otherwhise we return sal_False. - Further we return a fallback URL, in case we have to return sal_False. Because - the outside code must select a valid item of the popup menu everytime ... - and we define it here. By the way this m ethod was written to handle - error situations gracefully. E.g. it can be called during creation time - but then we have no valid menu. For this case we know another fallback URL. - Then we return the private:factory/ URL of the default factory. - - @param *pMenu - pounts to the popup menu, on which item we try to locate the given URL - Can be NULL! Search will be supressed then. - - @param sURL - the URL for searching - - @param pFallback - contains the fallback URL in case we return FALSE - Must point to valid memory! - - @param pImage - contains the image of the menu for the URL. - - @return sal_True - if URL could be located as an item of the popup menu. - sal_False - otherwise. -*/ -sal_Bool Impl_ExistURLInMenu( const PopupMenu *pMenu , - String &sURL , - String *pFallback , - Image *pImage ) -{ - sal_Bool bValidFallback = sal_False; - if (pMenu && sURL.Len()) - { - sal_uInt16 c = pMenu->GetItemCount(); - for (sal_uInt16 p=0; p<c; ++p) - { - sal_uInt16 nId = pMenu->GetItemId(p); - String aCmd( pMenu->GetItemCommand(nId) ); - - if (!bValidFallback && aCmd.Len()) - { - *pFallback = aCmd; - bValidFallback = sal_True; - } - - if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667# - { - sURL = aCmd; - *pImage = pMenu->GetItemImage( nId ); - return sal_True; - } - } - } - - if (!bValidFallback) - { - *pFallback = "private:factory/" + SvtModuleOptions().GetDefaultModuleName(); - } - - return sal_False; -} - -long Select_Impl( void* pHdl, void* pVoid ); - -SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow() -{ - ToolBox& rBox = GetToolBox(); - ::Rectangle aRect( rBox.GetItemRect( GetId() ) ); - - if ( !pMenu ) - { - ::framework::MenuConfiguration aConf( m_xContext ); - if ( m_aCommandURL == ".uno:AddDirect" ) - pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU ); - else - pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU ); - } - - if ( pMenu ) - { - pMenu->SetSelectHdl( Link( NULL, Select_Impl ) ); - pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate )); - rBox.SetItemDown( GetId(), sal_True ); - sal_uInt16 nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN ); - if ( nSelected ) - { - aLastURL = pMenu->GetItemCommand( nSelected ); - SetImage( pMenu->GetItemCommand( nSelected ) ); - } - - rBox.SetItemDown( GetId(), sal_False ); - } - - return 0; -} - -void SfxAppToolBoxControl_Impl::SetImage( const String &rURL ) -{ - /* We accept URL's here only, which exist as items of our internal popup menu. - All other ones will be ignored and a fallback is used ... */ - String aURL = rURL; - String sFallback; - Image aMenuImage; - sal_Bool bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage); - if (!bValid) - aURL = sFallback; - - sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge(); - Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig ); - if ( !aImage ) - aImage = !!aMenuImage ? aMenuImage : - SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig ); - Size aBigSize( GetToolBox().GetDefaultImageSize() ); - if ( bBig && aImage.GetSizePixel() != aBigSize ) - { - BitmapEx aScaleBmpEx( aImage.GetBitmapEx() ); - aScaleBmpEx.Scale( aBigSize, BMP_SCALE_BESTQUALITY ); - GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) ); - } - else - GetToolBox().SetItemImage( GetId(), aImage ); - aLastURL = aURL; -} - -void SfxAppToolBoxControl_Impl::StateChanged -( - sal_uInt16 nSlotId, - SfxItemState eState, - const SfxPoolItem* pState -) -{ - if ( pState && pState->ISA(SfxStringItem) ) - { - // Important step for following SetImage() call! - // It needs the valid pMenu item to fullfill it's specification - // to check for supported URLs ... - if ( !pMenu ) - { - ::framework::MenuConfiguration aConf( m_xContext ); - // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct - // popup menu according to the slot ID our controller has been initialized with. - if ( nSlotId == SID_NEWDOCDIRECT ) - pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU ); - else - pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU ); - } - - GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED ); - SetImage(((const SfxStringItem*)pState)->GetValue()); - } - else - SfxToolBoxControl::StateChanged( nSlotId, eState, pState ); -} - -//-------------------------------------------------------------------- - -void SfxAppToolBoxControl_Impl::Select( sal_Bool bMod1 ) -{ - if( aLastURL.Len() ) - { - URL aTargetURL; - Reference< XDispatch > xDispatch; - Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY ); - - if ( xDispatchProvider.is() ) - { - aTargetURL.Complete = aLastURL; - getURLTransformer()->parseStrict( aTargetURL ); - - OUString aTarget( OUString("_default")); - if ( pMenu ) - { - ::framework::MenuConfiguration::Attributes* pMenuAttributes = - (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() ); - - if ( pMenuAttributes ) - aTarget = pMenuAttributes->aTargetFrame; - } - - xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 ); - - if ( xDispatch.is() ) - { - Sequence< PropertyValue > aArgs( 1 ); - - aArgs[0].Name = OUString("Referer"); - aArgs[0].Value = makeAny( OUString(SFX_REFERER_USER ) ); - - ExecuteInfo* pExecuteInfo = new ExecuteInfo; - pExecuteInfo->xDispatch = xDispatch; - pExecuteInfo->aTargetURL = aTargetURL; - pExecuteInfo->aArgs = aArgs; - Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo ); - } - } - } - else - SfxToolBoxControl::Select( bMod1 ); -} - -//-------------------------------------------------------------------- -long Select_Impl( void* /*pHdl*/, void* pVoid ) -{ - Menu* pMenu = (Menu*)pVoid; - String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) ); - - if( !aURL.Len() ) - return 0; - - Reference < ::com::sun::star::frame::XDesktop2 > xDesktop = - ::com::sun::star::frame::Desktop::create( ::comphelper::getProcessComponentContext() ); - - URL aTargetURL; - aTargetURL.Complete = aURL; - Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) ); - xTrans->parseStrict( aTargetURL ); - - Reference < XDispatch > xDisp; - if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL ) - xDisp = xDesktop->queryDispatch( aTargetURL, OUString(), 0 ); - else - { - OUString aTargetFrame( OUString("_blank") ); - ::framework::MenuConfiguration::Attributes* pMenuAttributes = - (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() ); - - if ( pMenuAttributes ) - aTargetFrame = pMenuAttributes->aTargetFrame; - - xDisp = xDesktop->queryDispatch( aTargetURL, aTargetFrame , 0 ); - } - - if ( xDisp.is() ) - { - SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo; - pExecuteInfo->xDispatch = xDisp; - pExecuteInfo->aTargetURL = aTargetURL; - pExecuteInfo->aArgs = Sequence< PropertyValue >(); - Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo ); - } - - return sal_True; -} - -IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu ) -{ - if ( pActMenu ) - { - const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings(); - sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle(); - sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus(); - - if (( nSymbolsStyle != m_nSymbolsStyle ) || - ( bShowMenuImages != m_bShowMenuImages )) - { - m_nSymbolsStyle = nSymbolsStyle; - m_bShowMenuImages = bShowMenuImages; - - sal_uInt16 nCount = pActMenu->GetItemCount(); - for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ ) - { - sal_uInt16 nId = pActMenu->GetItemId( nSVPos ); - if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR ) - { - if ( bShowMenuImages ) - { - sal_Bool bImageSet = sal_False; - OUString aImageId; - ::framework::MenuConfiguration::Attributes* pMenuAttributes = - (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId ); - - if ( pMenuAttributes ) - aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes - - if ( !aImageId.isEmpty() ) - { - Reference< ::com::sun::star::frame::XFrame > xFrame; - Image aImage = GetImage( xFrame, aImageId, false ); - if ( !!aImage ) - { - bImageSet = sal_True; - pActMenu->SetItemImage( nId, aImage ); - } - } - - String aCmd( pActMenu->GetItemCommand( nId ) ); - if ( !bImageSet && aCmd.Len() ) - { - Image aImage = SvFileInformationManager::GetImage( - INetURLObject(aCmd), false ); - if ( !!aImage ) - pActMenu->SetItemImage( nId, aImage ); - } - } - else - pActMenu->SetItemImage( nId, Image() ); - } - } - } - - return sal_True; - } - - return sal_False; -} - -//-------------------------------------------------------------------- - -IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo ) -{ -/* i62706: Don't catch all exceptions. We hide all problems here and are not able - to handle them on higher levels. - try - { -*/ - // Asynchronous execution as this can lead to our own destruction! - // Framework can recycle our current frame and the layout manager disposes all user interface - // elements if a component gets detached from its frame! - pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs ); - delete pExecuteInfo; - return 0; -} - -//-------------------------------------------------------------------- - -void SfxAppToolBoxControl_Impl::Click( ) -{ -} - -//-------------------------------------------------------------------- - SfxRecentFilesToolBoxControl::SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox ) : SfxToolBoxControl( nSlotId, nId, rBox ) { |