~ubuntu-branches/ubuntu/precise/gtkmm3.0/precise

« back to all changes in this revision

Viewing changes to gtk/src/textbuffer.ccg

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2011-06-17 00:12:44 UTC
  • Revision ID: james.westby@ubuntu.com-20110617001244-9hl5an15hiaaahi6
Tags: upstream-3.0.1
ImportĀ upstreamĀ versionĀ 3.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
/* $Id: textbuffer.ccg,v 1.8 2006/11/20 09:19:49 murrayc Exp $ */
 
3
 
 
4
/* Copyright(C) 1998-2002 The gtkmm Development Team
 
5
 *
 
6
 * This library is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Lesser General Public
 
8
 * License as published by the Free Software Foundation; either
 
9
 * version 2.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * Lesser General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU Lesser General Public
 
17
 * License along with this library; if not, write to the Free
 
18
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
 */
 
20
 
 
21
#include <glibmm/vectorutils.h>
 
22
 
 
23
#include <gtk/gtk.h>
 
24
#include <glib.h>
 
25
#include <gtkmm/textmark.h>
 
26
#include <gtkmm/textiter.h>
 
27
 
 
28
 
 
29
/*
 
30
static guint8* SignalProxy_Serialize(GtkTextBuffer* , GtkTextBuffer* content_buffer,
 
31
                                                   const GtkTextIter* start, const GtkTextIter* end,
 
32
                                                   gsize* length,
 
33
                                                   gpointer user_data)
 
34
{
 
35
  Gtk::TextBuffer::SlotSerialize* the_slot = static_cast<Gtk::TextBuffer::SlotSerialize*>(user_data);
 
36
 
 
37
  try
 
38
  {
 
39
    return (*the_slot)(Glib::wrap(content_buffer), Glib::wrap(start), Glib::wrap(end), *length);
 
40
  }
 
41
  catch(...)
 
42
  {
 
43
    Glib::exception_handlers_invoke();
 
44
  }
 
45
 
 
46
  return 0; // arbitrary value
 
47
}
 
48
 
 
49
static void SignalProxy_Serialize_gtk_callback_destroy(void* user_data)
 
50
{
 
51
  delete static_cast<Gtk::TextBuffer::SlotSerialize*>(user_data);
 
52
}
 
53
 
 
54
static gboolean SignalProxy_Deserialize(GtkTextBuffer* , GtkTextBuffer* content_buffer,
 
55
                                                   GtkTextIter* iter, const guint8* data,
 
56
                                                   gsize length, gboolean create_tags,
 
57
                                                   gpointer user_data,
 
58
                                                   GError** )
 
59
{
 
60
  Gtk::TextBuffer::SlotDeserialize* the_slot = static_cast<Gtk::TextBuffer::SlotDeserialize*>(user_data);
 
61
 
 
62
  try
 
63
  {
 
64
    (*the_slot)(Glib::wrap(content_buffer, true), Glib::wrap(iter), data, length, create_tags);
 
65
 
 
66
  }
 
67
  catch(...)
 
68
  {
 
69
    //TODO: Fill the error parameter.
 
70
    Glib::exception_handlers_invoke();
 
71
  }
 
72
 
 
73
  return 0; // arbitrary value
 
74
}
 
75
 
 
76
static void SignalProxy_Deserialize_gtk_callback_destroy(void* user_data)
 
77
{
 
78
  delete static_cast<Gtk::TextBuffer::SlotDeserialize*>(user_data);
 
79
}
 
80
*/
 
81
 
 
82
namespace Gtk
 
