📄 messageviewer.cpp
字号:
/*
* 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.
*
* Jabber
* Copyright (C) 2004 Xie Tian Lu http://sabber.jabberstudio.org/
*/
#include <AknNoteWrappers.h>
#include <frmtview.h>
#include <txtfrmat.h>
#include <coemain.h>
#include <eikscrlb.h>
#include <eiksbfrm.h> //sbfrm
#include <txtrich.h> //Richtext
#include <eikrted.h> //RichText Editor
#include <avkon.mbg> // Image Ids
#include <eikenv.h> // ReadResource()
#include <e32def.h> // for _L
#include <eikmenub.h>
#include <Sabber.rsg>
#include "MessageViewer.h"
#include "MessageItem.h"
#include "osaux.h"
CMessageViewer::CMessageViewer(const TRect& aRect)
{
CreateWindowL();
iRect = aRect;
iRect.iTl.iY = 0;
SetRect( iRect );
iStartLine = 0;
iLinesInClient = iRect.Height() / 20;
}
CMessageViewer::~CMessageViewer()
{
delete iSBFrame;
CloseWindow();
}
TInt CMessageViewer::CountComponentControls() const
{
return 0;
}
CCoeControl* CMessageViewer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return NULL;
default:
return NULL;
}
}
void CMessageViewer::Draw(const TRect& aRect) const
{
TBuf<128> buf;
CWindowGc& gc = SystemGc();
gc.Clear();
gc.SetPenColor( KRgbBlack );
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbWhite );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush);
gc.DrawRect( aRect );
gc.UseFont( iFont );
int x = 4;
int y = 18;
if ( iItem->IsReceived() )
CEikonEnv::Static()->ReadResource( buf, R_BUF_MSG_RECEIVED );
else
CEikonEnv::Static()->ReadResource( buf, R_BUF_MSG_SENT );
gc.DrawText( buf,TPoint( x, y ) );
y += 16;
gc.DrawText( iItem->GetTimeStamp(), TPoint( x + 24, y ) );
y += 16;
buf.Zero();
CEikonEnv::Static()->ReadResource( buf, R_BUF_MSG_FROM );
gc.DrawText( buf, TPoint( x, y ) );
buf.Zero();
CUtil::UTF82Unicode( buf, iItem->GetFrom() );
gc.DrawText( buf, TPoint( x + 36, y ) );
y += 16;
buf.Zero();
CEikonEnv::Static()->ReadResource( buf, R_BUF_MSG_TO );
gc.DrawText( buf, TPoint( x + 2, y ) );
buf.Zero();
CUtil::UTF82Unicode( buf, iItem->GetTo() );
gc.DrawText( buf, TPoint( x + 36, y ) );
gc.SetPenColor( KRgbGray );
gc.SetPenStyle( CGraphicsContext::ESolidPen );
y += 4;
gc.DrawLine( TPoint( 0, y ), TPoint( 176, y ) );
y += 2;
gc.DrawLine( TPoint( 0, y ), TPoint( 176, y ) );
gc.SetPenColor( KRgbBlack );
y += 20;
int lines = ( 176 - 20 - y ) / 16;
int l = 4;
int r = 174;
iItem->DrawContent( &gc, lines, l, r, x + 24, y, 16, iFont );
gc.SetPenColor( KRgbGray );
gc.DrawLine( TPoint( 0, aRect.iBr.iY - 1 ), TPoint( 176, aRect.iBr.iY - 1 ) );
}
TKeyResponse CMessageViewer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
if ( aType != EEventKey ) // Is not key event?
return EKeyWasNotConsumed;
TChar charCode(aKeyEvent.iCode);
switch ( charCode ) // The code of key event is...
{
case EKeyDownArrow:
{
if ( iStartLine + iLines - iLinesInClient > 0 ) {
iStartLine--;
iSBFrame->MoveThumbsBy( 0, 1 );
}
DrawNow();
return EKeyWasConsumed;
}
case EKeyUpArrow :
{
if( iStartLine < 0 ) {
iStartLine += 1;
iSBFrame->MoveThumbsBy( 0, -1 );
}
DrawNow();
return EKeyWasConsumed;
}
case EKeyLeftArrow: // Left key.
{
AddIndex();
return EKeyWasConsumed;
}
case EKeyRightArrow: // Right Key.
{
SubIndex();
return EKeyWasConsumed;
}
}
return EKeyWasNotConsumed;
}
void CMessageViewer::HandleControlEventL( CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
void CMessageViewer::HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType)
{
// Never called
}
void CMessageViewer::CreateScrollBars()
{
iSBModel = TEikScrollBarModel(10, 0, 0);
iSBFrame = new (ELeave) CEikScrollBarFrame( this, this, ETrue );
iSBFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn );
iSBFrame->Tile( &iSBModel );
//iSBFrame->DrawScrollBarsNow();
}
void CMessageViewer::ActivateL()
{
MakeVisible( ETrue );
CCoeControl::ActivateL();
SetFocus( ETrue );
}
void CMessageViewer::Quit()
{
MakeVisible(EFalse);
SetFocus( EFalse );
}
void CMessageViewer::SetModel( CMessageModel* aModel )
{
iModel = aModel;
}
void CMessageViewer::SetMessageItem( CMessageItem* aItem )
{
iItem = aItem;
}
void CMessageViewer::SetFont( CFont* aFont )
{
iFont = aFont;
}
void CMessageViewer::AddIndex()
{
}
void CMessageViewer::SubIndex()
{
}
void CMessageViewer::GetLineNum()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -