66
|
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 |
#include <j2me/jdebug.h>
|
|
26 |
|
|
27 |
CMIDTactileFeedbackExtension::CMIDTactileFeedbackExtension(MMIDTactileFeedbackComponent* aParent, TInt aParentType): TypeCanvas(1), TypeCustomItem(2)
|
|
28 |
|
|
29 |
{
|
|
30 |
iParent = aParent;
|
|
31 |
iParentType = aParentType;
|
|
32 |
iFeedbackInstance = MTouchFeedback::Instance();
|
|
33 |
}
|
|
34 |
|
|
35 |
|
|
36 |
CCoeControl* CMIDTactileFeedbackExtension::GetParentControl()
|
|
37 |
{
|
|
38 |
if (iParentType == TypeCanvas)
|
|
39 |
{
|
|
40 |
return &(((CMIDCanvas*)iParent)->Control());
|
|
41 |
}
|
|
42 |
else if (iParentType == TypeCustomItem)
|
|
43 |
{
|
|
44 |
return ((CMIDCustomItem*)iParent)->ComponentControl(0);
|
|
45 |
}
|
|
46 |
return 0;
|
|
47 |
}
|
|
48 |
|
|
49 |
|
|
50 |
CMIDTactileFeedbackExtension::FeedbackArea* CMIDTactileFeedbackExtension::GetArea(TInt idx)
|
|
51 |
{
|
|
52 |
return &iFeedbackAreasArray[idx];
|
|
53 |
}
|
|
54 |
|
|
55 |
CMIDTactileFeedbackExtension::FeedbackArea* CMIDTactileFeedbackExtension::GetAreaByID(TInt aId, TInt* aIdx)
|
|
56 |
{
|
|
57 |
TInt index = 0;
|
|
58 |
while (index < iFeedbackAreasArray.Count())
|
|
59 |
{
|
|
60 |
FeedbackArea* area;
|
|
61 |
|
|
62 |
area = &iFeedbackAreasArray[index];
|
|
63 |
|
|
64 |
if (area->id == aId)
|
|
65 |
{
|
|
66 |
if (aIdx) *aIdx = index;
|
|
67 |
return area;
|
|
68 |
}
|
|
69 |
index++;
|
|
70 |
}
|
|
71 |
|
|
72 |
return NULL;
|
|
73 |
|
|
74 |
}
|
|
75 |
|
|
76 |
void CMIDTactileFeedbackExtension::RegisterFeedbackArea(TInt aId, TRect aRect, TInt aStyle)
|
|
77 |
{
|
|
78 |
FeedbackArea* area = GetAreaByID(aId, NULL);
|
|
79 |
TInt err = KErrNone;
|
|
80 |
if (area)
|
|
81 |
{
|
|
82 |
area->rect = aRect;
|
|
83 |
area->style = (TTouchLogicalFeedback)aStyle;
|
|
84 |
}
|
|
85 |
else
|
|
86 |
{
|
|
87 |
FeedbackArea newArea;
|
|
88 |
newArea.id = aId;
|
|
89 |
newArea.rect = aRect;
|
|
90 |
newArea.style = (TTouchLogicalFeedback)aStyle;
|
|
91 |
err = iFeedbackAreasArray.Append(newArea);
|
|
92 |
}
|
|
93 |
|
|
94 |
if (KErrNone == err )
|
|
95 |
{
|
|
96 |
iParent->UpdateTactileFeedback();
|
|
97 |
}
|
|
98 |
else
|
|
99 |
{
|
|
100 |
DEBUG_INT("CMIDTactileFeedbackExtension::RegisterFeedbackArea - RArray append error %d", err);
|
|
101 |
}
|
|
102 |
}
|
|
103 |
|
|
104 |
void CMIDTactileFeedbackExtension::SetFeedbackArea(TInt aId, TRect aRect, TInt aStyle)
|
|
105 |
{
|
|
106 |
if (iFeedbackInstance)
|
|
107 |
iFeedbackInstance->SetFeedbackArea(GetParentControl(), aId, aRect, (TTouchLogicalFeedback)aStyle, ETouchEventStylusDown);
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
void CMIDTactileFeedbackExtension::RemoveFeedbackArea(TInt aId)
|
|
112 |
{
|
|
113 |
if (iFeedbackInstance)
|
|
114 |
iFeedbackInstance->RemoveFeedbackArea(GetParentControl(), aId);
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
TInt CMIDTactileFeedbackExtension::GetAreasCount()
|
|
119 |
{
|
|
120 |
return iFeedbackAreasArray.Count();
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
void CMIDTactileFeedbackExtension::UnregisterFeedbackArea(TInt aId)
|
|
125 |
{
|
|
126 |
TInt idx;
|
|
127 |
FeedbackArea* area = GetAreaByID(aId, &idx);
|
|
128 |
if (area)
|
|
129 |
{
|
|
130 |
RemoveFeedbackArea(aId);
|
|
131 |
iFeedbackAreasArray.Remove(idx);
|
|
132 |
iParent->UpdateTactileFeedback();
|
|
133 |
}
|
|
134 |
}
|
|
135 |
|
|
136 |
|
|
137 |
void CMIDTactileFeedbackExtension::UnregisterFeedbackForControl()
|
|
138 |
{
|
|
139 |
TInt index = 0;
|
|
140 |
while (index < iFeedbackAreasArray.Count())
|
|
141 |
{
|
|
142 |
FeedbackArea* area;
|
|
143 |
area = &iFeedbackAreasArray[index];
|
|
144 |
RemoveFeedbackArea(area->id);
|
|
145 |
index++;
|
|
146 |
}
|
|
147 |
|
|
148 |
iFeedbackAreasArray.Reset();
|
|
149 |
iParent->UpdateTactileFeedback();
|
|
150 |
}
|
|
151 |
|
|
152 |
void CMIDTactileFeedbackExtension::MoveAreaToFirstPriority(TInt aId)
|
|
153 |
{
|
|
154 |
if (iFeedbackInstance)
|
|
155 |
iFeedbackInstance->MoveFeedbackAreaToFirstPriority(GetParentControl(), aId);
|
|
156 |
}
|
|
157 |
|
|
158 |
#endif
|