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

📄 messages.cpp

📁 用于symbian手机的词典工具.绝对有用。
💻 CPP
字号:
/*
* MDictionary - dictionary program for Symbian cellular phones
*
* Copyright (C) 2005 Egyeki Gergely
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
*/
#include <eikenv.h>
#include <aknlistquerydialog.h>		//CAknListQueryDialog
#include <aknnotewrappers.h>		//CAknErrorNote
#include <StringLoader.h>			//StringLoader
#include <AknLists.h>				//the lists
#include <AknPopup.h>				//For the popup-list
#include <eikclbd.h>				//CFormattedCellListBoxData
#include <eikfrlbd.h>				//CFormattedCellListBoxItemDrawer

#include "MDictionary.hrh"
#include <MDictionary.rsg>
#include "messages.h"
#include "languages.h"

_LIT(KFormatter, "\t");
_LIT(KSeparator, "|");


TInt CMessages::ShowDicNotExisErrorL()
{
	//Error message
	TInt err = KErrNone;
	CAknErrorNote* errorNote = new ( ELeave ) CAknErrorNote( ETrue );
	errorNote->SetTimeout(CAknNoteDialog::ELongTimeout);
	errorNote->SetTone(CAknNoteDialog::EErrorTone);
	HBufC* aText = StringLoader::LoadLC( R_DIC_ERROR_TEXT );
	err = errorNote->ExecuteLD( *aText );
	CleanupStack::PopAndDestroy( aText );
	return err;
}


TInt CMessages::ShowEmptyErrorL()
{
	//Error message
	TInt err = KErrNone;
	CAknWarningNote* warningNote = new ( ELeave ) CAknWarningNote( EFalse );
	warningNote->SetTimeout(CAknNoteDialog::EShortTimeout);
	warningNote->SetTone(CAknNoteDialog::ENoTone);
	HBufC* aText = StringLoader::LoadLC( R_DIC_WARNING_TEXT );
	err = warningNote->ExecuteLD( *aText );
	CleanupStack::PopAndDestroy( aText );
	return err;
}



TInt CMessages::ShowSelectDicL(CDesC16ArraySeg* aDicList)
{ 
	TInt index(0);
	CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog(&index);
	query->PrepareLC(R_DICLIST_QUERY);
	CDesCArraySeg* tmpList = new (ELeave) CDesCArraySeg(aDicList->Count());
	for(TInt i=0; i<aDicList->Count(); i++) { tmpList->AppendL(aDicList->MdcaPoint(i)); }
	query->SetItemTextArray(tmpList);

	if( query->RunLD() )
	{
		return index;
	}
	else
	{
		return -1;
	}
}




TInt CMessages::ShowChangeDicL(CDesC16ArraySeg* aDicList)
{ 
	TInt index(0);
	CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog(&index);
	query->PrepareLC(R_DICLIST_REQUERY);
	CDesCArraySeg* tmpList = new (ELeave) CDesCArraySeg(aDicList->Count());
	for(TInt i=0; i<aDicList->Count(); i++) { tmpList->AppendL(aDicList->MdcaPoint(i)); }
	query->SetItemTextArray(tmpList);

	if( query->RunLD() )
	{
		return index;
	}
	else
	{
		return -1;
	}
}


