# examples/Graphics/WS/PtBuffer/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, CWindow* aParent)
    00029         {
    00030         // If a parent window was specified, use it; if not, use the window group
    00031         // (aParent defaults to 0).
    00032         RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->iGroup);
    00033         // Allocate and construct the window
    00034         iWindow=RWindow(iClient->iWs);
    00035         User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this));
    00036         // Store the window's extent
    00037         iRect = aRect;
    00038         // Set up the new window's extent
    00039         iWindow.SetExtent(iRect.iTl, iRect.Size());
    00040         // Set its background color
    00041         iWindow.SetBackgroundColor (aColor);
    00042         // Set pointer grab to enable drag and drop
    00043         iWindow.SetPointerGrab (ETrue);
    00044         // Allocate pointer move buffer for freehand drawing
    00045         iWindow.AllocPointerMoveBuffer(KPointerMoveBufferSize, 0);
    00046         iWindow.DisablePointerMoveBuffer();
    00047         // Tell the window server to deliver drag events
    00048         iWindow.PointerFilter(EPointerFilterDrag, 0);
    00049         // Activate the window
    00050         iWindow.Activate();
    00051         }
    00052
    00053 CWindow::~CWindow()
    00054         {
    00055         iWindow.FreePointerMoveBuffer();
    00056         iWindow.Close();
    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
    00075 //                                                      CWsRedrawer implementation
    00077
    00078 CWsRedrawer::CWsRedrawer()
    00079         : CActive(CActive::EPriorityLow)
    00080         {
    00081         }
    00082
    00083 void CWsRedrawer::ConstructL(CWsClient* aClient)
    00084         {
    00085         iClient=aClient; // remember WsClient that owns us
    00086         CActiveScheduler::Add(this); // add ourselves to the scheduler
    00087         IssueRequest(); // issue request to draw
    00088         }
    00089
    00090 CWsRedrawer::~CWsRedrawer()
    00091         {
    00092         Cancel();
    00093         }
    00094
    00095 void CWsRedrawer::IssueRequest()
    00096         {
    00097         iClient->iWs.RedrawReady(&iStatus);
    00098         SetActive();
    00099         }
    00100
    00101 void CWsRedrawer::DoCancel()
    00102         {
    00103         iClient->iWs.RedrawReadyCancel();
    00104         }
    00105
    00106 void CWsRedrawer::RunL()
    00107         {
    00108         // find out what needs to be done in response to the event
    00109         TWsRedrawEvent redrawEvent;
    00110     iClient->iWs.GetRedraw(redrawEvent); // get event
    00111         CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window
    00112         if (window)
    00113                 {
    00114                 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing
    00115                 // now do drawing
    00116                 iClient->iGc->Activate(window->Window());
    00117                 window->Window().BeginRedraw();
    00118                 window->Draw(rect);
    00119                 window->Window().EndRedraw();
    00120                 iClient->iGc->Deactivate();
    00121                 }
    00122         // maintain outstanding request
    00123         IssueRequest();
    00124         }
    00125
    00126
    00128 //                                                              CWsClient implementation
    00130 CWsClient::CWsClient()
    00131         : CActive(CActive::EPriorityStandard)
    00132         {
    00133         }
    00134
    00135 void CWsClient::ConstructL()
    00136         {
    00137         // add ourselves to scheduler
    00138         CActiveScheduler::Add(this);
    00139         // get a session going
    00140         User::LeaveIfError(iWs.Connect());
    00141         // construct our one and only window group
    00142         iGroup=RWindowGroup(iWs);
    00143         User::LeaveIfError(iGroup.Construct(2,ETrue)); // '2' is a meaningless handle
    00144         // construct screen device and graphics context
    00145         iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session
    00146         User::LeaveIfError(iScreen->Construct()); // and complete its construction
    00147         User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
    00148         // construct redrawer
    00149         iRedrawer=new (ELeave) CWsRedrawer;
    00150         iRedrawer->ConstructL(this);
    00151         // construct main window
    00152         ConstructMainWindowL();
    00153         // request first event and start scheduler
    00154         IssueRequest();
    00155         }
    00156
    00157 CWsClient::~CWsClient()
    00158         {
    00159         // neutralize us as an active object
    00160         Deque(); // cancels and removes from scheduler
    00161         // get rid of everything we allocated
    00162         delete iGc;
    00163         delete iScreen;
    00164         delete iRedrawer;
    00165         // destroy window group
    00166         iGroup.Close();
    00167         // finish with window server
    00168         iWs.Close();
    00169         }
    00170
    00171 void CWsClient::IssueRequest()
    00172         {
    00173         iWs.EventReady(&iStatus); // request an event
    00174         SetActive(); // so we're now active
    00175         }
    00176
    00177 void CWsClient::DoCancel()
    00178         {
    00179         iWs.EventReadyCancel(); // cancel event request
    00180         }
    00181
    00182 void CWsClient::ConstructMainWindowL()
    00183         {
    00184         }
    00185