Qt 4.8
qaccessible.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qaccessible.h"
43 
44 #ifndef QT_NO_ACCESSIBILITY
45 
46 #include "qaccessibleplugin.h"
47 #include "qaccessiblewidget.h"
48 #include "qapplication.h"
49 #include "qhash.h"
50 #include "qmetaobject.h"
51 #include "qmutex.h"
52 #include <private/qfactoryloader_p.h>
53 
54 #include "qwidget.h"
55 
57 
483 #ifndef QT_NO_LIBRARY
486 #endif
487 
489 
492 
493 static bool accessibility_active = false;
494 static bool cleanupAdded = false;
495 static void qAccessibleCleanup()
496 {
497  qAccessibleFactories()->clear();
498 }
499 
553 void QAccessible::installFactory(InterfaceFactory factory)
554 {
555  if (!factory)
556  return;
557 
558  if (!cleanupAdded) {
560  cleanupAdded = true;
561  }
562  if (qAccessibleFactories()->contains(factory))
563  return;
564  qAccessibleFactories()->append(factory);
565 }
566 
571 {
572  qAccessibleFactories()->removeAll(factory);
573 }
574 
586 {
589  return old;
590 }
591 
597 {
600  return old;
601 }
602 
623 {
624  accessibility_active = true;
625  QAccessibleInterface *iface = 0;
626  if (!object)
627  return 0;
628 
629  const QMetaObject *mo = object->metaObject();
630  while (mo) {
631  const QLatin1String cn(mo->className());
632  for (int i = qAccessibleFactories()->count(); i > 0; --i) {
633  InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
634  iface = factory(cn, object);
635  if (iface)
636  return iface;
637  }
638 #ifndef QT_NO_LIBRARY
639  QAccessibleFactoryInterface *factory = qobject_cast<QAccessibleFactoryInterface*>(loader()->instance(cn));
640  if (factory) {
641  iface = factory->create(cn, object);
642  if (iface)
643  return iface;
644  }
645 #endif
646  mo = mo->superClass();
647  }
648 
649  QWidget *widget = qobject_cast<QWidget*>(object);
650  if (widget)
651  return new QAccessibleWidget(widget);
652  else if (object == qApp)
653  return new QAccessibleApplication();
654 
655  return 0;
656 }
657 
666 {
667  return accessibility_active;
668 }
669 
1227 {
1228  if (!(state(0) & HasInvokeExtension))
1229  return QVariant();
1230 
1231  return static_cast<QAccessibleInterfaceEx *>(this)->invokeMethodEx(method, child, params);
1232 }
1233 
1235 {
1236  return QVariant();
1237 }
1238 
1241 {
1242  if (state(0) & HasInvokeExtension)
1243  return static_cast<QAccessibleInterfaceEx *>(this)->interface_cast(t);
1244  return 0;
1245 }
1246 
1248 
1249 #endif
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
T qobject_cast(QObject *object)
Definition: qobject.h:375
static void removeFactory(InterfaceFactory)
Removes factory from the list of installed InterfaceFactories.
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QAccessibleApplication class implements the QAccessibleInterface for QApplication.
QPointer< QWidget > widget
void qAddPostRoutine(QtCleanUpFunction p)
static bool accessibility_active
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual QAccessibleInterface * create(const QString &key, QObject *object)=0
QAccessible2Interface * cast_helper(QAccessible2::InterfaceType)
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static RootObjectHandler installRootObjectHandler(RootObjectHandler)
Installs the given handler as the function to be used by setRootObject(), and returns the previously ...
virtual QVariant virtual_hook(const QVariant &data)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void(* RootObjectHandler)(QObject *)
A function pointer type.
Definition: qaccessible.h:321
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QVariant invokeMethod(Method method, int child=0, const QVariantList &params=QVariantList())
Invokes a method on child with the given parameters params and returns the result of the operation as...
#define qApp
Method
This enum describes the possible types of methods that can be invoked on an accessible object...
Definition: qaccessible.h:311
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
void(* UpdateHandler)(QObject *, int who, Event reason)
A function pointer type.
Definition: qaccessible.h:320
QAccessibleInterface *(* InterfaceFactory)(const QString &key, QObject *)
This is a typedef for a pointer to a function with the following signature:
Definition: qaccessible.h:319
const QMetaObject * superClass() const
Returns the meta-object of the superclass, or 0 if there is no such object.
Definition: qobjectdefs.h:494
static void installFactory(InterfaceFactory)
Installs the InterfaceFactory factory.
static bool isActive()
Returns true if an accessibility implementation has been requested during the runtime of the applicat...
The QAccessibleWidget class implements the QAccessibleInterface for QWidgets.
static QAccessibleInterface * queryAccessibleInterface(QObject *)
If a QAccessibleInterface implementation exists for the given object, this function returns a pointer...
The QAccessibleInterface class defines an interface that exposes information about accessible objects...
Definition: qaccessible.h:370
static void qAccessibleCleanup()
const char * className() const
Returns the class name.
Definition: qobjectdefs.h:491
#define QAccessibleFactoryInterface_iid
static UpdateHandler installUpdateHandler(UpdateHandler)
Installs the given handler as the function to be used by updateAccessibility(), and returns the previ...
QImageIOHandler * handler
static bool cleanupAdded
static UpdateHandler updateHandler
Definition: qaccessible.h:337
#define Q_GLOBAL_STATIC_WITH_ARGS(TYPE, NAME, ARGS)
Declares a global static variable with the specified type and name.
Definition: qglobal.h:1982
static RootObjectHandler rootObjectHandler
Definition: qaccessible.h:338
The QList class is a template class that provides lists.
Definition: qdatastream.h:62