0023414: Remove deprecated classes Xw_PixMap and WNT_PixMap
[occt.git] / src / Xw / Xw_open_display.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 TEST /* GG_220998
19// Ne pas detruire ls structure display qui peut etre
20// utilisee par plusieurs windows d'ou plantage
21// a la destruction (pb de liberation du static destructeur)
22*/
23
24#define RIC120302 /* GG Add Xw_set_display function to pass
25// Display structure directly
26// Add Xw_get_display_name function to retrieve
27// the display string.
28*/
29
30#include <Xw_Extension.h>
31#include <string.h>
32
33 /* ifdef then trace on */
34#ifdef TRACE
35#define TRACE_OPEN_DISPLAY
36#define TRACE_CLOSE_DISPLAY
37#define TRACE_GET_DISPLAY
38#define TRACE_GET_DISPLAY_NAME
39#define TRACE_SET_DISPLAY
40#endif
41
42/*
43
44 XW_EXT_DISPLAY* Xw_open_display(displayname)
45
46 char *displayname ; Display Name must be "NODE:[:]server.screen"
47 or NULL if default screen.
48 Return the ext display address corresponding to the required displayname
49 or NULL if name is wrong or Display is protected
50
51 XW_EXT_DISPLAY* Xw_get_display(connexion)
52
53 char *connexion ; Display Name must be "NODE:[:]server.screen"
54 or NULL if default screen.
55 Return the ext display address corresponding to the required displayname
56 or NULL if Display is no more open
57
58 char* Xw_get_display_name(adisplay)
59
60 XW_EXT_DISPLAY* adisplay ;
61
62 Returns the display name.
63
64
65 XW_EXT_DISPLAY* Xw_set_display(vdisplay)
66
67 Display* vdisplay ; Display structure pointer.
68 Return the ext display address corresponding to the required displayname
69 or NULL if vdisplay is NULL
70
71 XW_STATUS Xw_close_display(adisplay)
72
73 XW_EXT_DISPLAY* adisplay ;
74
75 Close ALL ressources attached to this display
76
77 int Xw_get_plane_layer(adisplay,visualid);
78
79 XW_EXT_DISPLAY* adisplay
80 int visualid
81
82 Returns the plane layer ID from the Visual ID.
83
84*/
85
86#ifdef XW_PROTOTYPE
87int Xw_get_plane_layer(void* adisplay,int visualid)
88#else
89int Xw_get_plane_layer(adisplay,visualid)
90void* adisplay;
91int visualid;
92#endif /*XW_PROTOTYPE*/
93/*
94 GETS the plane layer ID from visual ID
95*/
96{
97XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*) adisplay ;
98static Atom oatom = 0;
99int layer = 0;
100
101 if( !oatom ) {
102 oatom = XInternAtom(_DDISPLAY, "SERVER_OVERLAY_VISUALS", True);
103 }
104 if( oatom ) {
105 unsigned long nitem,left;
106 int aformat;
107 Status status;
108 union {
109 unsigned char *string;
110 XOverlayVisualInfo *oinfo;
111 } prop;
112 Atom aatom;
113 status = XGetWindowProperty(_DDISPLAY, _DROOT,
114 oatom, 0, 100, False,
115 AnyPropertyType, &aatom, &aformat,
116 &nitem, &left, &prop.string);
117 nitem /= 4;
118 if( (status == Success) && (aformat == 32) && (nitem > 0) ) {
119 int i;
120 for( i=0 ; (unsigned int ) i < nitem ; i++ ) {
121 if( prop.oinfo[i].overlay_visual == visualid ) {
122 layer = prop.oinfo[i].layer;
123 break;
124 }
125 }
126 }
127 } else if( pdisplay->server == XW_SERVER_IS_SUN ) {
128 int mOptCode,fEvent,fError;
129 if( XQueryExtension(_DDISPLAY,"SUN_OVL",&mOptCode,&fEvent,&fError) ) {
130 if( visualid == 0x2a ) layer = 1;
131 }
132 }
133
134 return layer;
135}
136
137extern int Xw_error_handler() ;
138
139#ifdef XW_PROTOTYPE
140void* Xw_open_display(char* connexion)
141#else
142void* Xw_open_display(connexion)
143char *connexion ;
144#endif /*XW_PROTOTYPE*/
145/*
146 OPEN the display and
147 Return the display address corresponding to the required displayname
148 or NULL if name is wrong or Display is protected
149*/
150{
151XW_EXT_DISPLAY *pdisplay ;
152//XW_STATUS status ;
153char *vendor ;
154
155 pdisplay = (XW_EXT_DISPLAY*) Xw_get_display(connexion) ;
156
157 if( !pdisplay ) {
158 pdisplay = Xw_add_display_structure(sizeof(XW_EXT_DISPLAY)) ;
159 }
160
161 if( !pdisplay ) return (NULL) ;
162
163 if( !_DDISPLAY ) {
164 _DDISPLAY = XOpenDisplay(connexion) ;
165 if( _DDISPLAY ) {
166 vendor = ServerVendor(_DDISPLAY) ;
167 if( !strncmp(vendor,"DEC",3) )
168 pdisplay->server = XW_SERVER_IS_DEC ;
169 else if( !strncmp(vendor,"Sil",3) )
170 pdisplay->server = XW_SERVER_IS_SGI ;
171 else if( !strncmp(vendor,"Sun",3) )
172 pdisplay->server = XW_SERVER_IS_SUN ;
173 else if( !strncmp(vendor,"Hew",3) )
174 pdisplay->server = XW_SERVER_IS_HP ;
175 else pdisplay->server = XW_SERVER_IS_UNKNOWN ;
176 pdisplay->gname = (char*)strdup(connexion) ;
177
178 _DSCREEN = DefaultScreenOfDisplay(_DDISPLAY) ;
179 _DVISUAL = DefaultVisualOfScreen(_DSCREEN) ;
180 _DCOLORMAP = DefaultColormapOfScreen(_DSCREEN) ;
181 _DROOT = RootWindowOfScreen(_DSCREEN) ;
182 _DWIDTH = WidthOfScreen(_DSCREEN) ;
183 _DHEIGHT = HeightOfScreen(_DSCREEN) ;
184 _DGC = DefaultGCOfScreen(_DSCREEN) ;
185 XSetFunction(_DDISPLAY,_DGC,GXxor) ;
186
187 if( Xw_get_trace() > 0 ) {
188 Xw_set_synchronize(_DDISPLAY,True) ;
189 } else {
190 Xw_set_synchronize(_DDISPLAY,False) ;
191 XSetErrorHandler(Xw_error_handler) ;
192 }
193
194#ifdef TRACE_OPEN_DISPLAY
195if( Xw_get_trace() ) {
196 printf (" Xw_Server_Vendor is '%s' on Display '%s->%s'\n",
197 vendor,connexion,DisplayString(_DDISPLAY));
198 printf(" Xw_ProtocolVersion is %d,Revision is %d\n",
199 ProtocolVersion(_DDISPLAY),ProtocolRevision(_DDISPLAY));
200}
201#endif
202 } else {
203 /*ERROR*Bad Display connexion*/
204 Xw_set_error(66,"Xw_open_display",connexion) ;
205 Xw_del_display_structure(pdisplay) ;
206 pdisplay = NULL ;
207 }
208 }
209
210#ifdef TRACE_OPEN_DISPLAY
211if( Xw_get_trace() ) {
212 printf (" %lx = Xw_open_display('%s')\n",(long ) pdisplay,connexion) ;
213}
214#endif
215
216 return (pdisplay) ;
217}
218
219/*RIC120302*/
220#ifdef XW_PROTOTYPE
221char* Xw_get_display_name(void* adisplay)
222#else
223char* Xw_get_display_name(aDisplay)
224void* adisplay;
225#endif /*XW_PROTOTYPE*/
226/*
227 Retrieve the display name
228*/
229{
230XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ;
231char *connexion;
232
233 if( !Xw_isdefine_display(pdisplay) ) {
234 /*ERROR*Bad EXT_DISPLAY Address*/
235 Xw_set_error(96,"Xw_get_display_name",pdisplay) ;
236 return (NULL) ;
237 }
238
239 connexion = DisplayString(_DDISPLAY);
240
241#ifdef TRACE_GET_DISPLAY_NAME
242if( Xw_get_trace() ) {
243 printf (" '%s' = Xw_get_display_name(%x)\n", connexion, (long ) pdisplay) ;
244}
245#endif
246 return connexion;
247}
248
249#ifdef XW_PROTOTYPE
250void* Xw_set_display(void *vdisplay)
251#else
252void* Xw_open_display(vdisplay)
253void *vdisplay ;
254#endif /*XW_PROTOTYPE*/
255/*
256 REGISTER the display and
257 Return the ext display address
258 or NULL if the vdisplay is wrong
259*/
260{
261XW_EXT_DISPLAY *pdisplay ;
262//XW_STATUS status ;
263char *vendor,*connexion ;
264
265 if( !vdisplay ) return (NULL) ;
266
267 connexion = DisplayString((Display*)vdisplay);
268 pdisplay = (XW_EXT_DISPLAY*) Xw_get_display(connexion) ;
269
270 if( !pdisplay ) {
271 pdisplay = Xw_add_display_structure(sizeof(XW_EXT_DISPLAY)) ;
272 }
273
274 if( !pdisplay ) return (NULL) ;
275
276 if( !_DDISPLAY ) {
277 _DDISPLAY = (Display*)vdisplay ;
278 vendor = ServerVendor(_DDISPLAY) ;
279 if( !strncmp(vendor,"DEC",3) )
280 pdisplay->server = XW_SERVER_IS_DEC ;
281 else if( !strncmp(vendor,"Sil",3) )
282 pdisplay->server = XW_SERVER_IS_SGI ;
283 else if( !strncmp(vendor,"Sun",3) )
284 pdisplay->server = XW_SERVER_IS_SUN ;
285 else if( !strncmp(vendor,"Hew",3) )
286 pdisplay->server = XW_SERVER_IS_HP ;
287 else pdisplay->server = XW_SERVER_IS_UNKNOWN ;
288 pdisplay->gname = (char*)strdup(connexion) ;
289
290 _DSCREEN = DefaultScreenOfDisplay(_DDISPLAY) ;
291 _DVISUAL = DefaultVisualOfScreen(_DSCREEN) ;
292 _DCOLORMAP = DefaultColormapOfScreen(_DSCREEN) ;
293 _DROOT = RootWindowOfScreen(_DSCREEN) ;
294 _DWIDTH = WidthOfScreen(_DSCREEN) ;
295 _DHEIGHT = HeightOfScreen(_DSCREEN) ;
296 _DGC = DefaultGCOfScreen(_DSCREEN) ;
297 XSetFunction(_DDISPLAY,_DGC,GXxor) ;
298
299 if( Xw_get_trace() > 0 ) {
300 Xw_set_synchronize(_DDISPLAY,True) ;
301 } else {
302 Xw_set_synchronize(_DDISPLAY,False) ;
303 XSetErrorHandler(Xw_error_handler) ;
304 }
305
306#ifdef TRACE_SET_DISPLAY
307if( Xw_get_trace() ) {
308 printf (" Xw_Server_Vendor is '%s' on Display '%s->%s'\n",
309 vendor,connexion,DisplayString(_DDISPLAY));
310 printf(" Xw_ProtocolVersion is %d,Revision is %d\n",
311 ProtocolVersion(_DDISPLAY),ProtocolRevision(_DDISPLAY));
312}
313#endif
314 }
315
316#ifdef TRACE_SET_DISPLAY
317if( Xw_get_trace() ) {
318 printf (" %lx = Xw_set_display(%x = '%s')\n",
319 (long ) pdisplay,vdisplay,connexion) ;
320}
321#endif
322
323 return (pdisplay) ;
324}
325/*RIC120302*/
326
327static XW_EXT_DISPLAY *PdisplayList = NULL ;
328
329#ifdef XW_PROTOTYPE
330void* Xw_get_display(char* uname)
331#else
332void* Xw_get_display(uname)
333char *uname ;
334#endif /*XW_PROTOTYPE*/
335/*
336 Return the display address corresponding to the required displayname
337 or NULL if Display is no more open
338*/
339{
340XW_EXT_DISPLAY *pdisplay ;
341
342 for( pdisplay=PdisplayList ; pdisplay ;
343 pdisplay = (XW_EXT_DISPLAY*) pdisplay->link ) {
344 if( pdisplay->display ) {
345 if( !uname || !strlen(uname) ||
346 !strcmp(pdisplay->gname,uname) ) break ;
347 }
348 }
349
350 return (pdisplay) ;
351}
352
353#ifdef XW_PROTOTYPE
354XW_STATUS Xw_close_display(void* adisplay)
355#else
356XW_STATUS Xw_close_display(adisplay)
357void *adisplay ;
358#endif /*XW_PROTOTYPE*/
359/*
360 Close the Display
361*/
362{
363XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ;
364
365 if( !Xw_isdefine_display(pdisplay) ) {
366 /*ERROR*Bad EXT_DISPLAY Address*/
367 Xw_set_error(96,"Xw_close_display",pdisplay) ;
368 return (XW_ERROR) ;
369 }
370
371 if( !pdisplay ) {
372 while( Xw_del_display_structure(NULL) ) ;
373 } else {
374#ifndef TEST
375 Xw_del_display_structure(pdisplay) ;
376#endif
377 }
378
379#ifdef TRACE_CLOSE_DISPLAY
380if( Xw_get_trace() ) {
381 printf (" Xw_close_display(%lx)\n",(long ) pdisplay) ;
382}
383#endif
384
385 return (XW_SUCCESS) ;
386}
387
388#ifdef XW_PROTOTYPE
389void Xw_set_synchronize(Display* display,int state)
390#else
391void Xw_set_synchronize(display,state)
392Display *display ;
393int state ;
394#endif /*XW_PROTOTYPE*/
395/*
396 Set Synchronization on display or ALL display if NULL
397*/
398{
399XW_EXT_DISPLAY *pdisplay ;
400//int i,sync = (state > 0) ? True : False ;
401int sync = (state > 0) ? True : False ;
402
403 if( display ) {
404 XSynchronize(display,sync) ;
405 } else {
406 for( pdisplay=PdisplayList ; pdisplay ;
407 pdisplay = (XW_EXT_DISPLAY*) pdisplay->link) {
408 XSynchronize(_DDISPLAY,sync) ;
409 }
410 }
411}
412
413#ifdef XW_PROTOTYPE
414XW_EXT_DISPLAY* Xw_add_display_structure(int size)
415#else
416XW_EXT_DISPLAY* Xw_add_display_structure(size)
417int size ;
418#endif /*XW_PROTOTYPE*/
419/*
420 Create and Insert one Extended display structure in the
421 EXtended Display List
422
423 returns Extended display address if successful
424 or NULL if Bad Allocation
425*/
426{
427XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*) Xw_malloc(size) ;
428
429 if( pdisplay ) {
430 pdisplay->type = DISPLAY_TYPE ;
431 pdisplay->link = PdisplayList ;
432 pdisplay->display = NULL ;
433 pdisplay->screen = NULL ;
434 pdisplay->visual = NULL ;
435 pdisplay->colormap = 0 ;
436 pdisplay->rootwindow = 0 ;
437 pdisplay->grabwindow = 0 ;
438 pdisplay->gamma = 0. ;
439 pdisplay->gname = NULL ;
440 PdisplayList = pdisplay ;
441 } else {
442 /*ERROR*EXT_DISPLAY allocation failed*/
443 Xw_set_error(94,"Xw_add_display_structure",0) ;
444 }
445
446 return (pdisplay) ;
447}
448
449#ifdef XW_PROTOTYPE
450XW_EXT_DISPLAY* Xw_get_display_structure(Display *display)
451#else
452XW_EXT_DISPLAY* Xw_get_display_structure(display)
453Display *display ;
454#endif /*XW_PROTOTYPE*/
455/*
456 Return the Extended display address corresponding to the required
457 Display Id or NULL if not found
458*/
459{
460XW_EXT_DISPLAY *pdisplay = PdisplayList ;
461
462 while (pdisplay) {
463 if( _DDISPLAY == display ) {
464 break ;
465 }
466 pdisplay = (XW_EXT_DISPLAY*) pdisplay->link ;
467 }
468
469 return (pdisplay) ;
470}
471
472#ifdef XW_PROTOTYPE
473XW_STATUS Xw_del_display_structure(XW_EXT_DISPLAY* pdisplay)
474#else
475XW_STATUS Xw_del_display_structure(pdisplay)
476XW_EXT_DISPLAY *pdisplay;
477#endif /*XW_PROTOTYPE*/
478/*
479 Remove the Extended display address or the next from the Extended List
480 and Free the Extended Display
481
482 returns ERROR if the display address is not Found in the list
483 or NO more Display exist
484 returns SUCCESS if successful
485*/
486{
487XW_EXT_DISPLAY *qdisplay = PdisplayList ;
488//int i ;
489
490 if( !qdisplay ) return (XW_ERROR) ;
491
492 if( pdisplay == qdisplay ) {
493 PdisplayList = (XW_EXT_DISPLAY*) pdisplay->link ;
494 } else if( !pdisplay ) {
495 if( !PdisplayList ) return (XW_ERROR) ;
496 pdisplay = PdisplayList ;
497 PdisplayList = (XW_EXT_DISPLAY*) PdisplayList->link ;
498 } else {
499 for( ; qdisplay ; qdisplay = (XW_EXT_DISPLAY*) qdisplay->link ) {
500 if( qdisplay->link == pdisplay ) {
501 qdisplay->link = pdisplay->link ;
502 break ;
503 }
504 }
505 }
506#ifdef BUG
507 if( _DDISPLAY ) XCloseDisplay(_DDISPLAY) ;
508#endif
509
510 if( pdisplay->gname ) Xw_free(pdisplay->gname);
511 Xw_free(pdisplay) ;
512
513 return (XW_SUCCESS) ;
514}
515
516#ifndef Xw_malloc
517void* Xw_malloc(size)
518int size ;
519/*
520 Dynamic Memory allocation of char size
521*/
522{
523void *address ;
524
525 address = malloc(size) ;
526
527 return (address) ;
528}
529#endif
530
531#ifndef Xw_calloc
532void* Xw_calloc(length,size)
533int length,size ;
534/*
535 Dynamic Memory allocation of char length*size and set memory to 0
536*/
537{
538void *address ;
539
540 address = calloc(length,size) ;
541
542 return (address) ;
543}
544#endif
545
546#ifndef Xw_free
547void Xw_free(address)
548void *address ;
549/*
550 Free Dynamic memory
551*/
552{
553 free(address) ;
554}
555#endif
556
557#ifdef XW_PROTOTYPE
558void Xw_longcopy (register long* from,register long* to,register unsigned n)
559#else
560void Xw_longcopy (from,to,n)
561 register long *from,*to ;
562 register unsigned n;
563#endif
564/*
565 Copy long from to ...
566*/
567{
568 while ( n ) {
569 *to++ = *from++ ;
570 --n ;
571 }
572}
573
574#ifdef XW_PROTOTYPE
575void Xw_shortcopy (register short* from,register short* to,register unsigned n)
576#else
577void Xw_shortcopy (from,to,n)
578 register short *from,*to ;
579 register unsigned n;
580#endif
581/*
582 Copy short from to ...
583*/
584{
585 while ( n ) {
586 *to++ = *from++ ;
587 --n ;
588 }
589}
590
591#ifdef XW_PROTOTYPE
592void Xw_bytecopy (register char* from,register char* to,register unsigned n)
593#else
594void Xw_bytecopy (from,to,n)
595 register char *from,*to ;
596 register unsigned n;
597#endif
598/*
599 Copy byte from to ...
600*/
601{
602 while ( n ) {
603 *to++ = *from++ ;
604 --n ;
605 }
606}