1 /*
2  * Misc. functions for neXtaw
3  *
4  * Copyright (c) 1996 Alfedo K. Kojima
5  */
6 
7 #include "Misc.h"
8 
9 #ifdef XPM_TILE
10 #include <X11/xpm.h>
11 #endif
12 
13 void
neXtawDrawShadowBox(gw,tdw,x0,y0,x1,y1,out)14 neXtawDrawShadowBox (gw, tdw, x0, y0, x1, y1, out)
15     Widget gw;
16     ThreeDWidget tdw;
17     Position x0, y0, x1, y1;
18     Boolean out;
19 {
20     XPoint	pt[6];
21     Dimension	s = tdw->threeD.shadow_width;
22 
23     /*
24      * draw the shadows using the core part width and height,
25      * and the threeD part shadow_width.
26      *
27      *	no point to do anything if the shadow_width is 0 or the
28      *	widget has not been realized.
29      */
30     if((s > 0) && XtIsRealized (gw)){
31 
32 	Dimension	h = y1 - y0;
33 	Dimension	w = x1 - x0;
34 	Dimension	wms = w - s;
35 	Dimension	hms = h - s;
36 	Dimension	wmsm = w - (s>1 ? s/2 : 1);
37 	Dimension	hmsm = h - (s>1 ? s/2 : 1);
38 	Dimension	sm = (s>1 ? s/2 : 1);
39 	Display		*dpy = XtDisplay (gw);
40 	Window		win = XtWindow (gw);
41 	GC		top, bot, toph, both;
42 
43 	if (out) {
44 	    top = tdw->threeD.top_shadow_GC;
45 	    bot = tdw->threeD.bot_shadow_GC;
46 	    toph = tdw->threeD.top_half_shadow_GC;
47 	    both = tdw->threeD.bot_half_shadow_GC;
48 	} else {
49 	    top = tdw->threeD.bot_shadow_GC;
50 	    bot = tdw->threeD.top_shadow_GC;
51 	    toph = tdw->threeD.bot_half_shadow_GC;
52 	    both = tdw->threeD.top_half_shadow_GC;
53 	}
54 
55 	if (tdw->threeD.bevel == XtBevelSolid) {
56 		toph = top;
57 		both = bot;
58 	}
59 
60 	/* top-left shadow */
61 	pt[0].x = x0;		pt[0].y = y0+h;
62 	pt[1].x = x0;		pt[1].y = y0;
63 	pt[2].x = x0+w;		pt[2].y = y0;
64 	pt[3].x = x0+wmsm;	pt[3].y = y0+sm-1;
65 	pt[4].x = x0+sm;	pt[4].y = y0+sm;
66 	pt[5].x = x0+sm-1;	pt[5].y = y0+hmsm;
67 	XFillPolygon (dpy, win, toph, pt, 6,Complex,CoordModeOrigin);
68 	if (s > 1) {
69 	    pt[0].x = x0+s-1;	pt[0].y = y0+hms;
70 	    pt[1].x = x0+s;	pt[1].y = y0+s;
71 	    pt[2].x = x0+wms;	pt[2].y = y0+s-1;
72 	    XFillPolygon (dpy, win, top, pt, 6,Complex,CoordModeOrigin);
73 	}
74 
75 	/* bottom-right shadow */
76 	pt[0].x = x0;		pt[0].y = y0+h;
77 	pt[1].x = x0+w;		pt[1].y = y0+h;
78 	pt[2].x = x0+w;		pt[2].y = y0;
79 	pt[3].x = x0+wmsm;	pt[3].y = y0+sm-1;
80 	pt[4].x = x0+wmsm;	pt[4].y = y0+hmsm;
81 	pt[5].x = x0+sm-1;	pt[5].y = y0+hmsm;
82 	XFillPolygon (dpy, win, both, pt,6, Complex,CoordModeOrigin);
83 	if (s > 1) {
84 	    pt[0].x = x0+s-1;	pt[0].y = y0+hms;
85 	    pt[1].x = x0+wms;	pt[1].y = y0+hms;
86 	    pt[2].x = x0+wms;	pt[2].y = y0+s-1;
87 	    XFillPolygon (dpy, win, bot, pt,6, Complex,CoordModeOrigin);
88 	}
89     }
90 }
91 
92 
93 
94 #ifdef XPM_TILE
95 Boolean
neXtawcvtStringToTilePixmap(display,args,num_args,from,to,converter_data)96 neXtawcvtStringToTilePixmap ( display, args, num_args,  from, to, converter_data)
97      Display *display;
98      XrmValue *args;
99      Cardinal *num_args;
100      XrmValuePtr from;
101      XrmValuePtr to;
102      XtPointer *converter_data;
103 {
104     String file = (String) from->addr;
105     XpmAttributes attr;
106     Pixmap pixmap, mask;
107     Window win;
108 
109     if (*num_args != 2)
110           XtAppErrorMsg(XtDisplayToApplicationContext(display),
111 		  "cvtStringToTilePixmap", "wrongParameters",
112 		  "XtToolkitError",
113 		  "String to TilePixmap conversion needs screen and colormap arguments",
114 		  (String*) NULL, (Cardinal*) NULL);
115     win = RootWindow(display,
116 		     XScreenNumberOfScreen(*((Screen **)args[0].addr)));
117     attr.colormap = *((Colormap *)args[1].addr);
118     attr.valuemask = XpmSize | XpmReturnPixels|XpmColormap;
119     if(XpmReadFileToPixmap(display, win, file, &pixmap, &mask,
120 			   &attr) != XpmSuccess) {
121 	XtDisplayStringConversionWarning(display, file, XtRTilePixmap);
122 	return False;
123     }
124     if (mask!=None)
125       XFreePixmap(display, mask);
126     if (to->addr!=NULL) {
127 	if (to->size < sizeof(Pixmap)) {
128 	    to->size = sizeof(Pixmap);
129 	    XtDisplayStringConversionWarning(display, file, XtRTilePixmap);
130 	    return False;
131 	}
132 	*(Pixmap*)(to->addr) = pixmap;
133     } else {
134 	static Pixmap s_pixmap;
135 
136 	s_pixmap = pixmap;
137 	to->addr = (XtPointer)&s_pixmap;
138     }
139     to->size = sizeof(Pixmap);
140     return True;
141 }
142 #endif /* XPM_TILE */
143