summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_open_window.cxx
blob: c1322765d2f7e233af437dff8870db00d74cde6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <Xw_Extension.h>
#include <Aspect_Convert.hxx>

/* ifdef then trace on */
#ifdef TRACE
#define TRACE_OPEN_WINDOW
#define TRACE_OPEN_DISPLAY
#endif

/*
   Aspect_Handle Xw_open_window (adisplay,class,parent,sxc,syc,
        swidth,sheight,title,istransparent):
   XW_EXT_DISPLAY *adisplay Extended Display structure
   Xw_TypeOfVisual class ;  must be one of :
      Xw_TOV_STATICGRAY,
      Xw_TOV_GRAYSCALE,
      Xw_TOV_STATICCOLOR,
      Xw_TOV_PSEUDOCOLOR,
      Xw_TOV_TRUECOLOR,
      Xw_TOV_DIRECTCOLOR,
      Xw_TOV_DEFAULT
      Xw_TOV_PREFERRED_PSEUDOCOLOR,
      Xw_TOV_PREFERRED_TRUECOLOR
   Aspect_Handle  parent ; Parent Window (ROOT if 0)

   float sxc,syc ;    Window center position in [0,1] space
   float swidth,sheight   Window size in [0,1] space
   char *title ;  Banner Title NULL if default.
   int istransparent  TRUE for transparent window

  Create the window depending of the requested visual class
  on the specified display name

  returns XW_ERROR if Display string or Visual class is wrong
        returns his ID if successful .

*/

#define BORDER 0

#ifdef XW_PROTOTYPE
Aspect_Handle Xw_open_window (void* adisplay,
                              Xw_TypeOfVisual aclass,
                              Aspect_Handle parent,
                              float sxc,
                              float syc,
                              float swidth,
                              float sheight,
                              char* title,
                              int istransparent)
#else
Aspect_Handle Xw_open_window (adisplay, aclass, parent, sxc, syc, swidth, sheight, title, istransparent)
void *adisplay;
Xw_TypeOfVisual aclass;
Aspect_Handle parent;
float sxc, syc, swidth, sheight;
char *title;
int istransparent;
#endif /*XW_PROTOTYPE*/
{
XW_EXT_DISPLAY* pdisplay = (XW_EXT_DISPLAY* )adisplay;
Window window;
XSetWindowAttributes wattr;
unsigned long mask = 0;

  if (!Xw_isdefine_display (pdisplay))
  {
    /*ERROR*Bad EXT_DISPLAY Address*/
    Xw_set_error (96, "Xw_open_window", pdisplay);
    return (0) ;
  }

  if (swidth <= 0.0 || sheight <= 0.0)
  {
    /*ERROR*Coordinate must be in [0,1] space*/
    Xw_set_error (91, "Xw_open_window", 0);
    return (0);
  }

  XVisualInfo* ginfo = Xw_get_visual_info (pdisplay, aclass);
  if (!ginfo) return (0);

  Standard_Integer aParentSizeX, aParentSizeY;
  if (parent)
  {
    XWindowAttributes attributes;
    if( !XGetWindowAttributes(_DDISPLAY, parent, &attributes))
    {
      /*ERROR*Bad Window Attributes*/
      Xw_set_error (54, "Xw_open_window", &parent);
      return (0);
    }
    aParentSizeX = attributes.width;
    aParentSizeY = attributes.height;
    wattr.override_redirect = True ; mask |= CWOverrideRedirect;
  }
  else
  {
    parent = _DROOT;
    aParentSizeX = _DWIDTH;
    aParentSizeY = _DHEIGHT;
  }
  Standard_Integer aPxLeft, aPxTop, aPxWidth, aPxHeight;
  Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY,
                                      sxc, syc, swidth, sheight,
                                      aPxLeft, aPxTop, aPxWidth, aPxHeight);
  Aspect_Convert::FitIn (aParentSizeX, aParentSizeY,
                         aPxLeft, aPxTop, aPxWidth, aPxHeight);

  wattr.event_mask = ExposureMask | StructureNotifyMask;
    mask |= CWEventMask;
  wattr.backing_store = NotUseful;
    mask |= CWBackingStore;
  wattr.border_pixel = WhitePixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
    mask |= CWBorderPixel;
  if (!istransparent)
  {
    wattr.background_pixel = BlackPixel (_DDISPLAY, DefaultScreen (_DDISPLAY));
    mask |= CWBackPixel;
  }
  wattr.colormap = XCreateColormap (_DDISPLAY, parent,
                                    ginfo->visual, AllocNone);
    mask |= CWColormap ;

  window = XCreateWindow (_DDISPLAY, parent,
                          aPxLeft, aPxTop, aPxWidth, aPxHeight, BORDER,
                          ginfo->depth, InputOutput, ginfo->visual,
                          mask, &wattr);

  if (window && (parent == _DROOT))
  {
    XSizeHints hints;
    hints.x = aPxLeft; hints.y = aPxTop; hints.flags = PPosition;
    hints.width = aPxWidth; hints.height = aPxHeight; hints.flags |= PSize;
    XSetStandardProperties (_DDISPLAY, window, title, title, None,
                            NULL, 0, &hints);
  }

  XFree ((char* )ginfo);
  XFlush (_DDISPLAY);

#ifdef  TRACE_OPEN_WINDOW
  if (Xw_get_trace())
  {
    printf (" %lx = Xw_open_window(%lx,%d,%f,%f,%f,%f,'%s')\n",
    (long )window, (long )adisplay, aclass, sxc, syc, swidth, sheight, title);
  }
#endif
  return (window);
}