Пример #1
0
static void
nmt_editor_grid_remove (NmtNewtContainer *container,
                      NmtNewtWidget    *widget)
{
	NmtEditorGrid *grid = NMT_EDITOR_GRID (container);
	NmtEditorGridPrivate *priv = NMT_EDITOR_GRID_GET_PRIVATE (grid);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_editor_grid_parent_class);
	NmtEditorGridRow *rows = (NmtEditorGridRow *) priv->rows->data;
	int i;

	i = nmt_editor_grid_find_widget (grid, widget);
	if (i != -1) {
		if (rows[i].label)
			parent_class->remove (container, rows[i].label);
		parent_class->remove (container, rows[i].widget);
		if (rows[i].extra)
			parent_class->remove (container, rows[i].extra);

		g_array_remove_index (priv->rows, i);
		return;
	}

	// FIXME: shouldn't happen
	parent_class->remove (container, widget);
}
Пример #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);
}
Пример #3
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));
}
Пример #4
0
/**
 * 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);
}
Пример #5
0
static void
nmt_newt_form_remove (NmtNewtContainer *container,
                      NmtNewtWidget    *widget)
{
	NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (container);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_form_parent_class);

	g_return_if_fail (widget == priv->content);

	parent_class->remove (container, widget);
	priv->content = NULL;
}
Пример #6
0
/**
 * 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);
}
Пример #7
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);
}
Пример #8
0
static void
nmt_newt_section_remove (NmtNewtContainer *container,
                         NmtNewtWidget    *widget)
{
	NmtNewtSection *section = NMT_NEWT_SECTION (container);
	NmtNewtSectionPrivate *priv = NMT_NEWT_SECTION_GET_PRIVATE (section);
	NmtNewtContainerClass *parent_class = NMT_NEWT_CONTAINER_CLASS (nmt_newt_section_parent_class);

	if (widget == priv->header)
		priv->header = NULL;
	else if (widget == priv->body)
		priv->body = NULL;
	else if (widget == priv->border_grid)
		priv->border_grid = NULL;

	parent_class->remove (container, widget);
}
Пример #9
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;
}
Пример #10
0
static void
nmt_newt_button_box_remove (NmtNewtContainer *container,
                            NmtNewtWidget    *child)
{
	NmtNewtButtonBoxPrivate *priv = NMT_NEWT_BUTTON_BOX_GET_PRIVATE (container);
	int i;

	NMT_NEWT_CONTAINER_CLASS (nmt_newt_button_box_parent_class)->
		remove (container, child);

	for (i = 0; i < priv->start_buttons->len; i++) {
		if (priv->start_buttons->pdata[i] == (gpointer) child) {
			g_ptr_array_remove_index (priv->start_buttons, i);
			return;
		}
	}
	for (i = 0; i < priv->end_buttons->len; i++) {
		if (priv->end_buttons->pdata[i] == (gpointer) child) {
			g_ptr_array_remove_index (priv->end_buttons, i);
			return;
		}
	}
}
Пример #11
0
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 ();
}
Пример #12
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));
}
Пример #13
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 ("\\");
	}
}