|
S60 3rd Edition SDK for Symbian OS Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : SIPExLogContainer.cpp 00004 * Part of : SIPEx 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004-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 "SIPExLogContainer.h" 00018 #include "SIPExGameEngine.h" 00019 #include "SIPExDoc.h" 00020 00021 #include <SIPEx.rsg> 00022 00023 #include <akndef.h> 00024 #include <eikenv.h> 00025 #include <eikgted.h> // CGlobalTextEditor 00026 #include <txtglobl.h> // CGlobalText 00027 #include <barsread.h> 00028 00029 #include <AknsDrawUtils.h> 00030 #include <AknsBasicBackgroundControlContext.h> 00031 00032 const TInt KComponentCount( 1 ); 00033 const TInt KEditorMaxLength( 1024 ); 00034 const TInt KEditorDistanceFromScreenEdge( 8 ); 00035 const TInt KEditorBorderGrow( 2 ); 00036 const TInt KFontColorIndexBlue( 200 ); 00037 00038 // ============================ MEMBER FUNCTIONS =============================== 00039 00040 // ----------------------------------------------------------------------------- 00041 // CSIPExGameContainer::CSIPExGameContainer 00042 // C++ default constructor 00043 // ----------------------------------------------------------------------------- 00044 // 00045 CSIPExLogContainer::CSIPExLogContainer( CSIPExEngine& aEngine ) 00046 : iEngine( aEngine ) 00047 { 00048 // no implementation required 00049 } 00050 00051 // ----------------------------------------------------------------------------- 00052 // CSIPExLogContainer::ConstructL 00053 // EPOC two phased constructor 00054 // ----------------------------------------------------------------------------- 00055 // 00056 void CSIPExLogContainer::ConstructL( const TRect& aRect ) 00057 { 00058 CreateWindowL(); 00059 00060 iBgContext = 00061 CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, 00062 aRect, 00063 ETrue ); 00064 00065 // Create editor in which info texts are shown (log window) 00066 // 00067 iEditor = new ( ELeave ) CEikGlobalTextEditor(); 00068 00069 TInt flags( EEikEdwinNoAutoSelection | 00070 EEikEdwinJustAutoCurEnd | 00071 EEikEdwinLineCursor | 00072 EEikEdwinNoHorizScrolling ); 00073 00074 TRect editorRect( aRect ); 00075 editorRect.Shrink( KEditorDistanceFromScreenEdge, 00076 KEditorDistanceFromScreenEdge ); 00077 00078 iEditor->ConstructL( this, 00079 NumOfFittingEditorLines( editorRect ), 00080 KEditorMaxLength, 00081 flags, 00082 EGulFontControlAll, 00083 EGulAllFonts ); 00084 00085 iEditor->SetContainerWindowL( *this ); 00086 00087 00088 00089 AknLayoutUtils::LayoutEdwin( iEditor, 00090 editorRect, 00091 GetEditorLayout( editorRect ) ); 00092 00093 iEditor->CreateScrollBarFrameL(); 00094 iEditor->ScrollBarFrame()->SetScrollBarVisibilityL( 00095 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); 00096 00097 00098 SetRect( aRect ); 00099 00100 iEditor->ActivateL(); 00101 00102 ShowInfoL(); 00103 00104 ActivateL(); 00105 } 00106 00107 // ----------------------------------------------------------------------------- 00108 // CSIPExLogContainer::~CSIPExLogContainer 00109 // Destructor 00110 // ----------------------------------------------------------------------------- 00111 // 00112 CSIPExLogContainer::~CSIPExLogContainer() 00113 { 00114 delete iEditor; 00115 delete iBgContext; 00116 } 00117 00118 // ----------------------------------------------------------------------------- 00119 // CSIPExLogContainer::SizeChanged 00120 // Called by framework when the view size is changed 00121 // ----------------------------------------------------------------------------- 00122 // 00123 void CSIPExLogContainer::SizeChanged() 00124 { 00125 TRect editorRect( Rect() ); 00126 editorRect.Shrink( KEditorDistanceFromScreenEdge, 00127 KEditorDistanceFromScreenEdge ); 00128 00129 AknLayoutUtils::LayoutEdwin( iEditor, 00130 editorRect, 00131 GetEditorLayout( editorRect ) ); 00132 } 00133 00134 // ----------------------------------------------------------------------------- 00135 // CSIPExLogContainer::CountComponentControls 00136 // ----------------------------------------------------------------------------- 00137 // 00138 TInt CSIPExLogContainer::CountComponentControls() const 00139 { 00140 return KComponentCount; // return nbr of controls inside this container 00141 } 00142 00143 // ----------------------------------------------------------------------------- 00144 // CSIPExLogContainer::ComponentControl 00145 // ----------------------------------------------------------------------------- 00146 // 00147 CCoeControl* CSIPExLogContainer::ComponentControl( TInt aIndex ) const 00148 { 00149 switch( aIndex ) 00150 { 00151 case 0: 00152 return iEditor; 00153 default: 00154 { 00155 _LIT( KPanicCntx, "SIP Example" ); 00156 __ASSERT_ALWAYS( EFalse, User::Panic( KPanicCntx(), KErrArgument ) ); 00157 } 00158 } 00159 return NULL; 00160 } 00161 00162 // ----------------------------------------------------------------------------- 00163 // CSIPExLogContainer::Draw 00164 // ----------------------------------------------------------------------------- 00165 // 00166 void CSIPExLogContainer::Draw( const TRect& aRect ) const 00167 { 00168 CWindowGc& gc = SystemGc(); 00169 00170 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00171 gc.SetBrushColor( KRgbWhite ); 00172 gc.Clear(); 00173 00174 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); 00175 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); 00176 00177 AknsDrawUtils::Background( skin, cc, this, gc, aRect ); 00178 00179 // Draw editor border 00180 gc.SetBrushStyle( CGraphicsContext::ENullBrush ); 00181 gc.SetPenStyle( CGraphicsContext::ESolidPen ); 00182 gc.SetPenColor( TRgb( 174, 186, 227 ) ); 00183 00184 TRect editorRect( iEditor->Rect() ); 00185 editorRect.Grow( KEditorBorderGrow, KEditorBorderGrow ); 00186 gc.DrawRect( editorRect ); 00187 } 00188 00189 // ----------------------------------------------------------------------------- 00190 // CSIPExLogContainer::HandleControlEventL( 00191 // CCoeControl* aControl,TCoeEvent aEventType) 00192 // ----------------------------------------------------------------------------- 00193 // 00194 void CSIPExLogContainer::HandleControlEventL( 00195 CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/ ) 00196 { 00197 // Add your control event handler code here 00198 } 00199 00200 // ----------------------------------------------------------------------------- 00201 // CSIPExLogContainer::OfferKeyEventL 00202 // From CCoeControl. 00203 // ----------------------------------------------------------------------------- 00204 // 00205 TKeyResponse CSIPExLogContainer::OfferKeyEventL( 00206 const TKeyEvent& aKeyEvent, 00207 TEventCode aType ) 00208 { 00209 if( aType == EEventKeyUp ) 00210 { 00211 switch( aKeyEvent.iScanCode ) 00212 { 00213 case EStdKeyUpArrow: 00214 iEditor->MoveCursorL( TCursorPosition::EFPageUp, EFalse ); 00215 return EKeyWasConsumed; 00216 00217 case EStdKeyDownArrow: 00218 iEditor->MoveCursorL( TCursorPosition::EFPageDown, EFalse ); 00219 return EKeyWasConsumed; 00220 00221 default: 00222 return EKeyWasNotConsumed; 00223 } 00224 } 00225 00226 return EKeyWasNotConsumed; 00227 } 00228 00229 // ----------------------------------------------------------------------------- 00230 // CSIPExLogContainer::HandleResourceChange 00231 // From CCoeControl. 00232 // ----------------------------------------------------------------------------- 00233 // 00234 void CSIPExLogContainer::HandleResourceChange( TInt aType ) 00235 { 00236 CCoeControl::HandleResourceChange( aType ); 00237 00238 if ( aType == KEikDynamicLayoutVariantSwitch ) 00239 { 00240 TRect mainPaneRect; 00241 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 00242 mainPaneRect ); 00243 if ( iBgContext ) 00244 { 00245 iBgContext->SetRect( mainPaneRect ); 00246 } 00247 00248 SetRect( mainPaneRect ); 00249 DrawNow(); 00250 } 00251 } 00252 00253 // ----------------------------------------------------------------------------- 00254 // CSIPExLogContainer::MopSupplyObject 00255 // From CCoeControl. 00256 // ----------------------------------------------------------------------------- 00257 // 00258 TTypeUid::Ptr CSIPExLogContainer::MopSupplyObject( TTypeUid aId ) 00259 { 00260 if ( aId.iUid == MAknsControlContext::ETypeId ) 00261 { 00262 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); 00263 } 00264 return CCoeControl::MopSupplyObject( aId ); 00265 } 00266 00267 // ----------------------------------------------------------------------------- 00268 // CSIPExLogView::ShowInfoL 00269 // This is called from AppUi when info is received from engine 00270 // ----------------------------------------------------------------------------- 00271 // 00272 void CSIPExLogContainer::ShowInfoL() 00273 { 00274 // Read info text from document and set it to editor. 00275 // Current way is not the most optimal. 00276 CEikDocument* doc = 00277 static_cast< CEikAppUi* >( CEikonEnv::Static()->AppUi() )->Document(); 00278 00279 CGlobalText* globalText = iEditor->GlobalText(); 00280 globalText->Reset(); 00281 globalText->InsertL( 0, static_cast< CSIPExDoc* >( doc )->InfoText() ); 00282 00283 TCharFormat charFormat; 00284 TCharFormatMask charMask; 00285 iEditor->ApplyCharFormatL( charFormat, charMask ); 00286 00287 iEditor->MoveCursorL( TCursorPosition::EFPageDown, EFalse ); 00288 00289 DrawDeferred(); 00290 } 00291 00292 // ----------------------------------------------------------------------------- 00293 // CSIPExLogView::GetEditorLAyout 00294 // 00295 // ----------------------------------------------------------------------------- 00296 // 00297 AknLayoutUtils::SAknLayoutTextMultiline CSIPExLogContainer::GetEditorLayout( 00298 const TRect& aRect ) const 00299 { 00300 /* 00301 SAknLayoutTextMultiline struct: 00302 00303 @param iFont font id, ELatinPlain12, ELatinBold12, ELatinBold13 etc.. 00304 @param iC colour index, 0..255 00305 @param iL left margin 00306 @param iR right margin 00307 @param iB Baseline from top of the parent rectangle 00308 @param iW text width in pixels 00309 @param iJ justification. ELayoutAlignNone; ELayoutAlignCenter; 00310 ELayoutAlignLeft; ELayoutAlignRight; ELayoutAlignBidi 00311 00312 @param iNumberOfLinesShown 00313 @param iNextLineB baseline of 2nd line for multi-line labels/editors 00314 */ 00315 TInt fontHeight( FontHeightInPixels() ); 00316 TInt fontTotalHeight( FontTotalHeightInPixels() ); 00317 00318 AknLayoutUtils::SAknLayoutTextMultiline editorLayout; 00319 editorLayout.iFont = EAknLogicalFontSecondaryFont; 00320 editorLayout.iC = KFontColorIndexBlue; 00321 editorLayout.iL = KEditorDistanceFromScreenEdge; 00322 editorLayout.iR = KEditorDistanceFromScreenEdge; 00323 editorLayout.iB = KEditorDistanceFromScreenEdge + fontHeight; 00324 editorLayout.iW = aRect.Width() - editorLayout.iL - editorLayout.iR; 00325 editorLayout.iJ = ELayoutAlignLeft; 00326 editorLayout.iNumberOfLinesShown = NumOfFittingEditorLines( aRect ); 00327 editorLayout.iNextLineB = editorLayout.iB + fontTotalHeight; 00328 return editorLayout; 00329 } 00330 00331 // ----------------------------------------------------------------------------- 00332 // CSIPExLogView::FontHeightInPixels 00333 // 00334 // ----------------------------------------------------------------------------- 00335 // 00336 TInt CSIPExLogContainer::FontHeightInPixels() const 00337 { 00338 const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontSecondaryFont ); 00339 00340 _LIT( KPanicCntx, "SIP Example" ); 00341 __ASSERT_ALWAYS( font, User::Panic( KPanicCntx(), KErrNotFound ) ); 00342 00343 return font->HeightInPixels(); 00344 } 00345 00346 // ----------------------------------------------------------------------------- 00347 // CSIPExLogView::FontTotalHeightInPixels 00348 // 00349 // ----------------------------------------------------------------------------- 00350 // 00351 TInt CSIPExLogContainer::FontTotalHeightInPixels() const 00352 { 00353 const CFont* font = AknLayoutUtils::FontFromId( EAknLogicalFontSecondaryFont ); 00354 00355 _LIT( KPanicCntx, "SIP Example" ); 00356 __ASSERT_ALWAYS( font, User::Panic( KPanicCntx(), KErrNotFound ) ); 00357 00358 return ( font->HeightInPixels() + 00359 font->AscentInPixels() + 00360 font->DescentInPixels() ); 00361 } 00362 // ----------------------------------------------------------------------------- 00363 // CSIPExLogView::NumOfFittingLines 00364 // 00365 // ----------------------------------------------------------------------------- 00366 // 00367 TInt CSIPExLogContainer::NumOfFittingEditorLines( const TRect& aRect ) const 00368 { 00369 return aRect.Height() / FontTotalHeightInPixels(); 00370 } 00371 00372 // End of File
|
© Nokia 2006 |