textinput/peninputarc/src/peninputserverapp/peninputanimclientobj.cpp
changeset 0 eb1f2e154e89
child 6 6ceef9a83b1a
equal deleted inserted replaced
-1:000000000000 0:eb1f2e154e89
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Implementation for peninput server
       
    15 *
       
    16 */
       
    17 
       
    18 #include <coedef.h>
       
    19 #include "peninputanimclientobj.h"
       
    20 #include "peninputserver.h"
       
    21 #include "peninputclientserver.h"
       
    22 #include "peninputanimcommand.h"
       
    23 #include <coemain.h>
       
    24 // the animation dll name
       
    25 _LIT( KAnimDllName, "peninputanim.dll" );
       
    26 //animation window group name
       
    27 //_LIT(KPeninputServerAnimName,"peninputserveranimobj");
       
    28 class RWsSession;
       
    29 class RWindowGroup;
       
    30 
       
    31 void HideWindowGroupL(const RWsSession& aWs,const RWindowGroup& aGroup);
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CPeninputAnimObj::CPeninputAnimObj
       
    35 // Default constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 CPeninputAnimObj::CPeninputAnimObj(TSpriteMember& aSpriteMember)
       
    39                     : CActive( EPriorityStandard ),iSpriteMember(aSpriteMember)
       
    40     {
       
    41     iOnExiting = EFalse;
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CPeninputAnimObj::NewL
       
    46 // factory method
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CPeninputAnimObj* CPeninputAnimObj::NewL(TSpriteMember& aSpriteMember)
       
    50     {    
       
    51     CPeninputAnimObj* animObj = new(ELeave) CPeninputAnimObj(aSpriteMember);        
       
    52     CleanupStack::PushL(animObj);            
       
    53     CActiveScheduler::Add(animObj);
       
    54     animObj->ConstructL();
       
    55     CleanupStack::Pop(animObj);
       
    56     return animObj;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CPeninputAnimObj::~CPeninputAnimObj
       
    61 // Destructor
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 CPeninputAnimObj::~CPeninputAnimObj()
       
    65     {        
       
    66     Cancel();
       
    67     for(int i = 0 ; i < iAnimCmd.Count(); ++i)
       
    68     	{
       
    69     	const TAnimCmd* cmd = iAnimCmd[i];
       
    70     	delete cmd;
       
    71     	}
       
    72     iAnimCmd.Close();
       
    73     
       
    74     // closing the window server session frees all 
       
    75     // used resources in the ws session, including:
       
    76     //   iSprite
       
    77     //   iAnim
       
    78     //   iAnimDll
       
    79     iSprite.Close();
       
    80     iAnim.Close();
       
    81     iAnimDll.Close();            
       
    82     iWindowGroup.Close();
       
    83     iWsSession.Close();
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // CPeninputAnimObj::RunL
       
    88 // active ao call back
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CPeninputAnimObj::RunL()
       
    92     {
       
    93     ExecuteAnimCommand();
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CPeninputAnimObj::DoCancel
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 void CPeninputAnimObj::DoCancel()
       
   101     {
       
   102     //do nothing
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CPeninputAnimObj::RunError
       
   107 // ---------------------------------------------------------------------------
       
   108 //    
       
   109 TInt CPeninputAnimObj::RunError(TInt /*aErr*/)
       
   110     {
       
   111     //ignore error
       
   112     return KErrNone;
       
   113     }
       
   114     
       
   115 // ---------------------------------------------------------------------------
       
   116 // CPeninputAnimObj::ConstructL
       
   117 // 2nd phase constructor
       
   118 // ---------------------------------------------------------------------------
       
   119 //    
       
   120 void CPeninputAnimObj::ConstructL()
       
   121     {
       
   122     iAnimCmd.Reset();
       
   123     ConstructAnimL();    
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CPeninputAnimObj::ExecuteAnimCommand
       
   128 // Execute animation command
       
   129 // ---------------------------------------------------------------------------
       
   130 //        
       
   131 void CPeninputAnimObj::ExecuteAnimCommand()
       
   132     {    
       
   133     TInt i = 0;
       
   134     for(; i < iAnimCmd.Count(); ++i)
       
   135         {        
       
   136     	const TAnimCmd* cmd = iAnimCmd[i];        
       
   137         if(!cmd->ExecuteAnimCommand())
       
   138         	break; //execution not finished, need wait to next round. 
       
   139         delete cmd;        	
       
   140         }   
       
   141      
       
   142     //remove executed command
       
   143     while(--i >= 0)
       
   144     	{
       
   145     	iAnimCmd.Remove(i);
       
   146     	}
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CPeninputAnimObj::ExeOnePendingAnimCmd
       
   151 // Execute the first pending animation command
       
   152 // ---------------------------------------------------------------------------
       
   153 //        
       
   154 void CPeninputAnimObj::ExeOnePendingAnimCmd()
       
   155     {
       
   156     //search the first wait command
       
   157     for(TInt i = 0 ; i < iAnimCmd.Count(); i++)
       
   158         {
       
   159         if(!iAnimCmd[i]->Ready())
       
   160             {
       
   161             iAnimCmd[i]->SetReady(ETrue);
       
   162             //break;
       
   163             }
       
   164         }        
       
   165     //CompleteRequest();
       
   166     SetObjActive();
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // CPeninputAnimObj::AddAnimCommand
       
   171 // Add a animation command
       
   172 // ---------------------------------------------------------------------------
       
   173 //        
       
   174 void CPeninputAnimObj::AddAnimCommand(TAnimCmd* aCmd)
       
   175     {    
       
   176     if(iOnExiting) // do nothing if prepare for exiting
       
   177         {
       
   178         delete aCmd;
       
   179         aCmd = 0;    
       
   180         return;
       
   181         }
       
   182     iAnimCmd.Append(aCmd);
       
   183    
       
   184     //CompleteRequest();
       
   185     SetObjActive();
       
   186     }
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CPeninputAnimObj::SetObjActive
       
   190 // Set animation object active so as to be rescheduled by AO scheduler.
       
   191 // ---------------------------------------------------------------------------
       
   192 //        
       
   193 void CPeninputAnimObj::SetObjActive()
       
   194     {
       
   195     if(!IsActive())
       
   196         {
       
   197     	iStatus=KRequestPending;
       
   198     	SetActive();    	
       
   199     	TRequestStatus *pS=(&iStatus);
       
   200     	
       
   201         User::RequestComplete(pS,0);
       
   202     	}    
       
   203     }
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CPeninputAnimObj::ConstructSpriteAnimL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TInt CPeninputAnimObj::ConstructAnimL()
       
   211     {                
       
   212     User::LeaveIfError( iWsSession.Connect() );   
       
   213     iWindowGroup = RWindowGroup( iWsSession);
       
   214     iWindowGroup.Construct( RThread().Id(), EFalse );    
       
   215    
       
   216     iWindowGroup.SetOrdinalPosition( -1, -1);    
       
   217     iWindowGroup.SetOrdinalPriorityAdjust( ECoeWinPriorityAlwaysAtFront );
       
   218     iWindowGroup.EnableReceiptOfFocus( EFalse );
       
   219     iWindowGroup.AutoForeground(EFalse);
       
   220     
       
   221 	HideWindowGroupL(iWsSession,iWindowGroup);  
       
   222     TInt id = iWindowGroup.Identifier();    
       
   223     iSprite = RWsSprite( iWsSession);
       
   224     User::LeaveIfError( iSprite.Construct( iWindowGroup,
       
   225                                            TPoint( 0, 0 ),ESpriteNoChildClip | 
       
   226                                                             ESpriteNoShadows ) );
       
   227     // add sprite member
       
   228     User::LeaveIfError( iSprite.AppendMember( iSpriteMember ));
       
   229          
       
   230     // load peninput animation dll
       
   231     iAnimDll = RAnimDll( iWsSession );
       
   232     User::LeaveIfError( iAnimDll.Load( KAnimDllName ) );    
       
   233     
       
   234     // create peninput sprite animation class
       
   235     iAnim = RPeninputAnim( iAnimDll);
       
   236     iAnim.ConstructL( iSprite );    
       
   237     return KErrNone;
       
   238     }
       
   239 
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // CPeninputAnimObj::AddActivationCmd
       
   243 // Add activation command
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 TBool CPeninputAnimObj::AddActivationCmd(TBool aUiFlag, TBool aWaitFlag)
       
   247 	{
       
   248 	TAnimActivateUiCmd* cmd = new TAnimActivateUiCmd(iAnim,aUiFlag,!aWaitFlag);
       
   249 	if(!cmd)
       
   250 		return EFalse;
       
   251 	AddAnimCommand(cmd);
       
   252 	return ETrue;
       
   253 	}
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CPeninputAnimObj::AddChangeSizeCmd
       
   257 // Add changing size command
       
   258 // ---------------------------------------------------------------------------
       
   259 //	
       
   260 TBool CPeninputAnimObj::AddChangeSizeCmd(const TSize& aSize)
       
   261 	{
       
   262 	TAnimChangeSizeCmd* cmd = new TAnimChangeSizeCmd(iAnim,aSize);
       
   263 	if(!cmd)
       
   264 		return EFalse;
       
   265 	AddAnimCommand(cmd);
       
   266 	return ETrue;	
       
   267 	}
       
   268 	
       
   269 // ---------------------------------------------------------------------------
       
   270 // CPeninputAnimObj::AddSetPosCmd
       
   271 // Add setting position command
       
   272 // ---------------------------------------------------------------------------
       
   273 //	
       
   274 TBool CPeninputAnimObj::AddSetPosCmd(const TPoint& aPt)
       
   275 	{
       
   276 	TAnimSetPosCmd* cmd = new TAnimSetPosCmd(iAnim,aPt);
       
   277 	if(!cmd)
       
   278 		return EFalse;
       
   279 	AddAnimCommand(cmd);
       
   280 	return ETrue;
       
   281 	}
       
   282 	
       
   283 // ---------------------------------------------------------------------------
       
   284 // CPeninputAnimObj::AddChangeDispModeCmd
       
   285 // Add changing display mode command
       
   286 // ---------------------------------------------------------------------------
       
   287 //		
       
   288 TBool CPeninputAnimObj::AddChangeDispModeCmd(TSpriteMember& aMember)
       
   289 	{
       
   290     TAnimChangeDispModeCmd* cmd = new	TAnimChangeDispModeCmd(iAnim,
       
   291                                                              iSprite,
       
   292                                                              aMember);
       
   293 
       
   294 	if(!cmd)
       
   295 		return EFalse;
       
   296 	AddAnimCommand(cmd);
       
   297 	return ETrue;	
       
   298 	}
       
   299 	
       
   300 // ---------------------------------------------------------------------------
       
   301 // CPeninputAnimObj::AddUpdateUiCmd
       
   302 // Add updaing UI command
       
   303 // ---------------------------------------------------------------------------
       
   304 //			
       
   305 TBool CPeninputAnimObj::AddUpdateUiCmd(const TRect& aRect, TBool aUpdateFlag)
       
   306 	{
       
   307 	TAnimUpdateUiRectCmd* cmd = new TAnimUpdateUiRectCmd(iAnim,aRect,aUpdateFlag);
       
   308 	if(!cmd)
       
   309 		return EFalse;
       
   310 	AddAnimCommand(cmd);
       
   311 	return ETrue;		
       
   312 	}
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CPeninputAnimObj::AddUpdateUiCmd
       
   316 // Add updaing UI command
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 TBool CPeninputAnimObj::AddUpdateUiCmd(TUpdateArea *aArea,TInt aNum)
       
   320     {
       
   321 	  TAnimUpdateUiRectCmd* cmd = new TAnimUpdateUiRectCmd(iAnim,aArea,aNum);
       
   322 	  if (!cmd)
       
   323 		    return EFalse;
       
   324 	  AddAnimCommand(cmd);
       
   325 	  return ETrue;		
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // CPeninputAnimObj::AddCapturePointerCmd
       
   330 // Add capturing pointer command
       
   331 // ---------------------------------------------------------------------------
       
   332 //				
       
   333 TBool CPeninputAnimObj::AddCapturePointerCmd(TBool aFlag, TInt aCaptureCtrlID)
       
   334 	{
       
   335 	TAnimCapturePtCmd* cmd = new TAnimCapturePtCmd(iAnim,aFlag, aCaptureCtrlID);	
       
   336 	if(!cmd)
       
   337 		return EFalse;
       
   338 	AddAnimCommand(cmd);
       
   339 	return ETrue;		
       
   340 	}
       
   341 	
       
   342 // ---------------------------------------------------------------------------
       
   343 // CPeninputAnimObj::AddSimulatedEventCmd
       
   344 // Add ignoring similated event command
       
   345 // ---------------------------------------------------------------------------
       
   346 //					
       
   347 TBool CPeninputAnimObj::AddSimulateEventCmd(const TRawEvent& aEvent)
       
   348 	{
       
   349     TAnimSimulateEventCmd* cmd = new TAnimSimulateEventCmd(iAnim, aEvent);
       
   350     if (!cmd)
       
   351         return EFalse;
       
   352     AddAnimCommand(cmd);
       
   353     return ETrue;	
       
   354 	}
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // Execute simulate event command
       
   358 // ---------------------------------------------------------------------------
       
   359 //					
       
   360 TBool CPeninputAnimObj::ExecuteSimulateEventCmd( const TRawEvent& aEvent )
       
   361 	{
       
   362     TAnimSimulateEventCmd* cmd = new TAnimSimulateEventCmd( iAnim, aEvent );    
       
   363     if (!cmd)
       
   364         return EFalse;
       
   365     cmd->ExecuteAnimCommand();
       
   366     delete cmd;
       
   367     cmd = NULL;
       
   368     return ETrue;		
       
   369 	}
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CPeninputAnimObj::AddFlushSessionCmd
       
   373 // Add flushing session command
       
   374 // ---------------------------------------------------------------------------
       
   375 //						
       
   376 TBool CPeninputAnimObj::AddFlushSessionCmd()
       
   377 	{
       
   378 	TAnimFlushWsSessionCmd* cmd = new TAnimFlushWsSessionCmd(iAnim,iWsSession);
       
   379 	if(!cmd)
       
   380 		return EFalse;
       
   381 	AddAnimCommand(cmd);
       
   382 	return ETrue;		
       
   383 	}
       
   384 
       
   385 #ifdef RD_TACTILE_FEEDBACK
       
   386 	
       
   387 // ---------------------------------------------------------------------------
       
   388 // CPeninputAnimObj::AddRegisterFeedbackAreaCmd
       
   389 // Add feedback registeration command
       
   390 // ---------------------------------------------------------------------------
       
   391 //							
       
   392 TBool CPeninputAnimObj::AddRegisterFeedbackAreaCmd(const TTactileFeedbackArea& aArea,
       
   393                                                 TBool aCmdFlag)		
       
   394     { 
       
   395 	TAnimFeedbackAreaCmd* cmd = new TAnimFeedbackAreaCmd(iAnim,aArea,
       
   396 	                                                       TAnimFeedbackAreaCmd::TFeedbackAreaOpAdd,
       
   397 	                                                       aCmdFlag);
       
   398 	if(!cmd)
       
   399 		return EFalse;
       
   400 	AddAnimCommand(cmd);
       
   401 	return ETrue;	        
       
   402     }
       
   403 
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CPeninputAnimObj::AddRegisterFeedbackAreaCmd
       
   407 // Add feedback registeration command
       
   408 // ---------------------------------------------------------------------------
       
   409 //							
       
   410 /*TBool CPeninputAnimObj::AddRegisterFeedbackAreaCmd(const RArray<TTactileFeedbackArea>& aAreaList)		
       
   411     { 
       
   412 	TAnimFeedbackAreaCmd* cmd = new TAnimFeedbackAreaCmd(iAnim,aAreaList,
       
   413 	                                                       TAnimFeedbackAreaCmd::TFeedbackAreaOpAdd,
       
   414 	                                                       ETrue);
       
   415 	if(!cmd)
       
   416 		return EFalse;
       
   417 	AddAnimCommand(cmd);
       
   418 	return ETrue;	        
       
   419     }*/
       
   420 
       
   421 
       
   422 // ---------------------------------------------------------------------------
       
   423 // CPeninputAnimObj::AddDeRegisterFeedbackAreaCmd
       
   424 // Remove feedback registeration command
       
   425 // ---------------------------------------------------------------------------
       
   426 //							
       
   427 TBool CPeninputAnimObj::AddDeRegisterFeedbackAreaCmd(const TTactileFeedbackArea& aArea,
       
   428                                             TBool aCmdFlag)
       
   429     { 
       
   430 	TAnimFeedbackAreaCmd* cmd = new TAnimFeedbackAreaCmd(iAnim,aArea,
       
   431 	                                                       TAnimFeedbackAreaCmd::TFeedbackAreaOpRemove,
       
   432 	                                                       aCmdFlag);
       
   433 	if(!cmd)
       
   434 		return EFalse;
       
   435 	AddAnimCommand(cmd);
       
   436 	return ETrue;	        
       
   437     }
       
   438     
       
   439 // ---------------------------------------------------------------------------
       
   440 // CPeninputAnimObj::AddChangeFeedbackAreaCmd
       
   441 // Add feedback registeration command
       
   442 // ---------------------------------------------------------------------------
       
   443 //							
       
   444 TBool CPeninputAnimObj::AddChangeFeedbackAreaCmd(const TTactileFeedbackArea& aArea,
       
   445                                             TBool aCmdFlag)
       
   446     { 
       
   447 	TAnimFeedbackAreaCmd* cmd = new TAnimFeedbackAreaCmd(iAnim,aArea,
       
   448 	                                                       TAnimFeedbackAreaCmd::TFeedbackAreaOpChange,
       
   449 	                                                       aCmdFlag);
       
   450 	if(!cmd)
       
   451 		return EFalse;
       
   452 	AddAnimCommand(cmd);
       
   453 	return ETrue;	        
       
   454     }  
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CPeninputAnimObj::AddChangeFeedbackTypeCmd
       
   458 // Add feedback registeration command
       
   459 // ---------------------------------------------------------------------------
       
   460 //							
       
   461 TBool CPeninputAnimObj::AddChangeFeedbackTypeCmd(const TTactileFeedbackArea& aArea,
       
   462                                             TBool aCmdFlag)
       
   463     { 
       
   464 	TAnimFeedbackAreaCmd* cmd = new TAnimFeedbackAreaCmd(iAnim,aArea,
       
   465 	                                                       TAnimFeedbackAreaCmd::TFeedbackTypeOpChange,
       
   466 	                                                       aCmdFlag);
       
   467 	if(!cmd)
       
   468 		return EFalse;
       
   469 	AddAnimCommand(cmd);
       
   470 	return ETrue;	        
       
   471     }  
       
   472 
       
   473 #endif // RD_TACTILE_FEEDBACK
       
   474 TBool CPeninputAnimObj::AddEnalbeSpriteCmd(TBool aFlag)
       
   475     {
       
   476 	TAnimEnableSpriteCmd* cmd = new TAnimEnableSpriteCmd(iAnim,aFlag);
       
   477 	if(!cmd)
       
   478 		return EFalse;
       
   479 	AddAnimCommand(cmd);
       
   480 	return ETrue;	                
       
   481     }
       
   482 
       
   483 RWindowGroup& CPeninputAnimObj::WindowGroup()
       
   484     {
       
   485     return iWindowGroup;
       
   486     }
       
   487     
       
   488 void CPeninputAnimObj::OnExiting()
       
   489     {
       
   490     iOnExiting = ETrue;
       
   491     }
       
   492     
       
   493 void CPeninputAnimObj::GetDSAState(TBool& aState)
       
   494     {
       
   495     iAnim.GetDSAState(aState);    
       
   496     }
       
   497 //end of file