1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
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)
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.
30 #include <Xw_Extension.h>
33 /* ifdef then trace on */
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
44 XW_EXT_DISPLAY* Xw_open_display(displayname)
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
51 XW_EXT_DISPLAY* Xw_get_display(connexion)
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
58 char* Xw_get_display_name(adisplay)
60 XW_EXT_DISPLAY* adisplay ;
62 Returns the display name.
65 XW_EXT_DISPLAY* Xw_set_display(vdisplay)
67 Display* vdisplay ; Display structure pointer.
68 Return the ext display address corresponding to the required displayname
69 or NULL if vdisplay is NULL
71 XW_STATUS Xw_close_display(adisplay)
73 XW_EXT_DISPLAY* adisplay ;
75 Close ALL ressources attached to this display
77 int Xw_get_plane_layer(adisplay,visualid);
79 XW_EXT_DISPLAY* adisplay
82 Returns the plane layer ID from the Visual ID.
87 int Xw_get_plane_layer(void* adisplay,int visualid)
89 int Xw_get_plane_layer(adisplay,visualid)
92 #endif /*XW_PROTOTYPE*/
94 GETS the plane layer ID from visual ID
97 XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*) adisplay ;
98 static Atom oatom = 0;
102 oatom = XInternAtom(_DDISPLAY, "SERVER_OVERLAY_VISUALS", True);
105 unsigned long nitem,left;
109 unsigned char *string;
110 XOverlayVisualInfo *oinfo;
113 status = XGetWindowProperty(_DDISPLAY, _DROOT,
114 oatom, 0, 100, False,
115 AnyPropertyType, &aatom, &aformat,
116 &nitem, &left, &prop.string);
118 if( (status == Success) && (aformat == 32) && (nitem > 0) ) {
120 for( i=0 ; (unsigned int ) i < nitem ; i++ ) {
121 if( prop.oinfo[i].overlay_visual == visualid ) {
122 layer = prop.oinfo[i].layer;
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;
137 extern int Xw_error_handler() ;
140 void* Xw_open_display(char* connexion)
142 void* Xw_open_display(connexion)
144 #endif /*XW_PROTOTYPE*/
147 Return the display address corresponding to the required displayname
148 or NULL if name is wrong or Display is protected
151 XW_EXT_DISPLAY *pdisplay ;
155 pdisplay = (XW_EXT_DISPLAY*) Xw_get_display(connexion) ;
158 pdisplay = Xw_add_display_structure(sizeof(XW_EXT_DISPLAY)) ;
161 if( !pdisplay ) return (NULL) ;
164 _DDISPLAY = XOpenDisplay(connexion) ;
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) ;
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) ;
187 if( Xw_get_trace() > 0 ) {
188 Xw_set_synchronize(_DDISPLAY,True) ;
190 Xw_set_synchronize(_DDISPLAY,False) ;
191 XSetErrorHandler(Xw_error_handler) ;
194 #ifdef TRACE_OPEN_DISPLAY
195 if( 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));
203 /*ERROR*Bad Display connexion*/
204 Xw_set_error(66,"Xw_open_display",connexion) ;
205 Xw_del_display_structure(pdisplay) ;
210 #ifdef TRACE_OPEN_DISPLAY
211 if( Xw_get_trace() ) {
212 printf (" %lx = Xw_open_display('%s')\n",(long ) pdisplay,connexion) ;
221 char* Xw_get_display_name(void* adisplay)
223 char* Xw_get_display_name(aDisplay)
225 #endif /*XW_PROTOTYPE*/
227 Retrieve the display name
230 XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ;
233 if( !Xw_isdefine_display(pdisplay) ) {
234 /*ERROR*Bad EXT_DISPLAY Address*/
235 Xw_set_error(96,"Xw_get_display_name",pdisplay) ;
239 connexion = DisplayString(_DDISPLAY);
241 #ifdef TRACE_GET_DISPLAY_NAME
242 if( Xw_get_trace() ) {
243 printf (" '%s' = Xw_get_display_name(%x)\n", connexion, (long ) pdisplay) ;
250 void* Xw_set_display(void *vdisplay)
252 void* Xw_open_display(vdisplay)
254 #endif /*XW_PROTOTYPE*/
256 REGISTER the display and
257 Return the ext display address
258 or NULL if the vdisplay is wrong
261 XW_EXT_DISPLAY *pdisplay ;
263 char *vendor,*connexion ;
265 if( !vdisplay ) return (NULL) ;
267 connexion = DisplayString((Display*)vdisplay);
268 pdisplay = (XW_EXT_DISPLAY*) Xw_get_display(connexion) ;
271 pdisplay = Xw_add_display_structure(sizeof(XW_EXT_DISPLAY)) ;
274 if( !pdisplay ) return (NULL) ;
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) ;
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) ;
299 if( Xw_get_trace() > 0 ) {
300 Xw_set_synchronize(_DDISPLAY,True) ;
302 Xw_set_synchronize(_DDISPLAY,False) ;
303 XSetErrorHandler(Xw_error_handler) ;
306 #ifdef TRACE_SET_DISPLAY
307 if( 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));
316 #ifdef TRACE_SET_DISPLAY
317 if( Xw_get_trace() ) {
318 printf (" %lx = Xw_set_display(%x = '%s')\n",
319 (long ) pdisplay,vdisplay,connexion) ;
327 static XW_EXT_DISPLAY *PdisplayList = NULL ;
330 void* Xw_get_display(char* uname)
332 void* Xw_get_display(uname)
334 #endif /*XW_PROTOTYPE*/
336 Return the display address corresponding to the required displayname
337 or NULL if Display is no more open
340 XW_EXT_DISPLAY *pdisplay ;
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 ;
354 XW_STATUS Xw_close_display(void* adisplay)
356 XW_STATUS Xw_close_display(adisplay)
358 #endif /*XW_PROTOTYPE*/
363 XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ;
365 if( !Xw_isdefine_display(pdisplay) ) {
366 /*ERROR*Bad EXT_DISPLAY Address*/
367 Xw_set_error(96,"Xw_close_display",pdisplay) ;
372 while( Xw_del_display_structure(NULL) ) ;
375 Xw_del_display_structure(pdisplay) ;
379 #ifdef TRACE_CLOSE_DISPLAY
380 if( Xw_get_trace() ) {
381 printf (" Xw_close_display(%lx)\n",(long ) pdisplay) ;
385 return (XW_SUCCESS) ;
389 void Xw_set_synchronize(Display* display,int state)
391 void Xw_set_synchronize(display,state)
394 #endif /*XW_PROTOTYPE*/
396 Set Synchronization on display or ALL display if NULL
399 XW_EXT_DISPLAY *pdisplay ;
400 //int i,sync = (state > 0) ? True : False ;
401 int sync = (state > 0) ? True : False ;
404 XSynchronize(display,sync) ;
406 for( pdisplay=PdisplayList ; pdisplay ;
407 pdisplay = (XW_EXT_DISPLAY*) pdisplay->link) {
408 XSynchronize(_DDISPLAY,sync) ;
414 XW_EXT_DISPLAY* Xw_add_display_structure(int size)
416 XW_EXT_DISPLAY* Xw_add_display_structure(size)
418 #endif /*XW_PROTOTYPE*/
420 Create and Insert one Extended display structure in the
421 EXtended Display List
423 returns Extended display address if successful
424 or NULL if Bad Allocation
427 XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*) Xw_malloc(size) ;
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 ;
442 /*ERROR*EXT_DISPLAY allocation failed*/
443 Xw_set_error(94,"Xw_add_display_structure",0) ;
450 XW_EXT_DISPLAY* Xw_get_display_structure(Display *display)
452 XW_EXT_DISPLAY* Xw_get_display_structure(display)
454 #endif /*XW_PROTOTYPE*/
456 Return the Extended display address corresponding to the required
457 Display Id or NULL if not found
460 XW_EXT_DISPLAY *pdisplay = PdisplayList ;
463 if( _DDISPLAY == display ) {
466 pdisplay = (XW_EXT_DISPLAY*) pdisplay->link ;
473 XW_STATUS Xw_del_display_structure(XW_EXT_DISPLAY* pdisplay)
475 XW_STATUS Xw_del_display_structure(pdisplay)
476 XW_EXT_DISPLAY *pdisplay;
477 #endif /*XW_PROTOTYPE*/
479 Remove the Extended display address or the next from the Extended List
480 and Free the Extended Display
482 returns ERROR if the display address is not Found in the list
483 or NO more Display exist
484 returns SUCCESS if successful
487 XW_EXT_DISPLAY *qdisplay = PdisplayList ;
490 if( !qdisplay ) return (XW_ERROR) ;
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 ;
499 for( ; qdisplay ; qdisplay = (XW_EXT_DISPLAY*) qdisplay->link ) {
500 if( qdisplay->link == pdisplay ) {
501 qdisplay->link = pdisplay->link ;
507 if( _DDISPLAY ) XCloseDisplay(_DDISPLAY) ;
510 if( pdisplay->gname ) Xw_free(pdisplay->gname);
513 return (XW_SUCCESS) ;
517 void* Xw_malloc(size)
520 Dynamic Memory allocation of char size
525 address = malloc(size) ;
532 void* Xw_calloc(length,size)
535 Dynamic Memory allocation of char length*size and set memory to 0
540 address = calloc(length,size) ;
547 void Xw_free(address)
558 void Xw_longcopy (register long* from,register long* to,register unsigned n)
560 void Xw_longcopy (from,to,n)
561 register long *from,*to ;
565 Copy long from to ...
575 void Xw_shortcopy (register short* from,register short* to,register unsigned n)
577 void Xw_shortcopy (from,to,n)
578 register short *from,*to ;
582 Copy short from to ...
592 void Xw_bytecopy (register char* from,register char* to,register unsigned n)
594 void Xw_bytecopy (from,to,n)
595 register char *from,*to ;
599 Copy byte from to ...