1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <osx/a11yfocustracker.hxx>
21 #include <osx/a11yfactory.h>
22 
23 #include "a11yfocuslistener.hxx"
24 
25 using namespace ::com::sun::star::accessibility;
26 using namespace ::com::sun::star::uno;
27 
28 rtl::Reference< AquaA11yFocusListener > AquaA11yFocusListener::theListener;
29 
get()30 rtl::Reference< AquaA11yFocusListener > const & AquaA11yFocusListener::get()
31 {
32     if ( ! theListener.is() )
33         theListener = new AquaA11yFocusListener();
34 
35     return theListener;
36 }
37 
AquaA11yFocusListener()38 AquaA11yFocusListener::AquaA11yFocusListener() : m_focusedObject(nil)
39 {
40 }
41 
getFocusedUIElement()42 id AquaA11yFocusListener::getFocusedUIElement()
43 {
44     if ( nil == m_focusedObject ) {
45         Reference< XAccessible > xAccessible( TheAquaA11yFocusTracker::get().getFocusedObject() );
46         try {
47             if( xAccessible.is() ) {
48                 Reference< XAccessibleContext > xContext(xAccessible->getAccessibleContext());
49                 if( xContext.is() )
50                     m_focusedObject = [ AquaA11yFactory wrapperForAccessibleContext: xContext ];
51             }
52         } catch(const RuntimeException &)  {
53             // intentionally do nothing ..
54         }
55     }
56 
57     return m_focusedObject;
58 }
59 
60 void
focusedObjectChanged(const Reference<XAccessible> & xAccessible)61 AquaA11yFocusListener::focusedObjectChanged(const Reference< XAccessible >& xAccessible)
62 {
63     if ( nil != m_focusedObject ) {
64         [ m_focusedObject release ];
65         m_focusedObject = nil;
66     }
67 
68     try {
69         if( xAccessible.is() ) {
70             Reference< XAccessibleContext > xContext(xAccessible->getAccessibleContext());
71             if( xContext.is() )
72             {
73                 m_focusedObject = [ AquaA11yFactory wrapperForAccessibleContext: xContext ];
74                 NSAccessibilityPostNotification(m_focusedObject, NSAccessibilityFocusedUIElementChangedNotification);
75             }
76         }
77     } catch(const RuntimeException &) {
78         // intentionally do nothing ..
79     }
80 }
81 
82 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
83