xref: /trunk/main/framework/source/fwe/helper/actiontriggerhelper.cxx (revision 6d739b60ff8f4ed2134ae1442e284f9da90334b4)
1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22*6d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir #include <framework/actiontriggerhelper.hxx>
27cdf0e10cSrcweir #include <classes/actiontriggerseparatorpropertyset.hxx>
28cdf0e10cSrcweir #include <classes/rootactiontriggercontainer.hxx>
29cdf0e10cSrcweir #include <classes/imagewrapper.hxx>
30cdf0e10cSrcweir #include <framework/addonsoptions.hxx>
31cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
33cdf0e10cSrcweir #include <com/sun/star/awt/XBitmap.hpp>
34cdf0e10cSrcweir #include <vcl/svapp.hxx>
35cdf0e10cSrcweir #include <vos/mutex.hxx>
36cdf0e10cSrcweir #include <tools/stream.hxx>
37cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
38cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir const sal_uInt16 START_ITEMID = 1000;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace rtl;
44cdf0e10cSrcweir using namespace vos;
45cdf0e10cSrcweir using namespace com::sun::star::awt;
46cdf0e10cSrcweir using namespace com::sun::star::uno;
47cdf0e10cSrcweir using namespace com::sun::star::lang;
48cdf0e10cSrcweir using namespace com::sun::star::beans;
49cdf0e10cSrcweir using namespace com::sun::star::container;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace framework
52cdf0e10cSrcweir {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir // ----------------------------------------------------------------------------
55cdf0e10cSrcweir // implementation helper ( menu => ActionTrigger )
56cdf0e10cSrcweir // ----------------------------------------------------------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir sal_Bool IsSeparator( Reference< XPropertySet > xPropertySet )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     Reference< XServiceInfo > xServiceInfo( xPropertySet, UNO_QUERY );
61cdf0e10cSrcweir     try
62cdf0e10cSrcweir     {
63cdf0e10cSrcweir         return xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGERSEPARATOR )) );
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir     catch ( Exception& )
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir     }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     return sal_False;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir void GetMenuItemAttributes( Reference< XPropertySet > xActionTriggerPropertySet,
73cdf0e10cSrcweir                             OUString& aMenuLabel,
74cdf0e10cSrcweir                             OUString& aCommandURL,
75cdf0e10cSrcweir                             OUString& aHelpURL,
76cdf0e10cSrcweir                             Reference< XBitmap >& xBitmap,
77cdf0e10cSrcweir                             Reference< XIndexContainer >& xSubContainer )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     Any a;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     try
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         // mandatory properties
84cdf0e10cSrcweir         a = xActionTriggerPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )) );
85cdf0e10cSrcweir         a >>= aMenuLabel;
86cdf0e10cSrcweir         a = xActionTriggerPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )) );
87cdf0e10cSrcweir         a >>= aCommandURL;
88cdf0e10cSrcweir         a = xActionTriggerPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )) );
89cdf0e10cSrcweir         a >>= xBitmap;
90cdf0e10cSrcweir         a = xActionTriggerPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )) );
91cdf0e10cSrcweir         a >>= xSubContainer;
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir     catch ( Exception& )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir     }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // optional properties
98cdf0e10cSrcweir     try
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         a = xActionTriggerPropertySet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL" )) );
101cdf0e10cSrcweir         a >>= aHelpURL;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir     catch ( Exception& )
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir void InsertSubMenuItems( Menu* pSubMenu, sal_uInt16& nItemId, Reference< XIndexContainer > xActionTriggerContainer )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     Reference< XIndexAccess > xIndexAccess( xActionTriggerContainer, UNO_QUERY );
111cdf0e10cSrcweir     if ( xIndexAccess.is() )
112cdf0e10cSrcweir     {
113cdf0e10cSrcweir         AddonsOptions aAddonOptions;
114cdf0e10cSrcweir         const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
115cdf0e10cSrcweir         sal_Bool bHiContrast = rSettings.GetHighContrastMode();
116cdf0e10cSrcweir 
117cdf0e10cSrcweir         OUString aSlotURL( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < xIndexAccess->getCount(); i++ )
120cdf0e10cSrcweir         {
121cdf0e10cSrcweir             try
122cdf0e10cSrcweir             {
123cdf0e10cSrcweir                 Reference< XPropertySet > xPropSet;
124cdf0e10cSrcweir                 if (( xIndexAccess->getByIndex( i ) >>= xPropSet ) && ( xPropSet.is() ))
125cdf0e10cSrcweir                 {
126cdf0e10cSrcweir                     if ( IsSeparator( xPropSet ))
127cdf0e10cSrcweir                     {
128cdf0e10cSrcweir                         // Separator
129cdf0e10cSrcweir                         OGuard aGuard( Application::GetSolarMutex() );
130cdf0e10cSrcweir                         pSubMenu->InsertSeparator();
131cdf0e10cSrcweir                     }
132cdf0e10cSrcweir                     else
133cdf0e10cSrcweir                     {
134cdf0e10cSrcweir                         // Menu item
135cdf0e10cSrcweir                         OUString aLabel;
136cdf0e10cSrcweir                         OUString aCommandURL;
137cdf0e10cSrcweir                         OUString aHelpURL;
138cdf0e10cSrcweir                         Reference< XBitmap > xBitmap;
139cdf0e10cSrcweir                         Reference< XIndexContainer > xSubContainer;
140cdf0e10cSrcweir                         sal_Bool bSpecialItemId = sal_False;
141cdf0e10cSrcweir 
142cdf0e10cSrcweir                         sal_uInt16 nNewItemId = nItemId++;
143cdf0e10cSrcweir                         GetMenuItemAttributes( xPropSet, aLabel, aCommandURL, aHelpURL, xBitmap, xSubContainer );
144cdf0e10cSrcweir 
145cdf0e10cSrcweir                         OGuard aGuard( Application::GetSolarMutex() );
146cdf0e10cSrcweir                         {
147cdf0e10cSrcweir                             // insert new menu item
148cdf0e10cSrcweir                             sal_Int32 nIndex = aCommandURL.indexOf( aSlotURL );
149cdf0e10cSrcweir                             if ( nIndex >= 0 )
150cdf0e10cSrcweir                             {
151cdf0e10cSrcweir                                 // Special code for our menu implementation: some menu items don't have a
152cdf0e10cSrcweir                                 // command url but uses the item id as a unqiue identifier. These entries
153cdf0e10cSrcweir                                 // got a special url during conversion from menu=>actiontriggercontainer.
154cdf0e10cSrcweir                                 // Now we have to extract this special url and set the correct item id!!!
155cdf0e10cSrcweir                                 bSpecialItemId = sal_True;
156cdf0e10cSrcweir                                 nNewItemId = (sal_uInt16)aCommandURL.copy( nIndex+aSlotURL.getLength() ).toInt32();
157cdf0e10cSrcweir                                 pSubMenu->InsertItem( nNewItemId, aLabel );
158cdf0e10cSrcweir                             }
159cdf0e10cSrcweir                             else
160cdf0e10cSrcweir                             {
161cdf0e10cSrcweir                                 pSubMenu->InsertItem( nNewItemId, aLabel );
162cdf0e10cSrcweir                                 pSubMenu->SetItemCommand( nNewItemId, aCommandURL );
163cdf0e10cSrcweir                             }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir                             // handle bitmap
166cdf0e10cSrcweir                             if ( xBitmap.is() )
167cdf0e10cSrcweir                             {
168cdf0e10cSrcweir                                 sal_Bool bImageSet = sal_False;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir                                 Reference< XUnoTunnel > xUnoTunnel( xBitmap, UNO_QUERY );
171cdf0e10cSrcweir                                 if ( xUnoTunnel.is() )
172cdf0e10cSrcweir                                 {
173cdf0e10cSrcweir                                     // Try to get implementation pointer through XUnoTunnel
174cdf0e10cSrcweir                                     sal_Int64 nPointer = xUnoTunnel->getSomething( ImageWrapper::GetUnoTunnelId() );
175cdf0e10cSrcweir                                     if ( nPointer )
176cdf0e10cSrcweir                                     {
177cdf0e10cSrcweir                                         // This is our own optimized implementation of menu images!
178cdf0e10cSrcweir                                         ImageWrapper* pImageWrapper = reinterpret_cast< ImageWrapper * >( nPointer );
179cdf0e10cSrcweir                                         Image aMenuImage = pImageWrapper->GetImage();
180cdf0e10cSrcweir 
181cdf0e10cSrcweir                                         if ( !!aMenuImage )
182cdf0e10cSrcweir                                             pSubMenu->SetItemImage( nNewItemId, aMenuImage );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir                                         bImageSet = sal_True;
185cdf0e10cSrcweir                                     }
186cdf0e10cSrcweir                                 }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir                                 if ( !bImageSet )
189cdf0e10cSrcweir                                 {
190cdf0e10cSrcweir                                     // This is an unknown implementation of a XBitmap interface. We have to
191cdf0e10cSrcweir                                     // use a more time consuming way to build an Image!
192cdf0e10cSrcweir                                     Image   aImage;
193cdf0e10cSrcweir                                     Bitmap  aBitmap;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir                                     Sequence< sal_Int8 > aDIBSeq;
196cdf0e10cSrcweir                                     {
197cdf0e10cSrcweir                                         aDIBSeq = xBitmap->getDIB();
198cdf0e10cSrcweir                                         SvMemoryStream aMem( (void *)aDIBSeq.getConstArray(), aDIBSeq.getLength(), STREAM_READ );
199cdf0e10cSrcweir                                         aMem >> aBitmap;
200cdf0e10cSrcweir                                     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir                                     aDIBSeq = xBitmap->getMaskDIB();
203cdf0e10cSrcweir                                     if ( aDIBSeq.getLength() > 0 )
204cdf0e10cSrcweir                                     {
205cdf0e10cSrcweir                                         Bitmap aMaskBitmap;
206cdf0e10cSrcweir                                         SvMemoryStream aMem( (void *)aDIBSeq.getConstArray(), aDIBSeq.getLength(), STREAM_READ );
207cdf0e10cSrcweir                                         aMem >> aMaskBitmap;
208cdf0e10cSrcweir                                         aImage = Image( aBitmap, aMaskBitmap );
209cdf0e10cSrcweir                                     }
210cdf0e10cSrcweir                                     else
211cdf0e10cSrcweir                                         aImage = Image( aBitmap );
212cdf0e10cSrcweir 
213cdf0e10cSrcweir                                     if ( !!aImage )
214cdf0e10cSrcweir                                         pSubMenu->SetItemImage( nNewItemId, aImage );
215cdf0e10cSrcweir                                 }
216cdf0e10cSrcweir                             }
217cdf0e10cSrcweir                             else
218cdf0e10cSrcweir                             {
219cdf0e10cSrcweir                                 // Support add-on images for context menu interceptors
220cdf0e10cSrcweir                                 Image aImage = aAddonOptions.GetImageFromURL( aCommandURL, sal_False, bHiContrast, sal_True );
221cdf0e10cSrcweir                                 if ( !!aImage )
222cdf0e10cSrcweir                                     pSubMenu->SetItemImage( nNewItemId, aImage );
223cdf0e10cSrcweir                             }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir                             if ( xSubContainer.is() )
226cdf0e10cSrcweir                             {
227cdf0e10cSrcweir                                 PopupMenu* pNewSubMenu = new PopupMenu;
228cdf0e10cSrcweir 
229cdf0e10cSrcweir                                 // Sub menu (recursive call CreateSubMenu )
230cdf0e10cSrcweir                                 InsertSubMenuItems( pNewSubMenu, nItemId, xSubContainer );
231cdf0e10cSrcweir                                 pSubMenu->SetPopupMenu( nNewItemId, pNewSubMenu );
232cdf0e10cSrcweir                             }
233cdf0e10cSrcweir                         }
234cdf0e10cSrcweir                     }
235cdf0e10cSrcweir                 }
236cdf0e10cSrcweir             }
237cdf0e10cSrcweir             catch ( IndexOutOfBoundsException )
238cdf0e10cSrcweir             {
239cdf0e10cSrcweir                 return;
240cdf0e10cSrcweir             }
241cdf0e10cSrcweir             catch ( WrappedTargetException )
242cdf0e10cSrcweir             {
243cdf0e10cSrcweir                 return;
244cdf0e10cSrcweir             }
245cdf0e10cSrcweir             catch ( RuntimeException )
246cdf0e10cSrcweir             {
247cdf0e10cSrcweir                 return;
248cdf0e10cSrcweir             }
249cdf0e10cSrcweir         }
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 
254cdf0e10cSrcweir // ----------------------------------------------------------------------------
255cdf0e10cSrcweir // implementation helper ( ActionTrigger => menu )
256cdf0e10cSrcweir // ----------------------------------------------------------------------------
257cdf0e10cSrcweir 
258cdf0e10cSrcweir Reference< XPropertySet > CreateActionTrigger( sal_uInt16 nItemId, const Menu* pMenu, const Reference< XIndexContainer >& rActionTriggerContainer ) throw ( RuntimeException )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir     Reference< XPropertySet > xPropSet;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     Reference< XMultiServiceFactory > xMultiServiceFactory( rActionTriggerContainer, UNO_QUERY );
263cdf0e10cSrcweir     if ( xMultiServiceFactory.is() )
264cdf0e10cSrcweir     {
265cdf0e10cSrcweir         xPropSet = Reference< XPropertySet >(   xMultiServiceFactory->createInstance(
266cdf0e10cSrcweir                                                     OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ActionTrigger" )) ),
267cdf0e10cSrcweir                                                 UNO_QUERY );
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         Any a;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         try
272cdf0e10cSrcweir         {
273cdf0e10cSrcweir             // Retrieve the menu attributes and set them in our PropertySet
274cdf0e10cSrcweir             OUString aLabel = pMenu->GetItemText( nItemId );
275cdf0e10cSrcweir             a <<= aLabel;
276cdf0e10cSrcweir             xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )), a );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir             OUString aCommandURL = pMenu->GetItemCommand( nItemId );
279cdf0e10cSrcweir 
280cdf0e10cSrcweir             if ( aCommandURL.getLength() == 0 )
281cdf0e10cSrcweir             {
282cdf0e10cSrcweir                 aCommandURL = OUString( RTL_CONSTASCII_USTRINGPARAM( "slot:" ));
283cdf0e10cSrcweir                 aCommandURL += OUString::valueOf( (sal_Int32)nItemId );
284cdf0e10cSrcweir             }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir             a <<= aCommandURL;
287cdf0e10cSrcweir             xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL" )), a );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir             Image aImage = pMenu->GetItemImage( nItemId );
290cdf0e10cSrcweir             if ( !!aImage )
291cdf0e10cSrcweir             {
292cdf0e10cSrcweir                 // We use our own optimized XBitmap implementation
293cdf0e10cSrcweir                 Reference< XBitmap > xBitmap( static_cast< cppu::OWeakObject* >( new ImageWrapper( aImage )), UNO_QUERY );
294cdf0e10cSrcweir                 a <<= xBitmap;
295cdf0e10cSrcweir                 xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Image" )), a );
296cdf0e10cSrcweir             }
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir         catch ( Exception& )
299cdf0e10cSrcweir         {
300cdf0e10cSrcweir         }
301cdf0e10cSrcweir     }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     return xPropSet;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir Reference< XPropertySet > CreateActionTriggerSeparator( const Reference< XIndexContainer >& rActionTriggerContainer ) throw ( RuntimeException )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir     Reference< XMultiServiceFactory > xMultiServiceFactory( rActionTriggerContainer, UNO_QUERY );
309cdf0e10cSrcweir     if ( xMultiServiceFactory.is() )
310cdf0e10cSrcweir     {
311cdf0e10cSrcweir         return Reference< XPropertySet >(   xMultiServiceFactory->createInstance(
312cdf0e10cSrcweir                                                 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ActionTriggerSeparator" )) ),
313cdf0e10cSrcweir                                             UNO_QUERY );
314cdf0e10cSrcweir     }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     return Reference< XPropertySet >();
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319cdf0e10cSrcweir Reference< XIndexContainer > CreateActionTriggerContainer( const Reference< XIndexContainer >& rActionTriggerContainer ) throw ( RuntimeException )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     Reference< XMultiServiceFactory > xMultiServiceFactory( rActionTriggerContainer, UNO_QUERY );
322cdf0e10cSrcweir     if ( xMultiServiceFactory.is() )
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         return Reference< XIndexContainer >( xMultiServiceFactory->createInstance(
325cdf0e10cSrcweir                                                 OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ActionTriggerContainer" )) ),
326cdf0e10cSrcweir                                              UNO_QUERY );
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     return Reference< XIndexContainer >();
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
332cdf0e10cSrcweir void FillActionTriggerContainerWithMenu( const Menu* pMenu, Reference< XIndexContainer >& rActionTriggerContainer )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     OGuard aGuard( Application::GetSolarMutex() );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < pMenu->GetItemCount(); nPos++ )
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         sal_uInt16          nItemId = pMenu->GetItemId( nPos );
339cdf0e10cSrcweir         MenuItemType    nType   = pMenu->GetItemType( nPos );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir         try
342cdf0e10cSrcweir         {
343cdf0e10cSrcweir             Any a;
344cdf0e10cSrcweir             Reference< XPropertySet > xPropSet;
345cdf0e10cSrcweir 
346cdf0e10cSrcweir             if ( nType == MENUITEM_SEPARATOR )
347cdf0e10cSrcweir             {
348cdf0e10cSrcweir                 xPropSet = CreateActionTriggerSeparator( rActionTriggerContainer );
349cdf0e10cSrcweir 
350cdf0e10cSrcweir                 a <<= xPropSet;
351cdf0e10cSrcweir                 rActionTriggerContainer->insertByIndex( nPos, a );
352cdf0e10cSrcweir             }
353cdf0e10cSrcweir             else
354cdf0e10cSrcweir             {
355cdf0e10cSrcweir                 xPropSet = CreateActionTrigger( nItemId, pMenu, rActionTriggerContainer );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir                 a <<= xPropSet;
358cdf0e10cSrcweir                 rActionTriggerContainer->insertByIndex( nPos, a );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir                 PopupMenu* pPopupMenu = pMenu->GetPopupMenu( nItemId );
361cdf0e10cSrcweir                 if ( pPopupMenu )
362cdf0e10cSrcweir                 {
363cdf0e10cSrcweir                     // recursive call to build next sub menu
364cdf0e10cSrcweir                     Reference< XIndexContainer > xSubContainer = CreateActionTriggerContainer( rActionTriggerContainer );
365cdf0e10cSrcweir 
366cdf0e10cSrcweir                     a <<= xSubContainer;
367cdf0e10cSrcweir                     xPropSet->setPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer" )), a );
368cdf0e10cSrcweir                     FillActionTriggerContainerWithMenu( pPopupMenu, xSubContainer );
369cdf0e10cSrcweir                 }
370cdf0e10cSrcweir             }
371cdf0e10cSrcweir         }
372cdf0e10cSrcweir         catch ( Exception& )
373cdf0e10cSrcweir         {
374cdf0e10cSrcweir         }
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir void ActionTriggerHelper::CreateMenuFromActionTriggerContainer(
379cdf0e10cSrcweir     Menu* pNewMenu,
380cdf0e10cSrcweir     const Reference< XIndexContainer >& rActionTriggerContainer )
381cdf0e10cSrcweir {
382cdf0e10cSrcweir     sal_uInt16 nItemId = START_ITEMID;
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     if ( rActionTriggerContainer.is() )
385cdf0e10cSrcweir         InsertSubMenuItems( pNewMenu, nItemId, rActionTriggerContainer );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
388cdf0e10cSrcweir void ActionTriggerHelper::FillActionTriggerContainerFromMenu(
389cdf0e10cSrcweir     Reference< XIndexContainer >& xActionTriggerContainer,
390cdf0e10cSrcweir     const Menu* pMenu )
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     FillActionTriggerContainerWithMenu( pMenu, xActionTriggerContainer );
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir Reference< XIndexContainer > ActionTriggerHelper::CreateActionTriggerContainerFromMenu(
396cdf0e10cSrcweir     // #110897#
397cdf0e10cSrcweir     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
398cdf0e10cSrcweir     const Menu* pMenu,
399cdf0e10cSrcweir     const ::rtl::OUString* pMenuIdentifier )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     return new RootActionTriggerContainer( pMenu, pMenuIdentifier, xServiceFactory );
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir }
405