Beispiel #1
0
/**
 * nmt_newt_entry_set_text:
 * @entry: an #NmtNewtEntry
 * @text: the new text
 *
 * Updates @entry's text. Note that this skips the entry's
 * #NmtNewtEntryFilter, but will cause its #NmtNewtEntryValidator to
 * be re-run.
 */
void
nmt_newt_entry_set_text (NmtNewtEntry *entry,
                         const char   *text)
{
    newtComponent co;

    co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (entry));
    nmt_newt_entry_set_text_internal (entry, text, co);
}
Beispiel #2
0
static void
nmt_newt_listbox_activated (NmtNewtWidget *widget)
{
	NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (widget);
	newtComponent co = nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget));

	nmt_newt_listbox_set_active (listbox, GPOINTER_TO_UINT (newtListboxGetCurrent (co)));

	NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->activated (widget);
}
Beispiel #3
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;
}
Beispiel #4
0
static void
nmt_newt_listbox_size_allocate (NmtNewtWidget *widget,
                                int            x,
                                int            y,
                                int            width,
                                int            height)
{
	NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget);

	if (width > priv->width) {
		newtListboxSetWidth (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
		                     width);
	}

	NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->
		size_allocate (widget, x, y, width, height);

	priv->alloc_height = height;

	if (!priv->fixed_height && height != priv->height) {
		priv->height = height;
		nmt_newt_widget_needs_rebuild (widget);
	}
}
static void
nmt_newt_popup_activated (NmtNewtWidget *widget)
{
	NmtNewtPopupPrivate *priv = NMT_NEWT_POPUP_GET_PRIVATE (widget);
	NmtNewtPopupEntry *entries = (NmtNewtPopupEntry *)priv->entries->data;
	NmtNewtForm *form;
	NmtNewtWidget *listbox, *ret;
	int button_x, button_y;
	int window_x, window_y;
	int list_w, list_h;
	int i, active;

	listbox = nmt_newt_listbox_new (priv->entries->len, 0);
	nmt_newt_widget_set_exit_on_activate (listbox, TRUE);
	for (i = 0; i < priv->entries->len; i++)
		nmt_newt_listbox_append (NMT_NEWT_LISTBOX (listbox), entries[i].label, NULL);
	nmt_newt_listbox_set_active (NMT_NEWT_LISTBOX (listbox), priv->active);
	nmt_newt_widget_set_padding (listbox, 1, 0, 1, 0);

	nmt_newt_widget_size_request (listbox, &list_w, &list_h);

	g_object_get (nmt_newt_widget_get_form (widget),
	              "x", &window_x,
	              "y", &window_y,
	              NULL);
	newtComponentGetPosition (nmt_newt_component_get_component (NMT_NEWT_COMPONENT (widget)),
	                          &button_x, &button_y);
	/* (window_x + button_x) is the screen X coordinate of the newtComponent. A
	 * newtButton labelled "Foo" is rendered as " <Foo>" (with a preceding
	 * space), so the "F" is at (window_x + button_x + 2). We've added 1 column
	 * of padding to the left of the listbox, so we need to position the popup
	 * at (window_x + button_x + 1) in order for its text to be aligned with the
	 * button's text. (The x and y coordinates given to NmtNewtForm are the
	 * coordinates of the top left of the window content, ignoring the border
	 * graphics.)
	 */
	window_x += button_x + 1;
	window_y += button_y - priv->active;

	form = g_object_new (NMT_TYPE_NEWT_FORM,
	                     "x", window_x,
	                     "y", window_y,
	                     "width", list_w,
	                     "height", list_h,
	                     "padding", 0,
	                     "escape-exits", TRUE,
	                     NULL);
	nmt_newt_form_set_content (form, listbox);

	ret = nmt_newt_form_run_sync (form);
	if (ret == listbox)
		active = nmt_newt_listbox_get_active (NMT_NEWT_LISTBOX (listbox));
	else
		active = priv->active;

	g_object_unref (form);

	if (active != priv->active) {
		priv->active = active;
		g_object_notify (G_OBJECT (widget), "active");
		g_object_notify (G_OBJECT (widget), "active-id");
		nmt_newt_widget_needs_rebuild (widget);
	}

	NMT_NEWT_WIDGET_CLASS (nmt_newt_popup_parent_class)->activated (widget);
}