static void gdaui_numeric_entry_assume_delete (GdauiEntry *entry, gint virt_start_pos, gint virt_end_pos, gint offset) { GdauiNumericEntry *fentry; GString *string; gchar *otext, *ntext = NULL; gint i, nlen, ndel, olen = 0; gint cursor_pos; fentry = (GdauiNumericEntry*) entry; ndel = virt_end_pos - virt_start_pos; otext = gdaui_entry_get_text (GDAUI_ENTRY (entry)); cursor_pos = gtk_editable_get_position (GTK_EDITABLE (entry)); if (otext) { if ((ndel == 1) && (otext[virt_start_pos] == fentry->priv->decimal_sep) && (fentry->priv->nb_decimals != G_MAXUINT16)) { gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos - 1); g_free (otext); return; } string = g_string_new (otext); olen = g_utf8_strlen (otext, -1); g_free (otext); g_string_erase (string, virt_start_pos, ndel); } else string = g_string_new (NULL); cursor_pos -= (virt_end_pos - virt_start_pos); /*g_print ("RAW: [%s]", string->str);*/ text_unformat (fentry, string->str, &cursor_pos); /*g_print ("SANITIZED: [%s]", string->str);*/ if (!test_text_validity (fentry, string->str)) { if ((string->str[0] == fentry->priv->decimal_sep) && string->str[1] == 0) ntext = g_strdup (""); g_string_free (string, TRUE); if (!ntext) { /*g_print ("ERROR!\n");*/ return; } } else { ntext = text_reformat (fentry, string->str, &cursor_pos, FALSE); g_string_free (string, TRUE); } /*g_print ("NEW: [%s]\n", ntext);*/ i = offset; nlen = strlen (ntext); gtk_editable_delete_text ((GtkEditable*) entry, offset, olen + offset); gtk_editable_insert_text ((GtkEditable*) entry, ntext, nlen, &i); g_free (ntext); gtk_editable_set_position (GTK_EDITABLE (entry), cursor_pos); }
static void real_set_value (GdauiEntryWrapper *mgwrap, const GValue *value) { GdauiEntryString *mgstr; GdaDataHandler *dh; PangoLayout *layout; gchar *text; g_return_if_fail (GDAUI_IS_ENTRY_STRING (mgwrap)); mgstr = GDAUI_ENTRY_STRING (mgwrap); GdauiEntryStringPrivate *priv = gdaui_entry_string_get_instance_private (mgstr); dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgwrap)); /* do we need to go into multi line mode ? */ text = gda_data_handler_get_str_from_value (dh, value); layout = gtk_widget_create_pango_layout (GTK_WIDGET (mgwrap), text); if (pango_layout_get_line_count (layout) > 1) g_object_set (G_OBJECT (mgwrap), "multiline", TRUE, NULL); g_object_unref (G_OBJECT (layout)); /* fill the single line widget */ if (value) { if (gda_value_is_null ((GValue *) value)) gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL); else gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), text); } else gdaui_entry_set_text (GDAUI_ENTRY (priv->entry), NULL); /* fill the multiline widget */ if (value) { if (gda_value_is_null ((GValue *) value) || !text) gtk_text_buffer_set_text (priv->buffer, "", -1); else gtk_text_buffer_set_text (priv->buffer, text, -1); } else gtk_text_buffer_set_text (priv->buffer, "", -1); g_free (text); }
static void prop_text_null_cb (G_GNUC_UNUSED GtkButton *button, G_GNUC_UNUSED gpointer data) { gsize i; g_print ("Setting entries' text to NULL\n"); for (i = 0; i < NB_ENTRIES; i++) if (entries [i]) gdaui_entry_set_text (GDAUI_ENTRY (entries [i]), NULL); }
static void prop_text_set_cb (G_GNUC_UNUSED GtkButton *button, GdauiEntry *entry) { gchar *tmp; gsize i; tmp = gdaui_entry_get_text (entry); g_print ("Setting entries' text to [%s]\n", tmp); for (i = 0; i < NB_ENTRIES; i++) if (entries [i]) gdaui_entry_set_text (GDAUI_ENTRY (entries [i]), tmp); g_free (tmp); }
static void prop_length_set_cb (G_GNUC_UNUSED GtkButton *button, GdauiEntry *entry) { gchar *tmp; gint max; gsize i; tmp = gdaui_entry_get_text (entry); max = atoi (tmp); g_free (tmp); g_print ("Setting Max entries' length to %d\n", max); for (i = 0; i < NB_ENTRIES; i++) if (entries [i]) gdaui_entry_set_max_length (GDAUI_ENTRY (entries [i]), max); }
static void gdaui_numeric_entry_assume_insert (GdauiEntry *entry, const gchar *text, gint text_length, gint *virt_pos, gint offset) { GdauiNumericEntry *fentry; gchar *otext, *ptr, *ntext; gchar tmp; gint i; GString *string; gint olen, nlen; fentry = (GdauiNumericEntry*) entry; otext = gdaui_entry_get_text (GDAUI_ENTRY (entry)); olen = strlen (otext); for (ptr = otext, i = 0; (i < *virt_pos) && *ptr; ptr = g_utf8_next_char (ptr), i++); if (i != *virt_pos) return; tmp = *ptr; *ptr = 0; string = g_string_new (""); g_string_append (string, otext); *ptr = tmp; g_string_append (string, text); g_string_append (string, ptr); g_free (otext); /*g_print ("RAW: [%s]", string->str);*/ *virt_pos += text_length; text_unformat (fentry, string->str, virt_pos); /*g_print ("SANITIZED: [%s]", string->str);*/ if (!test_text_validity (fentry, string->str)) { g_string_free (string, TRUE); /*g_print ("ERROR!\n");*/ return; } ntext = text_reformat (fentry, string->str, virt_pos, (text[text_length-1] == fentry->priv->decimal_sep)); g_string_free (string, TRUE); /*g_print ("NEW: [%s]\n", ntext);*/ i = offset; nlen = strlen (ntext); gtk_editable_delete_text ((GtkEditable*) entry, offset, olen + offset); gtk_editable_insert_text ((GtkEditable*) entry, ntext, nlen, &i); g_free (ntext); }
static GValue * real_get_value (GdauiEntryWrapper *mgwrap) { GValue *value; GdauiEntryString *mgstr; GdaDataHandler *dh; g_return_val_if_fail (GDAUI_IS_ENTRY_STRING (mgwrap), NULL); mgstr = GDAUI_ENTRY_STRING (mgwrap); GdauiEntryStringPrivate *priv = gdaui_entry_string_get_instance_private (mgstr); dh = gdaui_data_entry_get_handler (GDAUI_DATA_ENTRY (mgwrap)); if (! priv->multiline) { gchar *cstr; cstr = gdaui_entry_get_text (GDAUI_ENTRY (priv->entry)); value = gda_data_handler_get_value_from_str (dh, cstr, gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (mgwrap))); g_free (cstr); } else { GtkTextIter start, end; gchar *str; gtk_text_buffer_get_start_iter (priv->buffer, &start); gtk_text_buffer_get_end_iter (priv->buffer, &end); str = gtk_text_buffer_get_text (priv->buffer, &start, &end, FALSE); value = gda_data_handler_get_value_from_str (dh, str, gdaui_data_entry_get_value_type (GDAUI_DATA_ENTRY (mgwrap))); g_free (str); } if (!value) { /* in case the gda_data_handler_get_value_from_str() returned an error because the contents of the GtkEntry cannot be interpreted as a GValue */ value = gda_value_new_null (); } return value; }
static void gdaui_numeric_entry_set_property (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec) { GdauiNumericEntry *entry; gchar *otext; entry = GDAUI_NUMERIC_ENTRY (object); otext = gdaui_entry_get_text (GDAUI_ENTRY (entry)); if (entry->priv) { switch (param_id) { case PROP_TYPE: { NumAttr num_attr; compute_numeric_attributes (g_value_get_gtype (value), &num_attr); if (num_attr.is_numerical == FALSE) g_warning (_("Type %s is not numerical"), g_type_name (g_value_get_gtype (value))); else { entry->priv->type = g_value_get_gtype (value); entry->priv->num_attr = num_attr; } break; } case PROP_N_DECIMALS: entry->priv->nb_decimals = g_value_get_uint (value); break; case PROP_DECIMAL_SEP: { gchar sep; sep = (gchar) g_value_get_schar (value); if ((sep == 0) || (sep == '+') || (sep == '-')) g_warning (_("Decimal separator cannot be the '%c' character"), sep ? sep : '0'); else { entry->priv->decimal_sep = (gchar) g_value_get_schar (value); } break; } case PROP_THOUSANDS_SEP: { gchar sep; sep = (gchar) g_value_get_schar (value); if ((sep == '+') || (sep == '-') || (sep == '_')) g_warning (_("Decimal thousands cannot be the '%c' character"), sep); else { entry->priv->thousands_sep = (gchar) g_value_get_schar (value); } break; } default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); break; } } gdaui_entry_set_text (GDAUI_ENTRY (entry), otext); g_free (otext); gint msize; if (entry->priv->num_attr.max_nchars == 0) msize = -1; else { msize = (gint) entry->priv->num_attr.max_nchars; if (entry->priv->thousands_sep) msize += entry->priv->num_attr.max_nchars / 3; if (! entry->priv->num_attr.is_int) msize += 1; if (entry->priv->nb_decimals != G_MAXUINT16) msize += entry->priv->nb_decimals; } /*g_print ("GdauiNumericEntry: type %s => msize = %d\n", g_type_name (entry->priv->type), msize);*/ gdaui_entry_set_width_chars (GDAUI_ENTRY (entry), msize); }