summaryrefslogtreecommitdiff
path: root/tvision/examples/terminal/terminal.cc
blob: a7efc471b4bc4b9bc306b7b5d45bb4c51411f2d8 (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
/**[txh]********************************************************************

  Description:
  That's a small example on how to use the TTerminal class. I wrote it
because Andris found a bug in the Robert's port (was in the prevLine,
Robert translated it from assembler in the wrong way).

  Copyright (c) 1999 by Salvador E. Tropea

  This file is provided as an example nothing else. As all files needs a
disclaimer y choose to use the GPL license for this file. So use it under
the terms of the GPL license.

***************************************************************************/

#define Uses_TApplication
#define Uses_TEvent
#define Uses_TDialog
#define Uses_TScrollBar
#define Uses_TTerminal
#define Uses_TButton
#define Uses_TDeskTop
#include <tv.h>

#include <tv/configtv.h>
// The SSC code doesn't support as much as needed for it.
#ifndef HAVE_SSC

class TMyApp : public TApplication
{
public:
 TMyApp();
 virtual void handleEvent(TEvent &event);
 void Test();
};

TMyApp::TMyApp() :
  TProgInit( &TMyApp::initStatusLine,
             &TMyApp::initMenuBar,
             &TMyApp::initDeskTop
           )
{
}

const int cmAbout=0x1000;

void TMyApp::handleEvent( TEvent &event )
{
 TApplication::handleEvent(event);

 if (event.what==evCommand)
   {
    switch (event.message.command)
      {
       case cmAbout:
            Test();
            break;
       default:
            break;
      }
   }
}

class TestDialog : public TDialog
{
public:
 TestDialog();
};

TestDialog::TestDialog() :
  TWindowInit(&TestDialog::initFrame),
  TDialog(TRect(0,0,60,18),"Dumb terminal")
{
 options |= ofCentered;

 TScrollBar *hsb=new TScrollBar(TRect(58,1,59,13));
 TScrollBar *vsb=new TScrollBar(TRect(1,13,58,14));
 insert(hsb);
 insert(vsb);
 TTerminal *tt=new TTerminal(TRect(1,1,57,12),hsb,vsb,4096);
 tt->do_sputn("Hello!\nThat's just a test in the buffer.\nThat's all falks.",58);
 //tt->do_sputn("Hello!\r\nThat's just a test in the buffer.\r\nThat's all falks.",60);
 insert(tt);
 insert(new TButton(TRect(25,15,35,17),"O~K~",cmOK,bfNormal));

 selectNext(False);
}

void TMyApp::Test()
{
 TestDialog *d=new TestDialog;
 deskTop->execView(d);
 CLY_destroy(d);
}

int main()
{
 TEvent init;
 init.what=evCommand;
 init.message.command=cmAbout;

 TMyApp myApp;
 myApp.putEvent(init);
 myApp.run();
 return 0;
}

#else

int main()
{
 fprintf (stderr, "Sorry: The SSC code doesn't support as much as needed for it.\n");
}

#endif