LibreOffice Module sfx2 (master) 1
unoctitm.cxx
Go to the documentation of this file.
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 <config_java.h>
21
22#include <tools/debug.hxx>
23#include <svl/eitem.hxx>
24#include <svl/intitem.hxx>
25#include <svl/itempool.hxx>
26#include <svl/itemset.hxx>
27#include <svl/stritem.hxx>
28#include <svl/visitem.hxx>
31#include <tools/urlobj.hxx>
32#include <com/sun/star/awt/FontDescriptor.hpp>
33#include <com/sun/star/awt/Point.hpp>
34#include <com/sun/star/awt/Size.hpp>
35#include <com/sun/star/util/URLTransformer.hpp>
36#include <com/sun/star/util/XURLTransformer.hpp>
37#include <com/sun/star/frame/XFrame.hpp>
38#include <com/sun/star/frame/status/FontHeight.hpp>
39#include <com/sun/star/frame/status/ItemStatus.hpp>
40#include <com/sun/star/frame/status/ItemState.hpp>
41#include <com/sun/star/frame/status/Template.hpp>
42#include <com/sun/star/frame/DispatchResultState.hpp>
43#include <com/sun/star/frame/status/Visibility.hpp>
45#include <uno/current_context.hxx>
46#include <utility>
47#include <vcl/svapp.hxx>
48#include <vcl/uitest/logger.hxx>
49#include <boost/property_tree/json_parser.hpp>
50#include <tools/json_writer.hxx>
51
52#include <sfx2/app.hxx>
53#include <unoctitm.hxx>
54#include <sfx2/viewfrm.hxx>
55#include <sfx2/frame.hxx>
56#include <sfx2/ctrlitem.hxx>
57#include <sfx2/sfxuno.hxx>
58#include <sfx2/bindings.hxx>
59#include <sfx2/dispatch.hxx>
60#include <sfx2/sfxsids.hrc>
61#include <sfx2/request.hxx>
62#include <sfx2/msg.hxx>
63#include <sfx2/viewsh.hxx>
64#include <slotserv.hxx>
65#include <rtl/ustring.hxx>
66#include <sfx2/lokhelper.hxx>
67
68#include <memory>
69#include <string_view>
70
71#include <sal/log.hxx>
72#include <LibreOfficeKit/LibreOfficeKitEnums.h>
73#include <comphelper/lok.hxx>
75
77#include <vcl/threadex.hxx>
79
80using namespace ::com::sun::star;
81using namespace ::com::sun::star::uno;
82using namespace ::com::sun::star::util;
83
84namespace {
85
86enum URLTypeId
87{
88 URLType_BOOL,
89 URLType_BYTE,
90 URLType_SHORT,
91 URLType_LONG,
92 URLType_HYPER,
93 URLType_STRING,
94 URLType_FLOAT,
95 URLType_DOUBLE,
96 URLType_COUNT
97};
98
99}
100
101const char* const URLTypeNames[URLType_COUNT] =
102{
103 "bool",
104 "byte",
105 "short",
106 "long",
107 "hyper",
108 "string",
109 "float",
110 "double"
111};
112
113static void InterceptLOKStateChangeEvent( sal_uInt16 nSID, SfxViewFrame* pViewFrame, const css::frame::FeatureStateEvent& aEvent, const SfxPoolItem* pState );
114
116{
117 css::lang::EventObject aObject;
118 aObject.Source = getXWeak();
119 std::unique_lock aGuard(maMutex);
120 maListeners.disposeAndClear( aGuard, aObject );
121}
122
123void SfxStatusDispatcher::sendStatusChanged(const OUString& rURL, const css::frame::FeatureStateEvent& rEvent)
124{
125 std::unique_lock aGuard(maMutex);
127 if (!pContnr)
128 return;
129 pContnr->forEach(aGuard,
130 [&rEvent](const css::uno::Reference<css::frame::XStatusListener>& xListener)
131 {
132 xListener->statusChanged(rEvent);
133 }
134 );
135}
136
137void SAL_CALL SfxStatusDispatcher::dispatch( const css::util::URL&, const css::uno::Sequence< css::beans::PropertyValue >& )
138{
139}
140
142 const css::util::URL&,
143 const css::uno::Sequence< css::beans::PropertyValue >&,
144 const css::uno::Reference< css::frame::XDispatchResultListener >& )
145{
146}
147
149{
150}
151
152void SAL_CALL SfxStatusDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL)
153{
154 {
155 std::unique_lock aGuard(maMutex);
156 maListeners.addInterface( aGuard, aURL.Complete, aListener );
157 }
158 if ( aURL.Complete == ".uno:LifeTime" )
159 {
160 css::frame::FeatureStateEvent aEvent;
161 aEvent.FeatureURL = aURL;
162 aEvent.Source = static_cast<css::frame::XDispatch*>(this);
163 aEvent.IsEnabled = true;
164 aEvent.Requery = false;
165 aListener->statusChanged( aEvent );
166 }
167}
168
169void SAL_CALL SfxStatusDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL )
170{
171 std::unique_lock aGuard(maMutex);
172 maListeners.removeInterface( aGuard, aURL.Complete, aListener );
173}
174
175
176SfxOfficeDispatch::SfxOfficeDispatch( SfxBindings& rBindings, SfxDispatcher* pDispat, const SfxSlot* pSlot, const css::util::URL& rURL )
177 : pImpl( new SfxDispatchController_Impl( this, &rBindings, pDispat, pSlot, rURL ))
178{
179 // pImpl is an adapter that shows a css::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
180
181}
182
183SfxOfficeDispatch::SfxOfficeDispatch( SfxDispatcher* pDispat, const SfxSlot* pSlot, const css::util::URL& rURL )
184 : pImpl( new SfxDispatchController_Impl( this, nullptr, pDispat, pSlot, rURL ))
185{
186 // pImpl is an adapter that shows a css::frame::XDispatch-Interface to the outside and uses a SfxControllerItem to monitor a state
187}
188
190{
191 if ( pImpl )
192 {
193 // when dispatch object is released, destroy its connection to this object and destroy it
194 pImpl->UnBindController();
195
196 // Ensure that SfxDispatchController_Impl is deleted while the solar mutex is locked, since
197 // that derives from SfxListener.
198 SolarMutexGuard aGuard;
199 pImpl.reset();
200 }
201}
202
203#if HAVE_FEATURE_JAVA
204// The JavaContext contains an interaction handler which is used when
205// the creation of a Java Virtual Machine fails. There shall only be one
206// user notification (message box) even if the same error (interaction)
207// reoccurs. The effect is, that if a user selects a menu entry than they
208// may get only one notification that a JRE is not selected.
209// This function checks if a JavaContext is already available (typically
210// created by Desktop::Main() in app.cxx), and creates new one if not.
211namespace {
212std::unique_ptr< css::uno::ContextLayer > EnsureJavaContext()
213{
214 css::uno::Reference< css::uno::XCurrentContext > xContext(css::uno::getCurrentContext());
215 if (xContext.is())
216 {
217 css::uno::Reference< css::task::XInteractionHandler > xHandler;
218 xContext->getValueByName(JAVA_INTERACTION_HANDLER_NAME) >>= xHandler;
219 if (xHandler.is())
220 return nullptr; // No need to add new layer: JavaContext already present
221 }
222 return std::make_unique< css::uno::ContextLayer >(new svt::JavaContext(xContext));
223}
224}
225#endif
226
227void SAL_CALL SfxOfficeDispatch::dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& aArgs )
228{
229 // ControllerItem is the Impl class
230 if ( pImpl )
231 {
232#if HAVE_FEATURE_JAVA
233 std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext());
234#endif
235 utl::MediaDescriptor aDescriptor(aArgs);
236 bool bOnMainThread = aDescriptor.getUnpackedValueOrDefault("OnMainThread", false);
237 if (bOnMainThread)
238 {
239 // Make sure that we own the solar mutex, otherwise later
240 // vcl::SolarThreadExecutor::execute() will release the solar mutex, even if it's owned by
241 // another thread, leading to an std::abort() at the end.
242 SolarMutexGuard aGuard;
243 vcl::solarthread::syncExecute([this, &aURL, &aArgs]() {
244 pImpl->dispatch(aURL, aArgs,
245 css::uno::Reference<css::frame::XDispatchResultListener>());
246 });
247 }
248 else
249 {
250 pImpl->dispatch(aURL, aArgs,
251 css::uno::Reference<css::frame::XDispatchResultListener>());
252 }
253 }
254}
255
256void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const css::util::URL& aURL,
257 const css::uno::Sequence< css::beans::PropertyValue >& aArgs,
258 const css::uno::Reference< css::frame::XDispatchResultListener >& rListener )
259{
260 // ControllerItem is the Impl class
261 if ( pImpl )
262 {
263#if HAVE_FEATURE_JAVA
264 std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext());
265#endif
266 pImpl->dispatch( aURL, aArgs, rListener );
267 }
268}
269
270void SAL_CALL SfxOfficeDispatch::addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL)
271{
272 {
273 std::unique_lock aGuard(maMutex);
274 maListeners.addInterface( aGuard, aURL.Complete, aListener );
275 }
276 if ( pImpl )
277 {
278 // ControllerItem is the Impl class
279 pImpl->addStatusListener( aListener, aURL );
280 }
281}
282
284{
285 return pImpl->GetDispatcher();
286}
287
288sal_uInt16 SfxOfficeDispatch::GetId() const
289{
290 return pImpl ? pImpl->GetId() : 0;
291}
292
293void SfxOfficeDispatch::SetFrame(const css::uno::Reference< css::frame::XFrame >& xFrame)
294{
295 if ( pImpl )
296 pImpl->SetFrame( xFrame );
297}
298
300{
301 if ( pImpl )
302 pImpl->setMasterSlaveCommand( bSet );
303}
304
305// Determine if URL contains a master/slave command which must be handled a little bit different
306bool SfxOfficeDispatch::IsMasterUnoCommand( const css::util::URL& aURL )
307{
308 return aURL.Protocol == ".uno:" && ( aURL.Path.indexOf( '.' ) > 0 );
309}
310
311OUString SfxOfficeDispatch::GetMasterUnoCommand( const css::util::URL& aURL )
312{
313 OUString aMasterCommand;
314 if ( IsMasterUnoCommand( aURL ))
315 {
316 sal_Int32 nIndex = aURL.Path.indexOf( '.' );
317 if ( nIndex > 0 )
318 aMasterCommand = aURL.Path.copy( 0, nIndex );
319 }
320
321 return aMasterCommand;
322}
323
325 SfxOfficeDispatch* pDisp,
326 SfxBindings* pBind,
327 SfxDispatcher* pDispat,
328 const SfxSlot* pSlot,
329 css::util::URL aURL )
330 : aDispatchURL(std::move( aURL ))
331 , pDispatcher( pDispat )
332 , pBindings( pBind )
333 , pLastState( nullptr )
334 , pDispatch( pDisp )
335 , bMasterSlave( false )
336 , bVisible( true )
337{
338 if ( aDispatchURL.Protocol == "slot:" && !pSlot->pUnoName.isEmpty() )
339 {
340 aDispatchURL.Complete = pSlot->GetCommand();
341 Reference< XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
342 xTrans->parseStrict( aDispatchURL );
343 }
344
345 sal_uInt16 nSlot = pSlot->GetSlotId();
346 SetId( nSlot );
347 if ( pBindings )
348 {
349 // Bind immediately to enable the cache to recycle dispatches when asked for the same command
350 // a command in "slot" or in ".uno" notation must be treated as identical commands!
351 pBindings->ENTERREGISTRATIONS();
353 pBindings->LEAVEREGISTRATIONS();
354 }
355 assert(pDispatcher);
356 assert(SfxApplication::Get()->GetAppDispatcher_Impl() == pDispatcher
357 || pDispatcher->GetFrame() != nullptr);
358 if (pDispatcher->GetFrame())
359 {
361 }
362 else
363 {
365 }
366}
367
369{
370 if (rHint.GetId() == SfxHintId::Dying)
371 { // both pBindings and pDispatcher are dead if SfxViewFrame is dead
372 pBindings = nullptr;
373 pDispatcher = nullptr;
374 EndListening(rBC);
375 }
376}
377
379{
381 delete pLastState;
382
383 if ( pDispatch )
384 {
385 // disconnect
386 pDispatch->pImpl = nullptr;
387
388 // force all listeners to release the dispatch object
389 pDispatch->ReleaseAll();
390 }
391}
392
393void SfxDispatchController_Impl::SetFrame(const css::uno::Reference< css::frame::XFrame >& _xFrame)
394{
395 xFrame = _xFrame;
396}
397
399{
400 bMasterSlave = bSet;
401}
402
404{
405 pDispatch = nullptr;
406 if ( IsBound() )
407 {
408 GetBindings().ENTERREGISTRATIONS();
410 GetBindings().LEAVEREGISTRATIONS();
411 }
412}
413
414void SfxDispatchController_Impl::addParametersToArgs( const css::util::URL& aURL, css::uno::Sequence< css::beans::PropertyValue >& rArgs )
415{
416 // Extract the parameter from the URL and put them into the property value sequence
417 sal_Int32 nQueryIndex = aURL.Complete.indexOf( '?' );
418 if ( nQueryIndex <= 0 )
419 return;
420
421 OUString aParamString( aURL.Complete.copy( nQueryIndex+1 ));
422 sal_Int32 nIndex = 0;
423 do
424 {
425 OUString aToken = aParamString.getToken( 0, '&', nIndex );
426
427 sal_Int32 nParmIndex = 0;
428 OUString aParamType;
429 OUString aParamName = aToken.getToken( 0, '=', nParmIndex );
430 OUString aValue = aToken.getToken( 0, '=', nParmIndex );
431
432 if ( !aParamName.isEmpty() )
433 {
434 nParmIndex = 0;
435 aToken = aParamName;
436 aParamName = aToken.getToken( 0, ':', nParmIndex );
437 aParamType = aToken.getToken( 0, ':', nParmIndex );
438 }
439
440 sal_Int32 nLen = rArgs.getLength();
441 rArgs.realloc( nLen+1 );
442 auto pArgs = rArgs.getArray();
443 pArgs[nLen].Name = aParamName;
444
445 if ( aParamType.isEmpty() )
446 {
447 // Default: LONG
448 pArgs[nLen].Value <<= aValue.toInt32();
449 }
450 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BOOL], 4 ))
451 {
452 // sal_Bool support
453 pArgs[nLen].Value <<= aValue.toBoolean();
454 }
455 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_BYTE], 4 ))
456 {
457 // sal_uInt8 support
458 pArgs[nLen].Value <<= sal_Int8( aValue.toInt32() );
459 }
460 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_LONG], 4 ))
461 {
462 // LONG support
463 pArgs[nLen].Value <<= aValue.toInt32();
464 }
465 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_SHORT], 5 ))
466 {
467 // SHORT support
468 pArgs[nLen].Value <<= sal_Int16( aValue.toInt32() );
469 }
470 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_HYPER], 5 ))
471 {
472 // HYPER support
473 pArgs[nLen].Value <<= aValue.toInt64();
474 }
475 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_FLOAT], 5 ))
476 {
477 // FLOAT support
478 pArgs[nLen].Value <<= aValue.toFloat();
479 }
480 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_STRING], 6 ))
481 {
482 // STRING support
484 }
485 else if ( aParamType.equalsAsciiL( URLTypeNames[URLType_DOUBLE], 6))
486 {
487 // DOUBLE support
488 pArgs[nLen].Value <<= aValue.toDouble();
489 }
490 }
491 while ( nIndex >= 0 );
492}
493
495{
496 sal_uInt16 nWhich = rPool.GetWhich( nSlotId );
497 return rPool.GetMetric( nWhich );
498}
499
500OUString SfxDispatchController_Impl::getSlaveCommand( const css::util::URL& rURL )
501{
502 OUString aSlaveCommand;
503 sal_Int32 nIndex = rURL.Path.indexOf( '.' );
504 if (( nIndex > 0 ) && ( nIndex < rURL.Path.getLength() ))
505 aSlaveCommand = rURL.Path.copy( nIndex+1 );
506 return aSlaveCommand;
507}
508
509namespace {
510
511void collectUIInformation(const util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& rArgs)
512{
513 static const char* pFile = std::getenv("LO_COLLECT_UIINFO");
514 if (!pFile)
515 return;
516
518 Concat2View("Send UNO Command (\"" + rURL.Complete + "\") "), rArgs);
519}
520
521}
522
523void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
524 const css::uno::Sequence< css::beans::PropertyValue >& aArgs,
525 const css::uno::Reference< css::frame::XDispatchResultListener >& rListener )
526{
527 if ( aURL.Protocol == ".uno:")
528 {
530 }
531 collectUIInformation(aURL, aArgs);
532
533 SolarMutexGuard aGuard;
534
536 SfxViewShell::Current()->isBlockedCommand(aURL.Complete))
537 {
538 tools::JsonWriter aTree;
539 aTree.put("code", "");
540 aTree.put("kind", "BlockedCommand");
541 aTree.put("cmd", aURL.Complete);
542 aTree.put("message", "Blocked feature");
543 aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
544
546 return;
547 }
548
549 if (
550 !(pDispatch &&
551 (
552 (aURL.Protocol == ".uno:" && aURL.Path == aDispatchURL.Path) ||
553 (aURL.Protocol == "slot:" && aURL.Path.toInt32() == GetId())
554 ))
555 )
556 return;
557
558 if ( !pDispatcher && pBindings )
560
561 css::uno::Sequence< css::beans::PropertyValue > lNewArgs;
562 sal_Int32 nCount = aArgs.getLength();
563
564 // Support for URL based arguments
565 INetURLObject aURLObj( aURL.Complete );
566 if ( aURLObj.HasParam() )
567 addParametersToArgs( aURL, lNewArgs );
568
569 // Try to find call mode and frame name inside given arguments...
571 sal_Int32 nMarkArg = -1;
572
573 // Filter arguments which shouldn't be part of the sequence property value
574 sal_uInt16 nModifier(0);
575 std::vector< css::beans::PropertyValue > aAddArgs;
576 for( sal_Int32 n=0; n<nCount; n++ )
577 {
578 const css::beans::PropertyValue& rProp = aArgs[n];
579 if( rProp.Name == "SynchronMode" )
580 {
581 bool bTemp;
582 if( rProp.Value >>= bTemp )
584 }
585 else if( rProp.Name == "Bookmark" )
586 {
587 nMarkArg = n;
588 aAddArgs.push_back( aArgs[n] );
589 }
590 else if( rProp.Name == "KeyModifier" )
591 rProp.Value >>= nModifier;
592 else
593 aAddArgs.push_back( aArgs[n] );
594 }
595
596 // Add needed arguments to sequence property value
597 sal_uInt32 nAddArgs = aAddArgs.size();
598 if ( nAddArgs > 0 )
599 {
600 sal_uInt32 nIndex( lNewArgs.getLength() );
601
602 lNewArgs.realloc( nIndex + nAddArgs );
603 std::copy(aAddArgs.begin(), aAddArgs.end(), std::next(lNewArgs.getArray(), nIndex));
604 }
605
606 // Overwrite possible detected synchron argument, if real listener exists (currently no other way)
607 if ( rListener.is() )
608 nCall = SfxCallMode::SYNCHRON;
609
610 if( GetId() == SID_JUMPTOMARK && nMarkArg == - 1 )
611 {
612 // we offer dispatches for SID_JUMPTOMARK if the URL points to a bookmark inside the document
613 // so we must retrieve this as an argument from the parsed URL
614 lNewArgs.realloc( lNewArgs.getLength()+1 );
615 auto& el = lNewArgs.getArray()[lNewArgs.getLength()-1];
616 el.Name = "Bookmark";
617 el.Value <<= aURL.Mark;
618 }
619
620 css::uno::Reference< css::frame::XFrame > xFrameRef(xFrame.get(), css::uno::UNO_QUERY);
621 if (! xFrameRef.is() && pDispatcher)
622 {
623 SfxViewFrame* pViewFrame = pDispatcher->GetFrame();
624 if (pViewFrame)
625 xFrameRef = pViewFrame->GetFrame().GetFrameInterface();
626 }
627
628 bool bSuccess = false;
629 const SfxPoolItem* pItem = nullptr;
630 MapUnit eMapUnit( MapUnit::Map100thMM );
631
632 // Extra scope so that aInternalSet is destroyed before
633 // rListener->dispatchFinished potentially calls
634 // framework::Desktop::terminate -> SfxApplication::Deinitialize ->
635 // ~CntItemPool:
636 if (pDispatcher)
637 {
638 SfxAllItemSet aInternalSet( SfxGetpApp()->GetPool() );
639 if (xFrameRef.is()) // an empty set is no problem ... but an empty frame reference can be a problem !
640 aInternalSet.Put( SfxUnoFrameItem( SID_FILLFRAME, xFrameRef ) );
641
642 SfxShell* pShell( nullptr );
643 // #i102619# Retrieve metric from shell before execution - the shell could be destroyed after execution
644 if ( pDispatcher->GetBindings() )
645 {
646 if ( !pDispatcher->IsLocked() )
647 {
648 const SfxSlot *pSlot = nullptr;
649 if ( pDispatcher->GetShellAndSlot_Impl( GetId(), &pShell, &pSlot, false, false ) )
650 {
651 if ( bMasterSlave )
652 {
653 // Extract slave command and add argument to the args list. Master slot MUST
654 // have an argument that has the same name as the master slot and type is SfxStringItem.
655 sal_Int32 nIndex = lNewArgs.getLength();
656 lNewArgs.realloc( nIndex+1 );
657 auto plNewArgs = lNewArgs.getArray();
658 plNewArgs[nIndex].Name = pSlot->pUnoName;
660 }
661
662 eMapUnit = GetCoreMetric( pShell->GetPool(), GetId() );
663 std::optional<SfxAllItemSet> xSet(pShell->GetPool());
664 TransformParameters(GetId(), lNewArgs, *xSet, pSlot);
665 if (xSet->Count())
666 {
667 // execute with arguments - call directly
668 pItem = pDispatcher->Execute(GetId(), nCall, &*xSet, &aInternalSet, nModifier);
669 if ( pItem != nullptr )
670 {
671 if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem))
672 bSuccess = pBoolItem->GetValue();
673 else if ( !pItem->IsVoidItem() )
674 bSuccess = true; // all other types are true
675 }
676 // else bSuccess = false look to line 664 it is false
677 }
678 else
679 {
680 // Be sure to delete this before we send a dispatch
681 // request, which will destroy the current shell.
682 xSet.reset();
683
684 // execute using bindings, enables support for toggle/enum etc.
685 SfxRequest aReq( GetId(), nCall, pShell->GetPool() );
686 aReq.SetModifier( nModifier );
687 aReq.SetInternalArgs_Impl(aInternalSet);
688 pDispatcher->GetBindings()->Execute_Impl( aReq, pSlot, pShell );
689 pItem = aReq.GetReturnValue();
690 bSuccess = aReq.IsDone() || pItem != nullptr;
691 }
692 }
693 else
694 SAL_INFO("sfx.control", "MacroPlayer: Unknown slot dispatched!");
695 }
696 }
697 else
698 {
699 eMapUnit = GetCoreMetric( SfxGetpApp()->GetPool(), GetId() );
700 // AppDispatcher
701 SfxAllItemSet aSet( SfxGetpApp()->GetPool() );
702 TransformParameters( GetId(), lNewArgs, aSet );
703
704 if ( aSet.Count() )
705 pItem = pDispatcher->Execute(GetId(), nCall, &aSet, &aInternalSet, nModifier);
706 else
707 // SfxRequests take empty sets as argument sets, GetArgs() returning non-zero!
708 pItem = pDispatcher->Execute(GetId(), nCall, nullptr, &aInternalSet, nModifier);
709
710 // no bindings, no invalidate ( usually done in SfxDispatcher::Call_Impl()! )
712 {
713 SfxDispatcher* pAppDispat = pApp->GetAppDispatcher_Impl();
714 if ( pAppDispat )
715 {
716 const SfxPoolItem* pState=nullptr;
717 SfxItemState eState = pDispatcher->QueryState( GetId(), pState );
718 StateChangedAtToolBoxControl( GetId(), eState, pState );
719 }
720 }
721
722 bSuccess = (pItem != nullptr);
723 }
724 }
725
726 if ( !rListener.is() )
727 return;
728
729 css::frame::DispatchResultEvent aEvent;
730 if ( bSuccess )
731 aEvent.State = css::frame::DispatchResultState::SUCCESS;
732 else
733 aEvent.State = css::frame::DispatchResultState::FAILURE;
734
735 aEvent.Source = static_cast<css::frame::XDispatch*>(pDispatch);
736 if ( bSuccess && pItem && !pItem->IsVoidItem() )
737 {
738 sal_uInt16 nSubId( 0 );
739 if ( eMapUnit == MapUnit::MapTwip )
740 nSubId |= CONVERT_TWIPS;
741 pItem->QueryValue( aEvent.Result, static_cast<sal_uInt8>(nSubId) );
742 }
743
744 rListener->dispatchFinished( aEvent );
745}
746
748{
749 if ( !pDispatcher && pBindings )
751 return pDispatcher;
752}
753
754void SfxDispatchController_Impl::addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL)
755{
756 SolarMutexGuard aGuard;
757 if ( !pDispatch )
758 return;
759
760 // Use alternative QueryState call to have a valid UNO representation of the state.
761 css::uno::Any aState;
762 if ( !pDispatcher && pBindings )
764 SfxItemState eState = pDispatcher ? pDispatcher->QueryState( GetId(), aState ) : SfxItemState::DONTCARE;
765
766 if ( eState == SfxItemState::DONTCARE )
767 {
768 // Use special uno struct to transport don't care state
769 css::frame::status::ItemStatus aItemStatus;
770 aItemStatus.State = css::frame::status::ItemState::DONT_CARE;
771 aState <<= aItemStatus;
772 }
773
774 css::frame::FeatureStateEvent aEvent;
775 aEvent.FeatureURL = aURL;
776 aEvent.Source = static_cast<css::frame::XDispatch*>(pDispatch);
777 aEvent.Requery = false;
778 if ( bVisible )
779 {
780 aEvent.IsEnabled = eState != SfxItemState::DISABLED;
781 aEvent.State = aState;
782 }
783 else
784 {
785 css::frame::status::Visibility aVisibilityStatus;
786 aVisibilityStatus.bVisible = false;
787
788 // MBA: we might decide to *not* disable "invisible" slots, but this would be
789 // a change that needs to adjust at least the testtool
790 aEvent.IsEnabled = false;
791 aEvent.State <<= aVisibilityStatus;
792 }
793
794 aListener->statusChanged( aEvent );
795}
796
797void SfxDispatchController_Impl::sendStatusChanged(const OUString& rURL, const css::frame::FeatureStateEvent& rEvent)
798{
799 pDispatch->sendStatusChanged(rURL, rEvent);
800}
801
802void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer const * pSlotServ )
803{
804 if ( !pDispatch )
805 return;
806
807 // Bindings instance notifies controller about a state change, listeners must be notified also
808 // Don't cache visibility state changes as they are volatile. We need our real state to send it
809 // to our controllers after visibility is set to true.
810 bool bNotify = true;
811 if ( pState && !IsInvalidItem( pState ) )
812 {
813 if ( auto pVisibilityItem = dynamic_cast< const SfxVisibilityItem *>( pState ) )
814 bVisible = pVisibilityItem->GetValue();
815 else
816 {
818 {
819 bNotify = typeid(*pState) != typeid(*pLastState) || *pState != *pLastState;
820 delete pLastState;
821 }
822 pLastState = !IsInvalidItem(pState) ? pState->Clone() : pState;
823 bVisible = true;
824 }
825 }
826 else
827 {
829 delete pLastState;
830 pLastState = pState;
831 }
832
833 if (!bNotify)
834 return;
835
836 css::uno::Any aState;
837 if ( ( eState >= SfxItemState::DEFAULT ) && pState && !IsInvalidItem( pState ) && !pState->IsVoidItem() )
838 {
839 // Retrieve metric from pool to have correct sub ID when calling QueryValue
840 sal_uInt16 nSubId( 0 );
841 MapUnit eMapUnit( MapUnit::Map100thMM );
842
843 // retrieve the core metric
844 // it's enough to check the objectshell, the only shell that does not use the pool of the document
845 // is SfxViewFrame, but it hasn't any metric parameters
846 // TODO/LATER: what about the FormShell? Does it use any metric data?! Perhaps it should use the Pool of the document!
847 if ( pSlotServ && pDispatcher )
848 {
849 if (SfxShell* pShell = pDispatcher->GetShell( pSlotServ->GetShellLevel() ))
850 eMapUnit = GetCoreMetric( pShell->GetPool(), nSID );
851 }
852
853 if ( eMapUnit == MapUnit::MapTwip )
854 nSubId |= CONVERT_TWIPS;
855
856 pState->QueryValue( aState, static_cast<sal_uInt8>(nSubId) );
857 }
858 else if ( eState == SfxItemState::DONTCARE )
859 {
860 // Use special uno struct to transport don't care state
861 css::frame::status::ItemStatus aItemStatus;
862 aItemStatus.State = css::frame::status::ItemState::DONT_CARE;
863 aState <<= aItemStatus;
864 }
865
866 css::frame::FeatureStateEvent aEvent;
867 aEvent.FeatureURL = aDispatchURL;
868 aEvent.Source = static_cast<css::frame::XDispatch*>(pDispatch);
869 aEvent.IsEnabled = eState != SfxItemState::DISABLED;
870 aEvent.Requery = false;
871 aEvent.State = aState;
872
874 {
876 }
877
878 const std::vector<OUString> aContainedTypes = pDispatch->getContainedTypes();
879 for (const OUString& rName: aContainedTypes)
880 {
881 if (rName == aDispatchURL.Main || rName == aDispatchURL.Complete)
883 }
884}
885
887{
888 StateChanged( nSID, eState, pState, nullptr );
889}
890
891static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, SfxViewFrame* pViewFrame, const css::frame::FeatureStateEvent& aEvent, const SfxPoolItem* pState)
892{
894 return;
895
896 OUStringBuffer aBuffer(aEvent.FeatureURL.Complete + "=");
897
898 if (aEvent.FeatureURL.Path == "Bold" ||
899 aEvent.FeatureURL.Path == "CenterPara" ||
900 aEvent.FeatureURL.Path == "CharBackgroundExt" ||
901 aEvent.FeatureURL.Path == "ControlCodes" ||
902 aEvent.FeatureURL.Path == "DefaultBullet" ||
903 aEvent.FeatureURL.Path == "DefaultNumbering" ||
904 aEvent.FeatureURL.Path == "Italic" ||
905 aEvent.FeatureURL.Path == "JustifyPara" ||
906 aEvent.FeatureURL.Path == "LeftPara" ||
907 aEvent.FeatureURL.Path == "OutlineFont" ||
908 aEvent.FeatureURL.Path == "RightPara" ||
909 aEvent.FeatureURL.Path == "Shadowed" ||
910 aEvent.FeatureURL.Path == "SpellOnline" ||
911 aEvent.FeatureURL.Path == "OnlineAutoFormat" ||
912 aEvent.FeatureURL.Path == "SubScript" ||
913 aEvent.FeatureURL.Path == "SuperScript" ||
914 aEvent.FeatureURL.Path == "Strikeout" ||
915 aEvent.FeatureURL.Path == "Underline" ||
916 aEvent.FeatureURL.Path == "ModifiedStatus" ||
917 aEvent.FeatureURL.Path == "TrackChanges" ||
918 aEvent.FeatureURL.Path == "ShowTrackedChanges" ||
919 aEvent.FeatureURL.Path == "NextTrackedChange" ||
920 aEvent.FeatureURL.Path == "PreviousTrackedChange" ||
921 aEvent.FeatureURL.Path == "AlignLeft" ||
922 aEvent.FeatureURL.Path == "AlignHorizontalCenter" ||
923 aEvent.FeatureURL.Path == "AlignRight" ||
924 aEvent.FeatureURL.Path == "DocumentRepair" ||
925 aEvent.FeatureURL.Path == "ObjectAlignLeft" ||
926 aEvent.FeatureURL.Path == "ObjectAlignRight" ||
927 aEvent.FeatureURL.Path == "AlignCenter" ||
928 aEvent.FeatureURL.Path == "AlignUp" ||
929 aEvent.FeatureURL.Path == "AlignMiddle" ||
930 aEvent.FeatureURL.Path == "AlignDown" ||
931 aEvent.FeatureURL.Path == "TraceChangeMode" ||
932 aEvent.FeatureURL.Path == "FormatPaintbrush" ||
933 aEvent.FeatureURL.Path == "FreezePanes" ||
934 aEvent.FeatureURL.Path == "Sidebar" ||
935 aEvent.FeatureURL.Path == "SpacePara1" ||
936 aEvent.FeatureURL.Path == "SpacePara15" ||
937 aEvent.FeatureURL.Path == "SpacePara2" ||
938 aEvent.FeatureURL.Path == "DataFilterAutoFilter")
939 {
940 bool bTemp = false;
941 aEvent.State >>= bTemp;
942 aBuffer.append(bTemp);
943 }
944 else if (aEvent.FeatureURL.Path == "CharFontName")
945 {
946 css::awt::FontDescriptor aFontDesc;
947 aEvent.State >>= aFontDesc;
948 aBuffer.append(aFontDesc.Name);
949 }
950 else if (aEvent.FeatureURL.Path == "FontHeight")
951 {
952 css::frame::status::FontHeight aFontHeight;
953 aEvent.State >>= aFontHeight;
954 aBuffer.append(aFontHeight.Height);
955 }
956 else if (aEvent.FeatureURL.Path == "StyleApply")
957 {
958 css::frame::status::Template aTemplate;
959 aEvent.State >>= aTemplate;
960 aBuffer.append(aTemplate.StyleName);
961 }
962 else if (aEvent.FeatureURL.Path == "BackColor" ||
963 aEvent.FeatureURL.Path == "BackgroundColor" ||
964 aEvent.FeatureURL.Path == "CharBackColor" ||
965 aEvent.FeatureURL.Path == "Color" ||
966 aEvent.FeatureURL.Path == "FontColor" ||
967 aEvent.FeatureURL.Path == "FrameLineColor" ||
968 aEvent.FeatureURL.Path == "GlowColor")
969 {
970 sal_Int32 nColor = -1;
971 aEvent.State >>= nColor;
972 aBuffer.append(nColor);
973 }
974 else if (aEvent.FeatureURL.Path == "Undo" ||
975 aEvent.FeatureURL.Path == "Redo")
976 {
977 const SfxUInt32Item* pUndoConflict = dynamic_cast< const SfxUInt32Item * >( pState );
978 if ( pUndoConflict && pUndoConflict->GetValue() > 0 )
979 {
980 aBuffer.append("disabled");
981 }
982 else
983 {
984 aBuffer.append(aEvent.IsEnabled ? std::u16string_view(u"enabled") : std::u16string_view(u"disabled"));
985 }
986 }
987 else if (aEvent.FeatureURL.Path == "Cut" ||
988 aEvent.FeatureURL.Path == "Copy" ||
989 aEvent.FeatureURL.Path == "Paste" ||
990 aEvent.FeatureURL.Path == "SelectAll" ||
991 aEvent.FeatureURL.Path == "InsertAnnotation" ||
992 aEvent.FeatureURL.Path == "DeleteAnnotation" ||
993 aEvent.FeatureURL.Path == "ResolveAnnotation" ||
994 aEvent.FeatureURL.Path == "ResolveAnnotationThread" ||
995 aEvent.FeatureURL.Path == "InsertRowsBefore" ||
996 aEvent.FeatureURL.Path == "InsertRowsAfter" ||
997 aEvent.FeatureURL.Path == "InsertColumnsBefore" ||
998 aEvent.FeatureURL.Path == "InsertColumnsAfter" ||
999 aEvent.FeatureURL.Path == "MergeCells" ||
1000 aEvent.FeatureURL.Path == "InsertObjectChart" ||
1001 aEvent.FeatureURL.Path == "InsertSection" ||
1002 aEvent.FeatureURL.Path == "InsertAnnotation" ||
1003 aEvent.FeatureURL.Path == "InsertPagebreak" ||
1004 aEvent.FeatureURL.Path == "InsertColumnBreak" ||
1005 aEvent.FeatureURL.Path == "HyperlinkDialog" ||
1006 aEvent.FeatureURL.Path == "InsertSymbol" ||
1007 aEvent.FeatureURL.Path == "InsertPage" ||
1008 aEvent.FeatureURL.Path == "DeletePage" ||
1009 aEvent.FeatureURL.Path == "DuplicatePage" ||
1010 aEvent.FeatureURL.Path == "DeleteRows" ||
1011 aEvent.FeatureURL.Path == "DeleteColumns" ||
1012 aEvent.FeatureURL.Path == "DeleteTable" ||
1013 aEvent.FeatureURL.Path == "SelectTable" ||
1014 aEvent.FeatureURL.Path == "EntireRow" ||
1015 aEvent.FeatureURL.Path == "EntireColumn" ||
1016 aEvent.FeatureURL.Path == "EntireCell" ||
1017 aEvent.FeatureURL.Path == "SortAscending" ||
1018 aEvent.FeatureURL.Path == "SortDescending" ||
1019 aEvent.FeatureURL.Path == "AcceptAllTrackedChanges" ||
1020 aEvent.FeatureURL.Path == "RejectAllTrackedChanges" ||
1021 aEvent.FeatureURL.Path == "AcceptTrackedChange" ||
1022 aEvent.FeatureURL.Path == "RejectTrackedChange" ||
1023 aEvent.FeatureURL.Path == "NextTrackedChange" ||
1024 aEvent.FeatureURL.Path == "PreviousTrackedChange" ||
1025 aEvent.FeatureURL.Path == "FormatGroup" ||
1026 aEvent.FeatureURL.Path == "ObjectBackOne" ||
1027 aEvent.FeatureURL.Path == "SendToBack" ||
1028 aEvent.FeatureURL.Path == "ObjectForwardOne" ||
1029 aEvent.FeatureURL.Path == "BringToFront" ||
1030 aEvent.FeatureURL.Path == "WrapRight" ||
1031 aEvent.FeatureURL.Path == "WrapThrough" ||
1032 aEvent.FeatureURL.Path == "WrapLeft" ||
1033 aEvent.FeatureURL.Path == "WrapIdeal" ||
1034 aEvent.FeatureURL.Path == "WrapOn" ||
1035 aEvent.FeatureURL.Path == "WrapOff" ||
1036 aEvent.FeatureURL.Path == "UpdateCurIndex" ||
1037 aEvent.FeatureURL.Path == "InsertCaptionDialog" ||
1038 aEvent.FeatureURL.Path == "MergeCells" ||
1039 aEvent.FeatureURL.Path == "SplitTable" ||
1040 aEvent.FeatureURL.Path == "SplitCell" ||
1041 aEvent.FeatureURL.Path == "DeleteNote" ||
1042 aEvent.FeatureURL.Path == "AcceptChanges" ||
1043 aEvent.FeatureURL.Path == "SetDefault" ||
1044 aEvent.FeatureURL.Path == "ParaLeftToRight" ||
1045 aEvent.FeatureURL.Path == "ParaRightToLeft" ||
1046 aEvent.FeatureURL.Path == "ParaspaceIncrease" ||
1047 aEvent.FeatureURL.Path == "ParaspaceDecrease" ||
1048 aEvent.FeatureURL.Path == "TableDialog" ||
1049 aEvent.FeatureURL.Path == "FormatCellDialog" ||
1050 aEvent.FeatureURL.Path == "FontDialog" ||
1051 aEvent.FeatureURL.Path == "ParagraphDialog" ||
1052 aEvent.FeatureURL.Path == "OutlineBullet" ||
1053 aEvent.FeatureURL.Path == "InsertIndexesEntry" ||
1054 aEvent.FeatureURL.Path == "TransformDialog" ||
1055 aEvent.FeatureURL.Path == "EditRegion" ||
1056 aEvent.FeatureURL.Path == "ThesaurusDialog" ||
1057 aEvent.FeatureURL.Path == "OutlineRight" ||
1058 aEvent.FeatureURL.Path == "OutlineLeft" ||
1059 aEvent.FeatureURL.Path == "OutlineDown" ||
1060 aEvent.FeatureURL.Path == "OutlineUp" ||
1061 aEvent.FeatureURL.Path == "FormatArea" ||
1062 aEvent.FeatureURL.Path == "FormatLine" ||
1063 aEvent.FeatureURL.Path == "FormatColumns" ||
1064 aEvent.FeatureURL.Path == "Watermark" ||
1065 aEvent.FeatureURL.Path == "InsertBreak" ||
1066 aEvent.FeatureURL.Path == "InsertEndnote" ||
1067 aEvent.FeatureURL.Path == "InsertFootnote" ||
1068 aEvent.FeatureURL.Path == "InsertReferenceField" ||
1069 aEvent.FeatureURL.Path == "InsertBookmark" ||
1070 aEvent.FeatureURL.Path == "InsertAuthoritiesEntry" ||
1071 aEvent.FeatureURL.Path == "InsertMultiIndex" ||
1072 aEvent.FeatureURL.Path == "InsertField" ||
1073 aEvent.FeatureURL.Path == "PageNumberWizard" ||
1074 aEvent.FeatureURL.Path == "InsertPageNumberField" ||
1075 aEvent.FeatureURL.Path == "InsertPageCountField" ||
1076 aEvent.FeatureURL.Path == "InsertDateField" ||
1077 aEvent.FeatureURL.Path == "InsertTitleField" ||
1078 aEvent.FeatureURL.Path == "InsertFieldCtrl" ||
1079 aEvent.FeatureURL.Path == "CharmapControl" ||
1080 aEvent.FeatureURL.Path == "EnterGroup" ||
1081 aEvent.FeatureURL.Path == "LeaveGroup" ||
1082 aEvent.FeatureURL.Path == "Combine" ||
1083 aEvent.FeatureURL.Path == "Merge" ||
1084 aEvent.FeatureURL.Path == "Dismantle" ||
1085 aEvent.FeatureURL.Path == "Substract" ||
1086 aEvent.FeatureURL.Path == "DistributeSelection" ||
1087 aEvent.FeatureURL.Path == "Intersect" ||
1088 aEvent.FeatureURL.Path == "ResetAttributes" ||
1089 aEvent.FeatureURL.Path == "IncrementIndent" ||
1090 aEvent.FeatureURL.Path == "DecrementIndent" ||
1091 aEvent.FeatureURL.Path == "EditHeaderAndFooter" ||
1092 aEvent.FeatureURL.Path == "InsertSparkline" ||
1093 aEvent.FeatureURL.Path == "DeleteSparkline" ||
1094 aEvent.FeatureURL.Path == "DeleteSparklineGroup" ||
1095 aEvent.FeatureURL.Path == "EditSparklineGroup" ||
1096 aEvent.FeatureURL.Path == "EditSparkline" ||
1097 aEvent.FeatureURL.Path == "GroupSparklines" ||
1098 aEvent.FeatureURL.Path == "UngroupSparklines" ||
1099 aEvent.FeatureURL.Path == "FormatSparklineMenu" ||
1100 aEvent.FeatureURL.Path == "NumberFormatDecDecimals" ||
1101 aEvent.FeatureURL.Path == "NumberFormatIncDecimals" ||
1102 aEvent.FeatureURL.Path == "Protect" ||
1103 aEvent.FeatureURL.Path == "UnsetCellsReadOnly" ||
1104 aEvent.FeatureURL.Path == "ContentControlProperties" ||
1105 aEvent.FeatureURL.Path == "InsertCheckboxContentControl" ||
1106 aEvent.FeatureURL.Path == "InsertContentControl" ||
1107 aEvent.FeatureURL.Path == "InsertDateContentControl" ||
1108 aEvent.FeatureURL.Path == "InsertDropdownContentControl" ||
1109 aEvent.FeatureURL.Path == "InsertPlainTextContentControl" ||
1110 aEvent.FeatureURL.Path == "InsertPictureContentControl")
1111 {
1112 aBuffer.append(aEvent.IsEnabled ? std::u16string_view(u"enabled") : std::u16string_view(u"disabled"));
1113 }
1114 else if (aEvent.FeatureURL.Path == "AssignLayout" ||
1115 aEvent.FeatureURL.Path == "StatusSelectionMode" ||
1116 aEvent.FeatureURL.Path == "Signature" ||
1117 aEvent.FeatureURL.Path == "SelectionMode" ||
1118 aEvent.FeatureURL.Path == "StatusBarFunc")
1119 {
1120 sal_Int32 aInt32;
1121
1122 if (aEvent.IsEnabled && (aEvent.State >>= aInt32))
1123 {
1124 aBuffer.append(aInt32);
1125 }
1126 }
1127 else if (aEvent.FeatureURL.Path == "TransformPosX" ||
1128 aEvent.FeatureURL.Path == "TransformPosY" ||
1129 aEvent.FeatureURL.Path == "TransformWidth" ||
1130 aEvent.FeatureURL.Path == "TransformHeight")
1131 {
1132 const SfxViewShell* pViewShell = SfxViewShell::Current();
1133 if (aEvent.IsEnabled && pViewShell && pViewShell->isLOKMobilePhone())
1134 {
1135 boost::property_tree::ptree aTree;
1136 boost::property_tree::ptree aState;
1137 OUString aStr(aEvent.FeatureURL.Complete);
1138
1139 aTree.put("commandName", aStr.toUtf8().getStr());
1140 pViewFrame->GetBindings().QueryControlState(nSID, aState);
1141 aTree.add_child("state", aState);
1142
1143 aBuffer.setLength(0);
1144 std::stringstream aStream;
1145 boost::property_tree::write_json(aStream, aTree);
1146 aBuffer.appendAscii(aStream.str().c_str());
1147 }
1148 }
1149 else if (aEvent.FeatureURL.Path == "StatusDocPos" ||
1150 aEvent.FeatureURL.Path == "RowColSelCount" ||
1151 aEvent.FeatureURL.Path == "StatusPageStyle" ||
1152 aEvent.FeatureURL.Path == "StateWordCount" ||
1153 aEvent.FeatureURL.Path == "PageStyleName" ||
1154 aEvent.FeatureURL.Path == "PageStatus" ||
1155 aEvent.FeatureURL.Path == "LayoutStatus" ||
1156 aEvent.FeatureURL.Path == "Scale" ||
1157 aEvent.FeatureURL.Path == "Context")
1158 {
1159 OUString aString;
1160
1161 if (aEvent.IsEnabled && (aEvent.State >>= aString))
1162 {
1163 aBuffer.append(aString);
1164 }
1165 }
1166 else if (aEvent.FeatureURL.Path == "StateTableCell")
1167 {
1168 if (aEvent.IsEnabled)
1169 {
1170 if (const SfxStringItem* pSvxStatusItem = dynamic_cast<const SfxStringItem*>(pState))
1171 aBuffer.append(pSvxStatusItem->GetValue());
1172 }
1173 }
1174 else if (aEvent.FeatureURL.Path == "InsertMode" ||
1175 aEvent.FeatureURL.Path == "WrapText" ||
1176 aEvent.FeatureURL.Path == "NumberFormatCurrency" ||
1177 aEvent.FeatureURL.Path == "NumberFormatPercent" ||
1178 aEvent.FeatureURL.Path == "NumberFormatDecimal" ||
1179 aEvent.FeatureURL.Path == "NumberFormatDate" ||
1180 aEvent.FeatureURL.Path == "ShowResolvedAnnotations")
1181 {
1182 bool aBool;
1183
1184 if (aEvent.IsEnabled && (aEvent.State >>= aBool))
1185 {
1186 aBuffer.append(OUString::boolean(aBool));
1187 }
1188 }
1189 else if (aEvent.FeatureURL.Path == "ToggleMergeCells" ||
1190 aEvent.FeatureURL.Path == "SheetRightToLeft")
1191 {
1192 bool aBool;
1193
1194 if (aEvent.IsEnabled && (aEvent.State >>= aBool))
1195 {
1196 aBuffer.append(OUString::boolean(aBool));
1197 }
1198 else
1199 {
1200 aBuffer.append("disabled");
1201 }
1202 }
1203 else if (aEvent.FeatureURL.Path == "Position" ||
1204 aEvent.FeatureURL.Path == "FreezePanesColumn" ||
1205 aEvent.FeatureURL.Path == "FreezePanesRow")
1206 {
1207 css::awt::Point aPoint;
1208
1209 if (aEvent.IsEnabled && (aEvent.State >>= aPoint))
1210 {
1211 aBuffer.append( OUString::number(aPoint.X) + " / " + OUString::number(aPoint.Y));
1212 }
1213 }
1214 else if (aEvent.FeatureURL.Path == "Size")
1215 {
1216 css::awt::Size aSize;
1217
1218 if (aEvent.IsEnabled && (aEvent.State >>= aSize))
1219 {
1220 aBuffer.append( OUString::number(aSize.Width) + " x " + OUString::number(aSize.Height) );
1221 }
1222 }
1223 else if (aEvent.FeatureURL.Path == "LanguageStatus" ||
1224 aEvent.FeatureURL.Path == "StatePageNumber")
1225 {
1226 css::uno::Sequence< OUString > aSeq;
1227
1228 if (aEvent.IsEnabled)
1229 {
1230 OUString sValue;
1231 if (aEvent.State >>= sValue)
1232 {
1233 aBuffer.append(sValue);
1234 }
1235 else if (aEvent.State >>= aSeq)
1236 {
1237 aBuffer.append(aSeq[0]);
1238 }
1239 }
1240 }
1241 else if (aEvent.FeatureURL.Path == "InsertPageHeader" ||
1242 aEvent.FeatureURL.Path == "InsertPageFooter")
1243 {
1244 if (aEvent.IsEnabled)
1245 {
1246 css::uno::Sequence< OUString > aSeq;
1247 if (aEvent.State >>= aSeq)
1248 {
1249 aBuffer.append(u'{');
1250 for (sal_Int32 itSeq = 0; itSeq < aSeq.getLength(); itSeq++)
1251 {
1252 aBuffer.append("\"" + aSeq[itSeq]);
1253 if (itSeq != aSeq.getLength() - 1)
1254 aBuffer.append("\":true,");
1255 else
1256 aBuffer.append("\":true");
1257 }
1258 aBuffer.append(u'}');
1259 }
1260 }
1261 }
1262 else if (aEvent.FeatureURL.Path == "TableColumWidth" ||
1263 aEvent.FeatureURL.Path == "TableRowHeight")
1264 {
1265 sal_Int32 nValue;
1266 if (aEvent.State >>= nValue)
1267 {
1268 float nScaleValue = 1000.0;
1269 nValue *= nScaleValue;
1270 sal_Int32 nConvertedValue = o3tl::convert(nValue, o3tl::Length::twip, o3tl::Length::in);
1271 aBuffer.append(nConvertedValue / nScaleValue);
1272 }
1273 }
1274 else
1275 {
1276 // Try to send JSON state version
1277 SfxLokHelper::sendUnoStatus(pViewFrame->GetViewShell(), pState);
1278
1279 return;
1280 }
1281
1282 OUString payload = aBuffer.makeStringAndClear();
1283 if (const SfxViewShell* pViewShell = pViewFrame->GetViewShell())
1284 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, payload.toUtf8());
1285}
1286
1287/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::mutex maMutex
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
void TransformParameters(sal_uInt16 nSlotId, const uno::Sequence< beans::PropertyValue > &rArgs, SfxAllItemSet &rSet, const SfxSlot *pSlot)
Definition: appuno.cxx:170
AnyEventRef aEvent
SfxCallMode
Definition: bindings.hxx:57
sal_uInt32 GetValue() const
static void logUnoCommand(SAL_UNUSED_PARAMETER const OUString &)
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
bool HasParam() const
static SfxApplication * Get()
Definition: app.cxx:70
SAL_DLLPRIVATE SfxDispatcher * GetDispatcher_Impl()
Definition: bindings.hxx:180
void QueryControlState(sal_uInt16 nSID, boost::property_tree::ptree &rState)
Definition: bindings.cxx:1614
SAL_DLLPRIVATE const SfxPoolItem * Execute_Impl(sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi, SfxCallMode nCall, const SfxPoolItem **pInternalArgs, bool bGlobalOnly=false)
Definition: bindings.cxx:875
SAL_DLLPRIVATE void BindInternal_Impl(sal_uInt16 nNewId, SfxBindings *)
Definition: ctrlitem.cxx:64
SfxBindings & GetBindings()
Definition: ctrlitem.hxx:39
bool IsBound() const
Definition: ctrlitem.cxx:39
sal_uInt16 GetId() const
Definition: ctrlitem.hxx:63
MapUnit GetCoreMetric() const
Definition: ctrlitem.cxx:302
void SetId(sal_uInt16 nItemId)
Definition: ctrlitem.cxx:165
void sendStatusChanged(const OUString &rURL, const css::frame::FeatureStateEvent &rEvent)
Definition: unoctitm.cxx:797
css::uno::WeakReference< css::frame::XFrame > xFrame
Definition: unoctitm.hxx:114
void setMasterSlaveCommand(bool bSet)
Definition: unoctitm.cxx:398
static OUString getSlaveCommand(const css::util::URL &rURL)
Definition: unoctitm.cxx:500
virtual ~SfxDispatchController_Impl() override
Definition: unoctitm.cxx:378
SfxDispatcher * pDispatcher
Definition: unoctitm.hxx:108
SfxDispatcher * GetDispatcher()
Definition: unoctitm.cxx:747
const SfxPoolItem * pLastState
Definition: unoctitm.hxx:110
static void addParametersToArgs(const css::util::URL &aURL, css::uno::Sequence< css::beans::PropertyValue > &rArgs)
Definition: unoctitm.cxx:414
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: unoctitm.cxx:393
void StateChanged(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState, SfxSlotServer const *pServ)
Definition: unoctitm.cxx:802
void dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs, const css::uno::Reference< css::frame::XDispatchResultListener > &rListener)
Definition: unoctitm.cxx:523
void addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL)
Definition: unoctitm.cxx:754
virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: unoctitm.cxx:886
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: unoctitm.cxx:368
css::util::URL aDispatchURL
Definition: unoctitm.hxx:107
SfxDispatchController_Impl(SfxOfficeDispatch *pDisp, SfxBindings *pBind, SfxDispatcher *pDispat, const SfxSlot *pSlot, css::util::URL aURL)
Definition: unoctitm.cxx:324
SfxOfficeDispatch * pDispatch
Definition: unoctitm.hxx:111
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
Method to execute a <SfxSlot>s over the Slot-Id.
Definition: dispatch.cxx:833
SfxBindings * GetBindings() const
This method returns a pointer to the <SfxBinding> Instance on which the SfxDispatcher is currently bo...
Definition: dispatch.cxx:545
bool IsLocked() const
With this method it can be determined whether the SfxDispatcher is locked or unlocked.
Definition: dispatch.cxx:196
SfxViewFrame * GetFrame() const
Returns a pointer to the <SfxViewFrame> instance, which belongs to this SfxDispatcher.
Definition: dispatch.cxx:557
SfxShell * GetShell(sal_uInt16 nIdx) const
Returns a pointer to the <SfxShell> which is at the position nIdx (from the top, last pushed is 0) on...
Definition: dispatch.cxx:529
SAL_DLLPRIVATE bool GetShellAndSlot_Impl(sal_uInt16 nSlot, SfxShell **ppShell, const SfxSlot **ppSlot, bool bOwnShellsOnly, bool bRealSlot)
This method searches in SfxDispatcher after <SfxShell> , from the Slot Id nSlot currently being handl...
Definition: dispatch.cxx:696
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
Definition: dispatch.cxx:1970
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
Definition: frame.cxx:515
SfxHintId GetId() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
sal_uInt16 Count() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
static void sendUnoStatus(const SfxViewShell *pShell, const SfxPoolItem *pItem)
Emits a LOK_CALLBACK_STATE_CHANGED.
Definition: lokhelper.cxx:559
virtual ~SfxOfficeDispatch() override
Definition: unoctitm.cxx:189
std::unique_ptr< SfxDispatchController_Impl > pImpl
Definition: unoctitm.hxx:72
sal_uInt16 GetId() const
Definition: unoctitm.cxx:288
SfxDispatcher * GetDispatcher_Impl()
Definition: unoctitm.cxx:283
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: unoctitm.cxx:227
void SetFrame(const css::uno::Reference< css::frame::XFrame > &xFrame)
Definition: unoctitm.cxx:293
void SetMasterUnoCommand(bool bSet)
Definition: unoctitm.cxx:299
SfxOfficeDispatch(SfxBindings &rBind, SfxDispatcher *pDispat, const SfxSlot *pSlot, const css::util::URL &rURL)
Definition: unoctitm.cxx:176
static OUString GetMasterUnoCommand(const css::util::URL &aURL)
Definition: unoctitm.cxx:311
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unoctitm.cxx:270
static bool IsMasterUnoCommand(const css::util::URL &aURL)
Definition: unoctitm.cxx:306
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs, const css::uno::Reference< css::frame::XDispatchResultListener > &rListener) override
Definition: unoctitm.cxx:256
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
virtual bool IsVoidItem() const
const SfxPoolItem * GetReturnValue() const
Definition: request.cxx:429
bool IsDone() const
Definition: request.cxx:648
void SetModifier(sal_uInt16 nModi)
Definition: request.cxx:718
void SetInternalArgs_Impl(const SfxAllItemSet &rArgs)
Definition: request.cxx:309
The class SfxShell is the base class for all classes, which provide the functionality of the form <Sl...
Definition: shell.hxx:128
SfxItemPool & GetPool() const
Each Subclass of SfxShell must reference a pool.
Definition: shell.hxx:511
SfxViewShell * GetViewShell() const
Returns the SfxViewShell in which they are located in the subshells.
Definition: shell.cxx:129
sal_uInt16 GetShellLevel() const
Definition: slotserv.hxx:47
Definition: msg.hxx:184
sal_uInt16 GetSlotId() const
Definition: msg.hxx:253
OUString pUnoName
Definition: msg.hxx:205
SFX2_DLLPUBLIC OUString GetCommand() const
Definition: msg.cxx:46
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unoctitm.cxx:152
void sendStatusChanged(const OUString &rURL, const css::frame::FeatureStateEvent &rEvent)
Definition: unoctitm.cxx:123
std::mutex maMutex
Definition: unoctitm.hxx:46
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs, const css::uno::Reference< css::frame::XDispatchResultListener > &rListener) override
Definition: unoctitm.cxx:141
SfxStatusDispatcher_Impl_ListenerContainer maListeners
Definition: unoctitm.hxx:47
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: unoctitm.cxx:137
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xControl, const css::util::URL &aURL) override
Definition: unoctitm.cxx:169
SfxBindings & GetBindings()
Definition: viewfrm.hxx:110
SfxFrame & GetFrame() const
Definition: viewfrm.cxx:2782
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
Definition: viewsh.hxx:165
bool isLOKMobilePhone() const
Check if the lok client is running on a mobile device.
Definition: viewsh.hxx:470
virtual void libreOfficeKitViewCallback(int nType, const OString &pPayload) const override
Invokes the registered callback, if there are any.
Definition: viewsh.cxx:2244
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
Definition: viewsh.cxx:1848
void logCommand(std::u16string_view rAction, const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
static UITestLogger & getInstance()
void forEach(std::unique_lock< std::mutex > &rGuard, FuncT const &func) const
sal_Int32 removeInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 addInterface(::std::unique_lock<::std::mutex > &rGuard, const key &rKey, const css::uno::Reference< listener > &rListener)
void disposeAndClear(std::unique_lock< std::mutex > &rGuard, const css::lang::EventObject &rEvt)
OInterfaceContainerHelper4< listener > * getContainer(std::unique_lock< std::mutex > &rGuard, const key &rKey) const
void put(std::u16string_view pPropName, const OUString &rPropValue)
OString finishAndGetAsOString()
int nCount
URL aURL
float u
sal_Int16 nValue
sal_Int32 nIndex
sal_Int64 n
Sequence< sal_Int8 > aSeq
Definition: lnkbase2.cxx:83
#define SAL_INFO(area, stream)
MapUnit
aStr
Definition: mgetempl.cxx:407
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
auto syncExecute(FuncT const &func) -> decltype(func())
#define CONVERT_TWIPS
SfxItemState
bool IsInvalidItem(const SfxPoolItem *pItem)
Reference< XFrame > xFrame
bool bVisible
unsigned char sal_uInt8
signed char sal_Int8
const char *const URLTypeNames[URLType_COUNT]
Definition: unoctitm.cxx:101
static void InterceptLOKStateChangeEvent(sal_uInt16 nSID, SfxViewFrame *pViewFrame, const css::frame::FeatureStateEvent &aEvent, const SfxPoolItem *pState)
Definition: unoctitm.cxx:891
std::unique_ptr< char[]> aBuffer