56
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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 "HgPopupDrawer.h"
|
|
20 |
#include "HgConstants.h"
|
|
21 |
|
|
22 |
#include <gdi.h>
|
|
23 |
#include <AknUtils.h>
|
|
24 |
#include <AknsDrawUtils.h>
|
|
25 |
#include <bitstd.h>
|
|
26 |
#include <skinlayout.cdl.h>
|
|
27 |
#include <layoutmetadata.cdl.h>
|
|
28 |
#include <aknlayoutscalable_avkon.cdl.h>
|
|
29 |
#include <aknlayoutscalable_apps.cdl.h>
|
|
30 |
|
|
31 |
|
|
32 |
THgPopupDrawer::THgPopupDrawer()
|
|
33 |
: iRect(),
|
|
34 |
iFont (NULL),
|
|
35 |
iLongestMonth(0)
|
|
36 |
{
|
|
37 |
}
|
|
38 |
|
|
39 |
void THgPopupDrawer::Init( TRect aRect, const CFont* aFont )
|
|
40 |
{
|
|
41 |
iRect = aRect;
|
|
42 |
iFont = aFont;
|
|
43 |
iLongestMonth = 0;
|
|
44 |
}
|
|
45 |
|
|
46 |
void THgPopupDrawer::InitLongestMonth()
|
|
47 |
{
|
|
48 |
// font needs to be set
|
|
49 |
if(!iFont) return;
|
|
50 |
|
|
51 |
TTime time;
|
|
52 |
time.HomeTime();
|
|
53 |
TDateTime date = time.DateTime();
|
|
54 |
date.SetMonth(EJanuary);
|
|
55 |
time = date;
|
|
56 |
|
|
57 |
TFileName month;
|
|
58 |
month.Zero();
|
|
59 |
|
|
60 |
for(TInt i = 0; i < 12; ++i)
|
|
61 |
{
|
|
62 |
TRAP_IGNORE
|
|
63 |
(
|
|
64 |
time.FormatL(month, KGanesMonthString);
|
|
65 |
)
|
|
66 |
time += TTimeIntervalMonths(1);
|
|
67 |
TInt monthLen = iFont->TextWidthInPixels(month);
|
|
68 |
iLongestMonth = monthLen > iLongestMonth ? monthLen : iLongestMonth;
|
|
69 |
}
|
|
70 |
}
|
|
71 |
|
|
72 |
void THgPopupDrawer::Draw( CWindowGc& aGc, const TDesC& aDesc )
|
|
73 |
{
|
|
74 |
// font needs to be set
|
|
75 |
if(!iFont) return;
|
|
76 |
|
|
77 |
// Resolve rect for the popup "window"
|
|
78 |
const TInt textLength = iFont->TextWidthInPixels( aDesc );
|
|
79 |
TInt width = iRect.Width()/KPopupWidthDiv > textLength + KPopupTextExtraPadding ?
|
|
80 |
iRect.Width()/KPopupWidthDiv : textLength + KPopupTextExtraPadding;
|
|
81 |
TInt height = (iFont->FontMaxHeight() * 2);
|
|
82 |
|
|
83 |
// calculate the position of the popup
|
|
84 |
TPoint pos(((iRect.Width() - width )/2), (iRect.Height() - height)/2);
|
|
85 |
TRect area( pos, TSize( width, height) );
|
|
86 |
|
|
87 |
// First draw background box, after that the text
|
|
88 |
DrawBackground(aGc, area);
|
|
89 |
|
|
90 |
InitFont(aGc);
|
|
91 |
|
|
92 |
// Draw Text
|
|
93 |
TPoint point( area.iTl );
|
|
94 |
point.iY += iFont->FontMaxAscent() + ((area.Height() - iFont->FontMaxHeight()) / 2);
|
|
95 |
|
|
96 |
TRAP_IGNORE(
|
|
97 |
TBidiText* text = TBidiText::NewL( aDesc, 1 );
|
|
98 |
text->WrapText(area.Width(), *iFont, NULL);
|
|
99 |
if(text->Directionality() == TBidiText::ELeftToRight )
|
|
100 |
{
|
|
101 |
point.iX += (area.Width() - textLength)/2;
|
|
102 |
}
|
|
103 |
else
|
|
104 |
{
|
|
105 |
point.iX -= (area.Width() - textLength)/2;
|
|
106 |
}
|
|
107 |
|
|
108 |
text->DrawText( aGc, point );
|
|
109 |
delete text;
|
|
110 |
)
|
|
111 |
}
|
|
112 |
|
|
113 |
void THgPopupDrawer::DrawNaviChar( CWindowGc& aGc, const TDesC& aDesc )
|
|
114 |
{
|
|
115 |
TRgb normal;
|
|
116 |
AknsUtils::GetCachedColor(AknsUtils::SkinInstance(),
|
|
117 |
normal,
|
|
118 |
KAknsIIDQsnTextColors,
|
|
119 |
EAknsCIQsnTextColorsCG6 );
|
|
120 |
|
|
121 |
TAknLayoutRect layout;
|
|
122 |
layout.LayoutRect(iRect, AknLayoutScalable_Apps::popup_navstr_preview_pane(0));
|
|
123 |
|
|
124 |
DrawBackground( aGc, layout.Rect() );
|
|
125 |
|
|
126 |
TAknLayoutText textLayout;
|
|
127 |
textLayout.LayoutText(layout.Rect(), AknLayoutScalable_Apps::popup_navstr_preview_pane_t1(0).LayoutLine());
|
|
128 |
textLayout.DrawText(aGc, aDesc, ETrue, normal );
|
|
129 |
|
|
130 |
}
|
|
131 |
|
|
132 |
void THgPopupDrawer::Draw( CWindowGc& aGc,
|
|
133 |
const TDesC& aDesc1,
|
|
134 |
const TDesC& aDesc2
|
|
135 |
)
|
|
136 |
{
|
|
137 |
// font needs to be set
|
|
138 |
if(!iFont) return;
|
|
139 |
|
|
140 |
// init longest month value.
|
|
141 |
if(!iLongestMonth)
|
|
142 |
InitLongestMonth();
|
|
143 |
|
|
144 |
// Resolve rect for the popup "window"
|
|
145 |
TInt d1Length = iFont->TextWidthInPixels( aDesc1 );
|
|
146 |
TInt d2Length = iFont->TextWidthInPixels( aDesc2 );
|
|
147 |
|
|
148 |
// Calculate the dimensions
|
|
149 |
TInt width = iRect.Width()/KPopupWidthDiv > iLongestMonth + KPopupTextExtraPadding ?
|
|
150 |
iRect.Width()/KPopupWidthDiv : iLongestMonth + KPopupTextExtraPadding;
|
|
151 |
TInt height = (iFont->FontMaxHeight() * 3);
|
|
152 |
|
|
153 |
// calculate the position of the popup
|
|
154 |
TPoint pos(((iRect.Width() - width )/2), (iRect.Height() - height)/2);
|
|
155 |
TRect area( pos, TSize( width, height) );
|
|
156 |
|
|
157 |
// First draw background box, after that the text
|
|
158 |
DrawBackground(aGc, area);
|
|
159 |
|
|
160 |
InitFont(aGc);
|
|
161 |
|
|
162 |
// First text
|
|
163 |
TPoint point( area.iTl );
|
|
164 |
point.iY += iFont->FontMaxAscent() + (iFont->FontMaxHeight() / 2);
|
|
165 |
TRAP_IGNORE(
|
|
166 |
TBidiText* text = TBidiText::NewL( aDesc1, 1 );
|
|
167 |
text->WrapText(area.Width(), *iFont, NULL);
|
|
168 |
if(text->Directionality() == TBidiText::ELeftToRight )
|
|
169 |
{
|
|
170 |
point.iX += (area.Width() - d1Length)/2;
|
|
171 |
}
|
|
172 |
else
|
|
173 |
{
|
|
174 |
point.iX -= (area.Width() - d1Length)/2;
|
|
175 |
}
|
|
176 |
|
|
177 |
text->DrawText( aGc, point );
|
|
178 |
delete text;
|
|
179 |
)
|
|
180 |
|
|
181 |
// Second text
|
|
182 |
point.iX = area.iTl.iX;
|
|
183 |
point.iX += (area.Width() - d2Length)/2;
|
|
184 |
point.iY += iFont->FontMaxHeight();
|
|
185 |
aGc.DrawText(aDesc2, point );
|
|
186 |
}
|
|
187 |
|
|
188 |
void THgPopupDrawer::DrawBackground( CWindowGc& aGc, const TRect& aRect )
|
|
189 |
{
|
|
190 |
TAknLayoutRect cornerRect;
|
|
191 |
// skinned draw uses submenu popup window skin (skinned border)
|
|
192 |
cornerRect.LayoutRect(
|
|
193 |
aRect,
|
|
194 |
SkinLayout::Submenu_skin_placing_Line_2() );
|
|
195 |
|
|
196 |
TRect innerRect( aRect );
|
|
197 |
innerRect.Shrink( cornerRect.Rect().Width(), cornerRect.Rect().Height() );
|
|
198 |
|
|
199 |
if ( !AknsDrawUtils::DrawFrame(
|
|
200 |
AknsUtils::SkinInstance(),
|
|
201 |
aGc,
|
|
202 |
aRect,
|
|
203 |
innerRect,
|
|
204 |
KAknsIIDQsnFrPopupSub,
|
|
205 |
KAknsIIDQsnFrPopupCenterSubmenu ) )
|
|
206 |
{
|
|
207 |
// skinned border failed -> black border
|
|
208 |
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
|
|
209 |
aGc.SetBrushColor( KRgbBlack );
|
|
210 |
aGc.DrawRect( aRect );
|
|
211 |
}
|
|
212 |
}
|
|
213 |
|
|
214 |
void THgPopupDrawer::InitFont(CWindowGc& aGc)
|
|
215 |
{
|
|
216 |
// font needs to be set
|
|
217 |
if(!iFont) return;
|
|
218 |
|
|
219 |
// Get color for the text from the skin.
|
|
220 |
TRgb normal;
|
|
221 |
AknsUtils::GetCachedColor(AknsUtils::SkinInstance(),
|
|
222 |
normal,
|
|
223 |
KAknsIIDQsnTextColors,
|
|
224 |
EAknsCIQsnTextColorsCG6 );
|
|
225 |
|
|
226 |
// Draw text
|
|
227 |
aGc.UseFont( iFont );
|
|
228 |
aGc.SetPenColor(normal);
|
|
229 |
}
|
|
230 |
|