WAP之家:为您提供最全最新的WAP技术,CP.SP.3G等行业资讯。 WAP之家交流论坛全新开放 点击进入>>
WAP资讯 | 3G动态 | SP动态 | 运营商动态 | 内容商动态 | 制造商动态 | 论坛讨论>> 每次自动访问
WAP技术 | WAP源码 | 手机编程 | 手机源码 | 无线技术 | J2ME技术 | 手机软件 添加到收藏夹
IVR技术 | SP资料 | SMS MMS技术 | 商业方案 | IVR下载 | 书籍教程 | 工具软件 语言:繁體中文

WAP之家技术文章手机编程PlamPALM开发教程-第九章 分类和查找

PALM开发教程-第九章 分类和查找
作者:palmheart  来源:palmheart.net  发布时间:2005-12-21 3:36:55
ger,
ContactListCategoryListList,
true, &listCat, catName, 1, 0 );

// CH.9 Cursor starts at zero
cursor = 0;

// CH.9 Initialize the indexes
initIndexes();

// CH.9 Draw the table
drawTable();
}
// CH.9 Don't let the OS generate other events from this
return( true );

drawTable()的变化包括修改了一行代码和截去了一整块代码。在initIndexes()和scrollIndex()中可以更方便地管理的重复按钮和滚动条,并且更容易知道下一信息是什么。同样的,我们也可以使用这两个函数处理表和记录的何时到达结尾的问题。
和第八章不同,记录到达最后一条后就使所有行变为不可用,检查talbeIndex数组,看看是否有其它记录与这一行相联系。

// CH.8 Initialize the table styles
for( count = 0; count < TABLE_NUM_ROWS; count++ )
{
// CH.9 If there is data
if( tableIndex[count] != 0xffff )
{
// CH.8 Show the row
TblSetRowUsable( table, count, true );

截去处理向上向下箭头按钮和滚动条的代码,而把它放在程序的底部。这些完成后,在调用TblDrawTable()后,drawTable()函数就会立即结束。

// CH.8 Draw the table
TblDrawTable( table );

// CH.8 We're done
return;
}

在drawCell()中,我们只修改一行代码,这一行在函数的顶部,决定到底使用哪一条记录。

// CH.9 Calculate our record
record = tableIndex[row];

initIndexes()函数

函数initIndexes()创建了在表中所要显示的记录。它创建了数组tableIndex,代表在当前分类中的记录。我们在函数的顶部定义了一些变量并获得当前窗体的指针:

static void initIndexes( void )
{
FormPtr form;
Int count;
UInt index = cursor;
ControlPtr downArrow;
ControlPtr upArrow;
UInt numRecsInCategory;

// CH.9 Get the current form
form = FrmGetActiveForm();

根据行建立循环,在当前分类中查找下一条记录并把它放入行中。如果我们到达了最后一条记录,就把数字0xffff(65,535)赋给数组表示没有所查记录。最后,把游标指向一个已知的有效记录,代替原来或许是在分类中根本就不存在的记录。因为如果分类中没有所查记录,就把游标设为了0xffff。由于表中所有的行已被关掉,这样做就可以了。

// CH.9 For each table row
for( count = 0; count < TABLE_NUM_ROWS; count++ )
{
// CH.9 Find the next matching record
if( DmSeekRecordInCategory( contactsDB, &index, 0,
dmSeekForward, listCat ) )
{
// CH.9 No more records. Fill the rest of the array with
// 0xffff
for( ; count < TABLE_NUM_ROWS; count++ )
tableIndex[count] = 0xffff;
break;
}

// CH.9 Put the index number in the array
tableIndex[count] = index;
index++;
}

// CH.9 Set the cursor to a known category record
cursor = tableIndex[0];


下面是箭头按扭和滚动条处理的代码。它与原来drawTable()函数相比,没有太大的改变。这次它使用DmNumRecordsInCategory()和DmPositionInCategory()来实现对去按钮和滚动条的操作。

// CH.8 Get pointers to the arrow buttons
upArrow = getObject( form, ContactListRecordUpRepeating );
downArrow = getObject( form, ContactListRecordDownRepeating );

// CH.8 Update the arrow buttons and scrollbars
numRecsInCategory = DmNumRecordsInCategory( contactsDB, listCat );
if( numRecsInCategory > TABLE_NUM_ROWS )
{
UInt position = DmPositionInCategory( contactsDB, cursor,
listCat );

// CH.8 Show the up arrow
if( position > 0 )
{
CtlSetLabel( upArrow, BLACK_UP_ARROW );
CtlSetEnabled( upArrow, true );
}
else
{
CtlSetLabel( upArrow, GRAY_UP_ARROW );
CtlSetEnabled( upArrow, false );
}
CtlShowControl( upArrow );

// CH.8 Show the down arrow
if( position >= numRecsInCategory - TABLE_NUM_ROWS )
{
CtlSetLabel( downArrow, GRAY_DOWN_ARROW );
CtlSetEnabled( downArrow, false );
}
else
{
CtlSetLabel( downArrow, BLACK_DOWN_ARROW );
CtlSetEnabled( downArrow, true );
}
CtlShowControl( downArrow );

// CH.9 Show the scrollbar
SclSetScrollBar( getObject( form,
ContactListScrollbarScrollBar ), position, 0,
numRecsInCategory - TABLE_NUM_ROWS, TABLE_NUM_ROWS );
}
else
{
// CH.8 Hide the arrows
CtlHideControl( upArrow );
CtlHideControl( downArrow );

// CH.8 Hide the scrollbar
SclSetScrollBar( getObject( form,
ContactListScrollbarScrollBar ), 0, 0, 0, 0 );
}

// CH.9 We're done
return;
}

scrollIndexes()函数
函数scrollIndexes()修改了tableIndex()数组,要知道我们或许只浏览一小部分内容,因此表中的大部分值仍是好用的。我们先定义一些变量并获得当前窗体指针。我们使用窗体指针来获得向上向下重复按钮的指针。

static void scrollIndexes( Int amount )
{
FormPtr form;
UInt count;
UInt index;
ControlPtr downArrow;
ControlPtr upArrow;
UInt numRecsInCategory;

// CH.9 Get the current form
form = FrmGetActiveForm();

// CH.9 Get pointers to the arrow buttons
upArrow = getObject( form, ContactListRecordUpRepeating );
downArrow = getObject( form, ContactListRecordDownRepeating );

余下的函数分成两部分,一个是向上浏览,一个是向下浏览。首先是向下浏览,我们一直循环直到达到我们的要求。

// CH.9 If we're scrolling down
if( amount > 0 )
{
// CH.9 While there is still an amount to scroll
while( amount-- )
{

在循环中,每次移动一条记录。如果我们一条记录也没有找到,使向下箭头呈灰晕。我们将列表中的索引加一,并且在程序的底部,得到最新的索引。

// CH.9 Get a new index after the last one
index = tableIndex[TABLE_NUM_ROWS - 1];
if( DmSeekRecordInCategory( contactsDB, &index, 1,
dmSeekForward, listCat ) )
{
// CH.9 No mor

上一页  [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]  下一页

[] [返回上一页] [打 印]
文章评论

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码