-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMySplitterWnd.cpp
More file actions
1947 lines (1698 loc) · 49.9 KB
/
MySplitterWnd.cpp
File metadata and controls
1947 lines (1698 loc) · 49.9 KB
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
/*
Copyright (c) 2006 Tristan Lorach (lorachnroll@gmail.com)
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
// MySplitterWnd.cpp : implementation file
//
#include "stdafx.h"
#include <afxpriv.h>
#include "..\src\mfc\AFXIMPL.H"
#include "SvcMFCUI.h"
#include "MySplitterWnd.h"
#ifndef GWL_USERDATA
# define GWL_USERDATA -21
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifdef AFX_CORE3_SEG
#pragma code_seg(AFX_CORE3_SEG)
#endif
IMPLEMENT_RUNTIMECLASS(CMySplitterWnd, CWnd, -1, NULL, NULL);
/////////////////////////////////////////////////////////////////////////////
// Visual attributes and other constants
// HitTest return values (values and spacing between values is important)
enum HitTestValue
{
noHit = 0,
vSplitterBox = 1,
hSplitterBox = 2,
bothSplitterBox = 3, // just for keyboard
vSplitterBar1 = 101,
vSplitterBar15 = 115,
hSplitterBar1 = 201,
hSplitterBar15 = 215,
splitterIntersection1 = 301,
splitterIntersection225 = 525
};
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd
BEGIN_MESSAGE_MAP(CMySplitterWnd, CWnd)
//{{AFX_MSG_MAP(CMySplitterWnd)
ON_WM_SETCURSOR()
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_LBUTTONUP()
ON_WM_KEYDOWN()
ON_WM_SIZE()
ON_WM_HSCROLL()
ON_WM_VSCROLL()
ON_WM_NCCREATE()
ON_WM_SYSCOMMAND()
ON_WM_CANCELMODE()
ON_MESSAGE_VOID(WM_DISPLAYCHANGE, OnDisplayChange)
ON_MESSAGE_VOID(WM_WININICHANGE, OnDisplayChange)
ON_MESSAGE_VOID(WM_SETTINGCHANGE, OnDisplayChange)
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd construction/destruction
CMySplitterWnd::CMySplitterWnd()
{
// zero fill everything after the vtbl pointer
#define AFX_ZERO_INIT_OBJECT(base_class) \
memset(((base_class*)this)+1, 0, sizeof(*this) - sizeof(class base_class));
AFX_ZERO_INIT_OBJECT(CWnd);
// default splitter box/bar sizes (includes borders)
//if (afxData.bWin95)
//{
// m_cxSplitter = m_cySplitter = 4;
// m_cxBorderShare = m_cyBorderShare = 1;
// m_cxSplitterGap = m_cySplitterGap = 4 + 1 + 1;
// ASSERT(m_cxBorder == 0 && m_cyBorder == 0);
//}
//else
{
m_cxSplitter = m_cySplitter = 3 + 2 + 2;
m_cxBorderShare = m_cyBorderShare = 0;
m_cxSplitterGap = m_cySplitterGap = 3 + 2 + 2;
m_cxBorder = m_cyBorder = 2;
}
#ifdef _DEBUG
if (GetSystemMetrics(SM_CXBORDER) != 1 ||
GetSystemMetrics(SM_CYBORDER) != 1)
{
TRACE0("Warning: CMySplitterWnd assumes 1 pixel border.\n");
// will look ugly if borders are not 1 pixel wide and 1 pixel high
}
#endif
m_pRowInfo = NULL;
m_pColInfo = NULL;
}
CMySplitterWnd::~CMySplitterWnd()
{
delete[] m_pRowInfo;
delete[] m_pColInfo;
}
BOOL CMySplitterWnd::Create(CWnd* pParentWnd,
int nMaxRows, int nMaxCols, SIZE sizeMin,
CCreateContext* pContext, DWORD dwStyle, UINT nID)
{
return FALSE;
}
// simple "wiper" splitter
BOOL CMySplitterWnd::CreateStatic(CWnd* pParentWnd,
int nRows, int nCols, DWORD dwStyle, UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(nRows >= 1 && nRows <= 16);
ASSERT(nCols >= 1 && nCols <= 16);
ASSERT(nCols > 1 || nRows > 1); // 1x1 is not permitted
ASSERT(dwStyle & WS_CHILD);
ASSERT(!(dwStyle & SPLS_DYNAMIC_SPLIT)); // can't have dynamic split
ASSERT(m_nRows == 0 && m_nCols == 0); // none yet
m_nMaxRows = nRows;
m_nMaxCols = nCols;
m_nRows = m_nCols = 1; // start off as 1x1
// create with zero minimum pane size
if (!CreateCommon(pParentWnd, CSize(10, 10), dwStyle, nID))
return FALSE;
ASSERT(m_nRows == 1 && m_nCols == 1); // still 1x1
// all panes must be created with explicit calls to CreateView
return TRUE;
}
BOOL CMySplitterWnd::CreateCommon(CWnd* pParentWnd,
SIZE sizeMin, DWORD dwStyle, UINT nID)
{
ASSERT(pParentWnd != NULL);
ASSERT(sizeMin.cx >= 0 && sizeMin.cy >= 0);
ASSERT(dwStyle & WS_CHILD);
ASSERT(nID != 0);
ASSERT(m_pColInfo == NULL && m_pRowInfo == NULL); // only do once
ASSERT(m_nMaxCols > 0 && m_nMaxRows > 0);
// the Windows scroll bar styles bits turn on the smart scrollbars
DWORD dwCreateStyle = dwStyle & ~(WS_HSCROLL|WS_VSCROLL);
//if (!afxData.bWin95)
dwCreateStyle &= ~WS_BORDER;
VERIFY(AfxDeferRegisterClass(AFX_WNDMDIFRAME_REG));
// create with the same wnd-class as MDI-Frame (no erase bkgnd)
if (!CreateEx(0, /*_afxWndMDIFrame*/AFX_WNDMDIFRAME, NULL, dwCreateStyle, 0, 0, 0, 0,
pParentWnd->m_hWnd, (HMENU)nID, NULL))
return FALSE; // create invisible
// attach the initial splitter parts
TRY
{
if(m_pColInfo)
delete [] m_pColInfo;
m_pColInfo = new CRowColInfo[m_nMaxCols];
for (int col = 0; col < m_nMaxCols; col++)
{
m_pColInfo[col].nMinSize = m_pColInfo[col].nIdealSize = sizeMin.cx;
m_pColInfo[col].nCurSize = -1; // will be set in RecalcLayout
}
if(m_pRowInfo)
delete [] m_pRowInfo;
m_pRowInfo = new CRowColInfo[m_nMaxRows];
for (int row = 0; row < m_nMaxRows; row++)
{
m_pRowInfo[row].nMinSize = m_pRowInfo[row].nIdealSize = sizeMin.cy;
m_pRowInfo[row].nCurSize = -1; // will be set in RecalcLayout
}
// create scroll bars by setting the style
SetScrollStyle(dwStyle);
}
CATCH_ALL(e)
{
DestroyWindow(); // will clean up child windows
// Note: DELETE_EXCEPTION(e) not required
return FALSE;
}
END_CATCH_ALL
return TRUE;
}
BOOL CMySplitterWnd::OnNcCreate(LPCREATESTRUCT lpcs)
{
if (!CWnd::OnNcCreate(lpcs))
return FALSE;
// remove WS_EX_CLIENTEDGE style from parent window
// (the splitter itself will provide the 3d look)
CWnd* pParent = GetParent();
//ASSERT_VALID(pParent);
pParent->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd default creation of parts
// You must create ALL panes unless DYNAMIC_SPLIT is defined!
// Usually the splitter window is invisible when creating a pane
BOOL CMySplitterWnd::CreateView(int row, int col,
CRuntimeClass* pViewClass, SIZE sizeInit, CCreateContext* pContext)
{
return FALSE;
}
BOOL CMySplitterWnd::CreateScrollBarCtrl(DWORD dwStyle, UINT nID)
{
//ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
HWND hWnd = ::CreateWindow(_T("SCROLLBAR"), NULL,
dwStyle | WS_VISIBLE | WS_CHILD,
0, 0, 1, 1, m_hWnd, (HMENU)nID,
AfxGetInstanceHandle(), NULL);
#ifdef _DEBUG
if (hWnd == NULL)
TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
GetLastError());
#endif
return hWnd != NULL;
}
int CMySplitterWnd::IdFromRowCol(int row, int col) const
{
//ASSERT_VALID(this);
ASSERT(row >= 0);
ASSERT(row < m_nRows);
ASSERT(col >= 0);
ASSERT(col < m_nCols);
return AFX_IDW_PANE_FIRST + row * 16 + col;
}
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd attributes
CWnd* CMySplitterWnd::GetPane(int row, int col) const
{
//ASSERT_VALID(this);
CWnd* pView;// = GetDlgItem(IdFromRowCol(row, col));
int i = IdFromRowCol(row, col);
pView = this->GetWindow(GW_CHILD);
if(pView) do {
int l = GetWindowLong(pView->m_hWnd, GWL_USERDATA);
if(i == l)
break;
pView = pView->GetNextWindow();
} while(pView);
return pView;
}
BOOL CMySplitterWnd::IsChildPane(CWnd* pWnd, int* pRow, int* pCol)
{
//ASSERT_VALID(this);
//ASSERT_VALID(pWnd);
UINT nID = GetWindowLong(pWnd->m_hWnd, GWL_USERDATA);// _AfxGetDlgCtrlID(pWnd->m_hWnd);
if (IsChild(pWnd) && nID >= AFX_IDW_PANE_FIRST && nID <= AFX_IDW_PANE_LAST)
{
if (pRow != NULL)
*pRow = (nID - AFX_IDW_PANE_FIRST) / 16;
if (pCol != NULL)
*pCol = (nID - AFX_IDW_PANE_FIRST) % 16;
ASSERT(pRow == NULL || *pRow < m_nRows);
ASSERT(pCol == NULL || *pCol < m_nCols);
return TRUE;
}
else
{
if (pRow != NULL)
*pRow = -1;
if (pCol != NULL)
*pCol = -1;
return FALSE;
}
}
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd information access
// The get routines return the current size
// The set routines set the ideal size
// RecalcLayout must be called to update current size
void CMySplitterWnd::GetRowInfo(int row, int& cyCur, int& cyMin) const
{
//ASSERT_VALID(this);
ASSERT(row >= 0 && row < m_nMaxRows);
cyCur = m_pRowInfo[row].nCurSize;
cyMin = m_pRowInfo[row].nMinSize;
}
void CMySplitterWnd::SetRowInfo(int row, int cyIdeal, int cyMin)
{
//ASSERT_VALID(this);
ASSERT(row >= 0 && row < m_nMaxRows);
ASSERT(cyIdeal >= 0);
ASSERT(cyMin >= 0);
m_pRowInfo[row].nIdealSize = cyIdeal;
m_pRowInfo[row].nMinSize = cyMin;
}
void CMySplitterWnd::GetColumnInfo(int col, int& cxCur, int& cxMin) const
{
//ASSERT_VALID(this);
ASSERT(col >= 0 && col < m_nMaxCols);
cxCur = m_pColInfo[col].nCurSize;
cxMin = m_pColInfo[col].nMinSize;
}
void CMySplitterWnd::SetColumnInfo(int col, int cxIdeal, int cxMin)
{
//ASSERT_VALID(this);
ASSERT(col >= 0 && col < m_nMaxCols);
ASSERT(cxIdeal >= 0);
ASSERT(cxMin >= 0);
m_pColInfo[col].nIdealSize = cxIdeal;
m_pColInfo[col].nMinSize = cxMin;
}
DWORD CMySplitterWnd::GetScrollStyle() const
{
DWORD dwStyle = 0;
if (m_bHasHScroll)
dwStyle |= WS_HSCROLL;
if (m_bHasVScroll)
dwStyle |= WS_VSCROLL;
return dwStyle;
}
void CMySplitterWnd::SetScrollStyle(DWORD dwStyle)
{
// optimize for scroll info already set correctly
dwStyle &= (WS_HSCROLL|WS_VSCROLL);
if (GetScrollStyle() == dwStyle)
return;
// update to new state
m_bHasHScroll = (dwStyle & WS_HSCROLL) != 0;
m_bHasVScroll = (dwStyle & WS_VSCROLL) != 0;
CWnd* pScrollBar;
// show/hide all the shared horz scroll bars
for (int col = 0; col < m_nCols; col++)
{
pScrollBar = GetDlgItem(AFX_IDW_HSCROLL_FIRST + col);
if (pScrollBar == NULL)
{
// create the scroll bar when necessary
if (!CreateScrollBarCtrl(SBS_HORZ, AFX_IDW_HSCROLL_FIRST + col))
AfxThrowResourceException();
pScrollBar = GetDlgItem(AFX_IDW_HSCROLL_FIRST + col);
}
pScrollBar->ShowWindow(m_bHasHScroll ? SW_SHOW : SW_HIDE);
}
// show/hide all the shared vert scroll bars
for (int row = 0; row < m_nRows; row++)
{
pScrollBar = GetDlgItem(AFX_IDW_VSCROLL_FIRST + row);
if (pScrollBar == NULL)
{
// create the scroll bar when necessary
if (!CreateScrollBarCtrl(SBS_VERT, AFX_IDW_VSCROLL_FIRST + row))
AfxThrowResourceException();
pScrollBar = GetDlgItem(AFX_IDW_VSCROLL_FIRST + row);
}
pScrollBar->ShowWindow(m_bHasVScroll ? SW_SHOW : SW_HIDE);
}
// show/destroy size box if necessary
if (m_bHasVScroll && m_bHasHScroll)
{
pScrollBar = GetDlgItem(AFX_IDW_SIZE_BOX);
if (pScrollBar == NULL)
{
// create size box when necessary
if (!CreateScrollBarCtrl(SBS_SIZEBOX|WS_DISABLED, AFX_IDW_SIZE_BOX))
AfxThrowResourceException();
pScrollBar = GetDlgItem(AFX_IDW_SIZE_BOX);
}
pScrollBar->ShowWindow(SW_SHOW);
}
else
{
// the size box can be destroyed instead of hidden
pScrollBar = GetDlgItem(AFX_IDW_SIZE_BOX);
if (pScrollBar != NULL)
pScrollBar->DestroyWindow();
}
// Note: call RecalcLayout for the new layout to take effect
}
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd client operations/overridables
void CMySplitterWnd::OnDrawSplitter(CDC* pDC, ESplitType nType,
const CRect& rectArg)
{
// if pDC == NULL, then just invalidate
if (pDC == NULL)
{
RedrawWindow(rectArg, NULL, RDW_INVALIDATE|RDW_NOCHILDREN);
return;
}
//ASSERT_VALID(pDC);
// otherwise, actually draw
CRect rect = rectArg;
switch (nType)
{
case splitBorder:
//ASSERT(!afxData.bWin95);
pDC->Draw3dRect(rect, afxData.clrBtnShadow, afxData.clrBtnHilite);
//rect.InflateRect(-CX_BORDER, -CY_BORDER);
pDC->Draw3dRect(rect, afxData.clrWindowFrame, afxData.clrBtnFace);
return;
case splitIntersection:
//ASSERT(afxData.bWin95);
break;
case splitBox:
//if (!afxData.bWin95)
{
pDC->Draw3dRect(rect, afxData.clrBtnFace, afxData.clrWindowFrame);
//rect.InflateRect(-CX_BORDER, -CY_BORDER);
pDC->Draw3dRect(rect, afxData.clrBtnHilite, afxData.clrBtnShadow);
//rect.InflateRect(-CX_BORDER, -CY_BORDER);
break;
}
// fall through...
case splitBar:
//if (afxData.bWin95)
//{
// pDC->Draw3dRect(rect, afxData.clrBtnHilite, afxData.clrBtnShadow);
// rect.InflateRect(-CX_BORDER, -CY_BORDER);
//}
break;
default:
ASSERT(FALSE); // unknown splitter type
}
// fill the middle
COLORREF clr = afxData.clrBtnFace;
pDC->FillSolidRect(rect, clr);
}
/////////////////////////////////////////////////////////////////////////////
// Dynamic row/col split etc
AFX_STATIC int AFXAPI _AfxCanSplitRowCol(CMySplitterWnd::CRowColInfo* pInfoBefore,
int nBeforeSize, int nSizeSplitter)
// request to split Before row at point nBeforeSize
// returns size of new pane (nBeforeSize will be new size of Before pane)
// return -1 if not big enough
{
// ASSERT(pInfoBefore->nCurSize > 0);
// ASSERT(pInfoBefore->nMinSize > 0);
//ASSERT(nBeforeSize <= pInfoBefore->nCurSize);
// space gets take from before pane (weird UI for > 2 splits)
if (nBeforeSize < pInfoBefore->nMinSize)
{
TRACE0("Warning: split too small to fit in a new pane.\n");
return 20;//-1;
}
int nNewSize = pInfoBefore->nCurSize - nBeforeSize - nSizeSplitter;
if (nBeforeSize < pInfoBefore->nMinSize)
{
TRACE0("Warning: split too small to shrink old pane.\n");
return 20;//-1;
}
if (nNewSize < (pInfoBefore+1)->nMinSize)
{
//TRACE0("Warning: split too small to create new pane.\n");
//return -1;
nNewSize = pInfoBefore->nCurSize / 2;
}
return nNewSize;
}
BOOL CMySplitterWnd::SplitRow(int cyBefore)
{
//ASSERT_VALID(this);
ASSERT(m_nRows < m_nMaxRows);
cyBefore -= m_cyBorder;
int rowNew = m_nRows;
int cyNew = _AfxCanSplitRowCol(&m_pRowInfo[rowNew-1], cyBefore, m_cySplitter);
if (cyNew == -1)
return FALSE; // too small to split
m_nRows++; // bump count during view creation
// new parts created - resize and re-layout
m_pRowInfo[rowNew-1].nIdealSize = cyBefore;
m_pRowInfo[rowNew].nIdealSize = cyNew;
ASSERT(m_nRows == rowNew+1);
RecalcLayout();
return TRUE;
}
BOOL CMySplitterWnd::SplitColumn(int cxBefore)
{
//ASSERT_VALID(this);
ASSERT(m_nCols < m_nMaxCols);
cxBefore -= m_cxBorder;
int colNew = m_nCols;
int cxNew = _AfxCanSplitRowCol(&m_pColInfo[colNew-1], cxBefore, m_cxSplitter);
if (cxNew == -1)
return FALSE; // too small to split
m_nCols++; // bump count during view creation
// new parts created - resize and re-layout
m_pColInfo[colNew-1].nIdealSize = cxBefore;
m_pColInfo[colNew].nIdealSize = cxNew;
ASSERT(m_nCols == colNew+1);
RecalcLayout();
return TRUE;
}
void CMySplitterWnd::DeleteRow(int rowDelete)
{
//ASSERT_VALID(this);
//ASSERT(m_nRows > 1);
ASSERT(rowDelete < m_nRows);
if(m_nRows <= 1)
return;
int rowActive, colActive;
if (GetActivePane(&rowActive, &colActive) != NULL && rowActive == rowDelete)
{
if (++rowActive >= m_nRows)
rowActive = 0;
SetActivePane(rowActive, colActive);
}
CWnd* pScrollDel = m_bHasVScroll ?
GetDlgItem(AFX_IDW_VSCROLL_FIRST+rowDelete) : NULL;
for (int col = 0; col < m_nCols; col++)
{
for (int row = rowDelete+1; row < m_nRows; row++)
{
CWnd* pPane = GetPane(row, col);
if(pPane == NULL)
continue;
SetWindowLong(pPane->m_hWnd, GWL_USERDATA, IdFromRowCol(row-1, col));
m_pRowInfo[row-1] = m_pRowInfo[row];
//pPane->SetDlgCtrlID(IdFromRowCol(row-1, col));
if (m_bHasVScroll && col == m_nCols-1)
{
CWnd* pScroll = GetDlgItem(AFX_IDW_VSCROLL_FIRST+row);
if (pScroll != NULL)
pScroll->SetDlgCtrlID(AFX_IDW_VSCROLL_FIRST+row-1);
}
}
}
m_nRows--;
if (pScrollDel != NULL)
pScrollDel->DestroyWindow();
RecalcLayout(); // re-assign the space
}
void CMySplitterWnd::DeleteColumn(int colDelete)
{
//ASSERT_VALID(this);
//ASSERT(m_nCols > 1);
ASSERT(colDelete < m_nCols);
if(m_nCols <= 1)
return;
int rowActive, colActive;
if (GetActivePane(&rowActive, &colActive) != NULL && colActive == colDelete)
{
if (++colActive >= m_nCols)
colActive = 0;
SetActivePane(rowActive, colActive);
}
CWnd* pScrollDel = m_bHasHScroll ?
GetDlgItem(AFX_IDW_HSCROLL_FIRST+colDelete) : NULL;
for (int row = 0; row < m_nRows; row++)
{
for (int col = colDelete+1; col < m_nCols; col++)
{
CWnd* pPane = GetPane(row, col);
if(pPane == NULL)
continue;
SetWindowLong(pPane->m_hWnd, GWL_USERDATA, IdFromRowCol(row, col-1));
m_pColInfo[row-1] = m_pColInfo[row];
//pPane->SetDlgCtrlID(IdFromRowCol(row, col-1));
if (m_bHasHScroll && row == m_nRows-1)
{
CWnd* pScroll = GetDlgItem(AFX_IDW_HSCROLL_FIRST+col);
if (pScroll != NULL)
pScroll->SetDlgCtrlID(AFX_IDW_HSCROLL_FIRST+col-1);
}
}
}
m_nCols--;
if (pScrollDel != NULL)
pScrollDel->DestroyWindow();
RecalcLayout(); // re-assign the space
}
/////////////////////////////////////////////////////////////////////////////
// CMySplitterWnd tracking support
// like GetClientRect but inset by shared scrollbars
void CMySplitterWnd::GetInsideRect(CRect& rect) const
{
//ASSERT_VALID(this);
GetClientRect(rect);
ASSERT(rect.left == 0 && rect.top == 0);
// subtract space for 3d borders
rect.InflateRect(-m_cxBorder, -m_cyBorder);
// subtract scrollbar clearance
if (m_bHasVScroll)
rect.right -= afxData.cxVScroll/* - CX_BORDER*/;
if (m_bHasHScroll)
rect.bottom -= afxData.cyHScroll/* - CY_BORDER*/;
}
void CMySplitterWnd::StartTracking(int ht)
{
//ASSERT_VALID(this);
if (ht == noHit)
return;
// GetHitRect will restrict 'm_rectLimit' as appropriate
GetInsideRect(m_rectLimit);
if (ht >= splitterIntersection1 && ht <= splitterIntersection225)
{
// split two directions (two tracking rectangles)
int row = (ht - splitterIntersection1) / 15;
int col = (ht - splitterIntersection1) % 15;
GetHitRect(row + vSplitterBar1, m_rectTracker);
int yTrackOffset = m_ptTrackOffset.y;
m_bTracking2 = TRUE;
GetHitRect(col + hSplitterBar1, m_rectTracker2);
m_ptTrackOffset.y = yTrackOffset;
}
else if (ht == bothSplitterBox)
{
// hit on splitter boxes (for keyboard)
GetHitRect(vSplitterBox, m_rectTracker);
int yTrackOffset = m_ptTrackOffset.y;
m_bTracking2 = TRUE;
GetHitRect(hSplitterBox, m_rectTracker2);
m_ptTrackOffset.y = yTrackOffset;
// center it
m_rectTracker.OffsetRect(0, m_rectLimit.Height()/2);
m_rectTracker2.OffsetRect(m_rectLimit.Width()/2, 0);
}
else
{
// only hit one bar
GetHitRect(ht, m_rectTracker);
}
// allow active view to preserve focus before taking it away
WASACVIEW* pView = (WASACVIEW*)GetActivePane();
/*if (pView != NULL && pView->IsKindOf(RUNTIME_CLASS(WASACVIEW)))
{
//ASSERT_VALID(pView);
CFrameWnd* pFrameWnd = GetParentFrame();
//ASSERT_VALID(pFrameWnd);
//?????????????????????pView->OnActivateFrame(WA_INACTIVE, pFrameWnd);
}*/
// steal focus and capture
SetCapture();
SetFocus();
// make sure no updates are pending
RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_UPDATENOW);
// set tracking state and appropriate cursor
m_bTracking = TRUE;
OnInvertTracker(m_rectTracker);
if (m_bTracking2)
OnInvertTracker(m_rectTracker2);
m_htTrack = ht;
SetSplitCursor(ht);
}
void CMySplitterWnd::TrackRowSize(int y, int row)
{
//ASSERT_VALID(this);
ASSERT(m_nRows > 1);
CPoint pt(0, y);
ClientToScreen(&pt);
CWnd *p = GetPane(row, 0);
if(!p)
return;
p->ScreenToClient(&pt);
m_pRowInfo[row].nIdealSize = pt.y; // new size
if (pt.y < m_pRowInfo[row].nMinSize)
{
// resized too small
m_pRowInfo[row].nIdealSize = 0; // make it go away
if (GetStyle() & SPLS_DYNAMIC_SPLIT)
DeleteRow(row);
}
else if (m_pRowInfo[row].nCurSize + m_pRowInfo[row+1].nCurSize
< pt.y + m_pRowInfo[row+1].nMinSize)
{
// not enough room for other pane
if (GetStyle() & SPLS_DYNAMIC_SPLIT)
DeleteRow(row + 1);
}
}
void CMySplitterWnd::TrackColumnSize(int x, int col)
{
//ASSERT_VALID(this);
ASSERT(m_nCols > 1);
CPoint pt(x, 0);
ClientToScreen(&pt);
CWnd *p = GetPane(0, col);
if(!p)
return;
p->ScreenToClient(&pt);
m_pColInfo[col].nIdealSize = pt.x; // new size
if (pt.x < m_pColInfo[col].nMinSize)
{
// resized too small
m_pColInfo[col].nIdealSize = 0; // make it go away
if (GetStyle() & SPLS_DYNAMIC_SPLIT)
DeleteColumn(col);
}
else if (m_pColInfo[col].nCurSize + m_pColInfo[col+1].nCurSize
< pt.x + m_pColInfo[col+1].nMinSize)
{
// not enough room for other pane
if (GetStyle() & SPLS_DYNAMIC_SPLIT)
DeleteColumn(col + 1);
}
}
void CMySplitterWnd::StopTracking(BOOL bAccept)
{
//ASSERT_VALID(this);
if (!m_bTracking)
return;
ReleaseCapture();
// erase tracker rectangle
OnInvertTracker(m_rectTracker);
if (m_bTracking2)
OnInvertTracker(m_rectTracker2);
m_bTracking = m_bTracking2 = FALSE;
// save old active view
CWnd* pOldActiveView = GetActivePane();
// m_rectTracker is set to the new splitter position (without border)
// (so, adjust relative to where the border will be)
//m_rectTracker.OffsetRect(-CX_BORDER , -CY_BORDER);
//m_rectTracker2.OffsetRect(-CX_BORDER, -CY_BORDER);
if (bAccept)
{
if (m_htTrack == vSplitterBox)
{
SplitRow(m_rectTracker.top);
}
else if (m_htTrack >= vSplitterBar1 && m_htTrack <= vSplitterBar15)
{
// set row height
TrackRowSize(m_rectTracker.top, m_htTrack - vSplitterBar1);
RecalcLayout();
}
else if (m_htTrack == hSplitterBox)
{
SplitColumn(m_rectTracker.left);
}
else if (m_htTrack >= hSplitterBar1 && m_htTrack <= hSplitterBar15)
{
// set column width
TrackColumnSize(m_rectTracker.left, m_htTrack - hSplitterBar1);
RecalcLayout();
}
else if (m_htTrack >= splitterIntersection1 &&
m_htTrack <= splitterIntersection225)
{
// set row height and column width
int row = (m_htTrack - splitterIntersection1) / 15;
int col = (m_htTrack - splitterIntersection1) % 15;
TrackRowSize(m_rectTracker.top, row);
TrackColumnSize(m_rectTracker2.left, col);
RecalcLayout();
}
else if (m_htTrack == bothSplitterBox)
{
// rectTracker is vSplitter (splits rows)
// rectTracker2 is hSplitter (splits cols)
SplitRow(m_rectTracker.top);
SplitColumn(m_rectTracker2.left);
}
}
if (pOldActiveView == GetActivePane())
{
if (pOldActiveView != NULL)
{
SetActivePane(-1, -1, pOldActiveView); // re-activate
pOldActiveView->SetFocus(); // make sure focus is restored
}
}
}
void CMySplitterWnd::GetHitRect(int ht, CRect& rectHit)
{
//ASSERT_VALID(this);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.InflateRect(-m_cxBorder, -m_cyBorder);
int cx = rectClient.Width();
int cy = rectClient.Height();
int x = rectClient.top;
int y = rectClient.left;
// hit rectangle does not include border
// m_rectLimit will be limited to valid tracking rect
// m_ptTrackOffset will be set to appropriate tracking offset
m_ptTrackOffset.x = 0;
m_ptTrackOffset.y = 0;
if (ht == vSplitterBox)
{
cy = m_cySplitter - (2*m_cyBorder);// + afxData.bWin95);
m_ptTrackOffset.y = -(cy / 2);
ASSERT(m_pRowInfo[0].nCurSize > 0);
m_rectLimit.bottom -= cy;
}
else if (ht == hSplitterBox)
{
cx = m_cxSplitter - (2*m_cxBorder);// + afxData.bWin95);
m_ptTrackOffset.x = -(cx / 2);
ASSERT(m_pColInfo[0].nCurSize > 0);
m_rectLimit.right -= cx;
}
else if (ht >= vSplitterBar1 && ht <= vSplitterBar15)
{
cy = m_cySplitter - (2*m_cyBorder);// + afxData.bWin95);
m_ptTrackOffset.y = -(cy / 2);
int row;
for (row = 0; row < ht - vSplitterBar1; row++)
y += m_pRowInfo[row].nCurSize + m_cySplitterGap;
m_rectLimit.top = y;
y += m_pRowInfo[row].nCurSize + m_cyBorderShare;// - afxData.bWin95;
m_rectLimit.bottom -= cy;
}
else if (ht >= hSplitterBar1 && ht <= hSplitterBar15)
{
cx = m_cxSplitter - (2*m_cxBorder);// + afxData.bWin95);
m_ptTrackOffset.x = -(cx / 2);
int col;
for (col = 0; col < ht - hSplitterBar1; col++)
x += m_pColInfo[col].nCurSize + m_cxSplitterGap;
m_rectLimit.left = x;
x += m_pColInfo[col].nCurSize + m_cxBorderShare;// - afxData.bWin95;
m_rectLimit.right -= cx;
}
else
{
TRACE1("Error: GetHitRect(%d): Not Found!\n", ht);
ASSERT(FALSE);
}
rectHit.right = (rectHit.left = x) + cx;
rectHit.bottom = (rectHit.top = y) + cy;
}
int CMySplitterWnd::HitTest(CPoint pt) const
{
//ASSERT_VALID(this);
CRect rectClient;
GetClientRect(&rectClient);
rectClient.InflateRect(-m_cxBorder, -m_cyBorder);
CRect rectInside;
GetInsideRect(rectInside);
if (m_bHasVScroll && m_nRows < m_nMaxRows &&
CRect(rectInside.right, rectClient.top, rectClient.right,
rectClient.top + m_cySplitter /*+ afxData.bWin95*/).PtInRect(pt))
{
return vSplitterBox;
}
if (m_bHasHScroll && m_nCols < m_nMaxCols &&
CRect(rectClient.left, rectInside.bottom,
rectClient.left + m_cxSplitter /*+ afxData.bWin95*/,
rectClient.bottom).PtInRect(pt))
{
return hSplitterBox;
}
// for hit detect, include the border of splitters
CRect rect;
rect = rectClient;
int col, row;
for (col = 0; col < m_nCols - 1; col++)
{
rect.left += m_pColInfo[col].nCurSize;
rect.right = rect.left + m_cxSplitterGap;
if (rect.PtInRect(pt))
break;
rect.left = rect.right;
}
rect = rectClient;
for (row = 0; row < m_nRows - 1; row++)
{
rect.top += m_pRowInfo[row].nCurSize;
rect.bottom = rect.top + m_cySplitterGap;
if (rect.PtInRect(pt))
break;
rect.top = rect.bottom;
}
// row and col set for hit splitter (if not hit will be past end)
if (col != m_nCols - 1)