GTK: Add some documentation on accessible object reference ownerships
[geany-mirror.git] / scintilla / gtk / ScintillaGTKAccessible.h
blob93883025d17b9dc56da913348345e3e958bb8259
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
9 #ifdef SCI_NAMESPACE
10 namespace Scintilla {
11 #endif
13 #ifndef ATK_CHECK_VERSION
14 # define ATK_CHECK_VERSION(x, y, z) 0
15 #endif
17 class ScintillaGTKAccessible {
18 private:
19 // weak references to related objects
20 GtkAccessible *accessible;
21 ScintillaGTK *sci;
23 // local state for comparing
24 Position old_pos;
25 std::vector<SelectionRange> old_sels;
27 void UpdateCursor();
28 void Notify(GtkWidget *widget, gint code, SCNotification *nt);
29 static void SciNotify(GtkWidget *widget, gint code, SCNotification *nt, gpointer data) {
30 try {
31 reinterpret_cast<ScintillaGTKAccessible*>(data)->Notify(widget, code, nt);
32 } catch (...) {}
35 Position ByteOffsetFromCharacterOffset(Position startByte, int characterOffset) {
36 Position pos = sci->pdoc->GetRelativePosition(startByte, characterOffset);
37 if (pos == INVALID_POSITION) {
38 // clamp invalid positions inside the document
39 if (characterOffset > 0) {
40 return sci->pdoc->Length();
41 } else {
42 return 0;
45 return pos;
48 Position ByteOffsetFromCharacterOffset(int characterOffset) {
49 return ByteOffsetFromCharacterOffset(0, characterOffset);
52 int CharacterOffsetFromByteOffset(Position byteOffset) {
53 return sci->pdoc->CountCharacters(0, byteOffset);
56 void CharacterRangeFromByteRange(Position startByte, Position endByte, int *startChar, int *endChar) {
57 *startChar = CharacterOffsetFromByteOffset(startByte);
58 *endChar = *startChar + sci->pdoc->CountCharacters(startByte, endByte);
61 void ByteRangeFromCharacterRange(int startChar, int endChar, Position& startByte, Position& endByte) {
62 startByte = ByteOffsetFromCharacterOffset(startChar);
63 endByte = ByteOffsetFromCharacterOffset(startByte, endChar - startChar);
66 Position PositionBefore(Position pos) {
67 return sci->pdoc->MovePositionOutsideChar(pos - 1, -1, true);
70 Position PositionAfter(Position pos) {
71 return sci->pdoc->MovePositionOutsideChar(pos + 1, 1, true);
74 // For AtkText
75 gchar *GetTextRangeUTF8(Position startByte, Position endByte);
76 gchar *GetText(int startChar, int endChar);
77 gchar *GetTextAfterOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
78 gchar *GetTextBeforeOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
79 gchar *GetTextAtOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
80 #if ATK_CHECK_VERSION(2, 10, 0)
81 gchar *GetStringAtOffset(int charOffset, AtkTextGranularity granularity, int *startChar, int *endChar);
82 #endif
83 gunichar GetCharacterAtOffset(int charOffset);
84 gint GetCharacterCount();
85 gint GetCaretOffset();
86 gboolean SetCaretOffset(int charOffset);
87 gint GetOffsetAtPoint(gint x, gint y, AtkCoordType coords);
88 void GetCharacterExtents(int charOffset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords);
89 AtkAttributeSet *GetAttributesForStyle(unsigned int style);
90 AtkAttributeSet *GetRunAttributes(int charOffset, int *startChar, int *endChar);
91 AtkAttributeSet *GetDefaultAttributes();
92 gint GetNSelections();
93 gchar *GetSelection(gint selection_num, int *startChar, int *endChar);
94 gboolean AddSelection(int startChar, int endChar);
95 gboolean RemoveSelection(int selection_num);
96 gboolean SetSelection(gint selection_num, int startChar, int endChar);
97 // for AtkEditableText
98 bool InsertStringUTF8(Position bytePos, const gchar *utf8, int lengthBytes);
99 void SetTextContents(const gchar *contents);
100 void InsertText(const gchar *contents, int lengthBytes, int *charPosition);
101 void CopyText(int startChar, int endChar);
102 void CutText(int startChar, int endChar);
103 void DeleteText(int startChar, int endChar);
104 void PasteText(int charPosition);
106 public:
107 ScintillaGTKAccessible(GtkAccessible *accessible, GtkWidget *widget);
108 ~ScintillaGTKAccessible();
110 static ScintillaGTKAccessible *FromAccessible(GtkAccessible *accessible);
111 static ScintillaGTKAccessible *FromAccessible(AtkObject *accessible) {
112 return FromAccessible(GTK_ACCESSIBLE(accessible));
114 // So ScintillaGTK can notify us
115 void ChangeDocument(Document *oldDoc, Document *newDoc);
116 void NotifyReadOnly();
118 // Helper GtkWidget methods
119 static AtkObject *WidgetGetAccessibleImpl(GtkWidget *widget, AtkObject **cache, gpointer widget_parent_class);
121 // ATK methods
123 class AtkTextIface {
124 public:
125 static void init(::AtkTextIface *iface);
127 private:
128 AtkTextIface();
130 static gchar *GetText(AtkText *text, int start_offset, int end_offset);
131 static gchar *GetTextAfterOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset);
132 static gchar *GetTextBeforeOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset);
133 static gchar *GetTextAtOffset(AtkText *text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset);
134 #if ATK_CHECK_VERSION(2, 10, 0)
135 static gchar *GetStringAtOffset(AtkText *text, gint offset, AtkTextGranularity granularity, gint *start_offset, gint *end_offset);
136 #endif
137 static gunichar GetCharacterAtOffset(AtkText *text, gint offset);
138 static gint GetCharacterCount(AtkText *text);
139 static gint GetCaretOffset(AtkText *text);
140 static gboolean SetCaretOffset(AtkText *text, gint offset);
141 static gint GetOffsetAtPoint(AtkText *text, gint x, gint y, AtkCoordType coords);
142 static void GetCharacterExtents(AtkText *text, gint offset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords);
143 static AtkAttributeSet *GetRunAttributes(AtkText *text, gint offset, gint *start_offset, gint *end_offset);
144 static AtkAttributeSet *GetDefaultAttributes(AtkText *text);
145 static gint GetNSelections(AtkText *text);
146 static gchar *GetSelection(AtkText *text, gint selection_num, gint *start_pos, gint *end_pos);
147 static gboolean AddSelection(AtkText *text, gint start, gint end);
148 static gboolean RemoveSelection(AtkText *text, gint selection_num);
149 static gboolean SetSelection(AtkText *text, gint selection_num, gint start, gint end);
151 class AtkEditableTextIface {
152 public:
153 static void init(::AtkEditableTextIface *iface);
155 private:
156 AtkEditableTextIface();
158 static void SetTextContents(AtkEditableText *text, const gchar *contents);
159 static void InsertText(AtkEditableText *text, const gchar *contents, gint length, gint *position);
160 static void CopyText(AtkEditableText *text, gint start, gint end);
161 static void CutText(AtkEditableText *text, gint start, gint end);
162 static void DeleteText(AtkEditableText *text, gint start, gint end);
163 static void PasteText(AtkEditableText *text, gint position);
167 #ifdef SCI_NAMESPACE
169 #endif
172 #endif /* SCINTILLAGTKACCESSIBLE_H */