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