/* contacts-menu-button.c generated by valac 0.20.1.71-45f6, the Vala compiler
 * generated from contacts-menu-button.vala, do not modify */

/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
 * Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

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


#define CONTACTS_TYPE_MENU_BUTTON (contacts_menu_button_get_type ())
#define CONTACTS_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_MENU_BUTTON, ContactsMenuButton))
#define CONTACTS_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_MENU_BUTTON, ContactsMenuButtonClass))
#define CONTACTS_IS_MENU_BUTTON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_MENU_BUTTON))
#define CONTACTS_IS_MENU_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_MENU_BUTTON))
#define CONTACTS_MENU_BUTTON_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_MENU_BUTTON, ContactsMenuButtonClass))

typedef struct _ContactsMenuButton ContactsMenuButton;
typedef struct _ContactsMenuButtonClass ContactsMenuButtonClass;
typedef struct _ContactsMenuButtonPrivate ContactsMenuButtonPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))

#define CONTACTS_TYPE_WINDOW (contacts_window_get_type ())
#define CONTACTS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTACTS_TYPE_WINDOW, ContactsWindow))
#define CONTACTS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTACTS_TYPE_WINDOW, ContactsWindowClass))
#define CONTACTS_IS_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTACTS_TYPE_WINDOW))
#define CONTACTS_IS_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTACTS_TYPE_WINDOW))
#define CONTACTS_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CONTACTS_TYPE_WINDOW, ContactsWindowClass))

typedef struct _ContactsWindow ContactsWindow;
typedef struct _ContactsWindowClass ContactsWindowClass;

struct _ContactsMenuButton {
	GtkToggleButton parent_instance;
	ContactsMenuButtonPrivate * priv;
};

struct _ContactsMenuButtonClass {
	GtkToggleButtonClass parent_class;
};

struct _ContactsMenuButtonPrivate {
	GtkMenu* menu;
	gboolean popup_in_progress;
};


static gpointer contacts_menu_button_parent_class = NULL;

GType contacts_menu_button_get_type (void) G_GNUC_CONST;
#define CONTACTS_MENU_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CONTACTS_TYPE_MENU_BUTTON, ContactsMenuButtonPrivate))
enum  {
	CONTACTS_MENU_BUTTON_DUMMY_PROPERTY
};
void contacts_menu_button_set_menu (ContactsMenuButton* self, GtkMenu* menu);
ContactsMenuButton* contacts_menu_button_new (const gchar* label);
ContactsMenuButton* contacts_menu_button_construct (GType object_type, const gchar* label);
static void contacts_menu_button_menu_position (ContactsMenuButton* self, GtkMenu* menu, gint* x, gint* y, gboolean* push_in);
GType contacts_window_get_type (void) G_GNUC_CONST;
static void contacts_menu_button_real_toggled (GtkToggleButton* base);
static void _contacts_menu_button_menu_position_gtk_menu_position_func (GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer self);
static gboolean contacts_menu_button_real_button_press_event (GtkWidget* base, GdkEventButton* event);
static gboolean contacts_menu_button_real_button_release_event (GtkWidget* base, GdkEventButton* event);
static void contacts_menu_button_menu_show (ContactsMenuButton* self, GtkWidget* menu);
static void contacts_menu_button_menu_hide (ContactsMenuButton* self, GtkWidget* menu);
static void contacts_menu_button_menu_detach (ContactsMenuButton* self, GtkMenu* menu);
static void _contacts_menu_button_menu_show_gtk_widget_show (GtkWidget* _sender, gpointer self);
static void _contacts_menu_button_menu_hide_gtk_widget_hide (GtkWidget* _sender, gpointer self);
static void _contacts_menu_button_menu_detach_gtk_menu_detach_func (GtkWidget* attach_widget, GtkMenu* menu);
static gboolean contacts_menu_button_real_draw (GtkWidget* base, cairo_t* cr);
static void contacts_menu_button_finalize (GObject* obj);


ContactsMenuButton* contacts_menu_button_construct (GType object_type, const gchar* label) {
	ContactsMenuButton * self = NULL;
	GtkLabel* label_widget = NULL;
	const gchar* _tmp0_ = NULL;
	GtkLabel* _tmp1_ = NULL;
	GtkArrow* arrow = NULL;
	GtkArrow* _tmp2_ = NULL;
	GtkGrid* grid = NULL;
	GtkGrid* _tmp3_ = NULL;
	g_return_val_if_fail (label != NULL, NULL);
	self = (ContactsMenuButton*) g_object_new (object_type, NULL);
	gtk_button_set_focus_on_click ((GtkButton*) self, FALSE);
	_tmp0_ = label;
	_tmp1_ = (GtkLabel*) gtk_label_new (_tmp0_);
	g_object_ref_sink (_tmp1_);
	label_widget = _tmp1_;
	_tmp2_ = (GtkArrow*) gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
	g_object_ref_sink (_tmp2_);
	arrow = _tmp2_;
	_tmp3_ = (GtkGrid*) gtk_grid_new ();
	g_object_ref_sink (_tmp3_);
	grid = _tmp3_;
	gtk_orientable_set_orientation ((GtkOrientable*) grid, GTK_ORIENTATION_HORIZONTAL);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) label_widget);
	gtk_container_add ((GtkContainer*) grid, (GtkWidget*) arrow);
	gtk_grid_set_column_spacing (grid, (guint) 3);
	gtk_widget_set_hexpand ((GtkWidget*) grid, TRUE);
	gtk_widget_set_halign ((GtkWidget*) grid, GTK_ALIGN_CENTER);
	gtk_container_add ((GtkContainer*) self, (GtkWidget*) grid);
	_g_object_unref0 (grid);
	_g_object_unref0 (arrow);
	_g_object_unref0 (label_widget);
	return self;
}


ContactsMenuButton* contacts_menu_button_new (const gchar* label) {
	return contacts_menu_button_construct (CONTACTS_TYPE_MENU_BUTTON, label);
}


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


static void contacts_menu_button_menu_position (ContactsMenuButton* self, GtkMenu* menu, gint* x, gint* y, gboolean* push_in) {
	gint _vala_x = 0;
	gint _vala_y = 0;
	gboolean _vala_push_in = FALSE;
	GtkAllocation allocation = {0};
	GtkAllocation _tmp0_ = {0};
	gint sx = 0;
	gint sy = 0;
	gboolean _tmp1_ = FALSE;
	GdkWindow* _tmp8_ = NULL;
	gint _tmp9_ = 0;
	gint _tmp10_ = 0;
	gint _tmp11_ = 0;
	gint _tmp12_ = 0;
	GtkRequisition menu_req = {0};
	GdkRectangle monitor = {0};
	GtkMenu* _tmp13_ = NULL;
	GtkRequisition _tmp14_ = {0};
	GtkTextDirection _tmp15_ = 0;
	gint _tmp22_ = 0;
	GdkWindow* window = NULL;
	GdkWindow* _tmp23_ = NULL;
	GdkWindow* _tmp24_ = NULL;
	GdkScreen* screen = NULL;
	GdkScreen* _tmp25_ = NULL;
	GdkScreen* _tmp26_ = NULL;
	gint monitor_num = 0;
	GdkScreen* _tmp27_ = NULL;
	GdkWindow* _tmp28_ = NULL;
	gint _tmp29_ = 0;
	gint _tmp30_ = 0;
	GdkScreen* _tmp31_ = NULL;
	gint _tmp32_ = 0;
	GdkRectangle _tmp33_ = {0};
	gint _tmp34_ = 0;
	GdkRectangle _tmp35_ = {0};
	gint _tmp36_ = 0;
	GdkRectangle _tmp52_ = {0};
	gint _tmp53_ = 0;
	GdkRectangle _tmp54_ = {0};
	gint _tmp55_ = 0;
	gint _tmp56_ = 0;
	GtkAllocation _tmp57_ = {0};
	gint _tmp58_ = 0;
	GtkRequisition _tmp59_ = {0};
	gint _tmp60_ = 0;
	GtkMenu* _tmp88_ = NULL;
	gint _tmp89_ = 0;
	ContactsWindow* toplevel = NULL;
	GtkMenu* _tmp90_ = NULL;
	GtkWidget* _tmp91_ = NULL;
	ContactsWindow* _tmp92_ = NULL;
	gboolean _tmp93_ = FALSE;
	ContactsWindow* _tmp94_ = NULL;
	gboolean _tmp97_ = FALSE;
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
	gtk_widget_get_allocation ((GtkWidget*) self, &_tmp0_);
	allocation = _tmp0_;
	sx = 0;
	sy = 0;
	_tmp1_ = gtk_widget_get_has_window ((GtkWidget*) self);
	if (!_tmp1_) {
		gint _tmp2_ = 0;
		GtkAllocation _tmp3_ = {0};
		gint _tmp4_ = 0;
		gint _tmp5_ = 0;
		GtkAllocation _tmp6_ = {0};
		gint _tmp7_ = 0;
		_tmp2_ = sx;
		_tmp3_ = allocation;
		_tmp4_ = _tmp3_.x;
		sx = _tmp2_ + _tmp4_;
		_tmp5_ = sy;
		_tmp6_ = allocation;
		_tmp7_ = _tmp6_.y;
		sy = _tmp5_ + _tmp7_;
	}
	_tmp8_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp9_ = sx;
	_tmp10_ = sy;
	gdk_window_get_root_coords (_tmp8_, _tmp9_, _tmp10_, &_tmp11_, &_tmp12_);
	sx = _tmp11_;
	sy = _tmp12_;
	_tmp13_ = menu;
	gtk_widget_get_preferred_size ((GtkWidget*) _tmp13_, NULL, &_tmp14_);
	menu_req = _tmp14_;
	_tmp15_ = gtk_widget_get_direction ((GtkWidget*) self);
	if (_tmp15_ == GTK_TEXT_DIR_LTR) {
		gint _tmp16_ = 0;
		_tmp16_ = sx;
		_vala_x = _tmp16_;
	} else {
		gint _tmp17_ = 0;
		GtkAllocation _tmp18_ = {0};
		gint _tmp19_ = 0;
		GtkRequisition _tmp20_ = {0};
		gint _tmp21_ = 0;
		_tmp17_ = sx;
		_tmp18_ = allocation;
		_tmp19_ = _tmp18_.width;
		_tmp20_ = menu_req;
		_tmp21_ = _tmp20_.width;
		_vala_x = (_tmp17_ + _tmp19_) - _tmp21_;
	}
	_tmp22_ = sy;
	_vala_y = _tmp22_;
	_tmp23_ = gtk_widget_get_window ((GtkWidget*) self);
	_tmp24_ = _g_object_ref0 (_tmp23_);
	window = _tmp24_;
	_tmp25_ = gtk_widget_get_screen ((GtkWidget*) self);
	_tmp26_ = _g_object_ref0 (_tmp25_);
	screen = _tmp26_;
	_tmp27_ = screen;
	_tmp28_ = window;
	_tmp29_ = gdk_screen_get_monitor_at_window (_tmp27_, _tmp28_);
	monitor_num = _tmp29_;
	_tmp30_ = monitor_num;
	if (_tmp30_ < 0) {
		monitor_num = 0;
	}
	_tmp31_ = screen;
	_tmp32_ = monitor_num;
	gdk_screen_get_monitor_geometry (_tmp31_, _tmp32_, &_tmp33_);
	monitor = _tmp33_;
	_tmp34_ = _vala_x;
	_tmp35_ = monitor;
	_tmp36_ = _tmp35_.x;
	if (_tmp34_ < _tmp36_) {
		GdkRectangle _tmp37_ = {0};
		gint _tmp38_ = 0;
		_tmp37_ = monitor;
		_tmp38_ = _tmp37_.x;
		_vala_x = _tmp38_;
	} else {
		gint _tmp39_ = 0;
		GtkRequisition _tmp40_ = {0};
		gint _tmp41_ = 0;
		GdkRectangle _tmp42_ = {0};
		gint _tmp43_ = 0;
		GdkRectangle _tmp44_ = {0};
		gint _tmp45_ = 0;
		_tmp39_ = _vala_x;
		_tmp40_ = menu_req;
		_tmp41_ = _tmp40_.width;
		_tmp42_ = monitor;
		_tmp43_ = _tmp42_.x;
		_tmp44_ = monitor;
		_tmp45_ = _tmp44_.width;
		if ((_tmp39_ + _tmp41_) > (_tmp43_ + _tmp45_)) {
			GdkRectangle _tmp46_ = {0};
			gint _tmp47_ = 0;
			GdkRectangle _tmp48_ = {0};
			gint _tmp49_ = 0;
			GtkRequisition _tmp50_ = {0};
			gint _tmp51_ = 0;
			_tmp46_ = monitor;
			_tmp47_ = _tmp46_.x;
			_tmp48_ = monitor;
			_tmp49_ = _tmp48_.width;
			_tmp50_ = menu_req;
			_tmp51_ = _tmp50_.width;
			_vala_x = (_tmp47_ + _tmp49_) - _tmp51_;
		}
	}
	_tmp52_ = monitor;
	_tmp53_ = _tmp52_.y;
	_tmp54_ = monitor;
	_tmp55_ = _tmp54_.height;
	_tmp56_ = _vala_y;
	_tmp57_ = allocation;
	_tmp58_ = _tmp57_.height;
	_tmp59_ = menu_req;
	_tmp60_ = _tmp59_.height;
	if ((((_tmp53_ + _tmp55_) - _tmp56_) - _tmp58_) >= _tmp60_) {
		gint _tmp61_ = 0;
		GtkAllocation _tmp62_ = {0};
		gint _tmp63_ = 0;
		_tmp61_ = _vala_y;
		_tmp62_ = allocation;
		_tmp63_ = _tmp62_.height;
		_vala_y = _tmp61_ + _tmp63_;
	} else {
		gint _tmp64_ = 0;
		GdkRectangle _tmp65_ = {0};
		gint _tmp66_ = 0;
		GtkRequisition _tmp67_ = {0};
		gint _tmp68_ = 0;
		_tmp64_ = _vala_y;
		_tmp65_ = monitor;
		_tmp66_ = _tmp65_.y;
		_tmp67_ = menu_req;
		_tmp68_ = _tmp67_.height;
		if ((_tmp64_ - _tmp66_) >= _tmp68_) {
			gint _tmp69_ = 0;
			GtkRequisition _tmp70_ = {0};
			gint _tmp71_ = 0;
			_tmp69_ = _vala_y;
			_tmp70_ = menu_req;
			_tmp71_ = _tmp70_.height;
			_vala_y = _tmp69_ - _tmp71_;
		} else {
			GdkRectangle _tmp72_ = {0};
			gint _tmp73_ = 0;
			GdkRectangle _tmp74_ = {0};
			gint _tmp75_ = 0;
			gint _tmp76_ = 0;
			GtkAllocation _tmp77_ = {0};
			gint _tmp78_ = 0;
			gint _tmp79_ = 0;
			GdkRectangle _tmp80_ = {0};
			gint _tmp81_ = 0;
			_tmp72_ = monitor;
			_tmp73_ = _tmp72_.y;
			_tmp74_ = monitor;
			_tmp75_ = _tmp74_.height;
			_tmp76_ = _vala_y;
			_tmp77_ = allocation;
			_tmp78_ = _tmp77_.height;
			_tmp79_ = _vala_y;
			_tmp80_ = monitor;
			_tmp81_ = _tmp80_.y;
			if ((((_tmp73_ + _tmp75_) - _tmp76_) - _tmp78_) > (_tmp79_ - _tmp81_)) {
				gint _tmp82_ = 0;
				GtkAllocation _tmp83_ = {0};
				gint _tmp84_ = 0;
				_tmp82_ = _vala_y;
				_tmp83_ = allocation;
				_tmp84_ = _tmp83_.height;
				_vala_y = _tmp82_ + _tmp84_;
			} else {
				gint _tmp85_ = 0;
				GtkRequisition _tmp86_ = {0};
				gint _tmp87_ = 0;
				_tmp85_ = _vala_y;
				_tmp86_ = menu_req;
				_tmp87_ = _tmp86_.height;
				_vala_y = _tmp85_ - _tmp87_;
			}
		}
	}
	_tmp88_ = menu;
	_tmp89_ = monitor_num;
	gtk_menu_set_monitor (_tmp88_, _tmp89_);
	_tmp90_ = menu;
	_tmp91_ = gtk_widget_get_parent ((GtkWidget*) _tmp90_);
	_tmp92_ = _g_object_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (_tmp91_, CONTACTS_TYPE_WINDOW) ? ((ContactsWindow*) _tmp91_) : NULL);
	toplevel = _tmp92_;
	_tmp94_ = toplevel;
	if (_tmp94_ != NULL) {
		ContactsWindow* _tmp95_ = NULL;
		gboolean _tmp96_ = FALSE;
		_tmp95_ = toplevel;
		_tmp96_ = gtk_widget_get_visible ((GtkWidget*) _tmp95_);
		_tmp93_ = !_tmp96_;
	} else {
		_tmp93_ = FALSE;
	}
	_tmp97_ = _tmp93_;
	if (_tmp97_) {
		ContactsWindow* _tmp98_ = NULL;
		_tmp98_ = toplevel;
		gtk_window_set_type_hint ((GtkWindow*) _tmp98_, GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU);
	}
	_vala_push_in = FALSE;
	_g_object_unref0 (toplevel);
	_g_object_unref0 (screen);
	_g_object_unref0 (window);
	if (x) {
		*x = _vala_x;
	}
	if (y) {
		*y = _vala_y;
	}
	if (push_in) {
		*push_in = _vala_push_in;
	}
}


