static void nmt_newt_listbox_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NmtNewtListbox *listbox = NMT_NEWT_LISTBOX (object); NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (object); switch (prop_id) { case PROP_HEIGHT: priv->height = g_value_get_int (value); priv->fixed_height = (priv->height != 0); break; case PROP_FLAGS: priv->flags = g_value_get_uint (value); break; case PROP_ACTIVE: nmt_newt_listbox_set_active (listbox, g_value_get_int (value)); break; case PROP_ACTIVE_KEY: nmt_newt_listbox_set_active_key (listbox, g_value_get_pointer (value)); break; case PROP_SKIP_NULL_KEYS: priv->skip_null_keys = g_value_get_boolean (value); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static void update_active_internal (NmtNewtListbox *listbox, int new_active) { NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (listbox); if (priv->active == new_active) return; if (new_active >= priv->keys->len) return; if (priv->skip_null_keys && !priv->keys->pdata[new_active]) { if (new_active > priv->active) { while ( new_active < priv->entries->len && !priv->keys->pdata[new_active]) new_active++; } else { while ( new_active >= 0 && !priv->keys->pdata[new_active]) new_active--; } if ( new_active < 0 || new_active >= priv->entries->len || !priv->keys->pdata[new_active]) { g_assert (priv->active >= 0 && priv->active < priv->entries->len); return; } } nmt_newt_listbox_set_active (listbox, new_active); }
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); }
static void nmt_add_connection_show (NmtNewtForm *form) { NmtAddConnectionPrivate *priv = NMT_ADD_CONNECTION_GET_PRIVATE (form); if (priv->single_type) { nmt_newt_listbox_set_active (priv->listbox, 0); create_connection (NMT_NEWT_WIDGET (priv->listbox), g_object_ref (form)); } else NMT_NEWT_FORM_CLASS (nmt_add_connection_parent_class)->show (form); }
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); }