lafagnosticuifoundation/clockanim/src/CLIENT.CPP
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "CL_STD.H"
       
    17 
       
    18 // global and local functions
       
    19 
       
    20 
       
    21 LOCAL_C void Panic(TClockClientPanic aPanic)
       
    22 	{
       
    23 	_LIT(KPanicClockClient,"Clock-client");
       
    24 	User::Panic(KPanicClockClient, aPanic);
       
    25 	}
       
    26 
       
    27 LOCAL_C void AppendTextToBuf(TConstructorBuf8& aBuf, const TDesC& aText)
       
    28 	{
       
    29 	TInt textSize=aText.Size(); // N.B. this is different from calling Length() as Size() returns size in bytes regardless of UNICODE or not
       
    30 	aBuf.Append(TPtrC8((TUint8*)aText.Ptr(), textSize));
       
    31 	TInt numExtraBytesfor4byteAlign=Align4(textSize)-textSize;
       
    32 	TUint8 extraBytes[4];
       
    33 	extraBytes[0]=0;
       
    34 	extraBytes[1]=0;
       
    35 	extraBytes[2]=0;
       
    36 	extraBytes[3]=0;
       
    37 	aBuf.Append(&extraBytes[0], numExtraBytesfor4byteAlign);
       
    38 	}
       
    39 
       
    40 // TDisplayAddition
       
    41 
       
    42 const TDesC8& TDisplayAddition::Buf() const
       
    43 	{
       
    44 	return iBuf;
       
    45 	}
       
    46 
       
    47 // TDigitalDisplayTextSection
       
    48 
       
    49 EXPORT_C TDigitalDisplayTextSection::TDigitalDisplayTextSection(TInt aFontHandle, TRgb aTextColor, TDigitalDisplayHorizontalTextAlignment aHorizontalAlignment,
       
    50 																TDigitalDisplayVerticalTextAlignment aVerticalAlignment,
       
    51 																TInt aHorizontalMargin, TInt aVerticalMargin, const TDesC& aFormat)
       
    52 /** Constructs a text section for a digital clock.
       
    53 
       
    54 @param aFontHandle A handle to the font to use. This can be obtained with 
       
    55 CFbsFont::Handle(). This font cannot be destroyed until the RDigitalClock 
       
    56 has been completely constructed, including all necessary calls to RDigitalClock::AddTextSectionL().
       
    57 @param aTextColor Text colour
       
    58 @param aHorizontalAlignment Horizontal alignment
       
    59 @param aVerticalAlignment Vertical alignment
       
    60 @param aHorizontalMargin Horizontal margin
       
    61 @param aVerticalMargin Vertical margin
       
    62 @param aFormat A formatting string for the time. The allowed characters for 
       
    63 this are as for TTime::FormatL(), plus those in TDigitalDisplayLayoutChar.
       
    64 @see TDigitalDisplayLayoutChar
       
    65 @see TTime::FormatL() */
       
    66 	{
       
    67 	TPckgBuf<SDigitalDisplayTextSectionConstructorArgs> textSectionArgs;
       
    68 	textSectionArgs().iFontHandle=aFontHandle;
       
    69 	textSectionArgs().iTextColor=aTextColor;
       
    70 	textSectionArgs().iHorizontalAlignment=aHorizontalAlignment;
       
    71 	textSectionArgs().iVerticalAlignment=aVerticalAlignment;
       
    72 	textSectionArgs().iHorizontalMargin=aHorizontalMargin;
       
    73 	textSectionArgs().iVerticalMargin=aVerticalMargin;
       
    74 	textSectionArgs().iFormatLength=aFormat.Length();
       
    75 	iBuf.Append(textSectionArgs);
       
    76 	AppendTextToBuf(iBuf, aFormat);
       
    77 	}
       
    78 
       
    79 // TAnalogDisplayHand
       
    80 
       
    81 EXPORT_C TAnalogDisplayHand::TAnalogDisplayHand(TAnalogDisplayHandType aType)
       
    82 /** Constructs a hand for an analogue clock.
       
    83 
       
    84 @param aType Type of hand */
       
    85 	{
       
    86 	TPckgBuf<SAnalogDisplayHandConstructorArgs> handArgs;
       
    87 	handArgs().iType=aType;
       
    88 	handArgs().iNumFeatures=0; // this is set to its proper value later in Complete()
       
    89 	TInt numFeaturesIndex=iBuf.Length()+_FOFF(SAnalogDisplayHandConstructorArgs, iNumFeatures);
       
    90 	iBuf.Append(handArgs);
       
    91 	iNumFeaturesPtr=(TInt*)&iBuf[numFeaturesIndex];
       
    92 	}
       
    93 
       
    94 EXPORT_C void TAnalogDisplayHand::AddLine(CGraphicsContext::TPenStyle aPenStyle, TRgb aPenColor, const TSize& aPenSize,
       
    95 																const TPoint& aStartPoint, const TPoint& aEndPoint)
       
    96 /** Adds a line to the hand.
       
    97 
       
    98 @param aPenStyle The pen style
       
    99 @param aPenColor The pen colour
       
   100 @param aPenSize The pen size
       
   101 @param aStartPoint The start point for the line
       
   102 @param aEndPoint The end point for the line */
       
   103 	{
       
   104 	AppendType(EAnalogDisplayHandFeatureLine);
       
   105 
       
   106 	TPckgBuf<SAnalogDisplayHandLineConstructorArgs> lineArgs;
       
   107 	lineArgs().iPenStyle=aPenStyle;
       
   108 	lineArgs().iPenColor=aPenColor;
       
   109 	lineArgs().iPenSize=aPenSize;
       
   110 	lineArgs().iStartPoint=aStartPoint;
       
   111 	lineArgs().iEndPoint=aEndPoint;
       
   112 	iBuf.Append(lineArgs);
       
   113 	}
       
   114 
       
   115 EXPORT_C void TAnalogDisplayHand::AddPolyLine(CGraphicsContext::TPenStyle aPenStyle, TRgb aPenColor, const TSize& aPenSize,
       
   116 																CGraphicsContext::TBrushStyle aBrushStyle, TRgb aBrushColor,
       
   117 																TBool aClosed, const CArrayFix<TPoint>* aPointList)
       
   118 /** Adds a polyline to the hand.
       
   119 
       
   120 @param aPenStyle The pen style
       
   121 @param aPenColor The pen colour
       
   122 @param aPenSize The pen size
       
   123 @param aBrushStyle The brush style
       
   124 @param aBrushColor The brush colour
       
   125 @param aClosed True if the polyline forms a closed shape, else false
       
   126 @param aPointList An array of points for the polyline. The class does not delete 
       
   127 aPointList. */
       
   128 	{
       
   129 	TInt numPoints=aPointList->Count();
       
   130 
       
   131 	AppendType(EAnalogDisplayHandFeaturePolyLine);
       
   132 
       
   133 	TPckgBuf<SAnalogDisplayHandPolyLineConstructorArgs> polyLineArgs;
       
   134 	polyLineArgs().iPenStyle=aPenStyle;
       
   135 	polyLineArgs().iPenColor=aPenColor;
       
   136 	polyLineArgs().iPenSize=aPenSize;
       
   137 	polyLineArgs().iBrushStyle=aBrushStyle;
       
   138 	polyLineArgs().iBrushColor=aBrushColor;
       
   139 	polyLineArgs().iClosed=aClosed;
       
   140 	polyLineArgs().iNumPoints=numPoints;
       
   141 	iBuf.Append(polyLineArgs);
       
   142 
       
   143 	for (TInt i=0; i<numPoints; ++i)
       
   144 		{
       
   145 		TPckgBuf<TPoint> point;
       
   146 		point()=(*aPointList)[i];
       
   147 		iBuf.Append(point);
       
   148 		}
       
   149 	}
       
   150 
       
   151 EXPORT_C void TAnalogDisplayHand::AddCircle(CGraphicsContext::TPenStyle aPenStyle, TRgb aPenColor, const TSize& aPenSize,
       
   152 																CGraphicsContext::TBrushStyle aBrushStyle, TRgb aBrushColor,
       
   153 																const TPoint& aCircleCenter, TInt aRadius)
       
   154 /** Adds a circle to the hand.
       
   155 
       
   156 @param aPenStyle The pen style
       
   157 @param aPenColor The pen colour
       
   158 @param aPenSize The pen size
       
   159 @param aBrushStyle The brush style
       
   160 @param aBrushColor The brush colour
       
   161 @param aCircleCenter The centre of the circle
       
   162 @param aRadius The radius of the circle */
       
   163 	{
       
   164 	AppendType(EAnalogDisplayHandFeatureCircle);
       
   165 
       
   166 	TPckgBuf<SAnalogDisplayHandCircleConstructorArgs> circleArgs;
       
   167 	circleArgs().iPenStyle=aPenStyle;
       
   168 	circleArgs().iPenColor=aPenColor;
       
   169 	circleArgs().iPenSize=aPenSize;
       
   170 	circleArgs().iBrushStyle=aBrushStyle;
       
   171 	circleArgs().iBrushColor=aBrushColor;
       
   172 	circleArgs().iCircleCenter=aCircleCenter;
       
   173 	circleArgs().iRadius=aRadius;
       
   174 	iBuf.Append(circleArgs);
       
   175 	}
       
   176 
       
   177 void TAnalogDisplayHand::AppendType(TAnalogDisplayHandFeatureType aType)
       
   178 	{
       
   179 	++*iNumFeaturesPtr;
       
   180 
       
   181 	TPckgBuf<TAnalogDisplayHandFeatureType> featureType;
       
   182 	featureType()=aType;
       
   183 	iBuf.Append(featureType);
       
   184 	}
       
   185 
       
   186 // RAnimWithUtils
       
   187 
       
   188 RAnimWithUtils::RAnimWithUtils(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   189 	:RAnim(aAnimDll),
       
   190 	 iConstructorBuf(NULL),
       
   191 	 iConstructorBufAlreadySent(EFalse),
       
   192 	 iWindow(aWindow),
       
   193 	 iNumAdditionsStillExpected(0)
       
   194 	{
       
   195 	}
       
   196 
       
   197 void RAnimWithUtils::AppendToConstructorBufL(const TDesC8& aData)
       
   198 	{
       
   199 	__ASSERT_ALWAYS(!iConstructorBufAlreadySent, Panic(EClockClientPanicAlreadyConstructed));
       
   200 
       
   201 	if (iConstructorBuf==NULL)
       
   202 		iConstructorBuf=new(ELeave) TConstructorBuf8;
       
   203 
       
   204 	iConstructorBuf->Append(aData);
       
   205 	}
       
   206 
       
   207 void RAnimWithUtils::SendConstructorBufIfCompleteL(TInt aAnimatedObjectType)
       
   208 	{
       
   209 	--iNumAdditionsStillExpected;
       
   210 	__ASSERT_ALWAYS(iNumAdditionsStillExpected>=0, Panic(EClockClientPanicIncorrectNumberOfAdditions1));
       
   211 	if (iNumAdditionsStillExpected==0)
       
   212 		SendConstructorBufL(aAnimatedObjectType);
       
   213 	}
       
   214 
       
   215 void RAnimWithUtils::SendConstructorBufL(TInt aAnimatedObjectType)
       
   216 	{
       
   217 	__ASSERT_ALWAYS(iNumAdditionsStillExpected==0, Panic(EClockClientPanicIncorrectNumberOfAdditions2));
       
   218 
       
   219 	TPckgBuf<TInt> checkValue;
       
   220 	checkValue()=KCheckValueForEndOfTimeDeviceConstructionBuf;
       
   221 	AppendToConstructorBufL(checkValue);
       
   222 
       
   223 	TIpcArgs ipcArgs;
       
   224 	ipcArgs.Set(KIpcSlot, iConstructorBuf);
       
   225 	User::LeaveIfError(Construct(iWindow, aAnimatedObjectType, KNullDesC8, ipcArgs));
       
   226 	delete iConstructorBuf;
       
   227 	iConstructorBuf=NULL;
       
   228 	iConstructorBufAlreadySent=ETrue;
       
   229 	}
       
   230 
       
   231 TBool RAnimWithUtils::ConstructorBufExists() const
       
   232 	{
       
   233 	return (iConstructorBuf!=NULL);
       
   234 	}
       
   235 
       
   236 TBool RAnimWithUtils::ConstructorBufAlreadySent() const
       
   237 	{
       
   238 	return iConstructorBufAlreadySent;
       
   239 	}
       
   240 
       
   241 TConstructorBuf8& RAnimWithUtils::ConstructorBuf() const
       
   242 	{
       
   243 	__ASSERT_ALWAYS((iConstructorBuf!=NULL), Panic(EClockClientPanicNoConstructorBuf));
       
   244 	return *iConstructorBuf;
       
   245 	}
       
   246 
       
   247 void RAnimWithUtils::SetNumAdditionsStillExpected(TInt aNumAdditionsStillExpected)
       
   248 	{
       
   249 	__ASSERT_ALWAYS((iNumAdditionsStillExpected==0) && !iConstructorBufAlreadySent, Panic(EClockClientPanicBadSetNumAdditionsStillExpectedCall));
       
   250 	iNumAdditionsStillExpected=aNumAdditionsStillExpected;
       
   251 	}
       
   252 
       
   253 EXPORT_C void RAnimWithUtils::Close()
       
   254 /** Closes the clock animation. */
       
   255 	{
       
   256 	delete iConstructorBuf;
       
   257 	iConstructorBuf=NULL;
       
   258 	RAnim::Close();
       
   259 	}
       
   260 
       
   261 // RTimeDevice
       
   262 
       
   263 RTimeDevice::RTimeDevice(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   264 	:RAnimWithUtils(aAnimDll, aWindow)
       
   265 	{
       
   266 	}
       
   267 
       
   268 void RTimeDevice::AppendDisplayTypeL(TDisplayType aType)
       
   269 	{
       
   270 	TPckgBuf<TDisplayType> displayType;
       
   271 	displayType()=aType;
       
   272 	AppendToConstructorBufL(displayType);
       
   273 	}
       
   274 
       
   275 void RTimeDevice::AppendDigitalDisplayConstructorArgsL(const TPoint& aPosition, const TSize& aSize, const TMargins& aMargins, const STimeDeviceShadow& aShadow,
       
   276 																TRgb aBackgroundColor, TInt aNumTextSections)
       
   277 	{
       
   278 	AppendDisplayTypeL(EDisplayDigital);
       
   279 
       
   280 	__ASSERT_ALWAYS(aNumTextSections>0, Panic(EClockClientPanicTooFewTextSections));
       
   281 	TPckgBuf<SDigitalDisplayConstructorArgs> digitalDisplayArgs;
       
   282 	digitalDisplayArgs().iPosition=aPosition;
       
   283 	digitalDisplayArgs().iSize=aSize;
       
   284 	digitalDisplayArgs().iMargins=aMargins;
       
   285 	digitalDisplayArgs().iShadow=aShadow;
       
   286 	digitalDisplayArgs().iBackgroundColor=aBackgroundColor;
       
   287 	digitalDisplayArgs().iNumTextSections=aNumTextSections;
       
   288 	AppendToConstructorBufL(digitalDisplayArgs);
       
   289 
       
   290 	SetNumAdditionsStillExpected(aNumTextSections);
       
   291 	}
       
   292 
       
   293 void RTimeDevice::AppendAnalogDisplayConstructorArgsL(const TPoint& aPosition, const TSize& aSize, const TMargins& aMargins, const STimeDeviceShadow& aShadow,
       
   294 																TInt aFaceHandle, TInt aFaceMaskHandle, TInt aNumHands, const SAnalogDisplayAmPm* aAmPm)
       
   295 	{
       
   296 	AppendDisplayTypeL(EDisplayAnalog);
       
   297 
       
   298 	__ASSERT_ALWAYS(aNumHands>0, Panic(EClockClientPanicTooFewHands));
       
   299 	TPckgBuf<SAnalogDisplayConstructorArgs> analogDisplayArgs;
       
   300 	analogDisplayArgs().iPosition=aPosition;
       
   301 	analogDisplayArgs().iSize=aSize;
       
   302 	analogDisplayArgs().iMargins=aMargins;
       
   303 	analogDisplayArgs().iShadow=aShadow;
       
   304 	analogDisplayArgs().iFaceHandle=aFaceHandle;
       
   305 	analogDisplayArgs().iFaceMaskHandle=aFaceMaskHandle;
       
   306 	analogDisplayArgs().iNumHands=aNumHands;
       
   307 	analogDisplayArgs().iHasAmPm=(aAmPm!=NULL);
       
   308 	AppendToConstructorBufL(analogDisplayArgs);
       
   309 
       
   310 	if (aAmPm!=NULL)
       
   311 		{
       
   312 		TPckgBuf<SAnalogDisplayAmPm> amPmArgs;
       
   313 		amPmArgs()=*aAmPm;
       
   314 		AppendToConstructorBufL(amPmArgs);
       
   315 		}
       
   316 
       
   317 	SetNumAdditionsStillExpected(aNumHands);
       
   318 	}
       
   319 
       
   320 EXPORT_C void RTimeDevice::SetVisible(TBool aVisible)
       
   321 /** Makes the clock visible. By default, clocks are invisible.
       
   322 
       
   323 This function can only be called after full construction of the clock.
       
   324 
       
   325 @param aVisible ETrue makes the clock visible, EFalse invisible */
       
   326 	{
       
   327 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed1));
       
   328 	TPckgBuf<SDisplayCommandSetVisibleArgs> args;
       
   329 	args().iVisible=aVisible;
       
   330 	TInt error=CommandReply(EDisplayCommandSetVisible, args);
       
   331 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError1));
       
   332 	}
       
   333 
       
   334 EXPORT_C void RTimeDevice::SetPositionAndSize(const TPoint& aPosition, const TSize& aSize)
       
   335 /** Sets the clock's on-screen position and size.
       
   336 
       
   337 This function can only be called after full construction of the clock.
       
   338 
       
   339 @param aPosition Clock co-ordinates
       
   340 @param aSize Clock size */
       
   341 	{
       
   342 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed2));
       
   343 	TPckgBuf<SDisplayCommandSetPositionAndSizeArgs> args;
       
   344 	args().iPosition=aPosition;
       
   345 	args().iSize=aSize;
       
   346 	TInt error=CommandReply(EDisplayCommandSetPositionAndSize, args);
       
   347 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError2));
       
   348 	}
       
   349 
       
   350 EXPORT_C void RTimeDevice::SetPosition(const TPoint& aPosition)
       
   351 /** Sets the clock's on-screen position.
       
   352 
       
   353 This function can only be called after full construction of the clock.
       
   354 
       
   355 @param aPosition Clock co-ordinates */
       
   356 	{
       
   357 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed3));
       
   358 	TPckgBuf<SDisplayCommandSetPositionArgs> args;
       
   359 	args().iPosition=aPosition;
       
   360 	TInt error=CommandReply(EDisplayCommandSetPosition, args);
       
   361 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError3));
       
   362 	}
       
   363 
       
   364 EXPORT_C void RTimeDevice::SetSize(const TSize& aSize)
       
   365 /** Sets the clock's on-screen size.
       
   366 
       
   367 This function can only be called after full construction of the clock.
       
   368 
       
   369 @param aSize Clock size */
       
   370 	{
       
   371 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed4));
       
   372 	TPckgBuf<SDisplayCommandSetSizeArgs> args;
       
   373 	args().iSize=aSize;
       
   374 	TInt error=CommandReply(EDisplayCommandSetSize, args);
       
   375 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError4));
       
   376 	}
       
   377 
       
   378 EXPORT_C void RTimeDevice::UpdateDisplay()
       
   379 /** Forces an update to the clock's display.
       
   380 
       
   381 This function can only be called after full construction of the clock. */
       
   382 	{
       
   383 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed5));
       
   384 	TInt error=CommandReply(EDisplayCommandUpdateDisplay);
       
   385 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError5));
       
   386 	}
       
   387 
       
   388 EXPORT_C void RTimeDevice::Draw()
       
   389 /** Draws the clock. */
       
   390 	{
       
   391 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed6));
       
   392 	TInt error=CommandReply(EDisplayCommandDraw);
       
   393 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError6));
       
   394 	}
       
   395 
       
   396 // RClock
       
   397 
       
   398 RClock::RClock(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   399 	:RTimeDevice(aAnimDll, aWindow)
       
   400 	{
       
   401 	}
       
   402 
       
   403 void RClock::AppendClockConstructorArgsL(TTimeIntervalSeconds aUniversalTimeOffset)
       
   404 	{
       
   405 	TPckgBuf<SClockConstructorArgs> clockConstructorArgs;
       
   406 	clockConstructorArgs().iUniversalTimeOffset=aUniversalTimeOffset;
       
   407 	AppendToConstructorBufL(clockConstructorArgs);
       
   408 	}
       
   409 
       
   410 EXPORT_C void RClock::SetUniversalTimeOffset(TTimeIntervalSeconds aUniversalTimeOffset)
       
   411 /** Adjusts the clock's time.
       
   412 
       
   413 @param aUniversalTimeOffset The time to which to set the clock, expressed 
       
   414 as an offset from universal time.
       
   415 
       
   416 @publishedAll
       
   417 @released*/
       
   418 	{
       
   419 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed7));
       
   420 	TPckgBuf<SClockCommandSetUniversalTimeOffsetArgs> args;
       
   421 	args().iUniversalTimeOffset=aUniversalTimeOffset;
       
   422 	TInt error=CommandReply(EClockCommandSetUniversalTimeOffset, args);
       
   423 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError7));
       
   424 	}
       
   425 
       
   426 // RDigitalClock
       
   427 
       
   428 EXPORT_C RDigitalClock::RDigitalClock(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   429 	:RClock(aAnimDll, aWindow)
       
   430 /** Creates a digital clock object.
       
   431 
       
   432 To complete construction, you must call ConstructL().
       
   433 
       
   434 @param aAnimDll This RAnimDll must have been loaded with the server-side clock 
       
   435 animation DLL, clocka.dll
       
   436 @param aWindow Window to which to add the clock */
       
   437 	{
       
   438 	}
       
   439 
       
   440 EXPORT_C void RDigitalClock::ConstructL(TTimeIntervalSeconds aUniversalTimeOffset, const TPoint& aPosition, const TSize& aSize, const TMargins& aMargins,
       
   441 																const STimeDeviceShadow& aShadow, TRgb aBackgroundColor, TInt aNumTextSections)
       
   442 /** Completes construction of a digital clock.
       
   443 
       
   444 @param aUniversalTimeOffset Initial time for the clock, expressed as an offset 
       
   445 from universal time
       
   446 @param aPosition Clock's on-screen position
       
   447 @param aSize Clock's on-screen size
       
   448 @param aMargins Margin settings
       
   449 @param aShadow Shadow settings
       
   450 @param aBackgroundColor Background color
       
   451 @param aNumTextSections Number of text sections */
       
   452 	{
       
   453 	__ASSERT_ALWAYS(!ConstructorBufExists(), Panic(EClockClientPanicAlreadyConstructedDigitalClock));
       
   454 	__ASSERT_ALWAYS((aSize.iWidth>=0) && (aSize.iHeight>=0), Panic(EClockClientPanicRectIsNotNormalized));
       
   455 	AppendClockConstructorArgsL(aUniversalTimeOffset);
       
   456 	AppendDigitalDisplayConstructorArgsL(aPosition, aSize, aMargins, aShadow, aBackgroundColor, aNumTextSections);
       
   457 	}
       
   458 
       
   459 EXPORT_C void RDigitalClock::AddTextSectionL(const TDigitalDisplayTextSection& aTextSection)
       
   460 /** Adds a text section to the clock.
       
   461 
       
   462 This function can only be called after full construction of the clock.
       
   463 
       
   464 @param aTextSection Describes text section to add */
       
   465 	{
       
   466 	__ASSERT_ALWAYS(ConstructorBufExists(), Panic(EClockClientPanicNotYetConstructedDigitalClock));
       
   467 	TInt lengthOfConstructorBufBeforeTextSectionIsAdded=ConstructorBuf().Length();
       
   468 	AppendToConstructorBufL(aTextSection.Buf());
       
   469 	const SDigitalDisplayTextSectionConstructorArgs* textSectionConstructorArgs=(const SDigitalDisplayTextSectionConstructorArgs*)(ConstructorBuf().Ptr()+lengthOfConstructorBufBeforeTextSectionIsAdded);
       
   470 	TPtrC format((const TText*)(textSectionConstructorArgs+1), textSectionConstructorArgs->iFormatLength);
       
   471 	HBufC* formatWithoutFlashingBlockDelimiter=format.AllocLC();
       
   472 	TPtr ptr=formatWithoutFlashingBlockDelimiter->Des();
       
   473 	for (TInt positionOfFlashingBlockDelimiter=ptr.Locate(EDigitalDisplayLayoutCharFlashingBlockDelimiter); positionOfFlashingBlockDelimiter!=KErrNotFound; positionOfFlashingBlockDelimiter=ptr.Locate(EDigitalDisplayLayoutCharFlashingBlockDelimiter))
       
   474 		ptr.Delete(positionOfFlashingBlockDelimiter, 1);
       
   475 	TTime time;
       
   476 	TBuf<128> notUsed;
       
   477 	TRAPD(error, time.FormatL(notUsed, *formatWithoutFlashingBlockDelimiter));
       
   478 	CleanupStack::PopAndDestroy();
       
   479 	if ((error!=KErrNone) && (error!=KErrOverflow))
       
   480 		User::Leave(error);
       
   481 	SendConstructorBufIfCompleteL(EAnimClock);
       
   482 	}
       
   483 
       
   484 EXPORT_C void RDigitalClock::SetBackgroundColor(TRgb aBackgroundColor, TRgb aShadowColor)
       
   485 /** Sets the background colour for the clock.
       
   486 
       
   487 This function can only be called after full construction of the clock.
       
   488 
       
   489 @param aBackgroundColor Background colour
       
   490 @param aShadowColor Shadow colour */
       
   491 	{
       
   492 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed8));
       
   493 	TPckgBuf<SDigitalDisplayCommandSetBackgroundColorArgs> args;
       
   494 	args().iBackgroundColor=aBackgroundColor;
       
   495 	args().iShadowColor=aShadowColor;
       
   496 	TInt error=CommandReply(EDigitalDisplayCommandSetBackgroundColor, args);
       
   497 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError8));
       
   498 	}
       
   499 
       
   500 EXPORT_C void RDigitalClock::SetTextColor(TRgb aTextColor)
       
   501 /** Sets the text colour.
       
   502 
       
   503 This function can only be called after full construction of the clock.
       
   504 
       
   505 @param aTextColor Text colour */
       
   506 	{
       
   507 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedDigitalTextColor));
       
   508 	TPckgBuf<SDigitalDisplayCommandSetTextColorArgs> args;
       
   509 	args().iTextColor=aTextColor;
       
   510 	TInt error=CommandReply(EDigitalDisplayCommandSetTextColor, args);
       
   511 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorDigitalTextColor));
       
   512 	}
       
   513 
       
   514 
       
   515 // RAnalogClock
       
   516 
       
   517 EXPORT_C RAnalogClock::RAnalogClock(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   518 	:RClock(aAnimDll, aWindow)
       
   519 /** Creates an analogue clock object.
       
   520 
       
   521 To complete construction, you must call ConstructL().
       
   522 
       
   523 @param aAnimDll This RAnimDll must have been loaded with the server-side clock 
       
   524 animation DLL, clocka.dll
       
   525 @param aWindow Window to which to add the clock */
       
   526 	{
       
   527 	}
       
   528 
       
   529 EXPORT_C void RAnalogClock::ConstructL(TTimeIntervalSeconds aUniversalTimeOffset, const TPoint& aPosition, const TSize& aSize, const TMargins& aMargins,
       
   530 																const STimeDeviceShadow& aShadow, TInt aFaceHandle, TInt aFaceMaskHandle, TInt aNumHands, const SAnalogDisplayAmPm* aAmPm)
       
   531 /** Completes construction of an analogue clock.
       
   532 
       
   533 The bitmaps specified in aFaceHandle and aFaceMaskHandle cannot be destroyed 
       
   534 until the clock has been completely constructed, including all necessary calls 
       
   535 to RAnalogClock::AddHandL().
       
   536 
       
   537 @param aUniversalTimeOffset Initial time for the clock, expressed as an offset 
       
   538 from universal time
       
   539 @param aPosition Clock's on-screen position
       
   540 @param aSize Clock's on-screen size
       
   541 @param aMargins Margin settings
       
   542 @param aShadow Shadow settings
       
   543 @param aFaceHandle Handle to a bitmap of the clock face. You can obtain a bitmap 
       
   544 handle through CFbsBitmap::Handle().
       
   545 @param aFaceMaskHandle Handle to a bitmap mask for the clock face. This can 
       
   546 be 0, if no mask is required.
       
   547 @param aNumHands Number of hands on the clock. For each hand, you must call 
       
   548 AddHandL().
       
   549 @param aAmPm Options for displaying AM/PM
       
   550 @see CFbsBitmap::Handle() */
       
   551 	{
       
   552 	__ASSERT_ALWAYS(!ConstructorBufExists(), Panic(EClockClientPanicAlreadyConstructedAnalogClock));
       
   553 	AppendClockConstructorArgsL(aUniversalTimeOffset);
       
   554 	AppendAnalogDisplayConstructorArgsL(aPosition, aSize, aMargins, aShadow, aFaceHandle, aFaceMaskHandle, aNumHands, aAmPm);
       
   555 	}
       
   556 
       
   557 EXPORT_C void RAnalogClock::AddHandL(const TAnalogDisplayHand& aHand)
       
   558 /** Adds a hand to the clock.
       
   559 
       
   560 This function can only be called after full construction of the clock.
       
   561 
       
   562 @param aHand Settings for the hand. */
       
   563 	{
       
   564 	__ASSERT_ALWAYS(ConstructorBufExists(), Panic(EClockClientPanicNotYetConstructedAnalogClock));
       
   565 	__ASSERT_ALWAYS(aHand.NumFeatures()>0, Panic(EClockClientPanicTooFewHandFeatures));
       
   566 	AppendToConstructorBufL(aHand.Buf());
       
   567 	SendConstructorBufIfCompleteL(EAnimClock);
       
   568 	}
       
   569 
       
   570 EXPORT_C void RAnalogClock::SetBackgroundColor(TRgb aBackgroundColor, TRgb aShadowColor)
       
   571 /** Sets the background colour for the clock.
       
   572 
       
   573 This function can only be called after full construction of the clock.
       
   574 
       
   575 @param aBackgroundColor Background colour.
       
   576 @param aShadowColor Shadow colour. */
       
   577 	{
       
   578 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed8));
       
   579 	TPckgBuf<SDigitalDisplayCommandSetBackgroundColorArgs> args;
       
   580 	args().iBackgroundColor=aBackgroundColor;
       
   581 	args().iShadowColor=aShadowColor;
       
   582 	TInt error=CommandReply(EDigitalDisplayCommandSetBackgroundColor, args);
       
   583 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError8));
       
   584 	}
       
   585 
       
   586 EXPORT_C void RAnalogClock::SetTextColor(TRgb aTextColor)
       
   587 /** Sets the text colour.
       
   588 
       
   589 This function can only be called after full construction of the clock.
       
   590 
       
   591 @param aTextColor Text colour. */
       
   592 	{
       
   593 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedDigitalTextColor));
       
   594 	TPckgBuf<SDigitalDisplayCommandSetTextColorArgs> args;
       
   595 	args().iTextColor=aTextColor;
       
   596 	TInt error=CommandReply(EDigitalDisplayCommandSetTextColor, args);
       
   597 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorDigitalTextColor));
       
   598 	}
       
   599 
       
   600 EXPORT_C void RAnalogClock::SetPenColor(const TRgb aPenColor)
       
   601 /** Sets the pen colour for the hands.
       
   602 
       
   603 This function can only be called after full construction of the clock.
       
   604 
       
   605 @param aPenColor Pen colour. */
       
   606 	{
       
   607 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedAnalogPenColor));
       
   608 	TPckgBuf<SAnalogDisplayHandFeaturesPenColorArgs> args;
       
   609 	args().iPenColor=aPenColor;
       
   610 	TInt error=CommandReply(EAnalogDisplayCommandSetPenColor, args);
       
   611 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorAnalogPenColor));
       
   612 	}
       
   613 
       
   614 EXPORT_C void RAnalogClock::SetBrushColor(const TRgb aBrushColor)
       
   615 /** Sets the brush colour for the hands.
       
   616 
       
   617 This function can only be called after full construction of the clock.
       
   618 
       
   619 @param aBrushColor Brush colour. */
       
   620 	{
       
   621 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedAnalogBrushColor));
       
   622 	TPckgBuf<SAnalogDisplayHandFeaturesBrushColorArgs> args;
       
   623 	args().iBrushColor=aBrushColor;
       
   624 	TInt error=CommandReply(EAnalogDisplayCommandSetBrushColor, args);
       
   625 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorAnalogBrushColor));
       
   626 	}
       
   627 
       
   628 
       
   629 // RMessageWindow
       
   630 
       
   631 EXPORT_C RMessageWindow::RMessageWindow(RAnimDll& aAnimDll, const RWindowBase& aWindow)
       
   632 	:RAnimWithUtils(aAnimDll, aWindow)
       
   633 /** Constructor.
       
   634 
       
   635 @param aAnimDll This RAnimDll must have been loaded with the server-side message 
       
   636 window animation DLL, clocka.dll.
       
   637 @param aWindow Window to which to add the message window. */
       
   638 	{
       
   639 	}
       
   640 
       
   641 EXPORT_C void RMessageWindow::ConstructL(TInt aBaselineOffset, TInt aFontHandle, TRgb aBackgroundColor, TRgb aTextColor)
       
   642 /** Performs second-phase construction.
       
   643 
       
   644 @param aBaselineOffset Height of window in pixels above the font's baseline.
       
   645 @param aFontHandle Handle to the font to use. This can be obtained with CFbsFont::Handle().
       
   646 @param aBackgroundColor Window's background colour.
       
   647 @param aTextColor Message text colour.
       
   648 @see CFbsFont::Handle() */
       
   649 	{
       
   650 	TPckgBuf<SMessageWindowConstructorArgs> messageWindowConstructorArgs;
       
   651 	messageWindowConstructorArgs().iBaselineOffset=aBaselineOffset;
       
   652 	messageWindowConstructorArgs().iFontHandle=aFontHandle;
       
   653 	messageWindowConstructorArgs().iBackgroundColor=aBackgroundColor;
       
   654 	messageWindowConstructorArgs().iTextColor=aTextColor;
       
   655 	messageWindowConstructorArgs().iBorderColor=KRgbBlack;
       
   656 	AppendToConstructorBufL(messageWindowConstructorArgs);
       
   657 	SendConstructorBufL(EAnimMessageWindow);
       
   658 	}
       
   659 
       
   660 EXPORT_C void RMessageWindow::ConstructL(TInt aBaselineOffset, TInt aFontHandle, TRgb aBackgroundColor, TRgb aTextColor, TRgb aBorderColor)
       
   661 /** Performs second-phase construction, with a window border colour.
       
   662 
       
   663 @param aBaselineOffset Height of window in pixels above the font's baseline.
       
   664 @param aFontHandle Handle to the font to use. This can be obtained with CFbsFont::Handle().
       
   665 @param aBackgroundColor Window's background colour.
       
   666 @param aTextColor Message text colour.
       
   667 @param aBorderColor Window border colour.
       
   668 @see CFbsFont::Handle() */
       
   669 	{
       
   670 	TPckgBuf<SMessageWindowConstructorArgs> messageWindowConstructorArgs;
       
   671 	messageWindowConstructorArgs().iBaselineOffset=aBaselineOffset;
       
   672 	messageWindowConstructorArgs().iFontHandle=aFontHandle;
       
   673 	messageWindowConstructorArgs().iBackgroundColor=aBackgroundColor;
       
   674 	messageWindowConstructorArgs().iTextColor=aTextColor;
       
   675 	messageWindowConstructorArgs().iBorderColor=aBorderColor;
       
   676 	AppendToConstructorBufL(messageWindowConstructorArgs);
       
   677 	SendConstructorBufL(EAnimMessageWindow);
       
   678 	}
       
   679 
       
   680 EXPORT_C void RMessageWindow::SetBackgroundColor(TRgb aBackgroundColor)
       
   681 /** Sets the background colour for the window.
       
   682 
       
   683 @param aBackgroundColor Background colour. */
       
   684 	{
       
   685 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedMsgWindowBackgroundColor));
       
   686 	TPckgBuf<SMessageWindowBackgroundColorArgs> messageWindowArgs;
       
   687 	messageWindowArgs().iBackgroundColor=aBackgroundColor;
       
   688 	TInt error=CommandReply(EMessageWindowCommandSetBackgroundColor, messageWindowArgs);
       
   689 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorMsgWindowBackgroundColor));
       
   690 	}
       
   691 
       
   692 EXPORT_C void RMessageWindow::SetTextColor(TRgb aTextColor)
       
   693 /** Sets the message text colour.
       
   694 
       
   695 @param aTextColor Message text colour. */
       
   696 	{
       
   697 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedMsgWindowTextColor));
       
   698 	TPckgBuf<SMessageWindowTextColorArgs> messageWindowArgs;
       
   699 	messageWindowArgs().iTextColor=aTextColor;
       
   700 	TInt error=CommandReply(EMessageWindowCommandSetTextColor, messageWindowArgs);
       
   701 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorMsgWindowTextColor));
       
   702 	}
       
   703 
       
   704 EXPORT_C void RMessageWindow::SetBorderColor(TRgb aBorderColor)
       
   705 /** Sets the window border colour.
       
   706 
       
   707 @param aBorderColor Window border colour. */
       
   708 	{
       
   709 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedMsgWindowBorderColor));
       
   710 	TPckgBuf<SMessageWindowBorderColorArgs> messageWindowArgs;
       
   711 	messageWindowArgs().iBorderColor=aBorderColor;
       
   712 	TInt error=CommandReply(EMessageWindowCommandSetBorderColor, messageWindowArgs);
       
   713 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorMsgWindowBorderColor));
       
   714 	}
       
   715 
       
   716 EXPORT_C void RMessageWindow::SetPlinthColors(TRgb aTl,TRgb aBr)
       
   717 /** Sets the plinth colours.
       
   718 
       
   719 @param aTl Colour to use around the top and left borders.
       
   720 @param aBr Colour to use around the bottom and right borders. */
       
   721 	{
       
   722 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructedMsgWindowPlinthColor));
       
   723 	TPckgBuf<SMessageWindowPlinthColorArgs> messageWindowArgs;
       
   724 	messageWindowArgs().iTlColor=aTl;
       
   725 	messageWindowArgs().iBrColor=aBr;
       
   726 	TInt error=CommandReply(EMessageWindowCommandSetPlinthColor, messageWindowArgs);
       
   727 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedErrorMsgWindowPlinthColor));
       
   728 	}
       
   729 
       
   730 EXPORT_C void RMessageWindow::StartDisplay(TBool aFlash, TTimeIntervalMicroSeconds32 aInitialDelay, const TDesC& aText)
       
   731 /** Displays the message window for a specified time.
       
   732 
       
   733 @param aFlash Set this to true to make the message window flash.
       
   734 @param aInitialDelay Duration for which to display the message window.
       
   735 @param aText Text to put in the window. */
       
   736 	{
       
   737 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed9));
       
   738 	TPckgBuf<SMessageWindowCommandStartDisplayArgs> args;
       
   739 	args().iFlash=aFlash;
       
   740 	args().iInitialDelay=aInitialDelay;
       
   741 	args().iDuration=SMessageWindowCommandStartDisplayArgs::EIndefiniteDuration;
       
   742 	args().iText=aText;
       
   743 	TInt error=CommandReply(EMessageWindowCommandStartDisplay, args);
       
   744 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError9));
       
   745 	}
       
   746 
       
   747 EXPORT_C void RMessageWindow::StartDisplay(TBool aFlash, TTimeIntervalMicroSeconds32 aInitialDelay, TTimeIntervalMicroSeconds32 aDuration, const TDesC& aText)
       
   748 /** Displays the message window for a specified time with an initial delay.
       
   749 
       
   750 @param aFlash Set this to true to make the message window flash.
       
   751 @param aInitialDelay Initial delay before showing the window.
       
   752 @param aDuration Duration for which to display the message window.
       
   753 @param aText Text to put in the window. */
       
   754 	{
       
   755 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed10));
       
   756 	TPckgBuf<SMessageWindowCommandStartDisplayArgs> args;
       
   757 	args().iFlash=aFlash;
       
   758 	args().iInitialDelay=aInitialDelay;
       
   759 	args().iDuration=aDuration;
       
   760 	args().iText=aText;
       
   761 	TInt error=CommandReply(EMessageWindowCommandStartDisplay, args);
       
   762 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError10));
       
   763 	}
       
   764 
       
   765 EXPORT_C void RMessageWindow::CancelDisplay()
       
   766 /** Cancels the display of the window. */
       
   767 	{
       
   768 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed11));
       
   769 	TInt error=CommandReply(EMessageWindowCommandCancelDisplay);
       
   770 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError11));
       
   771 	}
       
   772 
       
   773 EXPORT_C void RMessageWindow::GetBorders(TMargins& aBorders)
       
   774 /** Gets the widths of the window's borders.
       
   775 
       
   776 @param aBorders On return, the widths of the window's borders */
       
   777 	{
       
   778 	__ASSERT_ALWAYS(ConstructorBufAlreadySent(), Panic(EClockClientPanicNotYetFullyConstructed12));
       
   779 	TPckg<TMargins> borders(aBorders);
       
   780 	TIpcArgs ipcArgs;
       
   781 	ipcArgs.Set(KIpcSlot, &borders);
       
   782 	TInt error=CommandReply(EMessageWindowCommandGetBorders, KNullDesC8, ipcArgs);
       
   783 	__ASSERT_ALWAYS(error==KErrNone, Panic(EClockClientPanicUnexpectedError12));
       
   784 	}
       
   785