|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Tests for control layout manager support.\n |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalComponent - Internal Symbian test code |
|
21 @file |
|
22 @internalComponent |
|
23 */ |
|
24 |
|
25 #include <e32std.h> |
|
26 #include <coeaui.h> |
|
27 #include "TCone5Step.h" |
|
28 |
|
29 //! Horizontal border for the control.\n |
|
30 const TUint KHorizontalBorder = 25; |
|
31 //! Vertical border for the control.\n |
|
32 const TUint KVerticalBorder = 25; |
|
33 //! Max number of component controls.\n |
|
34 const TUint KNumControls = 10; |
|
35 //! Minimum size of the Control.\n |
|
36 #define KMinSize TSize(10, 10) |
|
37 //! Total Size of the Window in which controls are spaced.\n |
|
38 #define KViewRect TRect(TPoint(0,0), TPoint(400,200)) |
|
39 |
|
40 |
|
41 /** |
|
42 Constructor for CCone5TestAppUi class.\n |
|
43 Sets the Test step Name.\n |
|
44 */ |
|
45 CCone5TestAppUi::CCone5TestAppUi(CTmsTestStep* aStep) : |
|
46 CTestCoeAppUi(aStep) |
|
47 { |
|
48 } |
|
49 /** |
|
50 Destructor for CCone5TestAppUi class.\n |
|
51 */ |
|
52 CCone5TestAppUi::~CCone5TestAppUi() |
|
53 { |
|
54 delete iTestAppView; |
|
55 } |
|
56 /** |
|
57 Second phase constructor for the CCone5TestAppUi class.\n |
|
58 Invokes the base class CTestCoeAppUi ConstructL function.\n |
|
59 Instantiates a layout manager object handles the layout of the components |
|
60 of the attached compound controls.\n |
|
61 It also calculates the attached compound controls' minimum size.\n |
|
62 Starts the asynchronous execution of tests using Auto test manager.\n |
|
63 */ |
|
64 void CCone5TestAppUi::ConstructL() |
|
65 { |
|
66 CTestCoeAppUi::ConstructL(); |
|
67 CLayoutTest* layoutMan = new(ELeave) CLayoutTest; |
|
68 // CLayoutTest derives from CObject, so push it on the cleanup stack using CleanupClosePushL() |
|
69 // this will call close on the object if a leave occurs decrementing the internal reference count |
|
70 // and deleting the object when the reference count gets to zero |
|
71 CleanupClosePushL(*layoutMan); |
|
72 iTestAppView = CLayoutTestAppView::NewL(layoutMan, KViewRect); |
|
73 // layout manager takes over ownership of itself |
|
74 CleanupStack::Pop(layoutMan); |
|
75 layoutMan->Close(); |
|
76 iLayoutMan = layoutMan; |
|
77 AutoTestManager().StartAutoTest(); |
|
78 } |
|
79 /** |
|
80 @SYMTestCaseID UIF-TCone5Step-DoTestsL |
|
81 |
|
82 @SYMPREQ |
|
83 |
|
84 @SYMTestCaseDesc Tests MCoeLayOutManager APIs.\n |
|
85 |
|
86 @SYMTestPriority High |
|
87 |
|
88 @SYMTestStatus Implemented |
|
89 |
|
90 @SYMTestActions : Gets the layout manager for the application initially using LayoutManager() API \n |
|
91 Sets the layout manager for the application using SetLayoutManager() API. \n |
|
92 The setting of layout manager is verified using the Get Function.\n |
|
93 The layouts performed by the layout manager are obtained using LayoutsPerformed() API. \n |
|
94 A relayout of the components of the application is requested using RequestReLayout() API.\n |
|
95 Change of component control sizes is tested.\n |
|
96 |
|
97 @SYMTestExpectedResults The application should be started without any error.\n |
|
98 |
|
99 @SYMTestType : CIT |
|
100 */ |
|
101 void CCone5TestAppUi::DoTestsL() |
|
102 { |
|
103 INFO_PRINTF1(_L("Testing Setting the Layout Manager")); |
|
104 MCoeLayoutManager* layout = NULL; |
|
105 layout = iTestAppView->LayoutManager(); |
|
106 TEST(layout == NULL); |
|
107 iTestAppView->SetLayoutManagerL(iLayoutMan); |
|
108 layout = iTestAppView->LayoutManager(); |
|
109 TEST(layout == iLayoutMan); |
|
110 iTestAppView->SetLayoutManagerL(NULL); |
|
111 layout = iTestAppView->LayoutManager(); |
|
112 TEST(layout == NULL); |
|
113 // set the layout manager in preparation for next test |
|
114 iTestAppView->SetLayoutManagerL(iLayoutMan); |
|
115 |
|
116 |
|
117 INFO_PRINTF1(_L("Testing CanAttach()")); |
|
118 layout = iTestAppView->LayoutManager(); |
|
119 TEST(layout->CanAttach() != EFalse); |
|
120 |
|
121 INFO_PRINTF1(_L("Testing Request Relayout")); |
|
122 TUint layoutsPerformed = iLayoutMan->LayoutsPerformed(); |
|
123 iTestAppView->RequestRelayout(iTestAppView); |
|
124 // this should have caused a layout to be performed |
|
125 ++layoutsPerformed; |
|
126 TEST(iLayoutMan->LayoutsPerformed() == layoutsPerformed); |
|
127 const RPointerArray<CTest5Control>& ctrlArray = iTestAppView->CtrlArray(); |
|
128 TInt numCtrls = ctrlArray.Count(); |
|
129 layoutsPerformed = iLayoutMan->LayoutsPerformed(); |
|
130 TInt ctrlCount = 0; |
|
131 for (ctrlCount = 0; ctrlCount < numCtrls; ctrlCount++) |
|
132 { |
|
133 ctrlArray[ctrlCount]->RequestRelayout(iTestAppView); |
|
134 ++layoutsPerformed; |
|
135 TEST(iLayoutMan->LayoutsPerformed() == layoutsPerformed); |
|
136 } |
|
137 |
|
138 |
|
139 INFO_PRINTF1(_L("Testing Changing Control Size")); |
|
140 // every time a controls size is changed a layout will be performed |
|
141 layoutsPerformed = iLayoutMan->LayoutsPerformed(); |
|
142 iTestAppView->SetRect(KViewRect); |
|
143 ++layoutsPerformed; |
|
144 TEST(iLayoutMan->LayoutsPerformed() == layoutsPerformed); |
|
145 numCtrls = ctrlArray.Count(); |
|
146 for (ctrlCount = 0; ctrlCount < numCtrls; ctrlCount++) |
|
147 { |
|
148 ctrlArray[ctrlCount]->SetRect(KMinSize); |
|
149 layoutsPerformed++; |
|
150 TEST(iLayoutMan->LayoutsPerformed() == layoutsPerformed); |
|
151 } |
|
152 |
|
153 INFO_PRINTF1(_L("Testing Calculating mimimum size")); |
|
154 TEST (iTestAppView->MinimumSize() == KMinSize); |
|
155 |
|
156 INFO_PRINTF1(_L("Testing baseline offset calculation")); |
|
157 TSize testSize(400, 400); |
|
158 |
|
159 // See implementation of CalcTextBaselineOffset - if the |
|
160 // width > 200, it returns height/4, else it returns 3*height/4 |
|
161 // ctrlArray[0] only porvided as dummy because fct requires it |
|
162 TInt baseOffset = iLayoutMan->CalcTextBaselineOffset(*ctrlArray[0], testSize); |
|
163 INFO_PRINTF2(_L("Width 400, offset = %d"), baseOffset); |
|
164 TEST (baseOffset < 200); |
|
165 |
|
166 testSize.iWidth = 100; |
|
167 baseOffset = iLayoutMan->CalcTextBaselineOffset(*ctrlArray[0], testSize); |
|
168 INFO_PRINTF2(_L("Width 100, offset = %d"), baseOffset); |
|
169 TEST (baseOffset > 200); |
|
170 } |
|
171 |
|
172 /** |
|
173 Auxilliary Function for all test cases.\n |
|
174 This function is iteratively called by the RunL function of the Autotestmanager |
|
175 asynchronously.\n |
|
176 Calls the following function\n |
|
177 1. DoTestsL() |
|
178 */ |
|
179 void CCone5TestAppUi::RunTestStepL(TInt aStepNum) |
|
180 { |
|
181 switch(aStepNum) |
|
182 { |
|
183 case 1: |
|
184 SetTestStepID(_L("UIF-TCone5Step-DoTestsL")); |
|
185 TRAPD(err, DoTestsL()); |
|
186 TEST(err == KErrNone); |
|
187 RecordTestResultL(); |
|
188 CloseTMSGraphicsStep(); |
|
189 break; |
|
190 case 2: |
|
191 AutoTestManager().FinishAllTestCases(CAutoTestManager::EPass); |
|
192 break; |
|
193 } |
|
194 } |
|
195 |
|
196 /** |
|
197 Completes the construction of the Control Environment(CCoeEnv object).\n |
|
198 Instantiates the CCone5TestAppUi class which serves as a AppUi class.\n |
|
199 Sets the CCone5TestAppUi object as the application's user interface object.\n |
|
200 Invokes the second phase constructor of the application's UI.\n |
|
201 */ |
|
202 void CTCone5Step::ConstructCone5AppL(CCoeEnv* aCoe) |
|
203 { // runs inside a TRAP harness |
|
204 aCoe->ConstructL(); |
|
205 CCone5TestAppUi* appUi=new(ELeave) CCone5TestAppUi(this); |
|
206 aCoe->SetAppUi(appUi); |
|
207 appUi->ConstructL(); |
|
208 } |
|
209 /** |
|
210 Constructor for CTCone5Step class.\n |
|
211 Sets the test step name.\n |
|
212 */ |
|
213 |
|
214 CTCone5Step::CTCone5Step() |
|
215 { |
|
216 SetTestStepName(KTCone5Step); |
|
217 } |
|
218 /** |
|
219 Destructor for CTCone5Step class.\n |
|
220 */ |
|
221 CTCone5Step::~CTCone5Step() |
|
222 {} |
|
223 |
|
224 /** |
|
225 Entry function for CTCone5 Test Step.\n |
|
226 Sets up the control environment.\n |
|
227 Constructs and Launches the CTCone5 Test application.\n |
|
228 */ |
|
229 TVerdict CTCone5Step::doTestStepL() |
|
230 { |
|
231 INFO_PRINTF1(_L("Test Started")); |
|
232 CCoeEnv* coe=new(ELeave) CCoeEnv; |
|
233 TRAPD(err,ConstructCone5AppL(coe)); |
|
234 if (!err) |
|
235 coe->ExecuteD(); |
|
236 else |
|
237 { |
|
238 SetTestStepResult(EFail); |
|
239 coe->PrepareToExit(); |
|
240 coe->DestroyEnvironment(); |
|
241 delete coe; |
|
242 } |
|
243 |
|
244 INFO_PRINTF1(_L("Test Finished")); |
|
245 return TestStepResult(); |
|
246 } |
|
247 |
|
248 |
|
249 // |
|
250 // |
|
251 // CTest5Control |
|
252 // |
|
253 // |
|
254 /** |
|
255 Constructor for CTest5Control class.\n |
|
256 */ |
|
257 CTest5Control::CTest5Control() |
|
258 { |
|
259 } |
|
260 /** |
|
261 Static function used for CTest5Control class instantiation.\n |
|
262 The function instantiates an CTest5Control object.\n |
|
263 Invokes second phase constructor of CTest5Control class passing pointers to |
|
264 Layout manager, container object as arguments.\n |
|
265 */ |
|
266 CTest5Control* CTest5Control::NewL(CLayoutTest* aLayoutMan, |
|
267 CCoeControl& aContainer, const TRect& aRect) |
|
268 { |
|
269 CTest5Control* self = new(ELeave) CTest5Control(); |
|
270 CleanupStack::PushL(self); |
|
271 self->ConstructL(aLayoutMan, aContainer, aRect); |
|
272 CleanupStack::Pop(); |
|
273 return self; |
|
274 } |
|
275 /** |
|
276 Destructor for CTest5Control class.\n |
|
277 */ |
|
278 CTest5Control::~CTest5Control() |
|
279 { |
|
280 } |
|
281 /** |
|
282 Second phase constructor for CTest5Control class.\n |
|
283 Sets the component control's container window to aContainer.\n |
|
284 Sets the parent control also to aContainer object.\n |
|
285 Sets the control's extent i.e; the dimensions to aRect.\n |
|
286 Sets the layout manager of the component to aLayoutMan object.\n |
|
287 Activate the control.\n |
|
288 */ |
|
289 void CTest5Control::ConstructL(CLayoutTest* aLayoutMan, |
|
290 CCoeControl& aContainer, const TRect& aRect) |
|
291 { |
|
292 SetContainerWindowL(aContainer); |
|
293 SetParent(&aContainer); |
|
294 SetRect(aRect); |
|
295 SetLayoutManagerL(aLayoutMan); |
|
296 ActivateL(); |
|
297 } |
|
298 /** |
|
299 Draws the CTest5Control object.\n |
|
300 Gets a pointer to the Windows Graphic context. |
|
301 Sets the pen colour,pen style and brush style settings.\n |
|
302 Draws the control using DrawRect function of the Graphics context.\n |
|
303 */ |
|
304 void CTest5Control::Draw(const TRect& /*aRect*/) const |
|
305 { |
|
306 CWindowGc& gc = SystemGc(); |
|
307 gc.SetPenColor(KRgbSymbianBlue); |
|
308 gc.SetPenStyle(CGraphicsContext::ESolidPen); |
|
309 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
310 gc.DrawRect(Rect()); |
|
311 } |
|
312 |
|
313 |
|
314 |
|
315 // |
|
316 // |
|
317 // CLayoutTestAppView |
|
318 // |
|
319 // |
|
320 /** |
|
321 Constructor for CLayoutTestAppView Class.\n |
|
322 */ |
|
323 CLayoutTestAppView::CLayoutTestAppView() |
|
324 { |
|
325 } |
|
326 /** |
|
327 Static entry function for CLayoutTestAppView class.\n |
|
328 Instantiates the CLayoutTestAppView object.\n |
|
329 Invokes the second phase constructor passing Layout manager as argument.\n |
|
330 */ |
|
331 CLayoutTestAppView* CLayoutTestAppView::NewL(CLayoutTest* aLayoutMan, |
|
332 const TRect& aRect) |
|
333 { |
|
334 CLayoutTestAppView* self = new(ELeave) CLayoutTestAppView(); |
|
335 CleanupStack::PushL(self); |
|
336 self->ConstructL(aLayoutMan, aRect); |
|
337 CleanupStack::Pop(); |
|
338 return self; |
|
339 } |
|
340 /** |
|
341 Destructor for CLayoutTestAppView class.\n |
|
342 Destroys the Control array.\n |
|
343 */ |
|
344 CLayoutTestAppView::~CLayoutTestAppView() |
|
345 { |
|
346 iCtrlArray.ResetAndDestroy(); |
|
347 iCtrlArray.Close(); |
|
348 } |
|
349 /** |
|
350 Second phase constructor for CLayoutTestAppView class.\n |
|
351 Creates a control's window. The created window is the child of the application's window group.\n |
|
352 Sets the view's extent i.e dimenstions.\n |
|
353 Instantiates Component controls each of CTest5Control class.\n |
|
354 Each component control is appended to a control array.\n |
|
355 The AppView object is added as the container control for all the component controls.\n |
|
356 The Appview is activated.\n |
|
357 */ |
|
358 void CLayoutTestAppView::ConstructL(CLayoutTest* aLayoutMan, const TRect& aRect) |
|
359 { |
|
360 CreateWindowL(); |
|
361 SetRect(aRect); |
|
362 TRect ctrlRect(10, 10, 20, 20); |
|
363 for (TInt ctrlCount = 0; ctrlCount < KNumControls; ctrlCount++) |
|
364 { |
|
365 CTest5Control* testCtrl = CTest5Control::NewL(aLayoutMan, *this, ctrlRect); |
|
366 iCtrlArray.Append(testCtrl); |
|
367 testCtrl->SetContainerWindowL(*this); |
|
368 TPoint offset(20, 0); |
|
369 ctrlRect.iTl += offset; |
|
370 ctrlRect.iBr += offset; |
|
371 } |
|
372 ActivateL(); |
|
373 TRect rect(TPoint(0,0), aRect.iBr - TPoint(1,1)); |
|
374 SetRect(rect); |
|
375 } |
|
376 /** |
|
377 Gets the component control's at the index (aIndex) in the Control array.\n |
|
378 */ |
|
379 CCoeControl* CLayoutTestAppView::ComponentControl(TInt aIndex) const |
|
380 { |
|
381 return iCtrlArray[aIndex]; |
|
382 } |
|
383 /** |
|
384 Gets the number of component controls contained by the App View .\n |
|
385 */ |
|
386 TInt CLayoutTestAppView::CountComponentControls() const |
|
387 { |
|
388 return iCtrlArray.Count(); |
|
389 } |
|
390 |
|
391 /** |
|
392 Function to Draw the App View .\n |
|
393 Gets a pointer to the Windows Graphic context. |
|
394 Sets the pen colour,pen style and brush style settings.\n |
|
395 Draws the control using DrawRect function of the Graphics context.\n |
|
396 */ |
|
397 void CLayoutTestAppView::Draw(const TRect& /*aRect*/) const |
|
398 { |
|
399 CWindowGc& gc = SystemGc(); |
|
400 gc.SetPenStyle(CGraphicsContext::ENullPen); |
|
401 gc.SetBrushStyle(CGraphicsContext::ESolidBrush); |
|
402 gc.DrawRect(Rect()); |
|
403 } |
|
404 |
|
405 /** |
|
406 Requests the relayout of the App View.\n |
|
407 Instantiates the layout manager.\n |
|
408 Invokes the PerformLayout function of Layout Manager.\n |
|
409 */ |
|
410 TBool CLayoutTestAppView::RequestRelayout(const CCoeControl* /* aChildControl */) |
|
411 { |
|
412 MCoeLayoutManager* layoutMan = LayoutManager(); |
|
413 layoutMan->PerformLayout(); |
|
414 return ETrue; |
|
415 } |
|
416 |
|
417 /** |
|
418 Returns the iCtrlArray member object.\n |
|
419 */ |
|
420 const RPointerArray<CTest5Control>& CLayoutTestAppView::CtrlArray() const |
|
421 { |
|
422 return iCtrlArray; |
|
423 } |
|
424 |
|
425 /** |
|
426 Destructor for CLayoutTest Class.\n |
|
427 Closes the control array (iCtrlArray) frees all memory allocated to it.\n |
|
428 */ |
|
429 CLayoutTest::~CLayoutTest() |
|
430 { |
|
431 iCtrlArray.Close(); |
|
432 } |
|
433 |
|
434 /** Determines if it is possible to attach another control to the layout manager. |
|
435 @return <code>ETrue</code> if possible, otherwise <code>EFalse</code> |
|
436 */ |
|
437 TBool CLayoutTest::CanAttach() const |
|
438 { |
|
439 return ETrue; |
|
440 } |
|
441 |
|
442 /** Attaches <code>aCompoundControl</code> to the layout manager. |
|
443 Is normally not called manually since <code>CCoeControl::SetLayoutManagerL()</code> |
|
444 calls this function. |
|
445 Once a compound control is attached to a layout manager, the layout manager owns itself. |
|
446 @see Detach |
|
447 @see CCoeControl::SetLayoutManagerL |
|
448 @param aCompoundControl The compound control. |
|
449 @leave KErrOverflow |
|
450 */ |
|
451 void CLayoutTest::AttachL(CCoeControl& aCompoundControl) |
|
452 { |
|
453 Open(); |
|
454 iCtrlArray.Append(&aCompoundControl); |
|
455 } |
|
456 |
|
457 |
|
458 /** Detaches <code>aCompoundControl</code> from the layout manager. |
|
459 Is normally not called manually since <code>CCoeControl::SetLayoutManagerL()</code> |
|
460 calls this function when you switch layout managers on a control. It is also called |
|
461 from <code>CCoeControl::~CCoeControl</code> |
|
462 When the last attached compound control detaches, the layout manager deletes itself. |
|
463 @see CCoeControl::SetLayoutManagerL |
|
464 @param aCompoundControl The compound control. |
|
465 */ |
|
466 void CLayoutTest::Detach(CCoeControl& aCompoundControl) |
|
467 { |
|
468 TInt index = iCtrlArray.Find(&aCompoundControl); |
|
469 if (index != KErrNotFound) |
|
470 { |
|
471 iCtrlArray.Remove(index); |
|
472 } |
|
473 Close(); |
|
474 } |
|
475 |
|
476 /** Calculates the minimum size of <code>aCompoundControl</code> |
|
477 Is normally not called manually since <code>CCoeControl::MinimumSize()</code> |
|
478 calls this function in the default implementation on controls with layout managers. |
|
479 |
|
480 To calculate the minimum size is almost as time consuming as performing an actual layout |
|
481 and should be used with caution. The minimum size depends on <code>aCompoundControl</code>'s |
|
482 maximum width. |
|
483 @see CCoeControl::MaximumWidth |
|
484 @param aCompoundControl The compound control |
|
485 @return The minimum size |
|
486 */ |
|
487 TSize CLayoutTest::CalcMinimumSize(const CCoeControl& /* aCompoundControl*/) const |
|
488 { |
|
489 |
|
490 TSize size = KMinSize; |
|
491 return size; |
|
492 } |
|
493 |
|
494 /** Performs the layout of the attached controls |
|
495 Is normally not called manually since <code>CCoeControl::SizeChanged()</code> |
|
496 calls this function in the default implementation on controls with layout managers. |
|
497 |
|
498 The layout is generally performed by calling the component controls' |
|
499 <code>SetMaximumWidth()</code>, followed by <code>MinimumSize()</code>, and then the |
|
500 layout manager tries to place the component controls according the their minimum |
|
501 sizes and the settings. |
|
502 |
|
503 If the layout manager is suspended it won't perform the actual layout until it |
|
504 gets activated. |
|
505 @see CCoeControl::SetMaximumWidth |
|
506 @see CCoeControl::MinimumSize |
|
507 @see SetSuspended |
|
508 */ |
|
509 |
|
510 void CLayoutTest::PerformLayout() |
|
511 { |
|
512 if (!iLayoutInProgress) |
|
513 { |
|
514 iLayoutsPerformed++; |
|
515 iLayoutInProgress = ETrue; |
|
516 iControlsCompleted = 0; |
|
517 // find the total rectangle we have to play with by finding the window owning control |
|
518 FindRectangle(); |
|
519 TInt curCtrlIndex = 0; |
|
520 while ((curCtrlIndex < iCtrlArray.Count()) && (curCtrlIndex != KErrTooBig)) |
|
521 { |
|
522 LayoutRow(curCtrlIndex); |
|
523 } |
|
524 // set all controls that haven't been layed out to invisible |
|
525 for ( ; iControlsCompleted < iCtrlArray.Count(); iControlsCompleted++) |
|
526 { |
|
527 // make sure we aren't setting the window owning control to invisible, else the |
|
528 // application will disappear |
|
529 if (!iCtrlArray[iControlsCompleted]->OwnsWindow()) |
|
530 { |
|
531 iCtrlArray[iControlsCompleted]->MakeVisible(EFalse); |
|
532 } |
|
533 } |
|
534 iCtrlArray[iWinOwningCtrlIndex]->DrawNow(); |
|
535 iLayoutInProgress = EFalse; |
|
536 } |
|
537 } |
|
538 |
|
539 /** |
|
540 @SYMPREQ PREQ527 |
|
541 Testing of function CalcTextBaselineOffset introduced by PREQ527 |
|
542 The switchover width, 1/4 and 3/4 values are purely arbitrary for |
|
543 the purpose of the test. |
|
544 @param CCoeControl& - reference to CCoeControl |
|
545 @param TSize& - rectangle size |
|
546 @return - The offset of the baseline to the top of the control |
|
547 */ |
|
548 |
|
549 TInt CLayoutTest::CalcTextBaselineOffset(const CCoeControl& /*aCompoundControl*/, const TSize& aSize) const |
|
550 { |
|
551 // Simulate a text control changing position dependent on the width of the |
|
552 // rect given. If the width is greater than a certain value, the text is |
|
553 // plced near the top of the rectangle, otherwise it's placed nearer the |
|
554 // bottom. |
|
555 const TInt KBaselineSwitchoverWidth = 200; |
|
556 |
|
557 TInt baseline = aSize.iHeight/4; // 1/4 of the way down. |
|
558 |
|
559 if (aSize.iWidth < KBaselineSwitchoverWidth) |
|
560 baseline *= 3; // 3/4 of the way down. |
|
561 |
|
562 return baseline; |
|
563 } |
|
564 |
|
565 /** |
|
566 @SYMPREQ PREQ527 |
|
567 Empty definition of SetTextBaselineSpacing introduced by PREQ527 |
|
568 @param TInt - the desired baseline spacing |
|
569 @return - none |
|
570 */ |
|
571 void CLayoutTest::SetTextBaselineSpacing(TInt /*aBaselineSpacing*/) |
|
572 { |
|
573 } |
|
574 |
|
575 TInt CLayoutTest::TextBaselineSpacing() const |
|
576 { |
|
577 return 0; |
|
578 } |
|
579 |
|
580 void CLayoutTest::HandleAddedControlL(const CCoeControl& /*aCompoundControl*/, const CCoeControl& /*aAddedControl*/) |
|
581 { |
|
582 } |
|
583 |
|
584 void CLayoutTest::HandleRemovedControl(const CCoeControl& /*aCompoundControl*/, const CCoeControl& /*aRemovedControl*/) |
|
585 { |
|
586 } |
|
587 |
|
588 TInt CLayoutTest::HandleControlReplaced(const CCoeControl& /*aOldControl*/, const CCoeControl& /*aNewControl*/) |
|
589 { |
|
590 return KErrNone; |
|
591 } |
|
592 |
|
593 void CLayoutTest::LayoutRow(TInt& aCurCtrlIndex) |
|
594 { |
|
595 iSizeUsed.iWidth = 0; |
|
596 TUint maxHeightOfRow = 0; |
|
597 // while theres space for another control |
|
598 while (SpaceForControl(maxHeightOfRow) && (aCurCtrlIndex < iCtrlArray.Count())) |
|
599 { |
|
600 if (aCurCtrlIndex == iWinOwningCtrlIndex) |
|
601 { |
|
602 aCurCtrlIndex++; |
|
603 iControlsCompleted++; |
|
604 continue; |
|
605 } |
|
606 TSize ctrlSize = iCtrlArray[aCurCtrlIndex]->Size(); |
|
607 // if we can layout the control, do it and move to the next one |
|
608 if (LayoutControl(aCurCtrlIndex, ctrlSize) != KErrNone) |
|
609 { |
|
610 break; |
|
611 } |
|
612 aCurCtrlIndex++; |
|
613 // check the max height of the current row, if this is more than the height left |
|
614 // return an error |
|
615 if (maxHeightOfRow < ctrlSize.iHeight) |
|
616 { |
|
617 maxHeightOfRow = ctrlSize.iHeight; |
|
618 } |
|
619 iSizeUsed.iWidth += (ctrlSize.iWidth + KHorizontalBorder); |
|
620 } |
|
621 iSizeUsed.iHeight += (maxHeightOfRow + KVerticalBorder); |
|
622 if (iSizeUsed.iHeight > iLayoutRect.Height()) |
|
623 { |
|
624 aCurCtrlIndex = KErrTooBig; |
|
625 } |
|
626 } |
|
627 |
|
628 /** |
|
629 Auxilliary Function performing the layout for a control.\n |
|
630 Checks if the used up width and height are less that than the available width and height respectively.\n |
|
631 If yes, initializes the top left and bottom right coordinates of the control |
|
632 and assigns the same to the control's extent.\n |
|
633 |
|
634 @return KErrNone if successful else KErrTooBig |
|
635 */ |
|
636 TInt CLayoutTest::LayoutControl(TUint aCurCtrlIndex, TSize aCtrlSize) |
|
637 { |
|
638 TInt layoutSuccess = KErrNone; |
|
639 // check that we haven't used all the space left on the screen |
|
640 if (((iSizeUsed.iWidth + aCtrlSize.iWidth + KHorizontalBorder) <= iLayoutRect.Width()) && |
|
641 ((iSizeUsed.iHeight + aCtrlSize.iHeight + KVerticalBorder) <= iLayoutRect.Height())) |
|
642 { |
|
643 TPoint topLeft(iSizeUsed.iWidth + KHorizontalBorder, iSizeUsed.iHeight + KVerticalBorder); |
|
644 TPoint bottomRight(iSizeUsed.iWidth + aCtrlSize.iWidth + KHorizontalBorder, |
|
645 iSizeUsed.iHeight + aCtrlSize.iHeight + KVerticalBorder); |
|
646 TRect ctrlRect(topLeft, bottomRight); |
|
647 CCoeControl* ctrl = iCtrlArray[aCurCtrlIndex]; |
|
648 ctrl->SetRect(ctrlRect); |
|
649 iControlsCompleted++; |
|
650 } |
|
651 else |
|
652 { |
|
653 layoutSuccess = KErrTooBig; |
|
654 } |
|
655 return layoutSuccess; |
|
656 } |
|
657 |
|
658 |
|
659 /** |
|
660 Checks whether there is any space for the component control on the container.\n |
|
661 Calculates the already used width and height are less than that allocated for the layout rectangle.\n |
|
662 |
|
663 @return Boolean,True if there is any space available.\n |
|
664 */ |
|
665 TBool CLayoutTest::SpaceForControl(TUint aMaxHeight) |
|
666 { |
|
667 if (((iSizeUsed.iWidth + KHorizontalBorder) < iLayoutRect.Width()) || |
|
668 ((iSizeUsed.iHeight + aMaxHeight + KVerticalBorder) < iLayoutRect.Height())) |
|
669 { |
|
670 return ETrue; |
|
671 } |
|
672 return EFalse; |
|
673 } |
|
674 /** |
|
675 Finds the rectange belonging to the window owning control.\n |
|
676 Iterates through the control array and finds the window owning control.\n |
|
677 Initializes the iLayoutRect member with the window owning control's extent.\n |
|
678 */ |
|
679 void CLayoutTest::FindRectangle() |
|
680 { |
|
681 for (TInt index = 0; index < iCtrlArray.Count(); index++) |
|
682 { |
|
683 if (iCtrlArray[index]->OwnsWindow()) |
|
684 { |
|
685 iWinOwningCtrlIndex = index; |
|
686 iLayoutRect = iCtrlArray[iWinOwningCtrlIndex]->Rect(); |
|
687 break; |
|
688 } |
|
689 } |
|
690 } |
|
691 |
|
692 /** |
|
693 @return Returns the number of layouts performed by the Layout Manager.\n |
|
694 |
|
695 The number of layouts performed is stored in iLayoutsPerformed member variable of CLayoutTest object.\n |
|
696 */ |
|
697 TUint CLayoutTest::LayoutsPerformed() const |
|
698 { |
|
699 return iLayoutsPerformed; |
|
700 } |