1 /* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */ 2 /* vim:set et sts=4: */ 3 /* ibus - The Input Bus 4 * Copyright (C) 2008-2013 Peng Huang <shawn.p.huang@gmail.com> 5 * Copyright (C) 2008-2013 Red Hat, Inc. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 20 * USA 21 */ 22 23 #if !defined (__IBUS_H_INSIDE__) && !defined (IBUS_COMPILATION) 24 #error "Only <ibus.h> can be included directly" 25 #endif 26 27 #ifndef __IBUS_OBJECT_H_ 28 #define __IBUS_OBJECT_H_ 29 30 /** 31 * SECTION: ibusobject 32 * @short_description: Base object of IBus. 33 * @title: IBusObject 34 * @stability: Stable 35 * 36 * IBusObject is the base object for all objects in IBus. 37 */ 38 39 #include <glib-object.h> 40 #include "ibustypes.h" 41 #include "ibusdebug.h" 42 43 /* 44 * Type macros. 45 */ 46 47 /* define GOBJECT macros */ 48 #define IBUS_TYPE_OBJECT \ 49 (ibus_object_get_type ()) 50 #define IBUS_OBJECT(obj) \ 51 (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_OBJECT, IBusObject)) 52 #define IBUS_OBJECT_CLASS(klass) \ 53 (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_OBJECT, IBusObjectClass)) 54 #define IBUS_IS_OBJECT(obj) \ 55 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_OBJECT)) 56 #define IBUS_IS_OBJECT_CLASS(klass) \ 57 (G_TYPE_CHECK_CLASS_TYPE ((klass), IBUS_TYPE_OBJECT)) 58 #define IBUS_OBJECT_GET_CLASS(obj) \ 59 (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_OBJECT, IBusObjectClass)) 60 61 /** 62 * IBusObjectFlags: 63 * @IBUS_IN_DESTRUCTION: Used in GObjectClass::dispose 64 * @IBUS_DESTROYED: Used during emitting IBusObject::destroy signal. 65 * @IBUS_RESERVED_1: Reserved. 66 * @IBUS_RESERVED_2: Reserved. 67 * 68 * The flags are used internally. 69 */ 70 typedef enum { 71 IBUS_IN_DESTRUCTION = (1 << 0), 72 IBUS_DESTROYED = (1 << 1), 73 IBUS_RESERVED_1 = (1 << 2), 74 IBUS_RESERVED_2 = (1 << 3), 75 } IBusObjectFlags; 76 77 #define IBUS_OBJECT_FLAGS(obj) (IBUS_OBJECT (obj)->flags) 78 #define IBUS_OBJECT_SET_FLAGS(obj,flag) G_STMT_START{ (IBUS_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END 79 #define IBUS_OBJECT_UNSET_FLAGS(obj,flag) G_STMT_START{ (IBUS_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END 80 #define IBUS_OBJECT_IN_DESTRUCTION(obj) (IBUS_OBJECT_FLAGS (obj) & IBUS_IN_DESTRUCTION) 81 #define IBUS_OBJECT_DESTROYED(obj) (IBUS_OBJECT_FLAGS (obj) & IBUS_DESTROYED) 82 83 G_BEGIN_DECLS 84 85 typedef struct _IBusObject IBusObject; 86 typedef struct _IBusObjectClass IBusObjectClass; 87 typedef struct _IBusObjectPrivate IBusObjectPrivate; 88 89 /** 90 * IBusObject: 91 * 92 * All the fields in the <structname>IBusObject</structname> structure are 93 * private to the #IBusObject and should never be accessed directly. 94 */ 95 struct _IBusObject { 96 GInitiallyUnowned parent; 97 /* instance members */ 98 guint32 flags; 99 100 IBusObjectPrivate *priv; 101 }; 102 103 typedef void ( *IBusObjectDestroyFunc) (IBusObject *object); 104 105 struct _IBusObjectClass { 106 GInitiallyUnownedClass parent; 107 108 /* signals */ 109 void (* destroy) (IBusObject *object); 110 111 /*< private >*/ 112 /* padding */ 113 gpointer pdummy[7]; 114 }; 115 116 GType ibus_object_get_type (void); 117 118 /** 119 * ibus_object_new: 120 * 121 * Creates a new #IBusObject. 122 * 123 * Returns: A newly allocated #IBusObject 124 */ 125 IBusObject *ibus_object_new (void); 126 127 /** 128 * ibus_object_destroy: 129 * @object: an #IBusObject to destroy. 130 * 131 * Emit the "destroy" signal notifying all reference holders that they should 132 * release the #IBusObject. 133 * 134 * The memory for the object itself won't be deleted until its reference count 135 * actually drops to 0; ibus_object_destroy merely asks reference holders to 136 * release their references. It does not free the object. 137 */ 138 void ibus_object_destroy (IBusObject *object); 139 140 G_END_DECLS 141 #endif 142 143