Re: get text from GtkText



On Wed, 2001-08-29 at 00:45, ZB wrote:

dont use the old one.

er... then why do you explain the old API then?
 
read the api at:
http://developer.gnome.org/doc/API/gtk/gtkeditable.html#GTK-EDITABLE-GET-CHARS

you want to use "gtk_editable_get_chars"

which, incidentally is the same function that I suggested ;)

Thomas Mailund wrote:

With the (old) text widget you can use

gchar*     gtk_editable_get_chars  (GtkEditable      *editable,
                                    gint              start_pos,
                                    gint              end_pos);



With the new text widget (which I haven't worked with, so all of the
below could be pure fiction and no facts) you access the text through a
"text buffer" that you point into via iterators.  To extract text you
use the functions

/**
 * gtk_text_buffer_get_text:
 * @buffer: a #GtkTextBuffer
 * @start: start of a range
 * @end: end of a range
 * @include_hidden_chars: whether to include invisible text
 *
 * Returns the text in the range [ start,@end). Excludes undisplayed
 * text (text marked with tags that set the invisibility attribute) if
 * @include_hidden_chars is FALSE. Does not include characters
 * representing embedded images, so byte and character indexes into
 * the returned string do <emphasis>not</emphasis> correspond to byte
 * and character indexes into the buffer. Contrast with
 * gtk_text_buffer_get_slice ().
 *
 * Return value: an allocated UTF-8 string
 **/
gchar  *gtk_text_buffer_get_text (GtkTextBuffer     *buffer,
                                  const GtkTextIter *start,
                                  const GtkTextIter *end,
                                  gboolean   include_hidden_chars);

/**
 * gtk_text_buffer_get_slice:
 * @buffer: a #GtkTextBuffer
 * @start: start of a range
 * @end: end of a range
 * @include_hidden_chars: whether to include invisible text
 *
 * Returns the text in the range [ start,@end). Excludes undisplayed
 * text (text marked with tags that set the invisibility attribute) if
 * @include_hidden_chars is FALSE. The returned string includes a
 * 0xFFFC character whenever the buffer contains
 * embedded images, so byte and character indexes into
 * the returned string <emphasis>do</emphasis> correspond to byte
 * and character indexes into the buffer. Contrast with
 * gtk_text_buffer_get_text (). Note that 0xFFFC can occur in normal
 * text as well, so it is not a reliable indicator that a pixbuf or
 * widget is in the buffer.
 *
 * Return value: an allocated UTF-8 string
 **/
gchar  *gtk_text_buffer_get_slice(GtkTextBuffer     *buffer,
                                  const GtkTextIter *start,
                                  const GtkTextIter *end,
                                  gboolean include_hidden_chars);



To get all the text I guess you'd use

GtkTextIter begin, end;
gtk_text_buffer_get_start_itr (buffer, &begin);
gtk_text_buffer_get_end_itr (buffer, &end);
char *text = gtk_text_buffer_get_text(buffer, &begin, &end, TRUE);

HTH
        /mailund

-- 
UNIX is the answer, but only if you phrase the question very carefully

Attachment: pgpx78NmnJWhD.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]