geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

ScintillaGTKAccessible.h
Go to the documentation of this file.
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. */
5
6#ifndef SCINTILLAGTKACCESSIBLE_H
7#define SCINTILLAGTKACCESSIBLE_H
8
9namespace Scintilla {
10
11#ifndef ATK_CHECK_VERSION
12# define ATK_CHECK_VERSION(x, y, z) 0
13#endif
14
16private:
17 // weak references to related objects
18 GtkAccessible *accessible;
20
21 // local state for comparing
23 std::vector<SelectionRange> old_sels;
24
25 bool Enabled() const;
26 void UpdateCursor();
27 void Notify(GtkWidget *widget, gint code, SCNotification *nt);
28 static void SciNotify(GtkWidget *widget, gint code, SCNotification *nt, gpointer data) {
29 try {
30 static_cast<ScintillaGTKAccessible*>(data)->Notify(widget, code, nt);
31 } catch (...) {}
32 }
33
36 return startByte + characterOffset;
37 }
38 if (characterOffset > 0) {
39 // Try and reduce the range by reverse-looking into the character offset cache
40 Sci::Line lineStart = sci->pdoc->LineFromPosition(startByte);
43 if (line != lineStart) {
44 startByte += sci->pdoc->LineStart(line) - sci->pdoc->LineStart(lineStart);
45 characterOffset -= sci->pdoc->IndexLineStart(line, SC_LINECHARACTERINDEX_UTF32) - posStart;
46 }
47 }
48 Sci::Position pos = sci->pdoc->GetRelativePosition(startByte, characterOffset);
49 if (pos == INVALID_POSITION) {
50 // clamp invalid positions inside the document
51 if (characterOffset > 0) {
52 return sci->pdoc->Length();
53 } else {
54 return 0;
55 }
56 }
57 return pos;
58 }
59
61 return ByteOffsetFromCharacterOffset(0, characterOffset);
62 }
63
66 return byteOffset;
67 }
68 const Sci::Line line = sci->pdoc->LineFromPosition(byteOffset);
69 const Sci::Position lineStart = sci->pdoc->LineStart(line);
70 return sci->pdoc->IndexLineStart(line, SC_LINECHARACTERINDEX_UTF32) + sci->pdoc->CountCharacters(lineStart, byteOffset);
71 }
72
73 void CharacterRangeFromByteRange(Sci::Position startByte, Sci::Position endByte, int *startChar, int *endChar) {
74 *startChar = CharacterOffsetFromByteOffset(startByte);
75 *endChar = *startChar + sci->pdoc->CountCharacters(startByte, endByte);
76 }
77
78 void ByteRangeFromCharacterRange(int startChar, int endChar, Sci::Position& startByte, Sci::Position& endByte) {
79 startByte = ByteOffsetFromCharacterOffset(startChar);
80 endByte = ByteOffsetFromCharacterOffset(startByte, endChar - startChar);
81 }
82
84 return sci->pdoc->MovePositionOutsideChar(pos - 1, -1, true);
85 }
86
88 return sci->pdoc->MovePositionOutsideChar(pos + 1, 1, true);
89 }
90
91 int StyleAt(Sci::Position position, bool ensureStyle = false) {
92 if (ensureStyle)
94 return sci->pdoc->StyleAt(position);
95 }
96
97 // For AtkText
98 gchar *GetTextRangeUTF8(Sci::Position startByte, Sci::Position endByte);
99 gchar *GetText(int startChar, int endChar);
100 gchar *GetTextAfterOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
101 gchar *GetTextBeforeOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
102 gchar *GetTextAtOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar);
103#if ATK_CHECK_VERSION(2, 10, 0)
104 gchar *GetStringAtOffset(int charOffset, AtkTextGranularity granularity, int *startChar, int *endChar);
105#endif
106 gunichar GetCharacterAtOffset(int charOffset);
107 gint GetCharacterCount();
108 gint GetCaretOffset();
109 gboolean SetCaretOffset(int charOffset);
110 gint GetOffsetAtPoint(gint x, gint y, AtkCoordType coords);
111 void GetCharacterExtents(int charOffset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords);
112 AtkAttributeSet *GetAttributesForStyle(unsigned int styleNum);
113 AtkAttributeSet *GetRunAttributes(int charOffset, int *startChar, int *endChar);
114 AtkAttributeSet *GetDefaultAttributes();
115 gint GetNSelections();
116 gchar *GetSelection(gint selection_num, int *startChar, int *endChar);
117 gboolean AddSelection(int startChar, int endChar);
118 gboolean RemoveSelection(int selection_num);
119 gboolean SetSelection(gint selection_num, int startChar, int endChar);
120 // for AtkEditableText
121 bool InsertStringUTF8(Sci::Position bytePos, const gchar *utf8, Sci::Position lengthBytes);
122 void SetTextContents(const gchar *contents);
123 void InsertText(const gchar *text, int lengthBytes, int *charPosition);
124 void CopyText(int startChar, int endChar);
125 void CutText(int startChar, int endChar);
126 void DeleteText(int startChar, int endChar);
127 void PasteText(int charPosition);
128
129public:
130 ScintillaGTKAccessible(GtkAccessible *accessible_, GtkWidget *widget_);
132
133 static ScintillaGTKAccessible *FromAccessible(GtkAccessible *accessible);
135 return FromAccessible(GTK_ACCESSIBLE(accessible));
136 }
137 // So ScintillaGTK can notify us
138 void ChangeDocument(Document *oldDoc, Document *newDoc);
139 void NotifyReadOnly();
140 void SetAccessibility(bool enabled);
141
142 // Helper GtkWidget methods
143 static AtkObject *WidgetGetAccessibleImpl(GtkWidget *widget, AtkObject **cache, gpointer widget_parent_class);
144
145 // ATK methods
146
148 public:
149 static void init(::AtkTextIface *iface);
150
151 private:
153
154 static gchar *GetText(AtkText *text, int start_offset, int end_offset);
155 static gchar *GetTextAfterOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset);
156 static gchar *GetTextBeforeOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset);
157 static gchar *GetTextAtOffset(AtkText *text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset);
158#if ATK_CHECK_VERSION(2, 10, 0)
159 static gchar *GetStringAtOffset(AtkText *text, gint offset, AtkTextGranularity granularity, gint *start_offset, gint *end_offset);
160#endif
161 static gunichar GetCharacterAtOffset(AtkText *text, gint offset);
162 static gint GetCharacterCount(AtkText *text);
163 static gint GetCaretOffset(AtkText *text);
164 static gboolean SetCaretOffset(AtkText *text, gint offset);
165 static gint GetOffsetAtPoint(AtkText *text, gint x, gint y, AtkCoordType coords);
166 static void GetCharacterExtents(AtkText *text, gint offset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords);
167 static AtkAttributeSet *GetRunAttributes(AtkText *text, gint offset, gint *start_offset, gint *end_offset);
168 static AtkAttributeSet *GetDefaultAttributes(AtkText *text);
169 static gint GetNSelections(AtkText *text);
170 static gchar *GetSelection(AtkText *text, gint selection_num, gint *start_pos, gint *end_pos);
171 static gboolean AddSelection(AtkText *text, gint start, gint end);
172 static gboolean RemoveSelection(AtkText *text, gint selection_num);
173 static gboolean SetSelection(AtkText *text, gint selection_num, gint start, gint end);
174 };
176 public:
177 static void init(::AtkEditableTextIface *iface);
178
179 private:
181
182 static void SetTextContents(AtkEditableText *text, const gchar *contents);
183 static void InsertText(AtkEditableText *text, const gchar *contents, gint length, gint *position);
184 static void CopyText(AtkEditableText *text, gint start, gint end);
185 static void CutText(AtkEditableText *text, gint start, gint end);
186 static void DeleteText(AtkEditableText *text, gint start, gint end);
187 static void PasteText(AtkEditableText *text, gint position);
188 };
189};
190
191}
192
193
194#endif
#define SC_LINECHARACTERINDEX_UTF32
Definition: Scintilla.h:1160
#define INVALID_POSITION
Definition: Scintilla.h:44
char SCI_METHOD StyleAt(Sci_Position position) const override
Definition: Document.h:395
void EnsureStyledTo(Sci::Position pos)
Definition: Document.cxx:2256
Sci_Position SCI_METHOD Length() const override
Definition: Document.h:430
Sci::Position MovePositionOutsideChar(Sci::Position pos, Sci::Position moveDir, bool checkLineEnd=true) const noexcept
Definition: Document.cxx:697
Sci::Position IndexLineStart(Sci::Line line, int lineCharacterIndex) const noexcept
Definition: Document.cxx:471
Sci_Position SCI_METHOD GetRelativePosition(Sci_Position positionStart, Sci_Position characterOffset) const override
Definition: Document.cxx:925
int LineCharacterIndex() const noexcept
Definition: Document.cxx:2171
Sci_Position SCI_METHOD LineFromPosition(Sci_Position pos) const override
Definition: Document.cxx:437
Sci::Line LineFromPositionIndex(Sci::Position pos, int lineCharacterIndex) const noexcept
Definition: Document.cxx:475
Sci_Position SCI_METHOD LineStart(Sci_Position line) const override
Definition: Document.cxx:395
Sci::Position CountCharacters(Sci::Position startPos, Sci::Position endPos) const noexcept
Definition: Document.cxx:1565
Document * pdoc
Definition: EditModel.h:53
static void CopyText(AtkEditableText *text, gint start, gint end)
static void DeleteText(AtkEditableText *text, gint start, gint end)
static void SetTextContents(AtkEditableText *text, const gchar *contents)
static void PasteText(AtkEditableText *text, gint position)
static void CutText(AtkEditableText *text, gint start, gint end)
static void InsertText(AtkEditableText *text, const gchar *contents, gint length, gint *position)
static AtkAttributeSet * GetRunAttributes(AtkText *text, gint offset, gint *start_offset, gint *end_offset)
static gboolean AddSelection(AtkText *text, gint start, gint end)
static gchar * GetTextAtOffset(AtkText *text, gint offset, AtkTextBoundary boundary_type, gint *start_offset, gint *end_offset)
static void GetCharacterExtents(AtkText *text, gint offset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords)
static gunichar GetCharacterAtOffset(AtkText *text, gint offset)
static gint GetOffsetAtPoint(AtkText *text, gint x, gint y, AtkCoordType coords)
static gboolean SetSelection(AtkText *text, gint selection_num, gint start, gint end)
static gboolean SetCaretOffset(AtkText *text, gint offset)
static AtkAttributeSet * GetDefaultAttributes(AtkText *text)
static gchar * GetTextBeforeOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset)
static gboolean RemoveSelection(AtkText *text, gint selection_num)
static gchar * GetSelection(AtkText *text, gint selection_num, gint *start_pos, gint *end_pos)
static gchar * GetTextAfterOffset(AtkText *text, int offset, AtkTextBoundary boundary_type, int *start_offset, int *end_offset)
static gchar * GetText(AtkText *text, int start_offset, int end_offset)
gchar * GetSelection(gint selection_num, int *startChar, int *endChar)
gchar * GetTextAfterOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar)
void ChangeDocument(Document *oldDoc, Document *newDoc)
bool InsertStringUTF8(Sci::Position bytePos, const gchar *utf8, Sci::Position lengthBytes)
gchar * GetTextBeforeOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar)
void InsertText(const gchar *text, int lengthBytes, int *charPosition)
gchar * GetTextRangeUTF8(Sci::Position startByte, Sci::Position endByte)
Sci::Position ByteOffsetFromCharacterOffset(Sci::Position startByte, int characterOffset)
AtkAttributeSet * GetRunAttributes(int charOffset, int *startChar, int *endChar)
void Notify(GtkWidget *widget, gint code, SCNotification *nt)
void SetTextContents(const gchar *contents)
static ScintillaGTKAccessible * FromAccessible(GtkAccessible *accessible)
void CutText(int startChar, int endChar)
void CharacterRangeFromByteRange(Sci::Position startByte, Sci::Position endByte, int *startChar, int *endChar)
gboolean AddSelection(int startChar, int endChar)
static AtkObject * WidgetGetAccessibleImpl(GtkWidget *widget, AtkObject **cache, gpointer widget_parent_class)
static void SciNotify(GtkWidget *widget, gint code, SCNotification *nt, gpointer data)
std::vector< SelectionRange > old_sels
static ScintillaGTKAccessible * FromAccessible(AtkObject *accessible)
ScintillaGTKAccessible(GtkAccessible *accessible_, GtkWidget *widget_)
gchar * GetTextAtOffset(int charOffset, AtkTextBoundary boundaryType, int *startChar, int *endChar)
gint GetOffsetAtPoint(gint x, gint y, AtkCoordType coords)
Sci::Position ByteOffsetFromCharacterOffset(Sci::Position characterOffset)
AtkAttributeSet * GetAttributesForStyle(unsigned int styleNum)
void DeleteText(int startChar, int endChar)
gboolean SetSelection(gint selection_num, int startChar, int endChar)
void CopyText(int startChar, int endChar)
Sci::Position PositionBefore(Sci::Position pos)
int StyleAt(Sci::Position position, bool ensureStyle=false)
void GetCharacterExtents(int charOffset, gint *x, gint *y, gint *width, gint *height, AtkCoordType coords)
void ByteRangeFromCharacterRange(int startChar, int endChar, Sci::Position &startByte, Sci::Position &endByte)
gboolean RemoveSelection(int selection_num)
Sci::Position CharacterOffsetFromByteOffset(Sci::Position byteOffset)
gunichar GetCharacterAtOffset(int charOffset)
Sci::Position PositionAfter(Sci::Position pos)
gchar * GetText(int startChar, int endChar)
gchar * text
Definition: editor.c:83
gint pos
Definition: editor.c:87
vString * line
Definition: geany_cobol.c:133
ptrdiff_t Position
Definition: Position.h:19
ptrdiff_t Line
Definition: Position.h:20
Styling buffer using one element for each run rather than using a filled buffer.
Definition: Converter.h:9
gint position[2]
Definition: search.c:120