Release 2.25.90
[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 "config.h"
23
24 #include "atkvalue.h"
25
26 /**
27  * SECTION:atkrange
28  * @Short_description: A given range or subrange, to be used with #AtkValue
29  * @Title:AtkRange
30  *
31  * #AtkRange are used on #AtkValue, in order to represent the full
32  * range of a given component (for example an slider or a range
33  * control), or to define each individual subrange this full range is
34  * splitted if available. See #AtkValue documentation for further
35  * details.
36  */
37
38 struct _AtkRange {
39   gdouble lower;
40   gdouble upper;
41   gchar *description;
42 };
43
44 /**
45  * atk_range_copy:
46  * @src: #AtkRange to copy
47  *
48  * Returns a new #AtkRange that is a exact copy of @src
49  *
50  * Since: 2.12
51  *
52  * Returns: (transfer full): a new #AtkRange copy of @src
53  */
54 AtkRange *
55 atk_range_copy (AtkRange *src)
56 {
57   g_return_val_if_fail (src != NULL, NULL);
58
59   return atk_range_new (src->lower,
60                         src->upper,
61                         src->description);
62 }
63
64 /**
65  * atk_range_free:
66  * @range: #AtkRange to free
67  *
68  * Free @range
69  *
70  * Since: 2.12
71  */
72 void
73 atk_range_free (AtkRange *range)
74 {
75   g_return_if_fail (range != NULL);
76
77   if (range->description)
78     g_free (range->description);
79
80   g_slice_free (AtkRange, range);
81 }
82
83 G_DEFINE_BOXED_TYPE (AtkRange, atk_range, atk_range_copy,
84                      atk_range_free)
85
86
87 /**
88  * atk_range_new:
89  * @lower_limit: inferior limit for this range
90  * @upper_limit: superior limit for this range
91  * @description: human readable description of this range.
92  *
93  * Creates a new #AtkRange.
94  *
95  * Since: 2.12
96  *
97  * Returns: (transfer full): a new #AtkRange
98  *
99  */
100 AtkRange*
101 atk_range_new  (gdouble   lower_limit,
102                 gdouble   upper_limit,
103                 const gchar *description)
104 {
105   AtkRange *range;
106
107   range = g_slice_new0 (AtkRange);
108
109   range->lower = lower_limit;
110   range->upper = upper_limit;
111   if (description != NULL)
112     range->description = g_strdup (description);
113
114   return range;
115 }
116
117 /**
118  * atk_range_get_lower_limit:
119  * @range: an #AtkRange
120  *
121  * Returns the lower limit of @range
122  *
123  * Since: 2.12
124  *
125  * Returns: the lower limit of @range
126  */
127 gdouble
128 atk_range_get_lower_limit  (AtkRange *range)
129 {
130   g_return_val_if_fail (range != NULL, 0);
131
132   return range->lower;
133 }
134
135 /**
136  * atk_range_get_upper_limit:
137  * @range: an #AtkRange
138  *
139  * Returns the upper limit of @range
140  *
141  * Since: 2.12
142  *
143  * Returns: the upper limit of @range
144  */
145 gdouble
146 atk_range_get_upper_limit (AtkRange *range)
147 {
148   g_return_val_if_fail (range != NULL, 0);
149
150   return range->upper;
151 }
152
153 /**
154  * atk_range_get_description:
155  * @range: an #AtkRange
156  *
157  * Returns the human readable description of @range
158  *
159  * Since: 2.12
160  *
161  * Returns: the human-readable description of @range
162  */
163 const gchar*
164 atk_range_get_description  (AtkRange *range)
165 {
166   g_return_val_if_fail (range != NULL, NULL);
167
168   return range->description;
169 }