|
1 /* |
|
2 * Copyright (c) 1997-1999 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <gulbordr.h> |
|
20 #include <gulutil.h> |
|
21 #include <gdi.h> |
|
22 #include <gulcolor.h> |
|
23 #include <coecntrl.h> |
|
24 |
|
25 #include "LAFSTD.H" |
|
26 #include "LAFCMBUT.H" |
|
27 #include <uiklaf/private/lafenv.h> |
|
28 #include "lafcommn.h" |
|
29 #include "uikon.hrh" |
|
30 #include <eikon.hrh> |
|
31 #include "lafpublc.h" |
|
32 |
|
33 |
|
34 const TInt KPressedDepth=2; |
|
35 const TInt KSetDepth=1; |
|
36 const TInt KImageMargin=0; |
|
37 const TInt KLabelMargin=0; |
|
38 const TInt KIntraComponentMargin=2; |
|
39 |
|
40 const TInt KCommandButtonBaseHorizontalMargins=KPressedDepth; //deals with command,twopicturecommand & invertercommand buttons |
|
41 const TInt KCommandButtonBaseVerticalMargins=KPressedDepth; //deals with command,twopicturecommand & invertercommand buttons |
|
42 const TInt KBitmapButtonHorizontalMargins=2; |
|
43 const TInt KBitmapButtonVerticalMargins=2; |
|
44 const TInt KTextButtonHorizontalMargins=2; |
|
45 const TInt KTextButtonVerticalMargins=2; |
|
46 |
|
47 // The border types for the above set and pressed depths |
|
48 const TInt KBorderClear =TGulBorder::EDeepRaised; |
|
49 const TInt KBorderClearPressed =TGulBorder::EDeepSunken; |
|
50 const TInt KBorderSet =TGulBorder::EDeepSunken; |
|
51 const TInt KBorderSetPressed =TGulBorder::EDeepSunken; |
|
52 |
|
53 |
|
54 // |
|
55 // Class LafCommandButtonBase |
|
56 // |
|
57 |
|
58 /** |
|
59 * Gets the default border for the matched control in aBorder. Called from the constructor of the matched control. |
|
60 */ |
|
61 EXPORT_C void LafCommandButtonBase::GetDefaultBorder(TGulBorder& aBorder) |
|
62 { |
|
63 aBorder=KBorderClear; |
|
64 } |
|
65 |
|
66 /** |
|
67 * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained |
|
68 * may depend on the the display mode, the environment color list and the instance of the |
|
69 * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the |
|
70 * Draw() method of TGulBorder. |
|
71 */ |
|
72 EXPORT_C void LafCommandButtonBase::GetBorderColors(TGulBorder::TColors& aBorderColors,const MLafEnv& aLafEnv,const CCoeControl& aMatchedControl) |
|
73 { |
|
74 LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors, |
|
75 EColorButtonFaceClear, aLafEnv,aMatchedControl ); |
|
76 } |
|
77 |
|
78 /** |
|
79 * Gets the border appropriate for the behavior (including default buttons) and state of the control. |
|
80 */ |
|
81 EXPORT_C void LafCommandButtonBase::GetBorder(TGulBorder& aBorder, TInt aDrawState, |
|
82 TInt aFlags,const CCoeControl& /*aButtonBase*/, |
|
83 const TBool /*aIsDefaultButton*/) |
|
84 { |
|
85 TInt borderType = TGulBorder::ENone; |
|
86 |
|
87 if (aFlags&EEikButLatches) |
|
88 { |
|
89 switch (aDrawState) |
|
90 { |
|
91 case SLafButtonBase::EDrawClear: |
|
92 borderType = KBorderClear; |
|
93 break; |
|
94 case SLafButtonBase::EDrawClearPressed: |
|
95 borderType = KBorderClearPressed; |
|
96 break; |
|
97 case SLafButtonBase::EDrawSet: |
|
98 borderType = KBorderSet; |
|
99 break; |
|
100 case SLafButtonBase::EDrawSetPressed: |
|
101 borderType = KBorderSetPressed; |
|
102 break; |
|
103 default: |
|
104 __ASSERT_DEBUG(EFalse,Panic(ELafPanicConstantNotKnown)); |
|
105 break; |
|
106 } |
|
107 } |
|
108 else |
|
109 { |
|
110 switch (aDrawState) |
|
111 { |
|
112 case SLafButtonBase::EDrawSetPressed: |
|
113 borderType = KBorderSetPressed; |
|
114 break; |
|
115 case SLafButtonBase::EDrawClear: |
|
116 borderType = KBorderClear; |
|
117 break; |
|
118 case SLafButtonBase::EDrawClearPressed: |
|
119 case SLafButtonBase::EDrawSet: |
|
120 borderType = KBorderSet; |
|
121 break; |
|
122 default: |
|
123 __ASSERT_DEBUG(EFalse,Panic(ELafPanicConstantNotKnown)); |
|
124 break; |
|
125 } |
|
126 } |
|
127 |
|
128 aBorder.SetType(borderType); |
|
129 } |
|
130 |
|
131 EXPORT_C TInt LafCommandButtonBase::ComponentOffset(TInt aDrawState, TInt aFlags) |
|
132 { |
|
133 TInt pos = 0; |
|
134 if (aFlags&EEikButLatches) |
|
135 { |
|
136 switch (aDrawState) |
|
137 { |
|
138 default: |
|
139 case SLafButtonBase::EDrawClear: |
|
140 break; |
|
141 case SLafButtonBase::EDrawClearPressed: |
|
142 pos = KPressedDepth; |
|
143 break; |
|
144 case SLafButtonBase::EDrawSet: |
|
145 pos = KSetDepth; |
|
146 break; |
|
147 case SLafButtonBase::EDrawSetPressed: |
|
148 pos = KPressedDepth; |
|
149 break; |
|
150 } |
|
151 } |
|
152 else |
|
153 { |
|
154 switch (aDrawState) |
|
155 { |
|
156 case SLafButtonBase::EDrawSetPressed: |
|
157 pos = KPressedDepth; |
|
158 break; |
|
159 default: |
|
160 case SLafButtonBase::EDrawClear: |
|
161 break; |
|
162 case SLafButtonBase::EDrawClearPressed: |
|
163 case SLafButtonBase::EDrawSet: |
|
164 pos = KSetDepth; |
|
165 break; |
|
166 } |
|
167 } |
|
168 return pos; |
|
169 } |
|
170 |
|
171 |
|
172 /** |
|
173 * Prepares the basic graphic contents according to the the type of command |
|
174 * button, e.g. pen and brush colors. |
|
175 * |
|
176 * @since ER5U |
|
177 */ |
|
178 EXPORT_C void LafCommandButtonBase::PrepareContext(CWindowGc& aGc,TInt aDrawState, |
|
179 const MLafEnv& aLafEnv, |
|
180 const CCoeControl& aButtonBase) |
|
181 { |
|
182 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
183 TRgb penColor; |
|
184 TRgb brushColor; |
|
185 switch (aDrawState) |
|
186 { |
|
187 case SLafButtonBase::EDrawSet: |
|
188 penColor=aLafEnv.ControlColor(EColorButtonTextPressed,aButtonBase); |
|
189 brushColor=aLafEnv.ControlColor(EColorButtonFaceSet,aButtonBase); |
|
190 break; |
|
191 case SLafButtonBase::EDrawClearPressed: |
|
192 penColor=aLafEnv.ControlColor(EColorButtonTextPressed,aButtonBase); |
|
193 brushColor=aLafEnv.ControlColor(EColorButtonFaceClearPressed,aButtonBase); |
|
194 break; |
|
195 case SLafButtonBase::EDrawClear: |
|
196 penColor=aLafEnv.ControlColor(EColorButtonText,aButtonBase); |
|
197 brushColor=aLafEnv.ControlColor(EColorButtonFaceClear,aButtonBase); |
|
198 break; |
|
199 case SLafButtonBase::EDrawSetPressed: |
|
200 penColor=aLafEnv.ControlColor(EColorButtonText,aButtonBase); |
|
201 brushColor=aLafEnv.ControlColor(EColorButtonFaceSetPressed,aButtonBase); |
|
202 break; |
|
203 default: |
|
204 __ASSERT_DEBUG(EFalse,Panic(ELafPanicConstantNotKnown)); |
|
205 break; |
|
206 } |
|
207 aGc.SetPenColor(penColor); |
|
208 aGc.SetBrushColor(brushColor); |
|
209 } |
|
210 |
|
211 /** |
|
212 * Prepares the graphics context, picks the appropriate border colors, sets up internal rectangles |
|
213 * and draws border and internal controls. Also facilitates different drawing of selected buttons |
|
214 * and buttons with default focus. |
|
215 */ |
|
216 EXPORT_C void LafCommandButtonBase::Draw(const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl, |
|
217 CWindowGc& aGc, |
|
218 const TGulBorder& aBorder, |
|
219 TInt aDrawOffset,TInt aDrawState, |
|
220 TMargins8 aMargins, |
|
221 TBool /*aIsDefaultButton*/) |
|
222 { |
|
223 PrepareContext(aGc,aDrawState,aLafEnv,aMatchedControl); |
|
224 TGulBorder::TColors borderColors; |
|
225 GetBorderColors(borderColors,aLafEnv, aMatchedControl); |
|
226 const TRect rect(aMatchedControl.Rect()); |
|
227 aBorder.Draw(aGc, rect, borderColors); |
|
228 |
|
229 const TRect outerRect(aBorder.InnerRect(rect)); |
|
230 TRect innerRect(outerRect); |
|
231 |
|
232 innerRect.SetRect(innerRect.iTl.iX+aMargins.iLeft+1,innerRect.iTl.iY+aMargins.iTop+1, |
|
233 innerRect.iBr.iX-aMargins.iRight-1,innerRect.iBr.iY-aMargins.iBottom-1); |
|
234 innerRect.Move(aDrawOffset,aDrawOffset); |
|
235 innerRect.iBr.iX-=1; |
|
236 innerRect.iBr.iY-=1; |
|
237 |
|
238 DrawUtils::ClearBetweenRects(aGc,outerRect,innerRect); |
|
239 |
|
240 if(aMatchedControl.IsFocused()) |
|
241 DrawSelection(aBorder,rect,aGc); |
|
242 } |
|
243 |
|
244 EXPORT_C void LafCommandButtonBase::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) |
|
245 { // static |
|
246 TInt commonAttributes = TCoeColorUse::ESurrounds|TCoeColorUse::ENeutral; |
|
247 TCoeColorUse colorUse; |
|
248 |
|
249 colorUse.SetLogicalColor(EColorButtonText); |
|
250 colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EActive|TCoeColorUse::ENormal|commonAttributes); |
|
251 aColorUseList.AppendL(colorUse); |
|
252 |
|
253 colorUse.SetLogicalColor(EColorButtonFaceClear); |
|
254 colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|TCoeColorUse::ENormal|commonAttributes); |
|
255 aColorUseList.AppendL(colorUse); |
|
256 |
|
257 colorUse.SetLogicalColor(EColorButtonTextPressed); |
|
258 colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EPressed|TCoeColorUse::ENormal|commonAttributes); |
|
259 aColorUseList.AppendL(colorUse); |
|
260 |
|
261 colorUse.SetLogicalColor(EColorButtonFaceClearPressed); |
|
262 colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EPressed|TCoeColorUse::ENormal|commonAttributes); |
|
263 aColorUseList.AppendL(colorUse); |
|
264 |
|
265 colorUse.SetLogicalColor(EColorButtonFaceSet); |
|
266 colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|TCoeColorUse::ESet|commonAttributes); |
|
267 aColorUseList.AppendL(colorUse); |
|
268 |
|
269 colorUse.SetLogicalColor(EColorButtonFaceSetPressed); |
|
270 colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EPressed|TCoeColorUse::ESet|commonAttributes); |
|
271 aColorUseList.AppendL(colorUse); |
|
272 |
|
273 colorUse.SetLogicalColor(EColorLabelDimmedText); |
|
274 colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EPressed|TCoeColorUse::ESet|commonAttributes); |
|
275 aColorUseList.AppendL(colorUse); |
|
276 } |
|
277 |
|
278 /** |
|
279 * Draws a dashed rectangle inside the button. |
|
280 * |
|
281 * @since ER5U |
|
282 */ |
|
283 void LafCommandButtonBase::DrawSelection(const TGulBorder& aBorder,const TRect& aRect, |
|
284 CWindowGc& aGc) |
|
285 { |
|
286 aGc.SetPenStyle(CGraphicsContext::EDashedPen); |
|
287 TRect innerRect=aBorder.InnerRect(aRect); |
|
288 // innerRect.Shrink(1,1); |
|
289 TInt offset=2; |
|
290 innerRect.iTl.iX += 1; |
|
291 innerRect.iTl.iY += 1; |
|
292 innerRect.iBr.iX -= offset; |
|
293 innerRect.iBr.iY -= offset; |
|
294 TPoint posTl=innerRect.iTl; |
|
295 TPoint posBr=innerRect.iBr; |
|
296 aGc.DrawLine(posTl,TPoint(posBr.iX+1,posTl.iY)); |
|
297 aGc.DrawLine(posBr,TPoint(posBr.iX,posTl.iY)); |
|
298 aGc.DrawLine(posTl,TPoint(posTl.iX,posBr.iY)); |
|
299 aGc.DrawLine(posBr,TPoint(posTl.iX-1,posBr.iY)); |
|
300 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
301 } |
|
302 |
|
303 /** |
|
304 * @internal |
|
305 */ |
|
306 EXPORT_C TInt LafCommandButtonBase::Constant(TConstantType aConstant) |
|
307 {// static |
|
308 TInt retValue = 0; |
|
309 switch (aConstant) |
|
310 { |
|
311 case EImageMargin: |
|
312 retValue = KImageMargin; |
|
313 break; |
|
314 case ELabelMargin: |
|
315 retValue = KLabelMargin; |
|
316 break; |
|
317 case EIntraComponentMargin: |
|
318 retValue = KIntraComponentMargin; |
|
319 break; |
|
320 default: |
|
321 __ASSERT_DEBUG(EFalse, Panic(ELafPanicConstantNotKnown)); |
|
322 break; |
|
323 } |
|
324 return retValue; |
|
325 } |
|
326 |
|
327 // |
|
328 // Class LafCommandButton |
|
329 // |
|
330 EXPORT_C TMargins8 LafCommandButton::Margins() |
|
331 { |
|
332 TMargins8 margins; |
|
333 margins.iTop =KCommandButtonBaseVerticalMargins; |
|
334 margins.iBottom =KCommandButtonBaseVerticalMargins; |
|
335 margins.iLeft =KCommandButtonBaseHorizontalMargins; |
|
336 margins.iRight =KCommandButtonBaseHorizontalMargins; |
|
337 return margins; |
|
338 } |
|
339 |
|
340 |
|
341 // |
|
342 // Class LafTwoPictureCommandButton |
|
343 // |
|
344 EXPORT_C TMargins8 LafTwoPictureCommandButton::Margins() |
|
345 { |
|
346 TMargins8 margins; |
|
347 margins.iTop =KCommandButtonBaseVerticalMargins; |
|
348 margins.iBottom =KCommandButtonBaseVerticalMargins; |
|
349 margins.iLeft =KCommandButtonBaseHorizontalMargins; |
|
350 margins.iRight =KCommandButtonBaseHorizontalMargins; |
|
351 return margins; |
|
352 } |
|
353 |
|
354 |
|
355 // |
|
356 // Class LafInverterCommandButton |
|
357 // |
|
358 EXPORT_C TMargins8 LafInverterCommandButton::Margins() |
|
359 { |
|
360 TMargins8 margins; |
|
361 margins.iTop =KCommandButtonBaseVerticalMargins; |
|
362 margins.iBottom =KCommandButtonBaseVerticalMargins; |
|
363 margins.iLeft =KCommandButtonBaseHorizontalMargins; |
|
364 margins.iRight =KCommandButtonBaseHorizontalMargins; |
|
365 return margins; |
|
366 } |
|
367 |
|
368 |
|
369 // |
|
370 // Class LafBitmapButton |
|
371 // |
|
372 EXPORT_C TMargins8 LafBitmapButton::Margins() |
|
373 { |
|
374 TMargins8 margins; |
|
375 margins.iTop =KBitmapButtonVerticalMargins; |
|
376 margins.iBottom =KBitmapButtonVerticalMargins; |
|
377 margins.iLeft =KBitmapButtonHorizontalMargins; |
|
378 margins.iRight =KBitmapButtonHorizontalMargins; |
|
379 return margins; |
|
380 } |
|
381 |
|
382 // |
|
383 // Class LafTextButton |
|
384 // |
|
385 EXPORT_C TMargins8 LafTextButton::Margins() |
|
386 { |
|
387 TMargins8 margins; |
|
388 margins.iTop =KTextButtonVerticalMargins; |
|
389 margins.iBottom =KTextButtonVerticalMargins; |
|
390 margins.iLeft =KTextButtonHorizontalMargins; |
|
391 margins.iRight =KTextButtonHorizontalMargins; |
|
392 return margins; |
|
393 } |
|
394 |
|
395 // |
|
396 // Class LafTwoPictureCommandButton |
|
397 // |
|
398 |
|
399 /** |
|
400 * Gets the default border for the matched control in aBorder. Called from the constructor of the matched control. |
|
401 */ |
|
402 EXPORT_C void LafTwoPictureCommandButton::GetDefaultBorder(TGulBorder& aBorder) |
|
403 { |
|
404 aBorder=TGulBorder(TGulBorder::ENone); |
|
405 } |
|
406 |
|
407 /** |
|
408 * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained |
|
409 * may depend on the the display mode, the environment color list and the instance of the |
|
410 * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the |
|
411 * Draw() method of TGulBorder. |
|
412 */ |
|
413 EXPORT_C void LafTwoPictureCommandButton::GetBorderColors(TGulBorder::TColors& aBorderColors, const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl) |
|
414 { |
|
415 LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors, |
|
416 EColorButtonFaceClear, aLafEnv,aMatchedControl ); |
|
417 } |
|
418 |
|
419 |