1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // SMARTTAGS 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 31*cdf0e10cSrcweir #include "precompiled_sw.hxx" 32*cdf0e10cSrcweir #include <stmenu.hxx> 33*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 34*cdf0e10cSrcweir #include <svl/eitem.hxx> 35*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <SwSmartTagMgr.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifndef _STMENU_HRC 40*cdf0e10cSrcweir #include <stmenu.hrc> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir #ifndef _VIEW_HXX 43*cdf0e10cSrcweir #include <view.hxx> 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir #include <breakit.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #define C2U(cChar) rtl::OUString::createFromAscii(cChar) 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::com::sun::star; 50*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir SwSmartTagPopup::SwSmartTagPopup( SwView* pSwView, 53*cdf0e10cSrcweir Sequence< rtl::OUString >& rSmartTagTypes, 54*cdf0e10cSrcweir Sequence< Reference< container::XStringKeyMap > >& rStringKeyMaps, 55*cdf0e10cSrcweir Reference< text::XTextRange > xTextRange ) : 56*cdf0e10cSrcweir PopupMenu( SW_RES(MN_SMARTTAG_POPUP) ), 57*cdf0e10cSrcweir mpSwView ( pSwView ), 58*cdf0e10cSrcweir mxTextRange( xTextRange ) 59*cdf0e10cSrcweir { 60*cdf0e10cSrcweir //CreateAutoMnemonics(); 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir Reference <frame::XController> xController = mpSwView->GetController(); 63*cdf0e10cSrcweir const lang::Locale aLocale( SW_BREAKITER()->GetLocale( (LanguageType)GetAppLanguage() ) ); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir sal_uInt16 nMenuPos = 0; 66*cdf0e10cSrcweir sal_uInt16 nSubMenuPos = 0; 67*cdf0e10cSrcweir sal_uInt16 nMenuId = 1; 68*cdf0e10cSrcweir sal_uInt16 nSubMenuId = MN_ST_INSERT_START; 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir const rtl::OUString aRangeText = mxTextRange->getString(); 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get(); 73*cdf0e10cSrcweir const rtl::OUString aApplicationName( rSmartTagMgr.GetApplicationName() ); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir Sequence < Sequence< Reference< smarttags::XSmartTagAction > > > aActionComponentsSequence; 76*cdf0e10cSrcweir Sequence < Sequence< sal_Int32 > > aActionIndicesSequence; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir rSmartTagMgr.GetActionSequences( rSmartTagTypes, 79*cdf0e10cSrcweir aActionComponentsSequence, 80*cdf0e10cSrcweir aActionIndicesSequence ); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir InsertSeparator(0); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir for ( sal_uInt16 j = 0; j < aActionComponentsSequence.getLength(); ++j ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir Reference< container::XStringKeyMap > xSmartTagProperties = rStringKeyMaps[j]; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // Get all actions references associated with the current smart tag type: 89*cdf0e10cSrcweir const Sequence< Reference< smarttags::XSmartTagAction > >& rActionComponents = aActionComponentsSequence[j]; 90*cdf0e10cSrcweir const Sequence< sal_Int32 >& rActionIndices = aActionIndicesSequence[j]; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir if ( 0 == rActionComponents.getLength() || 0 == rActionIndices.getLength() ) 93*cdf0e10cSrcweir continue; 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir // Ask first entry for the smart tag type caption: 96*cdf0e10cSrcweir Reference< smarttags::XSmartTagAction > xAction = rActionComponents[0]; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir if ( !xAction.is() ) 99*cdf0e10cSrcweir continue; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir const sal_Int32 nSmartTagIndex = rActionIndices[0]; 102*cdf0e10cSrcweir const rtl::OUString aSmartTagType = xAction->getSmartTagName( nSmartTagIndex ); 103*cdf0e10cSrcweir const rtl::OUString aSmartTagCaption = xAction->getSmartTagCaption( nSmartTagIndex, aLocale ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // no sub-menues if there's only one smart tag type listed: 106*cdf0e10cSrcweir PopupMenu* pSbMenu = this; 107*cdf0e10cSrcweir if ( 1 < aActionComponentsSequence.getLength() ) 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir InsertItem( nMenuId, aSmartTagCaption, 0, nMenuPos++); 110*cdf0e10cSrcweir pSbMenu = new PopupMenu; 111*cdf0e10cSrcweir SetPopupMenu( nMenuId++, pSbMenu ); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // sub-menu starts with smart tag caption and separator 115*cdf0e10cSrcweir const rtl::OUString aSmartTagCaption2 = aSmartTagCaption + C2U(": ") + aRangeText; 116*cdf0e10cSrcweir nSubMenuPos = 0; 117*cdf0e10cSrcweir pSbMenu->InsertItem( nMenuId++, aSmartTagCaption2, MIB_NOSELECT, nSubMenuPos++ ); 118*cdf0e10cSrcweir pSbMenu->InsertSeparator( nSubMenuPos++ ); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // Add subitem for every action reference for the current smart tag type: 121*cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rActionComponents.getLength(); ++i ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir xAction = rActionComponents[i]; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir for ( sal_Int32 k = 0; k < xAction->getActionCount( aSmartTagType, xController ); ++k ) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir const sal_uInt32 nActionID = xAction->getActionID( aSmartTagType, k, xController ); 128*cdf0e10cSrcweir rtl::OUString aActionCaption = xAction->getActionCaptionFromID( nActionID, 129*cdf0e10cSrcweir aApplicationName, 130*cdf0e10cSrcweir aLocale, 131*cdf0e10cSrcweir xSmartTagProperties, 132*cdf0e10cSrcweir aRangeText, 133*cdf0e10cSrcweir rtl::OUString(), 134*cdf0e10cSrcweir xController, 135*cdf0e10cSrcweir mxTextRange ); 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir pSbMenu->InsertItem( nSubMenuId++, aActionCaption, 0, nSubMenuPos++ ); 138*cdf0e10cSrcweir InvokeAction aEntry( xAction, xSmartTagProperties, nActionID ); 139*cdf0e10cSrcweir maInvokeActions.push_back( aEntry ); 140*cdf0e10cSrcweir } 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir } 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir /** Function: Execute 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir executes actions by calling the invoke function of the appropriate 148*cdf0e10cSrcweir smarttag library. 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir */ 151*cdf0e10cSrcweir sal_uInt16 SwSmartTagPopup::Execute( const Rectangle& rWordPos, Window* pWin ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir sal_uInt16 nId = PopupMenu::Execute(pWin, pWin->LogicToPixel(rWordPos)); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir if ( nId == MN_SMARTTAG_OPTIONS ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir SfxBoolItem aBool(SID_OPEN_SMARTTAGOPTIONS, sal_True); 158*cdf0e10cSrcweir mpSwView->GetViewFrame()->GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SFX_CALLMODE_ASYNCHRON, &aBool, 0L ); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir if ( nId < MN_ST_INSERT_START) return nId; 162*cdf0e10cSrcweir nId -= MN_ST_INSERT_START; 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir // compute smarttag lib index and action index 165*cdf0e10cSrcweir if ( nId < maInvokeActions.size() ) 166*cdf0e10cSrcweir { 167*cdf0e10cSrcweir Reference< smarttags::XSmartTagAction > xSmartTagAction = maInvokeActions[ nId ].mxAction; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // execute action 170*cdf0e10cSrcweir if ( xSmartTagAction.is() ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get(); 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir xSmartTagAction->invokeAction( maInvokeActions[ nId ].mnActionID, 175*cdf0e10cSrcweir rSmartTagMgr.GetApplicationName(), 176*cdf0e10cSrcweir mpSwView->GetController(), 177*cdf0e10cSrcweir mxTextRange, 178*cdf0e10cSrcweir maInvokeActions[ nId ].mxSmartTagProperties, 179*cdf0e10cSrcweir mxTextRange->getString(), 180*cdf0e10cSrcweir rtl::OUString(), 181*cdf0e10cSrcweir SW_BREAKITER()->GetLocale( (LanguageType)GetAppLanguage() ) ); 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir return nId; 186*cdf0e10cSrcweir } 187