Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <toolkit/awt/vclxmenu.hxx>
30 : : #include <toolkit/helper/macros.hxx>
31 : : #include <toolkit/helper/servicenames.hxx>
32 : : #include <toolkit/helper/vclunohelper.hxx>
33 : : #include <toolkit/helper/convert.hxx>
34 : : #include <cppuhelper/typeprovider.hxx>
35 : : #include <rtl/memory.h>
36 : : #include <rtl/uuid.h>
37 : : #include <osl/mutex.hxx>
38 : :
39 : : #include <vcl/menu.hxx>
40 : : #include <vcl/keycod.hxx>
41 : : #include <vcl/image.hxx>
42 : : #include <vcl/mnemonic.hxx>
43 : : #include <vcl/svapp.hxx>
44 : :
45 : : #include <com/sun/star/awt/KeyModifier.hpp>
46 : :
47 : :
48 : : #ifdef DBG_UTIL
49 : : #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
50 : : if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
51 : : throw ::com::sun::star::container::NoSuchElementException( \
52 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
53 : : += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item with " ) ) \
54 : : += ::rtl::OUString::valueOf( sal_Int32( nItemId ) ) \
55 : : += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " as identifier" ) ), \
56 : : *this \
57 : : );
58 : : #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
59 : : if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
60 : : throw ::com::sun::star::container::NoSuchElementException( \
61 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( Func ) ) \
62 : : += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ": There is no menu item at position " ) ) \
63 : : += ::rtl::OUString::valueOf( sal_Int32( nPos ) ), \
64 : : *this \
65 : : );
66 : : #else
67 : : #define THROW_MENUITEM_NOT_FOUND( Func, nItemId ) \
68 : : if ( MENU_ITEM_NOTFOUND == mpMenu->GetItemPos( nItemId ) ) \
69 : : throw ::com::sun::star::container::NoSuchElementException();
70 : : #define THROW_MENUPOS_NOT_FOUND( Func, nPos ) \
71 : : if ( MENU_ITEM_NOTFOUND == sal_uInt16( nPos ) ) \
72 : : throw ::com::sun::star::container::NoSuchElementException();
73 : : #endif
74 : :
75 : :
76 : : // ----------------------------------------------------
77 : : // class VCLXMenu
78 : : // ----------------------------------------------------
79 : :
80 : : DBG_NAME(VCLXMenu)
81 : :
82 [ + - ][ + - ]: 10788 : VCLXMenu::VCLXMenu() : maMenuListeners( *this )
[ + - ]
83 : : {
84 : : DBG_CTOR( VCLXMenu, 0 );
85 : 10788 : mpMenu = NULL;
86 : 10788 : }
87 : :
88 [ + - ][ + - ]: 1709 : VCLXMenu::VCLXMenu( Menu* pMenu ) : maMenuListeners( *this )
[ + - ]
89 : : {
90 : : DBG_CTOR( VCLXMenu, 0 );
91 : 1709 : mpMenu = pMenu;
92 : 1709 : }
93 : :
94 [ + - ][ + - ]: 12406 : VCLXMenu::~VCLXMenu()
[ + - ]
95 : : {
96 : : DBG_DTOR( VCLXMenu, 0 );
97 [ - + ]: 12406 : for ( size_t n = maPopupMenueRefs.size(); n; ) {
98 [ # # ]: 0 : delete maPopupMenueRefs[ --n ];
99 : : }
100 [ + - ]: 12406 : if ( mpMenu )
101 : : {
102 [ + - ][ + - ]: 12406 : mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
103 [ + - ][ + - ]: 12406 : delete mpMenu;
104 : : }
105 [ - + ]: 12406 : }
106 : :
107 : 15882 : sal_Bool VCLXMenu::IsPopupMenu() const
108 : : {
109 [ + - ][ + + ]: 15882 : return (mpMenu && ! mpMenu->IsMenuBar());
110 : : }
111 : :
112 : 10788 : void VCLXMenu::ImplCreateMenu( sal_Bool bPopup )
113 : : {
114 : : DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" );
115 : :
116 [ + - ]: 10788 : if ( bPopup )
117 [ + - ]: 10788 : mpMenu = new PopupMenu;
118 : : else
119 [ # # ]: 0 : mpMenu = new MenuBar;
120 : :
121 [ + - ]: 10788 : mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
122 : 10788 : }
123 : :
124 : 56 : IMPL_LINK( VCLXMenu, MenuEventListener, VclSimpleEvent*, pEvent )
125 : : {
126 : : DBG_ASSERT( pEvent && pEvent->ISA( VclMenuEvent ), "Unknown Event!" );
127 [ + - ][ + - ]: 56 : if ( pEvent && pEvent->ISA( VclMenuEvent ) )
[ + - ]
128 : : {
129 : : DBG_ASSERT( ((VclMenuEvent*)pEvent)->GetMenu() && mpMenu, "Menu???" );
130 : :
131 : 56 : VclMenuEvent* pMenuEvent = (VclMenuEvent*)pEvent;
132 [ + - ]: 56 : if ( pMenuEvent->GetMenu() == mpMenu ) // Also called for the root menu
133 : : {
134 [ - - - - : 56 : switch ( pMenuEvent->GetId() )
- + - ]
135 : : {
136 : : case VCLEVENT_MENU_SELECT:
137 : : {
138 [ # # ]: 0 : if ( maMenuListeners.getLength() )
139 : : {
140 [ # # ]: 0 : ::com::sun::star::awt::MenuEvent aEvent;
141 [ # # ]: 0 : aEvent.Source = (::cppu::OWeakObject*)this;
142 [ # # ]: 0 : aEvent.MenuId = mpMenu->GetCurItemId();
143 [ # # ][ # # ]: 0 : maMenuListeners.select( aEvent );
144 : : }
145 : : }
146 : 0 : break;
147 : : case VCLEVENT_OBJECT_DYING:
148 : : {
149 : 0 : mpMenu = NULL;
150 : : }
151 : 0 : break;
152 : : case VCLEVENT_MENU_HIGHLIGHT:
153 : : {
154 [ # # ]: 0 : if ( maMenuListeners.getLength() )
155 : : {
156 [ # # ]: 0 : ::com::sun::star::awt::MenuEvent aEvent;
157 [ # # ]: 0 : aEvent.Source = (::cppu::OWeakObject*)this;
158 [ # # ]: 0 : aEvent.MenuId = mpMenu->GetCurItemId();
159 [ # # ][ # # ]: 0 : maMenuListeners.highlight( aEvent );
160 : : }
161 : : }
162 : 0 : break;
163 : : case VCLEVENT_MENU_ACTIVATE:
164 : : {
165 [ # # ]: 0 : if ( maMenuListeners.getLength() )
166 : : {
167 [ # # ]: 0 : ::com::sun::star::awt::MenuEvent aEvent;
168 [ # # ]: 0 : aEvent.Source = (::cppu::OWeakObject*)this;
169 [ # # ]: 0 : aEvent.MenuId = mpMenu->GetCurItemId();
170 [ # # ][ # # ]: 0 : maMenuListeners.activate( aEvent );
171 : : }
172 : : }
173 : 0 : break;
174 : : case VCLEVENT_MENU_DEACTIVATE:
175 : : {
176 [ # # ]: 0 : if ( maMenuListeners.getLength() )
177 : : {
178 [ # # ]: 0 : ::com::sun::star::awt::MenuEvent aEvent;
179 [ # # ]: 0 : aEvent.Source = (::cppu::OWeakObject*)this;
180 [ # # ]: 0 : aEvent.MenuId = mpMenu->GetCurItemId();
181 [ # # ][ # # ]: 0 : maMenuListeners.deactivate( aEvent );
182 : : }
183 : : }
184 : 0 : break;
185 : :
186 : : // ignore accessibility events
187 : : case VCLEVENT_MENU_ENABLE:
188 : : case VCLEVENT_MENU_INSERTITEM:
189 : : case VCLEVENT_MENU_REMOVEITEM:
190 : : case VCLEVENT_MENU_SUBMENUACTIVATE:
191 : : case VCLEVENT_MENU_SUBMENUDEACTIVATE:
192 : : case VCLEVENT_MENU_SUBMENUCHANGED:
193 : : case VCLEVENT_MENU_DEHIGHLIGHT:
194 : : case VCLEVENT_MENU_DISABLE:
195 : : case VCLEVENT_MENU_ITEMTEXTCHANGED:
196 : : case VCLEVENT_MENU_ITEMCHECKED:
197 : : case VCLEVENT_MENU_ITEMUNCHECKED:
198 : : case VCLEVENT_MENU_SHOW:
199 : : case VCLEVENT_MENU_HIDE:
200 : 56 : break;
201 : :
202 : : default: OSL_FAIL( "MenuEventListener - Unknown event!" );
203 : : }
204 : : }
205 : : }
206 : 56 : return 0;
207 : : }
208 : :
209 : :
210 : : //=============================================================================
211 : : //=============================================================================
212 : : //=============================================================================
213 : :
214 : :
215 : : // ::com::sun::star::lang::XServiceInfo
216 : 0 : ::rtl::OUString SAL_CALL VCLXMenu::getImplementationName( )
217 : : throw (::com::sun::star::uno::RuntimeException)
218 : : {
219 [ # # ]: 0 : ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
220 [ # # ]: 0 : const sal_Bool bIsPopupMenu = IsPopupMenu();
221 [ # # ]: 0 : aGuard.clear();
222 : :
223 [ # # ]: 0 : ::rtl::OUString implName( RTL_CONSTASCII_USTRINGPARAM( "stardiv.Toolkit." ) );
224 [ # # ]: 0 : if ( bIsPopupMenu )
225 [ # # ]: 0 : implName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXPopupMenu" ) );
226 : : else
227 [ # # ]: 0 : implName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VCLXMenuBar" ) );
228 : :
229 [ # # ]: 0 : return implName;
230 : : }
231 : :
232 : :
233 : 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
234 : : throw (::com::sun::star::uno::RuntimeException)
235 : : {
236 [ # # ]: 0 : ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
237 [ # # ]: 0 : const sal_Bool bIsPopupMenu = IsPopupMenu();
238 [ # # ]: 0 : aGuard.clear();
239 : :
240 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames( 1 );
241 [ # # ]: 0 : if ( bIsPopupMenu )
242 [ # # ]: 0 : aNames[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_PopupMenu );
243 : : else
244 [ # # ]: 0 : aNames[ 0 ] = ::rtl::OUString::createFromAscii( szServiceName2_MenuBar );
245 : :
246 [ # # ]: 0 : return aNames;
247 : : }
248 : :
249 : :
250 : 0 : ::sal_Bool SAL_CALL VCLXMenu::supportsService( const ::rtl::OUString& rServiceName )
251 : : throw (::com::sun::star::uno::RuntimeException)
252 : : {
253 [ # # ]: 0 : ::com::sun::star::uno::Sequence< ::rtl::OUString > aServiceNames( getSupportedServiceNames() );
254 : :
255 [ # # ][ # # ]: 0 : if ( aServiceNames[ 0 ] == rServiceName )
256 : 0 : return sal_True;
257 : :
258 [ # # ]: 0 : return sal_False;
259 : : }
260 : :
261 : :
262 : : // ::com::sun::star::uno::XInterface
263 : 15882 : ::com::sun::star::uno::Any VCLXMenu::queryInterface( const ::com::sun::star::uno::Type & rType )
264 : : throw(::com::sun::star::uno::RuntimeException)
265 : : {
266 [ + - ]: 15882 : ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
267 [ + - ]: 15882 : const sal_Bool bIsPopupMenu = IsPopupMenu();
268 [ + - ]: 15882 : aGuard.clear();
269 : :
270 : 15882 : ::com::sun::star::uno::Any aRet;
271 : :
272 [ + + ]: 15882 : if ( bIsPopupMenu )
273 : : aRet = ::cppu::queryInterface( rType,
274 : : (static_cast< ::com::sun::star::awt::XMenu* >((::com::sun::star::awt::XMenuBar*) this) ),
275 : : (static_cast< ::com::sun::star::awt::XPopupMenu* >(this)),
276 : : (static_cast< ::com::sun::star::awt::XPopupMenuExtended* >(this)),
277 : : (static_cast< ::com::sun::star::awt::XMenuExtended* >((::com::sun::star::awt::XPopupMenuExtended*) this) ),
278 : : (static_cast< ::com::sun::star::awt::XMenuExtended2* >((::com::sun::star::awt::XPopupMenuExtended*) this) ),
279 : : (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)),
280 : : (static_cast< ::com::sun::star::lang::XServiceInfo* >(this)),
281 [ + - ]: 10846 : (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)) );
282 : : else
283 : : aRet = ::cppu::queryInterface( rType,
284 : : (static_cast< ::com::sun::star::awt::XMenu* >((::com::sun::star::awt::XMenuBar*) this) ),
285 : : (static_cast< ::com::sun::star::awt::XMenuBar* >(this)),
286 : : (static_cast< ::com::sun::star::awt::XMenuBarExtended* >(this)),
287 : : (static_cast< ::com::sun::star::awt::XMenuExtended* >((::com::sun::star::awt::XMenuBarExtended*) this) ),
288 : : (static_cast< ::com::sun::star::awt::XMenuExtended2* >((::com::sun::star::awt::XMenuBarExtended*) this) ),
289 : : (static_cast< ::com::sun::star::lang::XTypeProvider* >(this)),
290 : : (static_cast< ::com::sun::star::lang::XServiceInfo* >(this)),
291 [ + - ]: 5036 : (static_cast< ::com::sun::star::lang::XUnoTunnel* >(this)) );
292 : :
293 [ + - ][ # # ]: 15882 : return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
[ + - ]
294 : : }
295 : :
296 : : // ::com::sun::star::lang::XUnoTunnel
297 [ + - ][ + + ]: 15220 : IMPL_XUNOTUNNEL( VCLXMenu )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
298 : :
299 : : // ::com::sun::star::lang::XTypeProvider
300 : 0 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > VCLXMenu::getTypes()
301 : : throw(::com::sun::star::uno::RuntimeException)
302 : : {
303 [ # # ]: 0 : ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
304 [ # # ]: 0 : const sal_Bool bIsPopupMenu = IsPopupMenu();
305 [ # # ]: 0 : aGuard.clear();
306 : :
307 : : static ::cppu::OTypeCollection* pCollectionMenuBar = NULL;
308 : : static ::cppu::OTypeCollection* pCollectionPopupMenu = NULL;
309 : :
310 [ # # ]: 0 : if ( bIsPopupMenu )
311 : : {
312 [ # # ]: 0 : if( !pCollectionPopupMenu )
313 : : {
314 [ # # ][ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
315 [ # # ]: 0 : if( !pCollectionPopupMenu )
316 : : {
317 : : static ::cppu::OTypeCollection collectionPopupMenu(
318 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
319 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenu>* ) NULL ),
320 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu>* ) NULL ),
321 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenuExtended>* ) NULL ),
322 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended>* ) NULL ),
323 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended2>* ) NULL ),
324 [ # # ][ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
325 : 0 : pCollectionPopupMenu = &collectionPopupMenu;
326 [ # # ]: 0 : }
327 : : }
328 : :
329 [ # # ]: 0 : return (*pCollectionPopupMenu).getTypes();
330 : : }
331 : : else
332 : : {
333 [ # # ]: 0 : if( !pCollectionMenuBar )
334 : : {
335 [ # # ][ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
336 [ # # ]: 0 : if( !pCollectionMenuBar )
337 : : {
338 : : static ::cppu::OTypeCollection collectionMenuBar(
339 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider>* ) NULL ),
340 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenu>* ) NULL ),
341 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBar>* ) NULL ),
342 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuBarExtended>* ) NULL ),
343 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended>* ) NULL ),
344 [ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuExtended2>* ) NULL ),
345 [ # # ][ # # ]: 0 : getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
346 : 0 : pCollectionMenuBar = &collectionMenuBar;
347 [ # # ]: 0 : }
348 : : }
349 [ # # ]: 0 : return (*pCollectionMenuBar).getTypes();
350 [ # # ]: 0 : }
351 : : }
352 : :
353 : :
354 : 0 : ::com::sun::star::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId()
355 : : throw(::com::sun::star::uno::RuntimeException)
356 : : {
357 [ # # ]: 0 : ::osl::ResettableGuard < ::osl::Mutex > aGuard( GetMutex() );
358 [ # # ]: 0 : const sal_Bool bIsPopupMenu = IsPopupMenu();
359 [ # # ]: 0 : aGuard.clear();
360 : :
361 : : static ::cppu::OImplementationId* pIdMenuBar = NULL;
362 : : static ::cppu::OImplementationId* pIdPopupMenu = NULL;
363 : :
364 [ # # ]: 0 : if ( bIsPopupMenu )
365 : : {
366 [ # # ]: 0 : if( !pIdPopupMenu )
367 : : {
368 [ # # ][ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
369 [ # # ]: 0 : if( !pIdPopupMenu )
370 : : {
371 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId idPopupMenu( sal_False );
372 : 0 : pIdPopupMenu = &idPopupMenu;
373 [ # # ]: 0 : }
374 : : }
375 : :
376 [ # # ]: 0 : return (*pIdPopupMenu).getImplementationId();
377 : : }
378 : : else
379 : : {
380 [ # # ]: 0 : if( !pIdMenuBar )
381 : : {
382 [ # # ][ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGlobalGuard( ::osl::Mutex::getGlobalMutex() );
383 [ # # ]: 0 : if( !pIdMenuBar )
384 : : {
385 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId idMenuBar( sal_False );
386 : 0 : pIdMenuBar = &idMenuBar;
387 [ # # ]: 0 : }
388 : : }
389 : :
390 [ # # ]: 0 : return (*pIdMenuBar).getImplementationId();
391 [ # # ]: 0 : }
392 : : }
393 : :
394 : :
395 : : //=============================================================================
396 : : //=============================================================================
397 : : //=============================================================================
398 : :
399 : :
400 : 6 : void VCLXMenu::addMenuListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
401 : : {
402 [ + - ]: 6 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
403 : :
404 [ + - ][ + - ]: 6 : maMenuListeners.addInterface( rxListener );
405 : 6 : }
406 : :
407 : 6 : void VCLXMenu::removeMenuListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XMenuListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
408 : : {
409 [ + - ]: 6 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
410 : :
411 [ + - ][ + - ]: 6 : maMenuListeners.removeInterface( rxListener );
412 : 6 : }
413 : :
414 : 50 : void VCLXMenu::insertItem( sal_Int16 nItemId, const ::rtl::OUString& aText, sal_Int16 nItemStyle, sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException)
415 : : {
416 [ + - ]: 50 : SolarMutexGuard aSolarGuard;
417 [ + - ]: 50 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
418 : :
419 [ + - ]: 50 : if ( mpMenu )
420 [ + - ][ + - ]: 50 : mpMenu->InsertItem( nItemId, aText, (MenuItemBits)nItemStyle, nPos );
[ + - ][ + - ]
[ + - ]
421 : 50 : }
422 : :
423 : 0 : void VCLXMenu::removeItem( sal_Int16 nPos, sal_Int16 nCount ) throw(::com::sun::star::uno::RuntimeException)
424 : : {
425 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
426 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
427 : :
428 [ # # ]: 0 : sal_Int32 nItemCount = (sal_Int32)mpMenu->GetItemCount();
429 [ # # ][ # # ]: 0 : if ( mpMenu && ( nCount > 0 ) && ( nPos >= 0 ) && ( nPos < nItemCount ) && ( nItemCount > 0 ))
[ # # ][ # # ]
[ # # ]
430 : : {
431 : : sal_Int16 nP = sal::static_int_cast< sal_Int16 >(
432 : 0 : Min( (int)(nPos+nCount), (int)nItemCount ));
433 [ # # ]: 0 : while( nP-nPos > 0 )
434 [ # # ]: 0 : mpMenu->RemoveItem( --nP );
435 [ # # ][ # # ]: 0 : }
436 : 0 : }
437 : :
438 : 56 : sal_Int16 VCLXMenu::getItemCount( ) throw(::com::sun::star::uno::RuntimeException)
439 : : {
440 [ + - ]: 56 : SolarMutexGuard aSolarGuard;
441 [ + - ]: 56 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
442 : :
443 [ + - ][ + - ]: 56 : return mpMenu ? mpMenu->GetItemCount() : 0;
[ + - ][ + - ]
444 : : }
445 : :
446 : 0 : sal_Int16 VCLXMenu::getItemId( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException)
447 : : {
448 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
449 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
450 : :
451 [ # # ][ # # ]: 0 : return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
[ # # ][ # # ]
452 : : }
453 : :
454 : 0 : sal_Int16 VCLXMenu::getItemPos( sal_Int16 nId ) throw(::com::sun::star::uno::RuntimeException)
455 : : {
456 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
457 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
458 : :
459 [ # # ][ # # ]: 0 : return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
[ # # ][ # # ]
460 : : }
461 : :
462 : 0 : void VCLXMenu::enableItem( sal_Int16 nItemId, sal_Bool bEnable ) throw(::com::sun::star::uno::RuntimeException)
463 : : {
464 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
465 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
466 : :
467 [ # # ]: 0 : if ( mpMenu )
468 [ # # ][ # # ]: 0 : mpMenu->EnableItem( nItemId, bEnable );
[ # # ]
469 : 0 : }
470 : :
471 : 0 : sal_Bool VCLXMenu::isItemEnabled( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException)
472 : : {
473 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
474 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
475 : :
476 [ # # ][ # # ]: 0 : return mpMenu ? mpMenu->IsItemEnabled( nItemId ) : sal_False;
[ # # ][ # # ]
477 : : }
478 : :
479 : 0 : void VCLXMenu::setItemText( sal_Int16 nItemId, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
480 : : {
481 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
482 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
483 : :
484 [ # # ]: 0 : if ( mpMenu )
485 [ # # ][ # # ]: 0 : mpMenu->SetItemText( nItemId, aText );
[ # # ][ # # ]
[ # # ]
486 : 0 : }
487 : :
488 : 0 : ::rtl::OUString VCLXMenu::getItemText( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException)
489 : : {
490 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
491 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
492 : :
493 : 0 : ::rtl::OUString aItemText;
494 [ # # ]: 0 : if ( mpMenu )
495 [ # # ][ # # ]: 0 : aItemText = mpMenu->GetItemText( nItemId );
[ # # ]
496 [ # # ][ # # ]: 0 : return aItemText;
497 : : }
498 : :
499 : 0 : void VCLXMenu::setPopupMenu( sal_Int16 nItemId, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu >& rxPopupMenu ) throw(::com::sun::star::uno::RuntimeException)
500 : : {
501 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
502 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
503 : :
504 : 0 : VCLXMenu* pVCLMenu = VCLXMenu::GetImplementation( rxPopupMenu );
505 : : DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
506 : :
507 [ # # ][ # # ]: 0 : if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() )
[ # # ][ # # ]
[ # # ][ # # ]
508 : : {
509 : : // Selbst eine Ref halten!
510 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pNewRef = new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > ;
511 [ # # ]: 0 : *pNewRef = rxPopupMenu;
512 [ # # ]: 0 : maPopupMenueRefs.push_back( pNewRef );
513 : :
514 [ # # ]: 0 : mpMenu->SetPopupMenu( nItemId, (PopupMenu*) pVCLMenu->GetMenu() );
515 [ # # ][ # # ]: 0 : }
516 : 0 : }
517 : :
518 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > VCLXMenu::getPopupMenu( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException)
519 : : {
520 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
521 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
522 : :
523 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > aRef;
524 [ # # ][ # # ]: 0 : Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : NULL;
525 [ # # ]: 0 : if ( pMenu )
526 : : {
527 [ # # ]: 0 : for ( size_t n = maPopupMenueRefs.size(); n; )
528 : : {
529 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pRef = maPopupMenueRefs[ --n ];
530 [ # # ][ # # ]: 0 : Menu* pM = ((VCLXMenu*)pRef->get())->GetMenu();
531 [ # # ]: 0 : if ( pM == pMenu )
532 : : {
533 [ # # ]: 0 : aRef = *pRef;
534 : 0 : break;
535 : : }
536 : : }
537 : : // it seems the popup menu is not insert into maPopupMenueRefs
538 : : // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
539 [ # # ]: 0 : if( !aRef.is() )
540 : : {
541 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > * pNewRef = new ::com::sun::star::uno::Reference< ::com::sun::star::awt::XPopupMenu > ;
542 [ # # ][ # # ]: 0 : *pNewRef = new VCLXPopupMenu( (PopupMenu*)pMenu );
[ # # ]
543 [ # # ]: 0 : aRef = *pNewRef;
544 : : }
545 : : }
546 [ # # ][ # # ]: 0 : return aRef;
547 : : }
548 : :
549 : : // ::com::sun::star::awt::XPopupMenu
550 : 2 : void VCLXMenu::insertSeparator( sal_Int16 nPos ) throw(::com::sun::star::uno::RuntimeException)
551 : : {
552 [ + - ]: 2 : SolarMutexGuard aSolarGuard;
553 [ + - ]: 2 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
554 : :
555 [ + - ]: 2 : if ( mpMenu )
556 [ + - ][ + - ]: 2 : mpMenu->InsertSeparator( nPos );
[ + - ]
557 : 2 : }
558 : :
559 : 0 : void VCLXMenu::setDefaultItem( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException)
560 : : {
561 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
562 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
563 : :
564 [ # # ]: 0 : if ( mpMenu )
565 [ # # ][ # # ]: 0 : mpMenu->SetDefaultItem( nItemId );
566 : 0 : }
567 : :
568 : 0 : sal_Int16 VCLXMenu::getDefaultItem( ) throw(::com::sun::star::uno::RuntimeException)
569 : : {
570 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
571 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
572 : :
573 [ # # ][ # # ]: 0 : return mpMenu ? mpMenu->GetDefaultItem() : 0;
[ # # ]
574 : : }
575 : :
576 : 4 : void VCLXMenu::checkItem( sal_Int16 nItemId, sal_Bool bCheck ) throw(::com::sun::star::uno::RuntimeException)
577 : : {
578 [ + - ]: 4 : SolarMutexGuard aSolarGuard;
579 [ + - ]: 4 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
580 : :
581 [ + - ]: 4 : if ( mpMenu )
582 [ + - ][ + - ]: 4 : mpMenu->CheckItem( nItemId, bCheck );
[ + - ]
583 : 4 : }
584 : :
585 : 0 : sal_Bool VCLXMenu::isItemChecked( sal_Int16 nItemId ) throw(::com::sun::star::uno::RuntimeException)
586 : : {
587 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
588 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
589 : :
590 [ # # ][ # # ]: 0 : return mpMenu ? mpMenu->IsItemChecked( nItemId ) : sal_False;
[ # # ][ # # ]
591 : : }
592 : :
593 : 0 : sal_Int16 VCLXMenu::execute( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >& rxWindowPeer, const ::com::sun::star::awt::Rectangle& rArea, sal_Int16 nFlags ) throw(::com::sun::star::uno::RuntimeException)
594 : : {
595 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
596 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
597 : :
598 : 0 : sal_Int16 nRet = 0;
599 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
600 [ # # ][ # # ]: 0 : nRet = ((PopupMenu*)mpMenu)->Execute( VCLUnoHelper::GetWindow( rxWindowPeer ), VCLRectangle(rArea), nFlags | POPUPMENU_NOMOUSEUPCLOSE );
[ # # ]
601 [ # # ][ # # ]: 0 : return nRet;
602 : : }
603 : :
604 : :
605 : 50 : void SAL_CALL VCLXMenu::setCommand( sal_Int16 nItemId, const ::rtl::OUString& aCommand ) throw (::com::sun::star::uno::RuntimeException)
606 : : {
607 [ + - ]: 50 : SolarMutexGuard aSolarGuard;
608 [ + - ]: 50 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
609 : :
610 [ + - ]: 50 : if ( mpMenu )
611 [ + - ][ + - ]: 50 : mpMenu->SetItemCommand( nItemId, aCommand );
[ + - ][ + - ]
[ + - ]
612 : 50 : }
613 : :
614 : 0 : ::rtl::OUString SAL_CALL VCLXMenu::getCommand( sal_Int16 nItemId ) throw (::com::sun::star::uno::RuntimeException)
615 : : {
616 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
617 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
618 : :
619 : 0 : ::rtl::OUString aItemCommand;
620 [ # # ]: 0 : if ( mpMenu )
621 [ # # ][ # # ]: 0 : aItemCommand = mpMenu->GetItemCommand( nItemId );
622 [ # # ][ # # ]: 0 : return aItemCommand;
623 : : }
624 : :
625 : 0 : void SAL_CALL VCLXMenu::setHelpCommand( sal_Int16 nItemId, const ::rtl::OUString& aHelp ) throw (::com::sun::star::uno::RuntimeException)
626 : : {
627 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
628 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
629 : :
630 [ # # ]: 0 : if ( mpMenu )
631 [ # # ][ # # ]: 0 : mpMenu->SetHelpCommand( nItemId, aHelp );
[ # # ][ # # ]
[ # # ]
632 : 0 : }
633 : :
634 : 0 : ::rtl::OUString SAL_CALL VCLXMenu::getHelpCommand( sal_Int16 nItemId ) throw (::com::sun::star::uno::RuntimeException)
635 : : {
636 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
637 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
638 : :
639 : 0 : ::rtl::OUString aHelpCommand;
640 [ # # ]: 0 : if ( mpMenu )
641 [ # # ][ # # ]: 0 : aHelpCommand = mpMenu->GetHelpCommand( nItemId );
642 [ # # ][ # # ]: 0 : return aHelpCommand;
643 : : }
644 : :
645 : :
646 : : // ============================================================================
647 : : // ============================================================================
648 : : // ============================================================================
649 : :
650 : :
651 : : // BEGIN ANONYMOUS NAMESPACE
652 : : namespace
653 : : {
654 : : namespace css = ::com::sun::star;
655 : :
656 : 0 : Image lcl_XGraphic2VCLImage(
657 : : const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
658 : : sal_Bool bResize )
659 : : {
660 [ # # ]: 0 : Image aImage;
661 [ # # ]: 0 : if ( !xGraphic.is() )
662 : : return aImage;
663 : :
664 [ # # ][ # # ]: 0 : aImage = Image( xGraphic );
[ # # ]
665 [ # # ]: 0 : const ::Size aCurSize = aImage.GetSizePixel();
666 : 0 : const sal_Int32 nCurWidth = aCurSize.Width();
667 : 0 : const sal_Int32 nCurHeight = aCurSize.Height();
668 : 0 : const sal_Int32 nIdeal( 16 );
669 : :
670 [ # # ][ # # ]: 0 : if ( nCurWidth > 0 && nCurHeight > 0 )
671 : : {
672 [ # # ][ # # ]: 0 : if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) )
[ # # ]
673 : : {
674 [ # # ]: 0 : sal_Int32 nIdealWidth = nCurWidth > nIdeal ? nIdeal : nCurWidth;
675 [ # # ]: 0 : sal_Int32 nIdealHeight = nCurHeight > nIdeal ? nIdeal : nCurHeight;
676 : :
677 : 0 : ::Size aNewSize( nIdealWidth, nIdealHeight );
678 : :
679 : 0 : sal_Bool bModified( sal_False );
680 [ # # ]: 0 : BitmapEx aBitmapEx = aImage.GetBitmapEx();
681 [ # # ]: 0 : bModified = aBitmapEx.Scale( aNewSize, BMP_SCALE_BEST );
682 : :
683 [ # # ]: 0 : if ( bModified )
684 [ # # ][ # # ]: 0 : aImage = Image( aBitmapEx );
[ # # ][ # # ]
685 : : }
686 : : }
687 : 0 : return aImage;
688 : : }
689 : :
690 : : /**
691 : : As svtools builds after toolkit, we can not include/use
692 : : svtools/inc/acceleratorexecute.hxx
693 : : So I just copy here svt::AcceleratorExecute::st_AWTKey2VCLKey
694 : : and svt::AcceleratorExecute::st_VCLKey2AWTKey
695 : : */
696 : 0 : css::awt::KeyEvent lcl_VCLKey2AWTKey(const KeyCode& aVCLKey)
697 : : {
698 : 0 : css::awt::KeyEvent aAWTKey;
699 : 0 : aAWTKey.Modifiers = 0;
700 : 0 : aAWTKey.KeyCode = (sal_Int16)aVCLKey.GetCode();
701 : :
702 [ # # ]: 0 : if (aVCLKey.IsShift())
703 : 0 : aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
704 [ # # ]: 0 : if (aVCLKey.IsMod1())
705 : 0 : aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
706 [ # # ]: 0 : if (aVCLKey.IsMod2())
707 : 0 : aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
708 [ # # ]: 0 : if (aVCLKey.IsMod3())
709 : 0 : aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
710 : :
711 : 0 : return aAWTKey;
712 : : }
713 : :
714 : 0 : KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
715 : : {
716 : 0 : sal_Bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
717 : 0 : sal_Bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
718 : 0 : sal_Bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
719 : 0 : sal_Bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
720 : 0 : sal_uInt16 nKey = (sal_uInt16)aAWTKey.KeyCode;
721 : :
722 : 0 : return KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
723 : : }
724 : :
725 : : } // END ANONYMOUS NAMESPACE
726 : :
727 : :
728 : : // ============================================================================
729 : : // ============================================================================
730 : : // ============================================================================
731 : :
732 : :
733 : : // XMenuExtended2 Methods
734 : :
735 : 0 : ::sal_Bool SAL_CALL VCLXMenu::isPopupMenu( ) throw (::com::sun::star::uno::RuntimeException)
736 : : {
737 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
738 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
739 [ # # ][ # # ]: 0 : return IsPopupMenu();
[ # # ]
740 : : }
741 : :
742 : 0 : void SAL_CALL VCLXMenu::clear( ) throw (::com::sun::star::uno::RuntimeException)
743 : : {
744 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
745 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
746 [ # # ]: 0 : if ( mpMenu )
747 [ # # ][ # # ]: 0 : mpMenu->Clear();
[ # # ]
748 : 0 : }
749 : :
750 : :
751 : 0 : ::com::sun::star::awt::MenuItemType SAL_CALL VCLXMenu::getItemType( ::sal_Int16 nItemPos )
752 : : throw ( ::com::sun::star::container::NoSuchElementException,
753 : : ::com::sun::star::uno::RuntimeException)
754 : : {
755 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
756 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
757 : :
758 : : ::com::sun::star::awt::MenuItemType aMenuItemType =
759 : 0 : ::com::sun::star::awt::MenuItemType_DONTKNOW;
760 [ # # ]: 0 : if ( mpMenu )
761 : : {
762 [ # # ][ # # ]: 0 : THROW_MENUPOS_NOT_FOUND( "VCLXMenu::getItemType()", nItemPos )
763 [ # # ]: 0 : aMenuItemType = ( (::com::sun::star::awt::MenuItemType) mpMenu->GetItemType( nItemPos ) );
764 : : }
765 : :
766 [ # # ][ # # ]: 0 : return aMenuItemType;
767 : : }
768 : :
769 : 0 : void SAL_CALL VCLXMenu::hideDisabledEntries( ::sal_Bool bHide )
770 : : throw (::com::sun::star::uno::RuntimeException)
771 : : {
772 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
773 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
774 [ # # ]: 0 : if ( mpMenu )
775 : : {
776 [ # # ]: 0 : if ( bHide )
777 : 0 : mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_HIDEDISABLEDENTRIES );
778 : : else
779 : 0 : mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_HIDEDISABLEDENTRIES );
780 [ # # ][ # # ]: 0 : }
781 : 0 : }
782 : :
783 : :
784 : : // ============================================================================
785 : : // ============================================================================
786 : : // ============================================================================
787 : :
788 : :
789 : : // XPopupMenuExtended Methods
790 : :
791 : 0 : ::sal_Bool SAL_CALL VCLXMenu::isInExecute( )
792 : : throw (::com::sun::star::uno::RuntimeException)
793 : : {
794 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
795 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
796 : :
797 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
798 [ # # ]: 0 : return ( (PopupMenu*) mpMenu )->IsInExecute();
799 : : else
800 [ # # ][ # # ]: 0 : return sal_False;
801 : : }
802 : :
803 : :
804 : 0 : void SAL_CALL VCLXMenu::endExecute()
805 : : throw (::com::sun::star::uno::RuntimeException)
806 : : {
807 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
808 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
809 : :
810 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
811 [ # # ][ # # ]: 0 : ( (PopupMenu*) mpMenu )->EndExecute();
[ # # ]
812 : 0 : }
813 : :
814 : :
815 : 0 : void SAL_CALL VCLXMenu::setLogo( const ::com::sun::star::awt::MenuLogo& aMenuLogo )
816 : : throw (::com::sun::star::uno::RuntimeException)
817 : : {
818 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
819 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
820 : :
821 [ # # ]: 0 : if ( mpMenu )
822 : : {
823 [ # # ]: 0 : if ( aMenuLogo.Graphic.is() )
824 : : {
825 [ # # ]: 0 : Image aImage = lcl_XGraphic2VCLImage( aMenuLogo.Graphic, sal_False );
826 [ # # ]: 0 : MenuLogo aVCLMenuLogo;
827 : :
828 [ # # ][ # # ]: 0 : aVCLMenuLogo.aBitmap = aImage.GetBitmapEx();
[ # # ]
829 : 0 : aVCLMenuLogo.aStartColor = Color( (sal_uInt32)(aMenuLogo.StartColor) );
830 : 0 : aVCLMenuLogo.aEndColor = Color( (sal_uInt32)(aMenuLogo.EndColor) );
831 : :
832 [ # # ][ # # ]: 0 : mpMenu->SetLogo( aVCLMenuLogo );
[ # # ]
833 : : }
834 : : else
835 [ # # ]: 0 : mpMenu->SetLogo();
836 [ # # ][ # # ]: 0 : }
837 : 0 : }
838 : :
839 : :
840 : 0 : ::com::sun::star::awt::MenuLogo SAL_CALL VCLXMenu::getLogo( )
841 : : throw (::com::sun::star::uno::RuntimeException)
842 : : {
843 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
844 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
845 : :
846 [ # # ]: 0 : ::com::sun::star::awt::MenuLogo aAWTMenuLogo;
847 [ # # ]: 0 : if ( mpMenu )
848 : : {
849 [ # # ]: 0 : if ( mpMenu->HasLogo() )
850 : : {
851 [ # # ]: 0 : MenuLogo aVCLMenuLogo = mpMenu->GetLogo();
852 [ # # ][ # # ]: 0 : aAWTMenuLogo.Graphic = Image(aVCLMenuLogo.aBitmap).GetXGraphic();
[ # # ][ # # ]
853 : 0 : aAWTMenuLogo.StartColor = aVCLMenuLogo.aStartColor.GetColor();
854 [ # # ]: 0 : aAWTMenuLogo.EndColor = aVCLMenuLogo.aEndColor.GetColor();
855 : : }
856 : : }
857 [ # # ][ # # ]: 0 : return aAWTMenuLogo;
858 : : }
859 : :
860 : :
861 : 0 : void SAL_CALL VCLXMenu::enableAutoMnemonics( ::sal_Bool bEnable )
862 : : throw (::com::sun::star::uno::RuntimeException)
863 : : {
864 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
865 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
866 [ # # ]: 0 : if ( mpMenu )
867 : : {
868 [ # # ]: 0 : if ( !bEnable )
869 : 0 : mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MENU_FLAG_NOAUTOMNEMONICS );
870 : : else
871 : 0 : mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MENU_FLAG_NOAUTOMNEMONICS );
872 [ # # ][ # # ]: 0 : }
873 : 0 : }
874 : :
875 : :
876 : 0 : void SAL_CALL VCLXMenu::setAcceleratorKeyEvent( ::sal_Int16 nItemId,
877 : : const ::com::sun::star::awt::KeyEvent& aKeyEvent )
878 : : throw ( ::com::sun::star::container::NoSuchElementException,
879 : : ::com::sun::star::uno::RuntimeException)
880 : : {
881 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
882 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
883 : :
884 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
885 : : {
886 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setAcceleratorKeyEvent()", nItemId )
[ # # ]
887 [ # # ]: 0 : KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent );
888 [ # # ]: 0 : mpMenu->SetAccelKey( nItemId, aVCLKeyCode );
889 [ # # ][ # # ]: 0 : }
890 : 0 : }
891 : :
892 : :
893 : 0 : ::com::sun::star::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent( ::sal_Int16 nItemId )
894 : : throw ( ::com::sun::star::container::NoSuchElementException,
895 : : ::com::sun::star::uno::RuntimeException)
896 : : {
897 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
898 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
899 : :
900 [ # # ]: 0 : ::com::sun::star::awt::KeyEvent aKeyEvent;
901 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
902 : : {
903 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getAcceleratorKeyEvent()", nItemId )
[ # # ]
904 [ # # ]: 0 : KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId );
905 [ # # ][ # # ]: 0 : aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode );
[ # # ]
906 : : }
907 : :
908 [ # # ][ # # ]: 0 : return aKeyEvent;
909 : : }
910 : :
911 : :
912 : 0 : void SAL_CALL VCLXMenu::setHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sHelpText )
913 : : throw ( ::com::sun::star::container::NoSuchElementException,
914 : : ::com::sun::star::uno::RuntimeException)
915 : : {
916 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
917 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
918 : :
919 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
920 : : {
921 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setHelpText()", nItemId )
[ # # ]
922 [ # # ][ # # ]: 0 : mpMenu->SetHelpText( nItemId, sHelpText );
[ # # ]
923 [ # # ][ # # ]: 0 : }
924 : 0 : }
925 : :
926 : :
927 : 0 : ::rtl::OUString SAL_CALL VCLXMenu::getHelpText( ::sal_Int16 nItemId )
928 : : throw ( ::com::sun::star::container::NoSuchElementException,
929 : : ::com::sun::star::uno::RuntimeException)
930 : : {
931 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
932 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
933 : :
934 : 0 : rtl::OUString sHelpText;
935 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
936 : : {
937 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getHelpText()", nItemId )
[ # # ]
938 [ # # ][ # # ]: 0 : sHelpText = mpMenu->GetHelpText( nItemId );
939 : : }
940 : :
941 [ # # ][ # # ]: 0 : return sHelpText;
942 : : }
943 : :
944 : :
945 : 0 : void SAL_CALL VCLXMenu::setTipHelpText( ::sal_Int16 nItemId, const ::rtl::OUString& sTipHelpText )
946 : : throw ( ::com::sun::star::container::NoSuchElementException,
947 : : ::com::sun::star::uno::RuntimeException)
948 : : {
949 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
950 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
951 : :
952 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
953 : : {
954 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setTipHelpText()", nItemId )
[ # # ]
955 [ # # ][ # # ]: 0 : mpMenu->SetTipHelpText( nItemId, sTipHelpText );
[ # # ]
956 [ # # ][ # # ]: 0 : }
957 : 0 : }
958 : :
959 : :
960 : 0 : ::rtl::OUString SAL_CALL VCLXMenu::getTipHelpText( ::sal_Int16 nItemId )
961 : : throw ( ::com::sun::star::container::NoSuchElementException,
962 : : ::com::sun::star::uno::RuntimeException)
963 : : {
964 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
965 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
966 : :
967 : 0 : rtl::OUString sTipHelpText;
968 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
969 : : {
970 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getTipHelpText()", nItemId )
[ # # ]
971 [ # # ][ # # ]: 0 : sTipHelpText = mpMenu->GetTipHelpText( nItemId );
972 : : }
973 [ # # ][ # # ]: 0 : return sTipHelpText;
974 : : }
975 : :
976 : :
977 : 0 : void SAL_CALL VCLXMenu::setItemImage(
978 : : ::sal_Int16 nItemId,
979 : : const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& xGraphic, ::sal_Bool bScale )
980 : : throw ( ::com::sun::star::container::NoSuchElementException,
981 : : ::com::sun::star::uno::RuntimeException)
982 : : {
983 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
984 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
985 : :
986 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
987 : : {
988 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImage()", nItemId )
[ # # ]
989 [ # # ]: 0 : Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale );
990 [ # # ][ # # ]: 0 : mpMenu->SetItemImage( nItemId, aImage );
991 [ # # ][ # # ]: 0 : }
992 : 0 : }
993 : :
994 : :
995 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > SAL_CALL VCLXMenu::getItemImage( ::sal_Int16 nItemId )
996 : : throw ( ::com::sun::star::container::NoSuchElementException,
997 : : ::com::sun::star::uno::RuntimeException)
998 : : {
999 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
1000 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1001 : :
1002 : 0 : ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > rxGraphic;
1003 : :
1004 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
1005 : : {
1006 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImage()", nItemId )
[ # # ]
1007 [ # # ]: 0 : Image aImage = mpMenu->GetItemImage( nItemId );
1008 [ # # ]: 0 : if ( !!aImage )
1009 [ # # ][ # # ]: 0 : rxGraphic = aImage.GetXGraphic();
[ # # ]
1010 : : }
1011 [ # # ][ # # ]: 0 : return rxGraphic;
1012 : : }
1013 : :
1014 : :
1015 : 0 : void SAL_CALL VCLXMenu::setItemImageAngle( ::sal_Int16 nItemId, ::sal_Int32 nAngle )
1016 : : throw ( ::com::sun::star::container::NoSuchElementException,
1017 : : ::com::sun::star::uno::RuntimeException)
1018 : : {
1019 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
1020 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1021 : :
1022 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
1023 : : {
1024 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageAngle()", nItemId )
[ # # ]
1025 [ # # ]: 0 : mpMenu->SetItemImageAngle( nItemId, nAngle );
1026 [ # # ][ # # ]: 0 : }
1027 : 0 : }
1028 : :
1029 : :
1030 : 0 : ::sal_Int32 SAL_CALL VCLXMenu::getItemImageAngle( ::sal_Int16 nItemId )
1031 : : throw ( ::com::sun::star::container::NoSuchElementException,
1032 : : ::com::sun::star::uno::RuntimeException)
1033 : : {
1034 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
1035 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1036 : :
1037 : 0 : ::sal_Int32 nItemImageAngle( 0 );
1038 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
1039 : : {
1040 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::getItemImageAngle()", nItemId )
[ # # ]
1041 [ # # ]: 0 : nItemImageAngle = mpMenu->GetItemImageAngle( nItemId );
1042 : : }
1043 [ # # ][ # # ]: 0 : return nItemImageAngle;
1044 : : }
1045 : :
1046 : :
1047 : 0 : void SAL_CALL VCLXMenu::setItemImageMirrorMode( ::sal_Int16 nItemId, ::sal_Bool bMirror )
1048 : : throw ( ::com::sun::star::container::NoSuchElementException,
1049 : : ::com::sun::star::uno::RuntimeException)
1050 : : {
1051 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
1052 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1053 : :
1054 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
1055 : : {
1056 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::setItemImageMirrorMode()", nItemId )
[ # # ]
1057 [ # # ]: 0 : mpMenu->SetItemImageMirrorMode( nItemId, bMirror );
1058 [ # # ][ # # ]: 0 : }
1059 : 0 : }
1060 : :
1061 : :
1062 : 0 : ::sal_Bool SAL_CALL VCLXMenu::isItemImageInMirrorMode( ::sal_Int16 nItemId )
1063 : : throw ( ::com::sun::star::container::NoSuchElementException,
1064 : : ::com::sun::star::uno::RuntimeException)
1065 : : {
1066 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
1067 [ # # ]: 0 : ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1068 : :
1069 : 0 : sal_Bool bMirrorMode( sal_False );
1070 [ # # ][ # # ]: 0 : if ( mpMenu && IsPopupMenu() )
[ # # ][ # # ]
1071 : : {
1072 [ # # ][ # # ]: 0 : THROW_MENUITEM_NOT_FOUND( "VCLXMenu::isItemImageInMirrorMode()", nItemId )
[ # # ]
1073 [ # # ]: 0 : bMirrorMode = mpMenu->GetItemImageMirrorMode( nItemId );
1074 : : }
1075 [ # # ][ # # ]: 0 : return bMirrorMode;
1076 : : }
1077 : :
1078 : :
1079 : : // ----------------------------------------------------
1080 : : // class VCLXMenuBar
1081 : : // ----------------------------------------------------
1082 : :
1083 : : DBG_NAME(VCLXMenuBar);
1084 : :
1085 : 0 : VCLXMenuBar::VCLXMenuBar()
1086 : : {
1087 : : DBG_CTOR( VCLXMenuBar, 0 );
1088 [ # # ]: 0 : ImplCreateMenu( sal_False );
1089 : 0 : }
1090 : :
1091 : 1709 : VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( (Menu *)pMenuBar )
1092 : : {
1093 : : DBG_CTOR( VCLXMenuBar, 0 );
1094 : 1709 : }
1095 : :
1096 : : // ----------------------------------------------------
1097 : : // class VCLXPopupMenu
1098 : : // ----------------------------------------------------
1099 : :
1100 : : DBG_NAME(VCLXPopupMenu);
1101 : :
1102 : 10788 : VCLXPopupMenu::VCLXPopupMenu()
1103 : : {
1104 : : DBG_CTOR( VCLXPopupMenu, 0 );
1105 [ + - ]: 10788 : ImplCreateMenu( sal_True );
1106 : 10788 : }
1107 : :
1108 : 0 : VCLXPopupMenu::VCLXPopupMenu( PopupMenu* pPopMenu ) : VCLXMenu( (Menu *)pPopMenu )
1109 : : {
1110 : : DBG_CTOR( VCLXPopupMenu, 0 );
1111 : 0 : }
1112 : :
1113 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|