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 | |
19 | #include <Xw_Extension.h> |
20 | |
b311480e |
21 | /* ifdef then trace on */ |
7fd59977 |
22 | #ifdef TRACE |
23 | #define TRACE_GET_WINDOW_POSITION |
24 | #define TRACE_SET_WINDOW_POSITION |
25 | #define TRACE_GET_WINDOW_SIZE |
26 | #define TRACE_GET_WINDOW_STATE |
27 | #endif |
28 | |
29 | /* |
30 | WINDOWSTATE Xw_get_window_position (awindow,xc,yc,width,height): |
31 | XW_EXT_WINDOW *awindow |
32 | int *xc,*yc,*width,*height |
33 | |
34 | Returns the window Center position & Size in Pixel space |
35 | of the X window |
36 | |
37 | returns Window status,must be : |
38 | |
39 | POP The window is at the top of the screen |
40 | PUSH The window is at the bottom of the screen |
41 | ICONIFY The window is not mapped at the screen |
42 | UNKNOWN The window state is Unknown |
43 | |
44 | |
45 | STATUS Xw_set_window_position (awindow,xc,yc,width,height): |
46 | XW_EXT_WINDOW *awindow |
47 | int xc,yc,width,height |
48 | |
49 | Sets the window Center position & Size in Pixel space |
50 | of the X window |
51 | |
52 | returns ERROR if ExtendedWindowAddress is missing |
53 | returns SUCCESS if Successfull |
54 | |
55 | STATUS Xw_get_window_size (awindow,width,height): |
56 | XW_EXT_WINDOW *awindow |
57 | int *width,*height |
58 | |
59 | Returns the window Size in Pixel space |
60 | of the X window |
61 | |
62 | WINDOWSTATE Xw_get_window_state (awindow): |
63 | XW_EXT_WINDOW *awindow |
64 | |
65 | Returns the Window status,must be : |
66 | |
67 | POP The window is at the top of the screen |
68 | PUSH The window is at the bottom of the screen |
69 | ICONIFY The window is not mapped at the screen |
70 | UNKNOWN The window state is Unknown |
71 | */ |
72 | |
73 | #ifdef XW_PROTOTYPE |
74 | XW_WINDOWSTATE Xw_get_window_position (void *awindow,int *xc,int *yc,int *width,int *height) |
75 | #else |
76 | XW_WINDOWSTATE Xw_get_window_position (awindow,xc,yc,width,height) |
77 | void *awindow; |
78 | int *xc,*yc,*width,*height ; |
79 | #endif /*XW_PROTOTYPE*/ |
80 | { |
81 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
82 | XW_WINDOWSTATE state ; |
83 | Window child ; |
84 | |
85 | if( !Xw_isdefine_window(pwindow) ) { |
86 | /*ERROR*Bad EXT_WINDOW Address*/ |
87 | Xw_set_error(24,"Xw_get_window_position",pwindow) ; |
88 | return (XW_WS_UNKNOWN) ; |
89 | } |
90 | |
91 | XFlush(_DISPLAY) ; |
92 | |
93 | if( !XGetWindowAttributes(_DISPLAY,_WINDOW,&_ATTRIBUTES) ) { |
94 | /*ERROR*Bad Window Attributes*/ |
95 | Xw_set_error(54,"Xw_get_window_position",&_WINDOW) ; |
96 | return (XW_WS_UNKNOWN) ; |
97 | } |
98 | XTranslateCoordinates(_DISPLAY,_ROOT,_WINDOW,0,0,&_X,&_Y,&child) ; |
99 | _X = -_X ; _Y = -_Y ; |
100 | *xc = _X + _WIDTH/2 ; |
101 | *yc = _Y + _HEIGHT/2 ; |
102 | *width = _WIDTH ; |
103 | *height = _HEIGHT ; |
104 | switch (_STATE) { |
105 | case IsUnmapped : |
106 | state = XW_ICONIFY ; |
107 | break ; |
108 | case IsUnviewable : |
109 | state = XW_PUSH ; |
110 | break ; |
111 | case IsViewable : |
112 | state = XW_MAP ; |
113 | break ; |
114 | |
115 | default : |
116 | state = XW_WS_UNKNOWN ; |
117 | } |
118 | |
119 | #ifdef TRACE_GET_WINDOW_POSITION |
120 | if( Xw_get_trace() > 1 ) { |
121 | printf (" %d = Xw_get_window_position(%lx,%d,%d,%d,%d)\n", |
122 | state,(long ) pwindow,*xc,*yc,*width,*height) ; |
123 | } |
124 | #endif |
125 | |
126 | return (state) ; |
127 | } |
128 | |
129 | #ifdef XW_PROTOTYPE |
130 | XW_STATUS Xw_set_window_position (void *awindow,int xc,int yc,int width,int height) |
131 | #else |
132 | XW_STATUS Xw_set_window_position (awindow,xc,yc,width,height) |
133 | void *awindow ; |
134 | int xc,yc,width,height ; |
135 | #endif /*XW_PROTOTYPE*/ |
136 | { |
137 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
138 | int awidth,aheight,xleft,ytop,mask = 0 ; |
139 | XWindowChanges values ; |
140 | |
141 | if( !Xw_isdefine_window(pwindow) ) { |
142 | /*ERROR*Bad EXT_WINDOW Address*/ |
143 | Xw_set_error(24,"Xw_set_window_position",pwindow) ; |
144 | return (XW_ERROR) ; |
145 | } |
146 | |
147 | xleft = xc - width/2 ; |
148 | if( abs(xleft - pwindow->axleft) > 2 ) { |
149 | values.x = xleft ; mask |= CWX ; |
150 | } |
151 | |
152 | ytop = yc - height/2 ; |
153 | if( abs(ytop - pwindow->aytop) > 2 ) { |
154 | values.y = ytop ; mask |= CWY ; |
155 | } |
156 | |
157 | awidth = pwindow->axright - pwindow->axleft + 1 ; |
158 | if( abs(width - awidth) > 2 ) { |
159 | values.width = width ; mask |= CWWidth ; |
160 | } |
161 | |
162 | aheight = pwindow->aybottom - pwindow->aytop + 1 ; |
163 | if( abs(height - aheight) > 2 ) { |
164 | values.height = height ; mask |= CWHeight ; |
165 | } |
166 | |
167 | if( mask ) { |
168 | XConfigureWindow(_DISPLAY,_WINDOW,mask,&values) ; |
169 | XSync(_DISPLAY,True) ; |
170 | } |
171 | |
172 | #ifdef TRACE_SET_WINDOW_POSITION |
173 | if( Xw_get_trace() > 1 ) { |
174 | printf (" Xw_set_window_position(%lx,%d,%d,%d,%d)\n", |
175 | (long ) pwindow,xc,yc,width,height) ; |
176 | } |
177 | #endif |
178 | |
179 | return (XW_SUCCESS) ; |
180 | } |
181 | |
182 | #ifdef XW_PROTOTYPE |
183 | XW_STATUS Xw_get_window_size (void *awindow,int *width,int *height) |
184 | #else |
185 | XW_STATUS Xw_get_window_size (awindow,width,height) |
186 | void *awindow; |
187 | int *width,*height ; |
188 | #endif /*XW_PROTOTYPE*/ |
189 | { |
190 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
191 | |
192 | if( !Xw_isdefine_window(pwindow) ) { |
193 | /*ERROR*Bad EXT_WINDOW Address*/ |
194 | Xw_set_error(24,"Xw_get_window_size",pwindow) ; |
195 | return (XW_ERROR) ; |
196 | } |
197 | |
198 | if( (_WIDTH > 0) && (_HEIGHT > 0) ) { |
199 | *width = _WIDTH ; |
200 | *height = _HEIGHT ; |
201 | } else { |
202 | int xc,yc; |
203 | Xw_get_window_position (pwindow,&xc,&yc,width,height); |
204 | } |
205 | |
206 | #ifdef TRACE_GET_WINDOW_SIZE |
207 | if( Xw_get_trace() > 1 ) { |
208 | printf (" Xw_get_window_size(%lx,%d,%d)\n",(long ) pwindow,*width,*height) ; |
209 | } |
210 | #endif |
211 | |
212 | return (XW_SUCCESS) ; |
213 | } |
214 | |
215 | #ifdef XW_PROTOTYPE |
216 | XW_WINDOWSTATE Xw_get_window_state (void *awindow) |
217 | #else |
218 | XW_WINDOWSTATE Xw_get_window_state (awindow) |
219 | void *awindow; |
220 | #endif /*XW_PROTOTYPE*/ |
221 | { |
222 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
223 | XW_WINDOWSTATE state ; |
224 | |
225 | if( (_WIDTH > 0) && (_HEIGHT > 0) ) { |
226 | switch (_STATE) { |
227 | case IsUnmapped : |
228 | state = XW_ICONIFY ; |
229 | break ; |
230 | case IsUnviewable : |
231 | state = XW_PUSH ; |
232 | break ; |
233 | case IsViewable : |
234 | state = XW_MAP ; |
235 | break ; |
236 | |
237 | default : |
238 | state = XW_WS_UNKNOWN ; |
239 | } |
240 | } else { |
241 | int xc,yc,w,h; |
242 | state = Xw_get_window_position (pwindow,&xc,&yc,&w,&h); |
243 | } |
244 | |
245 | #ifdef TRACE_GET_WINDOW_STATE |
246 | if( Xw_get_trace() > 1 ) { |
247 | printf (" %d = Xw_get_window_state(%lx)\n",state,(long ) pwindow) ; |
248 | } |
249 | #endif |
250 | |
251 | return state; |
252 | } |