-
Notifications
You must be signed in to change notification settings - Fork 2
/
NetDoc.cpp
194 lines (151 loc) · 4.05 KB
/
NetDoc.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
// This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface
// (the "Fluent UI") and is provided only as referential material to supplement the
// Microsoft Foundation Classes Reference and related electronic documentation
// included with the MFC C++ library software.
// License terms to copy, use or distribute the Fluent UI are available separately.
// To learn more about our Fluent UI licensing program, please visit
// https://go.microsoft.com/fwlink/?LinkId=238214.
//
// Copyright (C) Microsoft Corporation
// All rights reserved.
// NetDoc.cpp : implementation of the CNetDoc class
//
#include "stdafx.h"
// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail
// and search filter handlers and allows sharing of document code with that project.
#ifndef SHARED_HANDLERS
#include "Tulip.h"
#endif
#include "NetDoc.h"
#include "NetworkEditor/NetworkLink.h"
#include "NetworkEditor/NetworkControlFactory.h"
#include <propkey.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CNetDoc
IMPLEMENT_DYNCREATE(CNetDoc, CDocument)
BEGIN_MESSAGE_MAP(CNetDoc, CDocument)
END_MESSAGE_MAP()
// CNetDoc construction/destruction
CNetDoc::CNetDoc()
{
}
CNetDoc::~CNetDoc()
{
}
// Called when a new document is created.
BOOL CNetDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
m_objs.Clear();
return TRUE;
}
// CNetDoc serialization
void CNetDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
ar.WriteString(m_objs.GetString() + _T("\r\n"));
INT_PTR count = 0;
CDiagramEntity* obj;
while ((obj = m_objs.GetAt(count++)))
ar.WriteString(obj->GetString() + _T("\r\n"));
INT_PTR max = m_objs.GetLinks();
for (INT_PTR t = 0; t < max; t++)
{
CNetworkLink* link = m_objs.GetLinkAt(t);
if (link)
ar.WriteString(link->GetString() + _T("\r\n"));
}
m_objs.SetModified(FALSE);
}
else
{
m_objs.Clear();
CString str;
while (ar.ReadString(str))
{
if (!m_objs.FromString(str))
{
CDiagramEntity* obj = CNetworkControlFactory::CreateFromString(str);
if (obj)
m_objs.Add(obj);
else
{
CNetworkLink* link = new CNetworkLink;
if (link->FromString(str))
m_objs.AddLink(link);
else
delete link;
}
}
}
m_objs.SetModified(TRUE);
}
}
#ifdef SHARED_HANDLERS
// Support for thumbnails
void CNetDoc::OnDrawThumbnail(CDC& dc, LPRECT lprcBounds)
{
// Modify this code to draw the document's data
dc.FillSolidRect(lprcBounds, RGB(255, 255, 255));
CString strText = _T("TODO: implement thumbnail drawing here");
LOGFONT lf;
CFont* pDefaultGUIFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
pDefaultGUIFont->GetLogFont(&lf);
lf.lfHeight = 36;
CFont fontDraw;
fontDraw.CreateFontIndirect(&lf);
CFont* pOldFont = dc.SelectObject(&fontDraw);
dc.DrawText(strText, lprcBounds, DT_CENTER | DT_WORDBREAK);
dc.SelectObject(pOldFont);
}
// Support for Search Handlers
void CNetDoc::InitializeSearchContent()
{
CString strSearchContent;
// Set search contents from document's data.
// The content parts should be separated by ";"
// For example: strSearchContent = _T("point;rectangle;circle;ole object;");
SetSearchContent(strSearchContent);
}
void CNetDoc::SetSearchContent(const CString& value)
{
if (value.IsEmpty())
{
RemoveChunk(PKEY_Search_Contents.fmtid, PKEY_Search_Contents.pid);
}
else
{
CMFCFilterChunkValueImpl *pChunk = nullptr;
ATLTRY(pChunk = new CMFCFilterChunkValueImpl);
if (pChunk != nullptr)
{
pChunk->SetTextValue(PKEY_Search_Contents, value, CHUNK_TEXT);
SetChunkValue(pChunk);
}
}
}
#endif // SHARED_HANDLERS
// CNetDoc diagnostics
#ifdef _DEBUG
// Asserts the validity of the current object.
void CNetDoc::AssertValid() const
{
CDocument::AssertValid();
}
// Dumps the current object state.
void CNetDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
// CNetDoc commands
// Called before a check is made to see if the data is modified.
BOOL CNetDoc::SaveModified()
{
SetModifiedFlag(m_objs.IsModified());
return CDocument::SaveModified();
}