static void _contacts_menu_button_menu_position_gtk_menu_position_func (GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer self) {
	contacts_menu_button_menu_position (self, menu, x, y, push_in);
}


static void contacts_menu_button_real_toggled (GtkToggleButton* base) {
	ContactsMenuButton * self;
	GtkStyleContext* context = NULL;
	GtkStyleContext* _tmp0_ = NULL;
	GtkStyleContext* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	self = (ContactsMenuButton*) base;
	_tmp0_ = gtk_widget_get_style_context ((GtkWidget*) self);
	_tmp1_ = _g_object_ref0 (_tmp0_);
	context = _tmp1_;
	_tmp2_ = gtk_toggle_button_get_active ((GtkToggleButton*) self);
	if (_tmp2_) {
		gboolean _tmp3_ = FALSE;
		GtkStyleContext* _tmp6_ = NULL;
		GtkStyleContext* _tmp7_ = NULL;
		_tmp3_ = self->priv->popup_in_progress;
		if (!_tmp3_) {
			GtkMenu* _tmp4_ = NULL;
			guint32 _tmp5_ = 0U;
			g_signal_emit_by_name (self, "popup");
			_tmp4_ = self->priv->menu;
			_tmp5_ = gtk_get_current_event_time ();
			gtk_menu_popup (_tmp4_, NULL, NULL, _contacts_menu_button_menu_position_gtk_menu_position_func, self, (guint) 1, _tmp5_);
		}
		_tmp6_ = context;
		gtk_style_context_add_class (_tmp6_, GTK_STYLE_CLASS_MENUBAR);
		_tmp7_ = context;
		gtk_style_context_add_class (_tmp7_, GTK_STYLE_CLASS_MENUITEM);
	} else {
		GtkStyleContext* _tmp8_ = NULL;
		GtkStyleContext* _tmp9_ = NULL;
		GtkMenu* _tmp10_ = NULL;
		_tmp8_ = context;
		gtk_style_context_remove_class (_tmp8_, GTK_STYLE_CLASS_MENUBAR);
		_tmp9_ = context;
		gtk_style_context_remove_class (_tmp9_, GTK_STYLE_CLASS_MENUITEM);
		_tmp10_ = self->priv->menu;
		gtk_menu_popdown (_tmp10_);
	}
	gtk_widget_reset_style ((GtkWidget*) self);
	_g_object_unref0 (context);
}


static gboolean contacts_menu_button_real_button_press_event (GtkWidget* base, GdkEventButton* event) {
	ContactsMenuButton * self;
	gboolean result = FALSE;
	GtkWidget* ewidget = NULL;
	GtkWidget* _tmp0_ = NULL;
	GtkWidget* _tmp1_ = NULL;
	gboolean _tmp2_ = FALSE;
	GtkWidget* _tmp3_ = NULL;
	gboolean _tmp5_ = FALSE;
	GtkMenu* _tmp6_ = NULL;
	guint32 _tmp7_ = 0U;
	self = (ContactsMenuButton*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = gtk_get_event_widget ((GdkEvent*) (event));
	_tmp1_ = _g_object_ref0 (_tmp0_);
	ewidget = _tmp1_;
	_tmp3_ = ewidget;
	if (_tmp3_ != G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WIDGET, GtkWidget)) {
		_tmp2_ = TRUE;
	} else {
		gboolean _tmp4_ = FALSE;
		_tmp4_ = gtk_toggle_button_get_active ((GtkToggleButton*) self);
		_tmp2_ = _tmp4_;
	}
	_tmp5_ = _tmp2_;
	if (_tmp5_) {
		result = FALSE;
		_g_object_unref0 (ewidget);
		return result;
	}
	g_signal_emit_by_name (self, "popup");
	_tmp6_ = self->priv->menu;
	_tmp7_ = gtk_get_current_event_time ();
	gtk_menu_popup (_tmp6_, NULL, NULL, _contacts_menu_button_menu_position_gtk_menu_position_func, self, (guint) 1, _tmp7_);
	gtk_toggle_button_set_active ((GtkToggleButton*) self, TRUE);
	self->priv->popup_in_progress = TRUE;
	result = TRUE;
	_g_object_unref0 (ewidget);
	return result;
}


static gboolean contacts_menu_button_real_button_release_event (GtkWidget* base, GdkEventButton* event) {
	ContactsMenuButton * self;
	gboolean result = FALSE;
	gboolean popup_in_progress_saved = FALSE;
	gboolean _tmp0_ = FALSE;
	GtkWidget* ewidget = NULL;
	GtkWidget* _tmp1_ = NULL;
	GtkWidget* _tmp2_ = NULL;
	gboolean _tmp3_ = FALSE;
	gboolean _tmp4_ = FALSE;
	GtkWidget* _tmp5_ = NULL;
	gboolean _tmp7_ = FALSE;
	gboolean _tmp9_ = FALSE;
	GtkWidget* _tmp11_ = NULL;
	self = (ContactsMenuButton*) base;
	g_return_val_if_fail (event != NULL, FALSE);
	_tmp0_ = self->priv->popup_in_progress;
	popup_in_progress_saved = _tmp0_;
	self->priv->popup_in_progress = FALSE;
	_tmp1_ = gtk_get_event_widget ((GdkEvent*) (event));
	_tmp2_ = _g_object_ref0 (_tmp1_);
	ewidget = _tmp2_;
	_tmp5_ = ewidget;
	if (_tmp5_ == G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WIDGET, GtkWidget)) {
		gboolean _tmp6_ = FALSE;
		_tmp6_ = popup_in_progress_saved;
		_tmp4_ = !_tmp6_;
	} else {
		_tmp4_ = FALSE;
	}
	_tmp7_ = _tmp4_;
	if (_tmp7_) {
		gboolean _tmp8_ = FALSE;
		_tmp8_ = gtk_toggle_button_get_active ((GtkToggleButton*) self);
		_tmp3_ = _tmp8_;
	} else {
		_tmp3_ = FALSE;
	}
	_tmp9_ = _tmp3_;
	if (_tmp9_) {
		GtkMenu* _tmp10_ = NULL;
		_tmp10_ = self->priv->menu;
		gtk_menu_popdown (_tmp10_);
		result = TRUE;
		_g_object_unref0 (ewidget);
		return result;
	}
	_tmp11_ = ewidget;
	if (_tmp11_ != G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_WIDGET, GtkWidget)) {
		GtkMenu* _tmp12_ = NULL;
		_tmp12_ = self->priv->menu;
		gtk_menu_popdown (_tmp12_);
		result = TRUE;
		_g_object_unref0 (ewidget);
		return result;
	}
	result = FALSE;
	_g_object_unref0 (ewidget);
	return result;
}


static void contacts_menu_button_menu_show (ContactsMenuButton* self, GtkWidget* menu) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
	self->priv->popup_in_progress = TRUE;
	gtk_toggle_button_set_active ((GtkToggleButton*) self, TRUE);
	self->priv->popup_in_progress = FALSE;
}


static void contacts_menu_button_menu_hide (ContactsMenuButton* self, GtkWidget* menu) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
	gtk_toggle_button_set_active ((GtkToggleButton*) self, FALSE);
}


static void contacts_menu_button_menu_detach (ContactsMenuButton* self, GtkMenu* menu) {
	g_return_if_fail (self != NULL);
	g_return_if_fail (menu != NULL);
}


static void _contacts_menu_button_menu_show_gtk_widget_show (GtkWidget* _sender, gpointer self) {
	contacts_menu_button_menu_show (self, _sender);
}


static void _contacts_menu_button_menu_hide_gtk_widget_hide (GtkWidget* _sender, gpointer self) {
	contacts_menu_button_menu_hide (self, _sender);
}


static void _contacts_menu_button_menu_detach_gtk_menu_detach_func (GtkWidget* attach_widget, GtkMenu* menu) {
	contacts_menu_button_menu_detach (attach_widget, menu);
}


void contacts_menu_button_set_menu (ContactsMenuButton* self, GtkMenu* menu) {
	GtkMenu* _tmp0_ = NULL;
	GtkMenu* _tmp6_ = NULL;
	GtkMenu* _tmp7_ = NULL;
	GtkMenu* _tmp8_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = self->priv->menu;
	if (_tmp0_ != NULL) {
		GtkMenu* _tmp1_ = NULL;
		guint _tmp2_ = 0U;
		GtkMenu* _tmp3_ = NULL;
		guint _tmp4_ = 0U;
		GtkMenu* _tmp5_ = NULL;
		_tmp1_ = self->priv->menu;
		g_signal_parse_name ("show", GTK_TYPE_WIDGET, &_tmp2_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkWidget*) _tmp1_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp2_, 0, NULL, (GCallback) _contacts_menu_button_menu_show_gtk_widget_show, self);
		_tmp3_ = self->priv->menu;
		g_signal_parse_name ("hide", GTK_TYPE_WIDGET, &_tmp4_, NULL, FALSE);
		g_signal_handlers_disconnect_matched ((GtkWidget*) _tmp3_, G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, _tmp4_, 0, NULL, (GCallback) _contacts_menu_button_menu_hide_gtk_widget_hide, self);
		_tmp5_ = self->priv->menu;
		gtk_menu_detach (_tmp5_);
	}
	_tmp6_ = menu;
	_tmp7_ = _g_object_ref0 (_tmp6_);
	_g_object_unref0 (self->priv->menu);
	self->priv->menu = _tmp7_;
	_tmp8_ = self->priv->menu;
	if (_tmp8_ != NULL) {
		GtkMenu* _tmp9_ = NULL;
		GtkMenu* _tmp10_ = NULL;
		GtkMenu* _tmp11_ = NULL;
		_tmp9_ = self->priv->menu;
		g_signal_connect_object ((GtkWidget*) _tmp9_, "show", (GCallback) _contacts_menu_button_menu_show_gtk_widget_show, self, 0);
		_tmp10_ = self->priv->menu;
		g_signal_connect_object ((GtkWidget*) _tmp10_, "hide", (GCallback) _contacts_menu_button_menu_hide_gtk_widget_hide, self, 0);
		_tmp11_ = self->priv->menu;
		gtk_menu_attach_to_widget (_tmp11_, (GtkWidget*) self, _contacts_menu_button_menu_detach_gtk_menu_detach_func);
	}
}


