示例#1
0
/**
 * nmt_newt_entry_get_text:
 * @entry: an #NmtNewtEntry
 *
 * Gets @entry's text
 *
 * Returns: @entry's text
 */
const char *
nmt_newt_entry_get_text (NmtNewtEntry *entry)
{
	NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

	return priv->text;
}
示例#2
0
static void
nmt_newt_entry_set_text_internal (NmtNewtEntry  *entry,
                                  const char    *text,
                                  newtComponent  co)
{
	NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

	if (!text)
		text = "";

	if (!strcmp (priv->text, text))
		return;

	g_free (priv->text);
	priv->text = g_strdup (text);

	if (co) {
		char *text_lc;

		text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL;
		newtEntrySet (co, text_lc, TRUE);
		g_free (text_lc);
		priv->last_cursor_pos = -1;
	}

	g_object_freeze_notify (G_OBJECT (entry));
	nmt_newt_entry_check_valid (entry);
	g_object_notify (G_OBJECT (entry), "text");
	g_object_thaw_notify (G_OBJECT (entry));
}
示例#3
0
static void
nmt_newt_entry_init (NmtNewtEntry *entry)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

    priv->text = g_strdup ("");
    priv->last_cursor_pos = -1;
}
示例#4
0
/**
 * nmt_newt_entry_set_filter:
 * @entry: an #NmtNewtEntry
 * @filter: the function to use to filter the entry
 * @user_data: data for @filter
 *
 * Sets a #NmtNewtEntryFilter on @entry, to allow filtering out
 * certain characters from the entry.
 *
 * Note that @filter will only be called for printable characters (eg,
 * not for cursor-control characters or the like), and that it will
 * only be called for user input, not, eg, for
 * nmt_newt_entry_set_text().
 */
void
nmt_newt_entry_set_filter (NmtNewtEntry       *entry,
                           NmtNewtEntryFilter  filter,
                           gpointer            user_data)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

    priv->filter = filter;
    priv->filter_data = user_data;
}
示例#5
0
static void
nmt_newt_entry_finalize (GObject *object)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (object);

    g_free (priv->text);
    if (priv->idle_update)
        g_source_remove (priv->idle_update);

    G_OBJECT_CLASS (nmt_newt_entry_parent_class)->finalize (object);
}
示例#6
0
static void
nmt_newt_entry_activated (NmtNewtWidget *widget)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (widget);

    if (priv->idle_update) {
        g_source_remove (priv->idle_update);
        idle_update_entry (widget);
    }

    NMT_NEWT_WIDGET_CLASS (nmt_newt_entry_parent_class)->activated (widget);
}
示例#7
0
/**
 * nmt_newt_entry_set_validator:
 * @entry: an #NmtNewtEntry
 * @validator: the function to use to validate the entry
 * @user_data: data for @validator
 *
 * Sets a #NmtNewtEntryValidator on @entry, to allow validation of
 * the entry contents. If @validator returns %FALSE, then the entry
 * will not be considered #NmtNewtWidget:valid.
 */
void
nmt_newt_entry_set_validator (NmtNewtEntry          *entry,
                              NmtNewtEntryValidator  validator,
                              gpointer               user_data)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

    priv->validator = validator;
    priv->validator_data = user_data;

    nmt_newt_entry_check_valid (entry);
}
示例#8
0
/**
 * nmt_newt_entry_set_width:
 * @entry: an #NmtNewtEntpry
 * @widget: the new width
 *
 * Updates @entry's width
 */
void
nmt_newt_entry_set_width (NmtNewtEntry *entry,
                          int           width)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);

    if (priv->width == width)
        return;

    priv->width = width;
    nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry));

    g_object_notify (G_OBJECT (entry), "width");
}
示例#9
0
static void
nmt_newt_entry_check_valid (NmtNewtEntry *entry)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
    gboolean valid;

    if (   (priv->flags & NMT_NEWT_ENTRY_NONEMPTY)
            && *priv->text == '\0')
        valid = FALSE;
    else if (priv->validator)
        valid = !!priv->validator (entry, priv->text, priv->validator_data);
    else
        valid = TRUE;

    nmt_newt_widget_set_valid (NMT_NEWT_WIDGET (entry), valid);
}
示例#10
0
static gboolean
idle_update_entry (gpointer entry)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry);
    newtComponent co = nmt_newt_component_get_component (entry);
    char *text;

    priv->idle_update = 0;
    if (!co)
        return FALSE;

    priv->last_cursor_pos = newtEntryGetCursorPosition (co);

    text = nmt_newt_locale_to_utf8 (newtEntryGetValue (co));
    nmt_newt_entry_set_text_internal (entry, text, NULL);
    g_free (text);

    return FALSE;
}
示例#11
0
static newtComponent
nmt_newt_entry_build_component (NmtNewtComponent *component,
                                gboolean          sensitive)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (component);
    newtComponent co;
    char *text_lc;
    int flags;

    flags = convert_flags (priv->flags);
    if (!sensitive)
        flags |= NEWT_FLAG_DISABLED;

    text_lc = priv->text ? nmt_newt_locale_from_utf8 (priv->text) : NULL;
    co = newtEntry (-1, -1, text_lc, priv->width, NULL, flags);
    g_free (text_lc);

    if (priv->last_cursor_pos != -1)
        newtEntrySetCursorPosition (co, priv->last_cursor_pos);

    newtEntrySetFilter (co, entry_filter, component);
    return co;
}
示例#12
0
static int
entry_filter (newtComponent  entry,
              void          *self,
              int            ch,
              int            cursor)
{
    NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (self);

    if (g_ascii_isprint (ch)) {
        if (priv->filter) {
            char *text = nmt_newt_locale_to_utf8 (newtEntryGetValue (entry));

            if (!priv->filter (self, text, ch, cursor, priv->filter_data)) {
                g_free (text);
                return 0;
            }
            g_free (text);
        }
    }

    if (!priv->idle_update)
        priv->idle_update = g_idle_add (idle_update_entry, self);
    return ch;
}