Back to index

unity  6.0.0
nux-text-entry-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 "nux-text-entry-accessible.h"
00034 
00035 #include "unitya11y.h"
00036 #include <Nux/TextEntry.h>
00037 
00038 /* GObject */
00039 static void nux_text_entry_accessible_class_init(NuxTextEntryAccessibleClass* klass);
00040 static void nux_text_entry_accessible_init(NuxTextEntryAccessible* self);
00041 
00042 /* AtkObject.h */
00043 static void         nux_text_entry_accessible_initialize(AtkObject* accessible,
00044                                                          gpointer   data);
00045 static AtkStateSet* nux_text_entry_accessible_ref_state_set(AtkObject* obj);
00046 
00047 /* Fixme: it should implement AtkText/AtkTextEditable interfaces */
00048 G_DEFINE_TYPE(NuxTextEntryAccessible, nux_text_entry_accessible,  NUX_TYPE_VIEW_ACCESSIBLE);
00049 
00050 
00051 #define NUX_TEXT_ENTRY_ACCESSIBLE_GET_PRIVATE(obj)                      \
00052   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NUX_TYPE_TEXT_ENTRY_ACCESSIBLE,  \
00053                                 NuxTextEntryAccessiblePrivate))
00054 
00055 struct _NuxTextEntryAccessiblePrivate
00056 {
00057 };
00058 
00059 
00060 static void
00061 nux_text_entry_accessible_class_init(NuxTextEntryAccessibleClass* klass)
00062 {
00063   GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
00064   AtkObjectClass* atk_class = ATK_OBJECT_CLASS(klass);
00065 
00066   /* AtkObject */
00067   atk_class->ref_state_set = nux_text_entry_accessible_ref_state_set;
00068   atk_class->initialize = nux_text_entry_accessible_initialize;
00069 
00070   g_type_class_add_private(gobject_class, sizeof(NuxTextEntryAccessiblePrivate));
00071 }
00072 
00073 static void
00074 nux_text_entry_accessible_init(NuxTextEntryAccessible* self)
00075 {
00076   NuxTextEntryAccessiblePrivate* priv =
00077     NUX_TEXT_ENTRY_ACCESSIBLE_GET_PRIVATE(self);
00078 
00079   self->priv = priv;
00080 }
00081 
00082 AtkObject*
00083 nux_text_entry_accessible_new(nux::Object* object)
00084 {
00085   AtkObject* accessible = NULL;
00086 
00087   g_return_val_if_fail(dynamic_cast<nux::TextEntry*>(object), NULL);
00088 
00089   accessible = ATK_OBJECT(g_object_new(NUX_TYPE_TEXT_ENTRY_ACCESSIBLE, NULL));
00090 
00091   atk_object_initialize(accessible, object);
00092 
00093   return accessible;
00094 }
00095 
00096 /* AtkObject.h */
00097 static void
00098 nux_text_entry_accessible_initialize(AtkObject* accessible,
00099                                      gpointer data)
00100 {
00101   ATK_OBJECT_CLASS(nux_text_entry_accessible_parent_class)->initialize(accessible, data);
00102 
00103   atk_object_set_role(accessible, ATK_ROLE_ENTRY);
00104 }
00105 
00106 static AtkStateSet*
00107 nux_text_entry_accessible_ref_state_set(AtkObject* obj)
00108 {
00109   AtkStateSet* state_set = NULL;
00110   nux::Object* nux_object = NULL;
00111 
00112   g_return_val_if_fail(NUX_IS_TEXT_ENTRY_ACCESSIBLE(obj), NULL);
00113 
00114   state_set = ATK_OBJECT_CLASS(nux_text_entry_accessible_parent_class)->ref_state_set(obj);
00115 
00116   nux_object = nux_object_accessible_get_object(NUX_OBJECT_ACCESSIBLE(obj));
00117   if (nux_object == NULL) /* defunct */
00118     return state_set;
00119 
00120   /* Text entry is editable by default */
00121   atk_state_set_add_state(state_set, ATK_STATE_EDITABLE);
00122 
00123   return state_set;
00124 }