File: Misc.c

package info (click to toggle)
nextaw 0.5.1-22
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 1,776 kB
  • ctags: 3,781
  • sloc: ansic: 27,708; makefile: 624; yacc: 247; lex: 126; sh: 69
file content (137 lines) | stat: -rw-r--r-- 3,768 bytes parent folder | download | duplicates (3)
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
/*
 * Misc. functions for neXtaw 
 * 
 * Copyright (c) 1996 Alfedo K. Kojima
 */

#include <X11/neXtaw/Misc.h>

#ifdef XPM_TILE
#include <X11/xpm.h>
#endif

void
neXtawDrawShadowBox (gw, tdw, x0, y0, x1, y1, out) 
    Widget gw;
    ThreeDWidget tdw;
    Position x0, y0, x1, y1;
    Boolean out;
{
    XPoint	pt[6];
    Dimension	s = tdw->threeD.shadow_width;
    
    /* 
     * draw the shadows using the core part width and height, 
     * and the threeD part shadow_width.
     *
     *	no point to do anything if the shadow_width is 0 or the
     *	widget has not been realized.
     */ 
    if((s > 0) && XtIsRealized (gw)){

	Dimension	h = y1 - y0;
	Dimension	w = x1 - x0;
	Dimension	wms = w - s;
	Dimension	hms = h - s;
	Dimension	wmsm = w - (s>1 ? s/2 : 1);
	Dimension	hmsm = h - (s>1 ? s/2 : 1);
	Dimension	sm = (s>1 ? s/2 : 1);
	Display		*dpy = XtDisplay (gw);
	Window		win = XtWindow (gw);
	GC		top, bot, toph, both;

	if (out) {
	    top = tdw->threeD.top_shadow_GC;
	    bot = tdw->threeD.bot_shadow_GC;
	    toph = tdw->threeD.top_half_shadow_GC;
	    both = tdw->threeD.bot_half_shadow_GC;
	} else {
	    top = tdw->threeD.bot_shadow_GC;
	    bot = tdw->threeD.top_shadow_GC;
	    toph = tdw->threeD.bot_half_shadow_GC;
	    both = tdw->threeD.top_half_shadow_GC;	    
	}

	/* top-left shadow */
	pt[0].x = x0;		pt[0].y = y0+h;
	pt[1].x = x0;		pt[1].y = y0;
	pt[2].x = x0+w;		pt[2].y = y0;
	pt[3].x = x0+wmsm;	pt[3].y = y0+sm-1;
	pt[4].x = x0+sm;	pt[4].y = y0+sm;
	pt[5].x = x0+sm-1;	pt[5].y = y0+hmsm;
	XFillPolygon (dpy, win, toph, pt, 6,Complex,CoordModeOrigin);
	if (s > 1) {
	    pt[0].x = x0+s-1;	pt[0].y = y0+hms;
	    pt[1].x = x0+s;	pt[1].y = y0+s;
	    pt[2].x = x0+wms;	pt[2].y = y0+s-1;
	    XFillPolygon (dpy, win, top, pt, 6,Complex,CoordModeOrigin);
	}	    

	/* bottom-right shadow */	
	pt[0].x = x0;		pt[0].y = y0+h;
	pt[1].x = x0+w;		pt[1].y = y0+h;
	pt[2].x = x0+w;		pt[2].y = y0;
	pt[3].x = x0+wmsm;	pt[3].y = y0+sm-1;
	pt[4].x = x0+wmsm;	pt[4].y = y0+hmsm;
	pt[5].x = x0+sm-1;	pt[5].y = y0+hmsm;
	XFillPolygon (dpy, win, both, pt,6, Complex,CoordModeOrigin);
	if (s > 1) {
	    pt[0].x = x0+s-1;	pt[0].y = y0+hms;
	    pt[1].x = x0+wms;	pt[1].y = y0+hms;
	    pt[2].x = x0+wms;	pt[2].y = y0+s-1;
	    XFillPolygon (dpy, win, bot, pt,6, Complex,CoordModeOrigin);
	}	    
    }
}



#ifdef XPM_TILE
Boolean
neXtawcvtStringToTilePixmap ( display, args, num_args,  from, to, converter_data)
     Display *display;
     XrmValue *args;
     Cardinal *num_args;
     XrmValuePtr from;
     XrmValuePtr to;
     XtPointer *converter_data;
{
    String file = (String) from->addr;
    XpmAttributes attr;
    Pixmap pixmap, mask;
    Window win;

    if (*num_args != 2)
          XtAppErrorMsg(XtDisplayToApplicationContext(display),
		  "cvtStringToTilePixmap", "wrongParameters",
		  "XtToolkitError",
		  "String to TilePixmap conversion needs screen and colormap arguments",
		  (String*) NULL, (Cardinal*) NULL);
    win = RootWindow(display, 
		     XScreenNumberOfScreen(*((Screen **)args[0].addr)));
    attr.colormap = *((Colormap *)args[1].addr);
    attr.valuemask = XpmSize | XpmReturnPixels|XpmColormap;
    if(XpmReadFileToPixmap(display, win, file, &pixmap, &mask,
			   &attr) != XpmSuccess) {
	XtDisplayStringConversionWarning(display, file, XtRTilePixmap);
	return False;
    } 
    if (mask!=None)
      XFreePixmap(display, mask);
    if (to->addr!=NULL) {
	if (to->size < sizeof(Pixmap)) {
	    to->size = sizeof(Pixmap);
	    XtDisplayStringConversionWarning(display, file, XtRTilePixmap);
	    return False;
	}
	*(Pixmap*)(to->addr) = pixmap;
    } else {
	static Pixmap s_pixmap;

	s_pixmap = pixmap;
	to->addr = (XtPointer)&s_pixmap;
    }
    to->size = sizeof(Pixmap);
    return True;
}
#endif /* XPM_TILE */