0
|
1 |
/*
|
|
2 |
* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Container class for log view.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <EcmtGui.rsg>
|
|
20 |
#include <stringloader.h>
|
|
21 |
|
|
22 |
#include "EcmtGuiLogContainer.h"
|
|
23 |
#include "EcmtGuiAppUi.h"
|
|
24 |
|
|
25 |
|
|
26 |
// ======== MEMBER FUNCTIONS ========
|
|
27 |
|
|
28 |
// ---------------------------------------------------------------------------
|
|
29 |
// C++ default constructor
|
|
30 |
// ---------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
CEcmtGuiLogContainer::CEcmtGuiLogContainer( CDesCArrayFlat& aMessageList )
|
|
33 |
: iMessageList( aMessageList )
|
|
34 |
{
|
|
35 |
}
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
// Destructor
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CEcmtGuiLogContainer::~CEcmtGuiLogContainer()
|
|
42 |
{
|
|
43 |
if( iListBox )
|
|
44 |
delete iListBox;
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// Symbian 2nd phase constructor can leave.
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CEcmtGuiLogContainer::ConstructL(const TRect& aRect)
|
|
52 |
{
|
|
53 |
iAutoScroll = ETrue;
|
|
54 |
|
|
55 |
CreateWindowL();
|
|
56 |
|
|
57 |
SetRect( aRect );
|
|
58 |
|
|
59 |
iListBox = new (ELeave) CAknDoubleStyleListBox();
|
|
60 |
iListBox->SetContainerWindowL( *this );
|
|
61 |
iListBox->ConstructL( NULL, EAknListBoxViewerFlags );
|
|
62 |
|
|
63 |
// Screate scroll bars
|
|
64 |
iListBox->CreateScrollBarFrameL( ETrue );
|
|
65 |
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
|
|
66 |
CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto );
|
|
67 |
|
|
68 |
// Give it to the control
|
|
69 |
iListBox->Model()->SetItemTextArray( &iMessageList );
|
|
70 |
iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
|
|
71 |
|
|
72 |
iListBox->SetRect( aRect );
|
|
73 |
|
|
74 |
// Activate the window, which makes it ready to be drawn
|
|
75 |
iListBox->ActivateL();
|
|
76 |
ActivateL();
|
|
77 |
}
|
|
78 |
|
|
79 |
// ---------------------------------------------------------------------------
|
|
80 |
// Loads message from resource and calls AddMessageL.
|
|
81 |
// ---------------------------------------------------------------------------
|
|
82 |
//
|
|
83 |
void CEcmtGuiLogContainer::LogMessageL( TInt aMsgResId )
|
|
84 |
{
|
|
85 |
TBuf<KMaxLogMsgLen> msg;
|
|
86 |
StringLoader::Load( msg, aMsgResId );
|
|
87 |
LogMessageL( msg );
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
// Calls AddMessageL
|
|
92 |
// ---------------------------------------------------------------------------
|
|
93 |
//
|
|
94 |
void CEcmtGuiLogContainer::LogMessageL( const TDesC& aMsg )
|
|
95 |
{
|
|
96 |
iLastMsg.SetLength(0);
|
|
97 |
_LIT( KTimeFormat, "\t%:0%J%:1%T%:2%S% " );
|
|
98 |
|
|
99 |
TTime curTime;
|
|
100 |
curTime.HomeTime();
|
|
101 |
curTime.FormatL( iLastMsg, KTimeFormat );
|
|
102 |
iLastMsg.Append( aMsg );
|
|
103 |
|
|
104 |
AddMessageL(iLastMsg, iAutoScroll);
|
|
105 |
}
|
|
106 |
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
// Adds message to the listbox and to the message list iMessageList.
|
|
109 |
// ---------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
void CEcmtGuiLogContainer::AddMessageL( const TDesC& aText, TBool aAutoScroll )
|
|
112 |
{
|
|
113 |
iMessageList.AppendL( aText );
|
|
114 |
iListBox->HandleItemAdditionL();
|
|
115 |
if ( aAutoScroll )
|
|
116 |
{
|
|
117 |
iListBox->SetCurrentItemIndexAndDraw( iMessageList.MdcaCount() - 1 );
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// ---------------------------------------------------------------------------
|
|
122 |
// Clears logs from the listbox.
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
void CEcmtGuiLogContainer::ClearMessageListL()
|
|
126 |
{
|
|
127 |
iListBox->HandleItemRemovalL();
|
|
128 |
iListBox->Reset();
|
|
129 |
}
|
|
130 |
|
|
131 |
// ---------------------------------------------------------------------------
|
|
132 |
// From class CCoeControl.
|
|
133 |
// Draws the control.
|
|
134 |
// ---------------------------------------------------------------------------
|
|
135 |
//
|
|
136 |
void CEcmtGuiLogContainer::Draw(const TRect& /*aRect*/) const
|
|
137 |
{
|
|
138 |
|
|
139 |
}
|
|
140 |
|
|
141 |
// ---------------------------------------------------------------------------
|
|
142 |
// From class CCoeControl.
|
|
143 |
// Responds to changes to the size and position of the contents of this
|
|
144 |
// control.
|
|
145 |
// ---------------------------------------------------------------------------
|
|
146 |
//
|
|
147 |
void CEcmtGuiLogContainer::SizeChanged()
|
|
148 |
{
|
|
149 |
|
|
150 |
}
|
|
151 |
|
|
152 |
// ---------------------------------------------------------------------------
|
|
153 |
// From class CCoeControl.
|
|
154 |
// Responds to changes to the size and position of the contents of this
|
|
155 |
// control.
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
TInt CEcmtGuiLogContainer::CountComponentControls() const
|
|
159 |
{
|
|
160 |
return 1;
|
|
161 |
}
|
|
162 |
|
|
163 |
// ---------------------------------------------------------------------------
|
|
164 |
// From class CCoeControl.
|
|
165 |
// Gets an indexed component of a compound control.
|
|
166 |
// ---------------------------------------------------------------------------
|
|
167 |
//
|
|
168 |
CCoeControl* CEcmtGuiLogContainer::ComponentControl(TInt aIndex) const
|
|
169 |
{
|
|
170 |
switch( aIndex )
|
|
171 |
{
|
|
172 |
case 0:
|
|
173 |
return iListBox;
|
|
174 |
default:
|
|
175 |
return NULL;
|
|
176 |
}
|
|
177 |
}
|
|
178 |
|