-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathETSLayout.cpp
3055 lines (2450 loc) · 81.6 KB
/
ETSLayout.cpp
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
////////////////////////////////////////////
// ___ ____ _________________ //
// / _/_ _// _______________/ //
// / _/ / / / / ___ ___ ____ //
// /__/ /_/ / / / // _/_ _/ //
// _________/ / / / // _/ / / //
// (c) 1998-2000_/ /___//_/ /_/ //
// //
////////////////////////////////////////////
// all rights reserved //
////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutDialog
//
// A class for smart layouting of Dialogs and such
//
// USAGE: See LayoutMgr.html
//
// AUTHOR: Erwin Tratar <tr@et-soft.de>
//
// DISCLAIMER:
//
// This Sourcecode and all accompaning material is ©1998-1999 Erwin Tratar.
// All rights reserved.
//
// The source code may be used in compiled form in any way you desire
// (including usage in commercial applications), providing that your
// application adds essential code (i.e. it is not only a wrapper) to the
// functionality found here
//
// Redistribution of the sourcecode itself, publication in any media or
// inclusion in a library requires the authors expressed written consent.
// You may not sale this code for profit.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. USE IT
// AT YOUR OWN RISK! THE AUTHOR ACCEPTS NO LIABILITY FOR ANY DAMAGE/LOSS OF
// BUSINESS THAT THIS PRODUCT MAY CAUSE.
//
//
// HISTORY:
// 1998/05/1 Initial Release
// 1998/05/13 Added ability to have a Pane with a control
// 1998/05/13 Added better support for TabControls
// 1998/05/14 automatically set Icon to IDR_MAINFRAME
// 1998/05/19 no flicker on restoring position in OnInitialUpdate
// Changed procedure for load/save, see constructor
// 1998/10/02 Added support for Maximum (tracking) size
// 1998/10/02 Much improved handling regarding RELATIVE/GREEDY
// /w critical minimum size
// 1998/10/02 turn on/off gripper at lower right corner
// 1998/10/05 Support for user defined minimum size for items
// (was hardcoded 5 before)
// 1998/10/07 Fix for FormViews
// 1998/10/31 Support for SECDialogBar/CDialogBar
// 1998/10/31 simplified interface
// 1998/10/31 Advanced positioning options
// 1998/10/31 Added paneNull for empty Pane (former: NULL)
// 1998/11/20 Swapped ETSLayoutDialog constructor parameters
// 1998/11/20 Added Pane::addItemSpaceBetween
// [Leo Zelevinsky]
// 1998/11/24 Added fixup for greedy panes
// 1998/11/24 addItemSpaceBetween now subtracts 2*nDefaultBorder
// 1998/11/24 addGrowing() added as a shortcut for a paneNull
// 1998/11/24 simplified interface: no more PaneBase:: / Pane::
// needed
// 1998/11/24 added FILL_* Modes
// 1998/11/24 improved maximum size handling for greedy panes
// 1998/11/25 Fixup of greedy panes caused infinite loop in some
// cases
// 1999/01/07 addItemSpaceLike() added
// 1999/04/03 Fixed ETSLayoutFormView memory leak
// 1999/04/07 Fixed ALIGN_xCENTER
// 1999/04/08 New simple stream-interface added
// 1999/04/09 Added support for an empty Status-Bar for resizing
// instead of a gripper in the lower right corner
// [Andreas Kapust]
// 1999/04/11 New code for much less flickering, OnEraseBkgnd()
// overidden for this task
// 1999/05/12 Split Layout code into understandable pieces and adding
// a lot of comments
// 1999/06/20 ABSOLUTE_X + ALIGN_FILL_X expands item if there is any
// left space (after all Abs/Rel/Greedy processing is done)
// 1999/10/06 Changed Load() and Save() to use WINDOWPLACEMENT
// [Keith Bussell]
// 1999/11/18 Added possibility to add panes of the same orientation
// to another pane. This merges both panes in one big
// pane with the same orientation
// 1999/11/18 Added support for BCGDialogBar (only with BCG > 4.52!)
// 1999/11/25 Addes support for PropertyPages/Sheets. Uses some code
// of a code submission from Anreas Kapust
// 1999/11/25 Renamed classes to ETSLayoutXXX
// 1999/11/25 Use CreateRoot() and Root() instead of m_pRootPane in
// derived class.
// 1999/11/26 Added autopointer support. No need to use normal pointers
// when defining layout anymore. Changed m_pRootPane to
// m_RootPane
// 1999/11/26 Bug in Fixup Greedy II with multiple GREEDY panes and one
// of them min/max limited
// 1999/11/28 Fixed PaneTab::getConstrainVert() for ABSOLUTE_VERT
// 1999/11/28 Fixed itemFixed()
// 1999/11/28 Changed DWORD modeResize Arguments to layModeResize for
// better type safety. Added typesafe operator|
// 1999/12/04 Don't reposition window in UpdateLayout if it's a child
// (as a child Dialog or PropertyPage)
// 1999/12/04 Erase Backgroung with GCL_HBRBACKGROUND (if available)
// 1999/12/04 itemSpaceXXX() adds a NORESIZE item instead of ABSOLUTE_XXX
// this will fix unwanted growing in secondary direction
//
// Version: 1.0 [1999/12/04] Initial Article on CodeProject
//
// 1999/12/10 Erase Backgroung within TabCtrl was 'fixed' badly. Reverted to
// old working code
// 2000/02/02 When the Dialog is child of a View the class works correctly
// now [Didier BULTIAUW]
// 2000/02/15 Combo-Boxes were not working correctly (in all modes!)
// 2000/02/17 aligned SpinButton Controls (with buddy) now handled
// automatically
// !! do not add such a control to the layout !! it is always
// reattached to its buddy.
// 2000/02/17 changed some cotrol class names to the defined constants
//
// Version: 1.1 [2000/02/17]
//
// 2000/02/25 Fixed auto alignment of SpinButton Controls to only affect
// visible ones
// 2000/02/27 Put all the classes into the namespace 'ETSLayout'
// 2000/03/07 Fixed growing Dialog after minimizing and restoring
// 2000/05/22 Whole Statusbar (Gripper) is not excluded anymore in EraseBkgnd()
// instead only the triangular Gripper is excluded
// 2000/05/31 Fix for PropertySheets with PSH_WIZARDHASFINISH [Thömmi]
// 2000/05/31 Fix for UpDown-Controls with EditCtrl Buddy in PropertyPages.
// These were not repositioned every time the page is being show
// until the first resize
// 2000/07/28 Problems with resizing ActiveX Controls fixed [Micheal Chapman]
// 2000/07/28 Some strings were not properly wrapped with _T()
// 2000/08/03 Check for BS_GROUPBOX was not correct as BS_GROUPBOX is more than one Bit
// 2000/08/03 New override AddMainArea added to ETSLayoutPropertySheet in order to
// have a hook for additional controls in a PropertySheet (besides the Tab)
// 2000/08/03 New override AddButtons added to ETSLayoutPropertySheet in order to
// have a hook for additional controls in the bottem pane of a PropertySheet
// 2000/08/03 Removed the need for DECLARE_LAYOUT
//
// Version: 1.2 [2000/08/05]
#define OEMRESOURCE
#include <windows.h>
#include "stdafx.h"
#include "ETSLayout.h"
using namespace ETSLayout;
#pragma warning(disable: 4097 4610 4510 4100)
#ifndef OBM_SIZE
#define OBM_SIZE 32766
// taken from WinresRc.h
// if not used for any reason
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static UINT auIDStatusBar[] =
{
ID_SEPARATOR
};
const int ERASE_GROUP_BORDER = 10;
const int FIXUP_CUTOFF = 5;
const int TAB_SPACE = 5;
// the _NULL-Pane
CWnd* ETSLayoutMgr::paneNull = 0;
void ETSLayoutMgr::Layout(CRect& rcClient)
{
if(rcClient.Height() && rcClient.Width() && m_RootPane.IsValid()) \
m_RootPane->resizeTo(rcClient); \
}
ETSLayoutMgr::CPane ETSLayoutMgr::pane( layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/,
int sizeSecondary /*=0*/)
{
Pane* pPane = new Pane ( this, orientation, sizeBorder, sizeExtraBorder );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneTab( CTabCtrl* pTab, layOrientation orientation,
ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/,
int sizeExtraBorder /*=0*/, int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneTab ( pTab, this, orientation, sizeBorder, sizeExtraBorder );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( CWnd* pCtrl, layOrientation orientation,
ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/,
int sizeExtraBorder /*=0*/, int sizeTopExtra /*=0*/,
int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneCtrl ( pCtrl, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( UINT nID, layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/,
int sizeTopExtra /*=0*/, int sizeSecondary /*=0*/)
{
Pane* pPane = new PaneCtrl ( nID, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra );
pPane->m_sizeSecondary = sizeSecondary;
pPane->m_modeResize = modeResize;
return CPane(pPane);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/,
int sizeXMin /*=-1*/, int sizeYMin /*=-1*/)
{
return new PaneItem( nID, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/,
int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=-1*/,
int sizeYMin /*=-1*/)
{
return new PaneItem( pWnd, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemFixed(layOrientation orientation, int sizePrimary)
{
CPaneBase p = new PaneItem(paneNull, this, NORESIZE, (orientation==HORIZONTAL)?sizePrimary:0, (orientation==VERTICAL)?sizePrimary:0);
return p;
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemGrowing(layOrientation orientation)
{
return new PaneItem(paneNull, this, (orientation==HORIZONTAL)?ABSOLUTE_VERT:ABSOLUTE_HORZ, 0, 0, -nDefaultBorder, -nDefaultBorder);
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, CWnd* pWndFirst, CWnd* pWndSecond )
{
if( orientation == HORIZONTAL ) {
// I'm interested in horizontal spacing
CRect rLeft, rRight;
pWndFirst->GetWindowRect(&rLeft);
pWndSecond->GetWindowRect(&rRight);
int sizeX = rRight.left - rLeft.right;
if( sizeX < 0 ) {
// compare top to top
sizeX = rRight.left - rLeft.left;
}
else {
sizeX -= 2*nDefaultBorder;
}
return new PaneItem(paneNull, this, NORESIZE, sizeX, 0);
}
else {
// I'm interested in vertical spacing
CRect rTop, rBot;
pWndFirst->GetWindowRect(&rTop);
pWndSecond->GetWindowRect(&rBot);
int sizeY = rBot.top - rTop.bottom;
if( sizeY < 0 ) {
// compare top to top
sizeY = sizeY = rBot.top - rTop.top;
}
else {
sizeY -= 2*nDefaultBorder;
}
return new PaneItem(paneNull, this, NORESIZE, 0, sizeY);
}
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, UINT nIDFirst, UINT nIDSecond )
{
CWnd *pFirst = GetWnd()->GetDlgItem(nIDFirst);
CWnd *pSecond = GetWnd()->GetDlgItem(nIDSecond);
ASSERT( pFirst && pSecond );
return itemSpaceBetween( orientation, pFirst, pSecond );
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, CWnd* pWnd )
{
CRect rRect;
pWnd->GetWindowRect(&rRect);
if( orientation == HORIZONTAL ) {
// I'm interested in horizontal spacing
return new PaneItem(paneNull, this, NORESIZE, rRect.Width(), 0);
}
else {
// I'm interested in vertical spacing
return new PaneItem(paneNull, this, NORESIZE, 0, rRect.Height() );
}
}
ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, UINT nID )
{
CWnd *pWnd = GetWnd()->GetDlgItem(nID);
ASSERT( pWnd );
return itemSpaceLike( orientation, pWnd );
}
ETSLayoutMgr::~ETSLayoutMgr()
{
}
void ETSLayoutMgr::UpdateLayout()
{
if(!m_RootPane)
return;
// Check constraints
CRect rcClient = GetRect();
if( m_pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) && !(m_pWnd->GetStyle()&WS_CHILD) ) {
CRect rcWindow;
m_pWnd->GetWindowRect(rcWindow);
// Added by Didier BULTIAUW
CWnd* parentWnd = m_pWnd->GetParent();
if( (parentWnd != 0) && parentWnd->IsKindOf(RUNTIME_CLASS(CView)) )
{
CRect rcParent;
parentWnd->GetWindowRect(rcParent);
rcWindow.OffsetRect(-rcParent.left,-rcParent.top);
}
// end add
CRect rcBorder = rcWindow;
rcBorder -= rcClient;
// Min and Max info
int minWidth = m_RootPane->getMinConstrainHorz() + rcBorder.Width() + 2*m_sizeRootBorders.cx;
int minHeight = m_RootPane->getMinConstrainVert() + rcBorder.Height() + 2*m_sizeRootBorders.cy;
int maxWidth = m_RootPane->getMaxConstrainHorz();
if(maxWidth != -1) {
maxWidth += rcBorder.Width() + 2*m_sizeRootBorders.cx;
maxWidth = max(maxWidth, minWidth);
}
int maxHeight = m_RootPane->getMaxConstrainVert();
if(maxHeight != -1) {
maxHeight += rcBorder.Height() + 2*m_sizeRootBorders.cy;
maxHeight = max(maxHeight, minHeight);
}
if(rcWindow.Width() < minWidth)
rcWindow.right = rcWindow.left + minWidth;
if(rcWindow.Height() < minHeight)
rcWindow.bottom = rcWindow.top + minHeight;
if(maxWidth != -1 && rcWindow.Width() > maxWidth)
rcWindow.right = rcWindow.left + maxWidth;
if(maxHeight != -1 && rcWindow.Height() > maxHeight)
rcWindow.bottom = rcWindow.top + maxHeight;
m_pWnd->MoveWindow(rcWindow);
}
// Do the Layout
rcClient = GetRect();
// Add a Border around the rootPane
rcClient.top += m_sizeRootBorders.cy;
rcClient.bottom -= m_sizeRootBorders.cy;
rcClient.left += m_sizeRootBorders.cx;
rcClient.right -= m_sizeRootBorders.cx;
if(GetWnd()->IsWindowVisible()) {
// Avoid ugly artifacts
//GetWnd()->SetRedraw(FALSE);
Layout(rcClient);
//GetWnd()->SetRedraw(TRUE);
}
else
Layout(rcClient);
// Take special care of SpinButtons (Up-Down Controls) with Buddy set, enumerate
// all childs:
CWnd* pWndChild = GetWnd()->GetWindow(GW_CHILD);
TCHAR szClassName[ MAX_PATH ];
while(pWndChild)
{
::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH );
DWORD dwStyle = pWndChild->GetStyle();
// is it a SpinButton?
if( _tcscmp(szClassName, UPDOWN_CLASS)==0 && ::IsWindowVisible(pWndChild->GetSafeHwnd()) ) {
HWND hwndBuddy = (HWND)::SendMessage( pWndChild->GetSafeHwnd(), UDM_GETBUDDY, 0, 0);
if( hwndBuddy != 0 && (dwStyle&(UDS_ALIGNRIGHT|UDS_ALIGNLEFT)) != 0 )
{
// reset Buddy
::SendMessage( pWndChild->GetSafeHwnd(), UDM_SETBUDDY, (WPARAM)hwndBuddy, 0);
}
}
pWndChild = pWndChild->GetWindow(GW_HWNDNEXT);
}
GetWnd()->Invalidate();
}
bool ETSLayoutMgr::Save(LPCTSTR lpstrRegKey)
{
CRect rcWnd;
if(IsWindow(GetWnd()->m_hWnd))
{
WINDOWPLACEMENT wp;
if(GetWnd()->GetWindowPlacement(&wp))
{
// Make sure we don't pop up
// minimized the next time
if(wp.showCmd != SW_SHOWMAXIMIZED)
wp.showCmd = SW_SHOWNORMAL;
AfxGetApp()->WriteProfileBinary(lpstrRegKey,
_T("WindowPlacement"),
reinterpret_cast<LPBYTE>(&wp), sizeof(wp));
}
}
return true;
}
bool ETSLayoutMgr::Load(LPCTSTR lpstrRegKey)
{
LPBYTE pbtData = 0;
UINT nSize = 0;
if(AfxGetApp()->GetProfileBinary(lpstrRegKey,
_T("WindowPlacement"), &pbtData, &nSize))
{
WINDOWPLACEMENT* pwp =
reinterpret_cast<WINDOWPLACEMENT*>(pbtData);
ASSERT(nSize == sizeof(WINDOWPLACEMENT));
if(nSize == sizeof(WINDOWPLACEMENT))
GetWnd()->SetWindowPlacement(reinterpret_cast<WINDOWPLACEMENT*>(pbtData));
delete [] pbtData;
}
return true;
}
void ETSLayoutMgr::EraseBkgnd(CDC* pDC)
{
CRect rcClient;
GetWnd()->GetClientRect( rcClient );
CRgn rgn;
rgn.CreateRectRgnIndirect(rcClient);
TRACE("CreateRgn (%d,%d,%d,%d)\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom );
CRgn rgnRect;
rgnRect.CreateRectRgn(0,0,0,0);
CRect rcChild;
CWnd* pWndChild = GetWnd()->GetWindow( GW_CHILD );
TCHAR szClassName[ MAX_PATH ];
pDC->SelectClipRgn(NULL);
while( pWndChild ) {
pWndChild->GetWindowRect(rcChild);
GetWnd()->ScreenToClient( rcChild );
rgnRect.SetRectRgn( rcChild );
::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH );
DWORD dwStyle = pWndChild->GetStyle();
// doesn't make sense for hidden children
if( dwStyle & WS_VISIBLE ) {
// Fix: BS_GROUPBOX is more than one Bit, extend check to (dwStyle & BS_GROUPBOX)==BS_GROUPBOX [ET]
if( _tcscmp(szClassName,_T("Button"))==0 && (dwStyle & BS_GROUPBOX)==BS_GROUPBOX ) {
// it is a group-box, ignore completely
}
else if( _tcscmp(szClassName,WC_TABCONTROL )==0 ) {
// ignore Tab-Control's inside rect
static_cast<CTabCtrl*>(pWndChild)->AdjustRect(FALSE,rcChild);
CRgn rgnContent;
rgnContent.CreateRectRgnIndirect(rcChild);
rgnRect.CombineRgn( &rgnRect, &rgnContent, RGN_DIFF );
rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF );
}
else if( _tcscmp(szClassName,STATUSCLASSNAME)==0 ) {
CPoint ptTriangleGrip[3];
ptTriangleGrip[0] = CPoint(rcChild.right,rcChild.top);
ptTriangleGrip[1] = CPoint(rcChild.right,rcChild.bottom);
ptTriangleGrip[2] = CPoint(rcChild.right-rcChild.Height(),rcChild.bottom);
CRgn rgnGripper;
rgnGripper.CreatePolygonRgn(ptTriangleGrip,3, WINDING);
rgn.CombineRgn( &rgn, &rgnGripper, RGN_DIFF );
}
else {
rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF );
}
}
pWndChild = pWndChild->GetNextWindow();
}
HBRUSH hBrBack = (HBRUSH) ::GetClassLong(GetWnd()->GetSafeHwnd(), GCL_HBRBACKGROUND) ;
if( hBrBack == 0 )
hBrBack = ::GetSysColorBrush(COLOR_BTNFACE);
pDC->FillRgn( &rgn,
CBrush::FromHandle( hBrBack )
);
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneItem implementation
ETSLayoutMgr::PaneItem::PaneItem(CWnd* pWnd, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/
, int sizeX/*=0*/, int sizeY/*=0*/
, int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr )
{
m_modeResize = modeResize;
m_hwndCtrl = pWnd->GetSafeHwnd();
m_sizeX = 0;
m_sizeY = 0;
m_bComboSpecial = false;
m_sizeXMin = sizeXMin;
m_sizeYMin = sizeYMin;
if(!m_hwndCtrl) { // only Dummy!
m_sizeX = sizeX;
m_sizeY = sizeY;
}
else {
CRect rcControl;
::GetWindowRect(m_hwndCtrl, &rcControl);
if(sizeX == 0) {
m_sizeX = rcControl.Width();
}
else {
m_sizeX = sizeX;
}
if( m_sizeXMin == -1 ) {
// do not make smaller than current size
m_sizeXMin = rcControl.Width();
}
if(sizeY == 0) {
m_sizeY = rcControl.Height();
}
else {
m_sizeY = sizeY;
}
if( m_sizeYMin == -1 ) {
// do not make smaller than current size
m_sizeYMin = rcControl.Height();
}
TCHAR szClassName[ MAX_PATH ];
::GetClassName( m_hwndCtrl, szClassName, MAX_PATH );
// special treatment for combo-boxes
if( _tcscmp(szClassName,_T("ComboBox"))==0 || _tcscmp(szClassName,WC_COMBOBOXEX)==0) {
m_bComboSpecial = true;
}
}
}
ETSLayoutMgr::PaneItem::PaneItem( UINT nID, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/
, int sizeX/*=0*/, int sizeY/*=0*/
, int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr )
{
CWnd* pWnd = pMgr->GetWnd()->GetDlgItem(nID);
m_hwndCtrl = pWnd->GetSafeHwnd();
m_sizeX = 0;
m_sizeY = 0;
m_bComboSpecial = false;
m_modeResize = modeResize;
m_sizeXMin = sizeXMin;
m_sizeYMin = sizeYMin;
if(!m_hwndCtrl) { // only Dummy!
m_sizeX = sizeX;
m_sizeY = sizeY;
}
else {
CRect rcControl;
::GetWindowRect(m_hwndCtrl, &rcControl);
if(sizeX == 0) {
m_sizeX = rcControl.Width();
}
else {
m_sizeX = sizeX;
}
if( m_sizeXMin == -1 ) {
// do not make smaller than current size
m_sizeXMin = rcControl.Width();
}
if(sizeY == 0) {
m_sizeY = rcControl.Height();
}
else {
m_sizeY = sizeY;
}
if( m_sizeYMin == -1 ) {
// do not make smaller than current size
m_sizeYMin = rcControl.Height();
}
TCHAR szClassName[ MAX_PATH ];
::GetClassName( m_hwndCtrl, szClassName, MAX_PATH );
// special treatment for combo-boxes
if( _tcscmp(szClassName,_T("ComboBox"))==0 || _tcscmp(szClassName,WC_COMBOBOXEX)==0) {
m_bComboSpecial = true;
}
}
}
int ETSLayoutMgr::PaneItem::getConstrainHorz(int sizeParent)
{
if( m_modeResize & ABSOLUTE_HORZ) {
return m_sizeX;
}
if(m_modeResize & RELATIVE_HORZ) {
return (sizeParent * m_sizeX) / 100;
}
return -1;
}
int ETSLayoutMgr::PaneItem::getConstrainVert(int sizeParent)
{
if(m_modeResize & ABSOLUTE_VERT) {
return m_sizeY;
}
if(m_modeResize & RELATIVE_VERT) {
return (sizeParent * m_sizeY) / 100;
}
return -1;
}
int ETSLayoutMgr::PaneItem::getMinConstrainHorz()
{
if(m_modeResize & ABSOLUTE_HORZ) {
return m_sizeX;
}
return max(nMinConstrain,m_sizeXMin);
}
int ETSLayoutMgr::PaneItem::getMinConstrainVert()
{
if(m_modeResize & ABSOLUTE_VERT) {
return m_sizeY;
}
return max(nMinConstrain,m_sizeYMin);
}
int ETSLayoutMgr::PaneItem::getMaxConstrainHorz()
{
if(m_modeResize & ABSOLUTE_HORZ) {
return m_sizeX;
}
return -1;
}
int ETSLayoutMgr::PaneItem::getMaxConstrainVert()
{
if(m_modeResize & ABSOLUTE_VERT) {
return m_sizeY;
}
return -1;
}
bool ETSLayoutMgr::PaneItem::resizeTo(CRect& rcNewArea)
{
if(m_hwndCtrl) {
CRect rcWnd;
::GetWindowRect( m_hwndCtrl, rcWnd );
if( !(m_modeResize & ALIGN_FILL_HORZ) && m_modeResize & ABSOLUTE_HORZ ) {
if( (m_modeResize & ALIGN_HCENTER) == ALIGN_HCENTER ) {
rcNewArea.OffsetRect( (rcNewArea.Width() - rcWnd.Width())/2, 0 );
}
else if( m_modeResize & ALIGN_RIGHT ) {
rcNewArea.OffsetRect( rcNewArea.Width() - rcWnd.Width(), 0 );
}
rcNewArea.right = rcNewArea.left + rcWnd.Width();
}
if( !(m_modeResize & ALIGN_FILL_VERT) && m_modeResize & ABSOLUTE_VERT ) {
if( (m_modeResize & ALIGN_VCENTER) == ALIGN_VCENTER ) {
rcNewArea.OffsetRect( 0, (rcNewArea.Height()-rcWnd.Height())/2 );
}
else if( m_modeResize & ALIGN_BOTTOM ) {
rcNewArea.OffsetRect( 0, rcNewArea.Height() - rcWnd.Height());
}
rcNewArea.bottom = rcNewArea.top + rcWnd.Height();
}
DWORD dwStyle = ::GetWindowLong( m_hwndCtrl, GWL_STYLE );
// special treatment for combo-boxes
if( m_bComboSpecial && (dwStyle & CBS_DROPDOWN) ) {
// keep height (though only fully visible when dropped down)
rcNewArea.bottom = rcNewArea.top + rcWnd.Height();
}
// FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman]
CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl );
pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height() );
if( m_bComboSpecial && !(dwStyle & CBS_DROPDOWN) && !(dwStyle & CBS_NOINTEGRALHEIGHT) ) {
// Keep CB Size = Edit + LB ( if not CBS_NOINTEGRALHEIGHT)
::GetWindowRect( m_hwndCtrl, rcWnd );
CRect rcListBox;
HWND hwndListBox = ::GetDlgItem(m_hwndCtrl, 1000); // ListBox of CB
if( hwndListBox != 0 )
{
::GetWindowRect( hwndListBox, rcListBox );
rcWnd.bottom = rcListBox.bottom;
rcNewArea.bottom = rcNewArea.top + rcWnd.Height();
// FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman]
CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl );
pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true );
}
}
::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW );
}
return true;
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneTab implementation
ETSLayoutMgr::PaneTab::PaneTab( CTabCtrl* pTab, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder)
{
ASSERT(pTab);
m_pTab = pTab;
}
int ETSLayoutMgr::PaneTab::getConstrainHorz(int sizeParent)
{
CRect rcTab;
m_pTab->AdjustRect(TRUE, &rcTab);
if(rcTab.Width() > sizeParent)
return rcTab.Width();
return Pane::getConstrainHorz(sizeParent /*- rcTab.Width()*/);
}
int ETSLayoutMgr::PaneTab::getConstrainVert(int sizeParent)
{
CRect rcTab;
m_pTab->AdjustRect(TRUE, &rcTab);
if( m_modeResize & ABSOLUTE_VERT ) {
return m_sizeSecondary + rcTab.Height();
}
if(rcTab.Height() > sizeParent)
return rcTab.Height();
return Pane::getConstrainVert(sizeParent /*- rcTab.Height()*/);
}
int ETSLayoutMgr::PaneTab::getMinConstrainHorz()
{
CRect rcTab(0,0,0,0);
m_pTab->AdjustRect(TRUE, &rcTab);
return Pane::getMinConstrainHorz() + rcTab.Width() ;
}
int ETSLayoutMgr::PaneTab::getMinConstrainVert()
{
CRect rcTab(0,0,0,0);
m_pTab->AdjustRect(TRUE, &rcTab);
return Pane::getMinConstrainVert() + rcTab.Height();
}
int ETSLayoutMgr::PaneTab::getMaxConstrainHorz()
{
CRect rcTab(0,0,0,0);
m_pTab->AdjustRect(TRUE, &rcTab);
int paneMax = Pane::getMaxConstrainHorz();
return (paneMax != -1) ? paneMax + rcTab.Width() : -1;
}
int ETSLayoutMgr::PaneTab::getMaxConstrainVert()
{
CRect rcTab(0,0,0,0);
m_pTab->AdjustRect(TRUE, &rcTab);
int paneMax = Pane::getMaxConstrainVert();
return (paneMax != -1) ? paneMax + rcTab.Height() : -1;
}
bool ETSLayoutMgr::PaneTab::resizeTo(CRect& rcNewArea)
{
m_pTab->MoveWindow(rcNewArea);
m_pTab->AdjustRect(FALSE,rcNewArea);
return Pane::resizeTo(rcNewArea);
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::PaneCtrl implementation
ETSLayoutMgr::PaneCtrl::PaneCtrl( CWnd* pCtrl, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder)
{
m_sizeTopExtra = sizeTopExtra;
ASSERT(pCtrl);
m_hwndCtrl = pCtrl->GetSafeHwnd();
}
ETSLayoutMgr::PaneCtrl::PaneCtrl( UINT nID, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ )
: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder)
{
m_sizeTopExtra = sizeTopExtra;
m_hwndCtrl = ::GetDlgItem(pMgr->GetWnd()->GetSafeHwnd(), nID);
ASSERT(m_hwndCtrl);
}
int ETSLayoutMgr::PaneCtrl::getConstrainHorz(int sizeParent)
{
return Pane::getConstrainHorz(sizeParent) ;
}
int ETSLayoutMgr::PaneCtrl::getConstrainVert(int sizeParent)
{
return Pane::getConstrainVert(sizeParent);
}
int ETSLayoutMgr::PaneCtrl::getMinConstrainHorz()
{
return Pane::getMinConstrainHorz();
}
int ETSLayoutMgr::PaneCtrl::getMinConstrainVert()
{
return Pane::getMinConstrainVert() + m_sizeTopExtra;
}
int ETSLayoutMgr::PaneCtrl::getMaxConstrainHorz()
{
int paneMax = Pane::getMaxConstrainHorz();
return ( paneMax == -1) ? -1 : paneMax ;
}
int ETSLayoutMgr::PaneCtrl::getMaxConstrainVert()
{
int paneMax = Pane::getMaxConstrainVert();
return ( paneMax == -1) ? -1 : paneMax + m_sizeTopExtra;
}
bool ETSLayoutMgr::PaneCtrl::resizeTo(CRect& rcNewArea)
{
// FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman]
CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl );
pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true );
::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW |RDW_ERASE);
rcNewArea.top += m_sizeTopExtra;
return Pane::resizeTo(rcNewArea);
}
/////////////////////////////////////////////////////////////////////////////
// ETSLayoutMgr::Pane implementation
ETSLayoutMgr::Pane::Pane( ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /* = nDefaultBorder */, int sizeExtraBorder /*= 0*/)
: PaneBase(pMgr)
{
m_Orientation = orientation;
m_sizeBorder = sizeBorder;
m_sizeSecondary = 0;
m_modeResize = 0;
m_sizeExtraBorder= sizeExtraBorder;
}
ETSLayoutMgr::Pane::~Pane()
{
}
bool ETSLayoutMgr::Pane::addItem( CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/)
{
CPaneBase pItem = new PaneItem( pWnd, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
return addPane( pItem );
}
bool ETSLayoutMgr::Pane::addItem( UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/)
{
CPaneBase pItem = new PaneItem( nID, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin);
return addPane( pItem );
}
bool ETSLayoutMgr::Pane::addItemFixed(int size)
{
CPaneBase pNewItem = m_pMgr->itemFixed(m_Orientation, size);
return addPane( pNewItem );
}
bool ETSLayoutMgr::Pane::addItemGrowing()
{
CPaneBase pNewItem = m_pMgr->itemGrowing(m_Orientation);
return addPane( pNewItem );
}
bool ETSLayoutMgr::Pane::addItemSpaceBetween( CWnd* pWndFirst, CWnd* pWndSecond )
{
CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, pWndFirst, pWndSecond);
return addPane( pNewItem );
}
bool ETSLayoutMgr::Pane::addItemSpaceBetween( UINT nIDFirst, UINT nIDSecond )
{
CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, nIDFirst, nIDSecond);
return addPane( pNewItem );
}