|
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 <gulfont.h> |
|
20 #include <gulcolor.h> |
|
21 #include <gulicon.h> |
|
22 #include <gulutil.h> |
|
23 #include <coeinput.h> |
|
24 #include <coecntrl.h> |
|
25 |
|
26 #include <avkon.hrh> |
|
27 |
|
28 #include "LAFSTD.H" |
|
29 #include "LAFMENUB.H" |
|
30 #include "lafcommn.h" |
|
31 #include "uikon.hrh" |
|
32 |
|
33 const TInt KLafDefaultPaneIndex = 0; |
|
34 const TInt KLafShadowHeight = 3; |
|
35 const TInt KLafTopLeftCornerPositionX = 0; |
|
36 const TInt KLafTopLeftCornerPositionY = 0; |
|
37 |
|
38 // From menu bar source code |
|
39 const TInt KLafExtraBaselineOffsetForFirstPaneItem = 4; |
|
40 const TInt KLafHorizontalBorder=8; |
|
41 const TInt KLafVerticalBorder=2; |
|
42 const TInt KLafMnemonicPad=3; |
|
43 |
|
44 const TInt KLafNumOfSideButtons=5; |
|
45 const TInt KLafSidebarPopupXPos=5; |
|
46 const TInt KLafMenuPaneOverlap=1; |
|
47 |
|
48 const TInt KLafMenuTitleLeftSpace = 12; |
|
49 const TInt KLafMenuTitleRightSpace = 12; |
|
50 const TInt KLafMenuTitleLeftSmallSpace = 4; |
|
51 const TInt KLafMenuTitleRightSmallSpace = 4; |
|
52 |
|
53 const TInt KLafSpaceBetweenMenuPaneTitleAndMenuBar = 0; |
|
54 |
|
55 // Menu pane title |
|
56 const TInt KLafMenuPaneTitleLeftSpace = 12; |
|
57 const TInt KLafMenuPaneTitleRightSpace = 12; |
|
58 const TInt KLafMenuPaneTitleSmallLeftSpace = 0; |
|
59 const TInt KLafMenuPaneTitleSmallRightSpace = 0; |
|
60 |
|
61 |
|
62 |
|
63 // |
|
64 // Class LafMenuPane::TTitleAttributes |
|
65 // |
|
66 |
|
67 EXPORT_C LafMenuBar::TTitleAttributes::TTitleAttributes() |
|
68 : iBaseLine(0), iFlags(0) |
|
69 { |
|
70 } |
|
71 |
|
72 // |
|
73 // Class LafMenuBar |
|
74 // |
|
75 |
|
76 |
|
77 /** |
|
78 * Returns ETrue if the menu bar should be always visible oterwise it resturns EFalse. |
|
79 */ |
|
80 EXPORT_C TBool LafMenuBar::IsAlwaysVisible() |
|
81 { // static |
|
82 return EFalse; |
|
83 } |
|
84 |
|
85 /** |
|
86 * Returns ETrue when the window behind the menu bar should be faded. |
|
87 */ |
|
88 EXPORT_C TBool LafMenuBar::FadeBehind() |
|
89 { // static |
|
90 return EFalse; |
|
91 } |
|
92 |
|
93 /** |
|
94 * Gets the default border for the matched control in aBorder. Called from the constructor of the matched control. |
|
95 */ |
|
96 EXPORT_C void LafMenuBar::GetDefaultBorder(TGulBorder& aBorder) |
|
97 { |
|
98 aBorder=TGulBorder(TGulBorder::EThickDeepRaisedWithOutline); |
|
99 } |
|
100 |
|
101 /** |
|
102 * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained |
|
103 * may depend on the the display mode, the environment color list and the instance of the |
|
104 * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the |
|
105 * Draw() method of TGulBorder. |
|
106 */ |
|
107 EXPORT_C void LafMenuBar::GetBorderColors(TGulBorder::TColors& aBorderColors, const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl) |
|
108 { |
|
109 LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors, |
|
110 EColorMenubarBackground, aLafEnv,aMatchedControl); |
|
111 } |
|
112 |
|
113 EXPORT_C LafMenuBar::TWidth LafMenuBar::DefaultSpan() |
|
114 { // static |
|
115 return EMinPossible; |
|
116 } |
|
117 |
|
118 /** |
|
119 * Returns the font corresponding to aFontType. |
|
120 */ |
|
121 EXPORT_C const CFont* LafMenuBar::Font(const MLafEnv& aLafEnv, TFontType aFontType) |
|
122 { // static |
|
123 TLogicalFont logicalFont; |
|
124 |
|
125 switch (aFontType) |
|
126 { |
|
127 case EAnnotation: |
|
128 logicalFont.iFontId=TUid::Uid(EAknLogicalFontSecondaryFont); |
|
129 break; |
|
130 case ENormal: |
|
131 logicalFont.iFontId=TUid::Uid(EAknLogicalFontPrimaryFont); |
|
132 break; |
|
133 case ESymbol: |
|
134 logicalFont.iFontId=TUid::Uid(EAknLogicalFontSecondaryFont); |
|
135 break; |
|
136 default: |
|
137 __ASSERT_DEBUG(EFalse, Panic(ELafPanicFontIndexOutOfRange)); // should never be reached |
|
138 break; |
|
139 } |
|
140 |
|
141 return aLafEnv.Font(logicalFont); |
|
142 } |
|
143 |
|
144 /** |
|
145 * Returns a constant value according to aConstatType. |
|
146 * @internal |
|
147 */ |
|
148 EXPORT_C TInt LafMenuBar::Constant(TConstantType aConstantType) |
|
149 {//static |
|
150 TInt retValue = 0; |
|
151 switch (aConstantType) |
|
152 { |
|
153 case EDefaultMenuPaneIndex: |
|
154 retValue = KLafDefaultPaneIndex; |
|
155 break; |
|
156 case EExtraBaselineOffsetForFirstPaneItem: |
|
157 retValue = KLafExtraBaselineOffsetForFirstPaneItem; |
|
158 break; |
|
159 case EHorizontalBorder: |
|
160 retValue = KLafHorizontalBorder; |
|
161 break; |
|
162 case EVerticalBorder: |
|
163 retValue = KLafVerticalBorder; |
|
164 break; |
|
165 case EMnemonicPad: |
|
166 retValue = KLafMnemonicPad; |
|
167 break; |
|
168 case EMenuPaneOverlap: |
|
169 retValue = KLafMenuPaneOverlap; |
|
170 break; |
|
171 case EMenuTitleLeftSpace: |
|
172 retValue = KLafMenuTitleLeftSpace; |
|
173 break; |
|
174 case EMenuTitleRightSpace: |
|
175 retValue = KLafMenuTitleRightSpace; |
|
176 break; |
|
177 case EMenuTitleLeftSmallSpace: |
|
178 retValue = KLafMenuTitleLeftSmallSpace; |
|
179 break; |
|
180 case EMenuTitleRightSmallSpace: |
|
181 retValue = KLafMenuTitleRightSmallSpace; |
|
182 break; |
|
183 case ENumOfSideButtons: |
|
184 retValue = KLafNumOfSideButtons; |
|
185 break; |
|
186 case ESidebarPopupXPos: |
|
187 retValue = KLafSidebarPopupXPos; |
|
188 break; |
|
189 case EShadowHeight: |
|
190 retValue = KLafShadowHeight; |
|
191 break; |
|
192 case ESpaceBetweenMenuPaneTitleAndMenuBar: |
|
193 retValue = KLafSpaceBetweenMenuPaneTitleAndMenuBar; |
|
194 break; |
|
195 default: |
|
196 __ASSERT_DEBUG(EFalse, Panic(ELafPanicConstantNotKnown)); |
|
197 break; |
|
198 } |
|
199 return retValue; |
|
200 } |
|
201 |
|
202 /** |
|
203 * Returns ETrue if the menu bar can show the hotkeys, otherwise it returns EFalse. |
|
204 */ |
|
205 EXPORT_C TBool LafMenuBar::ShowHotKeys() |
|
206 { // static |
|
207 return ETrue; |
|
208 } |
|
209 |
|
210 /** |
|
211 * Returns the left top corner position of the menu bar and if this position is relative to the screen |
|
212 * or to the client area. |
|
213 */ |
|
214 EXPORT_C void LafMenuBar::TopLeftCornerPosition(TPoint & aPosition, TAnchor& aMenuAnchor) |
|
215 { |
|
216 aMenuAnchor=ERelativeToScreen; |
|
217 aPosition = TPoint(KLafTopLeftCornerPositionX, KLafTopLeftCornerPositionY); |
|
218 } |
|
219 |
|
220 /** |
|
221 * |
|
222 */ |
|
223 EXPORT_C void LafMenuBar::DrawBetweenRects(const MLafEnv& aLafEnv, const CCoeControl& aMenuBar, CWindowGc& aGc, const TRect& aInnerRect, const TRect& aClientRect) |
|
224 { |
|
225 aGc.SetBrushColor(aLafEnv.ControlColor(EColorMenubarBackground, aMenuBar)); |
|
226 const TRect rect(aMenuBar.Rect()); |
|
227 const TInt bottomMargin = rect.iBr.iY - aInnerRect.iBr.iY; |
|
228 const TInt rightMargin = rect.iBr.iX - aInnerRect.iBr.iX; |
|
229 if ((rect.iBr.iY-aClientRect.iTl.iY <= bottomMargin + MenuPaneOverlap()) || |
|
230 (rect.iBr.iX-aClientRect.iTl.iX <= rightMargin+1)) |
|
231 {// handle special case of pane being moved |
|
232 TRect innerRect = aInnerRect; |
|
233 innerRect.Intersection(aClientRect); |
|
234 aGc.Clear(innerRect); |
|
235 return; |
|
236 } |
|
237 aGc.Clear(aInnerRect); |
|
238 } |
|
239 |
|
240 /** |
|
241 * Returns the keypresses a menu bar is interested in receiving from a FEP |
|
242 */ |
|
243 EXPORT_C TInt LafMenuBar::InputCapabilities() |
|
244 { // static |
|
245 return TCoeInputCapabilities::ENavigation|TCoeInputCapabilities::EWesternNumericIntegerPositive; |
|
246 } |
|
247 |
|
248 /** |
|
249 * Draws aText into the graphics context aGc, in the rectangle aRect. Called by the menu bar |
|
250 * control from its Draw() method after the aGc has been set up. |
|
251 */ |
|
252 EXPORT_C void LafMenuBar::DrawText(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuBar*/, CWindowGc& aGc, const TRect& aRect, const TDesC& aText, const TTitleAttributes& aTitleAttributes) |
|
253 { |
|
254 CGraphicsContext::TTextAlign align=(aTitleAttributes.iFlags&EEikMenuTitleRightAlign? |
|
255 CGraphicsContext::ERight : CGraphicsContext::ELeft); |
|
256 TBuf<SLafMenuBar::ENominalTextLength> text = aText; |
|
257 TextUtils::ClipToFit(text, *NormalFont(aLafEnv),aRect.Width()); |
|
258 aGc.DrawText(text, aRect, aTitleAttributes.iBaseLine, align); |
|
259 } |
|
260 |
|
261 /** |
|
262 * Prepares the graphics context aGc for drawing the title by setting the pen and brush. Called |
|
263 * by the menu bar control from its Draw() and DrawItem() methods. |
|
264 */ |
|
265 EXPORT_C void LafMenuBar::PrepareGcForDrawingTitle(const MLafEnv& aLafEnv, const CCoeControl& aMenuBar, CWindowGc& aGc) |
|
266 { // static |
|
267 aGc.SetPenColor(aLafEnv.ControlColor(EColorMenubarText, aMenuBar)); |
|
268 aGc.UseFont(NormalFont(aLafEnv)); |
|
269 aGc.SetBrushColor(aLafEnv.ControlColor(EColorMenubarBackground, aMenuBar)); |
|
270 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
271 } |
|
272 |
|
273 EXPORT_C void LafMenuBar::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) |
|
274 { // static |
|
275 TInt commonAttributes = TCoeColorUse::EActive|TCoeColorUse::ESurrounds|TCoeColorUse::ENormal|TCoeColorUse::ENeutral; |
|
276 TCoeColorUse colorUse; |
|
277 |
|
278 colorUse.SetLogicalColor(EColorMenubarText); |
|
279 colorUse.SetUse(TCoeColorUse::EFore|commonAttributes); |
|
280 aColorUseList.AppendL(colorUse); |
|
281 |
|
282 colorUse.SetLogicalColor(EColorMenubarBackground); |
|
283 colorUse.SetUse(TCoeColorUse::EBack|commonAttributes); |
|
284 aColorUseList.AppendL(colorUse); |
|
285 } |
|
286 |
|
287 /** |
|
288 * Returns the keycode to use with menus for the given event. Intended primarily to allow custom |
|
289 * device hardware keys to map to standard Epoc functions. |
|
290 * |
|
291 * @since App-Framework_6.1 |
|
292 */ |
|
293 EXPORT_C TUint LafMenuBar::MapKeyCode(const TKeyEvent& aKeyEvent,TEventCode /*aType*/) |
|
294 { // static |
|
295 return aKeyEvent.iCode; |
|
296 } |
|
297 |
|
298 // |
|
299 // Class LafMenuPaneTitle |
|
300 // |
|
301 |
|
302 /** |
|
303 * Gets the default border for the matched control in aBorder. Called from the constructor of the matched control. |
|
304 */ |
|
305 EXPORT_C void LafMenuPaneTitle::GetDefaultBorder(TGulBorder& aBorder) |
|
306 { |
|
307 aBorder=TGulBorder(TGulBorder::EThickDeepRaisedWithOutline); |
|
308 } |
|
309 |
|
310 /** |
|
311 * Gets the set of border colors for the matched control in aBorderColors. The RGB values of the colors obtained |
|
312 * may depend on the the display mode, the environment color list and the instance of the |
|
313 * matched control aMatchedControl. Called by the matched control from its Draw() method and passed on to the |
|
314 * Draw() method of TGulBorder. |
|
315 */ |
|
316 EXPORT_C void LafMenuPaneTitle::GetBorderColors(TGulBorder::TColors& aBorderColors, const MLafEnv& aLafEnv, const CCoeControl& aMatchedControl) |
|
317 { |
|
318 LafCommonUtils::GetRgbDerivedBorderColors( aBorderColors, |
|
319 EColorMenubarTitleBackground, aLafEnv,aMatchedControl ); |
|
320 } |
|
321 |
|
322 /** |
|
323 * Returns a constant value according to aConstatType. |
|
324 */ |
|
325 EXPORT_C TInt LafMenuPaneTitle::Constant(TConstantType aConstantType) |
|
326 {//static |
|
327 TInt retValue = 0; |
|
328 switch (aConstantType) |
|
329 { |
|
330 case EShadowHeight: |
|
331 retValue = KLafShadowHeight; |
|
332 break; |
|
333 case ETitleLeftSpace: |
|
334 retValue = KLafMenuPaneTitleLeftSpace; |
|
335 break; |
|
336 case ETitleRightSpace: |
|
337 retValue = KLafMenuPaneTitleRightSpace; |
|
338 break; |
|
339 case ETitleSmallLeftSpace: |
|
340 retValue = KLafMenuPaneTitleSmallLeftSpace; |
|
341 break; |
|
342 case ETitleSmallRightSpace: |
|
343 retValue = KLafMenuPaneTitleSmallRightSpace; |
|
344 break; |
|
345 default: |
|
346 __ASSERT_DEBUG(EFalse, Panic(ELafPanicConstantNotKnown)); |
|
347 break; |
|
348 } |
|
349 return retValue; |
|
350 } |
|
351 |
|
352 /** |
|
353 * |
|
354 */ |
|
355 EXPORT_C void LafMenuPaneTitle::DrawTitlePaneJoint(const MLafEnv& aLafEnv, const CCoeControl& aMenuPaneTitle, CWindowGc& aGc, const TRect& aInnerRect) |
|
356 { |
|
357 const TRect rect(aMenuPaneTitle.Rect()); |
|
358 |
|
359 aGc.SetPenStyle(CGraphicsContext::ENullPen); |
|
360 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
361 aGc.SetBrushColor(aLafEnv.ControlColor(EColorMenubarTitleBackground, aMenuPaneTitle)); |
|
362 aGc.DrawRect(TRect(aInnerRect.iTl, TPoint(aInnerRect.iBr.iX, rect.iBr.iY))); |
|
363 |
|
364 aGc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
365 |
|
366 // get rid of the bit of border on the left |
|
367 aGc.DrawLine(TPoint(rect.iTl.iX+1,rect.iBr.iY-4),TPoint(rect.iTl.iX+1,rect.iBr.iY)); |
|
368 aGc.DrawLine(TPoint(rect.iTl.iX+2,rect.iBr.iY-4),TPoint(rect.iTl.iX+2,rect.iBr.iY)); |
|
369 aGc.DrawLine(TPoint(rect.iTl.iX+3,rect.iBr.iY-4),TPoint(rect.iTl.iX+3,rect.iBr.iY)); |
|
370 |
|
371 // get rid of the bit of border frame on the right bottom side. |
|
372 TGulBorder::TColors borderColors; |
|
373 LafMenuPaneTitle::GetBorderColors(borderColors, aLafEnv, aMenuPaneTitle); |
|
374 aGc.SetPenColor(borderColors.iMid); |
|
375 aGc.DrawLine(TPoint(rect.iBr.iX-2,rect.iBr.iY-1),TPoint(rect.iBr.iX-5,rect.iBr.iY-1)); |
|
376 } |
|
377 |
|
378 /** |
|
379 * Draws aText into the graphics context aGc, in the rectangle aRect. Called by the menu |
|
380 * bar control from its Draw() method after the aGc has been set up. |
|
381 */ |
|
382 EXPORT_C void LafMenuPaneTitle::DrawText(const MLafEnv& aLafEnv, const CCoeControl& /*aMenuPaneTitle*/, CWindowGc& aGc, const TRect& aRect, const TDesC& aText, LafMenuBar::TTitleAttributes aMenuBarAttributes) |
|
383 { |
|
384 TInt menuPaneTitleBaseLine = aMenuBarAttributes.iBaseLine - KLafSpaceBetweenMenuPaneTitleAndMenuBar; |
|
385 CGraphicsContext::TTextAlign align=(aMenuBarAttributes.iFlags&EEikMenuTitleRightAlign? |
|
386 CGraphicsContext::ERight : CGraphicsContext::ELeft); |
|
387 |
|
388 TBuf<SLafMenuBar::ENominalTextLength> text = aText; |
|
389 TextUtils::ClipToFit(text, *LafMenuBar::NormalFont(aLafEnv),aRect.Width()); |
|
390 aGc.DrawText(text, aRect, menuPaneTitleBaseLine, align); |
|
391 } |
|
392 |
|
393 /** |
|
394 * Prepares the graphics context aGc for drawing the title by setting the pen and brush. |
|
395 */ |
|
396 EXPORT_C void LafMenuPaneTitle::PrepareGcForDrawingTitle(const MLafEnv& aLafEnv, const CCoeControl& aMenuPaneTitle, CWindowGc& aGc) |
|
397 { |
|
398 aGc.UseFont(LafMenuBar::NormalFont(aLafEnv)); |
|
399 aGc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
400 aGc.SetBrushColor(aLafEnv.ControlColor(EColorMenubarTitleBackground, aMenuPaneTitle)); |
|
401 aGc.SetPenColor(aLafEnv.ControlColor(EColorMenubarTitleText, aMenuPaneTitle)); |
|
402 } |
|
403 |
|
404 EXPORT_C void LafMenuPaneTitle::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList) |
|
405 { // static |
|
406 TInt commonAttributes = TCoeColorUse::EActive|TCoeColorUse::ESurrounds|TCoeColorUse::ENormal|TCoeColorUse::ENeutral; |
|
407 TCoeColorUse colorUse; |
|
408 |
|
409 colorUse.SetLogicalColor(EColorMenubarTitleText); |
|
410 colorUse.SetUse(TCoeColorUse::EFore|commonAttributes); |
|
411 aColorUseList.AppendL(colorUse); |
|
412 |
|
413 colorUse.SetLogicalColor(EColorMenubarTitleBackground); |
|
414 colorUse.SetUse(TCoeColorUse::EBack|commonAttributes); |
|
415 aColorUseList.AppendL(colorUse); |
|
416 } |
|
417 |
|
418 // |
|
419 // class LafMenuBarTitle |
|
420 // |
|
421 |
|
422 /** |
|
423 * Draws the icon for the title to the graphics context aGc, in the middle of the rectangle aRect |
|
424 */ |
|
425 EXPORT_C void LafMenuBarTitle::DrawIcon(CWindowGc& aGc, const TRect& aRect, const CGulIcon& aIcon) |
|
426 { |
|
427 |
|
428 // Determine the rect available for the bitmap |
|
429 TRect rect = aRect; |
|
430 // put the image in the middle of available rect |
|
431 const CFbsBitmap* bitmap = aIcon.Bitmap(); |
|
432 TSize bmpSize = bitmap->SizeInPixels(); |
|
433 TInt yoffset = (aRect.Size().iHeight - bmpSize.iHeight) / 2; |
|
434 TInt xoffset = (aRect.Size().iWidth - bmpSize.iWidth) / 2;; |
|
435 TPoint offset(xoffset,yoffset); |
|
436 const CFbsBitmap* mask = aIcon.Mask(); |
|
437 if (mask) |
|
438 { |
|
439 TRect bmpRect(TPoint(0,0), TPoint(bmpSize.iWidth, bmpSize.iHeight)); |
|
440 aGc.BitBltMasked(rect.iTl+offset, bitmap, bmpRect, mask, ETrue); |
|
441 } |
|
442 else |
|
443 aGc.BitBlt(rect.iTl+offset, bitmap); |
|
444 } |