Hi:
I am updating an existing shipping commercial application for Palm OS 5.0
compatibility. I have a table that displays right-aligned numerical text in
column zero and static text in column one. The table is not editable or even
selectable; it just displays information. It does need to scroll in response
to hard keys and needs to be updated in response to popup menu choices.
I modified the code with the new variable names and removed all the
references to the internal structures of the fields (which for example I had
used to right-align column zero), as required by the
DO_NOT_ALLOW_ACCESS_TO_INTERNALS_OF_STRUCTS #define for OS 5.0
compatibility.
Previously I had used FldDrawField to draw the text in both columns, but now
that I can't modify the justification attribute, I'm calculating the offset
and using WinDrawChars to draw the text in the table cell manually.
The problem is that column zero draws fine, but column one does not. The
proper text is present in column one of the table, but is just not visible
(I figured this out by setting the row to be selectable and tapping on the
cells in column one).
I've tried marking the table invalid and redrawing at all the obvious places
along the way... anyone have any idea what I'm doing wrong? Thanks in
advance, I'm not a newbie to Palm programming but definitely still a novice.
Code below.
--
Peter Wu, M.D.
Medical Toolbox Support
[EMAIL PROTECTED]
Medical Toolbox Software
Handheld Solutions for the Medical Workplace
www.medicaltoolbox.com
/***********************************************************************
*
* FUNCTION: StatsViewDrawResult
*
* DESCRIPTION: This routine draws the result in the table
*
* PARAMETERS: table - pointer to a table object
* row - row in the table of the aounnt field
* column - column in the table of the amount field
* bounds - bounds of the field object
*
* RETURNED: nothing
*
* HISTORY: 4/27/02 pkw modified to remove all references to field
* internal structures to ensure Palm OS 5.0
* compatibility. Because Palm withdrew support
for
* modification of field attributes, have to
* draw the result text manually with
WinDrawChars
* after calculating the offset in order to have
* right justified text in a table cell.
*
*
***********************************************************************/
static void StatsViewDrawResult(MemPtr table, UInt16 row, UInt16 column,
RectanglePtr bounds)
{
FontID curFont;
UInt16 result = 0;
CharPtr resultText;
Int16 lstWidth = 0;
Int16 textLen = 0;
Int16 x = 0;
Boolean fits = false;
Int16 charLen = 0;
// get the already calculated result from the result function
result = StatsViewInitResult (row);
// convert integer to a string; not strictly necessary, but had
prewritten code
StrIToA (resultText, result);
// Determine the length of text that will fit within the list bounds.
lstWidth = bounds->extent.x - 2;
textLen = StrLen(resultText);
FntCharsInWidth(resultText, &lstWidth, &textLen, &fits);
charLen = FntCharsWidth (resultText, textLen);
// calculate the offset from the right boundary of the cell
x = (bounds->topLeft.x + bounds->extent.x) - charLen;
// Now draw the text into the table.
WinDrawChars(resultText, textLen, x, bounds->topLeft.y);
curFont = FntSetFont (stdFont);
FntSetFont (curFont);
}
/***********************************************************************
*
* FUNCTION: StatsViewDrawLabel
*
* DESCRIPTION: This routine draws the label in the table
*
* PARAMETERS: table - pointer to a table object
* row - row in the table of the aounnt field
* column - column in the table of the amount field
* bounds - bounds of the field object
*
* RETURNED: nothing
*
* HISTORY: 4/27/02 pkw modified to remove all references to field
* internal structures to ensure Palm OS 5.0
* compatibility.
*
*
***********************************************************************/
static void StatsViewDrawLabel(MemPtr table, UInt16 row, UInt16 column,
RectanglePtr bounds)
{
FontID curFont;
UInt16 result = 0;
UInt16 resultNum = 0;
Int16 lstWidth = 0;
Int16 textLen = 0;
Int16 x = 0;
Boolean fits = false;
char resultLabel [37][1][24] = {
"Intrathoracic w/out CPB",
"Intrathoracic with CPB",
"Major vascular",
"Intracranial nonvasc",
"Intracranial vascular",
"Vaginal delivery",
"Cesarean section",
"Other",
"Ambulatory",
"Trauma",
"General/MAC",
"Epidural",
"Spinal",
"Nerve block",
"Arterial lines",
"Central catheters",
"PA catheters",
"Double lumen ETT",
"Laryngeal mask",
"Fiberoptic",
"TEE",
"Deliberate hypotension",
"EEG",
"Evoked potentials",
"Less than 45 wks PCA",
"45 wks PCA to 1 year",
"1 year to 12 years",
"13 yrs to 65 yrs",
"Older than 65 yrs",
"Acute Pain",
"Cancer Pain",
"Chronic Pain",
"Pain Spinal",
"Pain Epidural",
"Pain Nerve block",
"Pain Other",
"Total Cases"};
resultNum = TopVisibleResult + row;
// Determine the length of text that will fit within the list bounds.
lstWidth = bounds->extent.x - 4;
textLen = StrLen (resultLabel[resultNum][0]);
FntCharsInWidth(resultLabel[resultNum][0], &lstWidth, &textLen, &fits);
curFont = FntSetFont (stdFont);
FntSetFont (curFont);
// Now draw the text into the table.
WinDrawChars (resultLabel[resultNum][0], textLen, bounds->topLeft.x + 2,
bounds->topLeft.y);
}
/***********************************************************************
*
* FUNCTION: StatsViewLoadTable
*
* DESCRIPTION: This routine loads the results from the StatsTotals function
* into the table.
*
* PARAMETERS: fillTable - if true the top visible item will be scroll down
* such that a full table is displayed
*
* RETURNED: nothing
*
*
***********************************************************************/
static void StatsViewLoadTable (Boolean fillTable)
{
UInt16 row;
UInt16 height;
UInt16 numRows;
UInt16 dataHeight;
UInt16 tableHeight;
UInt16 columnWidth;
FormPtr frm;
TablePtr table;
Boolean rowsInserted = false;
RectangleType r;
UInt16 resultNum;
frm = FrmGetActiveForm ();
// Get the height of the table and the width of the label
// column.
table = GetObjectPtr (AnestatsStatsResultsTable);
TblGetBounds (table, &r);
tableHeight = r.extent.y;
columnWidth = TblGetColumnWidth (table, labelColumn);
row = 0;
dataHeight = 0;
resultNum = TopVisibleResult;
// Load results into the table.
for (row = 0; row < statsTableSize; row++)
{
// Compute the height of the item's description.
height = FntLineHeight ();
dataHeight += height;
// Determine if the row needs to be initialized. We will initialize
// the row if: the row is not usable (not displayed).
//if (! TblRowUsable (table, row))
//{
TblMarkRowInvalid (table, row);//}
resultNum++;
}
// Hide the items that don't have any data.
numRows = TblGetNumberOfRows (table);
while (row < numRows)
{
TblSetRowUsable (table, row, false);
row++;
}
TblMarkTableInvalid (table);
TblRedrawTable (table);
return;
/*/ If the table is not full and the first visible record is
// not the first record in the database, displays enough records
// to fill out the table.
while (dataHeight < tableHeight)
{
if (! fillTable)
break;
recordNum = TopVisibleRecord;
if ( ! SeekRecord (&recordNum, 1, dmSeekBackward))
break;
// Compute the height of the expense item's description.
height = FntLineHeight ();
// If adding the item to the table will overflow the height of
// the table, don't add the item.
if (dataHeight + height > tableHeight)
break;
// Insert a row before the first row.
TblInsertRow (table, 0);
DmRecordInfo (AnestatsDB, recordNum, NULL, &uniqueID, NULL);
MainViewInitTableRow (table, 0, recordNum, height, uniqueID);
TopVisibleRecord = recordNum;
rowsInserted = true;
dataHeight += height;
}*/
}
/***********************************************************************
*
* FUNCTION: StatsViewInit
*
* DESCRIPTION: pkw. Initializes table for the stats form
*
* PARAMETERS: event - the most recent event.
*
* RETURNED: nothing
*
***********************************************************************/
static void StatsViewInit (FormPtr frm, TablePtr table)
{
UInt16 row;
UInt16 width;
UInt16 rowsInTable;
RectangleType r;
rowsInTable = TblGetNumberOfRows (table);
for (row = 0; row < rowsInTable; row++)
{
TblSetItemStyle (table, row, resultColumn, customTableItem);
TblSetItemStyle (table, row, labelColumn, customTableItem);
TblSetRowSelectable (table, row, true);
TblSetRowUsable (table, row, true);
}
TblSetColumnUsable (table, resultColumn, true);
TblSetColumnUsable (table, labelColumn, true);
TblSetColumnSpacing (table, resultColumn, anestatsListColSpacing);
TblSetColumnSpacing (table, labelColumn, 0);
// Set the width of the label column.
TblGetBounds (table, &r);
width = r.extent.x;
width -= TblGetColumnWidth (table, resultColumn) +
TblGetColumnSpacing (table, resultColumn);
TblSetColumnWidth (table, labelColumn, width);
// Set the custom callback routines that draw the fields.
TblSetCustomDrawProcedure (table, resultColumn, StatsViewDrawResult);
TblSetCustomDrawProcedure (table, labelColumn, StatsViewDrawLabel);
StatsViewLoadTable (true);
}
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/