Back to index

unity  6.0.0
nux-object-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 "nux-object-accessible.h"
00032 
00033 #include <sigc++/connection.h>
00034 
00035 /* GObject */
00036 static void nux_object_accessible_class_init(NuxObjectAccessibleClass* klass);
00037 static void nux_object_accessible_init(NuxObjectAccessible* object_accessible);
00038 static void nux_object_accessible_finalize(GObject* object);
00039 
00040 /* AtkObject.h */
00041 static void       nux_object_accessible_initialize(AtkObject* accessible,
00042                                                    gpointer   data);
00043 static AtkStateSet* nux_object_accessible_ref_state_set(AtkObject* accessible);
00044 
00045 /* Private methods */
00046 static void       on_object_destroy_cb(nux::Object* base_object,
00047                                        NuxObjectAccessible* object_accessible);
00048 
00049 
00050 #define NUX_OBJECT_ACCESSIBLE_GET_PRIVATE(obj) \
00051   (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NUX_TYPE_OBJECT_ACCESSIBLE, NuxObjectAccessiblePrivate))
00052 
00053 G_DEFINE_TYPE(NuxObjectAccessible, nux_object_accessible,  ATK_TYPE_OBJECT)
00054 
00055 struct _NuxObjectAccessiblePrivate
00056 {
00057   nux::Object* object;
00058   sigc::connection on_destroyed_connection;
00059 };
00060 
00061 static void
00062 nux_object_accessible_class_init(NuxObjectAccessibleClass* klass)
00063 {
00064   GObjectClass* gobject_class = G_OBJECT_CLASS(klass);
00065   AtkObjectClass* atk_class = ATK_OBJECT_CLASS(klass);
00066 
00067   gobject_class->finalize = nux_object_accessible_finalize;
00068 
00069   /* AtkObject */
00070   atk_class->initialize = nux_object_accessible_initialize;
00071   atk_class->ref_state_set = nux_object_accessible_ref_state_set;
00072 
00073   g_type_class_add_private(gobject_class, sizeof(NuxObjectAccessiblePrivate));
00074 }
00075 
00076 static void
00077 nux_object_accessible_init(NuxObjectAccessible* object_accessible)
00078 {
00079   object_accessible->priv = NUX_OBJECT_ACCESSIBLE_GET_PRIVATE(object_accessible);
00080 
00081   object_accessible->priv->object = NULL;
00082 }
00083 
00084 AtkObject*
00085 nux_object_accessible_new(nux::Object* object)
00086 {
00087   AtkObject* accessible = NULL;
00088 
00089   g_return_val_if_fail(dynamic_cast<nux::Object*>(object), NULL);
00090 
00091   accessible = ATK_OBJECT(g_object_new(NUX_TYPE_OBJECT_ACCESSIBLE, NULL));
00092 
00093   atk_object_initialize(accessible, object);
00094 
00095   return accessible;
00096 }
00097 
00098 static void
00099 nux_object_accessible_finalize(GObject* object)
00100 {
00101   NuxObjectAccessible* self = NUX_OBJECT_ACCESSIBLE(object);
00102 
00103   self->priv->on_destroyed_connection.disconnect();
00104 
00105   G_OBJECT_CLASS(nux_object_accessible_parent_class)->finalize(object);
00106 }
00107 
00108 /* AtkObject.h */
00109 static void
00110 nux_object_accessible_initialize(AtkObject* accessible,
00111                                  gpointer data)
00112 {
00113   NuxObjectAccessible* self = NULL;
00114   nux::Object* object = NULL;
00115 
00116   ATK_OBJECT_CLASS(nux_object_accessible_parent_class)->initialize(accessible, data);
00117 
00118   self = NUX_OBJECT_ACCESSIBLE(accessible);
00119   object = (nux::Object*) data;
00120 
00121   self->priv->object = object;
00122 
00123   self->priv->on_destroyed_connection =
00124     object->OnDestroyed.connect(sigc::bind(sigc::ptr_fun(on_object_destroy_cb), self));
00125 
00126   accessible->role = ATK_ROLE_UNKNOWN;
00127 }
00128 
00139 nux::Object*
00140 nux_object_accessible_get_object(NuxObjectAccessible* self)
00141 {
00142   return self->priv->object;
00143 }
00144 
00145 static AtkStateSet*
00146 nux_object_accessible_ref_state_set(AtkObject* obj)
00147 {
00148   AtkStateSet* state_set = NULL;
00149 
00150   g_return_val_if_fail(NUX_IS_OBJECT_ACCESSIBLE(obj), NULL);
00151 
00152   state_set = ATK_OBJECT_CLASS(nux_object_accessible_parent_class)->ref_state_set(obj);
00153 
00154   if (NUX_OBJECT_ACCESSIBLE(obj)->priv->object == NULL)
00155     atk_state_set_add_state(state_set, ATK_STATE_DEFUNCT);
00156 
00157   return state_set;
00158 }
00159 
00160 /* Private methods */
00161 static void
00162 on_object_destroy_cb(nux::Object* base_object,
00163                      NuxObjectAccessible* object_accessible)
00164 {
00165   object_accessible->priv->object = NULL;
00166   object_accessible->priv->on_destroyed_connection.disconnect();
00167   atk_object_notify_state_change(ATK_OBJECT(object_accessible), ATK_STATE_DEFUNCT,
00168                                  TRUE);
00169 }