summaryrefslogtreecommitdiff
path: root/tvision/examples/listvi/listbox2.cpp
blob: 80fe691d28bac72d930dbff75f2e7addae18b538 (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
// ***********************************************************************
//
//  LISTBOX1.CPP Test Program
//  TListViewer Example - Scrolling Lists
//  revised November 27,1993
//  C.Porter 70262,1047
// Fixed: Use of constant strings for edition by Salvador E. Tropea.
// ***********************************************************************
#include <stdlib.h>

#define Uses_TApplication
#define Uses_TBackground
#define Uses_TButton
#define Uses_TInputLine
#define Uses_TKeys
#define Uses_TDeskTop
#define Uses_TDialog
#define Uses_TListBox
#define Uses_TMenu
#define Uses_TMenuBar
#define Uses_TMenuItem
#define Uses_TRect
#define Uses_TScrollBar
#define Uses_TStaticText
#define Uses_TStatusDef
#define Uses_TStatusItem
#define Uses_TStatusLine

#include <tv.h>
#include <string.h>
#include "lst_view.h"

const int wCity=18, cCities=13;

char *aCityList[cCities]=
{
 "Boston MA.   ",
 "Washington DC  ",
 "Orlando FL.    ",
 "New York City N.Y",
 "Chicago IL ",
 "Dallas TX.",
 "Birmingham AL.",
 "Memphis TN ",
 "Denver CO",
 "San Francisco CA.",
 "Los Angeles CA.",
 "Fort Worth TX",
 "Seattle WA"
};
char *aNumList[cCities]={"1","2","3","4","5","6","7","8","9","10","11","12","13"};
char **cityList;
char **numList;

//  global data
const int cmAbout   = 100;  // User selected menu item 'About'
const int cmList    = 101;  // User selected menu item 'List'

//*******************************************************
class TApp : public TApplication {
  public:

    TApp();

    // virtual functions to be locally redefined
    static TMenuBar *initMenuBar(TRect r);
    void handleEvent(TEvent &event);
    void idle();

    // declare new functions
    void AboutDialog();
    void ListDialog();
};
//*******************************************************

TApp::TApp() : TProgInit(TApplication::initStatusLine,
					TApp::initMenuBar,
					TApplication::initDeskTop) {

  TRect r = getExtent();
  r.a.x = r.b.x - 13;
  r.a.y = r.b.y - 1;

}
//*******************************************************

TMenuBar *TApp::initMenuBar(TRect r) {

  r.b.y = r.a.y + 1;
  return(new TMenuBar(r, new TMenu(
    *new TMenuItem("~A~bout", cmAbout, kbAltA, hcNoContext, 0,
	 new TMenuItem("~L~ist", cmList, kbAltL, hcNoContext, 0)))));
}
//*******************************************************

void TApp::handleEvent(TEvent &event) {

  TApplication::handleEvent(event);
  if (event.what == evCommand) {
    switch(event.message.command) {
	 case cmAbout:       // display the about box
	   AboutDialog();
	   clearEvent(event);
	   break;
	 case cmList:        // display our list box
	   ListDialog();
	   clearEvent(event);
	   break;
    }
  }
}
//*******************************************************
/* AboutDialog - create modal About dialog box */

void TApp::AboutDialog() {

  TDialog *pd = new TDialog(TRect(0, 0, 35, 10), "About");
  if (pd) {
	pd->options |= ofCentered;
	pd->insert(new TStaticText(TRect(1, 2, 34, 6),
			"\003TListViewBox Example 1\n"
			"\003A Simple TListViewer\n"
			"\003C.Porter CIS 70262,1047\n"));
	pd->insert(new TButton(TRect(13, 7, 22,9), "~O~k", cmOK, bfDefault));
	   deskTop->execView(pd);
  }
  CLY_destroy(pd);
}
//*******************************************************

void TApp::ListDialog() {

  TDialog *pd = new TListViewDialog(TRect(0, 0, 40, 15), "Scroll List",
                cityList,numList,cCities,wCity);

  if(validView(pd)) deskTop->execView(pd);

  CLY_destroy(pd);
}
//*******************************************************

void TApp::idle() {

  TProgram::idle();

}

//************************************************************************
int main(void) {
  int i;
  cityList=new char*[cCities];
  numList=new char*[cCities];
  for (i=0; i<cCities; i++)
     {
      cityList[i]=new char[wCity];
      strcpy(cityList[i],aCityList[i]);
      numList[i]=new char[wCity];
      strcpy(numList[i],aNumList[i]);
     }
  TApp myApp;
  myApp.run();
  return 0;
}