智手移动中文网's Archiver

智手小石头 发表于 2006-5-9 11:16

在Fep中处理指针事件的例子

~~~ CExampleFep.h ~~~
////////////////
#if !defined(__E32BASE_H__)
#include <E32BASE.H>
#endif

#if !defined(__W32STD_H__)
#include <W32STD.H>
#endif

#if !defined(__FRMTLAY_H__)
#include <FRMTLAY.H>
#endif

#if !defined(__COEMAIN_H__)
#include <COEMAIN.H>
#endif

#if !defined(__COECNTRL_H__)
#include <COECNTRL.H>
#endif

#if !defined(__FEPBASE_H__)
#include <FEPBASE.H>
#endif

#if !defined(__FEPITFR_H__)
#include <FEPITFR.H>
#endif

#if !defined(__EIKDIALG_H__)
#include <EIKDIALG.H>
#endif

#if !defined(__EIKMOBS_H__)
#include <EIKMOBS.H>
#endif
////////////////

class CExampleFepControl;

class CExampleFep : public CCoeFep
{
public:
CExampleFep(CCoeEnv& aConeEnvironment);
void ConstructL(const CCoeFepParameters& aFepParameters);
virtual ~CExampleFep();

// from CCoeFep
// virtual void CancelTransaction();
inline void SimulateKeyEventsL(const TArray<TUint>& aArrayOfCharacters) {CCoeFep::SimulateKeyEventsL(aArrayOfCharacters);}
inline void SimulateKeyEventsL(const TArray<MModifiedCharacter>& aArrayOfModifiedCharacters) {CCoeFep::SimulateKeyEventsL(aArrayOfModifiedCharacters);}
inline TBool IsSimulatingKeyEvent() const {return CCoeFep::IsSimulatingKeyEvent();}
inline void WriteAttributeDataAndBroadcastL(TUid aAttributeUid) {CCoeFep::WriteAttributeDataAndBroadcastL(aAttributeUid);}
inline TBool IsTurnedOnByL(const TKeyEvent& aKeyEvent) const {return CCoeFep::IsTurnedOnByL(aKeyEvent);}
inline TBool IsTurnedOffByL(const TKeyEvent& aKeyEvent) const {return CCoeFep::IsTurnedOffByL(aKeyEvent);}
inline TBool IsOn() const {return CCoeFep::IsOn();}
private:
// from CCoeFep
virtual void CancelTransaction();
virtual void IsOnHasChangedState();
virtual void OfferKeyEventL(TEventResponse& aEventResponse,
const TKeyEvent& aKeyEvent,
TEventCode aEventCode);
virtual void OfferPointerEventL(TEventResponse& aEventResponse,
const TPointerEvent& aPointerEvent,
const CCoeControl* aWindowOwningControl);
virtual void OfferPointerBufferReadyEventL(TEventResponse& aEventResponse,
const CCoeControl* aWindowOwningControl);

// from MCoeFocusObserver
virtual void HandleChangeInFocus();
virtual void HandleDestructionOfFocusedItem();

// from MCoeForegroundObserver
virtual void HandleGainingForeground();
virtual void HandleLosingForeground();

// from MFepAttributeStorer (via CCoeFep)
virtual TInt NumberOfAttributes() const;
virtual TUid AttributeAtIndex(TInt aIndex) const;
virtual void WriteAttributeDataToStreamL(TUid aAttributeUid, RWriteStream& aStream) const;
virtual void ReadAttributeDataFromStreamL(TUid aAttributeUid, RReadStream& aStream);

private:
CExampleFepControl* iFepControl;
};

~~~ CExampleFep.cpp ~~~
////////////////
#include <eikappui.h>
#include <eikenv.h> //CEikonEnv
#include <FEPBASE.H>
#include <w32std.h>
#include <frmtlay.h>
#include <QuartzFepDescription.h>

#include "fepexample.h"
#include "fepcontrol.h"
////////////////

GLDEF_C TInt E32Dll(TDllReason)
{
return KErrNone;
}

