b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_PUT_BACKGROUND_IMAGE |
24 | #define TRACE_CLEAR_BACKGROUND_IMAGE |
25 | #endif |
26 | |
27 | #define OCC153 // bad memory management |
28 | |
29 | /* |
30 | STATUS Xw_put_background_image (awindow,image,method): |
31 | XW_EXT_WINDOW *awindow |
32 | XW_EXT_IMAGEDATA *image Image structure |
33 | Aspect_FillMethod method Image fill method |
34 | |
35 | Draw an image to the window background according to the fill method. |
36 | |
37 | returns ERROR if NO Image is defined |
38 | returns SUCCESS if successful |
39 | |
40 | STATUS Xw_clear_background_image (awindow): |
41 | XW_EXT_WINDOW *awindow |
42 | |
43 | Clear the window background image |
44 | |
45 | returns SUCCESS allways |
46 | |
47 | STATUS Xw_update_background_image(awindow) |
48 | XW_EXT_WINDOW *awindow |
49 | |
50 | Updates the window background from an image |
51 | according to the window size and fill method |
52 | |
53 | returns SUCCESS if successful |
54 | |
55 | |
56 | STATUS Xw_set_background_pixmap(awindow,apixmap) |
57 | XW_EXT_WINDOW *awindow |
58 | Pixmap apixmap |
59 | |
60 | Updates the window background from a user pixmap |
61 | |
62 | |
63 | returns SUCCESS if successful |
64 | |
65 | STATUS Xw_get_background_pixmap(awindow,apixmap) |
66 | XW_EXT_WINDOW *awindow |
67 | Pixmap *apixmap |
68 | |
69 | Returns the current background pixmap coming from |
70 | an image or a user pixmap |
71 | */ |
72 | |
73 | #ifdef XW_PROTOTYPE |
74 | XW_STATUS Xw_put_background_image (void* awindow,void* aimage,Aspect_FillMethod method) |
75 | #else |
76 | XW_STATUS Xw_put_background_image (awindow,aimage,method) |
77 | void *awindow; |
78 | void *aimage ; |
79 | Aspect_FillMethod method; |
80 | #endif /*XW_PROTOTYPE*/ |
81 | { |
82 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
83 | XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*) aimage ; |
84 | XW_STATUS status ; |
85 | |
86 | if( !Xw_isdefine_window(pwindow) ) { |
87 | /*ERROR*Bad EXT_WINDOW Address*/ |
88 | Xw_set_error(24,"Xw_put_background_image",pwindow) ; |
89 | return (XW_ERROR) ; |
90 | } |
91 | |
92 | if( !Xw_isdefine_image(pimage) ) { |
93 | /*ERROR*Bad EXT_IMAGEDATA Address*/ |
94 | Xw_set_error(25,"Xw_put_background_image",pimage) ; |
95 | return (XW_ERROR) ; |
96 | } |
97 | |
98 | #ifdef OCC153 |
99 | if( _BIMAGE ) |
100 | { |
101 | if (_BIMAGE != pimage) |
102 | { |
103 | Xw_close_image(_BIMAGE); |
104 | _BIMAGE = pimage; |
105 | } |
106 | } |
107 | else |
108 | { |
109 | _BIMAGE = pimage; |
110 | } |
111 | #else |
112 | if( _BIMAGE ) Xw_close_image(_BIMAGE); |
113 | _BIMAGE = pimage; |
114 | #endif |
115 | _BMETHOD = method; |
116 | |
117 | status = Xw_update_background_image(pwindow); |
118 | |
119 | #ifdef TRACE_PUT_BACKGROUND_IMAGE |
120 | if( Xw_get_trace() ) |
121 | printf (" Xw_put_background_image(%lx,%lx)\n",(long ) pwindow,(long ) pimage) ; |
122 | #endif |
123 | |
124 | return status; |
125 | } |
126 | |
127 | #ifdef XW_PROTOTYPE |
128 | XW_STATUS Xw_clear_background_image (void* awindow) |
129 | #else |
130 | XW_STATUS Xw_clear_background_image (awindow) |
131 | void *awindow; |
132 | #endif /*XW_PROTOTYPE*/ |
133 | { |
134 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ; |
135 | |
136 | if( _BIMAGE ) { |
137 | Xw_close_image( _BIMAGE ); |
138 | _BIMAGE = NULL; |
139 | } |
140 | |
141 | if( _BPIXMAP ) { |
142 | XFreePixmap(_DISPLAY,_BPIXMAP) ; |
143 | _BPIXMAP = 0 ; |
144 | } |
145 | |
146 | XSetWindowBackgroundPixmap(_DISPLAY,_WINDOW,0) ; |
147 | |
148 | Xw_erase_window(pwindow) ; |
149 | |
150 | #ifdef TRACE_CLEAR_BACKGROUND_IMAGE |
151 | if( Xw_get_trace() ) { |
152 | printf (" Xw_clear_background_image(%lx)\n",(long ) pwindow) ; |
153 | } |
154 | #endif |
155 | |
156 | return XW_SUCCESS; |
157 | } |
158 | |
159 | #ifdef XW_PROTOTYPE |
160 | XW_STATUS Xw_update_background_image(void* awindow) |
161 | #else |
162 | XW_STATUS Xw_update_background_image(awindow) |
163 | void *awindow; |
164 | #endif |
165 | { |
166 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
167 | XW_EXT_IMAGEDATA *pimage = _BIMAGE; |
168 | XW_STATUS status; |
169 | int ix,iy,iwidth,iheight,wx,wy; |
170 | |
171 | if( !Xw_isdefine_window(pwindow) ) { |
172 | /*ERROR*Bad EXT_WINDOW Address*/ |
173 | Xw_set_error(24,"Xw_update_background_image",pwindow) ; |
174 | return (XW_ERROR) ; |
175 | } |
176 | |
177 | if( !pimage ) return XW_ERROR; |
178 | |
179 | ix = iy = wx = wy = 0 ; |
180 | iwidth = _IIMAGE->width; |
181 | iheight = _IIMAGE->height; |
182 | XImage *pximage = _IIMAGE ; |
183 | if( _BMETHOD == Aspect_FM_NONE ) { |
184 | if( iwidth > _WIDTH ) { |
185 | iwidth = _WIDTH; |
186 | } |
187 | if( iheight > _HEIGHT ) { |
188 | iheight = _HEIGHT; |
189 | } |
190 | } else if( _BMETHOD == Aspect_FM_CENTERED ) { |
191 | wx = (_WIDTH - iwidth)/2; |
192 | if( wx < 0 ) { ix = -wx; wx = 0; iwidth = _WIDTH; } |
193 | wy = (_HEIGHT - iheight)/2; |
194 | if( wy < 0 ) { iy = -wy; wy = 0; iheight = _HEIGHT; } |
195 | } else if( _BMETHOD == Aspect_FM_STRETCH ) { |
196 | float zoom = 1.; |
197 | if( iwidth != _WIDTH ) { |
198 | zoom = (float)_WIDTH/iwidth; |
199 | iwidth *= (int)zoom; iheight *= (int)zoom; |
200 | } |
201 | if( iheight != _HEIGHT ) { |
202 | zoom *= (float)_HEIGHT/iheight; |
203 | iwidth *= (int)zoom; iheight *= (int)zoom; |
204 | } |
205 | if( _ZIMAGE && (zoom == pimage->zoom) ) { |
206 | pximage = _ZIMAGE; |
207 | } else { |
208 | status = Xw_zoom_image(pimage,zoom); |
209 | if( status ) { |
210 | iwidth = _ZIMAGE->width; |
211 | iheight = _ZIMAGE->height; |
212 | wx = (_WIDTH - iwidth)/2; |
213 | if( wx < 0 ) { ix = -wx; wx = 0; iwidth = _WIDTH; } |
214 | wy = (_HEIGHT - iheight)/2; |
215 | if( wy < 0 ) { iy = -wy; wy = 0; iheight = _HEIGHT; } |
216 | pximage = _ZIMAGE; |
217 | } |
218 | } |
219 | } |
220 | |
221 | if( _BPIXMAP ) Xw_close_background_pixmap(pwindow) ; |
222 | |
223 | status = Xw_open_background_pixmap(pwindow) ; |
224 | if( !status ) return (XW_ERROR) ; |
225 | |
226 | if( _BMETHOD != Aspect_FM_TILED ) { |
227 | XPutImage(_DISPLAY,_BPIXMAP,pwindow->qgwind.gccopy, |
228 | pximage,ix,iy,wx,wy,iwidth,iheight) ; |
229 | } else { |
230 | for( wy=0 ; wy<_HEIGHT ; wy += iheight ) { |
231 | for( wx=0 ; wx<_WIDTH ; wx += iwidth ) { |
232 | XPutImage(_DISPLAY,_BPIXMAP,pwindow->qgwind.gccopy, |
233 | pximage,ix,iy,wx,wy,iwidth,iheight) ; |
234 | } |
235 | } |
236 | } |
237 | XSetWindowBackgroundPixmap(_DISPLAY,_WINDOW,_BPIXMAP) ; |
238 | |
239 | Xw_erase_window(pwindow) ; |
240 | |
241 | #ifdef TRACE_PUT_BACKGROUND_IMAGE |
242 | if( Xw_get_trace() ) |
243 | printf (" Xw_update_background_image(%lx)\n",(long ) pwindow) ; |
244 | #endif |
245 | |
246 | return (XW_SUCCESS); |
247 | } |
248 | |
249 | #ifdef XW_PROTOTYPE |
250 | XW_STATUS Xw_set_background_pixmap( void * awindow, Aspect_Handle apixmap ) |
251 | #else |
252 | XW_STATUS Xw_set_background_pixmap( awindow, apixmap ) |
253 | void * awindow; |
254 | Aspect_Handle apixmap; |
255 | #endif |
256 | { |
257 | XW_EXT_WINDOW * pwindow = ( XW_EXT_WINDOW * ) awindow; |
258 | |
259 | if ( !Xw_isdefine_window( pwindow ) ) { |
260 | Xw_set_error( 24, "Xw_set_background_pixmap", pwindow ); |
261 | return( XW_ERROR ); |
262 | } |
263 | |
264 | if ( !apixmap ) return XW_ERROR; |
265 | |
266 | if( _BIMAGE ) { |
267 | Xw_close_image(_BIMAGE); |
268 | _BIMAGE = NULL; |
269 | } |
270 | |
271 | if( _BPIXMAP ) XFreePixmap( _DISPLAY, _BPIXMAP ); |
272 | |
273 | _BPIXMAP = apixmap; |
274 | |
275 | XSetWindowBackgroundPixmap( _DISPLAY,_WINDOW,_BPIXMAP); |
276 | |
277 | Xw_erase_window(pwindow) ; |
278 | |
279 | return( XW_SUCCESS ); |
280 | |
281 | #ifdef TRACE_PUT_BACKGROUND_IMAGE |
282 | if( Xw_get_trace() ) |
283 | printf (" Xw_update_background_image(%lx)\n",(long ) pwindow) ; |
284 | #endif |
285 | } |
286 | |
287 | #ifdef XW_PROTOTYPE |
288 | XW_STATUS Xw_get_background_pixmap( void * awindow, Aspect_Handle& apixmap ) |
289 | #else |
290 | XW_STATUS Xw_get_background_pixmap( awindow, apixmap ) |
291 | void * awindow; |
292 | Aspect_Handle& apixmap; |
293 | #endif |
294 | { |
295 | XW_EXT_WINDOW * pwindow = ( XW_EXT_WINDOW * ) awindow; |
296 | |
297 | if ( !Xw_isdefine_window( pwindow ) ) { |
298 | Xw_set_error( 24, "Xw_get_background_pixmap", pwindow ); |
299 | return( XW_ERROR ); |
300 | } |
301 | |
302 | if ( !_BPIXMAP ) return( XW_ERROR ); |
303 | |
304 | apixmap = _BPIXMAP; |
305 | |
306 | return ( XW_SUCCESS ); |
307 | } |