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

Generated by  doxygen 1.6.2