static gboolean contacts_menu_button_real_draw (GtkWidget* base, cairo_t* cr) {
	ContactsMenuButton * self;
	gboolean result = FALSE;
	cairo_t* _tmp0_ = NULL;
	self = (ContactsMenuButton*) base;
	g_return_val_if_fail (cr != NULL, FALSE);
	_tmp0_ = cr;
	GTK_WIDGET_CLASS (contacts_menu_button_parent_class)->draw ((GtkWidget*) G_TYPE_CHECK_INSTANCE_CAST (self, GTK_TYPE_TOGGLE_BUTTON, GtkToggleButton), _tmp0_);
	result = FALSE;
	return result;
}


static void contacts_menu_button_class_init (ContactsMenuButtonClass * klass) {
	contacts_menu_button_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (ContactsMenuButtonPrivate));
	GTK_TOGGLE_BUTTON_CLASS (klass)->toggled = contacts_menu_button_real_toggled;
	GTK_WIDGET_CLASS (klass)->button_press_event = contacts_menu_button_real_button_press_event;
	GTK_WIDGET_CLASS (klass)->button_release_event = contacts_menu_button_real_button_release_event;
	GTK_WIDGET_CLASS (klass)->draw = contacts_menu_button_real_draw;
	G_OBJECT_CLASS (klass)->finalize = contacts_menu_button_finalize;
	g_signal_new ("popup", CONTACTS_TYPE_MENU_BUTTON, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
}


static void contacts_menu_button_instance_init (ContactsMenuButton * self) {
	self->priv = CONTACTS_MENU_BUTTON_GET_PRIVATE (self);
}


static void contacts_menu_button_finalize (GObject* obj) {
	ContactsMenuButton * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, CONTACTS_TYPE_MENU_BUTTON, ContactsMenuButton);
	contacts_menu_button_set_menu (self, NULL);
	_g_object_unref0 (self->priv->menu);
	G_OBJECT_CLASS (contacts_menu_button_parent_class)->finalize (obj);
}


GType contacts_menu_button_get_type (void) {
	static volatile gsize contacts_menu_button_type_id__volatile = 0;
	if (g_once_init_enter (&contacts_menu_button_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (ContactsMenuButtonClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) contacts_menu_button_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (ContactsMenuButton), 0, (GInstanceInitFunc) contacts_menu_button_instance_init, NULL };
		GType contacts_menu_button_type_id;
		contacts_menu_button_type_id = g_type_register_static (GTK_TYPE_TOGGLE_BUTTON, "ContactsMenuButton", &g_define_type_info, 0);
		g_once_init_leave (&contacts_menu_button_type_id__volatile, contacts_menu_button_type_id);
	}
	return contacts_menu_button_type_id__volatile;
}



