help me please ! Problem with "OfferkeyEventL". Thanks very much !

Login to reply to this topic.
Wed, 2005-10-12 08:22
Joined: 2005-06-21
Forum posts: 107
Hi all !
In my example,I want to change DX , DY values when user press any key . I use "OfferkeyEventL" funcution for catching event but It didn't happen . Please help me ! What error I have ! Thanks very much !

------------------------------------------------- My code -----------------------------------------------------

#include "MultiviewAppUi.h"
#include "View01View.h"

void CMultiviewAppUi::ConstructL()
{
    CEikAppUi::ConstructL();
    iView01 = CView01::NewL(ApplicationRect());
    RegisterViewL(*iView01);
    AddToStackL(*iView01,iView01);
    SetDefaultViewL(*iView01);
}


#include "View01View.h"
#include "Multiview.hrh"
#include "Multiview.rsg"

CView01* CView01::NewL(const TRect& aRect)
{
    CView01* self = CView01::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

CView01* CView01::NewLC(const TRect& aRect)
{
    CView01* self = new( ELeave ) CView01();
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

CView01::CView01()
{
}

CView01::~CView01()
{
}

void CView01::ConstructL(const TRect& aRect)
{
    iRect=aRect;
    DX=100;
    DY=100;
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
}

TVwsViewId CView01::ViewId() const
{
   return TVwsViewId( KUidQBasicApp,ViewUid() );
}

TUid CView01::ViewUid() const
{
     return iView01ID;
}

void CView01::Draw(const TRect& aRect) const
{
     CWindowGc& gc = SystemGc();
     TRect rect = Rect();
     gc.Clear();
     gc.SetPenColor( 0x3FEE50 );
     gc.SetBrushColor( 0x3FEE50 );
     gc.DrawRect( TRect( 10,10,DX,DY ) );
}

void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
      TUid aCustomMessageId, const TDesC8& aCustomMessage)
{

}

void CView01::ViewDeactivated()
{
    MakeVisible(EFalse);
}

TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if(aType != EEventKey)
    {
        return EKeyWasNotConsumed;
    }
    switch(aKeyEvent.iScanCode)
    {
        //----- case user presskey next
        case 15:
        case 165:
        {
            DX=200;
            DY=200;
        } break;
    }
}

-------------------------------------------------  doctinh113114  -----------------------------------------------------------

Wed, 2005-10-12 08:29
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Have you put your view on the stack?

pirosl

Wed, 2005-10-12 08:34
Joined: 2005-07-16
Forum posts: 127
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hello,

I guess the 15 and 165 are the right TStdScanCode. In the following code all the controll does not return. Check it.

TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if(aType != EEventKey)
    {
        return EKeyWasNotConsumed;
    }
    switch(aKeyEvent.iScanCode)
    {
        //----- case user presskey next
        case 15:
        case 165:
        {
            DX=200;
            DY=200;
        } break;
    }

    return EKeyWasConsumed;
}
Wed, 2005-10-12 08:50
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
I'm using SDK UIQ 2.1.
----------------------------------------
RegisterViewL(*iView01);
AddToStackL(*iView01,iView01);
----------------------------------------------
Is this code to add iView01 object to stack right or wrong ? I  didn't know ! Please help me ! How can I add iView01 to stack please ! Thanks very much !

Wed, 2005-10-12 09:01
Joined: 2005-07-16
Forum posts: 127
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi,

I am not familiar with UIQ development. But I guess the method call for view should be:

RegisterViewL(iView01);
AddToStackL(iView01);

Regards,
shagor
Wed, 2005-10-12 09:14
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
Thanks very much ! But It didn't work . please help me !
Wed, 2005-10-12 09:35
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
It should be AddToStackL(*iView, iController), or?

pirosl

Wed, 2005-10-12 09:47
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
My code :

----------------------------------------------------------
    CEikAppUi::ConstructL();
    iView01 = CView01::NewL(ApplicationRect());
    RegisterViewL(*iView01);
    AddToStackL(*iView01,iView01);  // = AddToStackL(*iView, iController)
    SetDefaultViewL(*iView01);
-------------------------------------------------

But I can't catch keypress event by OfferkeyEvent . Please help me to correct it ! Please share me some me code or example .Thanks very much!
Wed, 2005-10-12 09:57
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Can you show the ConstructL method of your view?

Also your code
CEikAppUi::ConstructL();
    iView01 = CView01::NewL(ApplicationRect());
    AddToStackL(*iView01,iView01);
    RegisterViewL(*iView01);
    SetDefaultViewL(*iView01);

is taken from appui rigth?. It's perfectly valid

pirosl

