static void nmt_newt_entry_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtNewtEntry *entry = NMT_NEWT_ENTRY (object); NmtNewtEntryPrivate *priv = NMT_NEWT_ENTRY_GET_PRIVATE (entry); switch (prop_id) { case PROP_TEXT: nmt_newt_entry_set_text (entry, g_value_get_string (value)); break; case PROP_WIDTH: nmt_newt_entry_set_width (entry, g_value_get_int (value)); break; case PROP_FLAGS: priv->flags = g_value_get_uint (value); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry)); break; case PROP_PASSWORD: if (g_value_get_boolean (value)) priv->flags |= NMT_NEWT_ENTRY_PASSWORD; else priv->flags &= ~NMT_NEWT_ENTRY_PASSWORD; nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (entry)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void nmt_password_fields_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtPasswordFields *fields = NMT_PASSWORD_FIELDS (object); NmtPasswordFieldsPrivate *priv = NMT_PASSWORD_FIELDS_GET_PRIVATE (fields); switch (prop_id) { case PROP_WIDTH: nmt_newt_entry_set_width (priv->entry, g_value_get_int (value)); break; case PROP_EXTRAS: priv->extras = g_value_get_uint (value); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (fields)); break; case PROP_PASSWORD: nmt_password_fields_set_password (fields, g_value_get_string (value)); break; case PROP_ALWAYS_ASK: if (priv->always_ask) nmt_newt_checkbox_set_active (priv->always_ask, g_value_get_boolean (value)); break; case PROP_SHOW_PASSWORD: if (priv->show_password) nmt_newt_checkbox_set_active (priv->show_password, g_value_get_boolean (value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void child_needs_rebuild (NmtNewtWidget *widget, gpointer user_data) { NmtNewtWidget *container = user_data; nmt_newt_widget_needs_rebuild (container); }
/** * nmt_newt_listbox_append: * @listbox: an #NmtNewtListbox * @entry: the text for the new row * @key: (allow-none): the key associated with @entry * * Adds a row to @listbox. */ void nmt_newt_listbox_append (NmtNewtListbox *listbox, const char *entry, gpointer key) { NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox); g_ptr_array_add (priv->entries, nmt_newt_locale_from_utf8 (entry)); g_ptr_array_add (priv->keys, key); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (listbox)); }
static void nmt_newt_section_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (object); switch (prop_id) { case PROP_SHOW_BORDER: priv->show_border = g_value_get_boolean (value); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object)); break; case PROP_OPEN: priv->open = g_value_get_boolean (value); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (object)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
/** * nmt_newt_label_set_style: * @label: an #NmtNewtLabel * @style: the #NmtNewtLabelStyle * * Sets the style of @label */ void nmt_newt_label_set_style (NmtNewtLabel *label, NmtNewtLabelStyle style) { NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label); if (priv->style == style) return; priv->style = style; g_object_notify (G_OBJECT (label), "style"); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label)); }
/** * nmt_newt_button_set_label: * @button: an #NmtNewtButton * @label: the new label * * Updates @button's label. */ void nmt_newt_button_set_label (NmtNewtButton *button, const char *label) { NmtNewtButtonPrivate *priv = NMT_NEWT_BUTTON_GET_PRIVATE (button); if (!g_strcmp0 (priv->label, label)) return; g_free (priv->label); priv->label = g_strdup (label); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (button)); }
/** * nmt_newt_listbox_clear: * @listbox: an #NmtNewtListbox * * Clears the contents of @listbox. */ void nmt_newt_listbox_clear (NmtNewtListbox *listbox) { NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox); g_ptr_array_set_size (priv->entries, 0); g_ptr_array_set_size (priv->keys, 0); priv->active = -1; priv->active_key = NULL; nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (listbox)); }
/** * nmt_newt_label_set_highlight: * @label: an #NmtNewtLabel * @highlight: %TRUE if @label should be highlighted * * Sets whether @label is highlighted. Highlighted labels are red; * this is generally used to highlight invalid widgets. */ void nmt_newt_label_set_highlight (NmtNewtLabel *label, gboolean highlight) { NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label); highlight = !!highlight; if (priv->highlight == highlight) return; priv->highlight = highlight; g_object_notify (G_OBJECT (label), "highlight"); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label)); }
static void nmt_newt_container_real_add (NmtNewtContainer *container, NmtNewtWidget *widget) { NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container); g_signal_connect (widget, "needs-rebuild", G_CALLBACK (child_needs_rebuild), container); g_signal_connect (widget, "notify::valid", G_CALLBACK (child_validity_notify), container); g_ptr_array_add (priv->children, g_object_ref_sink (widget)); nmt_newt_widget_set_parent (widget, NMT_NEWT_WIDGET (container)); nmt_newt_container_child_validity_changed (container, widget); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (container)); }
/** * 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"); }
/** * nmt_newt_label_set_text: * @label: an #NmtNewtLabel * @text: the new text * * Updates @label's text. */ void nmt_newt_label_set_text (NmtNewtLabel *label, const char *text) { NmtNewtLabelPrivate *priv = NMT_NEWT_LABEL_GET_PRIVATE (label); if (!g_strcmp0 (priv->text, text)) return; g_free (priv->text); priv->text = g_strdup (text); g_object_notify (G_OBJECT (label), "text"); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (label)); }
static void nmt_newt_container_real_remove (NmtNewtContainer *container, NmtNewtWidget *widget) { NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (container); int i; for (i = 0; i < priv->children->len; i++) { if (widget == priv->children->pdata[i]) { g_ptr_array_remove_index (priv->children, i); g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (child_needs_rebuild), container); g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (child_validity_notify), container); nmt_newt_widget_set_parent (widget, NULL); g_object_unref (widget); nmt_newt_container_child_validity_changed (container, NULL); nmt_newt_widget_needs_rebuild (NMT_NEWT_WIDGET (container)); return; } } }
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); }