~canonical-dx-team/unity/unity.fix-ql-losing-focus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * Copyright (C) 2011 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Rodrigo Moya <rodrigo.moya@canonical.com>
 */

/**
 * SECTION:unity-panel-view-accessible
 * @Title: UnityPanelViewAccessible
 * @short_description: Implementation of the ATK interfaces for #PanelView
 * @see_also: PanelView
 *
 * #UnityPanelViewAccessible implements the required ATK interfaces for
 * #PanelView, ie: exposing the different items contained in the panel
 * as children.
 *
 */

#include <glib/gi18n-lib.h>
#include <Nux/Nux.h>
#include "PanelView.h"
#include "unity-panel-view-accessible.h"

#include "unitya11y.h"

/* GObject */
static void unity_panel_view_accessible_class_init (UnityPanelViewAccessibleClass *klass);
static void unity_panel_view_accessible_init       (UnityPanelViewAccessible *self);

/* AtkObject */
static void         unity_panel_view_accessible_initialize     (AtkObject *accessible, gpointer data);
static gint         unity_panel_view_accessible_get_n_children (AtkObject *accessible);
static AtkObject   *unity_panel_view_accessible_ref_child      (AtkObject *accessible, gint i);

G_DEFINE_TYPE (UnityPanelViewAccessible, unity_panel_view_accessible,  NUX_TYPE_VIEW_ACCESSIBLE)

static void
unity_panel_view_accessible_class_init (UnityPanelViewAccessibleClass *klass)
{
  AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);

  /* AtkObject */
  atk_class->initialize = unity_panel_view_accessible_initialize;
  atk_class->get_n_children = unity_panel_view_accessible_get_n_children;
  atk_class->ref_child = unity_panel_view_accessible_ref_child;
}

static void
unity_panel_view_accessible_init (UnityPanelViewAccessible *self)
{
}

AtkObject *
unity_panel_view_accessible_new (nux::Object *object)
{
  AtkObject *accessible;

  g_return_val_if_fail (dynamic_cast<PanelView *>(object), NULL);

  accessible = ATK_OBJECT (g_object_new (UNITY_TYPE_PANEL_VIEW_ACCESSIBLE, NULL));

  atk_object_initialize (accessible, object);

  return accessible;
}

static void
unity_panel_view_accessible_initialize (AtkObject *accessible, gpointer data)
{
  ATK_OBJECT_CLASS (unity_panel_view_accessible_parent_class)->initialize (accessible, data);

  accessible->role = ATK_ROLE_PANEL;
}

static gint
unity_panel_view_accessible_get_n_children (AtkObject *accessible)
{
  nux::Object *nux_object = NULL;
  PanelView *panel;
  PanelHomeButton *home_button;
  gint rc = 0;

  g_return_val_if_fail (UNITY_IS_PANEL_VIEW_ACCESSIBLE (accessible), 0);

  nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (accessible));
  if (!nux_object) /* state is defunct */
    return 0;

  panel = dynamic_cast<PanelView *>(nux_object);
  if ((home_button = panel->HomeButton ()) != NULL)
    rc = 1;

  return rc;
}

static AtkObject *
unity_panel_view_accessible_ref_child (AtkObject *accessible, gint i)
{
  nux::Object *nux_object = NULL;
  PanelView *panel;
  PanelHomeButton *home_button;
  AtkObject *child_accessible = NULL;

  g_return_val_if_fail (UNITY_IS_PANEL_VIEW_ACCESSIBLE (accessible), NULL);

  nux_object = nux_object_accessible_get_object (NUX_OBJECT_ACCESSIBLE (accessible));
  if (!nux_object) /* state is defunct */
    return NULL;

  panel = dynamic_cast<PanelView *>(nux_object);
  if ((home_button = panel->HomeButton ()) != NULL)
    {
      nux::Object *child = NULL;

      child = dynamic_cast<nux::Object *>(home_button);
      child_accessible = unity_a11y_get_accessible (child);
      if (child_accessible != NULL)
        g_object_ref (child_accessible);
    }

  return child_accessible;
}