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 "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.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 CCoeControlStorage;
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 TInt ClaimPointerGrab(TInt aPointerNumber, TBool aSendUpEvent);
231 IMPORT_C void IgnoreEventsUntilNextPointerUp();
232 IMPORT_C void SetGloballyCapturing(TBool aGlobal);
234 IMPORT_C TInt SetHitTest(const MCoeControlHitTest* aHitTestControl);
235 IMPORT_C const MCoeControlHitTest* HitTest() const;
237 IMPORT_C void OverrideColorL(TInt aLogicalColor,TRgb aColor);
238 IMPORT_C TBool GetColor(TInt aLogicalColor,TRgb& aColor) const;
239 // Control background
240 IMPORT_C void DrawBackground(const TRect& aRect) const;
241 IMPORT_C void DrawForeground(const TRect& aRect) const;
242 IMPORT_C const MCoeControlBackground* Background() const;
243 IMPORT_C const MCoeControlBackground* FindBackground() const;
244 IMPORT_C void SetBackground(const MCoeControlBackground* aBackground);
246 IMPORT_C void SetZoomFactorL(TInt aZoomFactor, TZoomType aZoomType = ERelativeZoom);
247 IMPORT_C TZoomFactor AccumulatedZoom() const;
248 IMPORT_C const TCoeZoomWithType* ZoomWithType() const;
249 // Font provider (see ScreenFont() below)
250 IMPORT_C const CCoeFontProvider& FindFontProvider() const;
251 IMPORT_C void SetFontProviderL(const CCoeFontProvider& aFontProvider);
252 // Text baseline (virtuals)
253 IMPORT_C virtual TInt TextBaselineOffset(const TSize& aSize) const;
254 IMPORT_C virtual void SetTextBaselineSpacing(TInt aSpacing);
255 // Input capabilities
256 IMPORT_C TCoeInputCapabilities RecursivelyMergedInputCapabilities() const;
258 IMPORT_C void SetMopParent(MObjectProvider* aParent);
259 // Instance identification
260 IMPORT_C TInt UniqueHandle() const;
261 IMPORT_C TInt SetUniqueHandle(TInt aUniqueHandle);
262 public: // Pointer events (virtuals)
263 IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
264 protected: // Virtuals. Override to handle these events.
265 IMPORT_C virtual void HandlePointerBufferReadyL(); // See HandlePointerEventL()
267 IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
268 // Change of size and position
269 IMPORT_C virtual void SizeChanged();
270 IMPORT_C virtual void PositionChanged();
272 // Component control access
273 IMPORT_C virtual TInt CountComponentControls() const;
274 IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;
275 IMPORT_C TInt Index(const CCoeControl* aControl) const;
278 IMPORT_C TBool IsActivated() const;
279 IMPORT_C TBool IsBeingDestroyed() const;
280 // Component ownership
281 IMPORT_C void InitComponentArrayL();
282 IMPORT_C CCoeControlArray& Components();
283 IMPORT_C const CCoeControlArray& Components() const;
285 IMPORT_C RWindow& Window() const;
286 IMPORT_C RBackedUpWindow& BackedUpWindow() const;
287 IMPORT_C void CloseWindow();
288 IMPORT_C void CreateWindowL();
289 IMPORT_C void CreateWindowL(const CCoeControl* aParent);
290 IMPORT_C void CreateWindowL(RWindowTreeNode& aParent);
291 IMPORT_C void CreateWindowL(RWindowGroup* aParent);
292 IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent);
293 IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent,TDisplayMode aDisplayMode);
294 IMPORT_C void EnableWindowTransparency();
296 IMPORT_C void SetCornerAndSize(TGulAlignment aCorner,const TSize& aSize);
297 IMPORT_C void SetSizeWithoutNotification(const TSize& aSize);
299 IMPORT_C const CFont& ScreenFont(const TCoeFont& aFont) const;
301 IMPORT_C CCoeTextDrawerBase& TextDrawer(TInt aKey = KErrNotFound) const;
303 IMPORT_C void EnableDragEvents();
304 IMPORT_C void HandleRedrawEvent(const TRect& aRect) const;
305 IMPORT_C void SetAllowStrayPointers();
306 IMPORT_C CCoeControl* GrabbingComponent() const;
307 IMPORT_C CCoeControl* GrabbingComponent(TInt aPointer) const;
308 IMPORT_C TBool CapturesPointer() const;
310 IMPORT_C TBool IsReadyToDraw() const;
311 IMPORT_C TBool IsBlank() const;
312 IMPORT_C void SetBlank();
313 IMPORT_C void SetCanDrawOutsideRect();
314 IMPORT_C void ActivateGc() const;
315 IMPORT_C void DeactivateGc() const;
316 IMPORT_C void ResetGc() const;
318 IMPORT_C void ReportEventL(MCoeControlObserver::TCoeEvent aEvent);
320 IMPORT_C void HandleComponentControlsResourceChange(TInt aType);
321 // Copy Constructor and Assignment Operator
322 inline CCoeControl(const CCoeControl& aControl);
323 inline CCoeControl& operator=(const CCoeControl& aControl);
325 friend class CCoeControlArray;
326 IMPORT_C virtual void HandleControlArrayEventL(CCoeControlArray::TEvent aEvent, const CCoeControlArray* aArray, CCoeControl* aControl, TInt aControlId);
328 IMPORT_C virtual void Reserved_CCoeControl_10();
329 IMPORT_C virtual void Reserved_CCoeControl_11();
330 IMPORT_C virtual void Reserved_CCoeControl_12();
331 IMPORT_C virtual void Reserved_CCoeControl_13();
333 IMPORT_C virtual void GetTextDrawer(CCoeTextDrawerBase*& aTextDrawer, const CCoeControl* aDrawingControl, TInt aKey) const;
335 IMPORT_C virtual void Reserved_CCoeControl_8();
336 IMPORT_C virtual void Reserved_CCoeControl_9();
337 protected: // from MObjectProvider
338 IMPORT_C TTypeUid::Ptr MopSupplyObject(TTypeUid aId);
339 private: // from MObjectProvider
340 IMPORT_C MObjectProvider* MopNext();
342 // Drawing (override this to draw)
343 IMPORT_C virtual void Draw(const TRect& aRect) const;
346 IMPORT_C virtual void WriteInternalStateL(RWriteStream& aWriteStream) const;
348 IMPORT_C virtual void Reserved_2();
349 public: // but not exported
350 void ProcessPointerEventL(const TPointerEvent& aPointerEvent);
351 void ProcessPointerBufferReadyL();
352 void RecursivelyMergeInputCapabilities(TCoeInputCapabilities& aInputCapabilities) const;
353 void WriteInternalStateNowL(RWriteStream& aWriteStream) const;
354 void NotifyFontChange(const CCoeFontProvider* aFontProvider);
355 void RemoveFromParent();
356 void RefetchPixelMappingL();
357 public: // deprecated
358 inline TInt SetGc(CWindowGc* aGraphicsContext) const;
359 inline CWindowGc* GetGc() const;
361 friend class CCoeRedrawer;
362 void DrawComponents(const TRect& aRect) const;
363 void DrawWindowOwningComponentsNow() const;
364 void DrawWindowOwningComponentsNow(const TRect &aRect) const;
365 void SetGrabbed(TBool aGrabbed, TInt aPointerNumber);
366 TBool IsGrabbed(TInt aPointerNumber = 0) const;
367 void DoMakeVisible(TBool aVisible);
368 void CheckPointerEventPurge() const;
369 void RecursivelyMergeTextDrawers(CCoeTextDrawerBase*& aTextDrawer, const CCoeControl* aDrawingControl, TInt aKey) const;
370 CCoeControl* WindowOwningParent();
371 const CCoeControl* WindowOwningParent() const { return const_cast<CCoeControl*>(this)->WindowOwningParent(); }
372 const CCoeControl* SearchParent(const CCoeControl* aParentToFind) const;
373 TInt SetZoomWithType(TCoeZoomWithType* aZoomWithType);
374 TCoeZoomWithType* GetZoomWithType() const;
375 TInt SetFontProvider(const CCoeFontProvider* aFontProvider);
376 const CCoeFontProvider* GetFontProvider() const;
377 TInt FindColor(TInt aLogicalColor) const;
378 void ActivateGcRecursive() const;
379 void DeactivateGcRecursive() const;
380 void ReportControlStateChange(MCoeControlStateObserver::TCoeState aType);
381 TInt ValidateAdvancedPointerNumber( const TPointerEvent& aPointerEvent ) const;
382 void ControlClaimPointerGrab(TInt aPointerNumber);
384 IMPORT_C void EnableReportControlStateChange(TBool aState);
388 MCoeControlContext* iContext; // deprecated
393 RDrawableWindow* iWin;
394 CCoeControlStorage* iData;
395 MObjectProvider* iMopParent;
400 Gets the control environment object for this control.
402 @return The control's control environment object.
404 inline CCoeEnv* CCoeControl::ControlEnv() const
408 Deprecated. See CCoeControl::SetCustomGc().
411 inline TInt CCoeControl::SetGc(CWindowGc* aGraphicsContext) const
412 { return const_cast<CCoeControl*>(this)->SetCustomGc(aGraphicsContext); }
415 Deprecated. See CCoeControl::CustomGc().
418 inline CWindowGc* CCoeControl::GetGc() const
419 { return CustomGc(); }
422 #endif // __COECNTRL_H__