1 /* Scintilla source code edit control */
2 /* ScintillaGTKAccessible.h - GTK+ accessibility for ScintillaGTK */
3 /* Copyright 2016 by Colomban Wendling <colomban@geany.org>
4 * The License.txt file describes the conditions under which this software may be distributed. */
6 #ifndef SCINTILLAGTKACCESSIBLE_H
7 #define SCINTILLAGTKACCESSIBLE_H
13 #ifndef ATK_CHECK_VERSION
14 # define ATK_CHECK_VERSION(x, y, z) 0
17 class ScintillaGTKAccessible
{
19 GtkAccessible
*accessible
;
22 // local state for comparing
24 std::vector
<SelectionRange
> old_sels
;
27 void Notify(GtkWidget
*widget
, gint code
, SCNotification
*nt
);
28 static void SciNotify(GtkWidget
*widget
, gint code
, SCNotification
*nt
, gpointer data
) {
30 reinterpret_cast<ScintillaGTKAccessible
*>(data
)->Notify(widget
, code
, nt
);
34 Position
ByteOffsetFromCharacterOffset(Position startByte
, int characterOffset
) {
35 Position pos
= sci
->pdoc
->GetRelativePosition(startByte
, characterOffset
);
36 if (pos
== INVALID_POSITION
) {
37 // clamp invalid positions inside the document
38 if (characterOffset
> 0) {
39 return sci
->pdoc
->Length();
47 Position
ByteOffsetFromCharacterOffset(int characterOffset
) {
48 return ByteOffsetFromCharacterOffset(0, characterOffset
);
51 int CharacterOffsetFromByteOffset(Position byteOffset
) {
52 return sci
->pdoc
->CountCharacters(0, byteOffset
);
55 void CharacterRangeFromByteRange(Position startByte
, Position endByte
, int *startChar
, int *endChar
) {
56 *startChar
= CharacterOffsetFromByteOffset(startByte
);
57 *endChar
= *startChar
+ sci
->pdoc
->CountCharacters(startByte
, endByte
);
60 void ByteRangeFromCharacterRange(int startChar
, int endChar
, Position
& startByte
, Position
& endByte
) {
61 startByte
= ByteOffsetFromCharacterOffset(startChar
);
62 endByte
= ByteOffsetFromCharacterOffset(startByte
, endChar
- startChar
);
65 Position
PositionBefore(Position pos
) {
66 return sci
->pdoc
->MovePositionOutsideChar(pos
- 1, -1, true);
69 Position
PositionAfter(Position pos
) {
70 return sci
->pdoc
->MovePositionOutsideChar(pos
+ 1, 1, true);
74 gchar
*GetTextRangeUTF8(Position startByte
, Position endByte
);
75 gchar
*GetText(int startChar
, int endChar
);
76 gchar
*GetTextAfterOffset(int charOffset
, AtkTextBoundary boundaryType
, int *startChar
, int *endChar
);
77 gchar
*GetTextBeforeOffset(int charOffset
, AtkTextBoundary boundaryType
, int *startChar
, int *endChar
);
78 gchar
*GetTextAtOffset(int charOffset
, AtkTextBoundary boundaryType
, int *startChar
, int *endChar
);
79 #if ATK_CHECK_VERSION(2, 10, 0)
80 gchar
*GetStringAtOffset(int charOffset
, AtkTextGranularity granularity
, int *startChar
, int *endChar
);
82 gunichar
GetCharacterAtOffset(int charOffset
);
83 gint
GetCharacterCount();
84 gint
GetCaretOffset();
85 gboolean
SetCaretOffset(int charOffset
);
86 gint
GetOffsetAtPoint(gint x
, gint y
, AtkCoordType coords
);
87 void GetCharacterExtents(int charOffset
, gint
*x
, gint
*y
, gint
*width
, gint
*height
, AtkCoordType coords
);
88 AtkAttributeSet
*GetAttributesForStyle(unsigned int style
);
89 AtkAttributeSet
*GetRunAttributes(int charOffset
, int *startChar
, int *endChar
);
90 AtkAttributeSet
*GetDefaultAttributes();
91 gint
GetNSelections();
92 gchar
*GetSelection(gint selection_num
, int *startChar
, int *endChar
);
93 gboolean
AddSelection(int startChar
, int endChar
);
94 gboolean
RemoveSelection(int selection_num
);
95 gboolean
SetSelection(gint selection_num
, int startChar
, int endChar
);
96 // for AtkEditableText
97 bool InsertStringUTF8(Position bytePos
, const gchar
*utf8
, int lengthBytes
);
98 void SetTextContents(const gchar
*contents
);
99 void InsertText(const gchar
*contents
, int lengthBytes
, int *charPosition
);
100 void CopyText(int startChar
, int endChar
);
101 void CutText(int startChar
, int endChar
);
102 void DeleteText(int startChar
, int endChar
);
103 void PasteText(int charPosition
);
106 ScintillaGTKAccessible(GtkAccessible
*accessible
, GtkWidget
*widget
);
107 ~ScintillaGTKAccessible();
109 static ScintillaGTKAccessible
*FromAccessible(GtkAccessible
*accessible
);
110 static ScintillaGTKAccessible
*FromAccessible(AtkObject
*accessible
) {
111 return FromAccessible(GTK_ACCESSIBLE(accessible
));
113 // So ScintillaGTK can notify us
114 void ChangeDocument(Document
*oldDoc
, Document
*newDoc
);
115 void NotifyReadOnly();
117 // Helper GtkWidget methods
118 static AtkObject
*WidgetGetAccessibleImpl(GtkWidget
*widget
, AtkObject
**cache
, gpointer widget_parent_class
);
124 static void init(::AtkTextIface
*iface
);
129 static gchar
*GetText(AtkText
*text
, int start_offset
, int end_offset
);
130 static gchar
*GetTextAfterOffset(AtkText
*text
, int offset
, AtkTextBoundary boundary_type
, int *start_offset
, int *end_offset
);
131 static gchar
*GetTextBeforeOffset(AtkText
*text
, int offset
, AtkTextBoundary boundary_type
, int *start_offset
, int *end_offset
);
132 static gchar
*GetTextAtOffset(AtkText
*text
, gint offset
, AtkTextBoundary boundary_type
, gint
*start_offset
, gint
*end_offset
);
133 #if ATK_CHECK_VERSION(2, 10, 0)
134 static gchar
*GetStringAtOffset(AtkText
*text
, gint offset
, AtkTextGranularity granularity
, gint
*start_offset
, gint
*end_offset
);
136 static gunichar
GetCharacterAtOffset(AtkText
*text
, gint offset
);
137 static gint
GetCharacterCount(AtkText
*text
);
138 static gint
GetCaretOffset(AtkText
*text
);
139 static gboolean
SetCaretOffset(AtkText
*text
, gint offset
);
140 static gint
GetOffsetAtPoint(AtkText
*text
, gint x
, gint y
, AtkCoordType coords
);
141 static void GetCharacterExtents(AtkText
*text
, gint offset
, gint
*x
, gint
*y
, gint
*width
, gint
*height
, AtkCoordType coords
);
142 static AtkAttributeSet
*GetRunAttributes(AtkText
*text
, gint offset
, gint
*start_offset
, gint
*end_offset
);
143 static AtkAttributeSet
*GetDefaultAttributes(AtkText
*text
);
144 static gint
GetNSelections(AtkText
*text
);
145 static gchar
*GetSelection(AtkText
*text
, gint selection_num
, gint
*start_pos
, gint
*end_pos
);
146 static gboolean
AddSelection(AtkText
*text
, gint start
, gint end
);
147 static gboolean
RemoveSelection(AtkText
*text
, gint selection_num
);
148 static gboolean
SetSelection(AtkText
*text
, gint selection_num
, gint start
, gint end
);
150 class AtkEditableTextIface
{
152 static void init(::AtkEditableTextIface
*iface
);
155 AtkEditableTextIface();
157 static void SetTextContents(AtkEditableText
*text
, const gchar
*contents
);
158 static void InsertText(AtkEditableText
*text
, const gchar
*contents
, gint length
, gint
*position
);
159 static void CopyText(AtkEditableText
*text
, gint start
, gint end
);
160 static void CutText(AtkEditableText
*text
, gint start
, gint end
);
161 static void DeleteText(AtkEditableText
*text
, gint start
, gint end
);
162 static void PasteText(AtkEditableText
*text
, gint position
);
171 #endif /* SCINTILLAGTKACCESSIBLE_H */