b311480e |
1 | // Copyright (c) 1998-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | // Modifications: PLOTNIKOV Eugeny at July 1998 (BUC60286) |
20 | // TCL at October 2000 (G002) |
21 | // new method SetBackground(CString aName) |
7fd59977 |
22 | |
23 | // include windows.h first to have all definitions available |
24 | #include <windows.h> |
25 | |
26 | // GG 07/03/00 Add MMSize() method |
27 | |
28 | #include <WNT_Window.ixx> |
29 | |
692613e5 |
30 | #include <Image_AlienPixMap.hxx> |
7fd59977 |
31 | #include <Aspect_Convert.hxx> |
32 | |
33 | #include <stdio.h> |
34 | extern "C" void _debug_break ( char* ); |
35 | //************************************************************************// |
36 | //***// |
37 | // callback function to manage window's background |
38 | extern LRESULT CALLBACK WNT_WndProc ( |
39 | HWND, UINT, WPARAM, LPARAM |
40 | ); |
41 | //***// |
42 | #define SELECT_PALETTE(hDC) \ |
43 | HPALETTE hOldPal; \ |
44 | \ |
45 | if ( myExtraData.hPal ) { \ |
46 | \ |
47 | hOldPal = SelectPalette ( hDC, myExtraData.hPal, FALSE ); \ |
48 | \ |
49 | if ( RealizePalette ( hDC ) ) \ |
50 | \ |
51 | UpdateColors ( hDC ); \ |
52 | \ |
53 | } // end if |
54 | //***// |
55 | #define UNSELECT_PALETTE(hDC) \ |
56 | if ( myExtraData.hPal ) \ |
57 | \ |
58 | SelectPalette ( hDC, hOldPal, FALSE ); |
59 | |
60 | HBITMAP LoadImageFromFile ( Handle( WNT_GraphicDevice )&, char*, HDC = NULL ); |
61 | |
62 | //***// |
63 | //************************* Constructor **********************************// |
64 | //***// |
65 | // TODO - Here is enough of duplicated code in 1st and second constructors! |
66 | WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice, |
67 | const Standard_CString theTitle, |
68 | const Handle(WNT_WClass)& theClass, |
69 | const WNT_Dword& theStyle, |
70 | const Quantity_Parameter theXc, |
71 | const Quantity_Parameter theYc, |
72 | const Quantity_Parameter theWidth, |
73 | const Quantity_Parameter theHeight, |
74 | const Quantity_NameOfColor theBackColor, |
75 | const Aspect_Handle theParent, |
76 | const Aspect_Handle theMenu, |
77 | const Standard_Address theClientStruct) |
78 | : Aspect_Window (theDevice), |
79 | myWClass (theClass) |
80 | { |
81 | ZeroMemory (&myExtraData, sizeof (WNT_WindowData)); |
82 | DWORD dwStyle = theStyle; |
83 | const Handle(WNT_GraphicDevice)& aDev = Handle(WNT_GraphicDevice)::DownCast (MyGraphicDevice); |
84 | |
85 | if (theXc < 0.0 || theXc > 1.0 || theYc < 0.0 || theYc > 1.0 || |
86 | theWidth <= 0.0 || theHeight <= 0.0) |
87 | { |
88 | Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range"); |
89 | } |
90 | |
91 | Standard_Integer aParentSizeX, aParentSizeY; |
92 | if (theParent) |
93 | { |
94 | RECT aRect; |
95 | GetClientRect ((HWND )theParent, &aRect); |
96 | aParentSizeX = aRect.right; |
97 | aParentSizeY = aRect.bottom; |
98 | } |
99 | else |
100 | { |
101 | aDev->DisplaySize (aParentSizeX, aParentSizeY); |
102 | } |
103 | |
104 | Standard_Integer aPxWidth, aPxHeight; |
105 | Aspect_Convert::ConvertCoordinates (aParentSizeX, aParentSizeY, |
106 | theXc, theYc, theWidth, theHeight, |
107 | aXLeft, aYTop, aPxWidth, aPxHeight); |
108 | Aspect_Convert::FitIn (aParentSizeX, aParentSizeY, |
109 | aXLeft, aYTop, aPxWidth, aPxHeight); |
110 | aXRight = aXLeft + aPxWidth; |
111 | aYBottom = aYTop + aPxHeight; |
112 | |
113 | if (theParent && !(theStyle & WS_CHILD)) |
114 | { |
115 | dwStyle |= WS_CHILD | WS_CLIPSIBLINGS; |
116 | } |
117 | else if (!theParent && !(theStyle & WS_CLIPCHILDREN)) |
118 | { |
119 | dwStyle |= WS_CLIPCHILDREN; |
120 | } |
121 | |
122 | if (dwStyle & WS_OVERLAPPEDWINDOW) |
123 | { |
124 | // include decorations in the window dimensions |
125 | // to reproduce same behaviour of Xw_Window. |
126 | aXLeft -= GetSystemMetrics(SM_CXSIZEFRAME); |
127 | aYTop -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION); |
128 | aXRight += GetSystemMetrics(SM_CXSIZEFRAME); |
129 | aYBottom += GetSystemMetrics(SM_CYSIZEFRAME); |
130 | } |
131 | |
132 | myHWindow = CreateWindow ( |
133 | myWClass->Name(), // window's class name |
134 | theTitle, // window's name |
135 | dwStyle, // window's style |
136 | aXLeft, aYTop, // window's coordinates |
137 | (aXRight - aXLeft), (aYBottom - aYTop), |
138 | (HWND )theParent, // window's parent |
139 | (HMENU )theMenu, // window's menu |
140 | (HINSTANCE )myWClass->Instance(), // application's instance |
141 | theClientStruct); // pointer to CLIENTCREATESTRUCT |
142 | if (!myHWindow) |
143 | { |
144 | Aspect_WindowDefinitionError::Raise ("Unable to create window"); |
145 | } |
146 | |
147 | myDoubleBuffer = Standard_False; |
148 | myHPixmap = 0; |
149 | myHParentWindow = theParent; |
150 | myWndProc = myWClass->WndProc(); |
151 | SetBackground (theBackColor); |
152 | SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc); |
153 | myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData); |
154 | |
155 | myExtraData.WNT_Window_Ptr = (void* )this; |
156 | myExtraData.hPal = (HPALETTE )aDev->HPalette(); |
157 | |
158 | myImages = new WNT_ImageManager (this); |
159 | myFormat = WNT_TOI_XWD; |
160 | |
161 | SetFlags(WDF_NOERASEBKGRND); |
162 | } |
163 | |
164 | WNT_Window::WNT_Window (const Handle(WNT_GraphicDevice)& theDevice, |
165 | const Standard_CString theTitle, |
166 | const Handle(WNT_WClass)& theClass, |
167 | const WNT_Dword& theStyle, |
168 | const Standard_Integer thePxLeft, |
169 | const Standard_Integer thePxTop, |
170 | const Standard_Integer thePxWidth, |
171 | const Standard_Integer thePxHeight, |
172 | const Quantity_NameOfColor theBackColor, |
173 | const Aspect_Handle theParent, |
174 | const Aspect_Handle theMenu, |
175 | const Standard_Address theClientStruct) |
176 | : Aspect_Window (theDevice), |
177 | aXLeft (thePxLeft), |
178 | aYTop (thePxTop), |
179 | aXRight (thePxLeft + thePxWidth), |
180 | aYBottom (thePxTop + thePxHeight), |
181 | myWClass (theClass) |
182 | { |
183 | ZeroMemory (&myExtraData, sizeof (WNT_WindowData)); |
184 | DWORD dwStyle = theStyle; |
185 | const Handle(WNT_GraphicDevice)& aDev = Handle(WNT_GraphicDevice)::DownCast (MyGraphicDevice); |
186 | |
187 | if (thePxWidth <= 0 || thePxHeight <= 0) |
188 | { |
189 | Aspect_WindowDefinitionError::Raise ("Coordinate(s) out of range"); |
190 | } |
191 | |
192 | if (theParent && !(theStyle & WS_CHILD)) |
193 | { |
194 | dwStyle |= WS_CHILD | WS_CLIPSIBLINGS; |
195 | } |
196 | else if (!theParent && !(theStyle & WS_CLIPCHILDREN)) |
197 | { |
198 | dwStyle |= WS_CLIPCHILDREN; |
199 | } |
200 | |
201 | if (dwStyle & WS_OVERLAPPEDWINDOW) |
202 | { |
203 | // include decorations in the window dimensions |
204 | // to reproduce same behaviour of Xw_Window. |
205 | aXLeft -= GetSystemMetrics(SM_CXSIZEFRAME); |
206 | aYTop -= GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYCAPTION); |
207 | aXRight += GetSystemMetrics(SM_CXSIZEFRAME); |
208 | aYBottom += GetSystemMetrics(SM_CYSIZEFRAME); |
209 | } |
210 | |
211 | myHWindow = CreateWindow ( |
212 | myWClass->Name(), // window's class name |
213 | theTitle, // window's name |
214 | dwStyle, // window's style |
215 | aXLeft, aYTop, // window's coordinates |
216 | (aXRight - aXLeft), (aYBottom - aYTop), |
217 | (HWND )theParent, // window's parent |
218 | (HMENU )theMenu, // window's menu |
219 | (HINSTANCE )myWClass->Instance(), // application's instance |
220 | theClientStruct); // pointer to CLIENTCREATESTRUCT |
221 | if (!myHWindow) |
222 | { |
223 | Aspect_WindowDefinitionError::Raise ("Unable to create window"); |
224 | } |
225 | |
226 | myDoubleBuffer = Standard_False; |
227 | myHPixmap = 0; |
228 | myHParentWindow = theParent; |
229 | myWndProc = myWClass->WndProc(); |
230 | SetBackground (theBackColor); |
231 | SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc); |
232 | myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData); |
233 | |
234 | myExtraData.WNT_Window_Ptr = (void* )this; |
235 | myExtraData.hPal = (HPALETTE )aDev->HPalette(); |
236 | |
237 | myImages = new WNT_ImageManager (this); |
238 | myFormat = WNT_TOI_XWD; |
239 | |
240 | SetFlags (WDF_NOERASEBKGRND); |
241 | } |
242 | |
243 | //***// |
244 | //************************* Constructor **********************************// |
245 | //***// |
246 | WNT_Window :: WNT_Window ( |
247 | const Handle( WNT_GraphicDevice )& aDevice, |
248 | const Aspect_Handle aHandle, |
249 | const Quantity_NameOfColor aBackColor |
250 | ) : Aspect_Window ( aDevice ) { |
251 | |
252 | doCreate ( aDevice, aHandle, aBackColor ); |
253 | |
254 | /* Bug OCC20596 */ |
255 | SetFlags(WDF_NOERASEBKGRND); |
256 | |
257 | } // end constructor |
258 | //***// |
259 | //************************* Constructor **********************************// |
260 | //***// |
261 | WNT_Window :: WNT_Window ( |
262 | const Handle( WNT_GraphicDevice )& aDevice, |
263 | const Standard_Integer aPart1, |
264 | const Standard_Integer aPart2, |
265 | const Quantity_NameOfColor aBackColor |
266 | ) : Aspect_Window ( aDevice ) { |
267 | |
268 | Aspect_Handle aHandle = ( Aspect_Handle )( ( aPart1 << 16 ) + aPart2 ); |
269 | |
270 | doCreate ( aDevice, aHandle, aBackColor ); |
271 | |
272 | /* Bug OCC20596 */ |
273 | SetFlags(WDF_NOERASEBKGRND); |
274 | |
275 | } // end constructor |
276 | //***// |
277 | //***************************** Destroy **********************************// |
278 | //***// |
279 | void WNT_Window :: Destroy () { |
280 | |
281 | if ( MyHBackground ) DeleteObject ( MyHBackground ); // delete background brush |
282 | if ( myHPixmap ) DeleteObject ( myHPixmap ); // . . . and double buffer pixmap if exists |
283 | |
284 | if ( myHWindow ) { |
285 | |
286 | if (myUsrData != Standard_Address(-1)) |
287 | { |
288 | SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )myUsrData); |
289 | } |
290 | |
291 | if (myWndProc != NULL) |
292 | { |
293 | SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )myWndProc); |
294 | } |
295 | |
296 | if ( !( myExtraData.dwFlags & WDF_FOREIGN ) ) |
297 | |
298 | DestroyWindow ( ( HWND )myHWindow ); |
299 | |
300 | } // end if |
301 | |
302 | } // end WNT_Window :: Destroy |
303 | //***// |
304 | //************************ SetBackground (1) *****************************// |
305 | //***// |
306 | void WNT_Window :: SetBackground ( const Aspect_Background& Background ) { |
307 | |
308 | SetBackground ( Background.Color ().Name () ); |
309 | |
310 | } // end WNT_Window :: SetBackground |
311 | //***// |
312 | //************************ SetBackground (2) *****************************// |
313 | //***// |
314 | void WNT_Window :: SetBackground ( const Quantity_NameOfColor BackColor ) { |
315 | |
316 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
317 | DownCast ( MyGraphicDevice ); |
318 | |
319 | if ( MyHBackground ) |
320 | DeleteObject ( MyHBackground ); |
321 | |
322 | MyBackground.SetColor ( BackColor ); |
323 | MyHBackground = CreateSolidBrush ( |
324 | dev -> SetColor ( MyBackground.Color () ) |
325 | ); |
326 | |
327 | } // end WNT_Window :: SetBackground |
328 | //***// |
329 | //************************ SetBackground (3) *****************************// |
330 | //***// |
331 | void WNT_Window :: SetBackground ( const Aspect_Handle aBackPixmap ) { |
332 | |
333 | Aspect_Handle bitmap = CreatePatternBrush ( ( HBITMAP )aBackPixmap ); |
334 | |
335 | if( bitmap ) { |
336 | if ( MyHBackground ) DeleteObject ( MyHBackground ); |
337 | MyHBackground = bitmap; |
338 | MyBackgroundImage.Clear(); |
339 | MyBackgroundFillMethod = Aspect_FM_NONE; |
340 | } |
341 | |
342 | } // end WNT_Window :: SetBackground |
343 | //***// |
344 | //************************ SetBackground (4) *****************************// |
345 | //***// |
346 | Standard_Boolean WNT_Window::SetBackground( const Standard_CString aName, |
347 | const Aspect_FillMethod aMethod ) { |
348 | Standard_Boolean status = Standard_False; |
349 | |
350 | if( !aName ) return Standard_False; |
351 | |
352 | Handle( WNT_GraphicDevice ) gdev = |
353 | *( ( Handle_WNT_GraphicDevice * )& MyGraphicDevice ); |
354 | if ( MyHBackground ) |
355 | DeleteObject( MyHBackground ); |
356 | MyHBackground = 0; |
357 | |
358 | HBITMAP hBmp = LoadImageFromFile( gdev, (Standard_PCharacter)aName ); |
359 | |
360 | if( hBmp ) { |
361 | status = Standard_True; |
362 | MyBackgroundImage = aName; |
363 | MyBackgroundFillMethod = aMethod; |
364 | MyHBackground = CreatePatternBrush( hBmp ); |
365 | } |
366 | |
367 | return status; |
368 | } // end WNT_Window :: SetBackground |
369 | //***// |
370 | //************************ SetBackground (5) *****************************// |
371 | //***// |
372 | void WNT_Window::SetBackground( const Quantity_Color& color ) { |
373 | |
374 | const Handle( WNT_GraphicDevice )& dev = |
375 | Handle( WNT_GraphicDevice )::DownCast ( MyGraphicDevice ); |
376 | |
377 | if ( MyHBackground ) |
378 | DeleteObject( MyHBackground ); |
379 | |
380 | MyBackground.SetColor( color ); |
381 | MyHBackground = CreateSolidBrush( dev->SetColor( color ) ); |
382 | |
383 | } // end WNT_Window :: SetBackground |
384 | |
385 | //************************ SetBackground (6) *****************************// |
386 | //***// |
387 | void WNT_Window::SetBackground (const Aspect_GradientBackground& GrBackground) { |
388 | |
389 | Quantity_Color Color1, Color2; |
390 | GrBackground.Colors(Color1,Color2); |
391 | SetBackground(Color1,Color2, GrBackground.BgGradientFillMethod()); |
392 | |
393 | } // end WNT_Window :: SetBackground |
394 | |
395 | //************************ SetBackground (7) *****************************// |
396 | //***// |
397 | void WNT_Window::SetBackground( const Quantity_Color& color1, |
398 | const Quantity_Color& color2, |
399 | const Aspect_GradientFillMethod aMethod){ |
400 | |
401 | Standard_Integer bcolor = Standard_Integer( color1.Name() ) + Standard_Integer( color2.Name() ); |
402 | if( ( bcolor >= 0 ) ) |
403 | MyGradientBackground.SetColors( color1, color2, aMethod ) ; |
404 | } // end WNT_Window :: SetBackground |
405 | |
406 | //**************************** SetCursor *********************************// |
407 | //***// |
408 | void WNT_Window :: SetCursor ( const Aspect_Handle aCursor ) const { |
409 | |
410 | #ifndef _WIN64 |
411 | SetClassLong ( ( HWND )myHWindow, GCL_HCURSOR, ( LONG )aCursor ); |
412 | #else |
413 | SetClassLong ( ( HWND )myHWindow, GCLP_HCURSOR, ( LONG )aCursor ); |
414 | #endif |
415 | |
416 | } // end WNT_Window :: SetCursor |
417 | //***// |
418 | //**************************** SetIcon ***********************************// |
419 | //***// |
420 | void WNT_Window :: SetIcon ( |
421 | const Aspect_Handle anIcon, |
422 | const Standard_CString aName |
423 | ) { |
424 | |
425 | if ( !myIcon.IsNull () ) |
426 | |
427 | myIcon.Nullify (); |
428 | |
429 | myIcon = new WNT_Icon ( aName, anIcon, 0 ); |
430 | |
431 | } // end WNT_Window :: SetIcon |
432 | //***// |
433 | //**************************** SetIconName *******************************// |
434 | //***// |
435 | void WNT_Window :: SetIconName ( const Standard_CString aName ) { |
436 | |
437 | myIcon -> SetName ( aName ); |
438 | |
439 | } // end WNT_Window :: SetIconName |
440 | //***// |
441 | //************************** SetDoubleBuffer *****************************// |
442 | //***// |
443 | void WNT_Window :: SetDoubleBuffer ( const Standard_Boolean DBmode ) { |
444 | |
445 | if ( DBmode ) |
446 | |
447 | if ( !BackingStore () ) |
448 | |
449 | Aspect_WindowError :: Raise ( "Unable to set double buffer" ); |
450 | |
451 | else { |
452 | |
453 | myDoubleBuffer = Standard_True; |
454 | myExtraData.hBmp = ( HBITMAP )myHPixmap; |
455 | |
456 | } // end else |
457 | |
458 | else { |
459 | |
460 | myDoubleBuffer = Standard_False; |
461 | myExtraData.hBmp = NULL; |
462 | |
463 | } // end else |
464 | |
465 | } // end WNT_Window :: SetDoubleBuffer |
466 | //***// |
467 | //***************************** Flush ************************************// |
468 | //***// |
469 | void WNT_Window :: Flush () const { |
470 | |
471 | if ( myDoubleBuffer ) Restore (); |
472 | |
473 | } // end WNT_Window :: Flush |
474 | //***// |
475 | //***************************** IsMapped *********************************// |
476 | //***// |
477 | Standard_Boolean WNT_Window :: IsMapped () const { |
478 | if (IsVirtual()) { |
587630c5 |
479 | return Standard_True; |
7fd59977 |
480 | } |
481 | |
482 | WINDOWPLACEMENT wp; |
483 | |
484 | wp.length = sizeof ( WINDOWPLACEMENT ); |
485 | GetWindowPlacement ( ( HWND )myHWindow, &wp ); |
486 | |
487 | return !( wp.showCmd == SW_HIDE || wp.showCmd == SW_MINIMIZE ); |
488 | } // WNT_Window :: IsMapped |
489 | //***// |
490 | //***************************** Map (1) **********************************// |
491 | //***// |
492 | void WNT_Window :: Map () const { |
493 | if (IsVirtual()) { |
494 | return; |
495 | } |
496 | Map ( SW_SHOW ); |
497 | } // end WNT_Window :: Map |
498 | //***// |
499 | //***************************** Map (2) **********************************// |
500 | //***// |
501 | void WNT_Window :: Map ( const Standard_Integer aMapMode ) const { |
502 | if (IsVirtual()) { |
503 | return; |
504 | } |
505 | ShowWindow ( ( HWND )myHWindow, aMapMode ); |
506 | UpdateWindow ( ( HWND )myHWindow ); |
507 | |
508 | } // end WNT_Window :: Map |
509 | //***// |
510 | //**************************** Unmap *************************************// |
511 | //***// |
512 | void WNT_Window :: Unmap () const { |
513 | |
514 | Map ( SW_HIDE ); |
515 | |
516 | } // end WNT_Window :: Unmap |
517 | //***// |
518 | //**************************** DoResize **********************************// |
519 | //***// |
520 | Aspect_TypeOfResize WNT_Window :: DoResize () const { |
521 | |
522 | int mask = 0; |
523 | Aspect_TypeOfResize mode = Aspect_TOR_UNKNOWN; |
524 | WINDOWPLACEMENT wp; |
525 | |
526 | wp.length = sizeof ( WINDOWPLACEMENT ); |
527 | GetWindowPlacement ( ( HWND )myHWindow, &wp ); |
528 | |
529 | if ( wp.showCmd != SW_SHOWMINIMIZED ) { |
530 | |
531 | if ( Abs ( wp.rcNormalPosition.left - aXLeft ) > 2 ) mask |= 1; |
532 | if ( Abs ( wp.rcNormalPosition.right - aXRight ) > 2 ) mask |= 2; |
533 | if ( Abs ( wp.rcNormalPosition.top - aYTop ) > 2 ) mask |= 4; |
534 | if ( Abs ( wp.rcNormalPosition.bottom - aYBottom ) > 2 ) mask |= 8; |
535 | |
536 | switch ( mask ) { |
537 | |
538 | case 0: |
539 | |
540 | mode = Aspect_TOR_NO_BORDER; |
541 | |
542 | break; |
543 | |
544 | case 1: |
545 | |
546 | mode = Aspect_TOR_LEFT_BORDER; |
547 | |
548 | break; |
549 | |
550 | case 2: |
551 | |
552 | mode = Aspect_TOR_RIGHT_BORDER; |
553 | |
554 | break; |
555 | |
556 | case 4: |
557 | |
558 | mode = Aspect_TOR_TOP_BORDER; |
559 | |
560 | break; |
561 | |
562 | case 5: |
563 | |
564 | mode = Aspect_TOR_LEFT_AND_TOP_BORDER; |
565 | |
566 | break; |
567 | |
568 | case 6: |
569 | |
570 | mode = Aspect_TOR_TOP_AND_RIGHT_BORDER; |
571 | |
572 | break; |
573 | |
574 | case 8: |
575 | |
576 | mode = Aspect_TOR_BOTTOM_BORDER; |
577 | |
578 | break; |
579 | |
580 | case 9: |
581 | |
582 | mode = Aspect_TOR_BOTTOM_AND_LEFT_BORDER; |
583 | |
584 | break; |
585 | |
586 | case 10: |
587 | |
588 | mode = Aspect_TOR_RIGHT_AND_BOTTOM_BORDER; |
589 | |
590 | break; |
591 | |
592 | default: |
593 | |
594 | break; |
595 | |
596 | } // end switch |
597 | |
598 | *( ( Standard_Integer* )&aXLeft ) = wp.rcNormalPosition.left; |
599 | *( ( Standard_Integer* )&aXRight ) = wp.rcNormalPosition.right; |
600 | *( ( Standard_Integer* )&aYTop ) = wp.rcNormalPosition.top; |
601 | *( ( Standard_Integer* )&aYBottom ) = wp.rcNormalPosition.bottom; |
602 | |
603 | if ( myDoubleBuffer ) { |
604 | |
605 | DeleteObject ( myHPixmap ); |
606 | *( ( Aspect_Handle* )&myHPixmap ) = 0; |
607 | |
608 | if ( !BackingStore () ) |
609 | |
610 | Aspect_WindowError :: Raise ( "WNT_Window::DoResize (): Unable to set double buffer" ); |
611 | |
612 | } // end if |
613 | |
614 | } // end if |
615 | |
616 | return mode; |
617 | |
618 | } // end WNT_Window :: DoResize |
619 | |
620 | //***// |
621 | //**************************** DoMapping **********************************// |
622 | //***// |
623 | Standard_Boolean WNT_Window :: DoMapping () const { |
624 | // DO nothing on WNT. |
625 | return Standard_True; |
626 | } |
627 | |
628 | //***// |
629 | //**************************** Clear *************************************// |
630 | //***// |
631 | void WNT_Window :: Clear () const { |
632 | |
633 | RECT r; |
634 | |
635 | GetClientRect ( ( HWND )myHWindow, &r ); |
636 | ClearArea ( r.right / 2, r.bottom / 2, r.right, r.bottom ); |
637 | |
638 | } // end WNT_Window :: Clear |
639 | //***// |
640 | //**************************** ClearArea *********************************// |
641 | //***// |
642 | void WNT_Window :: ClearArea ( |
643 | const Standard_Integer Xc, |
644 | const Standard_Integer Yc, |
645 | const Standard_Integer Width, |
646 | const Standard_Integer Height |
647 | ) const { |
648 | |
649 | RECT r; |
650 | HDC hDC = GetDC ( ( HWND )myHWindow ); |
651 | |
652 | r.left = Xc - Width / 2; |
653 | r.right = r.left + Width; |
654 | r.top = Yc - Height / 2; |
655 | r.bottom = r.top + Height; |
656 | |
657 | if ( myDoubleBuffer && myHPixmap ) { |
658 | |
659 | HDC hDCmem = CreateCompatibleDC ( hDC ); |
660 | |
661 | SELECT_PALETTE( hDCmem ); |
662 | |
663 | SelectObject ( hDCmem, myHPixmap ); |
664 | FillRect ( hDCmem, &r, ( HBRUSH )MyHBackground ); |
665 | |
666 | UNSELECT_PALETTE( hDCmem ); |
667 | |
668 | DeleteDC ( hDCmem ); |
669 | |
670 | } else { |
671 | |
672 | SELECT_PALETTE( hDC ); |
673 | |
674 | FillRect ( hDC, &r, ( HBRUSH )MyHBackground ); |
675 | |
676 | UNSELECT_PALETTE( hDC ); |
677 | |
678 | } // end else |
679 | |
680 | ReleaseDC ( ( HWND )myHWindow, hDC ); |
681 | |
682 | } // end WNT_Window :: ClearArea |
683 | //***// |
684 | //**************************** Restore ***********************************// |
685 | //***// |
686 | void WNT_Window :: Restore () const { |
687 | |
688 | RECT r; |
689 | |
690 | if ( myHPixmap ) { |
691 | |
692 | GetClientRect ( ( HWND )myHWindow, &r ); |
693 | RestoreArea ( |
694 | r.right / 2, r.bottom - r.bottom / 2, r.right, r.bottom |
695 | ); |
696 | |
697 | } // end if |
698 | |
699 | } // end WNT_Window :: Restore |
700 | //***// |
701 | //************************* Restore Area *********************************// |
702 | //***// |
703 | void WNT_Window :: RestoreArea ( |
704 | const Standard_Integer Xc, |
705 | const Standard_Integer Yc, |
706 | const Standard_Integer Width, |
707 | const Standard_Integer Height |
708 | ) const { |
709 | |
710 | HDC hDC, hDCmem; |
711 | int x, y; |
712 | |
713 | if ( myHPixmap ) { |
714 | |
715 | hDC = GetDC ( ( HWND )myHWindow ); |
716 | hDCmem = CreateCompatibleDC ( hDC ); |
717 | |
718 | x = Xc - Width / 2; |
719 | y = Yc - Height / 2; |
720 | |
721 | SelectObject ( hDCmem, myHPixmap ); |
722 | BitBlt ( hDC, x, y, Width, Height, hDCmem, x, y, SRCCOPY ); |
723 | |
724 | DeleteDC ( hDCmem ); |
725 | ReleaseDC ( ( HWND )myHWindow, hDC ); |
726 | |
727 | } // end if |
728 | |
729 | } // end WNT_Window :: RestoreArea |
730 | //***// |
731 | //****************************** Dump ************************************// |
732 | //***// |
733 | Standard_Boolean WNT_Window::Dump (const Standard_CString theFilename, |
734 | const Standard_Real theGammaValue) const |
735 | { |
692613e5 |
736 | Image_AlienPixMap anImg; |
737 | if (!ToPixMap (anImg) || anImg.IsEmpty()) |
738 | { |
739 | return Standard_False; |
740 | } |
741 | if (Abs (theGammaValue - 1.0) > 0.001) |
742 | { |
743 | anImg.AdjustGamma (theGammaValue); |
744 | } |
745 | return anImg.Save (theFilename); |
7fd59977 |
746 | } // end WNT_Window :: Dump |
747 | //***// |
748 | //*************************** DumpArea ***********************************// |
749 | //***// |
750 | Standard_Boolean WNT_Window::DumpArea (const Standard_CString theFilename, |
751 | const Standard_Integer Xc, const Standard_Integer Yc, |
752 | const Standard_Integer Width, const Standard_Integer Height, |
753 | const Standard_Real aGammaValue) const |
754 | { |
755 | // *** Gamma correction must be implemented also under WNT ... |
756 | Standard_Integer x = Xc - Width / 2; |
757 | Standard_Integer y = Yc - Height / 2; |
758 | return (myDoubleBuffer) ? |
759 | myImages->SaveBuffer (theFilename, x, y, Width, Height) : |
760 | myImages->Save (theFilename, x, y, Width, Height); |
761 | |
762 | } // end WNT_Window :: DumpArea |
763 | //***// |
764 | |
692613e5 |
765 | static Standard_Boolean ConvertBitmap (HBITMAP theHBitmap, |
766 | Image_PixMap& thePixMap) |
7fd59977 |
767 | { |
692613e5 |
768 | // Get informations about the bitmap |
7fd59977 |
769 | BITMAP aBitmap; |
692613e5 |
770 | if (GetObject (theHBitmap, sizeof(BITMAP), (LPSTR )&aBitmap) == 0) |
771 | { |
772 | return Standard_False; |
773 | } |
7fd59977 |
774 | |
692613e5 |
775 | const Standard_Size aSizeRowBytes = Standard_Size(aBitmap.bmWidth) * 4; |
776 | if (!thePixMap.InitTrash (Image_PixMap::ImgBGR32, Standard_Size(aBitmap.bmWidth), Standard_Size(aBitmap.bmHeight), aSizeRowBytes)) |
777 | { |
778 | return Standard_False; |
779 | } |
780 | thePixMap.SetTopDown (false); |
7fd59977 |
781 | |
782 | // Setup image data |
783 | BITMAPINFOHEADER aBitmapInfo; |
784 | memset (&aBitmapInfo, 0, sizeof(BITMAPINFOHEADER)); |
692613e5 |
785 | aBitmapInfo.biSize = sizeof(BITMAPINFOHEADER); |
786 | aBitmapInfo.biWidth = aBitmap.bmWidth; |
787 | aBitmapInfo.biHeight = aBitmap.bmHeight; // positive means bottom-up! |
788 | aBitmapInfo.biPlanes = 1; |
789 | aBitmapInfo.biBitCount = 32; // use 32bit for automatic word-alignment per row |
7fd59977 |
790 | aBitmapInfo.biCompression = BI_RGB; |
791 | |
7fd59977 |
792 | // Copy the pixels |
793 | HDC aDC = GetDC (NULL); |
692613e5 |
794 | Standard_Boolean isSuccess = GetDIBits (aDC, theHBitmap, |
795 | 0, // first scan line to set |
796 | aBitmap.bmHeight, // number of scan lines to copy |
797 | thePixMap.ChangeData(), // array for bitmap bits |
798 | (LPBITMAPINFO )&aBitmapInfo, // bitmap data info |
799 | DIB_RGB_COLORS) != 0; |
7fd59977 |
800 | ReleaseDC (NULL, aDC); |
692613e5 |
801 | return isSuccess; |
7fd59977 |
802 | } |
803 | |
692613e5 |
804 | Standard_Boolean WNT_Window::ToPixMap (Image_PixMap& thePixMap) const |
7fd59977 |
805 | { |
806 | if (myDoubleBuffer && myHPixmap) |
807 | { |
692613e5 |
808 | return ConvertBitmap ((HBITMAP )myHPixmap, thePixMap); |
7fd59977 |
809 | } |
810 | |
811 | RECT aRect; |
812 | GetClientRect ((HWND )myHWindow, &aRect); |
813 | int aWidth = aRect.right - aRect.left; |
814 | int aHeight = aRect.bottom - aRect.top; |
815 | |
816 | // Prepare the DCs |
817 | HDC aDstDC = GetDC (NULL); |
818 | HDC aSrcDC = GetDC ((HWND )myHWindow); // we copy only client area |
819 | HDC aMemDC = CreateCompatibleDC (aDstDC); |
820 | |
821 | // Copy the screen to the bitmap |
822 | HBITMAP anHBitmapDump = CreateCompatibleBitmap (aDstDC, aWidth, aHeight); |
823 | HBITMAP anHBitmapOld = (HBITMAP )SelectObject (aMemDC, anHBitmapDump); |
824 | BitBlt (aMemDC, 0, 0, aWidth, aHeight, aSrcDC, 0, 0, SRCCOPY); |
825 | |
692613e5 |
826 | Standard_Boolean isSuccess = ConvertBitmap (anHBitmapDump, thePixMap); |
7fd59977 |
827 | |
828 | // Free objects |
829 | DeleteObject (SelectObject (aMemDC, anHBitmapOld)); |
830 | DeleteDC (aMemDC); |
831 | |
692613e5 |
832 | return isSuccess; |
7fd59977 |
833 | } |
834 | |
835 | //****************************** Load ************************************// |
836 | //***// |
837 | Standard_Boolean WNT_Window :: Load ( const Standard_CString aFilename ) const { |
838 | |
839 | RECT r; |
840 | |
841 | GetClientRect ( ( HWND )myHWindow, &r ); |
842 | |
843 | return LoadArea ( aFilename, r.right / 2, r.bottom / 2, r.right, r.bottom ); |
844 | |
845 | } // end WNT_Window :: Load |
846 | //***// |
847 | //*************************** LoadArea ***********************************// |
848 | //***// |
849 | Standard_Boolean WNT_Window :: LoadArea ( |
850 | const Standard_CString aFilename, |
851 | const Standard_Integer Xc, |
852 | const Standard_Integer Yc, |
853 | const Standard_Integer Width, |
854 | const Standard_Integer Height |
855 | ) const { |
856 | |
857 | Standard_Integer idx; |
858 | Standard_Boolean status; |
859 | |
860 | status = ( idx = myImages -> Load ( aFilename ) ) ? Standard_True : Standard_False; |
861 | |
862 | if ( status ) myImages -> Draw ( idx, Xc, Yc, Width, Height ); |
863 | |
864 | return status; |
865 | |
866 | } // end WNT_Window :: LoadArea |
867 | //***// |
868 | //*************************** BackingStore *******************************// |
869 | //***// |
870 | Standard_Boolean WNT_Window :: BackingStore () const { |
871 | |
872 | Standard_Boolean retVal = Standard_False;; |
873 | HDC hDC; |
874 | RECT r; |
875 | |
876 | if ( myHPixmap ) |
877 | |
878 | retVal = Standard_True; |
879 | |
880 | else { |
881 | |
882 | hDC = GetDC ( ( HWND )myHWindow ); |
883 | |
884 | GetClientRect ( ( HWND )myHWindow, &r ); |
885 | *( ( Aspect_Handle* )&myHPixmap ) = CreateCompatibleBitmap ( hDC, r.right, r.bottom ); |
886 | |
887 | if ( myHPixmap ) { |
888 | |
889 | HDC hDCmem; |
890 | |
891 | hDCmem = CreateCompatibleDC ( hDC ); |
892 | |
893 | SELECT_PALETTE( hDCmem ); |
894 | |
895 | SelectObject ( hDCmem, myHPixmap ); |
896 | FillRect ( hDCmem, &r, ( HBRUSH )MyHBackground ); |
897 | |
898 | UNSELECT_PALETTE( hDCmem ); |
899 | |
900 | DeleteDC ( hDCmem ); |
901 | |
902 | retVal = Standard_True; |
903 | |
904 | } // end if |
905 | |
906 | ReleaseDC ( ( HWND )myHWindow, hDC ); |
907 | |
908 | } // end else |
909 | |
910 | return retVal; |
911 | |
912 | } // end WNT_Window :: BackingStore |
913 | //***// |
914 | //******************************* Ratio **********************************// |
915 | //***// |
916 | Quantity_Ratio WNT_Window :: Ratio () const { |
917 | |
918 | RECT r; |
919 | |
920 | GetClientRect ( ( HWND )myHWindow, &r ); |
921 | |
922 | return ( Quantity_Ratio )( ( Quantity_Ratio )r.right / ( Quantity_Ratio )r.bottom ); |
923 | |
924 | } // end WNT_Window :: Ratio |
925 | //***// |
926 | //**************************** Position (1) ******************************// |
927 | //***// |
928 | void WNT_Window :: Position ( |
929 | Quantity_Parameter& X1, Quantity_Parameter& Y1, |
930 | Quantity_Parameter& X2, Quantity_Parameter& Y2 |
931 | ) const { |
932 | |
933 | POINT ptl, ptr; |
934 | RECT pr, cr; |
935 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
936 | DownCast ( MyGraphicDevice ); |
937 | |
938 | if ( myHParentWindow ) |
939 | |
940 | GetClientRect ( ( HWND )myHParentWindow, &pr ); |
941 | |
942 | else { |
943 | |
944 | int w, h; |
945 | |
946 | dev -> DisplaySize ( w, h ); |
947 | |
948 | pr.right = w; |
949 | pr.bottom = h; |
950 | |
951 | } // end else |
952 | |
953 | GetClientRect ( ( HWND )myHWindow, &cr ); |
954 | |
955 | ptl.x = ptl.y = 0; |
956 | ClientToScreen ( ( HWND )myHWindow, &ptl ); |
957 | cr.left = ptl.x; |
958 | cr.top = ptl.y; |
959 | |
960 | ptr.x = cr.right; |
961 | ptr.y = cr.bottom; |
962 | ClientToScreen ( ( HWND )myHWindow, &ptr ); |
963 | cr.right = ptr.x; |
964 | cr.bottom = ptr.y; |
965 | |
966 | if ( myHParentWindow ) { |
967 | |
968 | ScreenToClient ( ( HWND )myHParentWindow, &ptl ); |
969 | ScreenToClient ( ( HWND )myHParentWindow, &ptr ); |
970 | cr.left = ptl.x; |
971 | cr.top = ptl.y; |
972 | cr.right = ptr.x; |
973 | cr.bottom = ptr.y; |
974 | |
975 | } // end if |
976 | |
977 | X1 = ( Quantity_Parameter )cr.left / ( Quantity_Parameter )pr.right; |
978 | X2 = ( Quantity_Parameter )cr.right / ( Quantity_Parameter )pr.right; |
979 | Y1 = 1. - ( Quantity_Parameter )cr.top / ( Quantity_Parameter )pr.bottom; |
980 | Y2 = 1. - ( Quantity_Parameter )cr.bottom / ( Quantity_Parameter )pr.bottom; |
981 | |
982 | } // end WNT_Window :: Position |
983 | //***// |
984 | //**************************** Position (2) ******************************// |
985 | //***// |
986 | void WNT_Window :: Position ( |
987 | Standard_Integer& X1, Standard_Integer& Y1, |
988 | Standard_Integer& X2, Standard_Integer& Y2 |
989 | ) const { |
990 | |
991 | POINT ptl, ptr; |
992 | RECT r; |
993 | |
994 | GetClientRect ( ( HWND )myHWindow, &r ); |
995 | |
996 | ptl.x = ptl.y = 0; |
997 | ClientToScreen ( ( HWND )myHWindow, &ptl ); |
998 | ptr.x = r.right; |
999 | ptr.y = r.bottom; |
1000 | ClientToScreen ( ( HWND )myHWindow, &ptr ); |
1001 | |
1002 | if ( myHParentWindow ) { |
1003 | |
1004 | ScreenToClient ( ( HWND )myHParentWindow, &ptl ); |
1005 | ScreenToClient ( ( HWND )myHParentWindow, &ptr ); |
1006 | |
1007 | } // end if |
1008 | |
1009 | X1 = ptl.x; |
1010 | X2 = ptr.x; |
1011 | Y1 = ptl.y; |
1012 | Y2 = ptr.y; |
1013 | |
1014 | } // end WNT_Window :: Position |
1015 | //***// |
1016 | //******************************* Size (1) *******************************// |
1017 | //***// |
1018 | void WNT_Window :: Size ( |
1019 | Quantity_Parameter& Width, Quantity_Parameter& Height |
1020 | ) const { |
1021 | |
1022 | RECT pr, wr; |
1023 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1024 | DownCast ( MyGraphicDevice ); |
1025 | |
1026 | if ( myHParentWindow ) |
1027 | |
1028 | GetClientRect ( ( HWND )myHParentWindow, &pr ); |
1029 | |
1030 | else { |
1031 | |
1032 | int w, h; |
1033 | |
1034 | dev -> DisplaySize ( w, h ); |
1035 | |
1036 | pr.right = w; |
1037 | pr.bottom = h; |
1038 | |
1039 | } // end else |
1040 | |
1041 | GetClientRect ( ( HWND )myHWindow, &wr ); |
1042 | |
1043 | Width = ( Quantity_Parameter )wr.right / ( Quantity_Parameter )pr.right; |
1044 | Height = ( Quantity_Parameter )wr.bottom / ( Quantity_Parameter )pr.bottom; |
1045 | |
1046 | } // end WNT_Window :: Size |
1047 | //***// |
1048 | //******************************* Size (2) *******************************// |
1049 | //***// |
1050 | void WNT_Window :: Size ( |
1051 | Standard_Integer& Width, Standard_Integer& Height |
1052 | ) const { |
1053 | |
1054 | RECT r; |
1055 | |
1056 | GetClientRect ( ( HWND )myHWindow, &r ); |
1057 | |
1058 | Width = r.right; |
1059 | Height = r.bottom; |
1060 | |
1061 | } // end WNT_Window :: Size |
1062 | //***// |
1063 | //******************************* MMSize (1) *******************************// |
1064 | //***// |
1065 | void WNT_Window :: MMSize ( |
1066 | Standard_Real& Width, Standard_Real& Height |
1067 | ) const { |
1068 | |
1069 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1070 | DownCast ( MyGraphicDevice ); |
1071 | |
1072 | int w, h; |
1073 | dev -> DisplaySize ( w, h ); |
1074 | Standard_Real mmw,mmh; |
1075 | dev -> DisplaySize ( mmw, mmh ); |
1076 | Standard_Real mmratio = (mmw/w + mmh/h)/2.; |
1077 | |
1078 | RECT wr; |
1079 | GetClientRect ( ( HWND )myHWindow, &wr ); |
1080 | |
1081 | Width = mmratio * wr.right; |
1082 | Height = mmratio * wr.bottom; |
1083 | |
1084 | } // end WNT_Window :: MMSize |
1085 | //***// |
1086 | //**************************** Convert (1) *******************************// |
1087 | //***// |
1088 | Quantity_Parameter WNT_Window :: Convert ( |
1089 | const Standard_Integer PV |
1090 | ) const { |
1091 | |
1092 | int w, h; |
1093 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1094 | DownCast ( MyGraphicDevice ); |
1095 | |
1096 | dev -> DisplaySize ( w, h ); |
1097 | |
1098 | return ( Quantity_Parameter )( PV / Min ( w, h ) ); |
1099 | |
1100 | } // end WNT_Window :: Convert |
1101 | //***// |
1102 | //**************************** Convert (2) *******************************// |
1103 | //***// |
1104 | Standard_Integer WNT_Window :: Convert ( |
1105 | const Quantity_Parameter DV |
1106 | ) const { |
1107 | |
1108 | int w, h; |
1109 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1110 | DownCast ( MyGraphicDevice ); |
1111 | |
1112 | dev -> DisplaySize ( w, h ); |
1113 | |
1114 | return ( Standard_Integer )( DV * Min ( w, h ) ); |
1115 | |
1116 | } // end WNT_Window :: Convert |
1117 | //***// |
1118 | //**************************** Convert (3) *******************************// |
1119 | //***// |
1120 | |
1121 | void WNT_Window :: Convert ( |
1122 | const Standard_Integer PX, const Standard_Integer PY, |
1123 | Quantity_Parameter& DX, Quantity_Parameter& DY |
1124 | ) const { |
1125 | |
1126 | int w, h; |
1127 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1128 | DownCast ( MyGraphicDevice ); |
1129 | |
1130 | dev -> DisplaySize ( w, h ); |
1131 | |
1132 | DX = ( Quantity_Parameter )PX / ( Quantity_Parameter )w; |
1133 | DY = 1. - ( Quantity_Parameter )PY / ( Quantity_Parameter )h; |
1134 | |
1135 | } // end WNT_Window :: Convert |
1136 | //***// |
1137 | //**************************** Convert (4) *******************************// |
1138 | //***// |
1139 | void WNT_Window :: Convert ( |
1140 | const Quantity_Parameter DX, const Quantity_Parameter DY, |
1141 | Standard_Integer& PX, Standard_Integer& PY |
1142 | ) const { |
1143 | |
1144 | int w, h; |
1145 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1146 | DownCast ( MyGraphicDevice ); |
1147 | |
1148 | dev -> DisplaySize ( w, h ); |
1149 | |
1150 | PX = ( Standard_Integer )( DX * ( Quantity_Parameter )w ); |
1151 | PY = ( Standard_Integer )( ( 1. - DY ) * ( Quantity_Parameter )h ); |
1152 | |
1153 | } // end WNT_Window :: Convert |
1154 | //***// |
1155 | //******************************* SetPos *********************************// |
1156 | //***// |
1157 | void WNT_Window :: SetPos ( |
1158 | const Standard_Integer X, const Standard_Integer Y, |
1159 | const Standard_Integer X1, const Standard_Integer Y1 |
1160 | ) { |
1161 | |
1162 | aXLeft = X; |
1163 | aYTop = Y; |
1164 | aXRight = X1; |
1165 | aYBottom = Y1; |
1166 | |
1167 | } // end WNT_Window :: SetPos |
1168 | //***// |
1169 | //*************************** SetOutputFormat ****************************// |
1170 | //***// |
1171 | void WNT_Window :: SetOutputFormat ( const WNT_TypeOfImage aFormat ) { |
1172 | |
1173 | myFormat = aFormat; |
1174 | myImages -> SetFormat ( aFormat ); |
1175 | |
1176 | } // end WNT_Window :: SetOutputFormat |
1177 | //***// |
1178 | //**************************** SetFlags **********************************// |
1179 | //***// |
1180 | void WNT_Window :: SetFlags ( const Standard_Integer aFlags ) { |
1181 | |
1182 | myExtraData.dwFlags |= aFlags; |
1183 | |
1184 | } // end WNT_Window :: SetFlags |
1185 | //***// |
1186 | //*************************** ResetFlags *********************************// |
1187 | //***// |
1188 | void WNT_Window :: ResetFlags ( const Standard_Integer aFlags ) { |
1189 | |
1190 | myExtraData.dwFlags &= ~aFlags; |
1191 | |
1192 | } // end WNT_Window :: ResetFlags |
1193 | //***// |
1194 | //*************************** doCreate **********************************// |
1195 | //***// |
1196 | void WNT_Window :: doCreate ( |
1197 | const Handle( WNT_GraphicDevice )& aDevice, |
1198 | const Aspect_Handle aHandle, |
1199 | const Quantity_NameOfColor aBackColor |
1200 | ) { |
1201 | |
1202 | LONG uData; |
1203 | WNDPROC wProc; |
1204 | WINDOWPLACEMENT wp; |
1205 | |
1206 | const Handle( WNT_GraphicDevice )& dev = Handle( WNT_GraphicDevice ) :: |
1207 | DownCast ( MyGraphicDevice ); |
1208 | |
1209 | ZeroMemory ( &myExtraData, sizeof ( WNT_WindowData ) ); |
1210 | |
1211 | myHWindow = aHandle; |
1212 | myHParentWindow = GetParent ( ( HWND )aHandle ); |
1213 | myDoubleBuffer = Standard_False; |
1214 | myHPixmap = NULL; |
1215 | wProc = (WNDPROC )GetWindowLongPtr ((HWND )aHandle, GWLP_WNDPROC); |
1216 | uData = GetWindowLongPtr ((HWND )aHandle, GWLP_USERDATA); |
1217 | myUsrData = Standard_Address(-1); |
1218 | myWndProc = NULL; |
1219 | |
1220 | if ( wProc != &WNT_WndProc ) { |
1221 | |
1222 | myWndProc = wProc; |
1223 | |
1224 | SetBackground ( aBackColor ); |
1225 | |
1226 | myExtraData.WNT_Window_Ptr = ( void* )this; |
1227 | myExtraData.hPal = ( HPALETTE )dev -> HPalette (); |
1228 | |
1229 | if ( uData != ( LONG )&myExtraData ) |
1230 | { |
1231 | myUsrData = (Standard_Address )SetWindowLongPtr ((HWND )myHWindow, GWLP_USERDATA, (LONG_PTR )&myExtraData); |
1232 | } |
1233 | |
1234 | if (myWndProc != NULL) |
1235 | { |
1236 | SetWindowLongPtr ((HWND )myHWindow, GWLP_WNDPROC, (LONG_PTR )WNT_WndProc); |
1237 | } |
1238 | |
1239 | } // end if |
1240 | |
1241 | myExtraData.dwFlags = WDF_FOREIGN; |
1242 | |
1243 | myImages = new WNT_ImageManager ( this ); |
1244 | myFormat = WNT_TOI_XWD; |
1245 | |
1246 | wp.length = sizeof ( WINDOWPLACEMENT ); |
1247 | GetWindowPlacement ( ( HWND )myHWindow, &wp ); |
1248 | |
1249 | aXLeft = wp.rcNormalPosition.left; |
1250 | aYTop = wp.rcNormalPosition.top; |
1251 | aXRight = wp.rcNormalPosition.right; |
1252 | aYBottom = wp.rcNormalPosition.bottom; |
1253 | |
1254 | } // end WNT_Window :: doCreate |
1255 | //***// |
1256 | //************************************************************************// |