Back to index

unity  6.0.0
unity-quicklist-accessible.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Alejandro PiƱeiro Iglesias <apinheiro@igalia.com>
00017  */
00018 
00049 #include <glib/gi18n.h>
00050 
00051 #include "unity-quicklist-accessible.h"
00052 #include "unity-quicklist-menu-accessible.h"
00053 
00054 #include "unitya11y.h"
00055 #include "Launcher.h" /*without this I get a error with the following include*/
00056 #include "QuicklistView.h"
00057 
00058 /* GObject */
00059 static void unity_quicklist_accessible_class_init(UnityQuicklistAccessibleClass* klass);
00060 static void unity_quicklist_accessible_init(UnityQuicklistAccessible* self);
00061 
00062 /* AtkObject.h */
00063 static void         unity_quicklist_accessible_initialize(AtkObject* accessible,
00064                                                           gpointer   data);
00065 static gint         unity_quicklist_accessible_get_n_children(AtkObject* obj);
00066 static AtkObject*   unity_quicklist_accessible_ref_child(AtkObject* obj,
00067                                                          gint i);
00068 
00069 G_DEFINE_TYPE(UnityQuicklistAccessible, unity_quicklist_accessible,  NUX_TYPE_BASE_WINDOW_ACCESSIBLE);
00070 
00071 
00072 #define UNITY_QUICKLIST_ACCESSIBLE_GET_PRIVATE(obj)                      \
00073   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), UNITY_TYPE_QUICKLIST_ACCESSIBLE,  \
00074                                 UnityQuicklistAccessiblePrivate))
00075 
00076 struct _UnityQuicklistAccessiblePrivate
00077 {
00078   AtkObject* menu_accessible;
00079 };
00080 
00081 using unity::QuicklistView;
00082 
00083 static void
00084 unity_quicklist_accessible_class_init(UnityQuicklistAccessibleClass* klass)
00085 {
00086   GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
00087   AtkObjectClass* atk_class = ATK_OBJECT_CLASS(klass);
00088 
00089   /* AtkObject */
00090   atk_class->initialize = unity_quicklist_accessible_initialize;
00091   atk_class->get_n_children = unity_quicklist_accessible_get_n_children;
00092   atk_class->ref_child = unity_quicklist_accessible_ref_child;
00093 
00094   g_type_class_add_private(gobject_class, sizeof(UnityQuicklistAccessiblePrivate));
00095 }
00096 
00097 static void
00098 unity_quicklist_accessible_init(UnityQuicklistAccessible* self)
00099 {
00100   UnityQuicklistAccessiblePrivate* priv =
00101     UNITY_QUICKLIST_ACCESSIBLE_GET_PRIVATE(self);
00102 
00103   self->priv = priv;
00104   priv->menu_accessible = NULL;
00105 }
00106 
00107 AtkObject*
00108 unity_quicklist_accessible_new(nux::Object* object)
00109 {
00110   AtkObject* accessible = NULL;
00111 
00112   g_return_val_if_fail(dynamic_cast<QuicklistView*>(object), NULL);
00113 
00114   accessible = ATK_OBJECT(g_object_new(UNITY_TYPE_QUICKLIST_ACCESSIBLE, NULL));
00115 
00116   atk_object_initialize(accessible, object);
00117 
00118   return accessible;
00119 }
00120 
00121 /* AtkObject.h */
00122 static void
00123 unity_quicklist_accessible_initialize(AtkObject* accessible,
00124                                       gpointer data)
00125 {
00126   nux::Object* nux_object = NULL;
00127   QuicklistView* quicklist = NULL;
00128 
00129   ATK_OBJECT_CLASS(unity_quicklist_accessible_parent_class)->initialize(accessible, data);
00130 
00131   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(accessible));
00132   quicklist = dynamic_cast<QuicklistView*>(nux_object);
00133 
00134   if (quicklist == NULL) /* status defunct */
00135     return;
00136 }
00137 
00138 static gint
00139 unity_quicklist_accessible_get_n_children(AtkObject* obj)
00140 {
00141   QuicklistView* quicklist = NULL;
00142   nux::Object* nux_object = NULL;
00143 
00144   g_return_val_if_fail(UNITY_IS_QUICKLIST_ACCESSIBLE(obj), 0);
00145 
00146   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj));
00147   quicklist = dynamic_cast<QuicklistView*>(nux_object);
00148 
00149   if (quicklist == NULL)
00150     return 0;
00151   else
00152     return 1;
00153 }
00154 
00155 static AtkObject*
00156 unity_quicklist_accessible_ref_child(AtkObject* obj,
00157                                      gint i)
00158 {
00159   UnityQuicklistAccessible* self = NULL;
00160   QuicklistView* quicklist = NULL;
00161   nux::Object* nux_object = NULL;
00162 
00163   g_return_val_if_fail(UNITY_IS_QUICKLIST_ACCESSIBLE(obj), NULL);
00164   self = UNITY_QUICKLIST_ACCESSIBLE(obj);
00165 
00166   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj));
00167   quicklist = dynamic_cast<QuicklistView*>(nux_object);
00168   if (quicklist == NULL)
00169     return NULL;
00170 
00171   if (self->priv->menu_accessible == NULL)
00172   {
00173     self->priv->menu_accessible = unity_quicklist_menu_accessible_new(quicklist);
00174     atk_object_set_parent(self->priv->menu_accessible, ATK_OBJECT(self));
00175   }
00176 
00177   g_object_ref(self->priv->menu_accessible);
00178 
00179   return self->priv->menu_accessible;
00180 }