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