// the exported functions
/**
* Main Fep construction - defined in COEFEPU.DEF
*/
EXPORT_C CCoeFep* NewFepL(CCoeEnv& aConeEnvironment, const TDesC& /*aFullFileNameOfDll*/, const CCoeFepParameters& aFepParameters)
{
CExampleFep* const fep = new(ELeave) CExampleFep(aConeEnvironment);
CleanupStack::PushL(fep);
fep->ConstructL(aFepParameters);
CleanupStack::Pop(); // fep
return fep;
}
/**
* Export defined in COEFEPU.DEF - unused
*/
EXPORT_C void SynchronouslyExecuteSettingsDialogL(CCoeEnv& /*aConeEnvironment*/, const TDesC& /*aFullFileNameOfDll*/)
{
}
/**
* Reserved exports defined in COEFEPU.DEF - unused
*/
EXPORT_C void Reserved_1(){}
EXPORT_C void Reserved_2(){}
EXPORT_C void Reserved_3(){}
EXPORT_C void Reserved_4(){}
EXPORT_C void Reserved_5(){}
EXPORT_C void Reserved_6(){}
EXPORT_C void Reserved_7(){}
EXPORT_C void Reserved_8(){}

EXPORT_C void QuartzFepDescription(TQuartzFepDescription& aFepDescription )
{
aFepDescription.iFepName.Zero();
aFepDescription.iFepName.Copy(_L("FepEx"));
aFepDescription.iFepType = TQuartzFepDescription::EFepTypeFloatingInABox;
}

/////////////////////////////////////////////////////////////////////////////////
//
//Class CExampleFep
//
/////////////////////////////////////////////////////////////////////////////////

CExampleFep::CExampleFep(CCoeEnv& aConeEnvironment)
:CCoeFep(aConeEnvironment)
{
}

void CExampleFep::ConstructL(const CCoeFepParameters& aFepParameters)
{
BaseConstructL(aFepParameters);
iFepControl = CExampleFepControl::NewL(*this);
iFepControl->ActivateL();
}

CExampleFep::~CExampleFep()
{
if (iFepControl)
delete iFepControl;
}

TInt CExampleFep::NumberOfAttributes() const
{
return 0;
}

TUid CExampleFep::AttributeAtIndex(TInt /*aIndex*/) const
{
return KNullUid;
}

void CExampleFep::WriteAttributeDataToStreamL(TUid /*aAttributeUid*/, RWriteStream& /*aStream*/) const
{

}

void CExampleFep::ReadAttributeDataFromStreamL(TUid /*aAttributeUid*/, RReadStream& /*aStream*/)
{

}

void CExampleFep::OfferKeyEventL(TEventResponse& aEventResponse,const TKeyEvent& aKeyEvent, TEventCode aEventCode)
{
aEventResponse=EEventWasNotConsumed;
switch (iFepControl->OfferKeyEventL(aKeyEvent, aEventCode))
{
case EKeyWasNotConsumed:
aEventResponse=EEventWasNotConsumed;
break;
case EKeyWasConsumed:
aEventResponse=EEventWasConsumed;
break;
default:
aEventResponse=EEventWasNotConsumed;
break;
}
}

void CExampleFep::OfferPointerEventL(TEventResponse& aEventResponse,const TPointerEvent& aPointerEvent, const CCoeControl* /*aWindowOwningControl*/)
{
aEventResponse = EEventWasNotConsumed;
if(iFepControl) {
iFepControl->HandlePointerEventL(aPointerEvent);
aEventResponse=EEventWasConsumed;
}
}

void CExampleFep::OfferPointerBufferReadyEventL(TEventResponse& aEventResponse, const CCoeControl* /*aWindowOwningControl*/)
{
aEventResponse = EEventWasNotConsumed;
if(iFepControl) {
iFepControl->HandlePointerBufferReadyL();
aEventResponse=EEventWasConsumed;
}
}

void CExampleFep::HandleChangeInFocus()
{
if(iFepControl)
iFepControl->HandleChangeInFocus();
}

void CExampleFep::HandleDestructionOfFocusedItem()
{
}

void CExampleFep::HandleGainingForeground()
{
if(iFepControl)
iFepControl->HandleGainingForeground();
}

void CExampleFep::HandleLosingForeground()
{
}

void CExampleFep::CancelTransaction()
{
}

