66
|
1 |
/*******************************************************************************
|
|
2 |
* Copyright (c) 2007, 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved. This program and the accompanying materials
|
|
4 |
* are made available under the terms of the Eclipse Public License v1.0
|
|
5 |
* which accompanies this distribution, and is available at
|
|
6 |
* http://www.eclipse.org/legal/epl-v10.html
|
|
7 |
*
|
|
8 |
* Contributors:
|
|
9 |
* Nokia Corporation - S60 implementation
|
|
10 |
*******************************************************************************/
|
|
11 |
|
|
12 |
|
|
13 |
#include <akntabgrp.h>
|
|
14 |
#include <aknnavi.h>
|
|
15 |
#include <aknnavide.h>
|
|
16 |
#include <eikappui.h>
|
|
17 |
#include <aknappui.h>
|
|
18 |
#include <AknsControlContext.h>
|
|
19 |
#include <swtlaffacade.h>
|
|
20 |
#include "swtcontrolhelper.h"
|
|
21 |
#include "swtmultipagedialog.h"
|
|
22 |
|
|
23 |
|
|
24 |
// ======== MEMBER FUNCTIONS ========
|
|
25 |
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Destructor
|
|
29 |
*/
|
|
30 |
CSwtMultiPageDialog::~CSwtMultiPageDialog()
|
|
31 |
{
|
|
32 |
Close();
|
|
33 |
iTabItems.Reset();
|
|
34 |
iTabItems.Close();
|
|
35 |
delete iNaviDecorator;
|
|
36 |
delete iRedirector;
|
|
37 |
}
|
|
38 |
|
|
39 |
/**
|
|
40 |
* 1st and 2nd phase constructor wrapper.
|
|
41 |
*/
|
|
42 |
CSwtMultiPageDialog* CSwtMultiPageDialog::NewL(MSwtDisplay& aDisplay,
|
|
43 |
TSwtPeer aPeer, MSwtShell& aParent)
|
|
44 |
{
|
|
45 |
CSwtMultiPageDialog * self = new(ELeave) CSwtMultiPageDialog(
|
|
46 |
aDisplay, aPeer, aParent);
|
|
47 |
CleanupStack::PushL(self);
|
|
48 |
|
|
49 |
self->ConstructL();
|
|
50 |
self->InitControlBaseL();
|
|
51 |
|
|
52 |
CleanupStack::Pop(self);
|
|
53 |
return self;
|
|
54 |
}
|
|
55 |
|
|
56 |
/**
|
|
57 |
* 1st phase constructor.
|
|
58 |
*/
|
|
59 |
CSwtMultiPageDialog::CSwtMultiPageDialog(MSwtDisplay& aDisplay,
|
|
60 |
TSwtPeer aPeer, MSwtShell& aParent)
|
|
61 |
: ASwtControlBase(aDisplay, aPeer, aParent.Composite(), KSwtNone)
|
|
62 |
, iVisibleTab(-1)
|
|
63 |
, iTitleCount(0)
|
|
64 |
{}
|
|
65 |
|
|
66 |
/**
|
|
67 |
* 2nd phase constructor.
|
|
68 |
*/
|
|
69 |
void CSwtMultiPageDialog::ConstructL()
|
|
70 |
{
|
|
71 |
// We create the TabGroup here
|
|
72 |
CEikStatusPane * sp = ((CAknAppUi*) iEikonEnv->EikAppUi()) ->StatusPane();
|
|
73 |
ASSERT(sp);
|
|
74 |
iNaviCtrlCtnr = static_cast<CAknNavigationControlContainer *>(
|
|
75 |
sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi)));
|
|
76 |
ASSERT(iNaviCtrlCtnr);
|
|
77 |
iNaviDecorator = iNaviCtrlCtnr->CreateTabGroupL();
|
|
78 |
ASSERT(iNaviDecorator);
|
|
79 |
iTabGroup = static_cast<CAknTabGroup*>(iNaviDecorator->DecoratedControl());
|
|
80 |
ASSERT(iTabGroup);
|
|
81 |
iTabGroup->SetObserver(this);
|
|
82 |
|
|
83 |
// create edit redirection flag
|
|
84 |
iRedirector = new(ELeave) CSwtEditIndicatorRedictor();
|
|
85 |
// We initialize the control that will receive the events
|
|
86 |
CCoeControl& coeParent = GetParent() ->Control() ->CoeControl();
|
|
87 |
SetContainerWindowL(coeParent);
|
|
88 |
|
|
89 |
CCoeControl::MakeVisible(coeParent.IsVisible());
|
|
90 |
CCoeControl::SetDimmed(coeParent.IsDimmed());
|
|
91 |
CCoeControl::SetFocusing(EFalse);
|
|
92 |
SetComponentsToInheritVisibility(ETrue);
|
|
93 |
ActivateL();
|
|
94 |
}
|
|
95 |
|
|
96 |
/**
|
|
97 |
* Calcuates the size of the tabs
|
|
98 |
*/
|
|
99 |
void CSwtMultiPageDialog::SizeChanged()
|
|
100 |
{
|
|
101 |
HandleSizeChanged();
|
|
102 |
}
|
|
103 |
|
|
104 |
|
|
105 |
//
|
|
106 |
// Virtual methods from MSwtControl
|
|
107 |
//
|
|
108 |
TRect CSwtMultiPageDialog::ClientRect() const
|
|
109 |
{
|
|
110 |
return Rect();
|
|
111 |
}
|
|
112 |
|
|
113 |
CCoeControl& CSwtMultiPageDialog::CoeControl()
|
|
114 |
{
|
|
115 |
return *this;
|
|
116 |
}
|
|
117 |
|
|
118 |
const CCoeControl& CSwtMultiPageDialog::CoeControl() const
|
|
119 |
{
|
|
120 |
return *this;
|
|
121 |
}
|
|
122 |
|
|
123 |
TSize CSwtMultiPageDialog::ComputeSizeL(TInt /*aWHint*/, TInt /*aHHint*/)
|
|
124 |
{
|
|
125 |
return MinimumSize();
|
|
126 |
}
|
|
127 |
|
|
128 |
TInt CSwtMultiPageDialog::GetBorderWidth() const
|
|
129 |
{
|
|
130 |
return 0;
|
|
131 |
}
|
|
132 |
|
|
133 |
|
|
134 |
void CSwtMultiPageDialog::ProcessKeyEventL(const TKeyEvent& /*aKeyEvent*/,
|
|
135 |
TEventCode /*aType*/)
|
|
136 |
{}
|
|
137 |
|
|
138 |
TTypeUid::Ptr CSwtMultiPageDialog::MopSupplyObject(TTypeUid aId)
|
|
139 |
{
|
|
140 |
if (iRedirector && aId.iUid == CSwtEditIndicatorRedictor::ETypeId)
|
|
141 |
{
|
|
142 |
return aId.MakePtr(iRedirector);
|
|
143 |
}
|
|
144 |
|
|
145 |
if (aId.iUid == MAknsControlContext::ETypeId)
|
|
146 |
{
|
|
147 |
return MAknsControlContext::SupplyMopObject(aId,
|
|
148 |
GetParent()->Control()->GetControlContext());
|
|
149 |
}
|
|
150 |
|
|
151 |
return CCoeControl::MopSupplyObject(aId);
|
|
152 |
}
|
|
153 |
|
|
154 |
//
|
|
155 |
// Virtual methods from MSwtMultiPageDialog
|
|
156 |
//
|
|
157 |
|
|
158 |
MSwtControl* CSwtMultiPageDialog::Control()
|
|
159 |
{
|
|
160 |
return this;
|
|
161 |
}
|
|
162 |
|
|
163 |
void CSwtMultiPageDialog::Close()
|
|
164 |
{
|
|
165 |
ASSERT(iNaviCtrlCtnr);
|
|
166 |
if (iIsOpen)
|
|
167 |
{
|
|
168 |
iIsOpen = EFalse;
|
|
169 |
iNaviCtrlCtnr->Pop();
|
|
170 |
((CAknAppUi*) iEikonEnv->EikAppUi()) ->StatusPane() ->DrawNow();
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
void CSwtMultiPageDialog::CreatePageL(MSwtComposite* aComposite,
|
|
175 |
const TDesC& aTitle, MSwtImage* aImage)
|
|
176 |
{
|
|
177 |
ASSERT(aComposite);
|
|
178 |
|
|
179 |
//Lets change the MOP Parent so that we can serve children with objects
|
|
180 |
aComposite->Control()->CoeControl().SetMopParent(this);
|
|
181 |
aComposite->Control()->CoeControl().MakeVisible(EFalse);
|
|
182 |
|
|
183 |
TInt newId = 0;
|
|
184 |
if (iTabItems.Count() > 0)
|
|
185 |
{
|
|
186 |
newId = iTabItems[ iTabItems.Count() - 1 ].iTabId + 1;
|
|
187 |
}
|
|
188 |
|
|
189 |
if (aImage)
|
|
190 |
{
|
|
191 |
TAknLayoutText lrect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::ETabs4ActivePaneT1, iTabGroup->Rect());
|
|
192 |
TSize size = SwtControlHelper::GetAspectRatioScaledBitmapSize(aImage->GetBounds().Size(), lrect.TextRect().Size());
|
|
193 |
CFbsBitmap* bmp = SwtControlHelper::GetCopyOfBitmapLC(&aImage->Bitmap(), size);
|
|
194 |
CFbsBitmap* mask = NULL;
|
|
195 |
iTabGroup->AddTabL(newId, bmp , mask);// Bitmap ownership transfered
|
|
196 |
iTabGroup->SetTabMultiColorMode(newId, ETrue);
|
|
197 |
CleanupStack::Pop(bmp);
|
|
198 |
}
|
|
199 |
else
|
|
200 |
{
|
|
201 |
iTabGroup->AddTabL(newId, aTitle);
|
|
202 |
}
|
|
203 |
|
|
204 |
iTitleCount++;
|
|
205 |
|
|
206 |
TTabItem tabItem;
|
|
207 |
tabItem.iComposite = aComposite;
|
|
208 |
tabItem.iTabId = newId;
|
|
209 |
tabItem.iHasTitle = aTitle.Length() > 0 ? ETrue : EFalse;
|
|
210 |
iTabItems.AppendL(tabItem);
|
|
211 |
|
|
212 |
iTabGroup->SetTabFixedWidthL(ComputeTabStyle());
|
|
213 |
RefreshStatusPane();
|
|
214 |
}
|
|
215 |
|
|
216 |
void CSwtMultiPageDialog::DeletePageL(TInt aIndex)
|
|
217 |
{
|
|
218 |
ASSERT(aIndex > -1);
|
|
219 |
ASSERT(aIndex < iTabItems.Count());
|
|
220 |
iTabGroup->DeleteTabL(iTabItems[aIndex].iTabId);
|
|
221 |
if (iTabItems[aIndex].iHasTitle)
|
|
222 |
{
|
|
223 |
iTitleCount--;
|
|
224 |
}
|
|
225 |
iTabItems.Remove(aIndex);
|
|
226 |
iTabGroup->SetTabFixedWidthL(ComputeTabStyle());
|
|
227 |
RefreshStatusPane();
|
|
228 |
// in case the ActivePage has changed
|
|
229 |
if (aIndex == iVisibleTab)
|
|
230 |
{
|
|
231 |
iVisibleTab = -1;
|
|
232 |
if (iTabItems.Count() > 0)
|
|
233 |
{
|
|
234 |
ShowTab(iTabGroup->ActiveTabIndex());
|
|
235 |
}
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
TInt CSwtMultiPageDialog::GetSelectedIndex()
|
|
240 |
{
|
|
241 |
return iTabGroup->ActiveTabIndex();
|
|
242 |
}
|
|
243 |
|
|
244 |
void CSwtMultiPageDialog::OpenL()
|
|
245 |
{
|
|
246 |
ASSERT(iNaviCtrlCtnr);
|
|
247 |
if (!iIsOpen)
|
|
248 |
{
|
|
249 |
iNaviCtrlCtnr->PushL(*iNaviDecorator);
|
|
250 |
iIsOpen = ETrue;
|
|
251 |
if (iVisibleTab == -1 && iTabItems.Count() > 0)
|
|
252 |
{
|
|
253 |
SetSelection(0);
|
|
254 |
}
|
|
255 |
RefreshStatusPane();
|
|
256 |
}
|
|
257 |
}
|
|
258 |
|
|
259 |
void CSwtMultiPageDialog::SetSelection(TInt aIndex)
|
|
260 |
{
|
|
261 |
ShowTab(aIndex);
|
|
262 |
iTabGroup->SetActiveTabByIndex(aIndex);
|
|
263 |
}
|
|
264 |
|
|
265 |
void CSwtMultiPageDialog::SetTitleAndImageL(TInt aIndex, const TDesC& aText, MSwtImage* aImage)
|
|
266 |
{
|
|
267 |
ASSERT(aIndex > -1);
|
|
268 |
ASSERT(aIndex < iTabItems.Count());
|
|
269 |
|
|
270 |
CFbsBitmap* bmp = NULL;
|
|
271 |
CFbsBitmap* mask = NULL;
|
|
272 |
if (aImage)
|
|
273 |
{
|
|
274 |
TAknLayoutText lrect = CSwtLafFacade::GetLayoutText(CSwtLafFacade::ETabs4ActivePaneT1, iTabGroup->Rect());
|
|
275 |
TSize size = SwtControlHelper::GetAspectRatioScaledBitmapSize(aImage->GetBounds().Size(), lrect.TextRect().Size());
|
|
276 |
bmp = SwtControlHelper::GetCopyOfBitmapLC(&aImage->Bitmap(), size);
|
|
277 |
}
|
|
278 |
iTabGroup->ReplaceTabL(iTabGroup->TabIdFromIndex(aIndex), aText, bmp, mask); // Bitmap ownership transfered
|
|
279 |
if (bmp)
|
|
280 |
{
|
|
281 |
CleanupStack::Pop(bmp);
|
|
282 |
}
|
|
283 |
|
|
284 |
if (aText.Length() > 0 && !iTabItems[ aIndex ].iHasTitle)
|
|
285 |
{
|
|
286 |
iTabItems[ aIndex ].iHasTitle = ETrue;
|
|
287 |
iTitleCount++;
|
|
288 |
iTabGroup->SetTabFixedWidthL(ComputeTabStyle());
|
|
289 |
}
|
|
290 |
else if (aText.Length() < 0 && iTabItems[ aIndex ].iHasTitle)
|
|
291 |
{
|
|
292 |
iTabItems[ aIndex ].iHasTitle = EFalse;
|
|
293 |
iTitleCount--;
|
|
294 |
iTabGroup->SetTabFixedWidthL(ComputeTabStyle());
|
|
295 |
}
|
|
296 |
|
|
297 |
RefreshStatusPane();
|
|
298 |
}
|
|
299 |
|
|
300 |
void CSwtMultiPageDialog::SetTitleL(TInt aIndex, const TDesC& aText)
|
|
301 |
{
|
|
302 |
ASSERT(aIndex > -1);
|
|
303 |
ASSERT(aIndex < iTabItems.Count());
|
|
304 |
|
|
305 |
iTabGroup->ReplaceTabTextL(aIndex, aText);
|
|
306 |
if (!iTabItems[ aIndex ].iHasTitle)
|
|
307 |
{
|
|
308 |
iTabItems[ aIndex ].iHasTitle = ETrue;
|
|
309 |
iTitleCount++;
|
|
310 |
iTabGroup->SetTabFixedWidthL(ComputeTabStyle());
|
|
311 |
RefreshStatusPane();
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
//
|
|
317 |
// From MAknTabObserver
|
|
318 |
//
|
|
319 |
void CSwtMultiPageDialog::TabChangedL(TInt aIndex)
|
|
320 |
{
|
|
321 |
ShowTab(aIndex);
|
|
322 |
iDisplay.PostSelectionEventL(iPeer);
|
|
323 |
}
|
|
324 |
|
|
325 |
|
|
326 |
//
|
|
327 |
// New methods
|
|
328 |
//
|
|
329 |
void CSwtMultiPageDialog::ShowTab(TInt aIndex)
|
|
330 |
{
|
|
331 |
ASSERT(aIndex > -1);
|
|
332 |
ASSERT(aIndex < iTabItems.Count());
|
|
333 |
|
|
334 |
if (aIndex == iVisibleTab) return;
|
|
335 |
if (iVisibleTab >= 0 && iTabItems[ iVisibleTab ].iComposite)
|
|
336 |
{
|
|
337 |
iTabItems [iVisibleTab ].iComposite->Control() ->SetVisible(EFalse);
|
|
338 |
}
|
|
339 |
|
|
340 |
if (iTabItems[ aIndex ].iComposite)
|
|
341 |
{
|
|
342 |
iTabItems[ aIndex ].iComposite->Control() ->SetVisible(ETrue);
|
|
343 |
}
|
|
344 |
iVisibleTab = aIndex;
|
|
345 |
}
|
|
346 |
|
|
347 |
void CSwtMultiPageDialog::RefreshStatusPane() const
|
|
348 |
{
|
|
349 |
if (iIsOpen)
|
|
350 |
{
|
|
351 |
((CAknAppUi*) iEikonEnv->EikAppUi())->StatusPane()->DrawNow();
|
|
352 |
}
|
|
353 |
}
|
|
354 |
|
|
355 |
TInt CSwtMultiPageDialog::ComputeTabStyle() const
|
|
356 |
{
|
|
357 |
switch (iTabItems.Count())
|
|
358 |
{
|
|
359 |
case 1:
|
|
360 |
return KTabWidthWithOneTab;
|
|
361 |
case 2:
|
|
362 |
return KTabWidthWithTwoTabs;
|
|
363 |
case 3:
|
|
364 |
return KTabWidthWithThreeTabs;
|
|
365 |
default:
|
|
366 |
return KTabWidthWithFourTabs;
|
|
367 |
}
|
|
368 |
}
|
|
369 |
|