db48c1443aa30e8f26609226e7d84ab6a82f0f72
[platform/upstream/atk.git] / atk / atkrange.c
1 /* ATK -  Accessibility Toolkit
2  * Copyright 2014 Igalia S.L.
3  *
4  * Author: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include "atkvalue.h"
23
24 /**
25  * SECTION:atkrange
26  * @Short_description: A given range or subrange, to be used with #AtkValue
27  * @Title:AtkRange
28  *
29  * #AtkRange are used on #AtkValue, in order to represent the full
30  * range of a given component (for example an slider or a range
31  * control), or to define each individual subrange this full range is
32  * splitted if available. See #AtkValue documentation for further
33  * details.
34  */
35
36 struct _AtkRange {
37   gdouble lower;
38   gdouble upper;
39   gchar *description;
40 };
41
42 /**
43  * atk_range_copy:
44  * @src: #AtkRange to copy
45  *
46  * Returns a new #AtkRange that is a exact copy of @src
47  *
48  * Since: 2.12
49  *
50  * Returns: (transfer full): a new #AtkRange copy of @src
51  */
52 AtkRange *
53 atk_range_copy (AtkRange *src)
54 {
55   g_return_val_if_fail (src != NULL, NULL);
56
57   return atk_range_new (src->lower,
58                         src->upper,
59                         src->description);
60 }
61
62 /**
63  * atk_range_free:
64  * @range: #AtkRange to free
65  *
66  * Free @range
67  *
68  * Since: 2.12
69  */
70 void
71 atk_range_free (AtkRange *range)
72 {
73   g_return_if_fail (range != NULL);
74
75   if (range->description)
76     g_free (range->description);
77
78   g_slice_free (AtkRange, range);
79 }
80
81 G_DEFINE_BOXED_TYPE (AtkRange, atk_range, atk_range_copy,
82                      atk_range_free)
83
84
85 /**
86  * atk_range_new:
87  * @lower_limit: inferior limit for this range
88  * @upper_limit: superior limit for this range
89  * @description: human readable description of this range.
90  *
91  * Creates a new #AtkRange.
92  *
93  * Since: 2.12
94  *
95  * Returns: (transfer full): a new #AtkRange
96  *
97  */
98 AtkRange*
99 atk_range_new  (gdouble   lower_limit,
100                 gdouble   upper_limit,
101                 const gchar *description)
102 {
103   AtkRange *range;
104
105   range = g_slice_new0 (AtkRange);
106
107   range->lower = lower_limit;
108   range->upper = upper_limit;
109   if (description != NULL)
110     range->description = g_strdup (description);
111
112   return range;
113 }
114
115 /**
116  * atk_range_get_lower_limit:
117  * @range: an #AtkRange
118  *
119  * Returns the lower limit of @range
120  *
121  * Since: 2.12
122  *
123  * Returns: the lower limit of @range
124  */
125 gdouble
126 atk_range_get_lower_limit  (AtkRange *range)
127 {
128   g_return_val_if_fail (range != NULL, 0);
129
130   return range->lower;
131 }
132
133 /**
134  * atk_range_get_upper_limit:
135  * @range: an #AtkRange
136  *
137  * Returns the upper limit of @range
138  *
139  * Since: 2.12
140  *
141  * Returns: the upper limit of @range
142  */
143 gdouble
144 atk_range_get_upper_limit (AtkRange *range)
145 {
146   g_return_val_if_fail (range != NULL, 0);
147
148   return range->upper;
149 }
150
151 /**
152  * atk_range_get_description:
153  * @range: an #AtkRange
154  *
155  * Returns the human readable description of @range
156  *
157  * Since: 2.12
158  *
159  * Returns: the human-readable description of @range
160  */
161 const gchar*
162 atk_range_get_description  (AtkRange *range)
163 {
164   g_return_val_if_fail (range != NULL, NULL);
165
166   return range->description;
167 }