Esempio n. 1
0
/**
 * nmt_newt_form_set_content:
 * @form: the #NmtNewtForm
 * @content: the form's content
 *
 * Sets @form's content to be @content.
 */
void
nmt_newt_form_set_content (NmtNewtForm      *form,
                           NmtNewtWidget    *content)
{
	NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_form_parent_class);

	if (priv->content)
		nmt_newt_form_remove (NMT_NEWT_CONTAINER (form), priv->content);

	priv->content = content;

	if (priv->content)
		parent_class->add (NMT_NEWT_CONTAINER (form), content);
}
Esempio n. 2
0
/**
 * nmt_page_grid_append:
 * @grid: the #NmtPageGrid
 * @label: (allow-none): the label text for @widget, or %NULL
 * @widget: the (main) widget
 * @extra: (allow-none): optional extra widget
 *
 * Adds a row to @grid.
 *
 * If @label is non-%NULL, this will add a three-column row,
 * containing a right-aligned #NmtNewtLabel in the first column,
 * @widget in the second column, and @extra (if non-%NULL) in
 * the third column.
 *
 * If @label is %NULL, then this will add a row with a single
 * grid-spanning column, containing @widget.
 *
 * FIXME: That's sort of weird.
 *
 * See also nmt_page_grid_set_row_flags().
 */
void
nmt_page_grid_append (NmtPageGrid   *grid,
                      const char    *label,
                      NmtNewtWidget *widget,
                      NmtNewtWidget *extra)
{
	NmtPageGridPrivate *priv = NMT_PAGE_GRID_GET_PRIVATE (grid);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_page_grid_parent_class);
	NmtNewtContainer *container = NMT_NEWT_CONTAINER (grid);
	NmtPageGridRow row;

	memset (&row, 0, sizeof (row));

	if (label) {
		row.label = nmt_newt_label_new (label);
		parent_class->add (container, row.label);
	}

	row.widget = widget;
	parent_class->add (container, widget);
	if (row.label) {
		g_object_bind_property (row.widget, "valid",
		                        row.label, "highlight",
		                        G_BINDING_INVERT_BOOLEAN | G_BINDING_SYNC_CREATE);
	}

	if (extra) {
		row.extra = extra;
		parent_class->add (container, extra);
	}

	g_array_append_val (priv->rows, row);
}
/**
 * nmt_newt_button_box_add_widget_end:
 * @bbox: an #NmtNewtButtonBox
 * @widget: the #NmtNewtWidget to add
 *
 * Adds the given widget to the "end" section of @bbox.
 */
void
nmt_newt_button_box_add_widget_end (NmtNewtButtonBox *bbox,
                                    NmtNewtWidget    *widget)
{
	NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (bbox);

	NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
		add (NMT_NEWT_CONTAINER (bbox), widget);
	g_ptr_array_add (priv->end_buttons, widget);
}
Esempio n. 4
0
static void
nmt_newt_container_finalize (GObject *object)
{
	NmtNewtContainer *container = NMT_NEWT_CONTAINER (object);
	NmtNewtContainerPrivate *priv = NMT_NEWT_CONTAINER_GET_PRIVATE (object);

	while (priv->children->len)
		nmt_newt_container_remove (container, priv->children->pdata[0]);

	G_OBJECT_CLASS (nmt_newt_container_parent_class)->finalize (object);
}
/**
 * nmt_newt_section_set_body:
 * @section: an #NmtNewtSection
 * @body: the body widget
 *
 * Sets @section's body widget.
 */
