xref: /AOO41X/main/accessibility/source/standard/vclxaccessiblemenubar.cxx (revision 0841af799a0c15bc22ec7bb30da88488e7283293)
1*0841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0841af79SAndrew Rist  * distributed with this work for additional information
6*0841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0841af79SAndrew Rist  * "License"); you may not use this file except in compliance
9*0841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*0841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*0841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0841af79SAndrew Rist  * software distributed under the License is distributed on an
15*0841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
17*0841af79SAndrew Rist  * specific language governing permissions and limitations
18*0841af79SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*0841af79SAndrew Rist  *************************************************************/
21*0841af79SAndrew Rist 
22*0841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblemenubar.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <vcl/window.hxx>
31cdf0e10cSrcweir #include <vcl/menu.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
35cdf0e10cSrcweir using namespace ::com::sun::star::uno;
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::comphelper;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir // -----------------------------------------------------------------------------
41cdf0e10cSrcweir // class VCLXAccessibleMenuBar
42cdf0e10cSrcweir // -----------------------------------------------------------------------------
43cdf0e10cSrcweir 
VCLXAccessibleMenuBar(Menu * pMenu)44cdf0e10cSrcweir VCLXAccessibleMenuBar::VCLXAccessibleMenuBar( Menu* pMenu )
45cdf0e10cSrcweir 	:OAccessibleMenuComponent( pMenu )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	if ( pMenu )
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 		m_pWindow = pMenu->GetWindow();
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 		if ( m_pWindow )
52cdf0e10cSrcweir 			m_pWindow->AddEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
53cdf0e10cSrcweir 	}
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -----------------------------------------------------------------------------
57cdf0e10cSrcweir 
~VCLXAccessibleMenuBar()58cdf0e10cSrcweir VCLXAccessibleMenuBar::~VCLXAccessibleMenuBar()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	if ( m_pWindow )
61cdf0e10cSrcweir 		m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // -----------------------------------------------------------------------------
65cdf0e10cSrcweir 
IsFocused()66cdf0e10cSrcweir sal_Bool VCLXAccessibleMenuBar::IsFocused()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     sal_Bool bFocused = sal_False;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     if ( m_pWindow && m_pWindow->HasFocus() && !IsChildHighlighted() )
71cdf0e10cSrcweir         bFocused = sal_True;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     return bFocused;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir // -----------------------------------------------------------------------------
77cdf0e10cSrcweir 
IMPL_LINK(VCLXAccessibleMenuBar,WindowEventListener,VclSimpleEvent *,pEvent)78cdf0e10cSrcweir IMPL_LINK( VCLXAccessibleMenuBar, WindowEventListener, VclSimpleEvent*, pEvent )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 	DBG_ASSERT( pEvent && pEvent->ISA( VclWindowEvent ), "VCLXAccessibleMenuBar::WindowEventListener: unknown window event!" );
81cdf0e10cSrcweir 	if ( pEvent && pEvent->ISA( VclWindowEvent ) )
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		DBG_ASSERT( ((VclWindowEvent*)pEvent)->GetWindow(), "VCLXAccessibleMenuBar::WindowEventListener: no window!" );
84cdf0e10cSrcweir         if ( !((VclWindowEvent*)pEvent)->GetWindow()->IsAccessibilityEventsSuppressed() || ( pEvent->GetId() == VCLEVENT_OBJECT_DYING ) )
85cdf0e10cSrcweir 		{
86cdf0e10cSrcweir 		    ProcessWindowEvent( *(VclWindowEvent*)pEvent );
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 	return 0;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir // -----------------------------------------------------------------------------
93cdf0e10cSrcweir 
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)94cdf0e10cSrcweir void VCLXAccessibleMenuBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	switch ( rVclWindowEvent.GetId() )
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		case VCLEVENT_WINDOW_GETFOCUS:
99cdf0e10cSrcweir 		case VCLEVENT_WINDOW_LOSEFOCUS:
100cdf0e10cSrcweir 		{
101cdf0e10cSrcweir 			SetFocused( rVclWindowEvent.GetId() == VCLEVENT_WINDOW_GETFOCUS );
102cdf0e10cSrcweir 		}
103cdf0e10cSrcweir 		break;
104cdf0e10cSrcweir 		case VCLEVENT_OBJECT_DYING:
105cdf0e10cSrcweir 		{
106cdf0e10cSrcweir 			if ( m_pWindow )
107cdf0e10cSrcweir 			{
108cdf0e10cSrcweir 				m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
109cdf0e10cSrcweir 				m_pWindow = NULL;
110cdf0e10cSrcweir 			}
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 		break;
113cdf0e10cSrcweir 		default:
114cdf0e10cSrcweir 		{
115cdf0e10cSrcweir 		}
116cdf0e10cSrcweir 		break;
117cdf0e10cSrcweir 	}
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir // -----------------------------------------------------------------------------
121cdf0e10cSrcweir // XComponent
122cdf0e10cSrcweir // -----------------------------------------------------------------------------
123cdf0e10cSrcweir 
disposing()124cdf0e10cSrcweir void VCLXAccessibleMenuBar::disposing()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	OAccessibleMenuComponent::disposing();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 	if ( m_pWindow )
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		m_pWindow->RemoveEventListener( LINK( this, VCLXAccessibleMenuBar, WindowEventListener ) );
131cdf0e10cSrcweir 		m_pWindow = NULL;
132cdf0e10cSrcweir 	}
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // -----------------------------------------------------------------------------
136cdf0e10cSrcweir // XServiceInfo
137cdf0e10cSrcweir // -----------------------------------------------------------------------------
138cdf0e10cSrcweir 
getImplementationName()139cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleMenuBar::getImplementationName() throw (RuntimeException)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenuBar" );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir // -----------------------------------------------------------------------------
145cdf0e10cSrcweir 
getSupportedServiceNames()146cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleMenuBar::getSupportedServiceNames() throw (RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aNames(1);
149cdf0e10cSrcweir 	aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenuBar" );
150cdf0e10cSrcweir 	return aNames;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir // -----------------------------------------------------------------------------
154cdf0e10cSrcweir // XAccessibleContext
155cdf0e10cSrcweir // -----------------------------------------------------------------------------
156cdf0e10cSrcweir 
getAccessibleIndexInParent()157cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuBar::getAccessibleIndexInParent(  ) throw (RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	sal_Int32 nIndexInParent = -1;
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 	if ( m_pMenu )
164cdf0e10cSrcweir 	{
165cdf0e10cSrcweir 		Window* pWindow = m_pMenu->GetWindow();
166cdf0e10cSrcweir 		if ( pWindow )
167cdf0e10cSrcweir 		{
168cdf0e10cSrcweir 			Window* pParent = pWindow->GetAccessibleParentWindow();
169cdf0e10cSrcweir 			if ( pParent )
170cdf0e10cSrcweir 			{
171cdf0e10cSrcweir 				for ( sal_uInt16 n = pParent->GetAccessibleChildWindowCount(); n; )
172cdf0e10cSrcweir 				{
173cdf0e10cSrcweir 					Window* pChild = pParent->GetAccessibleChildWindow( --n );
174cdf0e10cSrcweir 					if ( pChild == pWindow )
175cdf0e10cSrcweir 					{
176cdf0e10cSrcweir 						nIndexInParent = n;
177cdf0e10cSrcweir 						break;
178cdf0e10cSrcweir 					}
179cdf0e10cSrcweir 				}
180cdf0e10cSrcweir 			}
181cdf0e10cSrcweir 		}
182cdf0e10cSrcweir 	}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 	return nIndexInParent;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir // -----------------------------------------------------------------------------
188cdf0e10cSrcweir 
getAccessibleRole()189cdf0e10cSrcweir sal_Int16 VCLXAccessibleMenuBar::getAccessibleRole(  ) throw (RuntimeException)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	return AccessibleRole::MENU_BAR;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
196cdf0e10cSrcweir // -----------------------------------------------------------------------------
197cdf0e10cSrcweir // XAccessibleExtendedComponent
198cdf0e10cSrcweir // -----------------------------------------------------------------------------
199cdf0e10cSrcweir 
getBackground()200cdf0e10cSrcweir sal_Int32 VCLXAccessibleMenuBar::getBackground(  ) throw (RuntimeException)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir 	OExternalLockGuard aGuard( this );
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	return Application::GetSettings().GetStyleSettings().GetMenuBarColor().GetColor();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // -----------------------------------------------------------------------------
208