Пример #1
0
static void
adjust_border_for_allocation (NmtNewtSectionPrivate *priv,
                              int                    height)
{
	int i;

	/* We have to use a series of one-line labels rather than a multi-line
	 * textbox, because newt will hide any component that's partially offscreen,
	 * but we want the on-screen portion of the border to show even if part of
	 * it is offscreen.
	 */

	if (height == 1) {
		nmt_newt_widget_set_visible (priv->border_closed_label, TRUE);
		nmt_newt_widget_set_visible (priv->border_open_label, FALSE);
		for (i = 0; i < priv->border_line_labels->len; i++)
			nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], FALSE);
		nmt_newt_widget_set_visible (priv->border_end_label, FALSE);
	} else {
		nmt_newt_widget_set_visible (priv->border_closed_label, FALSE);
		nmt_newt_widget_set_visible (priv->border_open_label, TRUE);
		for (i = 0; i < height - 2; i++) {
			if (i >= priv->border_line_labels->len) {
				NmtNewtWidget *label;

				label = nmt_newt_label_new (line_glyph);
				g_ptr_array_add (priv->border_line_labels, label);
				nmt_newt_grid_add (NMT_NEWT_GRID (priv->border_grid), label, 0, i + 1);
			} else 
				nmt_newt_widget_set_visible (priv->border_line_labels->pdata[i], TRUE);
		}
		nmt_newt_widget_set_visible (priv->border_end_label, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (priv->border_grid), priv->border_end_label, 0, height - 1);
	}
}
Пример #2
0
static void
nmt_widget_list_constructed (GObject *object)
{
	NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (object);

	if (priv->length == 0 && priv->empty_widget) {
		nmt_newt_widget_set_visible (priv->empty_widget, TRUE);
		nmt_newt_grid_move (NMT_NEWT_GRID (object), priv->add_button, 0, 1);
	}

	G_OBJECT_CLASS (nmt_widget_list_parent_class)->constructed (object);
}
Пример #3
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);
	}
}