|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : WebClientContainer.cpp 00004 * Part of : WebClient 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2005-2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <coemain.h> 00018 #include <eikenv.h> 00019 #include <txtrich.h> 00020 #include <eiklabel.h> 00021 #include <WebClient.rsg> 00022 #include "WebClient.pan" 00023 #include "WebClientContainer.h" 00024 #include "WebClientAppUi.h" 00025 #include "WebClientEngine.h" 00026 #include "WebClient.hrh" 00027 00028 // ---------------------------------------------------------------------------- 00029 // CWebClientContainer::NewL() 00030 // Creates instance of CWebClientContainer. 00031 // ---------------------------------------------------------------------------- 00032 CWebClientContainer* CWebClientContainer::NewL( const TRect& aRect ) 00033 { 00034 CWebClientContainer* self = CWebClientContainer::NewLC( aRect ); 00035 CleanupStack::Pop( self ); 00036 return self; 00037 } 00038 00039 // ---------------------------------------------------------------------------- 00040 // CWebClientContainer::NewLC() 00041 // Creates instance of CWebClientContainer. 00042 // ---------------------------------------------------------------------------- 00043 CWebClientContainer* CWebClientContainer::NewLC( const TRect& aRect ) 00044 { 00045 CWebClientContainer* self = new (ELeave) CWebClientContainer; 00046 CleanupStack::PushL( self ); 00047 self->ConstructL( aRect ); 00048 return self; 00049 } 00050 00051 // ---------------------------------------------------------------------------- 00052 // CWebClientContainer::CWebClientContainer() 00053 // First phase construction. 00054 // ---------------------------------------------------------------------------- 00055 CWebClientContainer::CWebClientContainer() 00056 { 00057 // no implementation required 00058 } 00059 00060 // ---------------------------------------------------------------------------- 00061 // CWebClientContainer::ConstructL() 00062 // Second phase construction. 00063 // ---------------------------------------------------------------------------- 00064 // 00065 void CWebClientContainer::ConstructL( const TRect& aRect ) 00066 { 00067 // Create a window for this application view 00068 CreateWindowL(); 00069 00070 iLabel = new (ELeave) CEikLabel; 00071 iLabel->SetContainerWindowL( *this ); 00072 iLabel->SetTextL( KHttpPrefix ); 00073 00074 // Create header window 00075 iHeaderWindow = new (ELeave) CEikRichTextEditor(); 00076 iHeaderWindow->SetContainerWindowL( *this ); 00077 iHeaderWindow->ConstructL( this, KNumberOfLines, KTextLimit, 00078 EEikEdwinReadOnly, EGulFontControlAll, EGulNoSymbolFonts ); 00079 iHeaderWindow->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 00080 CEikScrollBarFrame::EOn ); 00081 00082 // Create source window 00083 iSourceWindow = new (ELeave) CEikRichTextEditor(); 00084 iSourceWindow->SetContainerWindowL( *this ); 00085 iSourceWindow->ConstructL( this, KNumberOfLines, KTextLimit, 00086 EEikEdwinReadOnly, EGulFontControlAll, EGulNoSymbolFonts ); 00087 iSourceWindow->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 00088 CEikScrollBarFrame::EOn ); 00089 00090 // Create status window 00091 iStatusWindow = new (ELeave) CEikRichTextEditor(); 00092 iStatusWindow->SetContainerWindowL( *this ); 00093 iStatusWindow->ConstructL( this, KNumberOfLines, KTextLimit, 00094 EEikEdwinReadOnly, EGulFontControlAll, EGulNoSymbolFonts ); 00095 iStatusWindow->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, 00096 CEikScrollBarFrame::EOn ); 00097 iStatusWindow->SetFocus( ETrue ); 00098 00099 // Set the main window size 00100 SetRect( aRect ); 00101 00102 // Activate the window, which makes it ready to be drawn 00103 ActivateL(); 00104 } 00105 00106 // ---------------------------------------------------------------------------- 00107 // CWebClientContainer::~CWebClientContainer() 00108 // Destructor. 00109 // ---------------------------------------------------------------------------- 00110 // 00111 CWebClientContainer::~CWebClientContainer() 00112 { 00113 if ( iLabel ) 00114 { 00115 delete iLabel; 00116 iLabel = NULL; 00117 } 00118 if ( iHeaderWindow ) 00119 { 00120 delete iHeaderWindow; 00121 iHeaderWindow = NULL; 00122 } 00123 if ( iSourceWindow ) 00124 { 00125 delete iSourceWindow; 00126 iSourceWindow = NULL; 00127 } 00128 if ( iStatusWindow ) 00129 { 00130 delete iStatusWindow; 00131 iStatusWindow = NULL; 00132 } 00133 } 00134 00135 // --------------------------------------------------------- 00136 // CWebClientContainer::SizeChanged() 00137 // Called by framework when the view size is changed 00138 // --------------------------------------------------------- 00139 // 00140 void CWebClientContainer::SizeChanged() 00141 { 00142 TInt pointY = 0; 00143 TRect rect = Rect(); 00144 TInt width = rect.Width(); 00145 TInt height = rect.Height() - 4; // leave space for thin lines between windows 00146 TSize labelSize = iLabel->MinimumSize(); 00147 TInt dataWindowHeigth = (( height - labelSize.iHeight - KStatusWindowHeight ) / 2 ); 00148 labelSize.iWidth = width; 00149 00150 iLabel->SetExtent( TPoint( 0,pointY ), labelSize ); 00151 pointY = pointY + labelSize.iHeight + 1; 00152 iHeaderWindow->SetExtent( TPoint( 0,pointY ), 00153 TSize( width - KScrollBarWidth, dataWindowHeigth )); 00154 pointY = pointY + dataWindowHeigth + 1; 00155 iSourceWindow->SetExtent( TPoint( 0,pointY ), 00156 TSize( width - KScrollBarWidth, dataWindowHeigth )); 00157 pointY = pointY + dataWindowHeigth + 1; 00158 iStatusWindow->SetExtent( TPoint( 0,pointY ), 00159 TSize( width - KScrollBarWidth, KStatusWindowHeight )); 00160 00161 DrawNow(); 00162 } 00163 00164 // ---------------------------------------------------------------------------- 00165 // CWebClientContainer::Draw() 00166 // Draw this application's view to the screen 00167 // ---------------------------------------------------------------------------- 00168 // 00169 void CWebClientContainer::Draw( const TRect& aRect ) const 00170 { 00171 CWindowGc& gc = SystemGc(); 00172 00173 gc.SetPenStyle( CGraphicsContext::ENullPen ); 00174 gc.SetBrushColor( KRgbGray ); 00175 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00176 gc.DrawRect( aRect ); 00177 } 00178 00179 // ---------------------------------------------------------------------------- 00180 // CWebClientContainer::CountComponentControls() 00181 // Returns number of controls in this compound control. 00182 // ---------------------------------------------------------------------------- 00183 // 00184 TInt CWebClientContainer::CountComponentControls() const 00185 { 00186 return 4; // Label and 3 windows 00187 } 00188 00189 // ---------------------------------------------------------------------------- 00190 // CWebClientContainer::ComponentControl() 00191 // Returns pointer to control with index aIndex. 00192 // ---------------------------------------------------------------------------- 00193 // 00194 CCoeControl* CWebClientContainer::ComponentControl( TInt aIndex ) const 00195 { 00196 switch( aIndex ) 00197 { 00198 case 0: 00199 return iLabel; 00200 case 1: 00201 return iHeaderWindow; 00202 case 2: 00203 return iSourceWindow; 00204 case 3: 00205 return iStatusWindow; 00206 default: 00207 Panic( EClientView ); 00208 return 0; 00209 } 00210 } 00211 00212 // ---------------------------------------------------------------------------- 00213 // CWebClientContainer::HandleControlEventL() 00214 // Handles control events. 00215 // ---------------------------------------------------------------------------- 00216 // 00217 void CWebClientContainer::HandleControlEventL( CCoeControl* /* aControl */, 00218 TCoeEvent /* aEventType */ ) 00219 { 00220 // no implementation required 00221 } 00222 00223 // ---------------------------------------------------------------------------- 00224 // CWebClientContainer::ResetL() 00225 // Set label text and reset contents of text windows. 00226 // ---------------------------------------------------------------------------- 00227 // 00228 void CWebClientContainer::ResetL( const TDesC& aText ) 00229 { 00230 iLabel->SetTextL( aText ); 00231 iLabel->DrawNow(); 00232 00233 iHeaderWindow->Text()->Reset(); 00234 iHeaderWindow->HandleTextChangedL(); 00235 iHeaderWindow->SetCursorPosL( 0, EFalse ); 00236 00237 iSourceWindow->Text()->Reset(); 00238 iSourceWindow->HandleTextChangedL(); 00239 iSourceWindow->SetCursorPosL( 0, EFalse ); 00240 00241 iStatusWindow->Text()->Reset(); 00242 iStatusWindow->HandleTextChangedL(); 00243 iStatusWindow->SetCursorPosL( 0, EFalse ); 00244 00245 iHeaderWindow->SetFocus( EFalse ); 00246 iSourceWindow->SetFocus( EFalse ); 00247 iStatusWindow->SetFocus( ETrue ); 00248 } 00249 00250 // ---------------------------------------------------------------------------- 00251 // CWebClientContainer::HandleCommandL() 00252 // Called from CWebClientAppUi::HandleCommandL() 00253 // ---------------------------------------------------------------------------- 00254 // 00255 void CWebClientContainer::HandleCommandL( TInt aCommand ) 00256 { 00257 switch( aCommand ) 00258 { 00259 case EWebClientCmdHeader: 00260 { 00261 // Change focus to Header window and set cursor visible 00262 iHeaderWindow->SetFocus( ETrue ); 00263 iSourceWindow->SetFocus( EFalse ); 00264 iStatusWindow->SetFocus( EFalse ); 00265 iHeaderWindow->MoveCursorL( TCursorPosition::EFNoMovement, EFalse ); 00266 } 00267 break; 00268 case EWebClientCmdSource: 00269 { 00270 // Change focus to Source window and set cursor visible 00271 iSourceWindow->SetFocus( ETrue ); 00272 iHeaderWindow->SetFocus( EFalse ); 00273 iStatusWindow->SetFocus( EFalse ); 00274 iSourceWindow->MoveCursorL( TCursorPosition::EFNoMovement, EFalse ); 00275 } 00276 break; 00277 case EWebClientCmdStatus: 00278 { 00279 // Change focus to Status window and set cursor visible 00280 iStatusWindow->SetFocus( ETrue ); 00281 iHeaderWindow->SetFocus( EFalse ); 00282 iSourceWindow->SetFocus( EFalse ); 00283 iStatusWindow->MoveCursorL( TCursorPosition::EFNoMovement, EFalse ); 00284 } 00285 break; 00286 default: 00287 break; 00288 } 00289 } 00290 00291 // ---------------------------------------------------------------------------- 00292 // CWebClientContainer::OfferKeyEventL() 00293 // Handles key events. 00294 // ---------------------------------------------------------------------------- 00295 // 00296 TKeyResponse CWebClientContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 00297 TEventCode aType ) 00298 { 00299 // Redirect keyevents to controls 00300 if ( iHeaderWindow ) 00301 { 00302 if ( iHeaderWindow->IsFocused() ) 00303 return iHeaderWindow->OfferKeyEventL( aKeyEvent, aType ); 00304 } 00305 00306 if ( iSourceWindow ) 00307 { 00308 if ( iSourceWindow->IsFocused() ) 00309 return iSourceWindow->OfferKeyEventL( aKeyEvent, aType ); 00310 } 00311 00312 if ( iStatusWindow ) 00313 { 00314 if ( iStatusWindow->IsFocused() ) 00315 return iStatusWindow->OfferKeyEventL( aKeyEvent, aType ); 00316 } 00317 00318 return EKeyWasNotConsumed; 00319 } 00320 00321 // ---------------------------------------------------------------------------- 00322 // CWebClientContainer::AddToHeaderWindowL() 00323 // Add a single line of text to the header window. 00324 // ---------------------------------------------------------------------------- 00325 // 00326 void CWebClientContainer::AddToHeaderWindowL( const TDesC& aText ) 00327 { 00328 // Append aText to header window with line break 00329 CRichText* text = iHeaderWindow->RichText(); 00330 text->InsertL( text->DocumentLength(), aText ); 00331 text->InsertL( text->DocumentLength(), CEditableText::ELineBreak ); 00332 iHeaderWindow->HandleTextChangedL(); 00333 } 00334 00335 // ---------------------------------------------------------------------------- 00336 // CWebClientContainer::AddToSourceWindowL() 00337 // Add text to Sourcewindow. No formatting is provided. 00338 // ---------------------------------------------------------------------------- 00339 // 00340 void CWebClientContainer::AddToSourceWindowL( const TDesC8& aText ) 00341 { 00342 // Convert 8-bit aText to 16-bit and append it to end of Source window 00343 HBufC* tempBuf = HBufC::NewL( aText.Length() ); 00344 CleanupStack::PushL( tempBuf ); 00345 tempBuf->Des().Copy( aText ); 00346 CRichText* text = iSourceWindow->RichText(); 00347 text->InsertL( text->DocumentLength(), *tempBuf ); 00348 iSourceWindow->HandleTextChangedL(); 00349 CleanupStack::PopAndDestroy( tempBuf ); 00350 } 00351 00352 // ---------------------------------------------------------------------------- 00353 // CWebClientContainer::AddToStatusWindowL() 00354 // Add a single line of text to the status window. 00355 // ---------------------------------------------------------------------------- 00356 // 00357 void CWebClientContainer::AddToStatusWindowL( const TDesC& aText ) 00358 { 00359 // Append aText to status window with line break 00360 CRichText* text = iStatusWindow->RichText(); 00361 text->InsertL( text->DocumentLength(), aText ); 00362 text->InsertL( text->DocumentLength(), CEditableText::ELineBreak ); 00363 iStatusWindow->HandleTextChangedL(); 00364 iStatusWindow->MoveCursorL( TCursorPosition::EFLineDown, EFalse ); 00365 } 00366 00367 // ---------------------------------------------------------------------------- 00368 // CWebClientContainer::ClientEvent() 00369 // Called by CWebClientEngine to notify events to user 00370 // ---------------------------------------------------------------------------- 00371 // 00372 void CWebClientContainer::ClientEvent( const TDesC& aEventDescription ) 00373 { 00374 TRAPD( err, AddToStatusWindowL( aEventDescription )); 00375 if( err ) 00376 Panic( EClientView ); 00377 } 00378 00379 // ---------------------------------------------------------------------------- 00380 // CWebClientContainer::ClientHeaderReceived() 00381 // Called by CWebClientEngine when HTTP header received 00382 // ---------------------------------------------------------------------------- 00383 // 00384 void CWebClientContainer::ClientHeaderReceived( const TDesC& aHeaderData ) 00385 { 00386 TRAPD( err, AddToHeaderWindowL( aHeaderData )); 00387 if( err ) 00388 Panic( EClientView ); 00389 } 00390 00391 // ---------------------------------------------------------------------------- 00392 // CWebClientContainer::ClientBodyReceived() 00393 // Called by CWebClientEngine when part of response body received 00394 // ---------------------------------------------------------------------------- 00395 // 00396 void CWebClientContainer::ClientBodyReceived( const TDesC8& aBodyData ) 00397 { 00398 TRAPD( err, AddToSourceWindowL( aBodyData )); 00399 if( err ) 00400 Panic( EClientView ); 00401 }
|
© Nokia 2006 |