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/embed/VerbDescriptor.hpp>
21 : #include <com/sun/star/embed/VerbAttributes.hpp>
22 : #include <basic/sbstar.hxx>
23 : #include <officecfg/Office/Common.hxx>
24 : #include <rtl/ustring.hxx>
25 : #include <sal/log.hxx>
26 : #include <svl/itempool.hxx>
27 : #include <svl/undo.hxx>
28 : #include "itemdel.hxx"
29 : #include <svtools/asynclink.hxx>
30 : #include <basic/sbx.hxx>
31 :
32 : #include <sfx2/app.hxx>
33 : #include <sfx2/shell.hxx>
34 : #include <sfx2/bindings.hxx>
35 : #include <sfx2/dispatch.hxx>
36 : #include <sfx2/viewfrm.hxx>
37 : #include <sfx2/objface.hxx>
38 : #include <sfx2/objsh.hxx>
39 : #include <sfx2/viewsh.hxx>
40 : #include "sfxtypes.hxx"
41 : #include <sfx2/request.hxx>
42 : #include <sfx2/mnumgr.hxx>
43 : #include "statcach.hxx"
44 : #include <sfx2/msgpool.hxx>
45 : #include <sidebar/ContextChangeBroadcaster.hxx>
46 :
47 : #include <boost/ptr_container/ptr_map.hpp>
48 : #include <boost/ptr_container/ptr_vector.hpp>
49 :
50 : // Maps the Which() field to a pointer to a SfxPoolItem
51 : typedef boost::ptr_map<sal_uInt16, SfxPoolItem> SfxItemPtrMap;
52 :
53 569630 : TYPEINIT0(SfxShell);
54 :
55 : typedef boost::ptr_vector<SfxSlot> SfxVerbSlotArr_Impl;
56 :
57 : using namespace com::sun::star;
58 :
59 : struct SfxShell_Impl: public SfxBroadcaster
60 : {
61 : OUString aObjectName; // Name of Sbx-Objects
62 : SfxItemPtrMap aItems; // Data exchange on Item level
63 : SfxViewShell* pViewSh; // SfxViewShell if Shell is
64 : // ViewFrame/ViewShell/SubShell list
65 : SfxViewFrame* pFrame; // Frame, if <UI-active>
66 : SfxRepeatTarget* pRepeatTarget; // SbxObjectRef xParent;
67 : bool bActive;
68 : sal_uIntPtr nDisableFlags;
69 : sal_uIntPtr nHelpId;
70 : svtools::AsynchronLink* pExecuter;
71 : svtools::AsynchronLink* pUpdater;
72 : SfxVerbSlotArr_Impl aSlotArr;
73 :
74 : com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > aVerbList;
75 : ::sfx2::sidebar::ContextChangeBroadcaster maContextChangeBroadcaster;
76 :
77 40337 : SfxShell_Impl()
78 : : pViewSh(0)
79 : , pFrame(0)
80 : , pRepeatTarget(0)
81 : , bActive(false)
82 : , nDisableFlags(0)
83 : , nHelpId(0)
84 : , pExecuter(0)
85 40337 : , pUpdater(0)
86 : {
87 40337 : }
88 :
89 79502 : virtual ~SfxShell_Impl() { delete pExecuter; delete pUpdater;}
90 : };
91 :
92 :
93 0 : void SfxShell::EmptyExecStub(SfxShell *, SfxRequest &)
94 : {
95 0 : }
96 :
97 11886 : void SfxShell::EmptyStateStub(SfxShell *, SfxItemSet &)
98 : {
99 11886 : }
100 :
101 14657 : SfxShell::SfxShell()
102 : : pImp(0),
103 : pPool(0),
104 14657 : pUndoMgr(0)
105 : {
106 14657 : pImp = new SfxShell_Impl;
107 14657 : }
108 :
109 25680 : SfxShell::SfxShell( SfxViewShell *pViewSh )
110 : : pImp(0),
111 : pPool(0),
112 25680 : pUndoMgr(0)
113 : {
114 25680 : pImp = new SfxShell_Impl;
115 25680 : pImp->pViewSh = pViewSh;
116 25680 : }
117 :
118 79502 : SfxShell::~SfxShell()
119 : {
120 :
121 :
122 39751 : delete pImp;
123 39751 : }
124 :
125 72988 : void SfxShell::SetName( const OUString &rName )
126 : {
127 72988 : pImp->aObjectName = rName;
128 72988 : }
129 :
130 29023 : const OUString& SfxShell::GetName() const
131 : {
132 29023 : return pImp->aObjectName;
133 : }
134 :
135 23566 : SfxDispatcher* SfxShell::GetDispatcher() const
136 : {
137 23566 : return pImp->pFrame ? pImp->pFrame->GetDispatcher() : 0;
138 : }
139 :
140 862202 : SfxViewShell* SfxShell::GetViewShell() const
141 : {
142 862202 : return pImp->pViewSh;
143 : }
144 :
145 101376 : SfxViewFrame* SfxShell::GetFrame() const
146 : {
147 101376 : if ( pImp->pFrame )
148 38197 : return pImp->pFrame;
149 63179 : if ( pImp->pViewSh )
150 42936 : return pImp->pViewSh->GetViewFrame();
151 20243 : return 0;
152 : }
153 :
154 46439 : const SfxPoolItem* SfxShell::GetItem
155 : (
156 : sal_uInt16 nSlotId // Slot-Id of the querying <SfxPoolItem>s
157 : ) const
158 : {
159 46439 : SfxItemPtrMap::const_iterator it = pImp->aItems.find( nSlotId );
160 46439 : if( it != pImp->aItems.end() )
161 40523 : return it->second;
162 5916 : return 0;
163 : }
164 :
165 50082 : void SfxShell::PutItem
166 : (
167 : const SfxPoolItem& rItem /* Instance, of which a copy is created,
168 : which is stored in the SfxShell in a list. */
169 : )
170 : {
171 : DBG_ASSERT( !rItem.ISA(SfxSetItem), "SetItems aren't allowed here" );
172 : DBG_ASSERT( SfxItemPool::IsSlot( rItem.Which() ),
173 : "items with Which-Ids aren't allowed here" );
174 :
175 : // MSC made a mess here of WNT/W95, beware of changes
176 50082 : SfxPoolItem *pItem = rItem.Clone();
177 50082 : SfxPoolItemHint aItemHint( pItem );
178 50082 : sal_uInt16 nWhich = rItem.Which();
179 :
180 50082 : SfxItemPtrMap::iterator it = pImp->aItems.find( nWhich );
181 50082 : if( it != pImp->aItems.end() )
182 : {
183 : // Replace Item
184 5656 : pImp->aItems.erase( it );
185 5656 : pImp->aItems.insert( nWhich, pItem );
186 :
187 : // if active, notify Bindings
188 5656 : SfxDispatcher *pDispat = GetDispatcher();
189 5656 : if ( pDispat )
190 : {
191 1006 : SfxBindings* pBindings = pDispat->GetBindings();
192 1006 : pBindings->Broadcast( aItemHint );
193 1006 : sal_uInt16 nSlotId = nWhich; //pItem->GetSlotId();
194 1006 : SfxStateCache* pCache = pBindings->GetStateCache( nSlotId );
195 1006 : if ( pCache )
196 : {
197 174 : pCache->SetState( SfxItemState::DEFAULT, pItem->Clone(), true );
198 174 : pCache->SetCachedState( true );
199 : }
200 : }
201 55738 : return;
202 : }
203 : else
204 : {
205 44426 : Broadcast( aItemHint );
206 44426 : pImp->aItems.insert( nWhich, pItem );
207 44426 : }
208 : }
209 :
210 0 : SfxInterface* SfxShell::GetInterface() const
211 : {
212 0 : return GetStaticInterface();
213 : }
214 :
215 3631 : ::svl::IUndoManager* SfxShell::GetUndoManager()
216 : {
217 3631 : return pUndoMgr;
218 : }
219 :
220 16245 : void SfxShell::SetUndoManager( ::svl::IUndoManager *pNewUndoMgr )
221 : {
222 : OSL_ENSURE( ( pUndoMgr == NULL ) || ( pNewUndoMgr == NULL ) || ( pUndoMgr == pNewUndoMgr ),
223 : "SfxShell::SetUndoManager: exchanging one non-NULL manager with another non-NULL manager? Suspicious!" );
224 : // there's at least one client of our UndoManager - the DocumentUndoManager at the SfxBaseModel - which
225 : // caches the UndoManager, and registers itself as listener. If exchanging non-NULL UndoManagers is really
226 : // a supported scenario (/me thinks it is not), then we would need to notify all such clients instances.
227 :
228 16245 : pUndoMgr = pNewUndoMgr;
229 16245 : if ( pUndoMgr )
230 : pUndoMgr->SetMaxUndoActionCount(
231 11020 : officecfg::Office::Common::Undo::Steps::get());
232 16245 : }
233 :
234 524 : SfxRepeatTarget* SfxShell::GetRepeatTarget() const
235 : {
236 524 : return pImp->pRepeatTarget;
237 : }
238 :
239 1644 : void SfxShell::SetRepeatTarget( SfxRepeatTarget *pTarget )
240 : {
241 1644 : pImp->pRepeatTarget = pTarget;
242 1644 : }
243 :
244 25841 : void SfxShell::Invalidate
245 : (
246 : sal_uInt16 nId /* Invalidated Slot-Id or Which-Id.
247 : If these are 0 (default), then all
248 : by this Shell currently handled Slot-Ids are
249 : invalidated. */
250 : )
251 : {
252 25841 : if ( !GetViewShell() )
253 : {
254 : OSL_FAIL( "wrong Invalidate method called!" );
255 25841 : return;
256 : }
257 :
258 25841 : Invalidate_Impl( GetViewShell()->GetViewFrame()->GetBindings(), nId );
259 : }
260 :
261 29905 : void SfxShell::Invalidate_Impl( SfxBindings& rBindings, sal_uInt16 nId )
262 : {
263 29905 : if ( nId == 0 )
264 : {
265 996 : rBindings.InvalidateShell( *this, false );
266 : }
267 : else
268 : {
269 28909 : const SfxInterface *pIF = GetInterface();
270 1688 : do
271 : {
272 28909 : const SfxSlot *pSlot = pIF->GetSlot(nId);
273 28909 : if ( pSlot )
274 : {
275 : // At Enum-Slots invalidate the Master-Slot
276 27221 : if ( SFX_KIND_ENUM == pSlot->GetKind() )
277 0 : pSlot = pSlot->GetLinkedSlot();
278 :
279 : // Invalidate the Slot itself and possible also all Slave-Slots
280 27221 : rBindings.Invalidate( pSlot->GetSlotId() );
281 54442 : for ( const SfxSlot *pSlave = pSlot->GetLinkedSlot();
282 27221 : pSlave && pIF->ContainsSlot_Impl( pSlave ) &&
283 0 : pSlave->GetLinkedSlot() == pSlot;
284 : ++pSlave )
285 0 : rBindings.Invalidate( pSlave->GetSlotId() );
286 :
287 57126 : return;
288 : }
289 :
290 1688 : pIF = pIF->GetGenoType();
291 : }
292 :
293 : while ( pIF );
294 :
295 : DBG_WARNING( "W3: invalidating slot-id unknown in shell" );
296 : }
297 : }
298 :
299 43862 : void SfxShell::DoActivate_Impl( SfxViewFrame *pFrame, bool bMDI )
300 : {
301 : #ifdef DBG_UTIL
302 : const SfxInterface *p_IF = GetInterface();
303 : if ( !p_IF )
304 : return;
305 : #endif
306 : SAL_INFO(
307 : "sfx.control",
308 : "SfxShell::DoActivate() " << this << " " << GetInterface()->GetName()
309 : << " bMDI " << (bMDI ? "MDI" : ""));
310 :
311 43862 : if ( bMDI )
312 : {
313 : // Remember Frame, in which it was activated
314 43862 : pImp->pFrame = pFrame;
315 43862 : pImp->bActive = true;
316 : }
317 :
318 : // Notify Subclass
319 43862 : Activate(bMDI);
320 43862 : }
321 :
322 49536 : void SfxShell::DoDeactivate_Impl( SfxViewFrame *pFrame, bool bMDI )
323 : {
324 : #ifdef DBG_UTIL
325 : const SfxInterface *p_IF = GetInterface();
326 : if ( !p_IF )
327 : return;
328 : #endif
329 : SAL_INFO(
330 : "sfx.control",
331 : "SfxShell::DoDeactivate()" << this << " " << GetInterface()->GetName()
332 : << " bMDI " << (bMDI ? "MDI" : ""));
333 :
334 : // Only when it comes from a Frame
335 : // (not when for instance by poping BASIC-IDE from AppDisp)
336 49536 : if ( bMDI && pImp->pFrame == pFrame )
337 : {
338 : // deliver
339 44030 : pImp->pFrame = 0;
340 44030 : pImp->bActive = false;
341 : }
342 :
343 : // Notify Subclass
344 49536 : Deactivate(bMDI);
345 49536 : }
346 :
347 21536 : bool SfxShell::IsActive() const
348 : {
349 21536 : return pImp->bActive;
350 : }
351 :
352 32282 : void SfxShell::Activate
353 : (
354 : bool /*bMDI*/ /* TRUE
355 : the <SfxDispatcher>, on which the SfxShell is
356 : located, is activated or the SfxShell instance
357 : was pushed on an active SfxDispatcher.
358 : (compare with SystemWindow::IsMDIActivate())
359 :
360 : FALSE
361 : the <SfxViewFrame>, on which SfxDispatcher
362 : the SfxShell instance is located, was
363 : activated. (for example by a closing dialoge) */
364 : )
365 : {
366 32282 : BroadcastContextForActivation(true);
367 32282 : }
368 :
369 39280 : void SfxShell::Deactivate
370 : (
371 : bool /*bMDI*/ /* TRUE
372 : the <SfxDispatcher>, on which the SfxShell is
373 : located, is inactivated or the SfxShell instance
374 : was popped on an active SfxDispatcher.
375 : (compare with SystemWindow::IsMDIActivate())
376 :
377 : FALSE
378 : the <SfxViewFrame>, on which SfxDispatcher
379 : the SfxShell instance is located, was
380 : deactivated. (for example by a dialoge) */
381 : )
382 : {
383 39280 : BroadcastContextForActivation(false);
384 39280 : }
385 :
386 0 : void SfxShell::ParentActivate
387 : (
388 : )
389 : {
390 0 : }
391 :
392 0 : void SfxShell::ParentDeactivate
393 : (
394 : )
395 : {
396 0 : }
397 :
398 0 : ResMgr* SfxShell::GetResMgr() const
399 : {
400 0 : return GetInterface()->GetResMgr();
401 : }
402 :
403 1090 : bool SfxShell::CanExecuteSlot_Impl( const SfxSlot &rSlot )
404 : {
405 : // Get Slot status
406 1090 : SfxItemPool &rPool = GetPool();
407 1090 : const sal_uInt16 nId = rSlot.GetWhich( rPool );
408 1090 : SfxItemSet aSet(rPool, nId, nId);
409 1090 : SfxStateFunc pFunc = rSlot.GetStateFnc();
410 1090 : CallState( pFunc, aSet );
411 1090 : return aSet.GetItemState(nId) != SfxItemState::DISABLED;
412 : }
413 :
414 0 : long ShellCall_Impl( void* pObj, void* pArg )
415 : {
416 0 : ((SfxShell* )pObj)->ExecuteSlot( *(SfxRequest*)pArg, (SfxInterface*)0L );
417 0 : return 0;
418 : }
419 :
420 0 : const SfxPoolItem* SfxShell::ExecuteSlot( SfxRequest& rReq, bool bAsync )
421 : {
422 0 : if( !bAsync )
423 0 : return ExecuteSlot( rReq, (SfxInterface*)0L );
424 : else
425 : {
426 0 : if( !pImp->pExecuter )
427 : pImp->pExecuter = new svtools::AsynchronLink(
428 0 : Link( this, ShellCall_Impl ) );
429 0 : pImp->pExecuter->Call( new SfxRequest( rReq ) );
430 0 : return 0;
431 : }
432 : }
433 :
434 726 : const SfxPoolItem* SfxShell::ExecuteSlot
435 : (
436 : SfxRequest &rReq, // the relayed <SfxRequest>
437 : const SfxInterface* pIF // default = 0 means get virtually
438 : )
439 : {
440 726 : if ( !pIF )
441 726 : pIF = GetInterface();
442 :
443 726 : sal_uInt16 nSlot = rReq.GetSlot();
444 726 : const SfxSlot* pSlot = NULL;
445 726 : if ( nSlot >= SID_VERB_START && nSlot <= SID_VERB_END )
446 0 : pSlot = GetVerbSlot_Impl(nSlot);
447 726 : if ( !pSlot )
448 726 : pSlot = pIF->GetSlot(nSlot);
449 : DBG_ASSERT( pSlot, "slot not supported" );
450 :
451 726 : SfxExecFunc pFunc = pSlot->GetExecFnc();
452 726 : if ( pFunc )
453 726 : CallExec( pFunc, rReq );
454 :
455 726 : return rReq.GetReturnValue();
456 : }
457 :
458 149467 : const SfxPoolItem* SfxShell::GetSlotState
459 : (
460 : sal_uInt16 nSlotId, // Slot-Id to the Slots in question
461 : const SfxInterface* pIF, // default = 0 means get virtually
462 : SfxItemSet* pStateSet // SfxItemSet of the Slot-State method
463 : )
464 : {
465 : // Get Slot on the given Interface
466 149467 : if ( !pIF )
467 147039 : pIF = GetInterface();
468 149467 : SfxItemState eState = SfxItemState::UNKNOWN;
469 149467 : SfxItemPool &rPool = GetPool();
470 :
471 149467 : const SfxSlot* pSlot = NULL;
472 149467 : if ( nSlotId >= SID_VERB_START && nSlotId <= SID_VERB_END )
473 0 : pSlot = GetVerbSlot_Impl(nSlotId);
474 149467 : if ( !pSlot )
475 149467 : pSlot = pIF->GetSlot(nSlotId);
476 149467 : if ( pSlot )
477 : // Map on Which-Id if possible
478 149467 : nSlotId = pSlot->GetWhich( rPool );
479 :
480 : // Get Item and Item status
481 149467 : const SfxPoolItem *pItem = NULL;
482 149467 : SfxItemSet aSet( rPool, nSlotId, nSlotId ); // else pItem dies too soon
483 149467 : if ( pSlot )
484 : {
485 : // Call Status method
486 149467 : SfxStateFunc pFunc = pSlot->GetStateFnc();
487 149467 : if ( pFunc )
488 149467 : CallState( pFunc, aSet );
489 149467 : eState = aSet.GetItemState( nSlotId, true, &pItem );
490 :
491 : // get default Item if possible
492 149467 : if ( eState == SfxItemState::DEFAULT )
493 : {
494 46943 : if ( SfxItemPool::IsWhich(nSlotId) )
495 5812 : pItem = &rPool.GetDefaultItem(nSlotId);
496 : else
497 41131 : eState = SfxItemState::DONTCARE;
498 : }
499 : }
500 : else
501 0 : eState = SfxItemState::UNKNOWN;
502 :
503 : // Evaluate Item and item status and possibly maintain them in pStateSet
504 149467 : SfxPoolItem *pRetItem = 0;
505 149467 : if ( eState <= SfxItemState::DISABLED )
506 : {
507 9537 : if ( pStateSet )
508 441 : pStateSet->DisableItem(nSlotId);
509 9537 : return 0;
510 : }
511 139930 : else if ( eState == SfxItemState::DONTCARE )
512 : {
513 41131 : if ( pStateSet )
514 1153 : pStateSet->ClearItem(nSlotId);
515 41131 : pRetItem = new SfxVoidItem(0);
516 : }
517 : else
518 : {
519 98799 : if ( pStateSet && pStateSet->Put( *pItem ) )
520 1989 : return &pStateSet->Get( pItem->Which() );
521 96810 : pRetItem = pItem->Clone();
522 : }
523 137941 : DeleteItemOnIdle(pRetItem);
524 :
525 137941 : return pRetItem;
526 : }
527 :
528 0 : SFX_EXEC_STUB(SfxShell, VerbExec)
529 0 : SFX_STATE_STUB(SfxShell, VerbState)
530 :
531 988 : void SfxShell::SetVerbs(const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& aVerbs)
532 : {
533 988 : SfxViewShell *pViewSh = PTR_CAST ( SfxViewShell, this);
534 :
535 : DBG_ASSERT(pViewSh, "Only call SetVerbs at the ViewShell!");
536 988 : if ( !pViewSh )
537 988 : return;
538 :
539 : // First make all Statecaches dirty, so that no-one no longer tries to use
540 : // the Slots
541 : {
542 : SfxBindings *pBindings =
543 988 : pViewSh->GetViewFrame()->GetDispatcher()->GetBindings();
544 988 : sal_uInt16 nCount = pImp->aSlotArr.size();
545 988 : for (sal_uInt16 n1=0; n1<nCount ; n1++)
546 : {
547 0 : sal_uInt16 nId = SID_VERB_START + n1;
548 0 : pBindings->Invalidate(nId, false, true);
549 : }
550 : }
551 :
552 988 : sal_uInt16 nr=0;
553 988 : for (sal_Int32 n=0; n<aVerbs.getLength(); n++)
554 : {
555 0 : sal_uInt16 nSlotId = SID_VERB_START + nr++;
556 : DBG_ASSERT(nSlotId <= SID_VERB_END, "To many Verbs!");
557 0 : if (nSlotId > SID_VERB_END)
558 0 : break;
559 :
560 0 : SfxSlot *pNewSlot = new SfxSlot;
561 0 : pNewSlot->nSlotId = nSlotId;
562 0 : pNewSlot->nGroupId = 0;
563 :
564 : // Verb slots must be executed asynchronously, so that they can be
565 : // destroyed while executing.
566 0 : pNewSlot->nFlags = SFX_SLOT_ASYNCHRON | SFX_SLOT_CONTAINER;
567 0 : pNewSlot->nMasterSlotId = 0;
568 0 : pNewSlot->nValue = 0;
569 0 : pNewSlot->fnExec = SFX_STUB_PTR(SfxShell,VerbExec);
570 0 : pNewSlot->fnState = SFX_STUB_PTR(SfxShell,VerbState);
571 0 : pNewSlot->pType = 0; // HACK(SFX_TYPE(SfxVoidItem)) ???
572 0 : pNewSlot->pLinkedSlot = 0;
573 0 : pNewSlot->nArgDefCount = 0;
574 0 : pNewSlot->pFirstArgDef = 0;
575 0 : pNewSlot->pUnoName = 0;
576 :
577 0 : if (!pImp->aSlotArr.empty())
578 : {
579 0 : SfxSlot& rSlot = pImp->aSlotArr[0];
580 0 : pNewSlot->pNextSlot = rSlot.pNextSlot;
581 0 : rSlot.pNextSlot = pNewSlot;
582 : }
583 : else
584 0 : pNewSlot->pNextSlot = pNewSlot;
585 :
586 0 : pImp->aSlotArr.insert(pImp->aSlotArr.begin() + (sal_uInt16) n, pNewSlot);
587 : }
588 :
589 988 : pImp->aVerbList = aVerbs;
590 :
591 988 : if (pViewSh)
592 : {
593 : // The status of SID_OBJECT is collected in the controller directly on
594 : // the Shell, it is thus enough to encourage a new status update
595 : SfxBindings *pBindings = pViewSh->GetViewFrame()->GetDispatcher()->
596 988 : GetBindings();
597 988 : pBindings->Invalidate( SID_OBJECT, true, true );
598 : }
599 : }
600 :
601 14 : const com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor >& SfxShell::GetVerbs() const
602 : {
603 14 : return pImp->aVerbList;
604 : }
605 :
606 0 : void SfxShell::VerbExec(SfxRequest& rReq)
607 : {
608 0 : sal_uInt16 nId = rReq.GetSlot();
609 0 : SfxViewShell *pViewShell = GetViewShell();
610 0 : if ( pViewShell )
611 : {
612 0 : bool bReadOnly = pViewShell->GetObjectShell()->IsReadOnly();
613 0 : com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > aList = pViewShell->GetVerbs();
614 0 : for (sal_Int32 n=0, nVerb=0; n<aList.getLength(); n++)
615 : {
616 : // check for ReadOnly verbs
617 0 : if ( bReadOnly && !(aList[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_NEVERDIRTIES) )
618 0 : continue;
619 :
620 : // check for verbs that shouldn't appear in the menu
621 0 : if ( !(aList[n].VerbAttributes & embed::VerbAttributes::MS_VERBATTR_ONCONTAINERMENU) )
622 0 : continue;
623 :
624 0 : if (nId == SID_VERB_START + nVerb++)
625 : {
626 0 : pViewShell->DoVerb(aList[n].VerbID);
627 0 : rReq.Done();
628 0 : return;
629 : }
630 0 : }
631 : }
632 : }
633 :
634 0 : void SfxShell::VerbState(SfxItemSet& )
635 : {
636 0 : }
637 :
638 0 : const SfxSlot* SfxShell::GetVerbSlot_Impl(sal_uInt16 nId) const
639 : {
640 0 : com::sun::star::uno::Sequence < com::sun::star::embed::VerbDescriptor > rList = pImp->aVerbList;
641 :
642 : DBG_ASSERT(nId >= SID_VERB_START && nId <= SID_VERB_END,"Wrong VerbId!");
643 0 : sal_uInt16 nIndex = nId - SID_VERB_START;
644 : DBG_ASSERT(nIndex < rList.getLength(),"Wrong VerbId!");
645 :
646 0 : if (nIndex < rList.getLength())
647 0 : return &pImp->aSlotArr[nIndex];
648 : else
649 0 : return 0;
650 : }
651 :
652 18288 : void SfxShell::SetHelpId(sal_uIntPtr nId)
653 : {
654 18288 : pImp->nHelpId = nId;
655 18288 : }
656 :
657 94 : sal_uIntPtr SfxShell::GetHelpId() const
658 : {
659 94 : return pImp->nHelpId;
660 : }
661 :
662 1396 : SfxObjectShell* SfxShell::GetObjectShell()
663 : {
664 1396 : if ( GetViewShell() )
665 1396 : return GetViewShell()->GetViewFrame()->GetObjectShell();
666 : else
667 0 : return NULL;
668 : }
669 :
670 0 : bool SfxShell::HasUIFeature( sal_uInt32 )
671 : {
672 0 : return false;
673 : }
674 :
675 994 : long DispatcherUpdate_Impl( void*, void* pArg )
676 : {
677 994 : ((SfxDispatcher*) pArg)->Update_Impl( true );
678 994 : ((SfxDispatcher*) pArg)->GetBindings()->InvalidateAll(false);
679 994 : return 0;
680 : }
681 :
682 5958 : void SfxShell::UIFeatureChanged()
683 : {
684 5958 : SfxViewFrame *pFrame = GetFrame();
685 5958 : if ( pFrame && pFrame->IsVisible() )
686 : {
687 : // Also force an update, if dispatcher is already updated otherwise
688 : // something my get stuck in the bunkered tools. Asynchronous call to
689 : // prevent recursion.
690 4880 : if ( !pImp->pUpdater )
691 4602 : pImp->pUpdater = new svtools::AsynchronLink( Link( this, DispatcherUpdate_Impl ) );
692 :
693 : // Multiple views allowed
694 4880 : pImp->pUpdater->Call( pFrame->GetDispatcher(), true );
695 : }
696 5958 : }
697 :
698 111347 : void SfxShell::SetDisableFlags( sal_uIntPtr nFlags )
699 : {
700 111347 : pImp->nDisableFlags = nFlags;
701 111347 : }
702 :
703 105766 : sal_uIntPtr SfxShell::GetDisableFlags() const
704 : {
705 105766 : return pImp->nDisableFlags;
706 : }
707 :
708 0 : SfxItemSet* SfxShell::CreateItemSet( sal_uInt16 )
709 : {
710 0 : return NULL;
711 : }
712 :
713 0 : void SfxShell::ApplyItemSet( sal_uInt16, const SfxItemSet& )
714 : {
715 0 : }
716 :
717 6588 : void SfxShell::SetContextName (const ::rtl::OUString& rsContextName)
718 : {
719 6588 : pImp->maContextChangeBroadcaster.Initialize(rsContextName);
720 6588 : }
721 :
722 25094 : void SfxShell::SetViewShell_Impl( SfxViewShell* pView )
723 : {
724 25094 : pImp->pViewSh = pView;
725 25094 : }
726 :
727 71562 : void SfxShell::BroadcastContextForActivation (const bool bIsActivated)
728 : {
729 71562 : SfxViewFrame* pViewFrame = GetFrame();
730 71562 : if (pViewFrame != NULL)
731 : {
732 54273 : if (bIsActivated)
733 32282 : pImp->maContextChangeBroadcaster.Activate(pViewFrame->GetFrame().GetFrameInterface());
734 : else
735 21991 : pImp->maContextChangeBroadcaster.Deactivate(pViewFrame->GetFrame().GetFrameInterface());
736 : }
737 71562 : }
738 :
739 1776 : bool SfxShell::SetContextBroadcasterEnabled (const bool bIsEnabled)
740 : {
741 1776 : return pImp->maContextChangeBroadcaster.SetBroadcasterEnabled(bIsEnabled);
742 951 : }
743 :
744 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|