LCOV - code coverage report
Current view: top level - vcl/unx/gtk/a11y - atkutil.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 251 0.0 %
Date: 2012-08-25 Functions: 0 29 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #ifdef AIX
      31                 :            : #define _LINUX_SOURCE_COMPAT
      32                 :            : #include <sys/timer.h>
      33                 :            : #undef _LINUX_SOURCE_COMPAT
      34                 :            : #endif
      35                 :            : 
      36                 :            : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
      37                 :            : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
      38                 :            : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
      39                 :            : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      40                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      41                 :            : #include <com/sun/star/accessibility/XAccessibleText.hpp>
      42                 :            : #include <cppuhelper/implbase1.hxx>
      43                 :            : #include <osl/mutex.hxx>
      44                 :            : #include <rtl/ref.hxx>
      45                 :            : 
      46                 :            : #include <vcl/svapp.hxx>
      47                 :            : #include <vcl/window.hxx>
      48                 :            : #include <vcl/menu.hxx>
      49                 :            : #include <vcl/toolbox.hxx>
      50                 :            : 
      51                 :            : #include "atkwrapper.hxx"
      52                 :            : #include "atkutil.hxx"
      53                 :            : 
      54                 :            : #include <gtk/gtk.h>
      55                 :            : 
      56                 :            : #include <set>
      57                 :            : 
      58                 :            : // #define ENABLE_TRACING
      59                 :            : 
      60                 :            : #ifdef ENABLE_TRACING
      61                 :            : #include <stdio.h>
      62                 :            : #endif
      63                 :            : 
      64                 :            : using namespace ::com::sun::star;
      65                 :            : 
      66                 :            : namespace
      67                 :            : {
      68                 :            :     struct theNextFocusObject :
      69                 :            :         public rtl::Static< uno::WeakReference< accessibility::XAccessible >, theNextFocusObject>
      70                 :            :     {
      71                 :            :     };
      72                 :            : }
      73                 :            : 
      74                 :            : static guint focus_notify_handler = 0;
      75                 :            : 
      76                 :            : /*****************************************************************************/
      77                 :            : 
      78                 :            : extern "C" {
      79                 :            : 
      80                 :            : static gint
      81                 :          0 : atk_wrapper_focus_idle_handler (gpointer data)
      82                 :            : {
      83                 :          0 :     SolarMutexGuard aGuard;
      84                 :            : 
      85                 :          0 :     focus_notify_handler = 0;
      86                 :            : 
      87                 :          0 :     uno::Reference< accessibility::XAccessible > xAccessible = theNextFocusObject::get();
      88                 :          0 :     if( xAccessible.get() == reinterpret_cast < accessibility::XAccessible * > (data) )
      89                 :            :     {
      90                 :          0 :         AtkObject *atk_obj = xAccessible.is() ? atk_object_wrapper_ref( xAccessible ) : NULL;
      91                 :            :         // Gail does not notify focus changes to NULL, so do we ..
      92                 :          0 :         if( atk_obj )
      93                 :            :         {
      94                 :            : #ifdef ENABLE_TRACING
      95                 :            :             fprintf(stderr, "notifying focus event for %p\n", atk_obj);
      96                 :            : #endif
      97                 :          0 :             atk_focus_tracker_notify(atk_obj);
      98                 :            :             // #i93269#
      99                 :            :             // emit text_caret_moved event for <XAccessibleText> object,
     100                 :            :             // if cursor is inside the <XAccessibleText> object.
     101                 :            :             // also emit state-changed:focused event under the same condition.
     102                 :            :             {
     103                 :          0 :                 AtkObjectWrapper* wrapper_obj = ATK_OBJECT_WRAPPER (atk_obj);
     104                 :          0 :                 if( wrapper_obj && !wrapper_obj->mpText && wrapper_obj->mpContext )
     105                 :            :                 {
     106                 :          0 :                     uno::Any any = wrapper_obj->mpContext->queryInterface( accessibility::XAccessibleText::static_type(NULL) );
     107                 :          0 :                     if ( typelib_TypeClass_INTERFACE == any.pType->eTypeClass &&
     108                 :            :                          any.pReserved != 0 )
     109                 :            :                     {
     110                 :          0 :                         wrapper_obj->mpText = reinterpret_cast< accessibility::XAccessibleText * > (any.pReserved);
     111                 :          0 :                         if ( wrapper_obj->mpText != 0 )
     112                 :            :                         {
     113                 :          0 :                             wrapper_obj->mpText->acquire();
     114                 :          0 :                             gint caretPos = wrapper_obj->mpText->getCaretPosition();
     115                 :            : 
     116                 :          0 :                             if ( caretPos != -1 )
     117                 :            :                             {
     118                 :          0 :                                 atk_object_notify_state_change( atk_obj, ATK_STATE_FOCUSED, TRUE );
     119                 :          0 :                                 g_signal_emit_by_name( atk_obj, "text_caret_moved", caretPos );
     120                 :            :                             }
     121                 :            :                         }
     122                 :          0 :                     }
     123                 :            :                 }
     124                 :            :             }
     125                 :          0 :             g_object_unref(atk_obj);
     126                 :            :         }
     127                 :            :     }
     128                 :            : 
     129                 :          0 :     return FALSE;
     130                 :            : }
     131                 :            : 
     132                 :            : } // extern "C"
     133                 :            : 
     134                 :            : /*****************************************************************************/
     135                 :            : 
     136                 :            : static void
     137                 :          0 : atk_wrapper_focus_tracker_notify_when_idle( const uno::Reference< accessibility::XAccessible > &xAccessible )
     138                 :            : {
     139                 :          0 :     if( focus_notify_handler )
     140                 :          0 :         g_source_remove(focus_notify_handler);
     141                 :            : 
     142                 :          0 :     theNextFocusObject::get() = xAccessible;
     143                 :            : 
     144                 :          0 :     focus_notify_handler = g_idle_add (atk_wrapper_focus_idle_handler, xAccessible.get());
     145                 :          0 : }
     146                 :            : 
     147                 :            : /*****************************************************************************/
     148                 :            : 
     149                 :          0 : class DocumentFocusListener :
     150                 :            :     public ::cppu::WeakImplHelper1< accessibility::XAccessibleEventListener >
     151                 :            : {
     152                 :            : 
     153                 :            :     std::set< uno::Reference< uno::XInterface > > m_aRefList;
     154                 :            : 
     155                 :            : public:
     156                 :            :     void attachRecursive(
     157                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible
     158                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     159                 :            : 
     160                 :            :     void attachRecursive(
     161                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible,
     162                 :            :         const uno::Reference< accessibility::XAccessibleContext >& xContext
     163                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     164                 :            : 
     165                 :            :     void attachRecursive(
     166                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible,
     167                 :            :         const uno::Reference< accessibility::XAccessibleContext >& xContext,
     168                 :            :         const uno::Reference< accessibility::XAccessibleStateSet >& xStateSet
     169                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     170                 :            : 
     171                 :            :     void detachRecursive(
     172                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible
     173                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     174                 :            : 
     175                 :            :     void detachRecursive(
     176                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible,
     177                 :            :         const uno::Reference< accessibility::XAccessibleContext >& xContext
     178                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     179                 :            : 
     180                 :            :     void detachRecursive(
     181                 :            :         const uno::Reference< accessibility::XAccessible >& xAccessible,
     182                 :            :         const uno::Reference< accessibility::XAccessibleContext >& xContext,
     183                 :            :         const uno::Reference< accessibility::XAccessibleStateSet >& xStateSet
     184                 :            :     ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     185                 :            : 
     186                 :            :     static uno::Reference< accessibility::XAccessible > getAccessible(const lang::EventObject& aEvent )
     187                 :            :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException);
     188                 :            : 
     189                 :            :     // XEventListener
     190                 :            :     virtual void disposing( const lang::EventObject& Source ) throw (uno::RuntimeException);
     191                 :            : 
     192                 :            :     // XAccessibleEventListener
     193                 :            :     virtual void notifyEvent( const accessibility::AccessibleEventObject& aEvent ) throw( uno::RuntimeException );
     194                 :            : };
     195                 :            : 
     196                 :            : /*****************************************************************************/
     197                 :            : 
     198                 :          0 : void DocumentFocusListener::disposing( const lang::EventObject& aEvent )
     199                 :            :     throw (uno::RuntimeException)
     200                 :            : {
     201                 :            : 
     202                 :            :     // Unref the object here, but do not remove as listener since the object
     203                 :            :     // might no longer be in a state that safely allows this.
     204                 :          0 :     if( aEvent.Source.is() )
     205                 :          0 :         m_aRefList.erase(aEvent.Source);
     206                 :            : 
     207                 :          0 : }
     208                 :            : 
     209                 :            : /*****************************************************************************/
     210                 :            : 
     211                 :          0 : void DocumentFocusListener::notifyEvent( const accessibility::AccessibleEventObject& aEvent )
     212                 :            :     throw( uno::RuntimeException )
     213                 :            : {
     214                 :          0 :     switch( aEvent.EventId )
     215                 :            :     {
     216                 :            :         case accessibility::AccessibleEventId::STATE_CHANGED:
     217                 :            :             try
     218                 :            :             {
     219                 :          0 :                 sal_Int16 nState = accessibility::AccessibleStateType::INVALID;
     220                 :          0 :                 aEvent.NewValue >>= nState;
     221                 :            : 
     222                 :          0 :                 if( accessibility::AccessibleStateType::FOCUSED == nState )
     223                 :          0 :                     atk_wrapper_focus_tracker_notify_when_idle( getAccessible(aEvent) );
     224                 :            :             }
     225                 :          0 :             catch (const lang::IndexOutOfBoundsException&)
     226                 :            :             {
     227                 :          0 :                 g_warning("Focused object has invalid index in parent");
     228                 :            :             }
     229                 :          0 :             break;
     230                 :            : 
     231                 :            :         case accessibility::AccessibleEventId::CHILD:
     232                 :            :         {
     233                 :          0 :             uno::Reference< accessibility::XAccessible > xChild;
     234                 :          0 :             if( (aEvent.OldValue >>= xChild) && xChild.is() )
     235                 :          0 :                 detachRecursive(xChild);
     236                 :            : 
     237                 :          0 :             if( (aEvent.NewValue >>= xChild) && xChild.is() )
     238                 :          0 :                 attachRecursive(xChild);
     239                 :            :         }
     240                 :          0 :             break;
     241                 :            : 
     242                 :            :         case accessibility::AccessibleEventId::INVALIDATE_ALL_CHILDREN:
     243                 :          0 :             g_warning( "Invalidate all children called\n" );
     244                 :          0 :             break;
     245                 :            :         default:
     246                 :          0 :             break;
     247                 :            :     }
     248                 :          0 : }
     249                 :            : 
     250                 :            : /*****************************************************************************/
     251                 :            : 
     252                 :          0 : uno::Reference< accessibility::XAccessible > DocumentFocusListener::getAccessible(const lang::EventObject& aEvent )
     253                 :            :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     254                 :            : {
     255                 :          0 :     uno::Reference< accessibility::XAccessible > xAccessible(aEvent.Source, uno::UNO_QUERY);
     256                 :            : 
     257                 :          0 :     if( xAccessible.is() )
     258                 :          0 :         return xAccessible;
     259                 :            : 
     260                 :          0 :     uno::Reference< accessibility::XAccessibleContext > xContext(aEvent.Source, uno::UNO_QUERY);
     261                 :            : 
     262                 :          0 :     if( xContext.is() )
     263                 :            :     {
     264                 :          0 :         uno::Reference< accessibility::XAccessible > xParent( xContext->getAccessibleParent() );
     265                 :          0 :         if( xParent.is() )
     266                 :            :         {
     267                 :          0 :             uno::Reference< accessibility::XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
     268                 :          0 :             if( xParentContext.is() )
     269                 :            :             {
     270                 :          0 :                 return xParentContext->getAccessibleChild( xContext->getAccessibleIndexInParent() );
     271                 :          0 :             }
     272                 :          0 :         }
     273                 :            :     }
     274                 :            : 
     275                 :          0 :     return uno::Reference< accessibility::XAccessible >();
     276                 :            : }
     277                 :            : 
     278                 :            : /*****************************************************************************/
     279                 :            : 
     280                 :          0 : void DocumentFocusListener::attachRecursive(
     281                 :            :     const uno::Reference< accessibility::XAccessible >& xAccessible
     282                 :            : ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     283                 :            : {
     284                 :            :     uno::Reference< accessibility::XAccessibleContext > xContext =
     285                 :          0 :         xAccessible->getAccessibleContext();
     286                 :            : 
     287                 :          0 :     if( xContext.is() )
     288                 :          0 :         attachRecursive(xAccessible, xContext);
     289                 :          0 : }
     290                 :            : 
     291                 :            : /*****************************************************************************/
     292                 :            : 
     293                 :          0 : void DocumentFocusListener::attachRecursive(
     294                 :            :     const uno::Reference< accessibility::XAccessible >& xAccessible,
     295                 :            :     const uno::Reference< accessibility::XAccessibleContext >& xContext
     296                 :            : )  throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     297                 :            : {
     298                 :            :     uno::Reference< accessibility::XAccessibleStateSet > xStateSet =
     299                 :          0 :         xContext->getAccessibleStateSet();
     300                 :            : 
     301                 :          0 :     if( xStateSet.is() )
     302                 :          0 :         attachRecursive(xAccessible, xContext, xStateSet);
     303                 :          0 : }
     304                 :            : 
     305                 :            : /*****************************************************************************/
     306                 :            : 
     307                 :          0 : void DocumentFocusListener::attachRecursive(
     308                 :            :     const uno::Reference< accessibility::XAccessible >& xAccessible,
     309                 :            :     const uno::Reference< accessibility::XAccessibleContext >& xContext,
     310                 :            :     const uno::Reference< accessibility::XAccessibleStateSet >& xStateSet
     311                 :            : ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     312                 :            : {
     313                 :          0 :     if( xStateSet->contains(accessibility::AccessibleStateType::FOCUSED ) )
     314                 :          0 :         atk_wrapper_focus_tracker_notify_when_idle( xAccessible );
     315                 :            : 
     316                 :            :     uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster =
     317                 :          0 :         uno::Reference< accessibility::XAccessibleEventBroadcaster >(xContext, uno::UNO_QUERY);
     318                 :            : 
     319                 :          0 :     if (!xBroadcaster.is())
     320                 :          0 :         return;
     321                 :            : 
     322                 :            :     // If not already done, add the broadcaster to the list and attach as listener.
     323                 :          0 :     uno::Reference< uno::XInterface > xInterface = xBroadcaster;
     324                 :          0 :     if( m_aRefList.insert(xInterface).second )
     325                 :            :     {
     326                 :          0 :         xBroadcaster->addEventListener(static_cast< accessibility::XAccessibleEventListener *>(this));
     327                 :            : 
     328                 :          0 :         if( ! xStateSet->contains(accessibility::AccessibleStateType::MANAGES_DESCENDANTS ) )
     329                 :            :         {
     330                 :          0 :             sal_Int32 n, nmax = xContext->getAccessibleChildCount();
     331                 :          0 :             for( n = 0; n < nmax; n++ )
     332                 :            :             {
     333                 :          0 :                 uno::Reference< accessibility::XAccessible > xChild( xContext->getAccessibleChild( n ) );
     334                 :            : 
     335                 :          0 :                 if( xChild.is() )
     336                 :          0 :                     attachRecursive(xChild);
     337                 :          0 :             }
     338                 :            :         }
     339                 :          0 :     }
     340                 :            : }
     341                 :            : 
     342                 :            : /*****************************************************************************/
     343                 :            : 
     344                 :          0 : void DocumentFocusListener::detachRecursive(
     345                 :            :     const uno::Reference< accessibility::XAccessible >& xAccessible
     346                 :            : ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     347                 :            : {
     348                 :            :     uno::Reference< accessibility::XAccessibleContext > xContext =
     349                 :          0 :         xAccessible->getAccessibleContext();
     350                 :            : 
     351                 :          0 :     if( xContext.is() )
     352                 :          0 :         detachRecursive(xAccessible, xContext);
     353                 :          0 : }
     354                 :            : 
     355                 :            : /*****************************************************************************/
     356                 :            : 
     357                 :          0 : void DocumentFocusListener::detachRecursive(
     358                 :            :     const uno::Reference< accessibility::XAccessible >& xAccessible,
     359                 :            :     const uno::Reference< accessibility::XAccessibleContext >& xContext
     360                 :            : )  throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     361                 :            : {
     362                 :            :     uno::Reference< accessibility::XAccessibleStateSet > xStateSet =
     363                 :          0 :         xContext->getAccessibleStateSet();
     364                 :            : 
     365                 :          0 :     if( xStateSet.is() )
     366                 :          0 :         detachRecursive(xAccessible, xContext, xStateSet);
     367                 :          0 : }
     368                 :            : 
     369                 :            : /*****************************************************************************/
     370                 :            : 
     371                 :          0 : void DocumentFocusListener::detachRecursive(
     372                 :            :     const uno::Reference< accessibility::XAccessible >&,
     373                 :            :     const uno::Reference< accessibility::XAccessibleContext >& xContext,
     374                 :            :     const uno::Reference< accessibility::XAccessibleStateSet >& xStateSet
     375                 :            : ) throw (lang::IndexOutOfBoundsException, uno::RuntimeException)
     376                 :            : {
     377                 :            :     uno::Reference< accessibility::XAccessibleEventBroadcaster > xBroadcaster =
     378                 :          0 :         uno::Reference< accessibility::XAccessibleEventBroadcaster >(xContext, uno::UNO_QUERY);
     379                 :            : 
     380                 :          0 :     if( xBroadcaster.is() && 0 < m_aRefList.erase(xBroadcaster) )
     381                 :            :     {
     382                 :          0 :         xBroadcaster->removeEventListener(static_cast< accessibility::XAccessibleEventListener *>(this));
     383                 :            : 
     384                 :          0 :         if( ! xStateSet->contains(accessibility::AccessibleStateType::MANAGES_DESCENDANTS ) )
     385                 :            :         {
     386                 :          0 :             sal_Int32 n, nmax = xContext->getAccessibleChildCount();
     387                 :          0 :             for( n = 0; n < nmax; n++ )
     388                 :            :             {
     389                 :          0 :                 uno::Reference< accessibility::XAccessible > xChild( xContext->getAccessibleChild( n ) );
     390                 :            : 
     391                 :          0 :                 if( xChild.is() )
     392                 :          0 :                     detachRecursive(xChild);
     393                 :          0 :             }
     394                 :            :         }
     395                 :          0 :     }
     396                 :          0 : }
     397                 :            : 
     398                 :            : /*****************************************************************************/
     399                 :            : 
     400                 :            : /*
     401                 :            :  * page tabs in gtk are widgets, so we need to simulate focus events for those
     402                 :            :  */
     403                 :            : 
     404                 :          0 : static void handle_tabpage_activated(Window *pWindow)
     405                 :            : {
     406                 :            :     uno::Reference< accessibility::XAccessible > xAccessible =
     407                 :          0 :         pWindow->GetAccessible();
     408                 :            : 
     409                 :          0 :     if( ! xAccessible.is() )
     410                 :          0 :         return;
     411                 :            : 
     412                 :            :     uno::Reference< accessibility::XAccessibleSelection > xSelection(
     413                 :          0 :         xAccessible->getAccessibleContext(), uno::UNO_QUERY);
     414                 :            : 
     415                 :          0 :     if( xSelection.is() )
     416                 :          0 :         atk_wrapper_focus_tracker_notify_when_idle( xSelection->getSelectedAccessibleChild(0) );
     417                 :            : }
     418                 :            : 
     419                 :            : /*****************************************************************************/
     420                 :            : 
     421                 :            : /*
     422                 :            :  * toolbar items in gtk are widgets, so we need to simulate focus events for those
     423                 :            :  */
     424                 :            : 
     425                 :          0 : static void notify_toolbox_item_focus(ToolBox *pToolBox)
     426                 :            : {
     427                 :            :     uno::Reference< accessibility::XAccessible > xAccessible =
     428                 :          0 :         pToolBox->GetAccessible();
     429                 :            : 
     430                 :          0 :     if( ! xAccessible.is() )
     431                 :            :         return;
     432                 :            : 
     433                 :            :     uno::Reference< accessibility::XAccessibleContext > xContext =
     434                 :          0 :         xAccessible->getAccessibleContext();
     435                 :            : 
     436                 :          0 :     if( ! xContext.is() )
     437                 :            :         return;
     438                 :            : 
     439                 :          0 :     sal_Int32 nPos = pToolBox->GetItemPos( pToolBox->GetHighlightItemId() );
     440                 :          0 :     if( nPos != TOOLBOX_ITEM_NOTFOUND )
     441                 :          0 :         atk_wrapper_focus_tracker_notify_when_idle( xContext->getAccessibleChild( nPos ) );
     442                 :            : }
     443                 :            : 
     444                 :          0 : static void handle_toolbox_highlight(Window *pWindow)
     445                 :            : {
     446                 :          0 :     ToolBox *pToolBox = static_cast <ToolBox *> (pWindow);
     447                 :            : 
     448                 :            :     // Make sure either the toolbox or its parent toolbox has the focus
     449                 :          0 :     if ( ! pToolBox->HasFocus() )
     450                 :            :     {
     451                 :          0 :         ToolBox* pToolBoxParent = dynamic_cast< ToolBox* >( pToolBox->GetParent() );
     452                 :          0 :         if ( ! pToolBoxParent || ! pToolBoxParent->HasFocus() )
     453                 :          0 :             return;
     454                 :            :     }
     455                 :            : 
     456                 :          0 :     notify_toolbox_item_focus(pToolBox);
     457                 :            : }
     458                 :            : 
     459                 :          0 : static void handle_toolbox_highlightoff(Window *pWindow)
     460                 :            : {
     461                 :          0 :     ToolBox *pToolBox = static_cast <ToolBox *> (pWindow);
     462                 :          0 :     ToolBox* pToolBoxParent = dynamic_cast< ToolBox* >( pToolBox->GetParent() );
     463                 :            : 
     464                 :            :     // Notify when leaving sub toolboxes
     465                 :          0 :     if( pToolBoxParent && pToolBoxParent->HasFocus() )
     466                 :          0 :         notify_toolbox_item_focus( pToolBoxParent );
     467                 :          0 : }
     468                 :            : 
     469                 :            : /*****************************************************************************/
     470                 :            : 
     471                 :          0 : static void create_wrapper_for_child(
     472                 :            :     const uno::Reference< accessibility::XAccessibleContext >& xContext,
     473                 :            :     sal_Int32 index)
     474                 :            : {
     475                 :          0 :     if( xContext.is() )
     476                 :            :     {
     477                 :          0 :         uno::Reference< accessibility::XAccessible > xChild(xContext->getAccessibleChild(index));
     478                 :          0 :         if( xChild.is() )
     479                 :            :         {
     480                 :            :             // create the wrapper object - it will survive the unref unless it is a transient object
     481                 :          0 :             g_object_unref( atk_object_wrapper_ref( xChild ) );
     482                 :          0 :         }
     483                 :            :     }
     484                 :          0 : }
     485                 :            : 
     486                 :            : /*****************************************************************************/
     487                 :            : 
     488                 :          0 : static void handle_toolbox_buttonchange(VclWindowEvent const *pEvent)
     489                 :            : {
     490                 :          0 :     Window* pWindow = pEvent->GetWindow();
     491                 :          0 :     sal_Int32 index = (sal_Int32)(sal_IntPtr) pEvent->GetData();
     492                 :            : 
     493                 :          0 :     if( pWindow && pWindow->IsReallyVisible() )
     494                 :            :     {
     495                 :          0 :         uno::Reference< accessibility::XAccessible > xAccessible(pWindow->GetAccessible());
     496                 :          0 :         if( xAccessible.is() )
     497                 :            :         {
     498                 :          0 :             create_wrapper_for_child(xAccessible->getAccessibleContext(), index);
     499                 :          0 :         }
     500                 :            :     }
     501                 :          0 : }
     502                 :            : 
     503                 :            : 
     504                 :            : /*****************************************************************************/
     505                 :            : 
     506                 :          0 : static std::set< Window * > g_aWindowList;
     507                 :            : 
     508                 :          0 : static void handle_get_focus(::VclWindowEvent const * pEvent)
     509                 :            : {
     510                 :            :     static rtl::Reference< DocumentFocusListener > aDocumentFocusListener =
     511                 :          0 :         new DocumentFocusListener();
     512                 :            : 
     513                 :          0 :     Window *pWindow = pEvent->GetWindow();
     514                 :            : 
     515                 :            :     // The menu bar is handled through VCLEVENT_MENU_HIGHLIGHTED
     516                 :          0 :     if( ! pWindow || !pWindow->IsReallyVisible() || pWindow->GetType() == WINDOW_MENUBARWINDOW )
     517                 :            :         return;
     518                 :            : 
     519                 :            :     // ToolBoxes are handled through VCLEVENT_TOOLBOX_HIGHLIGHT
     520                 :          0 :     if( pWindow->GetType() == WINDOW_TOOLBOX )
     521                 :            :         return;
     522                 :            : 
     523                 :          0 :     if( pWindow->GetType() == WINDOW_TABCONTROL )
     524                 :            :     {
     525                 :          0 :         handle_tabpage_activated( pWindow );
     526                 :            :         return;
     527                 :            :     }
     528                 :            : 
     529                 :            :     uno::Reference< accessibility::XAccessible > xAccessible =
     530                 :          0 :         pWindow->GetAccessible();
     531                 :            : 
     532                 :          0 :     if( ! xAccessible.is() )
     533                 :            :         return;
     534                 :            : 
     535                 :            :     uno::Reference< accessibility::XAccessibleContext > xContext =
     536                 :          0 :         xAccessible->getAccessibleContext();
     537                 :            : 
     538                 :          0 :     if( ! xContext.is() )
     539                 :            :         return;
     540                 :            : 
     541                 :            :     uno::Reference< accessibility::XAccessibleStateSet > xStateSet =
     542                 :          0 :         xContext->getAccessibleStateSet();
     543                 :            : 
     544                 :          0 :     if( ! xStateSet.is() )
     545                 :            :         return;
     546                 :            : 
     547                 :            : /* the UNO ToolBox wrapper does not (yet?) support XAccessibleSelection, so we
     548                 :            :  * need to add listeners to the children instead of re-using the tabpage stuff
     549                 :            :  */
     550                 :          0 :     if( xStateSet->contains(accessibility::AccessibleStateType::FOCUSED) &&
     551                 :          0 :         ( pWindow->GetType() != WINDOW_TREELISTBOX ) )
     552                 :            :     {
     553                 :          0 :         atk_wrapper_focus_tracker_notify_when_idle( xAccessible );
     554                 :            :     }
     555                 :            :     else
     556                 :            :     {
     557                 :          0 :         if( g_aWindowList.find(pWindow) == g_aWindowList.end() )
     558                 :            :         {
     559                 :          0 :             g_aWindowList.insert(pWindow);
     560                 :            :             try
     561                 :            :             {
     562                 :          0 :                 aDocumentFocusListener->attachRecursive(xAccessible, xContext, xStateSet);
     563                 :            :             }
     564                 :          0 :             catch (const uno::Exception&)
     565                 :            :             {
     566                 :          0 :                 g_warning( "Exception caught processing focus events" );
     567                 :            :             }
     568                 :            :         }
     569                 :            : #ifdef ENABLE_TRACING
     570                 :            :         else
     571                 :            :             fprintf(stderr, "Window %p already in the list\n", pWindow );
     572                 :            : #endif
     573                 :          0 :     }
     574                 :            : }
     575                 :            : 
     576                 :            : /*****************************************************************************/
     577                 :            : 
     578                 :          0 : static void handle_menu_highlighted(::VclMenuEvent const * pEvent)
     579                 :            : {
     580                 :            :     try
     581                 :            :     {
     582                 :          0 :         Menu* pMenu = pEvent->GetMenu();
     583                 :          0 :         sal_uInt16 nPos = pEvent->GetItemPos();
     584                 :            : 
     585                 :          0 :         if( pMenu &&  nPos != 0xFFFF)
     586                 :            :         {
     587                 :          0 :             uno::Reference< accessibility::XAccessible > xAccessible ( pMenu->GetAccessible() );
     588                 :            : 
     589                 :          0 :             if( xAccessible.is() )
     590                 :            :             {
     591                 :          0 :                 uno::Reference< accessibility::XAccessibleContext > xContext ( xAccessible->getAccessibleContext() );
     592                 :            : 
     593                 :          0 :                 if( xContext.is() )
     594                 :          0 :                     atk_wrapper_focus_tracker_notify_when_idle( xContext->getAccessibleChild( nPos ) );
     595                 :          0 :             }
     596                 :            :         }
     597                 :            :     }
     598                 :          0 :     catch (const uno::Exception&)
     599                 :            :     {
     600                 :          0 :         g_warning( "Exception caught processing menu highlight events" );
     601                 :            :     }
     602                 :          0 : }
     603                 :            : 
     604                 :            : /*****************************************************************************/
     605                 :            : 
     606                 :          0 : long WindowEventHandler(void *, ::VclSimpleEvent const * pEvent)
     607                 :            : {
     608                 :            :     try
     609                 :            :     {
     610                 :          0 :         switch (pEvent->GetId())
     611                 :            :         {
     612                 :            :         case VCLEVENT_WINDOW_SHOW:
     613                 :          0 :             break;
     614                 :            :         case VCLEVENT_WINDOW_HIDE:
     615                 :          0 :             break;
     616                 :            :         case VCLEVENT_WINDOW_CLOSE:
     617                 :          0 :             break;
     618                 :            :         case VCLEVENT_WINDOW_GETFOCUS:
     619                 :          0 :             handle_get_focus(static_cast< ::VclWindowEvent const * >(pEvent));
     620                 :          0 :             break;
     621                 :            :         case VCLEVENT_WINDOW_LOSEFOCUS:
     622                 :          0 :             break;
     623                 :            :         case VCLEVENT_WINDOW_MINIMIZE:
     624                 :          0 :             break;
     625                 :            :         case VCLEVENT_WINDOW_NORMALIZE:
     626                 :          0 :             break;
     627                 :            :         case VCLEVENT_WINDOW_KEYINPUT:
     628                 :            :         case VCLEVENT_WINDOW_KEYUP:
     629                 :            :         case VCLEVENT_WINDOW_COMMAND:
     630                 :            :         case VCLEVENT_WINDOW_MOUSEMOVE:
     631                 :          0 :             break;
     632                 :            : 
     633                 :            :         case VCLEVENT_MENU_HIGHLIGHT:
     634                 :          0 :             if (const VclMenuEvent* pMenuEvent = dynamic_cast<const VclMenuEvent*>(pEvent))
     635                 :            :             {
     636                 :          0 :                 handle_menu_highlighted(pMenuEvent);
     637                 :            :             }
     638                 :          0 :             else if (const VclAccessibleEvent* pAccEvent = dynamic_cast<const VclAccessibleEvent*>(pEvent))
     639                 :            :             {
     640                 :          0 :                 uno::Reference< accessibility::XAccessible > xAccessible = pAccEvent->GetAccessible();
     641                 :          0 :                 if (xAccessible.is())
     642                 :          0 :                     atk_wrapper_focus_tracker_notify_when_idle(xAccessible);
     643                 :            :             }
     644                 :          0 :             break;
     645                 :            : 
     646                 :            :         case VCLEVENT_TOOLBOX_HIGHLIGHT:
     647                 :          0 :             handle_toolbox_highlight(static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow());
     648                 :          0 :             break;
     649                 :            : 
     650                 :            :         case VCLEVENT_TOOLBOX_BUTTONSTATECHANGED:
     651                 :          0 :             handle_toolbox_buttonchange(static_cast< ::VclWindowEvent const * >(pEvent));
     652                 :          0 :             break;
     653                 :            : 
     654                 :            :         case VCLEVENT_OBJECT_DYING:
     655                 :          0 :             g_aWindowList.erase( static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow() );
     656                 :            :             // fallthrough intentional !
     657                 :            :         case VCLEVENT_TOOLBOX_HIGHLIGHTOFF:
     658                 :          0 :             handle_toolbox_highlightoff(static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow());
     659                 :          0 :             break;
     660                 :            : 
     661                 :            :         case VCLEVENT_TABPAGE_ACTIVATE:
     662                 :          0 :             handle_tabpage_activated(static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow());
     663                 :          0 :             break;
     664                 :            : 
     665                 :            :         case VCLEVENT_COMBOBOX_SETTEXT:
     666                 :            :             // This looks quite strange to me. Stumbled over this when fixing #i104290#.
     667                 :            :             // This kicked in when leaving the combobox in the toolbar, after that the events worked.
     668                 :            :             // I guess this was a try to work around missing combobox events, which didn't do the full job, and shouldn't be necessary anymore.
     669                 :            :             // Fix for #i104290# was done in toolkit/source/awt/vclxaccessiblecomponent, FOCUSED state for compound controls in general.
     670                 :            :             // create_wrapper_for_children(static_cast< ::VclWindowEvent const * >(pEvent)->GetWindow());
     671                 :          0 :             break;
     672                 :            : 
     673                 :            :         default:
     674                 :          0 :             break;
     675                 :            :         }
     676                 :            :     }
     677                 :          0 :     catch (const lang::IndexOutOfBoundsException&)
     678                 :            :     {
     679                 :          0 :         g_warning("Focused object has invalid index in parent");
     680                 :            :     }
     681                 :          0 :     return 0;
     682                 :            : }
     683                 :            : 
     684                 :          0 : static Link g_aEventListenerLink( NULL, (PSTUB) WindowEventHandler );
     685                 :            : 
     686                 :            : /*****************************************************************************/
     687                 :            : 
     688                 :            : extern "C" {
     689                 :            : 
     690                 :            : static G_CONST_RETURN gchar *
     691                 :          0 : ooo_atk_util_get_toolkit_name (void)
     692                 :            : {
     693                 :          0 :     return "VCL";
     694                 :            : }
     695                 :            : 
     696                 :            : /*****************************************************************************/
     697                 :            : 
     698                 :            : static G_CONST_RETURN gchar *
     699                 :          0 : ooo_atk_util_get_toolkit_version (void)
     700                 :            : {
     701                 :            :     /*
     702                 :            :      * Version is passed in as a -D flag when this file is
     703                 :            :      * compiled.
     704                 :            :      */
     705                 :          0 :     return LIBO_VERSION;
     706                 :            : }
     707                 :            : 
     708                 :            : /*****************************************************************************/
     709                 :            : 
     710                 :            : /*
     711                 :            :  * GObject inheritance
     712                 :            :  */
     713                 :            : 
     714                 :            : static void
     715                 :          0 : ooo_atk_util_class_init (AtkUtilClass *)
     716                 :            : {
     717                 :            :     AtkUtilClass *atk_class;
     718                 :            :     gpointer data;
     719                 :            : 
     720                 :          0 :     data = g_type_class_peek (ATK_TYPE_UTIL);
     721                 :          0 :     atk_class = ATK_UTIL_CLASS (data);
     722                 :            : 
     723                 :          0 :     atk_class->get_toolkit_name = ooo_atk_util_get_toolkit_name;
     724                 :          0 :     atk_class->get_toolkit_version = ooo_atk_util_get_toolkit_version;
     725                 :            : 
     726                 :          0 :     Application::AddEventListener( g_aEventListenerLink );
     727                 :          0 : }
     728                 :            : 
     729                 :            : } // extern "C"
     730                 :            : 
     731                 :            : /*****************************************************************************/
     732                 :            : 
     733                 :            : GType
     734                 :          0 : ooo_atk_util_get_type (void)
     735                 :            : {
     736                 :            :     static GType type = 0;
     737                 :            : 
     738                 :          0 :     if (!type)
     739                 :            :     {
     740                 :          0 :         GType parent_type = g_type_from_name( "GailUtil" );
     741                 :            : 
     742                 :          0 :         if( ! parent_type )
     743                 :            :         {
     744                 :          0 :             g_warning( "Unknown type: GailUtil" );
     745                 :          0 :             parent_type = ATK_TYPE_UTIL;
     746                 :            :         }
     747                 :            : 
     748                 :            :         GTypeQuery type_query;
     749                 :          0 :         g_type_query( parent_type, &type_query );
     750                 :            : 
     751                 :            :         static const GTypeInfo typeInfo =
     752                 :            :         {
     753                 :            :             static_cast<guint16>(type_query.class_size),
     754                 :            :             (GBaseInitFunc) NULL,
     755                 :            :             (GBaseFinalizeFunc) NULL,
     756                 :            :             (GClassInitFunc) ooo_atk_util_class_init,
     757                 :            :             (GClassFinalizeFunc) NULL,
     758                 :            :             NULL,
     759                 :            :             static_cast<guint16>(type_query.instance_size),
     760                 :            :             0,
     761                 :            :             (GInstanceInitFunc) NULL,
     762                 :            :             NULL
     763                 :          0 :         } ;
     764                 :            : 
     765                 :          0 :         type = g_type_register_static (parent_type, "OOoUtil", &typeInfo, (GTypeFlags)0) ;
     766                 :            :   }
     767                 :            : 
     768                 :          0 :   return type;
     769                 :          0 : }
     770                 :            : 
     771                 :            : 
     772                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10