bencoolenappui.cpp

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

CPP
1,322
字号
			HBufC* message = StringLoader::LoadLC(
				R_BENCOOLEN_INFO_SCREENSHOT_SAVED, parse.NameAndExt());
			DisplayGlobalDlg(*message);
			CleanupStack::PopAndDestroy(); // message
			}
		}
	else
		{
		iIsContinuous = EFalse;
		DisplayErrorDlg(aError);
		}
	}
	
// --------------------------------------------------------------------------
// This function is called when a screenshot has been saved.
// --------------------------------------------------------------------------
void CBencoolenAppUi::OnSaveCompleted(TInt aError)
	{
	if (KErrNone == aError)
		{
		// Display the bitmap on the application container.
		AppContainer()->SetBitmap(iScreenShot->Bitmap());
		AppContainer()->DrawNow();
		
#ifdef __S60__
		// If we still have background bitmap, delete it.
		if (iBackgroundBitmap)
			{
			delete iBackgroundBitmap;
			iBackgroundBitmap = 0;
			}
#endif
		}
	else
		{
		iIsContinuous = EFalse;
		DisplayErrorDlg(aError);
		}
	}

// --------------------------------------------------------------------------
// Dynamically initialize menu pane.
// --------------------------------------------------------------------------
void CBencoolenAppUi::DynInitMenuPaneL(TInt aResourceId,
									   CEikMenuPane* aMenuPane)
	{
#if ((defined __WINS__) && (defined __UIQ__))

	// Displayes "Close (debug)" menu in UIQ.
	// This is needed because UIQ doesn't have Exit menu.
	if (R_BENCOOLEN_MENU_MAIN == aResourceId)
		{
		_LIT(KCloseMenu, "Close (debug)");
		CEikMenuPaneItem::SData itemData;
		itemData.iText	  = KCloseMenu;
		itemData.iCommandId = EEikCmdExit;
		itemData.iFlags	 = 0;
		itemData.iCascadeId = 0;
		aMenuPane->AddMenuItemL(itemData);
		}

#endif

#ifdef __S60__

#if (__S60__ >= 300)

	if (R_BENCOOLEN_MENU_MAIN == aResourceId)
		{
		// If there is a bitmap, then display the Send UI
		if ((iScreenShot) && (iScreenShot->IsIdle())
			&& (AppContainer()) && (AppContainer()->Bitmap())
			&& (!iBackgroundBitmap) && (iSendUi))
			{
			TInt pos;
			aMenuPane->ItemAndPos(EBencoolenCmdActivateCapture, pos);
			iSendUi->AddSendMenuItemL(*aMenuPane, pos + 1, EBencoolenCmdSend);
			}
		}

#else

	if (R_BENCOOLEN_MENU_MAIN == aResourceId)
		{
		// If there is a bitmap, then display the Send UI
		if ((iScreenShot) && (iScreenShot->IsIdle())
			&& (AppContainer()) && (AppContainer()->Bitmap())
			&& (!iBackgroundBitmap) && (iSendUi))
			{
			TSendingCapabilities aSendingCapabilities;
			TInt pos;
			aMenuPane->ItemAndPos(EBencoolenCmdActivateCapture, pos);
			iSendUi->DisplaySendMenuItemL(
				*aMenuPane, pos + 1, aSendingCapabilities);
			}
		}

	// Displays all supported MTM in the Send as menu.
	if ((iSendUi) && (R_SENDUI_MENU == aResourceId))
		{
		// Don't display SMS in the Send UI.
		CArrayFixFlat<TUid>* arrayUid = new (ELeave) CArrayFixFlat<TUid>(1);
		CleanupStack::PushL(arrayUid);	
		arrayUid->AppendL(KUidMsgTypeSMS);
		iSendUi->DisplaySendCascadeMenuL(*aMenuPane, arrayUid);
		CleanupStack::PopAndDestroy(); // arrayUid
		}

#endif // if (__S60__ >= 300)

#else

	// Handles menu from Category in UIQ.
	// It is called when the default drive and/or directory have been changed
	// by the users.
	if (R_BENCOOLEN_CATEGORY_PANE == aResourceId)
		{
		iMonitor->DynInitMenuPaneL(aMenuPane, EFalse);
		}

	// Enables or disabled Send as menu depends whether we have a bitmap
	// or not.
	if (R_BENCOOLEN_MENU_MAIN == aResourceId)
		{
		// If there is a bitmap, then display the Send UI
		if ((iScreenShot) && (iScreenShot->IsIdle())
			&& (AppContainer()) && (AppContainer()->Bitmap()))
			{
			aMenuPane->SetItemDimmed(EBencoolenCmdSend, EFalse);
			}
		else
			{
			aMenuPane->SetItemDimmed(EBencoolenCmdSend, ETrue);
			}
		}

#endif

	if (R_BENCOOLEN_MENU_MAIN == aResourceId)
		{
		// Displays start capture or stop capture
		if (iIsCapturing)
			{
			aMenuPane->SetItemTextL(EBencoolenCmdActivateCapture,
				R_BENCOOLEN_MENU_DEACTIVATE_CAPTURE);
			}
		else
			{
			aMenuPane->SetItemTextL(EBencoolenCmdActivateCapture,
				R_BENCOOLEN_MENU_ACTIVATE_CAPTURE);
			}

		// Enables or disabled activate/deactivate menu
		if ((iScreenShot) && (iScreenShot->IsIdle()))
			{
			aMenuPane->SetItemDimmed(EBencoolenCmdActivateCapture, EFalse);
			aMenuPane->SetItemDimmed(EBencoolenCmdSettings, EFalse);
			aMenuPane->SetItemDimmed(EBencoolenCmdStop, ETrue);
			}
		else
			{
			aMenuPane->SetItemDimmed(EBencoolenCmdActivateCapture, ETrue);
			aMenuPane->SetItemDimmed(EBencoolenCmdSettings, ETrue);

			// If no screenshot object, then disable Stop menu as well.
			// The reason we don't have no screenshot object is for example
			// not enough memory during startup of the application.
			if (iScreenShot)
				{
				aMenuPane->SetItemDimmed(EBencoolenCmdStop, EFalse);
				}
			else
				{
				aMenuPane->SetItemDimmed(EBencoolenCmdStop, ETrue);
				}
			}
		}
	}

#ifndef __S60__

// --------------------------------------------------------------------------
// Called when folder changed on UIQ.
// --------------------------------------------------------------------------
void CBencoolenAppUi::FolderChangeL(const TDriveNumber& aDrive,
									const TDesC& aFolder,
									const TBool /*aUpdateNeeded*/)
	{
	if (EDriveC == aDrive)
		{
		iScreenShotData->SetMemoryLocation(CScreenShotData::EPhoneMemory);
		}
	else
		{
		iScreenShotData->SetMemoryLocation(CScreenShotData::EMmcMemory);
		}

	iScreenShotData->SetDirectoryL(aFolder);	
	}

// --------------------------------------------------------------------------
// Called when folder change to All on UIQ.
// --------------------------------------------------------------------------
void CBencoolenAppUi::FolderChangeToAllL(const TBool /*aUpdateNeeded*/)
	{
	// We don't have All folder, so nothing to handle here.
	}

#endif

// --------------------------------------------------------------------------
// Handles event command.
// --------------------------------------------------------------------------
void CBencoolenAppUi::HandleCommandL(TInt aCommand)
	{
#ifndef __S60__
	// If the monitor process the command, then just return.
	if (iMonitor->ProcessCommandL(aCommand) == 0)
		{
		return;
		}
#endif

	switch (aCommand)
		{
#ifdef __S60__

		// Sends application to the background when Back menu is selected.
		case EAknSoftkeyBack:
			{
			TApaTask apaTask(iEikonEnv->WsSession());
			apaTask.SetWgId(iCoeEnv->RootWin().Identifier());
			apaTask.SendToBackground();
			break;
			}

		// NOTE: This will fall through to EEikCmdExit
		// So don't put any other cases below!!!
		case EAknCmdExit:
		case EAknSoftkeyExit:

#endif

		case EEikCmdExit:
			{
			TRAP_IGNORE(DoSaveSettingsL());
			Exit();
			break;
			}

		case EBencoolenCmdActivateCapture:
			{
			iIsCapturing = !iIsCapturing;
			if (iIsCapturing)
				{
				DisplayGlobalDlg(R_BENCOOLEN_INFO_ACTIVATE_CAPTURE);
				SetCaptureKey();
				}
			else
				{
				DisplayGlobalDlg(R_BENCOOLEN_INFO_DEACTIVATE_CAPTURE);
				CancelCaptureKey();
				}
			break;
			}

#ifdef __S60__

		// Currently support 5 MTMs
		case EBencoolenCmdSend:
		case EBencoolenCmdSend + 1:
		case EBencoolenCmdSend + 2:
		case EBencoolenCmdSend + 3:
		case EBencoolenCmdSend + 4:
			DoHandleSendL(aCommand);
			break;

#else

		case EBencoolenCmdSend:
			DoHandleSendL();
			break;

#endif

		case EBencoolenCmdSettings:
			DoHandleSettingsDlgL();
			break;

		case EBencoolenCmdStop:
			DoHandleStop();
			break;

		case EBencoolenCmdAbout:
			DoHandleAboutDlgL();
			break;

		default:
			break;
		}
	}

