Back to index

unity  6.0.0
unity-search-bar-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-search-bar-accessible.h"
00034 
00035 #include "unitya11y.h"
00036 #include "SearchBar.h"
00037 
00038 using namespace unity;
00039 
00040 /* GObject */
00041 static void unity_search_bar_accessible_class_init(UnitySearchBarAccessibleClass* klass);
00042 static void unity_search_bar_accessible_init(UnitySearchBarAccessible* self);
00043 static void unity_search_bar_accessible_finalize(GObject* object);
00044 
00045 /* AtkObject.h */
00046 static void       unity_search_bar_accessible_initialize(AtkObject* accessible,
00047                                                          gpointer   data);
00048 
00049 G_DEFINE_TYPE(UnitySearchBarAccessible, unity_search_bar_accessible,  NUX_TYPE_VIEW_ACCESSIBLE)
00050 
00051 #define UNITY_SEARCH_BAR_ACCESSIBLE_GET_PRIVATE(obj)                      \
00052   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), UNITY_TYPE_SEARCH_BAR_ACCESSIBLE,  \
00053                                 UnitySearchBarAccessiblePrivate))
00054 
00055 struct _UnitySearchBarAccessiblePrivate
00056 {
00057 
00058 };
00059 
00060 
00061 static void
00062 unity_search_bar_accessible_class_init(UnitySearchBarAccessibleClass* klass)
00063 {
00064   GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
00065   AtkObjectClass* atk_class = ATK_OBJECT_CLASS(klass);
00066 
00067   gobject_class->finalize = unity_search_bar_accessible_finalize;
00068 
00069   /* AtkObject */
00070   atk_class->initialize = unity_search_bar_accessible_initialize;
00071 
00072   g_type_class_add_private(gobject_class, sizeof(UnitySearchBarAccessiblePrivate));
00073 }
00074 
00075 static void
00076 unity_search_bar_accessible_init(UnitySearchBarAccessible* self)
00077 {
00078   UnitySearchBarAccessiblePrivate* priv =
00079     UNITY_SEARCH_BAR_ACCESSIBLE_GET_PRIVATE(self);
00080 
00081   self->priv = priv;
00082 }
00083 
00084 static void
00085 unity_search_bar_accessible_finalize(GObject* object)
00086 {
00087   G_OBJECT_CLASS(unity_search_bar_accessible_parent_class)->finalize(object);
00088 }
00089 
00090 AtkObject*
00091 unity_search_bar_accessible_new(nux::Object* object)
00092 {
00093   AtkObject* accessible = NULL;
00094 
00095   g_return_val_if_fail(dynamic_cast<SearchBar*>(object), NULL);
00096 
00097   accessible = ATK_OBJECT(g_object_new(UNITY_TYPE_SEARCH_BAR_ACCESSIBLE, NULL));
00098 
00099   atk_object_initialize(accessible, object);
00100 
00101   return accessible;
00102 }
00103 
00104 /* AtkObject.h */
00105 static void
00106 on_search_hint_change_cb(std::string const& s, UnitySearchBarAccessible* self)
00107 {
00108   SearchBar* search_bar = NULL;
00109   nux::TextEntry* text_entry = NULL;
00110   AtkObject* text_entry_accessible = NULL;
00111   nux::Object* nux_object = NULL;
00112 
00113   g_return_if_fail(UNITY_IS_SEARCH_BAR_ACCESSIBLE(self));
00114 
00115   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(self));
00116   search_bar = dynamic_cast<SearchBar*>(nux_object);
00117 
00118   if (search_bar == NULL) /* state defunct */
00119     return;
00120 
00121   text_entry = search_bar->text_entry();
00122 
00123   if (text_entry != NULL)
00124   {
00125     text_entry_accessible = unity_a11y_get_accessible(text_entry);
00126     atk_object_set_name(text_entry_accessible, s.c_str());
00127   }
00128 }
00129 
00130 
00131 static void
00132 unity_search_bar_accessible_initialize(AtkObject* accessible,
00133                                        gpointer data)
00134 {
00135   nux::Object* nux_object = NULL;
00136   SearchBar* search_bar = NULL;
00137   // nux::TextEntry* text_entry = NULL;
00138 
00139   ATK_OBJECT_CLASS(unity_search_bar_accessible_parent_class)->initialize(accessible, data);
00140 
00141   accessible->role = ATK_ROLE_PANEL;
00142 
00143   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(accessible));
00144   search_bar = dynamic_cast<SearchBar*>(nux_object);
00145 
00146   if (search_bar == NULL)
00147     return;
00148 
00149   search_bar->search_hint.changed.connect(sigc::bind(sigc::ptr_fun(on_search_hint_change_cb),
00150                                                      UNITY_SEARCH_BAR_ACCESSIBLE(accessible)));
00151 }