1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // SMARTTAGS 25cdf0e10cSrcweir 26cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 27cdf0e10cSrcweir #include "precompiled_sw.hxx" 28cdf0e10cSrcweir #include <stmenu.hxx> 29cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 30cdf0e10cSrcweir #include <svl/eitem.hxx> 31cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <SwSmartTagMgr.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifndef _STMENU_HRC 36cdf0e10cSrcweir #include <stmenu.hrc> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #ifndef _VIEW_HXX 39cdf0e10cSrcweir #include <view.hxx> 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir #include <breakit.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir #define C2U(cChar) rtl::OUString::createFromAscii(cChar) 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::com::sun::star; 46cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47cdf0e10cSrcweir 48cdf0e10cSrcweir SwSmartTagPopup::SwSmartTagPopup( SwView* pSwView, 49cdf0e10cSrcweir Sequence< rtl::OUString >& rSmartTagTypes, 50cdf0e10cSrcweir Sequence< Reference< container::XStringKeyMap > >& rStringKeyMaps, 51cdf0e10cSrcweir Reference< text::XTextRange > xTextRange ) : 52cdf0e10cSrcweir PopupMenu( SW_RES(MN_SMARTTAG_POPUP) ), 53cdf0e10cSrcweir mpSwView ( pSwView ), 54cdf0e10cSrcweir mxTextRange( xTextRange ) 55cdf0e10cSrcweir { 56cdf0e10cSrcweir //CreateAutoMnemonics(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir Reference <frame::XController> xController = mpSwView->GetController(); 59cdf0e10cSrcweir const lang::Locale aLocale( SW_BREAKITER()->GetLocale( (LanguageType)GetAppLanguage() ) ); 60cdf0e10cSrcweir 61cdf0e10cSrcweir sal_uInt16 nMenuPos = 0; 62cdf0e10cSrcweir sal_uInt16 nSubMenuPos = 0; 63cdf0e10cSrcweir sal_uInt16 nMenuId = 1; 64cdf0e10cSrcweir sal_uInt16 nSubMenuId = MN_ST_INSERT_START; 65cdf0e10cSrcweir 66cdf0e10cSrcweir const rtl::OUString aRangeText = mxTextRange->getString(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get(); 69cdf0e10cSrcweir const rtl::OUString aApplicationName( rSmartTagMgr.GetApplicationName() ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir Sequence < Sequence< Reference< smarttags::XSmartTagAction > > > aActionComponentsSequence; 72cdf0e10cSrcweir Sequence < Sequence< sal_Int32 > > aActionIndicesSequence; 73cdf0e10cSrcweir 74cdf0e10cSrcweir rSmartTagMgr.GetActionSequences( rSmartTagTypes, 75cdf0e10cSrcweir aActionComponentsSequence, 76cdf0e10cSrcweir aActionIndicesSequence ); 77cdf0e10cSrcweir 78cdf0e10cSrcweir InsertSeparator(0); 79cdf0e10cSrcweir 80cdf0e10cSrcweir for ( sal_uInt16 j = 0; j < aActionComponentsSequence.getLength(); ++j ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir Reference< container::XStringKeyMap > xSmartTagProperties = rStringKeyMaps[j]; 83cdf0e10cSrcweir 84cdf0e10cSrcweir // Get all actions references associated with the current smart tag type: 85cdf0e10cSrcweir const Sequence< Reference< smarttags::XSmartTagAction > >& rActionComponents = aActionComponentsSequence[j]; 86cdf0e10cSrcweir const Sequence< sal_Int32 >& rActionIndices = aActionIndicesSequence[j]; 87cdf0e10cSrcweir 88cdf0e10cSrcweir if ( 0 == rActionComponents.getLength() || 0 == rActionIndices.getLength() ) 89cdf0e10cSrcweir continue; 90cdf0e10cSrcweir 91cdf0e10cSrcweir // Ask first entry for the smart tag type caption: 92cdf0e10cSrcweir Reference< smarttags::XSmartTagAction > xAction = rActionComponents[0]; 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( !xAction.is() ) 95cdf0e10cSrcweir continue; 96cdf0e10cSrcweir 97cdf0e10cSrcweir const sal_Int32 nSmartTagIndex = rActionIndices[0]; 98cdf0e10cSrcweir const rtl::OUString aSmartTagType = xAction->getSmartTagName( nSmartTagIndex ); 99cdf0e10cSrcweir const rtl::OUString aSmartTagCaption = xAction->getSmartTagCaption( nSmartTagIndex, aLocale ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir // no sub-menues if there's only one smart tag type listed: 102cdf0e10cSrcweir PopupMenu* pSbMenu = this; 103cdf0e10cSrcweir if ( 1 < aActionComponentsSequence.getLength() ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir InsertItem( nMenuId, aSmartTagCaption, 0, nMenuPos++); 106cdf0e10cSrcweir pSbMenu = new PopupMenu; 107cdf0e10cSrcweir SetPopupMenu( nMenuId++, pSbMenu ); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir // sub-menu starts with smart tag caption and separator 111cdf0e10cSrcweir const rtl::OUString aSmartTagCaption2 = aSmartTagCaption + C2U(": ") + aRangeText; 112cdf0e10cSrcweir nSubMenuPos = 0; 113cdf0e10cSrcweir pSbMenu->InsertItem( nMenuId++, aSmartTagCaption2, MIB_NOSELECT, nSubMenuPos++ ); 114cdf0e10cSrcweir pSbMenu->InsertSeparator( nSubMenuPos++ ); 115cdf0e10cSrcweir 116cdf0e10cSrcweir // Add subitem for every action reference for the current smart tag type: 117cdf0e10cSrcweir for ( sal_uInt16 i = 0; i < rActionComponents.getLength(); ++i ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir xAction = rActionComponents[i]; 120cdf0e10cSrcweir 121cdf0e10cSrcweir for ( sal_Int32 k = 0; k < xAction->getActionCount( aSmartTagType, xController ); ++k ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir const sal_uInt32 nActionID = xAction->getActionID( aSmartTagType, k, xController ); 124cdf0e10cSrcweir rtl::OUString aActionCaption = xAction->getActionCaptionFromID( nActionID, 125cdf0e10cSrcweir aApplicationName, 126cdf0e10cSrcweir aLocale, 127cdf0e10cSrcweir xSmartTagProperties, 128cdf0e10cSrcweir aRangeText, 129cdf0e10cSrcweir rtl::OUString(), 130cdf0e10cSrcweir xController, 131cdf0e10cSrcweir mxTextRange ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir pSbMenu->InsertItem( nSubMenuId++, aActionCaption, 0, nSubMenuPos++ ); 134cdf0e10cSrcweir InvokeAction aEntry( xAction, xSmartTagProperties, nActionID ); 135cdf0e10cSrcweir maInvokeActions.push_back( aEntry ); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir } 138cdf0e10cSrcweir } 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir /** Function: Execute 142cdf0e10cSrcweir 143cdf0e10cSrcweir executes actions by calling the invoke function of the appropriate 144cdf0e10cSrcweir smarttag library. 145cdf0e10cSrcweir 146cdf0e10cSrcweir */ 147cdf0e10cSrcweir sal_uInt16 SwSmartTagPopup::Execute( const Rectangle& rWordPos, Window* pWin ) 148cdf0e10cSrcweir { 149cdf0e10cSrcweir sal_uInt16 nId = PopupMenu::Execute(pWin, pWin->LogicToPixel(rWordPos)); 150cdf0e10cSrcweir 151cdf0e10cSrcweir if ( nId == MN_SMARTTAG_OPTIONS ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir SfxBoolItem aBool(SID_OPEN_SMARTTAGOPTIONS, sal_True); 154cdf0e10cSrcweir mpSwView->GetViewFrame()->GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SFX_CALLMODE_ASYNCHRON, &aBool, 0L ); 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir if ( nId < MN_ST_INSERT_START) return nId; 158cdf0e10cSrcweir nId -= MN_ST_INSERT_START; 159cdf0e10cSrcweir 160cdf0e10cSrcweir // compute smarttag lib index and action index 161cdf0e10cSrcweir if ( nId < maInvokeActions.size() ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir Reference< smarttags::XSmartTagAction > xSmartTagAction = maInvokeActions[ nId ].mxAction; 164cdf0e10cSrcweir 165cdf0e10cSrcweir // execute action 166cdf0e10cSrcweir if ( xSmartTagAction.is() ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get(); 169cdf0e10cSrcweir 170cdf0e10cSrcweir xSmartTagAction->invokeAction( maInvokeActions[ nId ].mnActionID, 171cdf0e10cSrcweir rSmartTagMgr.GetApplicationName(), 172cdf0e10cSrcweir mpSwView->GetController(), 173cdf0e10cSrcweir mxTextRange, 174cdf0e10cSrcweir maInvokeActions[ nId ].mxSmartTagProperties, 175cdf0e10cSrcweir mxTextRange->getString(), 176cdf0e10cSrcweir rtl::OUString(), 177cdf0e10cSrcweir SW_BREAKITER()->GetLocale( (LanguageType)GetAppLanguage() ) ); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir return nId; 182cdf0e10cSrcweir } 183