📄 sabbermessagecontainer.cpp
字号:
/*
* ============================================================================
* Name : CSabberMessageContainer from SabberMessageContainer.cpp
* Part of : Sabber
* Created : 2004-12-9 by Xie Tian Lu
* Implementation notes:
* Initial content was generated by Series 60 AppWizard.
* Version : 0.1
* Copyright: (c) Xie Tian Lu Http://sabber.jabberstudio.org/
* ============================================================================
*/
// INCLUDE FILES
#include <barsread.h>
#include <Sabber.rsg>
#include <string.h>
#include "SabberMessageContainer.h"
#include "UUListBox.h"
#include "UUGTeditor.h"
#include "MessageModel.h"
#include "MessageViewer.h"
#include "osaux.h"
#include "SabberAppUi.h"
_LIT(KArialFont,"Arial");
// ================= MEMBER FUNCTIONS =======================
// ---------------------------------------------------------
// CSabberMessageContainer::ConstructL(const TRect& aRect)
// EPOC two phased constructor
// ---------------------------------------------------------
//
void CSabberMessageContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iEditorActive = EFalse;
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC( reader, R_MSG_GTEXTEDITOR );
iTextEditor = new ( ELeave ) CUUGTEditor;
if ( iTextEditor )
{
iTextEditor->SetContainerWindowL(*this);
iTextEditor->SetObserver( this );
iTextEditor->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy();
//iGlobalTextEditor->SetInputCapabilitiesL(TCoeInputCapabilities::EAllText);
iTextEditor->SetAvkonWrap( ETrue );
iTextEditor->SetBorder( TGulBorder::ESingleBlack );
iTextEditor->SetExtent( TPoint(6,88), iTextEditor->MinimumSize() );
iTextEditor->SetSize( TSize( 164,54 ) );
iTextEditor->SetBackgroundColorL( KRgbWhite );
}
iViewerActive = EFalse;
iMessageViewer = new ( ELeave ) CMessageViewer( aRect );
if ( iMessageViewer ) {
iMessageViewer->SetMopParent( this ); // must do this before following line
iMessageViewer->CreateScrollBars();
}
iListBox = 0;
iListBox = new (ELeave) CUUListBox;
if ( iListBox )
{
iListBox->SetListBoxObserver( this );
CUUListItemDrawer* drawer = new ( ELeave ) CUUListItemDrawer();
drawer->SetFont( iFont );
iListBox->ConstructL( iModel, drawer, this );
iListBox->SetContainerWindowL( *this );
CreateScrollbarL( iListBox );
}
SetRect(aRect);
ActivateL();
}
// Destructor
CSabberMessageContainer::~CSabberMessageContainer()
{
delete iListBox;
iListBox = 0;
delete iMessageViewer;
delete iTextEditor;
}
// ---------------------------------------------------------
// CSabberMessageContainer::SizeChanged()
// Called by framework when the view size is changed
// ---------------------------------------------------------
//
void CSabberMessageContainer::SizeChanged()
{
// TODO: Add here control resize code etc.
if ( iListBox )
{
TRect aRect = Rect();
if ( iEditorActive ) {
aRect.iBr.iY -= 64;
} else {
aRect.iBr.iY -= 1;
}
iListBox->SetRect( aRect );
iListBox->CalLayout();
}
}
// ---------------------------------------------------------
// CSabberMessageContainer::CountComponentControls() const
// ---------------------------------------------------------
//
TInt CSabberMessageContainer::CountComponentControls() const
{
TInt num = 1;
if ( iEditorActive || iViewerActive )
num++;
return num; // return nbr of controls inside this container
}
// ---------------------------------------------------------
// CSabberMessageContainer::ComponentControl(TInt aIndex) const
// ---------------------------------------------------------
//
CCoeControl* CSabberMessageContainer::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iListBox;
case 1:
if ( iEditorActive )
return iTextEditor;
if ( iViewerActive )
return iMessageViewer;
default:
return NULL;
}
}
// ---------------------------------------------------------
// CSabberMessageContainer::Draw(const TRect& aRect) const
// ---------------------------------------------------------
//
void CSabberMessageContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
if( iEditorActive )
{
gc.SetPenStyle(CGraphicsContext::ESolidPen);
gc.SetPenColor(KRgbBlack);
gc.DrawLine( TPoint( 1, 84 ), TPoint( 1, 143 ) );
gc.DrawLine( TPoint( 1, 84 ), TPoint( 174, 84 ) );
gc.DrawLine( TPoint( 1, 143 ), TPoint( 175, 143 ) );
gc.DrawLine( TPoint( 174,84 ), TPoint( 174, 143 ) );
gc.SetPenColor( KRgbGray );
gc.DrawLine( TPoint( 2, 85 ), TPoint( 2, 142 ) );
gc.DrawLine( TPoint( 2, 85 ), TPoint( 173, 85 ) );
gc.DrawLine( TPoint( 2, 142 ), TPoint( 174, 142 ) );
gc.DrawLine( TPoint( 173,85 ), TPoint( 173, 142 ) );
}
else
{
gc.SetPenStyle( CGraphicsContext::ESolidPen );
gc.SetPenColor( KRgbGray );
gc.DrawLine( TPoint( 0, aRect.iBr.iY - 1 ), TPoint( 176, aRect.iBr.iY - 1 ) );
}
}
// ---------------------------------------------------------
// CSabberMessageContainer::HandleControlEventL(
// CCoeControl* aControl,TCoeEvent aEventType)
// ---------------------------------------------------------
//
void CSabberMessageContainer::HandleControlEventL(
CCoeControl* /*aControl*/,TCoeEvent /*aEventType*/)
{
// TODO: Add your control event handler code here
}
void CSabberMessageContainer::HandleListBoxEventL(
CEikListBox* aListBox, TListBoxEvent aEventType )
{
}
TKeyResponse CSabberMessageContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
{
if ( iEditorActive )
return iTextEditor->OfferKeyEventL( aKeyEvent, aType );
else if ( iViewerActive )
return iMessageViewer->OfferKeyEventL( aKeyEvent, aType );
TChar charCode(aKeyEvent.iCode);
switch ( charCode ) // The code of key event is...
{
// Switches tab.
case EKeyLeftArrow: // Left key.
case EKeyRightArrow: // Right Key.
return EKeyWasNotConsumed; //iUi->HandleKeyEvent( aKeyEvent, aType );
}
if ( iListBox )
return iListBox->OfferKeyEventL( aKeyEvent, aType );
return EKeyWasNotConsumed;
}
void CSabberMessageContainer::SetAppUi( CSabberAppUi* aUi )
{
iUi = aUi;
}
TBool CSabberMessageContainer::GetTextEditorContent( char* cont )
{
strcpy( cont, "" );
TInt len = iTextEditor->TextLength();
if ( len == 0 )
return EFalse;
TBuf< 256 > buf;
iTextEditor->GetText( buf );
CUtil::Unicode2UTF8( cont, buf );
return ETrue;
}
void CSabberMessageContainer::GetCurItemDest( char* dest )
{
strcpy( dest, "" );
int idx = iListBox->CurrentItemIndex();
if( idx < 0 )
return;
CMessageItem* item = ( CMessageItem* )iModel->GetItemAt( idx );
strcpy( dest, item->GetDest() );
}
void CSabberMessageContainer::PopupEditorbox()
{
iListBox->View()->iCTimer->Cancel();
iTextEditor->ActivateL();
iTextEditor->SetFocus( ETrue );
iEditorActive = ETrue;
SizeChanged();
DrawNow();
}
void CSabberMessageContainer::PopoffEditorbox()
{
iTextEditor->SetFocus(EFalse);
ActivateListBox();
iListBox->View()->ShrinkCurrentItem();
iListBox->View()->iCTimer->Queue();
iEditorActive = EFalse;
SizeChanged();
DrawNow();
}
TBool CSabberMessageContainer::PopupViewer()
{
int idx = iListBox->CurrentItemIndex();
if( idx < 0 )
return EFalse;
CMessageItem* item = ( CMessageItem* )iModel->GetItemAt( idx );
iMessageViewer->SetMessageItem( item );
iMessageViewer->SetFont( iFont );
iMessageViewer->ActivateL();
iViewerActive = ETrue;
SizeChanged();
DrawNow();
return ETrue;
}
void CSabberMessageContainer::PopoffViewer()
{
iMessageViewer->Quit();
ActivateListBox();
iListBox->View()->ShrinkCurrentItem();
iListBox->View()->iCTimer->Queue();
iViewerActive = EFalse;
SizeChanged();
DrawNow();
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -