1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef __COECNTRL_H__
17 #define __COECNTRL_H__
30 #include <coetextdrawer.h>
31 #include <coecontrolarray.h>
33 #include <coecoloruse.h> // class TCoeColorUse
35 class TResourceReader;
37 class MCoeControlContext;
38 class RCoeDynamicDataStorage;
40 class MCoeLayoutManager;
41 class TCoeZoomWithType;
42 class CCoeFontProvider;
44 // forward declarations.
46 class CCoeTextDrawerBase;
48 /** Interface to be used if a control elects to be a background drawer.
50 Parent controls can elect to take responsibility for drawing the background for their child
51 controls. To achieve this, they should aggregate an object that implements this interface.
52 CCoeControl::SetBackground() accepts the object and sets it as the background drawer
54 @see CCoeControl::EnableWindowTransparency()
58 class MCoeControlBackground
61 /** Draw the background for a given control.
62 The text drawer that shall be used to draw text on the specific background can be
63 fetched through the GetTextDrawer() method.
65 @param aGc Graphics context used for drawing
66 @param aControl The control being drawn (may be a child of the drawer)
67 @param aRect The area to be redrawn
72 virtual void Draw(CWindowGc& aGc, const CCoeControl& aControl, const TRect& aRect) const = 0;
74 This function retrieves the text drawer associated with the background.
75 @param aTextDrawer The text drawer associated with the background. This may be null. The default implementation
76 always sets this to 0.
77 @param aDrawingControl The control that is requesting the text drawer.
79 IMPORT_C virtual void GetTextDrawer(CCoeTextDrawerBase*& aTextDrawer, const CCoeControl* aDrawingControl) const;
81 IMPORT_C MCoeControlBackground();
83 IMPORT_C virtual void MCoeControlBackground_Reserved1();
84 IMPORT_C virtual void MCoeControlBackground_Reserved2();
85 IMPORT_C virtual void MCoeControlBackground_Reserved3();
86 IMPORT_C virtual void MCoeControlBackground_Reserved4();
87 IMPORT_C virtual void MCoeControlBackground_Reserved5();
89 TInt iMCoeControlBackground_Reserved1();
92 /** Abstract interface for defining a control's hit region.
94 This could be implemented by a CCoeControl-derived class to
95 define hit region checking. The object is installed by calling CCoeControl::SetHitTest().
97 The hit region is the area inside the control's rectangle in which pointer events are handled.
98 It can be any shape, not necessarily rectangular.
103 class MCoeControlHitTest
106 /** Tests whether a pointer event occurred inside the control's hit region.
107 This function is called by CCoeControl::HandlePointerEventL().
109 @param aPoint The position of the pointer event.
110 @return ETrue if the specified point lies inside the hit region, EFalse if not.
115 virtual TBool HitRegionContains(const TPoint& aPoint, const CCoeControl& aControl) const = 0;
117 IMPORT_C MCoeControlHitTest();
119 IMPORT_C virtual void MCoeControlHitTest_Reserved1();
120 IMPORT_C virtual void MCoeControlHitTest_Reserved2();
122 TInt iMCoeControlHitTest_Reserved1;
127 Control base class from which all other controls are derived.
132 class CCoeControl : public CBase, public MObjectProvider
137 EAbsoluteZoom, // absolute
138 ERelativeZoom // relative to parent's zoom
141 // Construction and destruction
142 IMPORT_C CCoeControl();
143 IMPORT_C CCoeControl(CCoeEnv* aCoeEnv);
144 IMPORT_C ~CCoeControl();
145 IMPORT_C TBool ComponentArrayExists() const;
146 public: // Virtuals (see more related non-virtuals further down)
148 IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
150 IMPORT_C virtual void MakeVisible(TBool aVisible);
151 IMPORT_C virtual void SetDimmed(TBool aDimmed);
153 IMPORT_C virtual void SetContainerWindowL(const CCoeControl& aContainer);
154 IMPORT_C virtual void ConstructFromResourceL(TResourceReader& aReader);
155 IMPORT_C virtual void ActivateL();
157 IMPORT_C virtual void PrepareForFocusLossL();
158 IMPORT_C virtual void PrepareForFocusGainL();
160 IMPORT_C virtual void SetAdjacent(TInt aAdjacent);
161 IMPORT_C virtual void SetNeighbor(CCoeControl* aNeighbor);
162 IMPORT_C virtual TBool HasBorder() const; // deprecated from 9.2
164 IMPORT_C virtual TSize MinimumSize();
165 // Resource change handling
166 IMPORT_C virtual void HandleResourceChange(TInt aType);
167 // Logical color use (for Java)
168 IMPORT_C virtual void GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) const;
170 IMPORT_C virtual void GetHelpContext(TCoeHelpContext& aContext) const;
172 IMPORT_C virtual TCoeInputCapabilities InputCapabilities() const;
175 inline CCoeEnv* ControlEnv() const;
177 IMPORT_C RDrawableWindow* DrawableWindow() const;
178 IMPORT_C TBool OwnsWindow() const;
179 IMPORT_C TBool IsBackedUp() const;
180 IMPORT_C void SetContainerWindowL(RWindow& aWindow); // deprecated from 9.2
181 IMPORT_C void SetContainerWindowL(RBackedUpWindow& aWindow); // deprecated from 9.2
183 IMPORT_C CCoeControl* Parent();
184 IMPORT_C const CCoeControl* Parent() const;
185 IMPORT_C virtual TInt SetParent(CCoeControl* aParent);
187 IMPORT_C TRect Rect() const;
188 IMPORT_C void SetRect(const TRect& aRect);
189 IMPORT_C void SetExtent(const TPoint& aPosition,const TSize& aSize);
190 IMPORT_C void SetExtentToWholeScreen();
191 IMPORT_C TSize Size() const;
192 IMPORT_C void SetSize(const TSize& aSize);
193 IMPORT_C TPoint Position() const;
194 IMPORT_C TPoint PositionRelativeToScreen() const;
195 IMPORT_C void SetPosition(const TPoint& aPosition);
196 IMPORT_C TInt MaximumWidth() const;
197 IMPORT_C TInt SetMaximumWidth(TInt aMaxWidth);
199 IMPORT_C MCoeLayoutManager* LayoutManager() const;
200 IMPORT_C virtual void SetLayoutManagerL(MCoeLayoutManager* aLayout);
201 IMPORT_C virtual TBool RequestRelayout(const CCoeControl* aChildControl);
203 IMPORT_C TBool IsVisible() const;
204 IMPORT_C void SetComponentsToInheritVisibility(TBool aInherit=ETrue);
206 IMPORT_C TBool IsDimmed() const;
208 IMPORT_C void SetObserver(MCoeControlObserver* aObserver);
209 IMPORT_C MCoeControlObserver* Observer() const;
211 IMPORT_C TBool IsFocused() const;
212 IMPORT_C void SetFocus(TBool aFocus,TDrawNow aDrawNow=ENoDrawNow);
213 IMPORT_C void SetNonFocusing();
214 IMPORT_C void SetFocusing(TBool aFocusing);
215 IMPORT_C TBool IsNonFocusing() const;
216 // Drawing (see also Draw() below)
217 IMPORT_C void DrawNow() const;
218 IMPORT_C void DrawNow(const TRect &aRect) const;
219 IMPORT_C void DrawDeferred() const;
220 IMPORT_C CWindowGc& SystemGc() const;
221 IMPORT_C TInt SetCustomGc(CWindowGc* aGraphicsContext);
222 IMPORT_C CWindowGc* CustomGc() const;
223 // Control context (background color etc). Deprecated (use MCoeControlBackground)
224 IMPORT_C void SetControlContext(MCoeControlContext* aContext); // deprecated from 9.2
225 IMPORT_C void CopyControlContextFrom(const CCoeControl* aControl); // deprecated from 9.2
226 IMPORT_C MCoeControlContext* ControlContext() const; // deprecated from 9.2
228 IMPORT_C void SetPointerCapture(TBool aCapture=ETrue);
229 IMPORT_C void ClaimPointerGrab(TBool aSendUpEvent=ETrue);
230 IMPORT_C void IgnoreEventsUntilNextPointerUp();
231 IMPORT_C void SetGloballyCapturing(TBool aGlobal);
233 IMPORT_C TInt SetHitTest(const MCoeControlHitTest* aHitTestControl);
234 IMPORT_C const MCoeControlHitTest* HitTest() const;
236 IMPORT_C void OverrideColorL(TInt aLogicalColor,TRgb aColor);
237 IMPORT_C TBool GetColor(TInt aLogicalColor,TRgb& aColor) const;
238 // Control background
239 IMPORT_C void DrawBackground(const TRect& aRect) const;
240 IMPORT_C void DrawForeground(const TRect& aRect) const;
241 IMPORT_C const MCoeControlBackground* Background() const;
242 IMPORT_C const MCoeControlBackground* FindBackground() const;
243 IMPORT_C void SetBackground(const MCoeControlBackground* aBackground);
245 IMPORT_C void SetZoomFactorL(TInt aZoomFactor, TZoomType aZoomType = ERelativeZoom);
246 IMPORT_C TZoomFactor AccumulatedZoom() const;
247 IMPORT_C const TCoeZoomWithType* ZoomWithType() const;
248 // Font provider (see ScreenFont() below)
249 IMPORT_C const CCoeFontProvider& FindFontProvider() const;
250 IMPORT_C void SetFontProviderL(const CCoeFontProvider& aFontProvider);
251 // Text baseline (virtuals)
252 IMPORT_C virtual TInt TextBaselineOffset(const TSize& aSize) const;
253 IMPORT_C virtual void SetTextBaselineSpacing(TInt aSpacing);
254 // Input capabilities
255 IMPORT_C TCoeInputCapabilities RecursivelyMergedInputCapabilities() const;
257 IMPORT_C void SetMopParent(MObjectProvider* aParent);
258 // Instance identification
259 IMPORT_C TInt UniqueHandle() const;
260 IMPORT_C TInt SetUniqueHandle(TInt aUniqueHandle);
261 public: // Pointer events (virtuals)
262 IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
263 protected: // Virtuals. Override to handle these events.
264 IMPORT_C virtual void HandlePointerBufferReadyL(); // See HandlePointerEventL()
266 IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
267 // Change of size and position
268 IMPORT_C virtual void SizeChanged();
269 IMPORT_C virtual void PositionChanged();
271 // Component control access
272 IMPORT_C virtual TInt CountComponentControls() const;
273 IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;
274 IMPORT_C TInt Index(const CCoeControl* aControl) const;
277 IMPORT_C TBool IsActivated() const;
278 IMPORT_C TBool IsBeingDestroyed() const;
279 // Component ownership
280 IMPORT_C void InitComponentArrayL();
281 IMPORT_C CCoeControlArray& Components();
282 IMPORT_C const CCoeControlArray& Components() const;
284 IMPORT_C RWindow& Window() const;
285 IMPORT_C RBackedUpWindow& BackedUpWindow() const;
286 IMPORT_C void CloseWindow();
287 IMPORT_C void CreateWindowL();
288 IMPORT_C void CreateWindowL(const CCoeControl* aParent);
289 IMPORT_C void CreateWindowL(RWindowTreeNode& aParent);
290 IMPORT_C void CreateWindowL(RWindowGroup* aParent);
291 IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent);
292 IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent,TDisplayMode aDisplayMode);
293 IMPORT_C void EnableWindowTransparency();
295 IMPORT_C void SetCornerAndSize(TGulAlignment aCorner,const TSize& aSize);
296 IMPORT_C void SetSizeWithoutNotification(const TSize& aSize);
298 IMPORT_C const CFont& ScreenFont(const TCoeFont& aFont) const;
300 IMPORT_C CCoeTextDrawerBase& TextDrawer(TInt aKey = KErrNotFound) const;
302 IMPORT_C void EnableDragEvents();
303 IMPORT_C void HandleRedrawEvent(const TRect& aRect) const;
304 IMPORT_C void SetAllowStrayPointers();
305 IMPORT_C CCoeControl* GrabbingComponent() const;
306 IMPORT_C TBool CapturesPointer() const;
308 IMPORT_C TBool IsReadyToDraw() const;
309 IMPORT_C TBool IsBlank() const;
310 IMPORT_C void SetBlank();
311 IMPORT_C void SetCanDrawOutsideRect();
312 IMPORT_C void ActivateGc() const;
313 IMPORT_C void DeactivateGc() const;
314 IMPORT_C void ResetGc() const;
316 IMPORT_C void ReportEventL(MCoeControlObserver::TCoeEvent aEvent);
318 IMPORT_C void HandleComponentControlsResourceChange(TInt aType);
319 // Copy Constructor and Assignment Operator
320 inline CCoeControl(const CCoeControl& aControl);
321 inline CCoeControl& operator=(const CCoeControl& aControl);
323 friend class CCoeControlArray;
324 IMPORT_C virtual void HandleControlArrayEventL(CCoeControlArray::TEvent aEvent, const CCoeControlArray* aArray, CCoeControl* aControl, TInt aControlId);
326 IMPORT_C virtual void Reserved_CCoeControl_10();
327 IMPORT_C virtual void Reserved_CCoeControl_11();
328 IMPORT_C virtual void Reserved_CCoeControl_12();
329 IMPORT_C virtual void Reserved_CCoeControl_13();
331 IMPORT_C virtual void GetTextDrawer(CCoeTextDrawerBase*& aTextDrawer, const CCoeControl* aDrawingControl, TInt aKey) const;
333 IMPORT_C virtual void Reserved_CCoeControl_8();
334 IMPORT_C virtual void Reserved_CCoeControl_9();
335 protected: // from MObjectProvider
336 IMPORT_C TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
337 private: // from MObjectProvider
338 IMPORT_C MObjectProvider* MopNext();
340 // Drawing (override this to draw)
341 IMPORT_C virtual void Draw(const TRect& aRect) const;
344 IMPORT_C virtual void WriteInternalStateL(RWriteStream& aWriteStream) const;
346 IMPORT_C virtual void Reserved_2();
347 public: // but not exported
348 void ProcessPointerEventL(const TPointerEvent& aPointerEvent);
349 void ProcessPointerBufferReadyL();
350 void RecursivelyMergeInputCapabilities(TCoeInputCapabilities& aInputCapabilities) const;
351 void WriteInternalStateNowL(RWriteStream& aWriteStream) const;
352 void NotifyFontChange(const CCoeFontProvider* aFontProvider);
353 void RemoveFromParent();
354 void RefetchPixelMappingL();
355 public: // deprecated
356 inline TInt SetGc(CWindowGc* aGraphicsContext) const;
357 inline CWindowGc* GetGc() const;
359 friend class CCoeRedrawer;
360 void DrawComponents(const TRect& aRect) const;
361 void DrawWindowOwningComponentsNow() const;
362 void DrawWindowOwningComponentsNow(const TRect &aRect) const;
363 void SetGrabbed(TBool aGrabbed);
364 TBool IsGrabbed() const;
365 void DoMakeVisible(TBool aVisible);
366 void CheckPointerEventPurge() const;
367 void RecursivelyMergeTextDrawers(CCoeTextDrawerBase*& aTextDrawer, const CCoeControl* aDrawingControl, TInt aKey) const;
368 CCoeControl* WindowOwningParent();
369 const CCoeControl* WindowOwningParent() const { return const_cast<CCoeControl*>(this)->WindowOwningParent(); }
370 const CCoeControl* SearchParent(const CCoeControl* aParentToFind) const;
371 TInt SetZoomWithType(TCoeZoomWithType* aZoomWithType);
372 TCoeZoomWithType* GetZoomWithType() const;
373 TInt SetFontProvider(const CCoeFontProvider* aFontProvider);
374 const CCoeFontProvider* GetFontProvider() const;
375 TInt FindColor(TInt aLogicalColor) const;
376 void ActivateGcRecursive() const;
377 void DeactivateGcRecursive() const;
378 void ReportControlStateChange(MCoeControlStateObserver::TCoeState aType);
380 IMPORT_C void EnableReportControlStateChange(TBool aState);
384 MCoeControlContext* iContext; // deprecated
389 RDrawableWindow* iWin;
390 RCoeDynamicDataStorage* iData;
391 MObjectProvider* iMopParent;
396 Gets the control environment object for this control.
398 @return The control's control environment object.
400 inline CCoeEnv* CCoeControl::ControlEnv() const
404 Deprecated. See CCoeControl::SetCustomGc().
407 inline TInt CCoeControl::SetGc(CWindowGc* aGraphicsContext) const
408 { return const_cast<CCoeControl*>(this)->SetCustomGc(aGraphicsContext); }
411 Deprecated. See CCoeControl::CustomGc().
414 inline CWindowGc* CCoeControl::GetGc() const
415 { return CustomGc(); }
418 #endif // __COECNTRL_H__