/* ============================================================================ Name : Placeads2AppView.cpp Author : Copyright : Your copyright notice Description : Application view implementation ============================================================================ */ // INCLUDE FILES #include #include "Placeads2AppView.h" #include #include // ============================ MEMBER FUNCTIONS =============================== // ----------------------------------------------------------------------------- // CPlaceads2AppView::NewL() // Two-phased constructor. // ----------------------------------------------------------------------------- // CPlaceads2AppView* CPlaceads2AppView::NewL(const TRect& aRect) { CPlaceads2AppView* self = CPlaceads2AppView::NewLC(aRect); CleanupStack::Pop(self); return self; } // ----------------------------------------------------------------------------- // CPlaceads2AppView::NewLC() // Two-phased constructor. // ----------------------------------------------------------------------------- // CPlaceads2AppView* CPlaceads2AppView::NewLC(const TRect& aRect) { CPlaceads2AppView* self = new (ELeave) CPlaceads2AppView; CleanupStack::PushL(self); self->ConstructL(aRect); return self; } // ----------------------------------------------------------------------------- // CPlaceads2AppView::ConstructL() // Symbian 2nd phase constructor can leave. // ----------------------------------------------------------------------------- // void CPlaceads2AppView::ConstructL(const TRect& aRect) { // Create a window for this application view CreateWindowL(); // Set the windows size SetRect(aRect); CreateWindowL(); InitComponentArrayL(); // Set the windows size SetRect( aRect ); // Activate the window, which makes it ready to be drawn ActivateL(); // Activate the window, which makes it ready to be drawn ActivateL(); } // ----------------------------------------------------------------------------- // CPlaceads2AppView::CPlaceads2AppView() // C++ default constructor can NOT contain any code, that might leave. // ----------------------------------------------------------------------------- // CPlaceads2AppView::CPlaceads2AppView() { inFocusedIndex = 0; ipCtrl = NULL; // No implementation required } // ----------------------------------------------------------------------------- // CPlaceads2AppView::~CPlaceads2AppView() // Destructor. // ----------------------------------------------------------------------------- // CPlaceads2AppView::~CPlaceads2AppView() { // No implementation required } // ----------------------------------------------------------------------------- // CPlaceads2AppView::Draw() // Draws the display. // ----------------------------------------------------------------------------- // void CPlaceads2AppView::Draw(const TRect& /*aRect*/) const { // Get the standard graphics context CWindowGc& gc = SystemGc(); // Gets the control's extent TRect drawRect(Rect()); // Clears the screen gc.Clear(drawRect); } // ----------------------------------------------------------------------------- // CPlaceads2AppView::SizeChanged() // Called by framework when the view size is changed. // ----------------------------------------------------------------------------- // void CPlaceads2AppView::SizeChanged() { UpdateControls(); DrawNow(); } // ----------------------------------------------------------------------------- // CPlaceads2AppView::HandlePointerEventL() // Called by framework to handle pointer touch events. // Note: although this method is compatible with earlier SDKs, // it will not be called in SDKs without Touch support. // ----------------------------------------------------------------------------- // void CPlaceads2AppView::HandlePointerEventL(const TPointerEvent& aPointerEvent) { // Call base class HandlePointerEventL() CCoeControl::HandlePointerEventL(aPointerEvent); } void CPlaceads2AppView::AddCustomControl(CAdControl* apCtrl) { CleanupStack::PushL(apCtrl); apCtrl->SetFocusing(ETrue); AddControlL(apCtrl,0); CleanupStack::Pop(); ipCtrl = apCtrl; TRect rcMainPane; AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rcMainPane ); SetRect(rcMainPane); } void CPlaceads2AppView::ReloadView() { if(ipCtrl && !ipCtrl->IsVisible()) ipCtrl->MakeVisible(ETrue); TRect rcMainPane; AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rcMainPane ); SetRect(rcMainPane); } void CPlaceads2AppView::AddControlL(CCoeControl* aControl,TInt aControlId) { // NOTE: Transfer ownership of CCoeControl to Container Control Components().AppendLC(aControl,aControlId); CleanupStack::Pop(aControl); if (Components().Count()==1) { inFocusedIndex = 0; aControl->SetFocus(ETrue); } Components().SortById(); // Sort components UpdateControls(); } void CPlaceads2AppView::UpdateControls() { TPoint position; position.iX = 10; position.iY = 30; // Goes throught all components of this container control CCoeControlArray::TCursor cursor = Components().Begin(); CCoeControl* ctrl = NULL; while ((ctrl = cursor.Control()) != NULL) { // If control is not visible does not handle it if (!ctrl->IsVisible()) { cursor.Next(); continue; } // Set position ctrl->SetPosition(position); // Set size TSize size = ctrl->MinimumSize(); //size.SetSize(Rect().Width(),size.iHeight); ctrl->SetSize(size); // Store position of last component position.iY += size.iHeight+30; // // Does control fit to view? // if (position.iY >= Rect().iBr.iY) // { // ctrl->MakeVisible(EFalse); // } // else // { // ctrl->MakeVisible(ETrue); // } if (!cursor.Next()) break; } } TKeyResponse CPlaceads2AppView::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType) { if(aType != EEventKey) return EKeyWasNotConsumed; TKeyResponse resp = EKeyWasNotConsumed; // Goes throught all components of this container control CCoeControlArray::TCursor cursor = Components().Begin(); CCoeControl* ctrl = NULL; while ((ctrl = cursor.Control()) != NULL) { // If control is not visible does not handle it if (!ctrl->IsVisible()) { cursor.Next(); continue; } resp = ctrl->OfferKeyEventL(aKeyEvent, aType); if(resp == EKeyWasConsumed) break; cursor.Next(); } if(resp == EKeyWasNotConsumed) return CCoeControl::OfferKeyEventL(aKeyEvent, aType); else return EKeyWasConsumed; } // End of File