Re: Newbie questions - Frames (Using GtkCanvas)



Well, this will give you a bit more of an idea what's going on (or
not, as the case may be). I don't know why the raise/lower don't work
correctly in this case. Looks like either a bug in Fixed or the Canvas
to me.

--p

#include <gtk/gtk.h>
#include <gtk-canvas.h>

/*
compiled with : 

gcc `gtk-config --cflags` gc.c -o t1  -lgtk-canvas `gtk-config --libs`'

*/
#define STYLE GTK_SHADOW_IN

GtkCanvasItem *i1, *i2;

gint
button_press_handler (GtkWidget *widget, GdkEventButton *ev)
{
	if (ev->button == 1) {
		gtk_canvas_item_raise_to_top (i2);
	} else if (ev->button == 2) {
		gtk_canvas_item_move (i1, -10, -10);
	} else if (ev->button == 3) {
		gtk_canvas_item_move (i1, 10, 10);
	}
}

int
main (int argc, char *argv[])
{
        GtkWidget *app;
        GtkWidget *c;
        GtkWidget *frame1;
        GtkWidget *frame2;
        GtkWidget *f1;
        GtkWidget *f2;
        GtkCanvasGroup *root;
        int i;

        gtk_init (&argc, &argv);
        gtk_canvas_init();

        app = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_widget_set_usize (GTK_WIDGET(app), 400,400);
        c = gtk_canvas_new ();
        gtk_container_add(GTK_CONTAINER(app),c);
        gtk_widget_show(c);
        gtk_widget_show(app);

        frame1 = gtk_frame_new ("first");
        gtk_widget_set_usize (GTK_WIDGET (frame1), 200,200);

        frame2 = gtk_frame_new ("second");
        gtk_widget_set_usize (GTK_WIDGET (frame2), 200,200);

          root = gtk_canvas_root (GTK_CANVAS (c));


          i1 = gtk_canvas_item_new (root, gtk_canvas_widget_get_type (),
                      "widget", frame1,
                      "x", (double)0,
                      "y", (double)0,
                      "width", (double)200,
                      "height", (double)200,
                      "anchor", GTK_ANCHOR_NW,
                      "size_pixels", FALSE, NULL);

          i2 = gtk_canvas_item_new (root, gtk_canvas_widget_get_type (),
                      "widget", frame2,
                      "x", (double)50,
                      "y", (double)50,
                      "width", (double)200,
                      "height", (double)200,
                      "anchor", GTK_ANCHOR_NW,
                      "size_pixels", FALSE, NULL);

	  gtk_canvas_item_raise (i2, 1);
	  
	  gtk_signal_connect (GTK_OBJECT(app), "button_press_event",
			      (GtkSignalFunc) button_press_handler, 
			      0);

        f1=gtk_fixed_new();
        f2=gtk_fixed_new();
        gtk_container_add(GTK_CONTAINER(frame1),f1);
        gtk_container_add(GTK_CONTAINER(frame2),f2);
        gtk_widget_show(f1);
        gtk_widget_show(f2);
        gtk_frame_set_shadow_type (GTK_FRAME (frame1), STYLE);
        gtk_frame_set_shadow_type (GTK_FRAME (frame2), STYLE);
        gtk_widget_show(frame1);
        gtk_widget_show(frame2);

	gtk_main();
}






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