Adding items to tables
- From: Richard Gipps <rgipps netspace net au>
- To: goocanvas-list gnome org
- Subject: Adding items to tables
- Date: Sun, 14 Sep 2008 20:22:13 +1000
Hi all,
I have been working on some code which adds items to tables
when a particular event occurs. The problem is that when I add items to
the table using say a button push, the items are not drawn on the canvas
until I re-size it. I have tried using goo_canvas_update(canvas) but
that does not seem to do the trick. Is there another function I should
be using? I have included some sample code to put the question into
context. Note that I have no problem adding these items when not using
events i.e. before gtk_main() is called.
Regards,
Richard.
#include <gtk/gtk.h>
#include <goocanvas/goocanvas.h>
#define HOMOGENEOUS TRUE
#define NON_HOMOGENEOUS FALSE
#define SPACING 0
#define EXPAND TRUE
#define FILL TRUE
#define PADDING 0
GtkWidget* canvas;
GooCanvasItemModel* table;
static gboolean on_delete_event(GtkWidget* window,GdkEvent*
event,gpointer unused_data)
{
return(FALSE); //do not prevent window from being closed (destroyed)
}
static void on_destroy_event(GtkWidget* window,GdkEvent* event,gpointer
unused_data)
{
gtk_main_quit();
}
static void on_test_button_1_pressed(GtkButton* button,gpointer* data)
{
GooCanvasItemModel* rectangle_1;
GooCanvasItemModel* rectangle_2;
rectangle_1 = goo_canvas_rect_model_new(table,
0.0, //x
0.0, //y
50.0, //width,
50.0, //height
"fill-color","red",
NULL);
goo_canvas_item_model_set_child_properties(table,
rectangle_1,
"row",0,
"column",0,
NULL);
rectangle_2 = goo_canvas_rect_model_new(table,
0.0, //x
0.0, //y
50.0, //width,
50.0, //height
"fill-color","orange",
NULL);
goo_canvas_item_model_set_child_properties(table,
rectangle_2,
"row",0,
"column",1,
NULL);
goo_canvas_update(canvas);
}
int main(int argc,char* argv[])
{
GtkWidget* window;
GtkWidget* vbox;
GtkWidget* hbox;
GtkWidget* test_button_1;
GtkWidget* scroll_window;
GooCanvasItemModel* root;
GooCanvasItemModel* rectangle_1;
GooCanvasItemModel* rectangle_2;
//Initialize GTK+
gtk_init(&argc, &argv);
//Create GTK+ the window
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window,200,200);
vbox = gtk_vbox_new(NON_HOMOGENEOUS,SPACING);
gtk_container_add(GTK_CONTAINER(window),vbox);
hbox = gtk_hbox_new(HOMOGENEOUS,SPACING);
gtk_box_pack_start(GTK_BOX(vbox),
hbox,
FALSE,
FALSE,
PADDING);
test_button_1 = gtk_button_new_with_label("Test 1");
gtk_box_pack_start(GTK_BOX(hbox),
test_button_1,
TRUE,
TRUE,
0);
scroll_window = gtk_scrolled_window_new(NULL,NULL);
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_box_pack_start(GTK_BOX(vbox),
scroll_window,
TRUE,
TRUE,
PADDING);
//Create canvas
canvas = goo_canvas_new();
gtk_container_add(GTK_CONTAINER(scroll_window),canvas);
root = goo_canvas_group_model_new(NULL,NULL);
goo_canvas_set_root_item_model(GOO_CANVAS(canvas),root);
table = goo_canvas_table_model_new(root,
"row-spacing",0.0,
"column-spacing",0.0,
NULL);
goo_canvas_item_model_translate(table,10,10);
gtk_widget_show_all(window);
//Connect signals
g_signal_connect(G_OBJECT(test_button_1),
"clicked",
G_CALLBACK(on_test_button_1_pressed),
NULL);
g_signal_connect(G_OBJECT(window),
"delete_event",
G_CALLBACK(on_delete_event),
NULL);
g_signal_connect(G_OBJECT(window),
"destroy",
G_CALLBACK(on_destroy_event),
NULL);
//Pass control to the GTK+ main event loop.
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]