widgetmodel/alfwidgetmodel/src/alfeventinput.cpp
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     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:   File Implements the various input events, including custom events.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <alf/alfenv.h>
       
    20 #include <alf/alfevent.h>
       
    21 #include <alf/alfvisual.h>
       
    22 #include <osn/osncommon.h>
       
    23 #include "alf/alfreferencetovisual.h"
       
    24 #include <alf/alfexceptions.h>
       
    25 #include "alf/alfattribute.h"
       
    26 #include "alf/alfwidget.h"
       
    27 #include "alf/ialfattributeowner.h"
       
    28 #include <alf/alfwidgetevents.h>
       
    29 #include <alf/alfwidgetcommand.h>
       
    30 #include "alfeventinput.h"
       
    31 
       
    32 namespace Alf
       
    33     {
       
    34 
       
    35 
       
    36 // ======== LOCAL FUNCTIONS ========
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 AlfEventInput::AlfEventInput(int aEvtTypeFlags,int aEventID,int aEventData, int aKeyEventModifiers)
       
    41     {
       
    42     mEventTypeFlags = aEvtTypeFlags;
       
    43     mEventID = aEventID;
       
    44     mEventData = aEventData;
       
    45     mKeyEventModifiers = aKeyEventModifiers;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // ?implementation_description
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 bool AlfEventInput::accept( const TAlfEvent& aEvent ) const
       
    53     {
       
    54     bool ret = false;
       
    55 
       
    56 	// Custom event
       
    57     if ( aEvent.Type() == TAlfEvent::ETypeCustom &&
       
    58             ( mEventTypeFlags & custom ) &&
       
    59             aEvent.CustomParameter() == mEventID )
       
    60         {
       
    61         // If event data is defined to be used, it must match also
       
    62         if ( ( mEventTypeFlags & useEventData ) == 0 ||
       
    63                 aEvent.CustomEventData() == mEventData )
       
    64             {
       
    65             ret = true;
       
    66             }
       
    67         }
       
    68     // Key event
       
    69     else if( aEvent.Type() == TAlfEvent::ETypeKey &&
       
    70               ( mEventTypeFlags & custom ) == 0 &&
       
    71     		   aEvent.KeyEvent().iScanCode == mEventID )
       
    72         {
       
    73         // Test that key event up/down matches
       
    74         
       
    75         // keyDown triggers from EEventKey event.
       
    76         // keyUp triggers from EEventKeyUp event.
       
    77         
       
    78         if ( ( mEventTypeFlags & keyDown &&
       
    79                aEvent.Code() == EEventKey ) ||
       
    80              ( mEventTypeFlags & keyUp &&
       
    81                aEvent.Code() == EEventKeyUp ) )
       
    82         	{
       
    83         	// Set trigger status true first, match checks will change it to false if no match.
       
    84         	ret = true;
       
    85 
       
    86             // If no modifiers requested, no need to check anything
       
    87             if ( mKeyEventModifiers )
       
    88                 {                
       
    89             	uint receivedModifiers = aEvent.KeyEvent().iModifiers;
       
    90             	
       
    91             	while ( true )
       
    92             	    {
       
    93                 	if ( mKeyEventModifiers & alt )
       
    94                 	    {
       
    95             	        if ( !(receivedModifiers & (eventBitLeftAlt|eventBitRightAlt|eventBitAlt)) )
       
    96             	            {
       
    97             	            ret = false;
       
    98             	            break;
       
    99             	            }
       
   100                	        }
       
   101                 	if ( mKeyEventModifiers & ctrl )
       
   102             	        {
       
   103             	        if ( !(receivedModifiers & (eventBitLeftCtrl|eventBitRightCtrl|eventBitCtrl)) )
       
   104             	            {
       
   105             	            ret = false;
       
   106             	            break;
       
   107             	            }        	        
       
   108             	        }
       
   109                 	if ( mKeyEventModifiers & shift )
       
   110                 	    {
       
   111             	        if ( !(receivedModifiers & (eventBitLeftShift|eventBitRightShift|eventBitShift)) )
       
   112             	            {
       
   113                 	        ret = false;
       
   114                 	        break;
       
   115                 	        }        	        
       
   116                 	    }
       
   117                 	if ( mKeyEventModifiers & func )
       
   118                 	    {
       
   119             	        if ( !(receivedModifiers & (eventBitLeftFunc|eventBitRightFunc|eventBitFunc)) )
       
   120             	            {
       
   121                 	        ret = false;
       
   122                 	        break;
       
   123                 	        }        	    
       
   124                 	    }
       
   125                 	    
       
   126                 	break;
       
   127             	    }
       
   128                 	    
       
   129                	if ( mKeyEventModifiers & capsLock && !(receivedModifiers & eventBitCapsLock) )
       
   130                	    {
       
   131                	    ret = false;
       
   132                	    }
       
   133                	    
       
   134                	if ( mKeyEventModifiers & numLock && !(receivedModifiers & eventBitNumLock) )
       
   135                	    {
       
   136                	    ret = false;
       
   137                	    }
       
   138                	    
       
   139                	if ( mKeyEventModifiers & scrollLock && !(receivedModifiers & eventBitScrollLock) )
       
   140                	    {
       
   141                	    ret = false;
       
   142                	    }
       
   143                 }
       
   144         	}
       
   145         }
       
   146 
       
   147     return ret;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // ?description_if_needed
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 AlfPointerEventInput::AlfPointerEventInput()
       
   155     {
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // ?description_if_needed
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 AlfPointerEventInput::AlfPointerEventInput( const char* aElementName, 
       
   163                                             const char* aVisualName,
       
   164                                             WidgetPointerEvent aEvent )
       
   165     {
       
   166     mVisualRef.reset(AlfReferenceToVisual::create(aElementName, aVisualName, true ));
       
   167     mEvent = aEvent;
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // ?description_if_needed
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 AlfPointerEventInput::~AlfPointerEventInput()
       
   175     {
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // ?implementation_description
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 bool AlfPointerEventInput::accept(
       
   183     CAlfWidgetControl& aControl, const TAlfEvent& aEvent ) const
       
   184     {
       
   185     // Check whether the tapped visual matches with element and visual names
       
   186     // of this pointer event input.
       
   187     bool ret = false;
       
   188 
       
   189     // map OSN pointer event to TPointerEvent::TType
       
   190     TPointerEvent::TType eventType = TPointerEvent::EButton1Down;
       
   191     switch (mEvent)
       
   192         {
       
   193         case pointerEventDown:
       
   194             eventType = TPointerEvent::EButton1Down;
       
   195             break;
       
   196         case pointerEventUp:
       
   197             eventType = TPointerEvent::EButton1Up;
       
   198             break;
       
   199         case pointerEventDrag:
       
   200             eventType = TPointerEvent::EDrag;
       
   201             break;
       
   202         default:
       
   203             break;
       
   204         }
       
   205     
       
   206     ret = aEvent.IsPointerEvent() && 
       
   207           (eventType == aEvent.PointerEvent().iType) && 
       
   208           mVisualRef->resolve( aControl, aEvent.Visual());
       
   209 
       
   210     return ret;
       
   211     }
       
   212 // ---------------------------------------------------------------------------
       
   213 // Class AlfWidgetAttributeInput
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 AlfWidgetAttributeInput::AlfWidgetAttributeInput( AlfAttribute& aAttribute,
       
   217 	    const char* aElementId )
       
   218 	    {
       
   219 	    mAttr = &aAttribute;
       
   220 	    mElementId = "";
       
   221 	    if (aElementId)   
       
   222 	        {
       
   223 	        mElementId = aElementId;
       
   224 	        }
       
   225 	    }
       
   226 
       
   227 AlfWidgetAttributeInput::AlfWidgetAttributeInput()
       
   228     {
       
   229     }
       
   230 
       
   231 AlfWidgetAttributeInput::~AlfWidgetAttributeInput()
       
   232     {
       
   233     delete mAttr;
       
   234     }
       
   235     
       
   236 bool AlfWidgetAttributeInput::accept(const TAlfEvent& aEvent) const
       
   237     {
       
   238     bool accept(false);
       
   239     
       
   240     if (aEvent.IsCustomEvent())
       
   241         {
       
   242         unsigned int eventID = aEvent.CustomParameter(); 
       
   243         if (eventID == EEventWidgetAttributeChanged)
       
   244             {
       
   245             TAlfWidgetAttributeCommand* command = 
       
   246                 (TAlfWidgetAttributeCommand*)aEvent.CustomEventData();
       
   247             AlfAttribute* attribute = command->mOwnedAttribute;
       
   248             const char* name = attribute->name();
       
   249             const char* targetelement = command->mTarget.getUtf8();
       
   250                         
       
   251             accept = true;
       
   252             if (!mElementId.isEmpty() && targetelement)
       
   253             	{
       
   254 	            if ( strcmp(mElementId.getUtf8(), targetelement) )
       
   255 	                {
       
   256 	                accept = false;
       
   257 	                }
       
   258             	}
       
   259             
       
   260             if (accept)
       
   261             	{
       
   262             	accept= false;
       
   263 	            if (!strcmp(mAttr->name(), name))
       
   264 	                {
       
   265 	                accept = true;
       
   266 	                }
       
   267             	}
       
   268             }
       
   269         }
       
   270     
       
   271     return accept;
       
   272     }    
       
   273 // ---------------------------------------------------------------------------
       
   274 // Class AlfEventPasserInput
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 // AlfEventInput could be used instead of this class, it contains all the same
       
   278 // functionality! 
       
   279 //
       
   280 AlfEventPasserInput::AlfEventPasserInput( int aEventId, int aEventData  )
       
   281     {
       
   282     mEventId = aEventId;
       
   283     mEventData = aEventData;//not used yet...
       
   284     }
       
   285 
       
   286 AlfEventPasserInput::AlfEventPasserInput()
       
   287     {
       
   288     }
       
   289 
       
   290 AlfEventPasserInput::~AlfEventPasserInput()
       
   291     {
       
   292     }
       
   293     
       
   294 bool AlfEventPasserInput::accept( const TAlfEvent& aEvent ) const
       
   295     {
       
   296     // check whether the event matches to the one we need to pass to another widget
       
   297 
       
   298     return aEvent.IsCustomEvent() &&
       
   299         aEvent.CustomParameter() == mEventId;    
       
   300     }    
       
   301         
       
   302     }//Alf
       
   303 
       
   304 // End of File.