-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextView.cpp
More file actions
executable file
·181 lines (136 loc) · 4.3 KB
/
Copy pathTextView.cpp
File metadata and controls
executable file
·181 lines (136 loc) · 4.3 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
// TextView.cpp : implementation file
//
#include "stdafx.h"
#include "..\HDFPlugin.h"
#include "TextView.h"
#include "HdfObjAttribute.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTextView
IMPLEMENT_DYNCREATE(CTextView, CRichEditView)
CTextView::CTextView()
{
m_pObj = NULL;
}
CTextView::~CTextView()
{
}
BEGIN_MESSAGE_MAP(CTextView, CRichEditView)
//{{AFX_MSG_MAP(CTextView)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTextView drawing
void CTextView::OnInitialUpdate()
{
CRichEditView::OnInitialUpdate();
CRichEditCtrl& txtCtrl = GetRichEditCtrl();
txtCtrl.SetReadOnly();
//CString test;
//test="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\froman\\fprq2\\fcharset0 Times New Roman;}{\\f1\\fswiss\\fprq2\\fcharset0 System;}}{\\colortbl ;\\red255\\green0\\blue0;\\red51\\green153\\blue102;\\red0\\green0\\blue255;}\\viewkind4\\uc1\\pard\\cf1\\i\\f0\\fs24 Inputted\\cf0\\i0 \\cf2\\b rich\\cf0\\b0 \\cf3 text\\cf0 !\\b\\f1\\fs20 \\par }";
//test = "\ntest of attribute view\nline 1\nline2";
//Readin(test);
}
void CTextView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}
void CTextView::SetObj(CHObject* pObj)
{
if (pObj==NULL ||
pObj == m_pObj)
return;
CString info = pObj->GetObjInfo();
CObArray* attrList = pObj->ReadAttributes();
CString tmpStr;
if (attrList && attrList->GetSize() > 0)
{
int n = attrList->GetSize();
tmpStr.Format("%d", n);
info += "\n\nNumber of attributes = ";
info += tmpStr;
info +="\n";
info += TABLE_LINE;
CAttribute* attr;
CString attrValue;
for(int i=0; i<n; i++)
{
attr = (CAttribute*)attrList->GetAt(i);
attrValue = attr->ValueToStr();
if (attrValue.GetLength() <=0)
continue;
info +="\n";
info += attr->GetName();
info += " = ";
info += attrValue;
}
}
else
info += "\n\nNumber of attributes = 0";
Readin(info);
}
void CTextView::Readout(CString sReadText)
{
EDITSTREAM es;
es.dwCookie = (DWORD)&sReadText; // Pass a pointer to the CString to the callback function
es.pfnCallback = MEditStreamOutCallback; // Specify the pointer to the callback function.
CRichEditCtrl& txtCtrl = GetRichEditCtrl();
//txtCtrl.StreamOut(SF_RTF,es); // Perform the streaming
txtCtrl.StreamOut(SF_TEXT,es); // Perform the streaming
}
void CTextView::Readin(CString sWriteText)
{
DeleteContents(); // clean the old content
// This is hard-coded for example purposes. It is likely this would
// be read from file or another source.
EDITSTREAM es;
es.dwCookie = (DWORD)&sWriteText; // Pass a pointer to the CString to the callback function
es.pfnCallback = MEditStreamInCallback; // Specify the pointer to the callback function
CRichEditCtrl& txtCtrl = GetRichEditCtrl();
//txtCtrl.StreamIn(SF_RTF,es); // Perform the streaming
txtCtrl.StreamIn(SF_TEXT,es); // Perform the streaming
}
/////////////////////////////////////////////////////////////////////////////
// CTextView diagnostics
#ifdef _DEBUG
void CTextView::AssertValid() const
{
CRichEditView::AssertValid();
}
void CTextView::Dump(CDumpContext& dc) const
{
CRichEditView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTextView message handlers
DWORD __stdcall MEditStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString *psBuffer = (CString *)dwCookie;
if (cb > psBuffer->GetLength()) cb = psBuffer->GetLength();
for (int i=0;i<cb;i++) {
*(pbBuff+i) = psBuffer->GetAt(i);
}
*pcb = cb;
*psBuffer = psBuffer->Mid(cb);
return 0;
}
DWORD __stdcall MEditStreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CString sThisWrite;
sThisWrite.GetBufferSetLength(cb);
CString *psBuffer = (CString *)dwCookie;
for (int i=0;i<cb;i++) {
sThisWrite.SetAt(i,*(pbBuff+i));
}
*psBuffer += sThisWrite;
*pcb = sThisWrite.GetLength();
sThisWrite.ReleaseBuffer();
return 0;
}