source: trunk/src/gui/accessible/qaccessible2.cpp@ 139

Last change on this file since 139 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 5.7 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qaccessible2.h"
43#include "qapplication.h"
44#include "qclipboard.h"
45
46#ifndef QT_NO_ACCESSIBILITY
47
48QT_BEGIN_NAMESPACE
49
50/*!
51 \namespace QAccessible2
52 \ingroup accessibility
53 \internal
54 \preliminary
55
56 \brief The QAccessible2 namespace defines constants relating to
57 IAccessible2-based interfaces
58
59 \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink
60*/
61
62/*!
63 \class QAccessibleTextInterface
64
65 \ingroup accessibility
66 \internal
67 \preliminary
68
69 \brief The QAccessibleTextInterface class implements support for
70 the IAccessibleText interface.
71
72 \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink
73*/
74
75/*!
76 \class QAccessibleEditableTextInterface
77 \ingroup accessibility
78 \internal
79 \preliminary
80
81 \brief The QAccessibleEditableTextInterface class implements support for
82 the IAccessibleEditableText interface.
83
84 \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink
85*/
86
87/*!
88 \class QAccessibleSimpleEditableTextInterface
89 \ingroup accessibility
90 \internal
91 \preliminary
92
93 \brief The QAccessibleSimpleEditableTextInterface class is a convenience class for
94 text-based widgets.
95
96 \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink
97*/
98
99/*!
100 \class QAccessibleValueInterface
101 \ingroup accessibility
102 \internal
103 \preliminary
104
105 \brief The QAccessibleValueInterface class implements support for
106 the IAccessibleValue interface.
107
108 \link http://www.linux-foundation.org/en/Accessibility/IAccessible2 IAccessible2 Specification \endlink
109*/
110
111QAccessibleSimpleEditableTextInterface::QAccessibleSimpleEditableTextInterface(
112 QAccessibleInterface *accessibleInterface)
113 : iface(accessibleInterface)
114{
115 Q_ASSERT(iface);
116}
117
118#ifndef QT_NO_CLIPBOARD
119static QString textForRange(QAccessibleInterface *iface, int startOffset, int endOffset)
120{
121 return iface->text(QAccessible::Value, 0).mid(startOffset, endOffset - startOffset);
122}
123#endif
124
125void QAccessibleSimpleEditableTextInterface::copyText(int startOffset, int endOffset)
126{
127#ifdef QT_NO_CLIPBOARD
128 Q_UNUSED(startOffset);
129 Q_UNUSED(endOffset);
130#else
131 QApplication::clipboard()->setText(textForRange(iface, startOffset, endOffset));
132#endif
133}
134
135void QAccessibleSimpleEditableTextInterface::deleteText(int startOffset, int endOffset)
136{
137 QString txt = iface->text(QAccessible::Value, 0);
138 txt.remove(startOffset, endOffset - startOffset);
139 iface->setText(QAccessible::Value, 0, txt);
140}
141
142void QAccessibleSimpleEditableTextInterface::insertText(int offset, const QString &text)
143{
144 QString txt = iface->text(QAccessible::Value, 0);
145 txt.insert(offset, text);
146 iface->setText(QAccessible::Value, 0, txt);
147}
148
149void QAccessibleSimpleEditableTextInterface::cutText(int startOffset, int endOffset)
150{
151#ifdef QT_NO_CLIPBOARD
152 Q_UNUSED(startOffset);
153 Q_UNUSED(endOffset);
154#else
155 QString sub = textForRange(iface, startOffset, endOffset);
156 deleteText(startOffset, endOffset);
157 QApplication::clipboard()->setText(sub);
158#endif
159}
160
161void QAccessibleSimpleEditableTextInterface::pasteText(int offset)
162{
163#ifdef QT_NO_CLIPBOARD
164 Q_UNUSED(offset);
165#else
166 QString txt = iface->text(QAccessible::Value, 0);
167 txt.insert(offset, QApplication::clipboard()->text());
168 iface->setText(QAccessible::Value, 0, txt);
169#endif
170}
171
172void QAccessibleSimpleEditableTextInterface::replaceText(int startOffset, int endOffset, const QString &text)
173{
174 QString txt = iface->text(QAccessible::Value, 0);
175 txt.replace(startOffset, endOffset - startOffset, text);
176 iface->setText(QAccessible::Value, 0, txt);
177}
178
179QT_END_NAMESPACE
180
181#endif // QT_NO_ACCESSIBILITY
Note: See TracBrowser for help on using the repository browser.