📄 exercisecontainerview.cpp
字号:
/*
========================================================================
Name : ExerciseContainerView.cpp
Author :
Copyright : Your copyright notice
Description :
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <aknviewappui.h>
#include <eikmenub.h>
#include <avkon.hrh>
#include <barsread.h>
#include <stringloader.h>
#include <eiklabel.h>
#include <eikenv.h>
#include <akncontext.h>
#include <akntitle.h>
#include <eikbtgpc.h>
#include <Exercise.rsg>
// ]]] end generated region [Generated System Includes]
#include <aknquerydialog.h>
#include <aknnotewrappers.h>
#include <f32file.h>
#include <s32file.h>
#include <UTF.H> //转换
// [[[ begin generated region: do not modify [Generated User Includes]
#include "Exercise.hrh"
#include "ExerciseContainerView.h"
#include "ExeriseContainer.hrh"
#include "ExerciseListBox.hrh"
#include "ExerciseContainer.h"
// ]]] end generated region [Generated User Includes]
_LIT(KFileName,"C:\\Hello.txt");
// [[[ begin generated region: do not modify [Generated Constants]
// ]]] end generated region [Generated Constants]
/**
* First phase of Symbian two-phase construction. Should not contain any
* code that could leave.
*/
CExerciseContainerView::CExerciseContainerView()
{
// [[[ begin generated region: do not modify [Generated Contents]
iExerciseContainer = NULL;
// ]]] end generated region [Generated Contents]
}
/**
* The view's destructor removes the container from the control
* stack and destroys it.
*/
CExerciseContainerView::~CExerciseContainerView()
{
// [[[ begin generated region: do not modify [Generated Contents]
delete iExerciseContainer;
iExerciseContainer = NULL; /////
// ]]] end generated region [Generated Contents]
}
/**
* Symbian two-phase constructor.
* This creates an instance then calls the second-phase constructor
* without leaving the instance on the cleanup stack.
* @return new instance of CExerciseContainerView
*/
CExerciseContainerView* CExerciseContainerView::NewL()
{
CExerciseContainerView* self = CExerciseContainerView::NewLC();
CleanupStack::Pop( self );
return self;
}
/**
* Symbian two-phase constructor.
* This creates an instance, pushes it on the cleanup stack,
* then calls the second-phase constructor.
* @return new instance of CExerciseContainerView
*/
CExerciseContainerView* CExerciseContainerView::NewLC()
{
CExerciseContainerView* self = new ( ELeave ) CExerciseContainerView();
CleanupStack::PushL( self );
self->ConstructL();
return self;
}
/**
* Second-phase constructor for view.
* Initialize contents from resource.
*/
void CExerciseContainerView::ConstructL()
{
// [[[ begin generated region: do not modify [Generated Code]
BaseConstructL( R_EXERCISE_CONTAINER_EXERCISE_CONTAINER_VIEW );
// ]]] end generated region [Generated Code]
// add your own initialization code here
}
/**
* @return The UID for this view
*/
TUid CExerciseContainerView::Id() const //����ͼ�µ���ͼid,需要在hrh文件里枚举
{
return TUid::Uid( EExerciseContainerViewId );
}
/**
* Handle a command for this view (override)
@param aCommand command id to be handled
*/
void CExerciseContainerView::HandleCommandL( TInt aCommand )
{
// [[[ begin generated region: do not modify [Generated Code]
TBool commandHandled = EFalse;
switch ( aCommand )
{ // code to dispatch to the AknView's menu and CBA commands is generated here
case EAknSoftkeyDone:
AppUi()->HandleCommandL( EAknSoftkeyDone );
break;
case EExerciseContainerView_001MenuItemCommand:
AppUi()->HandleCommandL( EAknSoftkeyDone );
break;
case EExerciseContainerView_002MenuItemCommand://input
{
TBuf<100> Name;
RunDataQuery1L(Name,ETrue,NULL);//get the dialog
//name.Copy(Name);
TBuf8<200>name;
CnvUtfConverter::ConvertFromUnicodeToUtf8(name,Name);
//RunDataQuery1L(Name,ETrue,NULL);//get the dialog
//name.Copy(Name);
RFs afs;
RFile file;
User::LeaveIfError(afs.Connect()); //需建立与文件连接
CleanupClosePushL(afs);
TInt err=file.Open(afs,KFileName,EFileWrite);
if(err==KErrNotFound)
{
err=file.Create(afs,KFileName,EFileWrite);//if file hasn't exit,create it
}
TInt pos;
TInt temp=file.Size(pos);//pos stands for the positon of file's end
file.Seek(ESeekEnd,pos );//change the the file's start point.
file.Write(pos,name,name.Size());
file.Close();
afs.Close();
CleanupStack::PopAndDestroy();
}
break;
///***********////
case EExerciseContainerView_003MenuItemCommand:
{
RFs fs;
User::LeaveIfError(fs.Connect());
RFile file;
User::LeaveIfError(file.Open(fs, KFileName, EFileRead));
TBuf8<128> buf8;
file.Read(buf8);
HBufC* buf16=HBufC::NewLC(128);
TPtr ptr16=buf16->Des();
ptr16.Copy(buf8);
//HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( *buf16);
//TBuf<256> buf16;
//ConvGbk2Uni(buf8, buf16) ;
TInt Len=ptr16.Length();
for(TInt i=1;i<Len;i++)
{
ptr16.Delete(i,1);
Len=ptr16.Length();
}
fs.Close();
//CleanupStack::PopAndDestroy(3);
break;
/*
RFs fsSession;
RFile rFile;
// Connects a client process to the fileserver
User::LeaveIfError(fsSession.Connect());
CleanupClosePushL(fsSession);
//Open file where the stream text is
User::LeaveIfError(rFile.Open(fsSession,KFileName, EFileStreamText));//EFileShareReadersOnly));// EFileStreamText));
CleanupClosePushL(rFile);
// copy stream from file to RFileStream object
RFileReadStream inputFileStream(rFile);
CleanupClosePushL(inputFileStream);
// HBufC descriptor is created from the RFileStream object.
HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote;
// Show the information Note
informationNote->ExecuteLD( *fileData);
// Pop loaded resources from the cleanup stack
CleanupStack::PopAndDestroy(4); // filedata, inputFileStream, rFile, fsSession
fsSession.Close();
*/
}
default:
break;
}
if ( !commandHandled )
{
if ( aCommand == EAknSoftkeyExit )
{
AppUi()->HandleCommandL( EEikCmdExit );
}
}
// ]]] end generated region [Generated Code]
}
/**
* Handles user actions during activation of the view,
* such as initializing the content.
*/
void CExerciseContainerView::DoActivateL(
const TVwsViewId& /*aPrevViewId*/,
TUid /*aCustomMessageId*/,
const TDesC8& /*aCustomMessage*/ )
{
// [[[ begin generated region: do not modify [Generated Contents]
SetupStatusPaneL();
if ( iExerciseContainer == NULL )
{
iExerciseContainer = CreateContainerL();
iExerciseContainer->SetMopParent( this );
AppUi()->AddToStackL( *this, iExerciseContainer );
}
// ]]] end generated region [Generated Contents]
}
/**
*/
void CExerciseContainerView::DoDeactivate()
{
// [[[ begin generated region: do not modify [Generated Contents]
CleanupStatusPane();
if ( iExerciseContainer != NULL )
{
AppUi()->RemoveFromViewStack( *this, iExerciseContainer );
delete iExerciseContainer;
iExerciseContainer = NULL;
}
// ]]] end generated region [Generated Contents]
}
/**
* Handle status pane size change for this view (override)
*/
void CExerciseContainerView::HandleStatusPaneSizeChange()
{
CAknView::HandleStatusPaneSizeChange();
// this may fail, but we're not able to propagate exceptions here
TInt result;
TRAP( result, SetupStatusPaneL() );
// [[[ begin generated region: do not modify [Generated Code]
// ]]] end generated region [Generated Code]
}
// [[[ begin generated function: do not modify
void CExerciseContainerView::SetupStatusPaneL()
{
// reset the context pane
TUid contextPaneUid = TUid::Uid( EEikStatusPaneUidContext );
CEikStatusPaneBase::TPaneCapabilities subPaneContext =
StatusPane()->PaneCapabilities( contextPaneUid );
if ( subPaneContext.IsPresent() && subPaneContext.IsAppOwned() )
{
CAknContextPane* context = static_cast< CAknContextPane* > (
StatusPane()->ControlL( contextPaneUid ) );
context->SetPictureToDefaultL();
}
// setup the title pane
TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
StatusPane()->PaneCapabilities( titlePaneUid );
if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
{
CAknTitlePane* title = static_cast< CAknTitlePane* >(
StatusPane()->ControlL( titlePaneUid ) );
TResourceReader reader;
iEikonEnv->CreateResourceReaderLC( reader, R_EXERCISE_CONTAINER_TITLE_RESOURCE );
title->SetFromResourceL( reader );
CleanupStack::PopAndDestroy(); // reader internal state
}
}
// ]]] end generated function
// [[[ begin generated function: do not modify
void CExerciseContainerView::CleanupStatusPane()
{
}
// ]]] end generated function
/**
* Creates the top-level container for the view. You may modify this method's
* contents and the CExerciseContainer::NewL() signature as needed to initialize the
* container, but the signature for this method is fixed.
* @return new initialized instance of CExerciseContainer
*/
CExerciseContainer* CExerciseContainerView::CreateContainerL()
{
return CExerciseContainer::NewL( ClientRect(), NULL, this );
}
TInt CExerciseContainerView::RunDataQuery1L(//get a dialog and make data to aData
TDes& aData,
//HBufC& aData,
TBool aUseDefaults,
const TDesC* aOverridePrompt )
{
if ( aUseDefaults )
{
HBufC* text = StringLoader::LoadLC( R_EXERCISE_CONTAINER_EDIT1 );//load content from resourec's file
aData.Copy( *text );//get the data
CleanupStack::PopAndDestroy( text );
}
CAknTextQueryDialog* queryDialog = CAknTextQueryDialog::NewL( aData );
if ( aOverridePrompt != NULL )
{
CleanupStack::PushL( queryDialog );
queryDialog->SetPromptL( *aOverridePrompt );
CleanupStack::Pop();
}
return queryDialog->ExecuteLD( R_EXERCISE_CONTAINER_DATA_QUERY1 );//run it
}
/*case EExerciseContainerView_003MenuItemCommand:
{
RFs fs;
User::LeaveIfError(fs.Connect());
RFile file;
User::LeaveIfError(file.Open(fs, KFileName, EFileRead));
TBuf8<128> buf8;
//UTF8<128> ubuf8;
//TBuf8 buf8=static_cast<TBuf8>(ubf8);
file.Read(buf8);
HBufC* buf16=HBufC::NewLC(128); //tou guo zhe lai shengcheng dui duixiang
//TBuf16<128> buf16;
//CnvUtfConverter::ConvertToUnicodeFromUtf8(buf16,buf8);//::ConvertFromUnicodeToUtf8(name,Name);
TPtr ptr16=buf16->Des(); //只有指针描述符具有这种函数
ptr16.Copy(buf8);
//HBufC* fileData = HBufC::NewLC(inputFileStream, 32);
CAknInformationNote* informationNote;
informationNote = new ( ELeave ) CAknInformationNote; //弹出提示对话框
// Show the information Note
informationNote->ExecuteLD( *buf16); //*buf16 为描述符地址
//TBuf<256> buf16;
//ConvGbk2Uni(buf8, buf16) ;
TInt Len=ptr16.Length();
/*for(TInt i=1;i<Len;i++) //把描述符的内容删除,但只有这种方法么?
{
ptr16.Delete(i,1);
Len=ptr16.Length();
}/*/
/*ptr16.Delete(0,Len-1);
fs.Close();
//CleanupStack::PopAndDestroy(3); 什么时候需要这个命令
break;
}
default:
break;
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -