00001
00002
00003
00004
00005
00006
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
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
00061 iLog = new (ELeave) CEikEdwin();
00062 iLog->SetContainerWindowL( *this );
00063 iLog->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
00064 iLog->ConstructL( CEikEdwin::ENoAutoSelection |
00065 CEikEdwin::EReadOnly );
00066
00067
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;
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
00108
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
00115 iLog->SetExtent(upperLeftCorner, TSize(editorWidth, r.Height()));
00116 }
00117
00118
00121 void CLogContainer::Draw( const TRect& ) const
00122 {
00123
00124 CWindowGc& gc = SystemGc();
00125
00126
00127 TRect drawRect(Rect());
00128
00129
00130 gc.Clear(drawRect);
00131 }
00132
00138 void CLogContainer::HandleResourceChange(TInt aType)
00139 {
00140 CCoeControl::HandleResourceChange(aType);
00141
00142
00143 TRect rect;
00144
00145 if ( aType==KEikDynamicLayoutVariantSwitch )
00146 {
00147
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
00181 TDes16OverflowHandler overflowHandler;
00182
00183
00184 VA_LIST argList;
00185 VA_START(argList, aFormatString);
00186 logEntry.AppendFormatList(aFormatString, argList, &overflowHandler);
00187 VA_END(argList);
00188
00189
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