Debian Codegraph @

atk/src/text.hg

raw
1 /* $Id: text.hg,v 1.7 2005/01/05 18:21:30 murrayc Exp $ */
2
3 /* Copyright (C) 2002 The gtkmm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
17 */
18
19 _DEFS(atkmm,atk)
20
21 #include <atkmm/component.h> /* for Atk::CoordType */
22 #include <glibmm/slisthandle.h>
23 #include <atk/atktext.h>
24
25
26 namespace Atk
27 {
28
29 class ATKMM_API Attribute
30 {
31 _CLASS_GENERIC(Attribute, AtkAttribute)
32
33 public:
34 Attribute();
35 Attribute(const Glib::ustring& name, const Glib::ustring& value);
36 explicit Attribute(const AtkAttribute* gobject);
37 ~Attribute();
38
39 Attribute(const Attribute& other);
40 Attribute& operator=(const Attribute& other);
41
42 void swap(Attribute& other);
43
44 _MEMBER_GET(name, name, Glib::ustring, const char*)
45 _MEMBER_GET(value, value, Glib::ustring, const char*)
46
47 /// Provides access to the underlying C GObject.
48 AtkAttribute* gobj() { return &gobject_; }
49
50 /// Provides access to the underlying C GObject.
51 const AtkAttribute* gobj() const { return &gobject_; }
52
53 protected:
54 AtkAttribute gobject_;
55 };
56
57 /** @relates Atk::Attribute */
58 inline void swap(Attribute& lhs, Attribute& rhs)
59 { lhs.swap(rhs); }
60
61 struct AttributeTraits
62 {
63 typedef Atk::Attribute CppType;
64 typedef const AtkAttribute* CType;
65 typedef AtkAttribute* CTypeNonConst;
66
67 static CType to_c_type(CType item) { return item; }
68 static CType to_c_type(const CppType& item) { return item.gobj(); }
69 static CppType to_cpp_type(CType item) { return CppType(item); }
70 static void release_c_type(CType item) { g_free(const_cast<CTypeNonConst>(item)); }
71 };
72
73 typedef Glib::SListHandle<Attribute, AttributeTraits> AttributeSet;
74
75
76 _CC_INCLUDE(atk/atk-enum-types.h)
77 _WRAP_ENUM(BuiltinTextAttribute, AtkTextAttribute, decl_prefix ATKMM_API)
78
79 class ATKMM_API TextAttribute
80 {
81 private:
82 int attribute_;
83
84 public:
85 TextAttribute() : attribute_ (0) {}
86 TextAttribute(BuiltinTextAttribute attribute) : attribute_ (attribute) {}
87
88 // Behave like an ordinary enum.
89 explicit TextAttribute(int attribute) : attribute_ (attribute) {}
90 operator int() const { return attribute_; }
91
92 static TextAttribute for_name(const Glib::ustring& name);
93 static Glib::ustring get_name(TextAttribute attribute);
94 static Glib::ustring get_value(TextAttribute attribute, int index);
95 };
96
97 } // namespace Atk
98
99 #ifndef DOXYGEN_SHOULD_SKIP_THIS
100 namespace Glib
101 {
102
103 template <>
104 class ATKMM_API Value<Atk::TextAttribute> : public Glib::Value_Enum<Atk::TextAttribute>
105 {
106 public:
107 static GType value_type() G_GNUC_CONST;
108 };
109
110 } // namespace Glib
111 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
112
113 namespace Atk
114 {
115
116 _WRAP_ENUM(TextBoundary, AtkTextBoundary, decl_prefix ATKMM_API)
117 _WRAP_ENUM(TextClipType, AtkTextClipType, decl_prefix ATKMM_API)
118 _WRAP_ENUM(TextGranularity, AtkTextGranularity, decl_prefix ATKMM_API)
119
120 /** The ATK interface implemented by components with text content.
121 * This should be implemented by Atk::Objects on behalf of widgets that have text content which is either attributed
122 * or otherwise non-trivial. Atk::Objects whose text content is simple, unattributed, and very brief may expose that
123 * content via Atk::Object::get_name() instead; however if the text is editable, multi-line, typically longer than
124 * three or four words, attributed, selectable, or if the object already uses the 'name' ATK property for other
125 * information, this Text interface should be used to expose the text content. In the case of editable text content,
126 * Atk::EditableText (a subtype of the Atk::Text interface) should be implemented instead.
127 *
128 * Atk::Text provides not only traversal facilities and change notification for text content, but also caret tracking
129 * and glyph bounding box calculations. Note that the text strings are exposed as UTF-8, and are therefore potentially
130 * multi-byte, and caret-to-byte offset mapping makes no assumptions about the character length; also bounding box
131 * glyph-to-offset mapping may be complex for languages which use ligatures.
132 */
133 class ATKMM_API Text : public Glib::Interface
134 {
135 _CLASS_INTERFACE(Text, AtkText, ATK_TEXT, AtkTextIface, , , ATKMM_API)
136
137 public:
138 _WRAP_METHOD(Glib::ustring get_text(int start_offset, int end_offset) const, atk_text_get_text)
139 _WRAP_METHOD(gunichar get_character_at_offset(int offset) const, atk_text_get_character_at_offset)
140 _WRAP_METHOD(Glib::ustring get_text_after_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, atk_text_get_text_after_offset, deprecated "Use get_string_at_offset() instead.")
141 _WRAP_METHOD(Glib::ustring get_text_at_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, atk_text_get_text_at_offset, deprecated "Use get_string_at_offset() instead.")
142 _WRAP_METHOD(Glib::ustring get_text_before_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, atk_text_get_text_before_offset, deprecated "Use get_string_at_offset() instead.")
143
144 _WRAP_METHOD(Glib::ustring get_string_at_offset(int offset, TextGranularity granularity, int& start_offset, int& end_offset), atk_text_get_string_at_offset)
145
146 _WRAP_METHOD(int get_caret_offset() const, atk_text_get_caret_offset)
147 _WRAP_METHOD(void get_character_extents(int offset, int& x, int& y, int& width, int& height, CoordType coords) const, atk_text_get_character_extents)
148 _WRAP_METHOD(AttributeSet get_run_attributes(int offset, int& start_offset, int& end_offset) const, atk_text_get_run_attributes)
149 _WRAP_METHOD(AttributeSet get_default_attributes() const, atk_text_get_default_attributes)
150 _WRAP_METHOD(int get_character_count() const, atk_text_get_character_count)
151 _WRAP_METHOD(int get_offset_at_point(int x, int y, CoordType coords) const, atk_text_get_offset_at_point)
152 _WRAP_METHOD(int get_n_selections() const, atk_text_get_n_selections)
153 _WRAP_METHOD(Glib::ustring get_selection(int selection_num, int& start_offset, int& end_offset) const, atk_text_get_selection)
154 _WRAP_METHOD(bool add_selection(int start_offset, int end_offset), atk_text_add_selection)
155 _WRAP_METHOD(bool remove_selection(int selection_num), atk_text_remove_selection)
156 _WRAP_METHOD(bool set_selection(int selection_num, int start_offset, int end_offset), atk_text_set_selection)
157 _WRAP_METHOD(bool set_caret_offset(int offset), atk_text_set_caret_offset)
158
159 typedef AtkTextRectangle Rectangle;
160
161 _WRAP_METHOD(void get_range_extents(int start_offset, int end_offset,
162 CoordType coord_type,
163 Rectangle& rect), atk_text_get_range_extents)
164 _WRAP_METHOD(AtkTextRange** get_bounded_ranges(const Rectangle& rect, CoordType coord_type,
165 TextClipType x_clip_type, TextClipType y_clip_type), atk_text_get_bounded_ranges)
166
167
168 _WRAP_SIGNAL(void text_changed(int position, int length), "text_changed")
169 _WRAP_SIGNAL(void text_caret_moved(int location), "text_caret_moved")
170 _WRAP_SIGNAL(void text_selection_changed(), "text_selection_changed")
171 _WRAP_SIGNAL(void text_attributes_changed(), "text_attributes_changed")
172
173 protected:
174 #m4 _CONVERSION(`Glib::ustring', `gchar*', `g_strdup(($3).c_str())')
175 #m4 _CONVERSION(`gchar*', `Glib::ustring', `Glib::convert_return_gchar_ptr_to_ustring($3)')
176 _WRAP_VFUNC(Glib::ustring get_text(int start_offset, int end_offset) const, get_text)
177 _WRAP_VFUNC(gunichar get_character_at_offset(int offset) const, get_character_at_offset)
178
179 /** @deprecated This virtual function is deprecated and it should not be overridden.
180 */
181 _WRAP_VFUNC(Glib::ustring get_text_after_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, get_text_after_offset)
182
183 _WRAP_VFUNC(Glib::ustring get_text_at_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, get_text_at_offset)
184
185 /** @deprecated This virtual function is deprecated and it should not be overridden.
186 */
187 _WRAP_VFUNC(Glib::ustring get_text_before_offset(int offset, TextBoundary boundary_type, int& start_offset, int& end_offset) const, get_text_before_offset)
188
189 _WRAP_VFUNC(int get_caret_offset() const, get_caret_offset)
190 _WRAP_VFUNC(void get_character_extents(int offset, int& x, int& y, int& width, int& height, CoordType coords) const, get_character_extents)
191 _WRAP_VFUNC(AtkAttributeSet* get_run_attributes(int offset, int& start_offset, int& end_offset) const, get_run_attributes)
192 _WRAP_VFUNC(AtkAttributeSet* get_default_attributes() const, get_default_attributes)
193 _WRAP_VFUNC(int get_character_count() const, get_character_count)
194 _WRAP_VFUNC(int get_offset_at_point(int x, int y, CoordType coords) const, get_offset_at_point)
195 _WRAP_VFUNC(int get_n_selections() const, get_n_selections)
196 _WRAP_VFUNC(Glib::ustring get_selection(int selection_num, int& start_offset, int& end_offset) const, get_selection)
197 _WRAP_VFUNC(bool add_selection(int start_offset, int end_offset), add_selection)
198 _WRAP_VFUNC(bool remove_selection(int selection_num), remove_selection)
199 _WRAP_VFUNC(bool set_selection(int selection_num, int start_offset, int end_offset), set_selection)
200 _WRAP_VFUNC(bool set_caret_offset(int offset), set_caret_offset)
201
202 //TODO: Add get_range_extents(), and get_bounded_ranges() vfuncs when we can break ABI.
203 };
204
205 } // namespace Atk