Back to index

unity  6.0.0
unity-places-group-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 
00031 #include <glib/gi18n.h>
00032 
00033 #include "unity-places-group-accessible.h"
00034 
00035 #include "unitya11y.h"
00036 #include "PlacesGroup.h"
00037 
00038 /* GObject */
00039 static void unity_places_group_accessible_class_init(UnityPlacesGroupAccessibleClass* klass);
00040 static void unity_places_group_accessible_init(UnityPlacesGroupAccessible* self);
00041 
00042 /* AtkObject.h */
00043 static void         unity_places_group_accessible_initialize(AtkObject* accessible,
00044                                                              gpointer   data);
00045 
00046 G_DEFINE_TYPE(UnityPlacesGroupAccessible, unity_places_group_accessible,  NUX_TYPE_VIEW_ACCESSIBLE);
00047 
00048 
00049 #define UNITY_PLACES_GROUP_ACCESSIBLE_GET_PRIVATE(obj)            \
00050   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), UNITY_TYPE_PLACES_GROUP_ACCESSIBLE, \
00051                                 UnityPlacesGroupAccessiblePrivate))
00052 
00053 struct _UnityPlacesGroupAccessiblePrivate
00054 {
00055   gchar* stripped_name;
00056 };
00057 
00058 
00059 static void
00060 unity_places_group_accessible_class_init(UnityPlacesGroupAccessibleClass* klass)
00061 {
00062   GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
00063   AtkObjectClass* atk_class = ATK_OBJECT_CLASS(klass);
00064 
00065   /* AtkObject */
00066   atk_class->initialize = unity_places_group_accessible_initialize;
00067 
00068   g_type_class_add_private(gobject_class, sizeof(UnityPlacesGroupAccessiblePrivate));
00069 }
00070 
00071 static void
00072 unity_places_group_accessible_init(UnityPlacesGroupAccessible* self)
00073 {
00074   UnityPlacesGroupAccessiblePrivate* priv =
00075     UNITY_PLACES_GROUP_ACCESSIBLE_GET_PRIVATE(self);
00076 
00077   self->priv = priv;
00078   priv->stripped_name = NULL;
00079 }
00080 
00081 AtkObject*
00082 unity_places_group_accessible_new(nux::Object* object)
00083 {
00084   AtkObject* accessible = NULL;
00085 
00086   g_return_val_if_fail(dynamic_cast<unity::PlacesGroup*>(object), NULL);
00087 
00088   accessible = ATK_OBJECT(g_object_new(UNITY_TYPE_PLACES_GROUP_ACCESSIBLE, NULL));
00089 
00090   atk_object_initialize(accessible, object);
00091 
00092   return accessible;
00093 }
00094 
00095 /* AtkObject.h */
00096 /* expand label are usually focused during the key nav, but it don't
00097  * get a proper name always. In those cases we use the label.
00098  *
00099  * In the same way, it is possible that the PlacesGroup get focused
00100  * so we also set the own name with this label
00101  */
00102 static void
00103 ensure_proper_name(UnityPlacesGroupAccessible* self)
00104 {
00105   unity::PlacesGroup* group = NULL;
00106   nux::Object* nux_object = NULL;
00107   nux::StaticCairoText* label = NULL;
00108   nux::StaticCairoText* expand_label = NULL;
00109   AtkObject* label_accessible = NULL;
00110   AtkObject* expand_label_accessible = NULL;
00111 
00112   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(self));
00113   group = dynamic_cast<unity::PlacesGroup*>(nux_object);
00114 
00115   if (group == NULL)
00116     return;
00117 
00118   label = group->GetLabel();
00119   expand_label = group->GetExpandLabel();
00120 
00121 
00122   label_accessible = unity_a11y_get_accessible(label);
00123   expand_label_accessible = unity_a11y_get_accessible(expand_label);
00124 
00125   if ((label_accessible == NULL) || (expand_label_accessible == NULL))
00126     return;
00127 
00128   atk_object_set_name(ATK_OBJECT(self), atk_object_get_name(label_accessible));
00129 
00130   if (expand_label->GetText() == "")
00131     atk_object_set_name(expand_label_accessible, atk_object_get_name(label_accessible));
00132 }
00133 
00134 
00135 static void
00136 on_label_text_change_cb(nux::StaticCairoText* label, UnityPlacesGroupAccessible* self)
00137 {
00138   ensure_proper_name(self);
00139 }
00140 
00141 static void
00142 unity_places_group_accessible_initialize(AtkObject* accessible,
00143                                          gpointer data)
00144 {
00145   unity::PlacesGroup* group = NULL;
00146   nux::Object* nux_object = NULL;
00147   nux::StaticCairoText* label = NULL;
00148 
00149   ATK_OBJECT_CLASS(unity_places_group_accessible_parent_class)->initialize(accessible, data);
00150 
00151   atk_object_set_role(accessible, ATK_ROLE_PANEL);
00152 
00153   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(accessible));
00154   group = dynamic_cast<unity::PlacesGroup*>(nux_object);
00155 
00156   if (group == NULL)
00157     return;
00158 
00159   label = group->GetLabel();
00160 
00161   if (label == NULL)
00162     return;
00163 
00164   ensure_proper_name(UNITY_PLACES_GROUP_ACCESSIBLE(accessible));
00165   label->sigTextChanged.connect(sigc::bind(sigc::ptr_fun(on_label_text_change_cb),
00166                                            UNITY_PLACES_GROUP_ACCESSIBLE(accessible)));
00167 }
00168