File: NativeInstantiationTest.cs

package info (click to toggle)
gtk-sharp3 2.99.3-4.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,488 kB
  • sloc: xml: 308,885; cs: 38,796; sh: 11,336; perl: 1,295; makefile: 1,099; ansic: 903
file content (56 lines) | stat: -rwxr-xr-x 1,499 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Author: Mike Kestner <mkestner@novell.com>
//
// Copyright (c) 2009 Novell, Inc.

namespace GtkSharp {

	using Gtk;
	using System;
	using System.Runtime.InteropServices;

	public class InstantiationTest : Gtk.Window  {

		[DllImport ("libgobject-2.0.so.0")]
		static extern IntPtr g_object_new (IntPtr gtype, string prop, string val, IntPtr dummy);

		[DllImport ("libgtk-3.so.0")]
		static extern void gtk_widget_show (IntPtr handle);

		public static int Main (string[] args)
		{
			Application.Init ();
			GLib.GType gtype = LookupGType (typeof (InstantiationTest));
			GLib.GType.Register (gtype, typeof (InstantiationTest));
			Console.WriteLine ("Instantiating using managed constructor");
			new InstantiationTest ("Managed Instantiation Test").ShowAll ();
			Console.WriteLine ("Managed Instantiation complete");
			Console.WriteLine ("Instantiating using unmanaged construction");
			IntPtr handle = g_object_new (gtype.Val, "title", "Unmanaged Instantiation Test", IntPtr.Zero);
			gtk_widget_show (handle);
			Console.WriteLine ("Unmanaged Instantiation complete");
			Application.Run ();
			return 0;
		}


		public InstantiationTest (IntPtr raw) : base (raw)
		{
			Console.WriteLine ("IntPtr ctor invoked");
			DefaultWidth = 400;
			DefaultHeight = 200;
		}

		public InstantiationTest (string title) : base (title)
		{
			DefaultWidth = 200;
			DefaultHeight = 400;
		}

		protected override bool OnDeleteEvent (Gdk.Event ev)
		{
			Application.Quit ();
			return true;
		}

	}
}