Building custom widgets with the Zinzala SDK - page 15
The string do is converted by the tool yo into a tUint32 command, which we retrieve in the scripting message by using the label kScriptItemCommand. We will expect any other application sending scripting messages to send them in the format outlined in the protocol defined in the framework. If we can't find the command ID, the reply message will indicate that the script message was malformed.
switch(lCmd)
{
case kScriptCmdDo:
{
const tChar *lFunction;
Now that we know that this scripting message is asking the window to do something, we will retrieve the first argument, which is the label of the action that must be performed:
if(!aMessage->GetString(kScriptItemArgs,&lFunction,0))
{
if(!strcmp(lFunction,"reskin"))
{
const tChar *lSkin;
If the message asks the window to change the skin it is using, we will try to retrieve the next argument, which should be the path to the new skin:
if(!aMessage->GetString(kScriptItemArgs,&lSkin,1))
{
tErr lErr;
TRAP(lErr,ReSkinL(lSkin));
Because the method can leave (ea. if the skin cannot be loaded), we use the macro TRAP() to catch any possible exceptions. The variable lErr will be different from kErrNone if we catch an exception. In that case, in the reply message we will indicates that we failed to perform the command:
if(lErr)
{
aReply->SetBool(kScriptItemDone,false);
aReply->SetUint8(kScriptItemReason,kScriptErrFailed);
}
}
else
{
aReply->SetBool(kScriptItemDone,false);
aReply->SetUint8(kScriptItemReason,kScriptErrMissingArg);
}
}
else
{
aReply->SetBool(kScriptItemDone,false);
aReply->SetUint8(kScriptItemReason,kScriptErrIncorrect);
}
}
else
{
aReply->SetBool(kScriptItemDone,false);
aReply->SetUint8(kScriptItemReason,kScriptErrMalformed);
}
break;
}
For any other scripting command, we will pass the message to the base class method for handling:
default:
cWindow::ScriptingReceived(aMessage,aReply);
}
}
else
{
aReply->SetBool(kScriptItemDone,false);
aReply->SetUint8(kScriptItemReason,kScriptErrMalformed);
}
}
The application sending the scripting message expects to receive notice of whether or not it was successful. And if not, what the reason was for the failure. As we have seen in the above code, the reply's item kScriptItemDone will have true or false for its value. It will indicate if the command was performed or not. If an error occurs, the reply message will also contain the item kScriptItemReason which will contain an error code.
As we are going to see, the method ReSkinL() is far from complicate:
void cDWindow::ReSkinL(const tChar *aSkin)
{
cDSkin lSkin(aSkin);
sEnv::LeaveIfError(lSkin.GetFault());
iConsole->ReSkinL(lSkin);
}
It first creates a cDSkin object from the path of the skin we would like to use. If the object is invalid, we will leave right away. If valid, we will be calling the method ReskinL() for all the widgets of the window that needs their skin to change. For this test application, we only have the console widget to update.
cDConsoleView
In the method ReSkinL() of our console class, we perform something similar to what we have done in ConstructL(). We are going to instantiate all the bitmaps we need from the skin, then replace the old ones by the new ones. However, because the method can leave anytime, we only need to replace the old bitmaps once all the new ones have been created. This implies that we must use the cleanup stack to insure that all the bitmaps loaded before will be destroyed if we leave when we are instantiating the last bitmap of the skin. It also requires us to keep the newly created bitmap in some temporary array until they replace the old ones.
Here's the method implementation:
void cDConsoleView::ReSkinL(cDSkin &aSkin)
{
cBitmap *lBackground;
cBitmap *lBStates[kStatesCount];
cBitmap *lBLabelsN[kLabelsCount];
cBitmap *lBLabelsD[kLabelsCount];
// Leave if the widget is faulty
sEnv::LeaveIfError(iFault);
// Instantiate the background bitmap
lBackground = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResBackground),false);
// Instantiate the button bitmaps
lBStates[kStateNormal] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResNormal));
lBStates[kStateDimmed] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResDimmed));
lBStates[kStatePressed] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResPressed));
lBStates[kStateActive] = lBStates[kStateNormal]; // use same bitmap as the normal state
lBStates[kStateActive1] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResAnimate1));
lBStates[kStateActive2] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResAnimate2));
lBStates[kStateActive3] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResAnimate3));
// Instantiate the label bitmaps
lBLabelsN[kLabelBwd] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResBackwardN));
lBLabelsN[kLabelFwd] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResForwardN));
lBLabelsN[kLabelStop] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResStopN));
lBLabelsN[kLabelPlay] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResPlayN));
lBLabelsN[kLabelPause] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResPauseN));
lBLabelsD[kLabelBwd] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResBackwardD));
lBLabelsD[kLabelFwd] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResForwardD));
lBLabelsD[kLabelStop] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResStopD));
lBLabelsD[kLabelPlay] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResPlayD));
lBLabelsD[kLabelPause] = CreateBitmapFromResourceLC(aSkin.GetResourceL(eResPauseD));
// delete all the bitmap we currently use
// and assign the newly loaded bitmaps
delete iBackground;
iBackground = lBackground;
for(tUint8 i=0;i<kStatesCount;i++)
{
if(iBStates[i] && i!=kStateActive) // Active and Normal states share the same bitmap
delete iBStates[i];
iBStates[i] = lBStates[i];
}
for(tUint8 i=0;i<kLabelsCount;i++)
if(iBLabelsN[i])
{
delete iBLabelsN[i];
iBLabelsN[i] = lBLabelsN[i];
}
for(tUint8 i=0;i<kLabelsCount;i++)
if(iBLabelsD[i])
{
delete iBLabelsD[i];
iBLabelsD[i] = lBLabelsD[i];
}
// remove the bitmaps from the cleanupstack
sCleanupStack::PopL(17,lBackground);
Render(kButtonsCount,true);
}
Previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Next
Print version