Blame clients/tui/newt/nmt-newt-widget.c

Packit Service 87a54e
/* SPDX-License-Identifier: GPL-2.0-or-later */
Packit 5756e2
/*
Packit 5756e2
 * Copyright (C) 2013 Red Hat, Inc.
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * SECTION:nmt-newt-widget
Packit 5756e2
 * @short_description: Base TUI Widget class
Packit 5756e2
 *
Packit 5756e2
 * #NmtNewtWidget is the abstract base class for nmt-newt. All widgets
Packit 5756e2
 * inherit from one of its two subclasses: #NmtNewtComponent, for
Packit 5756e2
 * widgets that wrap a (single) #newtComponent, and #NmtNewtContainer,
Packit 5756e2
 * for widgets consisting of multiple components. See those classes
Packit 5756e2
 * for more details.
Packit 5756e2
 *
Packit 5756e2
 * With the exception of #NmtNewtForm, all widgets start out with a
Packit 5756e2
 * floating reference, which will be sunk by the container they are
Packit 5756e2
 * added to. #NmtNewtForm is the "top-level" widget type, and so does
Packit 5756e2
 * not have a floating reference.
Packit 5756e2
 *
Packit 5756e2
 * FIXME: need RTL support
Packit 5756e2
 */
Packit 5756e2
Packit 5756e2
#include "nm-default.h"
Packit 5756e2
Packit 5756e2
#include "nmt-newt-widget.h"
Packit 5756e2
#include "nmt-newt-form.h"
Packit 5756e2
Packit Service a1bd4f
G_DEFINE_ABSTRACT_TYPE(NmtNewtWidget, nmt_newt_widget, G_TYPE_INITIALLY_UNOWNED)
Packit 5756e2
Packit Service a1bd4f
#define NMT_NEWT_WIDGET_GET_PRIVATE(o) \
Packit Service a1bd4f
    (G_TYPE_INSTANCE_GET_PRIVATE((o), NMT_TYPE_NEWT_WIDGET, NmtNewtWidgetPrivate))
