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 #include <Xw_Extension.h>
19 #include <Aspect_Convert.hxx>
21 /* ifdef then trace on */
23 #define TRACE_OPEN_WINDOW
24 #define TRACE_OPEN_DISPLAY
28 Aspect_Handle Xw_open_window (adisplay,class,parent,sxc,syc,
29 swidth,sheight,title,istransparent):
30 XW_EXT_DISPLAY *adisplay Extended Display structure
31 Xw_TypeOfVisual class ; must be one of :
39 Xw_TOV_PREFERRED_PSEUDOCOLOR,
40 Xw_TOV_PREFERRED_TRUECOLOR
41 Aspect_Handle parent ; Parent Window (ROOT if 0)
43 float sxc,syc ; Window center position in [0,1] space
44 float swidth,sheight Window size in [0,1] space
45 char *title ; Banner Title NULL if default.
46 int istransparent TRUE for transparent window
48 Create the window depending of the requested visual class
49 on the specified display name
51 returns XW_ERROR if Display string or Visual class is wrong
52 returns his ID if successful .
59 Aspect_Handle Xw_open_window (void* adisplay,
60 Xw_TypeOfVisual aclass,
69 Aspect_Handle Xw_open_window (adisplay, aclass, parent, sxc, syc, swidth, sheight, title, istransparent)
71 Xw_TypeOfVisual aclass;
73 float sxc, syc, swidth, sheight;
76 #endif /*XW_PROTOTYPE*/
78 XW_EXT_DISPLAY* pdisplay = (XW_EXT_DISPLAY* )adisplay;
80 XSetWindowAttributes wattr;
81 unsigned long mask = 0;
83 if (!Xw_isdefine_display (pdisplay))
85 /*ERROR*Bad EXT_DISPLAY Address*/
86 Xw_set_error (96, "Xw_open_window", pdisplay);
90 if (swidth <= 0.0 || sheight <= 0.0)
92 /*ERROR*Coordinate must be in [0,1] space*/
93 Xw_set_error (91, "Xw_open_window", 0);
97 XVisualInfo* ginfo = Xw_get_visual_info (pdisplay, aclass);
98 if (!ginfo) return (0);
100 Standard_Integer aParentSizeX, aParentSizeY;
103 XWindowAttributes attributes;
104 if( !XGetWindowAttributes(_DDISPLAY, parent, &attributes))
106 /*ERROR*Bad Window Attributes*/
107 Xw_set_error (54, "Xw_open_window", &parent);
110 aParentSizeX = attributes.width;
111 aParentSizeY = attributes.height;
112 wattr.override_redirect = True ; mask |= CWOverrideRedirect;
117 aParentSizeX = _DWIDTH;
118 aParentSizeY = _DHEIGHT;
120 Standard_Integer aPxLeft, aPxTop, aPxWidth, aPxHeight;
121 Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY,
122 sxc, syc, swidth, sheight,
123 aPxLeft, aPxTop, aPxWidth, aPxHeight);
124 Aspect_Convert::FitIn (aParentSizeX, aParentSizeY,
125 aPxLeft, aPxTop, aPxWidth, aPxHeight);
127 wattr.event_mask = ExposureMask | StructureNotifyMask;
129 wattr.backing_store = NotUseful;
130 mask |= CWBackingStore;
131 wattr.border_pixel = WhitePixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
132 mask |= CWBorderPixel;
135 wattr.background_pixel = BlackPixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
138 wattr.colormap = XCreateColormap (_DDISPLAY, parent,
139 ginfo->visual, AllocNone);
142 window = XCreateWindow (_DDISPLAY, parent,
143 aPxLeft, aPxTop, aPxWidth, aPxHeight, BORDER,
144 ginfo->depth, InputOutput, ginfo->visual,
147 if (window && (parent == _DROOT))
150 hints.x = aPxLeft; hints.y = aPxTop; hints.flags = PPosition;
151 hints.width = aPxWidth; hints.height = aPxHeight; hints.flags |= PSize;
152 XSetStandardProperties (_DDISPLAY, window, title, title, None,
156 XFree ((char* )ginfo);
159 #ifdef TRACE_OPEN_WINDOW
162 printf (" %lx = Xw_open_window(%lx,%d,%f,%f,%f,%f,'%s')\n",
163 (long )window, (long )adisplay, aclass, sxc, syc, swidth, sheight, title);