-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTERMOLD.CPP
260 lines (231 loc) · 6.41 KB
/
TTERMOLD.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <owl\owlpch.h>
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\window.h>
#include <owl\dc.h>
#include <owl\scroller.h>
#include <windowsx.h>
#define GCL_STYLE (-26)
#include <ddeml.h>
#include "ddecli.rh"
#include "packmon.h"
#include "ttermold.h"
// Other prototypes
char *strsetsz(char *str,int newsize);
DEFINE_RESPONSE_TABLE2(TTerm, PACKMONWnd, TWindow)
EV_MESSAGE(WM_SETFONT, WMFONTS),
EV_WM_PAINT,
END_RESPONSE_TABLE;
//*************************************************************************
// Constructor Defintion
//*************************************************************************
TTerm::TTerm(TWindow* AParent1,UINT aBufSize,LPSTR ATITLE,bool CanIClose1):
PACKMONWnd(AParent1,ATITLE)
{
// Initializations
TextHeight=0;
// Check if size does not exceed the maximum
if (aBufSize>30000)
aBufSize=30000;
Buffer=new char[aBufSize+2];
// If no Buffer created, try a smaller buffer.
if (!Buffer) {
aBufSize=3000;
Buffer=new char[aBufSize+2];
}
// Initialize variables.
QueFront=QueBack=0;
BufferSize=aBufSize;
Attr.Style |= (WS_VSCROLL | WS_HSCROLL | WS_VISIBLE);
FlagFullBuffer=false;
CanIClose=CanIClose1;
TTerm::SetupWindow();
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void TTerm::SetupWindow()
{
TWindow::SetupWindow();
Scroller = new TScroller(this,8,15,80,60);
SetScrollDim(0);
Scroller->SetRange(260L,0L);
Scroller->ScrollTo(0L,0L);
if (CanIClose) {
long ClassStyle=GetClassLong(GCL_STYLE);
ClassStyle|=CS_NOCLOSE;
SetClassLong(GCL_STYLE,ClassStyle);
}
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void TTerm::CloseWindow(int RetVal)
{
if (Buffer)
delete(Buffer);
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void TTerm::SetScrollDim(UINT TotalHeight)
{
HDC hdc=GetDC(HWindow);
SelectObject(hdc,hfont);
SIZE SizeChar;
LPSTR lpszJustified = "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW";
// Defined in include\wingdi.h:
// GetTextExtentPoint32(hdc, lpszJustified, lstrlen(lpszJustified),&SizeChar);
GetTextExtentPoint(hdc, lpszJustified, lstrlen(lpszJustified),&SizeChar);
TextHeight=SizeChar.cy;
Scroller->SetUnits(SizeChar.cx/lstrlen(lpszJustified),TextHeight);
ReleaseDC(HWindow,hdc);
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
LRESULT TTerm::WMFONTS(WPARAM wp,LPARAM)
{
hfont=(HFONT)wp;
SetScrollDim(0);
Scroller->SetPageSize();
Invalidate(true);
//InvalidateRect(Scroller->HWindow, NULL, TRUE);
return (LRESULT)1;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void
TTerm::EvPaint()
{
TPaintDC paintDC(HWindow);
HDC hdc=GetDC(HWindow);
TRect rect;
GetClientRect(rect);
Paint(hdc,0,rect);
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void TTerm::Paint(TDC& dc, bool erase, TRect& rect)
{
char s[300];
COLORREF Tcol = GetSysColor(COLOR_WINDOWTEXT);
SetBkColor(dc,GetSysColor(COLOR_WINDOW));
SelectObject(dc,hfont);
UINT x;
int y=0;
long z=0L;
//rect.top=0;rect.bottom=0;rect.left=0;rect.right=0;CopyVerScr=0;CopyHorScr=0;
for(x=QueBack ; x!=QueFront ; x++,y++) {
if (x<=BufferSize) {
s[y]=Buffer[x];
if ((s[y]==13) || (y>=252)) {
if (Scroller->YPos>z) {
z++;
y=-1;
continue;
}
s[y]=NULL;
y=-1;
// What does this: strsetsz(s,250);
if (s[3]=='F' && s[4]=='m')
SetTextColor(dc,RGB(0,0,255));
else
SetTextColor(dc,Tcol);
// TabbedTextOut(PaintDC,0,z*TextHeight,s,strlen(s),0,0,0);
TextOut(dc,0,z*TextHeight,s,strlen((char *)s));
z++;
}
if (s[y]==10)
y--;
}//end if queback+x
else {
// x=x-BufferSize;
x=0;
s[y]=Buffer[x];
if (x==QueFront) break;
if ((s[y]==13) ||(y>=252)) {
if (Scroller->YPos>z) {z++;y=-1;continue;}
s[y]=NULL;
y=-1;
// What does this: strsetsz(s,250);
if (s[3]=='F' && s[4]=='m') SetTextColor(dc,RGB(0,0,255));
else SetTextColor(dc,Tcol);
// TabbedTextOut(PaintDC,0,z*TextHeight,s,lstrlen(s),0,0,0);
TextOut(dc,0,z*TextHeight,s,strlen((char *)s));
z++;
}
}
}//end fornext
if (y!=-1) {
s[y]=NULL;
y=-1;
// What does this: strsetsz(s,250);
if (s[0]=='F' && s[1]=='m')
SetTextColor(dc,RGB(0,0,255));
else
SetTextColor(dc,Tcol);
TextOut(dc,0,z*TextHeight,s,strlen((char *)s));
z++;
}
for (x=0;x<2;x++) //ADD 2 BLANK LINES
{
s[0]=NULL;
// What does this: strsetsz(s,250);
SetTextColor(dc,Tcol);
TextOut(dc,0,z*TextHeight,s,strlen((char *)s));
}
z++;
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
void TTerm::InsertTerm(unsigned char *s,int count)
{
UINT i;
//printf("INSERT TERM=%s\n",s);
//count=lstrlen(s);
if( QueFront + count >= BufferSize ) {
i = BufferSize - QueFront;
memmove( &Buffer[QueFront], s, i );
memmove( Buffer, &s[i], count - i );
QueFront = count - i;
QueBack=QueFront+1;
if (QueBack>=BufferSize)
QueBack=0;
FlagFullBuffer=TRUE;
}
else {
memmove( &Buffer[QueFront], s, count );
QueFront += count;
if (FlagFullBuffer) QueBack=QueFront+1;
// if (QueBack>=BufferSize) QueBack=0;
}
long xx=CountLines();
if (xx>Scroller->YRange) Scroller->SetRange(Scroller->XRange,xx);
Scroller->ScrollTo(0L,xx-Scroller->YPage);
// Invalidate(false);
Invalidate(true);
}
//////////////////////////////////////////////////////////////////////
//
//////////////////////////////////////////////////////////////////////
long TTerm::CountLines(void)
{
static UINT x;
long lines=0L;
for(x=QueBack;x!=QueFront;x++) {
if (x<=BufferSize) {if (Buffer[x]==13) lines++; }
else {
x=0;
if (x==QueFront) break;
if (Buffer[x]==13) lines++;
}
}//end for
return(lines);
}