Showing posts with label Symbian custom calendar. Show all posts
Showing posts with label Symbian custom calendar. Show all posts

Friday, July 16, 2010

Code to make Custom float calendar in symbian 5th edition


Below is the code:

CalenderAppAppView.h

#ifndef __CALENDERAPPAPPVIEW_h__
#define __CALENDERAPPAPPVIEW_h__

// INCLUDES
#include


#include "FloatingCalendar.h"
// CLASS DECLARATION
class CCalenderAppAppView : public CCoeControl
{
public:
// New methods

/**
* NewL.
* Two-phased constructor.
* Create a CCalenderAppAppView object, which will draw itself to aRect.
* @param aRect The rectangle this view will be drawn to.
* @return a pointer to the created instance of CCalenderAppAppView.
*/
static CCalenderAppAppView* NewL(const TRect& aRect);

/**
* NewLC.
* Two-phased constructor.
* Create a CCalenderAppAppView object, which will draw itself
* to aRect.
* @param aRect Rectangle this view will be drawn to.
* @return A pointer to the created instance of CCalenderAppAppView.
*/
static CCalenderAppAppView* NewLC(const TRect& aRect);

/**
* ~CCalenderAppAppView
* Virtual Destructor.
*/
virtual ~CCalenderAppAppView();

public:
// Functions from base classes

/**
* From CCoeControl, Draw
* Draw this CCalenderAppAppView to the screen.
* @param aRect the rectangle of this view that needs updating
*/
void Draw(const TRect& aRect) const;

/**
* From CoeControl, SizeChanged.
* Called by framework when the view size is changed.
*/
virtual void SizeChanged();

void ShowCalendar();
void hideFloatingWindow();

private:
// Constructors

/**
* ConstructL
* 2nd phase constructor.
* Perform the second phase construction of a
* CCalenderAppAppView object.
* @param aRect The rectangle this view will be drawn to.
*/
void ConstructL(const TRect& aRect);

/**
* CCalenderAppAppView.
* C++ default constructor.
*/
CCalenderAppAppView();

//floating window variables

CFloatingCalendar * iCalendarFloat;

};

#endif // __CALENDERAPPAPPVIEW_h__
// End of File

CalenderAppAppView.cpp

// INCLUDE FILES
#include
#include "CalenderAppAppView.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CCalenderAppAppView::NewL()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CCalenderAppAppView* CCalenderAppAppView::NewL(const TRect& aRect)
{
CCalenderAppAppView* self = CCalenderAppAppView::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}

// -----------------------------------------------------------------------------
// CCalenderAppAppView::NewLC()
// Two-phased constructor.
// -----------------------------------------------------------------------------
//
CCalenderAppAppView* CCalenderAppAppView::NewLC(const TRect& aRect)
{
CCalenderAppAppView* self = new ( ELeave ) CCalenderAppAppView;
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}

// -----------------------------------------------------------------------------
// CCalenderAppAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CCalenderAppAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
// screen co-ordinates.
TInt iWidthw = 353;
TInt iHeightw = 230;

/*iFloatingWindow = CFloatingWindow::NewL();
iFloatingWindow->setiWidthw(iWidthw);
iFloatingWindow->setiHeightw(iHeightw); */

iCalendarFloat = CFloatingCalendar::NewL();
iCalendarFloat->HideCalendar();
// Set the windows size
SetRect(aRect);

// Activate the window, which makes it ready to be drawn
ActivateL();
}

// -----------------------------------------------------------------------------
// CCalenderAppAppView::CCalenderAppAppView()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CCalenderAppAppView::CCalenderAppAppView()
{
// No implementation required
}

// -----------------------------------------------------------------------------
// CCalenderAppAppView::~CCalenderAppAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CCalenderAppAppView::~CCalenderAppAppView()
{
// No implementation required
//if(iFloatingWindow)
//delete iFloatingWindow;
if(iCalendarFloat)
delete iCalendarFloat;
}



// -----------------------------------------------------------------------------
// CCalenderAppAppView::Draw()
// Draws the display.
// -----------------------------------------------------------------------------
//
void CCalenderAppAppView::Draw(const TRect& /*aRect*/) const
{
// Get the standard graphics context
CWindowGc& gc = SystemGc();

// Gets the control's extent
TRect drawRect(Rect());

// Clears the screen
gc.Clear(drawRect);

}

// -----------------------------------------------------------------------------
// CCalenderAppAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CCalenderAppAppView::SizeChanged()
{
DrawNow();
}

void CCalenderAppAppView::ShowCalendar()
{
iCalendarFloat->MakeCalendarVisible();
}

void CCalenderAppAppView::hideFloatingWindow()
{
iCalendarFloat->HideCalendar();
}
// End of File

FloatingCalendar.h

#ifndef FLOATINGCALENDAR_H
#define FLOATINGCALENDAR_H

// INCLUDES
#include
#include
#include
#include
#include
#include "flogger.h"
#include

class MTouchFeedback;
class CFbsBitmap;
// CLASS DECLARATION

/**
* CFloatingCalendar
*
*/
class CFloatingCalendar : public CCoeControl , MCoeControlHitTest
{
public:
// Constructors and destructor

/**
* Destructor.
*/
~CFloatingCalendar();

/**
* Two-phased constructor.
*/
static CFloatingCalendar* NewL();

/**
* Two-phased constructor.
*/
static CFloatingCalendar* NewLC();

//virtual function
void HandlePointerEventL(const TPointerEvent& aPointerEvent);
void Draw(const TRect& aRect) const;
void HandleResourceChange( TInt aType );
//From MCoeControlHitTest
TBool HitRegionContains( const TPoint& aPoint, const CCoeControl& /*aControl*/ ) const;

//for popupmenu
void ProcessCommandL(TInt aCommandId);//for MEikMenuObserver
void SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)//for MEikMenuObserver
{
}

void MakeCalendarVisible();
void HideCalendar();
TBool IsVisible();

private:

/**
* Constructor for performing 1st stage construction
*/
CFloatingCalendar();

/**
* EPOC default constructor for performing 2nd stage construction
*/
void ConstructL();
void SetCalendarWindow();
TInt getMonthDays(TTime now );
TInt getStartWeekday(TTime now );
TDes& getCurrentMonth(TInt month);
void PreviousMonthDateValue();
void NextMonthDateValue();

private:
TBool iVisible;
TRect closeRect;//added on 10th nov 09
TRect prevMonthRect;//added on 10th nov 09
TRect nextMonthRect;//added on 10th nov 09
TRect titleLabel;
RArrayiDateArrayrect;
RArrayarrayDateVal;
RFileLogger iLog;
TInt monthIndex;
TInt yearIndex;
TInt start;
TBuf<64>stringMonth;
TPoint AnchorPos;
TBuf<64> currentmonth;
MTouchFeedback* iFeedback;
TInt screenWidth, screenHeight;
};

#endif // FLOATINGCALENDAR_H

FloatingCalendar.cpp


#include "FloatingCalendar.h"
#include
#include

#include
#include
#include

#include
#include

#include

#include

CFloatingCalendar::CFloatingCalendar()
{
// No implementation required
}

CFloatingCalendar::~CFloatingCalendar()
{
iDateArrayrect.Close();
arrayDateVal.Close();

iLog.CloseLog();
iLog.Close();
}

CFloatingCalendar* CFloatingCalendar::NewLC()
{
CFloatingCalendar* self = new (ELeave)CFloatingCalendar();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}

CFloatingCalendar* CFloatingCalendar::NewL()
{
CFloatingCalendar* self=CFloatingCalendar::NewLC();
CleanupStack::Pop(); // self;
return self;
}

void CFloatingCalendar::ConstructL()
{
iLog.Connect();
iLog.CreateLog(_L("logdir"),_L("logvelrun"),EFileLoggingModeOverwrite);

CreateWindowL();

EnableDragEvents();

RWindow& window = Window();
// Make window float && set a priority
window.SetOrdinalPosition(0, ECoeWinPriorityFep);

SetHitTest(this);
screenWidth = 353;
screenHeight = 319;

SetCalendarWindow();
SetFocusing(EFalse);



iFeedback = MTouchFeedback::Instance();
User::LeaveIfNull( iFeedback );


ActivateL();
DrawNow();
}


TBool CFloatingCalendar::HitRegionContains( const TPoint& aPoint, const CCoeControl& /*aControl*/ ) const
{

if(aPoint.iX >= 0 && aPoint.iX <= screenWidth && aPoint.iY >= 0 && aPoint.iY <= screenHeight) { return ETrue; } else return EFalse; } void CFloatingCalendar::HandlePointerEventL(const TPointerEvent& aPointerEvent) { //iLog.Write(_L("Now in CVirtualKeyboard::HandlePointerEventL")); // Check if touch is enabled or not if ( !AknLayoutUtils::PenEnabled() ) { return; } if(aPointerEvent.iType == TPointerEvent::EButton1Down) { if( HitRegionContains( aPointerEvent.iPosition, *this )) iFeedback->InstantFeedback(ETouchFeedbackBasic);

/*TBuf<19>tmp;
tmp.Num(aPointerEvent.iPosition.iY);
iLog.Write(_L("Y cordinates"));
iLog.Write(tmp);
tmp.Zero();
tmp.Num(aPointerEvent.iPosition.iX);
iLog.Write(_L("X cordinates"));
iLog.Write(tmp);*/
if (closeRect.Contains(aPointerEvent.iPosition))
{
/*CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote();
note->ExecuteLD(_L("word1Rect"));*/
if(iVisible)
HideCalendar();
}
else
if (prevMonthRect.Contains(aPointerEvent.iPosition))
{
/*CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote();
note->ExecuteLD(_L("Previous Rect"));*/
PreviousMonthDateValue();

}
else
if (nextMonthRect.Contains(aPointerEvent.iPosition))
{
NextMonthDateValue();

}
else
{
/*for(int y = 0 ; y <>s;
s.Num(iDateArrayrect[y].iBr.iX);
CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote();
note->ExecuteLD(s);

}

}*/
}

}
// Call base class method, that forwards pointer event the right child component
CCoeControl::HandlePointerEventL(aPointerEvent);
}

void CFloatingCalendar::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.Clear(aRect);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbBlack);
gc.SetBrushColor(KRgbWhite);;
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.UseFont(CEikonEnv::Static()->NormalFont());

gc.DrawRect(aRect);

TPoint titlePoint(0,0);
TSize titleSize(screenWidth,80);
gc.SetBrushColor(TRgb(215,112,36));
TRect titleRect(titlePoint,titleSize);
gc.DrawRect(titleRect);

TPoint weekPoint(0,titleRect.Height());
TSize weekSize(screenWidth,16);
gc.SetBrushColor(TRgb(215,112,36));
TRect weekRect(weekPoint,weekSize);
gc.DrawRect(weekRect);
gc.SetPenColor(KRgbWhite);

TPoint endPoint(screenWidth,titleRect.Height());
gc.DrawLine(weekPoint,endPoint);

gc.SetBrushColor(TRgb(136,71,23));
gc.SetPenColor(TRgb(101,179,243));
TSize cornerSize(9,9);
//draw close button
gc.DrawRoundRect(closeRect,cornerSize);
// draw previous button
gc.DrawRoundRect(prevMonthRect,cornerSize);
// draw next button
gc.DrawRoundRect(nextMonthRect,cornerSize);

gc.SetPenColor(KRgbWhite);

//draw close button text
gc.DrawText(_L("X"),( closeRect.iBr -TPoint(40,20)) );
// draw previous button text
gc.DrawText(_L("<"),( prevMonthRect.iBr -TPoint(30,20)) ); // draw next button text gc.DrawText(_L(">"),( nextMonthRect.iBr -TPoint(30,20)) );

gc.UseFont(LatinPlain12());
// draw week daystext
gc.DrawText(_L("Mon"),(TPoint(16,titleRect.Height()+11)) );
gc.DrawText(_L("Tue"),(TPoint(70,titleRect.Height()+11)) );
gc.DrawText(_L("Wed"),(TPoint(118,titleRect.Height()+11)) );
gc.DrawText(_L("Thu"),(TPoint(169,titleRect.Height()+11)) );
gc.DrawText(_L("Fri"),(TPoint(220,titleRect.Height()+11)) );
gc.DrawText(_L("Sat"),(TPoint(271,titleRect.Height()+11)) );
gc.DrawText(_L("Sun"),(TPoint(316,titleRect.Height()+11)) );

gc.UseFont(CEikonEnv::Static()->NormalFont());
// drawing date rect
gc.SetBrushColor(TRgb(240,198,166));
gc.SetPenColor(TRgb(240,198,166));
for(TInt v =0 ; v < x1 =" iDateArrayrect[v].iTl.iX;" y1 =" iDateArrayrect[v].iTl.iY;" endht =" iDateArrayrect[iDateArrayrect.Count()-1">val;

TTime currentDate;
currentDate.HomeTime();
TDateTime currentDT = currentDate.DateTime() ;
TInt date = currentDT.Day() + 1;
//draw date text
TInt ach =0;
for(TInt k =start ; k < x1 =" iDateArrayrect[k].iTl.iX;" y1 =" iDateArrayrect[k].iTl.iY;" date ="="" atype ="="">ScreenDevice()->GetDefaultScreenSizeAndRotation( ScreenSize );

/* TBuf<19>tmp;
tmp.Num(ScreenSize.iPixelSize.iWidth);
iLog.Write(_L("Width in px"));
iLog.Write(tmp);
tmp.Zero();
tmp.Num(ScreenSize.iPixelSize.iHeight);
iLog.Write(_L("Height in px"));
iLog.Write(tmp); */


TPoint CalendarPos(0, 0);
SetExtent(CalendarPos, TSize(208,200));
Window().SetExtent(CalendarPos, TSize(208,200));
Window().SetNonFading(ETrue);

SetRect(TRect(CalendarPos,TPoint(screenWidth,screenHeight)));

TPoint cTpoint(280,7);
TSize cTsize(60,60);
closeRect.SetRect(cTpoint,cTsize);//added on 13th nov 09

TPoint cTpoint1(9,7);
TSize cTsize1(40,60);
prevMonthRect.SetRect(cTpoint1,cTsize1);//added on 13th nov 09

TPoint cTpoint2(230,7);
TSize cTsize2(40,60);
nextMonthRect.SetRect(cTpoint2,cTsize2);//added on 13th nov 09


TInt YCoArray[6]= {96,133,168,202,237,272};
TInt xCoArray[7] ={4,53,104,154,204,254,303};

iDateArrayrect.Reset();
arrayDateVal.Reset();

for(TInt i = 0; i < j ="0" currentdt =" now.DateTime()" monthindex =" currentDT.Month();" yearindex =" currentDT.Year();"> mon;
stringMonth.Append(getCurrentMonth(currentDT.Month() + 1));
stringMonth.Append(_L(" "));
mon.Zero();
mon.Num(currentDT.Year());
stringMonth.Append(mon);


currentDT.SetDay(0);
TTime currentMonth(currentDT);

//TBuf<9>l;
//l.Num(monthIndex);
//iLog.Write(l);
//l.Zero();


start = getStartWeekday(currentMonth);

//l.Num(start);
//iLog.Write(l);

for (TInt u = 0; u < currentdt =" now.DateTime()" monthindex ="="" monthindex =" 11;"> mon;
stringMonth.Append(getCurrentMonth(1 + monthIndex));
stringMonth.Append(_L(" "));
mon.Zero();
mon.Num(yearIndex);
stringMonth.Append(mon);


currentDT.SetDay(0);
currentDT.SetMonth((TMonth)(monthIndex));
currentDT.SetYear( yearIndex);
TTime currentMonth(currentDT);

/*TBuf<9>l;
l.Num(monthIndex);
iLog.Write(l);
l.Zero();*/


start = getStartWeekday(currentMonth);

/*l.Num(start);
iLog.Write(l);

l.Zero();
l.Num(yearIndex);
iLog.Write(l);*/



for (TInt u = 0; u < currentdt =" now.DateTime()" monthindex ="="" monthindex =" 0;"> mon;
stringMonth.Append(getCurrentMonth(1 + monthIndex));
stringMonth.Append(_L(" "));
mon.Zero();
mon.Num(yearIndex);
stringMonth.Append(mon);


currentDT.SetDay(0);
currentDT.SetMonth((TMonth)(monthIndex));
currentDT.SetYear( yearIndex);
TTime currentMonth(currentDT);

/*TBuf<9>l;
l.Num(monthIndex);
iLog.Write(l);
l.Zero();*/


start = getStartWeekday(currentMonth);

/*l.Num(start);
iLog.Write(l);

l.Zero();
l.Num(yearIndex);
iLog.Write(l);*/



for (TInt u = 0; u < ivisible =" ETrue;" ivisible =" EFalse;" currentdt =" now.DateTime()" month =" currentDT.Month();" 4 ="="">