-
Notifications
You must be signed in to change notification settings - Fork 1
/
C3270Char.cpp
193 lines (156 loc) · 5.66 KB
/
C3270Char.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
/***********************************************************
WinTN3270
Copyright © 2007 Bob Carroll ([email protected])
This software is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation;
either version 2, or (at your option) any later version.
This software is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public
License along with this software; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301 USA
***********************************************************/
#include "stdafx.h"
#include "C3270Char.h"
#include "CEbcdicTranslator.h"
using namespace WinTN3270;
using namespace System;
using namespace System::Drawing;
/***********************************************************
Creates a NULL character object.
***********************************************************/
C3270Char::C3270Char()
{
this->__Constructor(NULL, false);
}
/***********************************************************
Creates a character object from a byte.
@param chChar the EBCDIC character to use
***********************************************************/
C3270Char::C3270Char(Byte chChar)
{
this->__Constructor(chChar, false);
}
/***********************************************************
Creates a character object from a byte. This is the
start-of-field byte.
@param chChar the EBCDIC character to use
@param fStartField flag to indicate start-of-field
***********************************************************/
C3270Char::C3270Char(Byte chChar, bool fStartField)
{
this->__Constructor(chChar, true);
this->UnserializeAttributes();
}
/***********************************************************
Creates a character object from a byte. This is the real
constructor.
@param chChar the EBCDIC character to use
@param fStartField flag to indicate start-of-field
***********************************************************/
void C3270Char::__Constructor(System::Byte chChar, bool fStartField)
{
m_chChar = (fStartField ? chChar : CEbcdicTranslator::CharToASCII(chChar));
m_chInitChar = m_chChar;
m_fAutoSkip = false;
m_fModified = false;
m_fNumeric = false;
m_fProtected = false;
m_fStartField = fStartField;
m_nDisplay = 0;
}
/***********************************************************
Gets the appropriate color brush.
@return the brush to paint with
***********************************************************/
Brush^ C3270Char::GetPaintBrush()
{
switch (m_nDisplay) {
/* Bright */
case DisplayOptions::Bright:
return Brushes::White;
/* Dark */
case DisplayOptions::Dark:
return Brushes::Black;
/* Normal */
default:
return Brushes::Green;
}
}
/***********************************************************
Gets the appropriate color brush.
@param fBaseColor flag to enable base colors
@return the brush to paint with
***********************************************************/
Brush^ C3270Char::GetPaintBrush(bool fBaseColor)
{
bool fBright = (m_nDisplay == DisplayOptions::Bright);
/* Get the base color */
if (!m_fProtected && !fBright) /* Green */
return Brushes::Green;
else if (!m_fProtected && fBright) /* Red */
return Brushes::Red;
else if (m_fProtected && !fBright) /* Blue */
return Brushes::Blue;
else if (m_fProtected && fBright) /* White */
return Brushes::White;
return this->GetPaintBrush();
}
/***********************************************************
Creates a string representation of the character object.
@return a pretty string
***********************************************************/
String^ C3270Char::ToString()
{
return this->ToString(false);
}
/***********************************************************
Creates a string representation of the character object.
@param fMasked flag to mask the character
@return a pretty string
***********************************************************/
String^ C3270Char::ToString(bool fMasked)
{
/* Null character displays nothing */
if (m_chChar == 0 || m_fStartField)
return " ";
/* Some unprotected fields are dark so we mask the real character */
if (fMasked && m_chChar != m_chInitChar)
return "*";
/* Otherwise output the character array */
array<wchar_t>^ pchString = { m_chChar };
return gcnew String(pchString);
}
/***********************************************************
Reads the field attribute bit field and sets class vars
accordingly.
@param chAttr the attribute byte
***********************************************************/
void C3270Char::UnserializeAttributes()
{
/* Bit 7: Modified Data Tag */
m_fModified = (m_chChar & 0x01);
/* Bit 6: Reserved, always zero */
/* Bits 4-5: Field Display */
if ((m_chChar >> 2 & 0x03) == 0x00)
m_nDisplay = DisplayOptions::NormalNoLPDetect;
else if ((m_chChar >> 2 & 0x03) == 0x01)
m_nDisplay = DisplayOptions::NormalLPDetect;
else if ((m_chChar >> 2 & 0x03) == 0x02)
m_nDisplay = DisplayOptions::Bright;
else if ((m_chChar >> 2 & 0x03) == 0x03)
m_nDisplay = DisplayOptions::Dark;
/* Bit 3: Numeric Only */
m_fNumeric = (m_chChar >> 4 & 0x01);
/* Bit 2: Protected */
m_fProtected = (m_chChar >> 5 & 0x01);
if (m_fNumeric && m_fProtected)
m_fAutoSkip = true;
/* Bit 1: Unknown (Ignored) */
/* Bit 0: Unknown (Ignored) */
}