📄 bookeditorview.cpp
字号:
/*
* ============================================================================
* Name : BookEditorView from BookEditorView.cpp
* Part of : Bookstore
* Created : 8.12.2003 by Forum Nokia
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
#include <barsread.h> // for resource reader
#include <eiklabel.h> // for label controls
#include <eikedwin.h> // for CEikEdwin
#include "BookEditorView.h"
#include <BookstoreDb.rsg> // Generated from BookstoreDb.rss
// Controls' positions in the view
#define LABEL_AUTHOR_POS TPoint(10, 5)
#define EDWIN_AUTHOR_POS TPoint(10, 19)
#define LABEL_TITLE_POS TPoint(10, 53)
#define EDWIN_TITLE_POS TPoint(10, 67)
#define LABEL_DESCRIPTION_POS TPoint(10, 101)
#define EDWIN_DESCRIPTION_POS TPoint(10, 115)
// Constants
const TInt KNumberOfControls = 6; //Number of UI controls within this container
// Constant texts
_LIT(KLabelTextAuthor,"Author:");
_LIT(KLabelTextTitle,"Title:");
_LIT(KLabelTextDescription, "Description:");
// Controls within this view control
enum TControls
{
ELabelAuthor,
EEdwinAuthor,
ELabelTitle,
EEdwinTitle,
ELabelDescription,
EEdwinDescription
};
// ---------------------------------------------------------------------------
// CBookEditorView::NewL()
//
// Create instance of this compound control.
// ---------------------------------------------------------------------------
//
CBookEditorView* CBookEditorView::NewL(const TRect& aRect)
{
CBookEditorView* self = new (ELeave) CBookEditorView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop(self);
return self;
}
// ---------------------------------------------------------------------------
// CBookEditorView::ConstructL()
//
// Perform the second phase construction. Instantiate the owned controls.
// ---------------------------------------------------------------------------
//
void CBookEditorView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
iLabelAuthor = new (ELeave) CEikLabel;
iLabelAuthor->SetContainerWindowL(*this);
iLabelAuthor->SetTextL(KLabelTextAuthor);
iLabelTitle = new (ELeave) CEikLabel;
iLabelTitle->SetContainerWindowL(*this);
iLabelTitle->SetTextL(KLabelTextTitle);
iLabelDescription = new (ELeave) CEikLabel;
iLabelDescription->SetContainerWindowL(*this);
iLabelDescription->SetTextL(KLabelTextDescription);
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_SIMPLE_EDWIN);
iEdwinAuthor = new (ELeave) CEikEdwin;
iEdwinAuthor->SetContainerWindowL(*this);
iEdwinAuthor->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // Resource reader
iCoeEnv->CreateResourceReaderLC(reader, R_SIMPLE_EDWIN);
iEdwinTitle = new (ELeave) CEikEdwin;
iEdwinTitle->SetContainerWindowL(*this);
iEdwinTitle->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // Resource reader
iCoeEnv->CreateResourceReaderLC(reader, R_SIMPLE_EDWIN);
iEdwinDescription = new (ELeave) CEikEdwin;
iEdwinDescription->SetContainerWindowL(*this);
iEdwinDescription->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // Resource reader
SizeChanged();
iEdwinAuthor->SetFocus(ETrue);
// Set the windows size
SetRect(aRect);
// Activate the window, which marks it ready to be drawn
ActivateL();
}
// ---------------------------------------------------------------------------
// CBookEditorView::CBookEditorView()
//
// // Constructor.
// ---------------------------------------------------------------------------
//
CBookEditorView::CBookEditorView()
:iLabelAuthor(NULL),
iLabelTitle(NULL),
iLabelDescription(NULL),
iEdwinAuthor(NULL),
iEdwinTitle(NULL),
iEdwinDescription(NULL)
{
// No implementation required
}
// ---------------------------------------------------------------------------
// CBookEditorView::~CBookEditorView()
//
// Destructor. Release the owned controls
// ---------------------------------------------------------------------------
//
CBookEditorView::~CBookEditorView()
{
delete iLabelAuthor;
delete iEdwinAuthor;
delete iLabelTitle;
delete iEdwinTitle;
delete iLabelDescription;
delete iEdwinDescription;
}
// ---------------------------------------------------------------------------
// CBookEditorView::Draw()
//
// Draw the view. Called by framework, when necessary.
// Because this is a container for lodger controls, just clear the background.
// The owned controls are drawn by the framework, when necessary.
// ---------------------------------------------------------------------------
//
void CBookEditorView::Draw(const TRect& aRect) const
{
//Clear the screen
CWindowGc& gc = SystemGc();
gc.Clear(Rect());
gc.SetBrushColor(KRgbGray);
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.DrawRect(aRect);
}
// ---------------------------------------------------------------------------
// CBookEditorView::SizeChanged()
//
// Scale the owned controls to reflect current (new) state
// ---------------------------------------------------------------------------
//
void CBookEditorView::SizeChanged()
{
iLabelAuthor->SetExtent(LABEL_AUTHOR_POS, iLabelAuthor->MinimumSize());
iLabelTitle->SetExtent(LABEL_TITLE_POS, iLabelTitle->MinimumSize());
iLabelDescription->SetExtent(LABEL_DESCRIPTION_POS,
iLabelDescription->MinimumSize());
iEdwinAuthor->SetExtent(EDWIN_AUTHOR_POS, iEdwinAuthor->MinimumSize());
iEdwinTitle->SetExtent(EDWIN_TITLE_POS, iEdwinTitle->MinimumSize());
iEdwinDescription->SetExtent(EDWIN_DESCRIPTION_POS,
iEdwinDescription->MinimumSize());
}
// ---------------------------------------------------------------------------
// CBookEditorView::CountComponentControls()
//
// Tell the framework the number of owned controls so that it can query them
// ---------------------------------------------------------------------------
//
TInt CBookEditorView::CountComponentControls() const
{
return KNumberOfControls;
}
// ---------------------------------------------------------------------------
// CBookEditorView::ComponentControl()
//
// Return owned controls to framework so it will draw them.
// ---------------------------------------------------------------------------
//
CCoeControl* CBookEditorView::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case ELabelAuthor:
return iLabelAuthor;
case EEdwinAuthor:
return iEdwinAuthor;
case ELabelTitle:
return iLabelTitle;
case EEdwinTitle:
return iEdwinTitle;
case ELabelDescription:
return iLabelDescription;
case EEdwinDescription:
return iEdwinDescription;
default:
return NULL;
}
}
// ---------------------------------------------------------------------------
// CBookEditorView::OfferKeyEventL()
//
// Handle key events. User of this view control must add this to control
// stack to ensure this component is able to get key events. In practise
// the AppUi does it.
// ---------------------------------------------------------------------------
//
TKeyResponse CBookEditorView::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
// Handle up & down keys. Switch edit boxes, if appropriate
// (change the focus).
if(aType == EEventKeyDown)
{
switch (aKeyEvent.iScanCode)
{
case EStdKeyUpArrow:
if(iEdwinTitle->IsFocused())
{
iEdwinTitle->SetFocus(EFalse);
iEdwinAuthor->SetFocus(ETrue);
return EKeyWasConsumed;
}
else if(iEdwinDescription->IsFocused())
{
iEdwinDescription->SetFocus(EFalse);
iEdwinTitle->SetFocus(ETrue);
return EKeyWasConsumed;
}
break;
case EStdKeyDownArrow:
if(iEdwinAuthor->IsFocused())
{
iEdwinAuthor->SetFocus(EFalse);
iEdwinTitle->SetFocus(ETrue);
return EKeyWasConsumed;
}
else if(iEdwinTitle->IsFocused())
{
iEdwinTitle->SetFocus(EFalse);
iEdwinDescription->SetFocus(ETrue);
return EKeyWasConsumed;
}
break;
}
}
// Let the focused edit box handle the key event
if (iEdwinAuthor->IsFocused())
{
return iEdwinAuthor->OfferKeyEventL(aKeyEvent, aType);
}
if (iEdwinTitle->IsFocused())
{
return iEdwinTitle->OfferKeyEventL(aKeyEvent, aType);
}
if( iEdwinDescription->IsFocused())
{
return iEdwinDescription->OfferKeyEventL(aKeyEvent, aType);
}
return EKeyWasNotConsumed;
}
// ---------------------------------------------------------------------------
// CBookEditorView::GetAuthor()
//
// Get author value from iEdwinAuthor
// ---------------------------------------------------------------------------
//
void CBookEditorView::GetAuthor(TDes& aResult) const
{
iEdwinAuthor->GetText(aResult);
aResult.Trim();
}
// ---------------------------------------------------------------------------
// CBookEditorView::GetTitle()
//
// Get title value from iEdwinTitle
// ---------------------------------------------------------------------------
//
void CBookEditorView::GetTitle(TDes& aResult) const
{
iEdwinTitle->GetText(aResult);
aResult.Trim();
}
// ---------------------------------------------------------------------------
// CBookEditorView::GetDescription()
//
// Get description value from iEdwinDescription
// ---------------------------------------------------------------------------
//
void CBookEditorView::GetDescription(TDes& aResult) const
{
iEdwinDescription->GetText(aResult);
aResult.Trim();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -