// ZOOM.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomAreaSprite
//
// A sprite in the form of a rectangle outline, intended to show the area being zoomed
// into by the CZoomWindow class. The position and size of the sprite can be changed.
// The sprite moves over a window of the size of the screen.
//

class CZoomAreaSprite : public CCoeControl
	{
public:
	CZoomAreaSprite(RWsSession& aWs);
	~CZoomAreaSprite();
	void ConstructL(TRect& aRect);
	void SetSpritePosition(TPoint aPos);
	void SetSpriteRectL(TRect& aRect);
private:
	TSpriteMember iSpriteMember;
	RWsSprite iSprite;
	CFbsBitmap *iBitmap;
	};

/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomCorner
// 
// A sprite to indicate the bottom right hand corner of the window 
// to give users an impression of what resizing is allowed
//
//

class CZoomCorner : public CCoeControl
	{
public:
	CZoomCorner(RWsSession& aWs);
	~CZoomCorner();
	void ConstructL(TRect& aRect);
	void SetSpritePosition(TPoint aPos);
	void SetSpriteRectL(TRect& aRect);
private:
	TSpriteMember iSpriteMember;
	RWsSprite iSprite;
	CFbsBitmap *iBitmap;
	};


/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomResizer
//
// "Button" to allow drag and drop resizing of the window
//
//
class CZoomControl;

class CZoomResizer : public CCoeControl
	{
public:
	CZoomResizer(CZoomControl* aParent);
	~CZoomResizer();

public: // from CCoeControl
	void Draw(const TRect& aRect) const;
	void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	virtual TInt CountComponentControls() const;
	virtual CCoeControl* ComponentControl(TInt aIndex) const;

private: // For corner sprite
	void CreateZoomCornerL();
	void DeleteZoomCorner();


private:
	CZoomControl* iParent;
	CZoomCorner* iCorner;
	};	


/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomWindow
//
// The window which displays the zoom-in-area. Includes all the code for getting
// the pointer events, updating the zoom-in-area indicator, and the grabbing and
// displaying of the bitmap.
//

class CZoomWindow : public CCoeControl
    {
	enum {EBitmapWidth=30,EBitmapHeight=30};
public:
	enum {EZoomOneToOne=1000,EDefaultZoomFactor=EZoomOneToOne*2};
public:
	~CZoomWindow();
	CZoomWindow();
	void ConstructL();
	void SetActive(TBool aActive);
	void SetZoomFactor(TInt aFactor);
	TBool SetZoomCentre(TPoint aCentre);
	TBool Active() const;
	TSize MinimumSize(); 
	TSize ZoomSize() const;
	TPoint ZoomCentre() const;
	TInt ZoomFactor() const;
	void UpdateNow();
	void ZoomSaveBitmap(TFileName& aFilename);
private: // overridden
	void Draw(const TRect& aRect) const;
	void HandlePointerEventL(const TPointerEvent& aPointerEvent);
protected:
	void SizeChangedL();
private:
	void ZoomRect(TRect &aRect) const;
	void CreateZoomAreaSpriteL();
	void UpdateZoomAreaSprite() const;
	void DeleteZoomAreaSprite();
	void UpdateZoomAreaBitmap();
	TBool ZoomRectInsideScreen(TRect &aRect) const;

private:
	TBool iActive;
	TPoint iZoomCentre;
	TInt iZoomFactor;
	TRect iScreenRect;
	TSize iBitmapSize;
	CFbsBitmap *iBitmap;
	CZoomAreaSprite *iZoomAreaSprite;
	};

/////////////////////////////////////////////////////////////////////////////////////
//
// Class CZoomNukeAppUi
//  
// A "Nuke" button that fires the AppUi exit function
// 

class CZoomAppUi;

class CZoomNukeAppUi : public CCoeControl
	{
public:
	CZoomNukeAppUi(CZoomAppUi* anAppUi);

public: // from CCoeControl
	void Draw(const TRect& aRect) const;
	void HandlePointerEventL(const TPointerEvent& aPointerEvent);

private:
	CZoomAppUi*	iControllingAppUi;
	};


/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomControl
//
// The control class for the CZoomWindow.
//
// Certain keys (eg. page up) are implemented to have some control over the
// CZoomWindow object.
//

class CZoomControl : public CCoeControl
    {
	enum {EZoomTitleHeight=21}; 
	enum {EZoomMargin=10};
	enum {EZoomZoomWidth=90,EZoomZoomHeight=90}; // initial size of display in pixels
	enum 
		{
		EZoomWindowWidth=EZoomZoomWidth+2*EZoomMargin,
		EZoomWindowHeight=EZoomZoomHeight+2*EZoomMargin+EZoomTitleHeight,
		EZoomMinimumBitmapSize = 4
		};
	enum {EZoomBorderWidth=1};
public: // From CCoeControl
	CZoomControl(CZoomAppUi* anAppUi);
	~CZoomControl();
    void ConstructL();
	void SizeChangedL();
	virtual TInt CountComponentControls() const;
	virtual CCoeControl* ComponentControl(TInt aIndex) const;
	virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	virtual TSize MinimumSize();
public:
	inline CZoomWindow* ZoomWindow() const { return iZoomWindow; }
private:
	void Draw(const TRect& aRect) const;
private:
	TSize           iWindowSize;
	TRect			iZoomRect;
	CEikMover*		iMover;
	CZoomWindow*    iZoomWindow;
	CZoomResizer*	iZoomResizer;
	CZoomAppUi*		iParentAppUi;
	CZoomNukeAppUi*	iNuke;
	};

//////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomAppUi
//
// Zoom application user interface

class CZoomAppUi : public CEikAppUi
    {
public:
	CZoomAppUi();
	~CZoomAppUi();
    void ConstructL();
	void SetTimerRate(TTimeIntervalMicroSeconds32);
	inline TTimeIntervalMicroSeconds32 TimerRate();
	inline TBool RefreshState();
	void StartPeriodicL();
	void StopPeriodic();
	void ZoomExit();

private:
	void HandleCommandL(TInt aCommand);

private: // to provide functionality
	void CmdDlgRateL();
	void CmdDlgFileSaveAsL();
	void ZoomIn();
	void ZoomOut();
	void SetWindowSizeL(TSize);
	TSize WindowSize();
	static TInt RefreshDraw(TAny*);

private:
    CZoomControl* iZoomControl;
	CPeriodic*	iZoomRefresh;
	TTimeIntervalMicroSeconds32 iInterval;

private:
	enum {
		EZoomFactorDelta = 200,
		EWindowSizeDelta = 2
	};
    };

/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomDocument
//

class CZoomDocument : public CEikDocument
	{
public:
	CZoomDocument(CEikApplication& aApp) : CEikDocument(aApp) { }
private: // from CApaDocument
	CEikAppUi* CreateAppUiL();
	};


/////////////////////////////////////////////////////////////////////////////////////
//
// class CZoomApplication
//


class CZoomApplication : public CEikApplication
	{
private:
	CApaDocument* CreateDocumentL();
	TUid AppDllUid() const;
	};

const TUid KUidZoomApp={268435764};

//////////////////////////////////////////////////////////////////////////////
//
// -----> CZoomRateDialog(definition)
//
//////////////////////////////////////////////////////////////////////////////
class CZoomRateDialog : public CEikDialog
	{
public:
	  // Construction
	CZoomRateDialog(TBool& ,TInt&);

private:
	  // Virtual, defined by CEikDialog; empty implementation provided by
	  // CEikDialog; full implementation provided by this class
	void       PreLayoutDynInitL();

	  // Virtual, defined by CEikDialog; replaces the implementation provided
	  // provided CEikDialog.
	TBool      OkToExitL(TInt aKeycode);
	
	  // Virtual, defined by CEikDialog
	void HandleControlStateChangeL(TInt aControlId);
private:
	TBool& iState;
	TInt& iInterval;

	};

