LCOV - code coverage report
Current view: top level - svx/source/mnuctrls - SmartTagCtl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 85 2.4 %
Date: 2014-11-03 Functions: 3 12 25.0 %
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             : 
      21             : #include <svx/SmartTagCtl.hxx>
      22             : #include <com/sun/star/smarttags/XSmartTagAction.hpp>
      23             : #include <com/sun/star/container/XStringKeyMap.hpp>
      24             : #include <svtools/stdmenu.hxx>
      25             : #include <svl/eitem.hxx>
      26             : #include <sfx2/dispatch.hxx>
      27             : #include <svx/svxids.hrc>
      28             : 
      29             : #include <svx/SmartTagItem.hxx>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::uno;
      33             : 
      34          88 : SFX_IMPL_MENU_CONTROL(SvxSmartTagsControl, SvxSmartTagItem);
      35             : 
      36             : 
      37             : 
      38           0 : SvxSmartTagsControl::SvxSmartTagsControl
      39             : (
      40             :     sal_uInt16          _nId,
      41             :     Menu&           rMenu,
      42             :     SfxBindings&    /*rBindings*/
      43             : ) :
      44           0 :     mpMenu  ( new PopupMenu ),
      45             :     mrParent    ( rMenu ),
      46           0 :     mpSmartTagItem( 0 )
      47             : {
      48           0 :     rMenu.SetPopupMenu( _nId, mpMenu );
      49           0 : }
      50             : 
      51             : 
      52             : 
      53             : const sal_uInt16 MN_ST_INSERT_START = 500;
      54             : 
      55           0 : void SvxSmartTagsControl::FillMenu()
      56             : {
      57           0 :     if ( !mpSmartTagItem )
      58           0 :         return;
      59             : 
      60           0 :     sal_uInt16 nMenuPos = 0;
      61           0 :     sal_uInt16 nSubMenuPos = 0;
      62           0 :     sal_uInt16 nMenuId = 1;
      63           0 :     sal_uInt16 nSubMenuId = MN_ST_INSERT_START;
      64             : 
      65           0 :     const Sequence < Sequence< Reference< smarttags::XSmartTagAction > > >& rActionComponentsSequence = mpSmartTagItem->GetActionComponentsSequence();
      66           0 :     const Sequence < Sequence< sal_Int32 > >& rActionIndicesSequence = mpSmartTagItem->GetActionIndicesSequence();
      67           0 :     const Sequence< Reference< container::XStringKeyMap > >& rStringKeyMaps = mpSmartTagItem->GetStringKeyMaps();
      68           0 :     const lang::Locale& rLocale = mpSmartTagItem->GetLocale();
      69           0 :     const OUString aApplicationName = mpSmartTagItem->GetApplicationName();
      70           0 :     const OUString aRangeText = mpSmartTagItem->GetRangeText();
      71           0 :     const Reference<text::XTextRange>& xTextRange = mpSmartTagItem->GetTextRange();
      72           0 :     const Reference<frame::XController>& xController = mpSmartTagItem->GetController();
      73             : 
      74           0 :     for ( sal_uInt16 j = 0; j < rActionComponentsSequence.getLength(); ++j )
      75             :     {
      76           0 :         Reference< container::XStringKeyMap > xSmartTagProperties = rStringKeyMaps[j];
      77             : 
      78             :         // Get all actions references associated with the current smart tag type:
      79           0 :         const Sequence< Reference< smarttags::XSmartTagAction > >& rActionComponents = rActionComponentsSequence[j];
      80           0 :         const Sequence< sal_Int32 >& rActionIndices = rActionIndicesSequence[j];
      81             : 
      82           0 :         if ( 0 == rActionComponents.getLength() || 0 == rActionIndices.getLength() )
      83           0 :             continue;
      84             : 
      85             :         // Ask first entry for the smart tag type caption:
      86           0 :         Reference< smarttags::XSmartTagAction > xAction = rActionComponents[0];
      87             : 
      88           0 :         if ( !xAction.is() )
      89           0 :             continue;
      90             : 
      91           0 :         const sal_Int32 nSmartTagIndex = rActionIndices[0];
      92           0 :         const OUString aSmartTagType = xAction->getSmartTagName( nSmartTagIndex );
      93           0 :         const OUString aSmartTagCaption = xAction->getSmartTagCaption( nSmartTagIndex, rLocale);
      94             : 
      95             :         // no sub-menus if there's only one smart tag type listed:
      96           0 :         PopupMenu* pSbMenu = mpMenu;
      97           0 :         if ( 1 < rActionComponentsSequence.getLength() )
      98             :         {
      99           0 :             mpMenu->InsertItem(nMenuId, aSmartTagCaption, MenuItemBits::NONE, OString(), nMenuPos++);
     100           0 :             pSbMenu = new PopupMenu;
     101           0 :             mpMenu->SetPopupMenu( nMenuId++, pSbMenu );
     102             :         }
     103           0 :         pSbMenu->SetSelectHdl( LINK( this, SvxSmartTagsControl, MenuSelect ) );
     104             : 
     105             :         // sub-menu starts with smart tag caption and separator
     106           0 :         const OUString aSmartTagCaption2 = aSmartTagCaption + ": " + aRangeText;
     107           0 :         nSubMenuPos = 0;
     108           0 :         pSbMenu->InsertItem(nMenuId++, aSmartTagCaption2, MenuItemBits::NOSELECT, OString(), nSubMenuPos++);
     109           0 :         pSbMenu->InsertSeparator(OString(), nSubMenuPos++);
     110             : 
     111             :         // Add subitem for every action reference for the current smart tag type:
     112           0 :         for ( sal_uInt16 i = 0; i < rActionComponents.getLength(); ++i )
     113             :         {
     114           0 :             xAction = rActionComponents[i];
     115             : 
     116           0 :             for ( sal_Int32 k = 0; k < xAction->getActionCount( aSmartTagType, xController, xSmartTagProperties ); ++k )
     117             :             {
     118           0 :                 const sal_uInt32 nActionID = xAction->getActionID( aSmartTagType, k, xController );
     119           0 :                 OUString aActionCaption = xAction->getActionCaptionFromID( nActionID,
     120             :                                                                                 aApplicationName,
     121             :                                                                                 rLocale,
     122             :                                                                                 xSmartTagProperties,
     123             :                                                                                 aRangeText,
     124             :                                                                                 OUString(),
     125             :                                                                                 xController,
     126           0 :                                                                                 xTextRange );
     127             : 
     128           0 :                 pSbMenu->InsertItem( nSubMenuId++, aActionCaption, MenuItemBits::NONE, OString(), nSubMenuPos++ );
     129           0 :                 InvokeAction aEntry( xAction, xSmartTagProperties, nActionID );
     130           0 :                 maInvokeActions.push_back( aEntry );
     131           0 :             }
     132             :         }
     133           0 :     }
     134             : }
     135             : 
     136             : 
     137             : 
     138           0 : void SvxSmartTagsControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
     139             : 
     140             : {
     141           0 :     mrParent.EnableItem( GetId(), SfxItemState::DISABLED != eState );
     142             : 
     143           0 :     if ( SfxItemState::DEFAULT == eState )
     144             :     {
     145           0 :         const SvxSmartTagItem* pSmartTagItem = PTR_CAST( SvxSmartTagItem, pState );
     146           0 :         if ( 0 != pSmartTagItem )
     147             :         {
     148           0 :             delete mpSmartTagItem;
     149           0 :             mpSmartTagItem = new SvxSmartTagItem( *pSmartTagItem );
     150           0 :             FillMenu();
     151             :         }
     152             :     }
     153           0 : }
     154             : 
     155             : 
     156             : 
     157           0 : IMPL_LINK_INLINE_START( SvxSmartTagsControl, MenuSelect, PopupMenu *, pMen )
     158             : {
     159           0 :     if ( !mpSmartTagItem )
     160           0 :         return 0;
     161             : 
     162           0 :     sal_uInt16 nMyId = pMen->GetCurItemId();
     163             : 
     164           0 :     if ( nMyId < MN_ST_INSERT_START) return 0;
     165           0 :     nMyId -= MN_ST_INSERT_START;
     166             : 
     167             :     // compute smarttag lib index and action index
     168           0 :     Reference< smarttags::XSmartTagAction > xSmartTagAction = maInvokeActions[ nMyId ].mxAction;
     169             : 
     170             :     // execute action
     171           0 :     if ( xSmartTagAction.is() )
     172             :     {
     173           0 :         xSmartTagAction->invokeAction( maInvokeActions[ nMyId ].mnActionID,
     174             :                                        mpSmartTagItem->GetApplicationName(),
     175           0 :                                        mpSmartTagItem->GetController(),
     176           0 :                                        mpSmartTagItem->GetTextRange(),
     177           0 :                                        maInvokeActions[ nMyId ].mxSmartTagProperties,
     178             :                                        mpSmartTagItem->GetRangeText(),
     179             :                                        OUString(),
     180           0 :                                        mpSmartTagItem->GetLocale() );
     181             :     }
     182             : 
     183             :     // ohne dispatcher!!!
     184             :     // GetBindings().Execute( GetId(), SfxCallMode::RECORD,meine beiden items, 0L );*/
     185             :     //SfxBoolItem aBool(SID_OPEN_SMARTTAGOPTIONS, sal_True);
     186             :     //GetBindings().GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SfxCallMode::ASYNCHRON, &aBool, 0L );
     187             : 
     188           0 :     return 0;
     189             : }
     190           0 : IMPL_LINK_INLINE_END( SvxSmartTagsControl, MenuSelect, PopupMenu *, pMen )
     191             : 
     192             : 
     193             : 
     194           0 : SvxSmartTagsControl::~SvxSmartTagsControl()
     195             : {
     196           0 :     delete mpSmartTagItem;
     197           0 :     delete mpMenu;
     198           0 : }
     199             : 
     200             : 
     201             : 
     202           0 : PopupMenu* SvxSmartTagsControl::GetPopup() const
     203             : {
     204           0 :     return mpMenu;
     205         594 : }
     206             : 
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10