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 <osl/mutex.hxx>
21 #include <vcl/image.hxx>
22 #include <vcl/menu.hxx>
24 #include <cppuhelper/compbase4.hxx>
25 #include <cppuhelper/compbase5.hxx>
26 #include <comphelper/broadcasthelper.hxx>
28 #include <com/sun/star/frame/XFrame.hpp>
29 #include <com/sun/star/accessibility/XAccessible.hpp>
30 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
32 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
33 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
34 #include <com/sun/star/lang/DisposedException.hpp>
36 #include <rtl/ref.hxx>
40 #include <svtools/framestatuslistener.hxx>
44 struct ToolbarMenu_Impl
;
46 class ToolbarMenuEntry
;
48 typedef ::std::vector
< ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
> > EventListenerVector
;
49 typedef std::vector
< ToolbarMenuEntry
* > ToolbarMenuEntryVector
;
51 const int SEPARATOR_HEIGHT
= 4;
52 const int TITLE_ID
= -1;
53 const int BORDER_X
= 0;
54 const int BORDER_Y
= 0;
56 // --------------------
57 // - ToolbarMenuEntry -
58 // --------------------
60 class ToolbarMenuEntry
79 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> mxAccContext
;
82 ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, const OUString
& rText
, MenuItemBits nBits
);
83 ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, const Image
& rImage
, const OUString
& rText
, MenuItemBits nBits
);
84 ToolbarMenuEntry( ToolbarMenu
& rMenu
, int nEntryId
, Control
* pControl
, MenuItemBits nBits
);
87 void init( int nEntryId
, MenuItemBits nBits
);
89 const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
>& GetAccessible( bool bCreate
= false );
91 sal_Int32
getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException
);
92 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> getAccessibleChild( sal_Int32 index
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
93 void selectAccessibleChild( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
97 return mbChecked
|| ( mnBits
& ( MIB_RADIOCHECK
| MIB_CHECKABLE
| MIB_AUTOCHECK
) );
102 // - ToolbarMenuAcc -
105 typedef ::cppu::PartialWeakComponentImplHelper5
<
106 ::com::sun::star::accessibility::XAccessible
,
107 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
108 ::com::sun::star::accessibility::XAccessibleContext
,
109 ::com::sun::star::accessibility::XAccessibleComponent
,
110 ::com::sun::star::accessibility::XAccessibleSelection
>
111 ToolbarMenuAccComponentBase
;
113 class ToolbarMenuAcc
:
114 public ::comphelper::OBaseMutex
,
115 public ToolbarMenuAccComponentBase
119 ToolbarMenuAcc( ToolbarMenu_Impl
& rParent
);
122 void FireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
123 bool HasAccessibleListeners() const { return( mxEventListeners
.size() > 0 ); }
128 virtual void SAL_CALL
dispose()throw (::com::sun::star::uno::RuntimeException
)
129 { WeakComponentImplHelperBase::dispose(); }
130 virtual void SAL_CALL
addEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & xListener
)throw (::com::sun::star::uno::RuntimeException
)
131 { WeakComponentImplHelperBase::addEventListener(xListener
); }
132 virtual void SAL_CALL
removeEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & xListener
)throw (::com::sun::star::uno::RuntimeException
)
133 { WeakComponentImplHelperBase::removeEventListener(xListener
); }
136 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
138 // XAccessibleEventBroadcaster
139 virtual void SAL_CALL
addAccessibleEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
140 virtual void SAL_CALL
removeAccessibleEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
142 // XAccessibleContext
143 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
144 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
145 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
146 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
147 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
148 virtual OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
149 virtual OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
150 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
151 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
152 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
154 // XAccessibleComponent
155 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
156 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleAtPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
157 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
158 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
159 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
160 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
161 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
162 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
163 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
164 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
166 // XAccessibleSelection
167 virtual void SAL_CALL
selectAccessibleChild( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
168 virtual sal_Bool SAL_CALL
isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
169 virtual void SAL_CALL
clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException
);
170 virtual void SAL_CALL
selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException
);
171 virtual sal_Int32 SAL_CALL
getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
172 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
173 virtual void SAL_CALL
deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
175 DECL_LINK( WindowEventListener
, VclSimpleEvent
* );
178 EventListenerVector mxEventListeners
;
179 ToolbarMenu_Impl
* mpParent
;
180 /// The current FOCUSED state.
183 void ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
);
185 /** Tell all listeners that the object is dying. This callback is
186 usually called from the WeakComponentImplHelper class.
188 virtual void SAL_CALL
disposing (void);
190 /** Check whether or not the object has been disposed (or is in the
191 state of beeing disposed). If that is the case then
192 DisposedException is thrown to inform the (indirect) caller of the
195 void ThrowIfDisposed (void) throw (::com::sun::star::lang::DisposedException
);
198 // -----------------------
199 // - ToolbarMenuEntryAcc -
200 // -----------------------
202 typedef ::cppu::PartialWeakComponentImplHelper4
< ::com::sun::star::accessibility::XAccessible
,
203 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
204 ::com::sun::star::accessibility::XAccessibleContext
,
205 ::com::sun::star::accessibility::XAccessibleComponent
> ToolbarMenuEntryAccBase
;
207 class ToolbarMenuEntryAcc
: public ::comphelper::OBaseMutex
,
208 public ToolbarMenuEntryAccBase
211 ToolbarMenuEntryAcc( ToolbarMenuEntry
* pParent
);
212 ~ToolbarMenuEntryAcc();
214 bool HasAccessibleListeners() const { return( mxEventListeners
.size() > 0 ); }
216 virtual void SAL_CALL
dispose()throw (::com::sun::star::uno::RuntimeException
)
217 { WeakComponentImplHelperBase::dispose(); }
218 virtual void SAL_CALL
addEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & xListener
)throw (::com::sun::star::uno::RuntimeException
)
219 { WeakComponentImplHelperBase::addEventListener(xListener
); }
220 virtual void SAL_CALL
removeEventListener(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
> & xListener
)throw (::com::sun::star::uno::RuntimeException
)
221 { WeakComponentImplHelperBase::removeEventListener(xListener
); }
224 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
226 // XAccessibleEventBroadcaster
227 virtual void SAL_CALL
addAccessibleEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
228 virtual void SAL_CALL
removeAccessibleEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
230 // XAccessibleContext
231 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
232 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleChild( sal_Int32 i
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
233 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
234 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
235 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
236 virtual OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
237 virtual OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
238 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
239 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
240 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
242 // XAccessibleComponent
243 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
244 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleAtPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
245 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
246 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
247 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
248 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
249 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
250 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
251 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
252 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
255 EventListenerVector mxEventListeners
;
256 ::osl::Mutex maMutex
;
257 ToolbarMenuEntry
* mpParent
;
259 /** Tell all listeners that the object is dying. This callback is
260 usually called from the WeakComponentImplHelper class.
262 virtual void SAL_CALL
disposing (void);
265 // -----------------------------------------------------------------------------
267 struct ToolbarMenu_Impl
271 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> mxFrame
;
272 rtl::Reference
< svt::FrameStatusListener
> mxStatusListener
;
273 rtl::Reference
< ToolbarMenuAcc
> mxAccessible
;
274 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> mxOldSelection
;
276 ToolbarMenuEntryVector maEntryVector
;
282 int mnHighlightedEntry
;
290 ToolbarMenu_Impl( ToolbarMenu
& rMenu
, const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& xFrame
);
293 void setAccessible( ToolbarMenuAcc
* pAccessible
);
295 void fireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
296 bool hasAccessibleListeners();
298 sal_Int32
getAccessibleChildCount() throw (::com::sun::star::uno::RuntimeException
);
299 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> getAccessibleChild( sal_Int32 index
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
300 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> getAccessibleChild( Control
* pControl
, sal_Int32 childIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
302 void selectAccessibleChild( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
303 sal_Bool
isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
304 void clearAccessibleSelection();
306 ToolbarMenuEntry
* implGetEntry( int nEntry
) const;
307 void notifyHighlightedEntry();
309 void implHighlightControl( sal_uInt16 nCode
, Control
* pControl
);
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */