examples/SFExamples/RecipeEx/src/LogContainer.cpp

00001 // Symbian Foundation Example Code
00002 // 
00003 // This software is in the public domain. No copyright is claimed, and you 
00004 // may use it for any purpose without license from the Symbian Foundation.
00005 // No warranty for any purpose is expressed or implied by the authors or
00006 // the Symbian Foundation. 
00007 
00008 
00009 #include <eikedwin.h>
00010 #include <eikenv.h>
00011 #include <aknutils.h> 
00012 
00013 #include <RecipeEx_0xE8FAA390.rsg>
00014 #include "LogContainer.h"
00015 
00016 #include <PtiEngine.h>
00017 #include <ptilanguage.h>
00018 
00019 // Constants
00021 const TInt KMaxLengthOfLogEntry = 256;
00022 
00023 
00024 
00028 CLogContainer* CLogContainer::NewL( const TRect& aRect)
00029         {
00030         CLogContainer* self = CLogContainer::NewLC( aRect);
00031         CleanupStack::Pop( self );
00032         return self;
00033         }
00034 
00038 CLogContainer* CLogContainer::NewLC( const TRect& aRect)
00039         {
00040         CLogContainer* self = new ( ELeave ) CLogContainer;
00041         CleanupStack::PushL( self );
00042         self->ConstructL( aRect);
00043         return self;
00044         }
00045 
00047 CLogContainer::~CLogContainer()
00048         {
00049     delete iLog;
00050     iLog = NULL;
00051         }
00052 
00056 void CLogContainer::ConstructL( const TRect& aRect)
00057         {
00058         CreateWindowL();        
00059         
00060     // Create editable editor control
00061     iLog = new (ELeave) CEikEdwin();
00062     iLog->SetContainerWindowL( *this );
00063     iLog->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
00064     iLog->ConstructL( CEikEdwin::ENoAutoSelection |
00065                           CEikEdwin::EReadOnly );
00066     
00067     // Use a smaller font 
00068     const CFont* logicalFont = AknLayoutUtils::FontFromId(EAknLogicalFontPrimarySmallFont);
00069     TFontSpec fontspec = logicalFont->FontSpecInTwips();
00070     TCharFormat charFormat = TCharFormat(fontspec.iTypeface.iName, fontspec.iHeight);
00071     TCharFormatMask charFormatMask;
00072     charFormatMask.SetAttrib(EAttFontTypeface);
00073     charFormatMask.SetAttrib(EAttFontHeight);
00074     iLog->SetCharFormatLayer(CCharFormatLayer::NewL(charFormat,charFormatMask));
00075 
00076         SetRect( aRect );
00077         ActivateL();
00078         }
00079 
00083 TInt CLogContainer::CountComponentControls() const
00084     {
00085     return 1; // The edwin
00086     }
00087 
00090 CCoeControl* CLogContainer::ComponentControl(TInt aIndex) const
00091     {
00092     switch ( aIndex )
00093         {
00094         case 0:
00095             return iLog;
00096         default:
00097             return NULL;
00098         }
00099     }
00100 
00105 void CLogContainer::SizeChanged()
00106         {
00107         // The scrollbar is drawn within the bounds of the client rect, so we need to alter the
00108         // Log edwin to adjust for the scrollbar size.
00109     TRect r = Rect();
00110     TInt scrollbarWidth = iLog->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EVertical);
00111     TInt editorWidth = r.Width() - scrollbarWidth;
00112     TPoint upperLeftCorner = TPoint(0, 0);
00113     
00114     // Update the edwin
00115     iLog->SetExtent(upperLeftCorner, TSize(editorWidth, r.Height()));
00116         }
00117 
00118 
00121 void CLogContainer::Draw( const TRect& /*aRect*/ ) const
00122         {
00123         // Get the standard graphics context
00124         CWindowGc& gc = SystemGc();
00125 
00126         // Gets the control's extent
00127         TRect drawRect(Rect());
00128 
00129         // Clears the screen
00130         gc.Clear(drawRect);
00131         }
00132 
00138 void CLogContainer::HandleResourceChange(TInt aType)
00139         {
00140     CCoeControl::HandleResourceChange(aType);
00141 
00142     // ADDED FOR SCALABLE UI SUPPORT
00143         TRect rect;
00144 
00145     if ( aType==KEikDynamicLayoutVariantSwitch )// layout change event
00146         {    
00147         // get new main panel rect and set it
00148         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00149         SetRect(rect);
00150         }
00151         }
00152 
00154 TKeyResponse CLogContainer::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
00155         {
00156         return iLog->OfferKeyEventL(aKeyEvent, aType);
00157         }
00158 
00163 void CLogContainer::LogSectionTitleL(const TDesC& aSectionTitle)
00164         {
00165         _LIT(KSectionBreak, "--------------------");
00166         AppendTextL(KSectionBreak);
00167         AppendTextL(aSectionTitle);
00168         AppendTextL(KSectionBreak);
00169         }
00170 
00176 void CLogContainer::LogEntryL(TRefByValue<const TDesC> aFormatString, ... )
00177         {
00178         TBuf<KMaxLengthOfLogEntry> logEntry;
00179         
00180         // Overflow handler which will just ignore any overflows 
00181         TDes16OverflowHandler overflowHandler;
00182 
00183         // Format the log entry
00184         VA_LIST argList;
00185         VA_START(argList, aFormatString);
00186         logEntry.AppendFormatList(aFormatString, argList, &overflowHandler);
00187         VA_END(argList);
00188         
00189         // Log the entry
00190         AppendTextL(logEntry);
00191         }
00192 
00193 
00197 void CLogContainer::AppendTextL(const TDesC& aLogText)
00198         {
00199         CPlainText* text = iLog->Text();
00200         text->InsertL( text->DocumentLength(), aLogText );
00201         text->InsertL( text->DocumentLength(), CEditableText::ELineBreak );
00202         iLog->HandleTextChangedL();
00203         iLog->SetFocus( ETrue );        
00204         }
00205 
00208 void CLogContainer::ClearLogL()
00209         {
00210         CPlainText* text = iLog->Text();
00211         text->Reset();
00212         iLog->HandleTextChangedL();
00213         iLog->SetFocus( ETrue );                
00214         }
00215 
00216 
00217         
00218 // End of File

Generated by  doxygen 1.6.2