1 | /* gtkcellrendererprogress.c |
2 | * Copyright (C) 2002 Naba Kumar <kh_naba@users.sourceforge.net> |
3 | * heavily modified by Jörgen Scheibengruber <mfcn@gmx.de> |
4 | * heavily modified by Marco Pesenti Gritti <marco@gnome.org> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Library General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2 of the License, or (at your option) any later version. |
10 | * |
11 | * This library is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | * Library General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Library General Public |
17 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | /* |
20 | * Modified by the GTK+ Team and others 1997-2007. See the AUTHORS |
21 | * file for a list of people on the GTK+ Team. See the ChangeLog |
22 | * files for a list of changes. These files are distributed with |
23 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
24 | */ |
25 | |
26 | #include "config.h" |
27 | #include <stdlib.h> |
28 | |
29 | #include "gtkcellrendererprogress.h" |
30 | #include "gtkintl.h" |
31 | #include "gtkorientable.h" |
32 | #include "gtkprivate.h" |
33 | #include "gtksnapshot.h" |
34 | #include "gtkstylecontext.h" |
35 | |
36 | |
37 | /** |
38 | * GtkCellRendererProgress: |
39 | * |
40 | * Renders numbers as progress bars |
41 | * |
42 | * `GtkCellRendererProgress` renders a numeric value as a progress par in a cell. |
43 | * Additionally, it can display a text on top of the progress bar. |
44 | */ |
45 | |
46 | |
47 | enum |
48 | { |
49 | PROP_0, |
50 | PROP_VALUE, |
51 | PROP_TEXT, |
52 | PROP_PULSE, |
53 | PROP_TEXT_XALIGN, |
54 | PROP_TEXT_YALIGN, |
55 | PROP_ORIENTATION, |
56 | PROP_INVERTED |
57 | }; |
58 | |
59 | typedef struct _GtkCellRendererProgressClass GtkCellRendererProgressClass; |
60 | typedef struct _GtkCellRendererProgressPrivate GtkCellRendererProgressPrivate; |
61 | |
62 | struct _GtkCellRendererProgress |
63 | { |
64 | GtkCellRenderer parent_instance; |
65 | }; |
66 | |
67 | struct _GtkCellRendererProgressClass |
68 | { |
69 | GtkCellRendererClass parent_class; |
70 | }; |
71 | |
72 | struct _GtkCellRendererProgressPrivate |
73 | { |
74 | int value; |
75 | char *text; |
76 | char *label; |
77 | int min_h; |
78 | int min_w; |
79 | int pulse; |
80 | int offset; |
81 | float text_xalign; |
82 | float text_yalign; |
83 | GtkOrientation orientation; |
84 | gboolean inverted; |
85 | }; |
86 | |
87 | static void gtk_cell_renderer_progress_finalize (GObject *object); |
88 | static void gtk_cell_renderer_progress_get_property (GObject *object, |
89 | guint param_id, |
90 | GValue *value, |
91 | GParamSpec *pspec); |
92 | static void gtk_cell_renderer_progress_set_property (GObject *object, |
93 | guint param_id, |
94 | const GValue *value, |
95 | GParamSpec *pspec); |
96 | static void gtk_cell_renderer_progress_set_value (GtkCellRendererProgress *cellprogress, |
97 | int value); |
98 | static void gtk_cell_renderer_progress_set_text (GtkCellRendererProgress *cellprogress, |
99 | const char *text); |
100 | static void gtk_cell_renderer_progress_set_pulse (GtkCellRendererProgress *cellprogress, |
101 | int pulse); |
102 | static void compute_dimensions (GtkCellRenderer *cell, |
103 | GtkWidget *widget, |
104 | const char *text, |
105 | int *width, |
106 | int *height); |
107 | static void gtk_cell_renderer_progress_snapshot (GtkCellRenderer *cell, |
108 | GtkSnapshot *snapshot, |
109 | GtkWidget *widget, |
110 | const GdkRectangle *background_area, |
111 | const GdkRectangle *cell_area, |
112 | GtkCellRendererState flags); |
113 | |
114 | |
115 | G_DEFINE_TYPE_WITH_CODE (GtkCellRendererProgress, gtk_cell_renderer_progress, GTK_TYPE_CELL_RENDERER, |
116 | G_ADD_PRIVATE (GtkCellRendererProgress) |
117 | G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)) |
118 | |
119 | static void |
120 | recompute_label (GtkCellRendererProgress *cellprogress) |
121 | { |
122 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
123 | char *label; |
124 | |
125 | if (priv->text) |
126 | label = g_strdup (str: priv->text); |
127 | else if (priv->pulse < 0) |
128 | label = g_strdup_printf (C_("progress bar label" , "%d %%" ), priv->value); |
129 | else |
130 | label = NULL; |
131 | |
132 | g_free (mem: priv->label); |
133 | priv->label = label; |
134 | } |
135 | |
136 | static void |
137 | gtk_cell_renderer_progress_set_value (GtkCellRendererProgress *cellprogress, |
138 | int value) |
139 | { |
140 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
141 | |
142 | if (priv->value != value) |
143 | { |
144 | priv->value = value; |
145 | recompute_label (cellprogress); |
146 | g_object_notify (G_OBJECT (cellprogress), property_name: "value" ); |
147 | } |
148 | } |
149 | |
150 | static void |
151 | gtk_cell_renderer_progress_set_text (GtkCellRendererProgress *cellprogress, |
152 | const char *text) |
153 | { |
154 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
155 | char *new_text; |
156 | |
157 | new_text = g_strdup (str: text); |
158 | g_free (mem: priv->text); |
159 | priv->text = new_text; |
160 | recompute_label (cellprogress); |
161 | g_object_notify (G_OBJECT (cellprogress), property_name: "text" ); |
162 | } |
163 | |
164 | static void |
165 | gtk_cell_renderer_progress_set_pulse (GtkCellRendererProgress *cellprogress, |
166 | int pulse) |
167 | { |
168 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
169 | |
170 | if (pulse != priv->pulse) |
171 | { |
172 | if (pulse <= 0) |
173 | priv->offset = 0; |
174 | else |
175 | priv->offset = pulse; |
176 | g_object_notify (G_OBJECT (cellprogress), property_name: "pulse" ); |
177 | } |
178 | |
179 | priv->pulse = pulse; |
180 | recompute_label (cellprogress); |
181 | } |
182 | |
183 | static void |
184 | gtk_cell_renderer_progress_finalize (GObject *object) |
185 | { |
186 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object); |
187 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
188 | |
189 | g_free (mem: priv->text); |
190 | g_free (mem: priv->label); |
191 | |
192 | G_OBJECT_CLASS (gtk_cell_renderer_progress_parent_class)->finalize (object); |
193 | } |
194 | |
195 | static void |
196 | gtk_cell_renderer_progress_get_property (GObject *object, |
197 | guint param_id, |
198 | GValue *value, |
199 | GParamSpec *pspec) |
200 | { |
201 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object); |
202 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
203 | |
204 | switch (param_id) |
205 | { |
206 | case PROP_VALUE: |
207 | g_value_set_int (value, v_int: priv->value); |
208 | break; |
209 | case PROP_TEXT: |
210 | g_value_set_string (value, v_string: priv->text); |
211 | break; |
212 | case PROP_PULSE: |
213 | g_value_set_int (value, v_int: priv->pulse); |
214 | break; |
215 | case PROP_TEXT_XALIGN: |
216 | g_value_set_float (value, v_float: priv->text_xalign); |
217 | break; |
218 | case PROP_TEXT_YALIGN: |
219 | g_value_set_float (value, v_float: priv->text_yalign); |
220 | break; |
221 | case PROP_ORIENTATION: |
222 | g_value_set_enum (value, v_enum: priv->orientation); |
223 | break; |
224 | case PROP_INVERTED: |
225 | g_value_set_boolean (value, v_boolean: priv->inverted); |
226 | break; |
227 | default: |
228 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
229 | } |
230 | } |
231 | |
232 | static void |
233 | gtk_cell_renderer_progress_set_property (GObject *object, |
234 | guint param_id, |
235 | const GValue *value, |
236 | GParamSpec *pspec) |
237 | { |
238 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (object); |
239 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
240 | |
241 | switch (param_id) |
242 | { |
243 | case PROP_VALUE: |
244 | gtk_cell_renderer_progress_set_value (cellprogress, |
245 | value: g_value_get_int (value)); |
246 | break; |
247 | case PROP_TEXT: |
248 | gtk_cell_renderer_progress_set_text (cellprogress, |
249 | text: g_value_get_string (value)); |
250 | break; |
251 | case PROP_PULSE: |
252 | gtk_cell_renderer_progress_set_pulse (cellprogress, |
253 | pulse: g_value_get_int (value)); |
254 | break; |
255 | case PROP_TEXT_XALIGN: |
256 | priv->text_xalign = g_value_get_float (value); |
257 | break; |
258 | case PROP_TEXT_YALIGN: |
259 | priv->text_yalign = g_value_get_float (value); |
260 | break; |
261 | case PROP_ORIENTATION: |
262 | if (priv->orientation != g_value_get_enum (value)) |
263 | { |
264 | priv->orientation = g_value_get_enum (value); |
265 | g_object_notify_by_pspec (object, pspec); |
266 | } |
267 | break; |
268 | case PROP_INVERTED: |
269 | if (priv->inverted != g_value_get_boolean (value)) |
270 | { |
271 | priv->inverted = g_value_get_boolean (value); |
272 | g_object_notify_by_pspec (object, pspec); |
273 | } |
274 | break; |
275 | default: |
276 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
277 | } |
278 | } |
279 | |
280 | static void |
281 | compute_dimensions (GtkCellRenderer *cell, |
282 | GtkWidget *widget, |
283 | const char *text, |
284 | int *width, |
285 | int *height) |
286 | { |
287 | PangoRectangle logical_rect; |
288 | PangoLayout *layout; |
289 | int xpad, ypad; |
290 | |
291 | layout = gtk_widget_create_pango_layout (widget, text); |
292 | pango_layout_get_pixel_extents (layout, NULL, logical_rect: &logical_rect); |
293 | |
294 | gtk_cell_renderer_get_padding (cell, xpad: &xpad, ypad: &ypad); |
295 | |
296 | if (width) |
297 | *width = logical_rect.width + xpad * 2; |
298 | |
299 | if (height) |
300 | *height = logical_rect.height + ypad * 2; |
301 | |
302 | g_object_unref (object: layout); |
303 | } |
304 | |
305 | static void |
306 | gtk_cell_renderer_progress_get_preferred_width (GtkCellRenderer *cell, |
307 | GtkWidget *widget, |
308 | int *minimum, |
309 | int *natural) |
310 | { |
311 | GtkCellRendererProgress *self = GTK_CELL_RENDERER_PROGRESS (cell); |
312 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self); |
313 | int w, h; |
314 | int size; |
315 | |
316 | if (priv->min_w < 0) |
317 | { |
318 | char *text = g_strdup_printf (C_("progress bar label" , "%d %%" ), 100); |
319 | compute_dimensions (cell, widget, text, |
320 | width: &priv->min_w, |
321 | height: &priv->min_h); |
322 | g_free (mem: text); |
323 | } |
324 | |
325 | compute_dimensions (cell, widget, text: priv->label, width: &w, height: &h); |
326 | |
327 | size = MAX (priv->min_w, w); |
328 | |
329 | if (minimum != NULL) |
330 | *minimum = size; |
331 | if (natural != NULL) |
332 | *natural = size; |
333 | } |
334 | |
335 | static void |
336 | gtk_cell_renderer_progress_get_preferred_height (GtkCellRenderer *cell, |
337 | GtkWidget *widget, |
338 | int *minimum, |
339 | int *natural) |
340 | { |
341 | GtkCellRendererProgress *self = GTK_CELL_RENDERER_PROGRESS (cell); |
342 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self); |
343 | int w, h; |
344 | int size; |
345 | |
346 | if (priv->min_w < 0) |
347 | { |
348 | char *text = g_strdup_printf (C_("progress bar label" , "%d %%" ), 100); |
349 | compute_dimensions (cell, widget, text, |
350 | width: &priv->min_w, |
351 | height: &priv->min_h); |
352 | g_free (mem: text); |
353 | } |
354 | |
355 | compute_dimensions (cell, widget, text: priv->label, width: &w, height: &h); |
356 | |
357 | size = MIN (priv->min_h, h); |
358 | |
359 | if (minimum != NULL) |
360 | *minimum = size; |
361 | if (natural != NULL) |
362 | *natural = size; |
363 | } |
364 | |
365 | static inline int |
366 | get_bar_size (int pulse, |
367 | int value, |
368 | int full_size) |
369 | { |
370 | int bar_size; |
371 | |
372 | if (pulse < 0) |
373 | bar_size = full_size * MAX (0, value) / 100; |
374 | else if (pulse == 0) |
375 | bar_size = 0; |
376 | else if (pulse == G_MAXINT) |
377 | bar_size = full_size; |
378 | else |
379 | bar_size = MAX (2, full_size / 5); |
380 | |
381 | return bar_size; |
382 | } |
383 | |
384 | static inline int |
385 | get_bar_position (int start, |
386 | int full_size, |
387 | int bar_size, |
388 | int pulse, |
389 | int offset, |
390 | gboolean is_rtl) |
391 | { |
392 | int position; |
393 | |
394 | if (pulse < 0 || pulse == 0 || pulse == G_MAXINT) |
395 | { |
396 | position = is_rtl ? (start + full_size - bar_size) : start; |
397 | } |
398 | else |
399 | { |
400 | position = (is_rtl ? offset + 12 : offset) % 24; |
401 | if (position > 12) |
402 | position = 24 - position; |
403 | position = start + full_size * position / 15; |
404 | } |
405 | |
406 | return position; |
407 | } |
408 | |
409 | static void |
410 | gtk_cell_renderer_progress_snapshot (GtkCellRenderer *cell, |
411 | GtkSnapshot *snapshot, |
412 | GtkWidget *widget, |
413 | const GdkRectangle *background_area, |
414 | const GdkRectangle *cell_area, |
415 | GtkCellRendererState flags) |
416 | { |
417 | GtkCellRendererProgress *cellprogress = GTK_CELL_RENDERER_PROGRESS (cell); |
418 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
419 | GtkStyleContext *context; |
420 | GtkBorder padding; |
421 | PangoLayout *layout; |
422 | PangoRectangle logical_rect; |
423 | int x, y, w, h, x_pos, y_pos, bar_position, bar_size, start, full_size; |
424 | int xpad, ypad; |
425 | GdkRectangle clip; |
426 | gboolean is_rtl; |
427 | |
428 | context = gtk_widget_get_style_context (widget); |
429 | is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL; |
430 | |
431 | gtk_cell_renderer_get_padding (cell, xpad: &xpad, ypad: &ypad); |
432 | x = cell_area->x + xpad; |
433 | y = cell_area->y + ypad; |
434 | w = cell_area->width - xpad * 2; |
435 | h = cell_area->height - ypad * 2; |
436 | |
437 | gtk_style_context_save (context); |
438 | gtk_style_context_add_class (context, class_name: "trough" ); |
439 | |
440 | gtk_snapshot_render_background (snapshot, context, x, y, width: w, height: h); |
441 | gtk_snapshot_render_frame (snapshot, context, x, y, width: w, height: h); |
442 | |
443 | gtk_style_context_get_padding (context, padding: &padding); |
444 | |
445 | x += padding.left; |
446 | y += padding.top; |
447 | w -= padding.left + padding.right; |
448 | h -= padding.top + padding.bottom; |
449 | |
450 | gtk_style_context_restore (context); |
451 | |
452 | if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) |
453 | { |
454 | clip.y = y; |
455 | clip.height = h; |
456 | |
457 | start = x; |
458 | full_size = w; |
459 | |
460 | bar_size = get_bar_size (pulse: priv->pulse, value: priv->value, full_size); |
461 | |
462 | if (!priv->inverted) |
463 | bar_position = get_bar_position (start, full_size, bar_size, |
464 | pulse: priv->pulse, offset: priv->offset, is_rtl); |
465 | else |
466 | bar_position = get_bar_position (start, full_size, bar_size, |
467 | pulse: priv->pulse, offset: priv->offset, is_rtl: !is_rtl); |
468 | |
469 | clip.width = bar_size; |
470 | clip.x = bar_position; |
471 | } |
472 | else |
473 | { |
474 | clip.x = x; |
475 | clip.width = w; |
476 | |
477 | start = y; |
478 | full_size = h; |
479 | |
480 | bar_size = get_bar_size (pulse: priv->pulse, value: priv->value, full_size); |
481 | |
482 | if (priv->inverted) |
483 | bar_position = get_bar_position (start, full_size, bar_size, |
484 | pulse: priv->pulse, offset: priv->offset, TRUE); |
485 | else |
486 | bar_position = get_bar_position (start, full_size, bar_size, |
487 | pulse: priv->pulse, offset: priv->offset, FALSE); |
488 | |
489 | clip.height = bar_size; |
490 | clip.y = bar_position; |
491 | } |
492 | |
493 | if (bar_size > 0) |
494 | { |
495 | gtk_style_context_save (context); |
496 | gtk_style_context_add_class (context, class_name: "progressbar" ); |
497 | |
498 | gtk_snapshot_render_background (snapshot, context, x: clip.x, y: clip.y, width: clip.width, height: clip.height); |
499 | gtk_snapshot_render_frame (snapshot, context, x: clip.x, y: clip.y, width: clip.width, height: clip.height); |
500 | |
501 | gtk_style_context_restore (context); |
502 | } |
503 | |
504 | if (priv->label) |
505 | { |
506 | float text_xalign; |
507 | |
508 | layout = gtk_widget_create_pango_layout (widget, text: priv->label); |
509 | pango_layout_get_pixel_extents (layout, NULL, logical_rect: &logical_rect); |
510 | |
511 | if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) |
512 | text_xalign = 1.0 - priv->text_xalign; |
513 | else |
514 | text_xalign = priv->text_xalign; |
515 | |
516 | x_pos = x + padding.left + text_xalign * |
517 | (w - padding.left - padding.right - logical_rect.width); |
518 | |
519 | y_pos = y + padding.top + priv->text_yalign * |
520 | (h - padding.top - padding.bottom - logical_rect.height); |
521 | |
522 | gtk_snapshot_push_clip (snapshot, |
523 | bounds: &GRAPHENE_RECT_INIT( |
524 | clip.x, clip.y, |
525 | clip.width, clip.height |
526 | )); |
527 | |
528 | gtk_style_context_save (context); |
529 | gtk_style_context_add_class (context, class_name: "progressbar" ); |
530 | |
531 | gtk_snapshot_render_layout (snapshot, context, |
532 | x: x_pos, y: y_pos, |
533 | layout); |
534 | |
535 | gtk_style_context_restore (context); |
536 | gtk_snapshot_pop (snapshot); |
537 | |
538 | gtk_style_context_save (context); |
539 | gtk_style_context_add_class (context, class_name: "trough" ); |
540 | |
541 | if (bar_position > start) |
542 | { |
543 | if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) |
544 | { |
545 | clip.x = x; |
546 | clip.width = bar_position - x; |
547 | } |
548 | else |
549 | { |
550 | clip.y = y; |
551 | clip.height = bar_position - y; |
552 | } |
553 | |
554 | gtk_snapshot_push_clip (snapshot, |
555 | bounds: &GRAPHENE_RECT_INIT( |
556 | clip.x, clip.y, |
557 | clip.width, clip.height |
558 | )); |
559 | |
560 | gtk_snapshot_render_layout (snapshot, context, |
561 | x: x_pos, y: y_pos, |
562 | layout); |
563 | |
564 | gtk_snapshot_pop (snapshot); |
565 | } |
566 | |
567 | if (bar_position + bar_size < start + full_size) |
568 | { |
569 | if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) |
570 | { |
571 | clip.x = bar_position + bar_size; |
572 | clip.width = x + w - (bar_position + bar_size); |
573 | } |
574 | else |
575 | { |
576 | clip.y = bar_position + bar_size; |
577 | clip.height = y + h - (bar_position + bar_size); |
578 | } |
579 | |
580 | gtk_snapshot_push_clip (snapshot, |
581 | bounds: &GRAPHENE_RECT_INIT( |
582 | clip.x, clip.y, |
583 | clip.width, clip.height |
584 | )); |
585 | |
586 | gtk_snapshot_render_layout (snapshot, context, |
587 | x: x_pos, y: y_pos, |
588 | layout); |
589 | |
590 | gtk_snapshot_pop (snapshot); |
591 | } |
592 | |
593 | gtk_style_context_restore (context); |
594 | g_object_unref (object: layout); |
595 | } |
596 | } |
597 | |
598 | static void |
599 | gtk_cell_renderer_progress_class_init (GtkCellRendererProgressClass *klass) |
600 | { |
601 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
602 | GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); |
603 | |
604 | object_class->finalize = gtk_cell_renderer_progress_finalize; |
605 | object_class->get_property = gtk_cell_renderer_progress_get_property; |
606 | object_class->set_property = gtk_cell_renderer_progress_set_property; |
607 | |
608 | cell_class->get_preferred_width = gtk_cell_renderer_progress_get_preferred_width; |
609 | cell_class->get_preferred_height = gtk_cell_renderer_progress_get_preferred_height; |
610 | cell_class->snapshot = gtk_cell_renderer_progress_snapshot; |
611 | |
612 | /** |
613 | * GtkCellRendererProgress:value: |
614 | * |
615 | * The "value" property determines the percentage to which the |
616 | * progress bar will be "filled in". |
617 | **/ |
618 | g_object_class_install_property (oclass: object_class, |
619 | property_id: PROP_VALUE, |
620 | pspec: g_param_spec_int (name: "value" , |
621 | P_("Value" ), |
622 | P_("Value of the progress bar" ), |
623 | minimum: 0, maximum: 100, default_value: 0, |
624 | GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
625 | |
626 | /** |
627 | * GtkCellRendererProgress:text: |
628 | * |
629 | * The "text" property determines the label which will be drawn |
630 | * over the progress bar. Setting this property to %NULL causes the default |
631 | * label to be displayed. Setting this property to an empty string causes |
632 | * no label to be displayed. |
633 | **/ |
634 | g_object_class_install_property (oclass: object_class, |
635 | property_id: PROP_TEXT, |
636 | pspec: g_param_spec_string (name: "text" , |
637 | P_("Text" ), |
638 | P_("Text on the progress bar" ), |
639 | NULL, |
640 | GTK_PARAM_READWRITE)); |
641 | |
642 | /** |
643 | * GtkCellRendererProgress:pulse: |
644 | * |
645 | * Setting this to a non-negative value causes the cell renderer to |
646 | * enter "activity mode", where a block bounces back and forth to |
647 | * indicate that some progress is made, without specifying exactly how |
648 | * much. |
649 | * |
650 | * Each increment of the property causes the block to move by a little |
651 | * bit. |
652 | * |
653 | * To indicate that the activity has not started yet, set the property |
654 | * to zero. To indicate completion, set the property to %G_MAXINT. |
655 | */ |
656 | g_object_class_install_property (oclass: object_class, |
657 | property_id: PROP_PULSE, |
658 | pspec: g_param_spec_int (name: "pulse" , |
659 | P_("Pulse" ), |
660 | P_("Set this to positive values to indicate that some progress is made, but you don’t know how much." ), |
661 | minimum: -1, G_MAXINT, default_value: -1, |
662 | GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
663 | |
664 | /** |
665 | * GtkCellRendererProgress:text-xalign: |
666 | * |
667 | * The "text-xalign" property controls the horizontal alignment of the |
668 | * text in the progress bar. Valid values range from 0 (left) to 1 |
669 | * (right). Reserved for RTL layouts. |
670 | */ |
671 | g_object_class_install_property (oclass: object_class, |
672 | property_id: PROP_TEXT_XALIGN, |
673 | pspec: g_param_spec_float (name: "text-xalign" , |
674 | P_("Text x alignment" ), |
675 | P_("The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts." ), |
676 | minimum: 0.0, maximum: 1.0, default_value: 0.5, |
677 | GTK_PARAM_READWRITE)); |
678 | |
679 | /** |
680 | * GtkCellRendererProgress:text-yalign: |
681 | * |
682 | * The "text-yalign" property controls the vertical alignment of the |
683 | * text in the progress bar. Valid values range from 0 (top) to 1 |
684 | * (bottom). |
685 | */ |
686 | g_object_class_install_property (oclass: object_class, |
687 | property_id: PROP_TEXT_YALIGN, |
688 | pspec: g_param_spec_float (name: "text-yalign" , |
689 | P_("Text y alignment" ), |
690 | P_("The vertical text alignment, from 0 (top) to 1 (bottom)." ), |
691 | minimum: 0.0, maximum: 1.0, default_value: 0.5, |
692 | GTK_PARAM_READWRITE)); |
693 | |
694 | g_object_class_override_property (oclass: object_class, |
695 | property_id: PROP_ORIENTATION, |
696 | name: "orientation" ); |
697 | |
698 | g_object_class_install_property (oclass: object_class, |
699 | property_id: PROP_INVERTED, |
700 | pspec: g_param_spec_boolean (name: "inverted" , |
701 | P_("Inverted" ), |
702 | P_("Invert the direction in which the progress bar grows" ), |
703 | FALSE, |
704 | GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); |
705 | } |
706 | |
707 | static void |
708 | gtk_cell_renderer_progress_init (GtkCellRendererProgress *cellprogress) |
709 | { |
710 | GtkCellRendererProgressPrivate *priv = gtk_cell_renderer_progress_get_instance_private (self: cellprogress); |
711 | |
712 | priv->value = 0; |
713 | priv->text = NULL; |
714 | priv->label = NULL; |
715 | priv->min_w = -1; |
716 | priv->min_h = -1; |
717 | priv->pulse = -1; |
718 | priv->offset = 0; |
719 | |
720 | priv->text_xalign = 0.5; |
721 | priv->text_yalign = 0.5; |
722 | |
723 | priv->orientation = GTK_ORIENTATION_HORIZONTAL, |
724 | priv->inverted = FALSE; |
725 | } |
726 | |
727 | /** |
728 | * gtk_cell_renderer_progress_new: |
729 | * |
730 | * Creates a new `GtkCellRendererProgress`. |
731 | * |
732 | * Returns: the new cell renderer |
733 | **/ |
734 | GtkCellRenderer* |
735 | gtk_cell_renderer_progress_new (void) |
736 | { |
737 | return g_object_new (GTK_TYPE_CELL_RENDERER_PROGRESS, NULL); |
738 | } |
739 | |