1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 // include windows.h first to have all definitions available
19 #include <Aspect_Convert.hxx>
20 #include <Aspect_WindowDefinitionError.hxx>
21 #include <Aspect_WindowError.hxx>
22 #include <Image_AlienPixMap.hxx>
23 #include <Standard_Type.hxx>
24 #include <WNT_WClass.hxx>
25 #include <WNT_Window.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(WNT_Window,Aspect_Window)
31 // =======================================================================
32 // function : WNT_Window
34 // =======================================================================
35 WNT_Window::WNT_Window (const Standard_CString theTitle,
36 const Handle(WNT_WClass)& theClass,
37 const WNT_Dword& theStyle,
38 const Standard_Integer thePxLeft,
39 const Standard_Integer thePxTop,
40 const Standard_Integer thePxWidth,
41 const Standard_Integer thePxHeight,
42 const Quantity_NameOfColor theBackColor,
43 const Aspect_Handle theParent,
44 const Aspect_Handle theMenu,
45 const Standard_Address theClientStruct)
49 aXRight (thePxLeft + thePxWidth),
50 aYBottom (thePxTop + thePxHeight),
52 myIsForeign (Standard_False)
54 DWORD dwStyle = theStyle;
56 if (thePxWidth <= 0 || thePxHeight <= 0)
58 Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
61 if (theParent && !(theStyle & WS_CHILD))
63 dwStyle |= WS_CHILD | WS_CLIPSIBLINGS;
65 else if (!theParent && !(theStyle & WS_CLIPCHILDREN))
67 dwStyle |= WS_CLIPCHILDREN;
70 // include decorations in the window dimensions
71 // to reproduce same behaviour of Xw_Window.
74 aRect.bottom = aYBottom;
76 aRect.right = aXRight;
77 AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE);
80 aXRight = aRect.right;
81 aYBottom = aRect.bottom;
83 myHWindow = CreateWindow (
84 myWClass->Name(), // window's class name
85 theTitle, // window's name
86 dwStyle, // window's style
87 aXLeft, aYTop, // window's coordinates
88 (aXRight - aXLeft), (aYBottom - aYTop),
89 (HWND )theParent, // window's parent
90 (HMENU )theMenu, // window's menu
91 (HINSTANCE )myWClass->Instance(), // application's instance
92 theClientStruct); // pointer to CLIENTCREATESTRUCT
95 Aspect_WindowDefinitionError::Raise ("Unable to create window");
98 myHParentWindow = theParent;
99 SetBackground (theBackColor);
102 // =======================================================================
103 // function : WNT_Window
105 // =======================================================================
106 WNT_Window::WNT_Window (const Aspect_Handle theHandle,
107 const Quantity_NameOfColor theBackColor)
108 : myIsForeign (Standard_True)
110 myHWindow = theHandle;
111 myHParentWindow = GetParent ((HWND )theHandle);
113 SetBackground (theBackColor);
115 WINDOWPLACEMENT aPlace;
116 aPlace.length = sizeof (WINDOWPLACEMENT);
117 ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
119 aXLeft = aPlace.rcNormalPosition.left;
120 aYTop = aPlace.rcNormalPosition.top;
121 aXRight = aPlace.rcNormalPosition.right;
122 aYBottom = aPlace.rcNormalPosition.bottom;
125 // =======================================================================
126 // function : Destroy
128 // =======================================================================
129 void WNT_Window::Destroy()
131 if (myHWindow == NULL
137 DestroyWindow ((HWND )myHWindow);
138 myIsForeign = Standard_False;
141 // =======================================================================
142 // function : SetCursor
144 // =======================================================================
145 void WNT_Window::SetCursor (const Aspect_Handle theCursor) const
147 ::SetClassLongPtr ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor);
150 // =======================================================================
151 // function : IsMapped
153 // =======================================================================
154 Standard_Boolean WNT_Window::IsMapped() const
158 return Standard_True;
161 WINDOWPLACEMENT aPlace;
162 aPlace.length = sizeof (WINDOWPLACEMENT);
163 ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
164 return !(aPlace.showCmd == SW_HIDE
165 || aPlace.showCmd == SW_MINIMIZE);
168 // =======================================================================
171 // =======================================================================
172 void WNT_Window::Map() const
180 // =======================================================================
183 // =======================================================================
184 void WNT_Window::Map (const Standard_Integer theMapMode) const
191 ::ShowWindow ((HWND )myHWindow, theMapMode);
192 ::UpdateWindow ((HWND )myHWindow);
195 // =======================================================================
198 // =======================================================================
199 void WNT_Window::Unmap() const
204 // =======================================================================
205 // function : DoResize
207 // =======================================================================
208 Aspect_TypeOfResize WNT_Window::DoResize() const
212 return Aspect_TOR_UNKNOWN;
216 Aspect_TypeOfResize mode = Aspect_TOR_UNKNOWN;
219 wp.length = sizeof ( WINDOWPLACEMENT );
220 GetWindowPlacement ( ( HWND )myHWindow, &wp );
222 if (wp.showCmd != SW_SHOWMINIMIZED)
224 if (Abs (wp.rcNormalPosition.left - aXLeft ) > 2) mask |= 1;
225 if (Abs (wp.rcNormalPosition.right - aXRight ) > 2) mask |= 2;
226 if (Abs (wp.rcNormalPosition.top - aYTop ) > 2) mask |= 4;
227 if (Abs (wp.rcNormalPosition.bottom - aYBottom) > 2) mask |= 8;
232 mode = Aspect_TOR_NO_BORDER;
235 mode = Aspect_TOR_LEFT_BORDER;
238 mode = Aspect_TOR_RIGHT_BORDER;
241 mode = Aspect_TOR_TOP_BORDER;
244 mode = Aspect_TOR_LEFT_AND_TOP_BORDER;
247 mode = Aspect_TOR_TOP_AND_RIGHT_BORDER;
250 mode = Aspect_TOR_BOTTOM_BORDER;
253 mode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
256 mode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
262 *((Standard_Integer* )&aXLeft ) = wp.rcNormalPosition.left;
263 *((Standard_Integer* )&aXRight ) = wp.rcNormalPosition.right;
264 *((Standard_Integer* )&aYTop ) = wp.rcNormalPosition.top;
265 *((Standard_Integer* )&aYBottom) = wp.rcNormalPosition.bottom;
271 // =======================================================================
274 // =======================================================================
275 Quantity_Ratio WNT_Window::Ratio() const
279 return Quantity_Ratio(aXRight - aXLeft)/ Quantity_Ratio(aYBottom - aYTop);
283 GetClientRect ((HWND )myHWindow, &aRect);
284 return Quantity_Ratio(aRect.right - aRect.left) / Quantity_Ratio(aRect.bottom - aRect.top);
287 // =======================================================================
288 // function : Position
290 // =======================================================================
291 void WNT_Window::Position (Standard_Integer& theX1, Standard_Integer& theY1,
292 Standard_Integer& theX2, Standard_Integer& theY2) const
304 ::GetClientRect ((HWND )myHWindow, &aRect);
306 POINT aPntLeft, aPntRight;
307 aPntLeft.x = aPntLeft.y = 0;
308 ::ClientToScreen ((HWND )myHWindow, &aPntLeft);
309 aPntRight.x = aRect.right;
310 aPntRight.y = aRect.bottom;
311 ::ClientToScreen ((HWND )myHWindow, &aPntRight);
313 if (myHParentWindow != NULL)
315 ::ScreenToClient ((HWND )myHParentWindow, &aPntLeft);
316 ::ScreenToClient ((HWND )myHParentWindow, &aPntRight);
325 // =======================================================================
328 // =======================================================================
329 void WNT_Window::Size (Standard_Integer& theWidth,
330 Standard_Integer& theHeight) const
334 theWidth = aXRight - aXLeft;
335 theHeight = aYBottom - aYTop;
340 ::GetClientRect ((HWND )myHWindow, &aRect);
341 theWidth = aRect.right;
342 theHeight = aRect.bottom;
345 // =======================================================================
348 // =======================================================================
349 void WNT_Window::SetPos (const Standard_Integer theX, const Standard_Integer theY,
350 const Standard_Integer theX1, const Standard_Integer theY1)