|
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(¶ms,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 { |
|
134 return(WriteReply(EWsSpriteOpActivate)); |
|
135 } |
|
136 |
|
137 EXPORT_C TInt RWsSpriteBase::AppendMember(const TSpriteMember &aMemberData) |
|
138 /** Adds a sprite member to a sprite or pointer cursor. |
|
139 |
|
140 Sprite members are displayed by the sprite in the order in which they were |
|
141 added to the sprite. This function can be called before and after the sprite |
|
142 has been activated. |
|
143 |
|
144 The position of the bitmap can be changed in relation to the sprite's origin |
|
145 using the iOffset member of aSpriteList. |
|
146 |
|
147 This function always causes a flush of the window server buffer. |
|
148 |
|
149 @param aMemberData The sprite member to add. |
|
150 @return KErrNone if successful, otherwise one of the system-wide error codes. */ |
|
151 { |
|
152 TCmdSpriteMember params(aMemberData); |
|
153 return(WriteReply(¶ms,sizeof(params),EWsSpriteOpAppendMember)); |
|
154 } |
|
155 |
|
156 // |
|
157 // RWsSprite |
|
158 // |
|
159 |
|
160 EXPORT_C RWsSprite::RWsSprite() : RWsSpriteBase() |
|
161 /** Default C++ constructor. |
|
162 |
|
163 This allows classes that contain an RWsSprite to be constructed before an |
|
164 RWsSession exists. |
|
165 |
|
166 Note: do not use this version of the constructor on its own. Before an RWsSprite |
|
167 object can be used it must be constructed using the RWsSprite(RWsSession) |
|
168 constructor. An example of this might be as follows: |
|
169 |
|
170 @code |
|
171 RWsSprite iSprite; |
|
172 iSprite=RWsSprite(iWsSession); |
|
173 @endcode */ |
|
174 {} |
|
175 |
|
176 EXPORT_C RWsSprite::RWsSprite(RWsSession &aWs) : RWsSpriteBase(aWs) |
|
177 /** Constructs a sprite with a window server session. |
|
178 |
|
179 Initialisation must be completed using the Construct() function before the |
|
180 sprite can be activated using RWsSpriteBase::Activate(). |
|
181 |
|
182 @param aWs The window server session owning the sprite. */ |
|
183 {} |
|
184 |
|
185 EXPORT_C TInt RWsSprite::Construct(RWindowTreeNode &aWindow, const TPoint &aPos, TInt aFlags) |
|
186 /** Completes the construction of a sprite. |
|
187 |
|
188 This function must be called before a sprite is activated using RWsSpriteBase::Activate(). |
|
189 |
|
190 It always causes a flush of the window server buffer. |
|
191 |
|
192 @param aWindow The window in which the sprite is displayed. |
|
193 @param aPos The position of the sprite's origin relative to aWindow's origin. |
|
194 The origin is the top left corner of the window. |
|
195 @param aFlags Any one of the TSpriteFlags values, or a combination of the flags, |
|
196 using a bit-wise OR operation. |
|
197 @return KErrNone if successful, otherwise one of the system-wide error codes. |
|
198 @panic TW32Panic 17 in debug builds if called on an already constructed object. |
|
199 @see TSpriteFlags */ |
|
200 { |
|
201 __ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction)); |
|
202 TWsClCmdCreateSprite params(aWindow.WsHandle(),aPos,aFlags); |
|
203 TInt ret; |
|
204 if ((ret=iBuffer->WriteReplyWs(¶ms,sizeof(params),EWsClOpCreateSprite))>=0) |
|
205 { |
|
206 iWsHandle=ret; |
|
207 ret=KErrNone; |
|
208 } |
|
209 return(ret); |
|
210 } |
|
211 |
|
212 EXPORT_C void RWsSprite::SetPosition(const TPoint &aPos) |
|
213 /** Sets the sprite's position. |
|
214 |
|
215 This function can be called before or after the sprite has been activated. |
|
216 |
|
217 Note: the sprite's initial position is set when the sprite is constructed (see Construct()). |
|
218 |
|
219 @param aPos Position of the sprite's origin relative to the origin of the |
|
220 window that owns it. The origin is the top left corner of the window. */ |
|
221 { |
|
222 WritePoint(aPos,EWsSpriteOpSetPosition); |
|
223 } |
|
224 |
|
225 // |
|
226 // RWsPointerCursor |
|
227 // |
|
228 |
|
229 EXPORT_C RWsPointerCursor::RWsPointerCursor() : RWsSpriteBase() |
|
230 /** Default C++ constructor. |
|
231 |
|
232 Use this constructor to allow classes that contain an RWsPointerCursor |
|
233 to be constructed before an RWsSession exists. |
|
234 |
|
235 Note: do not use this version of the constructor on its own. |
|
236 Before an RWsPointerCursor object can be used, it must be constructed |
|
237 using the RWsPointerCursor(RWsSession) constructor. An example of this |
|
238 might be as follows: |
|
239 |
|
240 @code |
|
241 RWsPointerCursor pointerCursor; |
|
242 pointerCursor=RWsPointerCursor(iWsSession); |
|
243 @endcode */ |
|
244 {} |
|
245 |
|
246 EXPORT_C RWsPointerCursor::RWsPointerCursor(RWsSession &aWs) : RWsSpriteBase(aWs) |
|
247 /** Constructs a pointer cursor initialised with a window server session. |
|
248 |
|
249 Initialisation must be completed using the Construct() function before the |
|
250 sprite can be activated using RWsSpriteBase::Activate(). |
|
251 |
|
252 Once initialisation is complete, the pointer cursor can be passed as an argument |
|
253 to RWsSession::SetSystemPointerCursor() or RWindowTreeNode::SetCustomPointerCursor(). |
|
254 |
|
255 @param aWs The window server session owning the pointer cursor. */ |
|
256 {} |
|
257 |
|
258 EXPORT_C TInt RWsPointerCursor::Construct(TInt aFlags) |
|
259 /** Completes pointer cursor construction. |
|
260 |
|
261 This function must be called before the pointer cursor is activated. |
|
262 |
|
263 It always causes a flush of the window server buffer. |
|
264 |
|
265 @param aFlags ESpriteFlash to flash the sprite on and off or 0 for a non-flashing |
|
266 cursor. Note that pointer cursors always behave as if ESpriteNoChildClip and |
|
267 ESpriteNoShadows are set. |
|
268 @return KErrNone if successful, otherwise one of the system-wide error codes. */ |
|
269 { |
|
270 __ASSERT_DEBUG(iWsHandle == KNullHandle, Panic(EW32PanicGraphicDoubleConstruction)); |
|
271 TWsClCmdCreatePointerCursor params; |
|
272 params.flags=aFlags; |
|
273 TInt ret; |
|
274 if ((ret=iBuffer->WriteReplyWs(¶ms,sizeof(params),EWsClOpCreatePointerCursor))>=0) |
|
275 { |
|
276 iWsHandle=ret; |
|
277 ret=KErrNone; |
|
278 } |
|
279 return(ret); |
|
280 } |