summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_get_background_image.cxx
blob: 783ae43cfa18c4619544dee8aff35f70f486668a (plain)
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
/*
// GG IMP060200	Xw_get_background_image signatuire change 
*/
#include <Xw_Extension.h>

	/* ifdef then trace on */
#ifdef TRACE
#define TRACE_GET_BACKGROUND_IMAGE
#endif

/*
   XW_STATUS Xw_get_background_image (awindow,xc,yc,width,height):
   XW_EXT_WINDOW *awindow
   int xc,yc			Image center location in pixels 
   int width,height		Image size in pixels

	Get the window Background from the actual Window
	at the required Center location 

	returns  ERROR if Image is outside of the window
	returns  SUCCESS if successful

*/

#ifdef XW_PROTOTYPE
XW_STATUS Xw_get_background_image (void* awindow,
			int xc,int yc,int width,int height)
#else
XW_STATUS Xw_get_background_image (awindow,xc,yc,width,height)
void *awindow;
int xc,yc ;
int width,height ;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
XW_EXT_DISPLAY *pdisplay = pwindow->connexion ;
XW_STATUS status ;
XImage *pimage ;
int wx,wy ;

    	if( !Xw_isdefine_window(pwindow) ) {
            /*ERROR*Bad EXT_WINDOW Address*/
            Xw_set_error(24,"Xw_get_background_image",pwindow) ;
            return (XW_ERROR) ;
    	}

    	wx = xc - width/2 ;
    	wy = yc - height/2 ;

	if( _DGRAB ) {
	    wx += _X ; wy += _Y ;
    	    if( (wx + width) < 0 || wx  > _DWIDTH || 
				(wy + height) < 0 || wy > _DHEIGHT ) {
	        /*WARNING*Try to Get Image from outside the display*/
	        Xw_set_error(45,"Xw_get_background_image",0) ;
                return (XW_ERROR) ;
    	    }
    	    pimage = XGetImage(_DISPLAY,_DROOT,wx,wy,
					width,height,AllPlanes,ZPixmap) ;
	} else {
    	    if( (wx + width) < 0 || wx  > _WIDTH || 
				(wy + height) < 0 || wy > _HEIGHT ) {
	        /*WARNING*Try to Get Image from outside the window*/
	        Xw_set_error(45,"Xw_get_background_image",0) ;
                return (XW_ERROR) ;
    	    }
    	    pimage = XGetImage(_DISPLAY,_WINDOW,wx,wy,
					width,height,AllPlanes,ZPixmap) ;
	}

        if( _BPIXMAP ) Xw_close_background_pixmap(pwindow) ;

        if( _PIXMAP || _NWBUFFER > 0 ) {
	    status = Xw_open_background_pixmap(pwindow) ;
	    if( !status ) return (XW_ERROR) ;
            for( wx=0 ; wx<_WIDTH ; wx += width ) {
              for( wy=0 ; wy<_HEIGHT ; wy += height ) {
                XPutImage(_DISPLAY,_BPIXMAP,pwindow->qgwind.gccopy,
                        		pimage,0,0,wx,wy,width,height) ;
              }
            }
        } else {
            Pixmap pixmap = XCreatePixmap(_DISPLAY,_WINDOW,
                                                width,height,_DEPTH);
	    if( !pixmap ) return (XW_ERROR) ;
            XPutImage(_DISPLAY,pixmap,pwindow->qgwind.gccopy,
                        pimage,0,0,wx,wy,width,height) ;
            XSetWindowBackgroundPixmap(_DISPLAY,_WINDOW,pixmap) ;
            XFlush(_DISPLAY) ;
            XFreePixmap(_DISPLAY,pixmap) ;
        }

	Xw_erase_window(pwindow) ;

#ifdef  TRACE_GET_BACKGROUND_IMAGE
if( Xw_get_trace() ) {
    printf (" Xw_get_background_image(%lx,%d,%d,%d,%d)\n",
					(long ) pwindow,xc,yc,width,height);
}
#endif

    return (XW_SUCCESS);
}