×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    12

    Passing data between two views

    Hello All ,
    I am new to this development , plz help me .

    My Application:
    Display a image and text in scrollable View2 when an item is selected in a Listbox in View1.

    Status: Till now i could place a list box , then select a item. and also i could display a image in View2. But , now my problem is i could not make the View2 scrollable and also am not able to display text with the image .

    Plz find my programm pasted here and kindly help me.

    Following are the Views :

    1> CListView
    CListConatiner
    2> CDataView
    CDataContainer

    #ifndef __LISTVIEW_H__
    #define __LISTVIEW_H__

    #include <aknview.h>
    #include <ListContainer.h>

    class CListContainer ;
    class CListView : public CAknView
    {
    public :
    static CListView* NewL( );
    static CListView* NewLC( );
    ~CListView();
    TInt GetCurrentItem();
    public :
    TUid Id() const;
    void HandleCommandL(TInt aCommand);
    void DoActivateL(const TVwsViewId& aPrevViewId,
    TUid aCustomMessageId,
    const TDesC8& aCustomMessage);
    void DoDeactivate();
    private:
    CListView();
    void ConstructL();
    public:
    CListContainer * iContainer ;
    TUid iIdentifier;
    TInt iCurrentItem;
    };

    #endif // __LISTVIEW_H__


    /* Copyright (c) 2004, Nokia Mobile Phones. All rights reserved */

    #include <aknviewappui.h>
    #include <avkon.hrh>
    #include <aknconsts.h>

    #include <Views.rsg>
    #include "ListView.h"
    #include "ListContainer.h"
    #include "Views.hrh"

    CListView* CListView::NewL( )
    {
    CListView* self = CListView::NewLC( );
    CleanupStack::Pop( self );
    return self;
    }

    CListView* CListView::NewLC()
    {
    CListView* self = new (ELeave) CListView();
    CleanupStack::PushL( self );
    self->ConstructL();
    return self;
    }

    CListView::CListView()
    {
    }
    CListView::~CListView()
    {
    }
    void CListView::ConstructL()
    {
    BaseConstructL( R_MULTIVIEWS_VIEW1 );
    }


    TUid CListView::Id( ) const
    {
    return TUid::Uid( EMultiViewsView1Id );
    }

    void CListView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
    TUid /*aCustomMessageId*/,
    const TDesC8& /*aCustomMessage*/)
    {
    ASSERT(!( iContainer ));
    iContainer = CListContainer::NewL( ClientRect( ) );
    }


    TInt CListView::GetCurrentItem()
    {
    iCurrentItem = iContainer->iCurrentItem;
    return iCurrentItem ;
    }

    void CListView::DoDeactivate()
    {
    if (iContainer)
    {
    AppUi()->RemoveFromStack( iContainer );
    delete iContainer ;
    iContainer = NULL ;
    }
    }

    void CListView::HandleCommandL(TInt aCommand)
    {

    if ( aCommand == EMultiViewsSwitchToView2)
    {
    AppUi()->ActivateLocalViewL( TUid::Uid( EMultiViewsView2Id ) );
    }
    else
    {
    AppUi()->HandleCommandL(aCommand);
    }
    }


    #ifndef LISTCONTAINER_H
    #define LISTCONTAINER_H

    // INCLUDES
    #include <coecntrl.h>
    #include <eiktxlbx.h>
    #include <eiktxlbm.h>
    #include <eiklabel.h>
    #include <barsread.h>

    // FORWARD DECLARATIONS
    class CEikLabel ; // for example labels
    class CEikTextListBox ;
    class CTextListBoxModel ;

    class CListContainer : public CCoeControl, MCoeControlObserver , public MEikListBoxObserver
    {
    public: // Constructors and destructor
    void StoreItemNo( TInt iCurrent);
    TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent , TEventCode aType );
    void ConstructL(const TRect& aRect);
    void ConstructControls();
    void GetOurMenu();
    void initListBox();
    void Setno();
    ~CListContainer();

    public:
    static CListContainer* NewL(const TRect& aRect);
    static CListContainer* NewLC(const TRect& aRect);

    public:
    void SizeChanged();
    TInt CountComponentControls() const;
    CCoeControl* ComponentControl(TInt aIndex) const;
    void Draw(const TRect& aRect) const;
    virtual void HandleListBoxEventL( CEikListBox * aListBox , TListBoxEvent aEventType );
    void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
    public:
    CEikTextListBox * iListBox;
    CDesCArray * itemDrive;
    CTextListBoxModel * modelDrive;
    TInt iCurrentItem;
    };
    #endif

    #include "ListContainer.h"
    #include <EikEnv.h>
    #include <Views.rsg>
    #include <Views.hrh>
    #include <eiklabel.h> // for example label control
    #include <aknlists.h>
    #include <aknviewappui.h>
    #include <aknappui.h>
    #include <ViewsAppUi.h>
    #include "DataContainer.h"
    TKeyResponse CListContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent , TEventCode aType )
    {
    if ( iListBox )
    {
    iListBox->UpdateScrollBarsL();
    return iListBox->OfferKeyEventL(aKeyEvent, aType);
    }
    return EKeyWasNotConsumed ;
    }

    void CListContainer::ConstructControls()
    {
    TRect rect ;
    rect = Rect();
    rect.Shrink( 20 ,20 );
    TSize size ;
    size.iHeight = rect.Height();
    size.iWidth = rect.Width();

    iListBox = new(ELeave) CEikTextListBox ;
    iListBox->SetContainerWindowL( *this );

    TResourceReader reader;
    CEikonEnv::Static()->CreateResourceReaderLC(reader,R_LISTBOX );
    iListBox->SetListBoxObserver(this);
    iListBox->ConstructFromResourceL(reader);
    iListBox->CreateScrollBarFrameL( ETrue );
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOn , CEikScrollBarFrame::EAuto );
    iListBox->SetExtent( TPoint( 10 , 10 ) , size );
    CleanupStack::PopAndDestroy( ); // Resource reader
    initListBox();
    }

    void CListContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    ConstructControls();
    SetRect(aRect);
    ActivateL();
    }


    CListContainer::~CListContainer()
    {
    delete iListBox ;
    }

    void CListContainer::StoreItemNo( TInt iCurrent)
    {
    iCurrentItem = iCurrent ;
    }

    void CListContainer::SizeChanged()
    {

    TRect rect ;
    rect = Rect();
    rect.Shrink( 0 ,20 );
    TSize size ;
    size.iHeight = rect.Height();
    size.iWidth = rect.Width();
    iListBox->SetExtent( TPoint( 0 ,0 ) , size );
    // iListBox->UpdateScrollBarsL();
    }

    TInt CListContainer::CountComponentControls() const
    {
    return 1; // return nbr of controls inside this container
    }


    CCoeControl* CListContainer::ComponentControl(TInt aIndex) const
    {
    switch ( aIndex )
    {
    case 0 :
    return iListBox;
    default:
    return NULL;
    }
    }

    CListContainer* CListContainer::NewL(const TRect& aRect)
    {
    CListContainer * self = CListContainer::NewLC(aRect);
    CleanupStack::Pop( self );
    return self ;
    }

    CListContainer* CListContainer::NewLC(const TRect& aRect)
    {
    CListContainer * self = new (ELeave) CListContainer;
    CleanupStack::PushL( self );
    self->ConstructL( aRect );
    return self;
    }

    void CListContainer::GetOurMenu()
    {
    TPtrC ourmenu[] = {
    _L("WHOPPER@Sandwiches") ,
    _L("Fire-Grilled Burgers") ,
    _L("Chicken and Fish") ,
    _L("Salads") ,
    _L("Breakfast") ,
    _L("Treats") ,
    _L("Sides and Beverages") ,
    _L("Kids Menu")
    };

    iListBox->Reset();
    itemDrive->Reset();

    for( int i = 0 ; i < 8 ; i++ )
    {
    TBuf<32> aBuff;
    aBuff.Append( ourmenu[ i ] );
    itemDrive->InsertL( i , aBuff );
    iListBox->HandleItemAdditionL();
    }
    iListBox->DrawNow( );
    }
    void CListContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbWhite ) ;
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

    // ---------------------------------------------------------
    // CListContainer::HandleControlEventL(
    // CCoeControl* aControl,TCoeEvent aEventType)
    // ---------------------------------------------------------
    //
    void CListContainer::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    }
    void CListContainer::initListBox()
    {
    itemDrive = new ( ELeave ) CDesCArrayFlat( 10 );
    modelDrive = iListBox->Model();
    modelDrive->SetItemTextArray( itemDrive );
    GetOurMenu();
    }

    void CListContainer::Setno()
    {
    this->iCurrentItem = iListBox->CurrentItemIndex();

    //TPtrC str = itemDrive->MdcaPoint( iCurrentItem );
    //StoreItemNo( iCurrentItem );
    // ((CDataView *)((CViewsAppUi *)(( CAknViewAppUi * )iEikonEnv->EikAppUi())))->iContainer->SetInt( iCurrentItem );
    }
    void CListContainer::HandleListBoxEventL( CEikListBox * aListBox , TListBoxEvent aEventType )
    {

    if((aListBox == iListBox) && ( aEventType == EEventItemClicked ) )
    {
    (( CViewsAppUi * )iEikonEnv->EikAppUi())->iCurrentItem = iListBox->CurrentItemIndex( );
    (( CAknViewAppUi * )iEikonEnv->EikAppUi())->ActivateLocalViewL( TUid::Uid( EMultiViewsView2Id ) );
    //Setno();
    }
    }

    Second View is posted in next post .

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    12

    Passing data between in views ( Continued .. )

    /* Copyright (c) 2004, Nokia Mobile Phones. All rights reserved */

    #include "DataContainer.h"
    #include <EikEnv.h>
    #include <palbimageviewerbasic.h>
    #include "ListView.h"
    #include <ViewsAppUi.h>
    #include <Views.rsg>

    #define KLeftImagePositionInTheText 28
    #define KRightImagePositionInTheText 42
    #define KEndofCenterFormat 60
    #define KLeftNokia 12
    #define KRightNokia 17
    // 567 twips == 1cm
    #define KKImageWidth 290
    #define KImageHeight 120

    CDataContainer* CDataContainer::NewL(const TRect& aRect)
    {
    CDataContainer* self = CDataContainer::NewLC(aRect);
    CleanupStack::Pop(self);
    return self;
    }

    CDataContainer* CDataContainer::NewLC(const TRect& aRect)
    {
    CDataContainer* self = new (ELeave) CDataContainer;
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
    }

    CDataContainer::~CDataContainer()
    {
    delete iImage ;
    delete iRtEd ;
    }

    void CDataContainer::WhopperSandwiches( const TRect& aRect )
    {
    iImage = CPAlbImageViewerBasic::NewL(this,TRect(TPoint( 15 , 15 ) , TSize(aRect.Width()-30,aRect.Height()-30)));
    iImage->SetImageNameAndDisplaymodeL( _L("c:\\Images\\water.png") , CEikonEnv::Static()->DefaultDisplayMode());
    iImage->LoadImageL();
    iRtEd = new(ELeave) CEikRichTextEditor;
    Prepare( );
    iRtEd->ConstructL(this,0,0,0);
    iRtEd->SetFocus(ETrue);
    SetRect( aRect );
    }

    void CDataContainer::FireGrilledBurgers( const TRect & aRect )
    {
    iImage = CPAlbImageViewerBasic::NewL( this , TRect(TPoint( 15 , 15 ), TSize(aRect.Width()-30 , aRect.Height()-30)) );
    iImage->SetImageNameAndDisplaymodeL( _L("c:\\Images\\coffee.png") , CEikonEnv::Static()->DefaultDisplayMode() );
    iImage->LoadImageL();
    iRtEd = new(ELeave) CEikRichTextEditor;
    Prepare( );
    iRtEd->ConstructL(this,0,0,0);
    iRtEd->SetFocus(ETrue);
    SetRect( aRect );
    }

    void CDataContainer::SetImageAndText( const TRect& aRect )
    {
    // TInt no = GetCurrentItem() ;
    TInt no = (( CViewsAppUi * )iEikonEnv->EikAppUi())->iCurrentItem;

    switch( no )
    {
    case 0:
    WhopperSandwiches( aRect );
    break ;
    case 1:
    FireGrilledBurgers( aRect );
    break ;
    case 2:

    break;
    default:
    WhopperSandwiches( aRect );
    }
    }

    void CDataContainer::ConstructL( const TRect& aRect )
    {
    CreateWindowL();
    SetRect(aRect);
    SetImageAndText( aRect );
    ActivateL( );
    }

    void CDataContainer::DemoL()
    {
    TBuf<256> Demobuf;
    CEikonEnv::Static()->ReadResource( Demobuf, R_TYPE_II_DIALOG_TBUF_DEMO_TEXT);
    iRtEd->SetTextL(&Demobuf);
    iRtEd->RichText()->InsertL( KLeftImagePositionInTheText , CEditableText::EParagraphDelimiter);
    iRtEd->SetSelectionL( KLeftImagePositionInTheText , KEndofCenterFormat );
    CParaFormat paraFormat;
    TParaFormatMask paraFormatMask;
    paraFormatMask.SetAttrib(EAttAlignment); // set the mask
    paraFormat.iHorizontalAlignment = CParaFormat::ECenterAlign;
    iRtEd->ApplyParaFormatL( &paraFormat , paraFormatMask );

    // Do some color change
    iRtEd->SetSelectionL( KLeftImagePositionInTheText , KRightImagePositionInTheText );
    TCharFormat charFormat ;
    TCharFormatMask charFormatMask ;
    charFormat.iFontPresentation.iTextColor=KRgbBlue;
    charFormatMask.SetAttrib(EAttColor );
    iRtEd->ApplyCharFormatL(charFormat, charFormatMask);
    iRtEd->SetSelectionL(KLeftNokia, KRightNokia);
    iRtEd->ApplyCharFormatL(charFormat, charFormatMask);

    // Insert a dot at the end
    iRtEd->RichText()->InsertL(iRtEd->Text()->DocumentLength()/* at the end*/,
    _L("."));
    }
    TInt CDataContainer::GetCurrentItem()
    {
    return (( CListView *)(( CViewsAppUi * )(( CAknViewAppUi * )iEikonEnv->EikAppUi())))->iContainer->iCurrentItem ;
    }
    void CDataContainer::Prepare()
    {
    iRtEd->SetAknEditorCase(EAknEditorLowerCase);
    iRtEd->SetAknEditorFlags
    (
    EAknEditorFlagFixedCase|
    EAknEditorFlagEnableScrollBars
    );

    }
    CDataContainer::CDataContainer()
    {
    }

    TInt CDataContainer::CountComponentControls() const
    {
    return 2;
    }

    void CDataContainer::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc( );
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbWhite );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

    CCoeControl* CDataContainer::ComponentControl( TInt aIndex ) const
    {
    switch( aIndex )
    {
    case 0 :
    return iImage ;
    case 1 :
    return iRtEd ;
    default :
    return NULL;
    }
    }

    #ifndef VIEWSAPPUI_H
    #define VIEWSAPPUI_H

    // INCLUDES
    #include <eikapp.h>
    #include <eikdoc.h>
    #include <e32std.h>
    #include <coeccntx.h>
    #include <aknappui.h>
    #include "DataView.h"
    #include "ListView.h"
    #include <aknviewappui.h>
    // FORWARD DECLARATIONS
    class CListContainer;


    // CLASS DECLARATION

    /**
    * Application UI class.
    * Provides support for the following features:
    * - EIKON control architecture
    *
    */
    class CViewsAppUi : public CAknViewAppUi
    {
    public:
    void ConstructL();
    ~CViewsAppUi();
    void GetCurrentItem();
    private:
    void DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane);
    private:
    void HandleCommandL(TInt aCommand);
    virtual TKeyResponse HandleKeyEventL(
    const TKeyEvent& aKeyEvent,TEventCode aType);

    public: //Data
    TInt iCurrentItem ;
    CDataView * idataview;
    CListView * ilistview;
    };

    #endif

    // End of File

    Help me .
    Thanks and Regards

  3. #3
    Super Contributor
    Join Date
    Apr 2003
    Location
    Czech Republic
    Posts
    915
    Hi, too long a code for me to go through all of it, but one thing striked me:
    Code:
    void CListContainer::ConstructControls()
    {
    TRect rect ;
    rect = Rect();
    ...
    }
    
    void CListContainer::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    ConstructControls();
    SetRect(aRect);
    ActivateL();
    }
    Please, try to call SetRect(aRect) before constructing the listbox, as Rect() now doesn't return the right rectangle....

    \

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    12

    Passing data between in views ( Continued .. )

    Thanks for replying but the actual problem i have is in passing data between views.
    Can u give me ur mail id , so that i can send u zip containing the application.
    Need help .
    Plz do the needful.
    Regards .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×