34
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-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: Text transaction element
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "texttransactionelement.h"
|
|
20 |
#include "aixmluiutils.h"
|
|
21 |
|
|
22 |
#include "xntype.h"
|
|
23 |
#include "xnproperty.h"
|
|
24 |
#include "xntext.h"
|
|
25 |
#include "xntexteditor.h"
|
|
26 |
#include "xnmenuadapter.h"
|
|
27 |
#include "xnnewsticker.h"
|
|
28 |
//#include <xnmarquee.h>
|
|
29 |
#include "mxncomponentinterface.h"
|
|
30 |
#include "xnnodeappif.h"
|
|
31 |
#include "xnuiengineappif.h"
|
|
32 |
#include "xnproperty.h"
|
|
33 |
#include "xndompropertyvalue.h"
|
|
34 |
#include "xnvolumecontrol.h"
|
|
35 |
#include "aistrcnv.h"
|
|
36 |
|
|
37 |
_LIT8( KTextEditor, "texteditor" );
|
|
38 |
|
|
39 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
40 |
|
|
41 |
using namespace AiXmlUiController;
|
|
42 |
using namespace XnTextInterface;
|
|
43 |
|
|
44 |
CTextTransactionElement::CTextTransactionElement(AiUtility::CContentPriorityMap& aContentPriorityMap)
|
|
45 |
: CTransactionElement(aContentPriorityMap)
|
|
46 |
{
|
|
47 |
}
|
|
48 |
|
|
49 |
CTextTransactionElement* CTextTransactionElement::NewL(AiUtility::CContentPriorityMap& aContentPriorityMap)
|
|
50 |
{
|
|
51 |
CTextTransactionElement* self = new( ELeave ) CTextTransactionElement(aContentPriorityMap);
|
|
52 |
|
|
53 |
return self;
|
|
54 |
}
|
|
55 |
|
|
56 |
CTextTransactionElement::~CTextTransactionElement()
|
|
57 |
{
|
|
58 |
if (iNewText)
|
|
59 |
{
|
|
60 |
delete iNewText;
|
|
61 |
iNewText = NULL;
|
|
62 |
}
|
|
63 |
}
|
|
64 |
|
|
65 |
void CTextTransactionElement::InitializeL( CXnNodeAppIf& aTarget, const TDesC& aText )
|
|
66 |
{
|
|
67 |
CheckTypeL( aTarget );
|
|
68 |
SetTarget( aTarget );
|
|
69 |
|
|
70 |
if (iNewText)
|
|
71 |
{
|
|
72 |
delete iNewText;
|
|
73 |
iNewText = NULL;
|
|
74 |
}
|
|
75 |
iNewText = aText.AllocL();
|
|
76 |
}
|
|
77 |
|
|
78 |
void CTextTransactionElement::UpdateDataL()
|
|
79 |
{
|
|
80 |
// Set new text
|
|
81 |
SetTextL();
|
|
82 |
|
|
83 |
// Update content priority
|
|
84 |
UpdateContentPriorityL();
|
|
85 |
}
|
|
86 |
|
|
87 |
void CTextTransactionElement::Reset()
|
|
88 |
{
|
|
89 |
CTransactionElement::Reset();
|
|
90 |
|
|
91 |
|
|
92 |
if (iNewText)
|
|
93 |
{
|
|
94 |
delete iNewText;
|
|
95 |
iNewText = NULL;
|
|
96 |
}
|
|
97 |
}
|
|
98 |
|
|
99 |
TBool CTextTransactionElement::IsSupported( CXnNodeAppIf& aTarget )
|
|
100 |
{
|
|
101 |
CXnType* typeInfo = aTarget.Type();
|
|
102 |
|
|
103 |
if ( !typeInfo )
|
|
104 |
{
|
|
105 |
return EFalse;
|
|
106 |
}
|
|
107 |
|
|
108 |
const TDesC8& type = typeInfo->Type();
|
|
109 |
|
|
110 |
// Text element, menu item, newsticker, and marquee supported
|
|
111 |
return ( type == XnTextInterface::MXnTextInterface::Type() ||
|
|
112 |
type == KXnMenuItem ||
|
|
113 |
type == KXnMenu ||
|
|
114 |
type == XnPropertyNames::softkey::KNodeName ||
|
|
115 |
type == XnPropertyNames::volumecontrol::KSlider ||
|
|
116 |
type == KTextEditor );
|
|
117 |
}
|
|
118 |
|
|
119 |
void CTextTransactionElement::CheckTypeL( CXnNodeAppIf& aTarget )
|
|
120 |
{
|
|
121 |
if ( !IsSupported( aTarget ) )
|
|
122 |
{
|
|
123 |
User::Leave( KErrNotSupported );
|
|
124 |
}
|
|
125 |
}
|
|
126 |
|
|
127 |
void CTextTransactionElement::SetTextL()
|
|
128 |
{
|
|
129 |
// Get type info
|
|
130 |
const TDesC8& type = LeaveIfNull( Target().Type(), KErrNotSupported )->Type();
|
|
131 |
|
|
132 |
if ( type == XnTextInterface::MXnTextInterface::Type() ) // text element
|
|
133 |
{
|
|
134 |
// Get control interface
|
|
135 |
XnTextInterface::MXnTextInterface* textControl = NULL;
|
|
136 |
XnComponentInterface::MakeInterfaceL( textControl, Target() );
|
|
137 |
LeaveIfNull( textControl, KErrNotSupported );
|
|
138 |
|
|
139 |
// set text
|
|
140 |
textControl->SetTextL( *iNewText );
|
|
141 |
}
|
|
142 |
else if( type == XnTextEditorInterface::MXnTextEditorInterface::Type() )
|
|
143 |
{
|
|
144 |
XnTextEditorInterface::MXnTextEditorInterface* editorControl = NULL;
|
|
145 |
XnComponentInterface::MakeInterfaceL( editorControl, Target() );
|
|
146 |
LeaveIfNull( editorControl, KErrNotSupported );
|
|
147 |
|
|
148 |
// set text
|
|
149 |
editorControl->SetTextL( *iNewText );
|
|
150 |
}
|
|
151 |
|
|
152 |
// Menu softkey texts
|
|
153 |
else if ( type == XnPropertyNames::softkey::KNodeName)
|
|
154 |
{
|
|
155 |
CXnNodeAppIf& target = Target();
|
|
156 |
// Set the label of the softkey
|
|
157 |
CXnDomPropertyValue* propertyValue =
|
|
158 |
CXnDomPropertyValue::NewL( &target.UiEngineL()->StringPool() );
|
|
159 |
|
|
160 |
CleanupStack::PushL( propertyValue );
|
|
161 |
|
|
162 |
// Convert unicode to UTF-8
|
|
163 |
HBufC8* textBuf = NULL;
|
|
164 |
|
|
165 |
textBuf = AiUtility::CopyToBufferL( textBuf, *iNewText );
|
|
166 |
CleanupStack::PushL( textBuf );
|
|
167 |
|
|
168 |
propertyValue->SetStringValueL( CXnDomPropertyValue::EString,
|
|
169 |
*textBuf );
|
|
170 |
|
|
171 |
CleanupStack::PopAndDestroy( textBuf );
|
|
172 |
|
|
173 |
CXnProperty* newProperty = CXnProperty::NewL( XnPropertyNames::menu::KLabel,
|
|
174 |
propertyValue,
|
|
175 |
target.UiEngineL()->StringPool() );
|
|
176 |
CleanupStack::Pop( propertyValue );
|
|
177 |
|
|
178 |
CleanupStack::PushL( newProperty );
|
|
179 |
|
|
180 |
target.SetPropertyL( newProperty );
|
|
181 |
|
|
182 |
CleanupStack::Pop( newProperty );
|
|
183 |
target.UiEngineL()->RefreshMenuL();
|
|
184 |
|
|
185 |
}
|
|
186 |
|
|
187 |
else if ( type == XnPropertyNames::volumecontrol::KSlider ) // slider
|
|
188 |
{
|
|
189 |
// Get volume control interface
|
|
190 |
XnVolumeControlInterface::MXnVolumeControlInterface* volumeControl = NULL;
|
|
191 |
XnComponentInterface::MakeInterfaceL( volumeControl, Target() );
|
|
192 |
LeaveIfNull( volumeControl, KErrNotSupported );
|
|
193 |
|
|
194 |
TInt32 volume = 0;
|
|
195 |
|
|
196 |
User::LeaveIfError( AiUtility::ParseInt( volume, *iNewText ) );
|
|
197 |
volumeControl->SetValue( volume );
|
|
198 |
}
|
|
199 |
/* else if ( type == XnNewstickerInterface::MXnNewstickerInterface::Type() )
|
|
200 |
{
|
|
201 |
// Get Newsticker control interface
|
|
202 |
XnNewstickerInterface::MXnNewstickerInterface* newsTicker = NULL;
|
|
203 |
XnComponentInterface::MakeInterfaceL( newsTicker, Target() );
|
|
204 |
LeaveIfNull( newsTicker, KErrNotSupported );
|
|
205 |
|
|
206 |
// Append new title
|
|
207 |
newsTicker->ClearTitles();
|
|
208 |
newsTicker->AppendTitleL( iNewText );
|
|
209 |
}
|
|
210 |
else if ( type == XnMarqueeInterface::MXnMarqueeInterface::Type() )
|
|
211 |
{
|
|
212 |
// Get marquee interface
|
|
213 |
XnMarqueeInterface::MXnMarqueeInterface* marquee = NULL;
|
|
214 |
XnComponentInterface::MakeInterfaceL( marquee, Target() );
|
|
215 |
LeaveIfNull( marquee, KErrNotSupported );
|
|
216 |
|
|
217 |
// Set new text
|
|
218 |
marquee->SetTextL( iNewText );
|
|
219 |
}*/
|
|
220 |
else
|
|
221 |
{
|
|
222 |
User::Leave( KErrNotSupported );
|
|
223 |
}
|
|
224 |
}
|
|
225 |
|
|
226 |
// End of File
|