bencoolenappui.cpp

来自「Symbian_OS_code 初学Symbian_OS学习代码, 屏幕截图软」· C++ 代码 · 共 1,322 行 · 第 1/3 页

CPP
1,322
字号
		// We have to use TRAPD, otherwise the application won't be
		// able to go to the background if leave happens.
		TRAP_IGNORE(DoSaveSettingsL());
		}

	CSymbianAppUi::HandleForegroundEventL(aForeground);
	}

#if (__S60__ >= 203)

// --------------------------------------------------------------------------
// Called when control's resource changed. Normally we have to re-layout
// the control.
// --------------------------------------------------------------------------
void CBencoolenAppUi::HandleResourceChangeL(TInt aType)
	{
	CAknAppUi::HandleResourceChangeL(aType);
	if (iAppView)
		{
		iAppView->HandleResourceChange(aType);
		}
	if (iSettingsView)
		{
		iSettingsView->HandleResourceChange(aType);
		}
	}

// --------------------------------------------------------------------------
// Starting from S60 3.x, pressing End key will terminate application.
// We don't want this to happen in this application, so we have to handle
// End key event (KAknUidValueEndKeyCloseEvent).
// --------------------------------------------------------------------------
void CBencoolenAppUi::HandleWsEventL(const TWsEvent &aEvent,
		CCoeControl* aDestination)
	{
	// This part is very important!!!
	// It is related to Knowledge Base published at Forum Nokia (KIS000708).
	// 
	// According to Forum Nokia, we are not allowed to capture <#> and <*> keys
	// because it will have a conflict with the phone application.
	//
	// Fortunately, it is possible to overcome this limitation.
	// The trick is by re-sending the event to the phone application
	// when we receive <#> or <*> keys.
	if (((KHashKeyScanCode == aEvent.Key()->iScanCode)
			|| (KAsteriskKeyScanCode == aEvent.Key()->iScanCode))
		&& ((aEvent.Key()->iScanCode == iCaptureKey)
			|| (aEvent.Key()->iScanCode == iCaptureKeySecondary)))
		{
		RWsSession& ws = iCoeEnv->WsSession();
		TInt wgid = ws.GetFocusWindowGroup();
		CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC(ws, wgid);
		TUid foregroundUid = wgName->AppUid();
		delete wgName;
		
		// Only re-send the application if the current window is not active.
		if (foregroundUid != KUidBencoolen)
			{
			TWsEvent event = aEvent;
			ws.SendEventToWindowGroup(wgid, event);
			}
		}	
	
	// If the user press End key, we just send the application to the background.
	switch (aEvent.Type()) 
		{ 
		case KAknUidValueEndKeyCloseEvent:
			break;

		default:
			CAknViewAppUi::HandleWsEventL(aEvent, aDestination);
		}
	}

#endif

#ifdef __S60__

#if (__S60__ >= 300)

// --------------------------------------------------------------------------
// Sends screenshot file to another device on S60 3.x.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleSendL(TInt /*aCommand*/)
	{
	ASSERT(iSendUi);
	ASSERT(iScreenShot);

	const HBufC* fileName = iScreenShot->CurrentFileName();
	if (fileName)
		{
		CMessageData* messageData = CMessageData::NewLC();
		messageData->AppendAttachmentL(*fileName);
		iSendUi->ShowQueryAndSendL(messageData,
			TSendingCapabilities(0, 0, TSendingCapabilities::ESupportsAttachments));
		CleanupStack::PopAndDestroy(); // messageData
		}
	else
		{
		User::Leave(KErrNotFound);
		}
	}

#else

// --------------------------------------------------------------------------
// Sends screenshot file to another device on pre-S60 3.x.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleSendL(TInt aCommand)
	{
	ASSERT(iSendUi);
	ASSERT(iScreenShot);

	const HBufC* fileName = iScreenShot->CurrentFileName();
	if (fileName)
		{
		// Array for attachments
		CDesCArrayFlat* attachments = new (ELeave) CDesCArrayFlat(1);
		CleanupStack::PushL(attachments);
		attachments->AppendL(*fileName);
		iSendUi->CreateAndSendMessageL(aCommand, 0, attachments);
		CleanupStack::PopAndDestroy(); // attachments
		}
	else
		{
		User::Leave(KErrNotFound);
		}
	}

#endif // #if (__S60__ >= 300)

#else

// --------------------------------------------------------------------------
// Sends screenshot file to another device on UIQ.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleSendL()
	{
	ASSERT(iScreenShot);

	const HBufC* fileName = iScreenShot->CurrentFileName();

	if (fileName)
		{
		TParse parse;
		parse.Set(*fileName, NULL, NULL);
		CQikSendAsDialog::RunDlgLD(
			0, parse.FullName(), parse.NameAndExt(), parse.NameAndExt(),
			KUidMtmQuerySupportAttachments);
		}
	else
		{
		User::Leave(KErrNotFound);
		}
	}

#endif

// --------------------------------------------------------------------------
// Displays About dialog box.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleAboutDlgL()
	{
#ifdef __S60__
	CBencoolenAboutDlg* dialog = new (ELeave) CBencoolenAboutDlg();
	dialog->ExecuteLD(R_BENCOOLEN_DIALOG_ABOUT);
#else
	// Checks whether the icon is there or not. If not, then use About dialog
	// box without icon.
	TFileName fileName(Application()->AppFullName());
	TParse parse;
	parse.Set(fileName, 0, 0);
	fileName.Copy(parse.DriveAndPath());
	fileName.Append(KAboutDialogImage);

	if (BaflUtils::FileExists(iCoeEnv->FsSession(), fileName))
		{
		CEikDialog* dialog = new (ELeave) CEikDialog();
		dialog->ExecuteLD(R_BENCOOLEN_DIALOG_ABOUT);
		}
	else
		{
		CEikDialog* dialog = new (ELeave) CEikDialog();
		dialog->ExecuteLD(R_BENCOOLEN_DIALOG_ABOUT_NOICON);
		}
#endif
	}

// --------------------------------------------------------------------------
// Displays settings dialog box.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleSettingsDlgL()
	{
#ifdef __S60__
	ActivateLocalViewL(iSettingsView->Id());
#else
	CBencoolenSettingsDlg* dialog = new (ELeave) CBencoolenSettingsDlg(
		*iScreenShotData);
	if ((dialog->ExecuteLD(R_BENCOOLEN_DIALOG_SETTINGS))
		&& (iIsCapturing))
		{
		SetCaptureKey();
		}
#endif
	}

// --------------------------------------------------------------------------
// Stops continuous capturing mode.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoHandleStop()
	{
	iScreenShot->StopCapture();
	iIsContinuous = EFalse;
	DisplayGlobalDlg(R_BENCOOLEN_INFO_STOPPED);
	}

// --------------------------------------------------------------------------
// Loads user's preference from the .ini file.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoLoadSettingsL()
	{
	CDictionaryStore* store = Application()->OpenIniFileLC(iCoeEnv->FsSession());
	// If the requested UID is present, then read. Otherwise just return
	// and use the default value.
	if ((store) && (store->IsPresentL(KUidBencoolenIniFile)) && (iScreenShotData))
		{
		RDictionaryReadStream readStream;
		readStream.OpenLC(*store, KUidBencoolenIniFile);
		readStream >> *iScreenShotData;
		readStream.Close();
		store->CommitL();
		CleanupStack::PopAndDestroy(); // readStream
		}
	CleanupStack::PopAndDestroy(); // store
	}

// --------------------------------------------------------------------------
// Saves user's preferences to the .ini file.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoSaveSettingsL()
	{
	CDictionaryStore* store = Application()->OpenIniFileLC(iCoeEnv->FsSession());
	if ((store) && (iScreenShotData))
		{
		RDictionaryWriteStream writeStream;
		writeStream.AssignLC(*store, KUidBencoolenIniFile);
		writeStream << *iScreenShotData;
		writeStream.Close();
		store->CommitL();
		CleanupStack::PopAndDestroy(); // writeStream
		}
	CleanupStack::PopAndDestroy(); // store
	}

// --------------------------------------------------------------------------
// Sets the key used to capture screenshot.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DoSetCaptureKey(TInt aCaptureKey, TInt aCaptureKey2,
                                      TInt aCaptureKeySecondary, TInt aCaptureKey2Secondary,
                                      TUint aModifierMask, TInt aRepeats)
	{
	// If there is another handle, we have to cancel it first.
	CancelCaptureKey();

	// Sets the capture key.
	iCaptureKey           = aCaptureKey;
	iCaptureKey2          = aCaptureKey2;
	iCaptureKeySecondary  = aCaptureKeySecondary;
	iCaptureKey2Secondary = aCaptureKey2Secondary;
	iModifierMask         = aModifierMask;
	iRepeats              = aRepeats;

#ifdef __WINS__

	// Don't care about secondary key in the emulator.
	iHandleCaptureKey = iCoeEnv-> RootWin().CaptureKeyUpAndDowns(
		iCaptureKey, iModifierMask, iModifierMask PRIORITYCAPTUREKEY);
		
#else // __WINS__

#ifdef __UIQ__

	// In UIQ, we use standard key, instead of normal key.
	iHandleCaptureKey = iCoeEnv-> RootWin().CaptureKey(
		iCaptureKey, iModifierMask, iModifierMask, 2);
	
	if (iCaptureKeySecondary)
		{
		iHandleCaptureKeySecondary = iCoeEnv-> RootWin().CaptureKey(
			iCaptureKeySecondary, iModifierMask, iModifierMask, 2);

		}
		
#else

	// In the old Symbian version, there is no support for priority.
	// That's why we have PRIORITYCAPTUREKEY.
	// It is defined as ",2" in newer S60 and nothing in S60 1st Edition.

	// This will capture scan code of the keypress.
	if (iCaptureKey)
		{
		iHandleCaptureKey = iCoeEnv-> RootWin().CaptureKeyUpAndDowns(
			iCaptureKey, iModifierMask, iModifierMask PRIORITYCAPTUREKEY);
		}
	
	if (iCaptureKeySecondary)
		{
		iHandleCaptureKeySecondary = iCoeEnv-> RootWin().CaptureKeyUpAndDowns(
			iCaptureKeySecondary, iModifierMask, iModifierMask PRIORITYCAPTUREKEY);
		}
	
	//// WARNING: We need to capture the normal code of keypress otherwise
	// the key event will be sent to another application.
	if (iCaptureKey2)
		{
		iHandleCaptureKey2 = iCoeEnv-> RootWin().CaptureKey(
			iCaptureKey2, iModifierMask, iModifierMask PRIORITYCAPTUREKEY);
		}

	if (iCaptureKey2Secondary)
		{	
		iHandleCaptureKey2Secondary = iCoeEnv-> RootWin().CaptureKey(
			iCaptureKey2Secondary, iModifierMask, iModifierMask PRIORITYCAPTUREKEY);
		}
		
#endif // __UIQ__

#endif // __WINS__
	}

// --------------------------------------------------------------------------
// Displays global message based on resource identifier.
// The dialog will be displayed even though this application is in
// the background.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DisplayGlobalDlg(TInt aResourceId)
	{
#ifdef __S60__

	HBufC* message = iEikonEnv->AllocReadResourceLC(aResourceId);
	CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	globalNote->ShowNoteL(EAknGlobalInformationNote, *message);
	CleanupStack::PopAndDestroy(2); // message and globalNote

#else

	RNotifier notifier;
	notifier.Connect();
	HBufC* message = iEikonEnv->AllocReadResourceLC(aResourceId);
	notifier.InfoPrint(*message);
	CleanupStack::PopAndDestroy(); // message
	notifier.Close();

#endif
	}

// --------------------------------------------------------------------------
// Displays global message based on aMessage.
// The dialog will be displayed even though this application is in
// the background.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DisplayGlobalDlg(const TDesC& aMessage)
	{
#ifdef __S60__
		
	CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	globalNote->ShowNoteL(EAknGlobalInformationNote, aMessage);
	CleanupStack::PopAndDestroy(); // globalNote

#else

	RNotifier notifier;
	notifier.Connect();
	notifier.InfoPrint(aMessage);
	notifier.Close();

#endif
	}

// --------------------------------------------------------------------------
// Displays error dialog based on error code.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DisplayErrorDlg(TInt aError)
	{
	HBufC* message;
	switch (aError)
		{
		case KErrNotSupported:
			message = iEikonEnv->AllocReadResourceLC(
				R_BENCOOLEN_ERROR_NOT_SUPPORTED);
			break;

		case KErrPathNotFound:
			message = iEikonEnv->AllocReadResourceLC(
				R_BENCOOLEN_ERROR_PATH_NOT_FOUND);
			break;

		case KErrNotReady:
			message = iEikonEnv->AllocReadResourceLC(
				R_BENCOOLEN_ERROR_NOT_READY);
			break;

		case KErrDiskFull:
			message = iEikonEnv->AllocReadResourceLC(
				R_BENCOOLEN_ERROR_DISK_FULL);
			break;

		case KErrCompletion:
			message = iEikonEnv->AllocReadResourceLC(
				R_BENCOOLEN_ERROR_COMPLETION);
			break;

		default:
			{
			message = StringLoader::LoadLC(R_BENCOOLEN_ERROR_UNKNOWN_ERROR,
				aError);
			break;
			}
		}

#ifdef __S60__
		
	CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	globalNote->ShowNoteL(EAknGlobalErrorNote, *message);
	CleanupStack::PopAndDestroy(2); // message and globalNote

#else

	RNotifier notifier;
	notifier.Connect();
	notifier.InfoPrint(*message);
	notifier.Close();
	CleanupStack::PopAndDestroy(); // message

#endif
	}

// End of File  

⌨️ 快捷键说明

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