Re: turn on italics in TextView



Indeed I tried your code from Aug 15 and if you insert a character at the
beginning of the 3rd or 5th line, the indent/margin disappears.  Then if
you backspace over that inserted character, the indent/margin re-appears.
I tried this in <3.20 and 3.22.  Would you consider this a bug?  I've never
reported a bug to GTK.  What is the basic procedure?

On Tue, Aug 15, 2017 at 2:38 PM, Doug McCasland <dougm bravoecho net> wrote:

Indeed, gtk_text_buffer_insert_with_tags_by_name() does what it says.
What I was talking about was (in some future Textview) applying the tag to
an iter, then whenever the insert point was on that iter, it would inherit
the tag properties set there.  So typing at that point gets the
formatting.

I don't have my code in front of me, but as I recall the jumpy-cursor
thing happened with this:

   1. Insert some text in a line.
   2. Apply indent 50px to whole line.  The line will be indented on the
   screen.
   3. Start typing at the beginning of line, which will not inherit the
   indent tag.  The indent will disappear on the screen.
   4. Move the cursor to the region with the applied indent -- the indent
   comes back.



On Tue, Aug 15, 2017 at 2:27 PM, <cecashon aol com> wrote:


Have you tried gtk_text_buffer_insert_with_tags_by_name() to insert text
with a tag at an iter?

What tag combo do you use to get the cursor to bounce around? If I test
having two indent tags on the same line, the first one applied wins out.
This is what I tested with.

Eric


/*
  gcc -Wall move_cursor1.c -o move_cursor1 `pkg-config --cflags --libs
gtk+-3.0`
  Tested on GTK3.18 and Ubuntu16.04
*/

#include<gtk/gtk.h>

static void get_style(GtkTextView *tv, GtkMovementStep step, gint count,
gboolean extend, gpointer *user_data)
  {
    static int i=1;
    GtkTextIter start;
    GtkTextMark *mark;
    GtkTextBuffer *buf;

    buf=gtk_text_view_get_buffer(GTK_TEXT_VIEW(tv));

    mark=gtk_text_buffer_get_insert(buf);
    gtk_text_buffer_get_iter_at_mark (buf, &start, mark);
    g_print("Iter %i\n", gtk_text_iter_get_offset(&start));

    GSList *tlist=NULL;
    GSList *p=NULL;
    tlist=gtk_text_iter_get_tags(&start);
    g_print("%i. List %p p %p\n", i, tlist, p);
    i++;
    for(p=tlist;p;p=p->next)
      {
        gchar *string=NULL;
        g_object_get(G_OBJECT(p->data), "name", &string, NULL);
        g_print("p %p %s\n", p, string);
        g_free(string);
      }

    g_print("List %p\n", tlist);
    if(tlist!=NULL) g_slist_free(tlist);
  }
int main (int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Move Cursor");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget *textview=gtk_text_view_new();
    gtk_widget_set_vexpand(textview, TRUE);
    gtk_widget_set_hexpand(textview, TRUE);
    g_signal_connect(textview, "move-cursor", G_CALLBACK(get_style),
NULL);

    GtkTextBuffer *buffer=gtk_text_view_get_buff
er(GTK_TEXT_VIEW(textview));
    gtk_text_buffer_create_tag(buffer, "ital", "style",
PANGO_STYLE_ITALIC, NULL);
    gtk_text_buffer_create_tag(buffer, "bold", "weight",
PANGO_WEIGHT_BOLD, NULL);
    gtk_text_buffer_create_tag(buffer, "uline", "underline",
PANGO_UNDERLINE_SINGLE, NULL);
    gtk_text_buffer_create_tag(buffer, "indent", "indent", 20, NULL);
    gtk_text_buffer_create_tag(buffer, "indent2", "indent", 40, NULL);
    gtk_text_buffer_create_tag(buffer, "left-margin", "left-margin", 20,
NULL);
    gtk_text_buffer_create_tag(buffer, "left-margin2", "left-margin",
40, NULL);

    GtkTextIter iter;
    gtk_text_buffer_get_start_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "ital ", -1,
"ital", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "bold ", -1,
"bold", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    //Check a newline for a tag.
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "uline \n",
-1, "uline", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "all\n", -1,
"ital", "bold", "uline", NULL);
    //Check indents in the same line.
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "indent ",
-1, "indent", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "indent2\n",
-1, "indent2", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "indent2\n",
-1, "indent2", NULL);
    //Check left-margin in the same line.
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter, "left-margin
", -1, "left-margin", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
"left-margin2\n", -1, "left-margin2", NULL);
    gtk_text_buffer_get_end_iter(buffer, &iter);
    gtk_text_buffer_insert_with_tags_by_name(buffer, &iter,
"left-margin2", -1, "left-margin2", NULL);

    GtkWidget *grid=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid), 8);
    gtk_grid_attach(GTK_GRID(grid), textview, 0, 0, 1, 1);

    gtk_container_add(GTK_CONTAINER(window), grid);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;
  }




--
Doug McCasland   <dougm bravoecho net>




-- 
Doug McCasland   <dougm bravoecho net>


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