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

Generated by  doxygen 1.6.2