xref: /AOO41X/main/toolkit/source/awt/vclxmenu.cxx (revision d026be4010c9a2cd3d6542218aa632c5d984860c)
1b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b0724fc6SAndrew Rist  * distributed with this work for additional information
6b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18b0724fc6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b0724fc6SAndrew Rist  *************************************************************/
21b0724fc6SAndrew Rist 
22b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <toolkit/awt/vclxmenu.hxx>
28*d026be40SAriel Constenla-Haile #include <toolkit/helper/convert.hxx>
29cdf0e10cSrcweir #include <toolkit/helper/macros.hxx>
30cdf0e10cSrcweir #include <toolkit/helper/servicenames.hxx>
31cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
32*d026be40SAriel Constenla-Haile 
33cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
34cdf0e10cSrcweir #include <rtl/memory.h>
35*d026be40SAriel Constenla-Haile #include <rtl/ustrbuf.hxx>
36cdf0e10cSrcweir #include <rtl/uuid.h>
37cdf0e10cSrcweir #include <vcl/image.hxx>
38*d026be40SAriel Constenla-Haile #include <vcl/keycod.hxx>
39*d026be40SAriel Constenla-Haile #include <vcl/menu.hxx>
40cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
41cdf0e10cSrcweir #include <vcl/svapp.hxx>
42*d026be40SAriel Constenla-Haile #include <vos/mutex.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
45cdf0e10cSrcweir 
46*d026be40SAriel Constenla-Haile using rtl::OUString;
47*d026be40SAriel Constenla-Haile using rtl::OUStringBuffer;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 
50cdf0e10cSrcweir DBG_NAME(VCLXMenu)
51cdf0e10cSrcweir 
52*d026be40SAriel Constenla-Haile VCLXMenu::VCLXMenu()
53*d026be40SAriel Constenla-Haile     : maMenuListeners( *this )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir     DBG_CTOR( VCLXMenu, 0 );
56cdf0e10cSrcweir     mpMenu = NULL;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59*d026be40SAriel Constenla-Haile VCLXMenu::VCLXMenu( Menu* pMenu )
60*d026be40SAriel Constenla-Haile     : maMenuListeners( *this )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     DBG_CTOR( VCLXMenu, 0 );
63cdf0e10cSrcweir     mpMenu = pMenu;
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir VCLXMenu::~VCLXMenu()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     DBG_DTOR( VCLXMenu, 0 );
69cdf0e10cSrcweir     for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; )
70cdf0e10cSrcweir     {
71*d026be40SAriel Constenla-Haile         css::uno::Reference< css::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n );
72cdf0e10cSrcweir         delete pRef;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     if ( mpMenu )
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
77cdf0e10cSrcweir         delete mpMenu;
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir sal_Bool VCLXMenu::IsPopupMenu() const
82cdf0e10cSrcweir {
83cdf0e10cSrcweir     return (mpMenu && ! mpMenu->IsMenuBar());
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir void VCLXMenu::ImplCreateMenu( sal_Bool bPopup )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     if ( bPopup )
91cdf0e10cSrcweir         mpMenu = new PopupMenu;
92cdf0e10cSrcweir     else
93cdf0e10cSrcweir         mpMenu = new MenuBar;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir IMPL_LINK( VCLXMenu, MenuEventListener, VclSimpleEvent*, pEvent )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     DBG_ASSERT( pEvent && pEvent->ISA( VclMenuEvent ), "Unknown Event!" );
101cdf0e10cSrcweir     if ( pEvent && pEvent->ISA( VclMenuEvent ) )
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         DBG_ASSERT( ((VclMenuEvent*)pEvent)->GetMenu() && mpMenu, "Menu???" );
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         VclMenuEvent* pMenuEvent = (VclMenuEvent*)pEvent;
106cdf0e10cSrcweir         if ( pMenuEvent->GetMenu() == mpMenu )  // Also called for the root menu
107cdf0e10cSrcweir         {
108cdf0e10cSrcweir             switch ( pMenuEvent->GetId() )
109cdf0e10cSrcweir             {
110cdf0e10cSrcweir                 case VCLEVENT_MENU_SELECT:
111cdf0e10cSrcweir                 {
112cdf0e10cSrcweir                     if ( maMenuListeners.getLength() )
113cdf0e10cSrcweir                     {
114*d026be40SAriel Constenla-Haile                         css::awt::MenuEvent aEvent;
115cdf0e10cSrcweir                         aEvent.Source = (::cppu::OWeakObject*)this;
116cdf0e10cSrcweir                         aEvent.MenuId = mpMenu->GetCurItemId();
117*d026be40SAriel Constenla-Haile                         maMenuListeners.itemSelected( aEvent );
118cdf0e10cSrcweir                     }
119cdf0e10cSrcweir                 }
120cdf0e10cSrcweir                 break;
121cdf0e10cSrcweir                 case VCLEVENT_OBJECT_DYING:
122cdf0e10cSrcweir                 {
123cdf0e10cSrcweir                     mpMenu = NULL;
124cdf0e10cSrcweir                 }
125cdf0e10cSrcweir                 break;
126cdf0e10cSrcweir                 case VCLEVENT_MENU_HIGHLIGHT:
127cdf0e10cSrcweir                 {
128cdf0e10cSrcweir                     if ( maMenuListeners.getLength() )
129cdf0e10cSrcweir                     {
130*d026be40SAriel Constenla-Haile                         css::awt::MenuEvent aEvent;
131cdf0e10cSrcweir                         aEvent.Source = (::cppu::OWeakObject*)this;
132cdf0e10cSrcweir                         aEvent.MenuId = mpMenu->GetCurItemId();
133*d026be40SAriel Constenla-Haile                         maMenuListeners.itemHighlighted( aEvent );
134cdf0e10cSrcweir                     }
135cdf0e10cSrcweir                 }
136cdf0e10cSrcweir                 break;
137cdf0e10cSrcweir                 case VCLEVENT_MENU_ACTIVATE:
138cdf0e10cSrcweir                 {
139cdf0e10cSrcweir                     if ( maMenuListeners.getLength() )
140cdf0e10cSrcweir                     {
141*d026be40SAriel Constenla-Haile                         css::awt::MenuEvent aEvent;
142cdf0e10cSrcweir                         aEvent.Source = (::cppu::OWeakObject*)this;
143cdf0e10cSrcweir                         aEvent.MenuId = mpMenu->GetCurItemId();
144*d026be40SAriel Constenla-Haile                         maMenuListeners.itemActivated( aEvent );
145cdf0e10cSrcweir                     }
146cdf0e10cSrcweir                 }
147cdf0e10cSrcweir                 break;
148cdf0e10cSrcweir                 case VCLEVENT_MENU_DEACTIVATE:
149cdf0e10cSrcweir                 {
150cdf0e10cSrcweir                     if ( maMenuListeners.getLength() )
151cdf0e10cSrcweir                     {
152*d026be40SAriel Constenla-Haile                         css::awt::MenuEvent aEvent;
153cdf0e10cSrcweir                         aEvent.Source = (::cppu::OWeakObject*)this;
154cdf0e10cSrcweir                         aEvent.MenuId = mpMenu->GetCurItemId();
155*d026be40SAriel Constenla-Haile                         maMenuListeners.itemDeactivated( aEvent );
156cdf0e10cSrcweir                     }
157cdf0e10cSrcweir                 }
158cdf0e10cSrcweir                 break;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir                 // ignore accessibility events
161cdf0e10cSrcweir                 case VCLEVENT_MENU_ENABLE:
162cdf0e10cSrcweir                 case VCLEVENT_MENU_INSERTITEM:
163cdf0e10cSrcweir                 case VCLEVENT_MENU_REMOVEITEM:
164cdf0e10cSrcweir                 case VCLEVENT_MENU_SUBMENUACTIVATE:
165cdf0e10cSrcweir                 case VCLEVENT_MENU_SUBMENUDEACTIVATE:
166cdf0e10cSrcweir                 case VCLEVENT_MENU_SUBMENUCHANGED:
167cdf0e10cSrcweir                 case VCLEVENT_MENU_DEHIGHLIGHT:
168cdf0e10cSrcweir                 case VCLEVENT_MENU_DISABLE:
169cdf0e10cSrcweir                 case VCLEVENT_MENU_ITEMTEXTCHANGED:
170cdf0e10cSrcweir                 case VCLEVENT_MENU_ITEMCHECKED:
171cdf0e10cSrcweir                 case VCLEVENT_MENU_ITEMUNCHECKED:
172cdf0e10cSrcweir                 case VCLEVENT_MENU_SHOW:
173cdf0e10cSrcweir                 case VCLEVENT_MENU_HIDE:
174cdf0e10cSrcweir                 break;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir                 default:    DBG_ERROR( "MenuEventListener - Unknown event!" );
177cdf0e10cSrcweir            }
178cdf0e10cSrcweir        }
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir     return 0;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 
184*d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getImplementationName(  )
185*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
188cdf0e10cSrcweir     const sal_Bool bIsPopupMenu = IsPopupMenu();
189cdf0e10cSrcweir     aGuard.clear();
190cdf0e10cSrcweir 
191*d026be40SAriel Constenla-Haile     OUStringBuffer implName;
192*d026be40SAriel Constenla-Haile     implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "stardiv.Toolkit." ) );
193cdf0e10cSrcweir     if ( bIsPopupMenu )
194*d026be40SAriel Constenla-Haile         implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VCLXPopupMenu" ) );
195cdf0e10cSrcweir     else
196*d026be40SAriel Constenla-Haile         implName.appendAscii( RTL_CONSTASCII_STRINGPARAM( "VCLXMenuBar" ) );
197cdf0e10cSrcweir 
198*d026be40SAriel Constenla-Haile     return implName.makeStringAndClear();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202*d026be40SAriel Constenla-Haile css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames(  )
203*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
206cdf0e10cSrcweir     const sal_Bool bIsPopupMenu = IsPopupMenu();
207cdf0e10cSrcweir     aGuard.clear();
208cdf0e10cSrcweir 
209*d026be40SAriel Constenla-Haile     css::uno::Sequence< OUString > aNames( 1 );
210cdf0e10cSrcweir     if ( bIsPopupMenu )
211*d026be40SAriel Constenla-Haile         aNames[ 0 ] = OUString::createFromAscii( szServiceName2_PopupMenu );
212cdf0e10cSrcweir     else
213*d026be40SAriel Constenla-Haile         aNames[ 0 ] = OUString::createFromAscii( szServiceName2_MenuBar );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     return aNames;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219*d026be40SAriel Constenla-Haile ::sal_Bool SAL_CALL VCLXMenu::supportsService(
220*d026be40SAriel Constenla-Haile     const OUString& rServiceName )
221*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
222cdf0e10cSrcweir {
223*d026be40SAriel Constenla-Haile     css::uno::Sequence< OUString > aServiceNames( getSupportedServiceNames() );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     if ( aServiceNames[ 0 ] == rServiceName )
226cdf0e10cSrcweir         return sal_True;
227cdf0e10cSrcweir 
228cdf0e10cSrcweir     return sal_False;
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232*d026be40SAriel Constenla-Haile css::uno::Any VCLXMenu::queryInterface(
233*d026be40SAriel Constenla-Haile     const css::uno::Type & rType )
234*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
237cdf0e10cSrcweir     const sal_Bool bIsPopupMenu = IsPopupMenu();
238cdf0e10cSrcweir     aGuard.clear();
239cdf0e10cSrcweir 
240*d026be40SAriel Constenla-Haile     css::uno::Any aRet;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     if ( bIsPopupMenu )
243cdf0e10cSrcweir         aRet = ::cppu::queryInterface(  rType,
244*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::awt::XMenu*, (css::awt::XPopupMenu*) this ),
245*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::awt::XPopupMenu*, this ),
246*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XTypeProvider*, this ),
247*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XServiceInfo*, this ),
248*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XUnoTunnel*, this ) );
249cdf0e10cSrcweir     else
250cdf0e10cSrcweir         aRet = ::cppu::queryInterface(  rType,
251*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::awt::XMenu*, (css::awt::XMenuBar*) this ),
252*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::awt::XMenuBar*, this ),
253*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XTypeProvider*, this ),
254*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XServiceInfo*, this ),
255*d026be40SAriel Constenla-Haile                                         SAL_STATIC_CAST( css::lang::XUnoTunnel*, this ) );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260*d026be40SAriel Constenla-Haile 
261cdf0e10cSrcweir IMPL_XUNOTUNNEL( VCLXMenu )
262cdf0e10cSrcweir 
263*d026be40SAriel Constenla-Haile 
264*d026be40SAriel Constenla-Haile css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes()
265*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
266cdf0e10cSrcweir {
267cdf0e10cSrcweir     ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
268cdf0e10cSrcweir     const sal_Bool bIsPopupMenu = IsPopupMenu();
269cdf0e10cSrcweir     aGuard.clear();
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     static ::cppu::OTypeCollection* pCollectionMenuBar = NULL;
272cdf0e10cSrcweir     static ::cppu::OTypeCollection* pCollectionPopupMenu = NULL;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     if ( bIsPopupMenu )
275cdf0e10cSrcweir     {
276cdf0e10cSrcweir         if( !pCollectionPopupMenu )
277cdf0e10cSrcweir         {
278cdf0e10cSrcweir             ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
279cdf0e10cSrcweir             if( !pCollectionPopupMenu )
280cdf0e10cSrcweir             {
281cdf0e10cSrcweir                 static ::cppu::OTypeCollection collectionPopupMenu(
282*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::lang::XTypeProvider>* ) NULL ),
283*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::awt::XMenu>* ) NULL ),
284*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::awt::XPopupMenu>* ) NULL ),
285*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::lang::XServiceInfo>* ) NULL ) );
286cdf0e10cSrcweir                 pCollectionPopupMenu = &collectionPopupMenu;
287cdf0e10cSrcweir             }
288cdf0e10cSrcweir         }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         return (*pCollectionPopupMenu).getTypes();
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir     else
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         if( !pCollectionMenuBar )
295cdf0e10cSrcweir         {
296cdf0e10cSrcweir             ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
297cdf0e10cSrcweir             if( !pCollectionMenuBar )
298cdf0e10cSrcweir             {
299cdf0e10cSrcweir                 static ::cppu::OTypeCollection collectionMenuBar(
300*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::lang::XTypeProvider>* ) NULL ),
301*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::awt::XMenu>* ) NULL ),
302*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::awt::XMenuBar>* ) NULL ),
303*d026be40SAriel Constenla-Haile                 getCppuType( ( css::uno::Reference< css::lang::XServiceInfo>* ) NULL ) );
304cdf0e10cSrcweir                 pCollectionMenuBar = &collectionMenuBar;
305cdf0e10cSrcweir             }
306cdf0e10cSrcweir         }
307cdf0e10cSrcweir         return (*pCollectionMenuBar).getTypes();
308cdf0e10cSrcweir     }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 
312*d026be40SAriel Constenla-Haile css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId()
313*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
314cdf0e10cSrcweir {
315cdf0e10cSrcweir     ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
316cdf0e10cSrcweir     const sal_Bool bIsPopupMenu = IsPopupMenu();
317cdf0e10cSrcweir     aGuard.clear();
318cdf0e10cSrcweir 
319cdf0e10cSrcweir     static ::cppu::OImplementationId* pIdMenuBar = NULL;
320cdf0e10cSrcweir     static ::cppu::OImplementationId* pIdPopupMenu = NULL;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     if ( bIsPopupMenu )
323cdf0e10cSrcweir     {
324cdf0e10cSrcweir         if( !pIdPopupMenu )
325cdf0e10cSrcweir         {
326cdf0e10cSrcweir             ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
327cdf0e10cSrcweir             if( !pIdPopupMenu )
328cdf0e10cSrcweir             {
329cdf0e10cSrcweir                 static ::cppu::OImplementationId idPopupMenu( sal_False );
330cdf0e10cSrcweir                 pIdPopupMenu = &idPopupMenu;
331cdf0e10cSrcweir             }
332cdf0e10cSrcweir         }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir         return (*pIdPopupMenu).getImplementationId();
335cdf0e10cSrcweir     }
336cdf0e10cSrcweir     else
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         if( !pIdMenuBar )
339cdf0e10cSrcweir         {
340cdf0e10cSrcweir             ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
341cdf0e10cSrcweir             if( !pIdMenuBar )
342cdf0e10cSrcweir             {
343cdf0e10cSrcweir                 static ::cppu::OImplementationId idMenuBar( sal_False );
344cdf0e10cSrcweir                 pIdMenuBar = &idMenuBar;
345cdf0e10cSrcweir             }
346cdf0e10cSrcweir         }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         return (*pIdMenuBar).getImplementationId();
349cdf0e10cSrcweir     }
350cdf0e10cSrcweir }
351cdf0e10cSrcweir 
352*d026be40SAriel Constenla-Haile void VCLXMenu::addMenuListener(
353*d026be40SAriel Constenla-Haile     const css::uno::Reference< css::awt::XMenuListener >& rxListener )
354*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     maMenuListeners.addInterface( rxListener );
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361*d026be40SAriel Constenla-Haile void VCLXMenu::removeMenuListener(
362*d026be40SAriel Constenla-Haile     const css::uno::Reference< css::awt::XMenuListener >& rxListener )
363*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     maMenuListeners.removeInterface( rxListener );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370*d026be40SAriel Constenla-Haile void VCLXMenu::insertItem(
371*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
372*d026be40SAriel Constenla-Haile     const OUString& aText,
373*d026be40SAriel Constenla-Haile     sal_Int16 nItemStyle,
374*d026be40SAriel Constenla-Haile     sal_Int16 nPos )
375*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
376cdf0e10cSrcweir {
377cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
378cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
379cdf0e10cSrcweir 
380cdf0e10cSrcweir     if ( mpMenu )
381cdf0e10cSrcweir         mpMenu->InsertItem( nItemId, aText, (MenuItemBits)nItemStyle, nPos );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384*d026be40SAriel Constenla-Haile void VCLXMenu::removeItem(
385*d026be40SAriel Constenla-Haile     sal_Int16 nPos,
386*d026be40SAriel Constenla-Haile     sal_Int16 nCount )
387*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
388cdf0e10cSrcweir {
389cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
390cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir     sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount();
393cdf0e10cSrcweir     if ( mpMenu && ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 ))
394cdf0e10cSrcweir     {
395cdf0e10cSrcweir         sal_Int16 nP = sal::static_int_cast< sal_Int16 >(
396cdf0e10cSrcweir             Min( (int)(nPos+nCount), (int)nItemCount ));
397cdf0e10cSrcweir         while( nP-nPos > 0 )
398cdf0e10cSrcweir             mpMenu->RemoveItem( --nP );
399cdf0e10cSrcweir     }
400cdf0e10cSrcweir }
401cdf0e10cSrcweir 
402*d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemCount(  )
403*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
406cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     return mpMenu ? mpMenu->GetItemCount() : 0;
409cdf0e10cSrcweir }
410cdf0e10cSrcweir 
411*d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemId(
412*d026be40SAriel Constenla-Haile     sal_Int16 nPos )
413*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
414cdf0e10cSrcweir {
415cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
416cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
417cdf0e10cSrcweir 
418cdf0e10cSrcweir     return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
421*d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getItemPos(
422*d026be40SAriel Constenla-Haile     sal_Int16 nId )
423*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
424cdf0e10cSrcweir {
425cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
426cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
427cdf0e10cSrcweir 
428cdf0e10cSrcweir     return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir 
431*d026be40SAriel Constenla-Haile void VCLXMenu::enableItem(
432*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
433*d026be40SAriel Constenla-Haile     sal_Bool bEnable )
434*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
435cdf0e10cSrcweir {
436cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
437cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
438cdf0e10cSrcweir 
439cdf0e10cSrcweir     if ( mpMenu )
440cdf0e10cSrcweir         mpMenu->EnableItem( nItemId, bEnable );
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443*d026be40SAriel Constenla-Haile sal_Bool VCLXMenu::isItemEnabled(
444*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
445*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
448cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     return mpMenu ? mpMenu->IsItemEnabled( nItemId ) : sal_False;
451cdf0e10cSrcweir }
452cdf0e10cSrcweir 
453*d026be40SAriel Constenla-Haile void VCLXMenu::setItemText(
454*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
455*d026be40SAriel Constenla-Haile     const OUString& aText )
456*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
457cdf0e10cSrcweir {
458cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
459cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     if ( mpMenu )
462cdf0e10cSrcweir         mpMenu->SetItemText( nItemId, aText );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir 
465*d026be40SAriel Constenla-Haile OUString VCLXMenu::getItemText(
466*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
467*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
470cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
471cdf0e10cSrcweir 
472*d026be40SAriel Constenla-Haile     OUString aItemText;
473cdf0e10cSrcweir     if ( mpMenu )
474cdf0e10cSrcweir         aItemText = mpMenu->GetItemText( nItemId );
475cdf0e10cSrcweir     return aItemText;
476cdf0e10cSrcweir }
477cdf0e10cSrcweir 
478*d026be40SAriel Constenla-Haile void VCLXMenu::setPopupMenu(
479*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
480*d026be40SAriel Constenla-Haile     const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu )
481*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
484cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir     VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu );
487cdf0e10cSrcweir     DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() )
490cdf0e10cSrcweir     {
491cdf0e10cSrcweir         // Selbst eine Ref halten!
492*d026be40SAriel Constenla-Haile         css::uno::Reference< css::awt::XPopupMenu > * pNewRef = new css::uno::Reference< css::awt::XPopupMenu > ;
493cdf0e10cSrcweir         *pNewRef = rxPopupMenu;
494cdf0e10cSrcweir         maPopupMenueRefs.Insert( pNewRef, LIST_APPEND );
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         mpMenu->SetPopupMenu( nItemId, (PopupMenu*) pVCLMenu->GetMenu() );
497cdf0e10cSrcweir     }
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500*d026be40SAriel Constenla-Haile css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu(
501*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
502*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
503cdf0e10cSrcweir {
504cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
505cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
506cdf0e10cSrcweir 
507*d026be40SAriel Constenla-Haile     css::uno::Reference< css::awt::XPopupMenu >  aRef;
508cdf0e10cSrcweir     Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : NULL;
509cdf0e10cSrcweir     if ( pMenu )
510cdf0e10cSrcweir     {
511cdf0e10cSrcweir         for ( sal_uInt32 n = maPopupMenueRefs.Count(); n; )
512cdf0e10cSrcweir         {
513*d026be40SAriel Constenla-Haile             css::uno::Reference< css::awt::XPopupMenu > * pRef = maPopupMenueRefs.GetObject( --n );
514cdf0e10cSrcweir             Menu* pM = ((VCLXMenu*)pRef->get())->GetMenu();
515cdf0e10cSrcweir             if ( pM == pMenu )
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 aRef = *pRef;
518cdf0e10cSrcweir                 break;
519cdf0e10cSrcweir             }
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir     }
522cdf0e10cSrcweir     return aRef;
523cdf0e10cSrcweir }
524cdf0e10cSrcweir 
525*d026be40SAriel Constenla-Haile // css::awt::XPopupMenu
526*d026be40SAriel Constenla-Haile void VCLXMenu::insertSeparator(
527*d026be40SAriel Constenla-Haile     sal_Int16 nPos )
528*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
531cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     if ( mpMenu )
534cdf0e10cSrcweir         mpMenu->InsertSeparator( nPos );
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537*d026be40SAriel Constenla-Haile void VCLXMenu::setDefaultItem(
538*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
539*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
540cdf0e10cSrcweir {
541cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
542cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
543cdf0e10cSrcweir 
544cdf0e10cSrcweir     if ( mpMenu )
545cdf0e10cSrcweir         mpMenu->SetDefaultItem( nItemId );
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548*d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::getDefaultItem(  )
549*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
550cdf0e10cSrcweir {
551cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
552cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
553cdf0e10cSrcweir 
554cdf0e10cSrcweir     return mpMenu ? mpMenu->GetDefaultItem() : 0;
555cdf0e10cSrcweir }
556cdf0e10cSrcweir 
557*d026be40SAriel Constenla-Haile void VCLXMenu::checkItem(
558*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
559*d026be40SAriel Constenla-Haile     sal_Bool bCheck )
560*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
563cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
564cdf0e10cSrcweir 
565cdf0e10cSrcweir     if ( mpMenu )
566cdf0e10cSrcweir         mpMenu->CheckItem( nItemId, bCheck );
567cdf0e10cSrcweir }
568cdf0e10cSrcweir 
569*d026be40SAriel Constenla-Haile sal_Bool VCLXMenu::isItemChecked(
570*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
571*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
572cdf0e10cSrcweir {
573cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
574cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
575cdf0e10cSrcweir 
576cdf0e10cSrcweir     return mpMenu ? mpMenu->IsItemChecked( nItemId ) : sal_False;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579*d026be40SAriel Constenla-Haile sal_Int16 VCLXMenu::execute(
580*d026be40SAriel Constenla-Haile     const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer,
581*d026be40SAriel Constenla-Haile     const css::awt::Point& rPos,
582*d026be40SAriel Constenla-Haile     sal_Int16 nFlags )
583*d026be40SAriel Constenla-Haile throw(css::uno::RuntimeException)
584cdf0e10cSrcweir {
585cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
586cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     sal_Int16 nRet = 0;
589cdf0e10cSrcweir     if ( mpMenu && IsPopupMenu() )
590*d026be40SAriel Constenla-Haile     {
591*d026be40SAriel Constenla-Haile         const ::Point aPoint = VCLPoint( rPos );
592*d026be40SAriel Constenla-Haile         nRet = ((PopupMenu*)mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ),
593*d026be40SAriel Constenla-Haile                                               ::Rectangle(aPoint,aPoint),
594*d026be40SAriel Constenla-Haile                                               nFlags | POPUPMENU_NOMOUSEUPCLOSE );
595*d026be40SAriel Constenla-Haile     }
596cdf0e10cSrcweir     return nRet;
597cdf0e10cSrcweir }
598cdf0e10cSrcweir 
599cdf0e10cSrcweir 
600*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setCommand(
601*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
602*d026be40SAriel Constenla-Haile     const OUString& aCommand )
603*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
606cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
607cdf0e10cSrcweir 
608cdf0e10cSrcweir     if ( mpMenu )
609cdf0e10cSrcweir         mpMenu->SetItemCommand( nItemId, aCommand );
610cdf0e10cSrcweir }
611cdf0e10cSrcweir 
612*d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getCommand(
613*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
614*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
617cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
618cdf0e10cSrcweir 
619*d026be40SAriel Constenla-Haile     OUString aItemCommand;
620cdf0e10cSrcweir     if ( mpMenu )
621cdf0e10cSrcweir         aItemCommand = mpMenu->GetItemCommand( nItemId );
622cdf0e10cSrcweir     return aItemCommand;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir 
625*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setHelpCommand(
626*d026be40SAriel Constenla-Haile     sal_Int16 nItemId,
627*d026be40SAriel Constenla-Haile     const OUString& aHelp )
628*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
629cdf0e10cSrcweir {
630cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
631cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
632cdf0e10cSrcweir 
633cdf0e10cSrcweir     if ( mpMenu )
634cdf0e10cSrcweir         mpMenu->SetHelpCommand( nItemId, aHelp );
635cdf0e10cSrcweir }
636cdf0e10cSrcweir 
637*d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getHelpCommand(
638*d026be40SAriel Constenla-Haile     sal_Int16 nItemId )
639*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
640cdf0e10cSrcweir {
641cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
642cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
643cdf0e10cSrcweir 
644*d026be40SAriel Constenla-Haile     OUString aHelpCommand;
645cdf0e10cSrcweir     if ( mpMenu )
646cdf0e10cSrcweir         aHelpCommand = mpMenu->GetHelpCommand( nItemId );
647cdf0e10cSrcweir     return aHelpCommand;
648cdf0e10cSrcweir }
649cdf0e10cSrcweir 
650cdf0e10cSrcweir 
651cdf0e10cSrcweir namespace
652cdf0e10cSrcweir {
653*d026be40SAriel Constenla-Haile     static Image lcl_XGraphic2VCLImage(
654cdf0e10cSrcweir         const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
655cdf0e10cSrcweir         sal_Bool bResize )
656cdf0e10cSrcweir     {
657cdf0e10cSrcweir         Image aImage;
658cdf0e10cSrcweir         if ( !xGraphic.is() )
659cdf0e10cSrcweir             return aImage;
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         aImage = Image( xGraphic );
662cdf0e10cSrcweir         const ::Size aCurSize = aImage.GetSizePixel();
663cdf0e10cSrcweir         const sal_Int32 nCurWidth = aCurSize.Width();
664cdf0e10cSrcweir         const sal_Int32 nCurHeight = aCurSize.Height();
665cdf0e10cSrcweir         const sal_Int32 nIdeal( 16 );
666cdf0e10cSrcweir 
667cdf0e10cSrcweir         if ( nCurWidth > 0 && nCurHeight > 0 )
668cdf0e10cSrcweir         {
669cdf0e10cSrcweir             if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) )
670cdf0e10cSrcweir             {
671cdf0e10cSrcweir                 sal_Int32 nIdealWidth  = nCurWidth  > nIdeal ? nIdeal : nCurWidth;
672cdf0e10cSrcweir                 sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight;
673cdf0e10cSrcweir 
674cdf0e10cSrcweir                 ::Size aNewSize( nIdealWidth, nIdealHeight );
675cdf0e10cSrcweir 
676cdf0e10cSrcweir                 sal_Bool bModified( sal_False );
677cdf0e10cSrcweir                 BitmapEx aBitmapEx = aImage.GetBitmapEx();
678cdf0e10cSrcweir                 bModified = aBitmapEx.Scale( aNewSize, BMP_SCALE_INTERPOLATE );
679cdf0e10cSrcweir 
680cdf0e10cSrcweir                 if ( bModified )
681cdf0e10cSrcweir                     aImage = Image( aBitmapEx );
682cdf0e10cSrcweir             }
683cdf0e10cSrcweir         }
684cdf0e10cSrcweir         return aImage;
685cdf0e10cSrcweir     }
686cdf0e10cSrcweir 
687*d026be40SAriel Constenla-Haile     /** Copied from svtools/inc/acceleratorexecute.hxx */
688*d026be40SAriel Constenla-Haile     static css::awt::KeyEvent lcl_VCLKey2AWTKey(
689*d026be40SAriel Constenla-Haile         const KeyCode& aVCLKey)
690cdf0e10cSrcweir     {
691cdf0e10cSrcweir         css::awt::KeyEvent aAWTKey;
692cdf0e10cSrcweir         aAWTKey.Modifiers = 0;
693cdf0e10cSrcweir         aAWTKey.KeyCode   = (sal_Int16)aVCLKey.GetCode();
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         if (aVCLKey.IsShift())
696cdf0e10cSrcweir             aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
697cdf0e10cSrcweir         if (aVCLKey.IsMod1())
698cdf0e10cSrcweir             aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
699cdf0e10cSrcweir         if (aVCLKey.IsMod2())
700cdf0e10cSrcweir             aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
701cdf0e10cSrcweir         if (aVCLKey.IsMod3())
702cdf0e10cSrcweir             aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
703cdf0e10cSrcweir 
704cdf0e10cSrcweir         return aAWTKey;
705cdf0e10cSrcweir     }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
708cdf0e10cSrcweir     {
709cdf0e10cSrcweir         sal_Bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
710cdf0e10cSrcweir         sal_Bool bMod1  = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1  );
711cdf0e10cSrcweir         sal_Bool bMod2  = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2  );
712cdf0e10cSrcweir         sal_Bool bMod3  = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3  );
713cdf0e10cSrcweir         sal_uInt16   nKey   = (sal_uInt16)aAWTKey.KeyCode;
714cdf0e10cSrcweir 
715cdf0e10cSrcweir         return KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
716cdf0e10cSrcweir     }
717cdf0e10cSrcweir 
718*d026be40SAriel Constenla-Haile }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 
721*d026be40SAriel Constenla-Haile ::sal_Bool SAL_CALL VCLXMenu::isPopupMenu(  )
722*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
723cdf0e10cSrcweir {
724cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
725cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
726cdf0e10cSrcweir     return IsPopupMenu();
727cdf0e10cSrcweir }
728cdf0e10cSrcweir 
729*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::clear(  )
730*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
731cdf0e10cSrcweir {
732cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
733cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
734cdf0e10cSrcweir     if ( mpMenu )
735cdf0e10cSrcweir         mpMenu->Clear();
736cdf0e10cSrcweir }
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 
739*d026be40SAriel Constenla-Haile css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType(
740*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemPos )
741*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
742cdf0e10cSrcweir {
743cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
744cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
745cdf0e10cSrcweir 
746*d026be40SAriel Constenla-Haile     css::awt::MenuItemType aMenuItemType =
747*d026be40SAriel Constenla-Haile         css::awt::MenuItemType_DONTKNOW;
748cdf0e10cSrcweir     if ( mpMenu )
749cdf0e10cSrcweir     {
750*d026be40SAriel Constenla-Haile         aMenuItemType = ( (css::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) );
751cdf0e10cSrcweir     }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir     return aMenuItemType;
754cdf0e10cSrcweir }
755cdf0e10cSrcweir 
756*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::hideDisabledEntries(
757*d026be40SAriel Constenla-Haile     ::sal_Bool bHide )
758*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
759cdf0e10cSrcweir {
760cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
761cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
762cdf0e10cSrcweir     if ( mpMenu )
763cdf0e10cSrcweir     {
764cdf0e10cSrcweir         if ( bHide )
765cdf0e10cSrcweir             mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
766cdf0e10cSrcweir         else
767cdf0e10cSrcweir             mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES );
768cdf0e10cSrcweir     }
769cdf0e10cSrcweir }
770cdf0e10cSrcweir 
771cdf0e10cSrcweir 
772cdf0e10cSrcweir ::sal_Bool SAL_CALL VCLXMenu::isInExecute(  )
773*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
776cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
777cdf0e10cSrcweir 
778cdf0e10cSrcweir     if ( mpMenu && IsPopupMenu() )
779cdf0e10cSrcweir         return ( (PopupMenu*) mpMenu )->IsInExecute();
780cdf0e10cSrcweir     else
781cdf0e10cSrcweir         return sal_False;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 
785cdf0e10cSrcweir void SAL_CALL VCLXMenu::endExecute()
786*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
787cdf0e10cSrcweir {
788cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
789cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     if ( mpMenu && IsPopupMenu() )
792cdf0e10cSrcweir         ( (PopupMenu*) mpMenu )->EndExecute();
793cdf0e10cSrcweir }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 
796*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::enableAutoMnemonics(
797*d026be40SAriel Constenla-Haile     ::sal_Bool bEnable )
798*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
799cdf0e10cSrcweir {
800cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
801cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
802cdf0e10cSrcweir     if ( mpMenu )
803cdf0e10cSrcweir     {
804cdf0e10cSrcweir         if ( !bEnable )
805cdf0e10cSrcweir             mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
806cdf0e10cSrcweir         else
807cdf0e10cSrcweir             mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS );
808cdf0e10cSrcweir     }
809cdf0e10cSrcweir }
810cdf0e10cSrcweir 
811cdf0e10cSrcweir 
812*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setAcceleratorKeyEvent(
813*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId,
814*d026be40SAriel Constenla-Haile     const css::awt::KeyEvent& aKeyEvent )
815*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
816cdf0e10cSrcweir {
817cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
818cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
819cdf0e10cSrcweir 
820*d026be40SAriel Constenla-Haile     if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
821cdf0e10cSrcweir     {
822cdf0e10cSrcweir         KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent );
823cdf0e10cSrcweir         mpMenu->SetAccelKey( nItemId, aVCLKeyCode );
824cdf0e10cSrcweir     }
825cdf0e10cSrcweir }
826cdf0e10cSrcweir 
827cdf0e10cSrcweir 
828*d026be40SAriel Constenla-Haile css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent(
829*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId )
830*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
831cdf0e10cSrcweir {
832cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
833cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
834cdf0e10cSrcweir 
835*d026be40SAriel Constenla-Haile     css::awt::KeyEvent aKeyEvent;
836*d026be40SAriel Constenla-Haile     if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId );
839cdf0e10cSrcweir         aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode );
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     return aKeyEvent;
843cdf0e10cSrcweir }
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 
846*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setHelpText(
847*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId,
848*d026be40SAriel Constenla-Haile     const OUString& sHelpText )
849*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
852cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
853cdf0e10cSrcweir 
854*d026be40SAriel Constenla-Haile     if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
855cdf0e10cSrcweir     {
856cdf0e10cSrcweir         mpMenu->SetHelpText( nItemId, sHelpText );
857cdf0e10cSrcweir     }
858cdf0e10cSrcweir }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 
861*d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getHelpText(
862*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId )
863*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
864cdf0e10cSrcweir {
865cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
866cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
867cdf0e10cSrcweir 
868cdf0e10cSrcweir     rtl::OUString sHelpText;
869*d026be40SAriel Constenla-Haile     if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
870cdf0e10cSrcweir     {
871cdf0e10cSrcweir         sHelpText = mpMenu->GetHelpText( nItemId );
872cdf0e10cSrcweir     }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir     return sHelpText;
875cdf0e10cSrcweir }
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 
878*d026be40SAriel Constenla-Haile void SAL_CALL VCLXMenu::setTipHelpText(
879*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId,
880*d026be40SAriel Constenla-Haile     const OUString& sTipHelpText )
881*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
882cdf0e10cSrcweir {
883cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
884cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
885cdf0e10cSrcweir 
886*d026be40SAriel Constenla-Haile     if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
887cdf0e10cSrcweir     {
888cdf0e10cSrcweir         mpMenu->SetTipHelpText( nItemId, sTipHelpText );
889cdf0e10cSrcweir     }
890cdf0e10cSrcweir }
891cdf0e10cSrcweir 
892cdf0e10cSrcweir 
893*d026be40SAriel Constenla-Haile OUString SAL_CALL VCLXMenu::getTipHelpText(
894*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId )
895*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
896cdf0e10cSrcweir {
897cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
898cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
899cdf0e10cSrcweir 
900cdf0e10cSrcweir     rtl::OUString sTipHelpText;
901*d026be40SAriel Constenla-Haile     if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
902cdf0e10cSrcweir     {
903cdf0e10cSrcweir         sTipHelpText = mpMenu->GetTipHelpText( nItemId );
904cdf0e10cSrcweir     }
905cdf0e10cSrcweir     return sTipHelpText;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 
909cdf0e10cSrcweir void SAL_CALL VCLXMenu::setItemImage(
910cdf0e10cSrcweir     ::sal_Int16 nItemId,
911*d026be40SAriel Constenla-Haile     const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
912*d026be40SAriel Constenla-Haile     ::sal_Bool bScale )
913*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
914cdf0e10cSrcweir {
915cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
916cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
917cdf0e10cSrcweir 
918*d026be40SAriel Constenla-Haile     if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
919cdf0e10cSrcweir     {
920cdf0e10cSrcweir         Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale );
921cdf0e10cSrcweir         mpMenu->SetItemImage( nItemId, aImage );
922cdf0e10cSrcweir     }
923cdf0e10cSrcweir }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 
926*d026be40SAriel Constenla-Haile css::uno::Reference< css::graphic::XGraphic > SAL_CALL
927*d026be40SAriel Constenla-Haile VCLXMenu::getItemImage(
928*d026be40SAriel Constenla-Haile     ::sal_Int16 nItemId )
929*d026be40SAriel Constenla-Haile throw (css::uno::RuntimeException)
930cdf0e10cSrcweir {
931cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
932cdf0e10cSrcweir     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
933cdf0e10cSrcweir 
934*d026be40SAriel Constenla-Haile     css::uno::Reference< css::graphic::XGraphic > rxGraphic;
935cdf0e10cSrcweir 
936*d026be40SAriel Constenla-Haile     if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
937cdf0e10cSrcweir     {
938cdf0e10cSrcweir         Image aImage = mpMenu->GetItemImage( nItemId );
939cdf0e10cSrcweir         if ( !!aImage )
940cdf0e10cSrcweir             rxGraphic = aImage.GetXGraphic();
941cdf0e10cSrcweir     }
942cdf0e10cSrcweir     return rxGraphic;
943cdf0e10cSrcweir }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 
947cdf0e10cSrcweir DBG_NAME(VCLXMenuBar);
948cdf0e10cSrcweir 
949cdf0e10cSrcweir VCLXMenuBar::VCLXMenuBar()
950cdf0e10cSrcweir {
951cdf0e10cSrcweir     DBG_CTOR( VCLXMenuBar, 0 );
952cdf0e10cSrcweir     ImplCreateMenu( sal_False );
953cdf0e10cSrcweir }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( (Menu *)pMenuBar )
956cdf0e10cSrcweir {
957cdf0e10cSrcweir     DBG_CTOR( VCLXMenuBar, 0 );
958cdf0e10cSrcweir }
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 
961cdf0e10cSrcweir DBG_NAME(VCLXPopupMenu);
962cdf0e10cSrcweir 
963cdf0e10cSrcweir VCLXPopupMenu::VCLXPopupMenu()
964cdf0e10cSrcweir {
965cdf0e10cSrcweir     DBG_CTOR( VCLXPopupMenu, 0 );
966cdf0e10cSrcweir     ImplCreateMenu( sal_True );
967cdf0e10cSrcweir }
968