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