-
Notifications
You must be signed in to change notification settings - Fork 2
/
DialogEditorDoc.cpp
193 lines (154 loc) · 4.54 KB
/
DialogEditorDoc.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
// DialogEditorDoc.cpp : implementation of the CDialogEditorDoc class
//
#include "stdafx.h"
#include "Tulip.h"
#include "DialogEditorDoc.h"
// --- DiagramEditor ---
#include "DialogEditor/DiagramControlFactory.h"
#include "TextFile/TextFile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogEditorDoc
IMPLEMENT_DYNCREATE(CDialogEditorDoc, CDocument)
BEGIN_MESSAGE_MAP(CDialogEditorDoc, CDocument)
//{{AFX_MSG_MAP(CDialogEditorDoc)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogEditorDoc construction/destruction
CDialogEditorDoc::CDialogEditorDoc()
{
}
CDialogEditorDoc::~CDialogEditorDoc()
{
}
BOOL CDialogEditorDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// --- DiagramEditor ---
// Removing the current data
m_objs.Clear();
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CDialogEditorDoc serialization
void CDialogEditorDoc::Serialize(CArchive& ar)
{
// --- DiagramEditor ---
// Saving and loading to/from a text file
if (ar.IsStoring())
{
ar.WriteString(m_objs.GetString() + _T("\r\n"));
int count = 0;
CDiagramEntity* obj;
while ((obj = m_objs.GetAt(count++)))
ar.WriteString(obj->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 = CDiagramControlFactory::CreateFromString(str);
if (obj)
m_objs.Add(obj);
}
}
m_objs.SetModified(TRUE);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDialogEditorDoc diagnostics
#ifdef _DEBUG
void CDialogEditorDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CDialogEditorDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDialogEditorDoc commands
// --- DiagramEditor ---
CDiagramEntityContainer* CDialogEditorDoc::GetData()
{
// Data accessor
return &m_objs;
}
BOOL CDialogEditorDoc::SaveModified()
{
// We override this to get the dirty-
// handling right
SetModifiedFlag(m_objs.IsModified());
return CDocument::SaveModified();
}
void CDialogEditorDoc::ExportHTML(CString filename)
{
// Exporting to HTML
CStringArray stra;
// Header. I don't want this in the CDiagramEntityContainer class
// where it would normally belong, as it should not be necessary
// to derive a class from CDiagramEntityContainer.
stra.Add(_T("<html>"));
stra.Add(_T("<head>"));
stra.Add(_T("<style>"));
stra.Add(_T("\t.controls { font-family:MS Sans Serif;font-size:12; }"));
stra.Add(_T("\tbody { background-color:#c0c0c0; }"));
stra.Add(_T("</style>"));
stra.Add(_T("<script>"));
stra.Add(_T("function buttonHandler( obj )"));
stra.Add(_T("{"));
stra.Add(_T("\talert( obj.name )"));
stra.Add(_T("}"));
stra.Add(_T("function checkboxHandler( obj )"));
stra.Add(_T("{"));
stra.Add(_T("\talert( obj.name )"));
stra.Add(_T("}"));
stra.Add(_T("function radiobuttonHandler( obj )"));
stra.Add(_T("{"));
stra.Add(_T("\talert( obj.name )"));
stra.Add(_T("}"));
stra.Add(_T("function listboxHandler( obj )"));
stra.Add(_T("{"));
stra.Add(_T("\talert( obj.name )"));
stra.Add(_T("}"));
stra.Add(_T("function comboboxHandler( obj )"));
stra.Add(_T("{"));
stra.Add(_T("\talert( obj.name )"));
stra.Add(_T("}"));
stra.Add(_T("</script>"));
stra.Add(_T("</head>"));
stra.Add(_T("<body topmargin=0 leftmargin=0>"));
CRect rect(0, 0, m_objs.GetVirtualSize().cx + 1, m_objs.GetVirtualSize().cy + 1);
CString input1(_T("<div style='position:absolute;left:%i;top:%i;width:%i;height:%i;border:1 solid black;'>"));
CString input2(_T("<div style='position:absolute;left:0;top:0;width:%i;height:%i;border-top:1 solid white;border-left:1 solid white;border-right:1 solid gray;border-bottom:1 solid gray;'>"));
CString str;
str.Format(input1, rect.left, rect.top, rect.Width(), rect.Height());
stra.Add(str);
rect.InflateRect(-1, -1);
str.Format(input2, rect.Width(), rect.Height());
stra.Add(str);
// The export itself
m_objs.Export(stra);
// The footer
stra.Add(_T("</div>"));
stra.Add(_T("</div>"));
stra.Add(_T("</body>"));
stra.Add(_T("</html>"));
// Writing it to a file
CTextFile tf(_T("html"), _T("\n"));
if (!tf.WriteTextFile(filename, stra))
if (filename.GetLength())
AfxMessageBox(tf.GetErrorMessage());
}