|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CMIDENV_H |
|
20 #define CMIDENV_H |
|
21 |
|
22 #include <e32def.h> |
|
23 #include <lcdui.h> |
|
24 |
|
25 class CMIDKeyTranslator; |
|
26 class CMIDToolkit; |
|
27 class CMIDToLcduiObserver; |
|
28 |
|
29 |
|
30 /** |
|
31 * |
|
32 * A MIDlet environment, one per MIDlet, providing utility methods for the |
|
33 * MIDP implementation |
|
34 * |
|
35 */ |
|
36 class CMIDEnv : public CBase, public MMIDEnv |
|
37 { |
|
38 public: |
|
39 CMIDEnv(CMIDToolkit* aToolkit, const TSize& aSize); |
|
40 void ConstructL(); |
|
41 ~CMIDEnv(); |
|
42 |
|
43 void SetUtils(MMIDUtils* aUtils); |
|
44 |
|
45 public: |
|
46 virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TEventType aEventType,TInt aEventData,TInt aEventData1,TInt aEventData2); |
|
47 virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TEventType aEventType=ENoType,TInt aEventData=0); |
|
48 virtual TBool PostJavaEvent(MMIDComponent& aSource,TSourceType aSourceType,TInt aEventData); |
|
49 virtual TBool PostMidletEvent(TEventType aEventType); |
|
50 |
|
51 virtual MMIDNotifyEvent* NewNotifyL(MMIDComponent& aSource); |
|
52 virtual TBool PostJavaNotify(MMIDNotifyEvent* aNotify); |
|
53 |
|
54 virtual TBool TranslateKeyL(TMIDKeyEvent& aEvent, const TKeyEvent&, TEventCode aType); |
|
55 virtual TBool PostKeyEvent(MMIDComponent& aSource, TMIDKeyEvent& aEvent); |
|
56 virtual void ResetKeys(); |
|
57 |
|
58 virtual MMIDDisplayable* Current(); |
|
59 virtual TPtrC MidletName() const; |
|
60 virtual TUid MidletUid() const; |
|
61 virtual TPtrC MidletHome() const; |
|
62 virtual void DisplayableIsDestructed(const MMIDDisplayable* displayable); |
|
63 const MMIDDisplayable* LastFullscreenDisplayable() const; |
|
64 |
|
65 #ifdef RD_SCALABLE_UI_V2 |
|
66 // This function can be moved out from RD_SCALABLE_UI_V2 flag if needed. |
|
67 // It is behind this flag because currently it is used only by Touch. |
|
68 /** |
|
69 * Returns MIDlet Suite uid that is parsed from the MIDlet home path. |
|
70 * In practise this function assumes that the midlet home path includes |
|
71 * Midlet suite uid inside the brackets, for example: |
|
72 * "e:\epoc32\winscw\c\private\102033E6\MIDlets\[101e0a27]" |
|
73 * |
|
74 * Note: |
|
75 * MIDlet suite uid could be retrieved from the Java registry based on |
|
76 * the midlet uid. But that operation is very time consuming because it |
|
77 * requires lot of file accessing, especially when there are many midlets |
|
78 * installed in the device. |
|
79 * @since S60 5.0 |
|
80 * @return TUid iMidletSuiteUid or |
|
81 * KNullUidValue if midlet suite uid not found or error occured. |
|
82 */ |
|
83 TUid MidletSuiteUid(); |
|
84 #endif //RD_SCALABLE_UI_V2 |
|
85 |
|
86 virtual TInt NumColors(); |
|
87 virtual TDisplayMode DisplayMode(); |
|
88 |
|
89 virtual void SetCanvasZoomSize(const TSize& aSize); |
|
90 virtual TSize CanvasZoomSize(); |
|
91 virtual TSize CanvasAssumedSize(); |
|
92 virtual TInt MidletAttribute(const TDesC& aAttributeName, TPtrC& aAttributeValue); |
|
93 |
|
94 /** |
|
95 * @see MMIDEnv#MidletAttributeIsSetToVal() |
|
96 */ |
|
97 virtual TBool MidletAttributeIsSetToVal(const TDesC& aAttributeName, const TDesC& aAttributeValue); |
|
98 |
|
99 /** |
|
100 * @see MMIDEnv#MidletAttributeContainsVal() |
|
101 */ |
|
102 virtual TBool MidletAttributeContainsVal(const TDesC& aAttributeName, const TDesC& aAttributeValue); |
|
103 |
|
104 virtual void SetCanvasAssumedSize(const TSize& aSize); |
|
105 |
|
106 // |
|
107 virtual void AddObserverL(MMIDEnvObserver& aObserver); |
|
108 virtual void RemoveObserver(MMIDEnvObserver& aObserver); |
|
109 // |
|
110 void HandleSwitchOnL(TBool aSwitchOn); |
|
111 void HandleForegroundL(TBool aForeground); |
|
112 void HandleResourceChangeL(TInt aType); |
|
113 |
|
114 /** |
|
115 * @see MMIDEnv#ReserveCanvasFrameBuffer() |
|
116 */ |
|
117 virtual CFbsBitmap* ReserveCanvasFrameBufferL(MMIDCanvas& aCanvas, const TSize& aSz); |
|
118 |
|
119 /** |
|
120 * @see MMIDEnv#ReleaseCanvasFrameBuffer() |
|
121 */ |
|
122 virtual void ReleaseCanvasFrameBuffer(MMIDCanvas& aCanvas, CFbsBitmap*& aFrameBuffer); |
|
123 |
|
124 /** |
|
125 * @see MMIDEnv#CanvasHasBackground() |
|
126 */ |
|
127 virtual TBool CanvasHasBackground(const MMIDCanvas& aCanvas) const; |
|
128 |
|
129 /** |
|
130 * Maps low level key event |
|
131 * @param aMidKeyEvent key event output data |
|
132 * @param aEvent key event input data |
|
133 * @see virtual void MMIDEnv::MappingDataForKey( TKeyEvent& aEvent ); |
|
134 */ |
|
135 virtual void MappingDataForKey(TKeyEvent& aEvent, TEventCode aType); |
|
136 |
|
137 /** |
|
138 * Set last key event |
|
139 * @param aEvent key event input data |
|
140 * @see virtual void MMIDEnv::SetLastKeyEvent( const TKeyEvent& aEvent ); |
|
141 */ |
|
142 virtual void SetLastKeyEvent(const TKeyEvent& aEvent); |
|
143 |
|
144 /** |
|
145 * From MMIDEnv. |
|
146 * Gets an instance of ToLcduiObserver. |
|
147 * |
|
148 * @since S60 5.0 |
|
149 * @return Pointer to ToLcduiObserver instance |
|
150 * @see iToLcduiObserver |
|
151 */ |
|
152 virtual MMIDToLcduiObserver& ToLcduiObserver(); |
|
153 |
|
154 #ifdef RD_JAVA_NGA_ENABLED |
|
155 /** |
|
156 * @see MMIDEnv#IsHardwareAccelerated() |
|
157 */ |
|
158 virtual TBool IsHardwareAcceleratedL( |
|
159 MMIDEnv::THardwareType aHardwareType = MMIDEnv::EHardware3D); |
|
160 |
|
161 /** |
|
162 * @see MMIDEnv#HandleFullOrPartialForegroundL() |
|
163 */ |
|
164 virtual void HandleFullOrPartialForegroundL(TBool aFullOrPartialFg); |
|
165 |
|
166 /** |
|
167 * @see MMIDEnv#HandleFreeGraphicsMemory() |
|
168 */ |
|
169 virtual void HandleFreeGraphicsMemory(); |
|
170 |
|
171 /** |
|
172 * @see MMIDEnv#HasFullOrPartialForeground() |
|
173 */ |
|
174 virtual TBool HasFullOrPartialForeground() const; |
|
175 private: |
|
176 /** |
|
177 * Checks and initializes 2D & 3D harware status |
|
178 * @return Hardware status @see MMIDEnv::THardwareType |
|
179 * @since S60 9.2 |
|
180 */ |
|
181 TInt InitHardwareStatusL(); |
|
182 |
|
183 #endif // RD_JAVA_NGA_ENABLED |
|
184 |
|
185 |
|
186 private: |
|
187 /** |
|
188 * Encapsulated canvas (frame buffer) data |
|
189 */ |
|
190 struct TCanvasData |
|
191 { |
|
192 |
|
193 /** |
|
194 * Ctor |
|
195 */ |
|
196 TCanvasData() |
|
197 : iRefCount(0), iFrameBuffer(NULL), iHasBackground(EFalse) |
|
198 { |
|
199 } |
|
200 |
|
201 /** |
|
202 * Reset frame buffer data |
|
203 */ |
|
204 inline void Reset() |
|
205 { |
|
206 delete iFrameBuffer; |
|
207 iFrameBuffer = NULL; |
|
208 iRefCount = 0; |
|
209 } |
|
210 TUint iRefCount; |
|
211 CFbsBitmap* iFrameBuffer; |
|
212 TBool iHasBackground; |
|
213 RMutex iLock; |
|
214 }; |
|
215 |
|
216 /** |
|
217 * Autolocker class. |
|
218 */ |
|
219 class TMutexAutoLock |
|
220 { |
|
221 public: |
|
222 /** |
|
223 * Ctor |
|
224 * @param aLock Syncronization primitive that is locked during construction |
|
225 */ |
|
226 TMutexAutoLock(RMutex* aLock) : iLock(aLock) |
|
227 { |
|
228 iLock->Wait(); |
|
229 } |
|
230 |
|
231 /** |
|
232 * Dtor. Signals the synchronization primitive |
|
233 */ |
|
234 ~TMutexAutoLock() |
|
235 { |
|
236 iLock->Signal(); |
|
237 } |
|
238 private: |
|
239 RMutex* iLock; |
|
240 }; |
|
241 |
|
242 |
|
243 /** |
|
244 * Create a frame buffer for a <code>MMIDCanvas</code> instance. |
|
245 * @param aCanvas Target canvas |
|
246 * @param aWsBitmap If <code>ETrue</code> then the type of the frame buffer |
|
247 * will be <code>WsBitmap</code> instead of a <code>CFbsBitmap</code>. |
|
248 * @param aSz Frame buffer size |
|
249 * @return Frame buffer instance |
|
250 * @since S60 5.0 |
|
251 */ |
|
252 CFbsBitmap* CreateCanvasFrameBufferL( |
|
253 MMIDCanvas& aCanvas, TBool aWsBitmap, const TSize& aSz); |
|
254 |
|
255 private: |
|
256 enum {EGranularity = 4}; |
|
257 |
|
258 private: |
|
259 CMIDToolkit* iToolkit; |
|
260 RArray<MMIDEnvObserver*> iObservers; |
|
261 CMIDKeyTranslator* iKeyTranslator; |
|
262 TSize iCanvasAssumedSize; |
|
263 TSize iCanvasZoomSize; |
|
264 TCanvasData iCanvasData; |
|
265 |
|
266 #ifdef RD_SCALABLE_UI_V2 |
|
267 // MIDlet suite uid |
|
268 TUid iMidletSuiteUid; |
|
269 #endif //RD_SCALABLE_UI_V2 |
|
270 |
|
271 /** |
|
272 * Provides possibility to make calls from non-LCDUI threads |
|
273 * to LCDUI ES thread. |
|
274 * Own. |
|
275 */ |
|
276 CMIDToLcduiObserver* iToLcduiObserver; |
|
277 |
|
278 #ifdef RD_JAVA_NGA_ENABLED |
|
279 TInt iHardwareStatus; |
|
280 TBool iFullOrPartialFg; |
|
281 #endif // RD_JAVA_NGA_ENABLED |
|
282 }; |
|
283 |
|
284 #endif // CMIDENV_H |