[gtk+/wip/actor: 42/42] xxx: progressbar
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/actor: 42/42] xxx: progressbar
- Date: Tue, 18 Dec 2012 13:29:34 +0000 (UTC)
commit 6759b8035d8a3f2327a18a86b90894f40ace0f78
Author: Benjamin Otte <otte redhat com>
Date: Wed Dec 12 17:34:25 2012 +0100
xxx: progressbar
gtk/gtkprogressbar.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 116 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkprogressbar.c b/gtk/gtkprogressbar.c
index 111820c..d867435 100644
--- a/gtk/gtkprogressbar.c
+++ b/gtk/gtkprogressbar.c
@@ -24,15 +24,21 @@
#include "config.h"
+#include <math.h>
#include <string.h>
#include "gtkprogressbar.h"
#include "gtkorientableprivate.h"
#include "gtkprivate.h"
#include "gtkintl.h"
+#include "gtkwidgetprivate.h"
#include "a11y/gtkprogressbaraccessible.h"
+#include "actors/gtkbinlayoutprivate.h"
+#include "actors/gtkcssboxprivate.h"
+#include "actors/gtkcsstextprivate.h"
+
/**
* SECTION:gtkprogressbar
* @Short_description: A widget which indicates progress visually
@@ -70,6 +76,8 @@
struct _GtkProgressBarPrivate
{
+ GtkActor *slider;
+
gchar *text;
gdouble fraction;
@@ -117,6 +125,8 @@ static void gtk_progress_bar_get_preferred_height (GtkWidget *widget,
static void gtk_progress_bar_real_update (GtkProgressBar *progress);
static gboolean gtk_progress_bar_draw (GtkWidget *widget,
cairo_t *cr);
+static void gtk_progress_bar_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress);
static void gtk_progress_bar_finalize (GObject *object);
static void gtk_progress_bar_set_orientation (GtkProgressBar *progress,
@@ -141,6 +151,7 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
widget_class->draw = gtk_progress_bar_draw;
widget_class->get_preferred_width = gtk_progress_bar_get_preferred_width;
widget_class->get_preferred_height = gtk_progress_bar_get_preferred_height;
+ widget_class->size_allocate = gtk_progress_bar_size_allocate;
g_object_class_override_property (gobject_class, PROP_ORIENTATION, "orientation");
@@ -296,6 +307,7 @@ static void
gtk_progress_bar_init (GtkProgressBar *pbar)
{
GtkProgressBarPrivate *priv;
+ GtkActor *trough;
pbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (pbar,
GTK_TYPE_PROGRESS_BAR,
@@ -316,6 +328,14 @@ gtk_progress_bar_init (GtkProgressBar *pbar)
priv->fraction = 0.0;
gtk_widget_set_has_window (GTK_WIDGET (pbar), FALSE);
+
+ trough = _gtk_widget_get_actor (GTK_WIDGET (pbar));
+ _gtk_actor_set_layout_manager (trough, _gtk_bin_layout_new ());
+ _gtk_css_box_add_class (GTK_CSS_BOX (trough), GTK_STYLE_CLASS_TROUGH);
+ _gtk_css_box_add_class (GTK_CSS_BOX (trough), GTK_STYLE_CLASS_HORIZONTAL);
+ priv->slider = _gtk_css_box_new ();
+ _gtk_css_box_add_class (GTK_CSS_BOX (priv->slider), GTK_STYLE_CLASS_PROGRESSBAR);
+ _gtk_actor_add_child (trough, priv->slider);
}
static void
@@ -423,6 +443,44 @@ gtk_progress_bar_real_update (GtkProgressBar *pbar)
priv = pbar->priv;
widget = GTK_WIDGET (pbar);
+ if (g_getenv ("ACTOR"))
+ {
+ gboolean inverted;
+
+ inverted = priv->inverted;
+
+ if (priv->activity_mode)
+ {
+ }
+ else
+ {
+ GtkLayoutManager *layout;
+
+ layout = _gtk_actor_get_layout_manager (_gtk_widget_get_actor (widget));
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ inverted = !inverted;
+
+ _gtk_bin_layout_set_child_alignment (GTK_BIN_LAYOUT (layout),
+ priv->slider,
+ inverted ? 1.0 : 0.0,
+ 0.0,
+ priv->fraction,
+ 1.0);
+ }
+ else
+ {
+ _gtk_bin_layout_set_child_alignment (GTK_BIN_LAYOUT (layout),
+ priv->slider,
+ 0.0,
+ inverted ? 1.0 : 0.0,
+ 1.0,
+ priv->fraction);
+ }
+ }
+ }
if (priv->activity_mode)
{
GtkAllocation allocation;
@@ -534,6 +592,20 @@ gtk_progress_bar_get_preferred_width (GtkWidget *widget,
g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
+ pbar = GTK_PROGRESS_BAR (widget);
+ priv = pbar->priv;
+
+ if (g_getenv ("ACTOR"))
+ {
+ gfloat min, nat;
+
+ _gtk_actor_get_preferred_size (_gtk_widget_get_actor (widget), GTK_ORIENTATION_HORIZONTAL, -1, &min, &nat);
+
+ *minimum = ceil (min);
+ *natural = ceil (nat);
+ return;
+ }
+
style_context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (style_context, state, &padding);
@@ -542,9 +614,6 @@ gtk_progress_bar_get_preferred_width (GtkWidget *widget,
"xspacing", &xspacing,
NULL);
- pbar = GTK_PROGRESS_BAR (widget);
- priv = pbar->priv;
-
width = padding.left + padding.right + xspacing;
if (priv->show_text)
@@ -609,6 +678,20 @@ gtk_progress_bar_get_preferred_height (GtkWidget *widget,
g_return_if_fail (GTK_IS_PROGRESS_BAR (widget));
+ pbar = GTK_PROGRESS_BAR (widget);
+ priv = pbar->priv;
+
+ if (g_getenv ("ACTOR"))
+ {
+ gfloat min, nat;
+
+ _gtk_actor_get_preferred_size (_gtk_widget_get_actor (widget), GTK_ORIENTATION_VERTICAL, -1, &min, &nat);
+
+ *minimum = ceil (min);
+ *natural = ceil (nat);
+ return;
+ }
+
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
@@ -617,9 +700,6 @@ gtk_progress_bar_get_preferred_height (GtkWidget *widget,
"yspacing", &yspacing,
NULL);
- pbar = GTK_PROGRESS_BAR (widget);
- priv = pbar->priv;
-
height = padding.top + padding.bottom + yspacing;
if (priv->show_text)
@@ -648,6 +728,18 @@ gtk_progress_bar_get_preferred_height (GtkWidget *widget,
}
static void
+gtk_progress_bar_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ //cairo_matrix_t matrix = { 1.0, 0.0, 0.0, 1.0, allocation->x, allocation->y };
+
+ GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->size_allocate (widget, allocation);
+
+ //_gtk_actor_position (priv->trough, &matrix);
+ _gtk_actor_allocate (_gtk_widget_get_actor (widget), allocation->width, allocation->height);
+}
+
+static void
gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
{
GtkProgressBarPrivate *priv = pbar->priv;
@@ -970,6 +1062,12 @@ gtk_progress_bar_draw (GtkWidget *widget,
GtkBorder padding;
int width, height;
+ if (g_getenv ("ACTOR"))
+ {
+ _gtk_actor_draw (_gtk_widget_get_actor (widget), cr);
+ return FALSE;
+ }
+
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, &padding);
@@ -1220,8 +1318,20 @@ gtk_progress_bar_set_orientation (GtkProgressBar *pbar,
if (priv->orientation != orientation)
{
+ GtkActor *actor = _gtk_widget_get_actor (GTK_WIDGET (pbar));
+
priv->orientation = orientation;
_gtk_orientable_set_style_classes (GTK_ORIENTABLE (pbar));
+ if (orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ _gtk_css_box_add_class (GTK_CSS_BOX (actor), GTK_STYLE_CLASS_HORIZONTAL);
+ _gtk_css_box_remove_class (GTK_CSS_BOX (actor), GTK_STYLE_CLASS_VERTICAL);
+ }
+ else
+ {
+ _gtk_css_box_add_class (GTK_CSS_BOX (actor), GTK_STYLE_CLASS_VERTICAL);
+ _gtk_css_box_remove_class (GTK_CSS_BOX (actor), GTK_STYLE_CLASS_HORIZONTAL);
+ }
gtk_widget_queue_resize (GTK_WIDGET (pbar));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]