Added modified signals to both widgets.
GcalDateEntry and GcalTimeEntry now have a ::modified signal.
This commit is contained in:
committed by
Rene A. Viant Moran
parent
c6887e9a37
commit
ba68b831cc
+37
-5
@@ -38,6 +38,14 @@ struct _GcalDateEntryPrivate
|
|||||||
gboolean have_long_year;
|
gboolean have_long_year;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MODIFIED,
|
||||||
|
NUM_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[NUM_SIGNALS] = { 0, };
|
||||||
|
|
||||||
static void gtk_editable_iface_init (GtkEditableInterface *iface);
|
static void gtk_editable_iface_init (GtkEditableInterface *iface);
|
||||||
|
|
||||||
static void gcal_date_entry_constructed (GObject *object);
|
static void gcal_date_entry_constructed (GObject *object);
|
||||||
@@ -70,9 +78,18 @@ gcal_date_entry_class_init (GcalDateEntryClass *klass)
|
|||||||
GObjectClass *object_class;
|
GObjectClass *object_class;
|
||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->constructed = gcal_date_entry_constructed;
|
object_class->constructed = gcal_date_entry_constructed;
|
||||||
|
|
||||||
|
signals[MODIFIED] = g_signal_new ("modified",
|
||||||
|
GCAL_TYPE_DATE_ENTRY,
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GcalDateEntryClass,
|
||||||
|
modified),
|
||||||
|
NULL, NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
0);
|
||||||
|
|
||||||
g_type_class_add_private ((gpointer)klass, sizeof(GcalDateEntryPrivate));
|
g_type_class_add_private ((gpointer)klass, sizeof(GcalDateEntryPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +272,10 @@ gcal_date_entry_insert_text (GtkEditable *editable,
|
|||||||
gchar* unit_string;
|
gchar* unit_string;
|
||||||
const gchar* text;
|
const gchar* text;
|
||||||
|
|
||||||
|
gint new_day;
|
||||||
|
gint new_month;
|
||||||
|
gint new_year;
|
||||||
|
|
||||||
/* making space for new_string */
|
/* making space for new_string */
|
||||||
priv->internal_skip = TRUE;
|
priv->internal_skip = TRUE;
|
||||||
gtk_editable_delete_text (editable,
|
gtk_editable_delete_text (editable,
|
||||||
@@ -270,18 +291,27 @@ gcal_date_entry_insert_text (GtkEditable *editable,
|
|||||||
/* Updating internal data and validating */
|
/* Updating internal data and validating */
|
||||||
text = gtk_entry_get_text (GTK_ENTRY (editable));
|
text = gtk_entry_get_text (GTK_ENTRY (editable));
|
||||||
unit_string = g_strndup (text + priv->day_pos, 2);
|
unit_string = g_strndup (text + priv->day_pos, 2);
|
||||||
priv->day = (guint) g_ascii_strtoull (unit_string, NULL, 10);
|
new_day = (gint) g_ascii_strtoull (unit_string, NULL, 10);
|
||||||
g_free (unit_string);
|
g_free (unit_string);
|
||||||
|
|
||||||
unit_string = g_strndup (text + priv->month_pos, 2);
|
unit_string = g_strndup (text + priv->month_pos, 2);
|
||||||
priv->month = (guint) g_ascii_strtoull (unit_string, NULL, 10);
|
new_month = (gint) g_ascii_strtoull (unit_string, NULL, 10);
|
||||||
g_free (unit_string);
|
g_free (unit_string);
|
||||||
|
|
||||||
unit_string = g_strndup (text + priv->year_pos, (priv->have_long_year ? 4 : 2));
|
unit_string = g_strndup (text + priv->year_pos, (priv->have_long_year ? 4 : 2));
|
||||||
priv->year = (guint) g_ascii_strtoull (unit_string, NULL, 10);
|
new_year = (gint) g_ascii_strtoull (unit_string, NULL, 10);
|
||||||
g_free (unit_string);
|
g_free (unit_string);
|
||||||
|
|
||||||
gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (editable));
|
if (priv->day != new_day ||
|
||||||
|
priv->month != new_month ||
|
||||||
|
priv->year != new_year)
|
||||||
|
{
|
||||||
|
priv->day = new_day;
|
||||||
|
priv->month = new_month;
|
||||||
|
priv->year = new_year;
|
||||||
|
|
||||||
|
gcal_date_entry_validate_and_insert (GCAL_DATE_ENTRY (editable));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +385,8 @@ gcal_date_entry_validate_and_insert (GcalDateEntry *entry)
|
|||||||
gtk_entry_set_text (GTK_ENTRY (entry), tmp);
|
gtk_entry_set_text (GTK_ENTRY (entry), tmp);
|
||||||
priv->internal_skip = FALSE;
|
priv->internal_skip = FALSE;
|
||||||
|
|
||||||
|
g_signal_emit (entry, signals[MODIFIED], 0);
|
||||||
|
|
||||||
g_free (tmp);
|
g_free (tmp);
|
||||||
g_free (tmp1);
|
g_free (tmp1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,9 @@ struct _GcalDateEntry
|
|||||||
struct _GcalDateEntryClass
|
struct _GcalDateEntryClass
|
||||||
{
|
{
|
||||||
GtkEntryClass parent_class;
|
GtkEntryClass parent_class;
|
||||||
|
|
||||||
|
/* signals */
|
||||||
|
void (*modified) (GcalDateEntry *entry);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gcal_date_entry_get_type (void);
|
GType gcal_date_entry_get_type (void);
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ struct _GcalTimeEntryPrivate
|
|||||||
gint minutes;
|
gint minutes;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
MODIFIED,
|
||||||
|
NUM_SIGNALS
|
||||||
|
};
|
||||||
|
|
||||||
|
static guint signals[NUM_SIGNALS] = { 0, };
|
||||||
|
|
||||||
|
|
||||||
static void gtk_editable_iface_init (GtkEditableInterface *iface);
|
static void gtk_editable_iface_init (GtkEditableInterface *iface);
|
||||||
|
|
||||||
static void gcal_time_entry_constructed (GObject *object);
|
static void gcal_time_entry_constructed (GObject *object);
|
||||||
@@ -41,6 +50,10 @@ static void gcal_time_entry_insert_text (GtkEditable
|
|||||||
gint new_text_length,
|
gint new_text_length,
|
||||||
gint *position);
|
gint *position);
|
||||||
|
|
||||||
|
static void gcal_time_entry_delete_text (GtkEditable *editable,
|
||||||
|
gint start_pos,
|
||||||
|
gint end_pos);
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GcalTimeEntry,
|
G_DEFINE_TYPE_WITH_CODE (GcalTimeEntry,
|
||||||
gcal_time_entry,
|
gcal_time_entry,
|
||||||
GTK_TYPE_ENTRY,
|
GTK_TYPE_ENTRY,
|
||||||
@@ -59,6 +72,17 @@ gcal_time_entry_class_init (GcalTimeEntryClass *klass)
|
|||||||
object_class = G_OBJECT_CLASS (klass);
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
object_class->constructed = gcal_time_entry_constructed;
|
object_class->constructed = gcal_time_entry_constructed;
|
||||||
|
|
||||||
|
signals[MODIFIED] = g_signal_new ("modified",
|
||||||
|
GCAL_TYPE_TIME_ENTRY,
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GcalTimeEntryClass,
|
||||||
|
modified),
|
||||||
|
NULL, NULL,
|
||||||
|
g_cclosure_marshal_VOID__VOID,
|
||||||
|
G_TYPE_NONE,
|
||||||
|
0);
|
||||||
|
|
||||||
|
|
||||||
g_type_class_add_private ((gpointer)klass, sizeof(GcalTimeEntryPrivate));
|
g_type_class_add_private ((gpointer)klass, sizeof(GcalTimeEntryPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +106,7 @@ static void
|
|||||||
gtk_editable_iface_init (GtkEditableInterface *iface)
|
gtk_editable_iface_init (GtkEditableInterface *iface)
|
||||||
{
|
{
|
||||||
iface->insert_text = gcal_time_entry_insert_text;
|
iface->insert_text = gcal_time_entry_insert_text;
|
||||||
|
iface->delete_text = gcal_time_entry_delete_text;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -311,6 +336,32 @@ gcal_time_entry_insert_text (GtkEditable *editable,
|
|||||||
*position = next_pos;
|
*position = next_pos;
|
||||||
g_free (old_text);
|
g_free (old_text);
|
||||||
g_free (text_to_insert);
|
g_free (text_to_insert);
|
||||||
|
|
||||||
|
/* sending modified signal */
|
||||||
|
g_signal_emit (editable, signals[MODIFIED], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gcal_time_entry_delete_text (GtkEditable *editable,
|
||||||
|
gint start_pos,
|
||||||
|
gint end_pos)
|
||||||
|
{
|
||||||
|
GcalTimeEntryPrivate *priv;
|
||||||
|
GtkEditableInterface *parent_editable_iface;
|
||||||
|
|
||||||
|
priv = GCAL_TIME_ENTRY (editable)->priv;
|
||||||
|
parent_editable_iface = g_type_interface_peek (gcal_time_entry_parent_class,
|
||||||
|
GTK_TYPE_EDITABLE);
|
||||||
|
if (! priv->internal_delete)
|
||||||
|
{
|
||||||
|
/* FIXME: Handle delete_text */
|
||||||
|
/* handle delete */
|
||||||
|
}
|
||||||
|
|
||||||
|
parent_editable_iface->delete_text (editable,
|
||||||
|
start_pos,
|
||||||
|
end_pos);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Public API */
|
/* Public API */
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ struct _GcalTimeEntry
|
|||||||
struct _GcalTimeEntryClass
|
struct _GcalTimeEntryClass
|
||||||
{
|
{
|
||||||
GtkEntryClass parent_class;
|
GtkEntryClass parent_class;
|
||||||
|
|
||||||
|
/* signals */
|
||||||
|
void (*modified) (GcalTimeEntry *entry);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gcal_time_entry_get_type (void);
|
GType gcal_time_entry_get_type (void);
|
||||||
|
|||||||
Reference in New Issue
Block a user