📄 bencoolenappcontainer.cpp
字号:
/*
* BencoolenAppContainer.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/>.
*/
// INCLUDE FILES
#include <symbianvariant.h>
#if (__S60__ >= 203)
#include <AknUtils.h>
#endif
#include <eikenv.h>
#include <coemain.h>
#include <eiklabel.h>
#include <eikedwin.h>
#include <screenshot.rsg>
#include "BencoolenAppContainer.h"
#include "Bencoolen.hrh"
// CONSTANTS
const TInt KBorderSize = 5;
// MEMBER FUNCTIONS
// --------------------------------------------------------------------------
// Second phase constructor.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iEikEdwin = new (ELeave) CEikEdwin();
iEikEdwin->SetContainerWindowL(*this);
iEikEdwin->MakeVisible(EFalse);
iEikEdwin->ConstructL();
iEikEdwin->SetReadOnly(ETrue);
SetRect(aRect);
ActivateL();
}
// --------------------------------------------------------------------------
// Destructor.
// --------------------------------------------------------------------------
CBencoolenAppContainer::~CBencoolenAppContainer()
{
delete iEikEdwin;
}
#if (__S60__ >= 203)
// --------------------------------------------------------------------------
// Called when screen size/resolution is changed.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::HandleResourceChange(TInt aType)
{
CCoeControl::HandleResourceChange(aType);
// ADDED FOR SCALABLE UI SUPPORT
// *****************************
if ( aType == KEikDynamicLayoutVariantSwitch )
{
TRect rect;
AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
SetRect(rect);
}
}
#endif
// --------------------------------------------------------------------------
// Sets the bitmap to be displayed on this container.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::SetBitmap(const CFbsBitmap* aBitmap, TBool aShowText)
{
iBitmap = aBitmap;
if (iBitmap)
{
iEikEdwin->MakeVisible(EFalse);
}
else if (aShowText)
{
iEikEdwin->MakeVisible(ETrue);
}
}
// --------------------------------------------------------------------------
// Clears the bitmap and (optionally) displays default text.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::ClearBitmap(TBool aShowText)
{
SetBitmap(0, aShowText);
if (aShowText)
{
// Creates message in the main window.
HBufC* message = CCoeEnv::Static()->AllocReadResourceLC(
R_BENCOOLEN_VIEW_DESCRIPTION);
SetTextL(*message);
CleanupStack::PopAndDestroy(); // message
}
}
// --------------------------------------------------------------------------
// Sets text to be displayed on this container.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::SetTextL(const TDesC& aText)
{
iEikEdwin->SetTextL(&aText);
CEikScrollBarFrame* scrollBarFrame = iEikEdwin->CreateScrollBarFrameL();
scrollBarFrame->SetScrollBarVisibilityL(
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
iEikEdwin->SetCursorPosL(0, EFalse);
iEikEdwin->UpdateScrollBarsL();
}
// --------------------------------------------------------------------------
// Called by framework when the view size is changed
// --------------------------------------------------------------------------
void CBencoolenAppContainer::SizeChanged()
{
if (iEikEdwin)
{
iEikEdwin->SetExtent(TPoint(0, 0), Rect().Size());
}
DrawNow();
}
// --------------------------------------------------------------------------
// Returns the number of controls in this view.
// --------------------------------------------------------------------------
TInt CBencoolenAppContainer::CountComponentControls() const
{
if (iBitmap)
{
return 0;
}
return 1;
}
// --------------------------------------------------------------------------
// Returns the pointer to the controls in this view.
// --------------------------------------------------------------------------
CCoeControl* CBencoolenAppContainer::ComponentControl(TInt aIndex) const
{
switch (aIndex)
{
case 0:
return iEikEdwin;
default:
return NULL;
}
}
// --------------------------------------------------------------------------
// Draws this container.
// --------------------------------------------------------------------------
void CBencoolenAppContainer::Draw(const TRect& /*aRect*/) const
{
CWindowGc& gc = SystemGc();
gc.Clear();
if (iBitmap)
{
// We want to stretch the bitmap so that it fits in the
// control. To do this, we have to compare the width and height
// of the bitmap and then resize the destination rectangle
// accordingly.
TRect drawRect(Rect());
TRect bitmapRect(
0, 0,
iBitmap->Header().iSizeInPixels.iWidth,
iBitmap->Header().iSizeInPixels.iHeight);
TReal32 ratioBitmap = (TReal32) iBitmap->Header().iSizeInPixels.iWidth
/ (TReal32) iBitmap->Header().iSizeInPixels.iHeight;
TReal32 ratioRect = (TReal32) drawRect.Width()
/ (TReal32) drawRect.Height();
TInt bitmapWidth = 0;
TInt bitmapHeight = 0;
if (ratioBitmap > ratioRect)
{
TReal32 ratio = (TReal32) drawRect.Width()
/ (TReal32) bitmapRect.Width();
bitmapWidth = (TInt) ((TReal32) bitmapRect.Width() * ratio);
bitmapHeight = (TInt) ((TReal32) bitmapRect.Height() * ratio);
}
else
{
TReal32 ratio = (TReal32) drawRect.Height()
/ (TReal32) bitmapRect.Height();
bitmapWidth = (TInt) ((TReal32) bitmapRect.Width() * ratio);
bitmapHeight = (TInt) ((TReal32) bitmapRect.Height() * ratio);
}
drawRect.Shrink(
(drawRect.Width() - bitmapWidth) / 2,
(drawRect.Height() - bitmapHeight) / 2);
drawRect.Shrink(KBorderSize, KBorderSize);
gc.DrawBitmap(drawRect, iBitmap);
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbBlack);
gc.SetBrushStyle(CGraphicsContext::ENullBrush);
gc.DrawRect(drawRect);
}
}
// --------------------------------------------------------------------------
// Handles key event in this container.
// --------------------------------------------------------------------------
TKeyResponse CBencoolenAppContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType)
{
if ((iEikEdwin) && (iEikEdwin->IsVisible()))
{
switch (aKeyEvent.iCode)
{
case EKeyDownArrow:
{
iEikEdwin->MoveCursorL(TCursorPosition::EFPageDown, EFalse);
return EKeyWasConsumed;
}
case EKeyUpArrow:
{
iEikEdwin->MoveCursorL(TCursorPosition::EFPageUp, EFalse);
return EKeyWasConsumed;
}
default:
return iEikEdwin->OfferKeyEventL(aKeyEvent, aType);
}
}
return EKeyWasNotConsumed;
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -