|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : focuseventappview.cpp 00004 * Part of : Focus event example 00005 * Interface : 00006 * Description : 00007 * Version : 00008 * 00009 * Copyright (c) 2004 - 2006 Nokia Corporation. 00010 * This material, including documentation and any related 00011 * computer programs, is protected by copyright controlled by 00012 * Nokia Corporation. 00013 * ============================================================================== 00014 */ 00015 00016 // INCLUDE FILES 00017 #include <hal.h> 00018 #include <eikenv.h> 00019 #include <AknUtils.h> 00020 00021 #include "FocusEventAppView.h" 00022 #include "EikonEnvironment.h" 00023 00024 // ============================ MEMBER FUNCTIONS =============================== 00025 00026 // ----------------------------------------------------------------------------- 00027 // CFocusEventAppView::CFocusEventAppView() 00028 // C++ default constructor can NOT contain any code, that might leave. 00029 // ----------------------------------------------------------------------------- 00030 // 00031 CFocusEventAppView::CFocusEventAppView() 00032 { 00033 // No implementation required 00034 } 00035 00036 // ----------------------------------------------------------------------------- 00037 // CFocusEventAppView::NewL() 00038 // Two-phased constructor. 00039 // ----------------------------------------------------------------------------- 00040 // 00041 CFocusEventAppView* CFocusEventAppView::NewL( const TRect& aRect ) 00042 { 00043 CFocusEventAppView* self = NewLC( aRect ); 00044 CleanupStack::Pop( self ); 00045 return self; 00046 } 00047 00048 // ----------------------------------------------------------------------------- 00049 // CFocusEventAppView::NewLC() 00050 // Two-phased constructor. 00051 // ----------------------------------------------------------------------------- 00052 // 00053 CFocusEventAppView* CFocusEventAppView::NewLC( const TRect& aRect ) 00054 { 00055 CFocusEventAppView* self = new ( ELeave ) CFocusEventAppView; 00056 CleanupStack::PushL( self ); 00057 self->ConstructL( aRect ); 00058 return self; 00059 } 00060 00061 // ----------------------------------------------------------------------------- 00062 // CFocusEventAppView::ConstructL() 00063 // Symbian 2nd phase constructor can leave. 00064 // ----------------------------------------------------------------------------- 00065 // 00066 void CFocusEventAppView::ConstructL( const TRect& aRect ) 00067 { 00068 // Create a window for this application view 00069 CreateWindowL(); 00070 00071 // Set the windows size 00072 SetRect( aRect ); 00073 00074 // Activate the window, which makes it ready to be drawn 00075 ActivateL(); 00076 00077 // Add the first blank line to the array of text lines 00078 User::LeaveIfError( iTextLines.Append( KNullDesC() ) ); 00079 } 00080 00081 // ----------------------------------------------------------------------------- 00082 // CFocusEventAppView::~CFocusEventAppView() 00083 // Destructor. 00084 // ----------------------------------------------------------------------------- 00085 // 00086 CFocusEventAppView::~CFocusEventAppView() 00087 { 00088 iTextLines.Close(); 00089 } 00090 00091 // ----------------------------------------------------------------------------- 00092 // CFocusEventAppView::Draw() 00093 // Draws the display. 00094 // ----------------------------------------------------------------------------- 00095 // 00096 void CFocusEventAppView::Draw( const TRect& /*aRect*/ ) const 00097 { 00098 00099 // Get the standard graphics context 00100 CWindowGc& gc = SystemGc(); 00101 00102 // Gets the control's extent 00103 TRect drawRect=Rect(); 00104 gc.UseFont( NEikonEnvironment::EikEnv().AnnotationFont() ); 00105 00106 // Clears the screen 00107 gc.Clear( drawRect ); 00108 00109 // Draw all lines of text 00110 TInt count; 00111 for ( count = 0; count < iTextLines.Count(); count++ ) 00112 { 00113 gc.DrawText( iTextLines[ count ], 00114 TPoint( KTextXMargin, KTextMinY+ 00115 ( count*KTextDistanceBetweenLines ) ) ); 00116 } 00117 } 00118 00119 // ----------------------------------------------------------------------------- 00120 // CFocusEventAppView::Print() 00121 // Show text on screen. 00122 // ----------------------------------------------------------------------------- 00123 // 00124 void CFocusEventAppView::Print( const TDesC& aText ) 00125 { 00126 ShowTextOnScreen( aText ); 00127 } 00128 00129 // ----------------------------------------------------------------------------- 00130 // CFocusEventAppView::ShowTextOnScreen() 00131 // Show text on screen. 00132 // ----------------------------------------------------------------------------- 00133 // 00134 void CFocusEventAppView::ShowTextOnScreen( const TDesC& aText ) 00135 { 00136 // Add the text line onto the last line 00137 TInt lastTextLine = iTextLines.Count() - 1; 00138 00139 // Make sure the text line doesn't get too long for the buffer. 00140 // This should really clip rather than not do anything 00141 // if the line is too long. 00142 if ( aText.Length() + iTextLines[ lastTextLine ].Length() 00143 <= KTestFrameworkMaxScreenMessageLength ) 00144 { 00145 iTextLines[ lastTextLine ].Append( aText ); 00146 DrawNow(); 00147 } 00148 } 00149 00150 // ----------------------------------------------------------------------------- 00151 // CFocusEventAppView::PrintNewLineL() 00152 // Print new line. 00153 // ----------------------------------------------------------------------------- 00154 // 00155 void CFocusEventAppView::PrintNewLineL() 00156 { 00157 // Add a new line onto the array 00158 // If the array is already at the maximum size, 00159 // delete the first line of text 00160 if ( iTextLines.Count() >= KMaxTextLines ) 00161 { 00162 iTextLines.Remove( 0 ); 00163 } 00164 User::LeaveIfError( iTextLines.Append( KNullDesC() ) ); 00165 DrawNow(); 00166 } 00167 00168 // --------------------------------------------------------- 00169 // CFocusEventAppView::HandleResourceChange() 00170 // Called by framework when layout is changed. 00171 // --------------------------------------------------------- 00172 // 00173 void CFocusEventAppView::HandleResourceChange(TInt aType) 00174 { 00175 CCoeControl::HandleResourceChange(aType); 00176 00177 // ADDED FOR SCALABLE UI SUPPORT 00178 // ***************************** 00179 if ( aType==KEikDynamicLayoutVariantSwitch ) 00180 { 00181 TRect rect; 00182 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect); 00183 SetRect(rect); 00184 } 00185 } 00186 // End of File
|
© Nokia 2009 |