examples/Graphics/WS/Direct/Direct.cpp

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

Generated by  doxygen 1.6.2