examples/SFExamples/Graphics_Images/src/AboutContainer.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 #include <eiklabel.h>
00030 #include <eikenv.h>
00031 #include <eikrted.h> 
00032 
00033         #include <aknutils.h> 
00034 
00035 
00036 #include "AboutContainer.h"
00037 
00038 #include "TextControl.h"
00039 
00040 // static text used with the scrolling text control
00041 _LIT(KTxLongText        ,"This is could be very long text for copyright notices,it does not need to fit the screen since it is made scrolling with a timer.");
00042 
00043 _LIT(KTxTitle           ,"Images Example");
00044 _LIT(KTxLine1           ,"version 1.00");
00045 _LIT(KTxLine2           ,"Copyright 2007");
00046 _LIT(KTxLine3           ,"no rights reserved");
00047 
00048 /*
00049 -----------------------------------------------------------------------------
00050 -----------------------------------------------------------------------------
00051 */ 
00052 CAboutContainer* CAboutContainer::NewL( const TRect& aRect )
00053         {
00054         CAboutContainer* self = CAboutContainer::NewLC( aRect );
00055         CleanupStack::Pop( self );
00056         return self;
00057         }
00058 /*
00059 -----------------------------------------------------------------------------
00060 -----------------------------------------------------------------------------
00061 */ 
00062 CAboutContainer* CAboutContainer::NewLC( const TRect& aRect )
00063         {
00064         CAboutContainer* self = new ( ELeave ) CAboutContainer;
00065         CleanupStack::PushL( self );
00066         self->ConstructL( aRect );
00067         return self;
00068         }
00069 /*
00070 -----------------------------------------------------------------------------
00071 -----------------------------------------------------------------------------
00072 */ 
00073 CAboutContainer::~CAboutContainer()
00074         {
00075         delete iTextControl;
00076         }
00077 /*
00078 -----------------------------------------------------------------------------
00079 -----------------------------------------------------------------------------
00080 */      
00081 void CAboutContainer::ConstructL( const TRect& aRect )
00082         {
00083         CreateWindowL();
00084         SetRect( aRect );
00085         
00086         //construct the scrolling text control
00087         iTextControl = CTextControl::NewL(KTxLongText);
00088         
00089         // text control is non-window owning, thus we need to set 
00090         // this containers windor as a container window for it
00091         iTextControl->SetContainerWindowL(*this);
00092         
00093         TRect smallerRect(iTextRect);
00094         smallerRect.Shrink(4,4);
00095         // and give the reduced area as a rect for the control
00096         iTextControl->SetRect(smallerRect);
00097         
00098         ActivateL();
00099         }
00100 
00101 /*
00102 -----------------------------------------------------------------------------
00103 normal CCoeControl function used to tell system how many 
00104 controls this container has 
00105 -----------------------------------------------------------------------------
00106 */ 
00107 TInt CAboutContainer::CountComponentControls() const
00108         {
00109         if(iTextControl)
00110                 {   
00111                 return 1;
00112                 }
00113         else
00114                 {
00115                 return 0;
00116                 }
00117         }
00118 
00119 /*
00120 -----------------------------------------------------------------------------
00121 normal CCoeControl function used to give pointers 
00122 to the controls inside this container 
00123 -----------------------------------------------------------------------------
00124 */ 
00125 CCoeControl* CAboutContainer::ComponentControl( TInt /*aIndex */) const
00126         {
00127         return iTextControl;
00128         }
00129 /*
00130 -----------------------------------------------------------------------------
00131 normal Draw funtion for CCoeControl, which is used to draw to the screen
00132 -----------------------------------------------------------------------------
00133 */ 
00134 void CAboutContainer::Draw( const TRect& /*aRect*/ ) const
00135         {
00136         CWindowGc& gc = SystemGc();
00137         
00138         TRect myRect(Rect());
00139         
00140         // clear the area with default brush (solid white)
00141         gc.Clear(myRect);
00142         
00143         // make rect smaller and draw borders with default pen(solid black)
00144         myRect.Shrink(2,2);
00145         gc.DrawRect(myRect);
00146         
00147         // make sure we don't draw on the area for the text control
00148         myRect.iBr.iY = iTextRect.iTl.iY;
00149         
00150         TInt totalHNeed = (CEikonEnv::Static()->TitleFont()->HeightInPixels() + (CEikonEnv::Static()->LegendFont()->HeightInPixels() * 3));
00151         
00152         TInt gapp = ((myRect.Height() - totalHNeed) / 7);
00153         
00154         // set rects initially with total rect, so we get X values ok.
00155         TRect titleRect(myRect);
00156         TRect lineRect1(myRect);
00157         TRect lineRect2(myRect);
00158         TRect lineRect3(myRect);
00159         
00160         // then calculate the Y values
00161         titleRect.iTl.iY = titleRect.iTl.iY + (2 * gapp);
00162         titleRect.iBr.iY = (titleRect.iTl.iY  + CEikonEnv::Static()->TitleFont()->HeightInPixels());
00163         
00164         // title has 2 gaps before and after
00165         lineRect1.iTl.iY = titleRect.iBr.iY + (2 * gapp);
00166         lineRect1.iBr.iY = (lineRect1.iTl.iY  + CEikonEnv::Static()->LegendFont()->HeightInPixels());
00167 
00168         // and rest of the lines have only one gap each
00169         lineRect2.iTl.iY = lineRect1.iBr.iY + gapp;
00170         lineRect2.iBr.iY = (lineRect2.iTl.iY  + CEikonEnv::Static()->LegendFont()->HeightInPixels());
00171 
00172         lineRect3.iTl.iY = lineRect2.iBr.iY + gapp;
00173         lineRect3.iBr.iY = (lineRect3.iTl.iY  + CEikonEnv::Static()->LegendFont()->HeightInPixels());
00174 
00175         // set font for the title
00176         gc.UseFont(CEikonEnv::Static()->TitleFont());
00177 
00178         gc.DrawText(KTxTitle,titleRect,CEikonEnv::Static()->TitleFont()->AscentInPixels(), CGraphicsContext::ECenter, 0);
00179         
00180         // set font for the lines, this will Discard the title font
00181         gc.UseFont(CEikonEnv::Static()->LegendFont());
00182         
00183         gc.DrawText(KTxLine1,lineRect1,CEikonEnv::Static()->LegendFont()->AscentInPixels(), CGraphicsContext::ECenter, 0);
00184         gc.DrawText(KTxLine2,lineRect2,CEikonEnv::Static()->LegendFont()->AscentInPixels(), CGraphicsContext::ECenter, 0);
00185         gc.DrawText(KTxLine3,lineRect3,CEikonEnv::Static()->LegendFont()->AscentInPixels(), CGraphicsContext::ECenter, 0);
00186         
00187         // and finally let the system know that we are done with the font
00188         gc.DiscardFont();
00189         }
00190 
00191 
00192 
00193 /*
00194 -----------------------------------------------------------------------------
00195 used for informinging about resource changes, 
00196 in S60 one usage is to know when the layout of the screen has been changed
00197 -----------------------------------------------------------------------------
00198 */
00199 void CAboutContainer::HandleResourceChange(TInt aType)
00200         {
00201         TRect rect;
00202 
00203     if ( aType==KEikDynamicLayoutVariantSwitch )// layout change event
00204         {    // get new main panel rect and set it
00205         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00206         SetRect(rect);
00207         }
00208 
00209         // forward events for CCoeControl's base class handler
00210         CCoeControl::HandleResourceChange(aType);
00211         }
00212 
00213 /*
00214 -----------------------------------------------------------------------------
00215 system calls this function when the size for the container has been chnaged
00216 -----------------------------------------------------------------------------
00217 */ 
00218 void CAboutContainer::SizeChanged()
00219         {
00220 
00221         TInt fHight = AknLayoutUtils::FontFromId(EAknLogicalFontSecondaryFont)->HeightInPixels();
00222 
00223 
00224         // calculate the text controls hight to be twice the font hight
00225         TInt textHeight = (fHight * 2);
00226 
00227         // initialize control rects as container rect
00228         iTextRect = Rect();
00229         
00230         // then count the actual Y values (height, and vertical position)
00231         iTextRect.iTl.iY = (iTextRect.iBr.iY - textHeight);
00232 
00233         if(iTextControl)
00234                 {       // if tect control was made earlier, set the new rect for it
00235                 
00236                 TRect smallerRect(iTextRect);
00237                 smallerRect.Shrink(4,4);
00238                 iTextControl->SetRect(smallerRect);
00239                 }
00240         }
00241  
00242 
00243         
00244 // End of File

Generated by  doxygen 1.6.2