Tuesday, October 20, 2009

Periodic task without using Active Objects

Sometimes you may want to call a function or do some task in regular interval without extending the class from CActive (i.e. You may want to show a informationNote on map - just like google maps does ;-)) . In that Situation it would be appropriate to a CPeriodic Object. Usage is trivial -
In the header file add:
CPeriodic* iTimer;

Use two functions which should look like following

/*Use this function whenever you have to start the time*/
void StartTimerL(TInt aStart, TInt aInterval)
{
if(iTimer)
{
delete iTimer;
iTimer = NULL;
}
iTimer = CPeriodic::NewL(EPriorityLow);
iTimer->Start(aStart, aInterval, TCallBack(TimerCallback, this));
}

/*This function will be called after the specified interval*/
TInt TimerCallback(TAny* aThis)
{
// Do whatever you have to do locally or you may call the following function
static_cast<>(aThis)->GlobalNoteProcessTimerEvent();
return 0;
}

/*Use this function to stop the timer*/
void CancelTimer()
{
iTimer->Cancel();
}

Thats it!!

Thursday, October 8, 2009

Transparent Animated GIF

I was trying to show an animated GIF over the maps as a blip to indicate user's position on the map. But I could not show a gif with transparent background. The gif background was shown to be white although the gif uimage had a transparent background. Then I changed a few lines of the tutorial and then it worked. The lines I have changed is as follows :

void CGifAnimatorContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
if(iIsVisible)
{
if(iGif_Reader)
{
if(iGif_Reader->Bitmap() && iGif_Reader->BitmapImg() && iGif_Reader->BitmapMsk())
{
if(iGif_Reader->Bitmap()->Handle() && iGif_Reader->BitmapImg()->Handle() && iGif_Reader->BitmapMsk()->Handle())
{
TSize gifSize = TSize(iGif_Reader->Bitmap()->SizeInPixels());
TSize screenSize = TSize(aRect.Size());
TRect tempRect = TRect(TPoint((screenSize.iWidth - gifSize.iWidth)/2 ,(screenSize.iHeight - gifSize.iHeight)/2),gifSize);
gc.DrawBitmapMasked(tempRect,iGif_Reader->BitmapImg(),
TRect(0, 0, iGif_Reader->BitmapImg()->SizeInPixels().iWidth, iGif_Reader->BitmapImg()->SizeInPixels().iHeight),
iGif_Reader->BitmapMsk(), EFalse);
//gc.DrawBitmapMasked
}
}
}
}

}

Just replace the original function with mine.

Wednesday, May 27, 2009

Performance tips for Symbian Developers

Have you seen it? If not, take a quick look:

Wednesday, April 8, 2009

Specifying default installation drive in .pkg file

in the .pkg file , if we want to select the installation drive (Phone memory or Memory Card)at runtime , we put a "!" instead of the drive letter. If we dont want to show the drive selection dialog during installation, we can specify the drive letter in which we want to install out exe instead of the "!" letter. Like this:
"C:\S60\devices\S60_3rd_FP2_SDK\epoc32\data\z\resource\apps\MyApp.rsc"-"C:\resource\apps\MyApp.rsc"

But in Visual Studio 2005 , this solution does not work if we build the .SIS file using the VS2005 IDE. So, to make this thing work we have to go to the "sis" folder under the project folder and run the following command:
makesis MyApp.pkg

Then this thing will work. So, what we need to do when we are using the VS2005 as development environment is to rebuild the solution and then run the above stated command. Building the SIS file using the IDE wont work.

Tuesday, February 17, 2009

leaves and traps..... (II)

How to work with leaves

We assume that a function has previously allocated memory on the heap and this memory is pointed to by a local pointer variable. Now,if a leave occurs within that function then ,that pointer will be destroyed by the Leave (As Leave unwinds the stack frame upto the TRAP macro). Lets see,


Eventually the memory pointed to by "test" variable is unallocated and will result in a memory leak.
How to prevent this?

If we have to use any local variable which point to heap objects, we must push the variable to the CleanupStack before calling any function that may leave.

Important Note:
1. Member variables are leave-safe
2.Neither a constructor nor a destructor should contain code that may
leave, since doing so would potentially leak memory.

Leaves Vs Panics

1. Leaves occur in exceptional conditions (Out of memory or Out of disk conditions). Leaves should be handled properly to continue the normal flow of execution. Leaves do not terminate the normal flow of execution. On the other hand, Panics cannot be caught and handled.

2. Leaves occur at program runtime due to exception situation. Panics , on the other hand occur at the development time. If they occur at runtime, they cannot be fixed. So, the cause pf panics should be searched and fixed at development period.

Leaves and traps (I)

How funny this should sound to a Symbian C++ programmer? Till now, I do not have a clear idea on Leave and Trap mechanism of Symbian OS. Anyways, better let than never!! Here are some informations that I found essential to know about Leave - Trap mechanism of Symbian C++.

BASICS
1. Standard C++ exception handling mechanism adds substantially to the size of compiled code and RAM overheads (irrespective of whether the exceptions are thrown or not). That is why Symbian OS introduced the Leave - Trap mechanism. Before Symbian OS version 9 , the standars C++ exception handling were disabled in compilers so that any call to try catch or throw would result in a compilation error.But in Symbian OS 9, the standars C++ is supported (Hurrah!!!!).

2. The Leave - Trap mechanism is an alternative to standard C++ exception and conventional error checking. In other words, Leave- Trap constitutes to lightweight error handling of Symbian OS.

3. a "leave" (i.e. User::Leave() or User::LeaveifError()) suspends the code execution at the point where the leave occurs and resumes the execution at the point where the "leave" is "Trap"ped. The trap harness in Symbian is actually a "TRAP" macro. The "leave" sets the stack pointer to the context of the "TRAP" and jumps to that location.

4. User::Leave() or User::LeaveIfError() ---- Throw
TRAP ------------------------------------- try + catch

5. Critical Information on Leave:
Unlike C++ throw, a Leave will simply deallocate objects on the stack - it does not call the descriptor of that object. So, if a stack object owns a resource which must be deallocated or released as a part of destruction, that resource is not released if a leave occurs. That is why we have a class naming convention of Symbian OS which clearly states which kinds of classes can be instantiated and used safely on the stack (T classes). So, only a stack based T class will be cleaned up correctly if a Leave occurs (because there is nothing of an object of T class in any place other than stack).

6.R classes may also be created on the stack, but they must be made ‘‘leave safe’’, if used in functions that may leave, by using the cleanup stack.

new(ELeave)

1. The overloaded new operator which takes ELeave as a parameter guarantees that the pointer return value will be valid if a Leave is not occured in the constructor. Use of this overload allows the pointer to be used without further test that the allcation was successful(The allocation would leave if it were not successful).














Sunday, January 25, 2009

Giving Shadowed or Custom Background to CEikEdwin

If we look at the flash lite editbox, we will observe a shadowed background in the text boxes.
How can we give the shadow on the textbox background like this? Flash lite application runs on Symbian phones, so they must have done some kind of tricks using Symbian. In my application, I was required to do the same thing. There is a way to put custom drawed background on the CEikEdwin. I dont know if it is the way that flashlite used to show shadow on TextBox background, but it surely works.

The things is , you have to implement MFormCustomDraw interface. Just take a Class which looks like

#include
#include
class CMyCustomDraw : public MFormCustomDraw
{
public: // Constructors and destructor
virtual void DrawBackground(const TParam &aParam, const TRgb &aBackground, TRect &aDrawn) const;
virtual void DrawLineGraphics(const TParam &aParam, const TLineInfo &aLineInfo) const;
};

The MFormCustomDraw has two some virtual functions (Drawbackground() and DrawLineGraphics()). We have to implement these two functions (Or preferrably only the first one) in order to get a custom shadow on the CEikEdwin background.
So, we have to just write the implementation of DrawBackground() function. The implementation is straight forward - you have the graphics Conrtext (aParam.iGc), you have the CEikEdwin Background Rectangle (aParam.iDrawRect), so you have everything. So, just put your code in
CMyCustomDraw::DrawBackground(const TParam &aParam, const TRgb &aBackground, TRect &aDrawn) const{} function.

Now, how do we use it with our CEikEdwin. Lets say, you have a CEikEdwin in your container.So, you create your CEikEdwin in the natural way and after constructing you write,

CMyCustomDraw* iCustomDraw = new (ELeave) CMyCustomDraw();
and iTextField->TextLayout()->SetCustomDraw(iCustomDraw);

and not only that. In the containers draw function, you have to set it everytime.
iTextField->TextLayout()->SetCustomDraw(iCustomDraw);

This is how we do it !!!!

Tuesday, January 13, 2009

How to get the Screen Size Anywhere in a GUI application

Just a simple line of code to access the Application related data from any file.
If you want to access the application rectangle or screen size then -
CEikonEnv::Static()->EikAppUi()->ApplicationRect().Size().iWidth
and you have to include -
eikenv.h and eikappui.h

Monday, December 1, 2008

Thoughts...

Some emotions are best kept inside the heart, should never be expressed. That way, those emotions remain warm forever. Otherwise those will become stale

Thursday, November 27, 2008

Thoughts...

The largest selling product ever in the history of human race is not made by human, Its made by GOD - The Woman.