LibreOffice Module toolkit (master) 1
vclxmenu.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
23
24#include <com/sun/star/uno/XComponentContext.hpp>
28#include <tools/debug.hxx>
29#include <vcl/dialoghelper.hxx>
30#include <vcl/graph.hxx>
31#include <vcl/menu.hxx>
32#include <vcl/keycod.hxx>
33#include <vcl/image.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/window.hxx>
36
37#include <com/sun/star/awt/KeyModifier.hpp>
38
40 : maMenuListeners( *this )
41 , mnDefaultItem(0)
42{
43 mpMenu = nullptr;
44}
45
47 : maMenuListeners( *this )
48 , mnDefaultItem(0)
49{
50 mpMenu = pMenu;
51}
52
54{
55 maPopupMenuRefs.clear();
56 if ( mpMenu )
57 {
59 mpMenu->RemoveEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
61 }
62}
63
65{
66 return (mpMenu && ! mpMenu->IsMenuBar());
67}
68
69void VCLXMenu::ImplCreateMenu( bool bPopup )
70{
71 DBG_ASSERT( !mpMenu, "CreateMenu: Menu exists!" );
72
73 if ( bPopup )
75 else
77
78 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
79}
80
82{
83 assert(mpMenu);
84 mpMenu->AddEventListener( LINK( this, VCLXMenu, MenuEventListener ) );
85}
86
87IMPL_LINK( VCLXMenu, MenuEventListener, VclMenuEvent&, rMenuEvent, void )
88{
89 DBG_ASSERT( rMenuEvent.GetMenu() && mpMenu, "Menu???" );
90
91 if ( rMenuEvent.GetMenu() != mpMenu ) // Also called for the root menu
92 return;
93
94 switch ( rMenuEvent.GetId() )
95 {
96 case VclEventId::MenuSelect:
97 {
98 if ( maMenuListeners.getLength() )
99 {
100 css::awt::MenuEvent aEvent;
101 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
102 aEvent.MenuId = mpMenu->GetCurItemId();
103 maMenuListeners.itemSelected( aEvent );
104 }
105 }
106 break;
107 case VclEventId::ObjectDying:
108 {
109 mpMenu = nullptr;
110 }
111 break;
112 case VclEventId::MenuHighlight:
113 {
114 if ( maMenuListeners.getLength() )
115 {
116 css::awt::MenuEvent aEvent;
117 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
118 aEvent.MenuId = mpMenu->GetCurItemId();
119 maMenuListeners.itemHighlighted( aEvent );
120 }
121 }
122 break;
123 case VclEventId::MenuActivate:
124 {
125 if ( maMenuListeners.getLength() )
126 {
127 css::awt::MenuEvent aEvent;
128 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
129 aEvent.MenuId = mpMenu->GetCurItemId();
130 maMenuListeners.itemActivated( aEvent );
131 }
132 }
133 break;
134 case VclEventId::MenuDeactivate:
135 {
136 if ( maMenuListeners.getLength() )
137 {
138 css::awt::MenuEvent aEvent;
139 aEvent.Source = static_cast<cppu::OWeakObject*>(this);
140 aEvent.MenuId = mpMenu->GetCurItemId();
141 maMenuListeners.itemDeactivated( aEvent );
142 }
143 }
144 break;
145
146 // ignore accessibility events
147 case VclEventId::MenuEnable:
148 case VclEventId::MenuInsertItem:
149 case VclEventId::MenuRemoveItem:
150 case VclEventId::MenuSubmenuActivate:
151 case VclEventId::MenuSubmenuDeactivate:
152 case VclEventId::MenuSubmenuChanged:
153 case VclEventId::MenuDehighlight:
154 case VclEventId::MenuDisable:
155 case VclEventId::MenuItemRoleChanged:
156 case VclEventId::MenuItemTextChanged:
157 case VclEventId::MenuItemChecked:
158 case VclEventId::MenuItemUnchecked:
159 case VclEventId::MenuShow:
160 case VclEventId::MenuHide:
161 break;
162
163 default: OSL_FAIL( "MenuEventListener - Unknown event!" );
164 }
165}
166
167
169{
170 std::unique_lock aGuard( maMutex );
171 const bool bIsPopupMenu = IsPopupMenu();
172 aGuard.unlock();
173
174 OUString implName( "stardiv.Toolkit." );
175 if ( bIsPopupMenu )
176 implName += "VCLXPopupMenu";
177 else
178 implName += "VCLXMenuBar";
179
180 return implName;
181}
182
183css::uno::Sequence< OUString > SAL_CALL VCLXMenu::getSupportedServiceNames( )
184{
185 std::unique_lock aGuard( maMutex );
186 const bool bIsPopupMenu = IsPopupMenu();
187 aGuard.unlock();
188
189 if ( bIsPopupMenu )
190 return css::uno::Sequence<OUString>{
191 "com.sun.star.awt.PopupMenu",
192 "stardiv.vcl.PopupMenu"};
193 else
194 return css::uno::Sequence<OUString>{
195 "com.sun.star.awt.MenuBar",
196 "stardiv.vcl.MenuBar"};
197}
198
199sal_Bool SAL_CALL VCLXMenu::supportsService(const OUString& rServiceName )
200{
201 return cppu::supportsService(this, rServiceName);
202}
203
205 const css::uno::Type & rType )
206{
207 std::unique_lock aGuard( maMutex );
208 const bool bIsPopupMenu = IsPopupMenu();
209 aGuard.unlock();
210
211 css::uno::Any aRet;
212
213 if ( bIsPopupMenu )
214 aRet = ::cppu::queryInterface( rType,
215 static_cast< css::awt::XMenu* >(static_cast<css::awt::XMenuBar*>(this)),
216 static_cast< css::awt::XPopupMenu* >(this),
217 static_cast< css::lang::XTypeProvider* >(this),
218 static_cast< css::lang::XServiceInfo* >(this) );
219 else
220 aRet = ::cppu::queryInterface( rType,
221 static_cast< css::awt::XMenu* >(static_cast<css::awt::XMenuBar*>(this)),
222 static_cast< css::awt::XMenuBar* >(this),
223 static_cast< css::lang::XTypeProvider* >(this),
224 static_cast< css::lang::XServiceInfo* >(this) );
225
226 return (aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ));
227}
228
229
230css::uno::Sequence< css::uno::Type > VCLXMenu::getTypes()
231{
232 std::unique_lock aGuard( maMutex );
233 const bool bIsPopupMenu = IsPopupMenu();
234 aGuard.unlock();
235
236 if ( bIsPopupMenu )
237 {
238 static cppu::OTypeCollection collectionPopupMenu(
242 return collectionPopupMenu.getTypes();
243 }
244 else
245 {
246 static cppu::OTypeCollection collectionMenuBar(
250 return collectionMenuBar.getTypes();
251 }
252}
253
254
255css::uno::Sequence< sal_Int8 > VCLXMenu::getImplementationId()
256{
257 return css::uno::Sequence<sal_Int8>();
258}
259
261 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
262{
263 std::unique_lock aGuard( maMutex );
264
265 maMenuListeners.addInterface( rxListener );
266}
267
269 const css::uno::Reference< css::awt::XMenuListener >& rxListener )
270{
271 std::unique_lock aGuard( maMutex );
272
273 maMenuListeners.removeInterface( rxListener );
274}
275
277 sal_Int16 nItemId,
278 const OUString& aText,
279 sal_Int16 nItemStyle,
280 sal_Int16 nPos )
281{
282 SolarMutexGuard aSolarGuard;
283 std::unique_lock aGuard( maMutex );
284
285 if ( mpMenu )
286 mpMenu->InsertItem(nItemId, aText, static_cast<MenuItemBits>(nItemStyle), {}, nPos);
287}
288
290 sal_Int16 nPos,
291 sal_Int16 nCount )
292{
293 SolarMutexGuard aSolarGuard;
294 std::unique_lock aGuard( maMutex );
295
296 if (!mpMenu)
297 return;
298
299 sal_Int32 nItemCount = static_cast<sal_Int32>(mpMenu->GetItemCount());
300 if ((nCount > 0) && (nPos >= 0) && (nPos < nItemCount))
301 {
302 sal_Int16 nP = sal::static_int_cast< sal_Int16 >(
303 std::min( static_cast<int>(nPos+nCount), static_cast<int>(nItemCount) ));
304 while( nP-nPos > 0 )
305 mpMenu->RemoveItem( --nP );
306 }
307}
308
310{
311 SolarMutexGuard aSolarGuard;
312 std::unique_lock aGuard( maMutex );
313
314 return mpMenu ? mpMenu->GetItemCount() : 0;
315}
316
318 sal_Int16 nPos )
319{
320 SolarMutexGuard aSolarGuard;
321 std::unique_lock aGuard( maMutex );
322
323 return mpMenu ? mpMenu->GetItemId( nPos ) : 0;
324}
325
327 sal_Int16 nId )
328{
329 SolarMutexGuard aSolarGuard;
330 std::unique_lock aGuard( maMutex );
331
332 return mpMenu ? mpMenu->GetItemPos( nId ) : 0;
333}
334
336 sal_Int16 nItemId,
337 sal_Bool bEnable )
338{
339 SolarMutexGuard aSolarGuard;
340 std::unique_lock aGuard( maMutex );
341
342 if ( mpMenu )
343 mpMenu->EnableItem( nItemId, bEnable );
344}
345
347 sal_Int16 nItemId )
348{
349 SolarMutexGuard aSolarGuard;
350 std::unique_lock aGuard( maMutex );
351
352 return mpMenu && mpMenu->IsItemEnabled( nItemId );
353}
354
356 sal_Int16 nItemId,
357 const OUString& aText )
358{
359 SolarMutexGuard aSolarGuard;
360 std::unique_lock aGuard( maMutex );
361
362 if ( mpMenu )
363 mpMenu->SetItemText( nItemId, aText );
364}
365
367 sal_Int16 nItemId )
368{
369 SolarMutexGuard aSolarGuard;
370 std::unique_lock aGuard( maMutex );
371
372 OUString aItemText;
373 if ( mpMenu )
374 aItemText = mpMenu->GetItemText( nItemId );
375 return aItemText;
376}
377
379 sal_Int16 nItemId,
380 const css::uno::Reference< css::awt::XPopupMenu >& rxPopupMenu )
381{
382 SolarMutexGuard aSolarGuard;
383 std::unique_lock aGuard( maMutex );
384
385 VCLXMenu* pVCLMenu = dynamic_cast<VCLXMenu*>( rxPopupMenu.get() );
386 DBG_ASSERT( pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu(), "setPopupMenu: Invalid Menu!" );
387
388 if ( mpMenu && pVCLMenu && pVCLMenu->GetMenu() && pVCLMenu->IsPopupMenu() )
389 {
390 maPopupMenuRefs.push_back( rxPopupMenu );
391
392 mpMenu->SetPopupMenu( nItemId, static_cast<PopupMenu*>( pVCLMenu->GetMenu() ) );
393 }
394}
395
396css::uno::Reference< css::awt::XPopupMenu > VCLXMenu::getPopupMenu(
397 sal_Int16 nItemId )
398{
399 SolarMutexGuard aSolarGuard;
400 std::unique_lock aGuard( maMutex );
401
402 css::uno::Reference< css::awt::XPopupMenu > aRef;
403 Menu* pMenu = mpMenu ? mpMenu->GetPopupMenu( nItemId ) : nullptr;
404 if ( pMenu )
405 {
406 for ( size_t n = maPopupMenuRefs.size(); n; )
407 {
408 css::uno::Reference< css::awt::XPopupMenu >& rRef = maPopupMenuRefs[ --n ];
409 Menu* pM = static_cast<VCLXMenu*>(rRef.get())->GetMenu();
410 if ( pM == pMenu )
411 {
412 aRef = rRef;
413 break;
414 }
415 }
416 // it seems the popup menu is not insert into maPopupMenuRefs
417 // if the popup men is not created by stardiv.Toolkit.VCLXPopupMenu
418 if( !aRef.is() )
419 {
420 aRef = new VCLXPopupMenu( static_cast<PopupMenu*>(pMenu) );
421 }
422 }
423 return aRef;
424}
425
426// css::awt::XPopupMenu
428 sal_Int16 nPos )
429{
430 SolarMutexGuard aSolarGuard;
431 std::unique_lock aGuard( maMutex );
432
433 if ( mpMenu )
434 mpMenu->InsertSeparator({}, nPos);
435}
436
438 sal_Int16 nItemId )
439{
440 std::unique_lock aGuard( maMutex );
441
442 mnDefaultItem = nItemId;
443}
444
446{
447 std::unique_lock aGuard( maMutex );
448
449 return mnDefaultItem;
450}
451
453 sal_Int16 nItemId,
454 sal_Bool bCheck )
455{
456 SolarMutexGuard aSolarGuard;
457 std::unique_lock aGuard( maMutex );
458
459 if ( mpMenu )
460 mpMenu->CheckItem( nItemId, bCheck );
461}
462
464 sal_Int16 nItemId )
465{
466 SolarMutexGuard aSolarGuard;
467 std::unique_lock aGuard( maMutex );
468
469 return mpMenu && mpMenu->IsItemChecked( nItemId );
470}
471
473 const css::uno::Reference< css::awt::XWindowPeer >& rxWindowPeer,
474 const css::awt::Rectangle& rPos,
475 sal_Int16 nFlags )
476{
477 SolarMutexGuard aSolarGuard;
478 auto pMenu = mpMenu;
479 {
480 std::unique_lock aGuard( maMutex );
481 if ( !mpMenu || !IsPopupMenu() )
482 return 0;
483 }
484 // cannot call this with mutex locked because it will call back into us
485 return static_cast<PopupMenu*>(pMenu.get())->Execute(
486 VCLUnoHelper::GetWindow( rxWindowPeer ),
487 VCLRectangle( rPos ),
488 static_cast<PopupMenuFlags>(nFlags) | PopupMenuFlags::NoMouseUpClose );
489}
490
491
493 sal_Int16 nItemId,
494 const OUString& aCommand )
495{
496 SolarMutexGuard aSolarGuard;
497 std::unique_lock aGuard( maMutex );
498
499 if ( mpMenu )
500 mpMenu->SetItemCommand( nItemId, aCommand );
501}
502
503OUString SAL_CALL VCLXMenu::getCommand(
504 sal_Int16 nItemId )
505{
506 SolarMutexGuard aSolarGuard;
507 std::unique_lock aGuard( maMutex );
508
509 OUString aItemCommand;
510 if ( mpMenu )
511 aItemCommand = mpMenu->GetItemCommand( nItemId );
512 return aItemCommand;
513}
514
516 sal_Int16 nItemId,
517 const OUString& aHelp )
518{
519 SolarMutexGuard aSolarGuard;
520 std::unique_lock aGuard( maMutex );
521
522 if ( mpMenu )
523 mpMenu->SetHelpCommand( nItemId, aHelp );
524}
525
526OUString SAL_CALL VCLXMenu::getHelpCommand(
527 sal_Int16 nItemId )
528{
529 SolarMutexGuard aSolarGuard;
530 std::unique_lock aGuard( maMutex );
531
532 OUString aHelpCommand;
533 if ( mpMenu )
534 aHelpCommand = mpMenu->GetHelpCommand( nItemId );
535 return aHelpCommand;
536}
537
538
539namespace
540{
541 Image lcl_XGraphic2VCLImage(
542 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
543 bool bResize )
544 {
545 Image aImage;
546 if ( !xGraphic.is() )
547 return aImage;
548
549 aImage = Image( xGraphic );
550 const ::Size aCurSize = aImage.GetSizePixel();
551 const sal_Int32 nCurWidth = aCurSize.Width();
552 const sal_Int32 nCurHeight = aCurSize.Height();
553 constexpr sal_Int32 nIdeal( 16 );
554
555 if ( nCurWidth > 0 && nCurHeight > 0 )
556 {
557 if ( bResize && ( nCurWidth > nIdeal || nCurHeight > nIdeal ) )
558 {
559 sal_Int32 nIdealWidth = std::min(nCurWidth, nIdeal);
560 sal_Int32 nIdealHeight = std::min(nCurHeight, nIdeal);
561
562 ::Size aNewSize( nIdealWidth, nIdealHeight );
563
564 bool bModified( false );
565 BitmapEx aBitmapEx = aImage.GetBitmapEx();
566 bModified = aBitmapEx.Scale( aNewSize, BmpScaleFlag::BestQuality );
567
568 if ( bModified )
569 aImage = Image( aBitmapEx );
570 }
571 }
572 return aImage;
573 }
574
576 css::awt::KeyEvent lcl_VCLKey2AWTKey(
577 const vcl::KeyCode& aVCLKey)
578 {
579 css::awt::KeyEvent aAWTKey;
580 aAWTKey.Modifiers = 0;
581 aAWTKey.KeyCode = static_cast<sal_Int16>(aVCLKey.GetCode());
582
583 if (aVCLKey.IsShift())
584 aAWTKey.Modifiers |= css::awt::KeyModifier::SHIFT;
585 if (aVCLKey.IsMod1())
586 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD1;
587 if (aVCLKey.IsMod2())
588 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD2;
589 if (aVCLKey.IsMod3())
590 aAWTKey.Modifiers |= css::awt::KeyModifier::MOD3;
591
592 return aAWTKey;
593 }
594
595 vcl::KeyCode lcl_AWTKey2VCLKey(const css::awt::KeyEvent& aAWTKey)
596 {
597 bool bShift = ((aAWTKey.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT );
598 bool bMod1 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD1 ) == css::awt::KeyModifier::MOD1 );
599 bool bMod2 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD2 ) == css::awt::KeyModifier::MOD2 );
600 bool bMod3 = ((aAWTKey.Modifiers & css::awt::KeyModifier::MOD3 ) == css::awt::KeyModifier::MOD3 );
601 sal_uInt16 nKey = static_cast<sal_uInt16>(aAWTKey.KeyCode);
602
603 return vcl::KeyCode(nKey, bShift, bMod1, bMod2, bMod3);
604 }
605
606}
607
608
610{
611 SolarMutexGuard aSolarGuard;
612 std::unique_lock aGuard( maMutex );
613 return IsPopupMenu();
614}
615
616void SAL_CALL VCLXMenu::clear( )
617{
618 SolarMutexGuard aSolarGuard;
619 std::unique_lock aGuard( maMutex );
620 if ( mpMenu )
621 mpMenu->Clear();
622}
623
624
625css::awt::MenuItemType SAL_CALL VCLXMenu::getItemType(
626 ::sal_Int16 nItemPos )
627{
628 SolarMutexGuard aSolarGuard;
629 std::unique_lock aGuard( maMutex );
630
631 css::awt::MenuItemType aMenuItemType =
632 css::awt::MenuItemType_DONTKNOW;
633 if ( mpMenu )
634 {
635 aMenuItemType = static_cast<css::awt::MenuItemType>(mpMenu->GetItemType( nItemPos ));
636 }
637
638 return aMenuItemType;
639}
640
642 sal_Bool bHide )
643{
644 SolarMutexGuard aSolarGuard;
645 std::unique_lock aGuard( maMutex );
646 if ( mpMenu )
647 {
648 if ( bHide )
649 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::HideDisabledEntries );
650 else
651 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::HideDisabledEntries );
652 }
653}
654
655
657{
658 SolarMutexGuard aSolarGuard;
659 std::unique_lock aGuard( maMutex );
660
661 if ( mpMenu && IsPopupMenu() )
663 else
664 return false;
665}
666
667
668void SAL_CALL VCLXMenu::endExecute()
669{
670 SolarMutexGuard aSolarGuard;
671 std::unique_lock aGuard( maMutex );
672
673 if ( mpMenu && IsPopupMenu() )
674 static_cast<PopupMenu*>( mpMenu.get() )->EndExecute();
675}
676
677
679 sal_Bool bEnable )
680{
681 SolarMutexGuard aSolarGuard;
682 std::unique_lock aGuard( maMutex );
683 if ( mpMenu )
684 {
685 if ( !bEnable )
686 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics );
687 else
688 mpMenu->SetMenuFlags( mpMenu->GetMenuFlags() & ~MenuFlags::NoAutoMnemonics );
689 }
690}
691
692
694 ::sal_Int16 nItemId,
695 const css::awt::KeyEvent& aKeyEvent )
696{
697 SolarMutexGuard aSolarGuard;
698 std::unique_lock aGuard( maMutex );
699
700 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
701 {
702 vcl::KeyCode aVCLKeyCode = lcl_AWTKey2VCLKey( aKeyEvent );
703 mpMenu->SetAccelKey( nItemId, aVCLKeyCode );
704 }
705}
706
707
708css::awt::KeyEvent SAL_CALL VCLXMenu::getAcceleratorKeyEvent(
709 ::sal_Int16 nItemId )
710{
711 SolarMutexGuard aSolarGuard;
712 std::unique_lock aGuard( maMutex );
713
714 css::awt::KeyEvent aKeyEvent;
715 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
716 {
717 vcl::KeyCode nKeyCode = mpMenu->GetAccelKey( nItemId );
718 aKeyEvent = lcl_VCLKey2AWTKey( nKeyCode );
719 }
720
721 return aKeyEvent;
722}
723
724
726 ::sal_Int16 nItemId,
727 const OUString& sHelpText )
728{
729 SolarMutexGuard aSolarGuard;
730 std::unique_lock aGuard( maMutex );
731
732 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
733 {
734 mpMenu->SetHelpText( nItemId, sHelpText );
735 }
736}
737
738
739OUString SAL_CALL VCLXMenu::getHelpText(
740 ::sal_Int16 nItemId )
741{
742 SolarMutexGuard aSolarGuard;
743 std::unique_lock aGuard( maMutex );
744
745 OUString sHelpText;
746 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
747 {
748 sHelpText = mpMenu->GetHelpText( nItemId );
749 }
750
751 return sHelpText;
752}
753
754
756 ::sal_Int16 nItemId,
757 const OUString& sTipHelpText )
758{
759 SolarMutexGuard aSolarGuard;
760 std::unique_lock aGuard( maMutex );
761
762 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
763 {
764 mpMenu->SetTipHelpText( nItemId, sTipHelpText );
765 }
766}
767
768
769OUString SAL_CALL VCLXMenu::getTipHelpText(
770 ::sal_Int16 nItemId )
771{
772 SolarMutexGuard aSolarGuard;
773 std::unique_lock aGuard( maMutex );
774
775 OUString sTipHelpText;
776 if ( mpMenu && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
777 {
778 sTipHelpText = mpMenu->GetTipHelpText( nItemId );
779 }
780 return sTipHelpText;
781}
782
783
785 ::sal_Int16 nItemId,
786 const css::uno::Reference< css::graphic::XGraphic >& xGraphic,
787 sal_Bool bScale )
788{
789 SolarMutexGuard aSolarGuard;
790 std::unique_lock aGuard( maMutex );
791
792 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
793 {
794 Image aImage = lcl_XGraphic2VCLImage( xGraphic, bScale );
795 mpMenu->SetItemImage( nItemId, aImage );
796 }
797}
798
799
800css::uno::Reference< css::graphic::XGraphic > SAL_CALL
802 ::sal_Int16 nItemId )
803{
804 SolarMutexGuard aSolarGuard;
805 std::unique_lock aGuard( maMutex );
806
807 css::uno::Reference< css::graphic::XGraphic > rxGraphic;
808
809 if ( mpMenu && IsPopupMenu() && MENU_ITEM_NOTFOUND != mpMenu->GetItemPos( nItemId ) )
810 {
811 Image aImage = mpMenu->GetItemImage( nItemId );
812 if ( !!aImage )
813 rxGraphic = Graphic(aImage.GetBitmapEx()).GetXGraphic();
814 }
815 return rxGraphic;
816}
817
818void VCLXMenu::setUserValue(sal_uInt16 nItemId, void* nUserValue, MenuUserDataReleaseFunction aFunc)
819{
820 SolarMutexGuard aSolarGuard;
821 std::unique_lock aGuard(maMutex);
822
823 mpMenu->SetUserValue(nItemId, nUserValue, aFunc);
824}
825
826void* VCLXMenu::getUserValue(sal_uInt16 nItemId)
827{
828 SolarMutexGuard aSolarGuard;
829 std::unique_lock aGuard(maMutex);
830
831 return mpMenu->GetUserValue(nItemId);
832}
833
834VCLXMenuBar::VCLXMenuBar()
835{
836 ImplCreateMenu( false );
837}
838
839VCLXMenuBar::VCLXMenuBar( MenuBar* pMenuBar ) : VCLXMenu( static_cast<Menu *>(pMenuBar) )
840{
841}
842
843extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
845 css::uno::XComponentContext *,
846 css::uno::Sequence<css::uno::Any> const &)
847{
848 return cppu::acquire(new VCLXMenuBar());
849}
850
852{
853 ImplCreateMenu( true );
854}
855
856VCLXPopupMenu::VCLXPopupMenu( PopupMenu* pPopMenu ) : VCLXMenu( static_cast<Menu *>(pPopMenu) )
857{
859}
860
861extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
863 css::uno::XComponentContext *,
864 css::uno::Sequence<css::uno::Any> const &)
865{
866 return cppu::acquire(new VCLXPopupMenu());
867}
868
869/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
BitmapEx GetBitmapEx() const
Size GetSizePixel() const
constexpr tools::Long Width() const
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
virtual sal_Int16 SAL_CALL getItemCount() override
Definition: vclxmenu.cxx:309
virtual OUString SAL_CALL getTipHelpText(::sal_Int16 nItemId) override
Definition: vclxmenu.cxx:769
PopupMenuRefList maPopupMenuRefs
Definition: vclxmenu.hxx:62
virtual void SAL_CALL removeItem(sal_Int16 nPos, sal_Int16 nCount) override
Definition: vclxmenu.cxx:289
virtual void SAL_CALL clear() override
Definition: vclxmenu.cxx:616
virtual ::sal_Int16 SAL_CALL execute(const css::uno::Reference< css::awt::XWindowPeer > &Parent, const css::awt::Rectangle &Position, ::sal_Int16 Direction) override
Definition: vclxmenu.cxx:472
virtual OUString SAL_CALL getHelpCommand(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:526
virtual void SAL_CALL checkItem(sal_Int16 nItemId, sal_Bool bCheck) override
Definition: vclxmenu.cxx:452
virtual void SAL_CALL enableItem(sal_Int16 nItemId, sal_Bool bEnable) override
Definition: vclxmenu.cxx:335
virtual sal_Bool SAL_CALL isItemChecked(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:463
bool IsPopupMenu() const
Definition: vclxmenu.cxx:64
sal_Int16 mnDefaultItem
Definition: vclxmenu.hxx:63
virtual void SAL_CALL addMenuListener(const css::uno::Reference< css::awt::XMenuListener > &xListener) override
Definition: vclxmenu.cxx:260
virtual void SAL_CALL setItemText(sal_Int16 nItemId, const OUString &aText) override
Definition: vclxmenu.cxx:355
virtual void SAL_CALL setPopupMenu(sal_Int16 nItemId, const css::uno::Reference< css::awt::XPopupMenu > &aPopupMenu) override
Definition: vclxmenu.cxx:378
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: vclxmenu.cxx:183
virtual void SAL_CALL setDefaultItem(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:437
virtual sal_Bool SAL_CALL isItemEnabled(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:346
virtual css::awt::KeyEvent SAL_CALL getAcceleratorKeyEvent(::sal_Int16 nItemId) override
Definition: vclxmenu.cxx:708
virtual void SAL_CALL setCommand(sal_Int16 nItemId, const OUString &aCommand) override
Definition: vclxmenu.cxx:492
virtual void SAL_CALL setItemImage(::sal_Int16 nItemId, const css::uno::Reference< css::graphic::XGraphic > &xGraphic, sal_Bool bScale) override
Definition: vclxmenu.cxx:784
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: vclxmenu.cxx:204
virtual ~VCLXMenu() override
Definition: vclxmenu.cxx:53
void ImplCreateMenu(bool bPopup)
Definition: vclxmenu.cxx:69
virtual sal_Int16 SAL_CALL getDefaultItem() override
Definition: vclxmenu.cxx:445
MenuListenerMultiplexer maMenuListeners
Definition: vclxmenu.hxx:61
virtual sal_Bool SAL_CALL isPopupMenu() override
Definition: vclxmenu.cxx:609
virtual void SAL_CALL hideDisabledEntries(sal_Bool bHide) override
Definition: vclxmenu.cxx:641
VCLXMenu()
Definition: vclxmenu.cxx:39
virtual css::awt::MenuItemType SAL_CALL getItemType(::sal_Int16 nItemPos) override
Definition: vclxmenu.cxx:625
virtual sal_Int16 SAL_CALL getItemPos(sal_Int16 nId) override
Definition: vclxmenu.cxx:326
void * getUserValue(sal_uInt16 nItemId)
Definition: vclxmenu.cxx:826
virtual OUString SAL_CALL getItemText(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:366
css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: vclxmenu.cxx:255
VclPtr< Menu > mpMenu
Definition: vclxmenu.hxx:60
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL getItemImage(::sal_Int16 nItemId) override
Definition: vclxmenu.cxx:801
virtual OUString SAL_CALL getCommand(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:503
virtual void SAL_CALL setHelpCommand(sal_Int16 nItemId, const OUString &aHelp) override
Definition: vclxmenu.cxx:515
virtual void SAL_CALL removeMenuListener(const css::uno::Reference< css::awt::XMenuListener > &xListener) override
Definition: vclxmenu.cxx:268
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: vclxmenu.cxx:199
virtual void SAL_CALL enableAutoMnemonics(sal_Bool bEnable) override
Definition: vclxmenu.cxx:678
virtual void SAL_CALL setHelpText(::sal_Int16 nItemId, const OUString &sHelpText) override
Definition: vclxmenu.cxx:725
virtual void SAL_CALL setTipHelpText(::sal_Int16 nItemId, const OUString &sTipHelpText) override
Definition: vclxmenu.cxx:755
virtual OUString SAL_CALL getImplementationName() override
Definition: vclxmenu.cxx:168
virtual sal_Bool SAL_CALL isInExecute() override
Definition: vclxmenu.cxx:656
std::mutex maMutex
Definition: vclxmenu.hxx:59
virtual sal_Int16 SAL_CALL getItemId(sal_Int16 nPos) override
Definition: vclxmenu.cxx:317
void ImplAddListener()
Definition: vclxmenu.cxx:81
virtual css::uno::Reference< css::awt::XPopupMenu > SAL_CALL getPopupMenu(sal_Int16 nItemId) override
Definition: vclxmenu.cxx:396
virtual void SAL_CALL insertItem(sal_Int16 nItemId, const OUString &aText, sal_Int16 nItemStyle, sal_Int16 nPos) override
Definition: vclxmenu.cxx:276
virtual OUString SAL_CALL getHelpText(::sal_Int16 nItemId) override
Definition: vclxmenu.cxx:739
Menu * GetMenu() const
Definition: vclxmenu.hxx:78
virtual void SAL_CALL endExecute() override
Definition: vclxmenu.cxx:668
virtual void SAL_CALL insertSeparator(sal_Int16 nPos) override
Definition: vclxmenu.cxx:427
void setUserValue(sal_uInt16 nItemId, void *nUserValue, MenuUserDataReleaseFunction aFunc)
Definition: vclxmenu.cxx:818
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: vclxmenu.cxx:230
virtual void SAL_CALL setAcceleratorKeyEvent(::sal_Int16 nItemId, const css::awt::KeyEvent &aKeyEvent) override
Definition: vclxmenu.cxx:693
void disposeAndClear()
reference_type * get() const
static VclPtr< reference_type > Create(Arg &&... arg)
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
bool IsMod1() const
sal_uInt16 GetCode() const
bool IsShift() const
bool IsMod2() const
bool IsMod3() const
inline ::tools::Rectangle VCLRectangle(const css::awt::Rectangle &rAWTRect)
Definition: convert.hxx:54
int nCount
#define DBG_ASSERT(sCon, aError)
sal_Int64 n
sal_uInt16 nPos
PopupMenuFlags
constexpr sal_uInt16 MENU_ITEM_NOTFOUND
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
bool IsInPopupMenuExecute()
sal_Int16 nId
OUString aCommand
const char * implName
unsigned char sal_Bool
bool bPopup
MenuItemBits
IMPL_LINK(VCLXMenu, MenuEventListener, VclMenuEvent &, rMenuEvent, void)
Definition: vclxmenu.cxx:87
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_VCLXMenuBar_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: vclxmenu.cxx:844
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * stardiv_Toolkit_VCLXPopupMenu_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: vclxmenu.cxx:862
void(* MenuUserDataReleaseFunction)(void *)
Definition: vclxmenu.hxx:50