Advertisement
Guest User

Untitled

a guest
Feb 18th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Vala 3.75 KB | None | 0 0
  1.  
  2.  
  3. using Gtk;
  4.  
  5. class WindowTest : Gtk.Box{
  6.         private Gdk.Window event_window;
  7.         private Button button = new Button.with_label("Foo");
  8.  
  9.  
  10.         public WindowTest() {
  11.                 GLib.Object(orientation: Orientation.HORIZONTAL, spacing: 25);
  12.                 button.no_show_all = true;
  13.                 this.pack_end(new Button.with_label("Bar"));
  14.                 this.pack_start(button);
  15.  
  16.                 this.enter_notify_event.connect( ()=> {
  17.                         button.show();
  18.                         message(" IN");
  19.                         return false;
  20.                 });
  21.                 this.leave_notify_event.connect( () => {
  22.                         button.hide();
  23.                         message("OUT");
  24.                         return false;
  25.                 });
  26.         }
  27.  
  28.         public override void realize() {
  29.                 message("realize");
  30.                 Allocation alloc;
  31.                 Gdk.WindowAttr attr = {};
  32.  
  33.                 this.get_allocation(out alloc);
  34.  
  35.                 this.set_realized(true);
  36.  
  37.  
  38.                 attr.x = alloc.x;
  39.                 attr.y = alloc.y;
  40.                 attr.width = alloc.width;
  41.                 attr.height = alloc.height;
  42.                 attr.window_type = Gdk.WindowType.CHILD;
  43.                 attr.event_mask = this.get_events();
  44.                 attr.event_mask |= (Gdk.EventMask.ENTER_NOTIFY_MASK |
  45.                                                         Gdk.EventMask.LEAVE_NOTIFY_MASK |
  46.                                                         Gdk.EventMask.EXPOSURE_MASK);
  47.  
  48.                 var attr_type = Gdk.WindowAttributesType.X |
  49.                                 Gdk.WindowAttributesType.Y;
  50.  
  51.  
  52.  
  53.                 bool visible_window = get_has_window();
  54.                 if(visible_window) {
  55.                     error("NOP!");
  56.                 }else {
  57.                         var parent = get_parent_window();
  58.                         set_window(parent);
  59.  
  60.                         attr.wclass = Gdk.WindowWindowClass.INPUT_ONLY;
  61.  
  62.                         this.event_window = new Gdk.Window(parent, attr, attr_type);
  63.                         this.event_window.set_user_data(this);
  64.                         message("No visible window");
  65.  
  66.                 }
  67.  
  68.         }
  69.  
  70.         public override void unrealize() {
  71.                 message("unrealize");
  72.                 if(this.event_window != null) {
  73.                         this.event_window.set_user_data(null);
  74.                         this.event_window.destroy();
  75.                         this.event_window = null;
  76.                 }
  77.  
  78.                 base.unrealize();
  79.         }
  80.  
  81.         public override void map(){
  82.                 message("map");
  83.                 base.map();
  84.                 if(event_window != null)
  85.                         event_window.show();
  86.  
  87.         }
  88.  
  89.         public override void unmap() {
  90.                 message("unmap");
  91.                 base.unmap();
  92.                 if(event_window != null)
  93.                         event_window.hide();
  94.         }
  95.  
  96.         public override void size_allocate(Allocation alloc) {
  97.                 message("size_allocate");
  98.                 this.set_allocation(alloc);
  99.  
  100.                 if(this.get_realized()) {
  101.                         if(event_window != null)
  102.                                 event_window.move_resize(alloc.x, alloc.y,
  103.                                                          alloc.width, alloc.height);
  104.                 }
  105.                 base.size_allocate(alloc);
  106.         }
  107.  
  108.  
  109.  
  110.         static void main(string[] args) {
  111.                 Gtk.init(ref args);
  112.  
  113.                 var win = new Window();
  114.                 win.add(new WindowTest());
  115.                 win.resize(200, 200);
  116.                 win.show_all();
  117.                 Gtk.main();
  118.         }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement