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

📄 mdictionaryappui.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 FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>		// CAknErrorNote
#include <stringloader.h>
#include <MDictionary.rsg>
#include <AknWaitNoteWrapper.h>		// CAknWaitNoteWrapper
#include <AknWaitDialog.h>			// for the wait dialog

#include "MDictionary.pan"
#include "MDictionaryAppUi.h"
#include "MDictionaryAppView1.h"
#include "MDictionaryAppView2.h"
#include "MDictionary.hrh"
#include "MDictionaryDocument.h"
#include "SettingsData.h"

#include "Dbhandler.h"
#include "Messages.h"



CMDictionaryAppUi::CMDictionaryAppUi():iDecoratedTabGroup(NULL)
{
}


CMDictionaryAppUi::~CMDictionaryAppUi()
{
	delete iDecoratedTabGroup;
	iDecoratedTabGroup = NULL;
}


void CMDictionaryAppUi::ConstructL()
{
	BaseConstructL(EAknEnableSkin);
	//TabGroup
	CreateTabGroupL();
	//iAppViews
	iAppView1 = CMDictionaryAppView1::NewL();
	AddViewL(iAppView1);
	iAppView2 = CMDictionaryAppView2::NewL();
	AddViewL(iAppView2);
	//Activating
	SetDefaultViewL(*iAppView1);
	iTabGroup->SetActiveTabById(ELang1MenuTab);
}


void CMDictionaryAppUi::CreateTabGroupL()
{
    CEikStatusPane* sp = StatusPane();
    // Fetch pointer to the default title pane control
    iTitlePane = 
		STATIC_CAST(CAknTitlePane*, sp->ControlL(TUid::Uid(EEikStatusPaneUidTitle)));
    // Fetch pointer to the default navi pane control
    iNaviPane = 
		(CAknNavigationControlContainer*)sp->ControlL(TUid::Uid(EEikStatusPaneUidNavi));
    iDecoratedTabGroup = iNaviPane->ResourceDecorator();
    if (iDecoratedTabGroup)
    {
        iTabGroup = (CAknTabGroup*) iDecoratedTabGroup->DecoratedControl();
    }
}


void CMDictionaryAppUi::SetTabGroupTitleL()
{
	iTabGroup->ReplaceTabTextL(ELang1MenuTab, GetDocument()->iDB->GetDBTitle1L()->Des());
	iTabGroup->ReplaceTabTextL(ELang2MenuTab, GetDocument()->iDB->GetDBTitle2L()->Des());
}


CMDictionaryDocument* CMDictionaryAppUi::GetDocument()
{
	return static_cast<CMDictionaryDocument*>( Document() );
}



void CMDictionaryAppUi::HandleCommandL( TInt aCommand )
{
	//Commands
    switch( aCommand )
    {
        case EEikCmdExit:
        case EAknSoftkeyExit:
			SaveL();
            Exit();
            break;

        case EMDictionarySearch1:
			{
				Searching(0,0);
			}
			break;
        case EMDictionarySearchEx1:
			{
				Searching(0,1);
			}
			break;
        case EMDictionarySearch2:
			{
				Searching(1,0);
			}
			break;
        case EMDictionarySearchEx2:
			{
				Searching(1,1);
			}
			break;
        case EMDictionaryChangeDic:
			{
				ChangeDBL();
			}
			break;
        case EMDictionaryAboutPrg:
			{
				CMessages::ShowAboutPrgL();
			}
			break;
        case EMDictionaryAboutDic:
			{
				CMessages::ShowAboutDicL(GetDocument()->iDB->GetDicTitle1L(),
										GetDocument()->iDB->GetDicTitle2L(),
										GetDocument()->iDB->GetAuthorsL(),
										GetDocument()->iDB->GetVersionL());
			}
			break;
        default:
            Panic( EMDictionaryUi );
            break;
    }
}



TKeyResponse CMDictionaryAppUi::HandleKeyEventL( 
			const TKeyEvent& aKeyEvent, TEventCode /*aType*/)
{

	TInt active = iTabGroup->ActiveTabIndex();
	TInt count = iTabGroup->TabCount();

	switch (aKeyEvent.iCode)
		{
        case EKeyLeftArrow:
	        if (active > 0)
		    {
			    active--;
				iTabGroup->SetActiveTabByIndex(active);
                ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
	        }
		    break;
        case EKeyRightArrow:
	        if (active + 1 < count)
		    {
			    active++;
                iTabGroup->SetActiveTabByIndex(active);
	            ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
		    }
			break;
        default:
	        return EKeyWasNotConsumed;
		    break;
		}
    return EKeyWasConsumed;
}


void CMDictionaryAppUi::HandleForegroundEventL(TBool aForeground)
{
	if(!aForeground)
	{
		//Lost focus
	}
	else
	{
	}
}



void CMDictionaryAppUi::InitDBL()
{
	//Set up the dictionary database file
	GetDocument()->iDB->SetActDB( GetDocument()->iData->GetActDBFile() );
	if( GetDocument()->iDB->DicExist == EFalse )
	{	
		CMessages::ShowDicNotExisErrorL();
		User::Exit(KErrNone);
	}
	else
	{
		if( GetDocument()->iDB->DicSelected == EFalse )
		{
			//Choosing a dictionary
			GetDocument()->iDB->SetActDBInt( CMessages::ShowSelectDicL(GetDocument()->iDB->iFormattedDicList) );
			GetDocument()->iData->SetActDBFile( GetDocument()->iDB->GetActDB() );
		}
		SetTabGroupTitleL();
	}
}



void CMDictionaryAppUi::ChangeDBL()
{
	//Reset the dictionary database file
	//Choosing a dictionary
	TInt res = CMessages::ShowChangeDicL( GetDocument()->iDB->iFormattedDicList );
	if( res >= 0 )
	{
		TInt old = GetDocument()->iDB->GetActDBInt();
		if( old != res )
		{
			GetDocument()->iDB->SetActDBInt( res );
			GetDocument()->iData->SetActDBFile( GetDocument()->iDB->GetActDB() );
			SetTabGroupTitleL();
			//Activate the other view
			TInt active = iTabGroup->ActiveTabIndex();
			if( active == 0 )
			{ active++; }
			else { active--; }
			iTabGroup->SetActiveTabByIndex(active);
			ActivateLocalViewL(TUid::Uid(iTabGroup->TabIdFromIndex(active)));
		}
	}
}


void CMDictionaryAppUi::Searching(TInt aLang, TInt aType)
{
	//Checking if the search is valid
	TBool ok = ETrue;
	if( aLang == 0 )
	{
		if( iAppView1->GetWordL()->CompareC( _L("") ) == 0 )
		{
			CMessages::ShowEmptyErrorL();
			ok = EFalse;
		}
	}
	else
	{
		if( iAppView2->GetWordL()->CompareC( _L("") ) == 0 )
		{
			CMessages::ShowEmptyErrorL();
			ok = EFalse;
		}
	}

	//Loading Progress if all is ok
	//wait note
	if( ok != EFalse )
	{
		CAknWaitNoteWrapper* waitNote = CAknWaitNoteWrapper::NewL();
		CleanupStack::PushL( reinterpret_cast<CBase*>(waitNote) );
		if( aLang == 0 )
		{ GetDocument()->iDB->SetParameters( iAppView1->GetWordL(), aLang, aType, 1); }
		else
		{ GetDocument()->iDB->SetParameters( iAppView2->GetWordL(), aLang, aType, 1); }

		waitNote->ExecuteL(
			R_SEARCHING_NOTE, *GetDocument()->iDB, ETrue, CAknNoteDialog::ENoTone);
		CleanupStack::PopAndDestroy( waitNote );

		if( aLang == 0 )
		{ CMessages::ShowSearchResultsL(
				GetDocument()->iDB->iResultList, iAppView1->GetWordL(), 0); }
		else
		{ CMessages::ShowSearchResultsL(
				GetDocument()->iDB->iResultList, iAppView2->GetWordL(), 1); }
	}
}


⌨️ 快捷键说明

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