merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / dialog / recfloat.cxx
blobbb9ad7b9a55f7e740f73f873474f2d04154e47a8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: recfloat.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 // includes *******************************************************************
35 #include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
36 #include <com/sun/star/frame/XModuleManager.hpp>
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41 #include <svtools/eitem.hxx>
42 #include <svtools/generictoolboxcontroller.hxx>
43 #include <vcl/msgbox.hxx>
44 #include <comphelper/processfactory.hxx>
46 #include "recfloat.hxx"
47 #include "dialog.hrc"
48 #include "sfxresid.hxx"
49 #include <sfx2/app.hxx>
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/viewsh.hxx>
54 #include "imagemgr.hxx"
56 using namespace ::com::sun::star;
58 static rtl::OUString GetLabelFromCommandURL( const rtl::OUString& rCommandURL, const uno::Reference< frame::XFrame >& xFrame )
60 rtl::OUString aLabel;
61 rtl::OUString aModuleIdentifier;
62 uno::Reference< container::XNameAccess > xUICommandLabels;
63 uno::Reference< lang::XMultiServiceFactory > xServiceManager;
64 uno::Reference< container::XNameAccess > xUICommandDescription;
65 uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager;
67 static uno::WeakReference< lang::XMultiServiceFactory > xTmpServiceManager;
68 static uno::WeakReference< container::XNameAccess > xTmpNameAccess;
69 static uno::WeakReference< ::com::sun::star::frame::XModuleManager > xTmpModuleMgr;
71 xServiceManager = xTmpServiceManager;
72 if ( !xServiceManager.is() )
74 xServiceManager = ::comphelper::getProcessServiceFactory();
75 xTmpServiceManager = xServiceManager;
78 xUICommandDescription = xTmpNameAccess;
79 if ( !xUICommandDescription.is() )
81 xUICommandDescription = uno::Reference< container::XNameAccess >(
82 xServiceManager->createInstance(
83 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
84 "com.sun.star.frame.UICommandDescription" ))),
85 uno::UNO_QUERY );
86 xTmpNameAccess = xUICommandDescription;
89 xModuleManager = xTmpModuleMgr;
90 if ( !xModuleManager.is() )
92 xModuleManager = uno::Reference< ::com::sun::star::frame::XModuleManager >(
93 xServiceManager->createInstance(
94 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
95 "com.sun.star.frame.ModuleManager" ))),
96 uno::UNO_QUERY_THROW );
97 xTmpModuleMgr = xModuleManager;
100 // Retrieve label from UI command description service
105 aModuleIdentifier = xModuleManager->identify( xFrame );
107 catch( uno::Exception& )
111 if ( xUICommandDescription.is() )
113 uno::Any a = xUICommandDescription->getByName( aModuleIdentifier );
114 uno::Reference< container::XNameAccess > xUICommands;
115 a >>= xUICommandLabels;
118 catch ( uno::Exception& )
122 if ( xUICommandLabels.is() )
126 if ( rCommandURL.getLength() > 0 )
128 uno::Sequence< beans::PropertyValue > aPropSeq;
129 uno::Any a( xUICommandLabels->getByName( rCommandURL ));
130 if ( a >>= aPropSeq )
132 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
134 if ( aPropSeq[i].Name.equalsAscii( "Label" ))
136 aPropSeq[i].Value >>= aLabel;
137 break;
143 catch (uno::Exception& )
148 return aLabel;
151 SFX_IMPL_FLOATINGWINDOW( SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW );
153 SfxRecordingFloatWrapper_Impl::SfxRecordingFloatWrapper_Impl( Window* pParentWnd ,
154 USHORT nId ,
155 SfxBindings* pBind ,
156 SfxChildWinInfo* pInfo )
157 : SfxChildWindow( pParentWnd, nId )
158 , pBindings( pBind )
160 pWindow = new SfxRecordingFloat_Impl( pBindings, this, pParentWnd );
161 SetWantsFocus( FALSE );
162 eChildAlignment = SFX_ALIGN_NOALIGNMENT;
163 ( ( SfxFloatingWindow* ) pWindow )->Initialize( pInfo );
166 SfxRecordingFloatWrapper_Impl::~SfxRecordingFloatWrapper_Impl()
168 SfxBoolItem aItem( FN_PARAM_1, TRUE );
169 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
170 if ( xRecorder.is() )
171 pBindings->GetDispatcher()->Execute( SID_STOP_RECORDING, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
174 sal_Bool SfxRecordingFloatWrapper_Impl::QueryClose()
176 // asking for recorded macro should be replaced if index access is available!
177 BOOL bRet = TRUE;
178 com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder = pBindings->GetRecorder();
179 if ( xRecorder.is() && xRecorder->getRecordedMacro().getLength() )
181 QueryBox aBox( GetWindow(), WB_YES_NO | WB_DEF_NO , String( SfxResId( STR_MACRO_LOSS ) ) );
182 aBox.SetText( String( SfxResId(STR_CANCEL_RECORDING) ) );
183 bRet = ( aBox.Execute() == RET_YES );
186 return bRet;
189 SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(
190 SfxBindings* pBind ,
191 SfxChildWindow* pChildWin ,
192 Window* pParent )
193 : SfxFloatingWindow( pBind,
194 pChildWin,
195 pParent,
196 SfxResId( SID_RECORDING_FLOATWINDOW ) )
197 , pWrapper( pChildWin )
198 , aTbx( this, SfxResId(SID_RECORDING_FLOATWINDOW) )
200 // Retrieve label from helper function
201 uno::Reference< frame::XFrame > xFrame = GetBindings().GetActiveFrame();
202 rtl::OUString aCommandStr( RTL_CONSTASCII_USTRINGPARAM( ".uno:StopRecording" ));
203 aTbx.SetItemText( SID_STOP_RECORDING, GetLabelFromCommandURL( aCommandStr, xFrame ));
205 // Determine size of toolbar
206 Size aTbxSize = aTbx.CalcWindowSizePixel();
207 aTbx.SetPosSizePixel( Point(), aTbxSize );
208 SetOutputSizePixel( aTbxSize );
210 // create a generic toolbox controller for our internal toolbox
211 svt::GenericToolboxController* pController = new svt::GenericToolboxController(
212 ::comphelper::getProcessServiceFactory(),
213 xFrame,
214 &aTbx,
215 SID_STOP_RECORDING,
216 aCommandStr );
217 xStopRecTbxCtrl = uno::Reference< frame::XToolbarController >(
218 static_cast< cppu::OWeakObject* >( pController ),
219 uno::UNO_QUERY );
220 uno::Reference< util::XUpdatable > xUpdate( xStopRecTbxCtrl, uno::UNO_QUERY );
221 if ( xUpdate.is() )
222 xUpdate->update();
224 aTbx.SetSelectHdl( LINK( this, SfxRecordingFloat_Impl, Select ) );
226 // start recording
227 SfxBoolItem aItem( SID_RECORDMACRO, TRUE );
228 GetBindings().GetDispatcher()->Execute( SID_RECORDMACRO, SFX_CALLMODE_SYNCHRON, &aItem, 0L );
231 SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl()
235 if ( xStopRecTbxCtrl.is() )
237 uno::Reference< lang::XComponent > xComp( xStopRecTbxCtrl, uno::UNO_QUERY );
238 xComp->dispose();
241 catch ( uno::Exception& )
246 BOOL SfxRecordingFloat_Impl::Close()
248 BOOL bRet = SfxFloatingWindow::Close();
249 return bRet;
252 void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
254 SfxFloatingWindow::FillInfo( rInfo );
255 rInfo.bVisible = sal_False;
258 void SfxRecordingFloat_Impl::StateChanged( StateChangedType nStateChange )
260 if ( nStateChange == STATE_CHANGE_INITSHOW )
262 SfxViewFrame *pFrame = GetBindings().GetDispatcher_Impl()->GetFrame();
263 Window* pEditWin = pFrame->GetViewShell()->GetWindow();
265 Point aPoint = pEditWin->OutputToScreenPixel( pEditWin->GetPosPixel() );
266 aPoint = GetParent()->ScreenToOutputPixel( aPoint );
267 aPoint.X() += 20;
268 aPoint.Y() += 10;
269 SetPosPixel( aPoint );
272 SfxFloatingWindow::StateChanged( nStateChange );
275 IMPL_LINK( SfxRecordingFloat_Impl, Select, ToolBox*, pToolBar )
277 (void)pToolBar;
278 sal_Int16 nKeyModifier( (sal_Int16)aTbx.GetModifier() );
279 if ( xStopRecTbxCtrl.is() )
280 xStopRecTbxCtrl->execute( nKeyModifier );
282 return 1;