forked from Mudlet/Mudlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTAccessibleTextEdit.h
103 lines (90 loc) · 4.75 KB
/
TAccessibleTextEdit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef MUDLET_TACCESSIBLETEXTEDIT_H
#define MUDLET_TACCESSIBLETEXTEDIT_H
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - [email protected] *
* Copyright (C) 2014-2017 by Ahmed Charles - [email protected] *
* Copyright (C) 2014-2020, 2022 by Stephen Lyons *
* - [email protected] *
* Copyright (C) 2022 by Thiago Jung Bauermann - [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "TTextEdit.h"
#include "pre_guard.h"
#include <QAccessibleInterface>
#include <QAccessibleTextInterface>
#include <QAccessibleWidget>
#include "post_guard.h"
class TAccessibleTextEdit : public QAccessibleWidget, public QAccessibleTextInterface
{
public:
explicit TAccessibleTextEdit(QWidget* w)
: QAccessibleWidget(w, QAccessible::EditableText)
{
Q_ASSERT(isValid());
}
static QAccessibleInterface* textEditFactory(const QString &classname, QObject *object)
{
// The original identifier "interface" was no good as it is an existing
// macro (on MSYS2/Mingw-w64) and breaks compilation on that platform in
// an obsecure way:
QAccessibleInterface* pInterface = nullptr;
if (classname == QLatin1String("TTextEdit") && object && object->isWidgetType()) {
pInterface = new TAccessibleTextEdit(static_cast<QWidget *>(object));
}
return pInterface;
}
void* interface_cast(QAccessible::InterfaceType t) override
{
if (t == QAccessible::TextInterface) {
return static_cast<QAccessibleTextInterface*>(this);
}
return QAccessibleWidget::interface_cast(t);
}
QAccessible::State state() const override;
void selection(int selectionIndex, int *startOffset, int *endOffset) const override;
int selectionCount() const override;
void addSelection(int startOffset, int endOffset) override;
void removeSelection(int selectionIndex) override;
void setSelection(int selectionIndex, int startOffset, int endOffset) override;
int cursorPosition() const override;
void setCursorPosition(int position) override;
QString text(QAccessible::Text t) const override;
QString text(int startOffset, int endOffset) const override;
int characterCount() const override;
QRect characterRect(int offset) const override;
int offsetAtPoint(const QPoint &point) const override;
void scrollToSubstring(int startIndex, int endIndex) override;
QString attributes(int offset, int *startOffset, int *endOffset) const override;
QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType, int *startOffset, int *endOffset) const override;
QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType, int *startOffset, int *endOffset) const override;
QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType, int *startOffset, int *endOffset) const override;
private:
enum class TextOp {
BeforeOffset,
AtOffset,
AfterOffset,
};
TTextEdit* textEdit() const;
bool offsetIsInvalid(int offset) const;
int lineForOffset(int offset, int *lengthSoFar) const;
int columnForOffset(int offset) const;
int offsetForPosition(int line, int column) const;
bool lineIsVisible(int line) const;
QString textAroundOffset(TextOp op, int offset, QAccessible::TextBoundaryType boundaryType,
int* startOffset, int* endOffset) const;
};
#endif // MUDLET_TACCESSIBLETEXTEDIT_H