This repository has been archived by the owner on Feb 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
AW_CMultiViewSplitter.cpp
executable file
·146 lines (122 loc) · 3.5 KB
/
AW_CMultiViewSplitter.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
// AW_CMultiViewSplitter.cpp: implementation of the AW_CMultiViewSplitter class.
//
// Written by Caroline Englebienne of AniWorld, Inc.
// Copyright (c) 2000 AniWorld, Inc.
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "AW_CMultiViewSplitter.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
AW_CMultiViewSplitter::AW_CMultiViewSplitter()
{
m_nIDCounter = 1;
}
AW_CMultiViewSplitter::~AW_CMultiViewSplitter()
{
}
int AW_CMultiViewSplitter::AddView(int nRow, int nCol, CRuntimeClass * pViewClass,
CCreateContext* pContext)
{
// hide the current view of the pane
int PreviousID = HideCurrentView(nRow, nCol);
// create the new view, if fail, set the previous view current
if (CreateView(nRow, nCol, pViewClass, CSize(10,10), pContext) == 0)
{
if (PreviousID != -1)
SetCurrentView(nRow, nCol, PreviousID);
return -1;
}
// get and store the new view
int NewViewID = m_nIDCounter;
CWnd* pNewWnd = GetPane(nRow, nCol);
CPoint pane(nRow, nCol);
long paneID = MAKELONG(pane.x,pane.y);
m_mapViewPane.insert(map<int, long>::value_type(NewViewID,paneID));
m_mapIDViews.insert(map<int, CWnd*>::value_type(NewViewID, pNewWnd));
// set the new view current
SetCurrentView(nRow, nCol, NewViewID);
RedrawWindow();
m_nIDCounter ++;
return NewViewID;
}
void AW_CMultiViewSplitter::ShowView(int nViewID)
{
if (GetView(nViewID) == NULL)
return;
// find the pane containing the view
CPoint pane;
GetPaneFromViewID(nViewID, &pane);
// switch views
HideCurrentView(pane.x, pane.y);
SetCurrentView(pane.x, pane.y, nViewID);
RecalcLayout();
}
CWnd* AW_CMultiViewSplitter::GetView(int nViewID)
{
map<int, CWnd*>::iterator itView;
itView = m_mapIDViews.find(nViewID);
if(itView==m_mapIDViews.end())
return NULL;
else
return (*itView).second;
}
CWnd* AW_CMultiViewSplitter::GetCurrentView(int nRow, int nCol, int * nCurID)
{
long paneID = MAKELONG(nRow,nCol);
map<long, int>::iterator itCur;
itCur = m_mapCurrentViews.find(paneID);
if (itCur == m_mapCurrentViews.end())
return NULL;
else
{
int PreviousID = (*itCur).second;
*nCurID = PreviousID;
return GetView(PreviousID);
}
}
void AW_CMultiViewSplitter::SetCurrentView(int nRow, int nCol, int nViewID)
{
long paneID = MAKELONG(nRow,nCol);
map<long, int>::iterator itCur;
itCur = m_mapCurrentViews.find(paneID);
if (itCur != m_mapCurrentViews.end())
(*itCur).second = nViewID;
else
m_mapCurrentViews.insert(map<long,int>::value_type(paneID,nViewID));
CWnd * pView = GetView(nViewID);
pView->SetDlgCtrlID(IdFromRowCol(nRow, nCol));
pView->ShowWindow(SW_SHOW);
}
int AW_CMultiViewSplitter::HideCurrentView(int nRow, int nCol)
{
int prevID;
CWnd * pCurView = GetCurrentView(nRow, nCol, &prevID);
if (pCurView == NULL)
return -1;
else
{
pCurView->SetDlgCtrlID(0);
pCurView->ShowWindow(SW_HIDE);
return prevID;
}
}
void AW_CMultiViewSplitter::GetPaneFromViewID(int nViewID, CPoint * pane)
{
map<int, long>::iterator itPane;
itPane = m_mapViewPane.find(nViewID);
if (itPane==m_mapViewPane.end())
{
pane = NULL;
return;
}
long paneID = (*itPane).second;
CPoint p(paneID);
pane->x = p.x;
pane->y = p.y;
}