83
{
 
84
 
 
85
typedef TextChildAnchor ChildAnchor; //Help the code-generator so that it does not have to fully qualify this type in the .cc file.
 
86
 
 
87
TextBuffer::TextBuffer(const Glib::RefPtr<TagTable>& tag_table)
 
88
:
 
89
  _CONSTRUCT("tag_table", Glib::unwrap(tag_table))
 
90
{}
 
91
 
 
92
Glib::RefPtr<TextBuffer::Tag> TextBuffer::create_tag(const Glib::ustring& tag_name)
 
93
{
 
94
  //gtk_text_buffer_create_tag takes a varargs list of property names and values.
 
95
  //gtkmm coders should use the Tag.set_* method instead.
 
96
  return Glib::wrap(gtk_text_buffer_create_tag(gobj(), tag_name.c_str(), (char*)0), true); //true = take_copy.
 
97
  //We have to take a copy because gtk_text_buffer_create_tag() doesn't ref for us, for no real reason.
 
98
}
 
99
 
 
100
Glib::RefPtr<TextBuffer::Tag> TextBuffer::create_tag()
 
101
{
 
102
  //gtk_text_buffer_create_tag takes a varargs list of property names and values.
 
103
  //gtkmm coders should use the Tag.set_* method instead.
 
104
  return Glib::wrap(gtk_text_buffer_create_tag(gobj(), (const char*)0, (char*)0), true); //true = take_copy.
 
105
  //We have to take a copy because gtk_text_buffer_create_tag() doesn't ref for us, for no real reason.
 
106
}
 
107
 
 
108
Glib::RefPtr<TextBuffer::Mark>
 
109
TextBuffer::create_mark(const TextBuffer::iterator& where, bool left_gravity)
 
110
{
 
111
  return Glib::wrap(gtk_text_buffer_create_mark(
 
112
      gobj(), 0, const_cast<GtkTextIter*>(where.gobj()), left_gravity),
 
113
      true); // acquire reference
 
114
}
 
115
 
 
116
TextBuffer::iterator TextBuffer::get_iter_at_line_offset(int line_number, int char_offset)
 
117
{
 
118
  iterator iter;
 
119
  gtk_text_buffer_get_iter_at_line_offset(gobj(), iter.gobj(), line_number, char_offset);
 
120
  return iter;
 
121
}
 
122
 
 
123
TextBuffer::iterator TextBuffer::get_iter_at_line_index(int line_number, int byte_index)
 
124
{
 
125
  iterator iter;
 
126
  gtk_text_buffer_get_iter_at_line_index(gobj(), iter.gobj(), line_number, byte_index);
 
127
  return iter;
 
128
}
 
129
 
 
130
TextBuffer::iterator TextBuffer::get_iter_at_offset(int char_offset)
 
131
{
 
132
  iterator iter;
 
133
  gtk_text_buffer_get_iter_at_offset(gobj(), iter.gobj(), char_offset);
 
134
  return iter;
 
135
}
 
136
 
 
137
TextBuffer::iterator TextBuffer::get_iter_at_line(int line_number)
 
138
{
 
139
  iterator iter;
 
140
  gtk_text_buffer_get_iter_at_line(gobj(), iter.gobj(), line_number);
 
141
  return iter;
 
142
}
 
143
 
 
144
TextBuffer::iterator TextBuffer::begin()
 
145
{
 
146
  iterator iter;
 
147
  gtk_text_buffer_get_start_iter(gobj(), iter.gobj());
 
148
  return iter;
 
149
}
 
150
 
 
151
TextBuffer::iterator TextBuffer::end()
 
152
{
 
153
  iterator iter;
 
154
  gtk_text_buffer_get_end_iter(gobj(), iter.gobj());
 
155
  return iter;
 
156
}
 
157
 
 
158
void TextBuffer::get_bounds(iterator& range_begin, iterator& range_end)
 
159
{
 
160
  gtk_text_buffer_get_bounds(gobj(), range_begin.gobj(), range_end.gobj());
 
161
}
 
162
 
 
163
TextBuffer::iterator TextBuffer::get_iter_at_mark(const Glib::RefPtr<Mark>& mark)
 
164
{
 
165
  iterator iter;
 
166
  gtk_text_buffer_get_iter_at_mark(gobj(), iter.gobj(), mark->gobj());
 
167
  return iter;
 
168
}
 
169
 
 
170
void TextBuffer::set_text(const Glib::ustring& text)
 
171
{
 
172
  gtk_text_buffer_set_text(gobj(), text.data(), text.bytes());
 
173
}
 
174
 
 
175
void TextBuffer::set_text(const char* text_begin, const char* text_end)
 
176
{
 
177
  gtk_text_buffer_set_text(gobj(), text_begin, text_end - text_begin);
 
178
}
 
179
 
 
180
TextBuffer::iterator TextBuffer::insert(const iterator& pos, const Glib::ustring& text)
 
181
{
 
182
  // gtk_text_buffer_insert() modifies the iterator, but that's not the
 
183
  // STL way so we give it something that we don't mind it modifying.
 
184
  iterator iterCopy (pos);
 
185
  gtk_text_buffer_insert(gobj(), iterCopy.gobj(), text.data(), text.bytes());
 
186
 
 
187
  // According to the gtk_text_buffer_insert() docs, the "default signal handler
 
188
  // revalidates it to point to the end of the inserted text".
 
189
  return iterCopy;
 
190
}
 
191
 
 
192
TextBuffer::iterator TextBuffer::insert(const iterator& pos, const char* text_begin, const char* text_end)
 
193
{
 
194
  // gtk_text_buffer_insert() modifies the iterator, but that's not the
 
195
  // STL way so we give it something that we don't mind it modifying.
 
196
  iterator iterCopy (pos);
 
197
  gtk_text_buffer_insert(gobj(), iterCopy.gobj(), text_begin, text_end - text_begin);
 
198
 
 
199
  // According to the gtk_text_buffer_insert() docs, the "default signal handler
 
200
  // revalidates it to point to the end of the inserted text".
 
201
  return iterCopy;
 
202
}
 
203
 
 
204
TextBuffer::iterator TextBuffer::insert_pixbuf(const iterator& pos, const Glib::RefPtr<Gdk::Pixbuf>& pixbuf)
 
205
{
 
206
  iterator iterCopy (pos);
 
207
  gtk_text_buffer_insert_pixbuf(gobj(), iterCopy.gobj(), pixbuf->gobj());
 
208
  return iterCopy;
 
209
}
 
210
 
 
211
TextBuffer::iterator TextBuffer::insert_child_anchor(const iterator& pos,
 
212
                                                     const Glib::RefPtr<ChildAnchor>& anchor)
 
213
{
 
214
  // Copy the iterator. It might be changed because it is used as a signal parameter internally.
 
215
  iterator iterCopy (pos);
 
216
  gtk_text_buffer_insert_child_anchor(gobj(), iterCopy.gobj(), Glib::unwrap(anchor));
 
217
  return iterCopy;
 
218
}
 
219
 
 
220
Glib::RefPtr<ChildAnchor> TextBuffer::create_child_anchor(const iterator& pos)
 
221
{
 
222
  // Copy the iterator. It might be changed because it is used as a signal parameter internally.
 
223
  iterator iterCopy (pos);
 
224
  return Glib::wrap(gtk_text_buffer_create_child_anchor(gobj(), iterCopy.gobj()),
 
225
                    true); // The function does not do a ref for us.
 
226
}
 
227
 
 
228
void TextBuffer::insert_at_cursor(const Glib::ustring& text)
 
229
{
 
230
  gtk_text_buffer_insert_at_cursor(gobj(), text.data(), text.bytes());
 
231
}
 
232
 
 
233
void TextBuffer::insert_at_cursor(const char* text_begin, const char* text_end)
 
234
{
 
235
  gtk_text_buffer_insert_at_cursor(gobj(), text_begin, text_end - text_begin);
 
236
}
 
237
 
 
238
std::pair<TextBuffer::iterator,bool>
 
239
TextBuffer::insert_interactive(const iterator& pos, const Glib::ustring& text, bool default_editable)
 
240
{
 
241
  // Since we have to copy the iterator anyway we can as well create the
 
242
  // std::pair now.  That saves another copy later (mind you, TextIter is
 
243
  // a heavy struct), and allows modern compilers to apply the return value
 
244
  // optimization.
 
245
  std::pair<iterator,bool> pair_iter_success (pos, false);
 
246
 
 
247
  pair_iter_success.second = gtk_text_buffer_insert_interactive(
 
248
      gobj(), pair_iter_success.first.gobj(), text.data(), text.bytes(), default_editable);
 
249
 
 
250
  return pair_iter_success;
 
251
}
 
252
 
 
253
std::pair<TextBuffer::iterator,bool>
 
254
TextBuffer::insert_interactive(const iterator& pos, const char* text_begin, const char* text_end,
 
255
                               bool default_editable)
 
256
{
 
257
  // Since we have to copy the iterator anyway we can as well create the
 
258
  // std::pair now.  That saves another copy later (mind you, TextIter is
 
259
  // a heavy struct), and allows modern compilers to apply the return value
 
260
  // optimization.
 
261
  std::pair<iterator,bool> pair_iter_success (pos, false);
 
262
 
 
263
  pair_iter_success.second =  gtk_text_buffer_insert_interactive(
 
264
      gobj(), pair_iter_success.first.gobj(), text_begin, text_end - text_begin, default_editable);
 
265
 
 
266
  return pair_iter_success;
 
267
}
 
268
 
 
269
bool TextBuffer::insert_interactive_at_cursor(const Glib::ustring& text, bool default_editable)
 
270
{
 
271
  return gtk_text_buffer_insert_interactive_at_cursor(
 
272
      gobj(), text.data(), text.bytes(), default_editable);
 
273
}
 
274
 
 
275
bool TextBuffer::insert_interactive_at_cursor(const char* text_begin, const char* text_end,
 
276
                                              bool default_editable)
 
277
{
 
278
  return gtk_text_buffer_insert_interactive_at_cursor(
 
279
      gobj(), text_begin, text_end - text_begin, default_editable);
 
280
}
 
281
 
 
282
TextBuffer::iterator TextBuffer::insert_with_tag(const iterator& pos, const Glib::ustring& text,
 
283
                                                 const Glib::RefPtr<Tag>& tag)
 
284
{
 
285
  // gtk_text_buffer_insert_with_tags() invalidates the iterator, but this lets us recreate it later.
 
286
  const int offset = pos.get_offset();
 
287
 
 
288
  iterator iterCopy (pos);
 
289
  gtk_text_buffer_insert_with_tags(
 
290
      gobj(), iterCopy.gobj(), text.data(), text.bytes(), tag->gobj(), (GtkTextTag*)0);
 
291
 
 
292
  return get_iter_at_offset(offset + text.size());
 
293
}
 
294
 
 
295
TextBuffer::iterator TextBuffer::insert_with_tag(const iterator& pos,
 
296
                                                 const char* text_begin, const char* text_end,
 
297
                                                 const Glib::RefPtr<Tag>& tag)
 
298
{
 
299
  // gtk_text_buffer_insert_with_tags() invalidates the iterator, but this lets us recreate it later.
 
300
  const int offset = pos.get_offset();
 
301
 
 
302
  iterator iterCopy (pos);
 
303
  gtk_text_buffer_insert_with_tags(
 
304
      gobj(), iterCopy.gobj(), text_begin, text_end - text_begin, tag->gobj(), (GtkTextTag*)0);
 
305
 
 
306
  return get_iter_at_offset(offset + (text_end - text_begin));
 
307
}
 
308
 
 
309
TextBuffer::iterator TextBuffer::insert_with_tag(const iterator& pos, const Glib::ustring& text,
 
310
                                                 const Glib::ustring& tag_name)
 
311
{
 
312
  // gtk_text_buffer_insert_with_tags() invalidates the iterator, but this lets us recreate it later.
 
313
  const int offset = pos.get_offset();
 
314
 
 
315
  iterator iterCopy (pos);
 
316
  gtk_text_buffer_insert_with_tags_by_name(
 
317
      gobj(), iterCopy.gobj(), text.data(), text.bytes(), tag_name.c_str(), (char*)0);
 
318
 
 
319
  return get_iter_at_offset(offset + text.size());
 
320
}
 
321
 
 
322
TextBuffer::iterator TextBuffer::insert_with_tag(const iterator& pos,
 
323
                                                 const char* text_begin, const char* text_end,
 
324
                                                 const Glib::ustring& tag_name)
 
325
{
 
326
  // gtk_text_buffer_insert_with_tags() invalidates the iterator, but this lets us recreate it later.
 
327
  const int offset = pos.get_offset();
 
328
 
 
329
  iterator iterCopy (pos);
 
330
  gtk_text_buffer_insert_with_tags_by_name(
 
331
      gobj(), iterCopy.gobj(), text_begin, text_end - text_begin, tag_name.c_str(), (char*)0);
 
332
 
 
333
  return get_iter_at_offset(offset + (text_end - text_begin));
 
334
}
 
335
 
 
336
TextBuffer::iterator TextBuffer::insert_with_tags(const iterator& pos, const Glib::ustring& text,
 
337
                                                  const std::vector< Glib::RefPtr<Tag> >& tags)
 
338
{
 
339
  const char *const text_begin = text.data();
 
340
  return insert_with_tags(pos, text_begin, text_begin + text.bytes(), tags);
 
341
}
 
342
 
 
343
TextBuffer::iterator TextBuffer::insert_with_tags(const iterator& pos,
 
344
                                                  const char* text_begin, const char* text_end,
 
345
                                                  const std::vector< Glib::RefPtr<Tag> >& tags)
 
346
{
 
347
  const int start_offset = pos.get_offset();
 
348
  iterator range_end (insert(pos, text_begin, text_end));
 
349
 
 
350
  GtkTextIter range_begin;
 
351
  gtk_text_buffer_get_iter_at_offset(gobj(), &range_begin, start_offset);
 
352
 
 
353
  Glib::ArrayHandler<Glib::RefPtr<Tag> >::ArrayKeeperType array_keeper (Glib::ArrayHandler<Glib::RefPtr<Tag> >::vector_to_array(tags));
 
354
 
 
355
  //This was GtkTextTag* const * const, but the SUN Forte compiler said that it couldn't convert to that. murrayc
 
356
  const GtkTextTag* const* tags_begin = array_keeper.data();
 
357
  const GtkTextTag* const* tags_end   = tags_begin + tags.size();
 
358
 
 
359
  //TODO: Investigate if this const_cast<> is really necessary.
 
360
  //I added it for the SUN Forte compiler. murrayc.
 
361
  for(GtkTextTag *const * ptag = const_cast<GtkTextTag* const *>(tags_begin); ptag != const_cast<GtkTextTag* const *>(tags_end); ++ptag)
 
362
  {
 
363
    gtk_text_buffer_apply_tag(gobj(), *ptag, &range_begin, range_end.gobj());
 
364
  }
 
365
 
 
366
  return range_end;
 
367
}
 
368
 
 
369
TextBuffer::iterator TextBuffer::insert_with_tags_by_name(const iterator& pos, const Glib::ustring& text,
 
370
                                                          const std::vector<Glib::ustring>& tag_names)
 
371
{
 
372
  const char *const text_begin = text.data();
 
373
  return insert_with_tags_by_name(pos, text_begin, text_begin + text.bytes(), tag_names);
 
374
}
 
375
 
 
376
TextBuffer::iterator TextBuffer::insert_with_tags_by_name(const iterator& pos,
 
377
                                                          const char* text_begin, const char* text_end,
 
378
                                                          const std::vector<Glib::ustring>& tag_names)
 
379
{
 
380
  // gtk_buffer_insert_with_tags_by_name() is a convenience wrapper, so it's kind of OK to reimplement it:
 
381
 
 
382
  const int start_offset = pos.get_offset();
 
383
  iterator range_end (insert(pos, text_begin, text_end));
 
384
 
 
385
  GtkTextIter range_begin;
 
386
  gtk_text_buffer_get_iter_at_offset(gobj(), &range_begin, start_offset);
 
387
 
 
388
  GtkTextTagTable *const tag_table = gtk_text_buffer_get_tag_table(gobj());
 
389
  Glib::ArrayHandler<Glib::ustring>::ArrayKeeperType array_keeper (Glib::ArrayHandler<Glib::ustring>::vector_to_array(tag_names));
 
390
 
 
391
  const char *const *const names_begin = array_keeper.data();
 
392
  const char *const *const names_end   = names_begin + tag_names.size();
 
393
 
 
394
  for(const char *const * pname = names_begin; pname != names_end; ++pname)
 
395
  {
 
396
    if(GtkTextTag *const tag = gtk_text_tag_table_lookup(tag_table, *pname))
 
397
    {
 
398
      gtk_text_buffer_apply_tag(gobj(), tag, &range_begin, range_end.gobj());
 
399
    }
 
400
    else
 
401
    {
 
402
      g_warning("Gtk::TextBuffer::insert_with_tags_by_name(): no tag with name '%s'!", *pname);
 
403
    }
 
404
  }
 
405
 
 
406
  return range_end;
 
407
}
 
408
 
 
409
TextBuffer::iterator TextBuffer::insert(const iterator& pos,
 
410
                                        const iterator& range_begin, const iterator& range_end)
 
411
{
 
412
  iterator iterCopy (pos);
 
413
  gtk_text_buffer_insert_range(gobj(), iterCopy.gobj(), range_begin.gobj(), range_end.gobj());
 
414
  return iterCopy;
 
415
}
 
416
 
 
417
std::pair<TextBuffer::iterator,bool>
 
418
TextBuffer::insert_interactive(const iterator& pos, const iterator& range_begin,
 
419
                               const iterator& range_end, bool default_editable)
 
420
{
 
421
  // Since we have to copy the iterator anyway we can as well create the
 
422
  // std::pair now.  That saves another copy later (mind you, TextIter is
 
423
  // a heavy struct), and allows modern compilers to apply the return value
 
424
  // optimization.
 
425
  std::pair<iterator,bool> pair_iter_success (pos, false);
 
426
 
 
427
  pair_iter_success.second = gtk_text_buffer_insert_range_interactive(
 
428
      gobj(), pair_iter_success.first.gobj(), range_begin.gobj(), range_end.gobj(), default_editable);
 
429
 
 
430
  return pair_iter_success;
 
431
}
 
432
 
 
433
TextBuffer::iterator TextBuffer::erase(const iterator& range_begin, const iterator& range_end)
 
434
{
 
435
  // GTK+ sets the iterators to where the deletion occured. We do it the STL way and therefore need copies.
 
436
  iterator beginCopy (range_begin);
 
437
  iterator endCopy   (range_end);
 
438
  gtk_text_buffer_delete(gobj(), beginCopy.gobj(), endCopy.gobj());
 
439
  return beginCopy;
 
440
}
 
441
 
 
442
TextBuffer::iterator TextBuffer::backspace(const iterator& iter, bool interactive, bool default_editable)
 
443
{
 
444
  // GTK+ sets the iterators to where the deletion occured. We do it the STL way and therefore need copies.
 
445
  iterator copy(iter);
 
446
  gtk_text_buffer_backspace(gobj(), copy.gobj(), interactive, default_editable);
 
447
  return copy;
 
448
}
 
449
 
 
450
_IGNORE(gtk_text_buffer_backspace)
 
451
 
 
452
std::pair<TextBuffer::iterator,bool>
 
453
TextBuffer::erase_interactive(const iterator& range_begin, const iterator& range_end,
 
454
                              bool default_editable)
 
455
{
 
456
  // Since we have to copy the iterator anyway we can as well create the
 
457
  // std::pair now.  That saves another copy later (mind you, TextIter is
 
458
  // a heavy struct), and allows modern compilers to apply the return value
 
459
  // optimization.
 
460
  std::pair<iterator,bool> pair_iter_success (range_begin, false);
 
461
 
 
462
  // GTK+ sets the iterators to where the deletion occured.
 
463
  // We do it the STL way and therefore need copies.
 
464
  iterator endCopy (range_end);
 
465
 
 
466
  pair_iter_success.second = gtk_text_buffer_delete_interactive(
 
467
      gobj(), pair_iter_success.first.gobj(), endCopy.gobj(), default_editable);
 
468
 
 
469
  return pair_iter_success;
 
470
}
 
471
 
 
472
void TextBuffer::paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, const iterator& override_location,
 
473
                                 bool default_editable)
 
474
{
 
475
  gtk_text_buffer_paste_clipboard(gobj(), clipboard->gobj(),
 
476
      const_cast<GtkTextIter*>(override_location.gobj()), default_editable);
 
477
}
 
478
 
 
479
void TextBuffer::paste_clipboard(const Glib::RefPtr<Clipboard>& clipboard, bool default_editable)
 
480
{
 
481
  gtk_text_buffer_paste_clipboard(gobj(), clipboard->gobj(), 0, default_editable);
 
482
}
 
483
 
 
484
TextBuffer::iterator TextBuffer::get_iter_at_child_anchor(const Glib::RefPtr<ChildAnchor>& anchor)
 
485
{
 
486
  iterator iter;
 
487
  gtk_text_buffer_get_iter_at_child_anchor(gobj(), iter.gobj(), anchor->gobj());
 
488
  return iter;
 
489
}
 
490
 
 
491
int TextBuffer::size() const
 
492
{
 
493
  return get_char_count();
 
494
}
 
495
 
 
496
Glib::ustring TextBuffer::get_text(bool include_hidden_chars) const
 
497
{
 
498
  TextBuffer* unconst = const_cast<TextBuffer*>(this); //Because begin() and end() are not const.
 
499
  return get_text(unconst->begin(), unconst->end(), include_hidden_chars);
 
500
}
 
