#AM TCL Lists
Burt,
If you're using the TCL and AppMaker-generated lists, then they are subclasses
of the TCL's CTable class, which doesn't use the Mac's list manager at all. In
this respect, lists aren't limited in size, as they are with list manager
lists.
You _do_ have to maintain an external structure that contains the data for your
list entries. I used the CArrayPane (CAMArrayPane) class in my book to display
the contents of my spreadsheet data. The advantage of the CArrayPane class is
that in addition to the 2-D table, it has an _associated_ array that's fairly
tightly coupled to the table. The advantage to the CArrayPane class is that any
changes to the array cause BroadcastChange messages to be issued, which your
CArrayPane instance will receive directly in its ProviderChanged method.
You can add rows or columns to the lists by using the methods in CTable for
this purpose (AddRow, AddCol, etc.). Check out my code which does this in
Chapter 8 (page 204) of the Easy Object Programming book (THINK C edition).
The best way for a method in another class to access the list is as follows:
1. First, it's usually best if the data associated with your list is kept in an
array
which is owned by the CMyData subclass. AppMaker generates code to make the
handle
to the CMyData instance available to most other classes.
2. Create an "access method" in the CMyData class that provides access to the
"array",
and not the list itself. By changing the contents of the array (if you're
using the
CArrayPane/array combination, or via an explicitly defined dependency
relationship),
the list will receive messages indicating the nature of the changes (add,
delete,
modify) via its ProviderChanged method.
In the case of the spreadsheet in my book, I really should have placed the
array under the complete control of the CEnsembleData class. Although it owns
the array, I didn't provide access methods for it, but rather transmitted its
handle to the classes that needed to access its contents. In retrospect, I
think I'd create access methods in the CEnsembleData class and require the
other classes to call these to access the data.
Nevertheless, to access the list, you access the data structure in which the
data _for_ the list is stored. The TCL's lists have no memory.
The list gets displayed by your CArrayPane's (or CTable's) GetCellText method,
which is called automatically by the TCL for each item in the list, when it
determines that the list needs to be redisplayed (either initially, or later).
Changes to the array in a CArrayPane instance can force an update of the list.
The GetCellText method provides the means to pass back a simple string for a
given list entry. If you require more elaborate formatting (as was the case in
my styled text version of the spreadsheet (shown in Chapters 9-11 of the book),
then you can also override the DrawCell method (which then must call your
GetCellText method to retrieve the data to use for drawing). The DrawCell
method can draw _anything_ you like, including styled text,
graphics,…whatever.
I hope this helps,
-rich-