summaryrefslogtreecommitdiff
path: root/setedit/setedit/ascii.cc
blob: 296296e1ecfaa077a1108a0b01979e8145d068f7 (plain)
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
/*----------------------------------------------------------*/
/*                                                          */
/*   Turbo Vision 1.0                                       */
/*   Copyright (c) 1991 by Borland International            */
/*                                                          */
/*   Ascii.cpp: Member functions of following classes:      */
/*                TTable                                    */
/*                TReport                                   */
/*                TAsciiChart                               */
/*----------------------------------------------------------*/

/* Modified by Robert Hoehne to be used with RHIDE
   Modified by Salvador E, Tropea to be used with SETEdit */

#define Uses_TRect
#define Uses_TEvent
#define Uses_TKeys
#define Uses_TDrawBuffer
#define Uses_TStreamableClass
#define Uses_TStreamable
#define Uses_TView
#define Uses_TWindow
#define Uses_string
#define Uses_TProgram
#define Uses_snprintf
#include <tv.h>

#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#include <ascii.h>

// RemoveFromEditorsHelper
#define Uses_SETAppVarious
#include <setapp.h>
#include <dskwin.h>

//
// TTable functions
//

TTable::TTable(TRect& r) :
 TView( r )
{
}


void TTable::draw()
{
    TDrawBuffer buf;
    char        color = getColor(6);

    for(int y = 0; y <= size.y-1; y++)
	{
	buf.moveChar(0, ' ', color, size.x);
	for(int x = 0; x <= size.x-1; x++)
	    buf.moveChar(x, 32*y+x, color, 1);
	writeLine(0, y, size.x, 1, buf);
	}
    showCursor();
}

//
// cmCharFocused is a offset value (basically the ascii code of the
// current selected character) thus should be added, not or'ed, to
// cmAsciiTableCmdBase.
//

void TTable::charFocused()
{
    message(owner, evBroadcast, cmAsciiTableCmdBase + cmCharFocused,
      (void *)(long)(cursor.x + 32 * cursor.y));
}


void TTable::handleEvent(TEvent& event)
{
    TView::handleEvent(event);

    if (event.what == evMouseDown)
	{
	do
	    {
	    if(mouseInView(event.mouse.where))
		{
		TPoint spot = makeLocal(event.mouse.where);
		setCursor(spot.x, spot.y);
		charFocused();
		}
	    } while (mouseEvent(event, evMouseMove));
	clearEvent(event);
	}
    else
	{
	if (event.what == evKeyboard)
	    {
	    switch (event.keyDown.keyCode)
		{
		case kbHome:
		    setCursor(0,0);
		    break;
		case kbEnd:
		    setCursor(size.x-1, size.y-1);
		    break;
		case kbUp:
		    if (cursor.y > 0)
			setCursor(cursor.x, cursor.y-1);
		    break;
		case kbDown:
		    if (cursor.y < size.y-1)
			setCursor(cursor.x, cursor.y+1);
		    break;
		case kbLeft:
		    if (cursor.x > 0)
			setCursor(cursor.x-1, cursor.y);
		    break;
		case kbRight:
		    if (cursor.x < size.x-1)
			setCursor(cursor.x+1, cursor.y);
                    break;
		default:
                    setCursor(event.keyDown.charScan.charCode % 32,
                      event.keyDown.charScan.charCode / 32);
                    break;
                }
            charFocused();
            clearEvent(event);
	    }
        }
}


//
// TReport functions
//

TReport::TReport(TRect& r) :
 TView(r)
{
    asciiChar = 0;
}


void TReport::draw()
{
    TDrawBuffer buf;
    char        color = getColor(6);
    char        str[80];
    char        *ch,*de,*he;

    ch=TVIntl::getTextNew(__("  Char: "));
    de=TVIntl::getTextNew(__(" Decimal: "));
    he=TVIntl::getTextNew(__(" Hex: "));

    CLY_snprintf(str, 80, "%s%c%s%3d%s%2X  ",
                 ch, (asciiChar==0)?(char)0x20:(char)asciiChar,
                 de, (int)asciiChar,
                 he, (int)asciiChar);

    DeleteArray(ch);
    DeleteArray(de);
    DeleteArray(he);

    buf.moveStr(0, str, color);
    writeLine(0, 0, 32, 1, buf);
}


void TReport::handleEvent(TEvent& event)
{
    TView::handleEvent(event);
    if (event.what == evBroadcast)
	{
        if (event.message.command == cmAsciiTableCmdBase + cmCharFocused)
            {
	    asciiChar = event.message.infoLong;
	    drawView();
            clearEvent(event);
            }
        }
}


//
// TAsciiChart functions
//

TAsciiChart::TAsciiChart() :
    TWindowInit( &TAsciiChart::initFrame ),
    TWindow(TRect(0, 0, 34, 12), __("ASCII Chart"), wnNoNumber)
{
    TView *control;

    flags &= ~(wfGrow | wfZoom);
    palette = wpGrayWindow;
    growMode = 0;

    TRect r = getExtent();
    r.grow(-1, -1);
    r.a.y = r.b.y - 1;
    control = new TReport( r );
    control->options |= ofFramed;
    control->eventMask |= evBroadcast;
    insert(control);

    r = getExtent();
    r.grow(-1, -1);
    r.b.y = r.b.y - 2;
    control = new TTable( r );
    control->options |= ofFramed;
    control->blockCursor();
    insert(control);

    control->select();
}