|  |  |  |  | 
 19
 Tables
  
19
 TablesTable.h. It discusses the following topics:
 
TableAttrType bit field defines the visible characteristics of the table. 
typedef struct {    UInt16 visible:1;    UInt16 editable:1;    UInt16 editing:1;    UInt16 selected:1;    UInt16 hasScrollBar:1;    UInt16 reserved:11;} TableAttrType;TableAttrType bit field as opaque. Use the functions specified in the descriptions below to retrieve and set each value. Do not attempt to change member values directly. 
TableColumnAttrType structure defines a column in a table. 
typedef struct {    Coord	 	 	 	 	 	 	 	 	 	 	 width;    UInt16	 	 	 	 	 	 	 	 	 	 	 reserved1 : 5;    UInt16	 	 	 	 	 	 	 	 	 	 	 masked : 1;    UInt16	 	 	 	 	 	 	 	 	 	 	 editIndicator : 1;    UInt16	 	 	 	 	 	 	 	 	 	 	 usable : 1;    UInt16	 	 	 	 	 	 	 	 	 	 	 reserved2 : 8;    Coord	 	 	 	 	 	 	 	 	 	 	 spacing;    TableDrawItemFuncPtr	 	 	 	 	 	 	 	 	 	 	 drawCallback;    TableLoadDataFuncPtr	 	 	 	 	 	 	 	 	 	 	 loadDataCallback;    TableSaveDataFuncPtr	 	 	 	 	 	 	 	 	 	 	 saveDataCallback;} TableColumnAttrType;TableColumnAttrType structure as opaque. Use the functions specified in the descriptions below to retrieve and set each value. Do not attempt to change structure member values directly. 
masked field is defined only if 3.5 New Feature Set is present. 
TableItemPtr points to a typedef TableItemType *TableItemPtr;TableItemType structure defines an item, or cell, within the table. 
typedef struct {    TableItemStyleType	 	 	 	 	 	 	 	 	 	 itemType;    FontID	 	 	 	 	 	 	 	 	 	 fontID;    Int16	 	 	 	 	 	 	 	 	 	 intValue;    Char *	 	 	 	 	 	 	 	 	 	 ptr;} TableItemType;TableItemType structure as opaque. Use the functions specified in the descriptions below to retrieve and set each value. Do not attempt to change structure member values directly. 
 
NOTE:  None of the table items create memory that you need to free. The table manager handles all of the allocating and deallocating of memory for table items. The only memory you are responsible for freeing is the memory handle containing the text that you want displayed in editable text fields. (SeeTableLoadDataFuncType.)
| itemType | The type of the item, such as a control, a text label, and so on. TblSetItemStylesets this value. The rest of the fields in this struct are either used or not used depending on theitemType. See Table 19.1. | 
| fontID  | ID of the font used to display the item's text. TblGetItemFontandTblSetItemFontretrieve and set this value. | 
| intValue  | Integer value of the item. TblGetItemIntandTblSetItemIntretrieve and set this value. | 
| ptr  | 
itemType field, describes how each type is drawn, describes which other fields are used for each itemType, and provides special instructions for setting those fields. Note in particular that the fontID field is often not used. Instead, certain items are displayed in a standard font. These are noted in the last column of this table. 
TablePtr type defines a pointer to a typedef TableType * TablePtr;tblPtr = FrmGetObjectPtr(frm, 
	 FrmGetObjectIndex(frm, tblID));tblID is the resource ID assigned when you created the table. 
TableRowAttrType structure defines a row in a table. 
typedef struct {    UInt16	 	 	 	 	 	 id;    Coord	 	 	 	 	 	 height;    UInt32	 	 	 	 	 	 data;    UInt16	 	 	 	 	 	 reserved1 : 7;    UInt16	 	 	 	 	 	 usable : 1;    UInt16	 	 	 	 	 	 reserved2 : 4;    UInt16	 	 	 	 	 	 masked : 1;    UInt16	 	 	 	 	 	 invalid : 1;    UInt16 	 	 	 	 	 	 staticHeight : 1;    UInt16	 	 	 	 	 	 selectable : 1;    UInt16	 	 	 	 	 	 reserved3;} TableRowAttrType;TableRowAttrType structure as opaque. Use the functions specified in the descriptions below to retrieve and set each value. Do not attempt to change structure member values directly. 
masked field is defined only if 3.5 New Feature Set is present. 
TableType structure represents a table. 
typedef struct TableType {    UInt16	 	 	 	 	 	 	 	 	 	 	 id;    RectangleType	 	 	 	 	 	 	 	 	 	 	 bounds;    TableAttrType	 	 	 	 	 	 	 	 	 	 	 attr;    Int16	 	 	 	 	 	 	 	 	 	 	 numColumns;    Int16	 	 	 	 	 	 	 	 	 	 	 numRows;    Int16	 	 	 	 	 	 	 	 	 	 	 currentRow;    Int16	 	 	 	 	 	 	 	 	 	 	 currentColumn;    Int16	 	 	 	 	 	 	 	 	 	 	 topRow;    TableColumnAttrType *	 	 	 	 	 	 	 	 	 	 	 columnAttrs;    TableRowAttrType *	 	 	 	 	 	 	 	 	 	 	 rowAttrs;    TableItemPtr	 	 	 	 	 	 	 	 	 	 	 items;    FieldType	 	 	 	 	 	 	 	 	 	 	 currentField;} TableType;TableType structure as opaque. Use the functions specified in the descriptions below to retrieve and set each value. Do not attempt to change structure member values directly. 
void TblDrawTable (TableType *tableP)
textTableItem, textWithNoteTableItem, or narrowTextTableItem), this function uses the TableLoadDataFunc returns, meaning that you are responsible for freeing the memory that you load into the table. 
 
