1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir // includes ******************************************************************* 32*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/frame/XModuleManager.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include <svl/eitem.hxx> 39*cdf0e10cSrcweir #include <svtools/generictoolboxcontroller.hxx> 40*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 41*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include "recfloat.hxx" 44*cdf0e10cSrcweir #include "dialog.hrc" 45*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 46*cdf0e10cSrcweir #include <sfx2/app.hxx> 47*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 48*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 49*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 50*cdf0e10cSrcweir #include <sfx2/viewsh.hxx> 51*cdf0e10cSrcweir #include "sfx2/imagemgr.hxx" 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir using namespace ::com::sun::star; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir static rtl::OUString GetLabelFromCommandURL( const rtl::OUString& rCommandURL, const uno::Reference< frame::XFrame >& xFrame ) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir rtl::OUString aLabel; 58*cdf0e10cSrcweir rtl::OUString aModuleIdentifier; 59*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xUICommandLabels; 60*cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xServiceManager; 61*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xUICommandDescription; 62*cdf0e10cSrcweir uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir static uno::WeakReference< lang::XMultiServiceFactory > xTmpServiceManager; 65*cdf0e10cSrcweir static uno::WeakReference< container::XNameAccess > xTmpNameAccess; 66*cdf0e10cSrcweir static uno::WeakReference< ::com::sun::star::frame::XModuleManager > xTmpModuleMgr; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir xServiceManager = xTmpServiceManager; 69*cdf0e10cSrcweir if ( !xServiceManager.is() ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir xServiceManager = ::comphelper::getProcessServiceFactory(); 72*cdf0e10cSrcweir xTmpServiceManager = xServiceManager; 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir xUICommandDescription = xTmpNameAccess; 76*cdf0e10cSrcweir if ( !xUICommandDescription.is() ) 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir xUICommandDescription = uno::Reference< container::XNameAccess >( 79*cdf0e10cSrcweir xServiceManager->createInstance( 80*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 81*cdf0e10cSrcweir "com.sun.star.frame.UICommandDescription" ))), 82*cdf0e10cSrcweir uno::UNO_QUERY ); 83*cdf0e10cSrcweir xTmpNameAccess = xUICommandDescription; 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir xModuleManager = xTmpModuleMgr; 87*cdf0e10cSrcweir if ( !xModuleManager.is() ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >( 90*cdf0e10cSrcweir xServiceManager->createInstance( 91*cdf0e10cSrcweir rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( 92*cdf0e10cSrcweir "com.sun.star.frame.ModuleManager" ))), 93*cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 94*cdf0e10cSrcweir xTmpModuleMgr = xModuleManager; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // Retrieve label from UI command description service 98*cdf0e10cSrcweir try 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir try 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir aModuleIdentifier = xModuleManager->identify( xFrame ); 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir catch( uno::Exception& ) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir if ( xUICommandDescription.is() ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir uno::Any a = xUICommandDescription->getByName( aModuleIdentifier ); 111*cdf0e10cSrcweir uno::Reference< container::XNameAccess > xUICommands; 112*cdf0e10cSrcweir a >>= xUICommandLabels; 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir catch ( uno::Exception& ) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir if ( xUICommandLabels.is() ) 120*cdf0e10cSrcweir { 121*cdf0e10cSrcweir try 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir if ( rCommandURL.getLength() > 0 ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aPropSeq; 126*cdf0e10cSrcweir uno::Any a( xUICommandLabels->getByName( rCommandURL )); 127*cdf0e10cSrcweir if ( a >>= aPropSeq ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir if ( aPropSeq[i].Name.equalsAscii( "Label" )) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir aPropSeq[i].Value >>= aLabel; 134*cdf0e10cSrcweir break; 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir catch (uno::Exception& ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir return aLabel; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir SFX_IMPL_FLOATINGWINDOW( SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW ); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl( Window* pParentWnd , 151*cdf0e10cSrcweir sal_uInt16 nId , 152*cdf0e10cSrcweir SfxBindings* pBind , 153*cdf0e10cSrcweir SfxChildWinInfo* pInfo ) 154*cdf0e10cSrcweir : SfxChildWindow( pParentWnd, nId ) 155*cdf0e10cSrcweir , pBindings( pBind ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir pWindow = new SfxRecordingFloat_Impl( pBindings, this, pParentWnd ); 158*cdf0e10cSrcweir SetWantsFocus( sal_False ); 159*cdf0e10cSrcweir eChildAlignment = SFX_ALIGN_NOALIGNMENT; 160*cdf0e10cSrcweir ( ( SfxFloatingWindow* ) pWindow )->Initialize( pInfo ); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl() 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir SfxBoolItem aItem( FN_PARAM_1, sal_True ); 166*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder(); 167*cdf0e10cSrcweir if ( xRecorder.is() ) 168*cdf0e10cSrcweir pBindings->GetDispatcher()->Execute( SID_STOP_RECORDING, SFX_CALLMODE_SYNCHRON, &aItem, 0L ); 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir sal_Bool SfxRecordingFloatWrapper_Impl::QueryClose() 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir // asking for recorded macro should be replaced if index access is available! 174*cdf0e10cSrcweir sal_Bool bRet = sal_True; 175*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder(); 176*cdf0e10cSrcweir if ( xRecorder.is() && xRecorder->getRecordedMacro().getLength() ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , String( SfxResId( STR_MACRO_LOSS ) ) ); 179*cdf0e10cSrcweir aBox.SetText( String( SfxResId(STR_CANCEL_RECORDING) ) ); 180*cdf0e10cSrcweir bRet = ( aBox.Execute() == RET_YES ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir return bRet; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir SfxRecordingFloat_Impl::SfxRecordingFloat_Impl( 187*cdf0e10cSrcweir SfxBindings* pBind , 188*cdf0e10cSrcweir SfxChildWindow* pChildWin , 189*cdf0e10cSrcweir Window* pParent ) 190*cdf0e10cSrcweir : SfxFloatingWindow( pBind, 191*cdf0e10cSrcweir pChildWin, 192*cdf0e10cSrcweir pParent, 193*cdf0e10cSrcweir SfxResId( SID_RECORDING_FLOATWINDOW ) ) 194*cdf0e10cSrcweir , pWrapper( pChildWin ) 195*cdf0e10cSrcweir , aTbx( this, SfxResId(SID_RECORDING_FLOATWINDOW) ) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir // Retrieve label from helper function 198*cdf0e10cSrcweir uno::Reference< frame::XFrame > xFrame = GetBindings().GetActiveFrame(); 199*cdf0e10cSrcweir rtl::OUString aCommandStr( RTL_CONSTASCII_USTRINGPARAM( ".uno:StopRecording" )); 200*cdf0e10cSrcweir aTbx.SetItemText( SID_STOP_RECORDING, GetLabelFromCommandURL( aCommandStr, xFrame )); 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir // Determine size of toolbar 203*cdf0e10cSrcweir Size aTbxSize = aTbx.CalcWindowSizePixel(); 204*cdf0e10cSrcweir aTbx.SetPosSizePixel( Point(), aTbxSize ); 205*cdf0e10cSrcweir SetOutputSizePixel( aTbxSize ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // create a generic toolbox controller for our internal toolbox 208*cdf0e10cSrcweir svt::GenericToolboxController* pController = new svt::GenericToolboxController( 209*cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), 210*cdf0e10cSrcweir xFrame, 211*cdf0e10cSrcweir &aTbx, 212*cdf0e10cSrcweir SID_STOP_RECORDING, 213*cdf0e10cSrcweir aCommandStr ); 214*cdf0e10cSrcweir xStopRecTbxCtrl = uno::Reference< frame::XToolbarController >( 215*cdf0e10cSrcweir static_cast< cppu::OWeakObject* >( pController ), 216*cdf0e10cSrcweir uno::UNO_QUERY ); 217*cdf0e10cSrcweir uno::Reference< util::XUpdatable > xUpdate( xStopRecTbxCtrl, uno::UNO_QUERY ); 218*cdf0e10cSrcweir if ( xUpdate.is() ) 219*cdf0e10cSrcweir xUpdate->update(); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir aTbx.SetSelectHdl( LINK( this, SfxRecordingFloat_Impl, Select ) ); 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // start recording 224*cdf0e10cSrcweir SfxBoolItem aItem( SID_RECORDMACRO, sal_True ); 225*cdf0e10cSrcweir GetBindings().GetDispatcher()->Execute( SID_RECORDMACRO, SFX_CALLMODE_SYNCHRON, &aItem, 0L ); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl() 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir try 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir if ( xStopRecTbxCtrl.is() ) 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( xStopRecTbxCtrl, uno::UNO_QUERY ); 235*cdf0e10cSrcweir xComp->dispose(); 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir catch ( uno::Exception& ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir sal_Bool SfxRecordingFloat_Impl::Close() 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir sal_Bool bRet = SfxFloatingWindow::Close(); 246*cdf0e10cSrcweir return bRet; 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir SfxFloatingWindow::FillInfo( rInfo ); 252*cdf0e10cSrcweir rInfo.bVisible = sal_False; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir void SfxRecordingFloat_Impl::StateChanged( StateChangedType nStateChange ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir if ( nStateChange == STATE_CHANGE_INITSHOW ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame(); 260*cdf0e10cSrcweir Window* pEditWin = pFrame->GetViewShell()->GetWindow(); 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() ); 263*cdf0e10cSrcweir aPoint = GetParent()->ScreenToOutputPixel( aPoint ); 264*cdf0e10cSrcweir aPoint.X() += 20; 265*cdf0e10cSrcweir aPoint.Y() += 10; 266*cdf0e10cSrcweir SetPosPixel( aPoint ); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir SfxFloatingWindow::StateChanged( nStateChange ); 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir IMPL_LINK( SfxRecordingFloat_Impl, Select, ToolBox*, pToolBar ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir (void)pToolBar; 275*cdf0e10cSrcweir sal_Int16 nKeyModifier( (sal_Int16)aTbx.GetModifier() ); 276*cdf0e10cSrcweir if ( xStopRecTbxCtrl.is() ) 277*cdf0e10cSrcweir xStopRecTbxCtrl->execute( nKeyModifier ); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir return 1; 280*cdf0e10cSrcweir } 281