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

📄 heatmeter2container.cpp

📁 一个symbian操作系统的
💻 CPP
字号:
/*
* ============================================================================
*  Name     : CHeatMeter2Container from HeatMeter2Container.h
*  Part of  : HeatMeter2
*  Created  : 2004.03.27. by 
*  Implementation notes:
*     Initial content was generated by Series 60 AppWizard.
*  Version  :
*  Copyright: 
* ============================================================================
*/

// INCLUDE FILES

#include <eiklabel.h>  // for example label control
#include <aknlists.h>
#include <avkon.hrh>
#include <avkon.mbg>
#include <aknquerydialog.h> 
#include "aknnotewrappers.h"
#include  <HeatMeter2.rsg>

#include "HeatMeter2Container.h"
#include "DataBase.h"


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

// ---------------------------------------------------------
// CHeatMeter2Container::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CHeatMeter2Container::ConstructL(const TRect& aRect)
    {
    CreateWindowL();

	//construct the item array
	iServerAddr.Input(_L("1.1.1.1"));
	iItemArray = new (ELeave) CDesCArrayFlat(5);
	iValues=new (ELeave) CArrayFixFlat<TInt>(5);
	iIDs=new (ELeave) CArrayFixFlat<TInt>(5);
	iHeatMeterDatabase=CDataBase::NewL(this);


	//construct the listbox
    iListBox = new (ELeave) CAknDoubleStyleListBox;
    iListBox->SetContainerWindowL( *this );
	iListBox->ConstructL(this, EAknListBoxSelectionList);
	iListBox->Model()->SetOwnershipType(ELbmOwnsItemArray);
	iListBox->Model()->SetItemTextArray(iItemArray);

	//ask the database to fill the listbox
	FillListBox();

	//initialize icons
	CArrayPtr<CGulIcon>* icons = new (ELeave) CArrayPtrFlat<CGulIcon>(2);
	((CAknDoubleStyleListBox*)iListBox)->ItemDrawer()->FormattedCellData()->SetIconArray(icons);

	icons->AppendL(iEikonEnv->CreateIconL(_L("Z:\\system\\data\\avkon.mbm"), EMbmAvkonQgn_note_empty, EMbmAvkonQgn_note_empty_mask));
	icons->AppendL(iEikonEnv->CreateIconL(_L("Z:\\system\\data\\avkon.mbm"), EMbmAvkonQgn_indi_marked_add, EMbmAvkonQgn_indi_marked_add_mask));

	//create scrollbar
	iListBox->CreateScrollBarFrameL(ETrue);
	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

	iPermanentNoteId=-1;
    
	
	SetRect(aRect);
    ActivateL();
    }

// Destructor
CHeatMeter2Container::~CHeatMeter2Container()
    {
	delete iHeatMeterDatabase;
	delete iListBox;
	delete iValues;
	delete iIDs;
    }

// ---------------------------------------------------------
// CHeatMeter2Container::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CHeatMeter2Container::SizeChanged()
{
    // TODO: Add here control resize code etc.
	iListBox->SetRect(Rect());
}

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

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

// ---------------------------------------------------------
// CHeatMeter2Container::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CHeatMeter2Container::Draw(const TRect& aRect) const
    {
    CWindowGc& gc = SystemGc();
    // TODO: Add your drawing code here
    // example code...
    gc.SetPenStyle( CGraphicsContext::ENullPen );
    gc.SetBrushColor( KRgbGray );
    gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
    gc.DrawRect( aRect );
    }

// ---------------------------------------------------------
// CHeatMeter2Container::HandleControlEventL(
//     CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CHeatMeter2Container::HandleControlEventL(
    CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
    {
    // TODO: Add your control event handler code here
    }


// End of File  

TKeyResponse CHeatMeter2Container::OfferKeyEventL(const TKeyEvent &aKeyEvent, TEventCode aType)
{

	if (aType!=EEventKey) return EKeyWasNotConsumed;

    switch ( aKeyEvent.iCode )
    {
        case EKeyUpArrow:
        case EKeyDownArrow:
			{
				TKeyResponse result=iListBox->OfferKeyEventL( aKeyEvent, aType ); 
				return result;
			} break;
		case EKeyRightArrow:
			{
			} break;
		case EKeyLeftArrow:
			{
			} break;
		case 8: //C key
			{
			} break;
		default:
			return EKeyWasNotConsumed;
	}
    
	return EKeyWasNotConsumed;
}


//show a dialog in which the user can enter the state of the current heatmeter
void CHeatMeter2Container::EditCurrentValue()
{
	TInt currentItem(iListBox->CurrentItemIndex());
	if (currentItem<0) return;
	
	CDesCArray* array=(CDesCArray*)(iListBox->Model()->ItemTextArray());
	
	TBuf<100> addr;
	addr.Copy((*array)[currentItem].Mid(1));
	TInt secondTabLocation=addr.Locate('\t');
	addr.SetLength(secondTabLocation);
	
	TInt buf=0;
	CAknNumberQueryDialog* dlg = CAknNumberQueryDialog::NewL( buf, CAknQueryDialog::ENoTone );
	dlg->SetPromptL(addr);

	TInt result=dlg->ExecuteLD(R_HEATMETER_STATE_INPUT);
	if ((result==0) || (buf==0)) return;

	iValues->At(currentItem)=buf;
	iHeatMeterDatabase->UpdateItemValue(iIDs->At(currentItem), buf);

	//update the listbox with the new value
	FillListBox();

}

//forward the synch request to the database
void CHeatMeter2Container::Synch()
{
	NewGlobalNote(_L("Synchronising..."));
	TBuf<15> path=_L("/gaz/gaz");
	iHeatMeterDatabase->Synch(iServerAddr, path);
}

//greate a global wait note dialog
void CHeatMeter2Container::NewGlobalNote(TPtrC aNoteText)
{
	iGlobalNote = CAknGlobalNote::NewL();
	CleanupStack::PushL(iGlobalNote);
	iPermanentNoteId = iGlobalNote->ShowNoteL( EAknGlobalWaitNote, aNoteText);
	CleanupStack::PopAndDestroy(); // iGlobalNote

}

//destroy the global wait note dialog
void CHeatMeter2Container::DestroyGlobalNote()
{
	if (iPermanentNoteId!=-1)
	{
		CAknGlobalNote * note = CAknGlobalNote::NewL();
		CleanupStack::PushL(note);
		note->CancelNoteL(iPermanentNoteId);
		CleanupStack::PopAndDestroy();  // note
		iPermanentNoteId=-1;
	}

}

//fill the listbox with values from the database
void CHeatMeter2Container::FillListBox()
{
	iItemArray = new (ELeave) CDesCArrayFlat(5);
	iHeatMeterDatabase->FillArrays(iItemArray, iValues, iIDs);
	iListBox->Model()->SetItemTextArray(iItemArray);
	iListBox->HandleItemRemovalL();
	iListBox->HandleItemAdditionL();
}

//called when a synchronisation operation is ready
void CHeatMeter2Container::SynchReady()
{
	FillListBox();
	DestroyGlobalNote();
}


//called when a synchronisation operation has failed
void CHeatMeter2Container::SynchFailed(TInt aReason)
{
	FillListBox();
	DestroyGlobalNote();

	if (aReason==1) //server connection is OK, but error on server side
	{
		TRAPD(err, 
		  CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
          informationNote->ExecuteLD(_L("Synch failed due to error on server side.")); );
	}
	else
	{
		TRAPD(err, 
		  CAknInformationNote* informationNote = new (ELeave) CAknInformationNote;
          informationNote->ExecuteLD(_L("Synch Failed. Probably wrong server address.")); );
	}

}

⌨️ 快捷键说明

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