66
|
1 |
/*
|
|
2 |
* Copyright (c) 2003-2006 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: ?Description
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <coemain.h>
|
|
20 |
#include <eikcapc.h>
|
|
21 |
|
|
22 |
#include "CMIDControlItem.h"
|
|
23 |
#include "CMIDGc.h"
|
|
24 |
#include "CMIDUtils.h"
|
|
25 |
#include "CMIDCommand.h"
|
|
26 |
#include "CMIDForm.h"
|
|
27 |
#include "CMIDCommandList.h"
|
|
28 |
// needed API for iLabelControl
|
|
29 |
#include "CMIDItemLabel.h"
|
|
30 |
// API for retrieving background control context
|
|
31 |
#include "CMIDDisplayable.h"
|
|
32 |
#include "CMIDMenuHandler.h"
|
|
33 |
|
|
34 |
#include <AknUtils.h>
|
|
35 |
#include <AknsDrawUtils.h>
|
|
36 |
// using API for CAknsFrameBackgroundControlContext (member iHighlightedBackgroundCc)
|
|
37 |
#include <AknsFrameBackgroundControlContext.h>
|
|
38 |
// LAF
|
|
39 |
// AknLayoutScalable_Avkon::form2_midp_content_pane
|
|
40 |
#include <aknlayoutscalable_avkon.cdl.h>
|
|
41 |
|
|
42 |
#include <j2me/jdebug.h>
|
|
43 |
|
|
44 |
#undef TRAP_INSTRUMENTATION_LEAVE
|
|
45 |
#define TRAP_INSTRUMENTATION_LEAVE(aResult) DEBUG_INT2("In CMIDControlItem.cpp, trapped method was called at line %D and got exception %D", __LINE__, aResult);
|
|
46 |
|
|
47 |
/** This constant limits the maximum number of lines in an item label */
|
|
48 |
const TInt KMaxNumLines = 10;
|
|
49 |
|
|
50 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
51 |
// class CMIDControlItem
|
|
52 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
53 |
|
|
54 |
CMIDControlItem::CMIDControlItem(MMIDItem::TLayout aLayout, CMIDUIManager* aUIManager)
|
|
55 |
: CMIDItem(aLayout, aUIManager)
|
|
56 |
, iCoeEnv(CCoeEnv::Static())
|
|
57 |
, iHighlighted(EFalse)
|
|
58 |
{
|
|
59 |
}
|
|
60 |
|
|
61 |
CMIDControlItem::~CMIDControlItem()
|
|
62 |
{
|
|
63 |
delete iLabelControl;
|
|
64 |
if (iForm)
|
|
65 |
{
|
|
66 |
iForm->RemoveDeletedItem(*this);
|
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
void CMIDControlItem::ConstructL()
|
|
71 |
{
|
|
72 |
CMIDItem::ConstructL();
|
|
73 |
|
|
74 |
iLabelControl = CMIDItemLabel::NewL(FormClientAreaWidth(),
|
|
75 |
Type() != MMIDComponent::EImageItem,
|
|
76 |
KMaxNumLines);
|
|
77 |
|
|
78 |
if (iLabel)
|
|
79 |
{
|
|
80 |
iLabelControl->SetTextL(*iLabel);
|
|
81 |
}
|
|
82 |
}
|
|
83 |
|
|
84 |
TInt CMIDControlItem::FormClientAreaWidth() const
|
|
85 |
{
|
|
86 |
return iForm ? iForm->Width(): CMIDForm::FormWidth();
|
|
87 |
}
|
|
88 |
|
|
89 |
TRect CMIDControlItem::FormClientAreaRect() const
|
|
90 |
{
|
|
91 |
return iForm ? iForm->FormRect(): CMIDForm::StaticFormRect();
|
|
92 |
}
|
|
93 |
|
|
94 |
// Returns bottom margin of form2_midp_content_pane
|
|
95 |
TInt CMIDControlItem::ItemContentBottomMargin() const
|
|
96 |
{
|
|
97 |
|
|
98 |
TAknLayoutRect form2MidpContentPaneRect;
|
|
99 |
TRect formRect;
|
|
100 |
if (iForm)
|
|
101 |
{
|
|
102 |
formRect = iForm->FormRect();
|
|
103 |
}
|
|
104 |
else
|
|
105 |
{
|
|
106 |
formRect = CMIDForm::StaticFormRect();
|
|
107 |
}
|
|
108 |
form2MidpContentPaneRect.LayoutRect(formRect,
|
|
109 |
AknLayoutScalable_Avkon::form2_midp_content_pane(0).LayoutLine());
|
|
110 |
return formRect.iBr.iY - form2MidpContentPaneRect.Rect().iBr.iY;
|
|
111 |
}
|
|
112 |
|
|
113 |
/**
|
|
114 |
* Resets the preferred size if the minimum size has changed.
|
|
115 |
* The minimum size will change if the label or content is modified.
|
|
116 |
*/
|
|
117 |
TSize CMIDControlItem::ResetPreferredSize() const
|
|
118 |
{
|
|
119 |
CMIDControlItem* self = const_cast<CMIDControlItem*>(this);
|
|
120 |
self->SetPreferredSize(iRequestedPreferredSize,self->MinimumSize());
|
|
121 |
return iPreferredSize;
|
|
122 |
}
|
|
123 |
|
|
124 |
/** This method is called by the form row when sizing the items
|
|
125 |
once it has determined the width available to the item. The item
|
|
126 |
will typically wrap its label to this width so that its height
|
|
127 |
will then be modified accordingly. See CMIDFormRow::SizeItemsL().
|
|
128 |
|
|
129 |
Items that have other width dependent behavious may want to extend
|
|
130 |
this method. For example string items may have to wrap their content
|
|
131 |
as well as the label to the given width.
|
|
132 |
*/
|
|
133 |
void CMIDControlItem::AdjustToNewWidthL(TInt aWidth)
|
|
134 |
{
|
|
135 |
ASSERT(aWidth >= 0);
|
|
136 |
|
|
137 |
if (iLabelControl && iLabelControl->Text()->Length() > 0)
|
|
138 |
{
|
|
139 |
|
|
140 |
iLabelControl->SetWidthL(aWidth);
|
|
141 |
|
|
142 |
if (iRequestedPreferredSize.iHeight < 0)
|
|
143 |
{
|
|
144 |
iPreferredSize.iHeight = LabelHeight() + ItemPreferredHeightWithoutLabel();
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
/** After having called AdjustToNewWidthL() and done its calculations, the form
|
|
150 |
row knows what size should be assigned to items and calls this method after having
|
|
151 |
called SetSizeQuiet. The elements inside an item should made to fit this size.
|
|
152 |
Typically this size is the same as the requested size (the width passed to AdjustToNewWidthL()
|
|
153 |
plus the resulting height. However if layout shrink applies, this may well be the minimum size
|
|
154 |
instead. This method is equally called by some items after having calculated their preferred
|
|
155 |
size. See SetPreferredSizeL().
|
|
156 |
|
|
157 |
Items that do not implement this method (text field, date field, choice group and gauge)
|
|
158 |
are such that their minimum size can always fit the entire label and any other element. This
|
|
159 |
is typical of items that fill the entire form width, basically they always get the size they
|
|
160 |
want in this case (the entire width plus as much height as needed).
|
|
161 |
|
|
162 |
Finally, we do not provide a common implementation that adjusts the label because we
|
|
163 |
do not know how much space of the given size is reserved to the label. */
|
|
164 |
void CMIDControlItem::AdjustToSizeL(const TSize& /*aSize*/)
|
|
165 |
{
|
|
166 |
|
|
167 |
}
|
|
168 |
|
|
169 |
TRect CMIDControlItem::FocusableRect()
|
|
170 |
{
|
|
171 |
return Rect();
|
|
172 |
}
|
|
173 |
|
|
174 |
TBool CMIDControlItem::IsSelectable() const
|
|
175 |
{
|
|
176 |
return (!IsNonFocusing() || (CommandList() ? CommandList()->Count() > 0 : 0));
|
|
177 |
}
|
|
178 |
|
|
179 |
void CMIDControlItem::SetLabelL(const TDesC& aLabel)
|
|
180 |
{
|
|
181 |
CMIDItem::SetLabelL(aLabel);
|
|
182 |
if (iLabelControl && iLabel)
|
|
183 |
{
|
|
184 |
iLabelControl->SetTextL(*iLabel);
|
|
185 |
}
|
|
186 |
}
|
|
187 |
|
|
188 |
void CMIDControlItem::SetContainerWindowL(const CCoeControl& aContainer)
|
|
189 |
{
|
|
190 |
CCoeControl::SetContainerWindowL(aContainer);
|
|
191 |
if (iLabelControl)
|
|
192 |
{
|
|
193 |
iLabelControl->SetContainerWindowL(*this);
|
|
194 |
}
|
|
195 |
}
|
|
196 |
|
|
197 |
void CMIDControlItem::SetFocus(TBool aFocus, TDrawNow aDrawNow)
|
|
198 |
{
|
|
199 |
CCoeControl::SetFocus(aFocus, aDrawNow);
|
|
200 |
}
|
|
201 |
|
|
202 |
void CMIDControlItem::FocusChanged(TDrawNow aDrawNow)
|
|
203 |
{
|
|
204 |
if (!iForm)
|
|
205 |
{
|
|
206 |
return;
|
|
207 |
}
|
|
208 |
|
|
209 |
SetLabelColor(iLabelControl);
|
|
210 |
|
|
211 |
if (aDrawNow && DrawableWindow())
|
|
212 |
{
|
|
213 |
iLabelControl->DrawNow();
|
|
214 |
}
|
|
215 |
}
|
|
216 |
|
|
217 |
TTypeUid::Ptr CMIDControlItem::MopSupplyObject(TTypeUid aId)
|
|
218 |
{
|
|
219 |
if (aId.iUid == MAknsControlContext::ETypeId && iForm)
|
|
220 |
{
|
|
221 |
if (iHighlighted)
|
|
222 |
{
|
|
223 |
// Highlighted background control context must be returned
|
|
224 |
// no matter if item is focused or not. Only then highlighted item
|
|
225 |
// will be displayed correctly, if Form is faded
|
|
226 |
// (e.g. Menu is shown).
|
|
227 |
return MAknsControlContext::SupplyMopObject(aId,
|
|
228 |
iForm->GetHighlightBackgroundCc());
|
|
229 |
}
|
|
230 |
else
|
|
231 |
{
|
|
232 |
return MAknsControlContext::SupplyMopObject(aId,
|
|
233 |
iForm->CurrentDisplayable().BackGroundControlContext());
|
|
234 |
}
|
|
235 |
}
|
|
236 |
return SupplyMopObject(aId, iMenuHandler->Cba(), iMenuHandler->MenuBar());
|
|
237 |
}
|
|
238 |
|
|
239 |
void CMIDControlItem::GetCaptionForFep(TDes& aCaption) const
|
|
240 |
{
|
|
241 |
const TDesC* labelText = iLabelControl->Text();
|
|
242 |
if (labelText)
|
|
243 |
{
|
|
244 |
const TInt maximumLength = aCaption.MaxLength();
|
|
245 |
if (labelText->Length() > maximumLength)
|
|
246 |
{
|
|
247 |
aCaption = labelText->Left(maximumLength);
|
|
248 |
}
|
|
249 |
else
|
|
250 |
{
|
|
251 |
aCaption = *labelText;
|
|
252 |
}
|
|
253 |
}
|
|
254 |
else
|
|
255 |
{
|
|
256 |
aCaption = KNullDesC;
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
void CMIDControlItem::SetLabelColor(CMIDItemLabel* aLabelControl)
|
|
261 |
{
|
|
262 |
TRgb color;
|
|
263 |
|
|
264 |
TInt labelColor = (iHighlighted
|
|
265 |
&& Type() != MMIDComponent::ECustomItem
|
|
266 |
&& Type() != MMIDComponent::EImageItem)
|
|
267 |
? EAknsCIQsnTextColorsCG8 : EAknsCIQsnTextColorsCG6;
|
|
268 |
|
|
269 |
// Get color from skin
|
|
270 |
if ((AknsUtils::GetCachedColor(AknsUtils::SkinInstance(), color,
|
|
271 |
KAknsIIDQsnTextColors, labelColor) == KErrNone) && iLabelControl)
|
|
272 |
{//data entry text color
|
|
273 |
TRAP_IGNORE(aLabelControl->SetColorL(color));
|
|
274 |
}
|
|
275 |
}
|
|
276 |
|
|
277 |
TInt CMIDControlItem::LabelHeight() const
|
|
278 |
{
|
|
279 |
if (iLabelControl && iLabelControl->Text()->Length())
|
|
280 |
{
|
|
281 |
return iLabelControl->Size().iHeight;
|
|
282 |
}
|
|
283 |
|
|
284 |
return 0;
|
|
285 |
}
|
|
286 |
|
|
287 |
/** Returns height of a label that has only one line of text */
|
|
288 |
TInt CMIDControlItem::OneLineLabelHeight() const
|
|
289 |
{
|
|
290 |
return iLabelControl->LineHeight() + iLabelControl->ItemLabelMargin();
|
|
291 |
}
|
|
292 |
|
|
293 |
void CMIDControlItem::ResolutionChange(TInt /*aType*/)
|
|
294 |
{
|
|
295 |
|
|
296 |
}
|
|
297 |
|
|
298 |
void CMIDControlItem::ColorChange(TInt /*aType*/)
|
|
299 |
{
|
|
300 |
|
|
301 |
}
|
|
302 |
|
|
303 |
TBool CMIDControlItem::HasLabel()
|
|
304 |
{
|
|
305 |
return iLabelControl && (iLabelControl->Text()->Length() > 0);
|
|
306 |
}
|
|
307 |
|
|
308 |
void CMIDControlItem::PostFocusTransferEvent(TBool /*aFocus*/, CMIDForm::TDirection /*aDirection*/)
|
|
309 |
{
|
|
310 |
// override the default implementation if needed
|
|
311 |
}
|
|
312 |
|
|
313 |
void CMIDControlItem::RestoreInnerFocus()
|
|
314 |
{
|
|
315 |
// override the default implementation if needed
|
|
316 |
}
|
|
317 |
|
|
318 |
void CMIDControlItem::HandleWindowFade(TBool /*aFaded*/)
|
|
319 |
{
|
|
320 |
// override the default implementation if needed
|
|
321 |
}
|