📄 classschedulecontainer.cpp
字号:
/*
* ============================================================================
* Name : CClassScheduleContainer from ClassScheduleContainer.h
* Part of : ClassSchedule
* Created : 2005-8-30 by
* Implementation notes:
* Initial content was generated by Series 60 AppWizard.
* Version :
* Copyright:
* ============================================================================
*/
// INCLUDE FILES
#include "ClassScheduleContainer.h"
#include "ClassScheduleAppUi.h"
#include "ClassScheduleDB.h"
#include <aknlists.h>
#include <aknPopup.h>
#include <ClassSchedule.rsg>
#include <aknnavi.h>
#include <akntabgrp.h>
#include <barsread.h>
#include <aknnavide.h>
#include <akntitle.h>
_LIT(KTab, "\t");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CClassScheduleContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CClassScheduleContainer::ConstructL(const TRect& aRect, CClassScheduleAppUi *aUi)
{
iUi = aUi;
iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
//CPeriodic产生规则的定时器时间和处理他们用一个回调函数分配和构造一个CPeriodic对象
CreateWindowL();
SetRect(aRect);
iListBox = new( ELeave ) CAknSingleHeadingStyleListBox();
//分配和构造一个CAknSingleHeadingStyleListBox类型的列表框对象
iListBox->ConstructL( this, EAknListBoxSelectionList );
iListBox->CreateScrollBarFrameL( ETrue );
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto);
iListBox->SetListBoxObserver( this );
CreateListBoxL();
ActivateL();
}
//-----------------------------------------------
// 析构函数
//-----------------------------------------------
CClassScheduleContainer::~CClassScheduleContainer()
{
delete iListBox;
delete iTimer;
}
// ---------------------------------------------------------
// CClassScheduleContainer::CountComponentControls() const
// ---------------------------------------------------------
TInt CClassScheduleContainer::CountComponentControls() const
{
return 1; // Returns number of controls inside this container.
}
// ---------------------------------------------------------
// CClassScheduleContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
CCoeControl* CClassScheduleContainer::ComponentControl(TInt /*aIndex*/) const
{
return iListBox;
}
// ---------------------------------------------------------
// CClassScheduleContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
void CClassScheduleContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
// TODO: Add your drawing code here
// example code...
gc.SetPenStyle(CGraphicsContext::ENullPen);
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------
// CClassScheduleContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
void CClassScheduleContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
//------------------------------------------------------------
//创建列表
//------------------------------------------------------------
void CClassScheduleContainer::CreateListBoxL()
{
iUi->iIsSearchStatus = EFalse;
CDesCArray* itemArray = STATIC_CAST( CDesCArray*,iListBox->Model()->ItemTextArray());
itemArray->Reset(); //从新设置内存空间为空
TName itemText;
TBuf<32> noneText;
CEikonEnv::Static()->ReadResource(noneText, R_STR_NONE);
CArrayFixFlat<TClassScheduleDBStruct>* arrayDay = (CArrayFixFlat<TClassScheduleDBStruct>*)iUi->iDB->iArray->At(iUi->iDB->iWeekId);
for(TInt res=R_STR_LESSON_01; res<=R_STR_LESSON_10; res ++) //循环,从第一节课到第十节课
{
TClassScheduleDBStruct &db = arrayDay->At(res-R_STR_LESSON_01); //取数组中的第一个值
CEikonEnv::Static()->ReadResource(itemText, res); //将从数组中得到的第一个值赋给itemText
itemText.Append(KTab); //将\t加到从数组获取的信息之后
if(db.iName.Length()==0) //如果数据库中没有课程名
{
itemText.Append(noneText); //在\t后加上None
}
else //如果数据库中保存有输入的课程名
{
itemText.Append(db.iName); //在\t后加上课程名
}
itemArray->AppendL(itemText); //将信息放到数组末尾
}
iListBox->HandleItemAdditionL(); //处理添加一个项到模型中
iListBox->SetRect(Rect()); //设置矩形区
iListBox->ActivateL();
iListBox->DrawNow();
}
TInt CClassScheduleContainer::GetCurrentItemIndex()
{
return iListBox->CurrentItemIndex(); //返回当前项的索引
}
void CClassScheduleContainer::SetCurrentItemIndex(TInt aIndex)
{
iListBox->SetCurrentItemIndexAndDraw(aIndex); //设置当前项和重画列表
}
//------------------------------------------------------------
//创建查询列表
//------------------------------------------------------------
void CClassScheduleContainer::CreateSearchListBoxL()
{
iUi->iIsSearchStatus = ETrue;
CDesCArray* itemArray = STATIC_CAST( CDesCArray*,iListBox->Model()->ItemTextArray()); //将通过iListBox 得到的数组数据类型转换成CDesCArray类型
itemArray->Reset(); //从新设置内存空间为空
TInt weekid = EWeek1;
TInt lessonid = ECourse01;
TName itemText, tips;
for(weekid=EWeek1; weekid<=EWeek7; weekid++) //循环从周一到周末
{
for(lessonid=ECourse01;lessonid<=ECourse10;lessonid++) //循环从第一节课到第十节课
{
if(iUi->iIsSearchFlag[weekid][lessonid]) //如果是搜寻结果的列表
{
CEikonEnv::Static()->ReadResource(tips, weekid+R_STR_WEEK_1); //获取星期的信息
itemText.Copy(tips); //将获取的信息拷贝到itemText
itemText.Append(KTab); //在信息后加上\t
CEikonEnv::Static()->ReadResource(tips, lessonid+R_STR_LESSON_01); //获取是哪节课的信息
itemText.Append(tips); //将获取的信息添加到itemText后
itemArray->AppendL(itemText); //将所有信息添加到数组末尾
}
}
}
iListBox->HandleItemAdditionL(); //处理添加一个项到模型中
iListBox->SetRect(Rect()); //设置矩形区
iListBox->ActivateL();
iListBox->DrawNow();
CEikStatusPane* sp = iEikonEnv->AppUiFactory()->StatusPane();
CAknTitlePane* iTitlePane = (CAknTitlePane *)sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle));
CEikonEnv::Static()->ReadResource(tips, R_STR_SEARCH_FOR_RESULT);
iTitlePane->SetTextL(tips);
}
//--------------------------------------------------------
//处理listbox 事件
//--------------------------------------------------------
void CClassScheduleContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/,TListBoxEvent aEventType )
{
if(aEventType==EEventEnterKeyPressed) //如果在listbox上按下键
{
OpenCurrentListItem(); //打开当前列表中的信息
}
}
//-----------------------------------------------------
//处理按键事件
//-----------------------------------------------------
TKeyResponse CClassScheduleContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
{
if(aType==EEventKey) //如果按键
{
if(aKeyEvent.iCode==EKeyLeftArrow) //如果按下左键
{
if(!iUi->iIsSearchStatus) //如果是列表框类型是显示十节课的类型
iUi->CmdPrev(); //显示上一天的信息
else
return EKeyWasConsumed;
}
else if(aKeyEvent.iCode==EKeyRightArrow) //如果按下右键
{
if(!iUi->iIsSearchStatus) //如果是列表框类型是显示十节课的类型
iUi->CmdNext(); //显示下一天的信息
else
return EKeyWasConsumed;
}
}
return iListBox->OfferKeyEventL(aKeyEvent, aType); //光标在列表上上下移动
}
void CClassScheduleContainer::OpenCurrentListItem()
{
iTimer->Start( 0, 0, TCallBack(CClassScheduleContainer::TimerPeriod, this));
//异步调用TimerPeriod ,时间间隔为0
}
TInt CClassScheduleContainer::TimerPeriod(TAny * aPtr)
{
((CClassScheduleContainer*)aPtr)->UpdataTimer();
return TRUE;
}
void CClassScheduleContainer::UpdataTimer()
{
iTimer->Cancel();
if(iUi->iIsSearchStatus) //如果list为查询状态
{
CmdSearchDetail(); //显示要查询的 详细信息
}
else
{
CmdDetail(); //否则显示详细信息
}
}
void CClassScheduleContainer::CmdDetail()
{
iUi->CmdDetail(); //显示详细信息
}
void CClassScheduleContainer::CmdSearchDetail()
{
iUi->iCurSearchItemIndex = iListBox->CurrentItemIndex(); //从视图中获取当前项的索引
iUi->CmdSearchDetail(); //显示查询的详细信息
}
void CClassScheduleContainer::CmdModify()
{
iUi->CmdModify(); //修改
}
void CClassScheduleContainer::CmdDelete()
{
iUi->CmdDelete(); //删除
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -