예제 #1
0
static void
nmt_newt_button_box_class_init (NmtNewtButtonBoxClass *bbox_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (bbox_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (bbox_class);
	NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (bbox_class);

	g_type_class_add_private (bbox_class, sizeof (NmtNewtButtonBoxPrivate));

	object_class->get_property = nmt_newt_button_box_get_property;
	object_class->set_property = nmt_newt_button_box_set_property;

	widget_class->get_components = nmt_newt_button_box_get_components;
	widget_class->size_request   = nmt_newt_button_box_size_request;
	widget_class->size_allocate  = nmt_newt_button_box_size_allocate;

	container_class->remove = nmt_newt_button_box_remove;

	g_object_class_install_property (object_class, PROP_ORIENTATION,
	                                 g_param_spec_int ("orientation", "", "",
	                                                   0, G_MAXINT, 0,
	                                                   G_PARAM_READWRITE |
	                                                   G_PARAM_CONSTRUCT_ONLY |
	                                                   G_PARAM_STATIC_STRINGS));
}
예제 #2
0
static void
nmt_newt_button_activated (NmtNewtWidget *widget)
{
	g_signal_emit (widget, signals[CLICKED], 0);

	NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->activated (widget);
}
static void
nmt_newt_toggle_button_activated (NmtNewtWidget *widget)
{
	NmtNewtToggleButton *button = NMT_NEWT_TOGGLE_BUTTON (widget);

	nmt_newt_toggle_button_set_active (button, !nmt_newt_toggle_button_get_active (button));

	NMT_NEWT_WIDGET_CLASS (nmt_newt_toggle_button_parent_class)->activated (widget);
}
예제 #4
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);
}
예제 #5
0
static void
nmt_editor_grid_unrealize (NmtNewtWidget *widget)
{
	NmtEditorGridFormState *state = get_form_state (widget);

	if (state)
		memset (state->col_widths, 0, sizeof (state->col_widths));

	NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->unrealize (widget);
}
예제 #6
0
static void
nmt_newt_button_size_request (NmtNewtWidget *widget,
                              int           *width,
                              int           *height)
{
	NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_request (widget, width, height);

	/* remove the automatically-added left padding */
	(*width)--;
}
예제 #7
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);
}
예제 #8
0
static void
nmt_newt_button_size_allocate (NmtNewtWidget *widget,
                               int            x,
                               int            y,
                               int            width,
                               int            height)
{
	/* account for the automatically-added left padding */
	x--;
	width++;

	NMT_NEWT_WIDGET_CLASS (nmt_newt_button_parent_class)->size_allocate (widget, x, y, width, height);
}
static void
nmt_newt_toggle_button_class_init (NmtNewtToggleButtonClass *button_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (button_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (button_class);

	g_type_class_add_private (button_class, sizeof (NmtNewtToggleButtonPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_toggle_button_set_property;
	object_class->get_property = nmt_newt_toggle_button_get_property;
	object_class->finalize     = nmt_newt_toggle_button_finalize;

	widget_class->activated = nmt_newt_toggle_button_activated;

	/**
	 * NmtNewtToggleButton:on-label:
	 *
	 * The label the button displays when it is "on".
	 */
	g_object_class_install_property
		(object_class, PROP_ON_LABEL,
		 g_param_spec_string ("on-label", "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtToggleButton:off-label:
	 *
	 * The label the button displays when it is "off".
	 */
	g_object_class_install_property
		(object_class, PROP_OFF_LABEL,
		 g_param_spec_string ("off-label", "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtToggleButton:active:
	 *
	 * Whether the button is currently "on" (%TRUE) or "off" (%FALSE)
	 */
	g_object_class_install_property
		(object_class, PROP_ACTIVE,
		 g_param_spec_boolean ("active", "", "",
		                       FALSE,
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS));
}
예제 #10
0
static void
nmt_newt_button_class_init (NmtNewtButtonClass *button_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (button_class);
	NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (button_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (button_class);

	g_type_class_add_private (button_class, sizeof (NmtNewtButtonPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_button_set_property;
	object_class->get_property = nmt_newt_button_get_property;
	object_class->finalize     = nmt_newt_button_finalize;

	widget_class->size_request  = nmt_newt_button_size_request;
	widget_class->size_allocate = nmt_newt_button_size_allocate;
	widget_class->activated     = nmt_newt_button_activated;

	component_class->build_component = nmt_newt_button_build_component;

	/* signals */

	/**
	 * NmtNewtButton::clicked:
	 * @button: the #NmtNewtButton
	 *
	 * Emitted when the button is clicked.
	 */
	signals[CLICKED] =
		g_signal_new ("clicked",
		              G_OBJECT_CLASS_TYPE (object_class),
		              G_SIGNAL_RUN_FIRST,
		              0, NULL, NULL, NULL,
		              G_TYPE_NONE, 0);

	/* properties */

	/**
	 * NmtNewtButton:label:
	 *
	 * The button's label
	 */
	g_object_class_install_property
		(object_class, PROP_LABEL,
		 g_param_spec_string ("label", "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS));
}
예제 #11
0
static void
nmt_newt_listbox_size_request (NmtNewtWidget *widget,
                               int           *width,
                               int           *height)
{
	NmtNewtListboxPrivate *priv = NMT_NEWT_LISTBOX_GET_PRIVATE (widget);

	NMT_NEWT_WIDGET_CLASS (nmt_newt_listbox_parent_class)->
		size_request (widget, width, height);

	priv->alloc_height = -1;
	if (!priv->fixed_height)
		*height = 1;
	priv->width = *width;
}
예제 #12
0
static void
nmt_newt_container_class_init (NmtNewtContainerClass *container_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (container_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (container_class);

	g_type_class_add_private (container_class, sizeof (NmtNewtContainerPrivate));

	/* virtual methods */
	object_class->finalize = nmt_newt_container_finalize;

	widget_class->realize        = nmt_newt_container_realize;
	widget_class->unrealize      = nmt_newt_container_unrealize;
	widget_class->find_component = nmt_newt_container_find_component;

	container_class->add    = nmt_newt_container_real_add;
	container_class->remove = nmt_newt_container_real_remove;
	container_class->child_validity_changed = nmt_newt_container_real_child_validity_changed;
}
예제 #13
0
static void
nmt_editor_grid_realize (NmtNewtWidget *widget)
{
	NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (widget);
	NmtNewtWidget *parent;

	NMT_NEWT_WIDGET_CLASS (nmt_editor_grid_parent_class)->realize (widget);

	/* This is a hack, but it's the simplest way to make it work... */
	priv->indent = 0;

	parent = nmt_newt_widget_get_parent (widget);
	while (parent) {
		if (NMT_IS_NEWT_SECTION (parent)) {
			priv->indent = 2;
			break;
		}
		parent = nmt_newt_widget_get_parent (parent);
	}
}
예제 #14
0
static void
nmt_editor_grid_class_init (NmtEditorGridClass *grid_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (grid_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (grid_class);
	NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (grid_class);

	g_type_class_add_private (grid_class, sizeof (NmtEditorGridPrivate));

	/* virtual methods */
	object_class->finalize = nmt_editor_grid_finalize;

	widget_class->realize        = nmt_editor_grid_realize;
	widget_class->unrealize      = nmt_editor_grid_unrealize;
	widget_class->get_components = nmt_editor_grid_get_components;
	widget_class->size_request   = nmt_editor_grid_size_request;
	widget_class->size_allocate  = nmt_editor_grid_size_allocate;

	container_class->remove = nmt_editor_grid_remove;
}
예제 #15
0
static void
nmt_newt_popup_class_init (NmtNewtPopupClass *popup_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (popup_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (popup_class);
	NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (popup_class);

	g_type_class_add_private (popup_class, sizeof (NmtNewtPopupPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_popup_set_property;
	object_class->get_property = nmt_newt_popup_get_property;
	object_class->finalize     = nmt_newt_popup_finalize;

	widget_class->activated = nmt_newt_popup_activated;

	component_class->build_component = nmt_newt_popup_build_component;

	/**
	 * NmtNewtPopup:active:
	 *
	 * The index of the currently-active entry.
	 */
	g_object_class_install_property
		(object_class, PROP_ACTIVE,
		 g_param_spec_uint ("active", "", "",
		                    0, G_MAXUINT, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtPopup:active-id:
	 *
	 * The textual ID of the currently-active entry.
	 */
	g_object_class_install_property
		(object_class, PROP_ACTIVE_ID,
		 g_param_spec_string ("active-id", "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS));
}
예제 #16
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);
	}
}
예제 #17
0
static void
nmt_route_entry_class_init (NmtRouteEntryClass *entry_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (entry_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (entry_class);

	g_type_class_add_private (entry_class, sizeof (NmtRouteEntryPrivate));

	/* virtual methods */
	object_class->constructed  = nmt_route_entry_constructed;
	object_class->set_property = nmt_route_entry_set_property;
	object_class->get_property = nmt_route_entry_get_property;
	object_class->finalize     = nmt_route_entry_finalize;

	widget_class->get_focus_component = nmt_route_entry_get_focus_component;

	/**
	 * NmtRouteEntry:family:
	 *
	 * The address family of the route, eg, %AF_INET
	 */
	g_object_class_install_property
		(object_class, PROP_FAMILY,
		 g_param_spec_int ("family", "", "",
		                   0, G_MAXINT, 0,
		                   G_PARAM_READWRITE |
		                   G_PARAM_CONSTRUCT_ONLY |
		                   G_PARAM_STATIC_STRINGS));
	/**
	 * NmtRouteEntry:ip-entry-width:
	 *
	 * The width in characters of the IP address entries
	 */
	g_object_class_install_property
		(object_class, PROP_IP_ENTRY_WIDTH,
		 g_param_spec_int ("ip-entry-width", "", "",
		                   0, G_MAXINT, 0,
		                   G_PARAM_READWRITE |
		                   G_PARAM_CONSTRUCT_ONLY |
		                   G_PARAM_STATIC_STRINGS));
	/**
	 * NmtRouteEntry:metric-entry-width:
	 *
	 * The width in characters of the metric entry
	 */
	g_object_class_install_property
		(object_class, PROP_METRIC_ENTRY_WIDTH,
		 g_param_spec_int ("metric-entry-width", "", "",
		                   0, G_MAXINT, 0,
		                   G_PARAM_READWRITE |
		                   G_PARAM_CONSTRUCT_ONLY |
		                   G_PARAM_STATIC_STRINGS));
	/**
	 * NmtRouteEntry:ip4-route:
	 *
	 * The contents of the entries, as an #NMIP4Route. Only valid
	 * if #NmtRouteEntry:family is %AF_INET.
	 */
	g_object_class_install_property
		(object_class, PROP_IP4_ROUTE,
		 g_param_spec_boxed ("ip4-route", "", "",
		                     nm_ip4_route_get_type (),
		                     G_PARAM_READWRITE |
		                     G_PARAM_STATIC_STRINGS));
	/**
	 * NmtRouteEntry:ip6-route:
	 *
	 * The contents of the entries, as an #NMIP6Route. Only valid
	 * if #NmtRouteEntry:family is %AF_INET6.
	 */
	g_object_class_install_property
		(object_class, PROP_IP6_ROUTE,
		 g_param_spec_boxed ("ip6-route", "", "",
		                     nm_ip6_route_get_type (),
		                     G_PARAM_READWRITE |
		                     G_PARAM_STATIC_STRINGS));
}
예제 #18
0
static void
nmt_newt_entry_class_init (NmtNewtEntryClass *entry_class)
{
    GObjectClass *object_class = G_OBJECT_CLASS (entry_class);
    NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (entry_class);
    NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (entry_class);

    g_type_class_add_private (entry_class, sizeof (NmtNewtEntryPrivate));

    /* virtual methods */
    object_class->constructed  = nmt_newt_entry_constructed;
    object_class->set_property = nmt_newt_entry_set_property;
    object_class->get_property = nmt_newt_entry_get_property;
    object_class->finalize     = nmt_newt_entry_finalize;

    widget_class->activated = nmt_newt_entry_activated;

    component_class->build_component    = nmt_newt_entry_build_component;

    /**
     * NmtNewtEntry:text
     *
     * The entry's text
     */
    g_object_class_install_property (object_class, PROP_TEXT,
                                     g_param_spec_string ("text", "", "",
                                             NULL,
                                             G_PARAM_READWRITE |
                                             G_PARAM_STATIC_STRINGS));
    /**
     * NmtNewtEntry:width
     *
     * The entry's width in characters
     */
    g_object_class_install_property (object_class, PROP_WIDTH,
                                     g_param_spec_int ("width", "", "",
                                             -1, 80, -1,
                                             G_PARAM_READWRITE |
                                             G_PARAM_STATIC_STRINGS));
    /**
     * NmtNewtEntry:flags
     *
     * The entry's #NmtNewtEntryFlags
     */
    g_object_class_install_property (object_class, PROP_FLAGS,
                                     g_param_spec_uint ("flags", "", "",
                                             0, 0xFFFF, 0,
                                             G_PARAM_READWRITE |
                                             G_PARAM_CONSTRUCT_ONLY |
                                             G_PARAM_STATIC_STRINGS));
    /**
     * NmtNewtEntry:password
     *
     * %TRUE if #NmtNewtEntry:flags contains %NMT_NEWT_ENTRY_PASSWORD,
     * %FALSE if not.
     */
    g_object_class_install_property (object_class, PROP_PASSWORD,
                                     g_param_spec_boolean ("password", "", "",
                                             FALSE,
                                             G_PARAM_READWRITE |
                                             G_PARAM_STATIC_STRINGS));
}
예제 #19
0
static void
nmt_newt_listbox_class_init (NmtNewtListboxClass *listbox_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (listbox_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (listbox_class);
	NmtNewtComponentClass *component_class = NMT_NEWT_COMPONENT_CLASS (listbox_class);

	g_type_class_add_private (listbox_class, sizeof (NmtNewtListboxPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_listbox_set_property;
	object_class->get_property = nmt_newt_listbox_get_property;
	object_class->finalize     = nmt_newt_listbox_finalize;

	widget_class->size_request  = nmt_newt_listbox_size_request;
	widget_class->size_allocate = nmt_newt_listbox_size_allocate;
	widget_class->activated     = nmt_newt_listbox_activated;

	component_class->build_component = nmt_newt_listbox_build_component;

	/* properties */

	/**
	 * NmtNewtListbox:height:
	 *
	 * The listbox's height, or -1 if it has no fixed height.
	 */
	g_object_class_install_property
		(object_class, PROP_HEIGHT,
		 g_param_spec_int ("height", "", "",
		                   -1, 255, -1,
		                   G_PARAM_READWRITE |
		                   G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtListbox:flags:
	 *
	 * The listbox's #NmtNewtListboxFlags.
	 */
	g_object_class_install_property
		(object_class, PROP_FLAGS,
		 g_param_spec_uint ("flags", "", "",
		                    0, 0xFFFF, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_CONSTRUCT_ONLY |
		                    G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtListbox:active:
	 *
	 * The currently-selected row.
	 */
	g_object_class_install_property
		(object_class, PROP_ACTIVE,
		 g_param_spec_int ("active", "", "",
		                   0, G_MAXINT, 0,
		                   G_PARAM_READWRITE |
		                   G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtListbox:active-key:
	 *
	 * The key of the currently-selected row.
	 */
	g_object_class_install_property
		(object_class, PROP_ACTIVE_KEY,
		 g_param_spec_pointer ("active-key", "", "",
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS));
	/**
	 * NmtNewtListbox:skip-null-keys:
	 *
	 * If %TRUE, rows with %NULL key values will be skipped over when
	 * navigating the list with the arrow keys.
	 */
	g_object_class_install_property
		(object_class, PROP_SKIP_NULL_KEYS,
		 g_param_spec_boolean ("skip-null-keys", "", "",
		                       FALSE,
		                       G_PARAM_READWRITE |
		                       G_PARAM_CONSTRUCT_ONLY |
		                       G_PARAM_STATIC_STRINGS));
}
예제 #20
0
static void
nmt_newt_section_class_init (NmtNewtSectionClass *section_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (section_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (section_class);
	NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (section_class);

	g_type_class_add_private (section_class, sizeof (NmtNewtSectionPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_section_set_property;
	object_class->get_property = nmt_newt_section_get_property;
	object_class->finalize     = nmt_newt_section_finalize;

	widget_class->get_components = nmt_newt_section_get_components;
	widget_class->size_request   = nmt_newt_section_size_request;
	widget_class->size_allocate  = nmt_newt_section_size_allocate;

	container_class->remove = nmt_newt_section_remove;

	/* properties */

	/**
	 * NmtNewtSection:show-border:
	 *
	 * %TRUE if the section should show a border along the left side.
	 */
	g_object_class_install_property
		(object_class, PROP_SHOW_BORDER,
		 g_param_spec_boolean ("show-border", "", "",
		                       TRUE,
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS));

	/**
	 * NmtNewtSection:open:
	 *
	 * %TRUE if the section is open (ie, its body is visible), %FALSE
	 * if not.
	 */
	g_object_class_install_property
		(object_class, PROP_OPEN,
		 g_param_spec_boolean ("open", "", "",
		                       FALSE,
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS));

	/* globals */
	closed_glyph = nmt_newt_locale_from_utf8 ("\342\225\220"); /* ═ */
	open_glyph   = nmt_newt_locale_from_utf8 ("\342\225\244"); /* ╤ */
	line_glyph   = nmt_newt_locale_from_utf8 ("\342\224\202"); /* │ */
	end_glyph    = nmt_newt_locale_from_utf8 ("\342\224\224"); /* └ */
	if (!*closed_glyph || !*open_glyph || !*line_glyph || !*end_glyph) {
		g_free (closed_glyph);
		g_free (open_glyph);
		g_free (line_glyph);
		g_free (end_glyph);

		closed_glyph = g_strdup ("-");
		open_glyph   = g_strdup ("+");
		line_glyph   = g_strdup ("|");
		end_glyph    = g_strdup ("\\");
	}
}
예제 #21
0
static void
nmt_newt_form_class_init (NmtNewtFormClass *form_class)
{
	GObjectClass *object_class = G_OBJECT_CLASS (form_class);
	NmtNewtContainerClass *container_class = NMT_NEWT_CONTAINER_CLASS (form_class);
	NmtNewtWidgetClass *widget_class = NMT_NEWT_WIDGET_CLASS (form_class);

	g_type_class_add_private (form_class, sizeof (NmtNewtFormPrivate));

	/* virtual methods */
	object_class->set_property = nmt_newt_form_set_property;
	object_class->get_property = nmt_newt_form_get_property;
	object_class->finalize     = nmt_newt_form_finalize;

	widget_class->needs_rebuild = nmt_newt_form_needs_rebuild;

	container_class->remove = nmt_newt_form_remove;

	form_class->show = nmt_newt_form_real_show;

	/* signals */

	/**
	 * NmtNewtForm::quit:
	 * @form: the #NmtNewtForm
	 *
	 * Emitted when the form quits.
	 */
	signals[QUIT] =
		g_signal_new ("quit",
		              G_OBJECT_CLASS_TYPE (object_class),
		              G_SIGNAL_RUN_FIRST,
		              G_STRUCT_OFFSET (NmtNewtFormClass, quit),
		              NULL, NULL, NULL,
		              G_TYPE_NONE, 0);

	/**
	 * NmtNewtForm:title:
	 *
	 * The form's title. If non-%NULL, this will be displayed above
	 * the form in its border.
	 */
	g_object_class_install_property
		(object_class, PROP_TITLE,
		 g_param_spec_string ("title", "", "",
		                      NULL,
		                      G_PARAM_READWRITE |
		                      G_PARAM_STATIC_STRINGS |
		                      G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:fullscreen:
	 *
	 * If %TRUE, the form will fill the entire "screen" (ie, terminal
	 * window).
	 */
	g_object_class_install_property
		(object_class, PROP_FULLSCREEN,
		 g_param_spec_boolean ("fullscreen", "", "",
		                       FALSE,
		                       G_PARAM_WRITABLE |
		                       G_PARAM_STATIC_STRINGS |
		                       G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:fullscreen-vertical:
	 *
	 * If %TRUE, the form will fill the entire "screen" (ie, terminal
	 * window) vertically, but not necessarily horizontally.
	 */
	g_object_class_install_property
		(object_class, PROP_FULLSCREEN_VERTICAL,
		 g_param_spec_boolean ("fullscreen-vertical", "", "",
		                       FALSE,
		                       G_PARAM_WRITABLE |
		                       G_PARAM_STATIC_STRINGS |
		                       G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:fullscreen-horizontal:
	 *
	 * If %TRUE, the form will fill the entire "screen" (ie, terminal
	 * window) horizontally, but not necessarily vertically.
	 */
	g_object_class_install_property
		(object_class, PROP_FULLSCREEN_HORIZONTAL,
		 g_param_spec_boolean ("fullscreen-horizontal", "", "",
		                       FALSE,
		                       G_PARAM_WRITABLE |
		                       G_PARAM_STATIC_STRINGS |
		                       G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:x:
	 *
	 * The form's x coordinate. By default, the form will be centered
	 * on the screen.
	 */
	g_object_class_install_property
		(object_class, PROP_X,
		 g_param_spec_uint ("x", "", "",
		                    0, G_MAXUINT, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS |
		                    G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:y:
	 *
	 * The form's y coordinate. By default, the form will be centered
	 * on the screen.
	 */
	g_object_class_install_property
		(object_class, PROP_Y,
		 g_param_spec_uint ("y", "", "",
		                    0, G_MAXUINT, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS |
		                    G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:width:
	 *
	 * The form's width. By default, this will be determined by the
	 * width of the form's content.
	 */
	g_object_class_install_property
		(object_class, PROP_WIDTH,
		 g_param_spec_uint ("width", "", "",
		                    0, G_MAXUINT, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS |
		                    G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:height:
	 *
	 * The form's height. By default, this will be determined by the
	 * height of the form's content.
	 */
	g_object_class_install_property
		(object_class, PROP_HEIGHT,
		 g_param_spec_uint ("height", "", "",
		                    0, G_MAXUINT, 0,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS |
		                    G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:padding:
	 *
	 * The padding between the form's content and its border.
	 */
	g_object_class_install_property
		(object_class, PROP_PADDING,
		 g_param_spec_uint ("padding", "", "",
		                    0, G_MAXUINT, 1,
		                    G_PARAM_READWRITE |
		                    G_PARAM_STATIC_STRINGS |
		                    G_PARAM_CONSTRUCT_ONLY));
	/**
	 * NmtNewtForm:escape-exits:
	 *
	 * If %TRUE, then hitting the Escape key will cause the form to
	 * exit.
	 */
	g_object_class_install_property
		(object_class, PROP_ESCAPE_EXITS,
		 g_param_spec_boolean ("escape-exits", "", "",
		                       FALSE,
		                       G_PARAM_READWRITE |
		                       G_PARAM_STATIC_STRINGS |
		                       G_PARAM_CONSTRUCT_ONLY));
}
예제 #22
0
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);
}