examples/ForumNokia/AudioStreamExample/src/AudioStreamView.cpp

00001 /*
00002  * Copyright © 2008 Nokia Corporation.
00003  */
00004 
00005 // INCLUDE FILES
00006 #include <aknutils.h>       // Fonts
00007 #include <w32std.h>         // key codes and events
00008 #include "AudioStreamView.h"
00009 
00010 #include <TXTRICH.H>
00011 
00012 
00013 const TUint KNumberOfLines = 0;
00014 const TUint KTextLimit = 0;
00015 
00016 
00017 CAudioStreamView* CAudioStreamView::NewL(const TRect & aRect, 
00018                                          CAudioStreamEngine* aEngine)
00019     {
00020     CAudioStreamView* self = NewLC(aRect, aEngine);
00021     CleanupStack::Pop(self);
00022     return self;
00023     }
00024 
00025 CAudioStreamView* CAudioStreamView::NewLC(const TRect & aRect, 
00026                                           CAudioStreamEngine* aEngine)
00027     {
00028     CAudioStreamView* self = new (ELeave) CAudioStreamView();
00029     CleanupStack::PushL(self);
00030     self->ConstructL(aRect, aEngine);
00031     return self;
00032     }
00033 
00034 // ----------------------------------------------------------------------------
00035 // CAudioStreamView::ConstructL(const TRect& aRect, 
00036 //                                CAudioStreamEngine* aEngine)
00037 //
00038 // Standard EPOC 2nd phase constructor
00039 // ----------------------------------------------------------------------------
00040 void CAudioStreamView::ConstructL(const TRect& aRect, 
00041                                   CAudioStreamEngine* aEngine)
00042     {
00043     iEngine = aEngine;
00044     // create new window,
00045     CreateWindowL();
00046 
00047     // Create a rich text editor into which information can be logged
00048     iLogComponent = new(ELeave) CEikRichTextEditor;
00049     iLogComponent->ConstructL(this, KNumberOfLines, KTextLimit,
00050             CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor);
00051     iLogComponent->CreateScrollBarFrameL()->SetScrollBarVisibilityL(
00052             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
00053 
00054     // Set font
00055     #ifdef __WINS__
00056     _LIT(KFontArial,"Arial");
00057     TFontSpec MyeFontSpec (KFontArial, 8*10);
00058     MyeFontSpec.iTypeface.SetIsProportional(ETrue);
00059     // Set font height
00060     TCharFormatMask charFormatMask;
00061     charFormatMask.SetAttrib(EAttFontHeight);
00062     TCharFormat charFormat(MyeFontSpec.iTypeface.iName, MyeFontSpec.iHeight);
00063     charFormat.iFontPresentation.iTextColor=KRgbBlack;
00064     charFormat.iFontSpec.iHeight=100;
00065     // apply formatting    
00066     CRichText* text = iLogComponent->RichText();
00067     text->ApplyCharFormatL(charFormat,charFormatMask,0,1);
00068     #endif
00069     
00070     SetRect(aRect);
00071     _LIT(KInfo, "Audio streaming example");
00072     ShowMessageL(KInfo);
00073     
00074     // activate window
00075     ActivateL();    
00076 
00077     // SetRect() is called again after ActivateL() to that ScrollBarFrame widht
00078     // can be readed in SizeChanged()
00079     SetRect(aRect);
00080     }
00081 
00082 // ----------------------------------------------------------------------------
00083 // CAudioStreamView::CAudioStreamView()
00084 //
00085 // constructor
00086 // ----------------------------------------------------------------------------
00087 CAudioStreamView::CAudioStreamView()
00088     {
00089     }
00090 
00091 // ----------------------------------------------------------------------------
00092 // CAudioStreamView::~CAudioStreamView()
00093 //
00094 // destructor
00095 // ----------------------------------------------------------------------------
00096 CAudioStreamView::~CAudioStreamView()
00097     {
00098     delete iLogComponent;
00099     }
00100 
00101 // ----------------------------------------------------------------------------
00102 // CAudioStreamView::SizeChanged()
00103 //
00104 // called by framework when the view size is changed
00105 // ----------------------------------------------------------------------------
00106 void CAudioStreamView::SizeChanged()
00107     {
00108     TRect rect = Rect();
00109     
00110     TInt scrollbarWidth = iLogComponent->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EVertical);
00111     // If scrollbars are not drawn yet, the width remains zero. In this
00112     // case, an intentionally magical number is returned.
00113     if (scrollbarWidth == 0)
00114         {
00115         scrollbarWidth = 8;
00116         }
00117     iLogComponent->SetExtent(TPoint(0, 0),
00118             TSize(rect.Width() - scrollbarWidth, rect.Height()));
00119     DrawNow();
00120     }
00121 
00122 // ---------------------------------------------------------
00123 // CAudioStreamView::HandleResourceChange()
00124 // Called by framework when resource is changed.
00125 // ---------------------------------------------------------
00126 //
00127 void CAudioStreamView::HandleResourceChange(TInt aType)
00128     {
00129     CCoeControl::HandleResourceChange(aType);
00130     if ( aType==KEikDynamicLayoutVariantSwitch )
00131         {
00132         TRect rect;
00133         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00134         SetRect(rect);
00135         }
00136     }
00137 
00138 
00139 // ----------------------------------------------------------------------------
00140 // CAudioStreamView::CountComponentControls() const
00141 // ----------------------------------------------------------------------------
00142 TInt CAudioStreamView::CountComponentControls() const
00143     {
00144     return 1;   // return number of controls inside this container
00145     }
00146 
00147 // ----------------------------------------------------------------------------
00148 // CAudioStreamView::ComponentControl(TInt aIndex) const
00149 // ----------------------------------------------------------------------------
00150 CCoeControl* CAudioStreamView::ComponentControl(TInt aIndex) const
00151     {
00152     switch ( aIndex )
00153         {
00154         case 0:
00155             return iLogComponent;
00156         default:
00157             return NULL;
00158         }
00159     }
00160 
00161 
00162 // ----------------------------------------------------------------------------
00163 // CAudioStreamView::Draw(const TRect& aRect) const
00164 // ----------------------------------------------------------------------------
00165 void CAudioStreamView::Draw( const TRect& aRect ) const
00166     {
00167     CWindowGc& gc = SystemGc();   
00168     gc.SetPenStyle( CGraphicsContext::ENullPen );
00169     gc.SetBrushColor( KRgbWhite );
00170     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00171     gc.DrawRect( aRect );
00172     }
00173 
00174 // ----------------------------------------------------------------------------
00175 // CAudioStreamView::ShowMessageL(const TDesC& aMsg)
00176 //
00177 // displays status messages to user
00178 // ----------------------------------------------------------------------------
00179 void CAudioStreamView::ShowMessageL(const TDesC& aMsg)
00180     {
00181     CPlainText* text = iLogComponent->Text();
00182     text->InsertL(text->DocumentLength(), aMsg);
00183     text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
00184     iLogComponent->HandleTextChangedL();
00185     // Keep displaying the bottom of the screen
00186     iLogComponent->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
00187     DrawNow();
00188     }
00189 
00190 
00191 // End of File  
00192 
00193 

Generated by  doxygen 1.6.2