Insert gap in text buffer by using a tag



I am having a text like "0bullet" inside of GtkTextView, where the first character is a bullet sign and the rest is the ordinary text I need to be able to format this text to insert some space gap between the bullet and the rest (should look like this: "0 bullet").

I've tried using tags in 3 different ways but none of these seem to work:

a) using "indent" property:

GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL,"indent", 18,"indent-set", TRUE,NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterBulletEnd, &iterEnd);

b) using "left-margin" property:

GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL,"left-margin", 18,"left-margin-set", TRUE,NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterBulletEnd, &iterEnd);

c) using "right-margin" property:

GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL, "right-margin", 18, "right-margin-set", TRUE, NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterStart, &iterBulletEnd);

where iterStart points to the start of text, iterEnd points to the end of text, iterBulletEnd points after the bullet sign.

Does anyone has an idea what is wrong here ?

Regards,
 Miroslav

PS. Entire sample below, uncomment "#if 0" blocks to try

#include <gtk/gtk.h>
void create_window();
void insert_bulleted_line();
GtkTextBuffer *buffer;
int main (int argc, char *argv[])
{
gtk_init (&argc, &argv);
create_window();
insert_bulleted_line();
gtk_main ();
return 0;
}

void create_window()
{
GtkWidget *window1;
GtkWidget *scrolledwindow2;
GtkWidget *textview1;
window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window1), "test");
gtk_widget_show (window1);
scrolledwindow2 = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_show (scrolledwindow2);
gtk_container_add (GTK_CONTAINER (window1), scrolledwindow2);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow2), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
buffer = gtk_text_buffer_new (NULL);
textview1 = gtk_text_view_new_with_buffer (buffer);
gtk_widget_show (textview1);
gtk_container_add (GTK_CONTAINER (scrolledwindow2), textview1);
}
void insert_bulleted_line()
{
//insert text
GtkTextIter iterStart;
gtk_text_buffer_get_start_iter (buffer, &iterStart);
gtk_text_buffer_insert(buffer, &iterStart, "obullet", -1);

// refresh iterator
gtk_text_buffer_get_start_iter (buffer, &iterStart);

GtkTextIter iterEnd;
gtk_text_buffer_get_end_iter (buffer, &iterEnd);

//
// formatting
//
#if 0
//indent entire bullet line - this works OK
GtkTextTag *tag = gtk_text_buffer_create_tag (buffer, NULL, "left-margin", 18, "left-margin-set", TRUE, NULL);
gtk_text_buffer_apply_tag(buffer, tag, &iterStart, &iterEnd);
#endif

// try to create a gap between the fist character (bullet) and the rest of the line
GtkTextIter iterBulletEnd = iterStart;
gtk_text_iter_forward_char (&iterBulletEnd);
int nOffset = gtk_text_iter_get_offset(&iterBulletEnd);

#if 1
GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL, "indent", 18, "indent-set", TRUE, NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterBulletEnd, &iterEnd);
#endif

#if 0
GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL, "left-margin", 18, "left-margin-set", TRUE, NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterBulletEnd, &iterEnd);
#endif

#if 0
GtkTextTag *tag1 = gtk_text_buffer_create_tag (buffer, NULL, "right-margin", 18, "right-margin-set", TRUE, NULL);
gtk_text_buffer_apply_tag(buffer, tag1, &iterStart, &iterBulletEnd);
#endif
}



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