textinput/peninputcommonctrls/src/peninputbuttons/peninputrawkeybutton.cpp
changeset 27 694fa80c203c
parent 24 fc42a86c98e3
child 35 0f326f2e628e
equal deleted inserted replaced
24:fc42a86c98e3 27:694fa80c203c
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 // system includes
       
    19 #include <barsread.h>
       
    20 #include <peninputlayout.h>
       
    21 #include <AknIconUtils.h>
       
    22 #include <coemain.h>
       
    23 #include <AknsUtils.h>
       
    24 // user includes
       
    25 #include <peninputrawkeybutton.h>
       
    26 #include <peninputcommonctrls.hrh>
       
    27 
       
    28 const TInt KInvalidEventId = 0xffff;
       
    29 // ======== MEMBER FUNCTIONS ========
       
    30 
       
    31 CAknFepCtrlRawKeyButton* CAknFepCtrlRawKeyButton::NewL(CFepUiLayout* aUiLayout, 
       
    32                                                        TInt aControlId, 
       
    33                                                        TInt aDownEvent,
       
    34                                                        TInt aUpEvent,
       
    35                                                        TInt aScanCode)
       
    36     { 
       
    37     CAknFepCtrlRawKeyButton* self = NewLC(aUiLayout, 
       
    38                                           aControlId, 
       
    39                                           aDownEvent, 
       
    40                                           aUpEvent,
       
    41                                           aScanCode);
       
    42     CleanupStack::Pop(self);
       
    43     
       
    44     return self;                        
       
    45     }
       
    46     
       
    47 CAknFepCtrlRawKeyButton* CAknFepCtrlRawKeyButton::NewLC(CFepUiLayout* aUiLayout, 
       
    48                                                         TInt aControlId, 
       
    49                                                         TInt aDownEvent,
       
    50                                                         TInt aUpEvent,
       
    51                                                         TInt aScanCode)
       
    52     { 
       
    53     CAknFepCtrlRawKeyButton* self = new (ELeave) CAknFepCtrlRawKeyButton(aUiLayout, 
       
    54                                                                          aControlId,
       
    55                                                                          aDownEvent,
       
    56                                                                          aUpEvent,
       
    57                                                                          aScanCode);
       
    58     CleanupStack::PushL(self);
       
    59     self->BaseConstructL();
       
    60     return self;                      
       
    61     }
       
    62 
       
    63 CAknFepCtrlRawKeyButton::CAknFepCtrlRawKeyButton(CFepUiLayout* aUiLayout, 
       
    64                                                  TInt aControlId, 
       
    65                                                  TInt aDownEvent,
       
    66                                                  TInt aUpEvent,
       
    67                                                  TInt aScanCode)
       
    68     : CAknFepCtrlButton(aUiLayout, aControlId),
       
    69       iDownEvent(aDownEvent),
       
    70       iUpEvent(aUpEvent),
       
    71       iScanCode(aScanCode)
       
    72     {        
       
    73     }
       
    74 
       
    75 CAknFepCtrlRawKeyButton::~CAknFepCtrlRawKeyButton()
       
    76     {
       
    77     }
       
    78 
       
    79 CFepUiBaseCtrl* CAknFepCtrlRawKeyButton::HandlePointerDownEventL(const TPoint& aPoint)
       
    80     {
       
    81     if (iDownEvent == KInvalidEventId)
       
    82         {
       
    83         return return CButtonBase::HandlePointerDownEventL(aPoint);
       
    84         }
       
    85     
       
    86     if(iDimmed)
       
    87         {
       
    88         return NULL;
       
    89         }
       
    90     
       
    91     CFepUiBaseCtrl::HandlePointerDownEventL(aPoint);
       
    92     if(IsActive())
       
    93         {
       
    94         SetBackgroundBmp(iActiveBmpPressed);
       
    95         SetBackgroundMaskBmp(iActiveMaskBmpPressed);
       
    96         }        
       
    97     else
       
    98         {
       
    99         SetBackgroundBmp(iNonActiveBkBmpPressed);
       
   100         SetBackgroundMaskBmp(iNonActiveBkMaskBmpPressed);
       
   101         }        
       
   102 
       
   103     Draw();
       
   104     UpdateArea(Rect(),EFalse);
       
   105 
       
   106 	TKeyEvent event= {0,0,0,0};
       
   107     TPtrC eventDataPtr;
       
   108     event.iScanCode = iScanCode;
       
   109     eventDataPtr.Set(reinterpret_cast<TUint16*>(&event),sizeof(event));
       
   110         
       
   111     ReportEvent(iDownEvent,eventDataPtr);
       
   112 
       
   113     return this;
       
   114     }
       
   115 
       
   116 CFepUiBaseCtrl* CAknFepCtrlRawKeyButton::HandlePointerUpEventL(const TPoint& aPoint)
       
   117     {
       
   118     if (iUpEvent == KInvalidEventId)
       
   119         {
       
   120         return CButtonBase::HandlePointerUpEventL(aPoint);
       
   121         }
       
   122     
       
   123     if(iDimmed)
       
   124         {
       
   125         return NULL;
       
   126         }
       
   127         
       
   128     if(IsActive())
       
   129         {
       
   130         SetBackgroundBmp(Bitmap(EBtnBmpActive,EFalse));
       
   131         SetBackgroundMaskBmp(Bitmap(EBtnBmpActive,ETrue));
       
   132         }
       
   133     else
       
   134         {
       
   135         SetBackgroundBmp(Bitmap(EBtnBmpNonActive,EFalse));
       
   136         SetBackgroundMaskBmp(Bitmap(EBtnBmpNonActive,ETrue));
       
   137         }
       
   138 
       
   139     SetActive(ETrue);
       
   140     Draw();
       
   141     UpdateArea(Rect(),EFalse);    
       
   142     
       
   143 	TKeyEvent event= {0,0,0,0};
       
   144     TPtrC eventDataPtr;
       
   145     event.iScanCode = iScanCode;
       
   146     eventDataPtr.Set(reinterpret_cast<TUint16*>(&event),sizeof(event));
       
   147 
       
   148     ReportEvent(iUpEvent,eventDataPtr);
       
   149 
       
   150     return this;
       
   151     }
       
   152 
       
   153 TInt CAknFepCtrlRawKeyButton::DownEvent() const
       
   154     {                           
       
   155     return iDownEvent;
       
   156     }
       
   157 
       
   158 TInt CAknFepCtrlRawKeyButton::UpEvent() const
       
   159     {                           
       
   160     return iUpEvent;
       
   161     }
       
   162 
       
   163 TInt CAknFepCtrlRawKeyButton::ScanCode() const
       
   164     {             
       
   165     return iScanCode;                                     
       
   166     }
       
   167 
       
   168 void CAknFepCtrlRawKeyButton::SetDownEvent(TInt aEvent)
       
   169     {               
       
   170     iDownEvent = aEvent;
       
   171     }
       
   172 
       
   173 void CAknFepCtrlRawKeyButton::SetUpEvent(TInt aEvent)
       
   174     {               
       
   175     iUpEvent = aEvent;
       
   176     }
       
   177 
       
   178 void CAknFepCtrlRawKeyButton::SetScanCode(TInt aScanCode)
       
   179     {                                                
       
   180     iScanCode = aScanCode;  
       
   181     }
       
   182     
       
   183 void CAknFepCtrlRawKeyButton::Draw()
       
   184     {
       
   185     CAknFepCtrlButton::Draw();
       
   186     }
       
   187     
       
   188    
       
   189 //  End Of File