📄 calendarapiexamplesearchcontainer.cpp
字号:
/*
* ============================================================================
* Name : CCalendarAPIexampleSearchContainer from CalendarAPIexampleSearchContainer.h
* Part of : CalendarAPIexample
* Created : 02/22/2005 by Forum Nokia
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include <aknlists.h> //CAknSingleStyleListBox
#include <barsread.h> //TResourceReader
#include <CalendarAPIexample.rsg>
#include <MYAGENDA.mbg>
#include "CalendarAPIexampleSearchContainer.h"
#include "CalendarAPIexample.pan"
// ================= MEMBER FUNCTIONS =======================
// constructor
CCalendarAPIexampleSearchContainer::CCalendarAPIexampleSearchContainer(CCalendarAPIexampleSearchView& aView)
: iSearchView(aView)
{
}
// destructor
CCalendarAPIexampleSearchContainer::~CCalendarAPIexampleSearchContainer()
{
delete iLabel;
iLabel = NULL;
delete iSearchListBox;
iSearchListBox = NULL;
delete iProgressDialog;
}
// Two-phased constructor.
CCalendarAPIexampleSearchContainer* CCalendarAPIexampleSearchContainer::NewL(const TRect& aRect,
CCalendarAPIexampleSearchView& aView)
{
CCalendarAPIexampleSearchContainer* self = new (ELeave) CCalendarAPIexampleSearchContainer(aView);
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop(self);
return self;
}
// Symbian OS default constructor can leave.
void CCalendarAPIexampleSearchContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
HBufC* text = iCoeEnv->AllocReadResourceLC(R_CALENDARAPIEXAMPLE_SEARCH_STRING);
iLabel->SetTextL(*text);
CleanupStack::PopAndDestroy(text);
/*Draw Bitmap YC*/
//_LIT(KDrawBitmapPath, "Z:\\system\\data\\MYAGENDA.mbm");
//iBitmap = new (ELeave) CFbsBitmap();
//User::LeaveIfError(iBitmap->Load(KDrawBitmapPath, EMbmMyagendaMyagenda));
/*End draw Bitmap YC*/
iSearchListBox = new (ELeave) CAknSingleStyleListBox;
iSearchListBox->SetContainerWindowL(*this);
TResourceReader reader;
CEikonEnv::Static()->CreateResourceReaderLC(reader, R_CALENDARAPIEXAMPLE_SEARCH_LIST);
iSearchListBox->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); //reader
iSearchListBox->SetListBoxObserver(this);
// set scrolling functionality
iSearchListBox->CreateScrollBarFrameL(ETrue);
iSearchListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
CEikScrollBarFrame::EAuto);
SetRect(aRect);
ActivateL();
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::SizeChanged()
// Responds to size changes to set the size and
// position of the contents of this control.
// ----------------------------------------------------
//
void CCalendarAPIexampleSearchContainer::SizeChanged()
{
iLabel->SetExtent( TPoint(5,5), iLabel->MinimumSize() );
iSearchListBox->SetExtent( TPoint(0,iLabel->MinimumSize().iHeight+5), iSearchListBox->MinimumSize() );
//iSearchListBox->
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::CountComponentControls()
// Gets the number of controls contained in a compound
// control.
// ----------------------------------------------------
//
TInt CCalendarAPIexampleSearchContainer::CountComponentControls() const
{
TInt count = 0;
if (iSearchListBox)
count++;
if (iLabel)
count++;
return count;
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::ComponentControl()
// Gets the specified component of a compound control.
// ----------------------------------------------------
//
CCoeControl* CCalendarAPIexampleSearchContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iLabel;
case 1:
return iSearchListBox;
default:
return NULL;
}
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::OfferKeyEventL()
// When a key event occurs, the control framework calls
// this function for each control on the control stack,
// until one of them can process the key event
// (and returns EKeyWasConsumed).
// ----------------------------------------------------
//
TKeyResponse CCalendarAPIexampleSearchContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
else if(iSearchListBox)
{
return iSearchListBox->OfferKeyEventL( aKeyEvent, aType );
}
else
{
return EKeyWasNotConsumed;
}
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::Draw()
// This function is used for window server-initiated
// redrawing of controls, and for some
// application-initiated drawing.
// ----------------------------------------------------
//
void CCalendarAPIexampleSearchContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbSymbianGreen );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
//gc.DrawRect( aRect );
//MAknsSkinInstance* skin = AknsUtils::SkinInstance();
//MAknsControlContext* cc = AknsDrawUtils::ControlContext(this);
//AknsDrawUtils::Background(skin, cc, this, gc, Rect());
//gc.DrawBitmap(TRect(TPoint(0,0),iBitmap->SizeInPixels()), iBitmap);
// gc.BitBlt(TPoint(0,0), iBitmap);
gc.DrawRect( aRect );
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::SearchType()
// Returns the selected search range (week, month,...)
// ----------------------------------------------------
//
TSearchType CCalendarAPIexampleSearchContainer::SearchType() const
{
switch (iSearchListBox->CurrentItemIndex())
{
case 0:
return EWeek;
case 1:
return EMonth;
case 2:
return ESixMonths;
case 3:
return EYear;
default:
Panic(EUnSupportedSearchType);
break;
}
return EWeek;
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::Progress()
// Monitors the progress of agenda model operations.
// Creates a progress dialog when first called and
// updates its status on later calls. Note that if the
// agenda models operation completes quickly, for
// instance when opening a small file, then Progress()
// will probably not be called at all.
// ----------------------------------------------------
//
void CCalendarAPIexampleSearchContainer::Progress(TInt aPercentageCompleted)
{
if (!iProgressDialog)
{
TRAPD
(
error,
iProgressDialog = new (ELeave) CAknProgressDialog(REINTERPRET_CAST(CEikDialog**, &iProgressDialog), ETrue);
iProgressDialog->PrepareLC(R_CALENDARAPIEXAMPLE_PROGRESS_NOTE);
iProgressInfo = iProgressDialog->GetProgressInfoL();
iProgressDialog->RunLD();
)
if (KErrNone == error)
{
iProgressInfo->SetFinalValue(100);
iProgressInfo->SetAndDraw(aPercentageCompleted);
}
else
{
delete iProgressDialog;
iProgressDialog = NULL;
}
}
else
{
iProgressInfo->SetAndDraw(aPercentageCompleted);
}
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::Completed()
// Called when agenda model has completed its operation.
// Deletes the progress dialog if one has been created.
// ----------------------------------------------------
//
void CCalendarAPIexampleSearchContainer::Completed(TInt /*aError*/)
{
if (iProgressDialog)
{
iProgressInfo->SetAndDraw(100);
TRAPD
(
error,
iProgressDialog->ProcessFinishedL();
)
iProgressInfo = NULL;
iProgressDialog = NULL;
}
}
// ----------------------------------------------------
// CCalendarAPIexampleSearchContainer::HandleListBoxEventL()
// Handles listbox events.
// ----------------------------------------------------
//
void CCalendarAPIexampleSearchContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/,
TListBoxEvent aEventType)
{
if (aEventType == EEventEnterKeyPressed)
{
iSearchView.HandleCommandL(ECalendarAPIexampleCmdSearch);
}
}
// end of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -