Nokia N97 SDK
Example Applications Guide

tactileexamplesquare.cpp

00001 /*
00002 * ============================================================================
00003 *  Name        : tactileexamplesquare.cpp
00004 *  Part of     : Tactile Example
00005 *  Interface   : N/A
00006 *  Description : Implementation of square custom control
00007 *  Version     :
00008 *
00009 *  Copyright (c) 2008 Nokia Corporation.
00010 *  This material, including documentation and any related
00011 *  computer programs, is protected by copyright controlled by
00012 *  Nokia Corporation.
00013 * ============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <touchfeedback.h>
00018 #include <akndef.h>
00019 #include "tactileexamplesquare.h"
00020 
00021 
00022 // ============================ MEMBER FUNCTIONS =============================
00023 
00024 
00025 // ---------------------------------------------------------------------------
00026 // Two-phased constructor.
00027 // ---------------------------------------------------------------------------
00028 //
00029 CTactileExampleSquare* CTactileExampleSquare::NewL(
00030     const TRect& aRect, const CCoeControl* aParent )
00031     {
00032     CTactileExampleSquare* self = new ( ELeave ) CTactileExampleSquare;
00033     CleanupStack::PushL( self );
00034     self->ConstructL( aRect, aParent );
00035     CleanupStack::Pop( self );
00036     return self;
00037     }
00038 
00039 
00040 // ---------------------------------------------------------------------------
00041 // Destructor
00042 // ---------------------------------------------------------------------------
00043 //
00044 CTactileExampleSquare::~CTactileExampleSquare()
00045     {
00046     if ( iFeedback )
00047         {
00048         iFeedback->RemoveFeedbackForControl( this );
00049         }
00050     }
00051 
00052 
00053 // ---------------------------------------------------------------------------
00054 // Enables/disables feedback for this control
00055 // ---------------------------------------------------------------------------
00056 //
00057 void CTactileExampleSquare::EnableFeedback( TBool aEnabled )
00058     {
00059     iFeedback->EnableFeedbackForControl( this, aEnabled );
00060     }
00061 
00062 
00063 // ---------------------------------------------------------------------------
00064 // From class MCoeControlHitTest.
00065 // Tests whether a pointer event occurred inside the control's hit region
00066 // ---------------------------------------------------------------------------
00067 //
00068 TBool CTactileExampleSquare::HitRegionContains( const TPoint& aPoint,
00069       const CCoeControl& /*aControl*/ ) const
00070     {
00071     return IsVisible() ? Rect().Contains( aPoint ) : EFalse;
00072     }
00073 
00074 
00075 // ---------------------------------------------------------------------------
00076 // From class CCoeControl.
00077 //
00078 // ---------------------------------------------------------------------------
00079 //
00080 void CTactileExampleSquare::Draw( const TRect& /*aRect*/ ) const
00081     {
00082     CWindowGc& gc = SystemGc();
00083     gc.SetPenStyle( CGraphicsContext::ENullPen );
00084     gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
00085     gc.SetBrushColor( KRgbRed );
00086     gc.DrawRect( Rect() );
00087     }
00088 
00089 
00090 // ---------------------------------------------------------------------------
00091 // From class CCoeControl.
00092 // Updates feedback area to match new position of the control
00093 // ---------------------------------------------------------------------------
00094 //
00095 void CTactileExampleSquare::PositionChanged()
00096     {
00097     iFeedback->ChangeFeedbackArea( this, 0, Rect() );
00098     }
00099 
00100 
00101 // ---------------------------------------------------------------------------
00102 // From class CCoeControl.
00103 // Updates feedback area to match new size of the control
00104 // ---------------------------------------------------------------------------
00105 //
00106 void CTactileExampleSquare::SizeChanged()
00107     {
00108     iFeedback->SetFeedbackArea( this, 0, Rect(),
00109         ETouchFeedbackBasic, ETouchEventStylusDown );
00110     }
00111 
00112 
00113 // ---------------------------------------------------------------------------
00114 // C++ default constructor can NOT contain any code, that might leave.
00115 // ---------------------------------------------------------------------------
00116 //
00117 CTactileExampleSquare::CTactileExampleSquare()
00118     {
00119     // No implementation required
00120     }
00121 
00122 
00123 // ---------------------------------------------------------------------------
00124 // Symbian 2nd phase constructor can leave.
00125 // ---------------------------------------------------------------------------
00126 //
00127 void CTactileExampleSquare::ConstructL(
00128     const TRect& aRect, const CCoeControl* aParent )
00129     {
00130     // Get a pointer to touch feedback instance
00131     iFeedback = MTouchFeedback::Instance();
00132     User::LeaveIfNull( iFeedback );
00133 
00134     SetContainerWindowL( *aParent );
00135     SetRect( aRect );
00136     
00137     // Set hit tester to be object itself
00138     SetHitTest( this );
00139 
00140     // Set feedback area for this control
00141     iFeedback->SetFeedbackArea( this, 0, Rect(),
00142         ETouchFeedbackBasic, ETouchEventStylusDown );
00143 
00144     ActivateL();
00145     }

© Nokia 2009

Back to top