void CMessages::ShowAboutPrgL()
{ 
	//ShowSingleItemPopupList
    // Create listbox and PUSH it.
    CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox;
    CleanupStack::PushL(list);
    // Create popup list and PUSH it.
    CAknPopupList* popupList = CAknPopupList::NewL(
                                        list, 
                                        R_AVKON_SOFTKEYS_OK_BACK,
                                        AknPopupLayouts::EDynMenuWindow);
    CleanupStack::PushL(popupList);
    // initialize listbox.
    list->ConstructL(popupList, EAknListBoxViewerFlag );
    list->CreateScrollBarFrameL(ETrue);
    list->ScrollBarFrame()->SetScrollBarVisibilityL(
                                CEikScrollBarFrame::EOn,
                                CEikScrollBarFrame::EAuto);

    // Make listitems. and PUSH it
	CDesCArrayFlat* items = 
		CCoeEnv::Static()->ReadDesCArrayResourceL(R_ABOUTPRG_MENU_ITEMS);
    CleanupStack::PushL(items);
    // Set listitems.
    CTextListBoxModel* model = list->Model();
    model->SetItemTextArray(items);
    model->SetOwnershipType(ELbmOwnsItemArray);
    CleanupStack::Pop();
    // Set title
	TBuf<TITLE_MAX_LENGTH> title;
	CCoeEnv::Static()->ReadResource(title, R_ABOUTPRG_MENU_TITLE);
    popupList->SetTitleL(title);
	popupList->ExecuteLD();
    CleanupStack::Pop();            // popuplist
    CleanupStack::PopAndDestroy();  // list
}




void CMessages::ShowAboutDicL(HBufC* aDicTitle1, HBufC* aDicTitle2, 
							  HBufC* aAuthors, HBufC* aVersion)
{ 
	//ShowSingleItemPopupList
    // Create listbox and PUSH it.
    CEikTextListBox* list = new(ELeave) CAknSinglePopupMenuStyleListBox;
    CleanupStack::PushL(list);
    // Create popup list and PUSH it.
    CAknPopupList* popupList = CAknPopupList::NewL(
                                        list,
                                        R_AVKON_SOFTKEYS_OK_BACK,
                                        AknPopupLayouts::EDynMenuWindow);
    CleanupStack::PushL(popupList);
    // initialize listbox.
    list->ConstructL(popupList, EAknListBoxViewerFlag );
    list->CreateScrollBarFrameL(ETrue);
    list->ScrollBarFrame()->SetScrollBarVisibilityL(
                                CEikScrollBarFrame::EOn,
                                CEikScrollBarFrame::EAuto);

    // Make listitems. and PUSH it
	CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(TITLE_MAX_LENGTH);
	//Titles
	TInt i = 0;
	TBuf<TITLE_MAX_LENGTH> ttitle;
	CCoeEnv::Static()->ReadResource(ttitle, R_ABOUTDIC_DICTIONARY_TITLE);
	items->InsertL(i, ttitle);
	i++;
	//Lang1
	items->InsertL(i, aDicTitle1->Des());
	i++;
	//Lang2
	items->InsertL(i, aDicTitle2->Des());
	i++;
	items->InsertL(i, _L(""));
	i++;
	//Authors
	TBuf<TITLE_MAX_LENGTH> atitle;
	CCoeEnv::Static()->ReadResource(atitle, R_ABOUTDIC_AUTHORS_TITLE);
	items->InsertL(i, atitle);
	i++;

	TInt pos;
	TBuf<KLangMaxLength> tmp;
	TBuf<KLangMaxLength> atmp = aAuthors->Des();
	TInt apos = atmp.Find(_L(","));
	while( apos != KErrNotFound )
	{
		tmp = atmp.Left( apos );
		pos = tmp.Find( _L("|") );
		items->InsertL(i, tmp.Left(pos));
		i++;
		tmp.Delete(0, pos+1);
		items->InsertL(i, tmp);
		i++;
		items->InsertL(i, _L(""));
		i++;
		atmp.Delete(0, apos+1);
		apos = atmp.Find(_L(","));
	}
	tmp.Delete(0, tmp.Length());
	tmp = atmp;
	pos = tmp.Find( _L("|") );
	items->InsertL(i, tmp.Left(pos));
	i++;
	tmp.Delete(0, pos+1);
	items->InsertL(i, tmp);
	i++;
	items->InsertL(i, _L(""));
	i++;
	//Version
	TBuf<TITLE_MAX_LENGTH> vtitle;
	CCoeEnv::Static()->ReadResource(vtitle, R_ABOUTDIC_VERSION_TITLE);
	items->InsertL(i, vtitle);
	i++;
	items->InsertL(i, aVersion->Des());

    CleanupStack::PushL(items);
    // Set listitems.
    CTextListBoxModel* model = list->Model();
    model->SetItemTextArray(items);
    model->SetOwnershipType(ELbmOwnsItemArray);
    CleanupStack::Pop();
    // Set title
	TBuf<TITLE_MAX_LENGTH> title;
	CCoeEnv::Static()->ReadResource(title, R_ABOUTDIC_MENU_TITLE);
    popupList->SetTitleL(title);
	popupList->ExecuteLD();
    CleanupStack::Pop();            // popuplist
    CleanupStack::PopAndDestroy();  // list
}



TInt CMessages::ShowPopUpSearchL()
{
	//ShowSingleItemPopupList
    CEikTextListBox* langPopUpList = new (ELeave) CAknSinglePopupMenuStyleListBox;
    CleanupStack::PushL(langPopUpList);
    // Create popup list and PUSH it.
    CAknPopupList* popupList = CAknPopupList::NewL( langPopUpList, 
                                     R_AVKON_SOFTKEYS_OK_BACK,   
                                     AknPopupLayouts::EMenuWindow);
    CleanupStack::PushL(popupList);
    // initialize listbox.
    langPopUpList->ConstructL(popupList, EAknListBoxSelectionList );
    langPopUpList->CreateScrollBarFrameL(ETrue);
    langPopUpList->ScrollBarFrame()->SetScrollBarVisibilityL(
                                CEikScrollBarFrame::EOn,
                                CEikScrollBarFrame::EAuto);
    // Make listitems. and PUSH it
    CDesCArrayFlat* items = 
		CCoeEnv::Static()->ReadDesCArrayResourceL(R_POPUP_MENU_ITEMS);
    CleanupStack::PushL(items);
    // Set listitems.
    CTextListBoxModel* model = langPopUpList->Model();
    model->SetItemTextArray(items);
    model->SetOwnershipType(ELbmOwnsItemArray);
	TInt res = popupList->ExecuteLD();
	TInt sInd = langPopUpList->CurrentItemIndex();
    CleanupStack::Pop();
    CleanupStack::Pop();  // popuplist
	CleanupStack::PopAndDestroy();  // list
	if( res > 0 ) { return sInd; }
	else { return -1; }
}



TInt CMessages::ShowSearchResultsL(CDesC16ArraySeg* aResultList, HBufC* aTitle, TInt aSource)
{
	TChar KSpace = TChar(32);		//Space
	TBuf<K2LangMaxLength> tmp;
	TBuf<KLangMaxLength> tmp1;
	TBuf<KLangMaxLength> lefttmp;
	TBuf<KLangMaxLength> rigthtmp;
	TInt pos;
	//ShowSingleItemPopupList
    CAknSinglePopupSubmenuStyleListBox* langPopUpList = 
		new (ELeave) CAknSinglePopupSubmenuStyleListBox();
    CleanupStack::PushL( langPopUpList );
    // Create popup list
    CAknPopupList* popupList = CAknPopupList::NewL( langPopUpList,
									R_AVKON_SOFTKEYS_OK_BACK,
									AknPopupLayouts::EMenuWindow);
    CleanupStack::PushL( popupList );
    // initialize listbox.
    langPopUpList->ConstructL(popupList, EAknListBoxViewerFlags);
    langPopUpList->CreateScrollBarFrameL(ETrue);
    langPopUpList->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOn,
									CEikScrollBarFrame::EAuto);
    // Make listitems.
	CDesCArraySeg* itemArray = new (ELeave) CDesCArraySeg( 4 * aResultList->Count() );
    CleanupStack::PushL( itemArray );

	for(TInt i=0; i<aResultList->Count(); i++)
	{
		tmp = aResultList->MdcaPoint(i);
		TInt delimPos = tmp.Find(KSeparator);
		lefttmp  = tmp.Left( delimPos );
		rigthtmp = tmp.Right( tmp.Length() - delimPos - 1 );
		lefttmp.TrimAll();
		rigthtmp.TrimAll();

		if( aSource == 0 )
		{
			tmp = lefttmp;
			while( tmp.Length() > KTextMaxLength )
			{
				tmp1 = tmp.Left( KTextMaxLength );
				pos = tmp1.LocateReverse( KSpace );
				tmp1 = tmp1.Left( pos );
				tmp1.Append( KFormatter );
				itemArray->AppendL( tmp1 );
				tmp.Delete(0, pos);
			}
			tmp.Append( KFormatter );
			itemArray->AppendL( tmp );

			tmp = rigthtmp;
			while( tmp.Length() > KTextMaxLength) 
			{
				tmp1 = tmp.Left( KTextMaxLength );
				pos = tmp1.LocateReverse( KSpace );
				tmp1 = tmp1.Left( pos );
				tmp1.Append( KFormatter );
				itemArray->AppendL( tmp1 );
				tmp.Delete(0, pos);
			}
			tmp.Append( KFormatter );
			itemArray->AppendL( tmp );
		}
		else
		{
			tmp = rigthtmp;
			while( tmp.Length() > KTextMaxLength) 
			{
				tmp1 = tmp.Left( KTextMaxLength );
				pos = tmp1.LocateReverse( KSpace );
				tmp1 = tmp1.Left( pos );
				tmp1.Append( KFormatter );
				itemArray->AppendL( tmp1 );
				tmp.Delete(0, pos);
			}
			tmp.Append( KFormatter );
			itemArray->AppendL( tmp );

			tmp = lefttmp;
			while( tmp.Length() > KTextMaxLength) 
			{
				tmp1 = tmp.Left( KTextMaxLength );
				pos = tmp1.LocateReverse( KSpace );
				tmp1 = tmp1.Left( pos );
				tmp1.Append( KFormatter );
				itemArray->AppendL( tmp1 );
				tmp.Delete(0, pos);
			}
			tmp.Append( KFormatter );
			itemArray->AppendL( tmp );
		}
		//to delimit the results
		tmp = _L("");
		tmp.Append( KFormatter );
		itemArray->AppendL( tmp );
	}

	//Adapt to screen
/*
	TInt scPos = 0;
	tmp1 = _L("");
	tmp1.Append( KFormatter );

	if( itemArray->Length() > 5 )
	{
		i = 0;
		while( i<itemArray->Length() )
		{
			tmp = itemArray->MdcaPoint(i);
			scPos++;
			i++;
			if( (scPos == 5)&&(tmp1.CompareC(itemArray->MdcaPoint(i)) == 0) )
			{
				itemArray->Delete(i);
				i--;
			}
			if( scPos == 5 ){ scPos = 0; }
		}
	}
*/
	itemArray->Compress();
	langPopUpList->Model()->SetItemTextArray(itemArray);
	//ownership of the item array is transferred to the listbox
    langPopUpList->Model()->SetOwnershipType(ELbmOwnsItemArray);
	langPopUpList->HandleItemAdditionL();

	//Changing font
/*	CFormattedCellListBoxItemDrawer* aDrawer = langPopUpList->ItemDrawer();
	CFormattedCellListBoxData* aData = aDrawer->FormattedCellData();
	const CFont* font = LatinPlain12();
//	const CFont* font = LatinBold12();
	for(TInt i=0; i<tmpArray->Count(); i++)
	{ 
		TSize sss = aData->SubCellSize(i);
		aData->SetSubCellFontL(i, font);
	}
*/
	popupList->SetTitleL( aTitle->Des() );
	TInt res = popupList->ExecuteLD();
	TInt sInd = langPopUpList->CurrentItemIndex();
    CleanupStack::Pop();	//tmpArray
    CleanupStack::Pop();  // popuplist
	CleanupStack::PopAndDestroy();  // list
	if( res > 0 ) { return sInd; }
	else { return -1; }
}


⌨️ 快捷键说明

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