void
nmt_newt_section_set_body (NmtNewtSection *section,
                           NmtNewtWidget  *body)
{
	NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);
	NmtNewtContainer *container = NMT_NEWT_CONTAINER (section);

	if (priv->body)
		parent_class->remove (container, priv->body);
	priv->body = body;
	parent_class->add (container, body);
}
static void
rebuild_header (NmtEditorSection *section)
{
	NmtEditorSectionPrivate *priv = NMT_EDITOR_SECTION_GET_PRIVATE (section);

	/* Removing any widget in an NmtEditorGrid removes its whole row, so we can
	 * remove the existing title/widget/toggle by asking to remove toggle.
	 */
	nmt_newt_container_remove (NMT_NEWT_CONTAINER (priv->header), priv->toggle);

	nmt_editor_grid_append (priv->header,
	                        priv->title,
	                        priv->header_widget,
	                        priv->toggle);
	nmt_editor_grid_set_row_flags (priv->header,
	                               priv->toggle,
	                               NMT_EDITOR_GRID_ROW_LABEL_ALIGN_LEFT |
	                               NMT_EDITOR_GRID_ROW_EXTRA_ALIGN_RIGHT);
}
static void
nmt_newt_section_init (NmtNewtSection *section)
{
	NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);

	priv->show_border = TRUE;

	priv->border_grid = nmt_newt_grid_new ();
	parent_class->add (NMT_NEWT_CONTAINER (section), priv->border_grid);

	priv->border_open_label = nmt_newt_label_new (open_glyph);
	nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_open_label, 0, 0);

	priv->border_closed_label = nmt_newt_label_new (closed_glyph);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_closed_label, 0, 0);

	priv->border_end_label = nmt_newt_label_new (end_glyph);
	nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
	nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, 1);

	priv->border_line_labels = g_ptr_array_new ();
}
Esempio n. 8
0
static void
ensure_widgets (NmtWidgetList *list)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (list);
	NmtNewtWidget *widget, *button, *focus;
	gboolean was_empty;
	NmtNewtForm *form;
	int i;

	was_empty = priv->widgets->len == 0;

	if (priv->length < priv->widgets->len) {
		/* remove excess widgets */
		for (i = priv->length; i < priv->widgets->len; i++) {
			nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->widgets->pdata[i]);
			nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->remove_buttons->pdata[i]);
		}
		g_ptr_array_set_size (priv->widgets, priv->length);
		g_ptr_array_set_size (priv->remove_buttons, priv->length);

	} else if (priv->length > priv->widgets->len) {
		/* add new widgets */
		for (i = priv->widgets->len; i < priv->length; i++) {
			widget = NMT_WIDGET_LIST_GET_CLASS (list)->create_widget (list, i);

			nmt_newt_grid_add (NMT_NEWT_GRID (list), widget, 0, i);
			g_ptr_array_add (priv->widgets, widget);

			button = nmt_newt_button_new (_("Remove"));
			g_signal_connect (button, "clicked",
			                  G_CALLBACK (remove_clicked), list);

			nmt_newt_grid_add (NMT_NEWT_GRID (list), button, 1, i);
			nmt_newt_widget_set_padding (button, 1, 0, 0, 0);
			g_ptr_array_add (priv->remove_buttons, button);
		}

	} else
		return;

	if (priv->widgets->len == 0 && priv->empty_widget) {
		nmt_newt_widget_set_visible (priv->empty_widget, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, 1);
	} else {
		if (was_empty && priv->empty_widget)
			nmt_newt_widget_set_visible (priv->empty_widget, FALSE);
		nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, priv->length);
	}

	form = nmt_newt_widget_get_form (NMT_NEWT_WIDGET (list));
	if (form) {
		if (priv->widgets->len) {
			if (was_empty)
				focus = priv->widgets->pdata[0];
			else
				focus = priv->widgets->pdata[priv->widgets->len - 1];
		} else
			focus = priv->add_button;
		nmt_newt_form_set_focus (form, focus);
	}

	g_clear_object (&priv->add_sensitivity);
	if (priv->widgets->len) {
		widget = priv->widgets->pdata[priv->widgets->len - 1];
		priv->add_sensitivity = g_object_bind_property (widget, "valid",
		                                                priv->add_button, "sensitive",
		                                                G_BINDING_SYNC_CREATE);
		g_object_add_weak_pointer (G_OBJECT (priv->add_sensitivity),
		                           (gpointer *)&priv->add_sensitivity);
	}
}