windowing/windowserver/nga/CLIENT/RSPRITE.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 1996-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 // Client side sprite code
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include "../SERVER/w32cmd.h"
       
    20 #include "CLIENT.H"
       
    21 
       
    22 TCmdSpriteMember::TCmdSpriteMember(const TSpriteMember &aSpriteMember)
       
    23 	{
       
    24 	if (aSpriteMember.iBitmap)
       
    25 		{
       
    26 		iBitmap=aSpriteMember.iBitmap->Handle();
       
    27 		iMaskBitmap=(aSpriteMember.iMaskBitmap) ? aSpriteMember.iMaskBitmap->Handle() : 0;
       
    28 		iInvertMask=aSpriteMember.iInvertMask;
       
    29 		iDrawMode=aSpriteMember.iDrawMode;
       
    30 		iOffset=aSpriteMember.iOffset;
       
    31 		}
       
    32 	else
       
    33 		Mem::FillZ(this,sizeof(*this));
       
    34 	iInterval=aSpriteMember.iInterval;
       
    35 	}
       
    36 
       
    37 //
       
    38 // RWsSpriteBase
       
    39 //
       
    40 
       
    41 EXPORT_C RWsSpriteBase::RWsSpriteBase()
       
    42 /** Protected constructor. 
       
    43 
       
    44 This prevents objects of this type being directly created. */
       
    45 	{}
       
    46 
       
    47 EXPORT_C RWsSpriteBase::RWsSpriteBase(RWsSession &aWs) : MWsClientClass(aWs.iBuffer)
       
    48 /** Protected constructor with a window server session. 
       
    49 
       
    50 This prevents objects of this type being directly created.
       
    51 
       
    52 @param aWs The window server session owning the sprite. */
       
    53 	{}
       
    54 
       
    55 EXPORT_C TInt RWsSpriteBase::UpdateMember(TInt aIndex, const TSpriteMember &aMemberData)
       
    56 /** Replaces one of a sprite's members. 
       
    57 
       
    58 This allows the appearance of the sprite to be modified after it has been 
       
    59 activated. 
       
    60 
       
    61 You must call this function if you have changed the size of a member. After 
       
    62 calling it, the sprite starts showing member zero again.
       
    63 
       
    64 This function always causes a flush of the window server buffer.
       
    65 
       
    66 @param aIndex Index of the sprite member. Sprite members are indexed in the 
       
    67 order they were added to the sprite, beginning with 0. 
       
    68 @param aMemberData New data for the sprite member. 
       
    69 @return KErrNone if successful, otherwise one of the system-wide error codes. */
       
    70 	{
       
    71 	TWsSpriteCmdUpdateMember params(aIndex,aMemberData);
       
    72 	return(WriteReply(&params,sizeof(params),EWsSpriteOpUpdateMember2));
       
    73 	}
       
    74 
       
    75 EXPORT_C void RWsSpriteBase::UpdateMember(TInt aIndex)
       
    76 /** Updates the displayed sprite, taking into account any change to the content 
       
    77 of the bitmaps for the specified member.
       
    78 
       
    79 The appearance of a sprite can be changed after it has been activated by drawing 
       
    80 to the appropriate TSpriteMember::iBitmap member, and then calling this function. 
       
    81 Alternatively, a new sprite member can be created, containing a new bitmap, 
       
    82 and the sprite can be updated to contain this new member by calling the other 
       
    83 UpdateMember() overload.
       
    84 
       
    85 You should only use this function if you have changed the content of 
       
    86 the bitmap or mask. If you have changed the size of the bitmap then you must 
       
    87 use the other overload.
       
    88 
       
    89 You only need to call this function if you want the content of the screen 
       
    90 to update immediately. If you don't call this function then the appearance 
       
    91 of a member will update automatically next time that member is drawn to the 
       
    92 screen.
       
    93 
       
    94 @param aIndex Index of the sprite member. Sprite members are indexed in the 
       
    95 order they were added to the sprite, beginning with 0. */
       
    96 	{
       
    97 	WriteInt(aIndex, EWsSpriteOpUpdateMember);
       
    98 	}
       
    99 
       
   100 EXPORT_C void RWsSpriteBase::Close()
       
   101 /** Destroys the sprite or pointer cursor in the window server, and frees client-side 
       
   102 resources used by the sprite. 
       
   103 
       
   104 Any application which constructs an RWsSprite or RWsPointerCursor should call 
       
   105 this function when the sprite or cursor is no longer needed.
       
   106 
       
   107 Note that this function does not free resources used by sprite members. */
       
   108 	{
       
   109 	if (iBuffer && iWsHandle)
       
   110 		Write(EWsSpriteOpFree);
       
   111 	iWsHandle=NULL;
       
   112 	}
       
   113 
       
   114 EXPORT_C TInt RWsSpriteBase::Activate()
       
   115 /** Activates the sprite or pointer cursor.
       
   116 
       
   117 Sprites are displayed on the screen when they are activated; pointer cursors 
       
   118 are not displayed until they are set into a window using either RWindowTreeNode::SetCustomPointerCursor() 
       
   119 or RWindowTreeNode::SetPointerCursor(). 
       
   120 
       
   121 This function should not be called until the sprite or pointer cursor has 
       
   122 been fully initialised, and its sprite members have been added.
       
   123 
       
   124 Before it can call this function, a sprite must be fully constructed using 
       
   125 the RWsSprite::RWsSprite(RWsSession& aWs) and RWsSprite::Construct() functions, 
       
   126 and must have at least one sprite member. Otherwise, a panic will occur. Similarly, 
       
   127 a pointer cursor must have at least one sprite member and must call RWsPointerCursor::RWsPointerCursor(RWsSession& 
       
   128 aWs) and RWsPointerCursor::Construct().
       
   129  
       
   130 This function always causes a flush of the window server buffer.
       
   131 
       
   132 @return KErrNone if successful, otherwise one of the system-wide error codes.
       
   133 @panic If no member is present, a panic will occur. */
       
   134 	{
       
   135 	return(WriteReply(EWsSpriteOpActivate));
       
   136 	}
       
   137 
       
   138 EXPORT_C TInt RWsSpriteBase::AppendMember(const TSpriteMember &aMemberData)
       
   139 /** Adds a sprite member to a sprite or pointer cursor. 
       
   140 
       
   141 Sprite members are displayed by the sprite in the order in which they were 
       
   142 added to the sprite. This function can be called before and after the sprite 
       
   143 has been activated.
       
   144 
       
   145 The position of the bitmap can be changed in relation to the sprite's origin 
       
   146 using the iOffset member of aSpriteList.
       
   147  
       
   148 This function always causes a flush of the window server buffer.
       
   149 
       
   150 @param aMemberData The sprite member to add.
       
   151 @return KErrNone if successful, otherwise one of the system-wide error codes. */
       
   152 	{
       
   153 	TCmdSpriteMember params(aMemberData);
       
   154 	return(WriteReply(&params,sizeof(params),EWsSpriteOpAppendMember));
       
   155 	}
       
   156 
       
   157 //
       
   158 // RWsSprite
       
   159 //
       
   160 
       
   161 EXPORT_C RWsSprite::RWsSprite() : RWsSpriteBase()
       
   162 /** Default C++ constructor. 
       
   163 
       
   164 This allows classes that contain an RWsSprite to be constructed before an 
       
   165 RWsSession exists.
       
   166 
       
   167 Note: do not use this version of the constructor on its own. Before an RWsSprite 
       
   168 object can be used it must be constructed using the RWsSprite(RWsSession) 
       
   169 constructor. An example of this might be as follows:
       
   170 
       
   171 @code
       
   172 RWsSprite iSprite;
       
   173 iSprite=RWsSprite(iWsSession);
       
   174 @endcode */
       
   175 	{}
       
   176 
       
   177 EXPORT_C RWsSprite::RWsSprite(RWsSession &aWs) : RWsSpriteBase(aWs)
       
   178 /** Constructs a sprite with a window server session. 
       
   179 
       
   180 Initialisation must be completed using the Construct() function before the 
       
   181 sprite can be activated using RWsSpriteBase::Activate().
       
   182 
       
   183 @param aWs The window server session owning the sprite. */
       
   184 	{}
       
   185 
       
   186 EXPORT_C TInt RWsSprite::Construct(RWindowTreeNode &aWindow, const TPoint &aPos, TInt aFlags)
       
   187 /** Completes the construction of a sprite. 
       
   188 
       
   189 This function must be called before a sprite is activated using RWsSpriteBase::Activate().
       
   190  
       
   191 It always causes a flush of the window server buffer.
       
   192 
       
   193 @param aWindow The window in which the sprite is displayed.
       
   194 @param aPos The position of the sprite's origin relative to aWindow's origin. 
       
   195 The origin is the top left corner of the window. 
       
   196 @param aFlags Any one of the TSpriteFlags values, or a combination of the flags, 
       
   197 using a bit-wise OR operation.
       
   198 @return KErrNone if successful, otherwise one of the system-wide error codes. 
       
   199 @panic TW32Panic 17 in debug builds if called on an already constructed object.
       
   200 @see TSpriteFlags */
       
   201 	{
       
   202 	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
       
   203 	TWsClCmdCreateSprite params(aWindow.WsHandle(),aPos,aFlags);
       
   204 	TInt ret;
       
   205 	if ((ret=iBuffer->WriteReplyWs(&params,sizeof(params),EWsClOpCreateSprite))>=0)
       
   206 		{
       
   207 		iWsHandle=ret;
       
   208 		ret=KErrNone;
       
   209 		}
       
   210 	return(ret);
       
   211 	}
       
   212 
       
   213 EXPORT_C void RWsSprite::SetPosition(const TPoint &aPos)
       
   214 /** Sets the sprite's position. 
       
   215 
       
   216 This function can be called before or after the sprite has been activated. 
       
   217 
       
   218 Note: the sprite's initial position is set when the sprite is constructed (see Construct()).
       
   219 
       
   220 @param aPos Position of the sprite's origin relative to the origin of the 
       
   221 window that owns it. The origin is the top left corner of the window. */
       
   222 	{
       
   223 	WritePoint(aPos,EWsSpriteOpSetPosition);
       
   224 	}
       
   225 
       
   226 //
       
   227 // RWsPointerCursor
       
   228 //
       
   229 
       
   230 EXPORT_C RWsPointerCursor::RWsPointerCursor() : RWsSpriteBase()
       
   231 /** Default C++ constructor. 
       
   232 
       
   233 Use this constructor to allow classes that contain an RWsPointerCursor 
       
   234 to be constructed before an RWsSession exists.
       
   235 
       
   236 Note: do not use this version of the constructor on its own. 
       
   237 Before an RWsPointerCursor object can be used, it must be constructed 
       
   238 using the RWsPointerCursor(RWsSession) constructor. An example of this 
       
   239 might be as follows:
       
   240 
       
   241 @code
       
   242 RWsPointerCursor pointerCursor;
       
   243 pointerCursor=RWsPointerCursor(iWsSession);
       
   244 @endcode */
       
   245 	{}
       
   246 
       
   247 EXPORT_C RWsPointerCursor::RWsPointerCursor(RWsSession &aWs) : RWsSpriteBase(aWs)
       
   248 /** Constructs a pointer cursor initialised with a window server session. 
       
   249 
       
   250 Initialisation must be completed using the Construct() function before the 
       
   251 sprite can be activated using RWsSpriteBase::Activate().
       
   252 
       
   253 Once initialisation is complete, the pointer cursor can be passed as an argument 
       
   254 to RWsSession::SetSystemPointerCursor() or RWindowTreeNode::SetCustomPointerCursor().
       
   255 
       
   256 @param aWs The window server session owning the pointer cursor. */
       
   257 	{}
       
   258 
       
   259 EXPORT_C TInt RWsPointerCursor::Construct(TInt aFlags)
       
   260 /** Completes pointer cursor construction. 
       
   261 
       
   262 This function must be called before the pointer cursor is activated.
       
   263  
       
   264 It always causes a flush of the window server buffer.
       
   265 
       
   266 @param aFlags ESpriteFlash to flash the sprite on and off or 0 for a non-flashing 
       
   267 cursor. Note that pointer cursors always behave as if ESpriteNoChildClip and 
       
   268 ESpriteNoShadows are set. 
       
   269 @return KErrNone if successful, otherwise one of the system-wide error codes. 
       
   270 @panic TW32Panic 17 in debug builds if called on an already constructed object.
       
   271 */
       
   272 	{
       
   273 	__ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction));
       
   274 	TWsClCmdCreatePointerCursor params;
       
   275 	params.flags=aFlags;
       
   276 	TInt ret;
       
   277 	if ((ret=iBuffer->WriteReplyWs(&params,sizeof(params),EWsClOpCreatePointerCursor))>=0)
       
   278 		{
       
   279 		iWsHandle=ret;
       
   280 		ret=KErrNone;
       
   281 		}
       
   282 	return(ret);
       
   283 	}