gtk: Fix TreeView.GetTooltipContext method signature (bxc#14678)

The x and y parameters of gtk_tree_view_get_tooltip_context() are marked
as inout in the Gtk+ docs, so we need to mark them as ref.
cairo: fix leak when Context object is finalized

When the finalizer calls Dispose(), disposing is false, it means that
CairoDebug traces should be printed, but the reference count on the
native context should still be decreased. Otherwise a real leak
would appear, as the native context would never be freed when the
managed object is GCed.
gtk: fix Application to be more robust when embedding mono

When embedding mono, Environment.GetCommandLineArgs() would not return
an array with any element.

Reported in the mailing list, by Vardar Sahin.
Revert "gtk: Mark the Cairo.Context in Widget.Drawn as owned"

This reverts commit 21bfaa7a9d84218e01529a7b9af28085f6e68306.

After fixing the memory leak when finalizing a Context object in the
previous commit, native crashes would happen when using a Gtk#-based
app. The reason is that this commit tried to fix the leak with the wrong
approach of marking the CairoContext as owned. This avoided the leak by
not incrementing the reference count, but now that the leak is fixed,
cairo_destroy is called one time too much.

The CairoContext passed in the Draw signal is not marked as
transfer-ownership=full in GObject-Introspection metadata. So unmarking
this as owned fixes the "potential double-free" assertion that was
causing the crash.
generator: Dispose ownable method parameters in VM callback (bxc#237)

Some virtual methods are passed a native object that is wrapped in an
IDisposable managed object, which is then passed on to the managed
overrides. We need to dispose those objects as soon as possible,
otherwise their native counterpart will not be freed until the next
garbage collection. Requiring the overrides to dispose them would be
cumbersome and error-prone.

Those parameters will now be disposed in a finally {...} block, after
the virtual method has returned. This means that overrides should not
keep a reference to such a parameter outside of the scope of the method,
as it will be diposed when the method returns.

This change only affects Cairo.Context parameter for now, but it was
particularly needed for them, as they could happily hold on to tens of
MBs of memory until the next garbage collection.
Merge pull request #89 from knocte/master

glib: fix IntPtr.Zero being dereferenced in GLib.Value.ToBoxed()
Merge pull request #90 from knocte/embedded

gtk: fix Application to be more robust when embedding mono
glib: Make all DllImports in custom code use a common const

This way there's less redundancy, and if the library name changes in the
future, it will be changed only in one place.

Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
glib: Avoid doing the same cast twice in KeyFile.ToData

The cast from UIntPtr to int can fail at runtime, but if your config
file is more than 2^31 bytes, you probably have bigger problems...
generator: Fix small typo in a comment in LPUGen.cs
glib: Remove obsolete Argv-related methods in Marshaller

The ArgvToArrayPtr and ArrayPtrToArgv have been marked obsolete since
2004, and removing them allows us to remove some more code.
Use GLib.Marshaller.Free instead of calling g_free directly

Using the GLib.Marshaller.Free method means we don't need to have the
g_free function definition duplicated all over the place.
glib: Avoid unnecessary qualifier in Marshaller.PtrToStringArrayGFree
glib: Use Marshaller methods in Argv for g_malloc and g_free
generator: Fix indentation in Signal.cs

Only whitespace changes, no real code change.
generator: Dispose ownable parameters in signal callbacks (bxc#237)

A similar situation to what is described in commit e48ac63d54c4 also
happens with signal callbacks: some signals are passed a native object
that is wrapped in an IDisposable managed object, which is then passed
as an argument to the signal handler. We need to dispose those objects
when the signal handler is done.

Those parameters will now be disposed in a finally {...} block, after
the signal handler has returned. This means that handlers should not
keep a reference to such a parameter, as it will be disposed right after
they return.

This change only affects the Cairo.Context parameter of the Widget.Drawn
signal, but it was badly needed, as shown by the Pixbuf demo in the
GtkDemo sample, which was leaking tens of MBs of memory.
sample: Add sample that uses only cairo and writes image files

The sample writes the same PNG file over and over, with some pauses in
between iterations. Some indicative numbers are written to the console,
to help track performance and memory usage.

Feel free to add more elaborate drawing to this sample, to exercise more
of the cairo API.
cairo: Throw ObjectDisposedException after an object has been disposed

Potentially all these IDisposable classes could be used after being
disposed, which would result in native crashes. We now do an explicit
check and throw an exception in managed land when the object has been
disposed.

This is particularly useful because:
 a/ the native crashes are quite obscure, there no indication that
you're using a disposed object
 b/ Gtk# is passing Context instances to user methods, and disposes them
when the method returns. So if the user code keeps a reference to the
Context, there a good chance it will try to use it after it's disposed.

Other changes in this patch include:
 * Renaming a parameter to be more consistent with the other subsequent
ctor called.
 * Replacing implementation of some [Obsolete()] methods with the call
to the methods they were replaced with, to avoid redundancy and the
need for more CheckDisposed() calls than necessary.
 * Throw ArgumentException when receiving an IntPtr.Zero as a handle,
as a way to protect ourselves from wrapping invalid native pointers,
and throwing ObjectDisposedExceptions because the object was invalid in
the first place.

Signed-off-by: Bertrand Lorentz <bertrand.lorentz@gmail.com>
build: Fix typo in sample/Makefile.am
cairo: Fix remaining leaks when finalizer gets called

Apply same finalizer leak fix to the rest of IDisposable-ownership
cairo classes as the one recently committed for Cairo.Context[1].

[1] https://github.com/mono/gtk-sharp/commit/41eeecbf9a6d8