501
 
 
502
std::vector<Glib::ustring> TextBuffer::get_serialize_formats() const
 
503
{
 
504
  int n_atoms = 0;
 
505
  GdkAtom* atoms = gtk_text_buffer_get_serialize_formats(const_cast<GtkTextBuffer*>(gobj()), &n_atoms);
 
506
  return Glib::ArrayHandler<Glib::ustring, Gdk::AtomUstringTraits>::array_to_vector(atoms, n_atoms, Glib::OWNERSHIP_SHALLOW);
 
507
}
 
508
 
 
509
std::vector<Glib::ustring> TextBuffer::get_deserialize_formats() const
 
510
{
 
511
  int n_atoms = 0;
 
512
  GdkAtom* atoms = gtk_text_buffer_get_deserialize_formats(const_cast<GtkTextBuffer*>(gobj()), &n_atoms);
 
513
  return Glib::ArrayHandler<Glib::ustring, Gdk::AtomUstringTraits>::array_to_vector(atoms, n_atoms, Glib::OWNERSHIP_SHALLOW);
 
514
}
 
515
 
 
516
/*
 
517
Glib::ustring TextBuffer::register_serialize_format(const Glib::ustring& mime_type, const SlotSerialize& slot)
 
518
{
 
519
  SlotSerialize* slot_copy = new SlotSerialize(slot);
 
520
  GdkAtom atom = gtk_text_buffer_register_serialize_format(gobj(), mime_type.c_str(), 
 
521
                &SignalProxy_Serialize, slot_copy, &SignalProxy_Serialize_gtk_callback_destroy);
 
522
 
 
523
  //Convert the atom to a string:
 
524
  Glib::ustring atom_as_string;
 
525
  char* atom_name = gdk_atom_name(atom);
 
526
  if(atom_name)
 
527
  {
 
528
    atom_as_string = atom_name;
 
529
    g_free(atom_name);
 
530
  }
 
531
 
 
532
  return atom_as_string;
 
533
}
 
534
 
 
535
Glib::ustring TextBuffer::register_deserialize_format(const Glib::ustring& mime_type, const SlotDeserialize& slot)
 
536
{
 
537
  SlotDeserialize* slot_copy = new SlotDeserialize(slot);
 
538
  GdkAtom atom = gtk_text_buffer_register_deserialize_format(gobj(), mime_type.c_str(), 
 
539
                &SignalProxy_Deserialize, slot_copy, &SignalProxy_Deserialize_gtk_callback_destroy);
 
540
 
 
541
  //Convert the atom to a string:
 
542
  Glib::ustring atom_as_string;
 
543
  char* atom_name = gdk_atom_name(atom);
 
544
  if(atom_name)
 
545
  {
 
546
    atom_as_string = atom_name;
 
547
    g_free(atom_name);
 
548
  }
 
549
 
 
550
  return atom_as_string;
 
551
}
 
552
*/
 
553
 
 
554
} // namespace Gtk