examples/Graphics/WS/Simple/Simple.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 #include "Simple.h"
00034 
00035 
00037 //                              Implementation for derived window classes
00039 
00041 //                                       CMainWindow implementation                                                     //
00043 
00044 /****************************************************************************\
00045 |       Function:       Constructor/Destructor for CMainWindow
00046 |                               Doesn't do much, as most initialisation is done by the
00047 |                               CWindow base class.
00048 |       Input:          aClient         Client application that owns the window
00049 \****************************************************************************/
00050 CMainWindow::CMainWindow (CWsClient* aClient)
00051 : CWindow (aClient)
00052         {
00053         }
00054 
00055 
00056 CMainWindow::~CMainWindow ()
00057         {
00058         }
00059 
00060 
00061 /****************************************************************************\
00062 |       Function:       CMainWindow::Draw
00063 |       Purpose:        Redraws the contents of CMainWindow within a given
00064 |                               rectangle. As CMainWindow has no contents, it simply
00065 |                               clears the redraw area. A blank window could be used here
00066 |                               instead. The Clear() is needed because a redraw should
00067 |                               always draw to every pixel in the redraw rectangle.
00068 |       Input:          aRect   Rectangle that needs redrawing
00069 |       Output:         None
00070 \****************************************************************************/
00071 void CMainWindow::Draw(const TRect& aRect)
00072         {
00073         CWindowGc* gc=SystemGc(); // get a gc
00074         gc->SetClippingRect(aRect); // clip outside this rect
00075         gc->Clear(aRect); // clear
00076         }
00077 
00078 /****************************************************************************\
00079 |       Function:       CMainWindow::HandlePointerEvent
00080 |       Purpose:        Handles pointer events for CMainWindow.  Doesn't do
00081 |                               anything here.
00082 |       Input:          aPointerEvent   The pointer event
00083 |       Output:         None
00084 \****************************************************************************/
00085 void CMainWindow::HandlePointerEvent (TPointerEvent& /*aPointerEvent*/)
00086         {
00087         }
00088 
00089 
00091 //                                       CSmallWindow implementation
00093 
00094 
00095 /****************************************************************************\
00096 |       Function:       Constructor/Destructor for CSmallWindow
00097 |                               Doesn't do much, as most initialisation is done by the
00098 |                               CWindow base class.
00099 |       Input:          aClient         Client application that owns the window
00100 \****************************************************************************/
00101 
00102 CSmallWindow::CSmallWindow (CWsClient* aClient)
00103 : CWindow (aClient)
00104         {
00105         }
00106 
00107 
00108 CSmallWindow::~CSmallWindow ()
00109         {
00110         iWindow.Close();
00111         }
00112 
00113 /****************************************************************************\
00114 |       Function:       CSmallWindow::Draw
00115 |       Purpose:        Redraws the contents of CSmallWindow within a given
00116 |                               rectangle.  CSmallWindow displays a square border around
00117 |                               the edges of the window, and two diagonal lines between the
00118 |                               corners.
00119 |       Input:          aRect   Rectangle that needs redrawing
00120 |       Output:         None
00121 \****************************************************************************/
00122 void CSmallWindow::Draw(const TRect& aRect)
00123         {
00124         // Drawing to a window is done using functions supplied by
00125         // the graphics context (CWindowGC), not the window.
00126         CWindowGc* gc=SystemGc(); // get a gc
00127         gc->SetClippingRect(aRect); // clip outside this rect
00128         gc->Clear(aRect); // clear
00129         TSize size=iWindow.Size();
00130         TInt width=size.iWidth;
00131         TInt height=size.iHeight;
00132         // Draw a square border
00133         gc->DrawLine(TPoint(0,0),TPoint(0,height-1));
00134         gc->DrawLine (TPoint (0, height-1), TPoint (width-1, height-1));
00135         gc->DrawLine(TPoint(width-1,height-1),TPoint(width-1,0));
00136         gc->DrawLine (TPoint (width-1, 0), TPoint (0, 0));
00137         // Draw a line between the corners of the window
00138         gc->DrawLine(TPoint(0,0),TPoint(width, height));
00139         gc->DrawLine (TPoint (0, height), TPoint (width, 0));
00140         }
00141 
00142 /****************************************************************************\
00143 |       Function:       CSmallWindow::HandlePointerEvent
00144 |       Purpose:        Handles pointer events for CSmallWindow.  Doesn't do
00145 |                               anything here.
00146 |       Input:          aPointerEvent   The pointer event
00147 |       Output:         None
00148 \****************************************************************************/
00149 
00150 void CSmallWindow::HandlePointerEvent (TPointerEvent& /*aPointerEvent*/)
00151         {
00152         }
00153 
00155 //                                       CExampleWsClient implementation                                                //
00157 
00158 CExampleWsClient* CExampleWsClient::NewL(const TRect& aRect)
00159         {
00160         // make new client
00161         CExampleWsClient* client=new (ELeave) CExampleWsClient(aRect);
00162         CleanupStack::PushL(client); // push, just in case
00163         client->ConstructL(); // construct and run
00164         CleanupStack::Pop();
00165         return client;
00166         }
00167 
00168 /****************************************************************************\
00169 |       Function:       Constructor/Destructor for CExampleWsClient
00170 |                               Destructor deletes everything that was allocated by
00171 |                               ConstructMainWindowL()
00172 \****************************************************************************/
00173 
00174 CExampleWsClient::CExampleWsClient(const TRect& aRect)
00175 :iRect(aRect)
00176         {
00177         }
00178 
00179 CExampleWsClient::~CExampleWsClient ()
00180         {
00181         delete iMainWindow;
00182         delete iSmallWindow;
00183         }
00184 
00185 
00186 /****************************************************************************\
00187 |       Function:       CExampleWsClient::ConstructMainWindowL()
00188 |                               Called by base class's ConstructL
00189 |       Purpose:        Allocates and creates all the windows owned by this client
00190 |                               (See list of windows in CExampleWsCLient declaration).
00191 \****************************************************************************/
00192 
00193 void CExampleWsClient::ConstructMainWindowL()
00194         {
00195         iMainWindow=new (ELeave) CMainWindow(this);
00196         iMainWindow->ConstructL(iRect);
00197         iSmallWindow  = new (ELeave) CSmallWindow (this);
00198         iSmallWindow->ConstructL (TRect (TPoint (100, 75), TSize (50, 50)), iMainWindow);
00199                 }
00200 
00201 
00202 /****************************************************************************\
00203 |       Function:       CExampleWsClient::RunL()
00204 |                               Called by active scheduler when an even occurs
00205 |       Purpose:        Processes events according to their type
00206 |                               For key events: calls HandleKeyEventL() (global to client)
00207 |                               For pointer event: calls HandlePointerEvent() for window
00208 |                                  event occurred in.
00209 \****************************************************************************/
00210 void CExampleWsClient::RunL()
00211         {
00212         // get the event
00213         iWs.GetEvent(iWsEvent);
00214         TInt eventType=iWsEvent.Type();
00215         // take action on it
00216         switch (eventType)
00217                 {
00218         // window-group related event types
00219         case EEventNull:
00220                 break;
00221         case EEventKey:
00222                 {
00223                 TKeyEvent& keyEvent=*iWsEvent.Key(); // get key event
00224                 HandleKeyEventL (keyEvent);
00225                 break;
00226                 }
00227         case EEventKeyUp:
00228         case EEventKeyDown:
00229         case EEventModifiersChanged:
00230         case EEventFocusLost:
00231         case EEventFocusGained:
00232         case EEventSwitchOn:
00233         case EEventPassword:
00234         case EEventWindowGroupsChanged:
00235         case EEventErrorMessage:
00236                 break;
00237         // window related events
00238         case EEventPointer:
00239                 {
00240                 CWindow* window=(CWindow*)(iWsEvent.Handle()); // get window
00241                 TPointerEvent& pointerEvent=*iWsEvent.Pointer();
00242                 window->HandlePointerEvent (pointerEvent);
00243 
00244                 break;
00245                 }
00246         case EEventPointerEnter:
00247         case EEventPointerExit:
00248         case EEventPointerBufferReady:
00249         case EEventDragDrop:
00250                 break;
00251         default:
00252                 break;
00253                 }
00254         IssueRequest(); // maintain outstanding request
00255         }
00256 
00257 void CExampleWsClient::HandleKeyEventL(struct TKeyEvent& /*aKeyEvent*/)
00258         {
00259         }

Generated by  doxygen 1.6.2