Convert uses of XKeycodeToKeysym (deprecated) to XkbKeycodeToKeysym
[oweals/cde.git] / cde / lib / DtSvc / DtEncap / scoop.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /*
24  * File:         scoop.c $XConsortium: scoop.c /main/3 1995/10/26 15:38:19 rswiston $
25  * Language:     C
26  *
27  * (c) Copyright 1988, Hewlett-Packard Company, all rights reserved.
28  *
29  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
30  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
31  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
32  * (c) Copyright 1993, 1994 Novell, Inc.                                *
33  */
34
35 #include <bms/sbport.h>  /* This must be the first file included */
36 #include <bms/scoop.h>
37
38 static void system_class_init (object_clasp to_do, object_clasp on_behalf_of);
39 static void system_object_init (object_clasp c, object *p);
40 static void root_class_init (object_clasp c);
41 static void root_object_init (object *p);
42 static object *root_clone (object *this_ptr, object *clone);
43 static object *root_new (object_clasp c);
44 static void root_free (object *p);
45      
46 /*--------------------------------------------------------------------------+*/
47 void object_destroy (object *p)
48 /*--------------------------------------------------------------------------+*/
49 {
50   memf (p->, free_obj, (p)) ;
51 }
52
53 /*--------------------------------------------------------------------------+*/
54 object *object_create (object_clasp c)
55 /*--------------------------------------------------------------------------+*/
56 {
57   object *p ;
58   
59   if (! c->init) { system_class_init (c, c) ; }
60   p = (*(c->new_obj))(c) ;
61   if (p)
62      object_init (c, p) ;
63   return p ;
64 }
65      
66 /*--------------------------------------------------------------------------+*/
67 void object_init (object_clasp c,  object *p)
68 /*--------------------------------------------------------------------------+*/
69 {
70   if (! c->init) { system_class_init (c, c) ; }
71   p->class_ptr = c ;
72   system_object_init (c, p) ;
73   }
74   
75 /*--------------------------------------------------------------------------+*/
76 static void system_class_init (object_clasp to_do, object_clasp on_behalf_of)
77 /*--------------------------------------------------------------------------+*/
78 {
79   object_clasp base ;
80
81   if ( on_behalf_of && to_do && ! on_behalf_of->init )
82     { }
83   else
84     return ;
85
86   if (to_do == on_behalf_of && to_do != root_class)
87     { on_behalf_of->base =  *((object_clasp *) (on_behalf_of->base)) ;
88     } ;
89   base = to_do->base ;
90   system_class_init (base, base) ;
91   system_class_init (base, on_behalf_of) ;
92
93   if (to_do == on_behalf_of)
94     { to_do->object_init = root_object_init ;
95       to_do->new_obj = root_new ;
96       to_do->free_obj = root_free ;
97     } ;
98
99 #ifdef GLSDEBUG
100   printf ("-> '%s' class for '%s'\n",
101                 to_do->name, on_behalf_of->name) ;
102 #endif /* GLSDEBUG */
103
104   (*(to_do->class_init))(on_behalf_of);
105   if (to_do == on_behalf_of) on_behalf_of->init = TRUE ;
106   }
107   
108 /*--------------------------------------------------------------------------+*/
109 static void system_object_init (object_clasp c, object *p)
110 /*--------------------------------------------------------------------------+*/
111
112   if (!c) return ;
113   
114 #ifdef GLSDEBUG
115   printf ("   '%s' object for '%s'\n", c->name, p->class_ptr->name) ;
116 #endif /* GLSDEBUG */
117   
118   system_object_init (c->base, p) ;
119   
120 #ifdef GLSDEBUG
121   printf ("-> '%s' object for '%s'\n", c->name, p->class_ptr->name) ;
122 #endif /* GLSDEBUG */
123   
124   (*(c->object_init))(p) ;
125 }
126
127 /*--------------------------------------------------------------------------+*/
128 static void root_class_init (object_clasp c)
129 /*--------------------------------------------------------------------------+*/
130 {
131   c->clone = root_clone ;
132 }
133
134 /*--------------------------------------------------------------------------+*/
135 static void root_object_init (object * UNUSED_PARM(p))
136 /*--------------------------------------------------------------------------+*/
137 {
138 }
139
140 /*
141   The clone (second) argument to the clone method may be either NULL or an
142   object pointer.  If NULL, a space of the size necessary for an object of
143   the same class as the primary object (this) will be allocated.  If the
144   input argument is not null, it is assumed that the caller has verified
145   there is sufficient space for a copy of the original object.
146      If the clone procedure does allocate the space for the clone, it only
147   allocates the space.  It does not do object initialization.
148   */
149 /*--------------------------------------------------------------------------+*/
150 static object *root_clone (object *this_ptr, object *clone)
151 /*--------------------------------------------------------------------------+*/
152 {
153   XeString orig = (XeString) this_ptr ;
154   XeString copy ;
155   
156   object_clasp o_class =        this_ptr->class_ptr ;
157   OSizeType     size =          o_class->object_size ;
158
159   if ( ! clone )
160     clone = (*(o_class->new_obj))(o_class) ;
161   if (clone) {
162      copy = (XeString) clone ;
163      while (size--)
164         *copy++ = *orig++ ;
165   }
166   return clone ;
167 }
168
169 /*--------------------------------------------------------------------------+*/
170 static object *root_new (object_clasp c)
171 /*--------------------------------------------------------------------------+*/
172 {  object *p = (object *)malloc((unsigned) c->object_size) ;
173    
174    /* Don't use XeMalloc here, we want to be able to grab our Edit */
175    /* widget without the rest of the world being pulled in.        */
176    if (!p) 
177    {
178        fprintf(stderr, "scoop: malloc in root_new failed, out of memory!\n");
179        exit(1);
180    }
181    
182    return p ;
183 }
184
185 /*--------------------------------------------------------------------------+*/
186 static void root_free (object *p)
187 /*--------------------------------------------------------------------------+*/
188 {
189   if (p) free ((char *)p) ;
190 }
191
192 struct root_class root_class_struct = {
193         (object_clasp) NULL,    /* root has no base class */
194         "root",                 /* class name */
195         root_class_init,
196         sizeof (object),
197         0,
198 } ;
199
200 object_clasp root_class = & root_class_struct ;