examples/Graphics/WS/Direct/Direct.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "CLifeEngine.h"
00017 #include "Direct.h"
00018 #include "CDirectDisplayLife.h"
00019 
00020 #include <eikenv.h>
00021 #include <eikmenub.h>
00022 
00023 #include <eikspane.h>
00024 
00025 #include <eikstart.h>
00026 
00027 //
00028 // CExampleAppView
00029 //
00030 
00031 CExampleAppView::CExampleAppView(CLifeEngine& aLifeEngine)
00032 : iLifeEngine(aLifeEngine)
00033         {
00034         }
00035 
00036 void CExampleAppView::ConstructL(const TRect& aRect)
00037         {
00038         // Create window
00039         CreateWindowL();
00040         SetRect(aRect);
00041 
00042         // Set up direct displayer for life engine
00043         iDirectDisplayLife = new (ELeave) CDirectDisplayLife (
00044                 iEikonEnv->WsSession(),         // Window server session
00045                 Window(),                                       // The window itself
00046                 iLifeEngine);
00047         iDirectDisplayLife -> ConstructL();
00048 
00049         ActivateL();
00050         }
00051 
00052 CExampleAppView::~CExampleAppView()
00053         {
00054         delete iDirectDisplayLife;
00055         }
00056 
00057 // Start using the DSA
00058 void CExampleAppView::StartDirectL()
00059         {
00060         iDirectDisplayLife -> StartL();
00061         iState = EDirectStarted;
00062         }
00063 
00064 // Pause use of the DSA
00065 void CExampleAppView::PauseDirect()
00066         {
00067         iState = EDirectPaused; 
00068         iDirectDisplayLife -> Cancel();
00069         }
00070 
00071 // Restart use of the DSA after pausing
00072 void CExampleAppView::RestartDirect()
00073         {
00074         iState = EDirectStarted;
00075         iDirectDisplayLife -> Restart(RDirectScreenAccess::ETerminateCancel);
00076         }
00077 
00078 // Gets the view state
00079 TInt CExampleAppView::State() const
00080         {
00081         return iState;
00082         }
00083 
00084 
00085 void CExampleAppView::Draw(const TRect& /*aRect*/) const
00086         {
00087         CWindowGc& gc = SystemGc();
00088         // white out whole rectangle
00089         TRect rect=Rect();
00090         gc.SetPenStyle(CGraphicsContext::ENullPen);
00091         gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00092         gc.SetBrushColor(KRgbWhite);
00093         gc.DrawRect(rect);
00094         // border
00095         rect.Shrink(10,10);
00096         gc.SetBrushStyle(CGraphicsContext::ENullBrush);
00097         gc.SetPenStyle(CGraphicsContext::ESolidPen);
00098         gc.DrawRect(rect);
00099         }
00100 
00101 
00102 //
00103 // CExampleAppUi
00104 //
00105 
00106 void CExampleAppUi::ConstructL()
00107         {
00108         BaseConstructL();
00109 
00110         // Construct the view
00111         iAppView=new(ELeave) CExampleAppView(static_cast<CExampleDocument*>(Document())->LifeEngine());
00112         iAppView->ConstructL(ClientRect());
00113 
00114         // Construct the example overlaying dialog
00115         iOverlayDialog = new (ELeave) COverlayDialog();
00116         CActiveScheduler::Add(iOverlayDialog);
00117         }
00118 
00119 CExampleAppUi::~CExampleAppUi()
00120         {
00121         delete iAppView;
00122         iOverlayDialog->Cancel();
00123         delete iOverlayDialog;
00124         }
00125 
00126 // Handle menu commands
00127 void CExampleAppUi::HandleCommandL(TInt aCommand)
00128         {
00129         switch (aCommand)
00130                 {
00131         // Start command
00132         case EExampleCmd1:
00133                 // Different action required for very first start
00134                 // And subsequent restarts
00135                 if (iAppView -> State() == CExampleAppView::EDirectNotStarted)
00136                         iAppView -> StartDirectL();
00137                 else
00138                         {
00139                         iAppView -> PauseDirect();
00140                         static_cast<CExampleDocument*>(Document())->LifeEngine().Reset();
00141                         iAppView -> RestartDirect();
00142                         }
00143                 break;
00144         // Test overlay command
00145         case EExampleCmd2:
00146                 iOverlayDialog->ShowDialog();
00147                 break;
00148         // Close command
00149         case EEikCmdExit: 
00150                 Exit();
00151                 break;
00152                 }
00153         }
00154 
00155 //
00156 // CExampleAppUi::COverlayDialog
00157 //
00158 
00159 CExampleAppUi::COverlayDialog::COverlayDialog()
00160 :CActive(EPriorityStandard)
00161         {
00162         iNotifier.Connect();
00163         }
00164 
00165 CExampleAppUi::COverlayDialog::~COverlayDialog()
00166         {
00167         Cancel();
00168         iNotifier.Close();
00169         }
00170 
00171 void CExampleAppUi::COverlayDialog::ShowDialog()
00172         {
00173         _LIT(KLine1,"Overlaying dialog");
00174         _LIT(KLine2,"Owned by another thread");
00175         _LIT(KBut,"OK");
00176 
00177         // Use a notifier to display a dialog from the notifier server thread
00178         iNotifier.Notify(KLine1,KLine2,KBut,KBut,iR,iStatus);
00179         SetActive();
00180         }
00181 
00182 void CExampleAppUi::COverlayDialog::RunL()
00183         {
00184         // Don't care what the dialog returned
00185         }
00186 
00187 void CExampleAppUi::COverlayDialog::DoCancel()
00188         {
00189         }
00190 
00191 //
00192 // CExampleDocument
00193 //
00194 
00195 CExampleDocument::CExampleDocument(CEikApplication& aApp)
00196                 : CEikDocument(aApp)
00197         {
00198         }
00199 
00200 CExampleDocument::~CExampleDocument()
00201         {
00202         delete iLifeEngine;
00203         }
00204 
00205 CLifeEngine& CExampleDocument::LifeEngine() const
00206         {
00207         return *iLifeEngine;
00208         }
00209 
00210 CEikAppUi* CExampleDocument::CreateAppUiL()
00211         {
00212         // Get a random seed from the timer
00213         User::After(1);
00214         TTime now;
00215         now.HomeTime();
00216 
00217         // Create engine
00218         iLifeEngine = new (ELeave) CLifeEngine(now.Int64());
00219         return new(ELeave) CExampleAppUi;
00220         }
00221 
00222 //
00223 // CExampleApplication
00224 //
00225 
00226 TUid CExampleApplication::AppDllUid() const
00227         {
00228         return KUidExample;
00229         }
00230 
00231 CApaDocument* CExampleApplication::CreateDocumentL()
00232         {
00233         return new (ELeave) CExampleDocument(*this);
00234         }
00235 
00236 //
00237 // DLL interface
00238 //
00239 
00240 EXPORT_C CApaApplication* NewApplication()
00241         {
00242         return new CExampleApplication;
00243         }
00244 
00245                                                                                 
00246 extern TInt E32Main()           
00247         {
00248         return EikStart::RunApplication(NewApplication);
00249         }

Generated by  doxygen 1.6.2