forked from AuroraMiddleware/gtk
Get rid of GtkProgress
The entire api was deprecated since 2.0. This patch detangles GtkProgress from GtkProgressBar and moves all the pieces into GtkProgressBar that are required for non-deprecated progressbar functionality. Bug #620618
This commit is contained in:
parent
882660e13d
commit
5e0dfed135
@ -2344,52 +2344,25 @@ GTK_PLUG_GET_CLASS
|
||||
gtk_plug_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkprogress</FILE>
|
||||
<TITLE>GtkProgress</TITLE>
|
||||
GtkProgress
|
||||
gtk_progress_set_show_text
|
||||
gtk_progress_set_text_alignment
|
||||
gtk_progress_set_format_string
|
||||
gtk_progress_set_adjustment
|
||||
gtk_progress_set_percentage
|
||||
gtk_progress_set_value
|
||||
gtk_progress_get_value
|
||||
gtk_progress_set_activity_mode
|
||||
gtk_progress_get_current_text
|
||||
gtk_progress_get_text_from_value
|
||||
gtk_progress_get_current_percentage
|
||||
gtk_progress_get_percentage_from_value
|
||||
gtk_progress_configure
|
||||
<SUBSECTION Standard>
|
||||
GTK_PROGRESS
|
||||
GTK_IS_PROGRESS
|
||||
GTK_TYPE_PROGRESS
|
||||
GTK_PROGRESS_CLASS
|
||||
GTK_IS_PROGRESS_CLASS
|
||||
GTK_PROGRESS_GET_CLASS
|
||||
<SUBSECTION Private>
|
||||
gtk_progress_get_type
|
||||
</SECTION>
|
||||
|
||||
<SECTION>
|
||||
<FILE>gtkprogressbar</FILE>
|
||||
<TITLE>GtkProgressBar</TITLE>
|
||||
GtkProgressBar
|
||||
gtk_progress_bar_new
|
||||
gtk_progress_bar_pulse
|
||||
gtk_progress_bar_set_text
|
||||
gtk_progress_bar_set_fraction
|
||||
gtk_progress_bar_set_pulse_step
|
||||
gtk_progress_bar_set_orientation
|
||||
gtk_progress_bar_set_ellipsize
|
||||
GtkProgressBarOrientation
|
||||
gtk_progress_bar_get_text
|
||||
gtk_progress_bar_get_fraction
|
||||
gtk_progress_bar_get_pulse_step
|
||||
GtkProgressBarOrientation
|
||||
gtk_progress_bar_set_orientation
|
||||
gtk_progress_bar_get_orientation
|
||||
gtk_progress_bar_set_show_text
|
||||
gtk_progress_bar_get_show_text
|
||||
gtk_progress_bar_set_text
|
||||
gtk_progress_bar_get_text
|
||||
gtk_progress_bar_set_ellipsize
|
||||
gtk_progress_bar_get_ellipsize
|
||||
GtkProgressBarStyle
|
||||
gtk_progress_bar_set_pulse_step
|
||||
gtk_progress_bar_get_pulse_step
|
||||
<SUBSECTION Standard>
|
||||
GTK_PROGRESS_BAR
|
||||
GTK_IS_PROGRESS_BAR
|
||||
|
@ -111,7 +111,6 @@ gtk_print_operation_preview_get_type
|
||||
gtk_print_settings_get_type
|
||||
gtk_print_unix_dialog_get_type
|
||||
gtk_progress_bar_get_type
|
||||
gtk_progress_get_type
|
||||
gtk_radio_action_get_type
|
||||
gtk_radio_button_get_type
|
||||
gtk_radio_menu_item_get_type
|
||||
|
@ -634,12 +634,6 @@ gtk_base_c_sources = \
|
||||
gtkwindow.c \
|
||||
$(gtk_clipboard_dnd_c_sources)
|
||||
|
||||
# Deprecated
|
||||
gtk_public_h_sources += \
|
||||
gtkprogress.h
|
||||
gtk_base_c_sources += \
|
||||
gtkprogress.c
|
||||
|
||||
gtk_c_sources = $(gtk_base_c_sources)
|
||||
gtk_all_c_sources = $(gtk_base_c_sources)
|
||||
|
||||
|
@ -365,7 +365,6 @@ gtk_recent_filter_flags_get_type G_GNUC_CONST
|
||||
gtk_print_operation_action_get_type G_GNUC_CONST
|
||||
gtk_private_flags_get_type G_GNUC_CONST
|
||||
gtk_progress_bar_orientation_get_type G_GNUC_CONST
|
||||
gtk_progress_bar_style_get_type G_GNUC_CONST
|
||||
gtk_rc_flags_get_type G_GNUC_CONST
|
||||
gtk_rc_token_type_get_type G_GNUC_CONST
|
||||
gtk_recent_chooser_error_get_type G_GNUC_CONST
|
||||
@ -2676,26 +2675,6 @@ gtk_print_win32_devnames_from_printer_name
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IN_HEADER(__GTK_PROGRESS_H__)
|
||||
#if IN_FILE(__GTK_PROGRESS_C__)
|
||||
#ifndef GTK_DISABLE_DEPRECATED
|
||||
gtk_progress_configure
|
||||
gtk_progress_get_current_percentage
|
||||
gtk_progress_get_current_text
|
||||
gtk_progress_get_percentage_from_value
|
||||
gtk_progress_get_text_from_value
|
||||
gtk_progress_get_type
|
||||
gtk_progress_get_value
|
||||
gtk_progress_set_activity_mode
|
||||
gtk_progress_set_adjustment
|
||||
gtk_progress_set_format_string
|
||||
gtk_progress_set_percentage
|
||||
gtk_progress_set_show_text
|
||||
gtk_progress_set_text_alignment
|
||||
gtk_progress_set_value
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IN_HEADER(__GTK_PROGRESS_BAR_H__)
|
||||
#if IN_FILE(__GTK_PROGRESS_BAR_C__)
|
||||
@ -2712,6 +2691,8 @@ gtk_progress_bar_set_orientation
|
||||
gtk_progress_bar_set_pulse_step
|
||||
gtk_progress_bar_set_text
|
||||
gtk_progress_bar_set_ellipsize
|
||||
gtk_progress_bar_set_show_text
|
||||
gtk_progress_bar_get_show_text
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -1,713 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#undef GTK_DISABLE_DEPRECATED
|
||||
#define __GTK_PROGRESS_C__
|
||||
|
||||
#include "gtkprogress.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkintl.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
#define EPSILON 1e-5
|
||||
#define DEFAULT_FORMAT "%P %%"
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_ACTIVITY_MODE,
|
||||
PROP_SHOW_TEXT,
|
||||
PROP_TEXT_XALIGN,
|
||||
PROP_TEXT_YALIGN
|
||||
};
|
||||
|
||||
|
||||
static void gtk_progress_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_progress_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
static void gtk_progress_destroy (GtkObject *object);
|
||||
static void gtk_progress_finalize (GObject *object);
|
||||
static void gtk_progress_realize (GtkWidget *widget);
|
||||
static gboolean gtk_progress_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event);
|
||||
static void gtk_progress_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
static void gtk_progress_create_pixmap (GtkProgress *progress);
|
||||
static void gtk_progress_value_changed (GtkAdjustment *adjustment,
|
||||
GtkProgress *progress);
|
||||
static void gtk_progress_changed (GtkAdjustment *adjustment,
|
||||
GtkProgress *progress);
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (GtkProgress, gtk_progress, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
gtk_progress_class_init (GtkProgressClass *class)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
|
||||
GtkObjectClass *object_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
|
||||
object_class = (GtkObjectClass *) class;
|
||||
widget_class = (GtkWidgetClass *) class;
|
||||
|
||||
gobject_class->finalize = gtk_progress_finalize;
|
||||
|
||||
gobject_class->set_property = gtk_progress_set_property;
|
||||
gobject_class->get_property = gtk_progress_get_property;
|
||||
object_class->destroy = gtk_progress_destroy;
|
||||
|
||||
widget_class->realize = gtk_progress_realize;
|
||||
widget_class->expose_event = gtk_progress_expose;
|
||||
widget_class->size_allocate = gtk_progress_size_allocate;
|
||||
|
||||
/* to be overridden */
|
||||
class->paint = NULL;
|
||||
class->update = NULL;
|
||||
class->act_mode_enter = NULL;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ACTIVITY_MODE,
|
||||
g_param_spec_boolean ("activity-mode",
|
||||
P_("Activity mode"),
|
||||
P_("If TRUE, the GtkProgress is in activity mode, meaning that it signals "
|
||||
"something is happening, but not how much of the activity is finished. "
|
||||
"This is used when you're doing something but don't know how long it will take."),
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SHOW_TEXT,
|
||||
g_param_spec_boolean ("show-text",
|
||||
P_("Show text"),
|
||||
P_("Whether the progress is shown as text."),
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_TEXT_XALIGN,
|
||||
g_param_spec_float ("text-xalign",
|
||||
P_("Text x alignment"),
|
||||
P_("The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts."),
|
||||
0.0, 1.0, 0.5,
|
||||
GTK_PARAM_READWRITE));
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_TEXT_YALIGN,
|
||||
g_param_spec_float ("text-yalign",
|
||||
P_("Text y alignment"),
|
||||
P_("The vertical text alignment, from 0 (top) to 1 (bottom)."),
|
||||
0.0, 1.0, 0.5,
|
||||
GTK_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkProgress *progress;
|
||||
|
||||
progress = GTK_PROGRESS (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVITY_MODE:
|
||||
gtk_progress_set_activity_mode (progress, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_SHOW_TEXT:
|
||||
gtk_progress_set_show_text (progress, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_TEXT_XALIGN:
|
||||
gtk_progress_set_text_alignment (progress,
|
||||
g_value_get_float (value),
|
||||
progress->y_align);
|
||||
break;
|
||||
case PROP_TEXT_YALIGN:
|
||||
gtk_progress_set_text_alignment (progress,
|
||||
progress->x_align,
|
||||
g_value_get_float (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkProgress *progress;
|
||||
|
||||
progress = GTK_PROGRESS (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_ACTIVITY_MODE:
|
||||
g_value_set_boolean (value, (progress->activity_mode != FALSE));
|
||||
break;
|
||||
case PROP_SHOW_TEXT:
|
||||
g_value_set_boolean (value, (progress->show_text != FALSE));
|
||||
break;
|
||||
case PROP_TEXT_XALIGN:
|
||||
g_value_set_float (value, progress->x_align);
|
||||
break;
|
||||
case PROP_TEXT_YALIGN:
|
||||
g_value_set_float (value, progress->y_align);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_init (GtkProgress *progress)
|
||||
{
|
||||
progress->adjustment = NULL;
|
||||
progress->offscreen_pixmap = NULL;
|
||||
progress->format = g_strdup (DEFAULT_FORMAT);
|
||||
progress->x_align = 0.5;
|
||||
progress->y_align = 0.5;
|
||||
progress->show_text = FALSE;
|
||||
progress->activity_mode = FALSE;
|
||||
progress->use_text_format = TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_realize (GtkWidget *widget)
|
||||
{
|
||||
GtkProgress *progress = GTK_PROGRESS (widget);
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
attributes.x = widget->allocation.x;
|
||||
attributes.y = widget->allocation.y;
|
||||
attributes.width = widget->allocation.width;
|
||||
attributes.height = widget->allocation.height;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.visual = gtk_widget_get_visual (widget);
|
||||
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||
attributes.event_mask = gtk_widget_get_events (widget);
|
||||
attributes.event_mask |= GDK_EXPOSURE_MASK;
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
||||
|
||||
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (widget->window, progress);
|
||||
|
||||
widget->style = gtk_style_attach (widget->style, widget->window);
|
||||
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
|
||||
|
||||
gtk_progress_create_pixmap (progress);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_destroy (GtkObject *object)
|
||||
{
|
||||
GtkProgress *progress = GTK_PROGRESS (object);
|
||||
|
||||
if (progress->adjustment)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (progress->adjustment,
|
||||
gtk_progress_value_changed,
|
||||
progress);
|
||||
g_signal_handlers_disconnect_by_func (progress->adjustment,
|
||||
gtk_progress_changed,
|
||||
progress);
|
||||
g_object_unref (progress->adjustment);
|
||||
progress->adjustment = NULL;
|
||||
}
|
||||
|
||||
GTK_OBJECT_CLASS (gtk_progress_parent_class)->destroy (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_finalize (GObject *object)
|
||||
{
|
||||
GtkProgress *progress = GTK_PROGRESS (object);
|
||||
|
||||
if (progress->offscreen_pixmap)
|
||||
g_object_unref (progress->offscreen_pixmap);
|
||||
|
||||
g_free (progress->format);
|
||||
|
||||
G_OBJECT_CLASS (gtk_progress_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_progress_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event)
|
||||
{
|
||||
if (gtk_widget_is_drawable (widget))
|
||||
gdk_draw_drawable (widget->window,
|
||||
widget->style->black_gc,
|
||||
GTK_PROGRESS (widget)->offscreen_pixmap,
|
||||
event->area.x, event->area.y,
|
||||
event->area.x, event->area.y,
|
||||
event->area.width,
|
||||
event->area.height);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
widget->allocation = *allocation;
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
gdk_window_move_resize (widget->window,
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
gtk_progress_create_pixmap (GTK_PROGRESS (widget));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_create_pixmap (GtkProgress *progress)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
|
||||
widget = GTK_WIDGET (progress);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
if (progress->offscreen_pixmap)
|
||||
g_object_unref (progress->offscreen_pixmap);
|
||||
|
||||
progress->offscreen_pixmap = gdk_pixmap_new (widget->window,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height,
|
||||
-1);
|
||||
|
||||
/* clear the pixmap for transparent themes */
|
||||
gtk_paint_flat_box (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
GTK_STATE_NORMAL, GTK_SHADOW_NONE,
|
||||
NULL, widget, "trough", 0, 0, -1, -1);
|
||||
|
||||
GTK_PROGRESS_GET_CLASS (progress)->paint (progress);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_changed (GtkAdjustment *adjustment,
|
||||
GtkProgress *progress)
|
||||
{
|
||||
/* A change in the value of adjustment->upper can change
|
||||
* the size request
|
||||
*/
|
||||
if (progress->use_text_format && progress->show_text)
|
||||
gtk_widget_queue_resize (GTK_WIDGET (progress));
|
||||
else
|
||||
GTK_PROGRESS_GET_CLASS (progress)->update (progress);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_value_changed (GtkAdjustment *adjustment,
|
||||
GtkProgress *progress)
|
||||
{
|
||||
GTK_PROGRESS_GET_CLASS (progress)->update (progress);
|
||||
}
|
||||
|
||||
static gchar *
|
||||
gtk_progress_build_string (GtkProgress *progress,
|
||||
gdouble value,
|
||||
gdouble percentage)
|
||||
{
|
||||
gchar buf[256] = { 0 };
|
||||
gchar tmp[256] = { 0 };
|
||||
gchar *src;
|
||||
gchar *dest;
|
||||
gchar fmt[10];
|
||||
|
||||
src = progress->format;
|
||||
|
||||
/* This is the new supported version of this function */
|
||||
if (!progress->use_text_format)
|
||||
return g_strdup (src);
|
||||
|
||||
/* And here's all the deprecated goo. */
|
||||
|
||||
dest = buf;
|
||||
|
||||
while (src && *src)
|
||||
{
|
||||
if (*src != '%')
|
||||
{
|
||||
*dest = *src;
|
||||
dest++;
|
||||
}
|
||||
else
|
||||
{
|
||||
gchar c;
|
||||
gint digits;
|
||||
|
||||
c = *(src + sizeof(gchar));
|
||||
digits = 0;
|
||||
|
||||
if (c >= '0' && c <= '2')
|
||||
{
|
||||
digits = (gint) (c - '0');
|
||||
src++;
|
||||
c = *(src + sizeof(gchar));
|
||||
}
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '%':
|
||||
*dest = '%';
|
||||
src++;
|
||||
dest++;
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
if (digits)
|
||||
{
|
||||
g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
|
||||
g_snprintf (tmp, sizeof (tmp), fmt, 100 * percentage);
|
||||
}
|
||||
else
|
||||
g_snprintf (tmp, sizeof (tmp), "%.0f", 100 * percentage);
|
||||
strcat (buf, tmp);
|
||||
dest = &(buf[strlen (buf)]);
|
||||
src++;
|
||||
break;
|
||||
case 'v':
|
||||
case 'V':
|
||||
if (digits)
|
||||
{
|
||||
g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
|
||||
g_snprintf (tmp, sizeof (tmp), fmt, value);
|
||||
}
|
||||
else
|
||||
g_snprintf (tmp, sizeof (tmp), "%.0f", value);
|
||||
strcat (buf, tmp);
|
||||
dest = &(buf[strlen (buf)]);
|
||||
src++;
|
||||
break;
|
||||
case 'l':
|
||||
case 'L':
|
||||
if (digits)
|
||||
{
|
||||
g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
|
||||
g_snprintf (tmp, sizeof (tmp), fmt, progress->adjustment->lower);
|
||||
}
|
||||
else
|
||||
g_snprintf (tmp, sizeof (tmp), "%.0f", progress->adjustment->lower);
|
||||
strcat (buf, tmp);
|
||||
dest = &(buf[strlen (buf)]);
|
||||
src++;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
if (digits)
|
||||
{
|
||||
g_snprintf (fmt, sizeof (fmt), "%%.%df", digits);
|
||||
g_snprintf (tmp, sizeof (tmp), fmt, progress->adjustment->upper);
|
||||
}
|
||||
else
|
||||
g_snprintf (tmp, sizeof (tmp), "%.0f", progress->adjustment->upper);
|
||||
strcat (buf, tmp);
|
||||
dest = &(buf[strlen (buf)]);
|
||||
src++;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
src++;
|
||||
}
|
||||
|
||||
return g_strdup (buf);
|
||||
}
|
||||
|
||||
/***************************************************************/
|
||||
|
||||
void
|
||||
gtk_progress_set_adjustment (GtkProgress *progress,
|
||||
GtkAdjustment *adjustment)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
if (adjustment)
|
||||
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
|
||||
else
|
||||
adjustment = (GtkAdjustment*) gtk_adjustment_new (0, 0, 100, 0, 0, 0);
|
||||
|
||||
if (progress->adjustment != adjustment)
|
||||
{
|
||||
if (progress->adjustment)
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (progress->adjustment,
|
||||
gtk_progress_changed,
|
||||
progress);
|
||||
g_signal_handlers_disconnect_by_func (progress->adjustment,
|
||||
gtk_progress_value_changed,
|
||||
progress);
|
||||
g_object_unref (progress->adjustment);
|
||||
}
|
||||
progress->adjustment = adjustment;
|
||||
if (adjustment)
|
||||
{
|
||||
g_object_ref_sink (adjustment);
|
||||
g_signal_connect (adjustment, "changed",
|
||||
G_CALLBACK (gtk_progress_changed),
|
||||
progress);
|
||||
g_signal_connect (adjustment, "value-changed",
|
||||
G_CALLBACK (gtk_progress_value_changed),
|
||||
progress);
|
||||
}
|
||||
|
||||
gtk_progress_changed (adjustment, progress);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_configure (GtkProgress *progress,
|
||||
gdouble value,
|
||||
gdouble min,
|
||||
gdouble max)
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
gboolean changed = FALSE;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
g_return_if_fail (min <= max);
|
||||
g_return_if_fail (value >= min && value <= max);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
adj = progress->adjustment;
|
||||
|
||||
if (fabs (adj->lower - min) > EPSILON || fabs (adj->upper - max) > EPSILON)
|
||||
changed = TRUE;
|
||||
|
||||
adj->value = value;
|
||||
adj->lower = min;
|
||||
adj->upper = max;
|
||||
|
||||
gtk_adjustment_value_changed (adj);
|
||||
if (changed)
|
||||
gtk_adjustment_changed (adj);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_percentage (GtkProgress *progress,
|
||||
gdouble percentage)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
g_return_if_fail (percentage >= 0 && percentage <= 1.0);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
gtk_progress_set_value (progress, progress->adjustment->lower + percentage *
|
||||
(progress->adjustment->upper - progress->adjustment->lower));
|
||||
}
|
||||
|
||||
gdouble
|
||||
gtk_progress_get_current_percentage (GtkProgress *progress)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
|
||||
return gtk_progress_get_percentage_from_value (progress, progress->adjustment->value);
|
||||
}
|
||||
|
||||
gdouble
|
||||
gtk_progress_get_percentage_from_value (GtkProgress *progress,
|
||||
gdouble value)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
|
||||
if (progress->adjustment->lower < progress->adjustment->upper &&
|
||||
value >= progress->adjustment->lower &&
|
||||
value <= progress->adjustment->upper)
|
||||
return (value - progress->adjustment->lower) /
|
||||
(progress->adjustment->upper - progress->adjustment->lower);
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_value (GtkProgress *progress,
|
||||
gdouble value)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
|
||||
if (fabs (progress->adjustment->value - value) > EPSILON)
|
||||
gtk_adjustment_set_value (progress->adjustment, value);
|
||||
}
|
||||
|
||||
gdouble
|
||||
gtk_progress_get_value (GtkProgress *progress)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS (progress), 0);
|
||||
|
||||
return progress->adjustment ? progress->adjustment->value : 0;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_show_text (GtkProgress *progress,
|
||||
gboolean show_text)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
|
||||
if (progress->show_text != show_text)
|
||||
{
|
||||
progress->show_text = show_text;
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (progress));
|
||||
|
||||
g_object_notify (G_OBJECT (progress), "show-text");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_text_alignment (GtkProgress *progress,
|
||||
gfloat x_align,
|
||||
gfloat y_align)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
g_return_if_fail (x_align >= 0.0 && x_align <= 1.0);
|
||||
g_return_if_fail (y_align >= 0.0 && y_align <= 1.0);
|
||||
|
||||
if (progress->x_align != x_align || progress->y_align != y_align)
|
||||
{
|
||||
g_object_freeze_notify (G_OBJECT (progress));
|
||||
if (progress->x_align != x_align)
|
||||
{
|
||||
progress->x_align = x_align;
|
||||
g_object_notify (G_OBJECT (progress), "text-xalign");
|
||||
}
|
||||
|
||||
if (progress->y_align != y_align)
|
||||
{
|
||||
progress->y_align = y_align;
|
||||
g_object_notify (G_OBJECT (progress), "text-yalign");
|
||||
}
|
||||
g_object_thaw_notify (G_OBJECT (progress));
|
||||
|
||||
if (gtk_widget_is_drawable (GTK_WIDGET (progress)))
|
||||
gtk_widget_queue_resize (GTK_WIDGET (progress));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_format_string (GtkProgress *progress,
|
||||
const gchar *format)
|
||||
{
|
||||
gchar *old_format;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
|
||||
/* Turn on format, in case someone called
|
||||
* gtk_progress_bar_set_text() and turned it off.
|
||||
*/
|
||||
progress->use_text_format = TRUE;
|
||||
|
||||
old_format = progress->format;
|
||||
|
||||
if (!format)
|
||||
format = DEFAULT_FORMAT;
|
||||
|
||||
progress->format = g_strdup (format);
|
||||
g_free (old_format);
|
||||
|
||||
gtk_widget_queue_resize (GTK_WIDGET (progress));
|
||||
}
|
||||
|
||||
gchar *
|
||||
gtk_progress_get_current_text (GtkProgress *progress)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
|
||||
return gtk_progress_build_string (progress, progress->adjustment->value,
|
||||
gtk_progress_get_current_percentage (progress));
|
||||
}
|
||||
|
||||
gchar *
|
||||
gtk_progress_get_text_from_value (GtkProgress *progress,
|
||||
gdouble value)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS (progress), NULL);
|
||||
|
||||
if (!progress->adjustment)
|
||||
gtk_progress_set_adjustment (progress, NULL);
|
||||
|
||||
return gtk_progress_build_string (progress, value,
|
||||
gtk_progress_get_percentage_from_value (progress, value));
|
||||
}
|
||||
|
||||
void
|
||||
gtk_progress_set_activity_mode (GtkProgress *progress,
|
||||
gboolean activity_mode)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
|
||||
if (progress->activity_mode != (activity_mode != FALSE))
|
||||
{
|
||||
progress->activity_mode = (activity_mode != FALSE);
|
||||
|
||||
if (progress->activity_mode)
|
||||
GTK_PROGRESS_GET_CLASS (progress)->act_mode_enter (progress);
|
||||
|
||||
if (gtk_widget_is_drawable (GTK_WIDGET (progress)))
|
||||
gtk_widget_queue_resize (GTK_WIDGET (progress));
|
||||
|
||||
g_object_notify (G_OBJECT (progress), "activity-mode");
|
||||
}
|
||||
}
|
||||
|
||||
#include "gtkaliasdef.c"
|
@ -1,120 +0,0 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#ifndef __GTK_PROGRESS_H__
|
||||
#define __GTK_PROGRESS_H__
|
||||
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
#include <gtk/gtkadjustment.h>
|
||||
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#if !defined (GTK_DISABLE_DEPRECATED) || defined (__GTK_PROGRESS_C__) || defined (__GTK_PROGRESS_BAR_C__)
|
||||
|
||||
#define GTK_TYPE_PROGRESS (gtk_progress_get_type ())
|
||||
#define GTK_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_PROGRESS, GtkProgress))
|
||||
#define GTK_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_PROGRESS, GtkProgressClass))
|
||||
#define GTK_IS_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_PROGRESS))
|
||||
#define GTK_IS_PROGRESS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PROGRESS))
|
||||
#define GTK_PROGRESS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PROGRESS, GtkProgressClass))
|
||||
|
||||
#endif /* !GTK_DISABLE_DEPRECATED */
|
||||
|
||||
typedef struct _GtkProgress GtkProgress;
|
||||
typedef struct _GtkProgressClass GtkProgressClass;
|
||||
|
||||
|
||||
struct _GtkProgress
|
||||
{
|
||||
GtkWidget widget;
|
||||
|
||||
GtkAdjustment *adjustment;
|
||||
GdkPixmap *offscreen_pixmap;
|
||||
gchar *format;
|
||||
gfloat x_align;
|
||||
gfloat y_align;
|
||||
|
||||
guint show_text : 1;
|
||||
guint activity_mode : 1;
|
||||
guint use_text_format : 1;
|
||||
};
|
||||
|
||||
struct _GtkProgressClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void (* paint) (GtkProgress *progress);
|
||||
void (* update) (GtkProgress *progress);
|
||||
void (* act_mode_enter) (GtkProgress *progress);
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gtk_reserved1) (void);
|
||||
void (*_gtk_reserved2) (void);
|
||||
void (*_gtk_reserved3) (void);
|
||||
void (*_gtk_reserved4) (void);
|
||||
};
|
||||
|
||||
/* This entire interface is deprecated. Use GtkProgressBar
|
||||
* directly.
|
||||
*/
|
||||
|
||||
#if !defined (GTK_DISABLE_DEPRECATED) || defined (__GTK_PROGRESS_C__) || defined (__GTK_PROGRESS_BAR_C__)
|
||||
|
||||
GType gtk_progress_get_type (void) G_GNUC_CONST;
|
||||
void gtk_progress_set_show_text (GtkProgress *progress,
|
||||
gboolean show_text);
|
||||
void gtk_progress_set_text_alignment (GtkProgress *progress,
|
||||
gfloat x_align,
|
||||
gfloat y_align);
|
||||
void gtk_progress_set_format_string (GtkProgress *progress,
|
||||
const gchar *format);
|
||||
void gtk_progress_set_adjustment (GtkProgress *progress,
|
||||
GtkAdjustment *adjustment);
|
||||
void gtk_progress_configure (GtkProgress *progress,
|
||||
gdouble value,
|
||||
gdouble min,
|
||||
gdouble max);
|
||||
void gtk_progress_set_percentage (GtkProgress *progress,
|
||||
gdouble percentage);
|
||||
void gtk_progress_set_value (GtkProgress *progress,
|
||||
gdouble value);
|
||||
gdouble gtk_progress_get_value (GtkProgress *progress);
|
||||
void gtk_progress_set_activity_mode (GtkProgress *progress,
|
||||
gboolean activity_mode);
|
||||
gchar* gtk_progress_get_current_text (GtkProgress *progress);
|
||||
gchar* gtk_progress_get_text_from_value (GtkProgress *progress,
|
||||
gdouble value);
|
||||
gdouble gtk_progress_get_current_percentage (GtkProgress *progress);
|
||||
gdouble gtk_progress_get_percentage_from_value (GtkProgress *progress,
|
||||
gdouble value);
|
||||
|
||||
#endif /* !GTK_DISABLE_DEPRECATED */
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_PROGRESS_H__ */
|
@ -44,14 +44,12 @@
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
/* Supported args */
|
||||
PROP_FRACTION,
|
||||
PROP_PULSE_STEP,
|
||||
PROP_ORIENTATION,
|
||||
PROP_TEXT,
|
||||
PROP_ELLIPSIZE,
|
||||
|
||||
PROP_SHOW_TEXT,
|
||||
PROP_ELLIPSIZE
|
||||
};
|
||||
|
||||
static void gtk_progress_bar_set_property (GObject *object,
|
||||
@ -66,11 +64,16 @@ static gboolean gtk_progress_bar_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event);
|
||||
static void gtk_progress_bar_size_request (GtkWidget *widget,
|
||||
GtkRequisition *requisition);
|
||||
static void gtk_progress_bar_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
static void gtk_progress_bar_style_set (GtkWidget *widget,
|
||||
GtkStyle *previous);
|
||||
static void gtk_progress_bar_real_update (GtkProgress *progress);
|
||||
static void gtk_progress_bar_paint (GtkProgress *progress);
|
||||
static void gtk_progress_bar_act_mode_enter (GtkProgress *progress);
|
||||
static void gtk_progress_bar_real_update (GtkProgressBar *progress);
|
||||
static void gtk_progress_bar_paint (GtkProgressBar *progress);
|
||||
static void gtk_progress_bar_act_mode_enter (GtkProgressBar *progress);
|
||||
static void gtk_progress_bar_realize (GtkWidget *widget);
|
||||
static void gtk_progress_bar_finalize (GObject *object);
|
||||
static void gtk_progress_bar_create_pixmap (GtkProgressBar *pbar);
|
||||
|
||||
|
||||
typedef struct
|
||||
@ -82,29 +85,30 @@ typedef struct
|
||||
#define GTK_PROGRESS_BAR_GET_PRIVATE(o) \
|
||||
(G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PROGRESS_BAR, GtkProgressBarPrivate))
|
||||
|
||||
G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_PROGRESS)
|
||||
G_DEFINE_TYPE (GtkProgressBar, gtk_progress_bar, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
gtk_progress_bar_class_init (GtkProgressBarClass *class)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
GtkProgressClass *progress_class;
|
||||
|
||||
gobject_class = G_OBJECT_CLASS (class);
|
||||
widget_class = (GtkWidgetClass *) class;
|
||||
progress_class = (GtkProgressClass *) class;
|
||||
|
||||
gobject_class->set_property = gtk_progress_bar_set_property;
|
||||
gobject_class->get_property = gtk_progress_bar_get_property;
|
||||
gobject_class->finalize = gtk_progress_bar_finalize;
|
||||
|
||||
widget_class->realize = gtk_progress_bar_realize;
|
||||
widget_class->expose_event = gtk_progress_bar_expose;
|
||||
widget_class->size_request = gtk_progress_bar_size_request;
|
||||
widget_class->size_allocate = gtk_progress_bar_size_allocate;
|
||||
widget_class->style_set = gtk_progress_bar_style_set;
|
||||
|
||||
progress_class->paint = gtk_progress_bar_paint;
|
||||
progress_class->update = gtk_progress_bar_real_update;
|
||||
progress_class->act_mode_enter = gtk_progress_bar_act_mode_enter;
|
||||
class->paint = gtk_progress_bar_paint;
|
||||
class->update = gtk_progress_bar_real_update;
|
||||
class->act_mode_enter = gtk_progress_bar_act_mode_enter;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_ORIENTATION,
|
||||
@ -139,6 +143,14 @@ gtk_progress_bar_class_init (GtkProgressBarClass *class)
|
||||
NULL,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_SHOW_TEXT,
|
||||
g_param_spec_boolean ("show-text",
|
||||
P_("Show text"),
|
||||
P_("Whether the progress is shown as text."),
|
||||
FALSE,
|
||||
GTK_PARAM_READWRITE));
|
||||
|
||||
/**
|
||||
* GtkProgressBar:ellipsize:
|
||||
*
|
||||
@ -236,7 +248,6 @@ gtk_progress_bar_init (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBarPrivate* priv;
|
||||
|
||||
pbar->bar_style = GTK_PROGRESS_CONTINUOUS;
|
||||
pbar->blocks = 10;
|
||||
pbar->in_block = -1;
|
||||
pbar->orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
|
||||
@ -246,6 +257,7 @@ gtk_progress_bar_init (GtkProgressBar *pbar)
|
||||
pbar->activity_step = 3;
|
||||
pbar->activity_blocks = 5;
|
||||
pbar->ellipsize = PANGO_ELLIPSIZE_NONE;
|
||||
pbar->show_text = FALSE;
|
||||
|
||||
/* FIXME: Put priv in the structure once we break ABI */
|
||||
priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
@ -253,6 +265,36 @@ gtk_progress_bar_init (GtkProgressBar *pbar)
|
||||
priv->fraction = 0.0;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_realize (GtkWidget *widget)
|
||||
{
|
||||
GdkWindowAttr attributes;
|
||||
gint attributes_mask;
|
||||
|
||||
gtk_widget_set_realized (widget, TRUE);
|
||||
|
||||
attributes.window_type = GDK_WINDOW_CHILD;
|
||||
attributes.x = widget->allocation.x;
|
||||
attributes.y = widget->allocation.y;
|
||||
attributes.width = widget->allocation.width;
|
||||
attributes.height = widget->allocation.height;
|
||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||
attributes.visual = gtk_widget_get_visual (widget);
|
||||
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||
attributes.event_mask = gtk_widget_get_events (widget);
|
||||
attributes.event_mask |= GDK_EXPOSURE_MASK;
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
||||
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
||||
&attributes, attributes_mask);
|
||||
gdk_window_set_user_data (widget->window, widget);
|
||||
|
||||
widget->style = gtk_style_attach (widget->style, widget->window);
|
||||
gtk_style_set_background (widget->style, widget->window, GTK_STATE_ACTIVE);
|
||||
|
||||
gtk_progress_bar_create_pixmap (GTK_PROGRESS_BAR (widget));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
@ -277,6 +319,9 @@ gtk_progress_bar_set_property (GObject *object,
|
||||
case PROP_TEXT:
|
||||
gtk_progress_bar_set_text (pbar, g_value_get_string (value));
|
||||
break;
|
||||
case PROP_SHOW_TEXT:
|
||||
gtk_progress_bar_set_show_text (pbar, g_value_get_boolean (value));
|
||||
break;
|
||||
case PROP_ELLIPSIZE:
|
||||
gtk_progress_bar_set_ellipsize (pbar, g_value_get_enum (value));
|
||||
break;
|
||||
@ -312,6 +357,9 @@ gtk_progress_bar_get_property (GObject *object,
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, priv->text);
|
||||
break;
|
||||
case PROP_SHOW_TEXT:
|
||||
g_value_set_boolean (value, pbar->show_text);
|
||||
break;
|
||||
case PROP_ELLIPSIZE:
|
||||
g_value_set_enum (value, pbar->ellipsize);
|
||||
break;
|
||||
@ -332,30 +380,23 @@ gtk_progress_bar_new (void)
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_real_update (GtkProgress *progress)
|
||||
gtk_progress_bar_real_update (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBar *pbar;
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS (progress));
|
||||
g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
|
||||
|
||||
pbar = GTK_PROGRESS_BAR (progress);
|
||||
widget = GTK_WIDGET (progress);
|
||||
widget = GTK_WIDGET (pbar);
|
||||
|
||||
if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS ||
|
||||
GTK_PROGRESS (pbar)->activity_mode)
|
||||
{
|
||||
if (GTK_PROGRESS (pbar)->activity_mode)
|
||||
if (pbar->activity_mode)
|
||||
{
|
||||
guint size;
|
||||
|
||||
/* advance the block */
|
||||
|
||||
if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
|
||||
pbar->orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
|
||||
{
|
||||
/* Update our activity step. */
|
||||
|
||||
pbar->activity_step = widget->allocation.width * pbar->pulse_fraction;
|
||||
|
||||
size = MAX (2, widget->allocation.width / pbar->activity_blocks);
|
||||
@ -363,9 +404,7 @@ gtk_progress_bar_real_update (GtkProgress *progress)
|
||||
if (pbar->activity_dir == 0)
|
||||
{
|
||||
pbar->activity_pos += pbar->activity_step;
|
||||
if (pbar->activity_pos + size >=
|
||||
widget->allocation.width -
|
||||
widget->style->xthickness)
|
||||
if (pbar->activity_pos + size >= widget->allocation.width - widget->style->xthickness)
|
||||
{
|
||||
pbar->activity_pos = widget->allocation.width -
|
||||
widget->style->xthickness - size;
|
||||
@ -385,7 +424,6 @@ gtk_progress_bar_real_update (GtkProgress *progress)
|
||||
else
|
||||
{
|
||||
/* Update our activity step. */
|
||||
|
||||
pbar->activity_step = widget->allocation.height * pbar->pulse_fraction;
|
||||
|
||||
size = MAX (2, widget->allocation.height / pbar->activity_blocks);
|
||||
@ -393,9 +431,7 @@ gtk_progress_bar_real_update (GtkProgress *progress)
|
||||
if (pbar->activity_dir == 0)
|
||||
{
|
||||
pbar->activity_pos += pbar->activity_step;
|
||||
if (pbar->activity_pos + size >=
|
||||
widget->allocation.height -
|
||||
widget->style->ythickness)
|
||||
if (pbar->activity_pos + size >= widget->allocation.height - widget->style->ythickness)
|
||||
{
|
||||
pbar->activity_pos = widget->allocation.height -
|
||||
widget->style->ythickness - size;
|
||||
@ -414,38 +450,57 @@ gtk_progress_bar_real_update (GtkProgress *progress)
|
||||
}
|
||||
}
|
||||
pbar->dirty = TRUE;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (progress));
|
||||
gtk_widget_queue_draw (widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
gint in_block;
|
||||
|
||||
in_block = -1 + (gint)(gtk_progress_get_current_percentage (progress) *
|
||||
(gdouble)pbar->blocks);
|
||||
|
||||
if (pbar->in_block != in_block)
|
||||
static void
|
||||
gtk_progress_bar_finalize (GObject *object)
|
||||
{
|
||||
pbar->in_block = in_block;
|
||||
pbar->dirty = TRUE;
|
||||
gtk_widget_queue_draw (GTK_WIDGET (progress));
|
||||
}
|
||||
}
|
||||
GtkProgressBar *pbar = GTK_PROGRESS_BAR (object);
|
||||
GtkProgressBarPrivate *priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
|
||||
if (pbar->offscreen_pixmap)
|
||||
g_object_unref (pbar->offscreen_pixmap);
|
||||
|
||||
g_free (priv->text);
|
||||
|
||||
G_OBJECT_CLASS (gtk_progress_bar_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_progress_bar_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event)
|
||||
{
|
||||
GtkProgressBar *pbar;
|
||||
GtkProgressBar *pbar = GTK_PROGRESS_BAR (widget);
|
||||
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS_BAR (widget), FALSE);
|
||||
if (gtk_widget_is_drawable (widget))
|
||||
{
|
||||
if (pbar->dirty)
|
||||
gtk_progress_bar_paint (pbar);
|
||||
|
||||
pbar = GTK_PROGRESS_BAR (widget);
|
||||
gdk_draw_drawable (widget->window,
|
||||
widget->style->black_gc,
|
||||
pbar->offscreen_pixmap,
|
||||
event->area.x, event->area.y,
|
||||
event->area.x, event->area.y,
|
||||
event->area.width,
|
||||
event->area.height);
|
||||
}
|
||||
|
||||
if (pbar->dirty && gtk_widget_is_drawable (widget))
|
||||
gtk_progress_bar_paint (GTK_PROGRESS (pbar));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return GTK_WIDGET_CLASS (gtk_progress_bar_parent_class)->expose_event (widget, event);
|
||||
static gchar *
|
||||
get_current_text (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBarPrivate *priv;
|
||||
|
||||
priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
|
||||
if (priv->text)
|
||||
return g_strdup (priv->text);
|
||||
else
|
||||
return g_strdup_printf ("%.0f %%", priv->fraction * 100.0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -475,8 +530,9 @@ gtk_progress_bar_size_request (GtkWidget *widget,
|
||||
width = 2 * widget->style->xthickness + xspacing;
|
||||
height = 2 * widget->style->ythickness + yspacing;
|
||||
|
||||
if ((buf = priv->text))
|
||||
if (pbar->show_text)
|
||||
{
|
||||
buf = get_current_text (pbar);
|
||||
layout = gtk_widget_create_pango_layout (widget, buf);
|
||||
|
||||
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
||||
@ -502,6 +558,7 @@ gtk_progress_bar_size_request (GtkWidget *widget,
|
||||
height += logical_rect.height;
|
||||
|
||||
g_object_unref (layout);
|
||||
g_free (buf);
|
||||
}
|
||||
|
||||
if (pbar->orientation == GTK_PROGRESS_LEFT_TO_RIGHT ||
|
||||
@ -520,6 +577,50 @@ gtk_progress_bar_size_request (GtkWidget *widget,
|
||||
requisition->height = MAX (min_height, height);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
widget->allocation = *allocation;
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
gdk_window_move_resize (widget->window,
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
gtk_progress_bar_create_pixmap (GTK_PROGRESS_BAR (widget));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_create_pixmap (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = GTK_WIDGET (pbar);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
if (pbar->offscreen_pixmap)
|
||||
g_object_unref (pbar->offscreen_pixmap);
|
||||
|
||||
pbar->offscreen_pixmap = gdk_pixmap_new (widget->window,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height,
|
||||
-1);
|
||||
|
||||
/* clear the pixmap for transparent themes */
|
||||
gtk_paint_flat_box (widget->style,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_NORMAL,
|
||||
GTK_SHADOW_NONE,
|
||||
NULL, widget, "trough", 0, 0, -1, -1);
|
||||
|
||||
GTK_PROGRESS_BAR_GET_CLASS (pbar)->paint (pbar);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_style_set (GtkWidget *widget,
|
||||
GtkStyle *previous)
|
||||
@ -532,14 +633,12 @@ gtk_progress_bar_style_set (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_act_mode_enter (GtkProgress *progress)
|
||||
gtk_progress_bar_act_mode_enter (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBar *pbar;
|
||||
GtkWidget *widget;
|
||||
GtkProgressBarOrientation orientation;
|
||||
|
||||
pbar = GTK_PROGRESS_BAR (progress);
|
||||
widget = GTK_WIDGET (progress);
|
||||
widget = GTK_WIDGET (pbar);
|
||||
|
||||
orientation = pbar->orientation;
|
||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
@ -614,7 +713,6 @@ gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
|
||||
GtkProgressBarOrientation orientation)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (pbar);
|
||||
GtkProgress *progress = GTK_PROGRESS (pbar);
|
||||
GdkRectangle area;
|
||||
|
||||
switch (orientation)
|
||||
@ -639,7 +737,7 @@ gtk_progress_bar_paint_activity (GtkProgressBar *pbar,
|
||||
}
|
||||
|
||||
gtk_paint_box (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
|
||||
&area, widget, "bar",
|
||||
area.x, area.y, area.width, area.height);
|
||||
@ -686,72 +784,18 @@ gtk_progress_bar_paint_continuous (GtkProgressBar *pbar,
|
||||
}
|
||||
|
||||
gtk_paint_box (widget->style,
|
||||
GTK_PROGRESS (pbar)->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
|
||||
&area, widget, "bar",
|
||||
area.x, area.y, area.width, area.height);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_paint_discrete (GtkProgressBar *pbar,
|
||||
GtkProgressBarOrientation orientation)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (pbar);
|
||||
gint i;
|
||||
|
||||
for (i = 0; i <= pbar->in_block; i++)
|
||||
{
|
||||
GdkRectangle area;
|
||||
gint space;
|
||||
|
||||
switch (orientation)
|
||||
{
|
||||
case GTK_PROGRESS_LEFT_TO_RIGHT:
|
||||
case GTK_PROGRESS_RIGHT_TO_LEFT:
|
||||
space = widget->allocation.width - 2 * widget->style->xthickness;
|
||||
|
||||
area.x = widget->style->xthickness + (i * space) / pbar->blocks;
|
||||
area.y = widget->style->ythickness;
|
||||
area.width = widget->style->xthickness + ((i + 1) * space) / pbar->blocks - area.x;
|
||||
area.height = widget->allocation.height - 2 * widget->style->ythickness;
|
||||
|
||||
if (orientation == GTK_PROGRESS_RIGHT_TO_LEFT)
|
||||
area.x = widget->allocation.width - area.width - area.x;
|
||||
break;
|
||||
|
||||
case GTK_PROGRESS_TOP_TO_BOTTOM:
|
||||
case GTK_PROGRESS_BOTTOM_TO_TOP:
|
||||
space = widget->allocation.height - 2 * widget->style->ythickness;
|
||||
|
||||
area.x = widget->style->xthickness;
|
||||
area.y = widget->style->ythickness + (i * space) / pbar->blocks;
|
||||
area.width = widget->allocation.width - 2 * widget->style->xthickness;
|
||||
area.height = widget->style->ythickness + ((i + 1) * space) / pbar->blocks - area.y;
|
||||
|
||||
if (orientation == GTK_PROGRESS_BOTTOM_TO_TOP)
|
||||
area.y = widget->allocation.height - area.height - area.y;
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
gtk_paint_box (widget->style,
|
||||
GTK_PROGRESS (pbar)->offscreen_pixmap,
|
||||
GTK_STATE_PRELIGHT, GTK_SHADOW_OUT,
|
||||
&area, widget, "bar",
|
||||
area.x, area.y, area.width, area.height);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
gint offset,
|
||||
gint amount,
|
||||
GtkProgressBarOrientation orientation)
|
||||
{
|
||||
GtkProgress *progress = GTK_PROGRESS (pbar);
|
||||
GtkWidget *widget = GTK_WIDGET (pbar);
|
||||
gint x;
|
||||
gint y;
|
||||
@ -760,13 +804,13 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect;
|
||||
GdkRectangle prelight_clip, start_clip, end_clip;
|
||||
gfloat text_xalign = progress->x_align;
|
||||
gfloat text_yalign = progress->y_align;
|
||||
gfloat text_xalign = 0.5;
|
||||
gfloat text_yalign = 0.5;
|
||||
|
||||
if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR)
|
||||
text_xalign = 1.0 - text_xalign;
|
||||
|
||||
buf = gtk_progress_get_current_text (progress);
|
||||
buf = get_current_text (pbar);
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, buf);
|
||||
pango_layout_set_ellipsize (layout, pbar->ellipsize);
|
||||
@ -835,7 +879,7 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
|
||||
if (start_clip.width > 0 && start_clip.height > 0)
|
||||
gtk_paint_layout (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_NORMAL,
|
||||
FALSE,
|
||||
&start_clip,
|
||||
@ -846,7 +890,7 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
|
||||
if (end_clip.width > 0 && end_clip.height > 0)
|
||||
gtk_paint_layout (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_NORMAL,
|
||||
FALSE,
|
||||
&end_clip,
|
||||
@ -856,7 +900,7 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
layout);
|
||||
|
||||
gtk_paint_layout (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_PRELIGHT,
|
||||
FALSE,
|
||||
&prelight_clip,
|
||||
@ -870,19 +914,14 @@ gtk_progress_bar_paint_text (GtkProgressBar *pbar,
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_paint (GtkProgress *progress)
|
||||
gtk_progress_bar_paint (GtkProgressBar *pbar)
|
||||
{
|
||||
GtkProgressBar *pbar;
|
||||
GtkProgressBarPrivate *priv;
|
||||
GtkWidget *widget;
|
||||
|
||||
GtkProgressBarOrientation orientation;
|
||||
|
||||
g_return_if_fail (GTK_IS_PROGRESS_BAR (progress));
|
||||
|
||||
pbar = GTK_PROGRESS_BAR (progress);
|
||||
priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
widget = GTK_WIDGET (progress);
|
||||
widget = GTK_WIDGET (pbar);
|
||||
|
||||
orientation = pbar->orientation;
|
||||
if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
|
||||
@ -893,21 +932,21 @@ gtk_progress_bar_paint (GtkProgress *progress)
|
||||
orientation = GTK_PROGRESS_LEFT_TO_RIGHT;
|
||||
}
|
||||
|
||||
if (progress->offscreen_pixmap)
|
||||
if (pbar->offscreen_pixmap)
|
||||
{
|
||||
gtk_paint_box (widget->style,
|
||||
progress->offscreen_pixmap,
|
||||
pbar->offscreen_pixmap,
|
||||
GTK_STATE_NORMAL, GTK_SHADOW_IN,
|
||||
NULL, widget, "trough",
|
||||
0, 0,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
|
||||
if (progress->activity_mode)
|
||||
if (pbar->activity_mode)
|
||||
{
|
||||
gtk_progress_bar_paint_activity (pbar, orientation);
|
||||
|
||||
if (priv->text)
|
||||
if (pbar->show_text)
|
||||
{
|
||||
gint offset;
|
||||
gint amount;
|
||||
@ -927,26 +966,35 @@ gtk_progress_bar_paint (GtkProgress *progress)
|
||||
else
|
||||
space = widget->allocation.height - 2 * widget->style->ythickness;
|
||||
|
||||
amount = space *
|
||||
gtk_progress_get_current_percentage (GTK_PROGRESS (pbar));
|
||||
amount = space * gtk_progress_bar_get_fraction (pbar);
|
||||
|
||||
if (pbar->bar_style == GTK_PROGRESS_CONTINUOUS)
|
||||
{
|
||||
gtk_progress_bar_paint_continuous (pbar, amount, orientation);
|
||||
|
||||
if (priv->text)
|
||||
if (pbar->show_text)
|
||||
gtk_progress_bar_paint_text (pbar, -1, amount, orientation);
|
||||
}
|
||||
else
|
||||
gtk_progress_bar_paint_discrete (pbar, orientation);
|
||||
}
|
||||
|
||||
pbar->dirty = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_progress_bar_set_activity_mode (GtkProgressBar *pbar,
|
||||
gboolean activity_mode)
|
||||
{
|
||||
activity_mode = !!activity_mode;
|
||||
|
||||
/*******************************************************************/
|
||||
if (pbar->activity_mode != activity_mode)
|
||||
{
|
||||
pbar->activity_mode = activity_mode;
|
||||
|
||||
if (pbar->activity_mode)
|
||||
GTK_PROGRESS_BAR_GET_CLASS (pbar)->act_mode_enter (pbar);
|
||||
|
||||
if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
|
||||
gtk_widget_queue_resize (GTK_WIDGET (pbar));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_progress_bar_set_fraction:
|
||||
@ -968,8 +1016,8 @@ gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
|
||||
|
||||
priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
priv->fraction = fraction;
|
||||
gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), FALSE);
|
||||
gtk_progress_set_percentage (GTK_PROGRESS (pbar), fraction);
|
||||
gtk_progress_bar_set_activity_mode (pbar, FALSE);
|
||||
gtk_progress_bar_real_update (pbar);
|
||||
|
||||
g_object_notify (G_OBJECT (pbar), "fraction");
|
||||
}
|
||||
@ -989,9 +1037,8 @@ gtk_progress_bar_pulse (GtkProgressBar *pbar)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
|
||||
|
||||
/* Sigh. */
|
||||
gtk_progress_set_activity_mode (GTK_PROGRESS (pbar), TRUE);
|
||||
gtk_progress_bar_real_update (GTK_PROGRESS (pbar));
|
||||
gtk_progress_bar_set_activity_mode (pbar, TRUE);
|
||||
gtk_progress_bar_real_update (pbar);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1012,13 +1059,63 @@ gtk_progress_bar_set_text (GtkProgressBar *pbar,
|
||||
priv = GTK_PROGRESS_BAR_GET_PRIVATE (pbar);
|
||||
g_free (priv->text);
|
||||
priv->text = text && *text ? g_strdup (text) : NULL;
|
||||
gtk_progress_set_show_text (GTK_PROGRESS (pbar), text && *text);
|
||||
gtk_progress_set_format_string (GTK_PROGRESS (pbar), text);
|
||||
GTK_PROGRESS (pbar)->use_text_format = (text == NULL);
|
||||
|
||||
if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
|
||||
gtk_widget_queue_resize (GTK_WIDGET (pbar));
|
||||
|
||||
g_object_notify (G_OBJECT (pbar), "text");
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_progress_bar_set_show_text:
|
||||
* @pbar: a #GtkProgressBar
|
||||
* @show_text: whether to show superimposed text
|
||||
*
|
||||
* Sets whether the progressbar will show text superimposed
|
||||
* over the bar. The shown text is either the value of
|
||||
* the #GtkProgressBar::text property or, if that is %NULL,
|
||||
* the #GtkProgressBar::fraction value, as a percentage.
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
void
|
||||
gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
|
||||
gboolean show_text)
|
||||
{
|
||||
g_return_if_fail (GTK_IS_PROGRESS_BAR (pbar));
|
||||
|
||||
show_text = !!show_text;
|
||||
|
||||
if (pbar->show_text != show_text)
|
||||
{
|
||||
pbar->show_text = show_text;
|
||||
|
||||
if (gtk_widget_is_drawable (GTK_WIDGET (pbar)))
|
||||
gtk_widget_queue_resize (GTK_WIDGET (pbar));
|
||||
|
||||
g_object_notify (G_OBJECT (pbar), "show-text");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_progress_bar_get_show_text:
|
||||
* @pbar: a #GtkProgressBar
|
||||
*
|
||||
* Gets the value of the #GtkProgressBar::show-text property.
|
||||
* See gtk_progress_bar_set_show_text().
|
||||
*
|
||||
* Returns: %TRUE if text is shown in the progress bar
|
||||
*
|
||||
* Since: 3.0
|
||||
*/
|
||||
gboolean
|
||||
gtk_progress_bar_get_show_text (GtkProgressBar *pbar)
|
||||
{
|
||||
g_return_val_if_fail (GTK_IS_PROGRESS_BAR (pbar), FALSE);
|
||||
|
||||
return pbar->show_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_progress_bar_set_pulse_step:
|
||||
* @pbar: a #GtkProgressBar
|
||||
@ -1183,4 +1280,6 @@ gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar)
|
||||
return pbar->ellipsize;
|
||||
}
|
||||
|
||||
|
||||
#define __GTK_PROGRESS_BAR_C__
|
||||
#include "gtkaliasdef.c"
|
||||
|
@ -31,9 +31,7 @@
|
||||
#ifndef __GTK_PROGRESS_BAR_H__
|
||||
#define __GTK_PROGRESS_BAR_H__
|
||||
|
||||
|
||||
#include <gtk/gtkprogress.h>
|
||||
|
||||
#include <gtk/gtkwidget.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -48,12 +46,6 @@ G_BEGIN_DECLS
|
||||
typedef struct _GtkProgressBar GtkProgressBar;
|
||||
typedef struct _GtkProgressBarClass GtkProgressBarClass;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_PROGRESS_CONTINUOUS,
|
||||
GTK_PROGRESS_DISCRETE
|
||||
} GtkProgressBarStyle;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GTK_PROGRESS_LEFT_TO_RIGHT,
|
||||
@ -64,9 +56,10 @@ typedef enum
|
||||
|
||||
struct _GtkProgressBar
|
||||
{
|
||||
GtkProgress progress;
|
||||
GtkWidget parent;
|
||||
|
||||
GdkPixmap *GSEAL (offscreen_pixmap);
|
||||
|
||||
GtkProgressBarStyle GSEAL (bar_style);
|
||||
GtkProgressBarOrientation GSEAL (orientation);
|
||||
|
||||
guint GSEAL (blocks);
|
||||
@ -81,17 +74,27 @@ struct _GtkProgressBar
|
||||
guint GSEAL (activity_dir) : 1;
|
||||
guint GSEAL (ellipsize) : 3;
|
||||
guint GSEAL (dirty) : 1;
|
||||
guint GSEAL (activity_mode) : 1;
|
||||
guint GSEAL (show_text) : 1;
|
||||
};
|
||||
|
||||
struct _GtkProgressBarClass
|
||||
{
|
||||
GtkProgressClass parent_class;
|
||||
GtkWidgetClass parent_class;
|
||||
|
||||
void (* paint) (GtkProgressBar *progress);
|
||||
void (* update) (GtkProgressBar *progress);
|
||||
void (* act_mode_enter) (GtkProgressBar *progress);
|
||||
|
||||
/* Padding for future expansion */
|
||||
void (*_gtk_reserved1) (void);
|
||||
void (*_gtk_reserved2) (void);
|
||||
void (*_gtk_reserved3) (void);
|
||||
void (*_gtk_reserved4) (void);
|
||||
void (*_gtk_reserved5) (void);
|
||||
void (*_gtk_reserved6) (void);
|
||||
void (*_gtk_reserved7) (void);
|
||||
void (*_gtk_reserved8) (void);
|
||||
};
|
||||
|
||||
|
||||
@ -118,6 +121,9 @@ void gtk_progress_bar_set_ellipsize (GtkProgressBar *pbar,
|
||||
PangoEllipsizeMode mode);
|
||||
PangoEllipsizeMode gtk_progress_bar_get_ellipsize (GtkProgressBar *pbar);
|
||||
|
||||
void gtk_progress_bar_set_show_text (GtkProgressBar *pbar,
|
||||
gboolean show_text);
|
||||
gboolean gtk_progress_bar_get_show_text (GtkProgressBar *pbar);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -32,8 +32,6 @@ static void gail_progress_bar_class_init (GailProgressBarClass *klass);
|
||||
static void gail_progress_bar_init (GailProgressBar *bar);
|
||||
static void gail_progress_bar_real_initialize (AtkObject *obj,
|
||||
gpointer data);
|
||||
static void gail_progress_bar_finalize (GObject *object);
|
||||
|
||||
|
||||
static void atk_value_interface_init (AtkValueIface *iface);
|
||||
|
||||
@ -47,8 +45,6 @@ static void gail_progress_bar_get_maximum_value (AtkValue *obj,
|
||||
GValue *value);
|
||||
static void gail_progress_bar_get_minimum_value (AtkValue *obj,
|
||||
GValue *value);
|
||||
static void gail_progress_bar_value_changed (GtkAdjustment *adjustment,
|
||||
gpointer data);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GailProgressBar, gail_progress_bar, GAIL_TYPE_WIDGET,
|
||||
G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
|
||||
@ -65,8 +61,6 @@ gail_progress_bar_class_init (GailProgressBarClass *klass)
|
||||
widget_class->notify_gtk = gail_progress_bar_real_notify_gtk;
|
||||
|
||||
class->initialize = gail_progress_bar_real_initialize;
|
||||
|
||||
gobject_class->finalize = gail_progress_bar_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -79,26 +73,9 @@ gail_progress_bar_real_initialize (AtkObject *obj,
|
||||
gpointer data)
|
||||
{
|
||||
GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (obj);
|
||||
GtkProgress *gtk_progress;
|
||||
|
||||
ATK_OBJECT_CLASS (gail_progress_bar_parent_class)->initialize (obj, data);
|
||||
|
||||
gtk_progress = GTK_PROGRESS (data);
|
||||
/*
|
||||
* If a GtkAdjustment already exists for the spin_button,
|
||||
* create the GailAdjustment
|
||||
*/
|
||||
if (gtk_progress->adjustment)
|
||||
{
|
||||
progress_bar->adjustment = gail_adjustment_new (gtk_progress->adjustment);
|
||||
g_signal_connect (gtk_progress->adjustment,
|
||||
"value-changed",
|
||||
G_CALLBACK (gail_progress_bar_value_changed),
|
||||
obj);
|
||||
}
|
||||
else
|
||||
progress_bar->adjustment = NULL;
|
||||
|
||||
obj->role = ATK_ROLE_PROGRESS_BAR;
|
||||
}
|
||||
|
||||
@ -114,71 +91,33 @@ static void
|
||||
gail_progress_bar_get_current_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
GailProgressBar *progress_bar;
|
||||
GtkWidget *widget;
|
||||
|
||||
g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
|
||||
|
||||
progress_bar = GAIL_PROGRESS_BAR (obj);
|
||||
if (progress_bar->adjustment == NULL)
|
||||
/*
|
||||
* Adjustment has not been specified
|
||||
*/
|
||||
return;
|
||||
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (obj));
|
||||
|
||||
atk_value_get_current_value (ATK_VALUE (progress_bar->adjustment), value);
|
||||
g_value_set_double (value, gtk_progress_bar_get_fraction (GTK_PROGRESS_BAR (widget)));
|
||||
}
|
||||
|
||||
static void
|
||||
gail_progress_bar_get_maximum_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
GailProgressBar *progress_bar;
|
||||
|
||||
g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
|
||||
|
||||
progress_bar = GAIL_PROGRESS_BAR (obj);
|
||||
if (progress_bar->adjustment == NULL)
|
||||
/*
|
||||
* Adjustment has not been specified
|
||||
*/
|
||||
return;
|
||||
|
||||
atk_value_get_maximum_value (ATK_VALUE (progress_bar->adjustment), value);
|
||||
g_value_set_double (value, 1.0);
|
||||
}
|
||||
|
||||
static void
|
||||
gail_progress_bar_get_minimum_value (AtkValue *obj,
|
||||
GValue *value)
|
||||
{
|
||||
GailProgressBar *progress_bar;
|
||||
|
||||
g_return_if_fail (GAIL_IS_PROGRESS_BAR (obj));
|
||||
|
||||
progress_bar = GAIL_PROGRESS_BAR (obj);
|
||||
if (progress_bar->adjustment == NULL)
|
||||
/*
|
||||
* Adjustment has not been specified
|
||||
*/
|
||||
return;
|
||||
|
||||
atk_value_get_minimum_value (ATK_VALUE (progress_bar->adjustment), value);
|
||||
g_value_set_double (value, 0.0);
|
||||
}
|
||||
|
||||
static void
|
||||
gail_progress_bar_finalize (GObject *object)
|
||||
{
|
||||
GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (object);
|
||||
|
||||
if (progress_bar->adjustment)
|
||||
{
|
||||
g_object_unref (progress_bar->adjustment);
|
||||
progress_bar->adjustment = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gail_progress_bar_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gail_progress_bar_real_notify_gtk (GObject *obj,
|
||||
GParamSpec *pspec)
|
||||
@ -186,41 +125,8 @@ gail_progress_bar_real_notify_gtk (GObject *obj,
|
||||
GtkWidget *widget = GTK_WIDGET (obj);
|
||||
GailProgressBar *progress_bar = GAIL_PROGRESS_BAR (gtk_widget_get_accessible (widget));
|
||||
|
||||
if (strcmp (pspec->name, "adjustment") == 0)
|
||||
{
|
||||
/*
|
||||
* Get rid of the GailAdjustment for the GtkAdjustment
|
||||
* which was associated with the progress_bar.
|
||||
*/
|
||||
if (progress_bar->adjustment)
|
||||
{
|
||||
g_object_unref (progress_bar->adjustment);
|
||||
progress_bar->adjustment = NULL;
|
||||
}
|
||||
/*
|
||||
* Create the GailAdjustment when notify for "adjustment" property
|
||||
* is received
|
||||
*/
|
||||
progress_bar->adjustment = gail_adjustment_new (GTK_PROGRESS (widget)->adjustment);
|
||||
g_signal_connect (GTK_PROGRESS (widget)->adjustment,
|
||||
"value-changed",
|
||||
G_CALLBACK (gail_progress_bar_value_changed),
|
||||
progress_bar);
|
||||
}
|
||||
if (strcmp (pspec->name, "fraction") == 0)
|
||||
g_object_notify (G_OBJECT (progress_bar), "accessible-value");
|
||||
else
|
||||
GAIL_WIDGET_CLASS (gail_progress_bar_parent_class)->notify_gtk (obj, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
gail_progress_bar_value_changed (GtkAdjustment *adjustment,
|
||||
gpointer data)
|
||||
{
|
||||
GailProgressBar *progress_bar;
|
||||
|
||||
g_return_if_fail (adjustment != NULL);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
progress_bar = GAIL_PROGRESS_BAR (data);
|
||||
|
||||
g_object_notify (G_OBJECT (progress_bar), "accessible-value");
|
||||
}
|
||||
|
@ -37,8 +37,6 @@ typedef struct _GailProgressBarClass GailProgressBarClass;
|
||||
struct _GailProgressBar
|
||||
{
|
||||
GailWidget parent;
|
||||
|
||||
AtkObject *adjustment;
|
||||
};
|
||||
|
||||
GType gail_progress_bar_get_type (void);
|
||||
|
@ -8908,10 +8908,7 @@ toggle_show_text (GtkWidget *widget, ProgressData *pdata)
|
||||
gboolean active;
|
||||
|
||||
active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
|
||||
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (pdata->pbar),
|
||||
active ? gtk_entry_get_text (GTK_ENTRY (pdata->entry)) : NULL);
|
||||
|
||||
gtk_widget_set_sensitive (pdata->entry, active);
|
||||
gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (pdata->pbar), active);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -9061,13 +9058,11 @@ create_progress_bar (GtkWidget *widget)
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 0);
|
||||
|
||||
pdata->entry = gtk_entry_new ();
|
||||
gtk_entry_set_text (GTK_ENTRY (pdata->entry), "Installing ...");
|
||||
g_signal_connect (pdata->entry, "changed",
|
||||
G_CALLBACK (entry_changed),
|
||||
pdata);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), pdata->entry, TRUE, TRUE, 0);
|
||||
gtk_widget_set_size_request (pdata->entry, 100, -1);
|
||||
gtk_widget_set_sensitive (pdata->entry, FALSE);
|
||||
|
||||
label = gtk_label_new ("Ellipsize text :");
|
||||
gtk_table_attach (GTK_TABLE (tab), label, 0, 1, 10, 11,
|
||||
|
Loading…
Reference in New Issue
Block a user