forked from AuroraMiddleware/gtk
Convert GtkCellRendererProgress to a GtkOrientable
And add an inverted property to it, too.
This commit is contained in:
parent
3302f22da2
commit
0ff6aedca0
@ -29,7 +29,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "gtkcellrendererprogress.h"
|
#include "gtkcellrendererprogress.h"
|
||||||
#include "gtkprogressbar.h"
|
#include "gtkorientable.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
|
|
||||||
@ -42,7 +42,8 @@ enum
|
|||||||
PROP_PULSE,
|
PROP_PULSE,
|
||||||
PROP_TEXT_XALIGN,
|
PROP_TEXT_XALIGN,
|
||||||
PROP_TEXT_YALIGN,
|
PROP_TEXT_YALIGN,
|
||||||
PROP_ORIENTATION
|
PROP_ORIENTATION,
|
||||||
|
PROP_INVERTED
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkCellRendererProgressPrivate
|
struct _GtkCellRendererProgressPrivate
|
||||||
@ -56,7 +57,8 @@ struct _GtkCellRendererProgressPrivate
|
|||||||
gint offset;
|
gint offset;
|
||||||
gfloat text_xalign;
|
gfloat text_xalign;
|
||||||
gfloat text_yalign;
|
gfloat text_yalign;
|
||||||
GtkProgressBarOrientation orientation;
|
GtkOrientation orientation;
|
||||||
|
gboolean inverted;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gtk_cell_renderer_progress_finalize (GObject *object);
|
static void gtk_cell_renderer_progress_finalize (GObject *object);
|
||||||
@ -95,7 +97,8 @@ static void gtk_cell_renderer_progress_render (GtkCellRenderer *ce
|
|||||||
guint flags);
|
guint flags);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER)
|
G_DEFINE_TYPE_WITH_CODE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER,
|
||||||
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL))
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass)
|
gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass)
|
||||||
@ -202,24 +205,17 @@ gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass)
|
|||||||
0.0, 1.0, 0.5,
|
0.0, 1.0, 0.5,
|
||||||
GTK_PARAM_READWRITE));
|
GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
/**
|
g_object_class_override_property (object_class,
|
||||||
* GtkCellRendererProgress:orientation:
|
PROP_ORIENTATION,
|
||||||
*
|
"orientation");
|
||||||
* The "orientation" property controls the direction and growth
|
|
||||||
* direction of the progress bar (left-to-right, right-to-left,
|
|
||||||
* top-to-bottom or bottom-to-top).
|
|
||||||
*
|
|
||||||
* Since: 2.12
|
|
||||||
*/
|
|
||||||
g_object_class_install_property (object_class,
|
|
||||||
PROP_ORIENTATION,
|
|
||||||
g_param_spec_enum ("orientation",
|
|
||||||
P_("Orientation"),
|
|
||||||
P_("Orientation and growth direction of the progress bar"),
|
|
||||||
GTK_TYPE_PROGRESS_BAR_ORIENTATION,
|
|
||||||
GTK_PROGRESS_LEFT_TO_RIGHT,
|
|
||||||
GTK_PARAM_READWRITE));
|
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_INVERTED,
|
||||||
|
g_param_spec_boolean ("inverted",
|
||||||
|
P_("Inverted"),
|
||||||
|
P_("Invert the direction in which the progress bar grows"),
|
||||||
|
FALSE,
|
||||||
|
GTK_PARAM_READWRITE));
|
||||||
|
|
||||||
g_type_class_add_private (object_class,
|
g_type_class_add_private (object_class,
|
||||||
sizeof (GtkCellRendererProgressPrivate));
|
sizeof (GtkCellRendererProgressPrivate));
|
||||||
@ -246,7 +242,8 @@ gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress)
|
|||||||
priv->text_xalign = 0.5;
|
priv->text_xalign = 0.5;
|
||||||
priv->text_yalign = 0.5;
|
priv->text_yalign = 0.5;
|
||||||
|
|
||||||
priv->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
|
priv->orientation = GTK_ORIENTATION_HORIZONTAL,
|
||||||
|
priv->inverted = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -306,6 +303,9 @@ gtk_cell_renderer_progress_get_property (GObject *object,
|
|||||||
case PROP_ORIENTATION:
|
case PROP_ORIENTATION:
|
||||||
g_value_set_enum (value, priv->orientation);
|
g_value_set_enum (value, priv->orientation);
|
||||||
break;
|
break;
|
||||||
|
case PROP_INVERTED:
|
||||||
|
g_value_set_boolean (value, priv->inverted);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||||
}
|
}
|
||||||
@ -343,6 +343,9 @@ gtk_cell_renderer_progress_set_property (GObject *object,
|
|||||||
case PROP_ORIENTATION:
|
case PROP_ORIENTATION:
|
||||||
priv->orientation = g_value_get_enum (value);
|
priv->orientation = g_value_get_enum (value);
|
||||||
break;
|
break;
|
||||||
|
case PROP_INVERTED:
|
||||||
|
priv->orientation = g_value_get_boolean (value);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
||||||
}
|
}
|
||||||
@ -562,8 +565,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
|
|||||||
NULL, widget, NULL,
|
NULL, widget, NULL,
|
||||||
x, y, w, h);
|
x, y, w, h);
|
||||||
|
|
||||||
if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|| priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
|
|
||||||
{
|
{
|
||||||
clip.y = y;
|
clip.y = y;
|
||||||
clip.height = h;
|
clip.height = h;
|
||||||
@ -573,7 +575,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
|
|||||||
|
|
||||||
bar_size = get_bar_size (priv->pulse, priv->value, full_size);
|
bar_size = get_bar_size (priv->pulse, priv->value, full_size);
|
||||||
|
|
||||||
if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT)
|
if (!priv->inverted)
|
||||||
bar_position = get_bar_position (start, full_size, bar_size,
|
bar_position = get_bar_position (start, full_size, bar_size,
|
||||||
priv->pulse, priv->offset, is_rtl);
|
priv->pulse, priv->offset, is_rtl);
|
||||||
else
|
else
|
||||||
@ -593,7 +595,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
|
|||||||
|
|
||||||
bar_size = get_bar_size (priv->pulse, priv->value, full_size);
|
bar_size = get_bar_size (priv->pulse, priv->value, full_size);
|
||||||
|
|
||||||
if (priv->orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
|
if (priv->inverted)
|
||||||
bar_position = get_bar_position (start, full_size, bar_size,
|
bar_position = get_bar_position (start, full_size, bar_size,
|
||||||
priv->pulse, priv->offset, TRUE);
|
priv->pulse, priv->offset, TRUE);
|
||||||
else
|
else
|
||||||
@ -637,8 +639,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
|
|||||||
|
|
||||||
if (bar_position > start)
|
if (bar_position > start)
|
||||||
{
|
{
|
||||||
if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|| priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
|
|
||||||
{
|
{
|
||||||
clip.x = x;
|
clip.x = x;
|
||||||
clip.width = bar_position - x;
|
clip.width = bar_position - x;
|
||||||
@ -658,8 +659,7 @@ gtk_cell_renderer_progress_render (GtkCellRenderer *cell,
|
|||||||
|
|
||||||
if (bar_position + bar_size < start + full_size)
|
if (bar_position + bar_size < start + full_size)
|
||||||
{
|
{
|
||||||
if (priv->orientation == GTK_PROGRESS_LEFT_TO_RIGHT
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|| priv->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
|
|
||||||
{
|
{
|
||||||
clip.x = bar_position + bar_size;
|
clip.x = bar_position + bar_size;
|
||||||
clip.width = x + w - (bar_position + bar_size);
|
clip.width = x + w - (bar_position + bar_size);
|
||||||
|
Loading…
Reference in New Issue
Block a user