On 06/09/2013 09:21 AM, Thomas A. Moulton wrote:
I see a lot of questions about this and I have not found an answer that works for me.

I create the chat window like this:


The printf above at times tells me the objects are not valid, but the addresses have not changed. Also the TextBuffer has a parent of 0! I even allocated and set the buffer manually.

If there it no anything obvious wrong here I will strip it down to a simpler test case

Tom

Ok here is a single file example of my code... it works the same way it does in my larger project

Any suggestions would be GREATLY appreciated!

tom

/*
 ============================================================================
 Name        : Scrolled.c
 Author      : Tom Moulton
 Version     :
 Copyright   : (c) 2013 Thoomas A. Moulton, Public Domain
 Description : Hello World in GTK+
 ============================================================================
 */

#include <gtk/gtk.h>
GtkNotebook *nb;

void Enter_Chat(GtkEntry *entry, GtkTextBuffer *buf) {
    char line[512];
    const gchar *cmd;
    GtkTextIter endit;

    cmd = gtk_entry_get_text(entry);
    strcpy(line, cmd);
    gtk_entry_set_text(entry, "");

    gtk_text_buffer_get_end_iter(buf, &endit);
    gtk_text_buffer_insert_with_tags(buf, &endit, line, -1, NULL, NULL);
}

void Chat_scroll_to_end(GtkTextBuffer *buf, GtkTextView *text) {
    GtkTextMark *mark;
    mark = gtk_text_buffer_get_mark(buf, "eob");
    gtk_text_view_scroll_mark_onscreen(text, mark);
}

void ChatNew(void) {
    GtkBox *chat;
    GtkTextBuffer *buf;
    GtkTextView *text;
    GtkEntry *entry;
    GtkScrolledWindow *scroll;
    GtkTextIter endit;
    GtkLabel *label;

    text = (GtkTextView *)gtk_text_view_new();
    gtk_text_view_set_editable(text, FALSE);
    gtk_text_view_set_wrap_mode(text, GTK_WRAP_WORD_CHAR);
    gtk_text_view_set_cursor_visible(text, FALSE);
    buf = gtk_text_buffer_new(NULL);
    gtk_text_view_set_buffer(text, buf);

    scroll = (GtkScrolledWindow *)gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(scroll, GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
    gtk_scrolled_window_add_with_viewport(scroll, GTK_WIDGET(text));

    entry =  (GtkEntry *)gtk_entry_new();
    gtk_widget_set_size_request(GTK_WIDGET(entry), -1, 30);

    chat = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 0));
    gtk_box_pack_start(chat, GTK_WIDGET(scroll), TRUE, TRUE, 0);
    gtk_box_pack_end(chat, (GtkWidget *)entry, FALSE, TRUE, 0);

g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(Enter_Chat), (gpointer)buf);

    gtk_text_buffer_get_end_iter(buf, &endit);
    gtk_text_buffer_create_mark(buf, "eob", &endit, FALSE);
g_signal_connect(G_OBJECT(buf), "changed", G_CALLBACK(Chat_scroll_to_end), (gpointer)text);
    label = (GtkLabel *)gtk_label_new("Test Scroll");
    gtk_notebook_append_page(nb, GTK_WIDGET(chat), GTK_WIDGET(label));
}

int main (int argc, char *argv[])
 {
    GtkWidget *window;

    gtk_init (&argc, &argv);

    /* create the main, top level, window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    /* give it the title */
    gtk_window_set_title (GTK_WINDOW (window), "Hello World");

    /* Connect the destroy signal of the window to gtk_main_quit
     * When the window is about to be destroyed we get a notification and
     * stop the main GTK+ loop
     */
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

    nb = (GtkNotebook *)gtk_notebook_new();
    ChatNew();

    /* and insert it into the main window  */
    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(nb));

    /* make sure that everything, window and label, are visible */
    gtk_widget_show_all (window);

/* start the main loop, and let it rest there until the application is closed */
    gtk_main ();

    return 0;
 }

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to