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