Kaydet (Commit) 273121f8 authored tarafından Ariel Constenla-Haile's avatar Ariel Constenla-Haile

Kill SfxAppToolBoxControl_Impl

üst c1954d6e
...@@ -37,6 +37,9 @@ struct SfxMenuCtrlFactory; ...@@ -37,6 +37,9 @@ struct SfxMenuCtrlFactory;
#include <tools/string.hxx> #include <tools/string.hxx>
#include <sfx2/ctrlitem.hxx> #include <sfx2/ctrlitem.hxx>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/util/URL.hpp>
class SFX2_DLLPUBLIC SfxMenuControl: public SfxControllerItem class SFX2_DLLPUBLIC SfxMenuControl: public SfxControllerItem
{ {
//friend SvStream& operator<<( SvStream& rStream, const SfxMenuControl& rItem ); //friend SvStream& operator<<( SvStream& rStream, const SfxMenuControl& rItem );
...@@ -165,6 +168,15 @@ public: ...@@ -165,6 +168,15 @@ public:
SFX_DECL_MENU_CONTROL(); SFX_DECL_MENU_CONTROL();
SfxAppMenuControl_Impl( sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings ); SfxAppMenuControl_Impl( sal_uInt16 nPos, Menu& rMenu, SfxBindings& rBindings );
~SfxAppMenuControl_Impl(); ~SfxAppMenuControl_Impl();
struct ExecuteInfo
{
::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
::com::sun::star::util::URL aTargetURL;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
};
DECL_STATIC_LINK( SfxAppMenuControl_Impl, ExecuteHdl_Impl, ExecuteInfo* );
}; };
//#endif //#endif
......
...@@ -346,46 +346,6 @@ public: ...@@ -346,46 +346,6 @@ public:
//------------------------------------------------------------------------ //------------------------------------------------------------------------
class SfxAppToolBoxControl_Impl : public SfxToolBoxControl
/* [Beschreibung]
Interne Hilfsklasse f"ur um das Popup-Menu <AppMenu_Impl> unter Neu
im SDT zu starten.
*/
{
public:
SFX_DECL_TOOLBOX_CONTROL();
SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
~SfxAppToolBoxControl_Impl();
void SetImage( const String& rFacName );
struct ExecuteInfo
{
::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
::com::sun::star::util::URL aTargetURL;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs;
};
DECL_STATIC_LINK( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo* );
protected:
virtual void Click();
using SfxToolBoxControl::Select;
virtual void Select( sal_Bool );
virtual void StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState );
virtual SfxPopupWindow* CreatePopupWindow();
DECL_LINK( Activate, Menu * ); // Needed to support high contrast images
private:
String aLastURL;
sal_Bool bBigImages;
PopupMenu* pMenu;
sal_uIntPtr m_nSymbolsStyle;
sal_Bool m_bWasHiContrastMode;
sal_Bool m_bShowMenuImages;
};
class SfxHistoryToolBoxControl_Impl : public SfxToolBoxControl class SfxHistoryToolBoxControl_Impl : public SfxToolBoxControl
{ {
Timer aTimer; Timer aTimer;
......
...@@ -69,8 +69,6 @@ void SfxApplication::Registrations_Impl() ...@@ -69,8 +69,6 @@ void SfxApplication::Registrations_Impl()
// Controller // Controller
SfxToolBoxControl::RegisterControl(SID_REPEAT); SfxToolBoxControl::RegisterControl(SID_REPEAT);
SfxURLToolBoxControl_Impl::RegisterControl(SID_OPENURL); SfxURLToolBoxControl_Impl::RegisterControl(SID_OPENURL);
SfxAppToolBoxControl_Impl::RegisterControl( SID_NEWDOCDIRECT );
SfxAppToolBoxControl_Impl::RegisterControl( SID_AUTOPILOTMENU );
}; };
//-------------------------------------------------------------------- //--------------------------------------------------------------------
......
...@@ -574,3 +574,62 @@ void SfxUnoMenuControl::Select() ...@@ -574,3 +574,62 @@ void SfxUnoMenuControl::Select()
{ {
pUnoCtrl->Execute(); pUnoCtrl->Execute();
} }
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::XFramesSupplier > xDesktop =
Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
URL aTargetURL;
aTargetURL.Complete = aURL;
Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
UNO_QUERY );
xTrans->parseStrict( aTargetURL );
Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
Reference < XDispatch > xDisp;
if ( xProv.is() )
{
if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
else
{
::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
::framework::MenuConfiguration::Attributes* pMenuAttributes =
(::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
if ( pMenuAttributes )
aTargetFrame = pMenuAttributes->aTargetFrame;
xDisp = xProv->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;
}
...@@ -121,7 +121,6 @@ using namespace ::com::sun::star::ui; ...@@ -121,7 +121,6 @@ using namespace ::com::sun::star::ui;
//==================================================================== //====================================================================
SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True); SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
static Window* GetTopMostParentSystemWindow( Window* pWindow ) static Window* GetTopMostParentSystemWindow( Window* pWindow )
{ {
...@@ -1510,381 +1509,3 @@ IMPL_LINK( SfxPopupWindow, Delete, void *, EMPTYARG ) ...@@ -1510,381 +1509,3 @@ IMPL_LINK( SfxPopupWindow, Delete, void *, EMPTYARG )
//-------------------------------------------------------------------- //--------------------------------------------------------------------
SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
: SfxToolBoxControl( nSlotId, nId, rBox )
, bBigImages( sal_False )
, 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_bWasHiContrastMode = rSettings.GetHighContrastMode();
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 - otherwhise.
*/
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 = DEFINE_CONST_UNICODE("private:factory/");
*pFallback += String(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_xServiceManager );
if ( m_aCommandURL.equalsAscii( ".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();
sal_Bool bHC = GetToolBox().GetSettings().GetStyleSettings().GetHighContrastMode();
Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig, bHC );
if ( !aImage )
aImage = !!aMenuImage ? aMenuImage :
SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig, bHC );
Size aBigSize( GetToolBox().GetDefaultImageSize() );
if ( bBig && aImage.GetSizePixel() != aBigSize )
{
BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
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_xServiceManager );
// 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 );
::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_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 = ::rtl::OUString::createFromAscii( "Referer" );
aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( 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::XFramesSupplier > xDesktop =
Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
URL aTargetURL;
aTargetURL.Complete = aURL;
Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
UNO_QUERY );
xTrans->parseStrict( aTargetURL );
Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
Reference < XDispatch > xDisp;
if ( xProv.is() )
{
if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
else
{
::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
::framework::MenuConfiguration::Attributes* pMenuAttributes =
(::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
if ( pMenuAttributes )
aTargetFrame = pMenuAttributes->aTargetFrame;
xDisp = xProv->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 bIsHiContrastMode = rSettings.GetHighContrastMode();
sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
if (( nSymbolsStyle != m_nSymbolsStyle ) ||
( bIsHiContrastMode != m_bWasHiContrastMode ) ||
( bShowMenuImages != m_bShowMenuImages ))
{
m_nSymbolsStyle = nSymbolsStyle;
m_bWasHiContrastMode = bIsHiContrastMode;
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;
::rtl::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.getLength() > 0 )
{
Reference< ::com::sun::star::frame::XFrame > xFrame;
Image aImage = GetImage( xFrame, aImageId, sal_False, bIsHiContrastMode );
if ( !!aImage )
{
bImageSet = sal_True;
pActMenu->SetItemImage( nId, aImage );
}
}
String aCmd( pActMenu->GetItemCommand( nId ) );
if ( !bImageSet && aCmd.Len() )
{
Image aImage = SvFileInformationManager::GetImage(
INetURLObject(aCmd), sal_False, bIsHiContrastMode );
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 );
/*
}
catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
{
throw exFilters;
}
catch (const Exception& )
{
}
*/
delete pExecuteInfo;
return 0;
}
//--------------------------------------------------------------------
void SfxAppToolBoxControl_Impl::Click( )
{
}
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