|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * ============================================================================== 00003 * Name : aknexnotecontainer.cpp 00004 * Part of : Note 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 <eiklabel.h> 00018 #include <e32math.h> 00019 #include <aknglobalnote.h> 00020 #include <aknwaitdialog.h> 00021 #include <aknexnote.rsg> 00022 #include <eikprogi.h> 00023 #include <aknnotecontrol.h> 00024 00025 #include "AknExNoteContainer.h" 00026 #include "AknExNoteView.h" 00027 #include "AknExNote.hrh" 00028 00029 // CONSTANTS 00030 #include "Aknexnoteconstants.h" 00031 00032 00033 // ========================= MEMBER FUNCTIONS ================================== 00034 00035 // ----------------------------------------------------------------------------- 00036 // CMultiViewsView2::CMultiViewsView2() 00037 // C++ default constructor can NOT contain any code, that might leave. 00038 // ----------------------------------------------------------------------------- 00039 // 00040 CAknExNoteContainer::CAknExNoteContainer( CAknExNoteView* aView ) 00041 : iLabel( NULL ), iView( aView ) 00042 00043 { 00044 // No implementation required 00045 } 00046 00047 00048 // ----------------------------------------------------------------------------- 00049 // CAknExNoteContainer::ConstructL() 00050 // Symbian 2nd phase constructor can leave. 00051 // ----------------------------------------------------------------------------- 00052 // 00053 void CAknExNoteContainer::ConstructL( const TRect& aRect ) 00054 { 00055 // Creates window. 00056 CreateWindowL(); 00057 00058 // Creates label object. 00059 CreateLabelL(); 00060 00061 // Sets rectangle of frame. 00062 SetRect( aRect ); 00063 00064 // Activates the window. (Ready to draw) 00065 ActivateL(); 00066 } 00067 00068 // ----------------------------------------------------------------------------- 00069 // CAknExNoteContainer::~CAknExNoteContainer() 00070 // Destructor. 00071 // ----------------------------------------------------------------------------- 00072 // 00073 CAknExNoteContainer::~CAknExNoteContainer() 00074 { 00075 delete iLabel; 00076 delete iIdle; 00077 } 00078 00079 // ----------------------------------------------------------------------------- 00080 // CAknExNoteContainer::SetTextToLabelL() 00081 // Sets text to Label 00082 // ----------------------------------------------------------------------------- 00083 // 00084 void CAknExNoteContainer::SetTextToLabelL( TInt aResourceId ) 00085 { 00086 //Allocate TBuf with constant length. 00087 TBuf<KAknExNoteMessageBufLength> messageString( NULL ); 00088 00089 // Reads a resource into a descriptor. 00090 iCoeEnv->ReadResource( messageString, aResourceId ); 00091 00092 // Set label's text with descriptor 00093 iLabel->SetTextL( messageString ); 00094 } 00095 00096 // ----------------------------------------------------------------------------- 00097 // CAknExNoteContainer::ShowGeneralNoteL() 00098 // Show General Note 00099 // ----------------------------------------------------------------------------- 00100 // 00101 void CAknExNoteContainer::ShowGeneralNoteL( TInt aResourceId, 00102 const CAknNoteDialog:: 00103 TTimeout aTimeout, 00104 const CAknNoteDialog::TTone aTone ) 00105 00106 { 00107 // Create CAknNoteDialog instance 00108 CAknNoteDialog* dlg = new ( ELeave ) CAknNoteDialog( aTone, aTimeout ); 00109 00110 // Show the Dialog 00111 dlg->ExecuteLD( aResourceId ); 00112 } 00113 00114 // ----------------------------------------------------------------------------- 00115 // CAknExNoteContainer::ShowGeneralNoteL() 00116 // Show General Note 00117 // ----------------------------------------------------------------------------- 00118 // 00119 void CAknExNoteContainer::ShowGeneralNoteL( TInt aResourceId, 00120 TInt /* aControlId */, const CAknNoteDialog::TTimeout aTimeout, 00121 const CAknNoteDialog::TTone aTone,TBool aPlural ) 00122 { 00123 00124 // Create CAknNoteDialog instance 00125 CAknNoteDialog* dlg = new ( ELeave ) CAknNoteDialog( aTone, aTimeout ); 00126 00127 dlg->PrepareLC( aResourceId ); 00128 dlg->SetTextPluralityL( aPlural ); 00129 00130 // Show the Dialog 00131 dlg->RunLD(); 00132 } 00133 00134 // ----------------------------------------------------------------------------- 00135 // CAknExNoteContainer::ShowDynamicNumberNoteL() 00136 // Show Dynamic Number Note 00137 // ----------------------------------------------------------------------------- 00138 // 00139 void CAknExNoteContainer::ShowDynamicNumberNoteL() 00140 { 00141 00142 // Create CAknNoteDialog instance 00143 CAknNoteDialog* dlg = new ( ELeave ) CAknNoteDialog( 00144 CAknNoteDialog::EConfirmationTone, 00145 CAknNoteDialog::ELongTimeout ); 00146 00147 dlg->PrepareLC( R_AKNEXNOTE_DYNAMIC_TEXT ); 00148 TTime theTime( KAknExNoteInitializeTime ); 00149 theTime.UniversalTime(); 00150 TInt64 randSeed( theTime.Int64() ); 00151 TInt number( Math::Rand( randSeed ) % KAknExNoteRandomNumberRange ); 00152 dlg->SetTextPluralityL( EFalse ); 00153 dlg->SetTextNumberL( number ); 00154 00155 // Show the Dialog 00156 dlg->RunLD(); 00157 } 00158 00159 // ----------------------------------------------------------------------------- 00160 // CAknExNoteContainer::ShowWaitNoteL() 00161 // Indicates wait note. 00162 // ----------------------------------------------------------------------------- 00163 // 00164 void CAknExNoteContainer::ShowWaitNoteL( TInt aResourceId, 00165 TInt /* aControlId */) 00166 { 00167 // Create CAknWaitDialog instance 00168 CAknWaitDialog* waitDialog = new ( ELeave ) CAknWaitDialog( NULL, ETrue ); 00169 00170 // Show the Dialog 00171 waitDialog->ExecuteLD( aResourceId ); 00172 } 00173 00174 // ----------------------------------------------------------------------------- 00175 // CAknExNoteContainer::ShowProgressNoteUnderSingleProcessL() 00176 // Show ProgressNote Under Single Process. 00177 // ----------------------------------------------------------------------------- 00178 // 00179 void CAknExNoteContainer::ShowProgressNoteUnderSingleProcessL( 00180 TInt aResourceId, 00181 TInt /* aControlId */) 00182 { 00183 // Delete possible previous CAknProgressDialog. 00184 delete iProgressDialog; 00185 00186 // Create new CAknProgressDialog. 00187 iProgressDialog = new ( ELeave ) CAknProgressDialog( reinterpret_cast 00188 <CEikDialog**> 00189 ( &iProgressDialog ) ); 00190 00191 iProgressDialog->SetCallback( this ); 00192 iProgressDialog->PrepareLC( aResourceId ); 00193 iProgressInfo = iProgressDialog->GetProgressInfoL(); 00194 iProgressInfo->SetFinalValue( KAknExNoteProgressbarFinalValue ); 00195 iProgressDialog->RunLD(); 00196 00197 delete iIdle; 00198 iIdle = CIdle::NewL( CActive::EPriorityStandard ); 00199 TCallBack callback( CallbackIncrementProgressNoteL, this ); 00200 iIdle->Start( callback ); 00201 } 00202 00203 // ----------------------------------------------------------------------------- 00204 // CAknExNoteContainer::ShowShowNoteL() 00205 // Show Note. 00206 // ----------------------------------------------------------------------------- 00207 // 00208 void CAknExNoteContainer::ShowShowNoteL( TAknGlobalNoteType aType, 00209 TInt aResourceId ) 00210 { 00211 //Allocate TBuf with constant length. 00212 TBuf<KAknExNoteTextBufLength> text( NULL ); 00213 00214 // Reads a resource into a descriptor. 00215 CEikonEnv::Static()->ReadResource( text, aResourceId ); 00216 00217 TPtrC noteText( text ); 00218 00219 // Create new CAknGlobalNote instance. 00220 CAknGlobalNote* globalNote = CAknGlobalNote::NewL(); 00221 00222 // Push CAknGlobalNote's pointer to CleanupStack 00223 CleanupStack::PushL( globalNote ); 00224 00225 iPermanentNoteId = globalNote->ShowNoteL( aType, noteText ); 00226 00227 // Pop and Destroy CAknGlobalNote's pointer from CleanupStack 00228 CleanupStack::PopAndDestroy(); 00229 } 00230 00231 // ----------------------------------------------------------------------------- 00232 // CAknExNoteContainer::CallbackIncrementProgressNoteL() 00233 // Just call UpdateProgressNote() function. 00234 // If return 1(ETrue), CIdle calls this again. 00235 // If retrun 0(EFalse), CIdle does not call this. 00236 // ----------------------------------------------------------------------------- 00237 // 00238 TInt CAknExNoteContainer::CallbackIncrementProgressNoteL( TAny* aThis ) 00239 { 00240 return static_cast<CAknExNoteContainer*>( aThis )->UpdateProgressNote(); 00241 } 00242 00243 // ----------------------------------------------------------------------------- 00244 // CAknExNoteContainer::UpdateProgressNote() 00245 // Updates ProgressNote 00246 // ----------------------------------------------------------------------------- 00247 // 00248 TInt CAknExNoteContainer::UpdateProgressNote() 00249 { 00250 TTime intervalTime; 00251 intervalTime.HomeTime(); 00252 intervalTime += TTimeIntervalMicroSeconds( 50000 ); 00253 TTime currentTime; 00254 currentTime.HomeTime(); 00255 00256 while ( intervalTime > currentTime ) 00257 { 00258 currentTime.HomeTime(); 00259 } 00260 00261 iProgressInfo->IncrementAndDraw( 1 ); 00262 if ( KAknExNoteProgressbarFinalValue <= iProgressInfo->CurrentValue() ) 00263 { 00264 iProgressDialog->ProcessFinishedL(); 00265 delete iProgressDialog; 00266 iProgressDialog = NULL; 00267 return 0; 00268 } 00269 return 1; 00270 } 00271 00272 // ----------------------------------------------------------------------------- 00273 // CAknExNoteContainer::DialogDismissedL() 00274 // Called when/if the dialog has been dismissed. 00275 // iIdle must be canceled when cancel button is pressed. 00276 // ----------------------------------------------------------------------------- 00277 // 00278 void CAknExNoteContainer::DialogDismissedL( TInt aButtonId ) 00279 { 00280 // Check when pressing cancel button. 00281 if ( aButtonId == -1 ) 00282 { 00283 delete iIdle; 00284 iIdle = NULL; 00285 } 00286 } 00287 00288 // ----------------------------------------------------------------------------- 00289 // CAknExNoteContainer::CreateLabelL() 00290 // Creates label object. 00291 // ----------------------------------------------------------------------------- 00292 // 00293 void CAknExNoteContainer::CreateLabelL() 00294 { 00295 if ( iLabel ) 00296 { 00297 delete iLabel; 00298 iLabel = NULL; 00299 } 00300 00301 // Create new CEikLabel instance 00302 iLabel = new ( ELeave ) CEikLabel; 00303 iLabel->SetContainerWindowL( *this ); 00304 iLabel->SetAlignment( EHCenterVCenter ); 00305 00306 // Set lablel's font 00307 iLabel->SetFont( LatinBold19() ); 00308 00309 // Set the Label's text from resource. 00310 SetTextToLabelL( R_AKNEXNOTE_TEXT_LABEL_TITLE ); 00311 } 00312 00313 // ----------------------------------------------------------------------------- 00314 // CAknExNoteContainer::OfferKeyEventL() 00315 // Handles the key events. 00316 // ----------------------------------------------------------------------------- 00317 // 00318 TKeyResponse CAknExNoteContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, 00319 TEventCode aType ) 00320 { 00321 // Is not key event? 00322 if ( aType != EEventKey ) 00323 { 00324 return EKeyWasNotConsumed; 00325 } 00326 00327 switch ( aKeyEvent.iCode ) 00328 { 00329 // Space key. 00330 case EKeySpace: 00331 00332 // Requires to display next outline screen. 00333 iView->DisplayNextOutlineL(); 00334 DrawNow(); 00335 break; 00336 00337 // Is list box created? 00338 default: 00339 return EKeyWasNotConsumed; 00340 } 00341 return EKeyWasConsumed; 00342 } 00343 00344 // ----------------------------------------------------------------------------- 00345 // CAknExNoteContainer::SizeChanged() 00346 // Called by framework when the view size is changed. 00347 // ----------------------------------------------------------------------------- 00348 // 00349 void CAknExNoteContainer::SizeChanged() 00350 { 00351 iLabel->SetRect( Rect() ); 00352 } 00353 00354 // ----------------------------------------------------------------------------- 00355 // CAknExNoteContainer::CountComponentControls() 00356 // Returns number of component. 00357 // ----------------------------------------------------------------------------- 00358 // 00359 TInt CAknExNoteContainer::CountComponentControls() const 00360 { 00361 // return nbr of controls inside this container 00362 TInt count( KAknExNoteComponentCount ); 00363 return count; 00364 } 00365 00366 // ----------------------------------------------------------------------------- 00367 // CAknExNoteContainer::ComponentControl() 00368 // Returns pointer to particular component. 00369 // ----------------------------------------------------------------------------- 00370 // 00371 CCoeControl* CAknExNoteContainer::ComponentControl( TInt aIndex ) const 00372 { 00373 switch ( aIndex ) 00374 { 00375 // Label object. 00376 case EAknExNoteComponentLabel: 00377 return iLabel; 00378 // Exception : returns NULL value. 00379 default: 00380 return NULL; 00381 } 00382 } 00383 00384 // ----------------------------------------------------------------------------- 00385 // CAknExNoteContainer::Draw() const 00386 // Clears the window's rectangle. 00387 // ----------------------------------------------------------------------------- 00388 // 00389 void CAknExNoteContainer::Draw( const TRect& aRect ) const 00390 { 00391 CWindowGc& gc = SystemGc(); 00392 gc.SetPenStyle( CGraphicsContext::ENullPen ); 00393 gc.SetBrushColor( KAknExNoteGray ); 00394 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); 00395 gc.DrawRect( aRect ); 00396 } 00397 00398 // End of File
|
© Nokia 2009 |