LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/smartmenu - stmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 65 0.0 %
Date: 2012-12-27 Functions: 0 2 0.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             : // SMARTTAGS
      21             : 
      22             : #include <stmenu.hxx>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <svl/eitem.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : 
      27             : #include <SwSmartTagMgr.hxx>
      28             : 
      29             : #include <stmenu.hrc>
      30             : #include <view.hxx>
      31             : #include <breakit.hxx>
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36           0 : SwSmartTagPopup::SwSmartTagPopup( SwView* pSwView,
      37             :                                   Sequence< rtl::OUString >& rSmartTagTypes,
      38             :                                   Sequence< Reference< container::XStringKeyMap > >& rStringKeyMaps,
      39             :                                   Reference< text::XTextRange > xTextRange ) :
      40             :     PopupMenu( SW_RES(MN_SMARTTAG_POPUP) ),
      41             :     mpSwView ( pSwView ),
      42           0 :     mxTextRange( xTextRange )
      43             : {
      44           0 :     Reference <frame::XController> xController = mpSwView->GetController();
      45           0 :     const lang::Locale aLocale( SW_BREAKITER()->GetLocale( GetAppLanguageTag() ) );
      46             : 
      47           0 :     sal_uInt16 nMenuPos = 0;
      48           0 :     sal_uInt16 nSubMenuPos = 0;
      49           0 :     sal_uInt16 nMenuId = 1;
      50           0 :     sal_uInt16 nSubMenuId = MN_ST_INSERT_START;
      51             : 
      52           0 :     const rtl::OUString aRangeText = mxTextRange->getString();
      53             : 
      54           0 :     SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get();
      55           0 :     const rtl::OUString aApplicationName( rSmartTagMgr.GetApplicationName() );
      56             : 
      57           0 :     Sequence < Sequence< Reference< smarttags::XSmartTagAction > > > aActionComponentsSequence;
      58           0 :     Sequence < Sequence< sal_Int32 > > aActionIndicesSequence;
      59             : 
      60             :     rSmartTagMgr.GetActionSequences( rSmartTagTypes,
      61             :                                      aActionComponentsSequence,
      62           0 :                                      aActionIndicesSequence );
      63             : 
      64           0 :     InsertSeparator(0);
      65             : 
      66           0 :     for ( sal_uInt16 j = 0; j < aActionComponentsSequence.getLength(); ++j )
      67             :     {
      68           0 :         Reference< container::XStringKeyMap > xSmartTagProperties = rStringKeyMaps[j];
      69             : 
      70             :         // Get all actions references associated with the current smart tag type:
      71           0 :         const Sequence< Reference< smarttags::XSmartTagAction > >& rActionComponents = aActionComponentsSequence[j];
      72           0 :         const Sequence< sal_Int32 >& rActionIndices = aActionIndicesSequence[j];
      73             : 
      74           0 :         if ( 0 == rActionComponents.getLength() || 0 == rActionIndices.getLength() )
      75           0 :             continue;
      76             : 
      77             :         // Ask first entry for the smart tag type caption:
      78           0 :         Reference< smarttags::XSmartTagAction > xAction = rActionComponents[0];
      79             : 
      80           0 :         if ( !xAction.is() )
      81           0 :             continue;
      82             : 
      83           0 :         const sal_Int32 nSmartTagIndex = rActionIndices[0];
      84           0 :         const rtl::OUString aSmartTagType = xAction->getSmartTagName( nSmartTagIndex );
      85           0 :         const rtl::OUString aSmartTagCaption = xAction->getSmartTagCaption( nSmartTagIndex, aLocale );
      86             : 
      87             :         // no sub-menus if there's only one smart tag type listed:
      88           0 :         PopupMenu* pSbMenu = this;
      89           0 :         if ( 1 < aActionComponentsSequence.getLength() )
      90             :         {
      91           0 :             InsertItem( nMenuId, aSmartTagCaption, 0, nMenuPos++);
      92           0 :             pSbMenu = new PopupMenu;
      93           0 :             SetPopupMenu( nMenuId++, pSbMenu );
      94             :         }
      95             : 
      96             :         // sub-menu starts with smart tag caption and separator
      97           0 :         const rtl::OUString aSmartTagCaption2 = aSmartTagCaption + ": " + aRangeText;
      98           0 :         nSubMenuPos = 0;
      99           0 :         pSbMenu->InsertItem( nMenuId++, aSmartTagCaption2, MIB_NOSELECT, nSubMenuPos++ );
     100           0 :         pSbMenu->InsertSeparator( nSubMenuPos++ );
     101             : 
     102             :         // Add subitem for every action reference for the current smart tag type:
     103           0 :         for ( sal_uInt16 i = 0; i < rActionComponents.getLength(); ++i )
     104             :         {
     105           0 :             xAction = rActionComponents[i];
     106             : 
     107           0 :             for ( sal_Int32 k = 0; k < xAction->getActionCount( aSmartTagType, xController ); ++k )
     108             :             {
     109           0 :                 const sal_uInt32 nActionID = xAction->getActionID( aSmartTagType, k, xController  );
     110           0 :                 rtl::OUString aActionCaption = xAction->getActionCaptionFromID( nActionID,
     111             :                                                                                 aApplicationName,
     112             :                                                                                 aLocale,
     113             :                                                                                 xSmartTagProperties,
     114             :                                                                                 aRangeText,
     115             :                                                                                 rtl::OUString(),
     116             :                                                                                 xController,
     117           0 :                                                                                 mxTextRange );
     118             : 
     119           0 :                 pSbMenu->InsertItem( nSubMenuId++, aActionCaption, 0, nSubMenuPos++ );
     120           0 :                 InvokeAction aEntry( xAction, xSmartTagProperties, nActionID );
     121           0 :                 maInvokeActions.push_back( aEntry );
     122           0 :             }
     123             :         }
     124           0 :     }
     125           0 : }
     126             : 
     127             : /** Function: Execute
     128             : 
     129             :    executes actions by calling the invoke function of the appropriate
     130             :    smarttag library.
     131             : 
     132             : */
     133           0 : sal_uInt16 SwSmartTagPopup::Execute( const Rectangle& rWordPos, Window* pWin )
     134             : {
     135           0 :     sal_uInt16 nId = PopupMenu::Execute(pWin, pWin->LogicToPixel(rWordPos));
     136             : 
     137           0 :     if ( nId == MN_SMARTTAG_OPTIONS )
     138             :     {
     139           0 :         SfxBoolItem aBool(SID_OPEN_SMARTTAGOPTIONS, sal_True);
     140           0 :         mpSwView->GetViewFrame()->GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SFX_CALLMODE_ASYNCHRON, &aBool, 0L );
     141             :     }
     142             : 
     143           0 :     if ( nId < MN_ST_INSERT_START) return nId;
     144           0 :     nId -= MN_ST_INSERT_START;
     145             : 
     146             :     // compute smarttag lib index and action index
     147           0 :     if ( nId < maInvokeActions.size() )
     148             :     {
     149           0 :         Reference< smarttags::XSmartTagAction > xSmartTagAction = maInvokeActions[ nId ].mxAction;
     150             : 
     151             :         // execute action
     152           0 :         if ( xSmartTagAction.is() )
     153             :         {
     154           0 :             SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get();
     155             : 
     156           0 :             xSmartTagAction->invokeAction( maInvokeActions[ nId ].mnActionID,
     157             :                                            rSmartTagMgr.GetApplicationName(),
     158             :                                            mpSwView->GetController(),
     159             :                                            mxTextRange,
     160           0 :                                            maInvokeActions[ nId ].mxSmartTagProperties,
     161           0 :                                            mxTextRange->getString(),
     162             :                                            rtl::OUString(),
     163           0 :                                            SW_BREAKITER()->GetLocale( GetAppLanguageTag() )  );
     164           0 :         }
     165             :     }
     166             : 
     167           0 :     return nId;
     168             : }
     169             : 
     170             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10