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