Wed, 2005-10-12 10:08
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
Yes, I get it from  ...AppUi  class ! This is my full code . Help me to correct it please ! Thanks very much ! Please help me Thanks!

------------------------------------------------- My code -----------------------------------------------------

#include "MultiviewAppUi.h"
#include "View01View.h"

void CMultiviewAppUi::ConstructL()
{
    CEikAppUi::ConstructL();
    iView01 = CView01::NewL(ApplicationRect());
    RegisterViewL(*iView01);
    AddToStackL(*iView01,iView01);
    SetDefaultViewL(*iView01);
}


#include "View01View.h"
#include "Multiview.hrh"
#include "Multiview.rsg"

CView01* CView01::NewL(const TRect& aRect)
{
    CView01* self = CView01::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
}

CView01* CView01::NewLC(const TRect& aRect)
{
    CView01* self = new( ELeave ) CView01();
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
}

CView01::CView01()
{
}

CView01::~CView01()
{
}

void CView01::ConstructL(const TRect& aRect)
{
    iRect=aRect;
    DX=100;
    DY=100;
    CreateWindowL();
    SetRect(aRect);
    ActivateL();
}

TVwsViewId CView01::ViewId() const
{
   return TVwsViewId( KUidQBasicApp,ViewUid() );
}

TUid CView01::ViewUid() const
{
     return iView01ID;
}

void CView01::Draw(const TRect& aRect) const
{
     CWindowGc& gc = SystemGc();
     TRect rect = Rect();
     gc.Clear();
     gc.SetPenColor( 0x3FEE50 );
     gc.SetBrushColor( 0x3FEE50 );
     gc.DrawRect( TRect( 10,10,DX,DY ) );
}

void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
      TUid aCustomMessageId, const TDesC8& aCustomMessage)
{

}

void CView01::ViewDeactivated()
{
    MakeVisible(EFalse);
}

TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if(aType != EEventKey)
    {
        return EKeyWasNotConsumed;
    }
    switch(aKeyEvent.iScanCode)
    {
        //----- case user presskey next
        case 15:
        case 165:
        {
            DX=200;
            DY=200;
        } break;
    }
}


Wed, 2005-10-12 10:33
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
In
void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
      TUid aCustomMessageId, const TDesC8& aCustomMessage)
{

}

make
void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
      TUid aCustomMessageId, const TDesC8& aCustomMessage)
{
ActivateL();
MakeVisible( ETrue);
}

pirosl

Wed, 2005-10-12 10:47
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
I thanks very much ! I correct my code the same above but It didn't work ! Please help me again ! Thanks !
Wed, 2005-10-12 11:06
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
One question...have you debuged the code and saw that OfferkeyEventL is not called or simply you don't see the DX, DY values changed?


pirosl

Wed, 2005-10-12 11:15
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
I change rectangle on OfferKeyEvent but It didn't work .Please help me again ! Thanks very much

-----------------------------------------------
switch(aKeyEvent.iScanCode)
    {
        //----- case user presskey next
        case 15:
        case 165:
        {
            //DX=200;
            //DY=200;
            CWindowGc& gc = SystemGc();
            TRect rect = Rect();
            gc.Clear();
            gc.SetPenColor( 0x3FEE50 );
            gc.SetBrushColor( 0x3FEE50 );
            gc.DrawRect( TRect( 10,10,200,200 ) );
        } break;
-----------------------------------------------------------------------------------------
Wed, 2005-10-12 11:57
Joined: 2004-05-24
Forum posts: 982
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
What i'm asking is that are 100% sure your OfferkeyEventL is not called? Have you made some debugs with some breakpoints OfferkeyEventL and saw it's not called?

May be the function is called but your aKeyEvent.iScanCode are not the rigth ones.

Try to put smth outside the switch if you can't make a debug

pirosl

Thu, 2005-10-13 02:09
Joined: 2005-06-21
Forum posts: 107
Re: help me please ! Problem with "OfferkeyEventL". Thanks very
Hi !
I think "offerkeyeventL" is not called the same to you . Because I put this code for changing width and height of rectangle out of  "switch" function but "offerkeyevent" doesn't do .

-------------------------------------------------
TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
    if(aType != EEventKey)
    {
        return EKeyWasNotConsumed;
    }
 
    CWindowGc& gc = SystemGc();
    TRect rect = Rect();
    gc.Clear();
    gc.SetPenColor( 0x3FEE50 );
    gc.SetBrushColor( 0x3FEE50 );
    gc.DrawRect( TRect( 10,10,100,100 ) );
 
    return EKeyWasConsumed;

}
----------------------------------------------------------------------
Please help me again ! Thanks very much !
  • Login to reply to this topic.