|
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 <eikbtpan.h> |
|
20 #include <eiklbbut.h> |
|
21 #include <eikcmbut.h> |
|
22 #include <eiklabel.h> |
|
23 #include <barsread.h> |
|
24 #include <coedef.h> |
|
25 #include <eiklabel.h> |
|
26 #include <eikcmobs.h> |
|
27 #include <uikon.hrh> |
|
28 #include <eikcoctl.rsg> |
|
29 #include <coemain.h> |
|
30 #include <eikenv.h> |
|
31 #include "lafbtpan.h" |
|
32 #include "laflbbut.h" |
|
33 #include <eiklbbut.h> |
|
34 #include <uiklaf/private/lafenv.h> |
|
35 |
|
36 // const TInt KButtonArrayGranularity=2; |
|
37 |
|
38 const TInt KVerticalSpaceForNonLabeledButtons=6; |
|
39 const TInt KEikButtonLabelTopMargin=2; |
|
40 const TInt KEikButtonLabelBottomMargin=1; |
|
41 // const TInt KStdMinButtonWidth=50; |
|
42 |
|
43 #define VERTICAL_BUTTONS_AT_BOTTOM |
|
44 |
|
45 static TBool AnyButtonHasHotKey(const CEikControlGroup* aGroup, const TInt count) |
|
46 { |
|
47 TBool hasHotkey=EFalse; |
|
48 for(TInt ii=0;ii<count && !hasHotkey;ii++) |
|
49 { |
|
50 if(static_cast<CEikLabeledButton*>(aGroup->Control(ii))->ShowsHotKey()) |
|
51 hasHotkey=ETrue; |
|
52 } |
|
53 return hasHotkey; |
|
54 } |
|
55 |
|
56 EXPORT_C CEikButtonPanel::~CEikButtonPanel() |
|
57 { |
|
58 if (iControlGroups) |
|
59 { |
|
60 iControlGroups->ResetAndDestroy(); |
|
61 delete iControlGroups; |
|
62 } |
|
63 } |
|
64 |
|
65 EXPORT_C CEikButtonPanel::CEikButtonPanel() |
|
66 : iMinButWidth(LafButtonPanel::MinButtonWidth()) |
|
67 { |
|
68 __DECLARE_NAME(_S("CEikButtonPanel")); |
|
69 SetNonFocusing(); |
|
70 } |
|
71 |
|
72 void CEikButtonPanel::AppendNewLineL() |
|
73 {//private |
|
74 CEikControlGroup* controlGroup=new(ELeave) CEikControlGroup(); |
|
75 CleanupStack::PushL(controlGroup); |
|
76 if(LafButtonPanel::ButtonsAllSameSize()) |
|
77 controlGroup->SetControlsAllSameSize(); |
|
78 controlGroup->SetControlSpacing(LafButtonPanel::HorGapBetweenButtons(),LafButtonPanel::VerGapBetweenButtons()); |
|
79 controlGroup->SetContainerWindowL(*this); |
|
80 controlGroup->ConstructL( |
|
81 static_cast<CEikControlGroup::TStartCorner>(LafButtonPanel::DefaultStartCorner()), |
|
82 static_cast<CEikControlGroup::TOrientation>(LafButtonPanel::DefaultOrientation())); |
|
83 iControlGroups->AppendL(controlGroup); |
|
84 CleanupStack::Pop(); // controlGroup |
|
85 iCount++; |
|
86 iMinSize=TSize(0,0); |
|
87 } |
|
88 |
|
89 /** |
|
90 * Writes the internal state of the control and its components to aStream. |
|
91 * Does nothing in release mode. |
|
92 * Designed to be overidden and base called by subclasses. |
|
93 * |
|
94 * @internal |
|
95 * @since App-Framework_6.1 |
|
96 */ |
|
97 #ifndef _DEBUG |
|
98 EXPORT_C void CEikButtonPanel::WriteInternalStateL(RWriteStream&) const |
|
99 {} |
|
100 #else |
|
101 EXPORT_C void CEikButtonPanel::WriteInternalStateL(RWriteStream& aWriteStream) const |
|
102 { |
|
103 _LIT(KEikLitBtpanCtlSt,"<CEikButtonPanel>"); |
|
104 _LIT(KEikLitBtpanCtlEnd,"<\\CEikButtonPanel>"); |
|
105 _LIT(KEikLitBtpanCtlMinSize, "<iMinSize>"); |
|
106 _LIT(KEikLitBtpanCtlMinSizeEnd, "<\\iMinSize>"); |
|
107 _LIT(KEikLitBtpanCtlButWidth, "<iButWidth>"); |
|
108 _LIT(KEikLitBtpanCtlButWidthEnd, "<\\iButWidth>"); |
|
109 _LIT(KEikLitBtpanCtlMinButWidth, "<iMinButWidth>"); |
|
110 _LIT(KEikLitBtpanCtlMinButWidthEnd, "<\\iMinButWidth>"); |
|
111 _LIT(KEikLitBtpanCtlCount, "<iCount>"); |
|
112 _LIT(KEikLitBtpanCtlCountEnd, "<\\iCount>"); |
|
113 _LIT(KEikLitBtpanCtlObs, "<iCommandObserver>"); |
|
114 _LIT(KEikLitBtpanCtlObsEnd, "<\\iCommandObserver>"); |
|
115 |
|
116 aWriteStream << KEikLitBtpanCtlSt; |
|
117 aWriteStream << KEikLitBtpanCtlMinSize; |
|
118 aWriteStream.WriteInt32L(iMinSize.iWidth); |
|
119 aWriteStream.WriteInt32L(iMinSize.iHeight); |
|
120 aWriteStream << KEikLitBtpanCtlMinSizeEnd; |
|
121 aWriteStream << KEikLitBtpanCtlButWidth; |
|
122 aWriteStream.WriteInt32L(iButWidth); |
|
123 aWriteStream << KEikLitBtpanCtlButWidthEnd; |
|
124 aWriteStream << KEikLitBtpanCtlMinButWidth; |
|
125 aWriteStream.WriteInt32L(iMinButWidth); |
|
126 aWriteStream << KEikLitBtpanCtlMinButWidthEnd; |
|
127 aWriteStream << KEikLitBtpanCtlCount; |
|
128 aWriteStream.WriteInt32L(iCount); |
|
129 aWriteStream << KEikLitBtpanCtlCountEnd; |
|
130 aWriteStream << KEikLitBtpanCtlObs; |
|
131 aWriteStream.WriteInt32L((TInt)iCommandObserver); |
|
132 aWriteStream << KEikLitBtpanCtlObsEnd; |
|
133 CCoeControl::WriteInternalStateL(aWriteStream); |
|
134 aWriteStream << KEikLitBtpanCtlEnd; |
|
135 } |
|
136 #endif |
|
137 |
|
138 EXPORT_C void CEikButtonPanel::ConstructL() |
|
139 { |
|
140 iControlGroups=new(ELeave) CArrayPtrFlat<CEikControlGroup>(1); |
|
141 AppendNewLineL(); |
|
142 } |
|
143 |
|
144 EXPORT_C void CEikButtonPanel::SetHorizontal() |
|
145 { |
|
146 for(TInt ii=0;ii<iCount;ii++) |
|
147 (*iControlGroups)[ii]->SetControlLayout(CEikControlGroup::EFromTopLeft, CEikControlGroup::ELayHorizontally); |
|
148 } |
|
149 |
|
150 EXPORT_C TInt CEikButtonPanel::ButtonId(CCoeControl* aControl) const |
|
151 { |
|
152 TInt id=0; |
|
153 for(TInt ii=0;ii<iCount;ii++) |
|
154 { |
|
155 id=(*iControlGroups)[ii]->ControlId(aControl); |
|
156 if((*iControlGroups)[ii]->ControlById(id)==aControl) |
|
157 break; |
|
158 } |
|
159 return id; |
|
160 // KErrNotFound is a valid Id, but also used by CEikControlGroup to signify not found! |
|
161 } |
|
162 |
|
163 EXPORT_C CEikCommandButtonBase* CEikButtonPanel::ButtonById(TInt aButtonId) const |
|
164 { |
|
165 CEikLabeledButton* button=LabeledButtonById(aButtonId); |
|
166 return (button ? button->Button() : NULL); |
|
167 } |
|
168 |
|
169 EXPORT_C CEikLabeledButton* CEikButtonPanel::LabeledButtonById(TInt aButtonId) const |
|
170 { |
|
171 CEikLabeledButton* button=NULL; |
|
172 for(TInt ii=0;ii<iCount && !button;ii++) |
|
173 { |
|
174 button=static_cast<CEikLabeledButton*>((*iControlGroups)[ii]->ControlById(aButtonId)); |
|
175 } |
|
176 return button; |
|
177 } |
|
178 |
|
179 EXPORT_C void CEikButtonPanel::AddButtonL(CEikLabeledButton* aButton,TInt aId) |
|
180 { |
|
181 AddButtonL(aButton,aId,iCount-1);//last row by default |
|
182 } |
|
183 |
|
184 /** |
|
185 * Takes ownership of aButton, with asociated id, aId and adds it to the row of buttons aRow. |
|
186 * Creates aRow if it does not already exist. Should not be used for vertical button layout. |
|
187 * Leaves in out of memory conditions. |
|
188 * |
|
189 * @ since Uikon1.2 |
|
190 */ |
|
191 EXPORT_C void CEikButtonPanel::AddButtonL(CEikLabeledButton* aButton,TInt aId,TInt aRow) |
|
192 { |
|
193 CleanupStack::PushL(aButton); |
|
194 aButton->SetNonFocusing(); |
|
195 aButton->SetContainerWindowL(*this); |
|
196 aButton->CopyControlContextFrom(this); |
|
197 aButton->SetObserver(this); |
|
198 for(;aRow>iCount;AppendNewLineL()) |
|
199 ;// no body |
|
200 (*iControlGroups)[aRow-1]->AddControlL(aButton,aId); |
|
201 CleanupStack::Pop(); // aButton |
|
202 ResetMinimumSize(); |
|
203 } |
|
204 |
|
205 EXPORT_C void CEikButtonPanel::ActivateL() |
|
206 { |
|
207 CCoeControl::ActivateL(); |
|
208 } |
|
209 |
|
210 EXPORT_C void CEikButtonPanel::ConstructFromResourceL(TResourceReader& aReader) |
|
211 { |
|
212 ConstructL(); |
|
213 aReader.ReadUint32(); // read past flags - they're only used in CBAs currently |
|
214 const TInt count=aReader.ReadInt16(); |
|
215 for (TInt ii=0;ii<count;++ii) |
|
216 { |
|
217 const TInt id=aReader.ReadInt16(); |
|
218 CEikLabeledButton* button=new(ELeave) CEikLabeledButton; |
|
219 CleanupStack::PushL(button); |
|
220 button->CopyControlContextFrom(this); |
|
221 button->ConstructFromResourceL(aReader); |
|
222 TInt lineNumber=aReader.ReadInt8(); |
|
223 if (button->ShowsHotKey()) |
|
224 { |
|
225 CEikLabel* label=button->Label(); |
|
226 label->CopyControlContextFrom(this); |
|
227 label->iMargin.iTop=KEikButtonLabelTopMargin; |
|
228 label->iMargin.iBottom=KEikButtonLabelBottomMargin; |
|
229 } |
|
230 CleanupStack::Pop(); // AddButtonL takes ownership |
|
231 AddButtonL(button,id,lineNumber); |
|
232 } |
|
233 } |
|
234 |
|
235 EXPORT_C void CEikButtonPanel::ResetMinimumSize() |
|
236 { |
|
237 iMinSize=TSize(0,0); |
|
238 } |
|
239 |
|
240 EXPORT_C void CEikButtonPanel::SetMinButtonWidth(TInt aWidth) |
|
241 { |
|
242 iMinButWidth=aWidth; |
|
243 } |
|
244 |
|
245 EXPORT_C void CEikButtonPanel::SetCommandObserver(MEikCommandObserver* aCommandObserver) |
|
246 { |
|
247 iCommandObserver=aCommandObserver; |
|
248 } |
|
249 |
|
250 void CEikButtonPanel::UpdateHotKeyL(TInt aCommandId,CEikLabeledButton::TFlags aFlags,TInt aKeyCode) |
|
251 { |
|
252 CEikLabeledButton* button=LabeledButtonById(aCommandId); |
|
253 if (!button) |
|
254 User::Leave(KErrNotFound); |
|
255 button->UpdateHotKey(aKeyCode,aFlags); |
|
256 } |
|
257 |
|
258 EXPORT_C TInt CEikButtonPanel::CountComponentControls() const |
|
259 { |
|
260 return iCount; |
|
261 } |
|
262 |
|
263 EXPORT_C CCoeControl* CEikButtonPanel::ComponentControl(TInt aIndex) const |
|
264 { |
|
265 return (*iControlGroups)[aIndex]; |
|
266 } |
|
267 |
|
268 EXPORT_C void CEikButtonPanel::SizeChanged() |
|
269 { |
|
270 if(!iMinSize.iWidth) |
|
271 SetButtonWidths(); |
|
272 TInt excess=iSize.iWidth-iMinSize.iWidth; |
|
273 TMargins8 margins = LafButtonPanel::Margins(); |
|
274 TInt gapBetweenButtons=LafButtonPanel::HorGapBetweenButtons(); |
|
275 if(excess<0) |
|
276 AdjustMarginsToFit(margins.iLeft, margins.iRight, gapBetweenButtons); |
|
277 TRect groupRect=Rect(); |
|
278 groupRect.iTl.iX+=margins.iLeft; |
|
279 groupRect.iBr.iX-=margins.iRight; |
|
280 groupRect.iTl.iY+=margins.iTop; |
|
281 |
|
282 #if defined VERTICAL_BUTTONS_AT_BOTTOM |
|
283 groupRect.iTl.iY+=(iSize.iHeight-iMinSize.iHeight); |
|
284 #endif |
|
285 |
|
286 TRect individualRect(groupRect.iTl,TSize(0,0)); |
|
287 TInt translateBy=0; |
|
288 TInt horizontal=0; |
|
289 TInt vertical=0; |
|
290 CEikControlGroup* group; |
|
291 TSize groupMinSize; |
|
292 for(TInt ii=0 ; ii<iCount ;ii++) |
|
293 { |
|
294 group=(*iControlGroups)[ii]; |
|
295 group->ControlSpacing(horizontal,vertical); |
|
296 group->SetControlSpacing(gapBetweenButtons,vertical); |
|
297 groupMinSize=group->MinimumSize(); |
|
298 individualRect=TRect(individualRect.iTl,TSize(groupRect.Width(),groupMinSize.iHeight)); |
|
299 TRect shiftedRect=individualRect; |
|
300 excess=groupRect.Width()-groupMinSize.iWidth; |
|
301 if (excess>0) |
|
302 { |
|
303 TInt shiftLeft=0; |
|
304 TInt shiftRight=0; |
|
305 LafButtonPanel::TranslateForExcessSpace(excess, shiftLeft, shiftRight); |
|
306 shiftedRect.iTl.iX+=shiftLeft; |
|
307 shiftedRect.iBr.iX+=shiftRight; |
|
308 } |
|
309 group->SetRect(shiftedRect); |
|
310 translateBy=group->Size().iHeight+LafButtonPanel::InterRowMargin(); |
|
311 if(LafLabeledButton::ShowHotKey() |
|
312 && group->Orientation()==CEikControlGroup::ELayHorizontally |
|
313 && !(AnyButtonHasHotKey(group,group->ControlArray()->Count()))) |
|
314 { |
|
315 translateBy+=KVerticalSpaceForNonLabeledButtons; |
|
316 } |
|
317 individualRect.iTl.iY+=translateBy; |
|
318 } |
|
319 } |
|
320 |
|
321 void CEikButtonPanel::AdjustMarginsToFit(TInt8& aLeftBorder,TInt8& aRightBorder, TInt& aGapBetweenButtons) |
|
322 { |
|
323 // let the laf dictate the shrinking policy |
|
324 CEikControlGroup* group; |
|
325 TFixedArray<LafButtonPanel::TDimensions,KLafButPanMaxLinesOfDlgButtons> array; |
|
326 for(TInt ii=0; ii<iCount && ii<KLafButPanMaxLinesOfDlgButtons;ii++) |
|
327 { |
|
328 group=(*iControlGroups)[ii]; |
|
329 array[ii].iNumButtons=group->ControlArray()->Count(); |
|
330 array[ii].iExcess=iSize.iWidth-group->MinimumSize().iWidth; |
|
331 } |
|
332 LafButtonPanel::ReduceMarginsToFit(array, aLeftBorder, aRightBorder, aGapBetweenButtons); |
|
333 } |
|
334 |
|
335 void CEikButtonPanel::SetButtonWidths() |
|
336 { |
|
337 if((*iControlGroups)[0]->Orientation()==CEikControlGroup::ELayHorizontally) |
|
338 { |
|
339 CArrayFix<TEikGroupControl>* array=NULL; |
|
340 TInt components; |
|
341 TInt width=0; |
|
342 if(iMinButWidth!=KLafButPanNoMinButWidth) |
|
343 width=iMinButWidth; |
|
344 if(LafButtonPanel::ButtonsAllSameSize()) |
|
345 { |
|
346 TInt thisWidth; |
|
347 for(TInt ll=0; ll<iCount ; ll++) |
|
348 { |
|
349 array=(*iControlGroups)[ll]->ControlArray(); |
|
350 components=array->Count(); |
|
351 for(TInt mm=0; mm<components;mm++) |
|
352 { |
|
353 thisWidth=(*array)[mm].iControl->MinimumSize().iWidth; |
|
354 if(thisWidth>iButWidth) |
|
355 iButWidth=thisWidth; |
|
356 } |
|
357 } |
|
358 if(width<iButWidth) |
|
359 width=iButWidth; |
|
360 } |
|
361 if(width) |
|
362 { |
|
363 for(TInt jj=0; jj<iCount ; jj++) |
|
364 { |
|
365 array=(*iControlGroups)[jj]->ControlArray(); |
|
366 components=array->Count(); |
|
367 for(TInt kk=0; kk<components;kk++) |
|
368 { |
|
369 TEikGroupControl& grpControl=(*array)[kk]; |
|
370 grpControl.SetLength(Max(width,grpControl.iControl->MinimumSize().iWidth)); |
|
371 } |
|
372 } |
|
373 } |
|
374 } |
|
375 } |
|
376 |
|
377 EXPORT_C TSize CEikButtonPanel::MinimumSize() |
|
378 { |
|
379 if (!iMinSize.iWidth) |
|
380 { |
|
381 SetButtonWidths(); |
|
382 TMargins8 margins = LafButtonPanel::Margins(); |
|
383 iMinSize.iHeight=margins.iTop+margins.iBottom; |
|
384 iMinSize.iWidth=0; |
|
385 iMinSize.iHeight+=(iCount-1)*LafButtonPanel::InterRowMargin(); |
|
386 CEikControlGroup* group=NULL; |
|
387 TSize groupMinSize; |
|
388 for(TInt jj=0; jj<iCount; jj++) |
|
389 { |
|
390 group=(*iControlGroups)[jj]; |
|
391 TInt count=group->ControlArray()->Count(); |
|
392 if(LafLabeledButton::ShowHotKey()) |
|
393 { |
|
394 CEikControlGroup::TOrientation orientation=group->Orientation(); |
|
395 if(orientation==CEikControlGroup::ELayVertically && !LafButtonPanel::ButtonsAllSameSize()) |
|
396 { |
|
397 for(TInt ii=0;ii<count;ii++) |
|
398 { |
|
399 if(!static_cast<CEikLabeledButton*>(group->Control(ii))->ShowsHotKey()) |
|
400 iMinSize.iHeight+=KVerticalSpaceForNonLabeledButtons; |
|
401 } |
|
402 } |
|
403 else if(orientation==CEikControlGroup::ELayVertically && LafButtonPanel::ButtonsAllSameSize()) |
|
404 { |
|
405 if(!AnyButtonHasHotKey(group,count)) |
|
406 { |
|
407 group->SetControlSpacing(LafButtonPanel::HorGapBetweenButtons(),LafButtonPanel::VerGapBetweenButtons()+KVerticalSpaceForNonLabeledButtons); |
|
408 iMinSize.iHeight+=KVerticalSpaceForNonLabeledButtons; // for bottom |
|
409 } |
|
410 } |
|
411 else if(orientation==CEikControlGroup::ELayHorizontally) |
|
412 { |
|
413 if(!AnyButtonHasHotKey(group,count)) |
|
414 iMinSize.iHeight+=KVerticalSpaceForNonLabeledButtons; |
|
415 } |
|
416 } |
|
417 groupMinSize=group->MinimumSize(); |
|
418 iMinSize.iHeight+=groupMinSize.iHeight; |
|
419 iMinSize.iWidth=Max(iMinSize.iWidth,groupMinSize.iWidth); |
|
420 } |
|
421 iMinSize.iWidth+=(margins.iLeft + margins.iRight); |
|
422 } |
|
423 return(iMinSize); |
|
424 } |
|
425 |
|
426 EXPORT_C void CEikButtonPanel::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType) |
|
427 { |
|
428 if (aEventType==EEventStateChanged) |
|
429 iCommandObserver->ProcessCommandL(ButtonId(aControl)); |
|
430 } |
|
431 |
|
432 EXPORT_C CEikCommandButtonBase* CEikButtonPanel::ButtonForKey(TInt aChar,TInt& aButtonId) const |
|
433 { |
|
434 const TCharF foldedChar(aChar); |
|
435 const TUint foldedCharCode=TUint(foldedChar); |
|
436 TInt count=0; |
|
437 CEikControlGroup* group=NULL; |
|
438 CEikCommandButtonBase* match=NULL; |
|
439 for(TInt jj=0;jj<iCount && !match;jj++) |
|
440 { |
|
441 group=(*iControlGroups)[jj]; |
|
442 count=group->ControlArray()->Count(); |
|
443 for (TInt ii=0;ii<count && !match ;++ii) |
|
444 { |
|
445 CEikLabeledButton* button=static_cast<CEikLabeledButton*>(group->Control(ii)); |
|
446 if ((foldedChar==TCharF(button->HotKeyCode())) |
|
447 ||((button->Button()->IsDefault())&&(LafEnv::IsDefaultKey(foldedCharCode)))) |
|
448 { |
|
449 aButtonId=group->ControlId(group->Control(ii)); |
|
450 if (button->IsVisible()) |
|
451 match=button->Button(); |
|
452 } |
|
453 } |
|
454 } |
|
455 return match; |
|
456 } |
|
457 |
|
458 EXPORT_C void CEikButtonPanel::MakeButtonVisible(TInt aButtonId,TBool aVisible) |
|
459 { |
|
460 TInt count=0; |
|
461 CEikControlGroup* group=NULL; |
|
462 for(TInt jj=0;jj<iCount;jj++) |
|
463 { |
|
464 group=(*iControlGroups)[jj]; |
|
465 count=group->ControlArray()->Count(); |
|
466 for (TInt ii=0;ii<count;++ii) |
|
467 { |
|
468 CEikLabeledButton* button=static_cast<CEikLabeledButton*>(group->Control(ii)); |
|
469 if (group->ControlId(group->Control(ii))==aButtonId) |
|
470 { |
|
471 button->MakeVisible(aVisible); |
|
472 return; |
|
473 } |
|
474 } |
|
475 } |
|
476 } |
|
477 |
|
478 |
|
479 void CEikButtonPanel::SetCommandL(TInt aPosition,TInt aCommandId,const TDesC* aText,const CFbsBitmap* aBitmap,const CFbsBitmap* aMask) |
|
480 { |
|
481 TInt groupIndex=0; |
|
482 CEikLabeledButton* lBut=LabeledButtonByPosition(aPosition,groupIndex); |
|
483 CEikCommandButtonBase* button=static_cast<CEikCommandButtonBase*>(lBut->Button()); |
|
484 static_cast<CEikCommandButton*>(button)->SetCommandL(aCommandId, aText, aBitmap, aMask); |
|
485 TInt ignore=0; |
|
486 (*((*iControlGroups)[groupIndex])->ControlArray())[RelativePosition(aPosition,ignore)].iId=aCommandId; |
|
487 } |
|
488 |
|
489 void CEikButtonPanel::SetCommandL(TInt aPosition,TInt aResourceId) |
|
490 { |
|
491 TResourceReader reader; |
|
492 iEikonEnv->CreateResourceReaderLC(reader,aResourceId); |
|
493 const TInt id=reader.ReadInt16(); // id |
|
494 const TInt type=reader.ReadInt16(); // buttontype |
|
495 if (type==EEikCtCommandButton) |
|
496 { |
|
497 CEikCommandButton* button=new(ELeave) CEikCommandButton; |
|
498 CleanupStack::PushL(button); |
|
499 button->ConstructFromResourceL(reader); |
|
500 /*TInt hotKeyCode=*/reader.ReadInt32(); |
|
501 /*TInt lButFlags=*/reader.ReadInt8(); |
|
502 SetCommandL(aPosition, id, button->Label()->Text(), NULL, NULL); |
|
503 CleanupStack::PopAndDestroy(); |
|
504 } |
|
505 CleanupStack::PopAndDestroy(); |
|
506 } |
|
507 |
|
508 void CEikButtonPanel::SetCommandSetL(TInt aResourceId) |
|
509 { |
|
510 TResourceReader reader; |
|
511 iEikonEnv->CreateResourceReaderLC(reader,aResourceId); |
|
512 const TInt count=reader.ReadInt16(); |
|
513 TInt ii; |
|
514 for (ii=0 ; ii<count; ii++) |
|
515 { |
|
516 const TInt id=reader.ReadInt16(); // id |
|
517 const TInt type=reader.ReadInt16(); // buttontype |
|
518 |
|
519 if (type==EEikCtCommandButton) |
|
520 { |
|
521 CEikCommandButton* button=new(ELeave) CEikCommandButton; |
|
522 CleanupStack::PushL(button); |
|
523 button->ConstructFromResourceL(reader); |
|
524 /*TInt hotKeyCode=*/reader.ReadInt32(); |
|
525 /*TInt lButFlags=*/reader.ReadInt8(); |
|
526 SetCommandL(ii, id, button->Label()->Text(), NULL, NULL); |
|
527 CleanupStack::PopAndDestroy(); |
|
528 DimCommand(id,EFalse); |
|
529 } |
|
530 } |
|
531 CleanupStack::PopAndDestroy(); |
|
532 } |
|
533 |
|
534 void CEikButtonPanel::AddCommandL(TInt aPosition,TInt aCommandId,const TDesC* aText,const CFbsBitmap* aBitmap,const CFbsBitmap* aMask) |
|
535 { |
|
536 // !!! todo - cleanup support for bitmaps |
|
537 // if (IsReadyToDraw()) |
|
538 // User::Leave(KErrGeneral); |
|
539 TInt groupIndex=0; |
|
540 TInt posInGroup=RelativePosition(aPosition,groupIndex); |
|
541 CEikControlGroup* group=(*iControlGroups)[groupIndex]; |
|
542 const TInt count=group->ControlArray()->Count(); |
|
543 if (aPosition>count) |
|
544 User::Leave(KErrOverflow); |
|
545 CEikCommandButton* button=new(ELeave) CEikCommandButton; |
|
546 CleanupStack::PushL(button); |
|
547 if (aText) |
|
548 button->SetTextL(*aText); |
|
549 if (aBitmap) |
|
550 button->SetPictureL(aBitmap,aMask); |
|
551 CEikLabeledButton* lBut=new(ELeave) CEikLabeledButton; |
|
552 CleanupStack::PushL(lBut); |
|
553 lBut->ConstructL(button,0,0); |
|
554 CleanupStack::Pop(); // button |
|
555 lBut->SetContainerWindowL(*this); |
|
556 lBut->SetObserver(this); |
|
557 if (aPosition<count) |
|
558 { |
|
559 TEikGroupControl grpControl=TEikGroupControl(lBut,aCommandId,0,0); |
|
560 group->InsertControlL(grpControl,posInGroup); |
|
561 } |
|
562 else |
|
563 group->AddControlL(lBut,aCommandId); |
|
564 CleanupStack::Pop(); // lBut |
|
565 } |
|
566 |
|
567 |
|
568 void CEikButtonPanel::AddCommandToStackL(TInt aPosition,TInt aCommandId,const TDesC* aText,const CFbsBitmap* aBitmap,const CFbsBitmap* aMask) |
|
569 { |
|
570 CEikCommandButton* lBut=static_cast<CEikCommandButton*>(LabeledButtonByPosition(aPosition)->Button()); |
|
571 TInt groupIndex=0; |
|
572 TInt relativePos=RelativePosition(aPosition,groupIndex); |
|
573 CEikControlGroup* group=(*iControlGroups)[groupIndex]; |
|
574 lBut->AddCommandToStackL(group->ControlId(group->Control(relativePos)),aText,aBitmap,aMask); |
|
575 (*group->ControlArray())[relativePos].iId=aCommandId; |
|
576 } |
|
577 |
|
578 void CEikButtonPanel::AddCommandToStackL(TInt /*aPosition*/,TInt /*aResourceId*/) |
|
579 { |
|
580 } |
|
581 |
|
582 void CEikButtonPanel::AddCommandSetToStackL(TInt /*aResourceId*/) |
|
583 { |
|
584 } |
|
585 |
|
586 void CEikButtonPanel::SetDefaultCommand(TInt /*aCommandId*/) |
|
587 { |
|
588 } |
|
589 |
|
590 TSize CEikButtonPanel::CalcMinimumSizeL(TInt /*aResourceId*/) |
|
591 { |
|
592 return MinimumSize(); |
|
593 } |
|
594 |
|
595 void CEikButtonPanel::RemoveCommandFromStack(TInt aPosition,TInt aCommandId) |
|
596 { |
|
597 TInt groupIndex=0; |
|
598 CEikCommandButton* lBut=static_cast<CEikCommandButton*>(LabeledButtonByPosition(aPosition,groupIndex)->Button()); |
|
599 CEikControlGroup* group=(*iControlGroups)[groupIndex]; |
|
600 if (aCommandId==group->ControlId(group->Control(aPosition))) |
|
601 { |
|
602 (*group->ControlArray())[aPosition].iId=lBut->PopCommandFromStack(); |
|
603 } |
|
604 else |
|
605 { |
|
606 lBut->RemoveCommandFromStack(aCommandId); |
|
607 } |
|
608 } |
|
609 |
|
610 TInt CEikButtonPanel::CommandPos(TInt aCommandId) const |
|
611 { |
|
612 TBool found=EFalse; |
|
613 TInt indexOfOwningGroup=0; |
|
614 CEikControlGroup* group=NULL; |
|
615 TInt pos=0; |
|
616 for(;(indexOfOwningGroup<iCount) && (!found); indexOfOwningGroup++) |
|
617 { |
|
618 group=(*iControlGroups)[indexOfOwningGroup]; |
|
619 if(group->IndexById(aCommandId)==KErrNotFound) |
|
620 pos+=group->ControlArray()->Count(); |
|
621 else |
|
622 { |
|
623 pos+=group->IndexById(aCommandId); |
|
624 found=ETrue; |
|
625 } |
|
626 } |
|
627 return (found? pos : KErrNotFound); |
|
628 } |
|
629 |
|
630 void CEikButtonPanel::DimCommand(TInt aCommandId,TBool aDimmed) |
|
631 { |
|
632 LabeledButtonById(aCommandId)->SetDimmed(aDimmed); |
|
633 LabeledButtonById(aCommandId)->DrawNow(); |
|
634 } |
|
635 |
|
636 TBool CEikButtonPanel::IsCommandDimmed(TInt aCommandId) const |
|
637 { |
|
638 return LabeledButtonById(aCommandId)->IsDimmed(); |
|
639 } |
|
640 |
|
641 void CEikButtonPanel::MakeCommandVisible(TInt aCommandId,TBool aVisible) |
|
642 { |
|
643 MakeButtonVisible(aCommandId,aVisible); |
|
644 } |
|
645 |
|
646 TBool CEikButtonPanel::IsCommandVisible(TInt aCommandId) const |
|
647 { |
|
648 return LabeledButtonById(aCommandId)->IsVisible(); |
|
649 } |
|
650 |
|
651 CCoeControl* CEikButtonPanel::AsControl() |
|
652 { |
|
653 return this; |
|
654 } |
|
655 |
|
656 const CCoeControl* CEikButtonPanel::AsControl() const |
|
657 { |
|
658 return this; |
|
659 } |
|
660 |
|
661 void CEikButtonPanel::SetBoundingRect(const TRect& /*aBoundingRect*/) |
|
662 { |
|
663 } |
|
664 |
|
665 void CEikButtonPanel::ReduceRect(TRect& /*aBoundingRect*/) const |
|
666 { |
|
667 } |
|
668 |
|
669 void CEikButtonPanel::SetMSKCommandObserver(MEikCommandObserver* /*aCommandObserver*/) |
|
670 { |
|
671 } |
|
672 |
|
673 void CEikButtonPanel::DimCommandByPosition(TInt /*aPosition*/,TBool /*aDimmed*/) |
|
674 { |
|
675 } |
|
676 |
|
677 TBool CEikButtonPanel::IsCommandDimmedByPosition(TInt /*aPosition*/) const |
|
678 { |
|
679 return EFalse; |
|
680 } |
|
681 |
|
682 void CEikButtonPanel::MakeCommandVisibleByPosition(TInt /*aPosition*/,TBool /*aVisible*/) |
|
683 { |
|
684 } |
|
685 |
|
686 TBool CEikButtonPanel::IsCommandVisibleByPosition(TInt /*aPosition*/) const |
|
687 { |
|
688 return EFalse; |
|
689 } |
|
690 |
|
691 void CEikButtonPanel::AnimateCommandByPosition(TInt /*aPosition*/) |
|
692 { |
|
693 } |
|
694 |
|
695 CCoeControl* CEikButtonPanel::GroupControlById(TInt aCommandId) const |
|
696 { |
|
697 return LabeledButtonById(aCommandId); // assume callers only care about the button part |
|
698 } |
|
699 |
|
700 CEikCommandButton* CEikButtonPanel::GroupControlAsButton(TInt aCommandId) const |
|
701 { |
|
702 CEikCommandButton* ret=NULL; |
|
703 CEikCommandButtonBase* but=ButtonById(aCommandId); |
|
704 if (but) |
|
705 ret=STATIC_CAST(CEikCommandButton*,but); |
|
706 return ret; |
|
707 } |
|
708 |
|
709 TInt CEikButtonPanel::CommandId(TInt aCommandPos) const |
|
710 { |
|
711 TInt indexOfOwningGroup; |
|
712 CEikLabeledButton* button=LabeledButtonByPosition(aCommandPos,indexOfOwningGroup); |
|
713 return (*iControlGroups)[indexOfOwningGroup]->ControlId(button); |
|
714 } |
|
715 |
|
716 CEikLabeledButton* CEikButtonPanel::LabeledButtonByPosition(TInt aPosition) const |
|
717 { |
|
718 TInt ignore; |
|
719 return LabeledButtonByPosition(aPosition,ignore); |
|
720 } |
|
721 |
|
722 CEikLabeledButton* CEikButtonPanel::LabeledButtonByPosition(TInt aPosition, TInt& aGroupIndex) const |
|
723 { |
|
724 TInt pos=RelativePosition(aPosition, aGroupIndex); |
|
725 return static_cast<CEikLabeledButton*>((*iControlGroups)[aGroupIndex]->Control(pos)); |
|
726 } |
|
727 |
|
728 TInt CEikButtonPanel::RelativePosition(TInt aCommandPos, TInt& aGroupIndex) const |
|
729 { |
|
730 TInt trialPos=aCommandPos; |
|
731 aGroupIndex=0; |
|
732 CEikControlGroup* group=NULL; |
|
733 for(;(aGroupIndex<iCount) && (trialPos>=0); aGroupIndex++) |
|
734 { |
|
735 aCommandPos=trialPos; |
|
736 group=(*iControlGroups)[aGroupIndex]; |
|
737 trialPos-=group->ControlArray()->Count(); |
|
738 } |
|
739 aGroupIndex--; |
|
740 return aCommandPos; |
|
741 } |
|
742 |
|
743 TInt CEikButtonPanel::ButtonCount() const |
|
744 { |
|
745 TInt buttonCount=0; |
|
746 CEikControlGroup* group=NULL; |
|
747 for(TInt jj=0; jj<iCount;jj++) |
|
748 { |
|
749 group=(*iControlGroups)[jj]; |
|
750 buttonCount+=group->ControlArray()->Count(); |
|
751 } |
|
752 return buttonCount; |
|
753 } |
|
754 |
|
755 TUint CEikButtonPanel::ButtonGroupFlags() const |
|
756 { |
|
757 return 0; |
|
758 } |
|
759 |
|
760 TBool CEikButtonPanel::ButtonsConsumedKeyL(TInt aCode) |
|
761 { |
|
762 TInt buttonId; |
|
763 CEikCommandButtonBase* button=ButtonForKey(aCode,buttonId); |
|
764 |
|
765 if (!button) |
|
766 return(EFalse); |
|
767 |
|
768 if (button->IsDimmed()) |
|
769 { |
|
770 ReportEventL(MCoeControlObserver::EEventInteractionRefused); |
|
771 return(EFalse); |
|
772 } |
|
773 |
|
774 if (!button->IsVisible()) |
|
775 return(EFalse); |
|
776 |
|
777 button->Animate(); |
|
778 iCommandObserver->ProcessCommandL(buttonId); |
|
779 |
|
780 return(ETrue); |
|
781 } |
|
782 |
|
783 EXPORT_C TKeyResponse CEikButtonPanel::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) |
|
784 { |
|
785 if (aType!=EEventKey) |
|
786 return(EKeyWasConsumed); |
|
787 |
|
788 TInt code=aKeyEvent.iCode; |
|
789 TInt foldedCode=TCharF(code); |
|
790 |
|
791 return ButtonsConsumedKeyL(foldedCode) ? EKeyWasConsumed : EKeyWasNotConsumed; |
|
792 } |
|
793 |
|
794 /** |
|
795 * Gets the list of logical colors employed in the drawing of the control, |
|
796 * paired with an explanation of how they are used. Appends the list to aColorUseList. |
|
797 * |
|
798 * @since ER5U |
|
799 */ |
|
800 EXPORT_C void CEikButtonPanel::GetColorUseListL(CArrayFix<TCoeColorUse>& /*aColorUseList*/) const |
|
801 { |
|
802 } |
|
803 |
|
804 /** |
|
805 * Handles a change to the control's resources of type aType |
|
806 * which are shared across the environment, e.g. colors or fonts. |
|
807 * |
|
808 * @since ER5U |
|
809 */ |
|
810 EXPORT_C void CEikButtonPanel::HandleResourceChange(TInt aType) |
|
811 { |
|
812 CCoeControl::HandleResourceChange(aType); |
|
813 } |
|
814 |
|
815 EXPORT_C void CEikButtonPanel::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
816 { |
|
817 CAknControl::HandlePointerEventL(aPointerEvent); |
|
818 } |
|
819 |
|
820 EXPORT_C void* CEikButtonPanel::ExtensionInterface( TUid /*aInterface*/ ) |
|
821 { |
|
822 return NULL; |
|
823 } |
|
824 |
|
825 EXPORT_C void CEikButtonPanel::Reserved_2() |
|
826 {} |