bencoolenaboutdlg.cpp

来自「Symbian_OS_code 初学Symbian_OS学习代码, 屏幕截图软」· C++ 代码 · 共 178 行

CPP
178
字号
/*
 * BencoolenAboutDlg.cpp
 *
 * Copyright 2005 - 2008, Antony Pranata
 * http://www.antonypranata.com
 *
 * Project: Screenshot for Symbian OS.
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */

// INCLUDES
#include <eikrted.h>
#include <txtrich.h>
#include <txtfrmat.h>
#include <StringLoader.h>
#include <screenshot.rsg>
#include "BencoolenAboutDlg.h"
#include "ScreenShotData.h"
#include "Bencoolen.hrh"

// MEMBER FUNCTIONS

// --------------------------------------------------------------------------
// Default constructor.
// --------------------------------------------------------------------------
CBencoolenAboutDlg::CBencoolenAboutDlg()
:CAknDialog()
	{
	}

// --------------------------------------------------------------------------
// Destructor.
// --------------------------------------------------------------------------
CBencoolenAboutDlg::~CBencoolenAboutDlg()
	{
	delete iTextEditorAbout;
	}

// --------------------------------------------------------------------------
// Creates rich edit control in this dialog to display copyright message.
// --------------------------------------------------------------------------
void CBencoolenAboutDlg::PreLayoutDynInitL()
	{
	// Construct a new rich text editor.
	iTextEditorAbout = new(ELeave) CEikRichTextEditor();
	iTextEditorAbout->ConstructL(this, 0, 0,
		CEikEdwin::EReadOnly | CEikEdwin::ENoAutoSelection);
	iTextEditorAbout->SetContainerWindowL(*this);
	iTextEditorAbout->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);

	// Insert all copyright text to the rich text.
	CRichText* richText = iTextEditorAbout->RichText();
	HBufC* message = StringLoader::LoadLC(R_BENCOOLEN_DIALOG_INFORMATION);
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, *message);
	CleanupStack::PopAndDestroy(); // message
	message = 0;

	message = StringLoader::LoadLC(R_BENCOOLEN_DIALOG_URL);
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, *message);
	CleanupStack::PopAndDestroy(); // message
	message = 0;

	message = StringLoader::LoadLC(R_BENCOOLEN_DIALOG_COPYRIGHT);
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, *message);
	CleanupStack::PopAndDestroy(); // message
	message = 0;

	message = StringLoader::LoadLC(R_BENCOOLEN_DIALOG_VERSION);
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, *message);
	CleanupStack::PopAndDestroy(); // message
	message = 0;

	message = StringLoader::LoadLC(R_BENCOOLEN_DIALOG_PROGRAM_NAME);
	richText->InsertL(0, '\f'); // EOL
	richText->InsertL(0, *message);
	CleanupStack::PopAndDestroy(); // message
	message = 0;

	// Make it to the center
	CParaFormat paraFormat;
	TParaFormatMask paraFormatMask;
	iTextEditorAbout->SetSelectionL(0, richText->DocumentLength());
	paraFormatMask.SetAttrib(EAttAlignment); // set the mask
	paraFormat.iHorizontalAlignment = CParaFormat::ECenterAlign;
	iTextEditorAbout->ApplyParaFormatL(&paraFormat, paraFormatMask);

	// Create scroll bar.
	CEikScrollBarFrame* scrollBarFrame = iTextEditorAbout->CreateScrollBarFrameL();
	scrollBarFrame->SetScrollBarVisibilityL(
		CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
	iTextEditorAbout->SetCursorPosL(0, EFalse);
	iTextEditorAbout->UpdateScrollBarsL();
	}

// --------------------------------------------------------------------------
// Returns the number of control in this dialog.
// In this case we have only one, which is the rich edit control.
// --------------------------------------------------------------------------
TInt CBencoolenAboutDlg::CountComponentControls() const
	{
	return 1;
	}

// --------------------------------------------------------------------------
// Returns the pointer to the controls in this dialog.
// --------------------------------------------------------------------------
CCoeControl* CBencoolenAboutDlg::ComponentControl(TInt aIndex) const
	{
	switch ( aIndex )
		{
		case 0:
			return iTextEditorAbout;
		default:
			return NULL;
		}
	}

// --------------------------------------------------------------------------
// Called when the size of this dialog is changed.
// In this case, we just resize the rich edit control.
// --------------------------------------------------------------------------
void CBencoolenAboutDlg::SizeChanged()
	{
	iTextEditorAbout->SetExtent(TPoint(0, 0), Rect().Size());
	DrawNow();
	}

// --------------------------------------------------------------------------
// We have to handle key event here because by default we don't set the focus
// to the text editor. That's why we have to pass the key event to the
// text editor.
// --------------------------------------------------------------------------
TKeyResponse CBencoolenAboutDlg::OfferKeyEventL(const TKeyEvent& aKeyEvent,
												TEventCode aType)
	{
	if (iTextEditorAbout)
		{
		switch (aKeyEvent.iCode)
			{
			case EKeyDownArrow:
				{
				iTextEditorAbout->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
				return EKeyWasConsumed;
				}
			case EKeyUpArrow:
				{
				iTextEditorAbout->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
				return EKeyWasConsumed;
				}
			default:
				return iTextEditorAbout->OfferKeyEventL(aKeyEvent, aType);
			}
		}
	else
		{
		return EKeyWasNotConsumed;
		}
	}

// End of File

⌨️ 快捷键说明

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