|
#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[256];
static gint n = 0;
sprintf(str, "age %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,"ageNum:%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;
} |
|