Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / recfloat.cxx
blob010002b1840b5f81a79211883b1c80d4fbd406a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // includes *******************************************************************
31 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
32 #include <com/sun/star/frame/XModuleManager.hpp>
33 #include <com/sun/star/container/XNameAccess.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
36 #include <svl/eitem.hxx>
37 #include <svtools/generictoolboxcontroller.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <comphelper/processfactory.hxx>
41 #include "recfloat.hxx"
42 #include "dialog.hrc"
43 #include "sfx2/sfxresid.hxx"
44 #include <sfx2/app.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/dispatch.hxx>
47 #include <sfx2/viewfrm.hxx>
48 #include <sfx2/viewsh.hxx>
49 #include "sfx2/imagemgr.hxx"
51 using namespace ::com::sun::star;
53 static rtl::OUString GetLabelFromCommandURL( const rtl::OUString& rCommandURL, const uno::Reference< frame::XFrame >& xFrame )
55 rtl::OUString aLabel;
56 rtl::OUString aModuleIdentifier;
57 uno::Reference< container::XNameAccess > xUICommandLabels;
58 uno::Reference< lang::XMultiServiceFactory > xServiceManager;
59 uno::Reference< container::XNameAccess > xUICommandDescription;
60 uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager;
62 static uno::WeakReference< lang::XMultiServiceFactory > xTmpServiceManager;
63 static uno::WeakReference< container::XNameAccess > xTmpNameAccess;
64 static uno::WeakReference< ::com::sun::star::frame::XModuleManager > xTmpModuleMgr;
66 xServiceManager = xTmpServiceManager;
67 if ( !xServiceManager.is() )
69 xServiceManager = ::comphelper::getProcessServiceFactory();
70 xTmpServiceManager = xServiceManager;
73 xUICommandDescription = xTmpNameAccess;
74 if ( !xUICommandDescription.is() )
76 xUICommandDescription = uno::Reference< container::XNameAccess >(
77 xServiceManager->createInstance(
78 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
79 "com.sun.star.frame.UICommandDescription" ))),
80 uno::UNO_QUERY );
81 xTmpNameAccess = xUICommandDescription;
84 xModuleManager = xTmpModuleMgr;
85 if ( !xModuleManager.is() )
87 xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >(
88 xServiceManager->createInstance(
89 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
90 "com.sun.star.frame.ModuleManager" ))),
91 uno::UNO_QUERY_THROW );
92 xTmpModuleMgr = xModuleManager;
95 // Retrieve label from UI command description service
96 try
98 try
100 aModuleIdentifier = xModuleManager->identify( xFrame );
102 catch( uno::Exception& )
106 if ( xUICommandDescription.is() )
108 uno::Any a = xUICommandDescription->getByName( aModuleIdentifier );
109 uno::Reference< container::XNameAccess > xUICommands;
110 a >>= xUICommandLabels;
113 catch ( uno::Exception& )
117 if ( xUICommandLabels.is() )
121 if ( !rCommandURL.isEmpty() )
123 uno::Sequence< beans::PropertyValue > aPropSeq;
124 uno::Any a( xUICommandLabels->getByName( rCommandURL ));
125 if ( a >>= aPropSeq )
127 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
129 if ( aPropSeq[i].Name == "Label" )
131 aPropSeq[i].Value >>= aLabel;
132 break;
138 catch (uno::Exception& )
143 return aLabel;
146 SFX_IMPL_FLOATINGWINDOW( SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW );
148 SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl( Window* pParentWnd ,
149 sal_uInt16 nId ,
150 SfxBindings* pBind ,
151 SfxChildWinInfo* pInfo )
152 : SfxChildWindow( pParentWnd, nId )
153 , pBindings( pBind )
155 pWindow = new SfxRecordingFloat_Impl( pBindings, this, pParentWnd );
156 SetWantsFocus( sal_False );
157 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
158 ( ( SfxFloatingWindow* ) pWindow )->Initialize( pInfo );
161 SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl()
163 SfxBoolItem aItem( FN_PARAM_1, sal_True );
164 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
165 if ( xRecorder.is() )
166 pBindings->GetDispatcher()->Execute( SID_STOP_RECORDING, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
169 sal_Bool SfxRecordingFloatWrapper_Impl::QueryClose()
171 // asking for recorded macro should be replaced if index access is available!
172 sal_Bool bRet = sal_True;
173 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
174 if ( xRecorder.is() && !xRecorder->getRecordedMacro().isEmpty() )
176 QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , String( SfxResId( STR_MACRO_LOSS ) ) );
177 aBox.SetText( String( SfxResId(STR_CANCEL_RECORDING) ) );
178 bRet = ( aBox.Execute() == RET_YES );
181 return bRet;
184 SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(
185 SfxBindings* pBind ,
186 SfxChildWindow* pChildWin ,
187 Window* pParent )
188 : SfxFloatingWindow( pBind,
189 pChildWin,
190 pParent,
191 SfxResId( SID_RECORDING_FLOATWINDOW ) )
192 , pWrapper( pChildWin )
193 , aTbx( this, SfxResId(SID_RECORDING_FLOATWINDOW) )
195 // Retrieve label from helper function
196 uno::Reference< frame::XFrame > xFrame = GetBindings().GetActiveFrame();
197 rtl::OUString aCommandStr( RTL_CONSTASCII_USTRINGPARAM( ".uno:StopRecording" ));
198 aTbx.SetItemText( SID_STOP_RECORDING, GetLabelFromCommandURL( aCommandStr, xFrame ));
200 // Determine size of toolbar
201 Size aTbxSize = aTbx.CalcWindowSizePixel();
202 aTbx.SetPosSizePixel( Point(), aTbxSize );
203 SetOutputSizePixel( aTbxSize );
205 // create a generic toolbox controller for our internal toolbox
206 svt::GenericToolboxController* pController = new svt::GenericToolboxController(
207 ::comphelper::getProcessServiceFactory(),
208 xFrame,
209 &aTbx,
210 SID_STOP_RECORDING,
211 aCommandStr );
212 xStopRecTbxCtrl = uno::Reference< frame::XToolbarController >(
213 static_cast< cppu::OWeakObject* >( pController ),
214 uno::UNO_QUERY );
215 uno::Reference< util::XUpdatable > xUpdate( xStopRecTbxCtrl, uno::UNO_QUERY );
216 if ( xUpdate.is() )
217 xUpdate->update();
219 aTbx.SetSelectHdl( LINK( this, SfxRecordingFloat_Impl, Select ) );
221 // start recording
222 SfxBoolItem aItem( SID_RECORDMACRO, sal_True );
223 GetBindings().GetDispatcher()->Execute( SID_RECORDMACRO, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
226 SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
230 if ( xStopRecTbxCtrl.is() )
232 uno::Reference< lang::XComponent > xComp( xStopRecTbxCtrl, uno::UNO_QUERY );
233 xComp->dispose();
236 catch ( uno::Exception& )
241 sal_Bool SfxRecordingFloat_Impl::Close()
243 sal_Bool bRet = SfxFloatingWindow::Close();
244 return bRet;
247 void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
249 SfxFloatingWindow::FillInfo( rInfo );
250 rInfo.bVisible = sal_False;
253 void SfxRecordingFloat_Impl::StateChanged( StateChangedType nStateChange )
255 if ( nStateChange == STATE_CHANGE_INITSHOW )
257 SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
258 Window* pEditWin = pFrame->GetViewShell()->GetWindow();
260 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
261 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
262 aPoint.X() += 20;
263 aPoint.Y() += 10;
264 SetPosPixel( aPoint );
267 SfxFloatingWindow::StateChanged( nStateChange );
270 IMPL_LINK( SfxRecordingFloat_Impl, Select, ToolBox*, pToolBar )
272 (void)pToolBar;
273 sal_Int16 nKeyModifier( (sal_Int16)aTbx.GetModifier() );
274 if ( xStopRecTbxCtrl.is() )
275 xStopRecTbxCtrl->execute( nKeyModifier );
277 return 1;
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */