summaryrefslogtreecommitdiff
path: root/tvision/examples/tcombo/tcombo.txt
blob: e045ed13bcd6bd3a91269844609fe47b5a8a5169 (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
Introduction

I have seen many requests in the Turbo Vision forum for a Combo Box class
similar to the one available in Microsoft Windows.  Here is a family of
classes that provide the functionality of the Windows Combo Box.

Combo Box Classes

There are three classes that make up the Combo Box family:  TComboBox,
TComboWindow, and TComboViewer.  TComboBox provides the icon in the dialog
box that represents the whole TComboBox; by clicking on the icon or pressing
the down arrow while the linked TInputLine is selected, the Combo Box
selection window becomes active.  The selection window is made up of a
TComboWindow, a TComboViewer, and a TScrollBar.  While active, the
TComboWindow is the modal view; clicking outside of the window area causes
the TComboWindow to terminate with a cmCancel command.

The TComboBox is only one character wide, so it should be place directly
after the inputline to which it will be linked.  For example:

   tv = new TInputLine(TRect(2,2,20,3), 25);
   insert(tv);
   insert(new TComboBox(TRect(20,2,21,3), tv, list));

The TComboWindow automatically sizes itself to be as wide as the inputline
and the combo box together.

When used with a regular TInputLine, TComboBox acts just like a THistory
object.  However, when used with the TStaticInputLine (also in this zip
file), TComboBox acts like a Combo Box in Windows, only allowing those items
already in the list to be selected.
Class Descriptions

TComboBox

TComboBox  implements a pick listof items for the user to choose.  When used
with a standard TInputLine, it acts very much like a THistory object.  If
used with a TStaticInputLine, only the items which are currently in the list
can be selected.

Data Members
char *icon;
     Points to the character that is used by the draw() function to display
     the icon on the screen.

TInputLine *link;
     Points to the related TInputLine, or a descendant of TInputLine.  Used
     to update the TInputLine data member when an item is selected from the
     list.

TCollection *list;
     Points to the list of items that are currently available for selection
     by the user.  This list is updated whenever the selected state of link
     is changed.

Member Functions
TComboBox(TRect& bounds, TInputLine *aLink, TCollection *aList);
     Constructs a new TComboBox.  If the extent of bounds is greater than a
     1 by 1 square, the extent is changed to that size.

virtual ushort dataSize();
     Returns the size of the data read or written by getData and setData.
     Currently returns sizeof(void *).

virtual void draw();
     Draws the character pointed to by icon in the specified color.

virtual void getData(void *rec);
     Returns a pointer to list in rec.

TPalette& getPalette() const;
     Returns the defined palette cpComboBox.

virtual void handleEvent(TEvent& event);
     Handles mouse events and a down arrow key event to open a TComboWindow.

virtual void newList(TCollection *aList);
     Sets a new list for TComboBox by first deleting the old list and then
     setting list to aList.

virtual void setData(void *rec);
     Reads a pointer from rec and assigns it to list.



void shutDown();
     Sets link = 0 and list = 0, then calls TView::shutDown().  Deleting the
     actual TCollection is the responsibility of the program; this provides
     for a persistent list between calls to the same dialog box.
TComboViewer

TComboViewer is a descendant of TListViewer; it provides the actual list
viewing mechanism for the TComboBox.

Data Members
TCollection *list;
     Points to the list of items that are currently available for selection
     by the user.  This list is updated whenever the selected state of link
     is changed.

Member Functions
TComboViewer(const TRect& bounds, TCollection *aList, TScrollBar *sb);
     Constructs a TComboViewer by setting list = aList and calling
     TListViewer(bounds, 1, 0, sb).

virtual ushort dataSize();
     Returns the size of the data read and written by getData and setData.

TPalette& getPalette() const;
     Returns the defined palette cpComboViewer.

virtual void getData(void *data);
     Accepts data in the format of a TListBoxRec.

virtual void getText(char *dest, short item, short maxLen);
     Returns the itemth item from list in dest, not copying more than maxLen
     characters.

virtual void handleEvent(TEvent& event);
     Checks for keyboard or mouse events that will end the modal view of
     TComboViewer.  All other events are passed on to
     TListViewer::handleEvent.

virtual void newList(TCollection *aList);
     Accepts a new list to be displayed, and disposes of the old list.

virtual void setData(void *data);
     Returns data in the format of a TListBoxRec.

void shutDown();
     Sets list = 0, then calls TListViewer::shutDown().  Disposing of the
     list is the responsibility of the programmer.
TComboWindow

Data Members
TComboViewer *viewer;
     A pointer to the TComboViewer that is a subview of TComboWindow.

Member Functions
TComboWindow(const TRect& bounds, TCollection *aList);
     Calls TWindow(bounds, 0, 0), the creates a TComboViewer and a TScrollBar
     to fit within its bounds.  The aList parameter is passed on to
     TComboViewer.

TPalette& getPalette() const;
     Returns the defined palette cpComboWindow.

void getSelection(char *dest);
     Returns in dest the item selected from the list.

virtual void handleEvent(TEvent&);
     Checks for mouse events outside of the bounds of TComboWindow; all other
     events are passed on to TWindow::handleEvent.

void setSelection(char *data);
     Sets the selected item in the list to data.
TStaticInputLine

Data Members
TCollection *list;
     Points to the list of items that are currently available for selection
     by the user.  This list is updated whenever the selected state of link
     is changed.

Member Functions
TStaticInputLine(const TRect& bounds, int maxLen, TCollection *aList);
     Created a TStaticInputLine by setting list = aList, and calling
     TInputLine(bounds, maxLen).

virtual void getNextMatch();
     A replacement for the call to matchFirstChar().  Currently getNextMatch
     calls matchFirstChar(), but later versions will have an algorithm to
     provide a circular search queue making TStaticInputLine behave more like
     Windows.

virtual void handleEvent(TEvent& event);
     Handles most keyboard events for TStaticInputLine; keyboard events
     handled include all printable characters, up and down arrow keys.  All
     other events are passed on to TInputLine::handleEvent.

virtual void newList(TCollection *aList);
     Accepts a new list to be displayed, and disposes of the old list.


Boolean matchFirstChar(void *, void *);
     matchFirstChar is not a member or a friend function of TStaticInputLine,
     but is called by TStaticInputLine::handleEvent.  This function is of
     type ccTestFunc and is used to test if the first characters of the two
     items passed are the same.  This function is case insensitive.