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
 * AtkRange:
28
 *
29
 * A given range or subrange, to be used with #AtkValue
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
{
40
  gdouble lower;
41
  gdouble upper;
42
  gchar *description;
43
};
44

            
45
/**
46
 * atk_range_copy:
47
 * @src: #AtkRange to copy
48
 *
49
 * Returns a new #AtkRange that is a exact copy of @src
50
 *
51
 * Since: 2.12
52
 *
53
 * Returns: (transfer full): a new #AtkRange copy of @src
54
 */
55
AtkRange *
56
atk_range_copy (AtkRange *src)
57
{
58
  g_return_val_if_fail (src != NULL, NULL);
59

            
60
  return atk_range_new (src->lower,
61
                        src->upper,
62
                        src->description);
63
}
64

            
65
/**
66
 * atk_range_free:
67
 * @range: #AtkRange to free
68
 *
69
 * Free @range
70
 *
71
 * Since: 2.12
72
 */
73
void
74
2
atk_range_free (AtkRange *range)
75
{
76
2
  g_return_if_fail (range != NULL);
77

            
78
2
  if (range->description)
79
    g_free (range->description);
80

            
81
2
  g_slice_free (AtkRange, range);
82
}
83

            
84
G_DEFINE_BOXED_TYPE (AtkRange, atk_range, atk_range_copy, atk_range_free)
85

            
86
/**
87
 * atk_range_new:
88
 * @lower_limit: inferior limit for this range
89
 * @upper_limit: superior limit for this range
90
 * @description: human readable description of this range.
91
 *
92
 * Creates a new #AtkRange.
93
 *
94
 * Since: 2.12
95
 *
96
 * Returns: (transfer full): a new #AtkRange
97
 *
98
 */
99
AtkRange *
100
2
atk_range_new (gdouble lower_limit,
101
               gdouble upper_limit,
102
               const gchar *description)
103
{
104
  AtkRange *range;
105

            
106
2
  range = g_slice_new0 (AtkRange);
107

            
108
2
  range->lower = lower_limit;
109
2
  range->upper = upper_limit;
110
2
  if (description != NULL)
111
    range->description = g_strdup (description);
112

            
113
2
  return range;
114
}
115

            
116
/**
117
 * atk_range_get_lower_limit:
118
 * @range: an #AtkRange
119
 *
120
 * Returns the lower limit of @range
121
 *
122
 * Since: 2.12
123
 *
124
 * Returns: the lower limit of @range
125
 */
126
gdouble
127
1
atk_range_get_lower_limit (AtkRange *range)
128
{
129
1
  g_return_val_if_fail (range != NULL, 0);
130

            
131
1
  return range->lower;
132
}
133

            
134
/**
135
 * atk_range_get_upper_limit:
136
 * @range: an #AtkRange
137
 *
138
 * Returns the upper limit of @range
139
 *
140
 * Since: 2.12
141
 *
142
 * Returns: the upper limit of @range
143
 */
144
gdouble
145
1
atk_range_get_upper_limit (AtkRange *range)
146
{
147
1
  g_return_val_if_fail (range != NULL, 0);
148

            
149
1
  return range->upper;
150
}
151

            
152
/**
153
 * atk_range_get_description:
154
 * @range: an #AtkRange
155
 *
156
 * Returns the human readable description of @range
157
 *
158
 * Since: 2.12
159
 *
160
 * Returns: the human-readable description of @range
161
 */
162
const gchar *
163
atk_range_get_description (AtkRange *range)
164
{
165
  g_return_val_if_fail (range != NULL, NULL);
166

            
167
  return range->description;
168
}