⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aknexquerycontainer.cpp

📁 symbian ui的 例子 初学者可以 好好看看,这个是培训的资料,应该比较宝贵
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
* ==============================================================================
*  Name        : aknexquerycontainer.cpp
*  Part of     : Query example
*  Interface   :
*  Description :
*  Version     :
*
*  Copyright (c) 2004 - 2006 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ==============================================================================
*/

// INCLUDE FILES
#include <eikenv.h>
#include <eiklabel.h> // For label control
#include <eikclb.h>   // For listbox
#include <eiktxlbm.h> // For listbox model
#include <eikclbd.h>  // For listbox data
#include <aknlists.h> // For list pane
#include <aknpopup.h>
#include <aknpopupheadingpane.h>
#include <akniconarray.h>
#include <AknMessageQueryDialog.h> // for global message query
#include <aknglobalconfirmationquery.h> // for global message query
#include <StringLoader.h>
#include <avkon.hrh>
#include <avkon.rsg>
#include <AKNEXQUERY.mbg>
#include <AknListQueryDialog.h>
#include <AknExQuery.rsg>
#include "AknExQuery.hrh"
#include "AknExQueryView.h"
#include "AknExQueryContainer.h"
#include "AknExQueryTimeAndDurationListEventHandler.h"

// ================= MEMBER FUNCTIONS =========================================

