|
1 /* |
|
2 * Copyright (c) 2005 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 the License "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 * Implementation of CBrowserWindowSelectionContainer. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include "BrowserWindowSelectionContainer.h" |
|
24 #include "BrowserWindowSelectionView.h" |
|
25 #include "BrowserAppUi.h" |
|
26 #include "Display.h" |
|
27 #include "WindowInfoProvider.h" |
|
28 #include "BrowserWindowManager.h" |
|
29 #include "BrowserWindow.h" |
|
30 #include <BrowserNG.rsg> |
|
31 #include <aknnavi.h> |
|
32 #include <akntabgrp.h> |
|
33 #include <aknnavide.h> |
|
34 #include <akntabgrp.h> |
|
35 #include <eikimage.h> |
|
36 #include <barsread.h> |
|
37 #include <BrCtlDefs.h> |
|
38 #include <BrCtlInterface.h> |
|
39 #include <BrCtlDefs.h> |
|
40 #include <browser.mbg> |
|
41 #include <gulicon.h> |
|
42 |
|
43 |
|
44 // --------------------------------------------------------- |
|
45 // CBrowserWindowSelectionContainer::ConstructL |
|
46 // --------------------------------------------------------- |
|
47 // |
|
48 void CBrowserWindowSelectionContainer::ConstructL(const TRect& aRect) |
|
49 { |
|
50 CreateWindowL(); |
|
51 // Tabgroup has been read from resource and it were pushed to the navi pane. |
|
52 // Get pointer to the navigation decorator with the ResourceDecorator() function. |
|
53 // Application owns the decorator and it has responsibility to delete the object. |
|
54 iNaviDecorator = iView->ApiProvider().Display().NaviPaneL()->CreateTabGroupL(); |
|
55 iTabGroup = (CAknTabGroup*)iNaviDecorator->DecoratedControl(); |
|
56 iTabGroup->SetObserver(this); |
|
57 |
|
58 /* |
|
59 // Create tab icon |
|
60 iTabIcon = new (ELeave) CEikImage; |
|
61 TResourceReader rr; |
|
62 iCoeEnv->CreateResourceReaderLC( rr, R_BROWSER_ICON_PROP_FOLDER ); |
|
63 iTabIcon->ConstructFromResourceL( rr ); |
|
64 CleanupStack::PopAndDestroy(); // rr |
|
65 */ |
|
66 |
|
67 SetRect(aRect); |
|
68 ActivateL(); |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CBrowserWindowSelectionContainer::CBrowserWindowSelectionContainer |
|
73 // --------------------------------------------------------- |
|
74 // |
|
75 CBrowserWindowSelectionContainer::CBrowserWindowSelectionContainer( CBrowserWindowSelectionView *aView ) : iView( aView ) |
|
76 { |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CBrowserWindowSelectionContainer::~CBrowserWindowSelectionContainer |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 CBrowserWindowSelectionContainer::~CBrowserWindowSelectionContainer() |
|
84 { |
|
85 delete iNaviDecorator; |
|
86 delete iThumbnail; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------- |
|
90 // CBrowserWindowSelectionContainer::ChangeTabL |
|
91 // --------------------------------------------------------- |
|
92 // |
|
93 void CBrowserWindowSelectionContainer::ChangeTabL( CArrayFixFlat<HBufC*>* aTabTexts, TInt aActivateTab ) |
|
94 { |
|
95 // If there are any tabs |
|
96 if ( iTabGroup->TabCount() ) |
|
97 { |
|
98 TInt tabCount = iTabGroup->TabCount(); |
|
99 // Delete all tabs |
|
100 for ( TInt tabIndex = 0; tabIndex < tabCount; tabIndex++ ) |
|
101 { |
|
102 // Delete the first tab until there is no more tab... |
|
103 iTabGroup->DeleteTabL( iTabGroup->TabIdFromIndex( 0 ) ); |
|
104 } |
|
105 } |
|
106 // If only two tabs are needed, dont show more tabs. |
|
107 if ( aTabTexts->Count() == 2 ) |
|
108 { |
|
109 GetTabGroup()->SetTabFixedWidthL( EAknTabWidthWithTwoLongTabs ); |
|
110 } |
|
111 // If more than two tabs are needed, maximum 3 tabs are visible |
|
112 else |
|
113 { |
|
114 GetTabGroup()->SetTabFixedWidthL( EAknTabWidthWithThreeLongTabs ); |
|
115 } |
|
116 // Add create the tabs |
|
117 for ( TInt tabIndex = 0; tabIndex < aTabTexts->Count(); tabIndex++ ) |
|
118 { |
|
119 iTabGroup->AddTabL( tabIndex, (*aTabTexts)[tabIndex]->Des() /*, iTabIcon->Bitmap(), iTabIcon->Mask()*/ ); |
|
120 } |
|
121 // Set focus of the specified tab |
|
122 iTabGroup->SetActiveTabByIndex( aActivateTab ); |
|
123 // Handle tab changes. |
|
124 iView->ApiProvider().Display().NaviPaneL()->PushL( *iNaviDecorator ); |
|
125 |
|
126 // Draw the thumbnail by the window id. |
|
127 GetWindowThumbnailL( iView->GetWindowIdFromTabIndex( GetTabGroup()->ActiveTabIndex() ) ); |
|
128 DrawNow(); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CBrowserWindowSelectionContainer::SizeChanged |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CBrowserWindowSelectionContainer::SizeChanged() |
|
136 { |
|
137 // TODO: Add here control resize code etc. |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------- |
|
141 // CBrowserWindowSelectionContainer::CountComponentControls |
|
142 // --------------------------------------------------------- |
|
143 // |
|
144 TInt CBrowserWindowSelectionContainer::CountComponentControls() const |
|
145 { |
|
146 return 0; // return nbr of controls inside this container |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------- |
|
150 // CBrowserWindowSelectionContainer::ComponentControl |
|
151 // --------------------------------------------------------- |
|
152 // |
|
153 CCoeControl* CBrowserWindowSelectionContainer::ComponentControl(TInt aIndex) const |
|
154 { |
|
155 switch ( aIndex ) |
|
156 { |
|
157 default: |
|
158 return NULL; |
|
159 } |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------- |
|
163 // CBrowserWindowSelectionContainer::Draw |
|
164 // --------------------------------------------------------- |
|
165 // |
|
166 void CBrowserWindowSelectionContainer::Draw(const TRect& aRect) const |
|
167 { |
|
168 CWindowGc& gc = SystemGc(); |
|
169 |
|
170 // example code... |
|
171 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
172 gc.SetBrushColor( KRgbWhite ); |
|
173 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
174 gc.DrawRect( aRect ); |
|
175 |
|
176 if ( iThumbnail ) |
|
177 { |
|
178 // Put in center |
|
179 // release |
|
180 TSize bitmapSize = iThumbnail->Bitmap()->SizeInPixels(); |
|
181 // test |
|
182 //TSize bitmapSize = iThumbnail->SizeInPixels(); |
|
183 TInt x = ( aRect.Width()-bitmapSize.iWidth ) / 2; |
|
184 TInt y = ( aRect.Height()-bitmapSize.iHeight ) / 2; |
|
185 // Draw thumbnail |
|
186 // release |
|
187 gc.BitBlt( TPoint(x,y), iThumbnail->Bitmap() ); |
|
188 // test |
|
189 // gc.BitBlt( TPoint(x,y), iThumbnail ); |
|
190 } |
|
191 } |
|
192 |
|
193 // --------------------------------------------------------- |
|
194 // CBrowserWindowSelectionContainer::OfferKeyEventL |
|
195 // --------------------------------------------------------- |
|
196 // |
|
197 TKeyResponse CBrowserWindowSelectionContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
198 { |
|
199 // Handle if Ok key was pressed. |
|
200 if ( aType == EEventKey && aKeyEvent.iCode == EKeyOK ) |
|
201 { |
|
202 TInt windowId = iView->GetWindowIdFromTabIndex( GetTabGroup()->ActiveTabIndex() ); |
|
203 iView->ApiProvider().WindowMgr().SwitchWindowL( windowId ); |
|
204 //If the user switches window we reset the CalledFromAnotherApp status |
|
205 if(iView->ApiProvider().CalledFromAnotherApp()) |
|
206 { |
|
207 iView->ApiProvider().SetCalledFromAnotherApp(EFalse); |
|
208 } |
|
209 iView->ApiProvider().SetViewToBeActivatedIfNeededL( iView->GetPreviousViewID() ); |
|
210 return EKeyWasConsumed; |
|
211 } |
|
212 |
|
213 // Check if navipane has valid parameters. |
|
214 if ( !iTabGroup ) |
|
215 { |
|
216 return EKeyWasNotConsumed; |
|
217 } |
|
218 if ( !iTabGroup->TabCount() ) |
|
219 { |
|
220 return EKeyWasNotConsumed; |
|
221 } |
|
222 if ( !iNaviDecorator ) |
|
223 { |
|
224 return EKeyWasNotConsumed; |
|
225 } |
|
226 // Get tab group |
|
227 CAknTabGroup* tabGroup = STATIC_CAST( CAknTabGroup*, iNaviDecorator->DecoratedControl() ); |
|
228 // If tab group was not created succesfully. |
|
229 if ( !tabGroup ) |
|
230 { |
|
231 return EKeyWasNotConsumed; |
|
232 } |
|
233 // If tab group has no tabs. |
|
234 if ( !tabGroup->TabCount() ) |
|
235 { |
|
236 return EKeyWasNotConsumed; |
|
237 } |
|
238 // Forward events to tabgroup. |
|
239 const TKeyResponse result = tabGroup->OfferKeyEventL( aKeyEvent, aType ); |
|
240 |
|
241 return result; |
|
242 } |
|
243 |
|
244 // --------------------------------------------------------- |
|
245 // CBrowserWindowSelectionContainer::HandleControlEventL |
|
246 // --------------------------------------------------------- |
|
247 // |
|
248 void CBrowserWindowSelectionContainer::HandleControlEventL( |
|
249 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/) |
|
250 { |
|
251 // TODO: Add your control event handler code here |
|
252 } |
|
253 |
|
254 // --------------------------------------------------------- |
|
255 // CBrowserWindowSelectionContainer::GetWindowThumbnail |
|
256 // --------------------------------------------------------- |
|
257 // |
|
258 void CBrowserWindowSelectionContainer::GetWindowThumbnailL( TInt aWindowId ) |
|
259 { |
|
260 // Get window url |
|
261 CBrowserWindow* window; |
|
262 iView->ApiProvider().WindowMgr().Window( aWindowId, window ); |
|
263 HBufC* windowUrl = window->BrCtlInterface().PageInfoLC( TBrCtlDefs::EPageInfoUrl ); |
|
264 |
|
265 // Get thumbnail |
|
266 // release |
|
267 delete iThumbnail; |
|
268 if (windowUrl) |
|
269 { |
|
270 iThumbnail = window->BrCtlInterface().GetBitmapData( windowUrl->Des(), TBrCtlDefs::EBitmapThumbnail ); |
|
271 } |
|
272 else |
|
273 { |
|
274 iThumbnail = NULL; |
|
275 } |
|
276 // eof release |
|
277 |
|
278 |
|
279 CleanupStack::PopAndDestroy(); // windowUrl |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CBrowserWindowSelectionContainer::HandlePointerEventL |
|
284 // --------------------------------------------------------- |
|
285 // |
|
286 void CBrowserWindowSelectionContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
287 { |
|
288 if (aPointerEvent.iType == TPointerEvent::EButton1Down) |
|
289 { |
|
290 iView->HandleCommandL(EAknCmdOpen); |
|
291 } |
|
292 } |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // CBrowserWindowSelectionContainer::TabChangedL |
|
296 // --------------------------------------------------------- |
|
297 // |
|
298 void CBrowserWindowSelectionContainer::TabChangedL(TInt /*aIndex*/) |
|
299 { |
|
300 iView->UpdateTitleL(); |
|
301 iView->UpdateTumbnailL(); |
|
302 } |
|
303 |
|
304 // End of File |