|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Model class for control button. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_FSCONTROLBUTTONMODEL_H |
|
20 #define C_FSCONTROLBUTTONMODEL_H |
|
21 //<cmail> SF |
|
22 #include <alf/alftexture.h> |
|
23 //</cmail> |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "fscontrolbuttonconst.h" |
|
27 #include "fscontrolbuttoninterface.h" |
|
28 |
|
29 class CAlfLayout; |
|
30 |
|
31 /** |
|
32 * Model class of ControlButton component |
|
33 * |
|
34 * @code |
|
35 * |
|
36 * @endcode |
|
37 * |
|
38 * @lib ?library |
|
39 */ |
|
40 NONSHARABLE_CLASS( CFsControlButtonModel ) : public CBase |
|
41 { |
|
42 |
|
43 public: |
|
44 |
|
45 /** Defines button states */ |
|
46 enum TFsButtonStateType |
|
47 { |
|
48 EButtonNormal, |
|
49 EButtonFocused, |
|
50 EButtonDimmed, |
|
51 EButtonBackground |
|
52 }; |
|
53 |
|
54 /** |
|
55 * Two-phased constructor. |
|
56 */ |
|
57 static CFsControlButtonModel* NewL( TInt aId, TFsControlButtonType aType, |
|
58 const TRect& aStartPoint, CAlfLayout& aParentLayout ); |
|
59 |
|
60 /** |
|
61 * Destructor |
|
62 */ |
|
63 virtual ~CFsControlButtonModel(); |
|
64 |
|
65 /** |
|
66 * Sets id of the button. |
|
67 * |
|
68 * @param aId id to be set. |
|
69 */ |
|
70 void SetId( TInt aId ); |
|
71 |
|
72 /** |
|
73 * Retrieves button's id. |
|
74 * |
|
75 * @return button's id. |
|
76 */ |
|
77 TInt Id(); |
|
78 |
|
79 /** |
|
80 * Sets type of the button. |
|
81 * |
|
82 * @param aType type to be set. |
|
83 */ |
|
84 void SetType( TFsControlButtonType aType ); |
|
85 |
|
86 /** |
|
87 * Retrieves button's type. |
|
88 * |
|
89 * @return button's type. |
|
90 */ |
|
91 TFsControlButtonType Type(); |
|
92 |
|
93 /** |
|
94 * Sets first line of text of the button. |
|
95 * |
|
96 * @param aLabel text to be set. |
|
97 * @param aContent Specifies the text element. |
|
98 */ |
|
99 void SetTextL( |
|
100 const TDesC& aLabel, |
|
101 MFsControlButtonInterface::TFsButtonContent aContent ); |
|
102 |
|
103 /** |
|
104 * Change the color of defined target. |
|
105 * |
|
106 * @param aColor New color. |
|
107 * @param aType Target type. |
|
108 */ |
|
109 void SetTextColor( const TRgb& aColor, TFsButtonStateType aType ); |
|
110 |
|
111 /** |
|
112 * Retrieves the requested target color. |
|
113 * |
|
114 * @param aType Target type. |
|
115 * @return Color of requested target. |
|
116 */ |
|
117 const TRgb& TextColor( TFsButtonStateType aType ) const; |
|
118 |
|
119 /** |
|
120 * Retrieves first line of button's text. |
|
121 * |
|
122 * @param aContent Specifies the text element. |
|
123 * @return button's text. |
|
124 */ |
|
125 TPtrC Text( MFsControlButtonInterface::TFsButtonContent aContent ); |
|
126 |
|
127 /** |
|
128 * Horizontal padding for text in button. |
|
129 * |
|
130 * @param aType Type of the button. |
|
131 * @return Horizontal padding. |
|
132 */ |
|
133 TInt LabelHPadding( TFsControlButtonType aType ) const; |
|
134 |
|
135 /** |
|
136 * Vertical padding for text in button. |
|
137 * |
|
138 * @param aType Type of the button. |
|
139 * @return Vertical padding. |
|
140 */ |
|
141 TInt LabelVPadding( TFsControlButtonType aType ) const; |
|
142 |
|
143 /** |
|
144 * Sets width of the button. |
|
145 * |
|
146 * @param aWidth width to be set. |
|
147 */ |
|
148 void SetWidth( TInt aWidth ); |
|
149 |
|
150 /** |
|
151 * Set size for the button. |
|
152 * |
|
153 * @param aSize New size of the button. |
|
154 */ |
|
155 void SetSize( TSize aSize ); |
|
156 |
|
157 /** |
|
158 * Retrieves size of the button. |
|
159 * |
|
160 * @return size of the button. |
|
161 */ |
|
162 const TSize& Size() const; |
|
163 |
|
164 /** |
|
165 * Set auto size mode for button. |
|
166 * Defines how the buttons size is changed. |
|
167 * |
|
168 * @param aAutoSizeMode new mode. |
|
169 */ |
|
170 void SetAutoSizeMode( |
|
171 MFsControlButtonInterface::TFsAutoSizeMode aAutoSizeMode ); |
|
172 |
|
173 /** |
|
174 * Resolve the current mode. |
|
175 * |
|
176 * @return Current auto size mode. |
|
177 */ |
|
178 MFsControlButtonInterface::TFsAutoSizeMode AutoSizeMode(); |
|
179 |
|
180 /** |
|
181 * Sets focus to control button. |
|
182 * |
|
183 * @param aState state of focus. |
|
184 */ |
|
185 void SetFocus( TBool aState = ETrue ); |
|
186 |
|
187 /** |
|
188 * Checks if button has focus. |
|
189 * |
|
190 * @return ETrue if focused, EFalse otherwise. |
|
191 */ |
|
192 TBool IsFocused(); |
|
193 |
|
194 /** |
|
195 * Sets dimmed state of control button. |
|
196 * |
|
197 * @param aDimmed state of control button. |
|
198 */ |
|
199 void SetDimmed( TBool aDimmed = ETrue ); |
|
200 |
|
201 /** |
|
202 * Checks if button is dimmed (read only). |
|
203 * |
|
204 * @return ETrue if enabled, EFalse otherwise. |
|
205 */ |
|
206 TBool IsDimmed(); |
|
207 |
|
208 /** |
|
209 * Sets icon in the button. |
|
210 * |
|
211 * @param aIcon icon to be added. |
|
212 * @param aElemType specifies which icon is to be added, A or B. |
|
213 */ |
|
214 void SetIconL( CAlfTexture& aIcon, |
|
215 TFsControlButtonElem aElemType = ECBElemIconA ); |
|
216 |
|
217 /** |
|
218 * Retrieves specified icon image. |
|
219 * |
|
220 * @param aElemType icon to be retrieved. |
|
221 * @return icon image. |
|
222 */ |
|
223 CAlfTexture* Icon( TFsControlButtonElem aElemType ); |
|
224 |
|
225 // <cmail> Platform layout changes |
|
226 /** |
|
227 * Sets position of the button. |
|
228 * |
|
229 * @param aTlPoint top left point of the button. |
|
230 * @param aClearFlag ETrue to remove autopositioning flag from the button, |
|
231 * EFalse otherwise. |
|
232 */ |
|
233 void SetPos( const TPoint& aTlPoint, TBool aClearFlag = ETrue ); |
|
234 // </cmail> Platform layout changes |
|
235 |
|
236 /** |
|
237 * Retrieves top left point of the button. |
|
238 * |
|
239 * @return top left point of the button. |
|
240 */ |
|
241 TPoint TopLeftPoint(); |
|
242 |
|
243 /** |
|
244 * Checks if current set button type contains specified icon type. |
|
245 * |
|
246 * @param aWhich icon to be checked. |
|
247 * @return ETrue if contains, WFalse otherwise. |
|
248 */ |
|
249 TBool ContainsElement( TFsControlButtonElem aWhich ); |
|
250 |
|
251 /** |
|
252 * Checks if size of button was changed. |
|
253 * |
|
254 * @return ETrue if width or height changed, EFalse otherwise. |
|
255 */ |
|
256 TBool ButtonSizeChanged(); |
|
257 |
|
258 /** |
|
259 * Checks if position of button was changed. |
|
260 * |
|
261 * @return ETrue if position changed, EFalse otherwise. |
|
262 */ |
|
263 TBool ButtonPosChanged(); |
|
264 |
|
265 /** |
|
266 * Checks if button should be automatically positioned. |
|
267 * |
|
268 * @return ETrue if button should be positioned automatically |
|
269 * EFalse if position was set to fixed value. |
|
270 */ |
|
271 TBool AutoPosition(); |
|
272 |
|
273 /** |
|
274 * Resolve the button's size from layout. |
|
275 * |
|
276 * @return Button's layout defined size. |
|
277 */ |
|
278 TSize GetLayoutSize(); |
|
279 |
|
280 /** |
|
281 * Resolve the button's size from layout. |
|
282 * |
|
283 * @param aParentRect Size and position of the parent rect. |
|
284 * @return Button's layout defined size. |
|
285 */ |
|
286 TSize GetLayoutSize( TRect& aParentRect ); |
|
287 |
|
288 /** |
|
289 * Get the layout position on controlbar. |
|
290 * |
|
291 * @return Layout position on controlbar. |
|
292 */ |
|
293 TInt GetLayoutPos(); |
|
294 |
|
295 /** |
|
296 * Set the layout position index on controlbar. |
|
297 * |
|
298 * @param aLayoutPos New layout position on controlbar. |
|
299 */ |
|
300 void SetParentIndex( TInt aLayoutPos ); |
|
301 |
|
302 /** |
|
303 * Resolve if layout data is used to define the size of the button. |
|
304 * |
|
305 * @return ETrue if layout data is used, otherwise EFalse. |
|
306 */ |
|
307 TBool IsLayoutSize(); |
|
308 |
|
309 /** |
|
310 * Refresh button's position. |
|
311 * |
|
312 * @param aParentSize Size of the button's parent. |
|
313 */ |
|
314 void RefreshButtonPosition( const TSize& aParentSize ); |
|
315 |
|
316 private: |
|
317 |
|
318 CFsControlButtonModel( TInt aId, TFsControlButtonType aType, |
|
319 const TRect& aStartPoint, CAlfLayout& aParentLayout ); |
|
320 |
|
321 /** |
|
322 * Constructs and initializes button's model. |
|
323 */ |
|
324 void ConstructL(); |
|
325 |
|
326 private: // data |
|
327 |
|
328 /** |
|
329 * Button's type. |
|
330 */ |
|
331 TFsControlButtonType iType; |
|
332 |
|
333 /** |
|
334 * Button's id value. |
|
335 */ |
|
336 TInt iId; |
|
337 |
|
338 /** |
|
339 * Focus flag for the button. |
|
340 */ |
|
341 TBool iFocused; |
|
342 |
|
343 /** |
|
344 * Texture of A icon of the button. |
|
345 * Not own. |
|
346 */ |
|
347 CAlfTexture* iIconA; |
|
348 |
|
349 /** |
|
350 * Texture of B icon of the button. |
|
351 * Not own. |
|
352 */ |
|
353 CAlfTexture* iIconB; |
|
354 |
|
355 /** |
|
356 * First line of text |
|
357 * Own. |
|
358 */ |
|
359 HBufC* iFirstTextLine; |
|
360 |
|
361 /** |
|
362 * Second line of text |
|
363 * Own. |
|
364 */ |
|
365 HBufC* iSecondTextLine; |
|
366 |
|
367 /** |
|
368 * Text horizontal padding for one text line item. |
|
369 */ |
|
370 TInt iLabelHPadding1; |
|
371 |
|
372 /** |
|
373 * Text horizontal padding for two text lines item. |
|
374 */ |
|
375 TInt iLabelHPadding2; |
|
376 |
|
377 /** |
|
378 * Text vertical padding for one text line item. |
|
379 */ |
|
380 TInt iLabelVPadding1; |
|
381 |
|
382 /** |
|
383 * Text vertical padding for two text lines item. |
|
384 */ |
|
385 TInt iLabelVPadding2; |
|
386 |
|
387 /** |
|
388 * Normal button text color. |
|
389 */ |
|
390 TRgb iColorNormal; |
|
391 |
|
392 /** |
|
393 * Focused button text color. |
|
394 */ |
|
395 TRgb iColorFocused; |
|
396 |
|
397 /** |
|
398 * Dimmed button text color. |
|
399 */ |
|
400 TRgb iColorDimmed; |
|
401 |
|
402 /** |
|
403 * Button's background color. |
|
404 */ |
|
405 TRgb iColorBackground; |
|
406 |
|
407 /** |
|
408 * Start point of the button (TopLeft) |
|
409 */ |
|
410 TPoint iStartPoint; |
|
411 |
|
412 /** |
|
413 * Flag for dimmed state. |
|
414 */ |
|
415 TBool iDimmed; |
|
416 |
|
417 /** |
|
418 * Flag for size changed. |
|
419 */ |
|
420 TBool iSizeChanged; |
|
421 |
|
422 /** |
|
423 * Is button auto posiotioned or has fixed position. |
|
424 */ |
|
425 TBool iAutoPosition; |
|
426 |
|
427 /** |
|
428 * Flag for position changed. |
|
429 */ |
|
430 TBool iPosChanged; |
|
431 |
|
432 /** |
|
433 * Size of the item. |
|
434 */ |
|
435 TSize iSize; |
|
436 |
|
437 /** |
|
438 * Current autosize mode info. |
|
439 */ |
|
440 MFsControlButtonInterface::TFsAutoSizeMode iAutoSizeMode; |
|
441 |
|
442 /** |
|
443 * Reference to button's layout. |
|
444 */ |
|
445 CAlfLayout& iParentLayout; |
|
446 |
|
447 /** |
|
448 * Position on controlbar. |
|
449 */ |
|
450 TInt iLayoutPos; |
|
451 |
|
452 /** |
|
453 * Bit to define if layout data used to define buttons size. |
|
454 */ |
|
455 TBool iUseLayoutData; |
|
456 |
|
457 /** |
|
458 * Button's manually set position. Used to determine mirrored position. |
|
459 */ |
|
460 TPoint iManualSetPos; |
|
461 |
|
462 }; |
|
463 |
|
464 |
|
465 #endif // C_FSCONTROLBUTTONMODEL_H |