0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_def_window.cxx
CommitLineData
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#define PURIFY /*GG_220596
b311480e 19Liberation memoire lors de la destruction d'une fenetre*/
7fd59977 20
21#define S3593 /*GG130398
22 OPTIMISATION MFT -> Desactiver temporairement le clipping
23*/
24
25#include <Xw_Extension.h>
26
27 /* ifdef then trace on */
28#ifdef TRACE
29#define TRACE_DEF_WINDOW
30#define TRACE_CLOSE_WINDOW
31#endif
32
33/*
34 XW_EXT_WINDOW* Xw_def_window (adisplay,window,istransparent);
35 XW_EXT_DISPLAY *adisplay ;
36 Aspect_Handle window XWindow ID
37 int istransparent
38
39 Create the Window Extension info
40 and save Window attributes
41
42 Returns ERROR if the connection failed.
43 Returns extended data window structure pointer
44 if the connection done.
45
46
47 XW_STATUS Xw_close_window (awindow,destroy):
48 XW_EXT_WINDOW *awindow
49 int destroy
50
51 Close the window(s) and free all structures attached to
52 NOTE than this Close all windows if awindow is NULL
53 Destroy the XWindow if destroy is TRUE;
54
55 returns ERROR NO Extended Window address has been defined
56 returns SUCCESS if successful
57
58*/
59
60#ifdef XW_PROTOTYPE
61void* Xw_def_window (void *adisplay,Aspect_Handle window,int istransparent)
62#else
63void* Xw_def_window (adisplay,window,istransparent)
64void *adisplay ;
65Aspect_Handle window ;
66int istransparent ;
67#endif /*XW_PROTOTYPE*/
68{
69XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ;
70XW_EXT_WINDOW *pwindow = NULL ;
71XW_WINDOWSTATE state ;
72//XWindowAttributes attributes ;
73XGCValues gc_values;
74int mask,maskext ;
75//XEvent event ;
76//int i,j,status,xc,yc,width,height ;
77int i,xc,yc,width,height ;
78
79 if( !Xw_isdefine_display(pdisplay) ) {
80 /*ERROR*Bad EXT_DISPLAY Address*/
81 Xw_set_error(96,"Xw_def_window",pdisplay) ;
82 return (NULL) ;
83 }
84
85 if( !(pwindow = Xw_add_window_structure(sizeof(XW_EXT_WINDOW))) )
86 return (NULL) ;
87
88 _DRAWABLE = _WINDOW = window ;
89 _PIXMAP = 0 ;
90 _NWBUFFER = 0 ;
91 _FWBUFFER = 0 ;
92 _BWBUFFER = 0 ;
93 _COLORMAP = NULL ;
94 _WIDTHMAP = NULL ;
95 _TYPEMAP = NULL ;
96 _FONTMAP = NULL ;
97 _TILEMAP = NULL ;
98 _MARKMAP = NULL ;
99
100 pwindow->connexion = pdisplay ;
101
102 state = Xw_get_window_position(pwindow,&xc,&yc,&width,&height) ;
103
104 if( state == XW_WS_UNKNOWN ) {
105 /*ERROR*Bad Window Attributes*/
106 Xw_del_window_structure(pwindow) ;
107 Xw_set_error(54,"Xw_def_window",&window) ;
108 return (NULL) ;
109 }
110
111 pwindow->axleft = xc - width/2 ;
112 pwindow->axright = xc + width/2 ;
113 pwindow->aytop = yc - height/2 ;
114 pwindow->aybottom = yc + height/2 ;
115 pwindow->rwidth = 0 ;
116 pwindow->rheight = 0 ;
117
118 pwindow->lineindex = 0 ;
119 pwindow->polyindex = 0 ;
120 pwindow->textindex = 0 ;
121 pwindow->markindex = 0 ;
122
123 if( istransparent ) {
124 pwindow->backindex = -1 ;
125 } else {
126 pwindow->backindex = 0 ;
127 }
128
129 pwindow->clipflag = True;
130
131 for( i=0 ; i<MAXEVENT ; i++ ) {
132 pwindow->ecbk[i].function = NULL ;
133 pwindow->ecbk[i].userdata = NULL ;
134 pwindow->icbk[i].function = NULL ;
135 }
136
137 gc_values.function = GXcopy ; mask = GCFunction ;
138 gc_values.plane_mask = AllPlanes ; mask |= GCPlaneMask ;
139 gc_values.background = BlackPixelOfScreen(_SCREEN) ;
140 mask |= GCBackground ;
141 gc_values.foreground = WhitePixelOfScreen(_SCREEN) ;
142 mask |= GCForeground ;
143 pwindow->qgwind.gc = XCreateGC(_DISPLAY,_WINDOW, mask, &gc_values) ;
144 gc_values.foreground = BlackPixelOfScreen(_SCREEN) ;
145 pwindow->qgwind.gcclear = XCreateGC(_DISPLAY,_WINDOW, mask, &gc_values);
146 gc_values.graphics_exposures = False ; mask |= GCGraphicsExposures ;
147 gc_values.foreground = WhitePixelOfScreen(_SCREEN) ;
148 pwindow->qgwind.gccopy = XCreateGC(_DISPLAY,_WINDOW, mask, &gc_values) ;
149 gc_values.function = GXxor ;
150 gc_values.graphics_exposures = True ;
151 pwindow->qgwind.gchigh = XCreateGC(_DISPLAY,_WINDOW, mask, &gc_values) ;
152 gc_values.function = GXcopy ;
153 pwindow->qgwind.code = ~0 ;
154 pwindow->qgwind.pimage = NULL ;
155 pwindow->qgwind.method = Aspect_FM_NONE ;
156 pwindow->qgwind.pixmap = 0 ;
157
158 _BINDEX = 0 ;
159 for( i=0 ; i<MAXBUFFERS ; i++ ) {
160 _BUFFER(i).bufferid = 0 ;
161 _BUFFER(i).gcf = NULL ;
162 _BUFFER(i).gcb = NULL ;
163 _BUFFER(i).code = 0 ;
164 _BUFFER(i).isdrawn = False ;
165 _BUFFER(i).isempty = True ;
166 _BUFFER(i).isretain = False ;
167 _BUFFER(i).isupdated = False ;
168 _BUFFER(i).rxmin = _WIDTH ;
169 _BUFFER(i).rymin = _HEIGHT ;
170 _BUFFER(i).rxmax = 0 ;
171 _BUFFER(i).rymax = 0 ;
172 _BUFFER(i).xpivot = 0 ;
173 _BUFFER(i).ypivot = 0 ;
174 _BUFFER(i).dxpivot = 0 ;
175 _BUFFER(i).dypivot = 0 ;
176 _BUFFER(i).xscale = 1. ;
177 _BUFFER(i).yscale = 1. ;
178 _BUFFER(i).dxscale = 1. ;
179 _BUFFER(i).dyscale = 1. ;
180 _BUFFER(i).angle = 0. ;
181 _BUFFER(i).dangle = 0. ;
182 _BUFFER(i).ptextdesc = NULL ;
183 _BUFFER(i).plinedesc = NULL ;
184 _BUFFER(i).ppntlist = NULL ;
185 _BUFFER(i).pseglist = NULL ;
186 _BUFFER(i).plinelist = NULL ;
187 _BUFFER(i).ppolylist = NULL ;
188 _BUFFER(i).plarclist = NULL ;
189 _BUFFER(i).pparclist = NULL ;
190 _BUFFER(i).pltextlist = NULL ;
191 _BUFFER(i).pptextlist = NULL ;
192 _BUFFER(i).plmarklist = NULL ;
193 _BUFFER(i).ppmarklist = NULL ;
194 _BUFFER(i).pimaglist = NULL ;
195 }
196
197 for( i=0 ; i<MAXQG ; i++ ) {
198 gc_values.line_width = 0 ; maskext = GCLineWidth ;
199 gc_values.line_style = LineSolid ; maskext |= GCLineStyle ;
200 gc_values.dash_offset = 0 ; maskext |= GCDashOffset ;
201 gc_values.join_style = JoinRound ; maskext |= GCJoinStyle ;
202 pwindow->qgline[i].code = ~0 ;
203 pwindow->qgline[i].count = 0 ;
204 pwindow->qgline[i].gc = XCreateGC(_DISPLAY,_WINDOW,
205 mask | maskext, &gc_values) ;
206 pwindow->qgmark[i].code = ~0;
207 pwindow->qgmark[i].count = 0 ;
208 pwindow->qgmark[i].gc = XCreateGC(_DISPLAY,_WINDOW,
209 mask | maskext, &gc_values) ;
210 gc_values.fill_style = FillSolid ; maskext = GCFillStyle ;
211 gc_values.fill_rule = EvenOddRule ; maskext |= GCFillRule ;
212 pwindow->qgpoly[i].code = ~0 ;
213 pwindow->qgpoly[i].count = 0 ;
214 pwindow->qgpoly[i].gc = XCreateGC(_DISPLAY,_WINDOW,
215 mask | maskext, &gc_values) ;
216 maskext = 0 ;
217 pwindow->qgtext[i].code = ~0;
218 pwindow->qgtext[i].count = 0 ;
219 pwindow->qgtext[i].gc = XCreateGC(_DISPLAY,_WINDOW,
220 mask | maskext, &gc_values) ;
221 }
222
223 XFlush(_DISPLAY) ;
224
225 Xw_set_window_ratio(pwindow,0.001 METER) ;
226
227#ifdef TRACE_DEF_WINDOW
228if( Xw_get_trace() ) {
229 printf (" Xw_def_window(%lx,%lx,%d)\n",(long ) pdisplay,(long ) window,istransparent) ;
230}
231#endif
232
233 return (pwindow);
234
235}
236
237static XW_EXT_WINDOW *PwindowList =NULL ;
238
239#ifdef XW_PROTOTYPE
240XW_EXT_WINDOW* Xw_add_window_structure(int size)
241#else
242XW_EXT_WINDOW* Xw_add_window_structure(size)
243int size ;
244#endif /*XW_PROTOTYPE*/
245/*
246 Create and Insert one Extended window structure in the
247 EXtended Window List
248
249 returns Extended window address if successful
250 or NULL if Bad Allocation
251*/
252{
253XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) Xw_malloc(size) ;
254
255 if( pwindow ) {
256 pwindow->type = WINDOW_TYPE ;
257 pwindow->link = PwindowList ;
258 pwindow->other = NULL ;
259 PwindowList = pwindow ;
260 } else {
261 /*ERROR*EXT_WINDOW allocation failed*/
262 Xw_set_error(69,"Xw_add_window_structure",0) ;
263 }
264
265 return (pwindow) ;
266}
267
268#ifdef XW_PROTOTYPE
269XW_EXT_WINDOW* Xw_get_window_structure(Window window)
270#else
271XW_EXT_WINDOW* Xw_get_window_structure(window)
272Window window ;
273#endif /*XW_PROTOTYPE*/
274/*
275 Return the Extended window address corresponding to the required
276 Window Id or NULL if not found
277*/
278{
279XW_EXT_WINDOW *pwindow = PwindowList ;
280
281 while (pwindow) {
282 if( pwindow->window == window ) {
283 break ;
284 }
285 pwindow = (XW_EXT_WINDOW*) pwindow->link ;
286 }
287
288 return (pwindow) ;
289}
290
291#ifdef XW_PROTOTYPE
292XW_STATUS Xw_close_window (void* awindow,int destroy)
293#else
294XW_STATUS Xw_close_window (awindow,destroy)
295void *awindow;
296int destroy;
297#endif /*XW_PROTOTYPE*/
298{
299XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
300int i ;
301
302 if( !pwindow ) {
303 while( Xw_del_window_structure(NULL) ) ;
304 } else {
305 if( destroy ) {
306#ifdef PURIFY
307 XFreeGC(_DISPLAY,pwindow->qgwind.gc);
308 XFreeGC(_DISPLAY,pwindow->qgwind.gcclear);
309 XFreeGC(_DISPLAY,pwindow->qgwind.gccopy);
310 XFreeGC(_DISPLAY,pwindow->qgwind.gchigh);
311
312 for( i=0 ; i<MAXQG ; i++ ) {
313 XFreeGC(_DISPLAY,pwindow->qgline[i].gc);
314 XFreeGC(_DISPLAY,pwindow->qgmark[i].gc);
315 XFreeGC(_DISPLAY,pwindow->qgpoly[i].gc);
316 XFreeGC(_DISPLAY,pwindow->qgtext[i].gc);
317 }
318#endif
319 XDestroyWindow(_DISPLAY,_WINDOW) ;
320 }
321 Xw_del_window_structure(pwindow) ;
322 }
323
324#ifdef TRACE_CLOSE_WINDOW
325if( Xw_get_trace() ) {
326 printf (" Xw_close_window(%lx,%d)\n",(long ) pwindow,destroy) ;
327}
328#endif
329
330 return (XW_SUCCESS);
331}
332
333#ifdef XW_PROTOTYPE
334XW_STATUS Xw_del_window_structure(XW_EXT_WINDOW* pwindow)
335#else
336XW_STATUS Xw_del_window_structure(pwindow)
337XW_EXT_WINDOW *pwindow;
338#endif /*XW_PROTOTYPE*/
339/*
340 Remove the Extended window address or the next from the Extended List
341 and Free the Extended Window
342
343 returns ERROR if the window address is not Found in the list
344 or NO more Window exist
345 returns SUCCESS if successful
346*/
347{
348XW_EXT_WINDOW *qwindow = PwindowList ;
349int i ;
350
351 if( !qwindow ) return (XW_ERROR) ;
352
353 if( pwindow == qwindow ) {
354 PwindowList = (XW_EXT_WINDOW*) pwindow->link ;
355 } else if( !pwindow ) {
356 if( !PwindowList ) return (XW_ERROR) ;
357 pwindow = PwindowList ;
358 PwindowList = (XW_EXT_WINDOW*) PwindowList->link ;
359 } else {
360 for( ; qwindow ; qwindow = (XW_EXT_WINDOW*) qwindow->link ) {
361 if( qwindow->link == pwindow ) {
362 qwindow->link = pwindow->link ;
363 break ;
364 }
365 }
366 }
367
368 if( _PIXMAP ) {
369 Xw_close_pixmap(pwindow) ;
370 }
371
372 if( _BIMAGE ) {
373 Xw_close_image(_BIMAGE) ;
374 _BIMAGE = NULL;
375 }
376
377 if( _BPIXMAP ) {
378 Xw_close_background_pixmap(pwindow) ;
379 _BPIXMAP = 0;
380 }
381
382 Xw_close_buffer(pwindow,0) ;
383
384 for( i=1 ; i<MAXBUFFERS ; i++ ) {
385 Xw_close_buffer(pwindow,-i) ;
386 }
387
388 if( pwindow->other ) Xw_free(pwindow->other) ;
389
390 if( _COLORMAP && (_COLORMAP->maxwindow > 0) ) {
391 _COLORMAP->maxwindow -= 1;
392 }
393
394 Xw_free(pwindow) ;
395
396 return (XW_SUCCESS) ;
397}
398
399#ifdef XW_PROTOTYPE
400XW_STATUS Xw_reset_attrib(XW_EXT_WINDOW* awindow)
401#else
402XW_STATUS Xw_reset_attrib(awindow)
403XW_EXT_WINDOW *awindow ;
404#endif /*XW_PROTOTYPE*/
405/*
406 Reset ALL Window attributes of a particular Window or ALL Windows
407 if NULL
408*/
409{
410XW_EXT_WINDOW *pwindow ;
411unsigned long highpixel,backpixel ;
412int i ;
413
414 if( !(pwindow = PwindowList) ) return (XW_ERROR) ;
415
416 while (pwindow) {
417 if( !awindow || (pwindow == awindow) ) {
418 for( i=0 ; i<MAXQG ; i++ ) {
419 pwindow->qgline[i].code = ~0 ;
420 pwindow->qgpoly[i].code = ~0 ;
421 pwindow->qgtext[i].code = ~0 ;
422 pwindow->qgmark[i].code = ~0 ;
423 }
424 if( _COLORMAP ) {
425 highpixel = _COLORMAP->highpixel ;
426 if( pwindow->backindex < 0 ) {
427 backpixel = _COLORMAP->backpixel ;
428 } else {
429 backpixel = _COLORMAP->pixels[pwindow->backindex] ;
430 }
431 XSetForeground(_DISPLAY, pwindow->qgwind.gccopy, highpixel) ;
432 highpixel ^= backpixel ;
433 XSetForeground(_DISPLAY, pwindow->qgwind.gchigh, highpixel) ;
434 }
435 }
436 pwindow = (XW_EXT_WINDOW*) pwindow->link ;
437 }
438
439 return (XW_SUCCESS) ;
440}
441
442#ifdef XW_PROTOTYPE
443XW_STATUS Xw_get_color_attrib(XW_EXT_WINDOW* awindow,
444 XW_DRAWMODE mode,int color,unsigned long* hcolor,
445 int* function,unsigned long* planemask)
446#else
447XW_STATUS Xw_get_color_attrib(awindow,mode,color,hcolor,function,planemask)
448XW_EXT_WINDOW *awindow ;
449XW_DRAWMODE mode ;
450int color ;
451int *function ;
452unsigned long *planemask ;
453unsigned long *hcolor ;
454#endif /*XW_PROTOTYPE*/
455/*
456 Returns the best drawing attributs color,function and planemask
457 depending of write mode and colormap visual class attached to this
458 window .
459
460 returns ERROR if the Visual class is not authorized
461 returns SUCCESS if successfull
462*/
463{
464XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow ;
465
466 switch ( _CLASS ) {
467
468 case TrueColor :
469
470 switch (mode) {
471 case XW_ERASE :
472 if( pwindow->backindex >= 0 )
473 *hcolor = _COLORMAP->pixels[pwindow->backindex] ;
474 else *hcolor = _COLORMAP->backpixel;
475 *function = GXcopy ;
476 *planemask = AllPlanes ;
477 break ;
478 case XW_REPLACE :
479 *hcolor = _COLORMAP->pixels[color] ;
480 *function = GXcopy ;
481 *planemask = AllPlanes ;
482 break ;
483 case XW_XORBACK :
484 if( pwindow->backindex >= 0 )
485 *hcolor = _COLORMAP->pixels[pwindow->backindex]
486 ^ _COLORMAP->pixels[color] ;
487 else *hcolor = _COLORMAP->backpixel
488 ^ _COLORMAP->pixels[color] ;
489 *function = GXxor ;
490 *planemask = AllPlanes ;
491 break ;
492 case XW_XORLIGHT :
493 case XW_HIGHLIGHT :
494 case XW_UNHIGHLIGHT :
495 *hcolor = _COLORMAP->highpixel ^ _COLORMAP->pixels[color] ;
496 *function = GXxor ;
497 *planemask = AllPlanes ;
498 break ;
499 }
500 break ;
501
502 case PseudoColor :
503
504 switch (mode) {
505 case XW_ERASE :
506 if( pwindow->backindex >= 0 )
507 *hcolor = _COLORMAP->pixels[pwindow->backindex] ;
508 else *hcolor = _COLORMAP->backpixel;
509 *function = GXcopy ;
510 *planemask = AllPlanes ;
511 break ;
512 case XW_REPLACE :
513 *hcolor = _COLORMAP->pixels[color] ;
514 *function = GXcopy ;
515 *planemask = AllPlanes ;
516 break ;
517 case XW_XORBACK :
518 if( pwindow->backindex >= 0 )
519 *hcolor = _COLORMAP->pixels[pwindow->backindex]
520 ^ _COLORMAP->pixels[color] ;
521 else *hcolor = _COLORMAP->backpixel
522 ^ _COLORMAP->pixels[color] ;
523 *function = GXxor ;
524 *planemask = AllPlanes ;
525 break ;
526 case XW_XORLIGHT :
527 case XW_HIGHLIGHT :
528 case XW_UNHIGHLIGHT :
529 *hcolor = _COLORMAP->highpixel ^ _COLORMAP->pixels[color] ;
530 *function = GXxor ;
531 *planemask = AllPlanes ;
532 break ;
533 }
534 break ;
535
536 case StaticColor :
537
538 switch (mode) {
539 case XW_ERASE :
540 if( pwindow->backindex >= 0 )
541 *hcolor = _COLORMAP->pixels[pwindow->backindex] ;
542 else *hcolor = _COLORMAP->backpixel;
543 *function = GXcopy ;
544 *planemask = AllPlanes ;
545 break ;
546 case XW_REPLACE :
547 *hcolor = _COLORMAP->pixels[color] ;
548 *function = GXcopy ;
549 *planemask = AllPlanes ;
550 break ;
551 case XW_XORBACK :
552 if( pwindow->backindex >= 0 )
553 *hcolor = _COLORMAP->pixels[pwindow->backindex]
554 ^ _COLORMAP->pixels[color] ;
555 else *hcolor = _COLORMAP->backpixel
556 ^ _COLORMAP->pixels[color] ;
557 *function = GXxor ;
558 *planemask = AllPlanes ;
559 break ;
560 case XW_XORLIGHT :
561 case XW_HIGHLIGHT :
562 case XW_UNHIGHLIGHT :
563 *hcolor = _COLORMAP->highpixel ^ _COLORMAP->pixels[color] ;
564 *function = GXxor ;
565 *planemask = AllPlanes ;
566 break ;
567 }
568 break ;
569
570 case StaticGray :
571 case GrayScale :
572 case DirectColor :
573 /*ERROR*Unimplemented Visual class*/
574 Xw_set_error(5,"Xw_get_color_attrib",&_CLASS) ;
575 return (XW_ERROR) ;
576 }
577
578 return (XW_SUCCESS) ;
579}
580
581#ifdef S3593
582#ifdef XW_PROTOTYPE
583void Xw_set_clipping(void* awindow, int flag)
584#else
585void Xw_set_clipping(awindow,flag)
586void* awindow;
587int flag;
588#endif
589{
590XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow;
591
592 if( !Xw_isdefine_window(pwindow) ) {
593 /*ERROR*Bad EXT_WINDOW Address*/
594 Xw_set_error(24,"Xw_set_clipping",pwindow) ;
595 return;
596 }
597
598 pwindow->clipflag = flag;
599}
600
601#ifdef XW_PROTOTYPE
602int Xw_get_clipping(void* awindow)
603#else
604int Xw_get_clipping(awindow)
605void* awindow;
606#endif
607{
608XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*) awindow;
609
610 if( !Xw_isdefine_window(pwindow) ) {
611 /*ERROR*Bad EXT_WINDOW Address*/
612 Xw_set_error(24,"Xw_get_clipping",pwindow) ;
613 return (True) ;
614 }
615
616 return pwindow->clipflag;
617}
618#endif /*S3593*/