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