Nokia N97 SDK
Example Applications Guide

longtapdetectorexcontainer.cpp

00001 /**
00002  * Copyright (c) 2007 Nokia Corporation.
00003  * This material, including documentation and any related
00004  * computer programs, is protected by
00005  * copyright controlled by Nokia Corporation.
00006  */
00007 
00008 #include <coemain.h>
00009 #include <badesca.h> 
00010 #include <eiklabel.h> 
00011 #include <aknbutton.h> 
00012 #include <barsread.h>
00013 #include <longtapdetectorexample.rsg>
00014 #include <aknsdrawutils.h>
00015 #include <aknsbasicbackgroundcontrolcontext.h>
00016 #include <stringloader.h>
00017 
00018 #include "longtapdetectorexcontainer.h"
00019 
00020 
00021 // ============================== CONSTANTS ==================================
00022 
00023 // =========================== MEMBER FUNCTIONS ==============================
00024 
00025 
00026 // ---------------------------------------------------------------------------
00027 // C++ default Constructor
00028 // ---------------------------------------------------------------------------
00029 //
00030 CLongTapDetectorExContainer::CLongTapDetectorExContainer() : iLongTapCallbackReceived( EFalse )
00031     {
00032     }
00033 
00034 // ---------------------------------------------------------------------------
00035 // Destructor
00036 // ---------------------------------------------------------------------------
00037 //
00038 CLongTapDetectorExContainer::~CLongTapDetectorExContainer()
00039     {
00040 
00041     delete iLabel;
00042     delete iBgContext;
00043     delete iLongTapDetector;
00044     }
00045 
00046 // ---------------------------------------------------------------------------
00047 // Symbian 2nd Constructor
00048 // ---------------------------------------------------------------------------
00049 //
00050 void CLongTapDetectorExContainer::ConstructL( const TRect& aRect )
00051     {
00052     CreateWindowL();
00053     SetRect( aRect );
00054     iLongTapDetector = CAknLongTapDetector::NewL( this );
00055     // Label for showing messages    
00056     iLabel = new ( ELeave ) CEikLabel;
00057     iLabel->SetContainerWindowL( *this );
00058     iLabel->SetLabelAlignment( ELayoutAlignCenter );
00059     HBufC* appName = StringLoader::LoadL( R_LONGTAPDETECTOREX_APPNAME );  
00060     iLabel->SetTextL( *appName );
00061     delete appName;
00062     
00063     // Background context for skinned background
00064     iBgContext = CAknsBasicBackgroundControlContext::NewL( 
00065         KAknsIIDSkinBmpMainPaneUsual, TRect( 0, 0, 0, 0 ), ETrue 
00066     );
00067     iBgContext->SetRect( Rect() );
00068     iBgContext->SetParentPos( PositionRelativeToScreen() );
00069     SizeChanged();
00070     DrawableWindow()->SetPointerGrab( ETrue );
00071     EnableDragEvents();
00072     ActivateL();
00073     }
00074 
00075 // ---------------------------------------------------------------------------
00076 // CLongTapDetectorExContainer::Draw
00077 // ---------------------------------------------------------------------------
00078 //
00079 void CLongTapDetectorExContainer::Draw( const TRect& aRect ) const
00080     {
00081     // Draw background
00082     CWindowGc& gc = SystemGc();
00083                 
00084     MAknsSkinInstance* skin = AknsUtils::SkinInstance();
00085     if ( !AknsDrawUtils::Background( skin, iBgContext, gc, aRect ) )
00086         {
00087         SystemGc().Clear( aRect );
00088         }
00089     
00090     TRgb textColor = KRgbBlack;
00091     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), textColor,
00092         KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG55 );
00093     AknLayoutUtils::OverrideControlColorL( *iLabel, EColorLabelText, textColor );
00094     }
00095 
00096 // ---------------------------------------------------------------------------
00097 // CLongTapDetectorExContainer::CountComponentControls
00098 // ---------------------------------------------------------------------------
00099 //
00100 TInt CLongTapDetectorExContainer::CountComponentControls() const
00101     {
00102     TInt count ( 1 ); // iLabel
00103     // TODO
00104     return count;
00105     }
00106 
00107 // ---------------------------------------------------------------------------
00108 // CLongTapDetectorExContainer::ComponentControl
00109 // ---------------------------------------------------------------------------
00110 //
00111 CCoeControl* CLongTapDetectorExContainer::ComponentControl( TInt aIndex ) const
00112     {
00113     if ( aIndex == 0 )
00114         {
00115         return iLabel;
00116         }
00117     
00118     // TODO
00119         
00120     return NULL;
00121     }
00122 
00123 void CLongTapDetectorExContainer::SizeChanged()
00124     {
00125     if( iLabel )
00126         {
00127         iLabel->SetRect( TRect( TPoint(Rect().iTl.iX, Rect().iTl.iY + 35), TPoint(Rect().iBr.iX, Rect().iTl.iY + 75  ) ) );
00128         }
00129     DrawDeferred();
00130     }
00131 
00132 void CLongTapDetectorExContainer::HandleResourceChange( TInt aType )
00133     {
00134     CCoeControl::HandleResourceChange( aType );
00135     if  ( aType == KEikDynamicLayoutVariantSwitch )
00136         {
00137         TRect rect;
00138         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
00139         SetRect(rect);
00140         
00141         iBgContext->SetRect( Rect() );
00142         iBgContext->SetParentPos( PositionRelativeToScreen() );
00143         }
00144     }
00145 void CLongTapDetectorExContainer::HandlePointerEventL( const TPointerEvent& aEvent )
00146     {
00147     if ( AknLayoutUtils::PenEnabled() )
00148         {
00149         CCoeControl::HandlePointerEventL( aEvent );
00150     
00151         if( aEvent.iType == TPointerEvent::EButton1Down )
00152             {
00153             iLongTapCallbackReceived = EFalse;
00154             HBufC* appName = StringLoader::LoadLC( R_LONGTAPDETECTOREX_APPNAME );  
00155             iLabel->SetTextL( *appName );
00156             CleanupStack::PopAndDestroy();
00157             DrawDeferred();
00158          }
00159          
00160         if( aEvent.iType == TPointerEvent::EButton1Up && !iLongTapCallbackReceived )
00161             {
00162             HBufC* appName = StringLoader::LoadLC( R_LONGTAPDETECTOREX_SINGLETAP_RECEIVED );  
00163             iLabel->SetTextL( *appName );
00164             CleanupStack::PopAndDestroy();
00165             DrawDeferred();
00166             }
00167 
00168         iLongTapDetector->PointerEventL( aEvent );   
00169         }
00170     }
00171     
00172 void CLongTapDetectorExContainer::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/, 
00173                                       const TPoint& /*aPenEventScreenLocation*/ )
00174     {
00175     iLongTapCallbackReceived = ETrue;
00176     HBufC* labelText = StringLoader::LoadLC( R_LONGTAPDETECTOREX_CALLBACK_RECEIVED );  
00177     iLabel->SetTextL( *labelText );
00178     CleanupStack::PopAndDestroy();
00179     DrawDeferred();
00180     }

© Nokia 2009

Back to top