0023830: BRepExtrema_DistShapeShape does not find intersection of face with edge
[occt.git] / src / Xw / Xw_open_window.cxx
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
18 #include <Xw_Extension.h>
19 #include <Aspect_Convert.hxx>
20
21 /* ifdef then trace on */
22 #ifdef TRACE
23 #define TRACE_OPEN_WINDOW
24 #define TRACE_OPEN_DISPLAY
25 #endif
26
27 /*
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 :
32       Xw_TOV_STATICGRAY,
33       Xw_TOV_GRAYSCALE,
34       Xw_TOV_STATICCOLOR,
35       Xw_TOV_PSEUDOCOLOR,
36       Xw_TOV_TRUECOLOR,
37       Xw_TOV_DIRECTCOLOR,
38       Xw_TOV_DEFAULT
39       Xw_TOV_PREFERRED_PSEUDOCOLOR,
40       Xw_TOV_PREFERRED_TRUECOLOR
41    Aspect_Handle  parent ; Parent Window (ROOT if 0)
42
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
47
48   Create the window depending of the requested visual class
49   on the specified display name
50
51   returns XW_ERROR if Display string or Visual class is wrong
52         returns his ID if successful .
53
54 */
55
56 #define BORDER 0
57
58 #ifdef XW_PROTOTYPE
59 Aspect_Handle Xw_open_window (void* adisplay,
60                               Xw_TypeOfVisual aclass,
61                               Aspect_Handle parent,
62                               float sxc,
63                               float syc,
64                               float swidth,
65                               float sheight,
66                               char* title,
67                               int istransparent)
68 #else
69 Aspect_Handle Xw_open_window (adisplay, aclass, parent, sxc, syc, swidth, sheight, title, istransparent)
70 void *adisplay;
71 Xw_TypeOfVisual aclass;
72 Aspect_Handle parent;
73 float sxc, syc, swidth, sheight;
74 char *title;
75 int istransparent;
76 #endif /*XW_PROTOTYPE*/
77 {
78 XW_EXT_DISPLAY* pdisplay = (XW_EXT_DISPLAY* )adisplay;
79 Window window;
80 XSetWindowAttributes wattr;
81 unsigned long mask = 0;
82
83   if (!Xw_isdefine_display (pdisplay))
84   {
85     /*ERROR*Bad EXT_DISPLAY Address*/
86     Xw_set_error (96, "Xw_open_window", pdisplay);
87     return (0) ;
88   }
89
90   if (swidth <= 0.0 || sheight <= 0.0)
91   {
92     /*ERROR*Coordinate must be in [0,1] space*/
93     Xw_set_error (91, "Xw_open_window", 0);
94     return (0);
95   }
96
97   XVisualInfo* ginfo = Xw_get_visual_info (pdisplay, aclass);
98   if (!ginfo) return (0);
99
100   Standard_Integer aParentSizeX, aParentSizeY;
101   if (parent)
102   {
103     XWindowAttributes attributes;
104     if( !XGetWindowAttributes(_DDISPLAY, parent, &attributes))
105     {
106       /*ERROR*Bad Window Attributes*/
107       Xw_set_error (54, "Xw_open_window", &parent);
108       return (0);
109     }
110     aParentSizeX = attributes.width;
111     aParentSizeY = attributes.height;
112     wattr.override_redirect = True ; mask |= CWOverrideRedirect;
113   }
114   else
115   {
116     parent = _DROOT;
117     aParentSizeX = _DWIDTH;
118     aParentSizeY = _DHEIGHT;
119   }
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);
126
127   wattr.event_mask = ExposureMask | StructureNotifyMask;
128     mask |= CWEventMask;
129   wattr.backing_store = NotUseful;
130     mask |= CWBackingStore;
131   wattr.border_pixel = WhitePixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
132     mask |= CWBorderPixel;
133   if (!istransparent)
134   {
135     wattr.background_pixel = BlackPixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
136     mask |= CWBackPixel;
137   }
138   wattr.colormap = XCreateColormap (_DDISPLAY, parent,
139                                     ginfo->visual, AllocNone);
140     mask |= CWColormap ;
141
142   window = XCreateWindow (_DDISPLAY, parent,
143                           aPxLeft, aPxTop, aPxWidth, aPxHeight, BORDER,
144                           ginfo->depth, InputOutput, ginfo->visual,
145                           mask, &wattr);
146
147   if (window && (parent == _DROOT))
148   {
149     XSizeHints hints;
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,
153                             NULL, 0, &hints);
154   }
155
156   XFree ((char* )ginfo);
157   XFlush (_DDISPLAY);
158
159 #ifdef  TRACE_OPEN_WINDOW
160   if (Xw_get_trace())
161   {
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);
164   }
165 #endif
166   return (window);
167 }