Packit 5756e2
Packit 5756e2
typedef struct {
Packit Service a1bd4f
    NmtNewtWidget *parent;
Packit Service a1bd4f
    gboolean       visible, realized, valid;
Packit Service a1bd4f
    gboolean       exit_on_activate;
Packit 5756e2
Packit Service a1bd4f
    int pad_left, pad_top, pad_right, pad_bottom;
Packit 5756e2
} NmtNewtWidgetPrivate;
Packit 5756e2
Packit 5756e2
enum {
Packit Service a1bd4f
    PROP_0,
Packit 5756e2
Packit Service a1bd4f
    PROP_PARENT,
Packit Service a1bd4f
    PROP_VISIBLE,
Packit Service a1bd4f
    PROP_VALID,
Packit Service a1bd4f
    PROP_EXIT_ON_ACTIVATE,
Packit 5756e2
Packit Service a1bd4f
    LAST_PROP
Packit 5756e2
};
Packit 5756e2
Packit 5756e2
enum {
Packit Service a1bd4f
    NEEDS_REBUILD,
Packit Service a1bd4f
    ACTIVATED,
Packit 5756e2
Packit Service a1bd4f
    LAST_SIGNAL
Packit 5756e2
};
Packit 5756e2
Packit Service a1bd4f
static guint signals[LAST_SIGNAL] = {0};
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_init(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    priv->visible = TRUE;
Packit Service a1bd4f
    priv->valid   = TRUE;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_finalize(GObject *object)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(object);
Packit 5756e2
Packit Service a1bd4f
    nmt_newt_widget_unrealize(NMT_NEWT_WIDGET(object));
Packit Service a1bd4f
    g_clear_object(&priv->parent);
Packit 5756e2
Packit Service a1bd4f
    G_OBJECT_CLASS(nmt_newt_widget_parent_class)->finalize(object);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_realize:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * "Realizes" @widget. That is, creates #newtComponents corresponding
Packit 5756e2
 * to @widget and its children.
Packit 5756e2
 *
Packit 5756e2
 * You should not need to call this yourself; an #NmtNewtForm will
Packit 5756e2
 * cause its children to be realized and unrealized as needed.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_realize(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    if (!priv->realized) {
Packit Service a1bd4f
        NMT_NEWT_WIDGET_GET_CLASS(widget)->realize(widget);
Packit Service a1bd4f
        priv->realized = TRUE;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_unrealize:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * "Unrealizes" @widget, destroying its #newtComponents.
Packit 5756e2
 *
Packit 5756e2
 * You should not need to call this yourself; an #NmtNewtForm will
Packit 5756e2
 * cause its children to be realized and unrealized as needed.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_unrealize(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    if (priv->realized) {
Packit Service a1bd4f
        NMT_NEWT_WIDGET_GET_CLASS(widget)->unrealize(widget);
Packit Service a1bd4f
        priv->realized = FALSE;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_realized:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Checks if @widget is realized or not.
Packit 5756e2
 *
Packit 5756e2
 * Returns: whether @widget is realized.
Packit 5756e2
 */
Packit 5756e2
gboolean
Packit Service a1bd4f
nmt_newt_widget_get_realized(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    return priv->realized;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_components:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets the #newtComponents that make up @widget, if @widget is
Packit 5756e2
 * visible. If @widget has not yet been realized, it will be realized
Packit 5756e2
 * first.
Packit 5756e2
 *
Packit 5756e2
 * If this function is called on a widget, then the widget will assume
Packit 5756e2
 * that someone else is now responsible for destroying the components,
Packit 5756e2
 * and so it will not destroy them itself when the widget is
Packit 5756e2
 * destroyed. Normally, components will end up being destroyed by the
Packit 5756e2
 * #NmtNewtForm they are added to.
Packit 5756e2
 *
Packit 5756e2
 * Returns: a %NULL-terminated array of components, in focus-chain
Packit 5756e2
 *   order. You must free the array with g_free() when you are done
Packit 5756e2
 *   with it.
Packit 5756e2
 */
Packit 5756e2
newtComponent *
Packit Service a1bd4f
nmt_newt_widget_get_components(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    if (nmt_newt_widget_get_visible(widget)) {
Packit Service a1bd4f
        nmt_newt_widget_realize(widget);
Packit Service a1bd4f
        return NMT_NEWT_WIDGET_GET_CLASS(widget)->get_components(widget);
Packit Service a1bd4f
    } else
Packit Service a1bd4f
        return NULL;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_find_component:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @co: a #newtComponent
Packit 5756e2
 *
Packit 5756e2
 * Finds the widget inside @widget that owns @co.
Packit 5756e2
 *
Packit 5756e2
 * Return value: @co's owner, or %NULL if it was not found.
Packit 5756e2
 */
Packit 5756e2
NmtNewtWidget *
Packit Service a1bd4f
nmt_newt_widget_find_component(NmtNewtWidget *widget, newtComponent co)
Packit 5756e2
{
Packit Service a1bd4f
    return NMT_NEWT_WIDGET_GET_CLASS(widget)->find_component(widget, co);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_set_padding:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @pad_left: padding on the left of @widget
Packit 5756e2
 * @pad_top: padding on the top of @widget
Packit 5756e2
 * @pad_right: padding on the right of @widget
Packit 5756e2
 * @pad_bottom: padding on the bottom of @widget
Packit 5756e2
 *
Packit 5756e2
 * Sets the padding on @widget.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_set_padding(NmtNewtWidget *widget,
Packit Service a1bd4f
                            int            pad_left,
Packit Service a1bd4f
                            int            pad_top,
Packit Service a1bd4f
                            int            pad_right,
Packit Service a1bd4f
                            int            pad_bottom)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    priv->pad_left   = pad_left;
Packit Service a1bd4f
    priv->pad_top    = pad_top;
Packit Service a1bd4f
    priv->pad_right  = pad_right;
Packit Service a1bd4f
    priv->pad_bottom = pad_bottom;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_size_request:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @width: (out): on output, the widget's requested width
Packit 5756e2
 * @height: (out): on output, the widget's requested height
Packit 5756e2
 *
Packit 5756e2
 * Asks @widget for its requested size. If @widget is not visible,
Packit 5756e2
 * this will return 0, 0. If @widget has not yet been realized, it
Packit 5756e2
 * will be realized first.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_size_request(NmtNewtWidget *widget, int *width, int *height)
Packit 5756e2
{
Packit Service a1bd4f
    if (nmt_newt_widget_get_visible(widget)) {
Packit Service a1bd4f
        NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
        nmt_newt_widget_realize(widget);
Packit Service a1bd4f
        NMT_NEWT_WIDGET_GET_CLASS(widget)->size_request(widget, width, height);
Packit 5756e2
Packit Service a1bd4f
        *width += priv->pad_left + priv->pad_right;
Packit Service a1bd4f
        *height += priv->pad_top + priv->pad_bottom;
Packit Service a1bd4f
    } else
Packit Service a1bd4f
        *width = *height = 0;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_size_allocate:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @x: the widget's (absolute) X coordinate
Packit 5756e2
 * @y: the widget's (absolute) Y coordinate
Packit 5756e2
 * @width: the widget's allocated width
Packit 5756e2
 * @height: the widget's allocated height
Packit 5756e2
 *
Packit 5756e2
 * Positions @widget at the given coordinates, with the given size. If
Packit 5756e2
 * @widget is not visible, this has no effect. If @widget has not yet
Packit 5756e2
 * been realized, it will be realized first.
Packit 5756e2
 *
Packit 5756e2
 * @x and @y are absolute coordinates (ie, relative to the screen /
Packit 5756e2
 * terminal window, not relative to @widget's parent).
Packit 5756e2
 *
Packit 5756e2
 * In general, the results are undefined if @width or @height is less
Packit 5756e2
 * than the widget's requested size. If @width or @height is larger
Packit 5756e2
 * than the requested size, most #NmtNewtComponents will ignore the
Packit 5756e2
 * extra space, but some components and most containers will expand to
Packit 5756e2
 * fit.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_size_allocate(NmtNewtWidget *widget, int x, int y, int width, int height)
Packit 5756e2
{
Packit Service a1bd4f
    if (nmt_newt_widget_get_visible(widget)) {
Packit Service a1bd4f
        NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
        nmt_newt_widget_realize(widget);
Packit Service a1bd4f
        x += priv->pad_left;
Packit Service a1bd4f
        y += priv->pad_top;
Packit Service a1bd4f
        width -= priv->pad_left + priv->pad_right;
Packit Service a1bd4f
        height -= priv->pad_top + priv->pad_bottom;
Packit 5756e2
Packit Service a1bd4f
        NMT_NEWT_WIDGET_GET_CLASS(widget)->size_allocate(widget, x, y, width, height);
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_focus_component:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets the #newtComponent that should be given the keyboard focus when
Packit 5756e2
 * @widget is focused.
Packit 5756e2
 *
Packit 5756e2
 * Returns: the #newtComponent to focus, or %NULL if @widget can't
Packit 5756e2
 *   take the focus.
Packit 5756e2
 */
Packit 5756e2
newtComponent
Packit Service a1bd4f
nmt_newt_widget_get_focus_component(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    if (!NMT_NEWT_WIDGET_GET_CLASS(widget)->get_focus_component)
Packit Service a1bd4f
        return NULL;
Packit 5756e2
Packit Service a1bd4f
    return NMT_NEWT_WIDGET_GET_CLASS(widget)->get_focus_component(widget);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_real_activated(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    if (priv->exit_on_activate)
Packit Service a1bd4f
        nmt_newt_form_quit(nmt_newt_widget_get_form(widget));
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_activated:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Tells @widget that its #newtComponent has been activated (ie, the
Packit 5756e2
 * user hit "Return" on it) and emits #NmtNewtWidget::activated.
Packit 5756e2
 *
Packit 5756e2
 * If #NmtNewtWidget:exit-on-activate is set on @widget, then this
Packit 5756e2
 * will call nmt_newt_form_quit() on the widget's form.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_activated(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    g_signal_emit(widget, signals[ACTIVATED], 0);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_exit_on_activate:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets @widget's #NmtNewtWidget:exit-on-activate flag, qv.
Packit 5756e2
 *
Packit 5756e2
 * Returns: @widget's #NmtNewtWidget:exit-on-activate flag
Packit 5756e2
 */
Packit 5756e2
gboolean
Packit Service a1bd4f
nmt_newt_widget_get_exit_on_activate(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    return priv->exit_on_activate;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_set_exit_on_activate:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @exit_on_activate: whether @widget should exit on activate.
Packit 5756e2
 *
Packit 5756e2
 * Sets @widget's #NmtNewtWidget:exit-on-activate flag, qv.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_set_exit_on_activate(NmtNewtWidget *widget, gboolean exit_on_activate)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    exit_on_activate = !!exit_on_activate;
Packit Service a1bd4f
    if (priv->exit_on_activate != exit_on_activate) {
Packit Service a1bd4f
        priv->exit_on_activate = exit_on_activate;
Packit Service a1bd4f
        g_object_notify(G_OBJECT(widget), "exit-on-activate");
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_visible:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets @widget's #NmtNewtWidget:visible flag, qv.
Packit 5756e2
 *
Packit 5756e2
 * Returns: @widget's #NmtNewtWidget:visible flag
Packit 5756e2
 */
Packit 5756e2
gboolean
Packit Service a1bd4f
nmt_newt_widget_get_visible(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    return priv->visible;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_set_visible:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @visible: whether @widget should be visible
Packit 5756e2
 *
Packit 5756e2
 * Sets @widget's #NmtNewtWidget:visible flag, qv.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_set_visible(NmtNewtWidget *widget, gboolean visible)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit Service a1bd4f
Packit Service a1bd4f
    visible = !!visible;
Packit Service a1bd4f
    if (priv->visible != visible) {
Packit Service a1bd4f
        priv->visible = visible;
Packit Service a1bd4f
        g_object_notify(G_OBJECT(widget), "visible");
Packit Service a1bd4f
        nmt_newt_widget_needs_rebuild(widget);
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_set_parent:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @parent: @widget's parent
Packit 5756e2
 *
Packit 5756e2
 * Sets @widget's parent to @parent. This is used internally by
Packit 5756e2
 * #NmtNewtContainer implementations; you must use an appropriate
Packit 5756e2
 * container-specific method to actually add a widget to a container.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_set_parent(NmtNewtWidget *widget, NmtNewtWidget *parent)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    g_clear_object(&priv->parent);
Packit Service a1bd4f
    priv->parent = parent ? g_object_ref(parent) : NULL;
Packit Service a1bd4f
    g_object_notify(G_OBJECT(widget), "parent");
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_parent:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets @widget's parent
Packit 5756e2
 *
Packit 5756e2
 * Returns: @widget's parent
Packit 5756e2
 */
Packit 5756e2
NmtNewtWidget *
Packit Service a1bd4f
nmt_newt_widget_get_parent(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    return priv->parent;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_form:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets @widget's top-level form.
Packit 5756e2
 *
Packit 5756e2
 * Returns: @widget's #NmtNewtForm
Packit 5756e2
 */
Packit 5756e2
NmtNewtForm *
Packit Service a1bd4f
nmt_newt_widget_get_form(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    while (widget) {
Packit Service a1bd4f
        if (NMT_IS_NEWT_FORM(widget))
Packit Service a1bd4f
            return NMT_NEWT_FORM(widget);
Packit Service a1bd4f
        widget = nmt_newt_widget_get_parent(widget);
Packit Service a1bd4f
    }
Packit 5756e2
Packit Service a1bd4f
    return NULL;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_get_valid:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Gets @widget's #NmtNewtWidget:valid flag, indicating whether its
Packit 5756e2
 * content is valid.
Packit 5756e2
 *
Packit 5756e2
 * Returns: @widget's #NmtNewtWidget:valid flag
Packit 5756e2
 */
Packit 5756e2
gboolean
Packit Service a1bd4f
nmt_newt_widget_get_valid(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    return priv->valid;
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_set_valid:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 * @valid: whether @widget is valid
Packit 5756e2
 *
Packit 5756e2
 * Sets @widget's #NmtNewtWidget:valid flag, indicating whether its
Packit 5756e2
 * content is valid.
Packit 5756e2
 *
Packit 5756e2
 * This method should be considered "protected"; if you change it, the
Packit 5756e2
 * widget implementation will likely just change it back at some
Packit 5756e2
 * point.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_set_valid(NmtNewtWidget *widget, gboolean valid)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(widget);
Packit 5756e2
Packit Service a1bd4f
    valid = !!valid;
Packit Service a1bd4f
    if (priv->valid == valid)
Packit Service a1bd4f
        return;
Packit 5756e2
Packit Service a1bd4f
    priv->valid = valid;
Packit Service a1bd4f
    g_object_notify(G_OBJECT(widget), "valid");
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
/**
Packit 5756e2
 * nmt_newt_widget_needs_rebuilds:
Packit 5756e2
 * @widget: an #NmtNewtWidget
Packit 5756e2
 *
Packit 5756e2
 * Marks @widget as needing to be "rebuilt" (ie, re-realized). This is
Packit 5756e2
 * called automatically in some cases (such as when adding a widget to
Packit 5756e2
 * or removing it from a container). #NmtNewtComponent implementations
Packit 5756e2
 * should also call this if they need to make some change that can
Packit 5756e2
 * only be done by destroying their current #newtComponent and
Packit 5756e2
 * creating a new one.
Packit 5756e2
 */
Packit 5756e2
void
Packit Service a1bd4f
nmt_newt_widget_needs_rebuild(NmtNewtWidget *widget)
Packit 5756e2
{
Packit Service a1bd4f
    g_signal_emit(widget, signals[NEEDS_REBUILD], 0);
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidget *widget = NMT_NEWT_WIDGET(object);
Packit Service a1bd4f
Packit Service a1bd4f
    switch (prop_id) {
Packit Service a1bd4f
    case PROP_PARENT:
Packit Service a1bd4f
        nmt_newt_widget_set_parent(widget, g_value_get_object(value));
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_VISIBLE:
Packit Service a1bd4f
        nmt_newt_widget_set_visible(widget, g_value_get_boolean(value));
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_EXIT_ON_ACTIVATE:
Packit Service a1bd4f
        nmt_newt_widget_set_exit_on_activate(widget, g_value_get_boolean(value));
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    default:
Packit Service a1bd4f
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
Packit 5756e2
{
Packit Service a1bd4f
    NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE(object);
Packit Service a1bd4f
Packit Service a1bd4f
    switch (prop_id) {
Packit Service a1bd4f
    case PROP_PARENT:
Packit Service a1bd4f
        g_value_set_object(value, priv->parent);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_VISIBLE:
Packit Service a1bd4f
        g_value_set_boolean(value, priv->visible);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_VALID:
Packit Service a1bd4f
        g_value_set_boolean(value, priv->valid);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    case PROP_EXIT_ON_ACTIVATE:
Packit Service a1bd4f
        g_value_set_boolean(value, priv->exit_on_activate);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    default:
Packit Service a1bd4f
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
Packit Service a1bd4f
        break;
Packit Service a1bd4f
    }
Packit 5756e2
}
Packit 5756e2
Packit 5756e2
static void
Packit Service a1bd4f
nmt_newt_widget_class_init(NmtNewtWidgetClass *widget_class)
Packit 5756e2
{
Packit Service a1bd4f
    GObjectClass *object_class = G_OBJECT_CLASS(widget_class);
Packit Service a1bd4f
Packit Service a1bd4f
    g_type_class_add_private(widget_class, sizeof(NmtNewtWidgetPrivate));
Packit Service a1bd4f
Packit Service a1bd4f
    /* virtual methods */
Packit Service a1bd4f
    object_class->set_property = nmt_newt_widget_set_property;
Packit Service a1bd4f
    object_class->get_property = nmt_newt_widget_get_property;
Packit Service a1bd4f
    object_class->finalize     = nmt_newt_widget_finalize;
Packit Service a1bd4f
Packit Service a1bd4f
    widget_class->activated = nmt_newt_widget_real_activated;
Packit Service a1bd4f
Packit Service a1bd4f
    /* signals */
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget::needs-rebuild:
Packit Service a1bd4f
     * @widget: the #NmtNewtWidget
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Emitted when nmt_newt_widget_need_rebuild() is called on @widget
Packit Service a1bd4f
     * or any of its children. This signal propagates up the container
Packit Service a1bd4f
     * hierarchy, eventually reaching the top-level #NmtNewtForm.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    signals[NEEDS_REBUILD] = g_signal_new("needs-rebuild",
Packit Service a1bd4f
                                          G_OBJECT_CLASS_TYPE(object_class),
Packit Service a1bd4f
                                          G_SIGNAL_RUN_FIRST,
Packit Service a1bd4f
                                          G_STRUCT_OFFSET(NmtNewtWidgetClass, needs_rebuild),
Packit Service a1bd4f
                                          NULL,
Packit Service a1bd4f
                                          NULL,
Packit Service a1bd4f
                                          NULL,
Packit Service a1bd4f
                                          G_TYPE_NONE,
Packit Service a1bd4f
                                          0);
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget::activated:
Packit Service a1bd4f
     * @widget: the #NmtNewtWidget
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Emitted when the widget's #newtComponent is activated.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    signals[ACTIVATED] = g_signal_new("activated",
Packit Service a1bd4f
                                      G_OBJECT_CLASS_TYPE(object_class),
Packit Service a1bd4f
                                      G_SIGNAL_RUN_FIRST,
Packit Service a1bd4f
                                      G_STRUCT_OFFSET(NmtNewtWidgetClass, activated),
Packit Service a1bd4f
                                      NULL,
Packit Service a1bd4f
                                      NULL,
Packit Service a1bd4f
                                      NULL,
Packit Service a1bd4f
                                      G_TYPE_NONE,
Packit Service a1bd4f
                                      0);
Packit Service a1bd4f
Packit Service a1bd4f
    /* properties */
Packit Service a1bd4f
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget:parent:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * The widget's parent widget, or %NULL if it has no parent.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    g_object_class_install_property(object_class,
Packit Service a1bd4f
                                    PROP_PARENT,
Packit Service a1bd4f
                                    g_param_spec_object("parent",
Packit Service a1bd4f
                                                        "",
Packit Service a1bd4f
                                                        "",
Packit Service a1bd4f
                                                        NMT_TYPE_NEWT_WIDGET,
Packit Service a1bd4f
                                                        G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget:visible:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Whether the widget is visible. Invisible widgets do not get
Packit Service a1bd4f
     * realized or sized.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    g_object_class_install_property(
Packit Service a1bd4f
        object_class,
Packit Service a1bd4f
        PROP_VISIBLE,
Packit Service a1bd4f
        g_param_spec_boolean("visible", "", "", TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget:valid:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * Whether the widget's content is considered valid. Components
Packit Service a1bd4f
     * determine their own validity. A container, by default, is
Packit Service a1bd4f
     * considered valid if all of its children are valid.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    g_object_class_install_property(
Packit Service a1bd4f
        object_class,
Packit Service a1bd4f
        PROP_VALID,
Packit Service a1bd4f
        g_param_spec_boolean("valid", "", "", TRUE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
Packit Service a1bd4f
    /**
Packit Service a1bd4f
     * NmtNewtWidget:exit-on-activate:
Packit Service a1bd4f
     *
Packit Service a1bd4f
     * If %TRUE, the widget will call nmt_newt_form_quit() on its form
Packit Service a1bd4f
     * when it is activated.
Packit Service a1bd4f
     */
Packit Service a1bd4f
    g_object_class_install_property(
Packit Service a1bd4f
        object_class,
Packit Service a1bd4f
        PROP_EXIT_ON_ACTIVATE,
Packit Service a1bd4f
        g_param_spec_boolean("exit-on-activate",
Packit Service a1bd4f
                             "",
Packit Service a1bd4f
                             "",
Packit Service a1bd4f
                             FALSE,
Packit Service a1bd4f
                             G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
Packit 5756e2
}