examples/sfexamples/FileStream/src/s60_3rd/FileStreamMainView.cpp

00001 /*
00002  * Copyright (c) 2002-2011 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 // INCLUDES
00031 #include <eikedwin.h>
00032 #include <eikenv.h>
00033 #include <aknutils.h>
00034 #include <FileStream.rsg>
00035 
00036 #include "FileStreamMainView.h"
00037 
00038 // MEMBER FUNCTIONS
00039 
00040 // --------------------------------------------------------------------------
00041 // Two-phase constructor
00042 // --------------------------------------------------------------------------
00043 CFileStreamMainView* CFileStreamMainView::NewL(const TRect& aRect)
00044         {
00045         CFileStreamMainView* self = CFileStreamMainView::NewLC(aRect);
00046         CleanupStack::Pop(self);
00047         return self;
00048         }
00049 
00050 // --------------------------------------------------------------------------
00051 // Two-phase constructor
00052 // --------------------------------------------------------------------------
00053 CFileStreamMainView* CFileStreamMainView::NewLC(const TRect& aRect)
00054         {
00055         CFileStreamMainView* self = new (ELeave) CFileStreamMainView;
00056         CleanupStack::PushL(self);
00057         self->ConstructL(aRect);
00058         return self;
00059         }
00060 
00061 // --------------------------------------------------------------------------
00062 // Destructor
00063 // --------------------------------------------------------------------------
00064 CFileStreamMainView::~CFileStreamMainView()
00065         {
00066         delete iEikEdwin;
00067         }
00068         
00069 // --------------------------------------------------------------------------
00070 // Second phase constructor
00071 // --------------------------------------------------------------------------
00072 void CFileStreamMainView::ConstructL(const TRect& aRect)
00073         {
00074         CreateWindowL();
00075         
00076         // Create an edwin on this control.
00077         iEikEdwin = new (ELeave) CEikEdwin();
00078         iEikEdwin->ConstructL(CEikEdwin::EReadOnly | CEikEdwin::ENoAutoSelection);
00079     iEikEdwin->SetContainerWindowL(*this);
00080         HBufC* message = ControlEnv()->AllocReadResourceLC(
00081                 R_FILESTREAM_TEXT);     
00082     iEikEdwin->SetTextL(message);
00083         CleanupStack::PopAndDestroy(message);
00084         
00085         SetRect(aRect);
00086         ActivateL();
00087         }
00088 
00089 // --------------------------------------------------------------------------
00090 // Sets the text to be displayed on this control.
00091 // --------------------------------------------------------------------------
00092 void CFileStreamMainView::SetTextL(const TDesC& aText)
00093         {
00094         if (iEikEdwin)
00095                 {
00096                 iEikEdwin->SetTextL(&aText);
00097                 DrawDeferred();
00098                 }
00099         }
00100 
00101 // --------------------------------------------------------------------------
00102 // Returns the number of controls.
00103 // In this example, it returns 1 because there is only one
00104 // control, which is an edwin control.
00105 // --------------------------------------------------------------------------
00106 TInt CFileStreamMainView::CountComponentControls() const
00107         {
00108         if (iEikEdwin)
00109                 {
00110                 return 1;
00111                 }
00112         return 0;
00113         }
00114 
00115 // --------------------------------------------------------------------------
00116 // Returns the pointer of the controls.
00117 // In this example, it returns the pointer of the edwin control.
00118 // --------------------------------------------------------------------------
00119 CCoeControl* CFileStreamMainView::ComponentControl(TInt aIndex) const
00120         {
00121         switch (aIndex)
00122                 {
00123                 case 0:
00124                         return iEikEdwin;
00125                 default:
00126                         break;
00127                 }
00128         return 0;
00129         }
00130 
00131 // --------------------------------------------------------------------------
00132 // Called when this control needs to be redrawn.
00133 // --------------------------------------------------------------------------
00134 void CFileStreamMainView::Draw(const TRect& /*aRect*/) const
00135         {
00136         CWindowGc& gc = SystemGc();
00137         gc.Clear();
00138         }
00139 
00140 // --------------------------------------------------------------------------
00141 // Called when the size/resolution of this control has been
00142 // changed. If this happens, the size of the edwin has to be
00143 // adjusted as well.
00144 // --------------------------------------------------------------------------
00145 void CFileStreamMainView::SizeChanged()
00146     {
00147     if (iEikEdwin)
00148                 {
00149                 TRect rect(Rect());
00150                 iEikEdwin->SetExtent(
00151                         TPoint(0, 0),
00152                         TSize(rect.Width(), rect.Height()));
00153                 }
00154     }
00155         
00156 // End of File

Generated by  doxygen 1.6.2