File: ExtObject.c

package info (click to toggle)
motif 2.3.8-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 36,432 kB
  • sloc: ansic: 452,643; sh: 4,613; makefile: 2,030; yacc: 1,604; lex: 352; cpp: 348
file content (543 lines) | stat: -rw-r--r-- 15,092 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
/* 
 * Motif
 *
 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
 *
 * These libraries and programs are free software; you can
 * redistribute them and/or modify them under the terms of the GNU
 * Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * These libraries and programs are distributed in the hope that
 * they will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 * PURPOSE. See the GNU Lesser General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with these librararies and programs; if not, write
 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
 * Floor, Boston, MA 02110-1301 USA
 */ 
#ifdef REV_INFO
#ifndef lint
static char rcsid[] = "$XConsortium: ExtObject.c /main/13 1995/10/25 20:03:50 cde-sun $"
#endif
#endif

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif


#include <string.h>
#include "BaseClassI.h"
#include "ExtObjectI.h"
#include "SyntheticI.h"
#include "XmI.h"


/********    Static Function Declarations    ********/

static void ClassInitialize(void);
static void ClassPartInitPrehook(WidgetClass c);
static void ClassPartInitPosthook(WidgetClass c);
static void ClassPartInitialize(WidgetClass c);
static void InitializePrehook(Widget req, Widget new_w,
			      ArgList args, Cardinal *num_args);
static void Initialize(Widget req, Widget new_w, 
		       ArgList args, Cardinal *num_args);
static Boolean SetValuesPrehook(Widget req, Widget curr, Widget new_w,
				ArgList args, Cardinal *num_args);
static void GetValuesPrehook(Widget new_w, ArgList args, Cardinal *num_args);
static Boolean SetValues(Widget old, Widget ref, Widget new_w,
			 ArgList args, Cardinal *num_args);
static void GetValuesHook(Widget new_w, ArgList args, Cardinal *num_args);
static void Destroy(Widget wid);
static void UseParent(Widget w, int offset, XrmValue *value);

/********    End Static Function Declarations    ********/

/***************************************************************************
 *
 * ExtObject Resources
 *
 ***************************************************************************/


#define Offset(field)	XtOffsetOf(struct _XmExtRec, ext.field)

static XtResource extResources[] =
{
  {
    XmNlogicalParent, XmCLogicalParent, XmRWidget, 
    sizeof (Widget), Offset (logicalParent),
    XmRCallProc, (XtPointer)UseParent
  },
  {
    XmNextensionType, XmCExtensionType, XmRExtensionType, 
    sizeof (unsigned char), Offset (extensionType),
    XmRImmediate, (XtPointer)XmDEFAULT_EXTENSION
  }
};
#undef Offset

#define XmNUM_ELEMENTS	4
#define XmNUM_BYTES	255

typedef struct _XmExtCache {
  char    data[XmNUM_BYTES];
  Boolean inuse;
} XmExtCache;

typedef union {
  XmExtCache	cache;
  double	force_alignment;
} Aligned_XmExtCache;

static Aligned_XmExtCache extarray[XmNUM_ELEMENTS];


static XmBaseClassExtRec myBaseClassExtRec = {
  NULL,				/* Next extension         */
  NULLQUARK,			/* record type XmQmotif   */
  XmBaseClassExtVersion,	/* version                */
  sizeof(XmBaseClassExtRec),	/* size                   */
  InitializePrehook,		/* initialize prehook     */
  SetValuesPrehook,		/* set_values prehook     */
  NULL,				/* initialize posthook    */
  NULL,				/* set_values posthook    */
  NULL,				/* secondary class        */
  NULL,				/* creation proc          */
  NULL,				/* getSecRes data         */
  { 0 },			/* fast subclass          */
  GetValuesPrehook,		/* get_values prehook     */
  NULL,				/* get_values posthook    */
  ClassPartInitPrehook,		/* class_part_prehook     */
  ClassPartInitPosthook,	/* class_part_posthook    */
  NULL,				/* compiled_ext_resources */   
  NULL,				/* ext_resources       	  */   
  0,				/* resource_count     	  */   
  FALSE				/* use_sub_resources	  */
};

externaldef(xmextclassrec)
XmExtClassRec xmExtClassRec = {
  {	
    (WidgetClass) &objectClassRec,/* superclass 	 */   
    "dynamic",			  /* class_name 	 */   
    sizeof(XmExtRec),	 	  /* size 		 */   
    ClassInitialize, 		  /* Class Initializer 	 */   
    ClassPartInitialize,	  /* class_part_init 	 */ 
    FALSE,			  /* Class init'ed ? 	 */   
    Initialize,			  /* initialize          */   
    NULL,			  /* initialize_notify   */ 
    NULL,			  /* realize             */   
    NULL,			  /* actions             */   
    0,				  /* num_actions         */   
    extResources,		  /* resources           */   
    XtNumber(extResources),	  /* resource_count      */   
    NULLQUARK, 			  /* xrm_class           */   
    FALSE,			  /* compress_motion     */   
    FALSE,			  /* compress_exposure   */   
    FALSE,			  /* compress_enterleave */   
    FALSE,			  /* visible_interest    */   
    Destroy,			  /* destroy             */   
    NULL,			  /* resize              */   
    NULL,			  /* expose              */   
    SetValues,	 		  /* set_values          */   
    NULL,			  /* set_values_hook     */ 
    NULL,			  /* set_values_almost   */ 
    GetValuesHook,		  /* get_values_hook     */ 
    NULL,			  /* accept_focus        */   
    XtVersion, 			  /* intrinsics version  */   
    NULL,			  /* callback offsets    */   
    NULL,			  /* tm_table            */   
    NULL,			  /* query_geometry      */ 
    NULL,			  /* display_accelerator */ 
    (XtPointer)&myBaseClassExtRec /* extension           */ 
  },	
  {
    NULL,			  /* synthetic resources */
    0				  /* num syn resources	 */
  }
};

externaldef(xmextobjectclass) 
WidgetClass xmExtObjectClass = (WidgetClass) (&xmExtClassRec);

/*ARGSUSED*/
static void 
UseParent(Widget w,
	  int offset,		/* unused */
	  XrmValue *value)
{
  value->addr = (XPointer) &(w->core.parent);
}

/************************************************************************
 *
 *  ClassInitialize
 *
 ************************************************************************/

static void 
ClassInitialize(void)
{
  myBaseClassExtRec.record_type = XmQmotif;
}

/************************************************************************
 *
 *  ClassPartInitPrehook
 *
 ************************************************************************/

static void 
ClassPartInitPrehook(WidgetClass c)
{
  XmExtObjectClass wc = (XmExtObjectClass) c;
  
  if ((WidgetClass)wc != xmExtObjectClass)
    {
      XmExtObjectClass sc = (XmExtObjectClass) c->core_class.superclass;
      XmBaseClassExt *scePtr = _XmGetBaseClassExtPtr(sc, XmQmotif);

      /*
       * If our superclass uses subresources, then we need to
       * temporarily fill it's core resource fields so that objectClass
       * classPartInit will be able to find them for merging.  We
       * assume that we only need to set things up for the
       * superclass and not any deeper ancestors.
       */
      if ((*scePtr)->use_sub_resources)
	{
	  sc->object_class.resources = (*scePtr)->compiled_ext_resources;
	  sc->object_class.num_resources = (*scePtr)->num_ext_resources;
	}
    }
}

/************************************************************************
 *
 *  ClassPartInitPosthook
 *
 ************************************************************************/

static void 
ClassPartInitPosthook(WidgetClass c)
{
  XmExtObjectClass wc = (XmExtObjectClass) c;
  XmBaseClassExt  *wcePtr = _XmGetBaseClassExtPtr(wc, XmQmotif);
  
  if ((*wcePtr) && (*wcePtr)->use_sub_resources)
    {
      /*
       * Put our compiled resources back and zero out oject class so
       * it's invisible to object class create processing.
       */
      (*wcePtr)->compiled_ext_resources = wc->object_class.resources;
      (*wcePtr)->num_ext_resources = wc->object_class.num_resources;
    }
}

/************************************************************************
 *
 *  ClassPartInitialize
 *    Set up the inheritance mechanism for the routines exported by
 *    vendorShells class part.
 *
 ************************************************************************/

static void 
ClassPartInitialize(WidgetClass c)
{
  XmExtObjectClass wc = (XmExtObjectClass) c;
  
  if (wc == (XmExtObjectClass)xmExtObjectClass)
    return;

  _XmBuildExtResources(c);
}

/*ARGSUSED*/
static void 
InitializePrehook(Widget req,	/* unused */
		  Widget new_w,
		  ArgList args,
		  Cardinal *num_args)
{
  XmExtObjectClass ec = (XmExtObjectClass) XtClass(new_w);
  XmBaseClassExt  *wcePtr = _XmGetBaseClassExtPtr(ec, XmQmotif);
  
  if ((*wcePtr)->use_sub_resources)
    {
      /*
       * Get a uncompiled resource list to use with XtGetSubresources.
       * We can't do this in ClassPartInitPosthook because Xt doesn't
       * set class_inited at the right place and thereby mishandles
       * the XtGetResourceList call.
       */
      _XmProcessLock();
      if ((*wcePtr)->ext_resources == NULL)
	{
	  ec->object_class.resources = (*wcePtr)->compiled_ext_resources;
	  ec->object_class.num_resources = (*wcePtr)->num_ext_resources;
	  
	  XtGetResourceList((WidgetClass) ec,
			    &((*wcePtr)->ext_resources),
			    &((*wcePtr)->num_ext_resources));
	}

      XtGetSubresources(XtParent(new_w),
			(XtPointer)new_w,
			NULL, NULL,
			(*wcePtr)->ext_resources,
			(*wcePtr)->num_ext_resources,
			args, *num_args);
      _XmProcessUnlock();
    }
}

static void 
Initialize(Widget req,
	   Widget new_w,
	   ArgList args,
	   Cardinal *num_args)
{
  XmExtObject      ne = (XmExtObject) new_w;
  XmExtObjectClass ec = (XmExtObjectClass) XtClass(new_w);
  Widget           resParent = ne->ext.logicalParent;
  XmWidgetExtData  extData;
  XmBaseClassExt  *wcePtr = _XmGetBaseClassExtPtr(ec, XmQmotif);
  
  if (!(*wcePtr)->use_sub_resources)
    {
      if (resParent)
	{
	  extData = (XmWidgetExtData) XtCalloc(1, sizeof(XmWidgetExtDataRec));
	  _XmPushWidgetExtData(resParent, extData, ne->ext.extensionType);
	  
	  extData->widget = new_w;
	  _XmProcessLock();
	  extData->reqWidget = (Widget)
	    _XmExtObjAlloc(XtClass(new_w)->core_class.widget_size);
	  memcpy((char *)extData->reqWidget, (char *)req,
		 XtClass(new_w)->core_class.widget_size);
	  _XmProcessUnlock();
	  
	  /*  Convert the fields from unit values to pixel values  */
	  _XmExtImportArgs(new_w, args, num_args);
	}
    }
}

/*ARGSUSED*/
static Boolean 
SetValuesPrehook(Widget req,	/* unused */
		 Widget curr,	/* unused */
		 Widget new_w,
		 ArgList args,
		 Cardinal *num_args)
{
  XmExtObjectClass ec = (XmExtObjectClass) XtClass(new_w);
  XmBaseClassExt *wcePtr = _XmGetBaseClassExtPtr(ec, XmQmotif);
  
  if ((*wcePtr)->use_sub_resources)
    {
      _XmProcessLock();
      XtSetSubvalues((XtPointer)new_w,
		     (*wcePtr)->ext_resources,
		     (*wcePtr)->num_ext_resources,
		     args, *num_args);
      _XmProcessUnlock();
    }

  return False;
}

static void 
GetValuesPrehook(Widget new_w,
		 ArgList args,
		 Cardinal *num_args)
{
  XmExtObjectClass ec = (XmExtObjectClass) XtClass(new_w);
  XmBaseClassExt *wcePtr = _XmGetBaseClassExtPtr(ec, XmQmotif);
  
  if ((*wcePtr)->use_sub_resources)
    {
      _XmProcessLock();
      XtGetSubvalues((XtPointer)new_w,
		     (*wcePtr)->ext_resources,
		     (*wcePtr)->num_ext_resources,
		     args, *num_args);
      _XmProcessUnlock();
    }
}

/************************************************************************
 *
 *  SetValues
 *
 ************************************************************************/

/*ARGSUSED*/
static Boolean 
SetValues(Widget old,
	  Widget ref,
	  Widget new_w,
	  ArgList args,
	  Cardinal *num_args)
{
  XmExtObject	  ne = (XmExtObject) new_w;
  Widget	  resParent = ne->ext.logicalParent;
  XmWidgetExtData ext = _XmGetWidgetExtData(resParent, ne->ext.extensionType);
  Cardinal	  extSize;

    if(ext == NULL)
    {
#ifdef DEBUG
        XmeWarning(NULL, "_XmGetWidgetExtData() returned NULL pointer.");
#endif    
        return FALSE;
    }
  
  if (resParent)
    {
      _XmProcessLock();
      extSize = XtClass(new_w)->core_class.widget_size;
      
      ext->widget = new_w;
      
      ext->oldWidget = (Widget) _XmExtObjAlloc(extSize);
      memcpy((char *)ext->oldWidget, (char *)old, extSize); 
      
      ext->reqWidget = (Widget) _XmExtObjAlloc(extSize);
      memcpy((char *)ext->reqWidget, (char *)ref, extSize); 
      _XmProcessUnlock();

      /* Convert the necessary fields from unit values to pixel values. */
      _XmExtImportArgs(new_w, args, num_args);
    }

  return FALSE;
}

/************************************************************************
 *
 *  GetValuesHook
 *
 ************************************************************************/

static void 
GetValuesHook(Widget new_w,
	      ArgList args,
	      Cardinal *num_args)
{
  XmExtObject     ne = (XmExtObject) new_w;
  Widget          resParent = ne->ext.logicalParent;
  XmWidgetExtData ext;
  
  if (resParent)
    {
      ext = _XmGetWidgetExtData(resParent, ne->ext.extensionType);
    if(ext == NULL)
    {
#ifdef DEBUG
        XmeWarning(NULL, "_XmGetWidgetExtData() returned NULL pointer.");
#endif    
        return;
    }
      
      ext->widget = new_w;
      
      _XmExtGetValuesHook(new_w, args, num_args);
    }
}

/************************************************************************
 *
 *  Destroy
 *
 ************************************************************************/

static void 
Destroy(Widget wid)
{
  XmExtObject extObj = (XmExtObject) wid;
  Widget      resParent = extObj->ext.logicalParent;
  
  if (resParent)
    {
      XmWidgetExtData extData;
      
      _XmPopWidgetExtData(resParent, &extData, extObj->ext.extensionType);
      
      XtFree((char *) extData);
    }
}

char * 
_XmExtObjAlloc(int size)
{
  register int i;
  
  if (size <= XmNUM_BYTES)
    {
      for (i = 0; i < XmNUM_ELEMENTS; i++)
	if (! extarray[i].cache.inuse)
	  {
	    extarray[i].cache.inuse = TRUE;
	    return extarray[i].cache.data;
	  }
    }
  
  return XtMalloc(size);
}

void 
_XmExtObjFree(XtPointer element)
{
  register int i;
  
  for (i = 0; i < XmNUM_ELEMENTS; i++)
    if (extarray[i].cache.data == (char*)element)
      {
	extarray[i].cache.inuse = FALSE;
	return;
      }
  
  XtFree((char *) element);
}

/**********************************************************************
 *
 *  _XmBuildExtResources
 *	Build up the ext's synthetic 
 *	resource processing list by combining the super classes with 
 *	this class.
 *
 **********************************************************************/

void 
_XmBuildExtResources(WidgetClass c)
{
  XmExtObjectClass wc = (XmExtObjectClass) c;
  XmExtObjectClass sc;

  _XmProcessLock();
  _XmInitializeSyntheticResources(wc->ext_class.syn_resources,
				  wc->ext_class.num_syn_resources);
  
  if (wc != (XmExtObjectClass) xmExtObjectClass)
    {
      sc = (XmExtObjectClass) wc->object_class.superclass;
      
      _XmBuildResources (&(wc->ext_class.syn_resources),
			 &(wc->ext_class.num_syn_resources),
			 sc->ext_class.syn_resources,
			 sc->ext_class.num_syn_resources);
    }
  _XmProcessUnlock();
}