toplanxue 发表于 2012-3-15 17:10:40

求救:notebook加入textview,切换notebook后无法显示textview

#include <gtk/gtk.h>
GtkWidget *win;
void refresh_textview( GtkWidget *win )
{
GtkTextBuffer *buffer;
GtkTextIter iter;
GtkTextMark *mark;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (win));
mark = gtk_text_buffer_get_insert (buffer); //
gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW (win),mark);
gtk_text_buffer_insert (buffer, &iter, "Buffer", -1);
gtk_widget_draw(GTK_WIDGET(win),NULL);
}
void clicked_cb(GtkWidget *button, GtkNotebook *nb)
{
GtkWidget *lbl, *txtview;
gchar str;
static gint n = 0;
sprintf(str, "Page %d", ++n);

lbl = gtk_label_new(str);
gtk_widget_show(lbl);
txtview = gtk_text_view_new();
refresh_textview(txtview);
gtk_notebook_append_page(nb, txtview, lbl);
gtk_widget_show(txtview);
gtk_widget_show(GTK_WIDGET(nb));
gtk_widget_queue_draw(GTK_WIDGET(nb));
}
void get_pagenum(GtkWidget *widget,GtkWidget *notebook)
{

    GtkWidget *dialog,*window;
    gint n;
    n=gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));

    window=gtk_widget_get_toplevel(widget);
    dialog=gtk_message_dialog_new(GTK_WINDOW(window),GTK_DIALOG_MODAL||GTK_DIALOG_NO_SEPARATOR,GTK_MESSAGE_INFO,GTK_BUTTONS_OK,"PageNum:%d",n);
    gtk_dialog_run(GTK_DIALOG(dialog));
    gtk_widget_destroy(dialog);
    g_print("%d\n",n);
}
gboolean refreshwin(gpointer notebook)
{
int num;
int pagenum;
pagenum=gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook));
num = gtk_notebook_current_page(GTK_NOTEBOOK(notebook));
g_print("Notebook Num:%d Pagenum = %d\n",num,pagenum);
g_print("Refreshwin\n");
gtk_widget_draw(notebook,NULL);
gtk_widget_show(notebook);
gtk_widget_show(win);
return TRUE;
}
int main(int argc, char **argv)
{
GtkWidget *vbox;
GtkWidget *nb;
GtkWidget *button;

gtk_init(&argc, &argv);

win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win),400,300);
g_signal_connect(G_OBJECT(win), "delete-event", G_CALLBACK(gtk_main_quit), NULL);

vbox = gtk_vbox_new(FALSE, 0);
gtk_container_add(GTK_CONTAINER(win), vbox);
gtk_widget_show(vbox);

nb = gtk_notebook_new();
g_signal_connect(G_OBJECT(nb),"switch_page",G_CALLBACK(refreshwin),nb);
gtk_box_pack_start(GTK_BOX(vbox), nb, TRUE, TRUE, 0);
gtk_widget_show(nb);

button = gtk_button_new_with_label("Add Page");
g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(clicked_cb), (gpointer)nb);
gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);

gtk_widget_show(win);

gtk_main();

return 0;
}

ACTom 发表于 2012-3-15 23:54:13

恩,我这测试没有问题,运行正常。

环境:Fedora 16 i686, Gtk+2.24.8

白浪 发表于 2012-3-22 16:51:55

windows下2.16正常如果你在windows下用2.24的话请换其它版本

mbt 发表于 2012-4-8 10:50:38

我跟你遇到了同样的问题

redwyz 发表于 2014-1-3 10:37:06

页: [1]
查看完整版本: 求救:notebook加入textview,切换notebook后无法显示textview