function reparent_label(widget, new_parent) { widget.reparent(new_parent); } function changed_parent_message(child, func_data) { if (!child.parent) princ("I lost my parent.\n"); else princ(string("My new parent is a ", class_name(child.parent), ", named ", child.parent.name,". My data is: ", func_data, "\n")); } function create_reparent () { local box1, box2, box3, box4, separator, button, frame; win_reparent = new (GtkWindow); win_reparent.signal ("destroy", #win_reparent = nil); win_reparent.title = "reparent"; win_reparent.border_width = 0; box1 = new (GtkVBox); win_reparent.add (box1); box2 = new (GtkHBox); box2.spacing = 5; box2.border_width = 10; box1.pack_start (box2, TRUE, TRUE, 0); label = new(GtkLabel); label.set_text("Hello World"); frame = new(GtkFrame); frame.label = "Frame 1"; box2.pack_start(frame, TRUE, TRUE, 0); box3 = new(GtkVBox); box3.spacing = 5; box3.border_width = 5; box3.name = "Left Box"; frame.add(box3); button = new(GtkButton); button.label = "switch"; button.signal("clicked", `reparent_label(@label, @box3)); button.user_data = label; box3.pack_start(button, FALSE, TRUE, 0); box3.pack_start(label, FALSE, TRUE, 0); label.signal("parent_set", `changed_parent_message(@label, 42)); frame = new(GtkFrame); frame.label = "Frame 2"; box2.pack_start(frame, TRUE, TRUE, 0); box4 = new(GtkVBox); box4.spacing = 5; box4.border_width = 5; box4.name = "Right Box"; frame.add(box4); button = new(GtkButton); button.label = "switch"; button.signal("clicked", `reparent_label(@label, @box4)); button.user_data = label; box4.pack_start(button, FALSE, TRUE, 0); separator = new(GtkHSeparator); box1.pack_start(separator, FALSE, TRUE, 0); box2 = new(GtkVBox); box2.spacing = 10; box2.border_width = 10; box1.pack_start(box2, FALSE, TRUE, 0); button = new (GtkButton); button.label = "close"; button.signal ("clicked", `(@win_reparent).destroy()); box2.pack_start (button, TRUE, TRUE, 0); button.can_default = TRUE; button.grab_default(); win_reparent.show_all(); win_reparent; } function main () { local window, win_reparent; TRUE=1; FALSE=0; window = create_reparent (); window.signal ("destroy", #exit_program(0)); init_ipc("reparent", "reparentq"); gtk_main (); }
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.