📄 stackcontainer.cpp
字号:
/*
* ============================================================================
* Name : CStackContainer from StackContainer.h
* Part of : Stack
* Created : 03.12.2005 by ToBeReplacedByAuthor
* Implementation notes:
* Initial content was generated by Series 60 AppWizard.
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDE FILES
#include "StackContainer.h"
#include <eiklabel.h> // for example label control
#include <eikedwin.h> // for CEikEdwin
#include <Stack.rsg>
#include <barsread.h>
#include <aknlists.h> // for Listbox
//#include <Stack.rsg>
#include "stack.hrh"
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CStackContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CStackContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iPushTextLabel = new (ELeave) CEikLabel;
iPushTextLabel->SetContainerWindowL( *this );
iPushTextLabel->SetTextL( _L("To Push") );
iPopTextLabel = new (ELeave) CEikLabel;
iPopTextLabel->SetContainerWindowL( *this );
iPopTextLabel->SetTextL( _L("Poped") );
iPopContentLabel = new (ELeave) CEikLabel;
iPopContentLabel->SetContainerWindowL( *this );
iPopContentLabel->SetTextL( _L("None") );
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_AKNEXEDITOR_OPERATECONTAINER_EDWIN);
iPushNumber = new (ELeave) CEikEdwin;
iPushNumber->SetContainerWindowL(*this);
iPushNumber->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // Resource reader
iPushNumber->SetBorder(TGulBorder::ESingleBlack);
iPushNumber->SetFocus(ETrue);
iListBox = new (ELeave) CAknSingleStyleListBox;
iListBox->SetContainerWindowL(*this);
iListBox->ConstructL(this, EAknListBoxSelectionList);
CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(array);
array->AppendL(_L("\tBottom of Stack"));
CleanupStack::Pop();
iListBox->Model()->SetItemTextArray(array);
iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto);
iListBox->ActivateL();
SetRect(aRect);
ActivateL();
}
// Destructor
CStackContainer::~CStackContainer()
{
delete iPushTextLabel;
delete iPopTextLabel;
delete iPopContentLabel;
delete iPushNumber;
delete iListBox;
}
#define PUSH_LABEL_POS TPoint(5,5)
#define PUSH_EDIT_POS TPoint(88,5)
#define POP_LABEL_POS TPoint(5,35)
#define POP_CONTENT_POS TPoint(88,35)
#define LIST_POS TPoint(0,60)
#define TEXT_SIZE TSize(60,20)
#define LISTBOX_SIZE TSize(176,80)
// ---------------------------------------------------------
// CStackContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CStackContainer::SizeChanged()
{
iPushTextLabel->SetExtent( PUSH_LABEL_POS, TEXT_SIZE );
iPushNumber->SetExtent( PUSH_EDIT_POS, TEXT_SIZE );
iPopTextLabel->SetExtent( POP_LABEL_POS, TEXT_SIZE );
iPopContentLabel->SetExtent( POP_CONTENT_POS, TEXT_SIZE );
iListBox->SetExtent( LIST_POS, LISTBOX_SIZE);
}
// ---------------------------------------------------------
// CStackContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CStackContainer::CountComponentControls() const
{
return 5; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CStackContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CStackContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iPushTextLabel;
case 1:
return iPushNumber;
case 2:
return iPopTextLabel;
case 3:
return iPopContentLabel;
case 4:
return iListBox;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CStackContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CStackContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGreen );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ---------------------------------------------------------
// CStackContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CStackContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
// ---------------------------------------------------------
// CStackContainer::OfferKeyEventL(...)
// Notify key events to editor and listbox.
// ---------------------------------------------------------
//
TKeyResponse CStackContainer::OfferKeyEventL(
const TKeyEvent& aKeyEvent, TEventCode aType)
{
if ( aType != EEventKey )
{
// 一般只需处理EEventKey事件,而不必处理EEventKeyDown和EEventKeyUp事件
return EKeyWasNotConsumed;
}
if (iPushNumber && iPushNumber->IsFocused())
{
// 编辑框在激活状态时的处理
if(aKeyEvent.iCode == EKeyDownArrow)
{
// 如果是方向导航键的下键,激活列表控件
iPushNumber->SetFocus(EFalse);
iListBox->SetFocus(ETrue);
return EKeyWasConsumed;
}
else
{
// 将其它按键的处理交给编辑框
return iPushNumber->OfferKeyEventL(aKeyEvent, aType);
}
}
else if (iListBox && iListBox->IsFocused())
{
// 列表在激活状态时的处理
if (iListBox->CurrentItemIndex()==0 && aKeyEvent.iCode == EKeyUpArrow)
{
// 如果列表的当前选项是第1个,而且按键是方向导航键的上键
// 则激活列表上面的编辑框
iPushNumber->SetFocus(ETrue);
iListBox->SetFocus(EFalse);
return EKeyWasConsumed;
}
else
{
// 其它情况下的按键交给列表处理
return iListBox->OfferKeyEventL(aKeyEvent, aType);
}
}
// 非以上情况是,说明事件没有被处理,返回EKeyWasNotConsumed
return EKeyWasNotConsumed;
}
void CStackContainer::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EStackCmdAppPush:
{
TBuf<32> buf;
buf.Zero();
iPushNumber->GetText(buf);
if (buf.Length()==0)
{
iEikonEnv->InfoMsg( _L("Can't push empty text") );
}
else
{
buf.Insert(0, _L("\t"));
CDesCArray* array = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
array->InsertL(0,buf);
iListBox->HandleItemAdditionL();
buf.Zero();
iPushNumber->SetTextL(&buf);
}
break;
}
case EStackCmdAppPop:
{
CDesCArray* array = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray());
if (array->Count()==1)
{
iEikonEnv->InfoMsg( _L("The stack is empty") );
}
else
{
TBuf<32> buf;
TPtrC ptr = (*array)[0];
buf.Copy(ptr);
buf.Delete(0,1);
iEikonEnv->InfoMsg(buf);
iPopContentLabel->SetTextL(buf);
array->Delete(0);
iListBox->HandleItemRemovalL();
}
break;
}
default:
{
break;
}
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -