Adjusting test cases at new structure of OCCT
[occt.git] / src / WNT / WNT_Window.cxx
CommitLineData
b311480e 1// Copyright (c) 1998-1999 Matra Datavision
973c2be1 2// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
b311480e 14
7fd59977 15// include windows.h first to have all definitions available
16#include <windows.h>
17
7fd59977 18
7fd59977 19#include <Aspect_Convert.hxx>
42cf5bc1 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>
7fd59977 26
27#include <stdio.h>
eaf5c5e0 28// =======================================================================
29// function : WNT_Window
30// purpose :
31// =======================================================================
dc3fe572 32WNT_Window::WNT_Window (const Standard_CString theTitle,
7fd59977 33 const Handle(WNT_WClass)& theClass,
34 const WNT_Dword& theStyle,
35 const Standard_Integer thePxLeft,
36 const Standard_Integer thePxTop,
37 const Standard_Integer thePxWidth,
38 const Standard_Integer thePxHeight,
39 const Quantity_NameOfColor theBackColor,
40 const Aspect_Handle theParent,
41 const Aspect_Handle theMenu,
42 const Standard_Address theClientStruct)
dc3fe572 43: Aspect_Window(),
7fd59977 44 aXLeft (thePxLeft),
45 aYTop (thePxTop),
46 aXRight (thePxLeft + thePxWidth),
47 aYBottom (thePxTop + thePxHeight),
eaf5c5e0 48 myWClass (theClass),
49 myIsForeign (Standard_False)
7fd59977 50{
7fd59977 51 DWORD dwStyle = theStyle;
7fd59977 52
53 if (thePxWidth <= 0 || thePxHeight <= 0)
54 {
55 Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range");
56 }
57
58 if (theParent && !(theStyle & WS_CHILD))
59 {
60 dwStyle |= WS_CHILD | WS_CLIPSIBLINGS;
61 }
62 else if (!theParent && !(theStyle & WS_CLIPCHILDREN))
63 {
64 dwStyle |= WS_CLIPCHILDREN;
65 }
66
7fe83417 67 // include decorations in the window dimensions
68 // to reproduce same behaviour of Xw_Window.
69 RECT aRect;
70 aRect.top = aYTop;
71 aRect.bottom = aYBottom;
72 aRect.left = aXLeft;
73 aRect.right = aXRight;
74 AdjustWindowRect (&aRect, dwStyle, theMenu != NULL ? TRUE : FALSE);
75 aXLeft = aRect.left;
76 aYTop = aRect.top;
77 aXRight = aRect.right;
78 aYBottom = aRect.bottom;
7fd59977 79
80 myHWindow = CreateWindow (
81 myWClass->Name(), // window's class name
82 theTitle, // window's name
83 dwStyle, // window's style
84 aXLeft, aYTop, // window's coordinates
85 (aXRight - aXLeft), (aYBottom - aYTop),
86 (HWND )theParent, // window's parent
87 (HMENU )theMenu, // window's menu
88 (HINSTANCE )myWClass->Instance(), // application's instance
89 theClientStruct); // pointer to CLIENTCREATESTRUCT
90 if (!myHWindow)
91 {
92 Aspect_WindowDefinitionError::Raise ("Unable to create window");
93 }
94
7fd59977 95 myHParentWindow = theParent;
7fd59977 96 SetBackground (theBackColor);
eaf5c5e0 97}
dc3fe572 98
eaf5c5e0 99// =======================================================================
100// function : WNT_Window
101// purpose :
102// =======================================================================
103WNT_Window::WNT_Window (const Aspect_Handle theHandle,
104 const Quantity_NameOfColor theBackColor)
105: myIsForeign (Standard_True)
106{
107 myHWindow = theHandle;
108 myHParentWindow = GetParent ((HWND )theHandle);
7fd59977 109
eaf5c5e0 110 SetBackground (theBackColor);
7fd59977 111
eaf5c5e0 112 WINDOWPLACEMENT aPlace;
113 aPlace.length = sizeof (WINDOWPLACEMENT);
114 ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
115
116 aXLeft = aPlace.rcNormalPosition.left;
117 aYTop = aPlace.rcNormalPosition.top;
118 aXRight = aPlace.rcNormalPosition.right;
119 aYBottom = aPlace.rcNormalPosition.bottom;
7fd59977 120}
121
eaf5c5e0 122// =======================================================================
123// function : Destroy
124// purpose :
125// =======================================================================
126void WNT_Window::Destroy()
dc3fe572 127{
eaf5c5e0 128 if (myHWindow == NULL
129 || myIsForeign)
130 {
131 return;
132 }
7fd59977 133
eaf5c5e0 134 DestroyWindow ((HWND )myHWindow);
135 myIsForeign = Standard_False;
136}
7fd59977 137
eaf5c5e0 138// =======================================================================
139// function : SetCursor
140// purpose :
141// =======================================================================
142void WNT_Window::SetCursor (const Aspect_Handle theCursor) const
143{
144 ::SetClassLongPtr ((HWND )myHWindow, GCLP_HCURSOR, (LONG_PTR )theCursor);
145}
7fd59977 146
eaf5c5e0 147// =======================================================================
148// function : IsMapped
149// purpose :
150// =======================================================================
151Standard_Boolean WNT_Window::IsMapped() const
dc3fe572 152{
eaf5c5e0 153 if (IsVirtual())
7fd59977 154 {
587630c5 155 return Standard_True;
7fd59977 156 }
157
eaf5c5e0 158 WINDOWPLACEMENT aPlace;
159 aPlace.length = sizeof (WINDOWPLACEMENT);
160 ::GetWindowPlacement ((HWND )myHWindow, &aPlace);
161 return !(aPlace.showCmd == SW_HIDE
162 || aPlace.showCmd == SW_MINIMIZE);
163}
dc3fe572 164
eaf5c5e0 165// =======================================================================
166// function : Map
167// purpose :
168// =======================================================================
169void WNT_Window::Map() const
170{
171 if (!IsVirtual())
172 {
173 Map (SW_SHOW);
7fd59977 174 }
eaf5c5e0 175}
176
177// =======================================================================
178// function : Map
179// purpose :
180// =======================================================================
181void WNT_Window::Map (const Standard_Integer theMapMode) const
182{
183 if (IsVirtual())
184 {
7fd59977 185 return;
186 }
7fd59977 187
eaf5c5e0 188 ::ShowWindow ((HWND )myHWindow, theMapMode);
189 ::UpdateWindow ((HWND )myHWindow);
190}
7fd59977 191
eaf5c5e0 192// =======================================================================
193// function : Unmap
194// purpose :
195// =======================================================================
196void WNT_Window::Unmap() const
197{
198 Map (SW_HIDE);
199}
dc3fe572 200
eaf5c5e0 201// =======================================================================
202// function : DoResize
203// purpose :
204// =======================================================================
205Aspect_TypeOfResize WNT_Window::DoResize() const
dc3fe572 206{
207 int mask = 0;
208 Aspect_TypeOfResize mode = Aspect_TOR_UNKNOWN;
209 WINDOWPLACEMENT wp;
7fd59977 210
dc3fe572 211 wp.length = sizeof ( WINDOWPLACEMENT );
212 GetWindowPlacement ( ( HWND )myHWindow, &wp );
7fd59977 213
dc3fe572 214 if (wp.showCmd != SW_SHOWMINIMIZED)
215 {
216 if (Abs (wp.rcNormalPosition.left - aXLeft ) > 2) mask |= 1;
217 if (Abs (wp.rcNormalPosition.right - aXRight ) > 2) mask |= 2;
218 if (Abs (wp.rcNormalPosition.top - aYTop ) > 2) mask |= 4;
219 if (Abs (wp.rcNormalPosition.bottom - aYBottom) > 2) mask |= 8;
220
221 switch (mask)
222 {
223 case 0:
224 mode = Aspect_TOR_NO_BORDER;
225 break;
226 case 1:
227 mode = Aspect_TOR_LEFT_BORDER;
228 break;
229 case 2:
230 mode = Aspect_TOR_RIGHT_BORDER;
231 break;
232 case 4:
233 mode = Aspect_TOR_TOP_BORDER;
234 break;
235 case 5:
236 mode = Aspect_TOR_LEFT_AND_TOP_BORDER;
237 break;
238 case 6:
239 mode = Aspect_TOR_TOP_AND_RIGHT_BORDER;
240 break;
241 case 8:
242 mode = Aspect_TOR_BOTTOM_BORDER;
243 break;
244 case 9:
245 mode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER;
246 break;
247 case 10:
248 mode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER;
249 break;
250 default:
251 break;
252 } // end switch
253
254 *((Standard_Integer* )&aXLeft ) = wp.rcNormalPosition.left;
255 *((Standard_Integer* )&aXRight ) = wp.rcNormalPosition.right;
256 *((Standard_Integer* )&aYTop ) = wp.rcNormalPosition.top;
257 *((Standard_Integer* )&aYBottom) = wp.rcNormalPosition.bottom;
258 }
7fd59977 259
dc3fe572 260 return mode;
7fd59977 261}
262
eaf5c5e0 263// =======================================================================
264// function : Ratio
265// purpose :
266// =======================================================================
267Quantity_Ratio WNT_Window::Ratio() const
dc3fe572 268{
eaf5c5e0 269 RECT r;
270 GetClientRect ((HWND )myHWindow, &r);
271 return (Quantity_Ratio )((Quantity_Ratio )r.right / (Quantity_Ratio )r.bottom);
272}
7fd59977 273
eaf5c5e0 274// =======================================================================
275// function : Position
276// purpose :
277// =======================================================================
278void WNT_Window::Position (Standard_Integer& theX1, Standard_Integer& theY1,
279 Standard_Integer& theX2, Standard_Integer& theY2) const
280{
281 RECT aRect;
282 ::GetClientRect ((HWND )myHWindow, &aRect);
7fd59977 283
eaf5c5e0 284 POINT aPntLeft, aPntRight;
285 aPntLeft.x = aPntLeft.y = 0;
286 ::ClientToScreen ((HWND )myHWindow, &aPntLeft);
287 aPntRight.x = aRect.right;
288 aPntRight.y = aRect.bottom;
289 ::ClientToScreen ((HWND )myHWindow, &aPntRight);
7fd59977 290
eaf5c5e0 291 if (myHParentWindow != NULL)
7fd59977 292 {
eaf5c5e0 293 ::ScreenToClient ((HWND )myHParentWindow, &aPntLeft);
294 ::ScreenToClient ((HWND )myHParentWindow, &aPntRight);
7fd59977 295 }
296
eaf5c5e0 297 theX1 = aPntLeft.x;
298 theX2 = aPntRight.x;
299 theY1 = aPntLeft.y;
300 theY2 = aPntRight.y;
301}
7fd59977 302
eaf5c5e0 303// =======================================================================
304// function : Size
305// purpose :
306// =======================================================================
307void WNT_Window::Size (Standard_Integer& theWidth,
308 Standard_Integer& theHeight) const
309{
310 RECT aRect;
311 ::GetClientRect ((HWND )myHWindow, &aRect);
312 theWidth = aRect.right;
313 theHeight = aRect.bottom;
314}
7fd59977 315
eaf5c5e0 316// =======================================================================
317// function : SetPos
318// purpose :
319// =======================================================================
320void WNT_Window::SetPos (const Standard_Integer theX, const Standard_Integer theY,
321 const Standard_Integer theX1, const Standard_Integer theY1)
322{
323 aXLeft = theX;
324 aYTop = theY;
325 aXRight = theX1;
326 aYBottom = theY1;
327}