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_vcl.hxx"
26 
27 #include <salhelper/refobj.hxx>
28 
29 #include "aqua/aqua11yfocustracker.hxx"
30 #include "aqua/aqua11yfactory.h"
31 
32 #include "aqua11yfocuslistener.hxx"
33 
34 using namespace ::com::sun::star::accessibility;
35 using namespace ::com::sun::star::uno;
36 
37 
38 static rtl::Reference< AquaA11yFocusListener > theListener;
39 
40 //------------------------------------------------------------------------------
41 
get()42 rtl::Reference< AquaA11yFocusListener > AquaA11yFocusListener::get()
43 {
44     if ( ! theListener.is() )
45         theListener = new AquaA11yFocusListener();
46 
47     return theListener;
48 }
49 
50 //------------------------------------------------------------------------------
51 
AquaA11yFocusListener()52 AquaA11yFocusListener::AquaA11yFocusListener() : m_focusedObject(nil)
53 {
54 }
55 
56 //------------------------------------------------------------------------------
57 
getFocusedUIElement()58 id AquaA11yFocusListener::getFocusedUIElement()
59 {
60     if ( nil == m_focusedObject ) {
61         Reference< XAccessible > xAccessible( AquaA11yFocusTracker::get().getFocusedObject() );
62         try {
63             if( xAccessible.is() ) {
64                 Reference< XAccessibleContext > xContext(xAccessible->getAccessibleContext());
65                 if( xContext.is() )
66                     m_focusedObject = [ AquaA11yFactory wrapperForAccessibleContext: xContext ];
67             }
68         } catch( RuntimeException )  {
69             // intentionally do nothing ..
70         }
71     }
72 
73     return m_focusedObject;
74 }
75 
76 //------------------------------------------------------------------------------
77 
78 void SAL_CALL
focusedObjectChanged(const Reference<XAccessible> & xAccessible)79 AquaA11yFocusListener::focusedObjectChanged(const Reference< XAccessible >& xAccessible)
80 {
81     if ( nil != m_focusedObject ) {
82         [ m_focusedObject release ];
83         m_focusedObject = nil;
84     }
85 
86     try {
87         if( xAccessible.is() ) {
88             Reference< XAccessibleContext > xContext(xAccessible->getAccessibleContext());
89             if( xContext.is() )
90             {
91                 m_focusedObject = [ AquaA11yFactory wrapperForAccessibleContext: xContext ];
92                 NSAccessibilityPostNotification(m_focusedObject, NSAccessibilityFocusedUIElementChangedNotification);
93             }
94         }
95     } catch( RuntimeException ) {
96         // intentionally do nothing ..
97     }
98 }
99 
100 //------------------------------------------------------------------------------
101 
102 oslInterlockedCount SAL_CALL
acquire()103 AquaA11yFocusListener::acquire() SAL_THROW(())
104 {
105     return ReferenceObject::acquire();
106 }
107 
108 //------------------------------------------------------------------------------
109 
110 oslInterlockedCount SAL_CALL
release()111 AquaA11yFocusListener::release() SAL_THROW(())
112 {
113     return ReferenceObject::release();
114 }
115 
116