LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/control - ctrlitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 65 72.3 %
Date: 2012-12-27 Functions: 12 18 66.7 %
Legend: Lines: hit not hit

          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 <svl/itempool.hxx>
      21             : 
      22             : #include <sfx2/ctrlitem.hxx>
      23             : #include <sfx2/bindings.hxx>
      24             : #include <sfx2/dispatch.hxx>
      25             : #include <sfx2/msgpool.hxx>
      26             : #include "statcach.hxx"
      27             : #include <sfx2/viewfrm.hxx>
      28             : 
      29             : //====================================================================
      30             : 
      31             : DBG_NAME(SfxControllerItem);
      32             : 
      33             : //--------------------------------------------------------------------
      34             : #ifdef DBG_UTIL
      35             : 
      36             : void SfxControllerItem::CheckConfigure_Impl( sal_uIntPtr nType )
      37             : {
      38             :     // Real Slot? (i.e. no Separator etc.)
      39             :     if ( !nId )
      40             :         return;
      41             : 
      42             :     // is the ID configurable at all in 'nType'?
      43             :     const SfxSlot *pSlot = SFX_SLOTPOOL().GetSlot(nId);
      44             :     DBG_ASSERTWARNING( pSlot, "SfxControllerItem: binding not existing slot" );
      45             :     if ( pSlot && !pSlot->IsMode(nType) )
      46             :     {
      47             :         DBG_WARNING( "SfxControllerItem: slot without ...Config-flag" );
      48             :         DbgOutf( "SfxControllerItem: Config-flag missing at SID %5d",
      49             :                  pSlot->GetSlotId() );
      50             :     }
      51             : }
      52             : 
      53             : #endif
      54             : 
      55             : //--------------------------------------------------------------------
      56             : // returns the next registered SfxControllerItem with the same id
      57             : 
      58       16724 : SfxControllerItem* SfxControllerItem::GetItemLink()
      59             : {
      60             :     DBG_CHKTHIS(SfxControllerItem, 0);
      61       16724 :     return pNext == this ? 0 : pNext;
      62             : }
      63             : 
      64             : //--------------------------------------------------------------------
      65             : // returns sal_True if this binding is really bound to a function
      66             : 
      67        7777 : sal_Bool SfxControllerItem::IsBound() const
      68             : {
      69             :     DBG_CHKTHIS(SfxControllerItem, 0);
      70        7777 :     return pNext != this;
      71             : }
      72             : 
      73             : //====================================================================
      74             : // registeres with the id at the bindings
      75             : 
      76        4728 : void SfxControllerItem::Bind( sal_uInt16 nNewId, SfxBindings *pBindinx )
      77             : {
      78             :     DBG_CHKTHIS(SfxControllerItem, 0);
      79             :     DBG_ASSERT(pBindings || pBindinx, "No Bindings");
      80             : 
      81        4728 :     if ( IsBound() ) {
      82             :         DBG_ASSERT(pBindings, "No Bindings");
      83           0 :         pBindings->Release(*this);
      84             :     }
      85             : 
      86        4728 :     nId = nNewId;
      87        4728 :     pNext = 0;
      88             : 
      89        4728 :     if (pBindinx)
      90        4728 :         pBindings = pBindinx;
      91        4728 :     pBindings->Register(*this);
      92        4728 : }
      93             : 
      94        1635 : void SfxControllerItem::BindInternal_Impl( sal_uInt16 nNewId, SfxBindings *pBindinx )
      95             : {
      96             :     DBG_CHKTHIS(SfxControllerItem, 0);
      97             :     DBG_ASSERT(pBindings || pBindinx, "No Bindings");
      98             : 
      99        1635 :     if ( IsBound() ) {
     100             :         DBG_ASSERT(pBindings, "No Bindings");
     101           0 :         pBindings->Release(*this);
     102             :     }
     103             : 
     104        1635 :     nId = nNewId;
     105        1635 :     pNext = 0;
     106             : 
     107        1635 :     if (pBindinx)
     108        1635 :         pBindings = pBindinx;
     109        1635 :     pBindings->RegisterInternal_Impl(*this);
     110        1635 : }
     111             : 
     112             : 
     113             : //====================================================================
     114             : 
     115        9515 : void SfxControllerItem::UnBind()
     116             : 
     117             : /*  [Description]
     118             : 
     119             :     Unbinds the connection of this SfxControllerItems with the SfxBindings
     120             :     instance with which it to time is bound. From this time on it does not
     121             :     receive any status notifications (<SfxControllerItem::StateChented()>)
     122             :     anymore.
     123             : 
     124             :     [Cross-reference]
     125             : 
     126             :     <SfxControllerItem::ReBind()>
     127             :     <SfxControllerItem::ClearCache()>
     128             : */
     129             : {
     130             :     DBG_CHKTHIS(SfxControllerItem, 0);
     131             :     DBG_ASSERT(pBindings, "No Bindings");
     132             :     DBG_ASSERT( IsBound(), "unbindings unbound SfxControllerItem" );
     133             : 
     134        9515 :     pBindings->Release(*this);
     135        9515 :     pNext = this;
     136        9515 : }
     137             : 
     138             : //====================================================================
     139             : 
     140        4720 : void SfxControllerItem::ReBind()
     141             : 
     142             : /*  [Description]
     143             : 
     144             :     Binds this SfxControllerItem with the SfxBindings instance again,
     145             :     with which it was last bound. From this time on it does receive status
     146             :     notifications (<SfxControllerItem::StateChented()>) again.
     147             : 
     148             :     [Cross-reference]
     149             : 
     150             :     <SfxControllerItem::UnBind()>
     151             :     <SfxControllerItem::ClearCache()>
     152             : */
     153             : 
     154             : {
     155             : DBG_CHKTHIS(SfxControllerItem, 0);
     156             :     DBG_ASSERT(pBindings, "No Bindings");
     157             :     DBG_ASSERT( !IsBound(), "bindings rebound SfxControllerItem" );
     158             : 
     159        4720 :     pBindings->Register(*this);
     160        4720 : }
     161             : 
     162             : //--------------------------------------------------------------------
     163             : 
     164           0 : void SfxControllerItem::ClearCache()
     165             : 
     166             : /*  [Description]
     167             : 
     168             :     Clears the cache status for this SfxControllerItem. That is by the next
     169             :     status update is the <SfxPoolItem> sent in any case, even if the same was
     170             :     sent before. This is needed if a controller can be switched on and note
     171             :     that status themselves.
     172             : 
     173             :     [Example]
     174             : 
     175             :     The combined controller for adjusting the surface type and the concrete
     176             :     expression (blue color, or hatching X) can be changed in type, but is then
     177             :     notified of the next selection again, even if it the same data.
     178             : 
     179             :     [Cross-reference]
     180             : 
     181             :     <SfxControllerItem::UnBind()>
     182             :     <SfxControllerItem::ReBind()>
     183             : */
     184             : 
     185             : 
     186             : {
     187             :     DBG_CHKTHIS(SfxControllerItem, 0);
     188             :     DBG_ASSERT(pBindings, "No Bindings");
     189             : 
     190           0 :     pBindings->ClearCache_Impl( GetId() );
     191           0 : }
     192             : 
     193             : //--------------------------------------------------------------------
     194             : // replaces the successor in the list of bindings of the same id
     195             : 
     196       11808 : SfxControllerItem* SfxControllerItem::ChangeItemLink( SfxControllerItem* pNewLink )
     197             : {
     198             :     DBG_CHKTHIS(SfxControllerItem, 0);
     199       11808 :     SfxControllerItem* pOldLink = pNext;
     200       11808 :     pNext = pNewLink;
     201       11808 :     return pOldLink == this ? 0 : pOldLink;
     202             : }
     203             : 
     204             : //--------------------------------------------------------------------
     205             : // changes the id of unbound functions (e.g. for sub-menu-ids)
     206             : 
     207        1635 : void SfxControllerItem::SetId( sal_uInt16 nItemId )
     208             : {
     209             :     DBG_CHKTHIS(SfxControllerItem, 0);
     210             :     DBG_ASSERT( !IsBound(), "changing id of bound binding" );
     211        1635 :     nId = nItemId;
     212        1635 : }
     213             : 
     214             : //--------------------------------------------------------------------
     215             : 
     216             : // creates a atomic item for a controller without registration.
     217             : 
     218        1635 : SfxControllerItem::SfxControllerItem():
     219             :     nId(0),
     220             :     pNext(this),
     221        1635 :     pBindings(0)
     222             : {
     223             :     DBG_CTOR(SfxControllerItem, 0);
     224        1635 : }
     225             : 
     226             : //--------------------------------------------------------------------
     227             : // creates a representation of the function nId and registeres it
     228             : 
     229        4728 : SfxControllerItem::SfxControllerItem( sal_uInt16 nID, SfxBindings &rBindings ):
     230             :     nId(nID),
     231             :     pNext(this),
     232        4728 :     pBindings(&rBindings)
     233             : {
     234             :     DBG_CTOR(SfxControllerItem, 0);
     235        4728 :     Bind(nId, &rBindings);
     236        4728 : }
     237             : 
     238             : //--------------------------------------------------------------------
     239             : // unregisteres the item in the bindings
     240             : 
     241        1339 : SfxControllerItem::~SfxControllerItem()
     242             : {
     243        1339 :     if ( IsBound() )
     244           4 :         pBindings->Release(*this);
     245             :     DBG_DTOR(SfxControllerItem, 0);
     246        1339 : }
     247             : 
     248             : //--------------------------------------------------------------------
     249             : 
     250           0 : void SfxControllerItem::StateChanged
     251             : (
     252             :     sal_uInt16,          // <SID> of the triggering slot
     253             :     SfxItemState,       // <SfxItemState> of 'pState'
     254             :     const SfxPoolItem*  // Slot-Status, NULL or IsInvalidItem()
     255             : )
     256             : 
     257             : /*  [Description]
     258             : 
     259             :     This virtual method is called by the SFx to inform the <SfxControllerItem>s
     260             :     is about that state of the slots 'NSID' has changed. The new value and the
     261             :     value determined by this status is given as 'pState' or 'eState'.
     262             : 
     263             :     The status of a slot may change, for example when the MDI window is
     264             :     switched or when the slot was invalidated explicitly with
     265             :     <SfxBindings::Invalidate()>.
     266             : 
     267             :     Achtung! Die Methode wird nicht gerufen, wenn der Slot ung"ultig wurde,
     268             :     danach jedoch wieder denselben Wert angenommen hat.
     269             : 
     270             :     Beware! The method is not called when the slot is invalid, however
     271             :     has again assumed the same value.
     272             : 
     273             :     This base class need not be called, further interim steps however
     274             :     (eg <SfxToolboxControl> ) should be called.
     275             : */
     276             : 
     277             : {
     278             :     DBG_CHKTHIS(SfxControllerItem, 0);
     279           0 : }
     280             : 
     281             : //--------------------------------------------------------------------
     282             : 
     283        4720 : void SfxControllerItem::DeleteFloatingWindow()
     284             : {
     285             :     DBG_CHKTHIS(SfxControllerItem, 0);
     286        4720 : }
     287             : 
     288             : //--------------------------------------------------------------------
     289             : 
     290           0 : void SfxStatusForwarder::StateChanged
     291             : (
     292             :     sal_uInt16          nSID,    // <SID> of the triggering slot
     293             :     SfxItemState        eState,  // <SfxItemState> of 'pState'
     294             :     const SfxPoolItem*  pState   // Slot-Status, NULL or IsInvalidItem()
     295             : )
     296             : 
     297             : {
     298           0 :     pMaster->StateChanged( nSID, eState, pState );
     299           0 : }
     300             : 
     301             : //--------------------------------------------------------------------
     302             : 
     303           0 : SfxStatusForwarder::SfxStatusForwarder(
     304             :             sal_uInt16              nSlotId,
     305             :             SfxControllerItem&  rMaster ):
     306           0 :     SfxControllerItem( nSlotId, rMaster.GetBindings() ),
     307           0 :     pMaster( &rMaster )
     308             : {
     309           0 : }
     310             : 
     311             : //--------------------------------------------------------------------
     312             : 
     313           0 : SfxItemState SfxControllerItem::GetItemState
     314             : (
     315             :     const SfxPoolItem* pState   /*  Pointer to  <SfxPoolItem>, which
     316             :                                     Status should be queried. */
     317             : )
     318             : 
     319             : /*  [Description]
     320             : 
     321             :     Static method to determine the status of the SfxPoolItem-Pointers, to be
     322             :     used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>
     323             : 
     324             :     [Return value]
     325             : 
     326             :     SfxItemState        SFX_ITEM_UNKNOWN
     327             :                         Enabled, but no further status information available.
     328             :                         Typical for <Slot>s, which anyway are sometimes
     329             :                         disabled, but otherwise do not change their appearance.
     330             : 
     331             :                         SFX_ITEM_DISABLED
     332             :                         Disabled and no further status information available.
     333             :                         All other values that may appear should be reset to
     334             :                         default.
     335             : 
     336             :                         SFX_ITEM_DONTCARE
     337             :                         Enabled but there were only ambiguous values available
     338             :                         (i.e. non that can be queried).
     339             : 
     340             :                         SFX_ITEM_AVAILABLE
     341             :                         Enabled and with available values, which are queried
     342             :                         by 'pState'. The Type is thus clearly defined in the
     343             :                         entire Program and specified through the Slot.
     344             : */
     345             : 
     346             : {
     347             :     return !pState
     348             :                 ? SFX_ITEM_DISABLED
     349           0 :                 : IsInvalidItem(pState)
     350             :                     ? SFX_ITEM_DONTCARE
     351           0 :                     : pState->ISA(SfxVoidItem) && !pState->Which()
     352             :                         ? SFX_ITEM_UNKNOWN
     353           0 :                         : SFX_ITEM_AVAILABLE;
     354             : }
     355             : 
     356             : //------------------------------------------------------------------------
     357             : 
     358             : #ifdef _MSC_VER
     359             : #pragma optimize("g",off)
     360             : #endif
     361             : 
     362             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10