/* handle.c generated by valac 0.34.6, the Vala compiler
 * generated from handle.vala, do not modify */

/* vim:set et sts=4 sw=4:
 *
 * ibus - The Input Bus
 *
 * Copyright(c) 2011-2016 Peng Huang <shawn.p.huang@gmail.com>
 * Copyright(c) 2016 Takao Fujiwara <takao.fujiwara1@gmail.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gdk/gdk.h>
#include <cairo.h>
#include <string.h>
#include <float.h>
#include <math.h>


#define TYPE_HANDLE (handle_get_type ())
#define HANDLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HANDLE, Handle))
#define HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HANDLE, HandleClass))
#define IS_HANDLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HANDLE))
#define IS_HANDLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HANDLE))
#define HANDLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HANDLE, HandleClass))

typedef struct _Handle Handle;
typedef struct _HandleClass HandleClass;
typedef struct _HandlePrivate HandlePrivate;
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

struct _Handle {
	GtkEventBox parent_instance;
	HandlePrivate * priv;
};

struct _HandleClass {
	GtkEventBoxClass parent_class;
};

struct _HandlePrivate {
	gboolean m_move_begined;
	GdkRectangle m_workarea;
	GdkPoint m_press_pos;
};


static gpointer handle_parent_class = NULL;

GType handle_get_type (void) G_GNUC_CONST;
#define HANDLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_HANDLE, HandlePrivate))
enum  {
	HANDLE_DUMMY_PROPERTY
};
Handle* handle_new (void);
Handle* handle_construct (GType object_type);
static void handle_real_realize (GtkWidget* base);
static gboolean handle_real_button_press_event (GtkWidget* base, GdkEventButton* event);
static gboolean handle_real_button_release_event (GtkWidget* base, GdkEventButton* event);
static gboolean handle_real_motion_notify_event (GtkWidget* base, GdkEventMotion* event);
static gboolean handle_real_draw (GtkWidget* base, cairo_t* cr);
static void handle_finalize (GObject* obj);


static gpointer _g_object_ref0 (gpointer self) {
	return self ? g_object_ref (self) : NULL;
}


Handle* handle_construct (GType object_type) {
	Handle * self = NULL;
	GdkEventMask mask = 0;
	GtkCssProvider* css_provider = NULL;
	GtkCssProvider* _tmp0_ = NULL;
	GtkStyleContext* context = NULL;
	GtkStyleContext* _tmp3_ = NULL;
	GtkStyleContext* _tmp4_ = NULL;
	GError * _inner_error_ = NULL;
	self = (Handle*) g_object_new (object_type, "name", "IBusHandle", NULL);
	gtk_widget_set_size_request ((GtkWidget*) self, 6, -1);
	mask = ((GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK) | GDK_BUTTON_RELEASE_MASK) | GDK_BUTTON1_MOTION_MASK;
	gtk_widget_set_events ((GtkWidget*) self, (gint) mask);
	self->priv->m_move_begined = FALSE;
	_tmp0_ = gtk_css_provider_new ();
	css_provider = _tmp0_;
	{
		gtk_css_provider_load_from_data (css_provider, "#IBusHandle { background-color: gray }", (gssize) -1, &_inner_error_);
		if (G_UNLIKELY (_inner_error_ != NULL)) {
			goto __catch2_g_error;
		}
	}
	goto __finally2;
	__catch2_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp1_ = NULL;
		const gchar* _tmp2_ = NULL;
		_error_ = _inner_error_;
		_inner_error_ = NULL;
		_tmp1_ = _error_;
		_tmp2_ = _tmp1_->message;
		g_warning ("handle.vala:53: Parse error in Handle: %s", _tmp2_);
		_g_error_free0 (_error_);
	}
	__finally2:
	if (G_UNLIKELY (_inner_error_ != NULL)) {
		_g_object_unref0 (css_provider);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	_tmp3_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp4_ = _g_object_ref0 (_tmp3_);
	context = _tmp4_;
	gtk_style_context_add_provider (context, (GtkStyleProvider*) css_provider, (guint) GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
	_g_object_unref0 (context);
	_g_object_unref0 (css_provider);
	return self;
}


Handle* handle_new (void) {
	return handle_construct (TYPE_HANDLE);
}


static void handle_real_realize (GtkWidget* base) {
	Handle * self;
	self = (Handle*) base;
	GTK_WIDGET_CLASS (handle_parent_class)->realize ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, gtk_event_box_get_type (), GtkEventBox));
}


static gboolean handle_real_button_press_event (GtkWidget* base, GdkEventButton* event) {
	Handle * self;
	gboolean result = FALSE;
	GdkEventButton* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	GdkRectangle _tmp2_ = {0};
	GdkRectangle _tmp3_ = {0};
	gint x = 0;
	gint y = 0;
	GtkWindow* toplevel = NULL;
	GtkWidget* _tmp104_ = NULL;
	GtkWindow* _tmp105_ = NULL;
	GtkWindow* _tmp106_ = NULL;
	gint _tmp107_ = 0;
	gint _tmp108_ = 0;
	GdkEventButton* _tmp109_ = NULL;
	gdouble _tmp110_ = 0.0;
	gint _tmp111_ = 0;
	GdkEventButton* _tmp112_ = NULL;
	gdouble _tmp113_ = 0.0;
	gint _tmp114_ = 0;
	self = (Handle*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = event;
	_tmp1_ = _tmp0_->button;
	if (_tmp1_ != ((guint) 1)) {
		result = FALSE;
		return result;
	}
	memset (&_tmp2_, 0, sizeof (GdkRectangle));
	_tmp2_.x = 0;
	_tmp2_.y = 0;
	_tmp2_.width = G_MAXINT;
	_tmp2_.height = G_MAXINT;
	self->priv->m_workarea = _tmp2_;
	_tmp3_ = self->priv->m_workarea;
	{
		gboolean _tmp4_ = FALSE;
		_tmp4_ = TRUE;
		while (TRUE) {
			GdkWindow* root = NULL;
			GdkWindow* _tmp5_ = NULL;
			GdkWindow* _tmp6_ = NULL;
			GdkAtom property = 0U;
			GdkAtom _tmp7_ = 0U;
			GdkAtom type = 0U;
			GdkAtom _tmp8_ = 0U;
			GdkAtom actual_type = 0U;
			gint format = 0;
			guchar* data = NULL;
			gint data_length1 = 0;
			gint _data_size_ = 0;
			gboolean _result_ = FALSE;
			GdkWindow* _tmp9_ = NULL;
			GdkAtom _tmp10_ = 0U;
			GdkAtom _tmp11_ = 0U;
			GdkAtom _tmp12_ = 0U;
			gint _tmp13_ = 0;
			guint8* _tmp14_ = NULL;
			gint _tmp15_ = 0;
			gboolean _tmp16_ = FALSE;
			gboolean _tmp17_ = FALSE;
			gboolean _tmp18_ = FALSE;
			gboolean _tmp19_ = FALSE;
			gboolean _tmp20_ = FALSE;
			gint index = 0;
			guchar* _tmp25_ = NULL;
			gint _tmp25__length1 = 0;
			guchar _tmp26_ = '\0';
			guchar* _tmp27_ = NULL;
			gint _tmp27__length1 = 0;
			guchar _tmp28_ = '\0';
			guchar* _tmp29_ = NULL;
			gint _tmp29__length1 = 0;
			guchar _tmp30_ = '\0';
			guchar* _tmp31_ = NULL;
			gint _tmp31__length1 = 0;
			guchar _tmp32_ = '\0';
			GdkAtom _tmp33_ = 0U;
			GdkAtom _tmp34_ = 0U;
			GdkWindow* _tmp35_ = NULL;
			GdkAtom _tmp36_ = 0U;
			GdkAtom _tmp37_ = 0U;
			GdkAtom _tmp38_ = 0U;
			gint _tmp39_ = 0;
			guint8* _tmp40_ = NULL;
			gint _tmp41_ = 0;
			gboolean _tmp42_ = FALSE;
			gboolean _tmp43_ = FALSE;
			gboolean _tmp44_ = FALSE;
			gboolean _tmp45_ = FALSE;
			gboolean _tmp46_ = FALSE;
			gint i = 0;
			gint _tmp52_ = 0;
			guchar* _tmp53_ = NULL;
			gint _tmp53__length1 = 0;
			gint _tmp54_ = 0;
			guchar _tmp55_ = '\0';
			guchar* _tmp56_ = NULL;
			gint _tmp56__length1 = 0;
			gint _tmp57_ = 0;
			guchar _tmp58_ = '\0';
			guchar* _tmp59_ = NULL;
			gint _tmp59__length1 = 0;
			gint _tmp60_ = 0;
			guchar _tmp61_ = '\0';
			guchar* _tmp62_ = NULL;
			gint _tmp62__length1 = 0;
			gint _tmp63_ = 0;
			guchar _tmp64_ = '\0';
			gint _tmp65_ = 0;
			guchar* _tmp66_ = NULL;
			gint _tmp66__length1 = 0;
			gint _tmp67_ = 0;
			guchar _tmp68_ = '\0';
			guchar* _tmp69_ = NULL;
			gint _tmp69__length1 = 0;
			gint _tmp70_ = 0;
			guchar _tmp71_ = '\0';
			guchar* _tmp72_ = NULL;
			gint _tmp72__length1 = 0;
			gint _tmp73_ = 0;
			guchar _tmp74_ = '\0';
			guchar* _tmp75_ = NULL;
			gint _tmp75__length1 = 0;
			gint _tmp76_ = 0;
			guchar _tmp77_ = '\0';
			gint _tmp78_ = 0;
			guchar* _tmp79_ = NULL;
			gint _tmp79__length1 = 0;
			gint _tmp80_ = 0;
			guchar _tmp81_ = '\0';
			guchar* _tmp82_ = NULL;
			gint _tmp82__length1 = 0;
			gint _tmp83_ = 0;
			guchar _tmp84_ = '\0';
			guchar* _tmp85_ = NULL;
			gint _tmp85__length1 = 0;
			gint _tmp86_ = 0;
			guchar _tmp87_ = '\0';
			guchar* _tmp88_ = NULL;
			gint _tmp88__length1 = 0;
			gint _tmp89_ = 0;
			guchar _tmp90_ = '\0';
			gint _tmp91_ = 0;
			guchar* _tmp92_ = NULL;
			gint _tmp92__length1 = 0;
			gint _tmp93_ = 0;
			guchar _tmp94_ = '\0';
			guchar* _tmp95_ = NULL;
			gint _tmp95__length1 = 0;
			gint _tmp96_ = 0;
			guchar _tmp97_ = '\0';
			guchar* _tmp98_ = NULL;
			gint _tmp98__length1 = 0;
			gint _tmp99_ = 0;
			guchar _tmp100_ = '\0';
			guchar* _tmp101_ = NULL;
			gint _tmp101__length1 = 0;
			gint _tmp102_ = 0;
			guchar _tmp103_ = '\0';
			if (!_tmp4_) {
				if (!FALSE) {
					break;
				}
			}
			_tmp4_ = FALSE;
			_tmp5_ = gdk_get_default_root_window ();
			_tmp6_ = _g_object_ref0 (_tmp5_);
			root = _tmp6_;
			_tmp7_ = gdk_atom_intern ("_NET_CURRENT_DESKTOP", FALSE);
			property = _tmp7_;
			_tmp8_ = gdk_atom_intern ("CARDINAL", FALSE);
			type = _tmp8_;
			_tmp9_ = root;
			_tmp10_ = property;
			_tmp11_ = type;
			_tmp16_ = gdk_property_get (_tmp9_, _tmp10_, _tmp11_, (gulong) 0, (gulong) G_MAXLONG, 0, &_tmp12_, &_tmp13_, &_tmp15_, &_tmp14_);
			actual_type = _tmp12_;
			format = _tmp13_;
			data = (g_free (data), NULL);
			data = _tmp14_;
			data_length1 = _tmp15_;
			_data_size_ = data_length1;
			_result_ = _tmp16_;
			_tmp20_ = _result_;
			if (!_tmp20_) {
				_tmp19_ = TRUE;
			} else {
				GdkAtom _tmp21_ = 0U;
				GdkAtom _tmp22_ = 0U;
				_tmp21_ = actual_type;
				_tmp22_ = type;
				_tmp19_ = _tmp21_ != _tmp22_;
			}
			if (_tmp19_) {
				_tmp18_ = TRUE;
			} else {
				gint _tmp23_ = 0;
				_tmp23_ = format;
				_tmp18_ = _tmp23_ != 32;
			}
			if (_tmp18_) {
				_tmp17_ = TRUE;
			} else {
				guchar* _tmp24_ = NULL;
				gint _tmp24__length1 = 0;
				_tmp24_ = data;
				_tmp24__length1 = data_length1;
				_tmp17_ = _tmp24__length1 != 4;
			}
			if (_tmp17_) {
				data = (g_free (data), NULL);
				_g_object_unref0 (root);
				break;
			}
			_tmp25_ = data;
			_tmp25__length1 = data_length1;
			_tmp26_ = _tmp25_[0];
			_tmp27_ = data;
			_tmp27__length1 = data_length1;
			_tmp28_ = _tmp27_[1];
			_tmp29_ = data;
			_tmp29__length1 = data_length1;
			_tmp30_ = _tmp29_[2];
			_tmp31_ = data;
			_tmp31__length1 = data_length1;
			_tmp32_ = _tmp31_[3];
			index = (gint) (((_tmp26_ | (_tmp28_ << 8)) | (_tmp30_ << 16)) | (_tmp32_ << 24));
			_tmp33_ = gdk_atom_intern ("_NET_WORKAREA", FALSE);
			property = _tmp33_;
			_tmp34_ = gdk_atom_intern ("CARDINAL", FALSE);
			type = _tmp34_;
			_tmp35_ = root;
			_tmp36_ = property;
			_tmp37_ = type;
			_tmp42_ = gdk_property_get (_tmp35_, _tmp36_, _tmp37_, (gulong) 0, (gulong) G_MAXLONG, 0, &_tmp38_, &_tmp39_, &_tmp41_, &_tmp40_);
			actual_type = _tmp38_;
			format = _tmp39_;
			data = (g_free (data), NULL);
			data = _tmp40_;
			data_length1 = _tmp41_;
			_data_size_ = data_length1;
			_result_ = _tmp42_;
			_tmp46_ = _result_;
			if (!_tmp46_) {
				_tmp45_ = TRUE;
			} else {
				GdkAtom _tmp47_ = 0U;
				GdkAtom _tmp48_ = 0U;
				_tmp47_ = actual_type;
				_tmp48_ = type;
				_tmp45_ = _tmp47_ != _tmp48_;
			}
			if (_tmp45_) {
				_tmp44_ = TRUE;
			} else {
				gint _tmp49_ = 0;
				_tmp49_ = format;
				_tmp44_ = _tmp49_ != 32;
			}
			if (_tmp44_) {
				_tmp43_ = TRUE;
			} else {
				guchar* _tmp50_ = NULL;
				gint _tmp50__length1 = 0;
				gint _tmp51_ = 0;
				_tmp50_ = data;
				_tmp50__length1 = data_length1;
				_tmp51_ = index;
				_tmp43_ = _tmp50__length1 < ((_tmp51_ + 1) * 16);
			}
			if (_tmp43_) {
				data = (g_free (data), NULL);
				_g_object_unref0 (root);
				break;
			}
			_tmp52_ = index;
			i = (_tmp52_ * 4) * 4;
			_tmp53_ = data;
			_tmp53__length1 = data_length1;
			_tmp54_ = i;
			_tmp55_ = _tmp53_[_tmp54_];
			_tmp56_ = data;
			_tmp56__length1 = data_length1;
			_tmp57_ = i;
			_tmp58_ = _tmp56_[_tmp57_ + 1];
			_tmp59_ = data;
			_tmp59__length1 = data_length1;
			_tmp60_ = i;
			_tmp61_ = _tmp59_[_tmp60_ + 2];
			_tmp62_ = data;
			_tmp62__length1 = data_length1;
			_tmp63_ = i;
			_tmp64_ = _tmp62_[_tmp63_ + 3];
			self->priv->m_workarea.x = (gint) (((_tmp55_ | (_tmp58_ << 8)) | (_tmp61_ << 16)) | (_tmp64_ << 24));
			_tmp65_ = i;
			i = _tmp65_ + 4;
			_tmp66_ = data;
			_tmp66__length1 = data_length1;
			_tmp67_ = i;
			_tmp68_ = _tmp66_[_tmp67_];
			_tmp69_ = data;
			_tmp69__length1 = data_length1;
			_tmp70_ = i;
			_tmp71_ = _tmp69_[_tmp70_ + 1];
			_tmp72_ = data;
			_tmp72__length1 = data_length1;
			_tmp73_ = i;
			_tmp74_ = _tmp72_[_tmp73_ + 2];
			_tmp75_ = data;
			_tmp75__length1 = data_length1;
			_tmp76_ = i;
			_tmp77_ = _tmp75_[_tmp76_ + 3];
			self->priv->m_workarea.y = (gint) (((_tmp68_ | (_tmp71_ << 8)) | (_tmp74_ << 16)) | (_tmp77_ << 24));
			_tmp78_ = i;
			i = _tmp78_ + 4;
			_tmp79_ = data;
			_tmp79__length1 = data_length1;
			_tmp80_ = i;
			_tmp81_ = _tmp79_[_tmp80_];
			_tmp82_ = data;
			_tmp82__length1 = data_length1;
			_tmp83_ = i;
			_tmp84_ = _tmp82_[_tmp83_ + 1];
			_tmp85_ = data;
			_tmp85__length1 = data_length1;
			_tmp86_ = i;
			_tmp87_ = _tmp85_[_tmp86_ + 2];
			_tmp88_ = data;
			_tmp88__length1 = data_length1;
			_tmp89_ = i;
			_tmp90_ = _tmp88_[_tmp89_ + 3];
			self->priv->m_workarea.width = (gint) (((_tmp81_ | (_tmp84_ << 8)) | (_tmp87_ << 16)) | (_tmp90_ << 24));
			_tmp91_ = i;
			i = _tmp91_ + 4;
			_tmp92_ = data;
			_tmp92__length1 = data_length1;
			_tmp93_ = i;
			_tmp94_ = _tmp92_[_tmp93_];
			_tmp95_ = data;
			_tmp95__length1 = data_length1;
			_tmp96_ = i;
			_tmp97_ = _tmp95_[_tmp96_ + 1];
			_tmp98_ = data;
			_tmp98__length1 = data_length1;
			_tmp99_ = i;
			_tmp100_ = _tmp98_[_tmp99_ + 2];
			_tmp101_ = data;
			_tmp101__length1 = data_length1;
			_tmp102_ = i;
			_tmp103_ = _tmp101_[_tmp102_ + 3];
			self->priv->m_workarea.height = (gint) (((_tmp94_ | (_tmp97_ << 8)) | (_tmp100_ << 16)) | (_tmp103_ << 24));
			data = (g_free (data), NULL);
			_g_object_unref0 (root);
		}
	}
	self->priv->m_move_begined = TRUE;
	_tmp104_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp105_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp104_, gtk_window_get_type (), GtkWindow));
	toplevel = _tmp105_;
	_tmp106_ = toplevel;
	gtk_window_get_position (_tmp106_, &_tmp107_, &_tmp108_);
	x = _tmp107_;
	y = _tmp108_;
	_tmp109_ = event;
	_tmp110_ = _tmp109_->x_root;
	_tmp111_ = x;
	self->priv->m_press_pos.x = ((gint) _tmp110_) - _tmp111_;
	_tmp112_ = event;
	_tmp113_ = _tmp112_->y_root;
	_tmp114_ = y;
	self->priv->m_press_pos.y = ((gint) _tmp113_) - _tmp114_;
	g_signal_emit_by_name (self, "move-begin");
	result = TRUE;
	_g_object_unref0 (toplevel);
	return result;
}


static gboolean handle_real_button_release_event (GtkWidget* base, GdkEventButton* event) {
	Handle * self;
	gboolean result = FALSE;
	GdkEventButton* _tmp0_ = NULL;
	guint _tmp1_ = 0U;
	GdkWindow* _tmp2_ = NULL;
	GdkCursor* _tmp3_ = NULL;
	GdkCursor* _tmp4_ = NULL;
	self = (Handle*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = event;
	_tmp1_ = _tmp0_->button;
	if (_tmp1_ != ((guint) 1)) {
		result = FALSE;
		return result;
	}
	self->priv->m_move_begined = FALSE;
	self->priv->m_press_pos.x = 0;
	self->priv->m_press_pos.y = 0;
	_tmp2_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp3_ = gdk_cursor_new (GDK_LEFT_PTR);
	_tmp4_ = _tmp3_;
	gdk_window_set_cursor (_tmp2_, _tmp4_);
	_g_object_unref0 (_tmp4_);
	g_signal_emit_by_name (self, "move-end");
	result = TRUE;
	return result;
}


static gboolean handle_real_motion_notify_event (GtkWidget* base, GdkEventMotion* event) {
	Handle * self;
	gboolean result = FALSE;
	gboolean _tmp0_ = FALSE;
	GtkWindow* toplevel = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkWindow* _tmp2_ = NULL;
	gint x = 0;
	GdkEventMotion* _tmp3_ = NULL;
	gdouble _tmp4_ = 0.0;
	GdkPoint _tmp5_ = {0};
	gint _tmp6_ = 0;
	gint y = 0;
	GdkEventMotion* _tmp7_ = NULL;
	gdouble _tmp8_ = 0.0;
	GdkPoint _tmp9_ = {0};
	gint _tmp10_ = 0;
	gboolean _tmp11_ = FALSE;
	gint _tmp12_ = 0;
	GdkRectangle _tmp13_ = {0};
	gint _tmp14_ = 0;
	gboolean _tmp20_ = FALSE;
	gint _tmp21_ = 0;
	GdkRectangle _tmp22_ = {0};
	gint _tmp23_ = 0;
	gint w = 0;
	gint h = 0;
	GtkWindow* _tmp29_ = NULL;
	gint _tmp30_ = 0;
	gint _tmp31_ = 0;
	gboolean _tmp32_ = FALSE;
	gint _tmp33_ = 0;
	gint _tmp34_ = 0;
	GdkRectangle _tmp35_ = {0};
	gint _tmp36_ = 0;
	GdkRectangle _tmp37_ = {0};
	gint _tmp38_ = 0;
	gboolean _tmp50_ = FALSE;
	gint _tmp51_ = 0;
	gint _tmp52_ = 0;
	GdkRectangle _tmp53_ = {0};
	gint _tmp54_ = 0;
	GdkRectangle _tmp55_ = {0};
	gint _tmp56_ = 0;
	GtkWindow* _tmp68_ = NULL;
	gint _tmp69_ = 0;
	gint _tmp70_ = 0;
	self = (Handle*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = self->priv->m_move_begined;
	if (!_tmp0_) {
		result = FALSE;
		return result;
	}
	_tmp1_ = gtk_widget_get_toplevel ((GtkWidget*) self);
	_tmp2_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_CAST (_tmp1_, gtk_window_get_type (), GtkWindow));
	toplevel = _tmp2_;
	_tmp3_ = event;
	_tmp4_ = _tmp3_->x_root;
	_tmp5_ = self->priv->m_press_pos;
	_tmp6_ = _tmp5_.x;
	x = (gint) (_tmp4_ - _tmp6_);
	_tmp7_ = event;
	_tmp8_ = _tmp7_->y_root;
	_tmp9_ = self->priv->m_press_pos;
	_tmp10_ = _tmp9_.y;
	y = (gint) (_tmp8_ - _tmp10_);
	_tmp12_ = x;
	_tmp13_ = self->priv->m_workarea;
	_tmp14_ = _tmp13_.x;
	if (_tmp12_ < _tmp14_) {
		gint _tmp15_ = 0;
		GdkRectangle _tmp16_ = {0};
		gint _tmp17_ = 0;
		_tmp15_ = x;
		_tmp16_ = self->priv->m_workarea;
		_tmp17_ = _tmp16_.x;
		_tmp11_ = _tmp15_ > (_tmp17_ - 16);
	} else {
		_tmp11_ = FALSE;
	}
	if (_tmp11_) {
		GdkRectangle _tmp18_ = {0};
		gint _tmp19_ = 0;
		_tmp18_ = self->priv->m_workarea;
		_tmp19_ = _tmp18_.x;
		x = _tmp19_;
	}
	_tmp21_ = y;
	_tmp22_ = self->priv->m_workarea;
	_tmp23_ = _tmp22_.y;
	if (_tmp21_ < _tmp23_) {
		gint _tmp24_ = 0;
		GdkRectangle _tmp25_ = {0};
		gint _tmp26_ = 0;
		_tmp24_ = y;
		_tmp25_ = self->priv->m_workarea;
		_tmp26_ = _tmp25_.y;
		_tmp20_ = _tmp24_ > (_tmp26_ - 16);
	} else {
		_tmp20_ = FALSE;
	}
	if (_tmp20_) {
		GdkRectangle _tmp27_ = {0};
		gint _tmp28_ = 0;
		_tmp27_ = self->priv->m_workarea;
		_tmp28_ = _tmp27_.y;
		y = _tmp28_;
	}
	_tmp29_ = toplevel;
	gtk_window_get_size (_tmp29_, &_tmp30_, &_tmp31_);
	w = _tmp30_;
	h = _tmp31_;
	_tmp33_ = x;
	_tmp34_ = w;
	_tmp35_ = self->priv->m_workarea;
	_tmp36_ = _tmp35_.x;
	_tmp37_ = self->priv->m_workarea;
	_tmp38_ = _tmp37_.width;
	if ((_tmp33_ + _tmp34_) > (_tmp36_ + _tmp38_)) {
		gint _tmp39_ = 0;
		gint _tmp40_ = 0;
		GdkRectangle _tmp41_ = {0};
		gint _tmp42_ = 0;
		GdkRectangle _tmp43_ = {0};
		gint _tmp44_ = 0;
		_tmp39_ = x;
		_tmp40_ = w;
		_tmp41_ = self->priv->m_workarea;
		_tmp42_ = _tmp41_.x;
		_tmp43_ = self->priv->m_workarea;
		_tmp44_ = _tmp43_.width;
		_tmp32_ = (_tmp39_ + _tmp40_) < ((_tmp42_ + _tmp44_) + 16);
	} else {
		_tmp32_ = FALSE;
	}
	if (_tmp32_) {
		GdkRectangle _tmp45_ = {0};
		gint _tmp46_ = 0;
		GdkRectangle _tmp47_ = {0};
		gint _tmp48_ = 0;
		gint _tmp49_ = 0;
		_tmp45_ = self->priv->m_workarea;
		_tmp46_ = _tmp45_.x;
		_tmp47_ = self->priv->m_workarea;
		_tmp48_ = _tmp47_.width;
		_tmp49_ = w;
		x = (_tmp46_ + _tmp48_) - _tmp49_;
	}
	_tmp51_ = y;
	_tmp52_ = h;
	_tmp53_ = self->priv->m_workarea;
	_tmp54_ = _tmp53_.y;
	_tmp55_ = self->priv->m_workarea;
	_tmp56_ = _tmp55_.height;
	if ((_tmp51_ + _tmp52_) > (_tmp54_ + _tmp56_)) {
		gint _tmp57_ = 0;
		gint _tmp58_ = 0;
		GdkRectangle _tmp59_ = {0};
		gint _tmp60_ = 0;
		GdkRectangle _tmp61_ = {0};
		gint _tmp62_ = 0;
		_tmp57_ = y;
		_tmp58_ = h;
		_tmp59_ = self->priv->m_workarea;
		_tmp60_ = _tmp59_.y;
		_tmp61_ = self->priv->m_workarea;
		_tmp62_ = _tmp61_.height;
		_tmp50_ = (_tmp57_ + _tmp58_) < ((_tmp60_ + _tmp62_) + 16);
	} else {
		_tmp50_ = FALSE;
	}
	if (_tmp50_) {
		GdkRectangle _tmp63_ = {0};
		gint _tmp64_ = 0;
		GdkRectangle _tmp65_ = {0};
		gint _tmp66_ = 0;
		gint _tmp67_ = 0;
		_tmp63_ = self->priv->m_workarea;
		_tmp64_ = _tmp63_.y;
		_tmp65_ = self->priv->m_workarea;
		_tmp66_ = _tmp65_.height;
		_tmp67_ = w;
		y = (_tmp64_ + _tmp66_) - _tmp67_;
	}
	_tmp68_ = toplevel;
	_tmp69_ = x;
	_tmp70_ = y;
	gtk_window_move (_tmp68_, _tmp69_, _tmp70_);
	result = TRUE;
	_g_object_unref0 (toplevel);
	return result;
}


static gboolean handle_real_draw (GtkWidget* base, cairo_t* cr) {
	Handle * self;
	gboolean result = FALSE;
	cairo_t* _tmp0_ = NULL;
	GdkWindow* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	self = (Handle*) base;
	g_return_val_if_fail (cr != NULL, FALSE);
	_tmp0_ = cr;
	_tmp1_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp2_ = gtk_cairo_should_draw_window (_tmp0_, _tmp1_);
	if (_tmp2_) {
		GtkStyleContext* context = NULL;
		GtkStyleContext* _tmp3_ = NULL;
		GtkStyleContext* _tmp4_ = NULL;
		GtkAllocation allocation = {0};
		GtkAllocation _tmp5_ = {0};
		GtkStyleContext* _tmp6_ = NULL;
		cairo_t* _tmp7_ = NULL;
		GtkAllocation _tmp8_ = {0};
		gint _tmp9_ = 0;
		GtkAllocation _tmp10_ = {0};
		gint _tmp11_ = 0;
		GtkAllocation _tmp12_ = {0};
		gint _tmp13_ = 0;
		GtkAllocation _tmp14_ = {0};
		gint _tmp15_ = 0;
		_tmp3_ = gtk_widget_get_style_context ((GtkWidget*) self);
		_tmp4_ = _g_object_ref0 (_tmp3_);
		context = _tmp4_;
		gtk_widget_get_allocation ((GtkWidget*) self, &_tmp5_);
		allocation = _tmp5_;
		_tmp6_ = context;
		_tmp7_ = cr;
		_tmp8_ = allocation;
		_tmp9_ = _tmp8_.x;
		_tmp10_ = allocation;
		_tmp11_ = _tmp10_.y;
		_tmp12_ = allocation;
		_tmp13_ = _tmp12_.height;
		_tmp14_ = allocation;
		_tmp15_ = _tmp14_.width;
		gtk_render_handle (_tmp6_, _tmp7_, (gdouble) _tmp9_, (gdouble) (_tmp11_ + ((_tmp13_ - 40) / 2)), (gdouble) _tmp15_, 40.0);
		_g_object_unref0 (context);
	}
	result = FALSE;
	return result;
}


static void handle_class_init (HandleClass * klass) {
	handle_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (HandlePrivate));
	((GtkWidgetClass *) klass)->realize = (void (*)(GtkWidget*)) handle_real_realize;
	((GtkWidgetClass *) klass)->button_press_event = (gboolean (*)(GtkWidget*, GdkEventButton*)) handle_real_button_press_event;
	((GtkWidgetClass *) klass)->button_release_event = (gboolean (*)(GtkWidget*, GdkEventButton*)) handle_real_button_release_event;
	((GtkWidgetClass *) klass)->motion_notify_event = (gboolean (*)(GtkWidget*, GdkEventMotion*)) handle_real_motion_notify_event;
	((GtkWidgetClass *) klass)->draw = (gboolean (*)(GtkWidget*, cairo_t*)) handle_real_draw;
	G_OBJECT_CLASS (klass)->finalize = handle_finalize;
	g_signal_new ("move_begin", TYPE_HANDLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
	g_signal_new ("move_end", TYPE_HANDLE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void handle_instance_init (Handle * self) {
	self->priv = HANDLE_GET_PRIVATE (self);
}


static void handle_finalize (GObject* obj) {
	Handle * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_HANDLE, Handle);
	G_OBJECT_CLASS (handle_parent_class)->finalize (obj);
}


GType handle_get_type (void) {
	static volatile gsize handle_type_id__volatile = 0;
	if (g_once_init_enter (&handle_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (HandleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) handle_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Handle), 0, (GInstanceInitFunc) handle_instance_init, NULL };
		GType handle_type_id;
		handle_type_id = g_type_register_static (gtk_event_box_get_type (), "Handle", &g_define_type_info, 0);
		g_once_init_leave (&handle_type_id__volatile, handle_type_id);
	}
	return handle_type_id__volatile;
}



