2 * This file is a part of hildon
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 * SECTION:hildon-range-editor
27 * @short_description: A widget is used to ask bounds of a range.
29 * HidlonRangeEditor allows entering a pair of integers, e.g. the lower
30 * and higher bounds of a range. A minimum and maximum can also be set
35 * range_editor = hildon_range_editor_new ();
36 * hildon_range_editor_set_limits (editor, start, end );
37 * hildon_range_editor_get_range (editor, &start, &end);
46 #include "hildon-range-editor.h"
47 #include <gtk/gtkbox.h>
48 #include <gtk/gtklabel.h>
49 #include <gtk/gtksignal.h>
50 #include <gtk/gtkentry.h>
51 #include <gdk/gdkkeysyms.h>
52 #include <glib/gprintf.h>
55 #include "hildon-banner.h"
57 #include "hildon-range-editor-private.h"
60 dgettext("hildon-libs", string)
62 /* Alignment in entry box ( 0 = left, 1 = right ) */
64 #define DEFAULT_ALIGNMENT 1
66 /* Amount of padding to add to each side of the separator */
68 #define DEFAULT_PADDING 3
70 #define DEFAULT_START -999
72 #define DEFAULT_END 999
74 #define DEFAULT_LENGTH 4
76 static GtkContainerClass *parent_class = NULL;
79 hildon_range_editor_class_init (HildonRangeEditorClass *editor_class);
82 hildon_range_editor_init (HildonRangeEditor *editor);
85 hildon_range_editor_forall (GtkContainer *container,
86 gboolean include_internals,
88 gpointer callback_data);
91 hildon_range_editor_destroy (GtkObject *self);
94 hildon_range_editor_size_request (GtkWidget *widget,
95 GtkRequisition *requisition);
98 hildon_range_editor_size_allocate (GtkWidget *widget,
99 GtkAllocation *allocation);
102 hildon_range_editor_entry_focus_in (GtkEditable *editable,
103 GdkEventFocus *event,
104 HildonRangeEditor *editor);
107 hildon_range_editor_entry_focus_out (GtkEditable *editable,
108 GdkEventFocus *event,
109 HildonRangeEditor *editor);
112 hildon_range_editor_entry_keypress (GtkWidget *widget,
114 HildonRangeEditor *editor);
117 hildon_range_editor_released (GtkEditable *editable,
118 GdkEventButton *event,
119 HildonRangeEditor *editor);
122 hildon_range_editor_press (GtkEditable *editable,
123 GdkEventButton *event,
124 HildonRangeEditor *editor);
127 hildon_range_editor_set_property (GObject *object,
133 hildon_range_editor_get_property (GObject *object,
139 hildon_range_editor_entry_changed (GtkWidget *widget,
140 HildonRangeEditor *editor);
153 hildon_range_editor_class_init (HildonRangeEditorClass *editor_class)
155 GObjectClass *gobject_class = G_OBJECT_CLASS (editor_class);
156 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (editor_class);
157 GtkContainerClass *container_class = GTK_CONTAINER_CLASS (editor_class);
159 parent_class = g_type_class_peek_parent (editor_class);
161 g_type_class_add_private (editor_class, sizeof (HildonRangeEditorPrivate));
163 gobject_class->set_property = hildon_range_editor_set_property;
164 gobject_class->get_property = hildon_range_editor_get_property;
165 widget_class->size_request = hildon_range_editor_size_request;
166 widget_class->size_allocate = hildon_range_editor_size_allocate;
168 container_class->forall = hildon_range_editor_forall;
169 GTK_OBJECT_CLASS (editor_class)->destroy = hildon_range_editor_destroy;
171 gtk_widget_class_install_style_property (widget_class,
172 g_param_spec_int ("hildon_range_editor_entry_alignment",
173 "Hildon RangeEditor entry alignment",
174 "Hildon RangeEditor entry alignment", 0, 1,
178 gtk_widget_class_install_style_property (widget_class,
179 g_param_spec_int ("hildon_range_editor_separator_padding",
180 "Hildon RangeEditor separator padding",
181 "Hildon RangeEditor separaror padding",
187 * HildonRangeEditor:min:
189 * Minimum value in a range.
192 g_object_class_install_property (gobject_class, PROP_MIN,
193 g_param_spec_int ("min",
195 "Minimum value in a range",
197 DEFAULT_START, G_PARAM_CONSTRUCT |
198 G_PARAM_READABLE | G_PARAM_WRITABLE));
201 * HildonRangeEditor:max:
203 * Maximum value in a range.
206 g_object_class_install_property (gobject_class, PROP_MAX,
207 g_param_spec_int ("max",
209 "Maximum value in a range",
211 DEFAULT_END, G_PARAM_CONSTRUCT |
212 G_PARAM_READABLE | G_PARAM_WRITABLE));
215 * HildonRangeEditor:lower:
217 * Current value in the entry presenting lower end of selected range.
220 g_object_class_install_property (gobject_class, PROP_LOWER,
221 g_param_spec_int ("lower",
222 "Current lower value",
223 "Current value in the entry presenting lower end of selected range",
225 DEFAULT_START, G_PARAM_CONSTRUCT |
226 G_PARAM_READABLE | G_PARAM_WRITABLE));
229 * HildonRangeEditor:higher:
231 * Current value in the entry presenting higher end of selected range.
234 g_object_class_install_property (gobject_class, PROP_HIGHER,
235 g_param_spec_int ("higher",
236 "Current higher value",
237 "Current value in the entry presenting higher end of selected range",
239 DEFAULT_END, G_PARAM_CONSTRUCT |
240 G_PARAM_READABLE | G_PARAM_WRITABLE));
243 * HildonRangeEditor:separator:
245 * Separator string to separate range editor entries.
248 g_object_class_install_property (gobject_class, PROP_SEPARATOR,
249 g_param_spec_string ("separator",
251 "Separator string to separate entries",
252 _("ckct_wi_range_separator"),
254 G_PARAM_READABLE | G_PARAM_WRITABLE));
258 hildon_range_editor_init (HildonRangeEditor *editor)
260 HildonRangeEditorPrivate *priv;
262 gint range_editor_entry_alignment;
263 gint range_editor_separator_padding;
265 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
268 GTK_WIDGET_SET_FLAGS (editor, GTK_NO_WINDOW);
270 gtk_widget_push_composite_child ();
272 priv->start_entry = gtk_entry_new ();
273 priv->end_entry = gtk_entry_new ();
274 priv->label = gtk_label_new (_("ckct_wi_range_separator"));
277 /* Get values from gtkrc (or use defaults) */
278 /* FIXME: This is broken, styles are not yet attached */
279 gtk_widget_style_get (GTK_WIDGET (editor),
280 "hildon_range_editor_entry_alignment",
281 &range_editor_entry_alignment,
282 "hildon_range_editor_separator_padding",
283 &range_editor_separator_padding, NULL);
285 /* Add padding to separator */
286 gtk_misc_set_padding (GTK_MISC (priv->label),
287 range_editor_separator_padding, 0);
289 /* Align the text to right in entry box */
290 gtk_entry_set_alignment (GTK_ENTRY (priv->start_entry),
291 range_editor_entry_alignment);
292 gtk_entry_set_alignment (GTK_ENTRY (priv->end_entry),
293 range_editor_entry_alignment);
295 gtk_widget_set_composite_name (priv->start_entry, "start_entry");
296 gtk_widget_set_composite_name (priv->end_entry, "end_entry");
297 gtk_widget_set_composite_name (priv->label, "separator_label");
298 gtk_widget_set_parent (priv->start_entry, GTK_WIDGET (editor));
299 gtk_widget_set_parent (priv->end_entry, GTK_WIDGET (editor));
300 gtk_widget_set_parent (priv->label, GTK_WIDGET (editor));
302 g_signal_connect (G_OBJECT (priv->start_entry), "button-release-event",
303 G_CALLBACK (hildon_range_editor_released), editor);
304 g_signal_connect (G_OBJECT (priv->end_entry), "button-release-event",
305 G_CALLBACK (hildon_range_editor_released), editor);
307 g_signal_connect (G_OBJECT (priv->start_entry), "button-press-event",
308 G_CALLBACK (hildon_range_editor_press), editor);
309 g_signal_connect (G_OBJECT (priv->end_entry), "button-press-event",
310 G_CALLBACK (hildon_range_editor_press), editor);
312 g_signal_connect (G_OBJECT (priv->start_entry), "key-press-event",
313 G_CALLBACK (hildon_range_editor_entry_keypress), editor);
314 g_signal_connect (G_OBJECT (priv->end_entry), "key-press-event",
315 G_CALLBACK (hildon_range_editor_entry_keypress), editor);
317 g_signal_connect (G_OBJECT (priv->start_entry), "focus-in-event",
318 G_CALLBACK (hildon_range_editor_entry_focus_in), editor);
319 g_signal_connect (G_OBJECT (priv->end_entry), "focus-in-event",
320 G_CALLBACK (hildon_range_editor_entry_focus_in), editor);
322 g_signal_connect (G_OBJECT (priv->start_entry), "focus-out-event",
323 G_CALLBACK (hildon_range_editor_entry_focus_out), editor);
324 g_signal_connect (G_OBJECT (priv->end_entry), "focus-out-event",
325 G_CALLBACK (hildon_range_editor_entry_focus_out), editor);
326 g_signal_connect (priv->start_entry, "changed",
327 G_CALLBACK (hildon_range_editor_entry_changed), editor);
328 g_signal_connect (priv->end_entry, "changed",
329 G_CALLBACK (hildon_range_editor_entry_changed), editor);
331 g_object_set (G_OBJECT (priv->start_entry),
332 "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL);
334 g_object_set( G_OBJECT (priv->end_entry),
335 "hildon-input-mode", HILDON_GTK_INPUT_MODE_NUMERIC, NULL);
337 gtk_widget_show (priv->start_entry);
338 gtk_widget_show (priv->end_entry);
339 gtk_widget_show (priv->label);
341 gtk_widget_pop_composite_child();
345 hildon_range_editor_set_property (GObject *object,
350 HildonRangeEditor *editor = HILDON_RANGE_EDITOR(object);
355 hildon_range_editor_set_lower (editor, g_value_get_int (value));
359 hildon_range_editor_set_higher (editor, g_value_get_int (value));
363 hildon_range_editor_set_min (editor, g_value_get_int (value));
367 hildon_range_editor_set_max (editor, g_value_get_int (value));
371 hildon_range_editor_set_separator (editor,
372 g_value_get_string (value));
376 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
382 hildon_range_editor_get_property (GObject *object,
387 HildonRangeEditor *editor = HILDON_RANGE_EDITOR(object);
392 g_value_set_int (value, hildon_range_editor_get_lower (editor));
396 g_value_set_int (value, hildon_range_editor_get_higher (editor));
400 g_value_set_int (value, hildon_range_editor_get_min (editor));
404 g_value_set_int (value, hildon_range_editor_get_max (editor));
408 g_value_set_string (value, hildon_range_editor_get_separator (editor));
412 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
418 hildon_range_editor_entry_validate (HildonRangeEditor *editor,
419 GtkWidget *edited_entry,
420 gboolean allow_intermediate)
422 HildonRangeEditorPrivate *priv;
425 gint min, max, fixup;
428 gboolean error = FALSE;
430 g_assert(HILDON_IS_RANGE_EDITOR(editor));
431 g_assert(GTK_IS_ENTRY(edited_entry));
433 priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor);
436 /* Find the valid range for the modified component */
437 if (edited_entry == priv->start_entry) {
438 min = hildon_range_editor_get_min (editor);
439 max = hildon_range_editor_get_higher (editor);
441 min = hildon_range_editor_get_lower (editor);
442 max = hildon_range_editor_get_max (editor);
445 text = gtk_entry_get_text (GTK_ENTRY (edited_entry));
447 if (text && text [0])
449 /* Try to convert entry text to number */
450 value = strtol(text, &tail, 10);
452 /* Check if conversion succeeded */
455 /* Check if value is in allowed range. This is tricky in those
456 cases when user is editing a value.
457 For example: Range = [100, 500] and user have just inputted "4".
458 This should not lead into error message. Otherwise value is
459 resetted back to "100" and next "4" press will reset it back
461 if (allow_intermediate)
463 /* We now have the following error cases:
464 * If inputted value as above maximum and
465 maximum is either positive or then maximum
466 negative and value is positive.
467 * If inputted value is below minimum and minimum
468 is negative or minumum positive and value
470 In all other cases situation can be fixed just by
471 adding new numbers to the string.
473 if (value > max && (max >= 0 || (max < 0 && value >= 0)))
477 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_maximum_value"), max);
479 else if (value < min && (min < 0 || (min >= 0 && value < 0)))
483 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_minimum_value"), min);
491 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_maximum_value"), max);
493 else if (value < min) {
496 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_minimum_value"), min);
501 if (edited_entry == priv->start_entry)
502 hildon_range_editor_set_lower (editor, fixup);
504 hildon_range_editor_set_higher (editor, fixup);
507 /* The only valid case when conversion can fail is when we
508 have plain '-', intermediate forms are allowed AND
509 minimum bound is negative */
510 else if (!allow_intermediate || strcmp(text, "-") != 0 || min >= 0) {
512 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_set_a_value_within_range"), min, max);
515 else if (! allow_intermediate) {
517 g_snprintf (buffer, sizeof (buffer), _("ckct_ib_set_a_value_within_range"), min, max);
522 hildon_banner_show_information (edited_entry, NULL, buffer);
523 gtk_widget_grab_focus (edited_entry);
528 hildon_range_editor_entry_focus_in (GtkEditable *editable,
529 GdkEventFocus *event,
530 HildonRangeEditor *editor)
532 HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor);
541 if (GTK_WIDGET (editable) == priv->start_entry)
542 gtk_editable_select_region (editable, -1, 0);
544 gtk_editable_select_region (editable, 0, -1);
548 /* Gets and sets the current range. This has two usefull side effects:
549 * Values are now sorted to the correct order
550 * Out of range values are clamped to range */
552 hildon_range_editor_apply_current_range (HildonRangeEditor *editor)
554 g_assert (HILDON_IS_RANGE_EDITOR (editor));
556 hildon_range_editor_set_range (editor,
557 hildon_range_editor_get_lower (editor),
558 hildon_range_editor_get_higher (editor));
562 hildon_range_editor_entry_changed (GtkWidget *widget,
563 HildonRangeEditor *editor)
565 g_assert (HILDON_IS_RANGE_EDITOR (editor));
567 hildon_range_editor_entry_validate (editor, widget, TRUE);
571 hildon_range_editor_entry_focus_out (GtkEditable *editable,
572 GdkEventFocus *event,
573 HildonRangeEditor *editor)
575 g_assert (HILDON_IS_RANGE_EDITOR(editor));
577 hildon_range_editor_entry_validate (editor, GTK_WIDGET (editable), FALSE);
582 hildon_range_editor_press (GtkEditable *editable,
583 GdkEventButton *event,
584 HildonRangeEditor *editor)
586 HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor);
594 hildon_range_editor_forall (GtkContainer *container,
595 gboolean include_internals,
596 GtkCallback callback,
597 gpointer callback_data)
599 HildonRangeEditorPrivate *priv;
601 g_assert (HILDON_IS_RANGE_EDITOR (container));
602 g_assert (callback != NULL);
604 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (container);
607 if (! include_internals)
610 (*callback) (priv->start_entry, callback_data);
611 (*callback) (priv->end_entry, callback_data);
612 (*callback) (priv->label, callback_data);
616 hildon_range_editor_destroy (GtkObject *self)
618 HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE (self);
620 if (priv->start_entry)
622 gtk_widget_unparent (priv->start_entry);
623 priv->start_entry = NULL;
627 gtk_widget_unparent (priv->end_entry);
628 priv->end_entry = NULL;
632 gtk_widget_unparent (priv->label);
636 if (GTK_OBJECT_CLASS (parent_class)->destroy)
637 GTK_OBJECT_CLASS (parent_class)->destroy (self);
642 hildon_range_editor_size_request (GtkWidget *widget,
643 GtkRequisition *requisition)
645 HildonRangeEditorPrivate *priv = NULL;
646 GtkRequisition lab_req, mreq;
648 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (widget);
651 gtk_entry_get_width_chars (GTK_ENTRY (priv->end_entry));
653 gtk_widget_size_request (priv->start_entry, &mreq);
654 gtk_widget_size_request (priv->end_entry, &mreq);
655 gtk_widget_size_request (priv->label, &lab_req);
657 /* Width for entries and separator label and border */
658 requisition->width = mreq.width * 2 + lab_req.width +
659 widget->style->xthickness * 2;
660 /* Add vertical border */
661 requisition->height = mreq.height + widget->style->ythickness * 2;
662 /* Fit label height */
663 requisition->height = MAX (requisition->height, lab_req.height);
667 hildon_range_editor_size_allocate (GtkWidget *widget,
668 GtkAllocation *allocation)
670 HildonRangeEditorPrivate *priv;
671 GtkAllocation child1_allocation, child2_allocation, child3_allocation;
673 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (widget);
676 widget->allocation = *allocation;
678 /* Allocate entries, left-to-right */
679 if (priv->start_entry && GTK_WIDGET_VISIBLE (priv->start_entry))
681 GtkRequisition child_requisition;
683 gtk_widget_get_child_requisition (priv->start_entry,
686 child1_allocation.x = allocation->x;
687 child1_allocation.y = allocation->y;
689 child1_allocation.width = child_requisition.width;
690 child1_allocation.height = allocation->height;
692 gtk_widget_size_allocate (priv->start_entry, &child1_allocation);
695 if (priv->label && GTK_WIDGET_VISIBLE (priv->label))
697 GtkRequisition child_requisition;
699 gtk_widget_get_child_requisition (priv->label, &child_requisition);
701 child2_allocation.x = child1_allocation.x + child1_allocation.width;
702 child2_allocation.y = allocation->y;
704 child2_allocation.width = child_requisition.width + 4;
705 child2_allocation.height = allocation->height;
707 gtk_widget_size_allocate (priv->label, &child2_allocation);
710 if (priv->end_entry && GTK_WIDGET_VISIBLE (priv->end_entry))
712 GtkRequisition child_requisition;
714 gtk_widget_get_child_requisition (priv->end_entry, &child_requisition);
716 child3_allocation.x = child2_allocation.x + child2_allocation.width;
717 child3_allocation.y = allocation->y;
719 child3_allocation.width = child_requisition.width;
720 child3_allocation.height = allocation->height;
722 gtk_widget_size_allocate (priv->end_entry, &child3_allocation);
726 /* Button released inside entries */
728 hildon_range_editor_released (GtkEditable *editable,
729 GdkEventButton *event,
730 HildonRangeEditor *editor)
732 HildonRangeEditorPrivate *priv = HILDON_RANGE_EDITOR_GET_PRIVATE(editor);
735 if (GTK_WIDGET (editable) == priv->start_entry)
736 gtk_editable_select_region(editable, -1, 0);
738 gtk_editable_select_region(editable, 0, -1);
744 hildon_range_editor_entry_keypress (GtkWidget *widget,
746 HildonRangeEditor *editor)
751 g_assert(HILDON_IS_RANGE_EDITOR (editor));
753 text = gtk_entry_get_text (GTK_ENTRY (widget));
754 cursor_pos = gtk_editable_get_position (GTK_EDITABLE (widget));
756 switch (event->keyval)
759 /* If we are on the first character and press left,
760 try to move to previous field */
761 if (cursor_pos == 0) {
762 (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_LEFT);
768 /* If the cursor is on the right, try to move to the next field */
769 if (cursor_pos >= g_utf8_strlen (text, -1)) {
770 (void) gtk_widget_child_focus (GTK_WIDGET (editor), GTK_DIR_RIGHT);
783 hildon_range_editor_refresh_widths (HildonRangeEditorPrivate *priv)
785 gchar start_range[32], end_range[32];
788 /* Calculate length of entry so extremes would fit */
789 g_snprintf (start_range, sizeof (start_range), "%d", priv->range_limits_start);
790 g_snprintf (end_range, sizeof (end_range), "%d", priv->range_limits_end);
791 length = MAX (g_utf8_strlen (start_range, -1), g_utf8_strlen (end_range, -1));
793 gtk_entry_set_width_chars (GTK_ENTRY (priv->start_entry), length);
794 gtk_entry_set_max_length (GTK_ENTRY (priv->start_entry), length);
795 gtk_entry_set_width_chars (GTK_ENTRY (priv->end_entry), length);
796 gtk_entry_set_max_length (GTK_ENTRY (priv->end_entry), length);
800 * hildon_range_editor_get_type:
802 * Initializes, and returns the type of a hildon range editor.
804 * @Returns : GType of #HildonRangeEditor
808 hildon_range_editor_get_type (void)
810 static GType editor_type = 0;
814 static const GTypeInfo editor_info =
816 sizeof (HildonRangeEditorClass),
817 NULL, /* base_init */
818 NULL, /* base_finalize */
819 (GClassInitFunc) hildon_range_editor_class_init,
820 NULL, /* class_finalize */
821 NULL, /* class_data */
822 sizeof (HildonRangeEditor),
824 (GInstanceInitFunc) hildon_range_editor_init,
826 editor_type = g_type_register_static (GTK_TYPE_CONTAINER,
834 * hildon_range_editor_new:
836 * HildonRangeEditor contains two GtkEntrys that accept numbers and minus.
838 * Returns: pointer to a new @HildonRangeEditor widget
841 hildon_range_editor_new (void)
843 return GTK_WIDGET (g_object_new (HILDON_TYPE_RANGE_EDITOR, NULL));
847 * hildon_range_editor_new_with_separator:
848 * @separator: a string that is shown between the numbers
850 * HildonRangeEditor contains two Gtk entries that accept numbers.
851 * A separator is displayed between two entries.
852 * CHECKME: Use '-' as a separator in the case of null separator?
854 * Returns: pointer to a new @HildonRangeEditor widget
857 hildon_range_editor_new_with_separator (const gchar *separator)
859 return GTK_WIDGET (g_object_new (HILDON_TYPE_RANGE_EDITOR,
860 "separator", separator, NULL));
864 * hildon_range_editor_set_range:
865 * @editor: the #HildonRangeEditor widget
866 * @start: range's start value
867 * @end: range's end value
869 * Sets a range to the editor. (The current value)
871 * Sets the range of the @HildonRangeEditor widget.
874 hildon_range_editor_set_range (HildonRangeEditor *editor,
878 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
880 /* Make sure that the start/end appear in the correct order */
881 hildon_range_editor_set_lower (editor, MIN (start, end));
882 hildon_range_editor_set_higher (editor, MAX (start, end));
886 * hildon_range_editor_get_range:
887 * @editor: the #HildonRangeEditor widget
888 * @start: ranges start value
889 * @end: ranges end value
891 * Gets the range of the @HildonRangeEditor widget.
894 hildon_range_editor_get_range (HildonRangeEditor *editor,
898 HildonRangeEditorPrivate *priv;
900 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor) && start && end);
901 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
903 *start = hildon_range_editor_get_lower (editor);
904 *end = hildon_range_editor_get_higher (editor);
908 * hildon_range_editor_set_limits:
909 * @editor: the #HildonRangeEditor widget
910 * @start: minimum acceptable value (default: no limit)
911 * @end: maximum acceptable value (default: no limit)
913 * Sets the range of the @HildonRangeEditor widget.
916 hildon_range_editor_set_limits (HildonRangeEditor *editor,
920 /* FIXME: Setting start/end as separate steps can modify
921 the inputted range unneedlesly */
922 hildon_range_editor_set_min (editor, start);
923 hildon_range_editor_set_max (editor, end);
927 hildon_range_editor_set_lower (HildonRangeEditor *editor,
930 HildonRangeEditorPrivate *priv;
933 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
934 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
936 g_snprintf(buffer, sizeof (buffer), "%d",
937 CLAMP (value, priv->range_limits_start, priv->range_limits_end));
939 /* Update entry text with new value */
940 gtk_entry_set_text (GTK_ENTRY (priv->start_entry), buffer);
941 g_object_notify (G_OBJECT (editor), "lower");
945 hildon_range_editor_set_higher (HildonRangeEditor *editor,
948 HildonRangeEditorPrivate *priv;
951 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
952 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
954 g_snprintf(buffer, sizeof(buffer), "%d",
955 CLAMP(value, priv->range_limits_start, priv->range_limits_end));
957 /* Update entry text with new value */
958 gtk_entry_set_text (GTK_ENTRY (priv->end_entry), buffer);
959 g_object_notify (G_OBJECT (editor), "higher");
963 hildon_range_editor_get_lower (HildonRangeEditor *editor)
965 HildonRangeEditorPrivate *priv;
966 g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0);
967 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
968 return atoi(gtk_entry_get_text(GTK_ENTRY(priv->start_entry)));
972 hildon_range_editor_get_higher (HildonRangeEditor *editor)
974 HildonRangeEditorPrivate *priv;
975 g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0);
976 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
977 return atoi (gtk_entry_get_text(GTK_ENTRY (priv->end_entry)));
981 hildon_range_editor_set_min (HildonRangeEditor *editor,
984 HildonRangeEditorPrivate *priv;
986 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
988 /* We can cause many properties to change */
989 g_object_freeze_notify (G_OBJECT(editor));
990 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
991 priv->range_limits_start = value;
993 if (priv->range_limits_end < value)
994 hildon_range_editor_set_max (editor, value);
995 /* Setting maximum applies widths and range in this case */
997 hildon_range_editor_refresh_widths (priv);
998 hildon_range_editor_apply_current_range (editor);
1001 g_object_notify (G_OBJECT (editor), "min");
1002 g_object_thaw_notify (G_OBJECT (editor));
1006 hildon_range_editor_set_max (HildonRangeEditor *editor,
1009 HildonRangeEditorPrivate *priv;
1011 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
1013 /* We can cause many properties to change */
1014 g_object_freeze_notify (G_OBJECT (editor));
1015 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
1016 priv->range_limits_end = value;
1018 if (priv->range_limits_start > value)
1019 hildon_range_editor_set_min (editor, value);
1020 /* Setting minimum applies widths and range in this case */
1022 hildon_range_editor_refresh_widths (priv);
1023 hildon_range_editor_apply_current_range (editor);
1026 g_object_notify (G_OBJECT (editor), "max");
1027 g_object_thaw_notify (G_OBJECT (editor));
1031 hildon_range_editor_get_min (HildonRangeEditor *editor)
1033 HildonRangeEditorPrivate *priv;
1034 g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0);
1035 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
1037 return priv->range_limits_start;
1041 hildon_range_editor_get_max (HildonRangeEditor *editor)
1043 HildonRangeEditorPrivate *priv;
1044 g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), 0);
1045 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
1047 return priv->range_limits_end;
1051 hildon_range_editor_set_separator (HildonRangeEditor *editor,
1052 const gchar *separator)
1054 HildonRangeEditorPrivate *priv;
1055 g_return_if_fail (HILDON_IS_RANGE_EDITOR (editor));
1056 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
1058 gtk_label_set_text (GTK_LABEL (priv->label), separator);
1059 g_object_notify (G_OBJECT(editor), "separator");
1063 hildon_range_editor_get_separator (HildonRangeEditor *editor)
1065 HildonRangeEditorPrivate *priv;
1066 g_return_val_if_fail (HILDON_IS_RANGE_EDITOR (editor), NULL);
1067 priv = HILDON_RANGE_EDITOR_GET_PRIVATE (editor);
1069 return gtk_label_get_text (GTK_LABEL (priv->label));