widgetmodel/alfwidgetmodel/src/alfeventoutput.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     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 output events, including custom events.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <alf/alfevent.h>
       
    20 #include <alf/alfcommand.h>
       
    21 #include <alf/alfenv.h>
       
    22 #include <osn/ustring.h>
       
    23 
       
    24 #include <alf/alfwidgetcontrol.h>
       
    25 #include "alf/alfreferencetovisual.h"
       
    26 #include <alf/alfvarianttype.h>
       
    27 #include "alf/alfwidget.h"
       
    28 #include <alf/alfexceptions.h>
       
    29 #include "alf/alfattribute.h"
       
    30 #include "alf/alfattributevaluetype.h"
       
    31 #include "alf/ialfattributeowner.h"
       
    32 #include <alf/alfeventoutputsignalsubscriber.h>
       
    33 #include <alf/ialfappeventlistener.h>
       
    34 #include <alf/alfwidgetcommand.h>
       
    35 #include <alf/alfwidgetenvextension.h>
       
    36 #include <alf/ialfwidgetfactory.h>
       
    37 
       
    38 #include "alfeventoutput.h"
       
    39 
       
    40 namespace Alf
       
    41     {
       
    42 
       
    43 // ======== LOCAL FUNCTIONS ========
       
    44 
       
    45 void DeleteIAlfVariantType( TAny* aParam )
       
    46     {
       
    47     IAlfVariantType* ptr = static_cast<IAlfVariantType*>( aParam );
       
    48     delete ptr;
       
    49     }
       
    50 
       
    51 // ======== MEMBER FUNCTIONS ========
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Class AlfEventOutput
       
    55 // ---------------------------------------------------------------------------
       
    56 //
       
    57 AlfEventOutput::AlfEventOutput(
       
    58     int aEventType, int aEventID, const char* aTargetWidget, unsigned int aDelay )
       
    59     {
       
    60     if ( aEventType != TAlfEvent::ETypeCustom &&
       
    61             aEventType != TAlfEvent::ETypeKey )
       
    62         {
       
    63         ALF_THROW(AlfVisualException,EInvalidAttribute,"AlfEventOutput")
       
    64         }
       
    65 
       
    66     // Key event outputs must have a target widget.
       
    67     if ( aEventType == TAlfEvent::ETypeKey &&
       
    68             !UString(aTargetWidget).compare(UString("")) )
       
    69         {
       
    70         ALF_THROW(AlfVisualException,EInvalidAttribute,"AlfEventOutput")
       
    71         }
       
    72 
       
    73     mEventType = aEventType;
       
    74     mEventID = aEventID;
       
    75     mTargetWidget = UString(aTargetWidget);
       
    76 
       
    77     mDelay = aDelay;
       
    78     }
       
    79 AlfEventOutput::AlfEventOutput()
       
    80     {
       
    81     }
       
    82 
       
    83 AlfEventOutput::~AlfEventOutput()
       
    84     {
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // ?implementation_description
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void AlfEventOutput::execute( const CAlfWidgetControl& aControl, const TAlfEvent& aEvent )
       
    92     {
       
    93     CAlfEnv& env = aControl.Env();
       
    94     CAlfWidgetControl* controller = NULL;
       
    95 
       
    96     if ( mTargetWidget.compare( UString("") ) )
       
    97         {
       
    98         IAlfWidget* widget = AlfWidgetEnvExtension::widgetFactory(env).findWidget( mTargetWidget.getUtf8() );
       
    99 
       
   100         if ( !widget )
       
   101             {
       
   102             ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfEventOutput")
       
   103             }
       
   104         controller = widget->control();
       
   105         }
       
   106 
       
   107     if ( mEventType == TAlfEvent::ETypeCustom )
       
   108         {
       
   109         // control is NULL if the event is to be broadcast
       
   110 
       
   111         TAlfCustomEventCommand command( mEventID, controller, aEvent.CustomEventData() );
       
   112         env.Send( command, mDelay );
       
   113         }
       
   114     else if ( mEventType == TAlfEvent::ETypeKey && controller )
       
   115         {
       
   116         // Simulate a key event with a given event ID as scan code.
       
   117         
       
   118         TKeyEvent key =
       
   119             {
       
   120             0,          // iCode
       
   121             mEventID,   // iScanCode
       
   122             0,          // iModifiers
       
   123             0           // iRepeats
       
   124             };
       
   125 
       
   126         TAlfEvent event( *controller->Display(), key, EEventKey );
       
   127         controller->processEvent( event );
       
   128         }
       
   129     }
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // Class AlfEventCancelOutput
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 AlfEventCancelOutput::AlfEventCancelOutput(
       
   136     const char* aTargetWidget, int aEventID, bool aCancelAll )
       
   137     {
       
   138     mTargetWidget = UString(aTargetWidget);
       
   139     mEventID = aEventID;
       
   140     mCancelAll = aCancelAll;
       
   141     }
       
   142 
       
   143 AlfEventCancelOutput::AlfEventCancelOutput()
       
   144     {
       
   145     }
       
   146 
       
   147 AlfEventCancelOutput::~AlfEventCancelOutput()
       
   148     {
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // ?implementation_description
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void AlfEventCancelOutput::execute( const CAlfWidgetControl& aControl )
       
   156     {
       
   157     // This cancels either all or specified command in the given
       
   158     // target control.
       
   159     
       
   160     CAlfEnv& env = aControl.Env();
       
   161 
       
   162     IAlfWidget* widget = AlfWidgetEnvExtension::widgetFactory(env).findWidget( mTargetWidget.getUtf8() );
       
   163 
       
   164     if ( !widget )
       
   165         {
       
   166         ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfEventCancelOutput")
       
   167         }
       
   168 
       
   169     CAlfControl* controller = widget->control();
       
   170 
       
   171     if ( mCancelAll )
       
   172         {
       
   173         env.CancelCustomCommands( controller );
       
   174         }
       
   175     else
       
   176         {
       
   177         env.CancelCustomCommands( controller, mEventID );
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Class AlfAnimationCancelOutput
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 AlfAnimationCancelOutput::AlfAnimationCancelOutput(
       
   186     const char* aElementName,
       
   187     const char* aVisualName,
       
   188     TAlfOp aOperation,
       
   189     bool aCancelAll )
       
   190     {
       
   191     mVisualRef.reset(AlfReferenceToVisual::create( aElementName, aVisualName, true ));
       
   192 
       
   193     mOperation = aOperation;
       
   194     mCancelAll = aCancelAll;
       
   195     }
       
   196 
       
   197 AlfAnimationCancelOutput::AlfAnimationCancelOutput()
       
   198     {
       
   199     }
       
   200 
       
   201 AlfAnimationCancelOutput::~AlfAnimationCancelOutput()
       
   202     {
       
   203     }
       
   204 // ---------------------------------------------------------------------------
       
   205 // ?implementation_description
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void AlfAnimationCancelOutput::execute(
       
   209     CAlfWidgetControl& aControl, int aDataID )
       
   210     {
       
   211     CAlfEnv& env = aControl.Env();
       
   212     CAlfVisual* visual=NULL;
       
   213 
       
   214     visual = mVisualRef->resolve( aControl, aDataID );
       
   215 
       
   216     if ( visual )
       
   217         {
       
   218         if ( mCancelAll )
       
   219             {
       
   220             env.CancelCommands( visual );
       
   221             }
       
   222         else
       
   223             {
       
   224             env.CancelCommands( visual, mOperation );
       
   225             }
       
   226         }
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // Class AlfWidgetAttributeOuptut
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 AlfWidgetAttributeOutput::AlfWidgetAttributeOutput( AlfAttribute& aAttribute,
       
   234     const char* aWidgetId )
       
   235     {
       
   236     mAttr = &aAttribute;
       
   237     mWidgetId = "";
       
   238     if (aWidgetId)   
       
   239         {
       
   240         mWidgetId = aWidgetId;
       
   241         }
       
   242     }
       
   243 
       
   244 AlfWidgetAttributeOutput::AlfWidgetAttributeOutput()
       
   245     {
       
   246     }
       
   247 
       
   248 AlfWidgetAttributeOutput::~AlfWidgetAttributeOutput()
       
   249     {
       
   250     delete mAttr;
       
   251     }
       
   252 
       
   253 void AlfWidgetAttributeOutput::execute( CAlfWidgetControl& aControl )
       
   254     {
       
   255     AlfWidget* widget = aControl.widget();
       
   256     
       
   257     IAlfAttributeOwner* owner = 0;
       
   258     if (mWidgetId.isEmpty())
       
   259         {
       
   260         owner = IAlfInterfaceBase::makeInterface<IAlfAttributeOwner>(widget);
       
   261         }
       
   262     else
       
   263         {
       
   264         IAlfWidget* widget1 = AlfWidgetEnvExtension::widgetFactory(aControl.Env()).findWidget(mWidgetId.getUtf8());
       
   265         owner = IAlfInterfaceBase::makeInterface<IAlfAttributeOwner>(widget1);
       
   266         }
       
   267 
       
   268     if ( owner )
       
   269         {        
       
   270         owner->setAttribute( *mAttr );
       
   271         UString target;
       
   272         TAlfWidgetAttributeCommand command( mAttr, target, widget );
       
   273         CAlfEnv& env = aControl.Env();
       
   274         env.Send( command, 0);
       
   275         command.mOwnedAttribute = NULL;
       
   276         }
       
   277     }
       
   278 
       
   279 
       
   280 #ifdef RD_TACTILE_FEEDBACK
       
   281 // ---------------------------------------------------------------------------
       
   282 // Class AlfWidgetTactileOutput
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 AlfTactileOutput::AlfTactileOutput( TTouchLogicalFeedback aFeedbackType )
       
   286     {
       
   287     mFeedbackType = aFeedbackType;
       
   288     }
       
   289 
       
   290 AlfTactileOutput::AlfTactileOutput()
       
   291     {
       
   292     }
       
   293 
       
   294 AlfTactileOutput::~AlfTactileOutput()
       
   295     {
       
   296     }
       
   297 
       
   298 void AlfTactileOutput::execute()
       
   299     {
       
   300     MTouchFeedback* feedback = MTouchFeedback::Instance();
       
   301     if ( feedback )
       
   302         {
       
   303         feedback->InstantFeedback( mFeedbackType );
       
   304         }
       
   305     }
       
   306 
       
   307 #endif // RD_TACTILE_FEEDBACK
       
   308 
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // Class AlfEventOutputSignal
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 AlfEventOutputSignal::AlfEventOutputSignal( 
       
   315 	IAlfEventOutputSignalSubscriber& aSubscriber )
       
   316 	: mSubscriber(&aSubscriber)
       
   317     {}
       
   318 
       
   319 AlfEventOutputSignal::~AlfEventOutputSignal()
       
   320     {
       
   321     delete mSubscriber;
       
   322     }
       
   323 
       
   324 void AlfEventOutputSignal::execute()
       
   325     {
       
   326     mSubscriber->receiveSignal();
       
   327     }
       
   328 
       
   329 // ---------------------------------------------------------------------------
       
   330 // Class AlfStateChangeOutput
       
   331 // ---------------------------------------------------------------------------
       
   332 //
       
   333 AlfStateChangeOutput::AlfStateChangeOutput(
       
   334     const char* aTargetWidget, uint aEnableStates, uint aDisableStates ):
       
   335     mTargetWidget(aTargetWidget),
       
   336     mEnableStates(aEnableStates),
       
   337     mDisableStates(aDisableStates)
       
   338     {
       
   339 
       
   340     // State change events output must have a target widget.
       
   341     if ( !aTargetWidget || aTargetWidget[0] == 0 )
       
   342         {
       
   343         ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfStateChangeOutput")
       
   344         }
       
   345 
       
   346     // State change events must not have ambiguous overlapping bits
       
   347     if ( mEnableStates & mDisableStates  )
       
   348         {
       
   349         ALF_THROW(AlfWidgetException,EInvalidArgument,"AlfStateChangeOutput")
       
   350         }
       
   351 
       
   352     }
       
   353 
       
   354 AlfStateChangeOutput::~AlfStateChangeOutput()
       
   355     {
       
   356     }
       
   357 
       
   358 // ---------------------------------------------------------------------------
       
   359 // ?implementation_description
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void AlfStateChangeOutput::execute( const CAlfWidgetControl& aControl)
       
   363     {
       
   364     CAlfEnv& env = aControl.Env();
       
   365 
       
   366     if ( mTargetWidget.compare( UString("") ) )
       
   367         {
       
   368         IAlfWidget* widget = AlfWidgetEnvExtension::widgetFactory(env).findWidget( mTargetWidget.getUtf8() );
       
   369 
       
   370         if ( !widget )
       
   371             {
       
   372             ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfStateChangeOutput")
       
   373             }
       
   374         CAlfWidgetControl* target = widget->control();
       
   375         target->enableState( mEnableStates);
       
   376         target->disableState(mDisableStates);
       
   377         }
       
   378     }
       
   379 
       
   380 // ---------------------------------------------------------------------------
       
   381 // Class AlfEventPasserOutput
       
   382 // ---------------------------------------------------------------------------
       
   383 //
       
   384 AlfEventPasserOutput::AlfEventPasserOutput( const char* aSourceWidget, const char* aTargetWidget ):
       
   385     mSourceWidget(aSourceWidget),
       
   386     mTargetWidget(aTargetWidget)                     
       
   387     {
       
   388     
       
   389     mEventMappingData = false;
       
   390     
       
   391     // Event passer events output must have a target widget.
       
   392     if ( !mTargetWidget )
       
   393         {
       
   394         ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfEventPasserOutput")
       
   395         }
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------------------------
       
   399 // Class AlfEventPasserOutput
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 AlfEventPasserOutput::AlfEventPasserOutput( const char* aSourceWidget , const char* aTargetWidget, 
       
   403                                             int aNewEventId , int aNewEventCustomData ):
       
   404     mSourceWidget(aSourceWidget),
       
   405     mTargetWidget(aTargetWidget),
       
   406     mNewEventId(aNewEventId),
       
   407     mNewEventCustomData(aNewEventCustomData)                     
       
   408     {
       
   409     
       
   410     mEventMappingData = true;
       
   411     // Event passer events output must have a target widget.
       
   412     if ( !mTargetWidget )
       
   413         {
       
   414         ALF_THROW(AlfWidgetException,EInvalidWidget,"AlfEventPasserOutput")
       
   415         }
       
   416     }
       
   417 
       
   418 AlfEventPasserOutput::AlfEventPasserOutput()
       
   419     {
       
   420     }
       
   421 
       
   422 AlfEventPasserOutput::~AlfEventPasserOutput()
       
   423     {
       
   424     }
       
   425 
       
   426 void AlfEventPasserOutput::execute( const CAlfWidgetControl* aControl , const TAlfEvent& aEvent )
       
   427     {
       
   428     if(mTargetWidget)
       
   429         {
       
   430         IAlfWidget* wdgt = AlfWidgetEnvExtension::widgetFactory(aControl->Env()).findWidget(mTargetWidget);
       
   431         //const char* wname = wdgt->widgetName(); //for debugging purposes
       
   432         // if widget is not found, ignore...
       
   433         if( wdgt  )
       
   434             {
       
   435             if(!mEventMappingData)
       
   436                 {
       
   437                 //pass to widgets control. The event handler that handles the event
       
   438                 //is found from the target widgets controls event handler list.
       
   439                 wdgt->control()->processEvent(aEvent);     
       
   440                 }
       
   441             else
       
   442                 {
       
   443                 //map event to other type of event. Use user set event ids and custom data.
       
   444                 wdgt->control()->processEvent(TAlfEvent(mNewEventId , mNewEventCustomData));      
       
   445                 }
       
   446             }
       
   447 
       
   448         }
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // Class AlfAppEventOutput
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 AlfAppEventOutput::AlfAppEventOutput( const UString& aCmd, IAlfAppEventListener& aAppEvent ):
       
   456     mAppEvent(&aAppEvent),
       
   457     mCmd(aCmd)
       
   458     {
       
   459     }
       
   460 
       
   461 AlfAppEventOutput::~AlfAppEventOutput()
       
   462     {
       
   463     }
       
   464 
       
   465 void AlfAppEventOutput::execute(const TAlfEvent& aEvent)
       
   466     {
       
   467     mAppEvent->handleApplicationEvent(mCmd, aEvent);
       
   468     }
       
   469 
       
   470     
       
   471     } // namespace Alf
       
   472         
       
   473 // End of File.