Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svx/SmartTagCtl.hxx>
31 : : #include <com/sun/star/smarttags/XSmartTagAction.hpp>
32 : : #include <com/sun/star/container/XStringKeyMap.hpp>
33 : : #include <svtools/stdmenu.hxx>
34 : : #include <svl/eitem.hxx>
35 : : #include <sfx2/dispatch.hxx>
36 : : #include <svx/svxids.hrc>
37 : :
38 : : #include <svx/SmartTagItem.hxx>
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::com::sun::star::uno;
42 : :
43 : : // STATIC DATA -----------------------------------------------------------
44 : :
45 [ # # ]: 73 : SFX_IMPL_MENU_CONTROL(SvxSmartTagsControl, SvxSmartTagItem);
46 : :
47 : : //--------------------------------------------------------------------
48 : :
49 : 0 : SvxSmartTagsControl::SvxSmartTagsControl
50 : : (
51 : : sal_uInt16 _nId,
52 : : Menu& rMenu,
53 : : SfxBindings& /*rBindings*/
54 : : ) :
55 [ # # ]: 0 : mpMenu ( new PopupMenu ),
56 : : mrParent ( rMenu ),
57 [ # # ][ # # ]: 0 : mpSmartTagItem( 0 )
58 : : {
59 [ # # ]: 0 : rMenu.SetPopupMenu( _nId, mpMenu );
60 : 0 : }
61 : :
62 : : //--------------------------------------------------------------------
63 : :
64 : : const sal_uInt16 MN_ST_INSERT_START = 500;
65 : :
66 : 0 : void SvxSmartTagsControl::FillMenu()
67 : : {
68 [ # # ]: 0 : if ( !mpSmartTagItem )
69 : 0 : return;
70 : :
71 : 0 : sal_uInt16 nMenuPos = 0;
72 : 0 : sal_uInt16 nSubMenuPos = 0;
73 : 0 : sal_uInt16 nMenuId = 1;
74 : 0 : sal_uInt16 nSubMenuId = MN_ST_INSERT_START;
75 : :
76 : 0 : const Sequence < Sequence< Reference< smarttags::XSmartTagAction > > >& rActionComponentsSequence = mpSmartTagItem->GetActionComponentsSequence();
77 : 0 : const Sequence < Sequence< sal_Int32 > >& rActionIndicesSequence = mpSmartTagItem->GetActionIndicesSequence();
78 : 0 : const Sequence< Reference< container::XStringKeyMap > >& rStringKeyMaps = mpSmartTagItem->GetStringKeyMaps();
79 : 0 : const lang::Locale& rLocale = mpSmartTagItem->GetLocale();
80 : 0 : const rtl::OUString aApplicationName = mpSmartTagItem->GetApplicationName();
81 : 0 : const rtl::OUString aRangeText = mpSmartTagItem->GetRangeText();
82 : 0 : const Reference<text::XTextRange>& xTextRange = mpSmartTagItem->GetTextRange();
83 : 0 : const Reference<frame::XController>& xController = mpSmartTagItem->GetController();
84 : :
85 [ # # ]: 0 : for ( sal_uInt16 j = 0; j < rActionComponentsSequence.getLength(); ++j )
86 : : {
87 : 0 : Reference< container::XStringKeyMap > xSmartTagProperties = rStringKeyMaps[j];
88 : :
89 : : // Get all actions references associated with the current smart tag type:
90 : 0 : const Sequence< Reference< smarttags::XSmartTagAction > >& rActionComponents = rActionComponentsSequence[j];
91 : 0 : const Sequence< sal_Int32 >& rActionIndices = rActionIndicesSequence[j];
92 : :
93 [ # # ][ # # ]: 0 : if ( 0 == rActionComponents.getLength() || 0 == rActionIndices.getLength() )
[ # # ]
94 : 0 : continue;
95 : :
96 : : // Ask first entry for the smart tag type caption:
97 : 0 : Reference< smarttags::XSmartTagAction > xAction = rActionComponents[0];
98 : :
99 [ # # ]: 0 : if ( !xAction.is() )
100 : 0 : continue;
101 : :
102 : 0 : const sal_Int32 nSmartTagIndex = rActionIndices[0];
103 [ # # ][ # # ]: 0 : const rtl::OUString aSmartTagType = xAction->getSmartTagName( nSmartTagIndex );
104 [ # # ][ # # ]: 0 : const rtl::OUString aSmartTagCaption = xAction->getSmartTagCaption( nSmartTagIndex, rLocale );
105 : :
106 : : // no sub-menus if there's only one smart tag type listed:
107 : 0 : PopupMenu* pSbMenu = mpMenu;
108 [ # # ]: 0 : if ( 1 < rActionComponentsSequence.getLength() )
109 : : {
110 [ # # ][ # # ]: 0 : mpMenu->InsertItem( nMenuId, aSmartTagCaption, 0, nMenuPos++);
[ # # ]
111 [ # # ][ # # ]: 0 : pSbMenu = new PopupMenu;
112 [ # # ]: 0 : mpMenu->SetPopupMenu( nMenuId++, pSbMenu );
113 : : }
114 [ # # ]: 0 : pSbMenu->SetSelectHdl( LINK( this, SvxSmartTagsControl, MenuSelect ) );
115 : :
116 : : // sub-menu starts with smart tag caption and separator
117 [ # # ]: 0 : const rtl::OUString aSmartTagCaption2 = aSmartTagCaption + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(": ")) + aRangeText;
118 : 0 : nSubMenuPos = 0;
119 [ # # ][ # # ]: 0 : pSbMenu->InsertItem( nMenuId++, aSmartTagCaption2, MIB_NOSELECT, nSubMenuPos++ );
[ # # ]
120 [ # # ]: 0 : pSbMenu->InsertSeparator( nSubMenuPos++ );
121 : :
122 : : // Add subitem for every action reference for the current smart tag type:
123 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < rActionComponents.getLength(); ++i )
124 : : {
125 [ # # ]: 0 : xAction = rActionComponents[i];
126 : :
127 [ # # ][ # # ]: 0 : for ( sal_Int32 k = 0; k < xAction->getActionCount( aSmartTagType, xController ); ++k )
[ # # ]
128 : : {
129 [ # # ][ # # ]: 0 : const sal_uInt32 nActionID = xAction->getActionID( aSmartTagType, k, xController );
130 [ # # ]: 0 : rtl::OUString aActionCaption = xAction->getActionCaptionFromID( nActionID,
131 : : aApplicationName,
132 : : rLocale,
133 : : xSmartTagProperties,
134 : : aRangeText,
135 : : rtl::OUString(),
136 : : xController,
137 [ # # ]: 0 : xTextRange );
138 : :
139 [ # # ][ # # ]: 0 : pSbMenu->InsertItem( nSubMenuId++, aActionCaption, 0, nSubMenuPos++ );
[ # # ]
140 [ # # ]: 0 : InvokeAction aEntry( xAction, xSmartTagProperties, nActionID );
141 [ # # ]: 0 : maInvokeActions.push_back( aEntry );
142 [ # # ]: 0 : }
143 : : }
144 [ # # ][ # # ]: 0 : }
145 : : }
146 : :
147 : : //--------------------------------------------------------------------
148 : :
149 : 0 : void SvxSmartTagsControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
150 : :
151 : : {
152 : 0 : mrParent.EnableItem( GetId(), SFX_ITEM_DISABLED != eState );
153 : :
154 [ # # ]: 0 : if ( SFX_ITEM_AVAILABLE == eState )
155 : : {
156 [ # # ][ # # ]: 0 : const SvxSmartTagItem* pSmartTagItem = PTR_CAST( SvxSmartTagItem, pState );
157 [ # # ]: 0 : if ( 0 != pSmartTagItem )
158 : : {
159 [ # # ]: 0 : delete mpSmartTagItem;
160 [ # # ]: 0 : mpSmartTagItem = new SvxSmartTagItem( *pSmartTagItem );
161 : 0 : FillMenu();
162 : : }
163 : : }
164 : 0 : }
165 : :
166 : : //--------------------------------------------------------------------
167 : :
168 : 0 : IMPL_LINK_INLINE_START( SvxSmartTagsControl, MenuSelect, PopupMenu *, pMen )
169 : : {
170 [ # # ]: 0 : if ( !mpSmartTagItem )
171 : 0 : return 0;
172 : :
173 [ # # ]: 0 : sal_uInt16 nMyId = pMen->GetCurItemId();
174 : :
175 [ # # ]: 0 : if ( nMyId < MN_ST_INSERT_START) return 0;
176 : 0 : nMyId -= MN_ST_INSERT_START;
177 : :
178 : : // compute smarttag lib index and action index
179 [ # # ]: 0 : Reference< smarttags::XSmartTagAction > xSmartTagAction = maInvokeActions[ nMyId ].mxAction;
180 : :
181 : : // execute action
182 [ # # ]: 0 : if ( xSmartTagAction.is() )
183 : : {
184 [ # # # # ]: 0 : xSmartTagAction->invokeAction( maInvokeActions[ nMyId ].mnActionID,
185 : : mpSmartTagItem->GetApplicationName(),
186 : 0 : mpSmartTagItem->GetController(),
187 : 0 : mpSmartTagItem->GetTextRange(),
188 [ # # ]: 0 : maInvokeActions[ nMyId ].mxSmartTagProperties,
189 : : mpSmartTagItem->GetRangeText(),
190 : : rtl::OUString(),
191 [ # # ]: 0 : mpSmartTagItem->GetLocale() );
192 : : }
193 : :
194 : : // ohne dispatcher!!!
195 : : // GetBindings().Execute( GetId(), SFX_CALLMODE_RECORD,meine beiden items, 0L );*/
196 : : //SfxBoolItem aBool(SID_OPEN_SMARTTAGOPTIONS, sal_True);
197 : : //GetBindings().GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SFX_CALLMODE_ASYNCHRON, &aBool, 0L );
198 : :
199 : 0 : return 0;
200 : : }
201 : 0 : IMPL_LINK_INLINE_END( SvxSmartTagsControl, MenuSelect, PopupMenu *, pMen )
202 : :
203 : : //--------------------------------------------------------------------
204 : :
205 : 0 : SvxSmartTagsControl::~SvxSmartTagsControl()
206 : : {
207 [ # # ][ # # ]: 0 : delete mpSmartTagItem;
208 [ # # ][ # # ]: 0 : delete mpMenu;
209 [ # # ]: 0 : }
210 : :
211 : : //--------------------------------------------------------------------
212 : :
213 : 0 : PopupMenu* SvxSmartTagsControl::GetPopup() const
214 : : {
215 : 0 : return mpMenu;
216 : : }
217 : :
218 : :
219 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|