narrowTextTableItem cells or customTableItem cells, this function uses the Boolean TblEditing (const TableType *tableP)
true if the table is in edit mode, false otherwise.
textTableItem, textWithNoteTableItem, or narrowTextTableItem), or when textWithNoteTableItem or when the table releases the focus (void TblEraseTable (TableType *tableP)
visible and selected attributes to false. It does not invalidate table rows. 
Boolean TblFindRowData (const TableType *tableP, UInt32 data, Int16 *rowP)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row data to find. | 
|   | <-  | Pointer to the row number (return value). | 
true if a match was found, false otherwise.
Boolean TblFindRowID (const TableType *tableP, UInt16 id, Int16 *rowP)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row ID to find. | 
|   | <-  | Pointer to the row number (return value). | 
true if a match was found, false otherwise.
void TblGetBounds (const TableType *tableP, RectangleType *r)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | <-  | A RectangleTypestructure in which the bounds are returned. | 
r parameter contains the bounds.
Coord TblGetColumnSpacing (const TableType *tableP, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
column parameter is invalid. 
Coord TblGetColumnWidth (const TableType *tableP, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
column parameter is invalid. 
FieldPtr TblGetCurrentField (const TableType *tableP)
NULL if the table is not in edit mode.
void TblGetItemBounds (const TableType *tableP, Int16 row, Int16 column, RectangleType *r)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
|   | <-  | Pointer to a structure that holds the bounds of the item. | 
r. This function may raise a fatal exception if the row or column parameter specifies a row or column that does not appear on screen. 
FontID TblGetItemFont (const TableType *tableP, Int16 row, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
row or column parameter specifies a row or column that is not on the screen. 
fontID field for this table item. Only certain types of table items use the font specified by the fontID field when they are displayed. The Int16 TblGetItemInt (const TableType *tableP, Int16 row, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
row or column does not appear on the screen. 
intValue field for this table item. Certain types of table items display the value stored in intValue, and other types display the value pointed to by the ptr field. See the intValue was never set for this table item, this function returns 0. 
 
void * TblGetItemPtr (const TableType *tableP, Int16 row, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
NULL if the item does not have a pointer value. This function may display a fatal message if the row or column parameter is invalid. 
ptr field for this table item. Certain types of table items display the value pointed to by the ptr, and other types display the value stored in the intValue field. See the ptr field anyway, even for items that use the intValue. This function always returns that value. 
return tableP->items[row * tableP->numColumns + 
	 column].ptr;Int16 TblGetLastUsableRow (const TableType *tableP)
tblUnusableRow if there are no usable rows.
Int16 TblGetNumberOfRows (const TableType *tableP)
UInt32 TblGetRowData (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Number of the row (zero-based). | 
row parameter is invalid. 
Coord TblGetRowHeight (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Number of the row (zero-based). | 
row parameter is invalid. 
UInt16 TblGetRowID (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Number of the row (zero-based). | 
row parameter is invalid. 
Boolean TblGetSelection (const TableType *tableP, Int16 *rowP, Int16 *columnP)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | <-  | The row and column indexes (zero-based) of the currently selected item. | 
true if the item is highlighted, false if not.
void TblGrabFocus (TableType *tableP, Int16 row, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Current row to be edited (zero-based). | 
|   | ->  | Current column to be edited (zero-based). | 
row or column parameter is invalid. 
FrmSetFocus releases the focus from the object that previously had it and sets the form's internal structures. After calling this function, you must call static void EditViewRestoreEditState () {    Int16	 	 	 	 	 row;    FormPtr	 	 	 	 	 frm;    TablePtr	 	 	 	 	 table;    FieldPtr	 	 	 	 	 fld;    if (CurrentFieldIndex == noFieldIndex)     	 return;    // Find the row that the current field is in.    table = GetObjectPtr (EditTable);    if ( ! TblFindRowID (table,     	 CurrentFieldIndex, &row) )    	 return;    frm = FrmGetActiveForm ();    FrmSetFocus (frm, FrmGetObjectIndex (frm,     	 EditTable));    TblGrabFocus (table, row, editDataColumn);        // Restore the insertion point position.    fld = TblGetCurrentField (table);    FldSetInsPtPosition (fld, EditFieldPosition);    FldGrabFocus (fld);}Boolean TblHandleEvent (TableType *tableP, EventType *event)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | The event to be handled. | 
true if the event was handled, false if it was not.
false if the table is not an editable table. 
 
fldHeightChangedEvent is only handled for dynamically sized fields. See the descriptions of hasScrollBar attribute in the table. (See void TblHasScrollBar (TableType *tableP, Boolean hasScrollBar)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | trueto set the attribute,falseto unset it. | 
ListViewUpdateScrollers function in the Memo example application (MemoMain.c) for an example of setting scroll bar values for a table. 
void TblInsertRow (TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row to insert (zero-based). | 
false. (See void TblMarkRowInvalid (TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
row parameter is invalid. 
void TblMarkTableInvalid (TableType *tableP)
void TblRedrawTable (TableType *tableP)
textTableItem, textWithNoteTableItem, or narrowTextTableItem), this function uses the TableLoadDataFunc returns, meaning that you are responsible for freeing the memory that you load into the table.
 
narrowTextTableItem cells or customTableItem cells, this function uses the void TblReleaseFocus (TableType *tableP)
noFocus to notify the form that the table has lost focus. The form code calls TblReleaseFocus for you. 
 
void TblRemoveRow (TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row to remove (zero-based). | 
Boolean TblRowInvalid (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
true if the row is invalid, false if it's valid. This function may raise a fatal error message if the row parameter is invalid. 
Boolean TblRowMasked (const TableType * tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
true if the row is masked, false otherwise. 
Boolean TblRowSelectable (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
true if the row is selectable, false if it's not.
Boolean TblRowUsable (const TableType *tableP, Int16 row)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
true if the row is usable, false if it's not. 
 
column parameter is invalid. 
void TblSelectItem (TableType *tableP, Int16 row, Int16 column)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row of the item to select (zero-based). | 
|   | ->  | Column of the item to select (zero-based). | 
column or row parameter point to an item that is not on the screen. 
row contains a masked private database record, then the item remains unselected. 
 
void TblSetBounds (TableType *tableP, const RectangleType *rP)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Pointer to a RectangleTypestructure that specifies the bounds for the table. | 
void TblSetColumnEditIndicator (TableType *tableP, Int16 column, Boolean editIndicator)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero based). | 
|   | ->  | trueto highlight,falseto turn off highlight. | 
editIndicator value of true, and all other table item types have an edit indicator of false. 
 
true and column 3 has an edit indicator of false, only the items in column 1 and 2 are drawn as highlighted when selected. Column 4 items are not drawn as highlighted. 
void TblSetColumnMasked (TableType *tableP, Int16 column, Boolean masked)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | trueto have the column be masked,falseotherwise. | 
column.
void TblSetColumnSpacing (TableType *tableP, Int16 column, Coord spacing)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | Spacing after the column in pixels. | 
column parameter is invalid. 
void TblSetColumnUsable (TableType *tableP, Int16 column, Boolean usable)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | truefor usable orfalsefor not usable. | 
column parameter is invalid. 
void TblSetColumnWidth (TableType *tableP, Int16 column, Coord width)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | Width of the column (in pixels). | 
column parameter is invalid. 
void TblSetCustomDrawProcedure (TableType *tableP, Int16 column, TableDrawItemFuncPtr drawCallback)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number. | 
|   | ->  | Callback function. | 
TableItemStyleType of customTableItem. See the column parameter is invalid. 
void TblSetItemFont (TableType *tableP, Int16 row, Int16 column, FontID fontID)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
|   | ->  | ID of the font to be used. | 
fontID field for this table item. Only certain types of table items use the font specified by the fontID field when they are displayed. The fontID for a table item that does not use it. 
 
row or column parameter specifies a row or column that is not on the screen. 
void TblSetItemInt (TableType *tableP, Int16 row, Int16 column, Int16 value)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
|   | ->  | Any byte value (an integer). | 
row or column parameter is invalid. 
intValue field for this table item. Certain types of table items display the value stored in intValue, and other types display the value pointed to by the ptr field. See the  description for details. If you set the intValue of an item that displays its ptr value, it is not an error. An application can store whatever value it wants in the intValue field; however, be aware that this has nothing to do with the value displayed by such a table cell. 
void TblSetItemPtr (TableType * tableP, Int16 row, Int16 column, void *value)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
|   | ->  | Pointer to data to display in the table item. | 
row or column parameter is invalid. 
ptr field for this table item. Certain types of table items display the value pointed to by ptr, and other types display the value stored in the intValue field. See the ptr of an item that displays its intValue, it is not an error. An application can store whatever value it wants in the ptr field; however, be aware that this has nothing to do with the value displayed by such a table cell. 
void TblSetItemStyle (TableType *tableP, Int16 row, Int16 column, TableItemStyleType type)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item (zero-based). | 
|   | ->  | Column number of the item (zero-based). | 
|   | ->  | The type of item, such as an editable text field or a check box. See TableItemTypefor a list of possible values. | 
row or column parameter is invalid. 
for (row = 0; row < rowsInTable; row++) {    TblSetItemStyle (table, row, completedColumn,     	 checkboxTableItem);    TblSetItemStyle (table, row, priorityColumn,     	 numericTableItem);    TblSetItemStyle (table, row, descColumn,     	 textTableItem);    TblSetItemStyle (table, row, dueDateColumn,     	 customTableItem);    TblSetItemStyle (table, row, categoryColumn, 
	 	 customTableItem);}void TblSetLoadDataProcedure (TableType *tableP, Int16 column, TableLoadDataFuncPtr loadDataCallback)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | Callback procedure. See TableLoadDataFuncType. | 
void TblSetRowData (TableType *tableP, Int16 row, UInt32 data)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
row parameter is invalid. 
void TblSetRowHeight (TableType *tableP, Int16 row, Coord height)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | New height in pixels. | 
row parameter is invalid. 
void TblSetRowID (TableType *tableP, Int16 row, UInt16 id)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | ID to identify a row. | 
row parameter is invalid. 
void TblSetRowMasked (TableType *tableP, Int16 row, Boolean masked)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | trueto have the row be masked,falseotherwise. | 
UInt16 attr;privateRecordViewEnum privateRecordStatus; Boolean masked;privateRecordStatus = (privateRecordViewEnum)    PrefGetPreference(prefShowPrivateRecords);....DmRecordInfo (ToDoDB, recordNum, &attr, NULL,     NULL);masked = ((attr & dmRecAttrSecret) &&     (privateRecordStatus == maskPrivateRecords));TblSetRowMasked(tableP, row, masked);void TblSetRowSelectable (TableType *tableP, Int16 row, Boolean selectable)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | true or false. | 
row parameter is invalid. 
void TblSetRowStaticHeight (TableType *tableP, Int16 row, Boolean staticHeight)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | trueto set the static height,falseto unset it. | 
row parameter is invalid. 
void TblSetRowUsable (TableType *tableP, Int16 row, Boolean usable)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number (zero-based). | 
|   | ->  | true or false. | 
row parameter is invalid. 
void TblSetSaveDataProcedure (TableType *tableP, Int16 column, TableSaveDataFuncPtr saveDataCallback)
|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Column number (zero-based). | 
|   | ->  | Callback function. See TableSaveDataFuncType. | 
column parameter is invalid. 
void TblUnhighlightSelection (TableType *tableP)
void TableDrawItemFuncType (void *tableP, Int16 row, Int16 column, RectangleType *bounds)|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the item to be drawn (zero-based). | 
|   | ->  | Column number of the item to be drawn (zero-based). | 
|   | ->  | The area of the screen in which the item is to be drawn. | 
customTableItem (to draw the entire item) or narrowTextTableItem (to draw whatever is required in the space between the text and the right edge of the table cell). 
 
customTableItem instead. For example, if you want to include a date in your table but you want it to show the year as well as the month and day, you should implement a custom drawing function. 
Err TableLoadDataFuncType (void *tableP, Int16 row, Int16 column, Boolean editable, MemHandle *dataH, Int16 *dataOffset, Int16 *dataSize, FieldPtr fld)|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the table item to load. | 
|   | ->  | Column number of the table item to load. | 
|   | ->  | If true, the table is currently being edited. Iffalse, the table is being drawn but not necessarily being edited. | 
|   | <-  | Unlocked handle of a block containing a null-terminated text string. | 
|   | <-  | Offset from start of block to start of the text string. | 
|   | <-  | Allocated size of text string, not the string length. | 
|   | ->  | Pointer to the text field in this table cell. | 
editing attribute is set to false. 
 
dataH, dataOffset, and dataSize that you would pass to dataH, the offset from the start of the record to the start of the string in dataOffset, and the allocated size of the string in dataSize. 
 
dataOffset bytes in the memory chunk. The string should be between 0 and dataSize - 1 bytes in length. 
 
FldSetText, you are responsible for freeing the memory associated with the dataH parameter. You can do so in the fld pointer passed to your function has already been initialized with default values by the table code. If you want to override a field's attributes (for example, if you want to change the underline mode) you can do so in this function. 
Boolean TableSaveDataFuncType (void *tableP, Int16 row, Int16 column);|   | ->  | Pointer to a table object. (See TableType.) | 
|   | ->  | Row number of the table item to load. | 
|   | ->  | Column number of the table item to load. | 
true if the table should be redrawn, or false if the table does not need to be redrawn. 
true from this function, |   |  |  |  |  |   |