void CExampleFep::IsOnHasChangedState()
{
}

~~~ CExampleFepControl.h ~~~
////////////////
#if !defined(__E32BASE_H__)
#include
#endif

#if !defined(__W32STD_H__)
#include
#endif

#if !defined(__FRMTLAY_H__)
#include
#endif

#if !defined(__COEMAIN_H__)
#include
#endif

#if !defined(__COECNTRL_H__)
#include
#endif

#if !defined(__FEPBASE_H__)
#include
#endif

#if !defined(__FEPITFR_H__)
#include
#endif

#if !defined(__EIKDIALG_H__)
#include
#endif
////////////////

// Forward declarations
class CExampleFep;

class CExampleFepControl : public CCoeControl, private MFepInlineTextFormatRetriever, MFepPointerEventHandlerDuringInlineEdit
{
private:
//constructor
CExampleFepControl(CExampleFep& aFep);
void ConstructL();
void Draw(const TRect& /*aRect*/) const;
public:
static CExampleFepControl* NewL(CExampleFep& aFep);
~CExampleFepControl();

//From CCoeControl
virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
virtual void HandlePointerBufferReadyL();
// virtual TCoeInputCapabilities InputCapabilities() const;
// from MFepInlineTextFormatRetriever
virtual void GetFormatOfFepInlineText(TCharFormat& aFormat, TInt& aNumberOfCharactersWithSameFormat, TInt aPositionOfCharacter) const;

// from MFepPointerEventHandlerDuringInlineEdit
virtual void HandlePointerEventInInlineTextL(TPointerEvent::TType aType, TUint aModifiers, TInt aPositionInInlineText);

public:

// New methods
void HandleGainingForeground();
void HandleLosingForeground();
void HandleChangeInFocus();
void HandleDestructionOfFocusedItem();

// Start of inline text editing
void StartInlineEditL(MCoeFepAwareTextEditor& aFepAwareTextEditor, const TDesC& aInitialInlineText,
TInt aPositionOfInsertionPointInInlineText, TBool aCursorVisibility);

void CancelInlineEdit(MCoeFepAwareTextEditor& aFepAwareTextEditor);
void UpdateInlineEditL(const TDesC& aNewInlineText, TInt aPositionOfInsertionPointInInlineText);
void CommitInlineEditL(MCoeFepAwareTextEditor& aFepAwareTextEditor, TBool aCursorVisibility);

private:
CExampleFep& iFep;
TCoeInputCapabilities iInputCapabilities;
TCursorSelection iUncommittedText;
TInt iInsideInlineEditingTransaction; // Flag for editor inline editing
};

~~~ CExampleFepControl.cpp ~~~
////////////////
#include
#include //CEikonEnv
#include //defines keys
#include "fepexample.h"
#include "fepcontrol.h"
////////////////

CExampleFepControl* CExampleFepControl::NewL(CExampleFep& aFep)
{
CExampleFepControl* self=new(ELeave) CExampleFepControl(aFep);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(); //self
return self;
}

CExampleFepControl::~CExampleFepControl()
{
STATIC_CAST(CCoeAppUi*, iCoeEnv->AppUi())->RemoveFromStack(this);
}

CExampleFepControl::CExampleFepControl(CExampleFep& aFep)
:iFep(aFep),
iInputCapabilities(TCoeInputCapabilities::ENone),
iInsideInlineEditingTransaction(EFalse)
{
}

void CExampleFepControl::ConstructL()
{

CreateWindowL();
SetNonFocusing();
EnableDragEvents();
DrawableWindow()->SetOrdinalPosition(0, ECoeWinPriorityFep);
TPoint fepControlPos(0,201);

SetExtent(fepControlPos, TSize(208,100));
DrawableWindow()->SetExtentErr(fepControlPos, TSize(208,100));
DrawableWindow()->SetNonFading(ETrue);

DrawableWindow()->AllocPointerMoveBuffer(256, 0);
DrawableWindow()->DisablePointerMoveBuffer();

STATIC_CAST(CCoeAppUi*, iCoeEnv->AppUi())->AddToStackL(this,
ECoeStackPriorityFep, ECoeStackFlagSharable|ECoeStackFlagRefusesFocus);

}

