1 // Created by: NW,JPB,CAL,GG
2 // Copyright (c) 1991-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 #define BUC60701 //GG 23/06/00 Enable to dump an exact image size
21 // according to the window size
22 #define RIC120302 //GG Add a NEW XParentWindow methods which enable
23 // to retrieve the parent of the actual Xwindow ID.
28 //-Design Creation d'une fenetre X
39 #include <Xw_Window.ixx>
40 // Routines C a declarer en extern
42 #include <Xw_Cextern.hxx>
44 #include <Aspect_Convert.hxx>
45 #include <Aspect_DisplayConnection.hxx>
46 #include <Image_AlienPixMap.hxx>
47 #include <Standard_PCharacter.hxx>
49 #include <Xw_Extension.h>
51 //-Static data definitions
53 static XW_STATUS status ;
55 //============================================================================
56 //==== HashCode : Returns a HashCode CString
57 //============================================================================
58 inline Standard_Integer HashCode (const Standard_CString Value)
60 Standard_Integer i,n,aHashCode = 0;
72 strcpy(u.charPtr,Value);
75 strncpy(u.charPtr,Value,80);
78 for( i=0 ; i<n ; i++ ) {
79 aHashCode = aHashCode ^ u.intPtr[i];
83 //printf(" HashCode of '%s' is %d\n",Value,aHashCode);
85 return Abs(aHashCode) + 1;
88 void Xw_Window::PrintError() {
89 Standard_CString ErrorMessag ;
90 Standard_Integer ErrorNumber ;
91 Standard_Integer ErrorGravity ;
94 ErrorMessag = Xw_get_error(&ErrorNumber,&ErrorGravity) ;
100 //-Global data definitions
104 Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection)
106 myDisplayConnection (theDisplayConnection)
112 //=======================================================================
113 //function : Xw_Window
115 //=======================================================================
116 Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
117 const Standard_Integer aPart1,
118 const Standard_Integer aPart2,
119 const Quantity_NameOfColor BackColor)
121 myDisplayConnection (theDisplayConnection)
124 Aspect_Handle aWindow = (aPart1 << 16) | (aPart2 & 0xFFFF);
125 SetWindow (aWindow, BackColor);
128 //=======================================================================
129 //function : Xw_Window
131 //=======================================================================
132 Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
133 const Aspect_Handle aWindow,
134 const Quantity_NameOfColor BackColor)
136 myDisplayConnection (theDisplayConnection)
139 SetWindow (aWindow, BackColor);
142 //=======================================================================
143 //function : Xw_Window
145 //=======================================================================
146 Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theDisplayConnection,
147 const Standard_CString theTitle,
148 const Standard_Integer thePxLeft,
149 const Standard_Integer thePxTop,
150 const Standard_Integer theWidth,
151 const Standard_Integer theHeight,
152 const Quantity_NameOfColor theBackColor,
153 const Aspect_Handle theParent)
155 myDisplayConnection (theDisplayConnection)
159 Standard_Integer aParentSizeX = 1;
160 Standard_Integer aParentSizeY = 1;
162 Aspect_Handle aRoot, aColormap, *aDisplay;
163 Xw_TypeOfVisual aVisualClass;
164 Standard_Integer aVisualDepth;
165 Xw_get_display_info (MyExtendedDisplay,
166 &aDisplay, &aRoot, &aColormap, &aVisualClass, &aVisualDepth);
167 Xw_get_screen_size (MyExtendedDisplay, &aParentSizeX, &aParentSizeY);
170 XWindowAttributes anAttributes;
171 if(XGetWindowAttributes ((Display* )aDisplay, theParent, &anAttributes))
173 aParentSizeX = anAttributes.width;
174 aParentSizeY = anAttributes.height;
177 Quantity_Parameter aQCenterX, aQCenterY, aQSizeX, aQSizeY;
178 Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY,
179 thePxLeft, thePxTop, theWidth, theHeight,
180 aQCenterX, aQCenterY, aQSizeX, aQSizeY);
181 SetWindow (theTitle, aQCenterX, aQCenterY, aQSizeX, aQSizeY,
182 theBackColor, theParent);
185 void Xw_Window::Init()
188 MyXParentWindow = 0 ;
189 #if defined(__APPLE__) && !defined(MACOSX_USE_GLX)
190 MyExtendedDisplay = NULL;
192 MyExtendedDisplay = Xw_set_display (myDisplayConnection->GetDisplay());
194 MyExtendedWindow = NULL ;
195 MyVisualClass = Xw_TOV_TRUECOLOR;
198 //=======================================================================
199 //function : SetWindow
201 //=======================================================================
203 void Xw_Window::SetWindow (const Aspect_Handle aWindow,
204 const Quantity_NameOfColor BackColor)
206 Aspect_Handle window,root,colormap,pixmap ;
207 Xw_TypeOfVisual visualclass ;
208 int visualdepth,visualid ;
210 MyXWindow = aWindow ;
211 MyXParentWindow = aWindow ;
218 Xw_def_window (MyExtendedDisplay,MyXWindow,Standard_False);
220 status = Xw_get_window_info(MyExtendedWindow,&window,&pixmap,
221 &root,&colormap,&visualclass,
222 &visualdepth,&visualid);
227 SetBackground(BackColor) ;
230 //=======================================================================
231 //function : SetWindow
233 //=======================================================================
235 void Xw_Window::SetWindow (const Standard_CString Title,
236 const Quantity_Parameter Xc,
237 const Quantity_Parameter Yc,
238 const Quantity_Parameter Width,
239 const Quantity_Parameter Height,
240 const Quantity_NameOfColor BackColor,
241 const Aspect_Handle Parent)
243 Standard_Integer istransparent = Standard_False ;
245 MyXParentWindow = Parent ;
248 MyXWindow = Xw_open_window(MyExtendedDisplay,MyVisualClass,MyXParentWindow,
249 (float)Xc,(float)Yc,(float)Width,(float)Height,
250 (Standard_PCharacter)Title,istransparent) ;
256 Xw_def_window (MyExtendedDisplay,MyXWindow,istransparent);
258 SetBackground(BackColor) ;
260 if( MyXParentWindow && (MyXWindow != MyXParentWindow) ) Map() ;
264 void Xw_Window::Map () const {
266 if( MyXWindow == MyXParentWindow ) return;
268 if (IsVirtual()) return;
269 status = Xw_set_window_state (MyExtendedWindow, XW_MAP);
275 void Xw_Window::Unmap () const {
277 if( MyXWindow == MyXParentWindow ) return;
279 status = Xw_set_window_state (MyExtendedWindow, XW_ICONIFY);
285 Aspect_TypeOfResize Xw_Window::DoResize () const {
286 XW_RESIZETYPE state ;
288 state = Xw_resize_window (MyExtendedWindow);
289 // if( state == Aspect_TOR_UNKNOWN ) {
290 if( state == XW_TOR_UNKNOWN ) {
294 return (Aspect_TypeOfResize(state)) ;
297 Standard_Boolean Xw_Window::DoMapping () const {
298 int pxc,pyc,width,height;
299 XW_WINDOWSTATE state;
301 state = Xw_get_window_position (MyExtendedWindow,&pxc,&pyc,&width,&height);
306 void Xw_Window::Destroy () {
307 Standard_Boolean destroy =
308 ( MyXWindow == MyXParentWindow ) ? Standard_False : Standard_True;
310 status = Xw_close_window (MyExtendedWindow,destroy);
316 MyExtendedWindow = NULL ;
319 void Xw_Window::SetCursor (const Standard_Integer anId, const Quantity_NameOfColor aColor) const {
320 Quantity_Color Color(aColor) ;
321 Standard_Real r,g,b ;
323 Color.Values(r,g,b,Quantity_TOC_RGB) ;
325 status = Xw_set_hard_cursor (MyExtendedWindow,(int)anId,0,
335 Standard_Boolean Xw_Window::IsMapped () const {
337 return Standard_True;
339 XW_WINDOWSTATE state;
340 state = Xw_get_window_state (MyExtendedWindow);
343 return Standard_False;
345 return Standard_False;
347 return Standard_True;
349 return Standard_True;
352 return Standard_False;
355 return Standard_False;
358 Standard_Real Xw_Window::Ratio () const {
361 status = Xw_get_window_size (MyExtendedWindow,&width,&height);
366 return ((Standard_Real)width/height) ;
369 void Xw_Window::Size (Standard_Integer &Width, Standard_Integer &Height) const {
371 status = Xw_get_window_size (MyExtendedWindow,&width,&height);
380 void Xw_Window::Position (Standard_Integer &X1, Standard_Integer &Y1, Standard_Integer &X2, Standard_Integer &Y2) const {
381 XW_WINDOWSTATE state = XW_WS_UNKNOWN ;
385 state = Xw_get_window_position (MyExtendedWindow,
386 &pxc,&pyc,&width,&height);
387 if( state == XW_WS_UNKNOWN ) {
391 X1 = pxc - width/2 ; Y1 = pyc - height/2 ;
392 X2 = X1 + width - 1 ; Y2 = Y1 + height - 1 ;
395 Aspect_Handle Xw_Window::XWindow () const {
401 void Xw_Window::XWindow (Standard_Integer& aPart1, Standard_Integer& aPart2) const {
403 aPart1 = (Standard_Integer)((MyXWindow >> 16 ) & 0xffff);
404 aPart2 = (Standard_Integer)(MyXWindow & 0xffff);
408 Aspect_Handle Xw_Window::XParentWindow () const {
410 return (MyXParentWindow);
414 void Xw_Window::XParentWindow (Standard_Integer& aPart1, Standard_Integer& aPart2) const {
416 aPart1 = (Standard_Integer)((MyXParentWindow >> 16 ) & 0xffff);
417 aPart2 = (Standard_Integer)(MyXParentWindow & 0xffff);
421 Aspect_Handle Xw_Window::XPixmap () const {
422 Aspect_Handle window,pixmap,root,colormap ;
423 Xw_TypeOfVisual visualclass ;
424 int visualdepth,visualid ;
426 status = Xw_get_window_info(MyExtendedWindow,&window,&pixmap,
427 &root,&colormap,&visualclass,&visualdepth,&visualid) ;
432 Standard_Boolean Xw_Window::PointerPosition (Standard_Integer& X, Standard_Integer& Y) const {
433 Standard_Boolean cstatus ;
436 cstatus = Xw_get_cursor_position(MyExtendedWindow,&x,&y) ;
443 Xw_TypeOfVisual Xw_Window::VisualClass () const {
445 return (MyVisualClass);
449 Standard_Boolean Xw_Window::BackgroundPixel ( Standard_Integer &aPixel ) const {
450 unsigned long pixel ;
452 status = Xw_get_background_pixel(MyExtendedWindow,&pixel) ;
453 if( !status ) PrintError() ;
455 aPixel = Standard_Integer(pixel);
461 Standard_Address Xw_Window::ExtendedWindow () const {
463 return (MyExtendedWindow);