📄 alarmorganisersecondcontainer.cpp
字号:
/**
*
* @brief Definition of CAlarmOrganiserSecondContainer
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDES
// Class include
#include "AlarmOrganiserSecondContainer.h"
// System includes
#include <AlarmOrganiser.rsg> // R_EMPTY_LIST_TEXT
#include <aknlists.h> // CAknSingleStyleListBox
#include <AknQueryDialog.h> // CAknQueryDialog
// User Includes
#include "AlarmOrganiserSecondEngine.h" // CAlarmOrganiserSecondEngine
// CONSTANTS
// ================ = MEMBER FUNCTIONS ====================== =
/**
* Symbian OS 2 phase constructor.
* Constructs the CAlarmOrganiserSecondContainer using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CAlarmOrganiserSecondContainer
*/
CAlarmOrganiserSecondContainer* CAlarmOrganiserSecondContainer::NewL(const TRect& aRect)
{
CAlarmOrganiserSecondContainer* self = CAlarmOrganiserSecondContainer::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CAlarmOrganiserSecondContainer using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @param aRect The rectangle for this window
* @return The newly constructed CAlarmOrganiserSecondContainer
*/
CAlarmOrganiserSecondContainer* CAlarmOrganiserSecondContainer::NewLC(const TRect& aRect)
{
CAlarmOrganiserSecondContainer* self = new (ELeave) CAlarmOrganiserSecondContainer;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
/**
* Symbian OS 2nd phase constructor. Symbian OS 2nd phase constructor.
* Creates a Window for the controls, creates the listbox
* and then creates the AlarmOrganiser engine
* @param aRect The rectangle for this window
*/
void CAlarmOrganiserSecondContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
// Create the List Box
iListBox = new (ELeave) CAknSingleNumberStyleListBox();
iListBox->ConstructL(this, EAknListBoxSelectionList);
iListBox->SetContainerWindowL(*this);
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
iListBox->SetRect(Rect());
iListBox->SetListBoxObserver(this);
// Show the empty list box text rather than the Second "no data"
HBufC* emptyListText = iEikonEnv->AllocReadResourceLC(R_EMPTY_LIST_TEXT);
iListBox->View()->SetListEmptyTextL(*emptyListText);
CleanupStack::PopAndDestroy(emptyListText);
SetRect(aRect);
ActivateL();
iEngine = CAlarmOrganiserSecondEngine::NewL(*this);
}
/**
*
* Called by framework when the view size is changed. Resizes the
* iListBox accordingly.
*
*/
void CAlarmOrganiserSecondContainer::SizeChanged()
{
if (iListBox)
{
iListBox->SetRect(Rect());
}
}
/**
* Called by the framework in compound controls
* @return The number of controls in this CAlarmOrganiserSecondContainer
*/
TInt CAlarmOrganiserSecondContainer::CountComponentControls() const
{
return 1;
}
/**
* Called by the framework in compound controls
* @param The index of the control to return
* @return The control for aIndex
*/
CCoeControl* CAlarmOrganiserSecondContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iListBox;
default:
return NULL;
}
}
/**
* Destructor.
*/
CAlarmOrganiserSecondContainer::~CAlarmOrganiserSecondContainer()
{
delete iEngine;
delete iListBox;
}
/**
* Called by the framework to draw this control. Clears the area in
* aRect.
* @param aRect in which to draw
*/
void CAlarmOrganiserSecondContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
}
/**
* Inherited from MAgnProgressCallBack.
* This function is called at intervals while an activity on an
* Agenda model (in this case OpenL()) is in progress. If the
* activity completes quickly this function may not be called at all.
* This is an empty implementation, could be extened in future to
* support a progress dialog.
* @param aPercentageCompleted what percentage of the process has been completed
*/
void CAlarmOrganiserSecondContainer::Progress(TInt /*aPercentageCompleted*/)
{
}
/**
* Inherited from MAgnProgressCallBack.
* Called when the activity has completed.
* This is an empty implementation.
* @param aError any error which has occurred.
*/
void CAlarmOrganiserSecondContainer::Completed(TInt /*aError*/)
{
}
/**
* Inherited from MAlarmOrganiserEngineMixin. Called back
* when the engine has been initialised.
* @param aError
*/
void CAlarmOrganiserSecondContainer::EngineCallBack(TInt aError)
{
if (aError == KErrNone)
{
SetListBoxArray();
}
}
/**
* Called by the framework whenever a key event occurs.
* Passes the key event to the listbox if it is not null, otherwise returns
* EKeyWasNotConsumed
* @param aKeyEvent the Key event which occured, e.g. select key pressed
* @param aType the type of Key event which occurred, e.g. key up, key down
* @return TKeyResponse EKeyWasNotConsumed if the key was not processed, EKeyWasConsumed if it was
*/
TKeyResponse CAlarmOrganiserSecondContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
TChar charCode(aKeyEvent.iCode);
switch (charCode)
{
// Switches tab
case EKeyLeftArrow: // Left key.
case EKeyRightArrow: // Right Key.
break;
default:
{
if (iListBox)
{
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
}
}
return EKeyWasNotConsumed;
}
/**
* Handles listbox event.
* @param aListBox Pointer to ListBox object is not used.
* @param aEventType Type of listbox event.
*/
void CAlarmOrganiserSecondContainer::HandleListBoxEventL(CEikListBox* /*aListBox*/, TListBoxEvent aListBoxEvent)
{
// if the Select Key has been pressed
if ((aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed) ||
(aListBoxEvent == MEikListBoxObserver::EEventItemClicked))
{
AddAlarmL();
}
}
/**
* This functions sets the data displayed in the list box
* to the array created by CAlarmOrganiserEngine
*/
void CAlarmOrganiserSecondContainer::SetListBoxArray()
{
CTextListBoxModel* model = iListBox->Model();
// Set the model data
model->SetItemTextArray(iEngine->ListBoxArray());
model->SetOwnershipType(ELbmDoesNotOwnItemArray);
iListBox->Reset();
DrawNow();
}
/**
* This function displays a dialog asking if the user would like
* to add an alarm to the selected entry. If yes, adds an alarm to the entry
*/
void CAlarmOrganiserSecondContainer::AddAlarmL()
{
TInt alarm = iListBox->CurrentItemIndex();
if (alarm < 0)
{
return; // Invalid alarm.
}
HBufC* text = CEikonEnv::Static()->AllocReadResourceLC(R_ADD_ALARM_TEXT);
CAknQueryDialog* dlg = new (ELeave) CAknQueryDialog(*text);
if (dlg->ExecuteLD(R_ALARMORGANISER_CONFIRMATION_QUERY))
{
iEngine->AddAlarmL(alarm);
}
CleanupStack::PopAndDestroy(text);
}
/**
* returns if the list box is empty or not
* @return ETrue if the listbox is empty
*/
TBool CAlarmOrganiserSecondContainer::ListBoxEmpty()
{
return (iListBox->Model()->NumberOfItems() == 0);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -