1 /*
2  * Motif
3  *
4  * Copyright (c) 1987-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 librararies 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 #ifdef REV_INFO
24 #ifndef lint
25 static char rcsid[] = "$TOG: Screen.c /main/16 1997/06/18 17:41:50 samborn $"
26 #endif
27 #endif
28 
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32 
33 
34 #include <stdio.h>
35 #include <X11/Xatom.h>
36 #include <Xm/Xm.h>		/* To make cpp on Sun happy. CR 5943 */
37 #include <Xm/AtomMgr.h>
38 #include <Xm/DisplayP.h>
39 #include "DragIconI.h"
40 #include "HashI.h"
41 #include "ImageCachI.h"
42 #include "MessagesI.h"
43 #include "RepTypeI.h"
44 #include "ScreenI.h"
45 #include "PixConvI.h"
46 
47 #define DEFAULT_QUAD_WIDTH 10
48 
49 #define RESOURCE_DEFAULT  (-1)
50 
51 #define MESSAGE1	_XmMMsgScreen_0000
52 #define MESSAGE2        _XmMMsgScreen_0001
53 
54 
55 /********    Static Function Declarations    ********/
56 
57 static void ClassPartInitialize(
58                         WidgetClass wc) ;
59 static void ClassInitialize( void ) ;
60 static void GetUnitFromFont(
61                         Display *display,
62                         XFontStruct *fst,
63                         int *ph_unit,
64                         int *pv_unit) ;
65 static void Initialize(
66                         Widget requested_widget,
67                         Widget new_widget,
68                         ArgList args,
69                         Cardinal *num_args) ;
70 static Boolean SetValues(
71                         Widget current,
72                         Widget requested,
73                         Widget new_w,
74                         ArgList args,
75                         Cardinal *num_args) ;
76 static void Destroy(
77                         Widget widget) ;
78 static void InsertChild(
79                         Widget wid) ;
80 static void DeleteChild(
81                         Widget wid) ;
82 static Boolean MatchPixmap(XmHashKey, XmHashKey) ;
83 static XmHashValue HashPixmap(XmHashKey) ;
84 static Boolean FreePixmap(XmHashKey k, XtPointer p, XtPointer client_data) ;
85 
86 /********    End Static Function Declarations    ********/
87 
88 #define Offset(x) (XtOffsetOf(XmScreenRec, x))
89 
90 static XtResource resources[] = {
91     {
92 	XmNdarkThreshold, XmCDarkThreshold, XmRInt,
93 	sizeof(int), Offset(screen.darkThreshold),
94 	XmRImmediate, (XtPointer)NULL,
95     },
96     {
97 	XmNlightThreshold, XmCLightThreshold, XmRInt,
98 	sizeof(int), Offset(screen.lightThreshold),
99 	XmRImmediate, (XtPointer)NULL,
100     },
101     {
102 	XmNforegroundThreshold, XmCForegroundThreshold, XmRInt,
103 	sizeof(int), Offset(screen.foregroundThreshold),
104 	XmRImmediate, (XtPointer)NULL,
105     },
106     {
107 	XmNdefaultNoneCursorIcon, XmCDefaultNoneCursorIcon, XmRWidget,
108 	sizeof(Widget), Offset(screen.defaultNoneCursorIcon),
109 	XmRImmediate, (XtPointer)NULL,
110     },
111     {
112 	XmNdefaultValidCursorIcon, XmCDefaultValidCursorIcon,
113 	XmRWidget, sizeof(Widget), Offset(screen.defaultValidCursorIcon),
114 	XmRImmediate, (XtPointer)NULL,
115     },
116     {
117 	XmNdefaultInvalidCursorIcon, XmCDefaultInvalidCursorIcon, XmRWidget,
118 	sizeof(Widget), Offset(screen.defaultInvalidCursorIcon),
119 	XmRImmediate, (XtPointer)NULL,
120     },
121     {
122 	XmNdefaultMoveCursorIcon, XmCDefaultMoveCursorIcon, XmRWidget,
123 	sizeof(Widget), Offset(screen.defaultMoveCursorIcon),
124 	XmRImmediate, (XtPointer)NULL,
125     },
126     {
127 	XmNdefaultLinkCursorIcon, XmCDefaultLinkCursorIcon,
128 	XmRWidget, sizeof(Widget), Offset(screen.defaultLinkCursorIcon),
129 	XmRImmediate, (XtPointer)NULL,
130     },
131     {
132 	XmNdefaultCopyCursorIcon, XmCDefaultCopyCursorIcon, XmRWidget,
133 	sizeof(Widget), Offset(screen.defaultCopyCursorIcon),
134 	XmRImmediate, (XtPointer)NULL,
135     },
136     {
137 	XmNdefaultSourceCursorIcon, XmCDefaultSourceCursorIcon, XmRWidget,
138 	sizeof(Widget), Offset(screen.defaultSourceCursorIcon),
139 	XmRImmediate, (XtPointer)NULL,
140     },
141     {
142 	XmNmenuCursor, XmCCursor, XmRCursor,
143 	sizeof(Cursor), Offset(screen.menuCursor),
144 	XmRString, "arrow",
145     },
146     {
147 	XmNunpostBehavior, XmCUnpostBehavior, XmRUnpostBehavior,
148 	sizeof(unsigned char), Offset(screen.unpostBehavior),
149 	XmRImmediate, (XtPointer)XmUNPOST_AND_REPLAY,
150     },
151     {
152 	XmNfont, XmCFont, XmRFontStruct,
153 	sizeof(XFontStruct *), Offset(screen.font_struct),
154 	XmRString, XmDEFAULT_FONT,
155     },
156     {
157 	XmNhorizontalFontUnit, XmCHorizontalFontUnit, XmRInt,
158 	sizeof(int), Offset(screen.h_unit),
159 	XmRImmediate, (XtPointer) RESOURCE_DEFAULT,
160     },
161     {
162 	XmNverticalFontUnit, XmCVerticalFontUnit, XmRInt,
163 	sizeof(int), Offset(screen.v_unit),
164 	XmRImmediate, (XtPointer) RESOURCE_DEFAULT,
165     },
166     {
167         XmNmoveOpaque, XmCMoveOpaque, XmRBoolean,
168         sizeof(unsigned char), Offset(screen.moveOpaque),
169         XmRImmediate, (XtPointer) False,
170     },
171     {
172         XmNcolorCalculationProc, XmCColorCalculationProc, XmRProc,
173         sizeof(XtProc), Offset(screen.color_calc_proc),
174         XmRImmediate, (XtPointer) NULL,
175     },
176     {
177         XmNcolorAllocationProc, XmCColorAllocationProc, XmRProc,
178         sizeof(XtProc), Offset(screen.color_alloc_proc),
179         XmRImmediate, (XtPointer) NULL,
180     },
181     {
182         XmNbitmapConversionModel, XmCBitmapConversionModel,
183         XmRBitmapConversionModel,
184         sizeof(XtEnum), Offset(screen.bitmap_conversion_model),
185         XmRImmediate, (XtPointer) XmMATCH_DEPTH,
186     },
187     {
188         XmNuserData, XmCUserData, XmRPointer,
189         sizeof(XtPointer), Offset(screen.user_data),
190         XmRPointer, (XtPointer) NULL
191     },
192     {
193 	XmNinsensitiveStippleBitmap, XmCInsensitiveStippleBitmap,
194 	XmRNoScalingBitmap,
195 	sizeof(Pixmap), Offset(screen.insensitive_stipple_bitmap),
196 	XmRString, XmS50_foreground
197     },
198 #ifdef DEFAULT_GLYPH_PIXMAP
199     {
200         XmNdefaultGlyphPixmap, XmCDefaultGlyphPixmap,
201 	/* if you move this one as a real pixmap,
202 	   change the code in the buttons as well,
203 	   move the copyplane into a copyarea */
204 	XmRBitmap,
205 	sizeof (Pixmap), Offset(screen.default_glyph_pixmap),
206 	XmRImmediate, (XtPointer) XmUNSPECIFIED_PIXMAP
207      },
208 #endif
209 
210 };
211 
212 #undef Offset
213 
214 
215 /***************************************************************************
216  *
217  * Class Record
218  *
219  ***************************************************************************/
220 
221 /***************************************************************************
222  *
223  * Class Record
224  *
225  ***************************************************************************/
226 
227 static XmBaseClassExtRec baseClassExtRec = {
228     NULL,
229     NULLQUARK,
230     XmBaseClassExtVersion,
231     sizeof(XmBaseClassExtRec),
232     NULL,				/* InitializePrehook	*/
233     NULL,				/* SetValuesPrehook	*/
234     NULL,				/* InitializePosthook	*/
235     NULL,				/* SetValuesPosthook	*/
236     NULL,				/* secondaryObjectClass	*/
237     NULL,				/* secondaryCreate	*/
238     NULL,          		        /* getSecRes data	*/
239     { 0 },     			        /* fastSubclass flags	*/
240     NULL,				/* getValuesPrehook	*/
241     NULL,				/* getValuesPosthook	*/
242     NULL,               /* classPartInitPrehook */
243     NULL,               /* classPartInitPosthook*/
244     NULL,               /* ext_resources        */
245     NULL,               /* compiled_ext_resources*/
246     0,                  /* num_ext_resources    */
247     FALSE,              /* use_sub_resources    */
248     NULL,               /* widgetNavigable      */
249     NULL                /* focusChange          */
250 };
251 
252 
253 externaldef(xmscreenclassrec)
254 XmScreenClassRec xmScreenClassRec = {
255     {
256 	(WidgetClass) &coreClassRec, /* superclass		*/
257 	"XmScreen",			/* class_name 		*/
258 	sizeof(XmScreenRec), 		/* size 		*/
259 	ClassInitialize,		/* Class Initializer 	*/
260 	ClassPartInitialize,		/* class_part_init 	*/
261 	FALSE, 				/* Class init'ed ? 	*/
262 	Initialize,		        /* initialize         	*/
263 	NULL, 				/* initialize_notify    */
264 	NULL,	 			/* realize            	*/
265 	NULL,	 			/* actions            	*/
266 	0,				/* num_actions        	*/
267 	resources,			/* resources          	*/
268 	XtNumber(resources),		/* resource_count     	*/
269 	NULLQUARK, 			/* xrm_class          	*/
270 	FALSE, 				/* compress_motion    	*/
271 	FALSE, 				/* compress_exposure  	*/
272 	FALSE, 				/* compress_enterleave	*/
273 	FALSE, 				/* visible_interest   	*/
274 	Destroy,			/* destroy            	*/
275 	NULL,		 		/* resize             	*/
276 	NULL, 				/* expose             	*/
277 	SetValues, 		        /* set_values         	*/
278 	NULL, 				/* set_values_hook      */
279 	NULL,			 	/* set_values_almost    */
280 	NULL,				/* get_values_hook      */
281 	NULL, 				/* accept_focus       	*/
282 	XtVersion, 			/* intrinsics version 	*/
283 	NULL, 				/* callback offsets   	*/
284 	NULL,				/* tm_table           	*/
285 	NULL, 				/* query_geometry       */
286 	NULL, 				/* screen_accelerator  */
287 	(XtPointer)&baseClassExtRec,	/* extension            */
288     },
289     {					/* desktop		*/
290 	NULL,				/* child_class		*/
291 	InsertChild,		        /* insert_child		*/
292 	DeleteChild,		        /* delete_child		*/
293 	NULL,				/* extension		*/
294     },
295     {
296 	NULL,
297     },
298 };
299 
300 externaldef(xmscreenclass) WidgetClass
301       xmScreenClass = (WidgetClass) (&xmScreenClassRec);
302 
303 
304 
305 externaldef(xmscreenquark) XrmQuark	_XmInvalidCursorIconQuark = NULLQUARK;
306 externaldef(xmscreenquark) XrmQuark	_XmValidCursorIconQuark = NULLQUARK;
307 externaldef(xmscreenquark) XrmQuark	_XmNoneCursorIconQuark = NULLQUARK;
308 externaldef(xmscreenquark) XrmQuark	_XmDefaultDragIconQuark = NULLQUARK;
309 externaldef(xmscreenquark) XrmQuark	_XmMoveCursorIconQuark = NULLQUARK;
310 externaldef(xmscreenquark) XrmQuark	_XmCopyCursorIconQuark = NULLQUARK;
311 externaldef(xmscreenquark) XrmQuark	_XmLinkCursorIconQuark = NULLQUARK;
312 
313 static void
ClassInitialize(void)314 ClassInitialize( void )
315 {
316   baseClassExtRec.record_type = XmQmotif;
317 
318   _XmInvalidCursorIconQuark = XrmPermStringToQuark("defaultInvalidCursorIcon");
319   _XmValidCursorIconQuark = XrmPermStringToQuark("defaultValidCursorIcon");
320   _XmNoneCursorIconQuark = XrmPermStringToQuark("defaultNoneCursorIcon");
321   _XmDefaultDragIconQuark = XrmPermStringToQuark("defaultSourceCursorIcon");
322   _XmMoveCursorIconQuark = XrmPermStringToQuark("defaultMoveCursorIcon");
323   _XmCopyCursorIconQuark = XrmPermStringToQuark("defaultCopyCursorIcon");
324   _XmLinkCursorIconQuark = XrmPermStringToQuark("defaultLinkCursorIcon");
325 }
326 
327 
328 static void
ClassPartInitialize(WidgetClass wc)329 ClassPartInitialize(
330 	WidgetClass wc )
331 {
332     _XmFastSubclassInit(wc, XmSCREEN_BIT);
333 
334 }
335 
336 /************************************************************************
337  *
338  *  GetUnitFromFont
339  *
340  ************************************************************************/
341 static void
GetUnitFromFont(Display * display,XFontStruct * fst,int * ph_unit,int * pv_unit)342 GetUnitFromFont(
343 	Display * display,
344 	XFontStruct * fst,
345 	int * ph_unit,
346 	int * pv_unit)
347 {
348     enum { XmAAVERAGE_WIDTH, XmAPIXEL_SIZE, XmARESOLUTION_Y, NUM_ATOMS };
349     static char *atom_names[] = {
350       XmIAVERAGE_WIDTH, XmIPIXEL_SIZE, XmIRESOLUTION_Y };
351     Atom atoms[XtNumber(atom_names)];
352     unsigned long pixel_s, avg_w, point_s, resolution_y;
353     unsigned long font_unit_return;
354 
355     if (fst) {
356       assert(XtNumber(atom_names) == NUM_ATOMS);
357       XInternAtoms(display, atom_names, XtNumber(atom_names), TRUE, atoms);
358 
359               /* Horizontal units */
360       if (ph_unit) {
361 	  if (atoms[XmAAVERAGE_WIDTH] &&
362 	      XGetFontProperty(fst, atoms[XmAAVERAGE_WIDTH], &avg_w)) {
363 	      *ph_unit = (int) ((float) (avg_w / 10) + 0.5) ;
364 	  } else if (XGetFontProperty (fst, XA_QUAD_WIDTH, &font_unit_return)){
365 	      *ph_unit = font_unit_return ;
366 	  } else {
367 	      *ph_unit = (int) ((fst->min_bounds.width +
368 				 fst-> max_bounds.width) / 2.3) + 0.5;
369 	  }
370       }
371 
372               /* Vertical units */
373       if (pv_unit) {
374 	  if (XGetFontProperty(fst, atoms[XmAPIXEL_SIZE], &pixel_s)) {
375 	      *pv_unit = (int) (((float) pixel_s) / 1.8) + 0.5;
376 	  } else if ((XGetFontProperty(fst, XA_POINT_SIZE, &point_s)) &&
377 		     (XGetFontProperty(fst, atoms[XmARESOLUTION_Y],
378 				       &resolution_y))) {
379 	      float ps, ry, tmp;
380 
381 	      ps = point_s;
382 	      ry = resolution_y;
383 
384 	      tmp = (ps * ry) / 1400.0;
385 
386 	      *pv_unit = (int) (tmp + 0.5) ;
387 	  } else {
388 	      *pv_unit = (int) ((float) (fst->max_bounds.ascent +
389 					 fst->max_bounds.descent) / 2.2) + 0.5;
390 	  }
391       }
392 
393     } else {  /* no X fontstruct */
394       if (ph_unit) *ph_unit = DEFAULT_QUAD_WIDTH ;
395       if (pv_unit) *pv_unit = DEFAULT_QUAD_WIDTH ;
396     }
397 
398 }
399 
400 
401 /************************************************************************
402  *
403  *  ScreenInitialize
404  *
405  ************************************************************************/
406 /* ARGSUSED */
407 static void
Initialize(Widget requested_widget,Widget new_widget,ArgList args,Cardinal * num_args)408 Initialize(
409         Widget requested_widget,
410         Widget new_widget,
411         ArgList args,
412         Cardinal *num_args )
413 {
414     XmScreen     xmScreen = (XmScreen)new_widget;
415     Display      *display = XtDisplay(new_widget);
416 
417     xmScreen->screen.screenInfo = NULL;
418 
419     XQueryBestCursor(display,
420 		     RootWindowOfScreen(XtScreen(xmScreen)),
421 		     1024, 1024,
422 		     &xmScreen->screen.maxCursorWidth,
423 		     &xmScreen->screen.maxCursorHeight);
424 
425     xmScreen->screen.nullCursor = None;
426     xmScreen->screen.cursorCache = NULL;
427     xmScreen->screen.scratchPixmaps = (XtPointer)
428       _XmAllocHashTable(20, MatchPixmap, HashPixmap);
429     xmScreen->screen.inUsePixmaps = (XtPointer)
430       _XmAllocHashTable(20, NULL, NULL);
431     xmScreen->screen.xmStateCursorIcon = NULL;
432     xmScreen->screen.xmMoveCursorIcon = NULL;
433     xmScreen->screen.xmCopyCursorIcon = NULL;
434     xmScreen->screen.xmLinkCursorIcon = NULL;
435     xmScreen->screen.xmSourceCursorIcon = NULL;
436     xmScreen->screen.mwmPresent = XmIsMotifWMRunning( new_widget) ;
437     xmScreen->screen.numReparented = 0;
438     xmScreen->desktop.num_children = 0;
439     xmScreen->desktop.children = NULL;
440     xmScreen->desktop.num_slots = 0;
441 
442     if(!XmRepTypeValidValue(XmRID_UNPOST_BEHAVIOR,
443                           xmScreen->screen.unpostBehavior,
444                           new_widget)) {
445       xmScreen->screen.unpostBehavior = XmUNPOST_AND_REPLAY;
446     }
447 
448     /* font unit stuff, priority to actual unit values, if they haven't
449      been set yet, compute from the font, otherwise, stay unchanged */
450 
451     if (xmScreen->screen.h_unit == RESOURCE_DEFAULT)
452 	GetUnitFromFont(display, xmScreen->screen.font_struct,
453 			&xmScreen->screen.h_unit, NULL);
454 
455     if (xmScreen->screen.v_unit == RESOURCE_DEFAULT)
456 	GetUnitFromFont(display, xmScreen->screen.font_struct,
457 			NULL, &xmScreen->screen.v_unit);
458 
459     xmScreen->screen.screenInfo = (XtPointer) XtNew(XmScreenInfo);
460 
461     ((XmScreenInfo *)(xmScreen->screen.screenInfo))->menu_state =
462 		(XtPointer)NULL;
463     ((XmScreenInfo *)(xmScreen->screen.screenInfo))->destroyCallbackAdded =
464 		False;
465 
466 
467 #ifdef DEFAULT_GLYPH_PIXMAP
468     if (xmScreen->screen.default_glyph_pixmap != XmUNSPECIFIED_PIXMAP) {
469 	(void) XmeGetPixmapData(XtScreen(new_widget),
470 			 xmScreen->screen.default_glyph_pixmap,
471 			 NULL, NULL, NULL, NULL, NULL, NULL,
472 			 &(xmScreen->screen.default_glyph_pixmap_width),
473 			 &(xmScreen->screen.default_glyph_pixmap_height));
474     }
475 #endif
476 
477 }
478 
479 /************************************************************************
480  *
481  *  SetValues
482  *
483  ************************************************************************/
484 /* ARGSUSED */
485 static Boolean
SetValues(Widget current,Widget requested,Widget new_w,ArgList args,Cardinal * num_args)486 SetValues(
487         Widget current,
488         Widget requested,
489         Widget new_w,
490         ArgList args,
491         Cardinal *num_args )
492 {
493     XmScreen		newScr = (XmScreen)new_w;
494     XmScreen		oldScr = (XmScreen)current;
495     Display * display = XtDisplay( new_w);
496 
497     if(!XmRepTypeValidValue(XmRID_UNPOST_BEHAVIOR,
498                           newScr->screen.unpostBehavior, new_w)) {
499       newScr->screen.unpostBehavior = XmUNPOST_AND_REPLAY;
500     }
501 
502     /*
503      *  If we are setting a default cursor icon, verify that
504      *  it has the same screen as the new XmScreen.
505      */
506 
507     /* defaultNoneCursorIcon */
508 
509     if (newScr->screen.defaultNoneCursorIcon !=
510 	    oldScr->screen.defaultNoneCursorIcon &&
511 	newScr->screen.defaultNoneCursorIcon != NULL &&
512 	XtScreenOfObject (XtParent (newScr->screen.defaultNoneCursorIcon)) !=
513 	     XtScreen (newScr)) {
514 
515 	XmeWarning( (Widget) new_w, MESSAGE1);
516 	newScr->screen.defaultNoneCursorIcon =
517 	    oldScr->screen.defaultNoneCursorIcon;
518     }
519 
520     /* defaultValidCursorIcon */
521 
522     if (newScr->screen.defaultValidCursorIcon !=
523 	    oldScr->screen.defaultValidCursorIcon &&
524 	newScr->screen.defaultValidCursorIcon != NULL &&
525 	XtScreenOfObject (XtParent (newScr->screen.defaultValidCursorIcon)) !=
526 	     XtScreen (newScr)) {
527 
528 	XmeWarning( (Widget) new_w, MESSAGE1);
529 	newScr->screen.defaultValidCursorIcon =
530 	    oldScr->screen.defaultValidCursorIcon;
531     }
532 
533     /* defaultInvalidCursorIcon */
534 
535     if (newScr->screen.defaultInvalidCursorIcon !=
536 	    oldScr->screen.defaultInvalidCursorIcon &&
537 	newScr->screen.defaultInvalidCursorIcon != NULL &&
538 	XtScreenOfObject (XtParent (newScr->screen.defaultInvalidCursorIcon)) !=
539 	     XtScreen (newScr)) {
540 
541 	XmeWarning( (Widget) new_w, MESSAGE1);
542 	newScr->screen.defaultInvalidCursorIcon =
543 	    oldScr->screen.defaultInvalidCursorIcon;
544     }
545 
546     /* defaultMoveCursorIcon */
547 
548     if (newScr->screen.defaultMoveCursorIcon !=
549 	    oldScr->screen.defaultMoveCursorIcon &&
550 	newScr->screen.defaultMoveCursorIcon != NULL &&
551 	XtScreenOfObject (XtParent (newScr->screen.defaultMoveCursorIcon)) !=
552 	     XtScreen (newScr)) {
553 
554 	XmeWarning( (Widget) new_w, MESSAGE1);
555 	newScr->screen.defaultMoveCursorIcon =
556 	    oldScr->screen.defaultMoveCursorIcon;
557     }
558 
559     /* defaultCopyCursorIcon */
560 
561     if (newScr->screen.defaultCopyCursorIcon !=
562 	    oldScr->screen.defaultCopyCursorIcon &&
563 	newScr->screen.defaultCopyCursorIcon != NULL &&
564 	XtScreenOfObject (XtParent (newScr->screen.defaultCopyCursorIcon)) !=
565 	     XtScreen (newScr)) {
566 
567 	XmeWarning( (Widget) new_w, MESSAGE1);
568 	newScr->screen.defaultCopyCursorIcon =
569 	    oldScr->screen.defaultCopyCursorIcon;
570     }
571 
572     /* defaultLinkCursorIcon */
573 
574     if (newScr->screen.defaultLinkCursorIcon !=
575 	    oldScr->screen.defaultLinkCursorIcon &&
576 	newScr->screen.defaultLinkCursorIcon != NULL &&
577 	XtScreenOfObject (XtParent (newScr->screen.defaultLinkCursorIcon)) !=
578 	     XtScreen (newScr)) {
579 
580 	XmeWarning( (Widget) new_w, MESSAGE1);
581 	newScr->screen.defaultLinkCursorIcon =
582 	    oldScr->screen.defaultLinkCursorIcon;
583     }
584 
585     /* defaultSourceCursorIcon */
586 
587     if (newScr->screen.defaultSourceCursorIcon !=
588 	    oldScr->screen.defaultSourceCursorIcon &&
589 	newScr->screen.defaultSourceCursorIcon != NULL &&
590 	XtScreenOfObject (XtParent (newScr->screen.defaultSourceCursorIcon)) !=
591 	     XtScreen (newScr)) {
592 
593 	XmeWarning( (Widget) new_w, MESSAGE1);
594 	newScr->screen.defaultSourceCursorIcon =
595 	    oldScr->screen.defaultSourceCursorIcon;
596     }
597 
598     /* font unit stuff, priority to actual unit values, if the
599        font has changed but not the unit values, report the change,
600        otherwise, use the unit value - i.e do nothing */
601 
602     if (newScr->screen.font_struct->fid !=
603 	oldScr->screen.font_struct->fid) {
604 
605 	if (newScr->screen.h_unit == oldScr->screen.h_unit) {
606 	    GetUnitFromFont(display, newScr->screen.font_struct,
607 			    &newScr->screen.h_unit, NULL);
608 	}
609 
610 	if (newScr->screen.v_unit == oldScr->screen.v_unit) {
611 	    GetUnitFromFont(display, newScr->screen.font_struct,
612 			    NULL, &newScr->screen.v_unit);
613 	}
614     }
615 
616     return FALSE ;
617 }
618 
619 
620 /************************************************************************
621  *
622  *  Destroy
623  *
624  ************************************************************************/
625 /* ARGSUSED */
626 static void
Destroy(Widget widget)627 Destroy(
628         Widget widget )
629 {
630     XmScreen		xmScreen = (XmScreen)widget;
631     XmDragCursorCache 	prevCache, cache;
632     XmHashTable		tab;
633 
634     /* destroy any default icons created by Xm */
635 
636     if (xmScreen->screen.xmStateCursorIcon != NULL) {
637 	_XmDestroyDefaultDragIcon (xmScreen->screen.xmStateCursorIcon);
638     }
639     if (xmScreen->screen.xmMoveCursorIcon != NULL) {
640 	_XmDestroyDefaultDragIcon (xmScreen->screen.xmMoveCursorIcon);
641     }
642     if (xmScreen->screen.xmCopyCursorIcon != NULL) {
643 	_XmDestroyDefaultDragIcon (xmScreen->screen.xmCopyCursorIcon);
644     }
645     if (xmScreen->screen.xmLinkCursorIcon != NULL) {
646 	_XmDestroyDefaultDragIcon (xmScreen->screen.xmLinkCursorIcon);
647     }
648     if (xmScreen->screen.xmSourceCursorIcon != NULL) {
649 	_XmDestroyDefaultDragIcon (xmScreen->screen.xmSourceCursorIcon);
650     }
651 
652     XtFree((char *) xmScreen->desktop.children);
653 
654     /* free the cursorCache and the pixmapCache */
655     cache = xmScreen->screen.cursorCache;
656     while(cache) {
657 	prevCache = cache;
658 	if (cache->cursor)
659 	  XFreeCursor(XtDisplay(xmScreen), cache->cursor);
660 	cache = cache->next;
661 	XtFree((char *)prevCache);
662     }
663 
664     _XmProcessLock();
665     tab = (XmHashTable) xmScreen->screen.scratchPixmaps;
666     _XmMapHashTable(tab, FreePixmap, xmScreen);
667     _XmFreeHashTable(tab);
668     _XmFreeHashTable((XmHashTable) xmScreen->screen.inUsePixmaps);
669     _XmProcessUnlock();
670 
671     XtFree((char *) xmScreen->screen.screenInfo);
672 
673     /* need to remove pixmap and GC related to this screen */
674     _XmCleanPixmapCache (XtScreen(widget), NULL);
675 }
676 
677 static void
InsertChild(Widget wid)678 InsertChild(
679         Widget wid )
680 {
681     XmDesktopObject w = (XmDesktopObject) wid ;
682     register Cardinal	     	position;
683     register Cardinal        	i;
684     register XmScreen 	cw;
685     register WidgetList      	children;
686 
687     cw = (XmScreen) w->desktop.parent;
688     children = cw->desktop.children;
689 
690     position = cw->desktop.num_children;
691 
692     if (cw->desktop.num_children == cw->desktop.num_slots) {
693 	/* Allocate more space */
694 	cw->desktop.num_slots +=  (cw->desktop.num_slots / 2) + 2;
695 	cw->desktop.children = children =
696 	  (WidgetList) XtRealloc((char *) children,
697 		(unsigned) (cw->desktop.num_slots) * sizeof(Widget));
698     }
699     /* Ripple children up one space from "position" */
700     for (i = cw->desktop.num_children; i > position; i--) {
701 	children[i] = children[i-1];
702     }
703     children[position] = (Widget)w;
704     cw->desktop.num_children++;
705 }
706 
707 static void
DeleteChild(Widget wid)708 DeleteChild(
709         Widget wid )
710 {
711     XmDesktopObject w = (XmDesktopObject) wid ;
712     register Cardinal	     	position;
713     register Cardinal	     	i;
714     register XmScreen 	cw;
715 
716     cw = (XmScreen) w->desktop.parent;
717 
718     for (position = 0; position < cw->desktop.num_children; position++) {
719         if (cw->desktop.children[position] == (Widget)w) {
720 	    break;
721 	}
722     }
723     if (position == cw->desktop.num_children) return;
724 
725     /* Ripple children down one space from "position" */
726     cw->desktop.num_children--;
727     for (i = position; i < cw->desktop.num_children; i++) {
728         cw->desktop.children[i] = cw->desktop.children[i+1];
729     }
730 }
731 
732 /************************************************************************
733  *
734  *  _XmScreenRemoveFromCursorCache
735  *
736  *  Mark any cursor cache reference to the specified icon as deallocated.
737  ************************************************************************/
738 
739 void
_XmScreenRemoveFromCursorCache(XmDragIconObject icon)740 _XmScreenRemoveFromCursorCache(
741     XmDragIconObject	icon )
742 {
743     XmScreen	       xmScreen = (XmScreen) XmGetXmScreen(XtScreen(icon));
744     XmDragCursorCache  ptr = xmScreen->screen.cursorCache;
745     XmDragCursorCache  previous = xmScreen->screen.cursorCache;
746     XmDragCursorCache  next;
747 
748     while (ptr) {
749 	next = ptr->next;
750 
751 	if ((ptr->sourceIcon == icon) ||
752 	    (ptr->stateIcon == icon) ||
753 	    (ptr->opIcon == icon))
754 	  {
755 	    if (ptr->cursor)
756 	      XFreeCursor (XtDisplay(icon), ptr->cursor);
757 
758 	    if ( xmScreen->screen.cursorCache == ptr )
759 		xmScreen->screen.cursorCache = ptr->next;
760 	    else
761 		previous->next = ptr->next;
762 
763 	    XtFree ((char*)ptr);
764 	  }
765 	else
766 	    previous = ptr;
767 
768 	ptr = next;
769     }
770 }
771 
772 static Boolean
FreePixmap(XmHashKey k,XtPointer p,XtPointer client_data)773 FreePixmap(XmHashKey k, XtPointer p, XtPointer client_data)
774 {
775   XmScreen	xmScreen = (XmScreen) client_data;
776 
777   XtFree((char*) k);
778   XFreePixmap(XtDisplay(xmScreen), (Pixmap) p);
779 
780   return False;
781 }
782 
783 
784 
785 /************************************************************************
786  *
787  *  _XmScreenGetOperationIcon ()
788  *
789  *  Returns one of the three XmScreen operation cursor types. These aren't
790  *  created ahead of time in order to let the client specify its own.
791  *  If they haven't by now (a drag is in process) then we create our
792  *  own. The name of the OperatonIcon can cause the built-in cursor data
793  *  to get loaded in (if not specified in the resource file).
794  ************************************************************************/
795 
796 XmDragIconObject
_XmScreenGetOperationIcon(Widget w,unsigned int operation)797 _XmScreenGetOperationIcon(
798         Widget w,
799 #if NeedWidePrototypes
800         unsigned int operation )
801 #else
802         unsigned char operation )
803 #endif /* NeedWidePrototypes */
804 {
805     XmScreen		xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(w));
806     XrmQuark		nameQuark = NULLQUARK;
807     XmDragIconObject	*ptr = NULL;
808     XmDragIconObject	*pt2 = NULL;
809 
810     switch ((int) operation) {
811 	case XmDROP_MOVE:
812 	    ptr = &xmScreen->screen.defaultMoveCursorIcon;
813 	    pt2 = &xmScreen->screen.xmMoveCursorIcon;
814 	    nameQuark = _XmMoveCursorIconQuark;
815 	    break;
816 
817 	case XmDROP_COPY:
818 	    ptr = &xmScreen->screen.defaultCopyCursorIcon;
819 	    pt2 = &xmScreen->screen.xmCopyCursorIcon;
820 	    nameQuark = _XmCopyCursorIconQuark;
821 	    break;
822 
823 	case XmDROP_LINK:
824 	    ptr = &xmScreen->screen.defaultLinkCursorIcon;
825 	    pt2 = &xmScreen->screen.xmLinkCursorIcon;
826 	    nameQuark = _XmLinkCursorIconQuark;
827 	    break;
828 
829 	default:
830 	    return (NULL);
831     }
832     if (*ptr == NULL) {
833 	if (*pt2 == NULL) {
834 	    *pt2 = (XmDragIconObject)
835 	        XmCreateDragIcon ((Widget) xmScreen,
836 			          XrmQuarkToString(nameQuark), NULL, 0);
837 	}
838 	*ptr = *pt2;
839     }
840     return *ptr;
841 }
842 
843 /************************************************************************
844  *
845  *  _XmScreenGetStateIcon ()
846  *
847  *  Returns one of the three XmScreen state cursor types. These aren't
848  *  created ahead of time in order to let the client specify its own.
849  *  If they haven't by now (a drag is in process) then we create our
850  *  own. The name of the StateIcon can cause the built-in cursor data
851  *  to get loaded in (if not specified in the resource file).
852  *  The default state cursors are the same XmDragIcon object.
853  ************************************************************************/
854 
855 XmDragIconObject
_XmScreenGetStateIcon(Widget w,unsigned int state)856 _XmScreenGetStateIcon(
857         Widget w,
858 #if NeedWidePrototypes
859         unsigned int state )
860 #else
861         unsigned char state )
862 #endif /* NeedWidePrototypes */
863 {
864     XmScreen		xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(w));
865     XrmQuark		nameQuark = NULLQUARK;
866     XmDragIconObject	icon = NULL;
867 
868     switch(state) {
869 	default:
870 	case XmNO_DROP_SITE:
871 	    icon = xmScreen->screen.defaultNoneCursorIcon;
872 	    nameQuark = _XmNoneCursorIconQuark;
873 	    break;
874 
875 	case XmVALID_DROP_SITE:
876 	    icon = xmScreen->screen.defaultValidCursorIcon;
877 	    nameQuark = _XmValidCursorIconQuark;
878 	    break;
879 
880 	case XmINVALID_DROP_SITE:
881 	    icon = xmScreen->screen.defaultInvalidCursorIcon;
882 	    nameQuark = _XmInvalidCursorIconQuark;
883 	    break;
884     }
885     if (icon == NULL) {
886 
887 	/*
888 	 *  We need to create the default state icons.
889 	 *  Set all uncreated state icons to the same XmDragIcon object.
890 	 */
891 
892 	if (xmScreen->screen.xmStateCursorIcon == NULL) {
893 	    xmScreen->screen.xmStateCursorIcon = (XmDragIconObject)
894 	        XmCreateDragIcon ((Widget) xmScreen,
895 			          XrmQuarkToString(nameQuark),
896 				  NULL, 0);
897 	}
898 	icon = xmScreen->screen.xmStateCursorIcon;
899 
900 	if (xmScreen->screen.defaultNoneCursorIcon == NULL) {
901 	    xmScreen->screen.defaultNoneCursorIcon = icon;
902 	}
903 	if (xmScreen->screen.defaultValidCursorIcon == NULL) {
904 	    xmScreen->screen.defaultValidCursorIcon = icon;
905 	}
906 	if (xmScreen->screen.defaultInvalidCursorIcon == NULL) {
907 	    xmScreen->screen.defaultInvalidCursorIcon = icon;
908 	}
909     }
910     return (icon);
911 }
912 
913 /************************************************************************
914  *
915  *  _XmScreenGetSourceIcon ()
916  *
917  *  Returns the XmScreen source cursor types.  This isn't created ahead of
918  *  time in order to let the client specify its own.  If it hasn't by now
919  *  (a drag is in process) then we create our own.
920  ************************************************************************/
921 
922 XmDragIconObject
_XmScreenGetSourceIcon(Widget w)923 _XmScreenGetSourceIcon(
924         Widget w )
925 {
926     XmScreen	xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(w));
927 
928     if (xmScreen->screen.defaultSourceCursorIcon == NULL) {
929 
930 	if (xmScreen->screen.xmSourceCursorIcon == NULL) {
931 	    xmScreen->screen.xmSourceCursorIcon = (XmDragIconObject)
932 	        XmCreateDragIcon ((Widget) xmScreen,
933 			          XrmQuarkToString(_XmDefaultDragIconQuark),
934 			          NULL, 0);
935 	}
936 	xmScreen->screen.defaultSourceCursorIcon =
937 	    xmScreen->screen.xmSourceCursorIcon;
938     }
939     return xmScreen->screen.defaultSourceCursorIcon;
940 }
941 
942 /************************************************************************
943  *
944  *  _XmAllocScratchPixmap
945  *
946  ************************************************************************/
947 
948 static Boolean
MatchPixmap(XmHashKey k1,XmHashKey k2)949 MatchPixmap(XmHashKey k1, XmHashKey k2)
950 {
951   XmScratchPixmapKey key1 = (XmScratchPixmapKey) k1;
952   XmScratchPixmapKey key2 = (XmScratchPixmapKey) k2;
953 
954   return(key1 -> height == key2 -> height &&
955 	 key1 -> width == key2 -> width &&
956 	 key1 -> depth == key2 -> depth);
957 }
958 
959 static XmHashValue
HashPixmap(XmHashKey k)960 HashPixmap(XmHashKey k)
961 {
962   XmScratchPixmapKey key = (XmScratchPixmapKey) k;
963 
964   return(key -> height + key -> width + key -> depth);
965 }
966 
967 Pixmap
_XmAllocScratchPixmap(XmScreen xmScreen,unsigned int depth,int width,int height)968 _XmAllocScratchPixmap(
969         XmScreen xmScreen,
970 #if NeedWidePrototypes
971         unsigned int depth,
972         int width,
973         int height )
974 #else
975         Cardinal depth,
976         Dimension width,
977         Dimension height )
978 #endif /* NeedWidePrototypes */
979 {
980     XmHashTable		scratchTable =
981       (XmHashTable) xmScreen->screen.scratchPixmaps;
982     XmHashTable		inUseTable =
983       (XmHashTable) xmScreen->screen.inUsePixmaps;
984     Pixmap		scratchPixmap = None;
985     XmScratchPixmapKeyRec	key;
986     XmScratchPixmapKey	returned_key;
987 
988     key.height = height;
989     key.width = width;
990     key.depth = depth;
991 
992     _XmProcessLock();
993     scratchPixmap = (Pixmap) _XmGetHashEntry(scratchTable, &key);
994 
995     if (scratchPixmap != None) {
996       /* remove from free table */
997       returned_key = (XmScratchPixmapKey)
998 	_XmRemoveHashEntry(scratchTable, &key);
999     } else {
1000       returned_key = XtNew(XmScratchPixmapKeyRec);
1001       returned_key->width = width;
1002       returned_key->height = height;
1003       returned_key->depth = depth;
1004       scratchPixmap = XCreatePixmap (XtDisplay(xmScreen),
1005 				     RootWindowOfScreen(XtScreen(xmScreen)),
1006 				     width, height,
1007 				     depth);
1008     }
1009 
1010     /* Place key in inUse table */
1011     _XmAddHashEntry(inUseTable, (XmHashKey) scratchPixmap, returned_key);
1012 
1013     _XmProcessUnlock();
1014     return(scratchPixmap);
1015 }
1016 
1017 /************************************************************************
1018  *
1019  *  _XmFreeScratchPixmap
1020  *
1021  ************************************************************************/
1022 
1023 void
_XmFreeScratchPixmap(XmScreen xmScreen,Pixmap pixmap)1024 _XmFreeScratchPixmap(
1025         XmScreen xmScreen,
1026         Pixmap pixmap )
1027 {
1028     XmHashTable scratchTable = (XmHashTable) xmScreen->screen.scratchPixmaps;
1029     XmHashTable inUseTable   = (XmHashTable) xmScreen->screen.inUsePixmaps;
1030     XmScratchPixmapKey returned_key;
1031 
1032     _XmProcessLock();
1033     returned_key = (XmScratchPixmapKey)
1034       _XmGetHashEntry(inUseTable, (XmHashKey) pixmap);
1035 
1036     if (returned_key == NULL) {
1037       /* Bad,  this pixmap wasn't in the cache,  return */
1038       _XmProcessUnlock();
1039       return;
1040     }
1041 
1042     _XmRemoveHashEntry(inUseTable, (XmHashKey) pixmap);
1043 
1044     _XmAddHashEntry(scratchTable, returned_key, (XtPointer) pixmap);
1045     _XmProcessUnlock();
1046 }
1047 
1048 
1049 /************************************************************************
1050  *
1051  *  _XmGetDragCursorCachePtr ()
1052  *
1053  ************************************************************************/
1054 
1055 XmDragCursorCache *
_XmGetDragCursorCachePtr(XmScreen xmScreen)1056 _XmGetDragCursorCachePtr(
1057         XmScreen xmScreen )
1058 {
1059     return &xmScreen->screen.cursorCache;
1060 }
1061 
1062 /************************************************************************
1063  *
1064  *  XmeQueryBestCursorSize()
1065  *
1066  ************************************************************************/
1067 
1068 void
XmeQueryBestCursorSize(Widget w,Dimension * width,Dimension * height)1069 XmeQueryBestCursorSize(
1070         Widget w,
1071         Dimension *width,
1072         Dimension *height )
1073 {
1074     XmScreen	xmScreen;
1075     _XmWidgetToAppContext(w);
1076 
1077     _XmAppLock(app);
1078     xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(w));
1079     *width = (Dimension)xmScreen->screen.maxCursorWidth;
1080     *height = (Dimension)xmScreen->screen.maxCursorHeight;
1081     _XmAppUnlock(app);
1082     return;
1083 }
1084 
1085 static XmConst char nullBits[] =
1086 {
1087     0x00, 0x00, 0x00, 0x00,
1088     0x00, 0x00, 0x00, 0x00,
1089     0x00, 0x00, 0x00, 0x00,
1090     0x00, 0x00, 0x00, 0x00,
1091 };
1092 
1093 /************************************************************************
1094  *
1095  *  XmeGetNullCursor ()
1096  *
1097  ************************************************************************/
1098 
1099 Cursor
XmeGetNullCursor(Widget w)1100 XmeGetNullCursor(
1101         Widget w )
1102 {
1103     XmScreen		xmScreen;
1104     Pixmap		pixmap;
1105     Cursor		cursor;
1106     XColor		foreground;
1107     XColor		background;
1108     _XmWidgetToAppContext(w);
1109 
1110     _XmAppLock(app);
1111     xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(w));
1112     if (xmScreen->screen.nullCursor == None) {
1113 	foreground.pixel =
1114 	  background.pixel = 0;
1115 	pixmap =
1116 	  XCreatePixmapFromBitmapData(XtDisplayOfObject(w),
1117 				      RootWindowOfScreen(XtScreenOfObject(w)),
1118 				      (char*)nullBits,
1119 				      4, 4,
1120 				      0, 0,
1121 				      1);
1122 	cursor =
1123 	  XCreatePixmapCursor(XtDisplayOfObject(w),
1124 			      pixmap,
1125 			      pixmap,
1126 			      &foreground, &background,
1127 			      0, 0);
1128 	XFreePixmap(XtDisplayOfObject(w), pixmap);
1129 	xmScreen->screen.nullCursor = cursor;
1130     }
1131     cursor = xmScreen->screen.nullCursor;
1132     _XmAppUnlock(app);
1133     return cursor;
1134 }
1135 
1136 /*
1137  * The following set of functions support the menu cursor functionality.
1138  * They have moved from MenuUtil to here.
1139  */
1140 
1141 
1142 /* Obsolete global per-display menu cursor manipulation functions */
1143 /* Programs have to use XtSet/GetValues on the XmScreen object instead */
1144 void
XmSetMenuCursor(Display * display,Cursor cursorId)1145 XmSetMenuCursor(
1146         Display *display,
1147         Cursor cursorId )
1148 {
1149     XmScreen          xmScreen;
1150     Screen            *scr;
1151     int i ;
1152     _XmDisplayToAppContext(display);
1153 
1154     /* This function has no screen parameter, so we have to set the
1155        menucursor for _all_ the xmscreen available on this display. why?
1156        because when RowColumn will be getting a menucursor for a particular
1157        screen, it will have to get what the application has set using
1158        this function, not the default for that particular screen (which is
1159        what will happen if we were only setting the default display here) */
1160 
1161     _XmAppLock(app);
1162     for (i=0, scr = ScreenOfDisplay(display, i); i < ScreenCount(display);
1163        i++, scr = ScreenOfDisplay(display, i)) {
1164 
1165       xmScreen = (XmScreen) XmGetXmScreen(scr);
1166       xmScreen->screen.menuCursor = cursorId ;
1167     }
1168     _XmAppUnlock(app);
1169 }
1170 
1171 
1172 Cursor
XmGetMenuCursor(Display * display)1173 XmGetMenuCursor(
1174         Display *display )
1175 {
1176    XmScreen           xmScreen;
1177    Cursor	      cursor;
1178    _XmDisplayToAppContext(display);
1179 
1180    /* get the default screen menuCursor since there is no
1181       other information available to this function */
1182    _XmAppLock(app);
1183    xmScreen = (XmScreen) XmGetXmScreen(DefaultScreenOfDisplay(display));
1184    cursor = xmScreen->screen.menuCursor;
1185    _XmAppUnlock(app);
1186    return cursor;
1187 }
1188 
1189 /* a convenience for RowColumn */
1190 Cursor
_XmGetMenuCursorByScreen(Screen * screen)1191 _XmGetMenuCursorByScreen(
1192         Screen * screen  )
1193 {
1194    XmScreen           xmScreen;
1195 
1196    xmScreen = (XmScreen) XmGetXmScreen(screen);
1197    return(xmScreen->screen.menuCursor);
1198 }
1199 
1200 Boolean
_XmGetMoveOpaqueByScreen(Screen * screen)1201 _XmGetMoveOpaqueByScreen(
1202         Screen * screen  )
1203 {
1204    XmScreen           xmScreen;
1205 
1206    xmScreen = (XmScreen) XmGetXmScreen(screen);
1207    return(xmScreen->screen.moveOpaque);
1208 }
1209 
1210 /* a convenience for RowColumn */
1211 unsigned char
_XmGetUnpostBehavior(Widget wid)1212 _XmGetUnpostBehavior(
1213         Widget wid )
1214 {
1215    XmScreen	xmScreen = (XmScreen) XmGetXmScreen(XtScreenOfObject(wid));
1216 
1217    return(xmScreen->screen.unpostBehavior);
1218 }
1219 
1220 
1221 /**********************************************************************
1222  **********************************************************************
1223 
1224       Font unit handling functions
1225 
1226  **********************************************************************
1227  **********************************************************************/
1228 
1229 /**********************************************************************
1230  *
1231  *  XmSetFontUnits
1232  *    Set the font_unit value for all screens.  These values can
1233  *    then be used later to process the font unit conversions.
1234  *
1235  **********************************************************************/
1236 void
XmSetFontUnits(Display * display,int h_value,int v_value)1237 XmSetFontUnits(
1238         Display *display,
1239         int h_value,
1240         int v_value )
1241 {
1242     XmScreen          xmScreen;
1243     Screen            *scr;
1244     int i ;
1245     _XmDisplayToAppContext(display);
1246 
1247     /* This function has no screen parameter, so we have to set the
1248        fontunit for _all_ the xmscreen available on this display. why?
1249        because when someone will be getting fontunits for a particular
1250        screen, it will have to get what the application has set using
1251        this function, not the default for that particular screen (which is
1252        what will happen if we were only setting the default display here) */
1253 
1254     _XmAppLock(app);
1255     for (i=0, scr = ScreenOfDisplay(display, i); i < ScreenCount(display);
1256        i++, scr = ScreenOfDisplay(display, i)) {
1257 
1258       xmScreen = (XmScreen) XmGetXmScreen(scr);
1259       xmScreen->screen.h_unit =  h_value ;
1260       xmScreen->screen.v_unit =  v_value ;
1261     }
1262     _XmAppUnlock(app);
1263 }
1264 
1265 /* DEPRECATED */
1266 void
XmSetFontUnit(Display * display,int value)1267 XmSetFontUnit(
1268         Display *display,
1269         int value )
1270 {
1271     XmSetFontUnits(display, value, value);
1272 }
1273 
1274 
1275 
1276 /**********************************************************************
1277  *
1278  *  _XmGetFontUnit
1279  *
1280  **********************************************************************/
1281 int
_XmGetFontUnit(Screen * screen,int dimension)1282 _XmGetFontUnit(
1283         Screen *screen,
1284         int dimension )
1285 {
1286     XmScreen          xmScreen;
1287 
1288     xmScreen = (XmScreen) XmGetXmScreen(screen);
1289     if (dimension == XmHORIZONTAL)
1290       return(xmScreen->screen.h_unit);
1291     else
1292       return(xmScreen->screen.v_unit);
1293 }
1294 
1295 
1296 /**********************************************************************
1297  *
1298  *  _XmGetColorCalculationProc
1299  *     Here there is no point of supporting the old function as
1300  *     place holder for the new color proc since the signature are
1301  *     different. The old color proc will still be managed by Visual.c
1302  *     in its own way.
1303  **********************************************************************/
1304 XmScreenColorProc
_XmGetColorCalculationProc(Screen * screen)1305 _XmGetColorCalculationProc(
1306         Screen *screen)
1307 {
1308     XmScreen          xmScreen;
1309 
1310     xmScreen = (XmScreen) XmGetXmScreen(screen);
1311     return(xmScreen->screen.color_calc_proc);
1312 }
1313 
1314 /**********************************************************************
1315  *
1316  *  _XmGetColorAllocationProc
1317  *
1318  **********************************************************************/
1319 XmAllocColorProc
_XmGetColorAllocationProc(Screen * screen)1320 _XmGetColorAllocationProc(
1321         Screen *screen)
1322 {
1323     XmScreen          xmScreen;
1324 
1325     xmScreen = (XmScreen) XmGetXmScreen(screen);
1326     return(xmScreen->screen.color_alloc_proc);
1327 }
1328 
1329 /**********************************************************************
1330  *
1331  *  _XmGetBitmapConversionModel
1332  *
1333  **********************************************************************/
1334 
1335 XtEnum
_XmGetBitmapConversionModel(Screen * screen)1336 _XmGetBitmapConversionModel(
1337         Screen *screen)
1338 {
1339     XmScreen          xmScreen;
1340 
1341     xmScreen = (XmScreen) XmGetXmScreen(screen);
1342     return(xmScreen->screen.bitmap_conversion_model);
1343 }
1344 
1345 
1346 
1347 
1348 /************************************************************************
1349  *
1350  * _XmGetInsensitiveStippleBitmap
1351  *
1352  * Returns the insensitive_stipple_bitmap field of the XmScreenPart
1353  ************************************************************************/
1354 
1355 Pixmap
_XmGetInsensitiveStippleBitmap(Widget w)1356 _XmGetInsensitiveStippleBitmap (Widget w)
1357 {
1358     XmScreen    xmScreen = (XmScreen) XmGetXmScreen(XtScreen(w));
1359 
1360     return(xmScreen->screen.insensitive_stipple_bitmap);
1361 }
1362 
1363 
1364 #ifdef DEFAULT_GLYPH_PIXMAP
1365 /**********************************************************************
1366  *
1367  *  _XmGetDefaultGlyphPixmap
1368  *
1369  **********************************************************************/
1370 Pixmap
_XmGetDefaultGlyphPixmap(Screen * screen,unsigned int * width,unsigned int * height)1371 _XmGetDefaultGlyphPixmap(
1372         Screen *screen,
1373         unsigned int * width,
1374         unsigned int  *height)
1375 {
1376     XmScreen          xmScreen;
1377 
1378     xmScreen = (XmScreen) XmGetXmScreen(screen);
1379 
1380     if (width) *width = xmScreen->screen.default_glyph_pixmap_width ;
1381     if (height) *height = xmScreen->screen.default_glyph_pixmap_height ;
1382 
1383     return(xmScreen->screen.default_glyph_pixmap);
1384 }
1385 #endif
1386 
1387 
1388 
1389 /*********************************************************************
1390  *
1391  *  XmGetXmScreen
1392  *
1393  *********************************************************************/
1394 
1395 /* ARGSUSED */
1396 Widget
XmGetXmScreen(Screen * screen)1397 XmGetXmScreen(
1398         Screen *screen )
1399 {
1400     XmDisplay	xmDisplay;
1401     WidgetList	children;
1402     Widget 	widget;
1403     int	num_children;
1404     Arg args[5];
1405     int i;
1406     Screen *scr;
1407     char name[25];
1408     _XmDisplayToAppContext(DisplayOfScreen(screen));
1409 
1410     _XmAppLock(app);
1411     if ((xmDisplay = (XmDisplay)
1412 	 XmGetXmDisplay(DisplayOfScreen(screen))) == NULL)
1413 	{
1414 		XmeWarning(NULL, MESSAGE2);
1415 		_XmAppUnlock(app);
1416 		return(NULL);
1417 	}
1418 
1419 	children = xmDisplay->composite.children;
1420 	num_children = xmDisplay->composite.num_children;
1421 
1422 	for (i=0; i < num_children; i++)
1423 	{
1424 		Widget child = children[i];
1425 		if ((XmIsScreen(child)) &&
1426 			(screen == XtScreen(child))) {
1427 			_XmAppUnlock(app);
1428 			return(child);
1429 		}
1430 	}
1431 
1432 	/* Not found; have to do an implied creation */
1433 	for (scr = ScreenOfDisplay(XtDisplay(xmDisplay), i);
1434 		i < ScreenCount(XtDisplay(xmDisplay));
1435 		i++, scr = ScreenOfDisplay(XtDisplay(xmDisplay), i))
1436 	{
1437 		if (scr == screen)
1438 			break;
1439 	}
1440 
1441 	sprintf(name, "screen%d", i);
1442 
1443 	i = 0;
1444 	XtSetArg(args[i], XmNscreen, screen); i++;
1445 	widget = XtCreateWidget(name, xmScreenClass, (Widget)xmDisplay,
1446 		args, i);
1447 	_XmAppUnlock(app);
1448 	return widget;
1449 }
1450