|
1 /******************************************************************************* |
|
2 * Copyright (c) 2005, 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. This program and the accompanying materials |
|
4 * are made available under the terms of the Eclipse Public License v1.0 |
|
5 * which accompanies this distribution, and is available at |
|
6 * http://www.eclipse.org/legal/epl-v10.html |
|
7 * |
|
8 * Contributors: |
|
9 * Nokia Corporation - S60 implementation |
|
10 *******************************************************************************/ |
|
11 |
|
12 |
|
13 #ifndef SWTDISPLAYBASE_H |
|
14 #define SWTDISPLAYBASE_H |
|
15 |
|
16 #ifdef RD_SCALABLE_UI_V2 |
|
17 #include <aknlongtapdetector.h> |
|
18 #endif |
|
19 |
|
20 #include "eswtgraphics.h" |
|
21 #include "swteventqueue.h" |
|
22 #include "swtinstancecounts.h" |
|
23 #include "swtmidmediakeyslistener.h" |
|
24 |
|
25 |
|
26 class CSwtEventQueue; |
|
27 class CSwtKeyMapper; |
|
28 class CSwtTimer; |
|
29 class MSwtFactory; |
|
30 class MSwtUiUtils; |
|
31 class MSwtMenuArranger; |
|
32 class MSwtCommandArranger; |
|
33 class CSwtMIDRemConObserver; |
|
34 class CSwtJavaBufferDrawer; |
|
35 class CSwtDialogBroker; |
|
36 |
|
37 /** |
|
38 * ASwtDisplayBase |
|
39 * Base class for implementing the C++ counterpart to the |
|
40 * org.eclipse.swt.widgets.Display Java class. |
|
41 * @lib eswt |
|
42 */ |
|
43 NONSHARABLE_CLASS(ASwtDisplayBase) |
|
44 : public MSwtDisplay |
|
45 , public MSwtDevice |
|
46 #ifdef RD_SCALABLE_UI_V2 |
|
47 , public MAknLongTapDetectorCallBack |
|
48 #endif |
|
49 , public MSwtPopupMenuCallBack |
|
50 , public MSwtMediaKeysListener |
|
51 { |
|
52 protected: |
|
53 ASwtDisplayBase(); |
|
54 void ConstructInJavaUiThreadL(); |
|
55 void ConstructInNativeUiThreadL(); |
|
56 ~ASwtDisplayBase(); |
|
57 void DestroyInNativeUiThread(); |
|
58 |
|
59 // Methods to be used by the java thread |
|
60 public: |
|
61 TBool Sleep(); |
|
62 inline void Wake(); |
|
63 inline TBool ReadAndDispatch(JNIEnv& aJniEnv); |
|
64 inline void PopAndDispatchPaintEvents(JNIEnv& aJniEnv, MSwtControl* aSwtControl); |
|
65 inline void PeerDisposed(TSwtPeer aPeer); |
|
66 void AddTimerL(TInt aDelayInMilliSeconds, TInt aTimerHandle); |
|
67 void RegisterTimerL(const CSwtTimer* aTimer); |
|
68 void UnRegisterTimer(const CSwtTimer* aTimer); |
|
69 |
|
70 // Methods to be used by the native thread |
|
71 public: |
|
72 void HandleNewEvent(); |
|
73 TInt GetIconDepth() const; |
|
74 TInt GetDoubleClickTime() const; |
|
75 void Beep() const; |
|
76 void PostL(const TSwtKeyEventData& aData); |
|
77 TBool MousePostL(const TSwtKeyEventData& aData, TPoint point); |
|
78 MSwtImage* NewImageL(const TSize& aSize); |
|
79 MSwtImage* NewImageFromDataL(const MSwtImageData& aData); |
|
80 inline CSwtJavaBufferDrawer& JavaBufferDrawer(); |
|
81 |
|
82 // Methods to be used by either thread |
|
83 public: |
|
84 inline TBool IsCurrentThreadJavaUi() const; |
|
85 #ifdef _DEBUG |
|
86 virtual TBool IsCurrentThreadNativeUi() const =0; |
|
87 #endif |
|
88 virtual TSwtPeer JavaPeer() =0; |
|
89 inline CSwtEventQueue* EventQueue() const; |
|
90 |
|
91 private: |
|
92 void DoWake(TBool aBecauseOfEvent); |
|
93 |
|
94 // Own internal event methods |
|
95 protected: |
|
96 void PostForegroundEventL(TSwtPeer aPeer, const TBool& aForeground); |
|
97 |
|
98 // From MSwtDisplay (mostly intended to be used by the App UI's thread) |
|
99 public: |
|
100 MSwtDevice& Device(); |
|
101 const MSwtFactory& Factory() const; |
|
102 MSwtUiUtils& UiUtils(); |
|
103 MSwtMenuArranger& MenuArranger(); |
|
104 MSwtCommandArranger* CommandArranger(); |
|
105 void AddResourceChangeObserverL(MSwtResourceChangeObserver* aObserver); |
|
106 void RemoveResourceChangeObserver(MSwtResourceChangeObserver* aObserver); |
|
107 void AddAppFocusObserverL(MSwtAppFocusObserver* aObserver); |
|
108 void RemoveAppFocusObserver(MSwtAppFocusObserver* aObserver); |
|
109 TInt GetSymbianScanCode(const TInt aSwtKeyCode) const; |
|
110 TUint GetSymbianKeyCode(const TInt aSwtKeyCode) const; |
|
111 void ForceTraverseEventL(MSwtControl& aControl, |
|
112 TSwtTraversal aDetail, TBool aDoIt); |
|
113 void PostTraverseEventL(MSwtControl& aControl, TSwtTraversal aDetail, |
|
114 const TKeyEvent& aKeyEvent, TEventCode aType, TBool aDoIt); |
|
115 void PostKeyEventL(MSwtControl& aControl, const TKeyEvent& aKeyEvent, |
|
116 TEventCode aType); |
|
117 void PostPaintEventL(TSwtPeer aSenderPeer, TSwtPeer aShellPeer, |
|
118 const TRect& aRect, TBool aMergeable); |
|
119 void PostMouseEventL(TSwtPeer aPeer, TSwtEventType aType, |
|
120 TInt aButton, const TPoint& aPos, TInt aStateMask); |
|
121 void PostMoveEventL(TSwtPeer aPeer); |
|
122 void PostResizeEventL(TSwtPeer aPeer); |
|
123 void PostScrollEventL(TSwtPeer aPeer, TInt aDetail); |
|
124 void PostSelectionEventL(TSwtPeer aPeer); |
|
125 void PostSelectionEventL(TSwtPeer aPeer, const TDesC& aText); |
|
126 void PostSelectionEventL(TSwtPeer aPeer, TInt aDetail, TSwtPeer aItemPeer); |
|
127 void PostDefaultSelectionEventL(TSwtPeer aPeer); |
|
128 void PostDefaultSelectionEventL(TSwtPeer aPeer, TInt aDetail, TSwtPeer aItemPeer); |
|
129 void PostFocusEventL(TSwtPeer aPeer, TSwtEventType aType); |
|
130 void PostShellEventL(TSwtPeer aPeer, TSwtEventType aType); |
|
131 void PostModifyEventL(TSwtPeer aPeer); |
|
132 void PostVerifyEventL(MSwtVerifyEventObserver& aWidget, TSwtPeer aPeer, |
|
133 TInt aStart, TInt aEnd, const TDesC& aText); |
|
134 void PostShowEventL(TSwtPeer aPeer); |
|
135 void PostHideEventL(TSwtPeer aPeer); |
|
136 void PostScreenEventL(TSwtPeer aPeer, TInt aType); |
|
137 void PostMobileDeviceEventL(TSwtPeer aPeer, TInt aEventType); |
|
138 void PostTreeEventL(TSwtPeer aPeer, TSwtEventType aType, TInt aItemHandle); |
|
139 void PostLocationChangingEventL(TSwtPeer aPeer, MSwtBrowser& aBrowser, |
|
140 TBool aDoIt, TBool aTop, const TDesC& aLocation, |
|
141 TSwtBrCallBackOperationType aCallBackOperationType); |
|
142 void PostLocationChangedEventL(TSwtPeer aPeer, TBool aDoIt, |
|
143 TBool aTop, const TDesC& aLocation); |
|
144 void PostProgressEventL(TSwtPeer aPeer, TInt current, TInt total); |
|
145 void PostProgressCompletedEventL(TSwtPeer aPeer, TInt current, TInt total); |
|
146 void PostStatusTextEventL(TSwtPeer aPeer, const TDesC& aText); |
|
147 void PostTitleEventL(TSwtPeer aPeer, const TDesC& aTitle); |
|
148 void PostDialogResultEventL(CSwtDialogBroker* aBroker, TSwtPeer aPeer, const TDesC& aDialogResult); |
|
149 void PostDialogResultEventL(CSwtDialogBroker* aBroker, TSwtPeer aPeer, TInt aDialogResult); |
|
150 void PostDialogResultEventL(CSwtDialogBroker* aBroker, TSwtPeer aPeer, TInt aDialogResult1, TInt aDialogResult2, TInt aDialogResult3); |
|
151 void PostCloseEventL(TSwtPeer aPeer, TBool& aDispatched); |
|
152 TInt ApplicationUid(); |
|
153 void SetMobileDevice(MSwtMobileDevice* aMobileDevice); |
|
154 MSwtMobileDevice* MobileDevice(); |
|
155 #ifdef RD_SCALABLE_UI_V2 |
|
156 void TryDetectLongTapL(const TPointerEvent& aPointerEvent); |
|
157 MSwtControl* LongTapAnimationControl() const; |
|
158 void CancelLongTapAnimation(); |
|
159 #endif // RD_SCALABLE_UI_V2 |
|
160 CEikonEnv* CoeEnv() const; |
|
161 CDesC16ArrayFlat* GetFontNamesL(TBool aScalable) const; |
|
162 TBool RevertPointerEvent() const; |
|
163 void SetRevertPointerEvent(TBool aStatus); |
|
164 |
|
165 // From MSwtDevice |
|
166 public: |
|
167 MSwtColor* CreateColorL(const TRgb& aRgbValue) const; |
|
168 TRect Bounds() const; |
|
169 TRect ClientArea() const; |
|
170 TInt Depth() const; |
|
171 TSize Dpi() const; |
|
172 CArrayFixFlat<TSwtFontData>* GetFontListL(const TDesC& aFaceName, |
|
173 TBool aScalable) const; |
|
174 TRgb GetSystemColor(TSwtColorId aId) const; |
|
175 const MSwtFont* GetSystemFont() const; |
|
176 TInt GetDefaultFontHeightL(); |
|
177 |
|
178 // From MSwtBitmapDrawable |
|
179 public: |
|
180 MSwtGc* NewGcL(); |
|
181 CBitmapDevice& GraphicsDevice(); |
|
182 void HandleUpdate(); |
|
183 private: |
|
184 static void DestroyNativeGc(CBitmapContext* aGc); |
|
185 |
|
186 #ifdef RD_SCALABLE_UI_V2 |
|
187 // From MAknLongTapDetectorCallBack |
|
188 public: |
|
189 void HandleLongTapEventL(const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation); |
|
190 #endif |
|
191 |
|
192 // From MSwtPopupMenuCallBack |
|
193 public: |
|
194 void HandlePopupMenuClosedL(); |
|
195 |
|
196 // From MSwtMediaKeysListener |
|
197 public: |
|
198 void HandleMediaKeyEvent(TKeyEvent& aKeyEvent, TInt aEventType); |
|
199 |
|
200 private: |
|
201 TInt LoadResourceFileL(); |
|
202 |
|
203 // Java thread's data |
|
204 protected: |
|
205 // The thread of the Java VM |
|
206 RThread iJavaUiThread; |
|
207 |
|
208 // The event queue, owned, cannot be NULL |
|
209 CSwtEventQueue* iEventQueue; |
|
210 |
|
211 // Our status object used for notification of events |
|
212 TRequestStatus iRequestStatus; |
|
213 |
|
214 // Native thread's data |
|
215 protected: |
|
216 // DLL's factory, owned, cannot be NULL |
|
217 MSwtFactory* iFactory; |
|
218 |
|
219 // The UI utility object, owned, cannot be NULL |
|
220 MSwtUiUtils* iUiUtils; |
|
221 |
|
222 // The Menu arranger, owned, cannot be NULL |
|
223 MSwtMenuArranger* iMenuArranger; |
|
224 |
|
225 // The Command arranger, owned, may be NULL |
|
226 MSwtCommandArranger* iCommandArranger; |
|
227 |
|
228 // The key mapper, owned, cannot be NULL |
|
229 CSwtKeyMapper* iKeyMapper; |
|
230 |
|
231 // The system font, object owned. Null at construction, |
|
232 // allocated at the first SystemFontL() method call. |
|
233 MSwtFont* iSystemFont; |
|
234 |
|
235 // The java side timers that are currently active |
|
236 RPointerArray<CSwtTimer> iTimers; |
|
237 |
|
238 // Registered resource change observers |
|
239 RPointerArray<MSwtResourceChangeObserver> iResourceChangeObservers; |
|
240 |
|
241 // Registered app focus observers |
|
242 RPointerArray<MSwtAppFocusObserver> iAppFocusObservers; |
|
243 |
|
244 // The unique instance of the mobile device |
|
245 MSwtMobileDevice* iMobileDevice; |
|
246 |
|
247 // The listener object for media keys |
|
248 CSwtMIDRemConObserver* iRemConObserver; |
|
249 |
|
250 // The shared object taking care of drawing the Java |
|
251 // content for all controls, owned, cannot be NULL |
|
252 CSwtJavaBufferDrawer* iJavaBufferDrawer; |
|
253 |
|
254 #ifdef RD_SCALABLE_UI_V2 |
|
255 // The long tap detector, cannot be NULL |
|
256 CAknLongTapDetector* iLongTapDetector; |
|
257 |
|
258 // Indicates if a long tap has been detected after the previous EButton1Down event. |
|
259 TBool iLongTapDetected; |
|
260 |
|
261 // The pointer event of type EButton1Down which initiates the long tap |
|
262 TPointerEvent iLongTapPointerEvent; |
|
263 |
|
264 // The control upon which long tap started |
|
265 MSwtControl* iLongTapControl; |
|
266 #endif |
|
267 |
|
268 // Id of the loaded resource file |
|
269 TInt iResId; |
|
270 |
|
271 // Cached Coe env reference. |
|
272 CEikonEnv* iCoeEnv; |
|
273 |
|
274 // Flag for state reverting pointer events. |
|
275 TBool iRevertPointerEvent; |
|
276 |
|
277 #if defined(_DEBUG) && defined(__WINS__) |
|
278 public: |
|
279 TSwtInstanceCounts iInstanceCounts; |
|
280 #endif // defined(_DEBUG) && defined(__WINS__) |
|
281 |
|
282 public: |
|
283 TInt iApplicationUid; |
|
284 }; |
|
285 |
|
286 /** |
|
287 * C++ consructor |
|
288 */ |
|
289 inline ASwtDisplayBase::ASwtDisplayBase() |
|
290 : iResId(KErrNotFound) |
|
291 { |
|
292 } |
|
293 |
|
294 /** |
|
295 * Checks if the current thread is the main thread. |
|
296 */ |
|
297 inline TBool ASwtDisplayBase::IsCurrentThreadJavaUi() const |
|
298 { |
|
299 return (RThread().Id() == iJavaUiThread.Id()); |
|
300 } |
|
301 |
|
302 /** |
|
303 * Awakens the display |
|
304 * Must not be executed from within the AppUi thread, but can be called from |
|
305 * within any Java thread. |
|
306 */ |
|
307 inline void ASwtDisplayBase::Wake() |
|
308 { |
|
309 ASSERT(!IsCurrentThreadNativeUi()); |
|
310 DoWake(EFalse); |
|
311 } |
|
312 |
|
313 /** |
|
314 * Reads the oldest event in the event queue and dispatches it. |
|
315 * Must be executed from within the main thread. |
|
316 * @return EFalse if the caller can sleep upon return; ETrue otherwise. |
|
317 */ |
|
318 inline TBool ASwtDisplayBase::ReadAndDispatch(JNIEnv& aJniEnv) |
|
319 { |
|
320 ASSERT(IsCurrentThreadJavaUi()); |
|
321 return iEventQueue->PopAndDispatch(aJniEnv); |
|
322 } |
|
323 |
|
324 /** |
|
325 * Reads paint events in the event queue and dispatches it. |
|
326 * Must be executed from within the main thread. |
|
327 * @param aPeer If equals NULL then all paint events of all control are dispatch |
|
328 * otherwise only the paint event of the Control correspondent to Peer was dispatched. |
|
329 */ |
|
330 inline void ASwtDisplayBase::PopAndDispatchPaintEvents(JNIEnv& aJniEnv, MSwtControl* aSwtControl) |
|
331 { |
|
332 ASSERT(IsCurrentThreadJavaUi()); |
|
333 iEventQueue->PopAndDispatchPaintEvents(aJniEnv, aSwtControl); |
|
334 } |
|
335 |
|
336 /** |
|
337 * Informs the Display that a Java object has been disposed of (i.e. its |
|
338 * C++ counterpart has been destroyed). |
|
339 * Must be executed from within the main thread. |
|
340 * @param aPeer The Java object that has been disposed of. |
|
341 */ |
|
342 inline void ASwtDisplayBase::PeerDisposed(TSwtPeer aPeer) |
|
343 { |
|
344 ASSERT(IsCurrentThreadJavaUi()); |
|
345 iEventQueue->PeerDisposed(aPeer); |
|
346 } |
|
347 |
|
348 /** |
|
349 * Returns the event queue |
|
350 */ |
|
351 inline CSwtEventQueue* ASwtDisplayBase::EventQueue() const |
|
352 { |
|
353 return iEventQueue; |
|
354 } |
|
355 |
|
356 /** |
|
357 * Returns the shared object taking care of drawing the Java content for all controls. |
|
358 */ |
|
359 inline CSwtJavaBufferDrawer& ASwtDisplayBase::JavaBufferDrawer() |
|
360 { |
|
361 return *iJavaBufferDrawer; |
|
362 } |
|
363 |
|
364 #endif // SWTDISPLAYBASE_H |