// --------------------------------------------------------------------------
// Handles key event. This is where we capture screenshot.
// --------------------------------------------------------------------------
TKeyResponse CBencoolenAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,
											  TEventCode aType)
	{
#ifdef __WINS__

	// In the emulator, we just checked for Yes .
	if (((iCaptureKey == (TUint) aKeyEvent.iScanCode)
			|| (iCaptureKeySecondary == (TUint) aKeyEvent.iScanCode))
		&& (EEventKeyDown == aType)
		&& (iIsCapturing))

#else

#ifdef __S60__

	// In S60, we always use Edit key in the shortcut, that's why we have to
	// check whether EModifierShift is set or not.
	if (((iCaptureKey == (TUint) aKeyEvent.iScanCode)
			|| (iCaptureKeySecondary == (TUint) aKeyEvent.iScanCode))
		&& (EEventKeyDown == aType)
		&& (aKeyEvent.iRepeats == iRepeats)
		&& ((aKeyEvent.iModifiers & iModifierMask) == iModifierMask)
		&& (iIsCapturing))

#else

	if (((iCaptureKey == aKeyEvent.iCode) || (iCaptureKeySecondary == aKeyEvent.iCode))
		&& (EEventKey == aType)
		&& (iIsCapturing))

#endif

#endif // __WINS__
		{
		// If there is a secondary key, then...
		if (iHandleCaptureKeySecondary)
			{
			// If the first key has not been pressed then, give signal...
			// After that, we just return.
			// When the next key is pressed, we'll get the signal.
			if (!iIsSecondary)
				{
				iIsSecondary = ETrue;
				return EKeyWasNotConsumed;
				}
			}

		// If now we are in continuous mode, then pressing shortcut key shall
		// stop the capturing.
		if (iIsContinuous)
			{
			DoHandleStop();
			return EKeyWasConsumed;
			}

		// If still waiting for the timer, then tells the users
		// that it is still waiting.
		if (!iScreenShot->IsIdle())
			{
			DisplayGlobalDlg(R_BENCOOLEN_ERROR_RETRY_AGAIN);
			return EKeyWasConsumed;
			}
		
		// Capture the screenshot.
		TRAPD(err, iScreenShot->CaptureL());

		// If this is not one shot mode, then it is continuous mode.
		if (CScreenShotData::EModeOneShot != iScreenShotData->Mode())
			{
			iIsContinuous = ETrue;
			}

		// Displays a message when the delay is quite long enough.
		// This is to prevent the users thinking the timer is not
		// activated yet.
		if (KErrNone == err)
		{
			if ((iScreenShotData->Delay() >= CScreenShotData::EFiveSeconds)
				|| (iScreenShotData->Mode() != CScreenShotData::EModeOneShot))
				{
				DisplayGlobalDlg(R_BENCOOLEN_INFO_STARTED);
				}
		}

		// Displays the error message to the users.
		else
			{
			DisplayErrorDlg(err);
			}
			
		iIsSecondary = EFalse;

		return EKeyWasConsumed;
		}
	
	// If a key is released, it means secondary key won't be pressed.
	if (EEventKeyUp == aType)
		{
		iIsSecondary = EFalse;
		}

	return EKeyWasNotConsumed;
	}

// --------------------------------------------------------------------------
// Called when this application goes to the foreground or background.
// --------------------------------------------------------------------------
void CBencoolenAppUi::HandleForegroundEventL(TBool aForeground)
	{
	if (aForeground)
		{
		// When the application gets the focus, it has to check whether
		// the screenshot is still available or not.
		//
		// This is to prevent the user has removed the file while
		// this application is in background.
		CBencoolenAppContainer* appContainer = AppContainer();
		if ((appContainer) && (iScreenShot) && (appContainer->Bitmap())
#ifdef __S60__
			&& (!iBackgroundBitmap)
#endif
			)
			{
			const HBufC* fileName = iScreenShot->CurrentFileName();
			if (!BaflUtils::FileExists(iEikonEnv->FsSession(), *fileName))
				{
				// If no file is found, then clear the bitmap
				// and show default message.
				appContainer->ClearBitmap(ETrue);
				AppContainer()->DrawNow();
				}
			}
		} // if (aForeground)
	else
		{
		// When the application goes to background, save all the settings.

⌨️ 快捷键说明

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