examples/Graphics/WS/BackedUp/Base.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 <w32std.h>
00017 #include "Base.h"
00018 
00020 //                                                      CWindow implementation
00022 
00023 CWindow::CWindow(CWsClient* aClient)
00024         : iClient(aClient)
00025         {
00026         }
00027 
00028 void CWindow::ConstructL (const TRect& aRect, const TRgb& aColor, CBackedUpWindow* aParent)
00029         {
00030         _LIT(KFontName,"Swiss");
00031         // If a parent window was specified, use it; if not, use the window group
00032         // (aParent defaults to 0).
00033         RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup);
00034         // Allocate and construct the window
00035         iWindow=RWindow(iClient->iWs);
00036         User::LeaveIfError(iWindow.Construct(*parent, (TUint32)this));
00037         // Store the window's extent
00038         iRect = aRect;
00039         // Set up the new window's extent
00040         User::LeaveIfError(iWindow.SetExtentErr(iRect.iTl, iRect.Size()));
00041         // Set its background color
00042         iWindow.SetBackgroundColor (aColor);
00043         // Set pointer grab to enable drag and drop
00044         iWindow.SetPointerGrab (ETrue);
00045         // Set up font for displaying text
00046         TFontSpec fontSpec(KFontName,200);
00047         User::LeaveIfError(iClient->iScreen->GetNearestFontInTwips(iFont,fontSpec));
00048         // Activate the window
00049         iWindow.Activate();
00050         }
00051 
00052 CWindow::~CWindow()
00053         {
00054         iWindow.FreePointerMoveBuffer();
00055         iWindow.Close();
00056         iClient->iScreen->ReleaseFont(iFont);
00057         }
00058 
00059 RWindow& CWindow::Window()
00060         {
00061         return iWindow;
00062         }
00063 
00064 CWindowGc* CWindow::SystemGc()
00065         {
00066         return iClient->iGc;
00067         }
00068 
00069 CWsScreenDevice* CWindow::Screen()
00070         {
00071         return iClient->iScreen;
00072         }
00073 
00074 CFont* CWindow::Font()
00075         {
00076         return iFont;
00077         }
00078 
00080 CBackedUpWindow::CBackedUpWindow(CWsClient* aClient)
00081         : iClient(aClient)
00082         {
00083         }
00084 
00085 void CBackedUpWindow::ConstructL (const TRect& aRect, CWindow* aParent)
00086         {
00087         _LIT(KFontName,"Swiss");
00088         // If a parent window was specified, use it; if not, use the window group
00089         // (aParent defaults to 0).
00090         RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup);
00091         // Allocate and construct the window
00092         iWindow=RBackedUpWindow(iClient->iWs);
00093         User::LeaveIfError(iWindow.Construct(*parent, EGray4, (TUint32)this));
00094         // Store the window's extent
00095         iRect = aRect;
00096         // Set up the new window's extent
00097         User::LeaveIfError(iWindow.SetExtentErr(iRect.iTl, iRect.Size()));
00098         // Set its background color
00099         iWindow.AllocPointerMoveBuffer(KPointerMoveBufferSize, 0);
00100         iWindow.DisablePointerMoveBuffer();
00101         iWindow.PointerFilter(EPointerFilterDrag, 0);
00102         // Set pointer grab to enable drag and drop
00103         iWindow.SetPointerGrab (ETrue);
00104         // Set up font for displaying text
00105         TFontSpec fontSpec(KFontName,200);
00106         User::LeaveIfError(iClient->iScreen->GetNearestFontInTwips(iFont,fontSpec));
00107         // Activate the window
00108         iWindow.Activate();
00109         }
00110 
00111 CBackedUpWindow::~CBackedUpWindow()
00112         {
00113         iWindow.Close();
00114         iClient->iScreen->ReleaseFont(iFont);
00115         }
00116 
00117 RBackedUpWindow& CBackedUpWindow::Window()
00118         {
00119         return iWindow;
00120         }
00121 
00122 CWindowGc* CBackedUpWindow::SystemGc()
00123         {
00124         return iClient->iGc;
00125         }
00126 
00127 CWsScreenDevice* CBackedUpWindow::Screen()
00128         {
00129         return iClient->iScreen;
00130         }
00131 
00132 CFont* CBackedUpWindow::Font()
00133         {
00134         return iFont;
00135         }
00136 
00137 
00139 //                                                      CWsRedrawer implementation
00141 
00142 CWsRedrawer::CWsRedrawer()
00143         : CActive(CActive::EPriorityLow)
00144         {
00145         }
00146 
00147 void CWsRedrawer::ConstructL(CWsClient* aClient)
00148         {
00149         iClient=aClient; // remember WsClient that owns us
00150         CActiveScheduler::Add(this); // add ourselves to the scheduler
00151         IssueRequest(); // issue request to draw
00152         }
00153 
00154 CWsRedrawer::~CWsRedrawer()
00155         {
00156         Cancel();
00157         }
00158 
00159 void CWsRedrawer::IssueRequest()
00160         {
00161         iClient->iWs.RedrawReady(&iStatus);
00162         SetActive();
00163         }
00164 
00165 void CWsRedrawer::DoCancel()
00166         {
00167         iClient->iWs.RedrawReadyCancel();
00168         }
00169 
00170 void CWsRedrawer::RunL()
00171         {       
00172         // find out what needs to be done in response to the event
00173         TWsRedrawEvent redrawEvent;
00174     iClient->iWs.GetRedraw(redrawEvent); // get event
00175         CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window
00176         if (window)
00177                 {
00178                 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing
00179                 // now do drawing
00180                 iClient->iGc->Activate(window->Window());
00181                 window->Window().BeginRedraw(rect);
00182                 window->Draw(rect);
00183                 window->Window().EndRedraw();
00184                 iClient->iGc->Deactivate();
00185                 }
00186         // maintain outstanding request
00187         IssueRequest();
00188         }
00189 
00190 
00192 //                                                              CWsClient implementation
00194 CWsClient::CWsClient()
00195         : CActive(CActive::EPriorityStandard)
00196         {
00197         }
00198 
00199 void CWsClient::ConstructL()
00200         {
00201         // add ourselves to active scheduler 
00202         CActiveScheduler::Add(this);
00203         // get a session going
00204         User::LeaveIfError(iWs.Connect());
00205         // construct our one and only window group
00206         iGroup=RWindowGroup(iWs);
00207         User::LeaveIfError(iGroup.Construct(2,ETrue)); // '2' is a meaningless handle
00208         // construct screen device and graphics context
00209         iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session
00210         User::LeaveIfError(iScreen->Construct()); // and complete its construction
00211         User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
00212         // construct redrawer
00213         iRedrawer=new (ELeave) CWsRedrawer;
00214         iRedrawer->ConstructL(this);
00215         // construct main window
00216         ConstructMainWindowL();
00217         // request first event and start scheduler
00218         IssueRequest();
00219         }
00220 
00221 CWsClient::~CWsClient()
00222         {
00223         // neutralize us as an active object
00224         Deque(); // cancels and removes from scheduler
00225         // get rid of everything we allocated
00226         delete iGc;
00227         delete iScreen;
00228         delete iRedrawer;
00229         // destroy window group
00230         iGroup.Close(); // what's the difference between this and destroy?
00231         // finish with window server
00232         iWs.Close();
00233         }
00234 
00235 void CWsClient::IssueRequest()
00236         {
00237         iWs.EventReady(&iStatus); // request an event
00238         SetActive(); // so we're now active
00239         }
00240 
00241 void CWsClient::DoCancel()
00242         {
00243         iWs.EventReadyCancel(); // cancel event request
00244         }
00245 
00246 void CWsClient::ConstructMainWindowL()
00247         {
00248         }
00249 

Generated by  doxygen 1.6.2