void CExampleFepControl:raw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.SetBrushColor(TRgb(130,170,240));
gc.Clear();
}

void CExampleFepControl::StartInlineEditL(MCoeFepAwareTextEditor& aFepAwareTextEditor,
const TDesC& aInitialInlineText,
TInt aPositionOfInsertionPointInInlineText,
TBool aCursorVisibility)
{
aFepAwareTextEditor.StartFepInlineEditL(aInitialInlineText, aPositionOfInsertionPointInInlineText,
aCursorVisibility, NULL, *this, *this);

iInsideInlineEditingTransaction = ETrue;
}

void CExampleFepControl::UpdateInlineEditL(const TDesC& aNewInlineText,
TInt aPositionOfInsertionPointInInlineText)
{
iInputCapabilities.FepAwareTextEditor()->UpdateFepInlineTextL(aNewInlineText, aPositionOfInsertionPointInInlineText);
}

void CExampleFepControl::CancelInlineEdit(MCoeFepAwareTextEditor& aFepAwareTextEditor)
{
aFepAwareTextEditor.CancelFepInlineEdit();
iInsideInlineEditingTransaction = EFalse;
}

void CExampleFepControl::CommitInlineEditL(MCoeFepAwareTextEditor& aFepAwareTextEditor,
TBool aCursorVisibility)
{
aFepAwareTextEditor.SetInlineEditingCursorVisibilityL(aCursorVisibility);
iInsideInlineEditingTransaction = EFalse;
aFepAwareTextEditor.CommitFepInlineEditL(*iCoeEnv);
aFepAwareTextEditor.GetCursorSelectionForFep(iUncommittedText);
}

void CExampleFepControl::GetFormatOfFepInlineText(TCharFormat& /*aFormat*/, TInt& /*aNumberOfCharactersWithSameFormat*/, TInt /*aPositionOfCharacter*/) const
{

}

void CExampleFepControl::HandlePointerEventInInlineTextL(TPointerEvent::TType /*aType*/,
TUint /*aModifiers*/, TInt /*aPositionInInlineText*/)
{

}

TKeyResponse CExampleFepControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aEventCode)
{
if (iFep.IsSimulatingKeyEvent())
{
return EKeyWasNotConsumed;
}
if (!iFep.IsOn() || iInputCapabilities.IsNone())
{
return EKeyWasNotConsumed;
}

if (aEventCode != EEventKey)
return EKeyWasNotConsumed;

return EKeyWasNotConsumed;
}

void CExampleFepControl::HandlePointerBufferReadyL()
{
CEikonEnv::Static()->InfoMsg(_L("HandlePointerBufferReadyL"));
TPoint pnts[256];
TPtr8 ptr((TUint8 *)&pnts,sizeof(pnts));
TInt numPnts=Window().RetrievePointerMoveBuffer(ptr);

TSize penSize;
penSize.SetSize(3,3);

CWindowGc& gc=SystemGc();
gc.SetPenSize(penSize);

for(TInt index=0;index{
gc.DrawLineTo(pnts[index]);
}

}

void CExampleFepControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
switch (aPointerEvent.iType)
{
case TPointerEvent::EButton1Down:
{
DrawableWindow()->EnablePointerMoveBuffer();
break;
}
case TPointerEvent::EButton1Up:
{
DrawableWindow()->DisablePointerMoveBuffer();
break;
}
default:
break;
}
}

void CExampleFepControl::HandleGainingForeground()
{
DrawableWindow()->MoveToGroup(iCoeEnv->WsSession().GetFocusWindowGroup());
MakeVisible(EFalse);
}

void CExampleFepControl::HandleLosingForeground()
{

}

void CExampleFepControl::HandleChangeInFocus()
{
// Get the newly focused control capability
iInputCapabilities = STATIC_CAST(const CCoeAppUi*, iCoeEnv->AppUi())->InputCapabilities();

// check & process the current capability underneath
if (iInputCapabilities.IsNone()) {
return ;
}
else {
ActivateL();
CEikonEnv::Static()->InfoMsg(_L("Text Input"));
}
}

运行时,point event 不能进入 HandlePointerEventL() 和 HandlePointerBufferReadyL() 。

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.