// ----------------------------------------------------------------------------
// CAknExQueryContainer::CAknExQueryContainer()
// Overload constructor.
//-----------------------------------------------------------------------------
//
CAknExQueryContainer::CAknExQueryContainer( CAknExQueryView* aView )
: iView( aView )
    {
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::ConstructL()
// two phased constructor
//-----------------------------------------------------------------------------
//
void CAknExQueryContainer::ConstructL( const TRect& aRect )
    {
    // Creates window.
    CreateWindowL();

    // Creates label object.
    if ( !iLabel )
        {
        iLabel = new ( ELeave ) CEikLabel;
        iLabel->SetContainerWindowL( *this );
        if (AknLayoutUtils::Variant() == EApacVariant)
		    {
			iLabel->SetFont( ApacPlain16() );
		    }
		else
		    {
			iLabel->SetFont( LatinBold19() );
		    }

        SetTextToLabelL( R_AKNEXQUERY_TITLE_MESSAGE );
        }

    SetRect( aRect ); // Sets rectangle of frame.
    ActivateL(); // Activates the window. ( Ready to draw )
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::~CAknExQueryContainer()
// Destructor.
// ----------------------------------------------------------------------------
//
CAknExQueryContainer::~CAknExQueryContainer()
    {
    delete iLabel;
    delete iLabelResultMessage;
    delete iListBox;
    delete iHandler;

    delete iGlobalListQuery;
    delete iGlobalListObserver;
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::ShowConfirmationQueryL()
// Display of Confirmation Query.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::ShowConfirmationQueryL(
                             const TInt aResourceId,
                             const TInt aTextResourceId,
                             const TBool aPromptFlag,
                             const TBool aToneFlag,
                             const TBool aHeaderTextAndImageFlag,
                             const CAknQueryDialog::TTone aTone
                             )
    {
    iDisplayDialog = ETrue;
    SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE );
    CAknQueryDialog* dlg;

    if ( aHeaderTextAndImageFlag )
        {
        dlg = CAknQueryDialog::NewL( aTone );
        dlg->PrepareLC( aResourceId );
        TBuf<KAknExQueryTextBufLength> prompt;
        iCoeEnv->ReadResource( prompt, R_AKNEXQUERY_NUMQUERY_WITHHEAD_HEAD );
        dlg->QueryHeading()->SetTextL( prompt );
        SetIconL( dlg, EMbmAknexqueryAnchor_id, EMbmAknexqueryAnchor_id_mask );
        dlg->RunLD();
        }
    else
        {
        if ( !aTextResourceId )
            {
            dlg = CAknQueryDialog::NewL( aTone );
            }
        else
            {
            TBuf<KAknExQueryTextBufLength> prompt;
            iCoeEnv->ReadResource( prompt, aTextResourceId );

            if ( aPromptFlag )
                {
                dlg = CAknQueryDialog::NewL( aTone );
                CleanupStack::PushL( dlg );
                dlg->SetPromptL( prompt );
                CleanupStack::Pop();
                }
            else if ( aToneFlag )
                {
                dlg = new ( ELeave ) CAknQueryDialog( prompt, aTone );
                }
            else
                {
                dlg = new ( ELeave ) CAknQueryDialog( prompt );
                }
            }
        ShowResultMessageL( dlg->ExecuteLD( aResourceId ) );
        }
    iDisplayDialog = EFalse;
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::ShowResultMessageL()
// Display return value of dialog.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::ShowResultMessageL( TBool aResult )
    {
    TInt res( R_AKNEXQUERY_NO_OR_CANCEL_MESSAGE );

    if ( aResult )
        {
        res = R_AKNEXQUERY_YES_OR_OK_MESSAGE;
        }

    TBuf<KAknExQueryTextBufLength> messageConfirmationQuery;
    iCoeEnv->ReadResource( messageConfirmationQuery, res );

    ShowMessageL( messageConfirmationQuery );
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::ShowDataQueryL()
// Display of Data Query.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::ShowDataQueryL(
    const TInt aQueryResourceId,
    const TInt aTextResourceId,
    const TInt aPromptResourceId,
    const TInt aMaxLength,
    const TBool aDisplayFlag )
    {
    iDisplayDialog = ETrue;
    SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE );

    TBuf<KAknExQueryTextBufLength> textData;
    if ( aTextResourceId )
        {
        iCoeEnv->ReadResource( textData, aTextResourceId );
        }

    CAknTextQueryDialog* dlg;
    if ( !aPromptResourceId )
        {
        dlg = new ( ELeave )CAknTextQueryDialog(
            textData, CAknQueryDialog::ENoTone );
        }
    else
        {
        TBuf<KAknExQueryTextBufLength> prompt;
        iCoeEnv->ReadResource( prompt, aTextResourceId );
        dlg = CAknTextQueryDialog::NewL(
            textData, CAknQueryDialog::ENoTone );
        CleanupStack::PushL( dlg );
        dlg->SetPromptL( prompt );
        CleanupStack::Pop(); // dlg
        }

    if ( aMaxLength )
        {
        dlg->SetMaxLength( aMaxLength );
        }

    TBool answer( dlg->ExecuteLD( aQueryResourceId ) );

    if ( aDisplayFlag && answer )
        {
        iLabelResultMessage->SetTextL( textData );
        }

    iDisplayDialog = EFalse;

    DrawNow();
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::ShowListQueryL()
// Display of List Query.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::ShowListQueryL( const TInt aResourceId )
    {
    iDisplayDialog = ETrue;
    SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE );
    CArrayFixFlat<TInt>* indexArray = NULL;
    CAknListQueryDialog* dlg;
    TInt index( 0 );

    if ( aResourceId == R_AKNEXQUERY_MULTI_SELECTION_LIST_QUERY )
        {

        indexArray = new ( ELeave ) CArrayFixFlat<TInt>( 6 );
        CleanupStack::PushL( indexArray );
        dlg = new ( ELeave ) CAknListQueryDialog( indexArray );

        }
    else
        {
        dlg = new ( ELeave ) CAknListQueryDialog( &index );
        }

    TInt answer( dlg->ExecuteLD( aResourceId ) );

    TBuf<KAknExQueryTextBufLength> text;
    if ( aResourceId == R_AKNEXQUERY_LIST_QUERY )
        {
        if ( answer )
            {
            TBuf<KAknExQueryTextBufLength> baseText;
            iCoeEnv->ReadResource( baseText, R_AKNEXQUERY_ITEM_SELECTED );
            text.Format( baseText, index+1 );
            ShowMessageL( text );
            }
        else
            {
            iCoeEnv->ReadResource( text, R_AKNEXQUERY_QUERYDISCARDED );
            ShowMessageL( text );
            }
        }

    if ( indexArray )
        {
        CleanupStack::PopAndDestroy();
        }
    iDisplayDialog = EFalse;
    }


// ----------------------------------------------------------------------------
// CAknExQueryContainer::PopoutListBoxL()
// Create handler.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::PopoutListBoxL()
    {
    SetTextToLabelL( R_AKNEXQUERY_OPERATE_MESSAGE );

    CreateListBoxL();
    
    iHandler->HandleListBoxEventL(
            iListBox, MEikListBoxObserver::EEventEnterKeyPressed );
    }

// ----------------------------------------------------------------------------
// CAknExQueryContainer::CreateListBoxL()
// Creates listbox object.
// ----------------------------------------------------------------------------
//
void CAknExQueryContainer::CreateListBoxL()
    {
    DeleteListBoxL();

    TInt resourceId = R_AKNEXQUERY_MULTILINE_TIME_AND_DURATION_LIST_ITEM;
    iHandler = new ( ELeave ) CAknExQueryTimeAndDurationListEventHandler(
                    this );

    TInt flags( CEikListBox::EPopout | CEikListBox::ELeftDownInViewRect );
    iListBox = new ( ELeave ) CEikColumnListBox;
    iListBox->ConstructL( this, flags );

    iListBox->SetListBoxObserver( iHandler );
    iListBox->SetBorder( TGulBorder::EShallowRaised );
    iListBox->CreateScrollBarFrameL( ETrue );
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
        CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );

    // Creates list items

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -