~ubuntu-branches/ubuntu/utopic/almanah/utopic-proposed

« back to all changes in this revision

Viewing changes to src/widgets/tag-accessible.c

  • Committer: Package Import Robot
  • Author(s): Angel Abad
  • Date: 2013-12-02 13:21:08 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20131202132108-d4v6my2vq69rk648
Tags: 0.11.0-1
* Imported Upstream version 0.11.0
* debian/control: Update Homepage field.
* debian/patches/:
  - encrypt_database: Removed, applied upstream
  - spellchecking_error: Removed, applied upstream
  - desktop_keywords: Removed, applied upstream
* Bump Standards-Version to 3.9.5 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
 
2
/*
 
3
 * Almanah
 
4
 * Copyright (C) Álvaro Peña 2013 <alvaropg@gmail.com>
 
5
 *
 
6
 * Almanah is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * Almanah 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
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with Almanah.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include <glib/gi18n.h>
 
21
 
 
22
#include "tag-accessible.h"
 
23
#include "tag.h"
 
24
 
 
25
struct _AlmanahTagAccessiblePrivate
 
26
{
 
27
        gint test;
 
28
};
 
29
 
 
30
static void  almanah_tag_accessible_initialize                    (AtkObject *obj, gpointer data);
 
31
 
 
32
static const gchar* almanah_tag_accessible_get_name               (AtkObject *accessible);
 
33
 
 
34
static void  almanah_tag_accessible_atk_action_iface_init         (AtkActionIface *iface);
 
35
gboolean     almanah_tag_accessible_atk_action_do_action          (AtkAction *action, gint i);
 
36
gint         almanah_tag_accessible_atk_action_get_n_actions      (AtkAction *action);
 
37
const gchar* almanah_tag_accessible_atk_action_get_description    (AtkAction *action, gint i);
 
38
const gchar* almanah_tag_accessible_atk_action_get_name           (AtkAction *action, gint i);
 
39
const gchar* almanah_tag_accessible_atk_action_get_keybinding     (AtkAction *action, gint i);
 
40
gboolean     almanah_tag_accessible_atk_action_set_description    (AtkAction *action, gint i, const gchar *desc);
 
41
const gchar* almanah_tag_accessible_atk_action_get_localized_name (AtkAction *action, gint i);
 
42
 
 
43
G_DEFINE_TYPE_WITH_CODE (AlmanahTagAccessible, almanah_tag_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
 
44
                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, almanah_tag_accessible_atk_action_iface_init))
 
45
 
 
46
static void
 
47
almanah_tag_accessible_class_init (AlmanahTagAccessibleClass *klass)
 
48
{
 
49
        AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
 
50
 
 
51
        g_type_class_add_private (klass, sizeof (AlmanahTagAccessiblePrivate));
 
52
 
 
53
        class->get_name = almanah_tag_accessible_get_name;
 
54
        class->initialize = almanah_tag_accessible_initialize;
 
55
}
 
56
 
 
57
static void
 
58
almanah_tag_accessible_init (AlmanahTagAccessible *self)
 
59
{
 
60
}
 
61
 
 
62
static void
 
63
almanah_tag_accessible_initialize (AtkObject *obj, gpointer data)
 
64
{
 
65
        GtkWidget  *widget;
 
66
 
 
67
        ATK_OBJECT_CLASS (almanah_tag_accessible_parent_class)->initialize (obj, data);
 
68
 
 
69
        obj->role = ATK_ROLE_DRAWING_AREA;
 
70
}
 
71
 
 
72
/* Code adapted from gtklabelaccessible in GTK+ project */
 
73
static const gchar*
 
74
almanah_tag_accessible_get_name (AtkObject *accessible)
 
75
{
 
76
        const gchar *name;
 
77
 
 
78
        g_return_val_if_fail (ALMANAH_IS_TAG_ACCESSIBLE (accessible), NULL);
 
79
 
 
80
        name = ATK_OBJECT_CLASS (almanah_tag_accessible_parent_class)->get_name (accessible);
 
81
        if (name != NULL)
 
82
                return name;
 
83
        else {
 
84
                /* Get the text on the tag */
 
85
                GtkWidget *widget;
 
86
 
 
87
                widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
 
88
                g_return_val_if_fail (widget != NULL, NULL);
 
89
                g_return_val_if_fail (ALMANAH_IS_TAG (widget), NULL);
 
90
 
 
91
                return almanah_tag_get_tag (ALMANAH_TAG (widget));
 
92
        }
 
93
}
 
94
 
 
95
static void
 
96
almanah_tag_accessible_atk_action_iface_init (AtkActionIface *iface)
 
97
{
 
98
        iface->do_action = almanah_tag_accessible_atk_action_do_action;
 
99
        iface->get_n_actions = almanah_tag_accessible_atk_action_get_n_actions;
 
100
        iface->get_description = almanah_tag_accessible_atk_action_get_description;
 
101
        iface->get_name = almanah_tag_accessible_atk_action_get_name;
 
102
        iface->get_keybinding = almanah_tag_accessible_atk_action_get_keybinding;
 
103
        iface->set_description = almanah_tag_accessible_atk_action_set_description;
 
104
        iface->get_localized_name = almanah_tag_accessible_atk_action_get_localized_name;
 
105
}
 
106
 
 
107
gboolean
 
108
almanah_tag_accessible_atk_action_do_action (AtkAction *action, gint i)
 
109
{
 
110
        GtkWidget *widget;
 
111
 
 
112
        widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
 
113
        g_return_val_if_fail (widget != NULL, FALSE);
 
114
 
 
115
        if (i == 0) {
 
116
                almanah_tag_remove (ALMANAH_TAG (widget));
 
117
                return TRUE;
 
118
        } else
 
119
                return FALSE;
 
120
}
 
121
 
 
122
gint
 
123
almanah_tag_accessible_atk_action_get_n_actions (AtkAction *action)
 
124
{
 
125
        return 1;
 
126
}
 
127
 
 
128
const gchar*
 
129
almanah_tag_accessible_atk_action_get_description (AtkAction *action, gint i)
 
130
{
 
131
        if (i == 0)
 
132
                return "Remove the tag from the entry";
 
133
        else
 
134
                return NULL;
 
135
}
 
136
 
 
137
const gchar*
 
138
almanah_tag_accessible_atk_action_get_name (AtkAction *action, gint i)
 
139
{
 
140
        if (i == 0)
 
141
                return "remove";
 
142
        else
 
143
                return NULL;
 
144
}
 
145
 
 
146
const gchar*
 
147
almanah_tag_accessible_atk_action_get_keybinding (AtkAction *action, gint i)
 
148
{
 
149
        if (i == 0)
 
150
                return "R;;";
 
151
        else
 
152
                return NULL;
 
153
}
 
154
 
 
155
gboolean
 
156
almanah_tag_accessible_atk_action_set_description (AtkAction *action, gint i, const gchar *desc)
 
157
{
 
158
        return FALSE;
 
159
}
 
160
 
 
161
const gchar*
 
162
almanah_tag_accessible_atk_action_get_localized_name (AtkAction *action, gint i)
 
163
{
 
164
        if (i == 0)
 
165
                return _("Remove the tag from the entry");
 
166
        else
 
167
                return NULL;
 
168
}