1
/*
2
 * Copyright 2008 Codethink Ltd.
3
 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the
17
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20

            
21
#include <atk/atk.h>
22
#include <glib.h>
23
#include <stdio.h>
24
#include <string.h>
25

            
26
#include "my-atk-object.h"
27
#include "my-atk-value.h"
28

            
29
typedef struct _MyAtkValueInfo MyAtkValueInfo;
30

            
31
static void atk_value_interface_init (AtkValueIface *iface);
32

            
33
7
G_DEFINE_TYPE_WITH_CODE (MyAtkValue,
34
                         my_atk_value,
35
                         MY_TYPE_ATK_OBJECT,
36
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE,
37
                                                atk_value_interface_init));
38

            
39
guint
40
7
my_atk_set_value (AtkValue *obj, gdouble min, gdouble cur, gdouble max, gdouble step)
41
{
42
7
  MyAtkValue *self = MY_ATK_VALUE (obj);
43
7
  g_return_val_if_fail (MY_IS_ATK_VALUE (obj), -1);
44

            
45
7
  self->min = min;
46
7
  self->cur = cur;
47
7
  self->max = max;
48
7
  self->step = step;
49

            
50
7
  return 0;
51
}
52

            
53
static void
54
3
my_atk_value_get_value_and_text (AtkValue *obj, gdouble *value, gchar **text)
55
{
56
3
  MyAtkValue *self = MY_ATK_VALUE (obj);
57
3
  g_return_if_fail (MY_IS_ATK_VALUE (obj));
58

            
59
3
  *value = self->cur;
60
3
  *text = g_strdup_printf ("%f", self->cur);
61
}
62

            
63
static AtkRange *
64
2
my_atk_value_get_range (AtkValue *obj)
65
{
66
2
  MyAtkValue *self = MY_ATK_VALUE (obj);
67
2
  g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL);
68

            
69
2
  return atk_range_new (self->min, self->max, NULL);
70
}
71

            
72
static gdouble
73
1
my_atk_value_get_increment (AtkValue *obj)
74
{
75
1
  MyAtkValue *self = MY_ATK_VALUE (obj);
76
1
  g_return_val_if_fail (MY_IS_ATK_VALUE (obj), 0);
77
1
  return self->step;
78
}
79

            
80
static GSList *
81
my_atk_value_get_sub_ranges (AtkValue *obj)
82
{
83
  g_return_val_if_fail (MY_IS_ATK_VALUE (obj), NULL);
84

            
85
  return NULL;
86
}
87

            
88
static void
89
1
my_atk_value_set_value (AtkValue *obj, const gdouble val)
90
{
91
1
  MyAtkValue *self = MY_ATK_VALUE (obj);
92
1
  g_return_if_fail (MY_IS_ATK_VALUE (obj));
93

            
94
1
  if (self->min < val && val < self->max)
95
1
    self->cur = val;
96
1
  return;
97
}
98

            
99
static void
100
7
atk_value_interface_init (AtkValueIface *iface)
101
{
102
7
  if (!iface)
103
    return;
104
7
  iface->get_value_and_text = my_atk_value_get_value_and_text;
105
7
  iface->get_range = my_atk_value_get_range;
106
7
  iface->get_increment = my_atk_value_get_increment;
107
7
  iface->get_sub_ranges = my_atk_value_get_sub_ranges;
108
7
  iface->set_value = my_atk_value_set_value;
109
}
110

            
111
static void
112
7
my_atk_value_init (MyAtkValue *self)
113
{
114
7
  self->min = 0;
115
7
  self->cur = 0;
116
7
  self->max = 0;
117
7
  self->step = 0;
118
7
}
119

            
120
static void
121
my_atk_value_class_initialize (AtkObject *obj, gpointer data)
122
{
123
}
124

            
125
static void
126
my_atk_value_class_finalize (GObject *obj)
127
{
128
}
129

            
130
static void
131
7
my_atk_value_class_init (MyAtkValueClass *my_class)
132
{
133
7
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (my_class);
134
7
  GObjectClass *gobject_class = G_OBJECT_CLASS (my_class);
135

            
136
7
  gobject_class->finalize = my_atk_value_class_finalize;
137

            
138
7
  atk_class->initialize = my_atk_value_class_initialize;
139
7
}