/* dash-entry.c generated by valac 0.16.1, the Vala compiler
* generated from dash-entry.vala, do not modify */
/* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 4 -*-
*
* Copyright (C) 2012 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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 .
*
* Authors: Michael Terry
*/
/* Vala's vapi for gtk3 is broken for lookup_color (it forgets the out keyword) */
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define TYPE_FADABLE (fadable_get_type ())
#define FADABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FADABLE, Fadable))
#define IS_FADABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FADABLE))
#define FADABLE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_FADABLE, FadableIface))
typedef struct _Fadable Fadable;
typedef struct _FadableIface FadableIface;
#define TYPE_FADE_TRACKER (fade_tracker_get_type ())
#define FADE_TRACKER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FADE_TRACKER, FadeTracker))
#define FADE_TRACKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FADE_TRACKER, FadeTrackerClass))
#define IS_FADE_TRACKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FADE_TRACKER))
#define IS_FADE_TRACKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FADE_TRACKER))
#define FADE_TRACKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FADE_TRACKER, FadeTrackerClass))
typedef struct _FadeTracker FadeTracker;
typedef struct _FadeTrackerClass FadeTrackerClass;
#define TYPE_DASH_ENTRY (dash_entry_get_type ())
#define DASH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_DASH_ENTRY, DashEntry))
#define DASH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DASH_ENTRY, DashEntryClass))
#define IS_DASH_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_DASH_ENTRY))
#define IS_DASH_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DASH_ENTRY))
#define DASH_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DASH_ENTRY, DashEntryClass))
typedef struct _DashEntry DashEntry;
typedef struct _DashEntryClass DashEntryClass;
typedef struct _DashEntryPrivate DashEntryPrivate;
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _pango_font_description_free0(var) ((var == NULL) ? NULL : (var = (pango_font_description_free (var), NULL)))
struct _FadableIface {
GTypeInterface parent_iface;
FadeTracker* (*get_fade_tracker) (Fadable* self);
void (*set_fade_tracker) (Fadable* self, FadeTracker* value);
};
struct _DashEntry {
GtkEntry parent_instance;
DashEntryPrivate * priv;
};
struct _DashEntryClass {
GtkEntryClass parent_class;
};
struct _DashEntryPrivate {
gchar* _constant_placeholder_text;
FadeTracker* _fade_tracker;
};
static gpointer dash_entry_parent_class = NULL;
static FadableIface* dash_entry_fadable_parent_iface = NULL;
gboolean gtk_style_context_lookup_color (GtkStyleContext* ctx, const gchar* color_name, GdkRGBA* color);
GType fade_tracker_get_type (void) G_GNUC_CONST;
GType fadable_get_type (void) G_GNUC_CONST;
GType dash_entry_get_type (void) G_GNUC_CONST;
#define DASH_ENTRY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_DASH_ENTRY, DashEntryPrivate))
enum {
DASH_ENTRY_DUMMY_PROPERTY,
DASH_ENTRY_CONSTANT_PLACEHOLDER_TEXT,
DASH_ENTRY_FADE_TRACKER
};
static gboolean dash_entry_real_draw (GtkWidget* base, cairo_t* c);
FadeTracker* fadable_get_fade_tracker (Fadable* self);
gdouble fade_tracker_get_alpha (FadeTracker* self);
const gchar* dash_entry_get_constant_placeholder_text (DashEntry* self);
static void dash_entry_draw_prompt_text (DashEntry* self, cairo_t* c);
static void dash_entry_changed_cb (DashEntry* self);
static void dash_entry_enable_arrow (DashEntry* self, gboolean enabled);
static void dash_entry_icon_press_cb (DashEntry* self);
DashEntry* dash_entry_new (void);
DashEntry* dash_entry_construct (GType object_type);
void dash_entry_set_constant_placeholder_text (DashEntry* self, const gchar* value);
static GObject * dash_entry_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
FadeTracker* fade_tracker_new (GtkWidget* widget);
FadeTracker* fade_tracker_construct (GType object_type, GtkWidget* widget);
void fadable_set_fade_tracker (Fadable* self, FadeTracker* value);
static void _dash_entry_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self);
static void _dash_entry_icon_press_cb_gtk_entry_icon_press (GtkEntry* _sender, GtkEntryIconPosition p0, GdkEvent* p1, gpointer self);
static void dash_entry_finalize (GObject* obj);
static void _vala_dash_entry_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec);
static void _vala_dash_entry_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec);
static gboolean dash_entry_real_draw (GtkWidget* base, cairo_t* c) {
DashEntry * self;
gboolean result = FALSE;
cairo_t* _tmp0_;
cairo_t* _tmp1_;
cairo_t* _tmp2_;
cairo_t* _tmp3_;
cairo_t* _tmp4_;
FadeTracker* _tmp5_;
FadeTracker* _tmp6_;
gdouble _tmp7_;
gdouble _tmp8_;
cairo_t* _tmp9_;
gboolean _tmp10_ = FALSE;
guint16 _tmp11_ = 0U;
gboolean _tmp15_;
self = (DashEntry*) base;
g_return_val_if_fail (c != NULL, FALSE);
_tmp0_ = c;
cairo_save (_tmp0_);
_tmp1_ = c;
cairo_push_group (_tmp1_);
_tmp2_ = c;
GTK_WIDGET_CLASS (dash_entry_parent_class)->draw ((GtkWidget*) GTK_ENTRY (self), _tmp2_);
_tmp3_ = c;
cairo_pop_group_to_source (_tmp3_);
_tmp4_ = c;
_tmp5_ = fadable_get_fade_tracker ((Fadable*) self);
_tmp6_ = _tmp5_;
_tmp7_ = fade_tracker_get_alpha (_tmp6_);
_tmp8_ = _tmp7_;
cairo_paint_with_alpha (_tmp4_, _tmp8_);
_tmp9_ = c;
cairo_restore (_tmp9_);
_tmp11_ = gtk_entry_get_text_length ((GtkEntry*) self);
if (((gint) _tmp11_) == 0) {
const gchar* _tmp12_;
gint _tmp13_;
gint _tmp14_;
_tmp12_ = self->priv->_constant_placeholder_text;
_tmp13_ = strlen (_tmp12_);
_tmp14_ = _tmp13_;
_tmp10_ = _tmp14_ > 0;
} else {
_tmp10_ = FALSE;
}
_tmp15_ = _tmp10_;
if (_tmp15_) {
cairo_t* _tmp16_;
_tmp16_ = c;
dash_entry_draw_prompt_text (self, _tmp16_);
}
result = FALSE;
return result;
}
static gpointer _g_object_ref0 (gpointer self) {
return self ? g_object_ref (self) : NULL;
}
static void dash_entry_draw_prompt_text (DashEntry* self, cairo_t* c) {
gint x = 0;
gint y = 0;
gint _tmp0_ = 0;
gint _tmp1_ = 0;
cairo_t* _tmp2_;
gint _tmp3_;
gint _tmp4_;
GdkRGBA fg = {0};
GtkStyleContext* _tmp5_ = NULL;
GtkStyleContext* _tmp6_;
GtkStyleContext* context;
GtkStyleContext* _tmp7_;
GdkRGBA _tmp8_ = {0};
gboolean _tmp9_ = FALSE;
cairo_t* _tmp10_;
GdkRGBA _tmp11_;
gdouble _tmp12_;
GdkRGBA _tmp13_;
gdouble _tmp14_;
GdkRGBA _tmp15_;
gdouble _tmp16_;
GdkRGBA _tmp17_;
gdouble _tmp18_;
const gchar* _tmp19_;
PangoLayout* _tmp20_ = NULL;
PangoLayout* layout;
PangoFontDescription* _tmp21_ = NULL;
PangoFontDescription* _tmp22_;
cairo_t* _tmp23_;
g_return_if_fail (self != NULL);
g_return_if_fail (c != NULL);
gtk_entry_get_layout_offsets ((GtkEntry*) self, &_tmp0_, &_tmp1_);
x = _tmp0_;
y = _tmp1_;
_tmp2_ = c;
_tmp3_ = x;
_tmp4_ = y;
cairo_move_to (_tmp2_, (gdouble) _tmp3_, (gdouble) _tmp4_);
memset (&fg, 0, sizeof (GdkRGBA));
_tmp5_ = gtk_widget_get_style_context ((GtkWidget*) self);
_tmp6_ = _g_object_ref0 (_tmp5_);
context = _tmp6_;
_tmp7_ = context;
_tmp9_ = gtk_style_context_lookup_color (_tmp7_, "placeholder_text_color", &_tmp8_);
fg = _tmp8_;
if (!_tmp9_) {
gdk_rgba_parse (&fg, "#ccc");
}
_tmp10_ = c;
_tmp11_ = fg;
_tmp12_ = _tmp11_.red;
_tmp13_ = fg;
_tmp14_ = _tmp13_.green;
_tmp15_ = fg;
_tmp16_ = _tmp15_.blue;
_tmp17_ = fg;
_tmp18_ = _tmp17_.alpha;
cairo_set_source_rgba (_tmp10_, _tmp12_, _tmp14_, _tmp16_, _tmp18_);
_tmp19_ = self->priv->_constant_placeholder_text;
_tmp20_ = gtk_widget_create_pango_layout ((GtkWidget*) self, _tmp19_);
layout = _tmp20_;
_tmp21_ = pango_font_description_from_string ("Ubuntu 16");
_tmp22_ = _tmp21_;
pango_layout_set_font_description (layout, _tmp22_);
_pango_font_description_free0 (_tmp22_);
_tmp23_ = c;
pango_cairo_show_layout (_tmp23_, layout);
_g_object_unref0 (layout);
_g_object_unref0 (context);
}
static void dash_entry_changed_cb (DashEntry* self) {
guint16 _tmp0_ = 0U;
g_return_if_fail (self != NULL);
_tmp0_ = gtk_entry_get_text_length ((GtkEntry*) self);
dash_entry_enable_arrow (self, ((gint) _tmp0_) != 0);
}
static void dash_entry_icon_press_cb (DashEntry* self) {
g_return_if_fail (self != NULL);
g_signal_emit_by_name ((GtkEntry*) self, "activate");
}
static void dash_entry_enable_arrow (DashEntry* self, gboolean enabled) {
gboolean _tmp0_;
g_return_if_fail (self != NULL);
_tmp0_ = enabled;
if (_tmp0_) {
gchar* _tmp1_ = NULL;
gchar* _tmp2_;
GFile* _tmp3_ = NULL;
GFile* _tmp4_;
GFile* file;
GFile* _tmp5_;
GFileIcon* _tmp6_;
GFileIcon* icon;
GFileIcon* _tmp7_;
_tmp1_ = g_build_filename (PKGDATADIR, "arrow_right.png", NULL, NULL);
_tmp2_ = _tmp1_;
_tmp3_ = g_file_new_for_path (_tmp2_);
_tmp4_ = _tmp3_;
_g_free0 (_tmp2_);
file = _tmp4_;
_tmp5_ = file;
_tmp6_ = (GFileIcon*) g_file_icon_new (_tmp5_);
icon = _tmp6_;
_tmp7_ = icon;
gtk_entry_set_icon_from_gicon ((GtkEntry*) self, GTK_ENTRY_ICON_SECONDARY, (GIcon*) _tmp7_);
_g_object_unref0 (icon);
_g_object_unref0 (file);
} else {
gtk_entry_set_icon_from_gicon ((GtkEntry*) self, GTK_ENTRY_ICON_SECONDARY, NULL);
}
}
DashEntry* dash_entry_construct (GType object_type) {
DashEntry * self = NULL;
self = (DashEntry*) g_object_new (object_type, NULL);
return self;
}
DashEntry* dash_entry_new (void) {
return dash_entry_construct (TYPE_DASH_ENTRY);
}
const gchar* dash_entry_get_constant_placeholder_text (DashEntry* self) {
const gchar* result;
const gchar* _tmp0_;
g_return_val_if_fail (self != NULL, NULL);
_tmp0_ = self->priv->_constant_placeholder_text;
result = _tmp0_;
return result;
}
void dash_entry_set_constant_placeholder_text (DashEntry* self, const gchar* value) {
const gchar* _tmp0_;
gchar* _tmp1_;
g_return_if_fail (self != NULL);
_tmp0_ = value;
_tmp1_ = g_strdup (_tmp0_);
_g_free0 (self->priv->_constant_placeholder_text);
self->priv->_constant_placeholder_text = _tmp1_;
g_object_notify ((GObject *) self, "constant-placeholder-text");
}
static FadeTracker* dash_entry_real_get_fade_tracker (Fadable* base) {
FadeTracker* result;
DashEntry* self;
FadeTracker* _tmp0_;
self = (DashEntry*) base;
_tmp0_ = self->priv->_fade_tracker;
result = _tmp0_;
return result;
}
static void dash_entry_real_set_fade_tracker (Fadable* base, FadeTracker* value) {
DashEntry* self;
FadeTracker* _tmp0_;
FadeTracker* _tmp1_;
self = (DashEntry*) base;
_tmp0_ = value;
_tmp1_ = _g_object_ref0 (_tmp0_);
_g_object_unref0 (self->priv->_fade_tracker);
self->priv->_fade_tracker = _tmp1_;
g_object_notify ((GObject *) self, "fade-tracker");
}
static void _dash_entry_changed_cb_gtk_editable_changed (GtkEditable* _sender, gpointer self) {
dash_entry_changed_cb (self);
}
static void _dash_entry_icon_press_cb_gtk_entry_icon_press (GtkEntry* _sender, GtkEntryIconPosition p0, GdkEvent* p1, gpointer self) {
dash_entry_icon_press_cb (self);
}
static GObject * dash_entry_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
GObject * obj;
GObjectClass * parent_class;
DashEntry * self;
FadeTracker* _tmp0_;
FadeTracker* _tmp1_;
PangoFontDescription* _tmp2_ = NULL;
PangoFontDescription* _tmp3_;
parent_class = G_OBJECT_CLASS (dash_entry_parent_class);
obj = parent_class->constructor (type, n_construct_properties, construct_properties);
self = DASH_ENTRY (obj);
_tmp0_ = fade_tracker_new ((GtkWidget*) self);
_tmp1_ = _tmp0_;
fadable_set_fade_tracker ((Fadable*) self, _tmp1_);
_g_object_unref0 (_tmp1_);
gtk_entry_set_icon_activatable ((GtkEntry*) self, GTK_ENTRY_ICON_SECONDARY, TRUE);
g_signal_connect_object ((GtkEditable*) self, "changed", (GCallback) _dash_entry_changed_cb_gtk_editable_changed, self, 0);
g_signal_connect_object ((GtkEntry*) self, "icon-press", (GCallback) _dash_entry_icon_press_cb_gtk_entry_icon_press, self, 0);
_tmp2_ = pango_font_description_from_string ("Ubuntu 14");
_tmp3_ = _tmp2_;
gtk_widget_override_font ((GtkWidget*) self, _tmp3_);
_pango_font_description_free0 (_tmp3_);
return obj;
}
static void dash_entry_class_init (DashEntryClass * klass) {
dash_entry_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (DashEntryPrivate));
GTK_WIDGET_CLASS (klass)->draw = dash_entry_real_draw;
G_OBJECT_CLASS (klass)->get_property = _vala_dash_entry_get_property;
G_OBJECT_CLASS (klass)->set_property = _vala_dash_entry_set_property;
G_OBJECT_CLASS (klass)->constructor = dash_entry_constructor;
G_OBJECT_CLASS (klass)->finalize = dash_entry_finalize;
g_object_class_install_property (G_OBJECT_CLASS (klass), DASH_ENTRY_CONSTANT_PLACEHOLDER_TEXT, g_param_spec_string ("constant-placeholder-text", "constant-placeholder-text", "constant-placeholder-text", NULL, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (G_OBJECT_CLASS (klass), DASH_ENTRY_FADE_TRACKER, g_param_spec_object ("fade-tracker", "fade-tracker", "fade-tracker", TYPE_FADE_TRACKER, G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB | G_PARAM_READABLE | G_PARAM_WRITABLE));
}
static void dash_entry_fadable_interface_init (FadableIface * iface) {
dash_entry_fadable_parent_iface = g_type_interface_peek_parent (iface);
iface->get_fade_tracker = dash_entry_real_get_fade_tracker;
iface->set_fade_tracker = dash_entry_real_set_fade_tracker;
}
static void dash_entry_instance_init (DashEntry * self) {
self->priv = DASH_ENTRY_GET_PRIVATE (self);
}
static void dash_entry_finalize (GObject* obj) {
DashEntry * self;
self = DASH_ENTRY (obj);
_g_free0 (self->priv->_constant_placeholder_text);
_g_object_unref0 (self->priv->_fade_tracker);
G_OBJECT_CLASS (dash_entry_parent_class)->finalize (obj);
}
GType dash_entry_get_type (void) {
static volatile gsize dash_entry_type_id__volatile = 0;
if (g_once_init_enter (&dash_entry_type_id__volatile)) {
static const GTypeInfo g_define_type_info = { sizeof (DashEntryClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dash_entry_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DashEntry), 0, (GInstanceInitFunc) dash_entry_instance_init, NULL };
static const GInterfaceInfo fadable_info = { (GInterfaceInitFunc) dash_entry_fadable_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
GType dash_entry_type_id;
dash_entry_type_id = g_type_register_static (GTK_TYPE_ENTRY, "DashEntry", &g_define_type_info, 0);
g_type_add_interface_static (dash_entry_type_id, TYPE_FADABLE, &fadable_info);
g_once_init_leave (&dash_entry_type_id__volatile, dash_entry_type_id);
}
return dash_entry_type_id__volatile;
}
static void _vala_dash_entry_get_property (GObject * object, guint property_id, GValue * value, GParamSpec * pspec) {
DashEntry * self;
self = DASH_ENTRY (object);
switch (property_id) {
case DASH_ENTRY_CONSTANT_PLACEHOLDER_TEXT:
g_value_set_string (value, dash_entry_get_constant_placeholder_text (self));
break;
case DASH_ENTRY_FADE_TRACKER:
g_value_set_object (value, fadable_get_fade_tracker ((Fadable*) self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void _vala_dash_entry_set_property (GObject * object, guint property_id, const GValue * value, GParamSpec * pspec) {
DashEntry * self;
self = DASH_ENTRY (object);
switch (property_id) {
case DASH_ENTRY_CONSTANT_PLACEHOLDER_TEXT:
dash_entry_set_constant_placeholder_text (self, g_value_get_string (value));
break;
case DASH_ENTRY_FADE_TRACKER:
fadable_set_fade_tracker ((Fadable*) self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}