Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Gtk;
- class WindowTest : Gtk.Box{
- private Gdk.Window event_window;
- private Button button = new Button.with_label("Foo");
- public WindowTest() {
- GLib.Object(orientation: Orientation.HORIZONTAL, spacing: 25);
- button.no_show_all = true;
- this.pack_end(new Button.with_label("Bar"));
- this.pack_start(button);
- this.enter_notify_event.connect( ()=> {
- button.show();
- message(" IN");
- return false;
- });
- this.leave_notify_event.connect( () => {
- button.hide();
- message("OUT");
- return false;
- });
- }
- public override void realize() {
- message("realize");
- Allocation alloc;
- Gdk.WindowAttr attr = {};
- this.get_allocation(out alloc);
- this.set_realized(true);
- attr.x = alloc.x;
- attr.y = alloc.y;
- attr.width = alloc.width;
- attr.height = alloc.height;
- attr.window_type = Gdk.WindowType.CHILD;
- attr.event_mask = this.get_events();
- attr.event_mask |= (Gdk.EventMask.ENTER_NOTIFY_MASK |
- Gdk.EventMask.LEAVE_NOTIFY_MASK |
- Gdk.EventMask.EXPOSURE_MASK);
- var attr_type = Gdk.WindowAttributesType.X |
- Gdk.WindowAttributesType.Y;
- bool visible_window = get_has_window();
- if(visible_window) {
- error("NOP!");
- }else {
- var parent = get_parent_window();
- set_window(parent);
- attr.wclass = Gdk.WindowWindowClass.INPUT_ONLY;
- this.event_window = new Gdk.Window(parent, attr, attr_type);
- this.event_window.set_user_data(this);
- message("No visible window");
- }
- }
- public override void unrealize() {
- message("unrealize");
- if(this.event_window != null) {
- this.event_window.set_user_data(null);
- this.event_window.destroy();
- this.event_window = null;
- }
- base.unrealize();
- }
- public override void map(){
- message("map");
- base.map();
- if(event_window != null)
- event_window.show();
- }
- public override void unmap() {
- message("unmap");
- base.unmap();
- if(event_window != null)
- event_window.hide();
- }
- public override void size_allocate(Allocation alloc) {
- message("size_allocate");
- this.set_allocation(alloc);
- if(this.get_realized()) {
- if(event_window != null)
- event_window.move_resize(alloc.x, alloc.y,
- alloc.width, alloc.height);
- }
- base.size_allocate(alloc);
- }
- static void main(string[] args) {
- Gtk.init(ref args);
- var win = new Window();
- win.add(new WindowTest());
- win.resize(200, 200);
- win.show_all();
- Gtk.main();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement