// COECNTRL.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__COECNTRL_H__)
#define __COECNTRL_H__

#if !defined(__E32STD_H__)
#include <e32std.h>
#endif

#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif

#if !defined(__W32STD_H__)
#include <w32std.h>
#endif

#if !defined(__COEDEF_H__)
#include <coedef.h>
#endif

#if !defined(__COECOBS_H__)
#include <coecobs.h>
#endif

#if !defined(__COEDEF_H__)
#include <coedef.h>
#endif

#if !defined(__COEALIGN_H__)
#include <coealign.h>
#endif

class TResourceReader;
class CCoeEnv;
class MCoeControlContext;
class CCoeControlExtension;

class RCoeExtensionStorage
	{
public:
	RCoeExtensionStorage();
	void Close();
	TInt& Flags();
	TInt Flags() const;
	void SetExtension(CCoeControlExtension* aExtension);
	CCoeControlExtension* Extension() const;
private:
	inline TBool IsFlags() const;
private:
	union
		{
		TInt iFlags;
		CCoeControlExtension* iExtension;
		};
	};

class CCoeControl : public CBase
	{
public:
	IMPORT_C CCoeControl();
	IMPORT_C ~CCoeControl();
	// client interface
	IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	IMPORT_C virtual void MakeVisible(TBool aVisible);
	IMPORT_C virtual void SetDimmed(TBool aDimmed);
	IMPORT_C virtual void SetContainerWindowL(const CCoeControl& aContainer);
	IMPORT_C void SetContainerWindow(RWindow& aWindow); 
	IMPORT_C void SetContainerWindow(RBackedUpWindow& aWindow);
	IMPORT_C virtual void ConstructFromResourceL(TResourceReader& aReader);
	IMPORT_C virtual void ActivateL();
	IMPORT_C virtual void PrepareForFocusLossL();
	IMPORT_C virtual void SetAdjacent(TInt aAdjacent);
	IMPORT_C virtual void SetNeighbor(CCoeControl* aNeighbor);
	IMPORT_C virtual TBool HasBorder() const;
	IMPORT_C virtual TSize MinimumSize();
	IMPORT_C void DrawNow() const;
	IMPORT_C void DrawDeferred() const;
	IMPORT_C void SetFocus(TBool aFocus,TDrawNow aDrawNow=ENoDrawNow);
	IMPORT_C void SetExtentL(const TPoint& aPosition,const TSize& aSize);
	IMPORT_C void SetSizeL(const TSize& aSize);
	IMPORT_C void SetPosition(const TPoint& aPosition);
	IMPORT_C void SetRectL(const TRect& aRect);
	IMPORT_C void SetExtentToWholeScreenL();
	IMPORT_C TBool IsFocused() const;
	IMPORT_C TBool IsVisible() const;
	IMPORT_C TBool IsDimmed() const;
	inline RDrawableWindow* DrawableWindow() const;
	IMPORT_C TSize Size() const;
	IMPORT_C TPoint Position() const;
	IMPORT_C TRect Rect() const;
	IMPORT_C TPoint PositionRelativeToScreen() const;
	IMPORT_C void SetObserver(MCoeControlObserver* aObserver);
	inline MCoeControlObserver* Observer() const;
	inline CCoeEnv* ControlEnv() const;
	IMPORT_C TInt Index(const CCoeControl* aControl) const;
	IMPORT_C void SetNonFocusing();
	IMPORT_C void SetFocusing(TBool aFocusing); // not available before Release 005
	IMPORT_C TBool IsNonFocusing() const;
	IMPORT_C void SetControlContext(MCoeControlContext* aContext);
	IMPORT_C void CopyControlContextFrom(const CCoeControl* aControl);
	IMPORT_C TBool OwnsWindow() const;
	IMPORT_C TBool IsBackedUp() const;
	IMPORT_C void SetPointerCapture(TBool aCapture=ETrue);
	IMPORT_C void ClaimPointerGrab(TBool aSendUpEvent=ETrue);
	IMPORT_C void IgnoreEventsUntilNextPointerUp();
	IMPORT_C void SetComponentsToInheritVisibility(TBool aInherit=ETrue);
	IMPORT_C void SetGloballyCapturing(TBool aGlobal);
	IMPORT_C void OverrideColorL(TInt aLogicalColor,TRgb aColor); // not available before Release 005
	IMPORT_C TBool GetColor(TInt aLogicalColor,TRgb& aColor) const; // not available before Release 005
public: // but not exported
	void ProcessPointerEventL(const TPointerEvent& aPointerEvent);
	void ProcessPointerBufferReadyL();
protected:
	IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	IMPORT_C virtual void HandlePointerBufferReadyL();
	IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
	IMPORT_C virtual void SizeChangedL();
	IMPORT_C virtual void PositionChanged();
	IMPORT_C virtual TInt CountComponentControls() const;
	IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;
	IMPORT_C void EnableDragEvents();
	IMPORT_C void HandleRedrawEvent(const TRect& aRect) const;
	inline RWindow& Window() const;
	inline RBackedUpWindow& BackedUpWindow() const;
	IMPORT_C void CloseWindow();
	IMPORT_C void CreateWindowL();
	IMPORT_C void CreateWindowL(const CCoeControl* aParent);
	IMPORT_C void CreateWindowL(RWindowTreeNode& aParent);
	IMPORT_C void CreateWindowL(RWindowGroup* aParent);
	IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent); // not available before Release 005
	IMPORT_C void CreateBackedUpWindowL(RWindowTreeNode& aParent,TDisplayMode aDisplayMode);
	IMPORT_C void SetAllowStrayPointers();
	IMPORT_C void SetCanDrawOutsideRect();
	IMPORT_C void SetBlank();
	IMPORT_C void ReportEventL(MCoeControlObserver::TCoeEvent aEvent);
	IMPORT_C void SetCornerAndSizeL(TCoeAlignment aCorner,const TSize& aSize);
	IMPORT_C void SetSizeWithoutNotificationL(const TSize& aSize);
	IMPORT_C CWindowGc& SystemGc() const;
	IMPORT_C void ActivateGc() const;
	IMPORT_C void ResetGc() const;
	IMPORT_C void DeactivateGc() const;
	IMPORT_C TBool IsReadyToDraw() const;
	IMPORT_C TBool IsActivated() const;
	IMPORT_C TBool IsBlank() const;
	IMPORT_C CCoeControl* GrabbingComponent() const;
	IMPORT_C TBool CapturesPointer() const;
private:
	friend class CCoeRedrawer;
	IMPORT_C virtual void Draw(const TRect& aRect) const;
	void DrawComponents(const TRect& aRect) const;
	void DrawWindowOwningComponentsNow() const;
	void SetGrabbed(TBool aGrabbed);
	TBool IsGrabbed() const;
	void DoMakeVisible(TBool aVisible);
	void CheckPointerEventPurge() const;
	inline TInt Flags() const;
	inline TInt& Flags();
private:
// reserved virtual function space
	IMPORT_C virtual void Reserved_1();
	IMPORT_C virtual void Reserved_2();
protected:
	CCoeEnv* iCoeEnv;
	MCoeControlContext* iContext;
	TPoint iPosition;
	TSize iSize;
private:
	RDrawableWindow* iWin;
	MCoeControlObserver* iObserver;
	RCoeExtensionStorage iExt;
	};
	
inline RWindow& CCoeControl::Window() const
	{
	return(*(RWindow*)iWin);
	}

inline RBackedUpWindow& CCoeControl::BackedUpWindow() const
	{
	return(*(RBackedUpWindow*)iWin);
	}

inline RDrawableWindow* CCoeControl::DrawableWindow() const
	{
	return(iWin);
	}

inline MCoeControlObserver* CCoeControl::Observer() const
	{
	return(iObserver);
	}

inline CCoeEnv* CCoeControl::ControlEnv() const
	{
	return(iCoeEnv);
	}

#endif
