|
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 SWTCONTROLBASE_H |
|
14 #define SWTCONTROLBASE_H |
|
15 |
|
16 |
|
17 #include <AknsFrameBackgroundControlContext.h> |
|
18 #include "eswtwidgetscore.h" |
|
19 |
|
20 |
|
21 class CSwtUiUtils; |
|
22 class CAknsBasicBackgroundControlContext; |
|
23 |
|
24 |
|
25 /** |
|
26 * ASwtControlBase |
|
27 * Abstract helper base class for implementing MSwtControl |
|
28 * @lib eswt |
|
29 */ |
|
30 class ASwtControlBase |
|
31 : public MSwtControl |
|
32 , public MCoeControlBackground |
|
33 { |
|
34 // Data types |
|
35 protected: |
|
36 enum TKeyScanCode |
|
37 { |
|
38 // CBA key scan codes |
|
39 EStdKeyCba1 = EStdKeyDevice0, |
|
40 EStdKeyCba2 = EStdKeyDevice1, |
|
41 EStdKeyCba3 = EStdKeyDevice2, |
|
42 EStdKeyCba4 = EStdKeyDevice3, |
|
43 |
|
44 // Rocker key scan codes |
|
45 EStdKeyRockerLeft = EStdKeyDevice6, |
|
46 EStdKeyRockerRight = EStdKeyDevice7, |
|
47 EStdKeyRockerUp = EStdKeyDevice8, |
|
48 EStdKeyRockerDown = EStdKeyDevice9, |
|
49 EStdKeyRockerMiddle = EStdKeyDeviceA |
|
50 }; |
|
51 |
|
52 enum |
|
53 { |
|
54 ECtrlFuncShiftMask = EModifierCtrl | EModifierFunc | EModifierShift |
|
55 }; |
|
56 |
|
57 // Own methods |
|
58 public: |
|
59 /** |
|
60 * Clips given rectangle to rectangle which can be fully visible in |
|
61 * its parent. Other controls in the same parent are not taken |
|
62 * into account. |
|
63 * @param aRect Rectangle to be clipped |
|
64 * @return Clipped rectangle |
|
65 */ |
|
66 TRect ClipToVisibleRect(const TRect& aRect) const; |
|
67 |
|
68 /** |
|
69 * Provide the Skin background. |
|
70 * Should be called by the MopSupplyObject of all implementeded controls. |
|
71 */ |
|
72 IMPORT_C TTypeUid::Ptr SwtMopSupplyObject(TTypeUid aId); |
|
73 |
|
74 MAknsControlContext* SwtMopSupplyCtrlContext(TBool aBeginSearchToThis = ETrue) const; |
|
75 |
|
76 /** |
|
77 * Set up a clipping region for a Composite not to draw the areas that will be |
|
78 * drawn by its children. This should be done by Composites to avoid flickering. |
|
79 * This function operates in window coordinates. You can use aOffset to convert |
|
80 * the region into client area coordinates for instance: aOffset = -ClientArea().iTl |
|
81 * or to screen coordinates: aOffset = +Window().Position() |
|
82 * |
|
83 * @param aComposite The composite to set the clipping region for |
|
84 * @param aGc The GC to set the clipping region to (that will be used by |
|
85 * the composite to draw) |
|
86 * @param aDrawRect The target drawing rectangle where drawing is about to be done into. |
|
87 * @param aOffset Optional offset. Used to move the whole region. |
|
88 * @return RRegion pointer to clipping region or null if clipping region was not set. |
|
89 * Caller owns the returned RRegion. It should be freed by calling |
|
90 * CancelChildClippingRegion after drawing is complete. |
|
91 */ |
|
92 RRegion* SetupChildClippingRegion(const MSwtComposite* aComposite, |
|
93 CWindowGc& aGc, |
|
94 const TRect& aDrawRect, |
|
95 const TPoint& aOffset = TPoint(0, 0)) const; |
|
96 |
|
97 /** |
|
98 * Helper to appropriately cancel and free the clipping region set by a call to |
|
99 * SetupChildClippingRegion. |
|
100 * |
|
101 * @param aClippingRegion The RRegion pointer obtained from SetupChildClippingRegion |
|
102 * @param aGc The GC that was passed to SetupChildClippingRegion |
|
103 */ |
|
104 void CancelChildClippingRegion(RRegion* aClippingRegion, CWindowGc& aGc) const; |
|
105 |
|
106 // Own methods |
|
107 protected: |
|
108 IMPORT_C ASwtControlBase(MSwtDisplay& aDisplay, TSwtPeer aPeer, |
|
109 MSwtComposite* aParent, TInt aStyle); |
|
110 |
|
111 IMPORT_C virtual ~ASwtControlBase(); |
|
112 |
|
113 /** |
|
114 * Needs to be called by all children from their NewL(), after ConstructL(). |
|
115 * Initialize this Object. |
|
116 */ |
|
117 void InitControlBaseL(); |
|
118 |
|
119 /** |
|
120 * Get the focus background of the Control at a certain moment in time. |
|
121 */ |
|
122 IMPORT_C CAknsBasicBackgroundControlContext* FocusBackgroundNow() const; |
|
123 |
|
124 /** |
|
125 * Trigger focus background redraw. |
|
126 */ |
|
127 void RedrawFocusBackground(); |
|
128 |
|
129 /** |
|
130 * Checks if this controls should display a border / frame in case of Shells. |
|
131 */ |
|
132 TBool HasBorderStyle() const; |
|
133 |
|
134 /** |
|
135 * Returns the size difference between the inner and outer rectangles of the border. |
|
136 */ |
|
137 TSize BorderSizeDelta() const; |
|
138 |
|
139 /** |
|
140 * Get rect inside the borders. |
|
141 */ |
|
142 IMPORT_C virtual TRect BorderInnerRect() const; |
|
143 |
|
144 /** |
|
145 * Add the borders size to a rect. |
|
146 */ |
|
147 IMPORT_C virtual TRect BorderOuterRect(const TRect& aRect) const; |
|
148 |
|
149 IMPORT_C virtual void DrawBorder(const TRect& aRect) const; |
|
150 |
|
151 /** |
|
152 * Invalidates the specified area if the control is visible. |
|
153 * Window coordinates. |
|
154 * @param aRect The area to invalidate |
|
155 */ |
|
156 void Invalidate(const TRect& aRect); |
|
157 |
|
158 /** |
|
159 * Invalidates the specified area if the control is visible. |
|
160 * Window coordinates. |
|
161 * @param aRect The area to invalidate |
|
162 */ |
|
163 void ForceInvalidate(const TRect& aRect); |
|
164 |
|
165 /** |
|
166 * Needs to be called by all children from their FocusChanged(TDrawNow). |
|
167 * Performs common focus change tasks. |
|
168 */ |
|
169 IMPORT_C void HandleFocusChanged(TDrawNow aDrawNow); |
|
170 void FocusabilityChanged(); |
|
171 TKeyResponse HandleKeyL(const TKeyEvent& aKeyEvent, TEventCode aType, TBool aTraversalDoIt); |
|
172 TKeyResponse OfferKeyEventToCommandAndMenuArrangersL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
173 TKeyResponse OfferKeyEventToTabGroupL(const TKeyEvent& aKeyEvent,TEventCode aType); |
|
174 |
|
175 /** |
|
176 * Register this <code>Control</code> with its parent <code>Composite</code> |
|
177 * |
|
178 * This method must <b>not</b> be called from within <code>ContructL()</code> |
|
179 * but from within <code>NewL()</code> <b>after</b> <code>ConstructL()</code> |
|
180 * has been called. Failure in doing so may result in objects registering with |
|
181 * their parents before being fully constructed. |
|
182 */ |
|
183 IMPORT_C void RegisterWithParentL(); |
|
184 inline const MSwtFont* Font() const; |
|
185 |
|
186 /** |
|
187 * Converts a point from client to window coordinates |
|
188 */ |
|
189 TPoint ClientToWindow(const TPoint& aPoint) const; |
|
190 |
|
191 /** |
|
192 * Converts a rectangle from client to window coordinates |
|
193 */ |
|
194 TRect ClientToWindow(const TRect& aRect) const; |
|
195 |
|
196 /** |
|
197 * Converts a point from window to client coordinates |
|
198 */ |
|
199 TPoint WindowToClient(const TPoint& aPoint) const; |
|
200 |
|
201 IMPORT_C virtual const MSwtFont& DefaultFont() const; |
|
202 IMPORT_C virtual void DoPaint(const TRect& aRect) const; |
|
203 IMPORT_C void SetColorL(TLogicalColor aLogicalColor, const MSwtColor* aColor); |
|
204 IMPORT_C CSwtUiUtils& UiUtils() const; |
|
205 |
|
206 /** |
|
207 * Called just before dispose() ends. |
|
208 */ |
|
209 IMPORT_C virtual void DoDelete(); |
|
210 |
|
211 /** |
|
212 * Needs to be called by all inheritors from their SizeChanged(). |
|
213 */ |
|
214 IMPORT_C void HandleSizeChanged(); |
|
215 |
|
216 /** |
|
217 * Needs to be called by all inheritors from their PositionChanged(). |
|
218 */ |
|
219 IMPORT_C void HandlePositionChanged(); |
|
220 |
|
221 /** |
|
222 * Draws the non-window-owning component controls of the specified control |
|
223 * The GC must have already been activated. |
|
224 */ |
|
225 static void DrawComponentControls(const CCoeControl& aControl, |
|
226 const TRect& aRect, CWindowGc& aGc, TBool aCanDrawOutsideRect); |
|
227 |
|
228 static TBool RectContainsRect(const TRect& aContainer, const TRect& aContainee); |
|
229 |
|
230 /** |
|
231 * Flushes the given gc operations to the given gc. |
|
232 */ |
|
233 void FlushJavaBuffer(MSwtGc* aGc,TInt* aIntParams, TInt aIntCount, HBufC* aStrParams, RWindow* aWindow, const TRect& aDrawRect) const; |
|
234 |
|
235 /** |
|
236 * Check if compound control focused or one of the children focused. |
|
237 */ |
|
238 TBool IsFocusedOrChildIsFocused() const; |
|
239 |
|
240 /** |
|
241 * Check if one of the children is focused. |
|
242 */ |
|
243 TBool ChildIsFocused() const; |
|
244 |
|
245 /** |
|
246 * Same as SetFontL but without redraw. |
|
247 */ |
|
248 void DoSetFontL(const MSwtFont* aFont); |
|
249 |
|
250 /** |
|
251 * Same as SetBackgroundL but without redraw. |
|
252 */ |
|
253 void DoSetBackgroundL(const MSwtColor* aColor); |
|
254 |
|
255 /** |
|
256 * Same as SetForegroundL but without redraw. |
|
257 */ |
|
258 void DoSetForegroundL(const MSwtColor* aColor); |
|
259 |
|
260 private: |
|
261 /** |
|
262 * Computes the location a control must be set to |
|
263 * This method is not intended to be used with <code>Shell</code>s. |
|
264 * @return The control's new location in window coordinates |
|
265 * @param aLocation The control's new location relative to its parent. |
|
266 */ |
|
267 TPoint ComputeLocationToSet(const TPoint& aLocation); |
|
268 |
|
269 /** |
|
270 * Convert a point from window coordinates to screen coordinates |
|
271 */ |
|
272 TPoint WindowToScreen(const TPoint& aPoint) const; |
|
273 TBool ParentHasDoNotDrawFlag(); |
|
274 |
|
275 /** |
|
276 * Method for sending two key events instead of one key event. Used for emulation of diagonal keys |
|
277 */ |
|
278 TKeyResponse HandleDiagonalKeysL(const TKeyEvent& aKeyEvent, TEventCode aType, |
|
279 TBool aTraversalDoIt, const TUint key1, const TStdScanCode scanCode1, |
|
280 const TUint key2, const TStdScanCode scanCode2); |
|
281 |
|
282 void CreateFocusBackgroundL(); |
|
283 |
|
284 /** |
|
285 * Common tasks for size and location changes. |
|
286 */ |
|
287 void HandleRectChanged(); |
|
288 |
|
289 // From MCoeControlBackground |
|
290 public: |
|
291 IMPORT_C void Draw(CWindowGc& aGc, const CCoeControl& aControl, const TRect& aRect) const; |
|
292 |
|
293 // From MSwtDrawable |
|
294 public: |
|
295 IMPORT_C MSwtGc* NewGcL(); |
|
296 IMPORT_C CBitmapDevice& GraphicsDevice(); |
|
297 IMPORT_C void HandleUpdate(); |
|
298 static void DestroyNativeGc(CBitmapContext* aGc); |
|
299 |
|
300 // From MSwtControl |
|
301 public: |
|
302 IMPORT_C TRect ClientRect() const; |
|
303 IMPORT_C TSwtPeer Dispose(); |
|
304 IMPORT_C TSwtPeer JavaPeer() const; |
|
305 IMPORT_C TUint Flags() const; |
|
306 IMPORT_C void Paint(const TRect& aRect, |
|
307 TBool aPaintNatively = ETrue, |
|
308 MSwtGc* aGc = NULL, |
|
309 TInt* aIntParams = NULL, |
|
310 TInt aIntCount = 0, |
|
311 HBufC* aStrParams = NULL) const; |
|
312 IMPORT_C void PaintUrgently(const TRect& aRect, TBool aInitDraw = ETrue) const; |
|
313 IMPORT_C TBool IsPaintingUrgently() const; |
|
314 IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent); |
|
315 IMPORT_C TBool IsFocusable(TInt aReason = KSwtFocusByApi) const; |
|
316 IMPORT_C TBool SetSwtFocus(TInt aReason = KSwtFocusByApi); |
|
317 IMPORT_C TInt FocusBackgroundPolicy() const; |
|
318 IMPORT_C TInt PressBackgroundPolicy() const; |
|
319 IMPORT_C TBool GetEnabled() const; |
|
320 IMPORT_C TBool GetVisible() const; |
|
321 IMPORT_C TBool GetVisibleRecursively() const; |
|
322 IMPORT_C TRect GetBounds() const; |
|
323 IMPORT_C TInt GetBorderWidth() const; |
|
324 IMPORT_C TBool IsDefaultBackgroundUse() const; |
|
325 IMPORT_C MAknsControlContext* GetControlContext() const; |
|
326 IMPORT_C TRgb GetBackground() const; |
|
327 IMPORT_C TRgb GetForeground() const; |
|
328 IMPORT_C void SetBackgroundL(const MSwtColor* aColor); |
|
329 IMPORT_C void SetForegroundL(const MSwtColor* aColor); |
|
330 IMPORT_C const MSwtFont* GetFont() const; |
|
331 IMPORT_C TPoint GetLocation() const; |
|
332 IMPORT_C const MSwtMenu* GetPopupMenu() const; |
|
333 IMPORT_C const MSwtMenu* GetControlMenu() const; |
|
334 IMPORT_C MSwtComposite* GetParent() const; |
|
335 IMPORT_C TBool IsDescentOf(const MSwtControl& aParent) const; |
|
336 IMPORT_C MSwtShell& GetShell() const; |
|
337 IMPORT_C MSwtShell& GetTopShell() const; |
|
338 IMPORT_C MSwtCaptionedControl* GetNearestCaptionedControl(TBool aIncludeSelf = ETrue) const; |
|
339 IMPORT_C TSize GetWidgetSize() const; |
|
340 IMPORT_C void SetWidgetSize(const TSize& aSize); |
|
341 IMPORT_C TBool IsFocusControl(); |
|
342 IMPORT_C void MoveAbove(const MSwtControl* aControl); |
|
343 IMPORT_C void MoveBelow(const MSwtControl* aControl); |
|
344 IMPORT_C void Redraw(); |
|
345 IMPORT_C void RedrawRegion(const TRect& aRect); |
|
346 IMPORT_C void SetRedraw(TBool aRedraw); |
|
347 IMPORT_C void SetFontL(const MSwtFont* aFont); |
|
348 IMPORT_C void SetVisible(TBool aVisible); |
|
349 IMPORT_C void SetLocation(const TPoint& aPoint); |
|
350 IMPORT_C void SetEnabled(TBool aEnabled); |
|
351 IMPORT_C void SetBounds(const TRect& aRect); |
|
352 IMPORT_C void SetPopupMenuL(const MSwtMenu* aMenu); |
|
353 IMPORT_C void SetCapture(TBool aCapture); |
|
354 IMPORT_C TInt Style() const; |
|
355 IMPORT_C void Update() const; |
|
356 IMPORT_C void ComputeTabListL(RSwtControlArray& aList); |
|
357 IMPORT_C TPoint ToControl(const TPoint& aPoint) const; |
|
358 IMPORT_C TPoint ToDisplay(const TPoint& aPoint) const; |
|
359 IMPORT_C TBool CbaButtonIsUsed(TInt aCbaButtonIndex) const; |
|
360 IMPORT_C TBool IsKeyUsed(TUint aKeyCode) const; |
|
361 IMPORT_C TBool MSKSelCmdEnabled() const; |
|
362 IMPORT_C HBufC* MSKLabelL() const; |
|
363 IMPORT_C TBool ForceTraverseEvent(TSwtTraversal aDetail, TBool aDoIt); |
|
364 IMPORT_C void AddToControlStackL(TInt aPriority); |
|
365 IMPORT_C void RemoveFromControlStack(); |
|
366 IMPORT_C TBool IsOnControlStack() const; |
|
367 IMPORT_C void UpdateDoNotDrawFlag(); |
|
368 IMPORT_C TBool HasDoNotDrawFlag() const; |
|
369 void HideSilently() {}; |
|
370 void ShowSilently() {}; |
|
371 TBool HiddenSilently() const |
|
372 { |
|
373 return GetShell().Control()->HiddenSilently(); |
|
374 }; |
|
375 IMPORT_C TBool IsLongTapAnimationCandidate(const TPointerEvent& aPointerEvent) const; |
|
376 IMPORT_C void DoControlSpecificFeedback(const TBool& aFirstTap, |
|
377 const TBool& aTappedToChildRect, |
|
378 const TPointerEvent& aPointerEvent) const; |
|
379 IMPORT_C void PostMouseEventL(const TPointerEvent& aPointerEvent); |
|
380 IMPORT_C void EnableFocusHighlight(TBool aEnable); |
|
381 IMPORT_C TRect VisibleRect(TBool aVisibleBounds = EFalse) const; |
|
382 IMPORT_C void SetHighlight(TBool aEnabled); |
|
383 IMPORT_C TBool HasHighlight(TBool aIncludingParents = ETrue) const; |
|
384 IMPORT_C void HandleHighlightChange(); |
|
385 TInt Pressed() const |
|
386 { |
|
387 return iPressed; |
|
388 }; |
|
389 IMPORT_C void PrepareForTraverse(); |
|
390 |
|
391 protected: |
|
392 MSwtDisplay& iDisplay; |
|
393 const TSwtPeer iPeer; // The Java peer object |
|
394 MSwtComposite* const iParent; // The parent control, not owned, may be NULL if we are a Shell |
|
395 mutable MSwtShell* iShell; // The first Shell parent up the parent tree. |
|
396 TUint iCtrlFlags; // Misc. flags |
|
397 TInt iStyle; // The SWT style |
|
398 const MSwtFont* iFont; // The font used in the control, may be NULL, ref counted. |
|
399 const MSwtMenu* iPopupMenu; // The popup menu of the control, may be NULL, not owned. |
|
400 TBool iIsOnControlStack; // True if this control is currently on the AppUi's Control Stack (needed by TextBase to be FEP aware). |
|
401 TInt iStackedSetRedrawFalseNb; // The number of setRedraw(true) must be equal to the number of setRedraw(false) to allow drawing |
|
402 TBool iBackgrdDefaultUsed; |
|
403 CAknsFrameBackgroundControlContext* iFocusFrame; // Frame context used to draw focus highlight background. |
|
404 TBool iTraverse; // True when a keypress causes traversing |
|
405 TPoint iPrevSwtPos; // Used by HandleSizeChanged and HandlePositionChanged only |
|
406 TPoint iPrevCoePos; // Used by HandleSizeChanged and HandlePositionChanged only |
|
407 TSize iPrevCoeSize; // Used by HandleSizeChanged and HandlePositionChanged only |
|
408 |
|
409 // True if control changed its focus. |
|
410 // Currently used for advanced tactile feedback. |
|
411 TBool iFocusChanged; |
|
412 |
|
413 /** |
|
414 * Control pressed by pointer. |
|
415 */ |
|
416 TInt iPressed; |
|
417 |
|
418 /** |
|
419 * If this is true, the control should draw a highlight |
|
420 * either because it is pressed or focused. |
|
421 */ |
|
422 TBool iHighlightEnabled; |
|
423 }; |
|
424 |
|
425 |
|
426 inline const MSwtFont* ASwtControlBase::Font() const |
|
427 { |
|
428 return iFont; |
|
429 } |
|
430 |
|
431 |
|
432 #endif // SWTCONTROLBASE_H |