examples/SFExamples/IRDevice/src/s60_3rd/IRDeviceMainView.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 // INCLUDES
00018 #include <eikedwin.h>
00019 #include <eikenv.h>
00020 #include <aknutils.h>
00021 #include <IRDevice.rsg>
00022 
00023 #include "IRDeviceMainView.h"
00024 
00025 // MEMBER FUNCTIONS
00026 
00027 // --------------------------------------------------------------------------
00028 // Two-phase constructor
00029 // --------------------------------------------------------------------------
00030 CIRDeviceMainView* CIRDeviceMainView::NewL(const TRect& aRect)
00031         {
00032         CIRDeviceMainView* self = CIRDeviceMainView::NewLC(aRect);
00033         CleanupStack::Pop(self);
00034         return self;
00035         }
00036 
00037 // --------------------------------------------------------------------------
00038 // Two-phase constructor
00039 // --------------------------------------------------------------------------
00040 CIRDeviceMainView* CIRDeviceMainView::NewLC(const TRect& aRect)
00041         {
00042         CIRDeviceMainView* self = new (ELeave) CIRDeviceMainView;
00043         CleanupStack::PushL(self);
00044         self->ConstructL(aRect);
00045         return self;
00046         }
00047 
00048 // --------------------------------------------------------------------------
00049 // Destructor
00050 // --------------------------------------------------------------------------
00051 CIRDeviceMainView::~CIRDeviceMainView()
00052         {
00053         delete iEikEdwin;
00054         }
00055         
00056 // --------------------------------------------------------------------------
00057 // Second phase constructor
00058 // --------------------------------------------------------------------------
00059 void CIRDeviceMainView::ConstructL(const TRect& aRect)
00060         {
00061         CreateWindowL();
00062         
00063         // Create an edwin on this control.
00064         iEikEdwin = new (ELeave) CEikEdwin();
00065         iEikEdwin->ConstructL(CEikEdwin::EReadOnly | CEikEdwin::ENoAutoSelection);
00066     iEikEdwin->SetContainerWindowL(*this);
00067         HBufC* message = CEikonEnv::Static()->AllocReadResourceLC(
00068                 R_IRDEVICE_TEXT);       
00069     iEikEdwin->SetTextL(message);
00070         CleanupStack::PopAndDestroy(message);
00071         
00072         SetRect(aRect);
00073         ActivateL();
00074         }
00075 
00076 // --------------------------------------------------------------------------
00077 // Sets the text to be displayed on this control.
00078 // --------------------------------------------------------------------------
00079 void CIRDeviceMainView::SetTextL(const TDesC& aText)
00080         {
00081         if (iEikEdwin)
00082                 {
00083                 iEikEdwin->SetTextL(&aText);
00084                 DrawDeferred();
00085                 }
00086         }
00087 
00088 // --------------------------------------------------------------------------
00089 // Returns the number of controls.
00090 // In this example, it returns 1 because there is only one
00091 // control, which is an edwin control.
00092 // --------------------------------------------------------------------------
00093 TInt CIRDeviceMainView::CountComponentControls() const
00094         {
00095         if (iEikEdwin)
00096                 {
00097                 return 1;
00098                 }
00099         return 0;
00100         }
00101 
00102 // --------------------------------------------------------------------------
00103 // Returns the pointer of the controls.
00104 // In this example, it returns the pointer of the edwin control.
00105 // --------------------------------------------------------------------------
00106 CCoeControl* CIRDeviceMainView::ComponentControl(TInt aIndex) const
00107         {
00108         switch (aIndex)
00109                 {
00110                 case 0:
00111                         return iEikEdwin;
00112                 default:
00113                         break;
00114                 }
00115         return 0;
00116         }
00117 
00118 // --------------------------------------------------------------------------
00119 // Called when this control needs to be redrawn.
00120 // --------------------------------------------------------------------------
00121 void CIRDeviceMainView::Draw(const TRect& /*aRect*/) const
00122         {
00123         CWindowGc& gc = SystemGc();
00124         gc.Clear();
00125         }
00126 
00127 // --------------------------------------------------------------------------
00128 // Called when the size/resolution of this control has been
00129 // changed. If this happens, the size of the edwin has to be
00130 // adjusted as well.
00131 // --------------------------------------------------------------------------
00132 void CIRDeviceMainView::SizeChanged()
00133     {
00134     if (iEikEdwin)
00135                 {
00136                 TRect rect(Rect());
00137                 iEikEdwin->SetExtent(
00138                         TPoint(0, 0),
00139                         TSize(rect.Width(), rect.Height()));
00140                 }
00141     }
00142         
00143 // End of File

Generated by  doxygen 1.6.2