📄 focuseventappview.cpp
字号:
/*
* ==============================================================================
* Name : focuseventappview.cpp
* Part of : Focus event example
* Interface :
* Description :
* Version :
*
* Copyright (c) 2004 - 2006 Nokia Corporation.
* This material, including documentation and any related
* computer programs, is protected by copyright controlled by
* Nokia Corporation.
* ==============================================================================
*/
// INCLUDE FILES
#include <hal.h>
#include <eikenv.h>
#include <AknUtils.h>
#include <eikedwin.h>
#include <COEMAIN.H>
#include "FocusEventAppUi.h"
#include "FocusEventAppView.h"
#include "EikonEnvironment.h"
const TInt ENumberofControls = 2;
_LIT( KEdwin1, "E1 ");
_LIT( KEdwin2, "E2 ");
_LIT( KEventKeyDown, "Down");
_LIT( KEventKey, "Hold");
_LIT( KEventKeyUp, "Up");
_LIT( KEdwinFmtChng, "Fmt chng");
_LIT( KEdwinNavi, "Nave");
_LIT( KEdwinUpdate, "Update");
// ============================ MEMBER FUNCTIONS ===============================
// -----------------------------------------------------------------------------
// CFocusEventAppView::CFocusEventAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CFocusEventAppView::CFocusEventAppView()
{
// No implementation required
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFocusEventAppView* CFocusEventAppView::NewL( const TRect& aRect )
{
CFocusEventAppView* self = NewLC( aRect );
CleanupStack::Pop( self );
return self;
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CFocusEventAppView* CFocusEventAppView::NewLC( const TRect& aRect )
{
CFocusEventAppView* self = new ( ELeave ) CFocusEventAppView;
CleanupStack::PushL( self );
self->ConstructL( aRect );
return self;
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::ConstructL( const TRect& aRect )
{
// Create a window for this application view
CreateWindowL();
iEdwin1 = new ( ELeave ) CEikEdwin;
iEdwin1->SetContainerWindowL( *this );
iEdwin1->SetEdwinObserver( this );
iEdwin1->ConstructL( CEikEdwin::EZeroEnumValue, 30, 30, 5 );
iEdwin1->SetInputCapabilitiesL( TCoeInputCapabilities::EWesternNumericIntegerPositive );
iEdwin1->SetFocus( ETrue );
iEdwin2 = new ( ELeave ) CEikEdwin;
iEdwin2->SetContainerWindowL( *this );
iEdwin2->SetEdwinObserver( this );
iEdwin2->ConstructL( CEikEdwin::EZeroEnumValue, 30, 30, 5);
iEdwin2->SetInputCapabilitiesL( TCoeInputCapabilities::EWesternNumericIntegerPositive );
// Set the windows size
SetRect( aRect );
// Activate the window, which makes it ready to be drawn
ActivateL();
// Add the first blank line to the array of text lines
User::LeaveIfError( iTextLines.Append( KNullDesC() ) );
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::~CFocusEventAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CFocusEventAppView::~CFocusEventAppView()
{
iTextLines.Close();
delete iEdwin1;
delete iEdwin2;
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::Draw( const TRect& /*aRect*/ ) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();
// Gets the control's extent
TRect drawRect=Rect();
gc.UseFont( NEikonEnvironment::EikEnv().AnnotationFont() );
//set background colour to gray
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbGray );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( Rect());
// Draw all lines of text
TInt count;
for ( count = 0; count < iTextLines.Count(); count++ )
{
gc.DrawText( iTextLines[ count ],
TPoint( KTextXMargin, KTextMinY+
( count*KTextDistanceBetweenLines ) ) );
}
}
// -----------------------------------------------------------------------------
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::SizeChanged()
{
TSize edwinSize( Rect().Width(), 20 );
TInt rightUpY = Rect().Height() - ( 2 * 20 + 5 );
TPoint P1( 0, rightUpY );
TPoint P2( 0, rightUpY + 20 + 5 );
iEdwin1->SetExtent( P1, edwinSize );
iEdwin2->SetExtent( P2, edwinSize );
DrawNow();
}
// ---------------------------------------------------------------------------
// CFocusEventAppView::CountComponentControls() const
//
// ---------------------------------------------------------------------------
//
TInt CFocusEventAppView::CountComponentControls() const
{
return ENumberofControls;
}
// ---------------------------------------------------------------------------
// CFocusEventAppView::ComponentControl(TInt aIndex) const
//
// ---------------------------------------------------------------------------
//
CCoeControl* CFocusEventAppView::ComponentControl( TInt aIndex ) const
{
switch ( aIndex )
{
case 0:
return iEdwin1;
case 1:
return iEdwin2;
default:
return NULL;
}
}
// ---------------------------------------------------------------------------
// CFocusEventAppView::OfferKeyEventL()
//
// ---------------------------------------------------------------------------
//
TKeyResponse CFocusEventAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
TEventCode aType )
{
TKeyResponse res = EKeyWasNotConsumed;
TBuf<32> msg( KNullDesC );
CEikEdwin* editor = NULL;
// Control the focus in which Edwin
// Click up arrow or down arrow, the focus will change to the
// other Edwin.
if ( iEdwin1->IsFocused() &&
EEventKey == aType &&
( EKeyUpArrow == aKeyEvent.iCode ||
EKeyDownArrow == aKeyEvent.iCode ))
{
iEdwin2->SetFocus( ETrue );
iEdwin1->SetFocus( EFalse );
}
else if ( iEdwin2->IsFocused() &&
EEventKey == aType &&
( EKeyUpArrow == aKeyEvent.iCode ||
EKeyDownArrow == aKeyEvent.iCode ))
{
iEdwin1->SetFocus( ETrue );
iEdwin2->SetFocus( EFalse );
}
// Shift + some key pressed at the same time
TBool shiftKeyPressed = (aKeyEvent.iModifiers & EModifierShift);
if ( shiftKeyPressed )
{
#ifdef __WINS__
_LIT( KShiftPress, "Shift" );
User::InfoPrint( KShiftPress );
#endif /* __WINS__ */
}
if ( shiftKeyPressed && aKeyEvent.iCode == EKeyDownArrow )
{
#ifdef __WINS__
_LIT( KShiftSpacePress, "Shift+Down" );
User::InfoPrint( KShiftSpacePress );
#endif /* __WINS__ */
}
// Focused edwin number
if ( iEdwin1->IsFocused() )
{
msg.Append( KEdwin1 );
editor = iEdwin1;
}
if ( iEdwin2->IsFocused() )
{
msg.Append( KEdwin2 );
editor = iEdwin2;
}
// Key Code: TKeyCode in e32key.h
_LIT( KCode, "%i/" );
msg.AppendFormat( KCode, aKeyEvent.iCode );
// Scan Code: TStdScanCode in e32key.h
_LIT( KScanCode, "%i/" );
msg.AppendFormat( KScanCode, aKeyEvent.iScanCode );
// Modifiers: TEventModifier
_LIT( KModifiers, "%i/" );
msg.AppendFormat( KModifiers, aKeyEvent.iModifiers );
// Repeats: 0-n
_LIT( KRepeats, "%i " );
msg.AppendFormat( KRepeats, aKeyEvent.iRepeats );
// TEventCode Down, Hold or Up
switch ( aType )
{
case EEventKeyDown:
msg.Append( KEventKeyDown );
break;
case EEventKey:
msg.Append( KEventKey );
break;
case EEventKeyUp:
msg.Append( KEventKeyUp );
break;
}
Print( msg );
PrintNewLineL();
res = editor->OfferKeyEventL( aKeyEvent, aType );
return res;
}
// ---------------------------------------------------------------------------
// CFocusEventAppView::HandleEdwinEventL()
//
// ---------------------------------------------------------------------------
//
void CFocusEventAppView::HandleEdwinEventL( CEikEdwin *aEdwin,
TEdwinEvent aEventType )
{
TBuf<32> msg( KNullDesC );
// Which control own focus
if ( aEdwin == iEdwin1 )
{
msg.Copy( KEdwin1 );
}
else if ( aEdwin == iEdwin2 )
{
msg.Copy( KEdwin2 );
}
else
{
// else process
}
// Which Event key Type
if ( EEventFormatChanged == aEventType )
{
msg.Append( KEdwinFmtChng );
}
if ( EEventNavigation == aEventType )
{
msg.Append( KEdwinNavi );
}
if ( EEventTextUpdate == aEventType )
{
msg.Append( KEdwinUpdate );
}
//Print to the screen
//Print( msg );
//PrintNewLineL();
}
// ---------------------------------------------------------------------------
// CFocusEventAppView::KeyCapturedL()
//
// ---------------------------------------------------------------------------
//
TBool CFocusEventAppView::KeyCapturedL(TWsEvent aEvent)
{
TBuf<32> msg( KNullDesC );
_LIT( KCapture, "BG key %i" );
msg.AppendFormat( KCapture, aEvent.Key()->iCode );
Print( msg );
PrintNewLineL();
dynamic_cast<CFocusEventAppUi*>(iCoeEnv->AppUi())->BringToForeground();
return ETrue;
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::Print()
// Show text on screen.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::Print( const TDesC& aText )
{
ShowTextOnScreen( aText );
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::ShowTextOnScreen()
// Show text on screen.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::ShowTextOnScreen( const TDesC& aText )
{
// Add the text line onto the last line
TInt lastTextLine = iTextLines.Count() - 1;
// Make sure the text line doesn't get too long for the buffer.
// This should really clip rather than not do anything
// if the line is too long.
if ( aText.Length() + iTextLines[ lastTextLine ].Length()
<= KTestFrameworkMaxScreenMessageLength )
{
iTextLines[ lastTextLine ].Append( aText );
DrawNow();
}
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::ClearTextOnScreen()
// Show text on screen.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::ClearTextOnScreen()
{
iTextLines.Reset();
iTextLines.Append( KNullDesC() );
DrawNow();
}
// -----------------------------------------------------------------------------
// CFocusEventAppView::PrintNewLineL()
// Print new line.
// -----------------------------------------------------------------------------
//
void CFocusEventAppView::PrintNewLineL()
{
// Add a new line onto the array
// If the array is already at the maximum size,
// delete the first line of text
if ( iTextLines.Count() >= KMaxTextLines )
{
iTextLines.Remove( 0 );
//iTextLines.Reset();
}
User::LeaveIfError( iTextLines.Append( KNullDesC() ) );
DrawNow();
}
// ---------------------------------------------------------
// CFocusEventAppView::HandleResourceChange()
// Called by framework when layout is changed.
// ---------------------------------------------------------
//
void CFocusEventAppView::HandleResourceChange(TInt aType)
{
CCoeControl::HandleResourceChange(aType);
// ADDED FOR SCALABLE UI SUPPORT
// *****************************
if ( aType==KEikDynamicLayoutVariantSwitch )
{
TRect rect;
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
SetRect(rect);
}
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -