javauis/lcdui_akn/lcdui/src/CMIDTactileFeedbackExtension.cpp
branchRCL_3
changeset 19 04becd199f91
child 60 6c158198356e
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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 of CMIDTactileFeedbackExtension to store feedback areas for an LCDUI component.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifdef RD_TACTILE_FEEDBACK
       
    20 
       
    21 #include "CMIDTactileFeedbackExtension.h"
       
    22 #include "CMIDCanvas.h"
       
    23 #include "CMIDCustomItem.h"
       
    24 
       
    25 CMIDTactileFeedbackExtension::CMIDTactileFeedbackExtension(MMIDTactileFeedbackComponent* aParent, TInt aParentType): TypeCanvas(1), TypeCustomItem(2)
       
    26 
       
    27 {
       
    28     iParent = aParent;
       
    29     iParentType = aParentType;
       
    30     iFeedbackInstance = MTouchFeedback::Instance();
       
    31 }
       
    32 
       
    33 
       
    34 CCoeControl* CMIDTactileFeedbackExtension::GetParentControl()
       
    35 {
       
    36     if (iParentType == TypeCanvas)
       
    37     {
       
    38         return  &(((CMIDCanvas*)iParent)->Control());
       
    39     }
       
    40     else if (iParentType == TypeCustomItem)
       
    41     {
       
    42         return ((CMIDCustomItem*)iParent)->ComponentControl(0);
       
    43     }
       
    44     return 0;
       
    45 }
       
    46 
       
    47 
       
    48 CMIDTactileFeedbackExtension::FeedbackArea* CMIDTactileFeedbackExtension::GetArea(TInt idx)
       
    49 {
       
    50     return &iFeedbackAreasArray[idx];
       
    51 }
       
    52 
       
    53 CMIDTactileFeedbackExtension::FeedbackArea* CMIDTactileFeedbackExtension::GetAreaByID(TInt aId, TInt* aIdx)
       
    54 {
       
    55     TInt index = 0;
       
    56     while (index < iFeedbackAreasArray.Count())
       
    57     {
       
    58         FeedbackArea* area;
       
    59 
       
    60         area = &iFeedbackAreasArray[index];
       
    61 
       
    62         if (area->id == aId)
       
    63         {
       
    64             if (aIdx) *aIdx = index;
       
    65             return area;
       
    66         }
       
    67         index++;
       
    68     }
       
    69 
       
    70     return NULL;
       
    71 
       
    72 }
       
    73 
       
    74 void CMIDTactileFeedbackExtension::RegisterFeedbackArea(TInt aId, TRect aRect, TInt aStyle)
       
    75 {
       
    76     FeedbackArea* area = GetAreaByID(aId, NULL);
       
    77     if (area)
       
    78     {
       
    79         area->rect = aRect;
       
    80         area->style = (TTouchLogicalFeedback)aStyle;
       
    81     }
       
    82     else
       
    83     {
       
    84         FeedbackArea newArea;
       
    85         newArea.id  = aId;
       
    86         newArea.rect = aRect;
       
    87         newArea.style = (TTouchLogicalFeedback)aStyle;
       
    88         iFeedbackAreasArray.Append(newArea);
       
    89     }
       
    90 
       
    91     iParent->UpdateTactileFeedback();
       
    92 }
       
    93 
       
    94 void CMIDTactileFeedbackExtension::SetFeedbackArea(TInt aId, TRect aRect, TInt aStyle)
       
    95 {
       
    96     if (iFeedbackInstance)
       
    97         iFeedbackInstance->SetFeedbackArea(GetParentControl(), aId, aRect, (TTouchLogicalFeedback)aStyle, ETouchEventStylusDown);
       
    98 }
       
    99 
       
   100 
       
   101 void CMIDTactileFeedbackExtension::RemoveFeedbackArea(TInt aId)
       
   102 {
       
   103     if (iFeedbackInstance)
       
   104         iFeedbackInstance->RemoveFeedbackArea(GetParentControl(), aId);
       
   105 }
       
   106 
       
   107 
       
   108 TInt CMIDTactileFeedbackExtension::GetAreasCount()
       
   109 {
       
   110     return iFeedbackAreasArray.Count();
       
   111 }
       
   112 
       
   113 
       
   114 void CMIDTactileFeedbackExtension::UnregisterFeedbackArea(TInt aId)
       
   115 {
       
   116     TInt idx;
       
   117     FeedbackArea* area = GetAreaByID(aId, &idx);
       
   118     if (area)
       
   119     {
       
   120         RemoveFeedbackArea(aId);
       
   121         iFeedbackAreasArray.Remove(idx);
       
   122         iParent->UpdateTactileFeedback();
       
   123     }
       
   124 }
       
   125 
       
   126 
       
   127 void CMIDTactileFeedbackExtension::UnregisterFeedbackForControl()
       
   128 {
       
   129     TInt index = 0;
       
   130     while (index < iFeedbackAreasArray.Count())
       
   131     {
       
   132         FeedbackArea* area;
       
   133         area = &iFeedbackAreasArray[index];
       
   134         RemoveFeedbackArea(area->id);
       
   135         index++;
       
   136     }
       
   137 
       
   138     iFeedbackAreasArray.Reset();
       
   139     iParent->UpdateTactileFeedback();
       
   140 }
       
   141 
       
   142 void CMIDTactileFeedbackExtension::MoveAreaToFirstPriority(TInt aId)
       
   143 {
       
   144     if (iFeedbackInstance)
       
   145         iFeedbackInstance->MoveFeedbackAreaToFirstPriority(GetParentControl(), aId);
       
   146 }
       
   147 
       
   148 #endif