?? 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 + -