examples/ForumNokia/AudioStreamExample/src/AudioStreamView.cpp

00001 /*
00002  * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 // INCLUDE FILES
00031 #include <aknutils.h>       // Fonts
00032 #include <w32std.h>         // key codes and events
00033 #include "AudioStreamView.h"
00034 
00035 #include <TXTRICH.H>
00036 
00037 
00038 const TUint KNumberOfLines = 0;
00039 const TUint KTextLimit = 0;
00040 
00041 
00042 CAudioStreamView* CAudioStreamView::NewL(const TRect & aRect, 
00043                                          CAudioStreamEngine* aEngine)
00044     {
00045     CAudioStreamView* self = NewLC(aRect, aEngine);
00046     CleanupStack::Pop(self);
00047     return self;
00048     }
00049 
00050 CAudioStreamView* CAudioStreamView::NewLC(const TRect & aRect, 
00051                                           CAudioStreamEngine* aEngine)
00052     {
00053     CAudioStreamView* self = new (ELeave) CAudioStreamView();
00054     CleanupStack::PushL(self);
00055     self->ConstructL(aRect, aEngine);
00056     return self;
00057     }
00058 
00059 // ----------------------------------------------------------------------------
00060 // CAudioStreamView::ConstructL(const TRect& aRect, 
00061 //                                CAudioStreamEngine* aEngine)
00062 //
00063 // Standard EPOC 2nd phase constructor
00064 // ----------------------------------------------------------------------------
00065 void CAudioStreamView::ConstructL(const TRect& aRect, 
00066                                   CAudioStreamEngine* aEngine)
00067     {
00068     iEngine = aEngine;
00069     // create new window,
00070     CreateWindowL();
00071 
00072     // Create a rich text editor into which information can be logged
00073     iLogComponent = new(ELeave) CEikRichTextEditor;
00074     iLogComponent->ConstructL(this, KNumberOfLines, KTextLimit,
00075             CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor);
00076     iLogComponent->CreateScrollBarFrameL()->SetScrollBarVisibilityL(
00077             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn);
00078 
00079     // Set font
00080     #ifdef __WINS__
00081     _LIT(KFontArial,"Arial");
00082     TFontSpec MyeFontSpec (KFontArial, 8*10);
00083     MyeFontSpec.iTypeface.SetIsProportional(ETrue);
00084     // Set font height
00085     TCharFormatMask charFormatMask;
00086     charFormatMask.SetAttrib(EAttFontHeight);
00087     TCharFormat charFormat(MyeFontSpec.iTypeface.iName, MyeFontSpec.iHeight);
00088     charFormat.iFontPresentation.iTextColor=KRgbBlack;
00089     charFormat.iFontSpec.iHeight=100;
00090     // apply formatting    
00091     CRichText* text = iLogComponent->RichText();
00092     text->ApplyCharFormatL(charFormat,charFormatMask,0,1);
00093     #endif
00094     
00095     SetRect(aRect);
00096     _LIT(KInfo, "Audio streaming example");
00097     ShowMessageL(KInfo);
00098     
00099     // activate window
00100     ActivateL();    
00101 
00102     // SetRect() is called again after ActivateL() to that ScrollBarFrame widht
00103     // can be readed in SizeChanged()
00104     SetRect(aRect);
00105     }
00106 
00107 // ----------------------------------------------------------------------------
00108 // CAudioStreamView::CAudioStreamView()
00109 //
00110 // constructor
00111 // ----------------------------------------------------------------------------
00112 CAudioStreamView::CAudioStreamView()
00113     {
00114     }
00115 
00116 // ----------------------------------------------------------------------------
00117 // CAudioStreamView::~CAudioStreamView()
00118 //
00119 // destructor
00120 // ----------------------------------------------------------------------------
00121 CAudioStreamView::~CAudioStreamView()
00122     {
00123     delete iLogComponent;
00124     }
00125 
00126 // ----------------------------------------------------------------------------
00127 // CAudioStreamView::SizeChanged()
00128 //
00129 // called by framework when the view size is changed
00130 // ----------------------------------------------------------------------------
00131 void CAudioStreamView::SizeChanged()
00132     {
00133     TRect rect = Rect();
00134     
00135     TInt scrollbarWidth = iLogComponent->ScrollBarFrame()->ScrollBarBreadth(CEikScrollBar::EVertical);
00136     // If scrollbars are not drawn yet, the width remains zero. In this
00137     // case, an intentionally magical number is returned.
00138     if (scrollbarWidth == 0)
00139         {
00140         scrollbarWidth = 8;
00141         }
00142     iLogComponent->SetExtent(TPoint(0, 0),
00143             TSize(rect.Width() - scrollbarWidth, rect.Height()));
00144     DrawNow();
00145     }
00146 
00147 // ---------------------------------------------------------
00148 // CAudioStreamView::HandleResourceChange()
00149 // Called by framework when resource is changed.
00150 // ---------------------------------------------------------
00151 //
00152 void CAudioStreamView::HandleResourceChange(TInt aType)
00153     {
00154     CCoeControl::HandleResourceChange(aType);
00155     if ( aType==KEikDynamicLayoutVariantSwitch )
00156         {
00157         TRect rect;
00158         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00159         SetRect(rect);
00160         }
00161     }
00162 
00163 
00164 // ----------------------------------------------------------------------------
00165 // CAudioStreamView::CountComponentControls() const
00166 // ----------------------------------------------------------------------------
00167 TInt CAudioStreamView::CountComponentControls() const
00168     {
00169     return 1;   // return number of controls inside this container
00170     }
00171 
00172 // ----------------------------------------------------------------------------
00173 // CAudioStreamView::ComponentControl(TInt aIndex) const
00174 // ----------------------------------------------------------------------------
00175 CCoeControl* CAudioStreamView::ComponentControl(TInt aIndex) const
00176     {
00177     switch ( aIndex )
00178         {
00179         case 0:
00180             return iLogComponent;
00181         default:
00182             return NULL;
00183         }
00184     }
00185 
00186 
00187 // ----------------------------------------------------------------------------
00188 // CAudioStreamView::Draw(const TRect& aRect) const
00189 // ----------------------------------------------------------------------------
00190 void CAudioStreamView::Draw( const TRect& aRect ) const
00191     {
00192     CWindowGc& gc = SystemGc();   
00193     gc.SetPenStyle( CGraphicsContext::ENullPen );
00194     gc.SetBrushColor( KRgbWhite );
00195     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00196     gc.DrawRect( aRect );
00197     }
00198 
00199 // ----------------------------------------------------------------------------
00200 // CAudioStreamView::ShowMessageL(const TDesC& aMsg)
00201 //
00202 // displays status messages to user
00203 // ----------------------------------------------------------------------------
00204 void CAudioStreamView::ShowMessageL(const TDesC& aMsg)
00205     {
00206     CPlainText* text = iLogComponent->Text();
00207     text->InsertL(text->DocumentLength(), aMsg);
00208     text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
00209     iLogComponent->HandleTextChangedL();
00210     // Keep displaying the bottom of the screen
00211     iLogComponent->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
00212     DrawNow();
00213     }
00214 
00215 
00216 // End of File  
00217 
00218 

Generated by  doxygen 1.6.2