1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
21 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
22 #include <comphelper/processfactory.hxx>
24 #include <vcl/dockwin.hxx>
25 #include <vcl/decoview.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/taskpanelist.hxx>
28 #include <vcl/toolbox.hxx>
30 #include "svtools/valueset.hxx"
31 #include "svtools/toolbarmenu.hxx"
32 #include "toolbarmenuimp.hxx"
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::frame
;
37 using namespace ::com::sun::star::accessibility
;
41 // --------------------------------------------------------------------
43 static Window
* GetTopMostParentSystemWindow( Window
* pWindow
)
45 OSL_ASSERT( pWindow
);
48 // ->manually search topmost system window
49 // required because their might be another system window between this and the top window
50 pWindow
= pWindow
->GetParent();
51 SystemWindow
* pTopMostSysWin
= NULL
;
54 if ( pWindow
->IsSystemWindow() )
55 pTopMostSysWin
= (SystemWindow
*)pWindow
;
56 pWindow
= pWindow
->GetParent();
58 pWindow
= pTopMostSysWin
;
59 OSL_ASSERT( pWindow
);
66 // --------------------------------------------------------------------
68 void ToolbarMenuEntry::init( int nEntryId
, MenuItemBits nBits
)
81 // --------------------------------------------------------------------
83 ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, const String
& rText
, MenuItemBits nBits
)
86 init( nEntryId
, nBits
);
92 // --------------------------------------------------------------------
94 ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, const Image
& rImage
, const String
& rText
, MenuItemBits nBits
)
97 init( nEntryId
, nBits
);
106 // --------------------------------------------------------------------
108 ToolbarMenuEntry::ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, Control
* pControl
, MenuItemBits nBits
)
111 init( nEntryId
, nBits
);
115 mpControl
= pControl
;
120 // --------------------------------------------------------------------
122 ToolbarMenuEntry::~ToolbarMenuEntry()
124 if( mxAccContext
.is() )
126 Reference
< XComponent
> xComponent( mxAccContext
, UNO_QUERY
);
127 if( xComponent
.is() )
128 xComponent
->dispose();
129 mxAccContext
.clear();
134 // --------------------------------------------------------------------
136 const Reference
< XAccessibleContext
>& ToolbarMenuEntry::GetAccessible( bool bCreate
/* = false */ )
138 if( !mxAccContext
.is() && bCreate
)
142 mxAccContext
= Reference
< XAccessibleContext
>( mpControl
->GetAccessible( sal_True
), UNO_QUERY
);
146 mxAccContext
= Reference
< XAccessibleContext
>( new ToolbarMenuEntryAcc( this ) );
153 // --------------------------------------------------------------------
155 sal_Int32
ToolbarMenuEntry::getAccessibleChildCount() throw (RuntimeException
)
159 const Reference
< XAccessibleContext
>& xContext
= GetAccessible( true );
162 return xContext
->getAccessibleChildCount();
168 // --------------------------------------------------------------------
170 Reference
< XAccessible
> ToolbarMenuEntry::getAccessibleChild( sal_Int32 index
) throw (IndexOutOfBoundsException
, RuntimeException
)
172 const Reference
< XAccessibleContext
>& xContext
= GetAccessible( true );
177 return xContext
->getAccessibleChild(index
);
180 else if( index
== 0 )
182 Reference
< XAccessible
> xRet( xContext
, UNO_QUERY
);
187 throw IndexOutOfBoundsException();
190 // --------------------------------------------------------------------
192 ToolbarMenu_Impl::ToolbarMenu_Impl( ToolbarMenu
& rMenu
, const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
)
198 , mnHighlightedEntry(-1)
199 , mnSelectedEntry(-1)
204 // --------------------------------------------------------------------
206 ToolbarMenu_Impl::~ToolbarMenu_Impl()
211 // --------------------------------------------------------------------
213 void ToolbarMenu_Impl::setAccessible( ToolbarMenuAcc
* pAccessible
)
215 if( mxAccessible
.get() != pAccessible
)
217 if( mxAccessible
.is() )
218 mxAccessible
->dispose();
220 mxAccessible
.set( pAccessible
);
224 // -----------------------------------------------------------------------
226 void ToolbarMenu_Impl::fireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
)
228 if( mxAccessible
.is() )
229 mxAccessible
->FireAccessibleEvent( nEventId
, rOldValue
, rNewValue
);
232 // -----------------------------------------------------------------------
234 bool ToolbarMenu_Impl::hasAccessibleListeners()
236 return( mxAccessible
.is() && mxAccessible
->HasAccessibleListeners() );
239 // --------------------------------------------------------------------
241 sal_Int32
ToolbarMenu_Impl::getAccessibleChildCount() throw (RuntimeException
)
243 sal_Int32 nCount
= 0;
244 const int nEntryCount
= maEntryVector
.size();
245 for( int nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
247 ToolbarMenuEntry
* pEntry
= maEntryVector
[nEntry
];
250 if( pEntry
->mpControl
)
252 nCount
+= pEntry
->getAccessibleChildCount();
264 // --------------------------------------------------------------------
266 Reference
< XAccessible
> ToolbarMenu_Impl::getAccessibleChild( sal_Int32 index
) throw (IndexOutOfBoundsException
, RuntimeException
)
268 const int nEntryCount
= maEntryVector
.size();
269 for( int nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
271 ToolbarMenuEntry
* pEntry
= maEntryVector
[nEntry
];
274 const sal_Int32 nCount
= pEntry
->getAccessibleChildCount();
277 return pEntry
->getAccessibleChild( index
);
283 throw IndexOutOfBoundsException();
286 // --------------------------------------------------------------------
288 Reference
< XAccessible
> ToolbarMenu_Impl::getAccessibleChild( Control
* pControl
, sal_Int32 childIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
290 const int nEntryCount
= maEntryVector
.size();
291 for( int nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
293 ToolbarMenuEntry
* pEntry
= maEntryVector
[nEntry
];
294 if( pEntry
&& (pEntry
->mpControl
== pControl
) )
296 return pEntry
->getAccessibleChild( childIndex
);
300 throw IndexOutOfBoundsException();
303 // --------------------------------------------------------------------
305 void ToolbarMenu_Impl::selectAccessibleChild( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
307 const int nEntryCount
= maEntryVector
.size();
308 for( int nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
310 ToolbarMenuEntry
* pEntry
= maEntryVector
[nEntry
];
313 const sal_Int32 nCount
= pEntry
->getAccessibleChildCount();
314 if( nChildIndex
< nCount
)
316 if( pEntry
->mpControl
)
318 Reference
< XAccessibleSelection
> xSel( pEntry
->GetAccessible(true), UNO_QUERY_THROW
);
319 xSel
->selectAccessibleChild(nChildIndex
);
321 else if( pEntry
->mnEntryId
!= TITLE_ID
)
323 mrMenu
.implSelectEntry( nEntry
);
327 nChildIndex
-= nCount
;
331 throw IndexOutOfBoundsException();
334 // --------------------------------------------------------------------
336 sal_Bool
ToolbarMenu_Impl::isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
338 const int nEntryCount
= maEntryVector
.size();
339 for( int nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
341 ToolbarMenuEntry
* pEntry
= maEntryVector
[nEntry
];
344 const sal_Int32 nCount
= pEntry
->getAccessibleChildCount();
345 if( nChildIndex
< nCount
)
347 if( mnHighlightedEntry
== nEntry
)
349 if( pEntry
->mpControl
)
351 Reference
< XAccessibleSelection
> xSel( pEntry
->GetAccessible(true), UNO_QUERY_THROW
);
352 xSel
->isAccessibleChildSelected(nChildIndex
);
361 nChildIndex
-= nCount
;
365 throw IndexOutOfBoundsException();
368 // --------------------------------------------------------------------
370 void ToolbarMenu_Impl::clearAccessibleSelection()
372 if( mnHighlightedEntry
!= -1 )
374 mrMenu
.implHighlightEntry( mnHighlightedEntry
, false );
375 mnHighlightedEntry
= -1;
380 // --------------------------------------------------------------------
382 void ToolbarMenu_Impl::notifyHighlightedEntry()
384 if( hasAccessibleListeners() )
386 ToolbarMenuEntry
* pEntry
= implGetEntry( mnHighlightedEntry
);
387 if( pEntry
&& pEntry
->mbEnabled
&& (pEntry
->mnEntryId
!= TITLE_ID
) )
390 Any
aOld( mxOldSelection
);
391 if( pEntry
->mpControl
)
393 sal_Int32 nChildIndex
= 0;
394 // todo: if other controls than ValueSet are allowed, addapt this code
395 ValueSet
* pValueSet
= dynamic_cast< ValueSet
* >( pEntry
->mpControl
);
397 nChildIndex
= static_cast< sal_Int32
>( pValueSet
->GetItemPos( pValueSet
->GetSelectItemId() ) );
399 if( nChildIndex
>= pEntry
->getAccessibleChildCount() )
402 aNew
<<= getAccessibleChild( pEntry
->mpControl
, nChildIndex
);
406 aNew
<<= pEntry
->GetAccessible(true);
409 fireAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
, aOld
, aNew
);
410 fireAccessibleEvent( AccessibleEventId::SELECTION_CHANGED
, aOld
, aNew
);
411 fireAccessibleEvent( AccessibleEventId::STATE_CHANGED
, Any(), Any( AccessibleStateType::FOCUSED
) );
412 aNew
>>= mxOldSelection
;
417 // --------------------------------------------------------------------
419 ToolbarMenuEntry
* ToolbarMenu_Impl::implGetEntry( int nEntry
) const
421 if( (nEntry
< 0) || (nEntry
>= (int)maEntryVector
.size() ) )
424 return maEntryVector
[nEntry
];
428 // --------------------------------------------------------------------
430 IMPL_LINK( ToolbarMenu
, HighlightHdl
, Control
*, pControl
)
433 mpImpl
->notifyHighlightedEntry();
437 // ====================================================================
439 ToolbarMenu::ToolbarMenu( const Reference
< XFrame
>& rFrame
, Window
* pParentWindow
, WinBits nBits
)
440 : DockingWindow(pParentWindow
, nBits
)
445 // --------------------------------------------------------------------
447 ToolbarMenu::ToolbarMenu( const Reference
< XFrame
>& rFrame
, Window
* pParentWindow
, const ResId
& rResId
)
448 : DockingWindow(pParentWindow
, rResId
)
453 // --------------------------------------------------------------------
455 void ToolbarMenu::implInit(const Reference
< XFrame
>& rFrame
)
457 mpImpl
= new ToolbarMenu_Impl( *this, rFrame
);
459 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
460 SetControlBackground( rStyleSettings
.GetMenuColor() );
464 Window
* pWindow
= GetTopMostParentSystemWindow( this );
466 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
469 // --------------------------------------------------------------------
471 ToolbarMenu::~ToolbarMenu()
473 Window
* pWindow
= GetTopMostParentSystemWindow( this );
475 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->RemoveWindow( this );
477 if ( mpImpl
->mxStatusListener
.is() )
479 mpImpl
->mxStatusListener
->dispose();
480 mpImpl
->mxStatusListener
.clear();
483 // delete all menu entries
484 const int nEntryCount
= mpImpl
->maEntryVector
.size();
486 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
488 delete mpImpl
->maEntryVector
[nEntry
];
494 // --------------------------------------------------------------------
496 int ToolbarMenu::getSelectedEntryId() const
498 ToolbarMenuEntry
* pEntry
= implGetEntry( mpImpl
->mnSelectedEntry
);
499 return pEntry
? pEntry
->mnEntryId
: -1;
502 // --------------------------------------------------------------------
504 int ToolbarMenu::getHighlightedEntryId() const
506 ToolbarMenuEntry
* pEntry
= implGetEntry( mpImpl
->mnHighlightedEntry
);
507 return pEntry
? pEntry
->mnEntryId
: -1;
510 // --------------------------------------------------------------------
512 void ToolbarMenu::checkEntry( int nEntryId
, bool bChecked
)
514 ToolbarMenuEntry
* pEntry
= implSearchEntry( nEntryId
);
515 if( pEntry
&& pEntry
->mbChecked
!= bChecked
)
517 pEntry
->mbChecked
= bChecked
;
522 // --------------------------------------------------------------------
524 void ToolbarMenu::enableEntry( int nEntryId
, bool bEnable
)
526 ToolbarMenuEntry
* pEntry
= implSearchEntry( nEntryId
);
527 if( pEntry
&& pEntry
->mbEnabled
!= bEnable
)
529 pEntry
->mbEnabled
= bEnable
;
530 if( pEntry
->mpControl
)
532 pEntry
->mpControl
->Enable( bEnable
);
534 // hack for the valueset to make it paint itself anew
535 pEntry
->mpControl
->Resize();
541 // --------------------------------------------------------------------
543 void ToolbarMenu::setEntryText( int nEntryId
, const String
& rStr
)
545 ToolbarMenuEntry
* pEntry
= implSearchEntry( nEntryId
);
546 if( pEntry
&& pEntry
->maText
!= rStr
)
548 pEntry
->maText
= rStr
;
549 mpImpl
->maSize
= implCalcSize();
555 // --------------------------------------------------------------------
557 void ToolbarMenu::setEntryImage( int nEntryId
, const Image
& rImage
)
559 ToolbarMenuEntry
* pEntry
= implSearchEntry( nEntryId
);
560 if( pEntry
&& pEntry
->maImage
!= rImage
)
562 pEntry
->maImage
= rImage
;
563 mpImpl
->maSize
= implCalcSize();
569 // --------------------------------------------------------------------
571 void ToolbarMenu::initWindow()
573 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
575 SetPointFont( rStyleSettings
.GetMenuFont() );
576 SetBackground( Wallpaper( GetControlBackground() ) );
577 SetTextColor( rStyleSettings
.GetMenuTextColor() );
581 mpImpl
->maSize
= implCalcSize();
584 // --------------------------------------------------------------------
586 static long ImplGetNativeCheckAndRadioSize( Window
* pWin
, long& rCheckHeight
, long& rRadioHeight
, long &rMaxWidth
)
588 rMaxWidth
= rCheckHeight
= rRadioHeight
= 0;
590 ImplControlValue aVal
;
591 Rectangle aNativeBounds
;
592 Rectangle aNativeContent
;
594 Rectangle
aCtrlRegion( tmp
, Size( 100, 15 ) );
595 if( pWin
->IsNativeControlSupported( CTRL_MENU_POPUP
, PART_MENU_ITEM_CHECK_MARK
) )
597 if( pWin
->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP
),
598 ControlPart(PART_MENU_ITEM_CHECK_MARK
),
600 ControlState(CTRL_STATE_ENABLED
),
607 rCheckHeight
= aNativeBounds
.GetHeight();
608 rMaxWidth
= aNativeContent
.GetWidth();
611 if( pWin
->IsNativeControlSupported( CTRL_MENU_POPUP
, PART_MENU_ITEM_RADIO_MARK
) )
613 if( pWin
->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP
),
614 ControlPart(PART_MENU_ITEM_RADIO_MARK
),
616 ControlState(CTRL_STATE_ENABLED
),
623 rRadioHeight
= aNativeBounds
.GetHeight();
624 rMaxWidth
= std::max (rMaxWidth
, aNativeContent
.GetWidth());
627 return (rCheckHeight
> rRadioHeight
) ? rCheckHeight
: rRadioHeight
;
632 Size
ToolbarMenu::implCalcSize()
634 const long nFontHeight
= GetTextHeight();
635 long nExtra
= nFontHeight
/4;
639 long nMaxTextWidth
= 0;
640 long nMinMenuItemHeight
= nFontHeight
+2;
641 sal_Bool bCheckable
= sal_False
;
643 const int nEntryCount
= mpImpl
->maEntryVector
.size();
646 const StyleSettings
& rSettings
= GetSettings().GetStyleSettings();
647 const bool bUseImages
= rSettings
.GetUseImagesInMenus();
649 // get maximum image size
652 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
654 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
655 if( pEntry
&& pEntry
->mbHasImage
)
657 Size
aImgSz( pEntry
->maImage
.GetSizePixel() );
658 nMinMenuItemHeight
= std::max( nMinMenuItemHeight
, aImgSz
.Height() + 6 );
659 aMaxImgSz
.Width() = std::max( aMaxImgSz
.Width(), aImgSz
.Width() );
664 mpImpl
->mnCheckPos
= nExtra
;
665 mpImpl
->mnImagePos
= nExtra
;
666 mpImpl
->mnTextPos
= mpImpl
->mnImagePos
+ aMaxImgSz
.Width();
668 if ( aMaxImgSz
.Width() )
669 mpImpl
->mnTextPos
+= std::max( nExtra
, 7L );
671 mpImpl
->mnTextPos
+= 16;
673 // set heights, calc maximum width
674 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
676 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
680 if ( ( pEntry
->mnBits
) & ( MIB_RADIOCHECK
| MIB_CHECKABLE
) )
681 bCheckable
= sal_True
;
684 if( pEntry
->mbHasText
|| pEntry
->mbHasImage
)
686 pEntry
->maSize
.Height() = nMinMenuItemHeight
;
688 if( pEntry
->mbHasText
)
690 long nTextWidth
= GetCtrlTextWidth( pEntry
->maText
) + mpImpl
->mnTextPos
+ nExtra
;
691 nMaxTextWidth
= std::max( nTextWidth
, nMaxTextWidth
);
695 else if( pEntry
->mpControl
)
697 Size
aControlSize( pEntry
->mpControl
->GetOutputSizePixel() );
699 nMaxTextWidth
= std::max( aControlSize
.Width(), nMaxTextWidth
);
700 pEntry
->maSize
.Height() = aControlSize
.Height() + 1;
703 if( pEntry
->HasCheck() && !pEntry
->mbHasImage
)
705 if( this->IsNativeControlSupported( CTRL_MENU_POPUP
,
706 (pEntry
->mnBits
& MIB_RADIOCHECK
)
707 ? PART_MENU_ITEM_CHECK_MARK
708 : PART_MENU_ITEM_RADIO_MARK
) )
710 long nCheckHeight
= 0, nRadioHeight
= 0, nMaxCheckWidth
= 0;
711 ImplGetNativeCheckAndRadioSize( this, nCheckHeight
, nRadioHeight
, nMaxCheckWidth
);
713 long nCtrlHeight
= (pEntry
->mnBits
& MIB_RADIOCHECK
) ? nCheckHeight
: nRadioHeight
;
714 nMaxTextWidth
+= nCtrlHeight
+ gfxExtra
;
716 else if( pEntry
->mbChecked
)
718 long nSymbolWidth
= (nFontHeight
*25)/40;
719 if ( pEntry
->mnBits
& MIB_RADIOCHECK
)
720 nSymbolWidth
= nFontHeight
/2;
722 nMaxTextWidth
+= nSymbolWidth
;
728 aSz
.Width() = nMaxTextWidth
+ (BORDER_X
<<1);
730 // positionate controls
732 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
734 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
738 pEntry
->maSize
.Width() = nMaxTextWidth
;
740 if( pEntry
->mpControl
)
742 Size
aControlSize( pEntry
->mpControl
->GetOutputSizePixel() );
743 Point
aControlPos( (aSz
.Width() - aControlSize
.Width())>>1, nY
);
745 pEntry
->mpControl
->SetPosPixel( aControlPos
);
747 pEntry
->maRect
= Rectangle( aControlPos
, aControlSize
);
751 pEntry
->maRect
= Rectangle( Point( 0, nY
), pEntry
->maSize
);
754 nY
+= pEntry
->maSize
.Height();
758 nY
+= SEPARATOR_HEIGHT
;
762 aSz
.Height() += nY
+ BORDER_Y
;
767 // --------------------------------------------------------------------
769 void ToolbarMenu::highlightFirstEntry()
771 implChangeHighlightEntry( 0 );
774 // --------------------------------------------------------------------
776 void ToolbarMenu::GetFocus()
778 if( mpImpl
->mnHighlightedEntry
== -1 )
779 implChangeHighlightEntry( 0 );
781 DockingWindow::GetFocus();
784 // --------------------------------------------------------------------
786 void ToolbarMenu::LoseFocus()
788 if( mpImpl
->mnHighlightedEntry
!= -1 )
789 implChangeHighlightEntry( -1 );
791 DockingWindow::LoseFocus();
794 // --------------------------------------------------------------------
796 void ToolbarMenu::appendEntry( int nEntryId
, const String
& rStr
, MenuItemBits nItemBits
)
798 appendEntry( new ToolbarMenuEntry( *this, nEntryId
, rStr
, nItemBits
) );
801 // --------------------------------------------------------------------
803 void ToolbarMenu::appendEntry( int nEntryId
, const String
& rStr
, const Image
& rImage
, MenuItemBits nItemBits
)
805 appendEntry( new ToolbarMenuEntry( *this, nEntryId
, rImage
, rStr
, nItemBits
) );
808 // --------------------------------------------------------------------
810 void ToolbarMenu::appendEntry( int nEntryId
, Control
* pControl
, MenuItemBits nItemBits
)
812 appendEntry( new ToolbarMenuEntry( *this, nEntryId
, pControl
, nItemBits
) );
815 // --------------------------------------------------------------------
817 void ToolbarMenu::appendEntry( ToolbarMenuEntry
* pEntry
)
819 mpImpl
->maEntryVector
.push_back( pEntry
);
820 mpImpl
->maSize
= implCalcSize();
825 // --------------------------------------------------------------------
827 void ToolbarMenu::appendSeparator()
832 // --------------------------------------------------------------------
834 /** creates an empty ValueSet that is initialized and can be inserted with appendEntry. */
835 ValueSet
* ToolbarMenu::createEmptyValueSetControl()
837 ValueSet
* pSet
= new ValueSet( this, WB_TABSTOP
| WB_MENUSTYLEVALUESET
| WB_FLATVALUESET
| WB_NOBORDER
| WB_NO_DIRECTSELECT
);
838 pSet
->EnableFullItemMode( sal_False
);
839 pSet
->SetColor( GetControlBackground() );
840 pSet
->SetHighlightHdl( LINK( this, ToolbarMenu
, HighlightHdl
) );
844 // --------------------------------------------------------------------
846 ToolbarMenuEntry
* ToolbarMenu::implGetEntry( int nEntry
) const
848 return mpImpl
->implGetEntry( nEntry
);
851 // --------------------------------------------------------------------
853 ToolbarMenuEntry
* ToolbarMenu::implSearchEntry( int nEntryId
) const
855 const int nEntryCount
= mpImpl
->maEntryVector
.size();
857 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
859 ToolbarMenuEntry
* p
= mpImpl
->maEntryVector
[nEntry
];
860 if( p
&& p
->mnEntryId
== nEntryId
)
869 // --------------------------------------------------------------------
871 void ToolbarMenu::implHighlightEntry( int nHighlightEntry
, bool bHighlight
)
873 Size
aSz( GetOutputSizePixel() );
876 const int nEntryCount
= mpImpl
->maEntryVector
.size();
878 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
880 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
881 if( pEntry
&& (nEntry
== nHighlightEntry
) )
883 // no highlights for controls only items
884 if( pEntry
->mpControl
)
888 ValueSet
* pValueSet
= dynamic_cast< ValueSet
* >( pEntry
->mpControl
);
891 pValueSet
->SetNoSelection();
897 bool bRestoreLineColor
= false;
899 bool bDrawItemRect
= true;
901 Rectangle
aItemRect( Point( nX
, nY
), Size( aSz
.Width(), pEntry
->maSize
.Height() ) );
902 if ( pEntry
->mnBits
& MIB_POPUPSELECT
)
904 long nFontHeight
= GetTextHeight();
905 aItemRect
.Right() -= nFontHeight
+ nFontHeight
/4;
908 if( IsNativeControlSupported( CTRL_MENU_POPUP
, PART_ENTIRE_CONTROL
) )
910 Size
aPxSize( GetOutputSizePixel() );
911 Push( PUSH_CLIPREGION
);
912 IntersectClipRegion( Rectangle( Point( nX
, nY
), Size( aSz
.Width(), pEntry
->maSize
.Height() ) ) );
913 Rectangle
aCtrlRect( Point( nX
, 0 ), Size( aPxSize
.Width()-nX
, aPxSize
.Height() ) );
914 DrawNativeControl( CTRL_MENU_POPUP
, PART_ENTIRE_CONTROL
,
919 if( bHighlight
&& IsNativeControlSupported( CTRL_MENU_POPUP
, PART_MENU_ITEM
) )
921 bDrawItemRect
= false;
922 if( sal_False
== DrawNativeControl( CTRL_MENU_POPUP
, PART_MENU_ITEM
,
924 CTRL_STATE_SELECTED
| ( pEntry
->mbEnabled
? CTRL_STATE_ENABLED
: 0 ),
928 bDrawItemRect
= bHighlight
;
932 bDrawItemRect
= bHighlight
;
939 if( pEntry
->mbEnabled
)
940 SetFillColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
944 oldLineColor
= GetLineColor();
945 SetLineColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
946 bRestoreLineColor
= true;
950 SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
952 DrawRect( aItemRect
);
954 implPaint( pEntry
, bHighlight
);
955 if( bRestoreLineColor
)
956 SetLineColor( oldLineColor
);
960 nY
+= pEntry
? pEntry
->maSize
.Height() : SEPARATOR_HEIGHT
;
964 // --------------------------------------------------------------------
966 void ToolbarMenu::implSelectEntry( int nSelectedEntry
)
968 mpImpl
->mnSelectedEntry
= nSelectedEntry
;
970 ToolbarMenuEntry
* pEntry
= NULL
;
971 if( nSelectedEntry
!= -1 )
972 pEntry
= mpImpl
->maEntryVector
[ nSelectedEntry
];
975 mpImpl
->maSelectHdl
.Call( this );
978 // --------------------------------------------------------------------
980 void ToolbarMenu::MouseButtonDown( const MouseEvent
& rMEvt
)
982 implHighlightEntry( rMEvt
, true );
984 implSelectEntry( mpImpl
->mnHighlightedEntry
);
987 // --------------------------------------------------------------------
989 void ToolbarMenu::MouseButtonUp( const MouseEvent
& )
993 // --------------------------------------------------------------------
995 void ToolbarMenu::MouseMove( const MouseEvent
& rMEvt
)
1000 implHighlightEntry( rMEvt
, false );
1003 // --------------------------------------------------------------------
1005 void ToolbarMenu::implHighlightEntry( const MouseEvent
& rMEvt
, bool /*bMBDown*/ )
1008 long nMouseY
= rMEvt
.GetPosPixel().Y();
1009 Size aOutSz
= GetOutputSizePixel();
1010 if ( ( nMouseY
>= 0 ) && ( nMouseY
< aOutSz
.Height() ) )
1012 bool bHighlighted
= sal_False
;
1014 const int nEntryCount
= mpImpl
->maEntryVector
.size();
1016 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
1018 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
1022 nY
+= pEntry
->maSize
.Height();
1024 if( pEntry
->mnEntryId
!= TITLE_ID
)
1026 if ( ( nOldY
<= nMouseY
) && ( nY
> nMouseY
) )
1028 if( nEntry
!= mpImpl
->mnHighlightedEntry
)
1030 implChangeHighlightEntry( nEntry
);
1032 bHighlighted
= true;
1038 nY
+= SEPARATOR_HEIGHT
;
1041 if ( !bHighlighted
)
1042 implChangeHighlightEntry( -1 );
1046 implChangeHighlightEntry( -1 );
1050 // --------------------------------------------------------------------
1052 void ToolbarMenu::implChangeHighlightEntry( int nEntry
)
1054 if( mpImpl
->mnHighlightedEntry
!= -1 )
1056 implHighlightEntry( mpImpl
->mnHighlightedEntry
, false );
1059 mpImpl
->mnHighlightedEntry
= nEntry
;
1062 if( mpImpl
->mnHighlightedEntry
!= -1 )
1064 implHighlightEntry( mpImpl
->mnHighlightedEntry
, true );
1067 mpImpl
->notifyHighlightedEntry();
1070 // --------------------------------------------------------------------
1072 static bool implCheckSubControlCursorMove( Control
* pControl
, bool bUp
, int& nLastColumn
)
1074 ValueSet
* pValueSet
= dynamic_cast< ValueSet
* >( pControl
);
1077 sal_uInt16 nItemPos
= pValueSet
->GetItemPos( pValueSet
->GetSelectItemId() );
1078 if( nItemPos
!= VALUESET_ITEM_NOTFOUND
)
1080 const sal_uInt16 nColCount
= pValueSet
->GetColCount();
1081 const sal_uInt16 nLine
= nItemPos
/ nColCount
;
1083 nLastColumn
= nItemPos
- (nLine
* nColCount
);
1091 const sal_uInt16 nLineCount
= (pValueSet
->GetItemCount() + nColCount
- 1) / nColCount
;
1092 return (nLine
+1) < nLineCount
;
1100 // --------------------------------------------------------------------
1102 ToolbarMenuEntry
* ToolbarMenu::implCursorUpDown( bool bUp
, bool bHomeEnd
)
1104 int n
= 0, nLoop
= 0;
1107 n
= mpImpl
->mnHighlightedEntry
;
1113 n
= mpImpl
->maEntryVector
.size()-1;
1117 // if we have a currently selected entry and
1118 // cursor keys are used than check if this entry
1119 // has a control that can use those cursor keys
1120 ToolbarMenuEntry
* pData
= mpImpl
->maEntryVector
[n
];
1121 if( pData
&& pData
->mpControl
&& !pData
->mbHasText
)
1123 if( implCheckSubControlCursorMove( pData
->mpControl
, bUp
, mpImpl
->mnLastColumn
) )
1131 // absolute positioning
1134 n
= mpImpl
->maEntryVector
.size();
1140 nLoop
= mpImpl
->maEntryVector
.size()-1;
1151 if( mpImpl
->mnHighlightedEntry
== -1 )
1152 n
= mpImpl
->maEntryVector
.size()-1;
1158 if( n
< ((int)mpImpl
->maEntryVector
.size()-1) )
1161 if( mpImpl
->mnHighlightedEntry
== -1 )
1167 ToolbarMenuEntry
* pData
= mpImpl
->maEntryVector
[n
];
1168 if( pData
&& (pData
->mnEntryId
!= TITLE_ID
) )
1170 implChangeHighlightEntry( n
);
1173 } while ( n
!= nLoop
);
1178 // --------------------------------------------------------------------
1180 void ToolbarMenu_Impl::implHighlightControl( sal_uInt16 nCode
, Control
* pControl
)
1182 ValueSet
* pValueSet
= dynamic_cast< ValueSet
* >( pControl
);
1185 const sal_uInt16 nItemCount
= pValueSet
->GetItemCount();
1186 sal_uInt16 nItemPos
= VALUESET_ITEM_NOTFOUND
;
1191 const sal_uInt16 nColCount
= pValueSet
->GetColCount();
1192 const sal_uInt16 nLastLine
= nItemCount
/ nColCount
;
1193 nItemPos
= std::min( ((nLastLine
-1) * nColCount
) + mnLastColumn
, nItemCount
-1 );
1197 nItemPos
= std::min( mnLastColumn
, nItemCount
-1 );
1200 nItemPos
= nItemCount
-1;
1206 pValueSet
->SelectItem( pValueSet
->GetItemId( nItemPos
) );
1207 notifyHighlightedEntry();
1211 // --------------------------------------------------------------------
1213 void ToolbarMenu::KeyInput( const KeyEvent
& rKEvent
)
1215 Control
* pForwardControl
= 0;
1216 sal_uInt16 nCode
= rKEvent
.GetKeyCode().GetCode();
1222 int nOldEntry
= mpImpl
->mnHighlightedEntry
;
1223 ToolbarMenuEntry
*p
= implCursorUpDown( nCode
== KEY_UP
, false );
1224 if( p
&& p
->mpControl
)
1226 if( nOldEntry
!= mpImpl
->mnHighlightedEntry
)
1228 mpImpl
->implHighlightControl( nCode
, p
->mpControl
);
1232 // in case we are in a system floating window, GrabFocus does not work :-/
1233 pForwardControl
= p
->mpControl
;
1241 ToolbarMenuEntry
* p
= implCursorUpDown( nCode
== KEY_END
, true );
1242 if( p
&& p
->mpControl
)
1244 mpImpl
->implHighlightControl( nCode
, p
->mpControl
);
1251 // Ctrl-F6 acts like ESC here, the menu bar however will then put the focus in the document
1252 if( nCode
== KEY_F6
&& !rKEvent
.GetKeyCode().IsMod1() )
1255 implSelectEntry( -1 );
1261 ToolbarMenuEntry
* pEntry
= implGetEntry( mpImpl
->mnHighlightedEntry
);
1262 if ( pEntry
&& pEntry
->mbEnabled
&& (pEntry
->mnEntryId
!= TITLE_ID
) )
1264 if( pEntry
->mpControl
)
1266 pForwardControl
= pEntry
->mpControl
;
1270 implSelectEntry( mpImpl
->mnHighlightedEntry
);
1277 ToolbarMenuEntry
* pEntry
= implGetEntry( mpImpl
->mnHighlightedEntry
);
1278 if ( pEntry
&& pEntry
->mbEnabled
&& pEntry
->mpControl
&& !pEntry
->mbHasText
)
1280 pForwardControl
= pEntry
->mpControl
;
1285 if( pForwardControl
)
1286 pForwardControl
->KeyInput( rKEvent
);
1290 // --------------------------------------------------------------------
1291 static void ImplPaintCheckBackground( Window
* i_pWindow
, const Rectangle
& i_rRect
, bool i_bHighlight
)
1293 sal_Bool bNativeOk
= sal_False
;
1294 if( i_pWindow
->IsNativeControlSupported( CTRL_TOOLBAR
, PART_BUTTON
) )
1296 ImplControlValue aControlValue
;
1297 ControlState nState
= CTRL_STATE_PRESSED
| CTRL_STATE_ENABLED
;
1299 aControlValue
.setTristateVal( BUTTONVALUE_ON
);
1301 bNativeOk
= i_pWindow
->DrawNativeControl( CTRL_TOOLBAR
, PART_BUTTON
,
1302 i_rRect
, nState
, aControlValue
,
1308 const StyleSettings
& rSettings
= i_pWindow
->GetSettings().GetStyleSettings();
1309 Color
aColor( i_bHighlight
? rSettings
.GetMenuHighlightTextColor() : rSettings
.GetHighlightColor() );
1310 i_pWindow
->DrawSelectionBackground( i_rRect
, 0, i_bHighlight
, sal_True
, sal_False
, 2, NULL
, &aColor
);
1314 void ToolbarMenu::implPaint( ToolbarMenuEntry
* pThisOnly
, bool bHighlighted
)
1316 sal_uInt16 nBorder
= 0; long nStartY
= 0; // from Menu implementations, needed when we support native menu background & scrollable menu
1318 long nFontHeight
= GetTextHeight();
1319 // long nExtra = nFontHeight/4;
1321 long nCheckHeight
= 0, nRadioHeight
= 0, nMaxCheckWidth
= 0;
1322 ImplGetNativeCheckAndRadioSize( this, nCheckHeight
, nRadioHeight
, nMaxCheckWidth
);
1324 DecorationView
aDecoView( this );
1325 const StyleSettings
& rSettings
= GetSettings().GetStyleSettings();
1326 const bool bUseImages
= rSettings
.GetUseImagesInMenus();
1328 int nOuterSpace
= 0; // ImplGetSVData()->maNWFData.mnMenuFormatExtraBorder;
1329 Point
aTopLeft( nOuterSpace
, nOuterSpace
), aTmpPos
;
1331 Size
aOutSz( GetOutputSizePixel() );
1332 const int nEntryCount
= mpImpl
->maEntryVector
.size();
1334 for( nEntry
= 0; nEntry
< nEntryCount
; nEntry
++ )
1336 ToolbarMenuEntry
* pEntry
= mpImpl
->maEntryVector
[nEntry
];
1338 Point
aPos( aTopLeft
);
1339 aPos
.Y() += nBorder
;
1340 aPos
.Y() += nStartY
;
1343 if( (pEntry
== 0) && !pThisOnly
)
1346 aTmpPos
.Y() = aPos
.Y() + ((SEPARATOR_HEIGHT
-2)/2);
1347 aTmpPos
.X() = aPos
.X() + 2 + nOuterSpace
;
1348 SetLineColor( rSettings
.GetShadowColor() );
1349 DrawLine( aTmpPos
, Point( aOutSz
.Width() - 3 - 2*nOuterSpace
, aTmpPos
.Y() ) );
1351 SetLineColor( rSettings
.GetLightColor() );
1352 DrawLine( aTmpPos
, Point( aOutSz
.Width() - 3 - 2*nOuterSpace
, aTmpPos
.Y() ) );
1355 else if( !pThisOnly
|| ( pEntry
== pThisOnly
) )
1357 const bool bTitle
= pEntry
->mnEntryId
== TITLE_ID
;
1359 if ( pThisOnly
&& bHighlighted
)
1360 SetTextColor( rSettings
.GetMenuHighlightTextColor() );
1364 long nTextOffsetY
= ((pEntry
->maSize
.Height()-nFontHeight
)/2);
1366 sal_uInt16 nTextStyle
= 0;
1367 sal_uInt16 nSymbolStyle
= 0;
1368 sal_uInt16 nImageStyle
= 0;
1370 if( !pEntry
->mbEnabled
)
1372 nTextStyle
|= TEXT_DRAW_DISABLE
;
1373 nSymbolStyle
|= SYMBOL_DRAW_DISABLE
;
1374 nImageStyle
|= IMAGE_DRAW_DISABLE
;
1377 Rectangle
aOuterCheckRect( Point( aPos
.X()+mpImpl
->mnCheckPos
, aPos
.Y() ), Size( pEntry
->maSize
.Height(), pEntry
->maSize
.Height() ) );
1378 aOuterCheckRect
.Left() += 1;
1379 aOuterCheckRect
.Right() -= 1;
1380 aOuterCheckRect
.Top() += 1;
1381 aOuterCheckRect
.Bottom() -= 1;
1385 // fill the background
1386 Rectangle
aRect( aTopLeft
, Size( aOutSz
.Width(), pEntry
->maSize
.Height() ) );
1387 SetFillColor(rSettings
.GetDialogColor());
1390 SetLineColor( rSettings
.GetLightColor() );
1391 DrawLine( aRect
.TopLeft(), aRect
.TopRight() );
1392 SetLineColor( rSettings
.GetShadowColor() );
1393 DrawLine( aRect
.BottomLeft(), aRect
.BottomRight() );
1397 if ( pEntry
->HasCheck() )
1399 // draw selection transparent marker if checked
1400 // onto that either a checkmark or the item image
1402 // however do not do this if native checks will be painted since
1403 // the selection color too often does not fit the theme's check and/or radio
1405 if( !pEntry
->mbHasImage
)
1407 if( this->IsNativeControlSupported( CTRL_MENU_POPUP
,
1408 (pEntry
->mnBits
& MIB_RADIOCHECK
)
1409 ? PART_MENU_ITEM_CHECK_MARK
1410 : PART_MENU_ITEM_RADIO_MARK
) )
1412 ControlPart nPart
= ((pEntry
->mnBits
& MIB_RADIOCHECK
)
1413 ? PART_MENU_ITEM_RADIO_MARK
1414 : PART_MENU_ITEM_CHECK_MARK
);
1416 ControlState nState
= 0;
1418 if ( pEntry
->mbChecked
)
1419 nState
|= CTRL_STATE_PRESSED
;
1421 if ( pEntry
->mbEnabled
)
1422 nState
|= CTRL_STATE_ENABLED
;
1425 nState
|= CTRL_STATE_SELECTED
;
1427 long nCtrlHeight
= (pEntry
->mnBits
& MIB_RADIOCHECK
) ? nCheckHeight
: nRadioHeight
;
1428 aTmpPos
.X() = aOuterCheckRect
.Left() + (aOuterCheckRect
.GetWidth() - nCtrlHeight
)/2;
1429 aTmpPos
.Y() = aOuterCheckRect
.Top() + (aOuterCheckRect
.GetHeight() - nCtrlHeight
)/2;
1431 Rectangle
aCheckRect( aTmpPos
, Size( nCtrlHeight
, nCtrlHeight
) );
1432 DrawNativeControl( CTRL_MENU_POPUP
, nPart
, aCheckRect
, nState
, ImplControlValue(), OUString() );
1433 aPos
.setX( aPos
.getX() + nCtrlHeight
+ gfxExtra
);
1435 else if ( pEntry
->mbChecked
) // by default do nothing for unchecked items
1437 ImplPaintCheckBackground( this, aOuterCheckRect
, pThisOnly
&& bHighlighted
);
1441 if ( pEntry
->mnBits
& MIB_RADIOCHECK
)
1443 eSymbol
= SYMBOL_RADIOCHECKMARK
;
1444 aSymbolSize
= Size( nFontHeight
/2, nFontHeight
/2 );
1448 eSymbol
= SYMBOL_CHECKMARK
;
1449 aSymbolSize
= Size( (nFontHeight
*25)/40, nFontHeight
/2 );
1451 aTmpPos
.X() = aOuterCheckRect
.Left() + (aOuterCheckRect
.GetWidth() - aSymbolSize
.Width())/2;
1452 aTmpPos
.Y() = aOuterCheckRect
.Top() + (aOuterCheckRect
.GetHeight() - aSymbolSize
.Height())/2;
1453 Rectangle
aRect( aTmpPos
, aSymbolSize
);
1454 aDecoView
.DrawSymbol( aRect
, eSymbol
, GetTextColor(), nSymbolStyle
);
1455 aPos
.setX( aPos
.getX() + aSymbolSize
.getWidth( ) + gfxExtra
);
1461 if( pEntry
->mbHasImage
&& bUseImages
)
1463 if( pEntry
->mbChecked
)
1464 ImplPaintCheckBackground( this, aOuterCheckRect
, pThisOnly
&& bHighlighted
);
1465 aTmpPos
= aOuterCheckRect
.TopLeft();
1466 aTmpPos
.X() += (aOuterCheckRect
.GetWidth()-pEntry
->maImage
.GetSizePixel().Width())/2;
1467 aTmpPos
.Y() += (aOuterCheckRect
.GetHeight()-pEntry
->maImage
.GetSizePixel().Height())/2;
1468 DrawImage( aTmpPos
, pEntry
->maImage
, nImageStyle
);
1472 if( pEntry
->mbHasText
)
1474 aTmpPos
.X() = aPos
.X() + (bTitle
? 4 : mpImpl
->mnTextPos
);
1475 aTmpPos
.Y() = aPos
.Y();
1476 aTmpPos
.Y() += nTextOffsetY
;
1477 sal_uInt16 nStyle
= nTextStyle
|TEXT_DRAW_MNEMONIC
;
1479 DrawCtrlText( aTmpPos
, pEntry
->maText
, 0, pEntry
->maText
.Len(), nStyle
, NULL
, NULL
); // pVector, pDisplayText );
1482 if ( pThisOnly
&& bHighlighted
)
1484 // This restores the normal menu or menu bar text
1485 // color for when it is no longer highlighted.
1486 SetTextColor( rSettings
.GetMenuTextColor() );
1491 aTopLeft
.Y() += pEntry
? pEntry
->maSize
.Height() : SEPARATOR_HEIGHT
;
1495 // --------------------------------------------------------------------
1497 void ToolbarMenu::Paint( const Rectangle
& )
1499 SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
1503 if( mpImpl
->mnHighlightedEntry
!= -1 )
1504 implHighlightEntry( mpImpl
->mnHighlightedEntry
, true );
1507 // --------------------------------------------------------------------
1509 void ToolbarMenu::RequestHelp( const HelpEvent
& rHEvt
)
1511 DockingWindow::RequestHelp( rHEvt
);
1514 // --------------------------------------------------------------------
1516 void ToolbarMenu::StateChanged( StateChangedType nType
)
1518 DockingWindow::StateChanged( nType
);
1520 if ( ( nType
== STATE_CHANGE_CONTROLFOREGROUND
) || ( nType
== STATE_CHANGE_CONTROLBACKGROUND
) )
1527 // --------------------------------------------------------------------
1529 void ToolbarMenu::DataChanged( const DataChangedEvent
& rDCEvt
)
1531 DockingWindow::DataChanged( rDCEvt
);
1533 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
1534 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
1535 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
1536 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
1543 // --------------------------------------------------------------------
1545 void ToolbarMenu::Command( const CommandEvent
& rCEvt
)
1547 if ( rCEvt
.GetCommand() == COMMAND_WHEEL
)
1549 const CommandWheelData
* pData
= rCEvt
.GetWheelData();
1550 if( !pData
->GetModifier() && ( pData
->GetMode() == COMMAND_WHEEL_SCROLL
) )
1552 implCursorUpDown( pData
->GetDelta() > 0L, false );
1557 // --------------------------------------------------------------------
1559 Reference
< ::com::sun::star::accessibility::XAccessible
> ToolbarMenu::CreateAccessible()
1561 mpImpl
->setAccessible( new ToolbarMenuAcc( *mpImpl
) );
1562 return Reference
< XAccessible
>( mpImpl
->mxAccessible
.get() );
1565 // --------------------------------------------------------------------
1567 // todo: move to new base class that will replace SfxPopupWindo
1568 void ToolbarMenu::AddStatusListener( const OUString
& rCommandURL
)
1570 initStatusListener();
1571 mpImpl
->mxStatusListener
->addStatusListener( rCommandURL
);
1574 // --------------------------------------------------------------------
1576 // XStatusListener (subclasses must override this one to get the status updates
1577 void SAL_CALL
ToolbarMenu::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& /*Event*/ ) throw ( ::com::sun::star::uno::RuntimeException
)
1581 // --------------------------------------------------------------------
1583 class ToolbarMenuStatusListener
: public svt::FrameStatusListener
1586 ToolbarMenuStatusListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
,
1587 ToolbarMenu
& rToolbarMenu
);
1589 virtual void SAL_CALL
dispose() throw (::com::sun::star::uno::RuntimeException
);
1590 virtual void SAL_CALL
statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw ( ::com::sun::star::uno::RuntimeException
);
1592 ToolbarMenu
* mpMenu
;
1595 // --------------------------------------------------------------------
1597 ToolbarMenuStatusListener::ToolbarMenuStatusListener(
1598 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
,
1599 ToolbarMenu
& rToolbarMenu
)
1600 : svt::FrameStatusListener( ::comphelper::getProcessComponentContext(), xFrame
)
1601 , mpMenu( &rToolbarMenu
)
1605 // --------------------------------------------------------------------
1607 void SAL_CALL
ToolbarMenuStatusListener::dispose() throw (::com::sun::star::uno::RuntimeException
)
1610 svt::FrameStatusListener::dispose();
1613 // --------------------------------------------------------------------
1615 void SAL_CALL
ToolbarMenuStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& Event
) throw ( ::com::sun::star::uno::RuntimeException
)
1618 mpMenu
->statusChanged( Event
);
1621 // --------------------------------------------------------------------
1623 void ToolbarMenu::initStatusListener()
1625 if( !mpImpl
->mxStatusListener
.is() )
1626 mpImpl
->mxStatusListener
.set( new ToolbarMenuStatusListener( mpImpl
->mxFrame
, *this ) );
1629 // --------------------------------------------------------------------
1631 bool ToolbarMenu::IsInPopupMode()
1633 return GetDockingManager()->IsInPopupMode(this);
1636 // --------------------------------------------------------------------
1638 void ToolbarMenu::EndPopupMode()
1640 GetDockingManager()->EndPopupMode(this);
1643 // --------------------------------------------------------------------
1645 const Size
& ToolbarMenu::getMenuSize() const
1647 return mpImpl
->maSize
;
1650 // --------------------------------------------------------------------
1652 void ToolbarMenu::SetSelectHdl( const Link
& rLink
)
1654 mpImpl
->maSelectHdl
= rLink
;
1657 // --------------------------------------------------------------------
1662 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */