21 #ifndef _KATE_VIEW_ACCESSIBLE_
22 #define _KATE_VIEW_ACCESSIBLE_
23 #ifndef QT_NO_ACCESSIBILITY
24 #if QT_VERSION >= 0x040800
30 #include <QtGui/QAccessible>
31 #include <QtGui/qaccessible2.h>
33 #include <qaccessiblewidget.h>
37 QString Q_GUI_EXPORT qTextBeforeOffsetFromString(
int offset, QAccessible2::BoundaryType boundaryType,
38 int *startOffset,
int *endOffset,
const QString& text);
39 QString Q_GUI_EXPORT qTextAtOffsetFromString(
int offset, QAccessible2::BoundaryType boundaryType,
40 int *startOffset,
int *endOffset,
const QString& text);
41 QString Q_GUI_EXPORT qTextAfterOffsetFromString(
int offset, QAccessible2::BoundaryType boundaryType,
42 int *startOffset,
int *endOffset,
const QString& text);
60 class KateCursorAccessible :
public QAccessibleInterface
67 : QAccessibleInterface()
72 virtual ~KateCursorAccessible()
76 virtual QString actionText(
int action, QAccessible::Text t,
int)
const
78 if (t == QAccessible::Name) {
80 case 0:
return i18n(
"Move To...");
81 case 1:
return i18n(
"Move Left");
82 case 2:
return i18n(
"Move Right");
83 case 3:
return i18n(
"Move Up");
84 case 4:
return i18n(
"Move Down");
91 virtual bool doAction(
int action,
int,
const QVariantList & params = QVariantList() )
97 if (params.count() < 2) ok =
false;
98 const int line = ok ? params[0].toInt(&ok) : 0;
99 const int column = ok ? params[1].toInt(&ok) : 0;
106 default: ok =
false;
break;
112 virtual int userActionCount(
int)
const
117 virtual int childAt(
int,
int)
const
122 virtual int childCount()
const
127 virtual int indexOfChild(
const QAccessibleInterface *)
const
132 virtual bool isValid()
const
138 virtual int navigate(QAccessible::RelationFlag relation,
int entry, QAccessibleInterface **target)
const
146 virtual QObject* object()
const
151 virtual QRect rect(
int)
const
154 QPoint p = m_view->view()->cursorPositionCoordinates();
155 return QRect(m_view->mapToGlobal(p),
QSize(0,0));
158 virtual QAccessible::Relation relationTo(
int child,
const QAccessibleInterface *other,
int otherChild)
const
162 Q_UNUSED(otherChild);
163 return QAccessible::Unrelated;
166 virtual QAccessible::Role role(
int)
const
168 return QAccessible::Cursor;
171 virtual void setText(QAccessible::Text,
int,
const QString &)
175 virtual QAccessible::State state(
int)
const
177 QAccessible::State s = QAccessible::Focusable | QAccessible::Focused;
181 virtual QString text(QAccessible::Text,
int)
const
196 class KateViewAccessible :
public QAccessibleWidgetEx,
public QAccessibleTextInterface,
public QAccessibleSimpleEditableTextInterface
202 : QAccessibleWidgetEx(view), QAccessibleSimpleEditableTextInterface(this)
203 , m_cursor(new KateCursorAccessible(view))
207 virtual ~KateViewAccessible()
211 virtual QString actionText(
int action, QAccessible::Text t,
int child)
const
213 if (child == KateCursorAccessible::ChildId)
214 return m_cursor->actionText(action, t, 0);
218 virtual bool doAction(
int action,
int child,
const QVariantList & params = QVariantList() )
220 if (child == KateCursorAccessible::ChildId)
221 return m_cursor->doAction(action, 0, params);
225 virtual int userActionCount(
int child)
const
227 if (child == KateCursorAccessible::ChildId)
228 return m_cursor->userActionCount(0);
232 virtual int childAt(
int x,
int y)
const
239 virtual int childCount()
const
244 virtual int indexOfChild(
const QAccessibleInterface *child)
const
246 return dynamic_cast<const KateCursorAccessible*
>(child) ? KateCursorAccessible::ChildId : 0;
249 virtual int navigate(QAccessible::RelationFlag relation,
int entry, QAccessibleInterface **target)
const
251 if ((relation == QAccessible::Child || QAccessible::FocusChild) && entry == KateCursorAccessible::ChildId) {
252 *target =
new KateCursorAccessible(view());
253 return KateCursorAccessible::ChildId;
259 virtual QRect rect(
int child)
const
261 if (child == KateCursorAccessible::ChildId)
262 return m_cursor->rect(0);
263 return QRect(view()->mapToGlobal(
QPoint(0,0)), view()->size());
266 virtual QAccessible::Relation relationTo(
int child,
const QAccessibleInterface *other,
int otherChild)
const
270 Q_UNUSED(otherChild);
271 return QAccessible::Unrelated;
274 virtual QAccessible::Role role(
int child)
const
276 if (child == KateCursorAccessible::ChildId)
277 return QAccessible::Cursor;
278 return QAccessible::EditableText;
281 virtual void setText(QAccessible::Text t,
int child,
const QString & text)
283 if (t == QAccessible::Value && child == 0 && view()->view()->document())
284 view()->view()->document()->setText(text);
287 virtual QAccessible::State state(
int child)
const
289 if (child == KateCursorAccessible::ChildId)
290 return m_cursor->state(0);
292 QAccessible::State s = QAccessibleWidgetEx::state(0);
293 s |= QAccessible::Focusable;
295 if (view()->hasFocus())
296 s |= QAccessible::Focused;
298 s |= QAccessible::HasInvokeExtension;
302 virtual QString text(QAccessible::Text t,
int child)
const
304 if (child == KateCursorAccessible::ChildId)
305 return m_cursor->text(t, 0);
307 if (view()->view()->document()) {
308 if (t == QAccessible::Name)
309 s = view()->view()->document()->documentName();
310 if (t == QAccessible::Value)
311 s = view()->view()->document()->text();
316 virtual int characterCount()
318 return view()->view()->document()->text().size();
321 virtual void addSelection(
int startOffset,
int endOffset)
324 range.
setRange(cursorFromInt(startOffset), cursorFromInt(endOffset));
325 view()->view()->setSelection(range);
326 view()->view()->setCursorPosition(cursorFromInt(endOffset));
329 virtual QString attributes(
int offset,
int* startOffset,
int* endOffset)
333 *endOffset = characterCount();
336 virtual QRect characterRect(
int offset, QAccessible2::CoordinateType )
341 QPoint p = view()->view()->cursorToCoordinate(c);
343 QPoint size = view()->view()->cursorToCoordinate(endCursor) - p;
344 return QRect(view()->mapToGlobal(p),
QSize(size.x(), size.y()));
346 virtual int cursorPosition()
349 return positionFromCursor(c);
351 virtual int offsetAtPoint(
const QPoint& , QAccessible2::CoordinateType )
355 virtual void removeSelection(
int selectionIndex)
357 if (selectionIndex != 0)
359 view()->view()->clearSelection();
361 virtual void scrollToSubstring(
int ,
int )
365 virtual void selection(
int selectionIndex,
int *startOffset,
int *endOffset)
367 if (selectionIndex != 0 || !view()->view()->selection()) {
373 *startOffset = positionFromCursor(range.
start());
374 *endOffset = positionFromCursor(range.
end());
377 virtual int selectionCount()
379 return view()->view()->selection() ? 1 : 0;
381 virtual void setCursorPosition(
int position)
383 view()->view()->setCursorPosition(cursorFromInt(position));
385 virtual void setSelection(
int selectionIndex,
int startOffset,
int endOffset)
387 if (selectionIndex != 0)
390 view()->view()->setSelection(range);
392 virtual QString text(
int startOffset,
int endOffset)
394 if (startOffset > endOffset)
396 return view()->view()->document()->text().mid(startOffset, endOffset - startOffset);
399 virtual QString textAfterOffset(
int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset,
int* endOffset)
401 if (boundaryType == QAccessible2::LineBoundary)
402 return textLine(1, offset + 1, startOffset, endOffset);
404 const QString text = view()->view()->document()->text();
405 return qTextAfterOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
407 virtual QString textAtOffset(
int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset,
int* endOffset)
409 if (boundaryType == QAccessible2::LineBoundary)
410 return textLine(0, offset, startOffset, endOffset);
412 const QString text = view()->view()->document()->text();
413 return qTextAtOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
415 virtual QString textBeforeOffset(
int offset, QAccessible2::BoundaryType boundaryType,
int* startOffset,
int* endOffset)
417 if (boundaryType == QAccessible2::LineBoundary)
418 return textLine(-1, offset - 1, startOffset, endOffset);
420 const QString text = view()->view()->document()->text();
421 return qTextBeforeOffsetFromString(offset, boundaryType, startOffset, endOffset, text);
424 virtual QVariant invokeMethodEx(Method,
int,
const QVariantList&)
437 const QString lineString = view()->view()->document()->line(line);
438 if (position > lineString.length()) {
440 position -= lineString.length() + 1;
452 for (
int line = 0; line < cursor.
line(); ++line) {
454 pos += view()->view()->document()->line(line).size() + 1;
461 QString textLine(
int shiftLines,
int offset,
int* startOffset,
int* endOffset)
const
467 *startOffset = positionFromCursor(pos);
468 QString line = view()->view()->document()->line(pos.
line()) +
'\n';
469 *endOffset = *startOffset + line.length();
473 KateCursorAccessible *m_cursor;
480 QAccessibleInterface* accessibleInterfaceFactory(
const QString &key,
QObject *
object)
485 return new KateViewAccessible(view);
QScriptValue i18n(QScriptContext *context, QScriptEngine *engine)
i18n("text", arguments [optional])
virtual void setRange(const Range &range)
virtual bool isValid() const
virtual void setLine(int line)
virtual void setPosition(const Cursor &position)
virtual void setColumn(int column)